View Javadoc

1   /*
2    * ClusterCalibrationAnalysisDriverTest.java
3    * JUnit based test
4    *
5    * Created on May 22, 2008, 11:41 AM
6    */
7   
8   package org.lcsim.cal.calib;
9   
10  import java.util.HashMap;
11  import java.util.Map;
12  import junit.framework.*;
13  import org.lcsim.conditions.ConditionsManager;
14  import org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException;
15  import org.lcsim.conditions.ConditionsSet;
16  
17  
18  import static java.lang.Math.sin;
19  import static java.lang.Math.PI;
20  
21  /**
22   *
23   * @author ngraf
24   */
25  public class ClusterCalibrationAnalysisDriverTest extends TestCase
26  {
27      //TODO add some assertions to be able to fail if things go wrong
28      public void testConditionsHandler() throws Exception
29      {
30          boolean debug = false;
31          ConditionsManager mgr = ConditionsManager.defaultInstance();
32          mgr.setDetector("sidloi3", 0);
33          ConditionsSet cs = null;
34          try
35          {
36              cs = mgr.getConditions("CalorimeterCalibration");
37          }
38          catch(ConditionsSetNotFoundException e)
39          {
40              System.out.println("ConditionSet CalorimeterCalibration not found for detector "+mgr.getDetector());
41              System.out.println("Please check that this properties file exists for this detector ");
42          }
43          if(debug) System.out.println(" testing CalorimeterCalibration conditions");
44          String collections = cs.getString("BaseHitCollectionNames");
45          if(debug) System.out.println(collections);
46          String[] collNames = collections.split(",\\s");
47          if(debug)
48          {
49          for(int i=0; i<collNames.length; ++i)
50          {
51              System.out.println(collNames[i]);
52          }
53          System.out.println("ECalMip_Cut= "+cs.getDouble("ECalMip_Cut"));
54          }
55          
56          // test sampling fraction handling...
57          Map<String, Double> _fitParameters = new HashMap<String, Double>();
58          // photons
59          String photonFitParametersList = cs.getString("PhotonFitParameters");
60          String[]  photonFitParameters = photonFitParametersList.split(",\\s");
61          for(int i=0; i<photonFitParameters.length; ++i)
62          {
63              _fitParameters.put(photonFitParameters[i], cs.getDouble(photonFitParameters[i]));
64          }
65          // neutral hadrons
66          String hadronFitParametersList = cs.getString("NeutralHadronFitParameters");
67          String[]  hadronFitParameters = hadronFitParametersList.split(",\\s");
68          for(int i=0; i<hadronFitParameters.length; ++i)
69          {
70              _fitParameters.put(hadronFitParameters[i], cs.getDouble(hadronFitParameters[i]));
71          }
72          
73          double[] _ecalLayering = cs.getDoubleArray("ECalLayering");
74          
75          String[] types = {"gamma", "neutralHadron"};
76          
77          for(int i=0; i< types.length; ++i)
78          {
79              String type = types[i];
80              
81              // test the em barrel
82              boolean isEM = true;
83              boolean isEndcap = false;
84              
85              boolean useFirstLayer = cs.getDouble("IsFirstEmLayerSampling")==1.;
86              if(useFirstLayer) if(debug) System.out.println("first layer is sampling");
87              
88              for (int layer = 0; layer<31; ++layer)
89              {
90                  int caltype = 0;
91                  for(int j=1; j<_ecalLayering.length+1; ++j)
92                  {
93                      if(layer >= _ecalLayering[j-1]) caltype = j-1;
94                  }
95                  
96                  if(debug) System.out.println("layer= "+layer+" caltype= "+caltype);
97                  String name = type + "_"+ (isEM ? "em"+caltype : "had") + (isEndcap ? "e" : "b");
98                  if(debug) System.out.println("fit parameter name "+name);
99                  
100                 double theta = PI/2.;
101                 // now calculate normal to the sampling plane
102                 if(isEndcap)
103                 {
104                     theta -= PI/2.;
105                 }
106                 else
107                 {
108                     theta -= PI;
109                 }
110                 double a = 0.;
111                 double b = 0.;
112                 if(caltype==0 && !useFirstLayer)
113                 {
114                     a = 0.;
115                     b = sin(theta);
116                 }
117                 else
118                 {
119                     a = _fitParameters.get(name+"_0");
120                     b = _fitParameters.get(name+"_1");
121                 }
122                 double correctionFactor = a + b*sin(theta);
123                 if(debug) System.out.println("theta= "+theta+" correction factor= "+correctionFactor);
124                 
125             }
126             
127         } // end of loop over type
128 
129     }
130 }