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
21using namespace Belle2;
22
23REG_MODULE(CDCDedxDQM);
24
25//---------------------------------
27{
28 setPropertyFlags(c_ParallelProcessingCertified); // parallel processing
29 setDescription("CDC dE/dx DQM plots with bhabha/hadron events.");
30 addParam("mmode", mmode, "default monitoring mode is basic", std::string("basic"));
31}
32
33//---------------------------------
35{
36
37 TDirectory* oldDir = gDirectory;
38 oldDir->mkdir("CDCDedx");
39 oldDir->cd("CDCDedx");
40
41 int expNum = -1;
42 int runNum = -1;
43 double rungain = -99.0;
44
45 if (m_MetaDataPtr) {
46 expNum = int(m_MetaDataPtr->getExperiment());
47 runNum = int(m_MetaDataPtr->getRun());
48 if (m_DBRunGain) rungain = m_DBRunGain->getRunGain();
49 }
50
51 hMeta = new TH1D("hMeta", "hMeta", 3, 0.5, 3.5);
52 hMeta->GetXaxis()->SetTitle("Quantity");
53 hMeta->GetYaxis()->SetTitle("Values");
54 hMeta->SetTitle(Form("(Exp:%d, Run:%d, RG:%0.03f)", expNum, runNum, rungain));
55 hMeta->GetXaxis()->SetBinLabel(1, "nevt");
56 hMeta->GetXaxis()->SetBinLabel(2, "nbhabha");
57 hMeta->GetXaxis()->SetBinLabel(3, "nhadron");
58
59 hdEdx = new TH1D("hdEdx", ";CDC dE/dx;Entries", 100, 0., 2.5);
60 hinjtimeHer = new TH2D("hinjtimeHer", ";injection time (#mu s); CDC dE/dx", 40, 0, 80e3, 50, 0, 2.5);
61 hinjtimeLer = new TH2D("hinjtimeLer", ";injection time (#mu s); CDC dE/dx", 40, 0, 80e3, 50, 0, 2.5);
62 hdEdxvsP = new TH2D("hdEdxVsP", ";#it{p}_{CDC} (GeV/c);CDC dE/dx", 100, 0.05, 2.50, 100, 0.35, 10.0);
63 hdEdxvsEvt = new TH2D("hdEdxvsEvt", ";Events(M);CDC dE/dx", 50, 0, 200, 50, 0.00, 2.0);
64 hdEdxvsCosth = new TH2D("hdEdxvsCosth", ";cos#theta (e^{-}e^{+} tracks);CDC dE/dx", 50, -1.00, 1.00, 50, 0.00, 2.5);
65 hdEdxvsPhi = new TH2D("hdEdxvsPhi", ";#phi (e^{-}e^{+} tracks);CDC dE/dx", 50, -3.20, 3.20, 50, 0.00, 2.5);
66 if (mmode != "basic") {
67 hWires = new TH2F("hWires", "All Wires;", 2400, -1.2, 1.2, 2400, -1.2, 1.2);
68 hWires->GetXaxis()->SetTitle("CDC-wire map: counter-clockwise and start from +x");
69 hWireStatus = new TH2F("hWireStatus", "Wire Status", 2400, -1.2, 1.2, 2400, -1.2, 1.2);
70 hWireStatus->GetXaxis()->SetTitle("CDC-wire map: counter-clockwise and start from +x");
71 }
72 oldDir->cd();
73
74}
75
76
77//---------------------------------
79{
80
81 if (!m_cdcDedxTracks.isOptional()) {
82 B2WARNING("Missing CDCDedxTracks array, CDCDedxDQM is skipped.");
83 return;
84 }
85
86 m_TrgResult.isOptional();
87 m_cdcDedxTracks.isRequired();
88 REG_HISTOGRAM
89
90}
91
92//-------------------------------
94{
95
96 if (!m_cdcDedxTracks.isOptional()) {
97 B2WARNING("Missing CDCDedxTracks array, CDCDedxDQM is skipped.");
98 return;
99 }
100
101 hMeta->Reset();
102 hdEdx->Reset();
103 hinjtimeHer->Reset();
104 hinjtimeLer->Reset();
105 hdEdxvsP->Reset();
106 hdEdxvsCosth->Reset();
107 hdEdxvsPhi->Reset();
108 hdEdxvsEvt->Reset();
109 if (mmode != "basic") {
110 hWires->Reset();
111 hWireStatus->Reset();
112 }
113}
114
115
116//----------------------------
118{
119
120 if (!m_cdcDedxTracks.isOptional()) return;
121
122 if (!m_TrgResult.isValid()) {
123 B2WARNING("Required SoftwareTriggerResult object not available: CDCDedxDQM is skipped");
124 return;
125 }
126
127 const std::map<std::string, int>& fresults = m_TrgResult->getResults();
128 if (fresults.find("software_trigger_cut&skim&accept_bhabha") == fresults.end()
129 and fresults.find("software_trigger_cut&skim&accept_hadron") == fresults.end())return;
130
131 const bool IsBhabhaEvt = (m_TrgResult->getResult("software_trigger_cut&skim&accept_bhabha") ==
133 const bool IsHadronEvt = (m_TrgResult->getResult("software_trigger_cut&skim&accept_hadron") ==
135
136 m_nEvt += 1;
137 if (!IsBhabhaEvt and !IsHadronEvt)return;
138 if (IsBhabhaEvt)m_nBEvt += 1;
139 if (IsHadronEvt)m_nHEvt += 1;
140
141 //Get current evt number
142 int event = -1;
143
144 if (m_MetaDataPtr)event = int(m_MetaDataPtr->getEvent());
145
146 for (int idedx = 0; idedx < m_cdcDedxTracks.getEntries(); idedx++) {
147
148 CDCDedxTrack* dedxTrack = m_cdcDedxTracks[idedx];
149 if (!dedxTrack || dedxTrack->size() == 0)continue;
150
151 const Track* track = dedxTrack->getRelatedFrom<Track>();
152 if (!track)continue;
153
154 const TrackFitResult* fitResult = track->getTrackFitResultWithClosestMass(Const::pion);
155 if (!fitResult)continue;
156
157 UncertainHelix helix = fitResult->getUncertainHelix();
158 static DBObjPtr<BeamSpot> beamSpotDB;
159 helix.passiveMoveBy(ROOT::Math::XYZVector(beamSpotDB->getIPPosition()));
160 const auto& frame = ReferenceFrame::GetCurrent();
161 double dr = frame.getVertex(ROOT::Math::XYZVector(helix.getPerigee())).Rho();
162 double dz = frame.getVertex(ROOT::Math::XYZVector(helix.getPerigee())).Z();
163 if (dr >= 1.0 || fabs(dz) >= 1.0)continue;
164
165 //CDC acceptance as well
166 double costh = dedxTrack->getCosTheta();
167 if (costh < TMath::Cos(150.0 * TMath::DegToRad()))continue;
168 if (costh > TMath::Cos(17.0 * TMath::DegToRad())) continue;
169
170 //clean tracks with relaxed nhit cut
171 double nhits = dedxTrack->getNLayerHits();
172 if (costh > -0.55 && costh < 0.820) {
173 if (nhits < 20)continue;
174 } else {
175 if (costh <= -0.62 || costh >= 0.880) {
176 if (nhits < 8)continue;
177 if (costh > 0 && nhits < 10)continue;
178 } else {
179 if (nhits < 15)continue;
180 }
181 }
182
183 double dedxnosat = dedxTrack->getDedxNoSat();
184 if (dedxnosat < 0)continue;
185
186 double dedx = dedxTrack->getDedx();
187 if (dedx < 0)continue;
188
189 double pCDC = dedxTrack->getMomentum();
190 if (pCDC <= 0) continue;
191
192 double pTrk = fitResult->getMomentum().R();
193 if (pTrk <= 0) continue;
194
195 if (IsBhabhaEvt) {
196 const ECLCluster* eclCluster = track->getRelated<ECLCluster>();
197 if (eclCluster and eclCluster->hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons)) {
198 double TrkEoverP = eclCluster->getEnergy(ECLCluster::EHypothesisBit::c_nPhotons) / pTrk;
199 if (TrkEoverP > 0) {
200 if (abs(TrkEoverP - 1.0) > 0.25)continue;
201 }
202 }
203
204 hdEdx->Fill(dedxnosat);
205 double phi = fitResult->getMomentum().Phi();
206 if (hdEdxvsCosth->Integral() <= 80000)hdEdxvsCosth->Fill(costh, dedxnosat);
207 if (hdEdxvsPhi->Integral() <= 80000)hdEdxvsPhi->Fill(phi, dedxnosat);
208
209 if (event >= 150e6)event = 150e6 - 100;
210 event = int(event / 5e5);
211 hdEdxvsEvt->Fill(event, dedxnosat);
212
213 // And check if the stored data is valid and if an injection happened recently
214 if (TTDInfo->isValid() && TTDInfo->hasInjection()) {
215 if (TTDInfo->isHER())
216 hinjtimeHer->Fill(TTDInfo->getTimeSinceLastInjectionInMicroSeconds(), dedxnosat);
217 else
218 hinjtimeLer->Fill(TTDInfo->getTimeSinceLastInjectionInMicroSeconds(), dedxnosat);
219 } else
220 return;
221
222 }
223 if (IsHadronEvt && hdEdxvsP->Integral() <= 80000)hdEdxvsP->Fill(pCDC, dedx);
224
225 if (mmode != "basic") {
226 for (int ihit = 0; ihit < dedxTrack->size(); ++ihit) {
227 int iwire = dedxTrack->getWire(ihit);
228 double iadc = dedxTrack->getADCCount(ihit);
229 if (m_adc[iwire].size() < 50)m_adc[iwire].push_back(iadc); //just contiung dead
230 }
231 }
232 }
233
234}
235
236//---------------------------------
238{
239
240 hMeta->SetBinContent(1, m_nEvt);
241 hMeta->SetBinContent(2, m_nBEvt);
242 hMeta->SetBinContent(3, m_nHEvt);
243
244 if (hdEdx->GetEntries() > 0) {
245 hdEdx->GetXaxis()->SetRange(hdEdx->FindFirstBinAbove(0, 1), hdEdx->FindLastBinAbove(0, 1));
246 }
247
248 if (hdEdxvsEvt->GetEntries() > 0) {
249 hdEdxvsEvt->GetXaxis()->SetRange(hdEdxvsEvt->FindFirstBinAbove(0, 1), hdEdxvsEvt->FindLastBinAbove(0, 1));
250 }
251
252 if (hinjtimeHer->GetEntries() > 0) {
253 hinjtimeHer->GetXaxis()->SetRange(hinjtimeHer->FindFirstBinAbove(0, 1), hinjtimeHer->FindLastBinAbove(0, 1));
254 }
255 if (hinjtimeLer->GetEntries() > 0) {
256 hinjtimeLer->GetXaxis()->SetRange(hinjtimeLer->FindFirstBinAbove(0, 1), hinjtimeLer->FindLastBinAbove(0, 1));
257 }
258 //get dead wire pattern
259 if (mmode != "basic") plotWireMap();
260}
261
262
263//---------------------------------
265{
266 B2INFO("CDCDedxDQMModule: terminate called");
267}
268
269//------------------------------------
271{
272
273 B2INFO("Creating CDCGeometryPar object");
275
276 int jwire = -1;
277 int nbadwires = 0;
278
279 for (unsigned int ilay = 0; ilay < c_maxNSenseLayers; ++ilay) {
280 for (unsigned int iwire = 0; iwire < cdcgeo.nWiresInLayer(ilay); ++iwire) {
281 jwire++;
282 double phi = 2.*TMath::Pi() * (iwire / double(cdcgeo.nWiresInLayer(ilay)));
283 double radius = cdcgeo.senseWireR(ilay) / 100.;
284 double x = radius * cos(phi);
285 double y = radius * sin(phi);
286 hWires->Fill(x, y);
287 if (m_adc[jwire].size() > 0)continue;
288 nbadwires++;
289 hWireStatus->Fill(x, y);
290 }
291 }
292 hWireStatus->SetTitle(Form("%d", nbadwires));
293}
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:78
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:93
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:26
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:34
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:661
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:351
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.