Belle II Software  release-05-02-19
TrackFilterModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Giulia Casarosa *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/modules/trackFilter/TrackFilterModule.h>
12 #include <mdst/dataobjects/TrackFitResult.h>
13 #include <mdst/dataobjects/HitPatternVXD.h>
14 #include <mdst/dataobjects/HitPatternCDC.h>
15 #include <framework/datastore/StoreArray.h>
16 
17 using namespace Belle2;
18 
19 double TrackFilterModule::m_min_d0 = -100;
20 double TrackFilterModule::m_max_d0 = +100;
21 double TrackFilterModule::m_min_z0 = -500;
22 double TrackFilterModule::m_max_z0 = +500;
29 
31 
32 TNtuple* TrackFilterModule::m_selectedNtpl = NULL;
33 TNtuple* TrackFilterModule::m_rejectedNtpl = NULL;
34 
35 //-----------------------------------------------------------------
36 // Register the Module
37 //-----------------------------------------------------------------
38 REG_MODULE(TrackFilter)
39 
40 //-----------------------------------------------------------------
41 // Implementation
42 //-----------------------------------------------------------------
43 
45 {
46  // Set module properties
47  setDescription("generates a new StoreArray from the input StoreArray which has all specified Tracks removed");
48 
49  // Parameter definitions
50  addParam("inputArrayName", m_inputArrayName, "StoreArray with the input tracks", std::string("Tracks"));
51  addParam("outputINArrayName", m_outputINArrayName, "StoreArray with the output tracks", std::string(""));
52  addParam("outputOUTArrayName", m_outputOUTArrayName, "StoreArray with the output tracks", std::string(""));
53 
54  //selection parameter definition
55  addParam("min_d0", m_min_d0, "minimum value of the d0", double(-100));
56  addParam("max_d0", m_max_d0, "maximum value of the d0", double(+100));
57  addParam("min_z0", m_min_z0, "minimum value of the z0", double(-500));
58  addParam("max_z0", m_max_z0, "maximum value of the z0", double(+500));
59  addParam("min_pCM", m_min_pCM, "minimum value of the center-of-mass-momentum", double(0));
60  addParam("min_pT", m_min_pT, "minimum value of the transverse momentum", double(0));
61  addParam("min_Pvalue", m_min_Pval, "minimum value of the P-Value of the track fit", double(0));
62  addParam("min_NumHitPXD", m_min_NumHitsPXD, "minimum number of PXD hits associated to the trcak", int(0));
63  addParam("min_NumHitSVD", m_min_NumHitsSVD, "minimum number of SVD hits associated to the trcak", int(0));
64  addParam("min_NumHitCDC", m_min_NumHitsCDC, "minimum number of CDC hits associated to the trcak", int(0));
65 
66  addParam("saveControNtuples", m_saveControlNtuples, "if true, generate a rootfile containing histograms ", bool(true));
67  addParam("outputFileName", m_rootFileName, "Name of output root file.",
68  std::string("TrackFilterControlNtuples.root"));
69 
70 }
71 
72 
74 {
75 
76  B2INFO("TrackFilterModule::inputArrayName: " << m_inputArrayName);
77  B2INFO("TrackFilterModule::outputINArrayName: " << m_outputINArrayName);
78  B2INFO("TrackFilterModule::outputOUTArrayName: " << m_outputOUTArrayName);
79 
80 
82  inputArray.isRequired();
83 
84  m_selectedTracks.registerSubset(inputArray, m_outputINArrayName);
85  m_selectedTracks.inheritAllRelations();
86 
87  m_notSelectedTracks.registerSubset(inputArray, m_outputOUTArrayName);
88  m_notSelectedTracks.inheritAllRelations();
89 
91  //set the ROOT File
92  m_rootFilePtr = new TFile(m_rootFileName.c_str(), "RECREATE");
93  m_selectedNtpl = new TNtuple("selected", "Selected Tracks", "d0:z0:phi:tanDip:omega:pT:pCM:nPXD:nSVD:nCDC:pVal");
94  m_rejectedNtpl = new TNtuple("rejected", "Rejected Tracks", "d0:z0:phi:tanDip:omega:pT:pCM:nPXD:nSVD:nCDC:pVal");
95  }
96 
97 
98 }
99 
100 
101 
103 {
104 
106 
107  m_notSelectedTracks.select([](const Track * track) {
108  return !isSelected(track);
109  }
110  );
111 
112 }
113 
115 {
116  if (m_rootFilePtr != nullptr) {
117  m_rootFilePtr->cd();
118 
119  m_selectedNtpl->Write();
120  m_rejectedNtpl->Write();
121 
122  m_rootFilePtr->Close();
123 
124  }
125 }
126 
128 {
129 
130  bool isExcluded = false;
131  int pionCode = 211;
132 
133  const TrackFitResult* tfr = track->getTrackFitResult(Const::ChargedStable(pionCode));
134  if (tfr == NULL)
135  return false;
136 
137  if (tfr->getD0() < m_min_d0 || tfr->getD0() > m_max_d0)
138  isExcluded = true;
139 
140  if (tfr->getZ0() < m_min_z0 || tfr->getZ0() > m_max_z0)
141  isExcluded = true;
142 
143  if (tfr->getPValue() < m_min_Pval)
144  isExcluded = true;
145 
146  if (tfr->getMomentum().Perp() < m_min_pT)
147  isExcluded = true;
148 
149  HitPatternVXD hitPatternVXD = tfr->getHitPatternVXD();
150  if (hitPatternVXD.getNSVDHits() < m_min_NumHitsSVD || hitPatternVXD.getNPXDHits() < m_min_NumHitsPXD)
151  isExcluded = true;
152 
153  HitPatternCDC hitPatternCDC = tfr->getHitPatternCDC();
154  if (hitPatternCDC.getNHits() < m_min_NumHitsCDC)
155  isExcluded = true;
156 
158  fillControlNtuples(track, !isExcluded);
159 
160 
161  return !isExcluded;
162 
163 }
164 
165 void TrackFilterModule::fillControlNtuples(const Track* track , bool isSelected)
166 {
167 
168  int pionCode = 211;
169  const TrackFitResult* tfr = track->getTrackFitResult(Const::ChargedStable(pionCode));
170  HitPatternVXD hitPatternVXD = tfr->getHitPatternVXD();
171  HitPatternCDC hitPatternCDC = tfr->getHitPatternCDC();
172 
173  double d0 = tfr->getD0();
174  double z0 = tfr->getZ0();
175  float phi = tfr->getPhi();
176  float tanDip = tfr->getTanLambda();
177  float omega = tfr->getOmega();
178 
179  double pt = tfr->getMomentum().Pt();
180  TLorentzVector pStar = tfr->get4Momentum();
181  pStar.Boost(0, 0, 3. / 11);
182  double pCM = pStar.P();
183  double pVal = tfr->getPValue();
184  int nPXDhits = hitPatternVXD.getNPXDHits();
185  int nSVDhits = hitPatternVXD.getNSVDHits();
186  int nCDChits = hitPatternCDC.getNHits();
187 
188  float nPXD = nPXDhits;
189  float nSVD = nSVDhits;
190  float nCDC = nCDChits;
191 
192  if (isSelected)
193  m_selectedNtpl->Fill(d0, z0, phi, tanDip, omega, pt, pCM, nPXD, nSVD, nCDC, pVal);
194  else
195  m_rejectedNtpl->Fill(d0, z0, phi, tanDip, omega, pt, pCM, nPXD, nSVD, nCDC, pVal);
196 
197 
198 }
Belle2::TrackFilterModule::terminate
virtual void terminate() override
terminates the module
Definition: TrackFilterModule.cc:114
Belle2::TrackFilterModule::m_min_Pval
static double m_min_Pval
miminum P-value of the track fit
Definition: TrackFilterModule.h:66
Belle2::TrackFitResult::get4Momentum
TLorentzVector get4Momentum() const
Getter for the 4Momentum at the closest approach of the track in the r/phi projection.
Definition: TrackFitResult.h:125
Belle2::TrackFilterModule::isSelected
static bool isSelected(const Track *track)
determine if the track satisfies the selection criteria
Definition: TrackFilterModule.cc:127
Belle2::TrackFilterModule::m_rejectedNtpl
static TNtuple * m_rejectedNtpl
tuple of rejected tracks
Definition: TrackFilterModule.h:87
Belle2::HitPatternVXD::getNPXDHits
unsigned short getNPXDHits() const
Get total number of hits in the PXD.
Definition: HitPatternVXD.cc:147
Belle2::TrackFilterModule::fillControlNtuples
static void fillControlNtuples(const Track *track, bool isSelected)
determine if the track does not satisfies the selection criteria
Definition: TrackFilterModule.cc:165
Belle2::TrackFitResult::getMomentum
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Definition: TrackFitResult.h:116
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::TrackFilterModule::m_saveControlNtuples
static bool m_saveControlNtuples
if true produces a rootfile with control ntupled
Definition: TrackFilterModule.h:68
Belle2::TrackFilterModule::m_min_pCM
static double m_min_pCM
miminum value of the center of mass momentum
Definition: TrackFilterModule.h:64
Belle2::TrackFitResult::getOmega
double getOmega() const
Getter for omega.
Definition: TrackFitResult.h:194
Belle2::TrackFitResult::getPValue
double getPValue() const
Getter for Chi2 Probability of the track fit.
Definition: TrackFitResult.h:163
Belle2::TrackFitResult::getTanLambda
double getTanLambda() const
Getter for tanLambda.
Definition: TrackFitResult.h:206
Belle2::TrackFilterModule::m_rootFilePtr
TFile * m_rootFilePtr
pointer at root file used for storing ntuples
Definition: TrackFilterModule.h:70
Belle2::TrackFilterModule::m_max_z0
static double m_max_z0
z0 maximum value
Definition: TrackFilterModule.h:60
Belle2::TrackFitResult
Values of the result of a track fit with a given particle hypothesis.
Definition: TrackFitResult.h:59
Belle2::TrackFilterModule::m_min_NumHitsPXD
static int m_min_NumHitsPXD
miminum value of PXD hits
Definition: TrackFilterModule.h:61
Belle2::TrackFilterModule::m_selectedTracks
SelectSubset< Track > m_selectedTracks
selected tracks
Definition: TrackFilterModule.h:78
Belle2::TrackFitResult::getHitPatternCDC
HitPatternCDC getHitPatternCDC() const
Getter for the hit pattern in the CDC;.
Definition: TrackFitResult.cc:120
Belle2::TrackFitResult::getZ0
double getZ0() const
Getter for z0.
Definition: TrackFitResult.h:200
Belle2::TrackFilterModule::initialize
virtual void initialize() override
init the module
Definition: TrackFilterModule.cc:73
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::TrackFilterModule::m_inputArrayName
std::string m_inputArrayName
StoreArray with the input tracks.
Definition: TrackFilterModule.h:74
Belle2::TrackFilterModule::m_min_z0
static double m_min_z0
z0 miminum value
Definition: TrackFilterModule.h:59
Belle2::TrackFilterModule::m_notSelectedTracks
SelectSubset< Track > m_notSelectedTracks
not selected tracks
Definition: TrackFilterModule.h:79
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFilterModule::event
virtual void event() override
processes the event
Definition: TrackFilterModule.cc:102
Belle2::TrackFilterModule::m_rootFileName
std::string m_rootFileName
root file name
Definition: TrackFilterModule.h:69
Belle2::TrackFilterModule::m_outputOUTArrayName
std::string m_outputOUTArrayName
StoreArray with the NOT selected output tracks.
Definition: TrackFilterModule.h:76
Belle2::TrackFilterModule::m_min_d0
static double m_min_d0
d0 miminum value
Definition: TrackFilterModule.h:57
Belle2::TrackFitResult::getHitPatternVXD
HitPatternVXD getHitPatternVXD() const
Getter for the hit pattern in the VXD;.
Definition: TrackFitResult.cc:125
Belle2::TrackFilterModule::m_min_NumHitsCDC
static int m_min_NumHitsCDC
miminum value of CDC hits
Definition: TrackFilterModule.h:63
Belle2::TrackFilterModule::m_min_NumHitsSVD
static int m_min_NumHitsSVD
miminum value of SVD hits
Definition: TrackFilterModule.h:62
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::HitPatternCDC::getNHits
unsigned short getNHits() const
Get the total Number of CDC hits in the fit.
Definition: HitPatternCDC.cc:49
Belle2::HitPatternVXD::getNSVDHits
unsigned short getNSVDHits() const
Get total number of hits in the SVD.
Definition: HitPatternVXD.cc:83
Belle2::TrackFilterModule::m_min_pT
static double m_min_pT
miminum value of the transverse momentum
Definition: TrackFilterModule.h:65
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::TrackFilterModule::m_selectedNtpl
static TNtuple * m_selectedNtpl
tuple of selected tracks
Definition: TrackFilterModule.h:86
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TrackFilterModule
generates a new StoreArray from the input StoreArray which has all specified Tracks removed
Definition: TrackFilterModule.h:38
Belle2::TrackFilterModule::m_max_d0
static double m_max_d0
d0 maximum value
Definition: TrackFilterModule.h:58
Belle2::TrackFilterModule::m_outputINArrayName
std::string m_outputINArrayName
StoreArray with the selected output tracks.
Definition: TrackFilterModule.h:75
Belle2::HitPatternVXD
Hit pattern of the VXD within a track.
Definition: HitPatternVXD.h:44
Belle2::HitPatternCDC
Hit pattern of CDC hits within a track.
Definition: HitPatternCDC.h:45
Belle2::TrackFitResult::getPhi
double getPhi() const
Getter for phi0 with CDF naming convention.
Definition: TrackFitResult.h:187
Belle2::TrackFitResult::getD0
double getD0() const
Getter for d0.
Definition: TrackFitResult.h:178