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 
26 
31 #include<type_traits>
32 
33 
34 #include "TMath.h"
35 #include <TF1.h>
38 //#include <iostream>
39 
40 using namespace std;
41 using namespace edm;
42 
44 
46  MultiTrackValidatorBase(pset,consumesCollector()),
47  parametersDefinerIsCosmic_(parametersDefiner == "CosmicParametersDefinerForTP"),
48  doSimPlots_(pset.getUntrackedParameter<bool>("doSimPlots")),
49  doSimTrackPlots_(pset.getUntrackedParameter<bool>("doSimTrackPlots")),
50  doRecoTrackPlots_(pset.getUntrackedParameter<bool>("doRecoTrackPlots")),
51  dodEdxPlots_(pset.getUntrackedParameter<bool>("dodEdxPlots"))
52 {
53  //theExtractor = IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet, consumesCollector());
54 
55  ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
56  string histoProducerAlgoName = psetForHistoProducerAlgo.getParameter<string>("ComponentName");
57  histoProducerAlgo_ = MTVHistoProducerAlgoFactory::get()->create(histoProducerAlgoName ,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 
67  tpSelector = TrackingParticleSelector(pset.getParameter<double>("ptMinTP"),
68  pset.getParameter<double>("minRapidityTP"),
69  pset.getParameter<double>("maxRapidityTP"),
70  pset.getParameter<double>("tipTP"),
71  pset.getParameter<double>("lipTP"),
72  pset.getParameter<int>("minHitTP"),
73  pset.getParameter<bool>("signalOnlyTP"),
74  pset.getParameter<bool>("chargedOnlyTP"),
75  pset.getParameter<bool>("stableOnlyTP"),
76  pset.getParameter<std::vector<int> >("pdgIdTP"));
77 
79  pset.getParameter<double>("minRapidityTP"),
80  pset.getParameter<double>("maxRapidityTP"),
81  pset.getParameter<double>("tipTP"),
82  pset.getParameter<double>("lipTP"),
83  pset.getParameter<int>("minHitTP"),
84  pset.getParameter<bool>("chargedOnlyTP"),
85  pset.getParameter<std::vector<int> >("pdgIdTP"));
86 
87 
88  ParameterSet psetVsEta = psetForHistoProducerAlgo.getParameter<ParameterSet>("TpSelectorForEfficiencyVsEta");
89  dRtpSelector = TrackingParticleSelector(psetVsEta.getParameter<double>("ptMin"),
90  psetVsEta.getParameter<double>("minRapidity"),
91  psetVsEta.getParameter<double>("maxRapidity"),
92  psetVsEta.getParameter<double>("tip"),
93  psetVsEta.getParameter<double>("lip"),
94  psetVsEta.getParameter<int>("minHit"),
95  psetVsEta.getParameter<bool>("signalOnly"),
96  psetVsEta.getParameter<bool>("chargedOnly"),
97  psetVsEta.getParameter<bool>("stableOnly"),
98  psetVsEta.getParameter<std::vector<int> >("pdgId"));
99 
100  useGsf = pset.getParameter<bool>("useGsf");
101 
102  _simHitTpMapTag = mayConsume<SimHitTPAssociationProducer::SimHitTPAssociationList>(pset.getParameter<edm::InputTag>("simHitTpMapTag"));
103 
104  labelTokenForDrCalculation = consumes<edm::View<reco::Track> >(pset.getParameter<edm::InputTag>("trackCollectionForDrCalculation"));
105 
106  if(UseAssociators) {
107  for (auto const& src: associators) {
108  associatorTokens.push_back(consumes<reco::TrackToTrackingParticleAssociator>(src));
109  }
110  } else {
111  for (auto const& src: associators) {
112  associatormapStRs.push_back(consumes<reco::SimToRecoCollection>(src));
113  associatormapRtSs.push_back(consumes<reco::RecoToSimCollection>(src));
114  }
115  }
116 }
117 
118 
120 
121 
123 
124  const auto minColl = -0.5;
125  const auto maxColl = label.size()-0.5;
126  const auto nintColl = label.size();
127 
128  auto binLabels = [&](MonitorElement *me) {
129  TH1 *h = me->getTH1();
130  for(size_t i=0; i<label.size(); ++i) {
131  h->GetXaxis()->SetBinLabel(i+1, label[i].label().c_str());
132  }
133  return me;
134  };
135 
136 
137  for (unsigned int ww=0;ww<associators.size();ww++){
138  ibook.cd();
139  ibook.setCurrentFolder(dirName_);
140 
141  h_reco_coll.push_back(binLabels( ibook.book1D("num_reco_coll", "N of reco track vs track collection", nintColl, minColl, maxColl) ));
142  h_assoc2_coll.push_back(binLabels( ibook.book1D("num_assoc(recoToSim)_coll", "N of associated (recoToSim) tracks vs track collection", nintColl, minColl, maxColl) ));
143  h_assoc_coll.push_back(binLabels( ibook.book1D("num_assoc(simToReco)_coll", "N of associated (simToReco) tracks vs track collection", nintColl, minColl, maxColl) ));
144  h_simul_coll.push_back(binLabels( ibook.book1D("num_simul_coll", "N of simulated tracks vs track collection", nintColl, minColl, maxColl) ));
145  h_looper_coll.push_back(binLabels( ibook.book1D("num_duplicate_coll", "N of associated (recoToSim) looper tracks vs track collection", nintColl, minColl, maxColl) ));
146  h_pileup_coll.push_back(binLabels( ibook.book1D("num_pileup_coll", "N of associated (recoToSim) pileup tracks vs track collection", nintColl, minColl, maxColl) ));
147 
148  for (unsigned int www=0;www<label.size();www++){
149  ibook.cd();
150  InputTag algo = label[www];
151  string dirName=dirName_;
152  if (algo.process()!="")
153  dirName+=algo.process()+"_";
154  if(algo.label()!="")
155  dirName+=algo.label()+"_";
156  if(algo.instance()!="")
157  dirName+=algo.instance()+"_";
158  if (dirName.find("Tracks")<dirName.length()){
159  dirName.replace(dirName.find("Tracks"),6,"");
160  }
161  string assoc= associators[ww].label();
162  if (assoc.find("Track")<assoc.length()){
163  assoc.replace(assoc.find("Track"),5,"");
164  }
165  dirName+=assoc;
166  std::replace(dirName.begin(), dirName.end(), ':', '_');
167 
168  ibook.setCurrentFolder(dirName.c_str());
169 
170  //Booking histograms concerning with simulated tracks
171  if(doSimPlots_) {
172  string subDirName = dirName + "/simulation";
173  ibook.setCurrentFolder(subDirName.c_str());
174 
176 
177  ibook.cd();
178  ibook.setCurrentFolder(dirName.c_str());
179  }
180  if(doSimTrackPlots_) {
182  }
183 
184  //Booking histograms concerning with reconstructed tracks
185  if(doRecoTrackPlots_) {
188  }
189  }//end loop www
190  }// end loop ww
191 }
192 
193 
195  using namespace reco;
196 
197  LogDebug("TrackValidator") << "\n====================================================" << "\n"
198  << "Analyzing new event" << "\n"
199  << "====================================================\n" << "\n";
200 
201 
202  edm::ESHandle<ParametersDefinerForTP> parametersDefinerTPHandle;
203  setup.get<TrackAssociatorRecord>().get(parametersDefiner,parametersDefinerTPHandle);
204  //Since we modify the object, we must clone it
205  auto parametersDefinerTP = parametersDefinerTPHandle->clone();
206 
207  edm::Handle<TrackingParticleCollection> TPCollectionHeff ;
208  event.getByToken(label_tp_effic,TPCollectionHeff);
209  TrackingParticleCollection const & tPCeff = *(TPCollectionHeff.product());
210 
211  edm::Handle<TrackingParticleCollection> TPCollectionHfake ;
212  event.getByToken(label_tp_fake,TPCollectionHfake);
213 
214 
217  //warning: make sure the TP collection used in the map is the same used in the MTV!
218  event.getByToken(_simHitTpMapTag,simHitsTPAssoc);
219  parametersDefinerTP->initEvent(simHitsTPAssoc);
220  cosmictpSelector.initEvent(simHitsTPAssoc);
221  }
222 
223 
224  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
225  event.getByToken(bsSrc,recoBeamSpotHandle);
226  reco::BeamSpot const & bs = *recoBeamSpotHandle;
227 
229  event.getByToken(label_pileupinfo,puinfoH);
230  PileupSummaryInfo puinfo;
231 
232  for (unsigned int puinfo_ite=0;puinfo_ite<(*puinfoH).size();++puinfo_ite){
233  if ((*puinfoH)[puinfo_ite].getBunchCrossing()==0){
234  puinfo=(*puinfoH)[puinfo_ite];
235  break;
236  }
237  }
238 
239  /*
240  edm::Handle<TrackingVertexCollection> tvH;
241  event.getByToken(label_tv,tvH);
242  TrackingVertexCollection const & tv = *tvH;
243  */
244 
245  // Calculate the number of 3D layers for TPs
246  //
247  // I would have preferred to produce the ValueMap to Event and read
248  // it from there, but there would have been quite some number of
249  // knock-on effects, and again the fact that we take two TP
250  // collections do not support Ref<TP>'s would have complicated that.
251  //
252  // In principle we could use the SimHitTPAssociationList read above
253  // for parametersDefinerIsCosmic_, but since we don't currently
254  // support Ref<TP>s, we can't in general use it since eff/fake TP
255  // collections can, in general, be different.
256  TrackingParticleNumberOfLayers tpNumberOfLayersAlgo(event, simHitTokens_);
257  auto nlayers_tPCeff_ptrs = tpNumberOfLayersAlgo.calculate(TPCollectionHeff, setup);
258  const auto& nLayers_tPCeff = *(std::get<TrackingParticleNumberOfLayers::nTrackerLayers>(nlayers_tPCeff_ptrs));
259  const auto& nPixelLayers_tPCeff = *(std::get<TrackingParticleNumberOfLayers::nPixelLayers>(nlayers_tPCeff_ptrs));
260  const auto& nStripMonoAndStereoLayers_tPCeff = *(std::get<TrackingParticleNumberOfLayers::nStripMonoAndStereoLayers>(nlayers_tPCeff_ptrs));
261 
262  // Precalculate TP selection (for efficiency), and momentum and vertex wrt PCA
263  //
264  // TODO: ParametersDefinerForTP ESProduct needs to be changed to
265  // EDProduct because of consumes.
266  //
267  // In principle, we could just precalculate the momentum and vertex
268  // wrt PCA for all TPs for once and put that to the event. To avoid
269  // repetitive calculations those should be calculated only once for
270  // each TP. That would imply that we should access TPs via Refs
271  // (i.e. View) in here, since, in general, the eff and fake TP
272  // collections can be different (and at least HI seems to use that
273  // feature). This would further imply that the
274  // RecoToSimCollection/SimToRecoCollection should be changed to use
275  // View<TP> instead of vector<TP>, and migrate everything.
276  //
277  // Or we could take only one input TP collection, and do another
278  // TP-selection to obtain the "fake" collection like we already do
279  // for "efficiency" TPs.
280  std::vector<size_t> selected_tPCeff;
281  std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>> momVert_tPCeff;
282  selected_tPCeff.reserve(tPCeff.size());
283  momVert_tPCeff.reserve(tPCeff.size());
285  for(size_t j=0; j<tPCeff.size(); ++j) {
286  TrackingParticleRef tpr(TPCollectionHeff, j);
287  if(cosmictpSelector(tpr,&bs,event,setup)) {
288  selected_tPCeff.push_back(j);
289  TrackingParticle::Vector momentum = parametersDefinerTP->momentum(event,setup,tpr);
290  TrackingParticle::Point vertex = parametersDefinerTP->vertex(event,setup,tpr);
291  momVert_tPCeff.emplace_back(momentum, vertex);
292  }
293  }
294  }
295  else {
296  size_t j=0;
297  for(auto const& tp: tPCeff) {
298  if(tpSelector(tp)) {
299  selected_tPCeff.push_back(j);
300  TrackingParticleRef tpr(TPCollectionHeff, j);
301  TrackingParticle::Vector momentum = parametersDefinerTP->momentum(event,setup,tpr);
302  TrackingParticle::Point vertex = parametersDefinerTP->vertex(event,setup,tpr);
303  momVert_tPCeff.emplace_back(momentum, vertex);
304  }
305  ++j;
306  }
307  }
308 
309  //calculate dR for TPs
310  float dR_tPCeff[tPCeff.size()];
311  {
312  float etaL[tPCeff.size()], phiL[tPCeff.size()];
313  for(size_t iTP: selected_tPCeff) {
314  //calculare dR wrt inclusive collection (also with PU, low pT, displaced)
315  auto const& tp2 = tPCeff[iTP];
316  auto && p = tp2.momentum();
317  etaL[iTP] = etaFromXYZ(p.x(),p.y(),p.z());
318  phiL[iTP] = atan2f(p.y(),p.x());
319  }
320  auto i=0U;
321  for ( auto const & tp : tPCeff) {
323  if(dRtpSelector(tp)) {//only for those needed for efficiency!
324  auto && p = tp.momentum();
325  float eta = etaFromXYZ(p.x(),p.y(),p.z());
326  float phi = atan2f(p.y(),p.x());
327  for(size_t iTP: selected_tPCeff) {
328  //calculare dR wrt inclusive collection (also with PU, low pT, displaced)
329  if (i==iTP) {continue;}
330  auto dR_tmp = reco::deltaR2(eta, phi, etaL[iTP], phiL[iTP]);
331  if (dR_tmp<dR) dR=dR_tmp;
332  } // ttp2 (iTP)
333  }
334  dR_tPCeff[i++] = std::sqrt(dR);
335  } // tp
336  }
337 
338  edm::Handle<View<Track> > trackCollectionForDrCalculation;
339  event.getByToken(labelTokenForDrCalculation, trackCollectionForDrCalculation);
340 
341  // dE/dx
342  // at some point this could be generalized, with a vector of tags and a corresponding vector of Handles
343  // I'm writing the interface such to take vectors of ValueMaps
344  std::vector<const edm::ValueMap<reco::DeDxData> *> v_dEdx;
345  if(dodEdxPlots_) {
348  event.getByToken(m_dEdx1Tag, dEdx1Handle);
349  event.getByToken(m_dEdx2Tag, dEdx2Handle);
350  v_dEdx.push_back(dEdx1Handle.product());
351  v_dEdx.push_back(dEdx2Handle.product());
352  }
353 
354  int w=0; //counter counting the number of sets of histograms
355  for (unsigned int ww=0;ww<associators.size();ww++){
356  for (unsigned int www=0;www<label.size();www++){
357  //
358  //get collections from the event
359  //
361  if(!event.getByToken(labelToken[www], trackCollection)&&ignoremissingtkcollection_)continue;
362 
363  reco::RecoToSimCollection const * recSimCollP=nullptr;
364  reco::SimToRecoCollection const * simRecCollP=nullptr;
365  reco::RecoToSimCollection recSimCollL;
366  reco::SimToRecoCollection simRecCollL;
367 
368  //associate tracks
369  LogTrace("TrackValidator") << "Analyzing "
370  << label[www] << " with "
371  << associators[ww] <<"\n";
372  if(UseAssociators){
374  event.getByToken(associatorTokens[ww], theAssociator);
375 
376  LogTrace("TrackValidator") << "Calling associateRecoToSim method" << "\n";
377  recSimCollL = std::move(theAssociator->associateRecoToSim(trackCollection,
378  TPCollectionHfake));
379  recSimCollP = &recSimCollL;
380  LogTrace("TrackValidator") << "Calling associateSimToReco method" << "\n";
381  simRecCollL = std::move(theAssociator->associateSimToReco(trackCollection,
382  TPCollectionHeff));
383  simRecCollP = &simRecCollL;
384  }
385  else{
386  Handle<reco::SimToRecoCollection > simtorecoCollectionH;
387  event.getByToken(associatormapStRs[ww], simtorecoCollectionH);
388  simRecCollP = simtorecoCollectionH.product();
389 
390  // We need to filter the associations of the current track
391  // collection only from SimToReco collection, otherwise the
392  // SimToReco histograms get false entries
393  simRecCollL = associationMapFilterValues(*simRecCollP, *trackCollection);
394  simRecCollP = &simRecCollL;
395 
396  Handle<reco::RecoToSimCollection > recotosimCollectionH;
397  event.getByToken(associatormapRtSs[ww],recotosimCollectionH);
398  recSimCollP = recotosimCollectionH.product();
399 
400  // In general, we should filter also the RecoToSim collection.
401  // But, that would require changing the input type of TPs to
402  // View<TrackingParticle>, and either replace current
403  // associator interfaces with (View<Track>, View<TP>) or
404  // adding the View,View interface (same goes for
405  // RefToBaseVector,RefToBaseVector). Since there is currently
406  // no compelling-enough use-case, we do not filter the
407  // RecoToSim collection here. If an association using a subset
408  // of the Sim collection is needed, user has to produce such
409  // an association explicitly.
410  }
411 
412  reco::RecoToSimCollection const & recSimColl = *recSimCollP;
413  reco::SimToRecoCollection const & simRecColl = *simRecCollP;
414 
415 
416 
417  // ########################################################
418  // fill simulation histograms (LOOP OVER TRACKINGPARTICLES)
419  // ########################################################
420 
421  //compute number of tracks per eta interval
422  //
423  LogTrace("TrackValidator") << "\n# of TrackingParticles: " << tPCeff.size() << "\n";
424  int ats(0); //This counter counts the number of simTracks that are "associated" to recoTracks
425  int st(0); //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) )
426  unsigned sts(0); //This counter counts the number of simTracks surviving the bunchcrossing cut
427  unsigned asts(0); //This counter counts the number of simTracks that are "associated" to recoTracks surviving the bunchcrossing cut
428 
429  //loop over already-selected TPs for tracking efficiency
430  for(size_t i=0; i<selected_tPCeff.size(); ++i) {
431  size_t iTP = selected_tPCeff[i];
432  TrackingParticleRef tpr(TPCollectionHeff, iTP);
433  const TrackingParticle& tp = tPCeff[iTP];
434 
435  auto const& momVert = momVert_tPCeff[i];
436  TrackingParticle::Vector momentumTP;
437  TrackingParticle::Point vertexTP;
438 
439  double dxySim(0);
440  double dzSim(0);
441  double dR=dR_tPCeff[iTP];
442 
443  //---------- THIS PART HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
444  //If the TrackingParticle is collison like, get the momentum and vertex at production state
446  {
447  momentumTP = tp.momentum();
448  vertexTP = tp.vertex();
449  //Calcualte the impact parameters w.r.t. PCA
450  const TrackingParticle::Vector& momentum = std::get<TrackingParticle::Vector>(momVert);
451  const TrackingParticle::Point& vertex = std::get<TrackingParticle::Point>(momVert);
452  dxySim = (-vertex.x()*sin(momentum.phi())+vertex.y()*cos(momentum.phi()));
453  dzSim = vertex.z() - (vertex.x()*momentum.x()+vertex.y()*momentum.y())/sqrt(momentum.perp2())
454  * momentum.z()/sqrt(momentum.perp2());
455  }
456  //If the TrackingParticle is comics, get the momentum and vertex at PCA
457  else
458  {
459  momentumTP = std::get<TrackingParticle::Vector>(momVert);
460  vertexTP = std::get<TrackingParticle::Point>(momVert);
461  dxySim = (-vertexTP.x()*sin(momentumTP.phi())+vertexTP.y()*cos(momentumTP.phi()));
462  dzSim = vertexTP.z() - (vertexTP.x()*momentumTP.x()+vertexTP.y()*momentumTP.y())/sqrt(momentumTP.perp2())
463  * momentumTP.z()/sqrt(momentumTP.perp2());
464  }
465  //---------- THE PART ABOVE HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
466 
467  //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) ), but only for in-time TPs
468  if(tp.eventId().bunchCrossing() == 0) {
469  st++;
470  }
471 
472  // in the coming lines, histos are filled using as input
473  // - momentumTP
474  // - vertexTP
475  // - dxySim
476  // - dzSim
477 
478  if(doSimPlots_) {
480  }
481  if(!doSimTrackPlots_)
482  continue;
483 
484  // ##############################################
485  // fill RecoAssociated SimTracks' histograms
486  // ##############################################
487  const reco::Track* matchedTrackPointer=0;
488  if(simRecColl.find(tpr) != simRecColl.end()){
489  auto const & rt = simRecColl[tpr];
490  if (rt.size()!=0) {
491  ats++; //This counter counts the number of simTracks that have a recoTrack associated
492  // isRecoMatched = true; // UNUSED
493  matchedTrackPointer = rt.begin()->first.get();
494  LogTrace("TrackValidator") << "TrackingParticle #" << st
495  << " with pt=" << sqrt(momentumTP.perp2())
496  << " associated with quality:" << rt.begin()->second <<"\n";
497  }
498  }else{
499  LogTrace("TrackValidator")
500  << "TrackingParticle #" << st
501  << " with pt,eta,phi: "
502  << sqrt(momentumTP.perp2()) << " , "
503  << momentumTP.eta() << " , "
504  << momentumTP.phi() << " , "
505  << " NOT associated to any reco::Track" << "\n";
506  }
507 
508 
509 
510 
511  int nSimHits = tp.numberOfTrackerHits();
512  int nSimLayers = nLayers_tPCeff[tpr];
513  int nSimPixelLayers = nPixelLayers_tPCeff[tpr];
514  int nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tpr];
515  histoProducerAlgo_->fill_recoAssociated_simTrack_histos(w,tp,momentumTP,vertexTP,dxySim,dzSim,nSimHits,nSimLayers,nSimPixelLayers,nSimStripMonoAndStereoLayers,matchedTrackPointer,puinfo.getPU_NumInteractions(), dR);
516  sts++;
517  h_simul_coll[ww]->Fill(www);
518  if (matchedTrackPointer) {
519  asts++;
520  h_assoc_coll[ww]->Fill(www);
521  }
522 
523 
524 
525 
526  } // End for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){
527 
528  if(doSimPlots_) {
530  }
531 
532 
533  // ##############################################
534  // fill recoTracks histograms (LOOP OVER TRACKS)
535  // ##############################################
536  if(!doRecoTrackPlots_)
537  continue;
538  LogTrace("TrackValidator") << "\n# of reco::Tracks with "
539  << label[www].process()<<":"
540  << label[www].label()<<":"
541  << label[www].instance()
542  << ": " << trackCollection->size() << "\n";
543 
544  int sat(0); //This counter counts the number of recoTracks that are associated to SimTracks from Signal only
545  int at(0); //This counter counts the number of recoTracks that are associated to SimTracks
546  int rT(0); //This counter counts the number of recoTracks in general
547 
548  //calculate dR for tracks
549  float dR_trk[trackCollection->size()];
550  int i=0;
551  float etaL[trackCollectionForDrCalculation->size()];
552  float phiL[trackCollectionForDrCalculation->size()];
553  for (auto const & track2 : *trackCollectionForDrCalculation) {
554  auto && p = track2.momentum();
555  etaL[i] = etaFromXYZ(p.x(),p.y(),p.z());
556  phiL[i] = atan2f(p.y(),p.x());
557  ++i;
558  }
559  for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
560  auto const & track = (*trackCollection)[i];
562  auto && p = track.momentum();
563  float eta = etaFromXYZ(p.x(),p.y(),p.z());
564  float phi = atan2f(p.y(),p.x());
565  for(View<Track>::size_type j=0; j<trackCollectionForDrCalculation->size(); ++j){
566  auto dR_tmp = reco::deltaR2(eta, phi, etaL[j], phiL[j]);
567  if ( (dR_tmp<dR) & (dR_tmp>std::numeric_limits<float>::min())) dR=dR_tmp;
568  }
569  dR_trk[i] = std::sqrt(dR);
570  }
571 
572  for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
573 
574  RefToBase<Track> track(trackCollection, i);
575  rT++;
576 
577  bool isSigSimMatched(false);
578  bool isSimMatched(false);
579  bool isChargeMatched(true);
580  int numAssocRecoTracks = 0;
581  int nSimHits = 0;
582  double sharedFraction = 0.;
583 
584  auto tpFound = recSimColl.find(track);
585  isSimMatched = tpFound != recSimColl.end();
586  if (isSimMatched) {
587  const auto& tp = tpFound->val;
588  nSimHits = tp[0].first->numberOfTrackerHits();
589  sharedFraction = tp[0].second;
590  if (tp[0].first->charge() != track->charge()) isChargeMatched = false;
591  if(simRecColl.find(tp[0].first) != simRecColl.end()) numAssocRecoTracks = simRecColl[tp[0].first].size();
592  at++;
593  for (unsigned int tp_ite=0;tp_ite<tp.size();++tp_ite){
594  TrackingParticle trackpart = *(tp[tp_ite].first);
595  if ((trackpart.eventId().event() == 0) && (trackpart.eventId().bunchCrossing() == 0)){
596  isSigSimMatched = true;
597  sat++;
598  break;
599  }
600  }
601  LogTrace("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
602  << " associated with quality:" << tp.begin()->second <<"\n";
603  } else {
604  LogTrace("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
605  << " NOT associated to any TrackingParticle" << "\n";
606  }
607 
608  double dR=dR_trk[i];
609  histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track,bs.position(),isSimMatched,isSigSimMatched, isChargeMatched, numAssocRecoTracks, puinfo.getPU_NumInteractions(), nSimHits, sharedFraction,dR);
610  h_reco_coll[ww]->Fill(www);
611  if(isSimMatched) {
612  h_assoc2_coll[ww]->Fill(www);
613  if(numAssocRecoTracks>1) {
614  h_looper_coll[ww]->Fill(www);
615  }
616  else if(!isSigSimMatched) {
617  h_pileup_coll[ww]->Fill(www);
618  }
619  }
620 
621  // dE/dx
623 
624 
625  //Fill other histos
626  if (!isSimMatched) continue;
627 
629 
630  TrackingParticleRef tpr = tpFound->val.begin()->first;
631 
632  /* TO BE FIXED LATER
633  if (associators[ww]=="trackAssociatorByChi2"){
634  //association chi2
635  double assocChi2 = -tp.begin()->second;//in association map is stored -chi2
636  h_assochi2[www]->Fill(assocChi2);
637  h_assochi2_prob[www]->Fill(TMath::Prob((assocChi2)*5,5));
638  }
639  else if (associators[ww]=="quickTrackAssociatorByHits"){
640  double fraction = tp.begin()->second;
641  h_assocFraction[www]->Fill(fraction);
642  h_assocSharedHit[www]->Fill(fraction*track->numberOfValidHits());
643  }
644  */
645 
646 
647  //Get tracking particle parameters at point of closest approach to the beamline
648  TrackingParticle::Vector momentumTP = parametersDefinerTP->momentum(event,setup,tpr);
649  TrackingParticle::Point vertexTP = parametersDefinerTP->vertex(event,setup,tpr);
650  int chargeTP = tpr->charge();
651 
652  histoProducerAlgo_->fill_ResoAndPull_recoTrack_histos(w,momentumTP,vertexTP,chargeTP,
653  *track,bs.position());
654 
655 
656  //TO BE FIXED
657  //std::vector<PSimHit> simhits=tpr.get()->trackPSimHit(DetId::Tracker);
658  //nrecHit_vs_nsimHit_rec2sim[w]->Fill(track->numberOfValidHits(), (int)(simhits.end()-simhits.begin() ));
659 
660  } // End of for(View<Track>::size_type i=0; i<trackCollection->size(); ++i){
661 
663 
664  LogTrace("TrackValidator") << "Total Simulated: " << st << "\n"
665  << "Total Associated (simToReco): " << ats << "\n"
666  << "Total Reconstructed: " << rT << "\n"
667  << "Total Associated (recoToSim): " << at << "\n"
668  << "Total Fakes: " << rT-at << "\n";
669 
670  w++;
671  } // End of for (unsigned int www=0;www<label.size();www++){
672  } //END of for (unsigned int ww=0;ww<associators.size();ww++){
673 
674 }
#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
int i
Definition: DBlmapReader.cc:9
std::vector< edm::InputTag > associators
virtual void fill_recoAssociated_simTrack_histos(int count, const TrackingParticle &tp, const TrackingParticle::Vector &momentumTP, const TrackingParticle::Point &vertexTP, double dxy, double dz, int nSimHits, int nSimLayers, int nSimPixelLayers, int nSimStripMonoAndStereoLayers, const reco::Track *track, int numVertices, double dR)=0
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:457
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.
virtual void fill_ResoAndPull_recoTrack_histos(int count, const TrackingParticle::Vector &momentumTP, const TrackingParticle::Point &vertexTP, int chargeTP, const reco::Track &track, const math::XYZPoint &bsPosition)=0
T_AssociationMap associationMapFilterValues(const T_AssociationMap &map, const T_RefVector &valueRefs)
TrackingParticleSelector dRtpSelector
std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associatorTokens
edm::EDGetTokenT< reco::BeamSpot > bsSrc
math::XYZPointD Point
point in the space
std::vector< MonitorElement * > h_looper_coll
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:584
TrackingParticleSelector tpSelector
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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
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
virtual void bookRecoHistos(DQMStore::IBooker &ibook)=0
virtual void bookSimHistos(DQMStore::IBooker &ibook)=0
T min(T a, T b)
Definition: MathUtil.h:58
virtual void bookSimTrackHistos(DQMStore::IBooker &ibook)=0
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
MTVHistoProducerAlgo * histoProducerAlgo_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
virtual void fill_simAssociated_recoTrack_histos(int count, const reco::Track &track)=0
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.
const T & get() const
Definition: EventSetup.h:55
virtual void fill_trackBased_histos(int count, int assTracks, int numRecoTracks, int numSimTracks)=0
std::string const & label() const
Definition: InputTag.h:43
EncodedEventId eventId() const
Signal source, crossing number.
Point vertex() const
Parent vertex position.
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
virtual void fill_generic_recoTrack_histos(int count, const reco::Track &track, const math::XYZPoint &bsPosition, bool isMatched, bool isSigMatched, bool isChargeMatched, int numAssocRecoTracks, int numVertices, int nSimHits, double sharedFraction, double dR)=0
std::vector< MonitorElement * > h_assoc2_coll
Monte Carlo truth information used for tracking validation.
virtual void fill_simTrackBased_histos(int count, int numSimTracks)=0
virtual void fill_dedx_recoTrack_histos(int count, const edm::RefToBase< reco::Track > &trackref, const std::vector< const edm::ValueMap< reco::DeDxData > * > &v_dEdx)=0
int charge() const
track electric charge
Definition: TrackBase.h:530
virtual void bookRecodEdxHistos(DQMStore::IBooker &ibook)=0
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_
virtual void fill_generic_simTrack_histos(int counter, const TrackingParticle::Vector &, const TrackingParticle::Point &vertex, int bx)=0
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.
T get(const Candidate &c)
Definition: component.h:55
edm::EDGetTokenT< edm::ValueMap< reco::DeDxData > > m_dEdx2Tag
Definition: Run.h:41
virtual ~MultiTrackValidator()
Destructor.
list at
Definition: asciidump.py:428
const bool parametersDefinerIsCosmic_