CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiTrackValidator.cc
Go to the documentation of this file.
3 
6 
25 
30 #include<type_traits>
31 
32 
33 #include "TMath.h"
34 #include <TF1.h>
37 //#include <iostream>
38 
39 using namespace std;
40 using namespace edm;
41 
43 
45  MultiTrackValidatorBase(pset,consumesCollector()),
46  parametersDefinerIsCosmic_(parametersDefiner == "CosmicParametersDefinerForTP"),
47  calculateDrSingleCollection_(pset.getUntrackedParameter<bool>("calculateDrSingleCollection")),
48  doPlotsOnlyForTruePV_(pset.getUntrackedParameter<bool>("doPlotsOnlyForTruePV")),
49  doSummaryPlots_(pset.getUntrackedParameter<bool>("doSummaryPlots")),
50  doSimPlots_(pset.getUntrackedParameter<bool>("doSimPlots")),
51  doSimTrackPlots_(pset.getUntrackedParameter<bool>("doSimTrackPlots")),
52  doRecoTrackPlots_(pset.getUntrackedParameter<bool>("doRecoTrackPlots")),
53  dodEdxPlots_(pset.getUntrackedParameter<bool>("dodEdxPlots")),
54  doPVAssociationPlots_(pset.getUntrackedParameter<bool>("doPVAssociationPlots")),
55  doSeedPlots_(pset.getUntrackedParameter<bool>("doSeedPlots"))
56 {
57  ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
58  histoProducerAlgo_ = std::make_unique<MTVHistoProducerAlgoForTracker>(psetForHistoProducerAlgo, consumesCollector());
59 
60  dirName_ = pset.getParameter<std::string>("dirName");
61  UseAssociators = pset.getParameter< bool >("UseAssociators");
62 
63  if(dodEdxPlots_) {
64  m_dEdx1Tag = consumes<edm::ValueMap<reco::DeDxData> >(pset.getParameter< edm::InputTag >("dEdx1Tag"));
65  m_dEdx2Tag = consumes<edm::ValueMap<reco::DeDxData> >(pset.getParameter< edm::InputTag >("dEdx2Tag"));
66  }
67 
69  label_tv = consumes<TrackingVertexCollection>(pset.getParameter< edm::InputTag >("label_tv"));
70  recoVertexToken_ = consumes<edm::View<reco::Vertex> >(pset.getUntrackedParameter<edm::InputTag>("label_vertex"));
71  vertexAssociatorToken_ = consumes<reco::VertexToTrackingVertexAssociator>(pset.getUntrackedParameter<edm::InputTag>("vertexAssociator"));
72  }
73 
74  tpSelector = TrackingParticleSelector(pset.getParameter<double>("ptMinTP"),
75  pset.getParameter<double>("minRapidityTP"),
76  pset.getParameter<double>("maxRapidityTP"),
77  pset.getParameter<double>("tipTP"),
78  pset.getParameter<double>("lipTP"),
79  pset.getParameter<int>("minHitTP"),
80  pset.getParameter<bool>("signalOnlyTP"),
81  pset.getParameter<bool>("intimeOnlyTP"),
82  pset.getParameter<bool>("chargedOnlyTP"),
83  pset.getParameter<bool>("stableOnlyTP"),
84  pset.getParameter<std::vector<int> >("pdgIdTP"));
85 
87  pset.getParameter<double>("minRapidityTP"),
88  pset.getParameter<double>("maxRapidityTP"),
89  pset.getParameter<double>("tipTP"),
90  pset.getParameter<double>("lipTP"),
91  pset.getParameter<int>("minHitTP"),
92  pset.getParameter<bool>("chargedOnlyTP"),
93  pset.getParameter<std::vector<int> >("pdgIdTP"));
94 
95 
96  ParameterSet psetVsPhi = psetForHistoProducerAlgo.getParameter<ParameterSet>("TpSelectorForEfficiencyVsPhi");
97  dRtpSelector = TrackingParticleSelector(psetVsPhi.getParameter<double>("ptMin"),
98  psetVsPhi.getParameter<double>("minRapidity"),
99  psetVsPhi.getParameter<double>("maxRapidity"),
100  psetVsPhi.getParameter<double>("tip"),
101  psetVsPhi.getParameter<double>("lip"),
102  psetVsPhi.getParameter<int>("minHit"),
103  psetVsPhi.getParameter<bool>("signalOnly"),
104  psetVsPhi.getParameter<bool>("intimeOnly"),
105  psetVsPhi.getParameter<bool>("chargedOnly"),
106  psetVsPhi.getParameter<bool>("stableOnly"),
107  psetVsPhi.getParameter<std::vector<int> >("pdgId"));
108 
110  psetVsPhi.getParameter<double>("minRapidity"),
111  psetVsPhi.getParameter<double>("maxRapidity"),
112  psetVsPhi.getParameter<double>("tip"),
113  psetVsPhi.getParameter<double>("lip"),
114  psetVsPhi.getParameter<int>("minHit"),
115  psetVsPhi.getParameter<bool>("signalOnly"),
116  psetVsPhi.getParameter<bool>("intimeOnly"),
117  psetVsPhi.getParameter<bool>("chargedOnly"),
118  psetVsPhi.getParameter<bool>("stableOnly"),
119  psetVsPhi.getParameter<std::vector<int> >("pdgId"));
120 
121  useGsf = pset.getParameter<bool>("useGsf");
122 
123  _simHitTpMapTag = mayConsume<SimHitTPAssociationProducer::SimHitTPAssociationList>(pset.getParameter<edm::InputTag>("simHitTpMapTag"));
124 
126  labelTokenForDrCalculation = consumes<edm::View<reco::Track> >(pset.getParameter<edm::InputTag>("trackCollectionForDrCalculation"));
127  }
128 
129  if(UseAssociators) {
130  for (auto const& src: associators) {
131  associatorTokens.push_back(consumes<reco::TrackToTrackingParticleAssociator>(src));
132  }
133  } else {
134  for (auto const& src: associators) {
135  associatormapStRs.push_back(consumes<reco::SimToRecoCollection>(src));
136  associatormapRtSs.push_back(consumes<reco::RecoToSimCollection>(src));
137  }
138  }
139 
140  if(doSeedPlots_) {
141  for(const auto& tag: pset.getParameter< std::vector<edm::InputTag> >("label")) {
142  seedToTrackTokens_.push_back(consumes<std::vector<int>>(tag));
143  }
144  }
145 }
146 
147 
149 
150 
152 
153  const auto minColl = -0.5;
154  const auto maxColl = label.size()-0.5;
155  const auto nintColl = label.size();
156 
157  auto binLabels = [&](MonitorElement *me) {
158  TH1 *h = me->getTH1();
159  for(size_t i=0; i<label.size(); ++i) {
160  h->GetXaxis()->SetBinLabel(i+1, label[i].label().c_str());
161  }
162  return me;
163  };
164 
165  //Booking histograms concerning with simulated tracks
166  if(doSimPlots_) {
167  ibook.cd();
168  ibook.setCurrentFolder(dirName_ + "simulation");
169 
170  histoProducerAlgo_->bookSimHistos(ibook);
171 
172  ibook.cd();
173  ibook.setCurrentFolder(dirName_);
174  }
175 
176  for (unsigned int ww=0;ww<associators.size();ww++){
177  ibook.cd();
178  // FIXME: these need to be moved to a subdirectory whose name depends on the associator
179  ibook.setCurrentFolder(dirName_);
180 
181  if(doSummaryPlots_) {
182  if(doSimTrackPlots_) {
183  h_assoc_coll.push_back(binLabels( ibook.book1D("num_assoc(simToReco)_coll", "N of associated (simToReco) tracks vs track collection", nintColl, minColl, maxColl) ));
184  h_simul_coll.push_back(binLabels( ibook.book1D("num_simul_coll", "N of simulated tracks vs track collection", nintColl, minColl, maxColl) ));
185 
186  h_assoc_coll_allPt.push_back(binLabels( ibook.book1D("num_assoc(simToReco)_coll_allPt", "N of associated (simToReco) tracks vs track collection", nintColl, minColl, maxColl) ));
187  h_simul_coll_allPt.push_back(binLabels( ibook.book1D("num_simul_coll_allPt", "N of simulated tracks vs track collection", nintColl, minColl, maxColl) ));
188 
189  }
190  if(doRecoTrackPlots_) {
191  h_reco_coll.push_back(binLabels( ibook.book1D("num_reco_coll", "N of reco track vs track collection", nintColl, minColl, maxColl) ));
192  h_assoc2_coll.push_back(binLabels( ibook.book1D("num_assoc(recoToSim)_coll", "N of associated (recoToSim) tracks vs track collection", nintColl, minColl, maxColl) ));
193  h_looper_coll.push_back(binLabels( ibook.book1D("num_duplicate_coll", "N of associated (recoToSim) looper tracks vs track collection", nintColl, minColl, maxColl) ));
194  h_pileup_coll.push_back(binLabels( ibook.book1D("num_pileup_coll", "N of associated (recoToSim) pileup tracks vs track collection", nintColl, minColl, maxColl) ));
195  }
196  }
197 
198  for (unsigned int www=0;www<label.size();www++){
199  ibook.cd();
200  InputTag algo = label[www];
201  string dirName=dirName_;
202  if (algo.process()!="")
203  dirName+=algo.process()+"_";
204  if(algo.label()!="")
205  dirName+=algo.label()+"_";
206  if(algo.instance()!="")
207  dirName+=algo.instance()+"_";
208  if (dirName.find("Tracks")<dirName.length()){
209  dirName.replace(dirName.find("Tracks"),6,"");
210  }
211  string assoc= associators[ww].label();
212  if (assoc.find("Track")<assoc.length()){
213  assoc.replace(assoc.find("Track"),5,"");
214  }
215  dirName+=assoc;
216  std::replace(dirName.begin(), dirName.end(), ':', '_');
217 
218  ibook.setCurrentFolder(dirName.c_str());
219 
220  if(doSimTrackPlots_) {
221  histoProducerAlgo_->bookSimTrackHistos(ibook);
222  if(doPVAssociationPlots_) histoProducerAlgo_->bookSimTrackPVAssociationHistos(ibook);
223  }
224 
225  //Booking histograms concerning with reconstructed tracks
226  if(doRecoTrackPlots_) {
227  histoProducerAlgo_->bookRecoHistos(ibook);
228  if (dodEdxPlots_) histoProducerAlgo_->bookRecodEdxHistos(ibook);
229  if (doPVAssociationPlots_) histoProducerAlgo_->bookRecoPVAssociationHistos(ibook);
230  }
231 
232  if(doSeedPlots_) {
233  histoProducerAlgo_->bookSeedHistos(ibook);
234  }
235  }//end loop www
236  }// end loop ww
237 }
238 
239 
241  using namespace reco;
242 
243  LogDebug("TrackValidator") << "\n====================================================" << "\n"
244  << "Analyzing new event" << "\n"
245  << "====================================================\n" << "\n";
246 
247 
248  edm::ESHandle<ParametersDefinerForTP> parametersDefinerTPHandle;
249  setup.get<TrackAssociatorRecord>().get(parametersDefiner,parametersDefinerTPHandle);
250  //Since we modify the object, we must clone it
251  auto parametersDefinerTP = parametersDefinerTPHandle->clone();
252 
253  edm::Handle<TrackingParticleCollection> TPCollectionHeff ;
254  event.getByToken(label_tp_effic,TPCollectionHeff);
255  TrackingParticleCollection const & tPCeff = *(TPCollectionHeff.product());
256 
257  edm::Handle<TrackingParticleCollection> TPCollectionHfake ;
258  event.getByToken(label_tp_fake,TPCollectionHfake);
259 
260 
263  //warning: make sure the TP collection used in the map is the same used in the MTV!
264  event.getByToken(_simHitTpMapTag,simHitsTPAssoc);
265  parametersDefinerTP->initEvent(simHitsTPAssoc);
266  cosmictpSelector.initEvent(simHitsTPAssoc);
267  }
268 
269  const reco::Vertex::Point *thePVposition = nullptr;
270  const TrackingVertex::LorentzVector *theSimPVPosition = nullptr;
273  event.getByToken(label_tv, htv);
274 
276  event.getByToken(recoVertexToken_, hvertex);
277 
279  event.getByToken(vertexAssociatorToken_, hvassociator);
280 
281  auto v_r2s = hvassociator->associateRecoToSim(hvertex, htv);
282  auto pvPtr = hvertex->refAt(0);
283  if(!(pvPtr->isFake() || pvPtr->ndof() < 0)) { // skip junk vertices
284  auto pvFound = v_r2s.find(pvPtr);
285  if(pvFound != v_r2s.end()) {
286  int simPVindex = -1;
287  int i=0;
288  for(const auto& vertexRefQuality: pvFound->val) {
289  const TrackingVertex& tv = *(vertexRefQuality.first);
290  if(tv.eventId().event() == 0 && tv.eventId().bunchCrossing() == 0) {
291  simPVindex = i;
292  }
293  ++i;
294  }
295  if(simPVindex >= 0) {
297  thePVposition = &(pvPtr->position());
298  theSimPVPosition = &(pvFound->val[simPVindex].first->position());
299  }
300  }
301  else if(doPlotsOnlyForTruePV_)
302  return;
303  }
304  else if(doPlotsOnlyForTruePV_)
305  return;
306  }
307  else if(doPlotsOnlyForTruePV_)
308  return;
309  }
310 
311  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
312  event.getByToken(bsSrc,recoBeamSpotHandle);
313  reco::BeamSpot const & bs = *recoBeamSpotHandle;
314 
316  event.getByToken(label_pileupinfo,puinfoH);
317  PileupSummaryInfo puinfo;
318 
319  for (unsigned int puinfo_ite=0;puinfo_ite<(*puinfoH).size();++puinfo_ite){
320  if ((*puinfoH)[puinfo_ite].getBunchCrossing()==0){
321  puinfo=(*puinfoH)[puinfo_ite];
322  break;
323  }
324  }
325 
326  /*
327  edm::Handle<TrackingVertexCollection> tvH;
328  event.getByToken(label_tv,tvH);
329  TrackingVertexCollection const & tv = *tvH;
330  */
331 
332  // Calculate the number of 3D layers for TPs
333  //
334  // I would have preferred to produce the ValueMap to Event and read
335  // it from there, but there would have been quite some number of
336  // knock-on effects, and again the fact that we take two TP
337  // collections do not support Ref<TP>'s would have complicated that.
338  //
339  // In principle we could use the SimHitTPAssociationList read above
340  // for parametersDefinerIsCosmic_, but since we don't currently
341  // support Ref<TP>s, we can't in general use it since eff/fake TP
342  // collections can, in general, be different.
343  TrackingParticleNumberOfLayers tpNumberOfLayersAlgo(event, simHitTokens_);
344  auto nlayers_tPCeff_ptrs = tpNumberOfLayersAlgo.calculate(TPCollectionHeff, setup);
345  const auto& nLayers_tPCeff = *(std::get<TrackingParticleNumberOfLayers::nTrackerLayers>(nlayers_tPCeff_ptrs));
346  const auto& nPixelLayers_tPCeff = *(std::get<TrackingParticleNumberOfLayers::nPixelLayers>(nlayers_tPCeff_ptrs));
347  const auto& nStripMonoAndStereoLayers_tPCeff = *(std::get<TrackingParticleNumberOfLayers::nStripMonoAndStereoLayers>(nlayers_tPCeff_ptrs));
348 
349  // Precalculate TP selection (for efficiency), and momentum and vertex wrt PCA
350  //
351  // TODO: ParametersDefinerForTP ESProduct needs to be changed to
352  // EDProduct because of consumes.
353  //
354  // In principle, we could just precalculate the momentum and vertex
355  // wrt PCA for all TPs for once and put that to the event. To avoid
356  // repetitive calculations those should be calculated only once for
357  // each TP. That would imply that we should access TPs via Refs
358  // (i.e. View) in here, since, in general, the eff and fake TP
359  // collections can be different (and at least HI seems to use that
360  // feature). This would further imply that the
361  // RecoToSimCollection/SimToRecoCollection should be changed to use
362  // View<TP> instead of vector<TP>, and migrate everything.
363  //
364  // Or we could take only one input TP collection, and do another
365  // TP-selection to obtain the "fake" collection like we already do
366  // for "efficiency" TPs.
367  std::vector<size_t> selected_tPCeff;
368  std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>> momVert_tPCeff;
369  selected_tPCeff.reserve(tPCeff.size());
370  momVert_tPCeff.reserve(tPCeff.size());
371  int nIntimeTPs = 0;
373  for(size_t j=0; j<tPCeff.size(); ++j) {
374  TrackingParticleRef tpr(TPCollectionHeff, j);
375 
376  TrackingParticle::Vector momentum = parametersDefinerTP->momentum(event,setup,tpr);
377  TrackingParticle::Point vertex = parametersDefinerTP->vertex(event,setup,tpr);
378  if(doSimPlots_) {
379  histoProducerAlgo_->fill_generic_simTrack_histos(momentum, vertex, tpr->eventId().bunchCrossing());
380  }
381  if(tpr->eventId().bunchCrossing() == 0)
382  ++nIntimeTPs;
383 
384  if(cosmictpSelector(tpr,&bs,event,setup)) {
385  selected_tPCeff.push_back(j);
386  momVert_tPCeff.emplace_back(momentum, vertex);
387  }
388  }
389  }
390  else {
391  size_t j=0;
392  for(auto const& tp: tPCeff) {
393 
394  // TODO: do we want to fill these from all TPs that include IT
395  // and OOT (as below), or limit to IT+OOT TPs passing tpSelector
396  // (as it was before)? The latter would require another instance
397  // of tpSelector with intimeOnly=False.
398  if(doSimPlots_) {
399  histoProducerAlgo_->fill_generic_simTrack_histos(tp.momentum(), tp.vertex(), tp.eventId().bunchCrossing());
400  }
401  if(tp.eventId().bunchCrossing() == 0)
402  ++nIntimeTPs;
403 
404  if(tpSelector(tp)) {
405  selected_tPCeff.push_back(j);
406  TrackingParticleRef tpr(TPCollectionHeff, j);
407  TrackingParticle::Vector momentum = parametersDefinerTP->momentum(event,setup,tpr);
408  TrackingParticle::Point vertex = parametersDefinerTP->vertex(event,setup,tpr);
409  momVert_tPCeff.emplace_back(momentum, vertex);
410  }
411  ++j;
412  }
413  }
414  if(doSimPlots_) {
415  histoProducerAlgo_->fill_simTrackBased_histos(nIntimeTPs);
416  }
417 
418  //calculate dR for TPs
419  float dR_tPCeff[tPCeff.size()];
420  {
421  float etaL[tPCeff.size()], phiL[tPCeff.size()];
422  for(size_t iTP: selected_tPCeff) {
423  //calculare dR wrt inclusive collection (also with PU, low pT, displaced)
424  auto const& tp2 = tPCeff[iTP];
425  auto && p = tp2.momentum();
426  etaL[iTP] = etaFromXYZ(p.x(),p.y(),p.z());
427  phiL[iTP] = atan2f(p.y(),p.x());
428  }
429  auto i=0U;
430  for ( auto const & tp : tPCeff) {
432  if(dRtpSelector(tp)) {//only for those needed for efficiency!
433  auto && p = tp.momentum();
434  float eta = etaFromXYZ(p.x(),p.y(),p.z());
435  float phi = atan2f(p.y(),p.x());
436  for(size_t iTP: selected_tPCeff) {
437  //calculare dR wrt inclusive collection (also with PU, low pT, displaced)
438  if (i==iTP) {continue;}
439  auto dR_tmp = reco::deltaR2(eta, phi, etaL[iTP], phiL[iTP]);
440  if (dR_tmp<dR) dR=dR_tmp;
441  } // ttp2 (iTP)
442  }
443  dR_tPCeff[i++] = std::sqrt(dR);
444  } // tp
445  }
446 
447  edm::Handle<View<Track> > trackCollectionForDrCalculation;
449  event.getByToken(labelTokenForDrCalculation, trackCollectionForDrCalculation);
450  }
451 
452  // dE/dx
453  // at some point this could be generalized, with a vector of tags and a corresponding vector of Handles
454  // I'm writing the interface such to take vectors of ValueMaps
455  std::vector<const edm::ValueMap<reco::DeDxData> *> v_dEdx;
456  if(dodEdxPlots_) {
459  event.getByToken(m_dEdx1Tag, dEdx1Handle);
460  event.getByToken(m_dEdx2Tag, dEdx2Handle);
461  v_dEdx.push_back(dEdx1Handle.product());
462  v_dEdx.push_back(dEdx2Handle.product());
463  }
464 
465  int w=0; //counter counting the number of sets of histograms
466  for (unsigned int ww=0;ww<associators.size();ww++){
467  for (unsigned int www=0;www<label.size();www++, w++){ // need to increment w here, since there are many continues in the loop body
468  //
469  //get collections from the event
470  //
472  if(!event.getByToken(labelToken[www], trackCollection)&&ignoremissingtkcollection_)continue;
473 
474  reco::RecoToSimCollection const * recSimCollP=nullptr;
475  reco::SimToRecoCollection const * simRecCollP=nullptr;
476  reco::RecoToSimCollection recSimCollL;
477  reco::SimToRecoCollection simRecCollL;
478 
479  //associate tracks
480  LogTrace("TrackValidator") << "Analyzing "
481  << label[www] << " with "
482  << associators[ww] <<"\n";
483  if(UseAssociators){
485  event.getByToken(associatorTokens[ww], theAssociator);
486 
487  LogTrace("TrackValidator") << "Calling associateRecoToSim method" << "\n";
488  recSimCollL = std::move(theAssociator->associateRecoToSim(trackCollection,
489  TPCollectionHfake));
490  recSimCollP = &recSimCollL;
491  LogTrace("TrackValidator") << "Calling associateSimToReco method" << "\n";
492  simRecCollL = std::move(theAssociator->associateSimToReco(trackCollection,
493  TPCollectionHeff));
494  simRecCollP = &simRecCollL;
495  }
496  else{
497  Handle<reco::SimToRecoCollection > simtorecoCollectionH;
498  event.getByToken(associatormapStRs[ww], simtorecoCollectionH);
499  simRecCollP = simtorecoCollectionH.product();
500 
501  // We need to filter the associations of the current track
502  // collection only from SimToReco collection, otherwise the
503  // SimToReco histograms get false entries
504  simRecCollL = associationMapFilterValues(*simRecCollP, *trackCollection);
505  simRecCollP = &simRecCollL;
506 
507  Handle<reco::RecoToSimCollection > recotosimCollectionH;
508  event.getByToken(associatormapRtSs[ww],recotosimCollectionH);
509  recSimCollP = recotosimCollectionH.product();
510 
511  // In general, we should filter also the RecoToSim collection.
512  // But, that would require changing the input type of TPs to
513  // View<TrackingParticle>, and either replace current
514  // associator interfaces with (View<Track>, View<TP>) or
515  // adding the View,View interface (same goes for
516  // RefToBaseVector,RefToBaseVector). Since there is currently
517  // no compelling-enough use-case, we do not filter the
518  // RecoToSim collection here. If an association using a subset
519  // of the Sim collection is needed, user has to produce such
520  // an association explicitly.
521  }
522 
523  reco::RecoToSimCollection const & recSimColl = *recSimCollP;
524  reco::SimToRecoCollection const & simRecColl = *simRecCollP;
525 
526 
527  // Fill seed-specific histograms
528  if(doSeedPlots_) {
529  edm::Handle<std::vector<int>> hseedToTrack;
530  event.getByToken(seedToTrackTokens_[www], hseedToTrack);
531  const int failed = std::count(hseedToTrack->begin(), hseedToTrack->end(), -1);
532  histoProducerAlgo_->fill_seed_histos(www, failed, hseedToTrack->size());
533  }
534 
535 
536  // ########################################################
537  // fill simulation histograms (LOOP OVER TRACKINGPARTICLES)
538  // ########################################################
539 
540  //compute number of tracks per eta interval
541  //
542  LogTrace("TrackValidator") << "\n# of TrackingParticles: " << tPCeff.size() << "\n";
543  int ats(0); //This counter counts the number of simTracks that are "associated" to recoTracks
544  int st(0); //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) )
545  unsigned sts(0); //This counter counts the number of simTracks surviving the bunchcrossing cut
546  unsigned asts(0); //This counter counts the number of simTracks that are "associated" to recoTracks surviving the bunchcrossing cut
547 
548  //loop over already-selected TPs for tracking efficiency
549  for(size_t i=0; i<selected_tPCeff.size(); ++i) {
550  size_t iTP = selected_tPCeff[i];
551  TrackingParticleRef tpr(TPCollectionHeff, iTP);
552  const TrackingParticle& tp = tPCeff[iTP];
553 
554  auto const& momVert = momVert_tPCeff[i];
555  TrackingParticle::Vector momentumTP;
556  TrackingParticle::Point vertexTP;
557 
558  double dxySim(0);
559  double dzSim(0);
560  double dxyPVSim = 0;
561  double dzPVSim = 0;
562  double dR=dR_tPCeff[iTP];
563 
564  //---------- THIS PART HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
565  //If the TrackingParticle is collison like, get the momentum and vertex at production state
567  {
568  momentumTP = tp.momentum();
569  vertexTP = tp.vertex();
570  //Calcualte the impact parameters w.r.t. PCA
571  const TrackingParticle::Vector& momentum = std::get<TrackingParticle::Vector>(momVert);
572  const TrackingParticle::Point& vertex = std::get<TrackingParticle::Point>(momVert);
573  dxySim = (-vertex.x()*sin(momentum.phi())+vertex.y()*cos(momentum.phi()));
574  dzSim = vertex.z() - (vertex.x()*momentum.x()+vertex.y()*momentum.y())/sqrt(momentum.perp2())
575  * momentum.z()/sqrt(momentum.perp2());
576 
577  if(theSimPVPosition) {
578  // As in TrackBase::dxy(Point) and dz(Point)
579  dxyPVSim = -(vertex.x()-theSimPVPosition->x())*sin(momentum.phi()) + (vertex.y()-theSimPVPosition->y())*cos(momentum.phi());
580  dzPVSim = vertex.z()-theSimPVPosition->z() - ( (vertex.x()-theSimPVPosition->x()) + (vertex.y()-theSimPVPosition->y()) )/sqrt(momentum.perp2()) * momentum.z()/sqrt(momentum.perp2());
581  }
582  }
583  //If the TrackingParticle is comics, get the momentum and vertex at PCA
584  else
585  {
586  momentumTP = std::get<TrackingParticle::Vector>(momVert);
587  vertexTP = std::get<TrackingParticle::Point>(momVert);
588  dxySim = (-vertexTP.x()*sin(momentumTP.phi())+vertexTP.y()*cos(momentumTP.phi()));
589  dzSim = vertexTP.z() - (vertexTP.x()*momentumTP.x()+vertexTP.y()*momentumTP.y())/sqrt(momentumTP.perp2())
590  * momentumTP.z()/sqrt(momentumTP.perp2());
591 
592  // Do dxy and dz vs. PV make any sense for cosmics? I guess not
593  }
594  //---------- THE PART ABOVE HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
595 
596  //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) ), but only for in-time TPs
597  if(tp.eventId().bunchCrossing() == 0) {
598  st++;
599  }
600 
601  // in the coming lines, histos are filled using as input
602  // - momentumTP
603  // - vertexTP
604  // - dxySim
605  // - dzSim
606  if(!doSimTrackPlots_)
607  continue;
608 
609  // ##############################################
610  // fill RecoAssociated SimTracks' histograms
611  // ##############################################
612  const reco::Track* matchedTrackPointer=0;
613  if(simRecColl.find(tpr) != simRecColl.end()){
614  auto const & rt = simRecColl[tpr];
615  if (rt.size()!=0) {
616  ats++; //This counter counts the number of simTracks that have a recoTrack associated
617  // isRecoMatched = true; // UNUSED
618  matchedTrackPointer = rt.begin()->first.get();
619  LogTrace("TrackValidator") << "TrackingParticle #" << st
620  << " with pt=" << sqrt(momentumTP.perp2())
621  << " associated with quality:" << rt.begin()->second <<"\n";
622  }
623  }else{
624  LogTrace("TrackValidator")
625  << "TrackingParticle #" << st
626  << " with pt,eta,phi: "
627  << sqrt(momentumTP.perp2()) << " , "
628  << momentumTP.eta() << " , "
629  << momentumTP.phi() << " , "
630  << " NOT associated to any reco::Track" << "\n";
631  }
632 
633 
634 
635 
636  int nSimHits = tp.numberOfTrackerHits();
637  int nSimLayers = nLayers_tPCeff[tpr];
638  int nSimPixelLayers = nPixelLayers_tPCeff[tpr];
639  int nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tpr];
640  histoProducerAlgo_->fill_recoAssociated_simTrack_histos(w,tp,momentumTP,vertexTP,dxySim,dzSim,dxyPVSim,dzPVSim,nSimHits,nSimLayers,nSimPixelLayers,nSimStripMonoAndStereoLayers,matchedTrackPointer,puinfo.getPU_NumInteractions(), dR, thePVposition);
641  sts++;
642  if(matchedTrackPointer)
643  asts++;
644  if(doSummaryPlots_) {
645  if(dRtpSelectorNoPtCut(tp)) {
646  h_simul_coll_allPt[ww]->Fill(www);
647  if (matchedTrackPointer) {
648  h_assoc_coll_allPt[ww]->Fill(www);
649  }
650 
651  if(dRtpSelector(tp)) {
652  h_simul_coll[ww]->Fill(www);
653  if (matchedTrackPointer) {
654  h_assoc_coll[ww]->Fill(www);
655  }
656  }
657  }
658  }
659 
660 
661 
662 
663  } // End for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){
664 
665  // ##############################################
666  // fill recoTracks histograms (LOOP OVER TRACKS)
667  // ##############################################
668  if(!doRecoTrackPlots_)
669  continue;
670  LogTrace("TrackValidator") << "\n# of reco::Tracks with "
671  << label[www].process()<<":"
672  << label[www].label()<<":"
673  << label[www].instance()
674  << ": " << trackCollection->size() << "\n";
675 
676  int sat(0); //This counter counts the number of recoTracks that are associated to SimTracks from Signal only
677  int at(0); //This counter counts the number of recoTracks that are associated to SimTracks
678  int rT(0); //This counter counts the number of recoTracks in general
679 
680  //calculate dR for tracks
681  const edm::View<Track> *trackCollectionDr = trackCollection.product();
683  trackCollectionDr = trackCollectionForDrCalculation.product();
684  }
685  float dR_trk[trackCollection->size()];
686  int i=0;
687  float etaL[trackCollectionDr->size()];
688  float phiL[trackCollectionDr->size()];
689  for (auto const & track2 : *trackCollectionDr) {
690  auto && p = track2.momentum();
691  etaL[i] = etaFromXYZ(p.x(),p.y(),p.z());
692  phiL[i] = atan2f(p.y(),p.x());
693  ++i;
694  }
695  for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
696  auto const & track = (*trackCollection)[i];
698  auto && p = track.momentum();
699  float eta = etaFromXYZ(p.x(),p.y(),p.z());
700  float phi = atan2f(p.y(),p.x());
701  for(View<Track>::size_type j=0; j<trackCollectionDr->size(); ++j){
702  auto dR_tmp = reco::deltaR2(eta, phi, etaL[j], phiL[j]);
703  if ( (dR_tmp<dR) & (dR_tmp>std::numeric_limits<float>::min())) dR=dR_tmp;
704  }
705  dR_trk[i] = std::sqrt(dR);
706  }
707 
708  for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
709 
710  RefToBase<Track> track(trackCollection, i);
711  rT++;
712 
713  bool isSigSimMatched(false);
714  bool isSimMatched(false);
715  bool isChargeMatched(true);
716  int numAssocRecoTracks = 0;
717  int nSimHits = 0;
718  double sharedFraction = 0.;
719 
720  auto tpFound = recSimColl.find(track);
721  isSimMatched = tpFound != recSimColl.end();
722  if (isSimMatched) {
723  const auto& tp = tpFound->val;
724  nSimHits = tp[0].first->numberOfTrackerHits();
725  sharedFraction = tp[0].second;
726  if (tp[0].first->charge() != track->charge()) isChargeMatched = false;
727  if(simRecColl.find(tp[0].first) != simRecColl.end()) numAssocRecoTracks = simRecColl[tp[0].first].size();
728  at++;
729  for (unsigned int tp_ite=0;tp_ite<tp.size();++tp_ite){
730  TrackingParticle trackpart = *(tp[tp_ite].first);
731  if ((trackpart.eventId().event() == 0) && (trackpart.eventId().bunchCrossing() == 0)){
732  isSigSimMatched = true;
733  sat++;
734  break;
735  }
736  }
737  LogTrace("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
738  << " associated with quality:" << tp.begin()->second <<"\n";
739  } else {
740  LogTrace("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
741  << " NOT associated to any TrackingParticle" << "\n";
742  }
743 
744  double dR=dR_trk[i];
745  histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track,bs.position(), thePVposition, isSimMatched,isSigSimMatched, isChargeMatched, numAssocRecoTracks, puinfo.getPU_NumInteractions(), nSimHits, sharedFraction, dR);
746  if(doSummaryPlots_) {
747  h_reco_coll[ww]->Fill(www);
748  if(isSimMatched) {
749  h_assoc2_coll[ww]->Fill(www);
750  if(numAssocRecoTracks>1) {
751  h_looper_coll[ww]->Fill(www);
752  }
753  if(!isSigSimMatched) {
754  h_pileup_coll[ww]->Fill(www);
755  }
756  }
757  }
758 
759  // dE/dx
760  if (dodEdxPlots_) histoProducerAlgo_->fill_dedx_recoTrack_histos(w,track, v_dEdx);
761 
762 
763  //Fill other histos
764  if (!isSimMatched) continue;
765 
766  histoProducerAlgo_->fill_simAssociated_recoTrack_histos(w,*track);
767 
768  TrackingParticleRef tpr = tpFound->val.begin()->first;
769 
770  /* TO BE FIXED LATER
771  if (associators[ww]=="trackAssociatorByChi2"){
772  //association chi2
773  double assocChi2 = -tp.begin()->second;//in association map is stored -chi2
774  h_assochi2[www]->Fill(assocChi2);
775  h_assochi2_prob[www]->Fill(TMath::Prob((assocChi2)*5,5));
776  }
777  else if (associators[ww]=="quickTrackAssociatorByHits"){
778  double fraction = tp.begin()->second;
779  h_assocFraction[www]->Fill(fraction);
780  h_assocSharedHit[www]->Fill(fraction*track->numberOfValidHits());
781  }
782  */
783 
784 
785  //Get tracking particle parameters at point of closest approach to the beamline
786  TrackingParticle::Vector momentumTP = parametersDefinerTP->momentum(event,setup,tpr);
787  TrackingParticle::Point vertexTP = parametersDefinerTP->vertex(event,setup,tpr);
788  int chargeTP = tpr->charge();
789 
790  histoProducerAlgo_->fill_ResoAndPull_recoTrack_histos(w,momentumTP,vertexTP,chargeTP,
791  *track,bs.position());
792 
793 
794  //TO BE FIXED
795  //std::vector<PSimHit> simhits=tpr.get()->trackPSimHit(DetId::Tracker);
796  //nrecHit_vs_nsimHit_rec2sim[w]->Fill(track->numberOfValidHits(), (int)(simhits.end()-simhits.begin() ));
797 
798  } // End of for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
799 
800  histoProducerAlgo_->fill_trackBased_histos(w,at,rT,st);
801 
802  LogTrace("TrackValidator") << "Total Simulated: " << st << "\n"
803  << "Total Associated (simToReco): " << ats << "\n"
804  << "Total Reconstructed: " << rT << "\n"
805  << "Total Associated (recoToSim): " << at << "\n"
806  << "Total Fakes: " << rT-at << "\n";
807  } // End of for (unsigned int www=0;www<label.size();www++){
808  } //END of for (unsigned int ww=0;ww<associators.size();ww++){
809 
810 }
#define LogDebug(id)
T getParameter(std::string const &) const
unsigned int size_type
Definition: View.h:85
edm::EDGetTokenT< edm::ValueMap< reco::DeDxData > > m_dEdx1Tag
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< edm::InputTag > associators
edm::EDGetTokenT< SimHitTPAssociationProducer::SimHitTPAssociationList > _simHitTpMapTag
int event() const
get the contents of the subdetector field (should be protected?)
std::vector< MonitorElement * > h_reco_coll
std::vector< edm::EDGetTokenT< reco::SimToRecoCollection > > associatormapStRs
const double w
Definition: UKUtility.cc:23
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > label_pileupinfo
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
CosmicTrackingParticleSelector cosmictpSelector
std::vector< TrackingParticle > TrackingParticleCollection
Vector momentum() const
spatial momentum vector
const_iterator end() const
last iterator over the map (read only)
edm::EDGetTokenT< TrackingParticleCollection > label_tp_effic
std::vector< MonitorElement * > h_simul_coll
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
void cd(void)
Definition: DQMStore.cc:268
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const_iterator find(const key_type &k) const
find element with specified reference key
void analyze(const edm::Event &, const edm::EventSetup &) override
Method called once per event.
size_type size() const
edm::EDGetTokenT< TrackingVertexCollection > label_tv
T_AssociationMap associationMapFilterValues(const T_AssociationMap &map, const T_RefVector &valueRefs)
TrackingParticleSelector dRtpSelector
TrackingParticleSelector dRtpSelectorNoPtCut
std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associatorTokens
const bool doPlotsOnlyForTruePV_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::BeamSpot > bsSrc
math::XYZPointD Point
point in the space
std::vector< MonitorElement * > h_looper_coll
math::XYZTLorentzVectorD LorentzVector
std::vector< MonitorElement * > h_pileup_coll
SingleObjectSelector< TrackingParticleCollection,::TrackingParticleSelector > TrackingParticleSelector
std::vector< MonitorElement * > h_assoc_coll
std::vector< edm::InputTag > label
std::vector< edm::EDGetTokenT< reco::RecoToSimCollection > > associatormapRtSs
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:18
int bunchCrossing() const
get the detector field from this detid
double pt() const
track transverse momentum
Definition: TrackBase.h:616
TrackingParticleSelector tpSelector
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
def move
Definition: eostools.py:510
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
int j
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< edm::View< reco::Track > > labelTokenForDrCalculation
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
void initEvent(edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssocToSet) const
std::vector< edm::EDGetTokenT< std::vector< int > > > seedToTrackTokens_
T min(T a, T b)
Definition: MathUtil.h:58
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
MultiTrackValidator(const edm::ParameterSet &pset)
Constructor.
#define LogTrace(id)
ObjectSelector< CosmicTrackingParticleSelector > CosmicTrackingParticleSelector
std::unique_ptr< MTVHistoProducerAlgoForTracker > histoProducerAlgo_
std::vector< MonitorElement * > h_assoc_coll_allPt
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
T const * product() const
Definition: Handle.h:81
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Method called to book the DQM histograms.
edm::EDGetTokenT< reco::VertexToTrackingVertexAssociator > vertexAssociatorToken_
const T & get() const
Definition: EventSetup.h:56
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
std::string const & label() const
Definition: InputTag.h:36
const bool doPVAssociationPlots_
EncodedEventId eventId() const
Signal source, crossing number.
Point vertex() const
Parent vertex position.
edm::EDGetTokenT< edm::View< reco::Vertex > > recoVertexToken_
std::string const & process() const
Definition: InputTag.h:40
std::tuple< std::unique_ptr< edm::ValueMap< unsigned int > >, std::unique_ptr< edm::ValueMap< unsigned int > >, std::unique_ptr< edm::ValueMap< unsigned int > > > calculate(const edm::Handle< TrackingParticleCollection > &tps, const edm::EventSetup &iSetup) const
const EncodedEventId & eventId() const
const bool calculateDrSingleCollection_
std::vector< MonitorElement * > h_simul_coll_allPt
std::vector< MonitorElement * > h_assoc2_coll
Monte Carlo truth information used for tracking validation.
int charge() const
track electric charge
Definition: TrackBase.h:562
int numberOfTrackerHits() const
The number of hits in the tracker. Hits on overlaps in the same layer count separately.
std::vector< edm::EDGetTokenT< edm::View< reco::Track > > > labelToken
math::XYZVectorD Vector
point in the space
std::vector< edm::EDGetTokenT< std::vector< PSimHit > > > simHitTokens_
edm::EDGetTokenT< TrackingParticleCollection > label_tp_fake
std::string const & instance() const
Definition: InputTag.h:37
tuple size
Write out results.
edm::EDGetTokenT< edm::ValueMap< reco::DeDxData > > m_dEdx2Tag
Definition: Run.h:43
virtual ~MultiTrackValidator()
Destructor.
const bool parametersDefinerIsCosmic_