View Javadoc

1   package org.lcsim.geometry.compact.converter.pandora;
2   
3   import static org.lcsim.geometry.Calorimeter.CalorimeterType.HAD_BARREL;
4   import static org.lcsim.geometry.Calorimeter.CalorimeterType.HAD_ENDCAP;
5   import static org.lcsim.geometry.Calorimeter.CalorimeterType.MUON_BARREL;
6   import static org.lcsim.geometry.Calorimeter.CalorimeterType.MUON_ENDCAP;
7   
8   import java.util.ArrayList;
9   import java.util.List;
10  import java.util.StringTokenizer;
11  
12  import org.lcsim.conditions.ConditionsSet;
13  import org.lcsim.geometry.Calorimeter;
14  import org.lcsim.geometry.Calorimeter.CalorimeterType;
15  
16  /**
17   * Represents CalorimeterConditions for a single subdetector.
18   * 
19   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
20   */
21  // FIXME: Put into separate package from Pandora converter.
22  public class CalorimeterConditions
23  {
24      SamplingLayers samplingLayers;
25      String name;
26      double mipEnergy;
27      double mipSigma;
28      double mipCut;
29      double timeCut;
30  
31      public String toString()
32      {
33          StringBuffer buff = new StringBuffer();
34          buff.append(name + '\n');
35          for (SamplingLayerRange range : samplingLayers)
36          {
37              buff.append("[" + range.getLowerLayer() + " - " + range.getUpperLayer() + "]" + '\n');
38              buff.append("    em = " + range.getEMSampling() + '\n');
39              buff.append("    had = " + range.getHADSampling() + '\n');
40          }
41  
42          return buff.toString();
43      }
44  
45      public SamplingLayers getSamplingLayers()
46      {
47          return samplingLayers;
48      }
49  
50      /**
51       * Constructor that parses raw CalorimeterCalibration conditions for a
52       * single subdetector.
53       * 
54       * @param calorimeter
55       * @param conditions
56       */
57      public CalorimeterConditions(Calorimeter calorimeter, ConditionsSet conditions)
58      {
59          //System.out.println("conditions: " + calorimeter.getName());
60          this.name = calorimeter.getName();
61  
62          // Figure out which layering conditions to use based on the
63          // CalorimeterType.
64          String layeringName = null;
65          if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP)
66          {
67              layeringName = "ECalLayering";
68          }
69          else if (calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP)
70          {
71              layeringName = "HCalLayering";
72          }
73          else if (calorimeter.getCalorimeterType() == CalorimeterType.MUON_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.MUON_ENDCAP)
74          {
75              layeringName = "MuonLayering";
76          }
77          else
78          {
79              throw new RuntimeException("Don't know how to handle CalorimeterConditions for " + calorimeter.getName() + ".");
80          }
81  
82          String emName = null;
83          String hadName = null;
84          if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.MUON_BARREL)
85          {
86              emName = "EMBarrel_SF";
87              hadName = "HadBarrel_SF";
88          }
89          else if (calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP || calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP || calorimeter.getCalorimeterType() == CalorimeterType.MUON_ENDCAP)
90          {
91              emName = "EMEndcap_SF";
92              hadName = "HadEndcap_SF";
93          }
94  
95          if (emName == null || hadName == null)
96          {
97              throw new RuntimeException("Sampling fractions not found for " + calorimeter.getName() + ".");
98          }
99  
100         String emSampling = conditions.getString(emName);
101         String hadSampling = conditions.getString(hadName);
102         List<Double> emSamplingFractions = new ArrayList<Double>();
103         List<Double> hadSamplingFractions = new ArrayList<Double>();
104         StringTokenizer tok = new StringTokenizer(emSampling, ",");
105         while (tok.hasMoreTokens())
106         {
107             Double emSamplingFraction = Double.valueOf(tok.nextToken().trim());
108             emSamplingFractions.add(emSamplingFraction);
109         }
110         tok = new StringTokenizer(hadSampling, ",");
111         while (tok.hasMoreTokens())
112         {
113             Double hadSamplingFraction = Double.valueOf(tok.nextToken().trim());
114             hadSamplingFractions.add(hadSamplingFraction);
115         }
116 
117         String layering = conditions.getString(layeringName);
118         tok = new StringTokenizer(layering, ",");
119         List<Integer> layers = new ArrayList<Integer>();
120         int maxLayer = calorimeter.getLayering().getLayerCount() - 1;
121         while (tok.hasMoreTokens())
122         {
123             String nextToken = tok.nextToken().trim();
124             int nextLayer = Integer.valueOf(nextToken);
125             layers.add(nextLayer);
126         }
127 
128         // FIXME Hack to get the correct starting index for the sampling
129         // fractions. Ideally, the sampling fractions should be separated by subdetector name.
130         int samplingIndex = 0;
131         if (calorimeter.getCalorimeterType() == HAD_BARREL || calorimeter.getCalorimeterType() == HAD_ENDCAP)
132         {
133             samplingIndex = (new StringTokenizer(conditions.getString("ECalLayering"), ",").countTokens());
134         }
135         if (calorimeter.getCalorimeterType() == MUON_BARREL || calorimeter.getCalorimeterType() == MUON_ENDCAP)
136         {
137             samplingIndex = (new StringTokenizer(conditions.getString("ECalLayering"), ",").countTokens());
138             samplingIndex += (new StringTokenizer(conditions.getString("HCalLayering"), ",").countTokens());
139         }
140 
141         // System.out.println("    samplingIndex: " + samplingIndex);
142 
143         // Create the SamplingLayerRange list.
144         samplingLayers = new SamplingLayers();
145         for (int i = 0; i < layers.size(); i++)
146         {
147             // Figure out the layer range.
148             int lowerLayer = layers.get(i);
149             int upperLayer = 0;
150             if (i + 1 > layers.size() - 1)
151                 upperLayer = maxLayer;
152             else
153                 upperLayer = layers.get(i + 1) - 1;
154 
155             // Create the sampling layer range.
156             double emSamplingFraction = emSamplingFractions.get(samplingIndex);
157             double hadSamplingFraction = hadSamplingFractions.get(samplingIndex);
158             SamplingLayerRange samplingLayerRange = new SamplingLayerRange(lowerLayer, upperLayer, emSamplingFraction, hadSamplingFraction);
159             // System.out.println("    " + lowerLayer + " - " + upperLayer +
160             // " : " + emSamplingFraction + ", " + hadSamplingFraction);
161 
162             samplingLayers.add(samplingLayerRange);
163 
164             ++samplingIndex;
165         }
166 
167         // MIP energy.
168         String mipCondition = null;
169         String mipSigmaCondition = null;
170         String mipCutCondition = null;
171         
172         // FIXME: Cleanup this ugliness.
173         if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP)
174         {
175             mipCondition = "ECalMip_MPV";
176             mipSigmaCondition = "ECalMip_sig";
177             mipCutCondition = "ECalMip_Cut";
178         }
179         else if (calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP)
180         {
181             mipCondition = "HCalMip_MPV";
182             mipSigmaCondition = "HCalMip_sig";
183             mipCutCondition = "HCalMip_Cut";
184         }
185         else if (calorimeter.getCalorimeterType() == CalorimeterType.MUON_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.MUON_ENDCAP)
186         {
187             mipCondition = "MuonMip_MPV";
188             mipSigmaCondition = "MuonMip_sig";
189             mipCutCondition = "MuonMip_Cut";
190         }
191         mipEnergy = conditions.getDouble(mipCondition);
192         mipSigma = conditions.getDouble(mipSigmaCondition);
193         mipCut = conditions.getDouble(mipCutCondition);
194         timeCut = conditions.getDouble("timeCut");
195 
196         /*
197          * System.out.println("    mipEnergy: " + mipEnergy);
198          * System.out.println("    mipSigma: " + mipSigma);
199          * System.out.println("    mipCut: " + mipCut);
200          * System.out.println("    timeCut: " + timeCut);
201          */
202     }
203 
204     public SamplingLayerRange getSamplingLayerRange(int layer)
205     {
206         for (SamplingLayerRange layers : this.samplingLayers)
207         {
208             if (layers.inRange(layer))
209                 return layers;
210         }
211         return null;
212     }
213 
214     public double getMipEnergy()
215     {
216         return mipEnergy;
217     }
218 
219     public double getMipSigma()
220     {
221         return mipSigma;
222     }
223 
224     public double getMipCut()
225     {
226         return mipCut;
227     }
228 
229     public double getTimeCut()
230     {
231         return timeCut;
232     }
233 }