CMS 3D CMS Logo

QualityCutsAnalyzer.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cctype>
3 #include <iomanip>
4 #include <set>
5 #include <sstream>
6 #include <vector>
7 
8 #include "TFile.h"
9 #include "TH1F.h"
10 
11 #include "HepPDT/ParticleID.hh"
12 
13 // user include files
17 
23 
25 
27 
29 
31 
32 //
33 // class decleration
34 //
35 
37 public:
38  explicit QualityCutsAnalyzer(const edm::ParameterSet &);
39  ~QualityCutsAnalyzer() override;
40 
41 private:
42  void beginJob() override;
43  void analyze(const edm::Event &, const edm::EventSetup &) override;
44  void endJob() override;
45 
46  // Member data
47 
48  typedef std::vector<int> vint;
49  typedef std::vector<std::string> vstring;
50 
54 
56 
59 
62 
66 
67  // Histograms for optimization
68 
70  double sdl; // Signed decay length
71  double dta; // Distance to jet axis
72  double tip; // Transverse impact parameter
73  double lip; // Longitudinal impact parameter
74  double ips; // Impact parameter significance.
75  double pt; // Transverse momentum
76  double chi2; // Chi^2
77  std::size_t hits; // Number of hits
78  std::size_t pixelhits; // Number of hits
79 
81  double d, double a, double t, double l, double i, double p, double c, std::size_t h, std::size_t x) {
82  sdl = d;
83  dta = a;
84  tip = t;
85  lip = l;
86  ips = i;
87  pt = p;
88  chi2 = c;
89  hits = h;
90  pixelhits = x;
91  }
92 
94  sdl = orig.sdl;
95  dta = orig.dta;
96  tip = orig.tip;
97  lip = orig.lip;
98  ips = orig.ips;
99  pt = orig.pt;
100  chi2 = orig.chi2;
101  hits = orig.hits;
102  pixelhits = orig.pixelhits;
103  }
104  };
105 
106  typedef std::vector<std::vector<histogram_element_t>> histogram_data_t;
107  histogram_data_t histogram_data_;
108 
109  class histogram_t {
110  TH1F *sdl;
111  TH1F *dta;
112  TH1F *tip;
113  TH1F *lip;
114  TH1F *ips;
115  TH1F *pixelhits;
116  TH1F *pt_1gev;
117  TH1F *chi2;
118  TH1F *hits;
119 
120  public:
123  name = std::string("hits_") + particleType;
124  title = std::string("Hit distribution for ") + particleType;
125  hits = new TH1F(name.c_str(), title.c_str(), 19, -0.5, 18.5);
126 
127  name = std::string("chi2_") + particleType;
128  title = std::string("Chi2 distribution for ") + particleType;
129  chi2 = new TH1F(name.c_str(), title.c_str(), 100, 0., 30.);
130 
131  name = std::string("pixelhits_") + particleType;
132  title = std::string("Pixel hits distribution for ") + particleType;
133  pixelhits = new TH1F(name.c_str(), title.c_str(), 21, -0.5, 20.5);
134 
135  name = std::string("pt_1Gev_") + particleType;
136  title = std::string("Pt distribution close 1Gev for ") + particleType;
137  pt_1gev = new TH1F(name.c_str(), title.c_str(), 100, 0., 2.);
138 
139  name = std::string("tip_") + particleType;
140  title = std::string("Transverse impact parameter distribution for ") + particleType;
141  tip = new TH1F(name.c_str(), title.c_str(), 100, -0.3, 0.3);
142 
143  name = std::string("lip_") + particleType;
144  title = std::string("Longitudinal impact parameter distribution for ") + particleType;
145  lip = new TH1F(name.c_str(), title.c_str(), 100, -1., 1.);
146 
147  name = std::string("ips_") + particleType;
148  title = std::string("IPS distribution for ") + particleType;
149  ips = new TH1F(name.c_str(), title.c_str(), 100, -25.0, 25.0);
150 
151  name = std::string("sdl_") + particleType;
152  title = std::string("Decay length distribution for ") + particleType;
153  sdl = new TH1F(name.c_str(), title.c_str(), 100, -5., 5.);
154 
155  name = std::string("dta_") + particleType;
156  title = std::string("Distance to jet distribution for ") + particleType;
157  dta = new TH1F(name.c_str(), title.c_str(), 100, 0.0, 0.2);
158  }
159 
161  delete hits;
162  delete chi2;
163  delete pixelhits;
164  delete pt_1gev;
165  delete tip;
166  delete lip;
167  delete ips;
168  delete sdl;
169  delete dta;
170  }
171 
173  hits->Fill(data.hits);
174  chi2->Fill(data.chi2);
175  pixelhits->Fill(data.pt);
176  pt_1gev->Fill(data.pt);
177  ips->Fill(data.ips);
178  tip->Fill(data.tip);
179  lip->Fill(data.lip);
180  sdl->Fill(data.sdl);
181  dta->Fill(data.dta);
182  }
183 
184  void Write() {
185  hits->Write();
186  chi2->Write();
187  pixelhits->Write();
188  pt_1gev->Write();
189  ips->Write();
190  tip->Write();
191  lip->Write();
192  sdl->Write();
193  dta->Write();
194  }
195  };
196 
197  // Track classification.
199 };
200 
201 //
202 // constructors and destructor
203 //
205  trackProducer_ = config.getUntrackedParameter<edm::InputTag>("trackProducer");
206  consumes<edm::View<reco::Track>>(trackProducer_);
207  primaryVertexProducer_ = config.getUntrackedParameter<edm::InputTag>("primaryVertexProducer");
208  consumes<reco::VertexCollection>(primaryVertexProducer_);
209  jetTracksAssociation_ = config.getUntrackedParameter<edm::InputTag>("jetTracksAssociation");
210  consumes<reco::JetTracksAssociationCollection>(jetTracksAssociation_);
211 
212  rootFile_ = config.getUntrackedParameter<std::string>("rootFile");
213 
214  minimumNumberOfHits_ = config.getUntrackedParameter<int>("minimumNumberOfHits");
215  minimumNumberOfPixelHits_ = config.getUntrackedParameter<int>("minimumNumberOfPixelHits");
216  minimumTransverseMomentum_ = config.getUntrackedParameter<double>("minimumTransverseMomentum");
217  maximumChiSquared_ = config.getUntrackedParameter<double>("maximumChiSquared");
218 
219  std::string trackQualityType = config.getUntrackedParameter<std::string>("trackQualityClass"); // used
220  trackQuality_ = reco::TrackBase::qualityByName(trackQualityType);
221  useAllQualities_ = false;
222 
224  trackQualityType.begin(), trackQualityType.end(), trackQualityType.begin(), (int (*)(int))std::tolower);
225  if (trackQualityType == "any") {
226  std::cout << "Using any" << std::endl;
227  useAllQualities_ = true;
228  }
229 }
230 
232 
233 //
234 // member functions
235 //
236 
237 // ------------ method called to for each event ------------
239  // Track collection
241  event.getByLabel(trackProducer_, trackCollection);
242  // Primary vertex
243  edm::Handle<reco::VertexCollection> primaryVertexCollection;
244  event.getByLabel(primaryVertexProducer_, primaryVertexCollection);
245  // Jet to tracks associator
247  event.getByLabel(jetTracksAssociation_, jetTracks);
248  // Trasient track builder
250  setup.get<TransientTrackRecord>().get("TransientTrackBuilder", TTbuilder);
251 
252  // Setting up event information for the track categories.
253  classifier_.newEvent(event, setup);
254 
255  LoopOverJetTracksAssociation(TTbuilder, primaryVertexCollection, jetTracks);
256 }
257 
258 // ------------ method called once each job just before starting event loop
259 // ------------
261 
262 // ------------ method called once each job just after ending the event loop
263 // ------------
265  TFile file(rootFile_.c_str(), "RECREATE");
266  file.cd();
267 
268  // saving the histograms
269  for (std::size_t i = 0; i < 6; i++) {
270  std::string particle;
271  if (i == 0)
272  particle = std::string("B_tracks");
273  else if (i == 1)
274  particle = std::string("C_tracks");
275  else if (i == 2)
276  particle = std::string("nonB_tracks");
277  else if (i == 3)
278  particle = std::string("displaced_tracks");
279  else if (i == 4)
280  particle = std::string("bad_tracks");
281  else
282  particle = std::string("fake_tracks");
283 
284  histogram_t histogram(particle);
285 
286  for (std::size_t j = 0; j < histogram_data_[i].size(); j++)
287  histogram.Fill(histogram_data_[i][j]);
288 
289  histogram.Write();
290  }
291 
292  file.Flush();
293 }
294 
296  const edm::ESHandle<TransientTrackBuilder> &TTbuilder,
298  const edm::Handle<reco::JetTracksAssociationCollection> &jetTracksAssociation) {
299  const TransientTrackBuilder *bproduct = TTbuilder.product();
300 
301  // getting the primary vertex
302  // use first pv of the collection
304 
305  if (!primaryVertexProducer_->empty()) {
307  std::vector<reco::Vertex> sortedList = pvs.sortedList(*(primaryVertexProducer_.product()));
308  pv = (sortedList.front());
309  } else { // create a dummy PV
310  // cout << "NO PV FOUND" << endl;
312  e(0, 0) = 0.0015 * 0.0015;
313  e(1, 1) = 0.0015 * 0.0015;
314  e(2, 2) = 15. * 15.;
315  reco::Vertex::Point p(0, 0, 0);
316  pv = reco::Vertex(p, e, 1, 1, 1);
317  }
318 
319  reco::JetTracksAssociationCollection::const_iterator it = jetTracksAssociation->begin();
320 
321  int i = 0;
322 
323  for (; it != jetTracksAssociation->end(); it++, i++) {
324  // get jetTracks object
325  reco::JetTracksAssociationRef jetTracks(jetTracksAssociation, i);
326 
327  double pvZ = pv.z();
328  GlobalVector direction(jetTracks->first->px(), jetTracks->first->py(), jetTracks->first->pz());
329 
330  // get the tracks associated to the jet
331  reco::TrackRefVector tracks = jetTracks->second;
332  for (std::size_t index = 0; index < tracks.size(); index++) {
334 
335  double pt = tracks[index]->pt();
336  double chi2 = tracks[index]->normalizedChi2();
337  int hits = tracks[index]->hitPattern().numberOfValidHits();
338  int pixelHits = tracks[index]->hitPattern().numberOfValidPixelHits();
339 
341  chi2 > maximumChiSquared_ || (!useAllQualities_ && !tracks[index]->quality(trackQuality_)))
342  continue;
343 
344  const reco::TransientTrack transientTrack = bproduct->build(&(*tracks[index]));
345  double dta = -IPTools::jetTrackDistance(transientTrack, direction, pv).second.value();
346  double sdl = IPTools::signedDecayLength3D(transientTrack, direction, pv).second.value();
347  double ips = IPTools::signedImpactParameter3D(transientTrack, direction, pv).second.value();
348  double d0 = IPTools::signedTransverseImpactParameter(transientTrack, direction, pv).second.value();
349  double dz = tracks[index]->dz() - pvZ;
350 
351  // Classify the reco track;
353 
354  // Check for the different categories
356  histogram_data_[5].push_back(histogram_element_t(sdl, dta, d0, dz, ips, pt, chi2, hits, pixelHits));
358  histogram_data_[0].push_back(histogram_element_t(sdl, dta, d0, dz, ips, pt, chi2, hits, pixelHits));
360  histogram_data_[4].push_back(histogram_element_t(sdl, dta, d0, dz, ips, pt, chi2, hits, pixelHits));
362  histogram_data_[3].push_back(histogram_element_t(sdl, dta, d0, dz, ips, pt, chi2, hits, pixelHits));
364  histogram_data_[1].push_back(histogram_element_t(sdl, dta, d0, dz, ips, pt, chi2, hits, pixelHits));
365  else
366  histogram_data_[2].push_back(histogram_element_t(sdl, dta, d0, dz, ips, pt, chi2, hits, pixelHits));
367  }
368  }
369 }
370 
T getUntrackedParameter(std::string const &, T const &) const
histogram_element_t(double d, double a, double t, double l, double i, double p, double c, std::size_t h, std::size_t x)
std::vector< std::vector< histogram_element_t > > histogram_data_t
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
transient_vector_type::const_iterator const_iterator
TrackQuality
track quality
Definition: TrackBase.h:151
std::vector< int > vint
reco::TrackBase::TrackQuality trackQuality_
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
void LoopOverJetTracksAssociation(const edm::ESHandle< TransientTrackBuilder > &, const edm::Handle< reco::VertexCollection > &, const edm::Handle< reco::JetTracksAssociationCollection > &)
std::pair< bool, Measurement1D > signedDecayLength3D(const TrajectoryStateOnSurface &state, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:94
reco::TransientTrack build(const reco::Track *p) const
std::vector< reco::Vertex > sortedList(const reco::VertexCollection &primaryVertex) const
const_iterator end() const
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
TrackClassifier classifier_
Definition: config.py:1
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:200
histogram_element_t(const histogram_element_t &orig)
TrackClassifier const & evaluate(reco::TrackBaseRef const &)
Classify the RecoTrack in categories.
histogram_t(const std::string &particleType)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
def pv(vc)
Definition: MetAnalyzer.py:7
double z() const
z coordinate
Definition: Vertex.h:115
void analyze(const edm::Event &, const edm::EventSetup &) override
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
void newEvent(edm::Event const &, edm::EventSetup const &)
Pre-process event information (for accessing reconstraction information)
edm::InputTag trackProducer_
bool is(Category category) const
Returns track flag for a given category.
std::vector< std::string > vstring
Get track history and classify it in function of their .
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:134
T const * product() const
Definition: Handle.h:74
void Fill(const histogram_element_t &data)
QualityCutsAnalyzer(const edm::ParameterSet &)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double a
Definition: hdecay.h:121
T get() const
Definition: EventSetup.h:71
edm::InputTag primaryVertexProducer_
const_iterator begin() const
T const * product() const
Definition: ESHandle.h:86
Definition: event.py:1
histogram_data_t histogram_data_
edm::InputTag jetTracksAssociation_