Belle II Software  release-05-01-25
CDCDedxSkimModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jake Bennett *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include "reconstruction/modules/CDCDedxSkim/CDCDedxSkimModule.h"
12 
13 #include "framework/datastore/StoreArray.h"
14 
15 #include <mdst/dataobjects/TrackFitResult.h>
16 
17 #include <tracking/dataobjects/RecoTrack.h>
18 
19 #include <cmath>
20 
21 #define mass_e 0.511e-3
22 #define mass_mu 105.658e-3
23 #define mass_pi 139.570e-3
24 #define mass_k 493.677e-3
25 #define mass_p 938.272e-3
26 
27 using namespace Belle2;
28 
29 REG_MODULE(CDCDedxSkim)
30 
32 {
33 
34  setDescription("Apply clean up cuts for dE/dx purposes.");
35 
36  // set default parameters
37  m_eventType = {0, 1};
38  m_EoverP = {0.85, 1.15};
39  m_EccOverEcm = {0.75, 1.15};
40 
41  addParam("eventType", m_eventType,
42  "Event type: (-1) clean up tracks, (0) bhabha, (1) radiative bhabha, (2) two photon (e+e-), (3) di-muon, (4) radiative di-muon (5) D-decays (D*->D0 pi; D0 -> K pi)",
43  m_eventType);
44 
45  addParam("unmatchedCluster", m_unmatchedCluster, "number of unmatched clusters per event", int(0));
46  addParam("EoverP", m_EoverP, "range for E/p per track", m_EoverP);
47  addParam("EccOverEcm", m_EccOverEcm, "ranger for total energy depostied in the calorimeter divided by the cm energy per event",
48  m_EccOverEcm);
49 
50  m_eventID = -1;
51  m_trackID = 0;
52 }
53 
55 
57 {
58 
59  // requred inputs
60  m_tracks.isRequired();
61 }
62 
64 {
65 
66  m_eventID++;
67 
68  // a boolean to toss out bad events
69  bool pass(true);
70 
71  // booleans for individual sample types
72  bool m_Bhabha(false), m_RadBhabha(false), m_TwoPhoton(false);
73  bool m_DiMuon(false), m_RadDiMuon(false);
74  bool m_Base(false);
75 
76  for (unsigned int i = 0; i < m_eventType.size(); i++) {
77  switch (m_eventType[i]) {
78  case 4:
79  m_RadDiMuon = true;
80  break;
81  case 3:
82  m_DiMuon = true;
83  break;
84  case 2:
85  m_TwoPhoton = true;
86  break;
87  case 1:
88  m_RadBhabha = true;
89  break;
90  case 0:
91  m_Bhabha = true;
92  break;
93  case -1:
94  // make sure at least one good track per event
95  m_Base = true;
96  pass = false;
97  break;
98  }
99  }
100 
101  int nGoodElectrons = 0;
102  int nGoodMuons = 0;
103 
104  // loop over each track in the event and cut on track quality information
105  m_trackID = 0;
106  for (int iTrack = 0; iTrack < m_tracks.getEntries(); iTrack++) {
107  const Track* track = m_tracks[iTrack];
108  m_trackID++;
109 
110  // if no type is specified, just clean up based on missing track fits
111  // -> make sure there is at least one good track per event
112  if (m_Base == true && isGoodTrack(track, Const::pion)) {
113  pass = true;
114  break;
115  }
116 
117  // only using the electron hypothesis
118  if (m_Bhabha == true || m_RadBhabha == true || m_TwoPhoton == true) {
119 
120  if (!isGoodTrack(track, Const::electron)) break;
121 
122  const TrackFitResult* fitResult = track->getTrackFitResult(Const::electron);
123  TVector3 trackMom = fitResult->getMomentum();
124  double trackEnergy = sqrt(trackMom.Mag2() + mass_e * mass_e);
125  double EoverP = trackEnergy / trackMom.Mag();
126 
127  // track level cuts
128  if (EoverP < m_EoverP[1] && EoverP > m_EoverP[0])
129  nGoodElectrons++;
130  } // end of bhabha selection
131 
132 
133  // only using the muon hypothesis
134  if (m_DiMuon == true || m_RadDiMuon == true) {
135 
136  if (!isGoodTrack(track, Const::muon)) break;
137 
138  const TrackFitResult* fitResult = track->getTrackFitResult(Const::muon);
139  TVector3 trackMom = fitResult->getMomentum();
140  double trackEnergy = sqrt(trackMom.Mag2() + mass_mu * mass_mu);
141  double EoverP = trackEnergy / trackMom.Mag();
142 
143  // track level cuts
144  if (EoverP < m_EoverP[1] && EoverP > m_EoverP[0])
145  nGoodMuons++;
146  } // end of di-muon selection
147  } // end of loop over tracks
148 
149  if ((m_Bhabha == true || m_RadBhabha == true || m_TwoPhoton == true) && nGoodElectrons != 2)
150  pass = false;
151  if ((m_DiMuon == true || m_RadDiMuon == true) && nGoodMuons != 2)
152  pass = false;
153 
154  setReturnValue(pass);
155 }
156 
157 bool CDCDedxSkimModule::isGoodTrack(const Track* track, const Const::ChargedStable& chargedStable)
158 {
159 
160  // check if the track fit failed
161  const TrackFitResult* fitResult = track->getTrackFitResultWithClosestMass(chargedStable);
162  if (!fitResult) {
163  B2WARNING("No related fit for this track, skipping");
164  return false;
165  }
166 
167  // check if there are (enough) cdc hits for this track
168  RecoTrack* recoTrack = track->getRelatedTo<RecoTrack>();
169  if (!recoTrack || recoTrack->getNumberOfTotalHits() == 0) {
170  B2WARNING("Track has no associated hits, skipping");
171  return false;
172  }
173 
174  // extract some information
175  double trackPVal = fitResult->getPValue();
176  double d0 = fitResult->getD0();
177  double z0 = fitResult->getZ0();
178  int nCDCHits = recoTrack->getNumberOfTotalHits();
179 
180  // apply track quality cuts
181  if (trackPVal < 0.00001 || nCDCHits < 1 || std::abs(d0) <= 0.1 || std::abs(z0) <= 10) {
182  return false;
183  }
184 
185  return true;
186 }
187 
189 {
190 
191  B2INFO("CDCDedxSkimModule exiting after processing " << m_trackID <<
192  " tracks in " << m_eventID + 1 << " events.");
193 }
Belle2::CDCDedxSkimModule::m_EoverP
std::vector< double > m_EoverP
range for E/p per track
Definition: CDCDedxSkimModule.h:85
Belle2::CDCDedxSkimModule::m_trackID
int m_trackID
the track number (for one event)
Definition: CDCDedxSkimModule.h:76
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::Const::electron
static const ChargedStable electron
electron particle
Definition: Const.h:533
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::CDCDedxSkimModule::m_eventID
int m_eventID
the event number
Definition: CDCDedxSkimModule.h:74
Belle2::TrackFitResult::getPValue
double getPValue() const
Getter for Chi2 Probability of the track fit.
Definition: TrackFitResult.h:163
Belle2::CDCDedxSkimModule::isGoodTrack
bool isGoodTrack(const Track *track, const Const::ChargedStable &chargedStable)
A method to check whether a track passes some nominal cuts.
Definition: CDCDedxSkimModule.cc:157
Belle2::TrackFitResult
Values of the result of a track fit with a given particle hypothesis.
Definition: TrackFitResult.h:59
Belle2::CDCDedxSkimModule::terminate
virtual void terminate() override
End of the event processing.
Definition: CDCDedxSkimModule.cc:188
Belle2::TrackFitResult::getZ0
double getZ0() const
Getter for z0.
Definition: TrackFitResult.h:200
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::Const::pion
static const ChargedStable pion
charged pion particle
Definition: Const.h:535
Belle2::CDCDedxSkimModule::initialize
virtual void initialize() override
Initialize routine.
Definition: CDCDedxSkimModule.cc:56
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCDedxSkimModule::event
virtual void event() override
Check the event and track quality and apply clean up cuts.
Definition: CDCDedxSkimModule.cc:63
Belle2::CDCDedxSkimModule
This module may be used to skim a data sample according to a specific set of cuts.
Definition: CDCDedxSkimModule.h:46
Belle2::CDCDedxSkimModule::~CDCDedxSkimModule
virtual ~CDCDedxSkimModule()
Destructor.
Definition: CDCDedxSkimModule.cc:54
Belle2::Module::setReturnValue
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:222
Belle2::RecoTrack::getNumberOfTotalHits
unsigned int getNumberOfTotalHits() const
Return the number of cdc + svd + pxd + bklm + eklm hits.
Definition: RecoTrack.h:432
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::CDCDedxSkimModule::m_eventType
std::vector< int > m_eventType
Event type: (0) bhabha, (1) radiative bhabha, (2) two photon (e+e-), (3) di-muon, (4) radiative di-mu...
Definition: CDCDedxSkimModule.h:80
Belle2::Const::muon
static const ChargedStable muon
muon particle
Definition: Const.h:534
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::CDCDedxSkimModule::m_tracks
StoreArray< Track > m_tracks
Required array of input tracks.
Definition: CDCDedxSkimModule.h:71
Belle2::TrackFitResult::getD0
double getD0() const
Getter for d0.
Definition: TrackFitResult.h:178