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