Belle II Software development
CDCDedxDQM.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 <cdc/modules/CDCDedxDQM/CDCDedxDQM.h>
10
11#include <cdc/geometry/CDCGeometryPar.h>
12
13#include <analysis/utility/ReferenceFrame.h>
14#include <mdst/dataobjects/Track.h>
15#include <mdst/dataobjects/ECLCluster.h>
16#include <mdst/dbobjects/BeamSpot.h>
17
18#include <TDirectory.h>
19#include <TMath.h>
20
21#include <cmath>
22
23using namespace Belle2;
24
25REG_MODULE(CDCDedxDQM);
26
27//---------------------------------
29{
30 setPropertyFlags(c_ParallelProcessingCertified); // parallel processing
31 setDescription("CDC dE/dx DQM plots with bhabha/hadron events.");
32 addParam("mmode", mmode, "default monitoring mode is basic", std::string("basic"));
33}
34
35//---------------------------------
37{
38
39 TDirectory* oldDir = gDirectory;
40 oldDir->mkdir("CDCDedx");
41 oldDir->cd("CDCDedx");
42
43 int expNum = -1;
44 int runNum = -1;
45 double rungain = -99.0;
46
47 if (m_MetaDataPtr) {
48 expNum = int(m_MetaDataPtr->getExperiment());
49 runNum = int(m_MetaDataPtr->getRun());
50 if (m_DBRunGain) rungain = m_DBRunGain->getRunGain();
51 }
52
53 hMeta = new TH1D("hMeta", "hMeta", 3, 0.5, 3.5);
54 hMeta->GetXaxis()->SetTitle("Quantity");
55 hMeta->GetYaxis()->SetTitle("Values");
56 hMeta->SetTitle(Form("(Exp:%d, Run:%d, RG:%0.03f)", expNum, runNum, rungain));
57 hMeta->GetXaxis()->SetBinLabel(1, "nevt");
58 hMeta->GetXaxis()->SetBinLabel(2, "nbhabha");
59 hMeta->GetXaxis()->SetBinLabel(3, "nhadron");
60
61 hdEdx = new TH1D("hdEdx", ";CDC dE/dx;Entries", 100, 0., 2.5);
62 hinjtimeHer = new TH2D("hinjtimeHer", ";injection time (#mu s); CDC dE/dx", 40, 0, 80e3, 50, 0, 2.5);
63 hinjtimeLer = new TH2D("hinjtimeLer", ";injection time (#mu s); CDC dE/dx", 40, 0, 80e3, 50, 0, 2.5);
64 hdEdxvsP = new TH2D("hdEdxVsP", ";#it{p}_{CDC} (GeV/c);CDC dE/dx", 100, 0.05, 2.50, 100, 0.35, 10.0);
65 hdEdxvsEvt = new TH2D("hdEdxvsEvt", ";Events(M);CDC dE/dx", 50, 0, 200, 50, 0.00, 2.0);
66 hdEdxvsCosth = new TH2D("hdEdxvsCosth", ";cos#theta (e^{-}e^{+} tracks);CDC dE/dx", 50, -1.00, 1.00, 50, 0.00, 2.5);
67 hdEdxvsPhi = new TH2D("hdEdxvsPhi", ";#phi (e^{-}e^{+} tracks);CDC dE/dx", 50, -3.20, 3.20, 50, 0.00, 2.5);
68 if (mmode != "basic") {
69 hWires = new TH2F("hWires", "All Wires;", 2400, -1.2, 1.2, 2400, -1.2, 1.2);
70 hWires->GetXaxis()->SetTitle("CDC-wire map: counter-clockwise and start from +x");
71 hWireStatus = new TH2F("hWireStatus", "Wire Status", 2400, -1.2, 1.2, 2400, -1.2, 1.2);
72 hWireStatus->GetXaxis()->SetTitle("CDC-wire map: counter-clockwise and start from +x");
73 }
74 oldDir->cd();
75
76}
77
78
79//---------------------------------
81{
82
83 if (!m_cdcDedxTracks.isOptional()) {
84 B2WARNING("Missing CDCDedxTracks array, CDCDedxDQM is skipped.");
85 return;
86 }
87
88 m_TrgResult.isOptional();
89 m_cdcDedxTracks.isRequired();
90 REG_HISTOGRAM
91
92}
93
94//-------------------------------
96{
97
98 if (!m_cdcDedxTracks.isOptional()) {
99 B2WARNING("Missing CDCDedxTracks array, CDCDedxDQM is skipped.");
100 return;
101 }
102
103 hMeta->Reset();
104 hdEdx->Reset();
105 hinjtimeHer->Reset();
106 hinjtimeLer->Reset();
107 hdEdxvsP->Reset();
108 hdEdxvsCosth->Reset();
109 hdEdxvsPhi->Reset();
110 hdEdxvsEvt->Reset();
111 if (mmode != "basic") {
112 hWires->Reset();
113 hWireStatus->Reset();
114 }
115}
116
117
118//----------------------------
120{
121
122 if (!m_cdcDedxTracks.isOptional()) return;
123
124 if (!m_TrgResult.isValid()) {
125 B2WARNING("Required SoftwareTriggerResult object not available: CDCDedxDQM is skipped");
126 return;
127 }
128
129 const std::map<std::string, int>& fresults = m_TrgResult->getResults();
130 if (fresults.find("software_trigger_cut&skim&accept_bhabha") == fresults.end()
131 and fresults.find("software_trigger_cut&skim&accept_hadron") == fresults.end())return;
132
133 const bool IsBhabhaEvt = (m_TrgResult->getResult("software_trigger_cut&skim&accept_bhabha") ==
135 const bool IsHadronEvt = (m_TrgResult->getResult("software_trigger_cut&skim&accept_hadron") ==
137
138 m_nEvt += 1;
139 if (!IsBhabhaEvt and !IsHadronEvt)return;
140 if (IsBhabhaEvt)m_nBEvt += 1;
141 if (IsHadronEvt)m_nHEvt += 1;
142
143 //Get current evt number
144 int event = -1;
145
146 if (m_MetaDataPtr)event = int(m_MetaDataPtr->getEvent());
147
148 for (int idedx = 0; idedx < m_cdcDedxTracks.getEntries(); idedx++) {
149
150 CDCDedxTrack* dedxTrack = m_cdcDedxTracks[idedx];
151 if (!dedxTrack || dedxTrack->size() == 0)continue;
152
153 const Track* track = dedxTrack->getRelatedFrom<Track>();
154 if (!track)continue;
155
156 const TrackFitResult* fitResult = track->getTrackFitResultWithClosestMass(Const::pion);
157 if (!fitResult)continue;
158
159 UncertainHelix helix = fitResult->getUncertainHelix();
160 static DBObjPtr<BeamSpot> beamSpotDB;
161 helix.passiveMoveBy(ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
162 const auto& frame = ReferenceFrame::GetCurrent();
163 double dr = frame.getVertex(ROOT::Math::XYZVector(helix.getPerigee())).Rho();
164 double dz = frame.getVertex(ROOT::Math::XYZVector(helix.getPerigee())).Z();
165 if (dr >= 1.0 || fabs(dz) >= 1.0)continue;
166
167 //CDC acceptance as well
168 double costh = dedxTrack->getCosTheta();
169 if (costh < TMath::Cos(150.0 * TMath::DegToRad()))continue;
170 if (costh > TMath::Cos(17.0 * TMath::DegToRad())) continue;
171
172 //clean tracks with relaxed nhit cut
173 double nhits = dedxTrack->getNLayerHits();
174 if (costh > -0.55 && costh < 0.820) {
175 if (nhits < 20)continue;
176 } else {
177 if (costh <= -0.62 || costh >= 0.880) {
178 if (nhits < 8)continue;
179 if (costh > 0 && nhits < 10)continue;
180 } else {
181 if (nhits < 15)continue;
182 }
183 }
184
185 double dedxnosat = dedxTrack->getDedxNoSat();
186 if (dedxnosat < 0)continue;
187
188 double dedx = dedxTrack->getDedx();
189 if (dedx < 0)continue;
190
191 double pCDC = dedxTrack->getMomentum();
192 if (pCDC <= 0) continue;
193
194 double pTrk = fitResult->getMomentum().R();
195 if (pTrk <= 0) continue;
196
197 if (IsBhabhaEvt) {
198 const ECLCluster* eclCluster = track->getRelated<ECLCluster>();
199 if (eclCluster and eclCluster->hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons)) {
200 double TrkEoverP = eclCluster->getEnergy(ECLCluster::EHypothesisBit::c_nPhotons) / pTrk;
201 if (TrkEoverP > 0) {
202 if (std::abs(TrkEoverP - 1.0) > 0.25)continue;
203 }
204 }
205
206 hdEdx->Fill(dedxnosat);
207 double phi = fitResult->getMomentum().Phi();
208 if (hdEdxvsCosth->Integral() <= 80000)hdEdxvsCosth->Fill(costh, dedxnosat);
209 if (hdEdxvsPhi->Integral() <= 80000)hdEdxvsPhi->Fill(phi, dedxnosat);
210
211 if (event >= 150e6)event = 150e6 - 100;
212 event = int(event / 5e5);
213 hdEdxvsEvt->Fill(event, dedxnosat);
214
215 // And check if the stored data is valid and if an injection happened recently
216 if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
217 if (TTDInfo->isHER())
218 hinjtimeHer->Fill(TTDInfo->getTimeSinceLastInjectionInMicroSeconds(), dedxnosat);
219 else
220 hinjtimeLer->Fill(TTDInfo->getTimeSinceLastInjectionInMicroSeconds(), dedxnosat);
221 } else
222 return;
223
224 }
225 if (IsHadronEvt && hdEdxvsP->Integral() <= 80000)hdEdxvsP->Fill(pCDC, dedx);
226
227 if (mmode != "basic") {
228 for (int ihit = 0; ihit < dedxTrack->size(); ++ihit) {
229 int iwire = dedxTrack->getWire(ihit);
230 // cppcheck-suppress variableScope ; kept next to the related declarations for readability
231 double iadc = dedxTrack->getADCCount(ihit);
232 if (m_adc[iwire].size() < 50)m_adc[iwire].push_back(iadc); //just contiung dead
233 }
234 }
235 }
236
237}
238
239//---------------------------------
241{
242
243 hMeta->SetBinContent(1, m_nEvt);
244 hMeta->SetBinContent(2, m_nBEvt);
245 hMeta->SetBinContent(3, m_nHEvt);
246
247 if (hdEdx->GetEntries() > 0) {
248 hdEdx->GetXaxis()->SetRange(hdEdx->FindFirstBinAbove(0, 1), hdEdx->FindLastBinAbove(0, 1));
249 }
250
251 if (hdEdxvsEvt->GetEntries() > 0) {
252 hdEdxvsEvt->GetXaxis()->SetRange(hdEdxvsEvt->FindFirstBinAbove(0, 1), hdEdxvsEvt->FindLastBinAbove(0, 1));
253 }
254
255 if (hinjtimeHer->GetEntries() > 0) {
256 hinjtimeHer->GetXaxis()->SetRange(hinjtimeHer->FindFirstBinAbove(0, 1), hinjtimeHer->FindLastBinAbove(0, 1));
257 }
258 if (hinjtimeLer->GetEntries() > 0) {
259 hinjtimeLer->GetXaxis()->SetRange(hinjtimeLer->FindFirstBinAbove(0, 1), hinjtimeLer->FindLastBinAbove(0, 1));
260 }
261 //get dead wire pattern
262 if (mmode != "basic") plotWireMap();
263}
264
265
266//---------------------------------
268{
269 B2INFO("CDCDedxDQMModule: terminate called");
270}
271
272//------------------------------------
274{
275
276 B2INFO("Creating CDCGeometryPar object");
278
279 int jwire = -1;
280 int nbadwires = 0;
281
282 for (unsigned int ilay = 0; ilay < c_maxNSenseLayers; ++ilay) {
283 for (unsigned int iwire = 0; iwire < cdcgeo.nWiresInLayer(ilay); ++iwire) {
284 jwire++;
285 double phi = 2.*TMath::Pi() * (iwire / double(cdcgeo.nWiresInLayer(ilay)));
286 double radius = cdcgeo.senseWireR(ilay) / 100.;
287 double x = radius * cos(phi);
288 double y = radius * sin(phi);
289 hWires->Fill(x, y);
290 if (m_adc[jwire].size() > 0)continue;
291 nbadwires++;
292 hWireStatus->Fill(x, y);
293 }
294 }
295 hWireStatus->SetTitle(Form("%d", nbadwires));
296}
TH2F * hWireStatus
dead wire status
Definition CDCDedxDQM.h:99
DBObjPtr< CDCDedxRunGain > m_DBRunGain
Run gain DB object.
Definition CDCDedxDQM.h:102
TH2D * hdEdxvsCosth
dedx vs costh
Definition CDCDedxDQM.h:97
virtual void initialize() override
Initialize the module.
Definition CDCDedxDQM.cc:80
TH2D * hdEdxvsP
dedx vs p
Definition CDCDedxDQM.h:95
TH2F * hWires
all wire mapping
Definition CDCDedxDQM.h:100
virtual void event() override
This method is called for each event.
virtual void endRun() override
This method is called at the end of each run.
virtual void terminate() override
End of the event processing.
TH1D * hMeta
metadata
Definition CDCDedxDQM.h:91
StoreObjPtr< EventMetaData > m_MetaDataPtr
Store array for metadata info.
Definition CDCDedxDQM.h:78
virtual void beginRun() override
This method is called for each run.
Definition CDCDedxDQM.cc:95
StoreArray< CDCDedxTrack > m_cdcDedxTracks
Store array for CDCDedxTrack.
Definition CDCDedxDQM.h:80
int m_nEvt
accepted events
Definition CDCDedxDQM.h:83
TH2D * hdEdxvsPhi
dedx vs phi
Definition CDCDedxDQM.h:96
int m_nBEvt
bhabha events
Definition CDCDedxDQM.h:84
std::array< std::vector< double >, c_nSenseWires > m_adc
adc per wire for wire status
Definition CDCDedxDQM.h:87
TH2D * hdEdxvsEvt
dedx vs event
Definition CDCDedxDQM.h:98
int m_nHEvt
hadron events
Definition CDCDedxDQM.h:85
StoreObjPtr< EventLevelTriggerTimeInfo > TTDInfo
Store array for injection time info.
Definition CDCDedxDQM.h:81
CDCDedxDQMModule()
Default constructor.
Definition CDCDedxDQM.cc:28
TH2D * hinjtimeLer
injection time in LER
Definition CDCDedxDQM.h:94
TH2D * hinjtimeHer
injection time in HER
Definition CDCDedxDQM.h:93
void plotWireMap()
function to plot wire status map (all, bad)
std::string mmode
monitoring mode all/basic
Definition CDCDedxDQM.h:89
StoreObjPtr< SoftwareTriggerResult > m_TrgResult
Store array for Trigger selection.
Definition CDCDedxDQM.h:79
virtual void defineHisto() override
Definition of histograms.
Definition CDCDedxDQM.cc:36
Debug output for CDCDedxPID module.
int getADCCount(int i) const
Return the adcCount for this hit.
double getDedx() const
Get dE/dx truncated mean for this track.
int getNLayerHits() const
Return the number of layer hits for this track.
double getCosTheta() const
Return cos(theta) for this track.
int getWire(int i) const
Return the sensor ID for this hit: wire number for CDC (0-14336)
double getDedxNoSat() const
Get dE/dx truncated mean without the saturation correction for this track.
int size() const
Return the number of hits for this track.
double getMomentum() const
Return the track momentum valid in the CDC.
The Class for CDC Geometry Parameters.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
static const ChargedStable pion
charged pion particle
Definition Const.h:662
Class for accessing objects in the database.
Definition DBObjPtr.h:21
ECL cluster data.
Definition ECLCluster.h:27
bool hasHypothesis(EHypothesisBit bitmask) const
Return if specific hypothesis bit is set.
Definition ECLCluster.h:360
double getEnergy(EHypothesisBit hypothesis) const
Return Energy (GeV).
Definition ECLCluster.cc:23
@ c_nPhotons
CR is split into n photons (N1)
Definition ECLCluster.h:41
HistoModule()
Constructor.
Definition HistoModule.h:32
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
static const ReferenceFrame & GetCurrent()
Get current rest frame.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Values of the result of a track fit with a given particle hypothesis.
ROOT::Math::XYZVector getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
UncertainHelix getUncertainHelix() const
Conversion to framework Uncertain Helix (i.e., with covariance).
Class that bundles various TrackFitResults.
Definition Track.h:25
This class represents an ideal helix in perigee parameterization including the covariance matrix of t...
double passiveMoveBy(const ROOT::Math::XYZVector &by)
Moves origin of the coordinate system (passive transformation) by the given vector.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.