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