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 = default;
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
51 
52  typedef std::vector<int> vint;
53  typedef std::vector<std::string> vstring;
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;
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  : ttrkToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
206  trkToken_(consumes<edm::View<reco::Track>>(config.getUntrackedParameter<edm::InputTag>("trackProducer"))),
207  vtxToken_(consumes<reco::VertexCollection>(config.getUntrackedParameter<edm::InputTag>("primaryVertexProducer"))),
208  jtaToken_(consumes<reco::JetTracksAssociationCollection>(
209  config.getUntrackedParameter<edm::InputTag>("jetTracksAssociation"))),
210  classifier_(config, consumesCollector()) {
211  rootFile_ = config.getUntrackedParameter<std::string>("rootFile");
212 
213  minimumNumberOfHits_ = config.getUntrackedParameter<int>("minimumNumberOfHits");
214  minimumNumberOfPixelHits_ = config.getUntrackedParameter<int>("minimumNumberOfPixelHits");
215  minimumTransverseMomentum_ = config.getUntrackedParameter<double>("minimumTransverseMomentum");
216  maximumChiSquared_ = config.getUntrackedParameter<double>("maximumChiSquared");
217 
218  std::string trackQualityType = config.getUntrackedParameter<std::string>("trackQualityClass"); // used
219  trackQuality_ = reco::TrackBase::qualityByName(trackQualityType);
220  useAllQualities_ = false;
221 
223  trackQualityType.begin(), trackQualityType.end(), trackQualityType.begin(), (int (*)(int))std::tolower);
224  if (trackQualityType == "any") {
225  std::cout << "Using any" << std::endl;
226  useAllQualities_ = true;
227  }
228 }
229 
230 //
231 // member functions
232 //
233 
234 // ------------ method called to for each event ------------
236  // Track collection
238  event.getByToken(trkToken_, trackCollection);
239  // Primary vertex
240  edm::Handle<reco::VertexCollection> primaryVertexCollection;
241  event.getByToken(vtxToken_, primaryVertexCollection);
242  // Jet to tracks associator
244  event.getByToken(jtaToken_, jetTracks);
245  // Trasient track builder
246  const edm::ESHandle<TransientTrackBuilder> TTbuilder = setup.getHandle(ttrkToken_);
247 
248  // Setting up event information for the track categories.
250 
251  LoopOverJetTracksAssociation(TTbuilder, primaryVertexCollection, jetTracks);
252 }
253 
254 // ------------ method called once each job just before starting event loop
255 // ------------
257 
258 // ------------ method called once each job just after ending the event loop
259 // ------------
261  TFile file(rootFile_.c_str(), "RECREATE");
262  file.cd();
263 
264  // saving the histograms
265  for (std::size_t i = 0; i < 6; i++) {
266  std::string particle;
267  if (i == 0)
268  particle = std::string("B_tracks");
269  else if (i == 1)
270  particle = std::string("C_tracks");
271  else if (i == 2)
272  particle = std::string("nonB_tracks");
273  else if (i == 3)
274  particle = std::string("displaced_tracks");
275  else if (i == 4)
276  particle = std::string("bad_tracks");
277  else
278  particle = std::string("fake_tracks");
279 
280  histogram_t histogram(particle);
281 
282  for (std::size_t j = 0; j < histogram_data_[i].size(); j++)
283  histogram.Fill(histogram_data_[i][j]);
284 
285  histogram.Write();
286  }
287 
288  file.Flush();
289 }
290 
292  const edm::ESHandle<TransientTrackBuilder> &TTbuilder,
293  const edm::Handle<reco::VertexCollection> &primaryVertexProducer_,
294  const edm::Handle<reco::JetTracksAssociationCollection> &jetTracksAssociation) {
295  const TransientTrackBuilder *bproduct = TTbuilder.product();
296 
297  // getting the primary vertex
298  // use first pv of the collection
300 
301  if (!primaryVertexProducer_->empty()) {
303  std::vector<reco::Vertex> sortedList = pvs.sortedList(*(primaryVertexProducer_.product()));
304  pv = (sortedList.front());
305  } else { // create a dummy PV
306  // cout << "NO PV FOUND" << endl;
308  e(0, 0) = 0.0015 * 0.0015;
309  e(1, 1) = 0.0015 * 0.0015;
310  e(2, 2) = 15. * 15.;
311  reco::Vertex::Point p(0, 0, 0);
312  pv = reco::Vertex(p, e, 1, 1, 1);
313  }
314 
315  reco::JetTracksAssociationCollection::const_iterator it = jetTracksAssociation->begin();
316 
317  int i = 0;
318 
319  for (; it != jetTracksAssociation->end(); it++, i++) {
320  // get jetTracks object
321  reco::JetTracksAssociationRef jetTracks(jetTracksAssociation, i);
322 
323  double pvZ = pv.z();
324  GlobalVector direction(jetTracks->first->px(), jetTracks->first->py(), jetTracks->first->pz());
325 
326  // get the tracks associated to the jet
328  for (std::size_t index = 0; index < tracks.size(); index++) {
330 
331  double pt = tracks[index]->pt();
332  double chi2 = tracks[index]->normalizedChi2();
333  int hits = tracks[index]->hitPattern().numberOfValidHits();
334  int pixelHits = tracks[index]->hitPattern().numberOfValidPixelHits();
335 
338  continue;
339 
340  const reco::TransientTrack transientTrack = bproduct->build(&(*tracks[index]));
341  double dta = -IPTools::jetTrackDistance(transientTrack, direction, pv).second.value();
342  double sdl = IPTools::signedDecayLength3D(transientTrack, direction, pv).second.value();
343  double ips = IPTools::signedImpactParameter3D(transientTrack, direction, pv).second.value();
344  double d0 = IPTools::signedTransverseImpactParameter(transientTrack, direction, pv).second.value();
345  double dz = tracks[index]->dz() - pvZ;
346 
347  // Classify the reco track;
349 
350  // Check for the different categories
361  else
362  histogram_data_[2].push_back(histogram_element_t(sdl, dta, d0, dz, ips, pt, chi2, hits, pixelHits));
363  }
364  }
365 }
366 
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)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< std::vector< histogram_element_t > > histogram_data_t
transient_vector_type::const_iterator const_iterator
const edm::EDGetTokenT< reco::JetTracksAssociationCollection > jtaToken_
TrackQuality
track quality
Definition: TrackBase.h:150
std::vector< int > vint
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::TrackBase::TrackQuality trackQuality_
JetTracksAssociation::Container JetTracksAssociationCollection
typedefs for backward compatibility
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:57
T const * product() const
Definition: Handle.h:70
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:105
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:81
const_iterator begin() const
TrackClassifier classifier_
Definition: config.py:1
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > ttrkToken_
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:206
reco::TransientTrack build(const reco::Track *p) const
histogram_element_t(const histogram_element_t &orig)
histogram_t(const std::string &particleType)
T const * product() const
Definition: ESHandle.h:86
bool is(Category category) const
Returns track flag for a given category.
const edm::EDGetTokenT< edm::View< reco::Track > > trkToken_
def pv(vc)
Definition: MetAnalyzer.py:7
void analyze(const edm::Event &, const edm::EventSetup &) override
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
void newEvent(edm::Event const &, edm::EventSetup const &)
Pre-process event information (for accessing reconstraction information)
d
Definition: ztail.py:151
const_iterator end() const
std::vector< std::string > vstring
static constexpr float d0
Get track history and classify it in function of their .
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
auto const & tracks
cannot be loose
TrackClassifier const & evaluate(reco::TrackBaseRef const &)
Classify the RecoTrack in categories.
const edm::EDGetTokenT< reco::VertexCollection > vtxToken_
void Fill(const histogram_element_t &data)
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
QualityCutsAnalyzer(const edm::ParameterSet &)
fixed size matrix
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
double a
Definition: hdecay.h:119
string quality
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
~QualityCutsAnalyzer() override=default
Definition: event.py:1
histogram_data_t histogram_data_
unsigned transform(const HcalDetId &id, unsigned transformCode)