Belle II Software development
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/* Own header. */
10#include <ecl/modules/eclEdgeCollector/eclEdgeCollectorModule.h>
11
12/* ECL headers. */
13#include <ecl/dataobjects/ECLElementNumbers.h>
14#include <ecl/dbobjects/ECLCrystalCalib.h>
15#include <ecl/geometry/ECLGeometryPar.h>
16
17/* ROOT headers. */
18#include <Math/Vector3D.h>
19#include <TH2F.h>
20#include <TMath.h>
21
22
23using namespace Belle2;
24
25//-----------------------------------------------------------------
26// Register the Module
27//-----------------------------------------------------------------
28REG_MODULE(eclEdgeCollector);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
34eclEdgeCollectorModule::eclEdgeCollectorModule() : CalibrationCollectorModule(), m_ECLCrystalOffsetTheta("ECLCrystalOffsetTheta"),
35 m_ECLCrystalOffsetPhi("ECLCrystalOffsetPhi")
36{
38 setDescription("Obtain location of crystal edges from geometry and ECLCrystalOffsetTheta and ECLCrystalOffsetPhi payloads.");
39}
40
42{
43 //..Define histograms
44 auto eclCrystalX = new TH1F("eclCrystalX", "x of each crystal;cellID;x (cm)", ECLElementNumbers::c_NCrystals, 1, 8737);
45 registerObject<TH1F>("eclCrystalX", eclCrystalX);
46
47 auto eclCrystalY = new TH1F("eclCrystalY", "y of each crystal;cellID;y(cm)", ECLElementNumbers::c_NCrystals, 1, 8737);
48 registerObject<TH1F>("eclCrystalY", eclCrystalY);
49
50 auto eclCrystalZ = new TH1F("eclCrystalZ", "z of each crystal;cellID;z (cm)", ECLElementNumbers::c_NCrystals, 1, 8737);
51 registerObject<TH1F>("eclCrystalZ", eclCrystalZ);
52
53 auto eclCrystalR = new TH1F("eclCrystalR", "R (3d) of each crystal;cellID;R (cm)", ECLElementNumbers::c_NCrystals, 1, 8737);
54 registerObject<TH1F>("eclCrystalR", eclCrystalR);
55
56 auto eclCrystalTheta = new TH1F("eclCrystalTheta", "theta of each crystal location;cellID;theta (rad)",
58 registerObject<TH1F>("eclCrystalTheta", eclCrystalTheta);
59
60 auto eclCrystalPhi = new TH1F("eclCrystalPhi", "phi of each crystal location;cellID;phi (rad)", ECLElementNumbers::c_NCrystals, 1,
61 8737);
62 registerObject<TH1F>("eclCrystalPhi", eclCrystalPhi);
63
64 auto eclCrystalDirTheta = new TH1F("eclCrystalDirTheta", "theta of each crystal direction;cellID;theta (rad)",
66 registerObject<TH1F>("eclCrystalDirTheta", eclCrystalDirTheta);
67
68 auto eclCrystalDirPhi = new TH1F("eclCrystalDirPhi", "phi of each crystal direction;cellID;phi (rad)",
70 registerObject<TH1F>("eclCrystalDirPhi", eclCrystalDirPhi);
71
72 auto eclCrystalEdgeTheta = new TH1F("eclCrystalEdgeTheta", "lower edge of each crystal in theta;cellID;theta (rad)",
74 registerObject<TH1F>("eclCrystalEdgeTheta", eclCrystalEdgeTheta);
75
76 auto eclCrystalEdgePhi = new TH1F("eclCrystalEdgePhi", "lower edge of each crystal in phi;cellID;phi (rad)",
78 registerObject<TH1F>("eclCrystalEdgePhi", eclCrystalEdgePhi);
79
80 auto eclEdgeCounter = new TH1F("eclEdgeCounter", "dummy histogram to count collector calls;cellID;calls",
82 registerObject<TH1F>("eclEdgeCounter", eclEdgeCounter);
83
84}
85
87{
88 //..First time through, store the ECL geometry.
89 if (storeGeo) {
90 storeGeo = false;
91
92 //..Read in payloads of offsets between crystal centers and edges
93 std::vector<float> offsetTheta;
94 if (m_ECLCrystalOffsetTheta.hasChanged()) {offsetTheta = m_ECLCrystalOffsetTheta->getCalibVector();}
95 std::vector<float> offsetPhi;
96 if (m_ECLCrystalOffsetPhi.hasChanged()) {offsetPhi = m_ECLCrystalOffsetPhi->getCalibVector();}
97
98 //..ECL geometry
100 for (int cellID = 1; cellID <= ECLElementNumbers::c_NCrystals; cellID++) {
101 ROOT::Math::XYZVector crystalPos = eclGeometry->GetCrystalPos(cellID - 1);
102 ROOT::Math::XYZVector crystalDirection = eclGeometry->GetCrystalVec(cellID - 1);
103 getObjectPtr<TH1F>("eclCrystalX")->SetBinContent(cellID, crystalPos.X());
104 getObjectPtr<TH1F>("eclCrystalY")->SetBinContent(cellID, crystalPos.Y());
105 getObjectPtr<TH1F>("eclCrystalZ")->SetBinContent(cellID, crystalPos.Z());
106 getObjectPtr<TH1F>("eclCrystalR")->SetBinContent(cellID, crystalPos.R());
107 getObjectPtr<TH1F>("eclCrystalTheta")->SetBinContent(cellID, crystalPos.Theta());
108 getObjectPtr<TH1F>("eclCrystalPhi")->SetBinContent(cellID, crystalPos.Phi());
109 getObjectPtr<TH1F>("eclCrystalDirTheta")->SetBinContent(cellID, crystalDirection.Theta());
110 getObjectPtr<TH1F>("eclCrystalDirPhi")->SetBinContent(cellID, crystalDirection.Phi());
111 getObjectPtr<TH1F>("eclEdgeCounter")->SetBinContent(cellID, 1);
112
113 //..Subtract the offset between crystal center and edge to get edge locations
114 float thetaEdge = crystalPos.Theta() - offsetTheta[cellID - 1];
115 getObjectPtr<TH1F>("eclCrystalEdgeTheta")->SetBinContent(cellID, thetaEdge);
116
117 float phiEdge = crystalPos.Phi();
118 if (!offsetPhi.empty()) phiEdge -= offsetPhi[cellID - 1];
119 if (phiEdge < -TMath::Pi()) {phiEdge += 2 * TMath::Pi();}
120 getObjectPtr<TH1F>("eclCrystalEdgePhi")->SetBinContent(cellID, phiEdge);
121
122 //..Print out some for debugging purposes
123 if (cellID % 1000 == 0) {
124 B2INFO("cellID " << cellID << ": theta " << crystalPos.Theta() << " phi " <<
125 crystalPos.Phi() << " R " << crystalPos.R() << " thetaEdge " << thetaEdge << " phiEdge " << phiEdge);
126 }
127 }
128 }
129}
130
131
Calibration collector module base class.
The Class for ECL Geometry Parameters.
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
ROOT::Math::XYZVector GetCrystalPos(int cid)
The Position of crystal.
ROOT::Math::XYZVector GetCrystalVec(int cid)
The direction of crystal.
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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.
eclEdgeCollectorModule()
Constructor: Sets the description, the properties and the parameters of the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.