Belle II Software  release-05-01-25
eclEdgeCollectorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2020 - Belle II Collaboration *
4  * *
5  * Contributors: Christopher Heary (hearty@physics.ubc.ca) *
6  * *
7  * This software is provided "as is" without any warranty. *
8  **************************************************************************/
9 
10 #include <ecl/modules/eclEdgeCollector/eclEdgeCollectorModule.h>
11 #include <TH2F.h>
12 #include <TVector3.h>
13 #include <TMath.h>
14 #include <ecl/geometry/ECLGeometryPar.h>
15 #include <ecl/dbobjects/ECLCrystalCalib.h>
16 
17 
18 using namespace Belle2;
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(eclEdgeCollector)
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
29 eclEdgeCollectorModule::eclEdgeCollectorModule() : CalibrationCollectorModule(), m_ECLCrystalOffsetTheta("ECLCrystalOffsetTheta"),
30  m_ECLCrystalOffsetPhi("ECLCrystalOffsetPhi")
31 {
33  setDescription("Obtain location of crystal edges from geometry and ECLCrystalOffsetTheta and ECLCrystalOffsetPhi payloads.");
34 }
35 
37 {
38  //..Define histograms
39  auto eclCrystalX = new TH1F("eclCrystalX", "x of each crystal;cellID;x (cm)", 8736, 1, 8737);
40  registerObject<TH1F>("eclCrystalX", eclCrystalX);
41 
42  auto eclCrystalY = new TH1F("eclCrystalY", "y of each crystal;cellID;y(cm)", 8736, 1, 8737);
43  registerObject<TH1F>("eclCrystalY", eclCrystalY);
44 
45  auto eclCrystalZ = new TH1F("eclCrystalZ", "z of each crystal;cellID;z (cm)", 8736, 1, 8737);
46  registerObject<TH1F>("eclCrystalZ", eclCrystalZ);
47 
48  auto eclCrystalR = new TH1F("eclCrystalR", "R (3d) of each crystal;cellID;R (cm)", 8736, 1, 8737);
49  registerObject<TH1F>("eclCrystalR", eclCrystalR);
50 
51  auto eclCrystalTheta = new TH1F("eclCrystalTheta", "theta of each crystal location;cellID;theta (rad)", 8736, 1, 8737);
52  registerObject<TH1F>("eclCrystalTheta", eclCrystalTheta);
53 
54  auto eclCrystalPhi = new TH1F("eclCrystalPhi", "phi of each crystal location;cellID;phi (rad)", 8736, 1, 8737);
55  registerObject<TH1F>("eclCrystalPhi", eclCrystalPhi);
56 
57  auto eclCrystalDirTheta = new TH1F("eclCrystalDirTheta", "theta of each crystal direction;cellID;theta (rad)", 8736, 1, 8737);
58  registerObject<TH1F>("eclCrystalDirTheta", eclCrystalDirTheta);
59 
60  auto eclCrystalDirPhi = new TH1F("eclCrystalDirPhi", "phi of each crystal direction;cellID;phi (rad)", 8736, 1, 8737);
61  registerObject<TH1F>("eclCrystalDirPhi", eclCrystalDirPhi);
62 
63  auto eclCrystalEdgeTheta = new TH1F("eclCrystalEdgeTheta", "lower edge of each crystal in theta;cellID;theta (rad)", 8736, 1, 8737);
64  registerObject<TH1F>("eclCrystalEdgeTheta", eclCrystalEdgeTheta);
65 
66  auto eclCrystalEdgePhi = new TH1F("eclCrystalEdgePhi", "lower edge of each crystal in phi;cellID;phi (rad)", 8736, 1, 8737);
67  registerObject<TH1F>("eclCrystalEdgePhi", eclCrystalEdgePhi);
68 
69 }
70 
72 {
73  //..First time through, store the ECL geometry.
74  if (storeGeo) {
75  storeGeo = false;
76 
77  //..Read in payloads of offsets between crystal centers and edges
78  std::vector<float> offsetTheta;
79  if (m_ECLCrystalOffsetTheta.hasChanged()) {offsetTheta = m_ECLCrystalOffsetTheta->getCalibVector();}
80  std::vector<float> offsetPhi;
81  if (m_ECLCrystalOffsetPhi.hasChanged()) {offsetPhi = m_ECLCrystalOffsetPhi->getCalibVector();}
82 
83  //..ECL geometry
85  for (int cellID = 1; cellID <= 8736; cellID++) {
86  TVector3 crystalPos = eclGeometry->GetCrystalPos(cellID - 1);
87  TVector3 crystalDirection = eclGeometry->GetCrystalVec(cellID - 1);
88  getObjectPtr<TH1F>("eclCrystalX")->SetBinContent(cellID, crystalPos.X());
89  getObjectPtr<TH1F>("eclCrystalY")->SetBinContent(cellID, crystalPos.Y());
90  getObjectPtr<TH1F>("eclCrystalZ")->SetBinContent(cellID, crystalPos.Z());
91  getObjectPtr<TH1F>("eclCrystalR")->SetBinContent(cellID, crystalPos.Mag());
92  getObjectPtr<TH1F>("eclCrystalTheta")->SetBinContent(cellID, crystalPos.Theta());
93  getObjectPtr<TH1F>("eclCrystalPhi")->SetBinContent(cellID, crystalPos.Phi());
94  getObjectPtr<TH1F>("eclCrystalDirTheta")->SetBinContent(cellID, crystalDirection.Theta());
95  getObjectPtr<TH1F>("eclCrystalDirPhi")->SetBinContent(cellID, crystalDirection.Phi());
96 
97  //..Subtract the offset between crystal center and edge to get edge locations
98  float thetaEdge = crystalPos.Theta() - offsetTheta[cellID - 1];
99  getObjectPtr<TH1F>("eclCrystalEdgeTheta")->SetBinContent(cellID, thetaEdge);
100 
101  float phiEdge = crystalPos.Phi() - offsetPhi[cellID - 1];
102  if (phiEdge < -TMath::Pi()) {phiEdge += 2 * TMath::Pi();}
103  getObjectPtr<TH1F>("eclCrystalEdgePhi")->SetBinContent(cellID, phiEdge);
104 
105  //..Print out some for debugging purposes
106  if (cellID % 1000 == 0) {
107  B2INFO("cellID " << cellID << ": theta " << crystalPos.Theta() << " phi " <<
108  crystalPos.Phi() << " R " << crystalPos.Mag() << " thetaEdge " << thetaEdge << " phiEdge " << phiEdge);
109  }
110  }
111  }
112 }
113 
114 
Belle2::CalibrationCollectorModule
Calibration collector module base class.
Definition: CalibrationCollectorModule.h:44
Belle2::ECL::ECLGeometryPar::GetCrystalVec
TVector3 GetCrystalVec(int cid)
The direction of crystal.
Definition: ECLGeometryPar.h:110
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::eclEdgeCollectorModule::collect
virtual void collect() override
Accumulate histograms.
Definition: eclEdgeCollectorModule.cc:71
Belle2::eclEdgeCollectorModule::m_ECLCrystalOffsetPhi
DBObjPtr< ECLCrystalCalib > m_ECLCrystalOffsetPhi
offset in phi
Definition: eclEdgeCollectorModule.h:52
Belle2::ECL::ECLGeometryPar::Instance
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
Definition: ECLGeometryPar.cc:151
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ECL::ECLGeometryPar::GetCrystalPos
TVector3 GetCrystalPos(int cid)
The Position of crystal.
Definition: ECLGeometryPar.h:102
Belle2::eclEdgeCollectorModule::prepare
virtual void prepare() override
Define histograms and read payloads from DB.
Definition: eclEdgeCollectorModule.cc:36
Belle2::ECL::ECLGeometryPar
The Class for ECL Geometry Parameters.
Definition: ECLGeometryPar.h:45
Belle2::eclEdgeCollectorModule
Collector to store ECL crystal locations.
Definition: eclEdgeCollectorModule.h:34
Belle2::eclEdgeCollectorModule::m_ECLCrystalOffsetTheta
DBObjPtr< ECLCrystalCalib > m_ECLCrystalOffsetTheta
force geometry to be saved first event
Definition: eclEdgeCollectorModule.h:48