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