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