Belle II Software  release-08-01-10
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 #include <Math/Boost.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 = nullptr;
33 TNtuple* TrackFilterModule::m_rejectedNtpl = nullptr;
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 == nullptr)
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().Rho() < 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().Rho();
180  ROOT::Math::PxPyPzEVector pStar = tfr->get4Momentum();
181  ROOT::Math::BoostZ boost(3. / 11);
182  pStar = boost(pStar);
183  double pCM = pStar.P();
184  double pVal = tfr->getPValue();
185  int nPXDhits = hitPatternVXD.getNPXDHits();
186  int nSVDhits = hitPatternVXD.getNSVDHits();
187  int nCDChits = hitPatternCDC.getNHits();
188 
189  float nPXD = nPXDhits;
190  float nSVD = nSVDhits;
191  float nCDC = nCDChits;
192 
193  if (isSelected)
194  m_selectedNtpl->Fill(d0, z0, phi, tanDip, omega, pt, pCM, nPXD, nSVD, nCDC, pVal);
195  else
196  m_rejectedNtpl->Fill(d0, z0, phi, tanDip, omega, pt, pCM, nPXD, nSVD, nCDC, pVal);
197 
198 
199 }
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:580
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
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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
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
TrackFilterModule()
Constructor: Sets the description, the properties and the parameters of the module.
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.
ROOT::Math::PxPyPzEVector get4Momentum() const
Getter for the 4Momentum at the closest approach of the track in the r/phi projection.
double getOmega() const
Getter for omega.
double getD0() const
Getter for d0.
double getTanLambda() const
Getter for tanLambda.
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.
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
REG_MODULE(arichBtest)
Register the Module.
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
Abstract base class for different kinds of events.