Belle II Software  release-05-01-25
CDCDedxElectronCollectorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: jikumar, jvbennett *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <reconstruction/modules/CDCDedxElectronCollector/CDCDedxElectronCollectorModule.h>
12 
13 #include <framework/dataobjects/EventMetaData.h>
14 #include <mdst/dataobjects/ECLCluster.h>
15 
16 #include <TTree.h>
17 #include <TH1D.h>
18 #include <TH1I.h>
19 #include <TMath.h>
20 
21 using namespace Belle2;
22 //-----------------------------------------------------------------
23 // Register the Module
24 //-----------------------------------------------------------------
25 REG_MODULE(CDCDedxElectronCollector)
26 
27 //-----------------------------------------------------------------
28 // Implementation
29 //-----------------------------------------------------------------
31 {
32  // Set module properties
33  setDescription("A collector module for CDC dE/dx electron calibrations");
34 
35  // Parameter definitions
36  addParam("cleanupCuts", m_cuts, "Boolean to apply cleanup cuts", true);
37  addParam("maxNumHits", m_maxNumHits,
38  "Maximum number of hits per track. If there is more than this the track will not be collected. ", int(100));
39  addParam("fSetEoverP", fSetEoverP, "Set E over p Cut values. ", double(0.25));
40  addParam("IsCosth", IsCosth, "true for adding costh tree branch. ", false);
41  addParam("IsMom", IsMom, "true for adding momentum tree branch. ", false);
42  addParam("IsCharge", IsCharge, "true for charge dedx tree branch. ", false);
43  addParam("IsRun", IsRun, "true for adding run number tree branch. ", false);
44  addParam("IsWire", IsWire, "true for adding wires tree branch. ", false);
45  addParam("IsLayer", IsLayer, "true for adding layers tree branch. ", false);
46  addParam("IsDoca", IsDoca, "true for adding doca tree branch. ", false);
47  addParam("IsEnta", IsEnta, "true for adding enta tree branch. ", false);
48  addParam("IsDocaRS", IsDocaRS, "true for adding doca tree branch. ", false);
49  addParam("IsEntaRS", IsEntaRS, "true for adding enta tree branch. ", false);
50  addParam("Isdedxhit", Isdedxhit, "true for adding dedxhit tree branch. ", false);
51  addParam("IsBhabhaEvt", IsBhabhaEvt, "true for bhabha events", true);
52  addParam("IsRadBhabhaEvt", IsRadBhabhaEvt, "true for radee events", false);
53  addParam("enableTrgSel", enableTrgSel, "true to enable trigger sel inside module", false);
54 }
55 
56 //-----------------------------------------------------------------
57 // Create ROOT objects
58 //-----------------------------------------------------------------
59 
61 {
62  m_TrgResult.isOptional();
63  m_dedxTracks.isRequired();
64  m_tracks.isRequired();
65  m_trackFitResults.isRequired();
66 
67  // Data object creation
68  auto means = new TH1D("means", "CDC dE/dx truncated means", 250, 0, 2.5);
69  auto ttree = new TTree("tree", "Tree with dE/dx information");
70 
71  auto hestats = new TH1I("hestats", "Event Stats", 6, -0.5, 5.5);
72  hestats->SetFillColor(kYellow);
73  hestats->GetXaxis()->SetBinLabel(1, "all");
74  hestats->GetXaxis()->SetBinLabel(2, "notrig");
75  hestats->GetXaxis()->SetBinLabel(3, "noskim");
76  hestats->GetXaxis()->SetBinLabel(4, "wrongskim");
77  hestats->GetXaxis()->SetBinLabel(5, "unclean");
78  hestats->GetXaxis()->SetBinLabel(6, "selected");
79 
80  auto htstats = new TH1I("htstats", "track Stats", 7, -0.5, 6.5);
81  htstats->SetFillColor(kYellow);
82  htstats->GetXaxis()->SetBinLabel(1, "alltrk");
83  htstats->GetXaxis()->SetBinLabel(2, "vtx");
84  htstats->GetXaxis()->SetBinLabel(3, "inCDC");
85  htstats->GetXaxis()->SetBinLabel(4, "whits");
86  htstats->GetXaxis()->SetBinLabel(5, "weop");
87  htstats->GetXaxis()->SetBinLabel(6, "radee");
88  htstats->GetXaxis()->SetBinLabel(7, "selected");
89 
90  ttree->Branch<double>("dedx", &m_dedx);
91  if (IsCosth)ttree->Branch<double>("costh", &m_costh);
92  if (IsMom)ttree->Branch<double>("p", &m_p);
93  if (IsCharge)ttree->Branch<int>("charge", &m_charge);
94  if (IsRun)ttree->Branch<int>("run", &m_run);
95 
96  if (IsWire)ttree->Branch("wire", &m_wire);
97  if (IsLayer)ttree->Branch("layer", &m_layer);
98  if (IsDoca)ttree->Branch("doca", &m_doca);
99  if (IsEnta)ttree->Branch("enta", &m_enta);
100  if (IsDocaRS)ttree->Branch("docaRS", &m_docaRS);
101  if (IsEntaRS)ttree->Branch("entaRS", &m_entaRS);
102  if (Isdedxhit)ttree->Branch("dedxhit", &m_dedxhit);
103 
104  // Collector object registration
105  registerObject<TH1D>("means", means);
106  registerObject<TTree>("tree", ttree);
107  registerObject<TH1I>("hestats", hestats);
108  registerObject<TH1I>("htstats", htstats);
109 }
110 
111 //-----------------------------------------------------------------
112 // Fill ROOT objects
113 //-----------------------------------------------------------------
115 {
116 
117  auto hestats = getObjectPtr<TH1I>("hestats");
118  hestats->Fill(0);
119 
120  if (enableTrgSel) {
121  if (!m_TrgResult.isValid()) {
122  B2WARNING("SoftwareTriggerResult required to select bhabha/radee event is not found");
123  hestats->Fill(1);
124  return;
125  }
126 
127  //release05: bhabha_all is grand skim = bhabha+bhabhaecl+radee
128  const std::map<std::string, int>& fresults = m_TrgResult->getResults();
129  if (fresults.find("software_trigger_cut&skim&accept_bhabha") == fresults.end() and
130  fresults.find("software_trigger_cut&skim&accept_radee") == fresults.end()) {
131  B2WARNING("Can't find required bhabha/radee trigger identifiers");
132  hestats->Fill(2);
133  return;
134  }
135 
136  const bool eBhabha = (m_TrgResult->getResult("software_trigger_cut&skim&accept_bhabha") ==
138 
139  const bool eRadBhabha = (m_TrgResult->getResult("software_trigger_cut&skim&accept_radee") ==
141 
142  if (!IsBhabhaEvt && !IsRadBhabhaEvt) {
143  B2WARNING("requested not-supported event type: going back");
144  hestats->Fill(3);
145  return;
146  } else if (IsBhabhaEvt && !IsRadBhabhaEvt && !eBhabha) {
147  B2WARNING("requested bhabha only but event not found: going back");
148  hestats->Fill(3);
149  return;
150  } else if (IsRadBhabhaEvt && !IsBhabhaEvt && !eRadBhabha) {
151  B2WARNING("requested radee only but event not found: going back");
152  hestats->Fill(3);
153  return;
154  }
155  } else {
156  hestats->GetXaxis()->SetBinLabel(2, "inact1");
157  hestats->GetXaxis()->SetBinLabel(3, "inact2");
158  hestats->GetXaxis()->SetBinLabel(4, "inact3");
159  }
160 
161  StoreObjPtr<EventMetaData> eventMetaDataPtr;
162  int run = eventMetaDataPtr->getRun();
163  if (IsRun)m_run = run;
164 
165  int nTracks = m_dedxTracks.getEntries();
166  if (nTracks >= 4) {
167  B2WARNING("too many tracks: unclean bhabha or radee event: " << nTracks);
168  hestats->Fill(4);
169  return;
170  }
171 
172  hestats->Fill(5);
173 
174  //Collector object access
175  auto tree = getObjectPtr<TTree>("tree");
176  auto htstats = getObjectPtr<TH1I>("htstats");
177  auto hmeans = getObjectPtr<TH1D>("means");
178 
179  for (int idedx = 0; idedx < nTracks; idedx++) {
180 
181  CDCDedxTrack* dedxTrack = m_dedxTracks[idedx];
182  if (!dedxTrack) {
183  B2WARNING("No dedx track: Going back: " << idedx);
184  continue;
185  }
186 
187  const Track* track = dedxTrack->getRelatedFrom<Track>();
188  if (!track) {
189  B2WARNING("No track: Going back: " << idedx);
190  continue;
191  }
192 
193  const TrackFitResult* fitResult = track->getTrackFitResultWithClosestMass(Const::pion);
194  if (!fitResult) {
195  B2WARNING("No related fit for this track...");
196  continue;
197  }
198 
199  m_dedx = dedxTrack->getDedxNoSat();
200  m_p = dedxTrack->getMomentum();
201  m_costh = dedxTrack->getCosTheta();
202  m_charge = fitResult->getChargeSign();
203  htstats->Fill(0);
204 
205  if (m_cuts) {
206  // apply cleanup cuts
207  if (fabs(fitResult->getD0()) >= 1.0)continue;
208  if (fabs(fitResult->getZ0()) >= 1.0) continue;
209  htstats->Fill(1);
210 
211  //if outside CDC
212  if (m_costh < TMath::Cos(150.0 * TMath::DegToRad()))continue; //-0.866
213  if (m_costh > TMath::Cos(17.0 * TMath::DegToRad())) continue; //0.95
214  htstats->Fill(2);
215 
216  //making some cuts based on acceptance
217  if (m_costh > -0.55 && m_costh < 0.820) {
218  if (dedxTrack->getNLayerHits() < 25)continue; //all CDC layer available here
219  } else {
220  if (m_costh <= -0.62 || m_costh >= 0.880) {
221  if (dedxTrack->getNLayerHits() < 10)continue; //less layer available here
222  if (m_costh > 0 && dedxTrack->getNLayerHits() < 13)continue;
223  } else {
224  if (dedxTrack->getNLayerHits() < 18)continue;
225  }
226  }
227  htstats->Fill(3);
228 
229  const ECLCluster* eclCluster = track->getRelated<ECLCluster>();
230  if (eclCluster and eclCluster->hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons)) {
231  double TrkEoverP = (eclCluster->getEnergy(ECLCluster::EHypothesisBit::c_nPhotons)) / (fitResult->getMomentum().Mag());
232  if (abs(TrkEoverP - 1.0) > fSetEoverP)continue;
233  }
234  htstats->Fill(4);
235 
236  //if dealing with radee here (do a safe side cleanup)
237  if (IsRadBhabhaEvt) {
238  if (nTracks != 2)continue; //exactly 2 tracks
239  bool goodradee = false;
240  //checking if dedx of other track is restricted
241  //will not do too much as radee is clean enough
242  for (int jdedx = 0; jdedx < nTracks; jdedx++) {
243  CDCDedxTrack* dedxOtherTrack = m_dedxTracks[abs(jdedx - 1)];
244  if (!dedxOtherTrack)continue;
245  if (abs(dedxOtherTrack->getDedxNoSat() - 1.0) > 0.25)continue; //loose for uncalibrated
246  goodradee = true;
247  break;
248  }
249  if (!goodradee)continue;
250  htstats->Fill(5);
251  }
252  }
253 
254 
255  // Make sure to remove all the data in vectors from the previous track
256  if (IsWire)m_wire.clear();
257  if (IsLayer)m_layer.clear();
258  if (IsDoca)m_doca.clear();
259  if (IsEnta)m_enta.clear();
260  if (IsDocaRS)m_docaRS.clear();
261  if (IsEntaRS)m_entaRS.clear();
262  if (Isdedxhit)m_dedxhit.clear();
263 
264  // Simple numbers don't need to be cleared
265  // make sure to use the truncated mean without the hadron saturation correction
266  m_nhits = dedxTrack->size();
267  if (m_nhits > m_maxNumHits) continue;
268 
269  for (int i = 0; i < m_nhits; ++i) {
270  // if (m_DBWireGains->getWireGain(dedxTrack->getWire(i)) == 0)continue;
271  if (IsWire)m_wire.push_back(dedxTrack->getWire(i));
272  if (IsLayer)m_layer.push_back(dedxTrack->getHitLayer(i));
273  if (IsDoca)m_doca.push_back(dedxTrack->getDoca(i));
274  if (IsEnta)m_enta.push_back(dedxTrack->getEnta(i));
275  if (IsDocaRS)m_docaRS.push_back(dedxTrack->getDocaRS(i) / dedxTrack->getCellHalfWidth(i));
276  if (IsEntaRS)m_entaRS.push_back(dedxTrack->getEntaRS(i));
277  if (Isdedxhit)m_dedxhit.push_back(dedxTrack->getDedx(i));
278  }
279 
280  // Track and/or hit information filled as per config
281  htstats->Fill(6);
282  hmeans->Fill(m_dedx);
283  tree->Fill();
284  }
285 }
Belle2::CalibrationCollectorModule
Calibration collector module base class.
Definition: CalibrationCollectorModule.h:44
Belle2::CDCDedxTrack::getDedxNoSat
double getDedxNoSat() const
Get dE/dx truncated mean without the saturation correction for this track.
Definition: CDCDedxTrack.h:117
Belle2::CDCDedxTrack::getHitLayer
int getHitLayer(int i) const
Return the (global) layer number for a hit.
Definition: CDCDedxTrack.h:205
Belle2::CDCDedxElectronCollectorModule::m_dedx
double m_dedx
track level information
Definition: CDCDedxElectronCollectorModule.h:83
Belle2::CDCDedxElectronCollectorModule::IsCharge
bool IsCharge
flag to write charge in treet
Definition: CDCDedxElectronCollectorModule.h:102
Belle2::CDCDedxElectronCollectorModule::m_nhits
int m_nhits
number of dE/dx hits on the track
Definition: CDCDedxElectronCollectorModule.h:88
Belle2::CDCDedxElectronCollectorModule::IsEntaRS
bool IsEntaRS
flag to write rescaled enta in tree
Definition: CDCDedxElectronCollectorModule.h:109
Belle2::CDCDedxTrack::getDedx
double getDedx() const
Get dE/dx truncated mean for this track.
Definition: CDCDedxTrack.h:114
Belle2::CDCDedxTrack::getEntaRS
double getEntaRS(int i) const
Return rescaled enta value for cell height=width assumption.
Definition: CDCDedxTrack.h:232
Belle2::TrackFitResult::getMomentum
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Definition: TrackFitResult.h:116
Belle2::ECLCluster
ECL cluster data.
Definition: ECLCluster.h:39
Belle2::CDCDedxTrack::getWire
int getWire(int i) const
Return the sensor ID for this hit: wire number for CDC (0-14336)
Definition: CDCDedxTrack.h:202
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::CDCDedxElectronCollectorModule::m_trackFitResults
StoreArray< TrackFitResult > m_trackFitResults
Required array for TrackFitResults.
Definition: CDCDedxElectronCollectorModule.h:76
Belle2::CDCDedxTrack::getMomentum
double getMomentum() const
Return the track momentum valid in the CDC.
Definition: CDCDedxTrack.h:129
Belle2::CDCDedxElectronCollectorModule::m_entaRS
std::vector< double > m_entaRS
rescaled entrance angle for the hit
Definition: CDCDedxElectronCollectorModule.h:96
Belle2::CDCDedxElectronCollectorModule::m_charge
int m_charge
track momentum
Definition: CDCDedxElectronCollectorModule.h:86
Belle2::ECLCluster::EHypothesisBit::c_nPhotons
@ c_nPhotons
CR is split into n photons (N1)
Belle2::CDCDedxElectronCollectorModule::IsDocaRS
bool IsDocaRS
flag to write rescaled doca in tree
Definition: CDCDedxElectronCollectorModule.h:108
Belle2::CDCDedxElectronCollectorModule::m_doca
std::vector< double > m_doca
distance of closest approach for the hit
Definition: CDCDedxElectronCollectorModule.h:93
Belle2::CDCDedxElectronCollectorModule
A collector module for CDC dE/dx electron calibrations.
Definition: CDCDedxElectronCollectorModule.h:41
Belle2::ECLCluster::hasHypothesis
bool hasHypothesis(EHypothesisBit bitmask) const
Return if specific hypothesis bit is set.
Definition: ECLCluster.h:374
Belle2::CDCDedxTrack::getEnta
double getEnta(int i) const
Return the entrance angle in the CDC cell for this hit.
Definition: CDCDedxTrack.h:226
Belle2::CDCDedxTrack::size
int size() const
Return the number of hits for this track.
Definition: CDCDedxTrack.h:196
Belle2::TrackFitResult
Values of the result of a track fit with a given particle hypothesis.
Definition: TrackFitResult.h:59
Belle2::CDCDedxElectronCollectorModule::IsBhabhaEvt
bool IsBhabhaEvt
flag to select bhabha event
Definition: CDCDedxElectronCollectorModule.h:111
Belle2::CDCDedxElectronCollectorModule::m_docaRS
std::vector< double > m_docaRS
rescaled distance of closest approach for the hit
Definition: CDCDedxElectronCollectorModule.h:95
Belle2::SoftwareTriggerCutResult::c_accept
@ c_accept
Accept this event.
Belle2::CDCDedxElectronCollectorModule::IsEnta
bool IsEnta
flag to write enta in tree
Definition: CDCDedxElectronCollectorModule.h:107
Belle2::CDCDedxElectronCollectorModule::m_dedxTracks
StoreArray< CDCDedxTrack > m_dedxTracks
Required array for CDCDedxTracks.
Definition: CDCDedxElectronCollectorModule.h:74
Belle2::TrackFitResult::getZ0
double getZ0() const
Getter for z0.
Definition: TrackFitResult.h:200
Belle2::CDCDedxElectronCollectorModule::IsWire
bool IsWire
flag to write wire number in tree
Definition: CDCDedxElectronCollectorModule.h:104
Belle2::ECLCluster::getEnergy
double getEnergy(const EHypothesisBit &hypothesis) const
Return Energy (GeV).
Definition: ECLCluster.cc:21
Belle2::CDCDedxElectronCollectorModule::m_costh
double m_costh
track cos(theta)
Definition: CDCDedxElectronCollectorModule.h:84
Belle2::CDCDedxElectronCollectorModule::m_wire
std::vector< int > m_wire
hit level information
Definition: CDCDedxElectronCollectorModule.h:91
Belle2::Const::pion
static const ChargedStable pion
charged pion particle
Definition: Const.h:535
Belle2::CDCDedxElectronCollectorModule::m_run
int m_run
run number
Definition: CDCDedxElectronCollectorModule.h:87
Belle2::CDCDedxElectronCollectorModule::IsRadBhabhaEvt
bool IsRadBhabhaEvt
flag to select radee event
Definition: CDCDedxElectronCollectorModule.h:112
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::CDCDedxElectronCollectorModule::m_cuts
bool m_cuts
Electron collector variables.
Definition: CDCDedxElectronCollectorModule.h:70
Belle2::CDCDedxTrack::getDoca
double getDoca(int i) const
Return the distance of closest approach to the sense wire for this hit.
Definition: CDCDedxTrack.h:223
Belle2::CDCDedxElectronCollectorModule::m_dedxhit
std::vector< double > m_dedxhit
dE/dx for the hit
Definition: CDCDedxElectronCollectorModule.h:97
Belle2::CDCDedxElectronCollectorModule::fSetEoverP
double fSetEoverP
Cut of E over P value.
Definition: CDCDedxElectronCollectorModule.h:81
Belle2::CDCDedxElectronCollectorModule::prepare
virtual void prepare() override
Create and book ROOT objects.
Definition: CDCDedxElectronCollectorModule.cc:60
Belle2::CDCDedxTrack::getCellHalfWidth
double getCellHalfWidth(int i) const
Return the half-width of the CDC cell.
Definition: CDCDedxTrack.h:244
Belle2::CDCDedxElectronCollectorModule::IsMom
bool IsMom
flag to write momentum in treet
Definition: CDCDedxElectronCollectorModule.h:101
Belle2::CDCDedxElectronCollectorModule::IsRun
bool IsRun
flag to write run number in tree
Definition: CDCDedxElectronCollectorModule.h:103
Belle2::CDCDedxElectronCollectorModule::Isdedxhit
bool Isdedxhit
flag to write dedxhits in tree
Definition: CDCDedxElectronCollectorModule.h:110
Belle2::CDCDedxElectronCollectorModule::m_enta
std::vector< double > m_enta
entrance angle for the hit
Definition: CDCDedxElectronCollectorModule.h:94
Belle2::CDCDedxElectronCollectorModule::IsLayer
bool IsLayer
flag to write layer number in tree
Definition: CDCDedxElectronCollectorModule.h:105
Belle2::CDCDedxTrack::getCosTheta
double getCosTheta() const
Return cos(theta) for this track.
Definition: CDCDedxTrack.h:132
Belle2::CDCDedxElectronCollectorModule::IsDoca
bool IsDoca
flag to write doca in tree
Definition: CDCDedxElectronCollectorModule.h:106
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::CDCDedxElectronCollectorModule::m_tracks
StoreArray< Track > m_tracks
Required array for Tracks.
Definition: CDCDedxElectronCollectorModule.h:75
Belle2::CDCDedxElectronCollectorModule::m_layer
std::vector< int > m_layer
continuous layer number for the hit
Definition: CDCDedxElectronCollectorModule.h:92
Belle2::CDCDedxTrack
Debug output for CDCDedxPID module.
Definition: CDCDedxTrack.h:36
Belle2::CDCDedxTrack::getNLayerHits
int getNLayerHits() const
Return the number of layer hits for this track.
Definition: CDCDedxTrack.h:170
Belle2::CDCDedxElectronCollectorModule::IsCosth
bool IsCosth
flag to write costh in tree
Definition: CDCDedxElectronCollectorModule.h:100
Belle2::CDCDedxElectronCollectorModule::collect
virtual void collect() override
Fill ROOT objects.
Definition: CDCDedxElectronCollectorModule.cc:114
Belle2::CDCDedxElectronCollectorModule::m_p
double m_p
track momentum
Definition: CDCDedxElectronCollectorModule.h:85
Belle2::CDCDedxTrack::getDocaRS
double getDocaRS(int i) const
Return rescaled doca value for cell height=width assumption.
Definition: CDCDedxTrack.h:229
Belle2::TrackFitResult::getChargeSign
short getChargeSign() const
Return track charge (1 or -1).
Definition: TrackFitResult.h:160
Belle2::RelationsInterface::getRelatedFrom
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Definition: RelationsObject.h:265
Belle2::CDCDedxElectronCollectorModule::enableTrgSel
bool enableTrgSel
flag to enable trigger skim selected in the module (off deafult)
Definition: CDCDedxElectronCollectorModule.h:113
Belle2::TrackFitResult::getD0
double getD0() const
Getter for d0.
Definition: TrackFitResult.h:178
Belle2::CDCDedxElectronCollectorModule::m_maxNumHits
int m_maxNumHits
module params
Definition: CDCDedxElectronCollectorModule.h:80
Belle2::CDCDedxElectronCollectorModule::m_TrgResult
StoreObjPtr< SoftwareTriggerResult > m_TrgResult
required input
Definition: CDCDedxElectronCollectorModule.h:73