CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackingNtuple.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: NtupleDump/TrackingNtuple
4 // Class: TrackingNtuple
5 //
13 //
14 // Original Author: Giuseppe Cerati
15 // Created: Tue, 25 Aug 2015 13:22:49 GMT
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
36 
39 
42 
46 
53 
56 
61 
66 
69 
77 
80 
82 
83 #include <set>
84 #include <map>
85 #include <unordered_set>
86 #include <unordered_map>
87 
88 #include "TTree.h"
89 
90 /*
91 todo:
92 add refitted hit position after track/seed fit
93 add local angle, path length!
94 */
95 
96 namespace {
97  std::string subdetstring(int subdet) {
98  switch(subdet) {
99  case StripSubdetector::TIB: return "- TIB";
100  case StripSubdetector::TOB: return "- TOB";
101  case StripSubdetector::TEC: return "- TEC";
102  case StripSubdetector::TID: return "- TID";
103  case PixelSubdetector::PixelBarrel: return "- PixBar";
104  case PixelSubdetector::PixelEndcap: return "- PixFwd";
105  default: return "UNKNOWN TRACKER HIT TYPE";
106  }
107  }
108 
109  struct ProductIDSetPrinter {
110  ProductIDSetPrinter(const std::set<edm::ProductID>& set): set_(set) {}
111 
112  void print(std::ostream& os) const {
113  for(const auto& item: set_) {
114  os << item << " ";
115  }
116  }
117 
118  const std::set<edm::ProductID>& set_;
119  };
120  std::ostream& operator<<(std::ostream& os, const ProductIDSetPrinter& o) {
121  o.print(os);
122  return os;
123  }
124  template <typename T>
125  struct ProductIDMapPrinter {
126  ProductIDMapPrinter(const std::map<edm::ProductID, T>& map): map_(map) {}
127 
128  void print(std::ostream& os) const {
129  for(const auto& item: map_) {
130  os << item.first << " ";
131  }
132  }
133 
134  const std::map<edm::ProductID, T>& map_;
135  };
136  template <typename T>
137  auto make_ProductIDMapPrinter(const std::map<edm::ProductID, T>& map) {
138  return ProductIDMapPrinter<T>(map);
139  }
140  template <typename T>
141  std::ostream& operator<<(std::ostream& os, const ProductIDMapPrinter<T>& o) {
142  o.print(os);
143  return os;
144  }
145 
146  template <typename T>
147  struct VectorPrinter {
148  VectorPrinter(const std::vector<T>& vec): vec_(vec) {}
149 
150  void print(std::ostream& os) const {
151  for(const auto& item: vec_) {
152  os << item << " ";
153  }
154  }
155 
156  const std::vector<T>& vec_;
157  };
158  template <typename T>
159  auto make_VectorPrinter(const std::vector<T>& vec) {
160  return VectorPrinter<T>(vec);
161  }
162  template <typename T>
163  std::ostream& operator<<(std::ostream& os, const VectorPrinter<T>& o) {
164  o.print(os);
165  return os;
166  }
167 
168  void checkProductID(const std::set<edm::ProductID>& set, const edm::ProductID& id, const char *name) {
169  if(set.find(id) == set.end())
170  throw cms::Exception("Configuration") << "Got " << name << " with a hit with ProductID " << id
171  << " which does not match to the set of ProductID's for the hits: "
172  << ProductIDSetPrinter(set)
173  << ". Usually this is caused by a wrong hit collection in the configuration.";
174  }
175 
176  template <typename SimLink, typename Func>
177  void forEachMatchedSimLink(const edm::DetSet<SimLink>& digiSimLinks, uint32_t channel, Func func) {
178  for(const auto& link: digiSimLinks) {
179  if(link.channel() == channel) {
180  func(link);
181  }
182  }
183  }
184 
185  std::map<unsigned int, double> chargeFraction(const SiPixelCluster& cluster, const DetId& detId,
186  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink) {
187  std::map<unsigned int, double> simTrackIdToAdc;
188 
189  auto idetset = digiSimLink.find(detId);
190  if(idetset == digiSimLink.end())
191  return simTrackIdToAdc;
192 
193  double adcSum = 0;
195  for(int iPix=0; iPix != cluster.size(); ++iPix) {
196  const SiPixelCluster::Pixel& pixel = cluster.pixel(iPix);
197  adcSum += pixel.adc;
198  uint32_t channel = PixelChannelIdentifier::pixelToChannel(pixel.x, pixel.y);
199  forEachMatchedSimLink(*idetset, channel, [&](const PixelDigiSimLink& simLink){
200  double& adc = simTrackIdToAdc[simLink.SimTrackId()];
201  adc += pixel.adc*simLink.fraction();
202  });
203  }
204 
205  for(auto& pair: simTrackIdToAdc) {
206  if(adcSum == 0.)
207  pair.second = 0.;
208  else
209  pair.second /= adcSum;
210  }
211 
212  return simTrackIdToAdc;
213  }
214 
215  std::map<unsigned int, double> chargeFraction(const SiStripCluster& cluster, const DetId& detId,
216  const edm::DetSetVector<StripDigiSimLink>& digiSimLink) {
217  std::map<unsigned int, double> simTrackIdToAdc;
218 
219  auto idetset = digiSimLink.find(detId);
220  if(idetset == digiSimLink.end())
221  return simTrackIdToAdc;
222 
223  double adcSum = 0;
225  int first = cluster.firstStrip();
226  for(size_t i=0; i<cluster.amplitudes().size(); ++i) {
227  adcSum += cluster.amplitudes()[i];
228  forEachMatchedSimLink(*idetset, first+i, [&](const StripDigiSimLink& simLink){
229  double& adc = simTrackIdToAdc[simLink.SimTrackId()];
230  adc += cluster.amplitudes()[i]*simLink.fraction();
231  });
232 
233  for(const auto& pair: simTrackIdToAdc) {
234  simTrackIdToAdc[pair.first] = (adcSum != 0. ? pair.second/adcSum : 0.);
235  }
236 
237  }
238  return simTrackIdToAdc;
239  }
240 }
241 
242 //
243 // class declaration
244 //
245 
246 class TrackingNtuple : public edm::one::EDAnalyzer<edm::one::SharedResources> {
247 public:
248  explicit TrackingNtuple(const edm::ParameterSet&);
249  ~TrackingNtuple();
250 
251  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
252 
253 
254 private:
255  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
256 
257  void clearVariables();
258 
259  // This pattern is copied from QuickTrackAssociatorByHitsImpl. If
260  // further needs arises, it wouldn't hurt to abstract it somehow.
261  typedef std::unordered_set<reco::RecoToSimCollection::index_type> TrackingParticleRefKeySet;
262  typedef std::unordered_map<reco::RecoToSimCollection::index_type, size_t> TrackingParticleRefKeyToIndex;
264  typedef std::pair<TrackPSimHitRef::key_type, edm::ProductID> SimHitFullKey;
265  typedef std::map<SimHitFullKey, size_t> SimHitRefKeyToIndex;
266 
267  enum class HitType {
268  Pixel = 0,
269  Strip = 1,
270  Glued = 2,
271  Invalid = 3,
272  Unknown = 99
273  };
274 
275  // This gives the "best" classification of a reco hit
276  // In case of reco hit mathing to multiple sim, smaller number is
277  // considered better
278  // To be kept in synch with class HitSimType in ntuple.py
279  enum class HitSimType {
280  Signal = 0,
281  ITPileup = 1,
282  OOTPileup = 2,
283  Noise = 3,
284  Unknown = 99
285  };
286 
287  struct TPHitIndex {
288  TPHitIndex(unsigned int tp=0, unsigned int simHit=0, float to=0, unsigned int id=0): tpKey(tp), simHitIdx(simHit), tof(to), detId(id) {}
289  unsigned int tpKey;
290  unsigned int simHitIdx;
291  float tof;
292  unsigned int detId;
293  };
294  static bool tpHitIndexListLess(const TPHitIndex& i, const TPHitIndex& j) { return (i.tpKey < j.tpKey); }
295  static bool tpHitIndexListLessSort(const TPHitIndex& i, const TPHitIndex& j) {
296  if(i.tpKey == j.tpKey) {
298  return i.detId < j.detId;
299  }
300  return i.tof < j.tof; // works as intended if either one is NaN
301  }
302  return i.tpKey < j.tpKey;
303  }
304 
305  void fillBeamSpot(const reco::BeamSpot& bs);
306  void fillPixelHits(const edm::Event& iEvent,
307  const ClusterTPAssociation& clusterToTPMap,
308  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
310  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink,
311  const TransientTrackingRecHitBuilder& theTTRHBuilder,
312  const TrackerTopology& tTopo,
313  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
314  std::set<edm::ProductID>& hitProductIds
315  );
316 
318  const ClusterTPAssociation& clusterToTPMap,
319  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
321  const edm::DetSetVector<StripDigiSimLink>& digiSimLink,
322  const TransientTrackingRecHitBuilder& theTTRHBuilder,
323  const TrackerTopology& tTopo,
324  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
325  std::set<edm::ProductID>& hitProductIds
326  );
327 
329  const TransientTrackingRecHitBuilder& theTTRHBuilder,
330  const TrackerTopology& tTopo,
331  std::vector<std::pair<int, int> >& monoStereoClusterList
332  );
333 
334  void fillSeeds(const edm::Event& iEvent,
335  const TrackingParticleRefVector& tpCollection,
336  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
337  const reco::BeamSpot& bs,
338  const reco::TrackToTrackingParticleAssociator& associatorByHits,
339  const TransientTrackingRecHitBuilder& theTTRHBuilder,
340  const MagneticField *theMF,
341  const std::vector<std::pair<int, int> >& monoStereoClusterList,
342  const std::set<edm::ProductID>& hitProductIds,
343  std::map<edm::ProductID, size_t>& seedToCollIndex
344  );
345 
347  const TrackingParticleRefVector& tpCollection,
348  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
349  const reco::BeamSpot& bs,
350  const reco::TrackToTrackingParticleAssociator& associatorByHits,
351  const TransientTrackingRecHitBuilder& theTTRHBuilder,
352  const TrackerTopology& tTopo,
353  const std::set<edm::ProductID>& hitProductIds,
354  const std::map<edm::ProductID, size_t>& seedToCollIndex
355  );
356 
357  void fillSimHits(const TrackerGeometry& tracker,
358  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
360  const TrackerTopology& tTopo,
361  SimHitRefKeyToIndex& simHitRefKeyToIndex,
362  std::vector<TPHitIndex>& tpHitList);
363 
364  void fillTrackingParticles(const edm::Event& iEvent, const edm::EventSetup& iSetup,
366  const TrackingParticleRefVector& tpCollection,
367  const TrackingVertexRefKeyToIndex& tvKeyToIndex,
368  const reco::TrackToTrackingParticleAssociator& associatorByHits,
369  const std::vector<TPHitIndex>& tpHitList
370  );
371 
374 
375  void fillTrackingVertices(const TrackingVertexRefVector& trackingVertices,
376  const TrackingParticleRefKeyToIndex& tpKeyToIndex
377  );
378 
379 
380 
381  struct SimHitData {
382  std::vector<int> matchingSimHit;
383  std::vector<float> chargeFraction;
384  std::vector<int> bunchCrossing;
385  std::vector<int> event;
387  };
388 
389  template <typename SimLink>
390  SimHitData matchCluster(const OmniClusterRef& cluster,
391  DetId hitId, int clusterKey,
393  const ClusterTPAssociation& clusterToTPMap,
394  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
396  const edm::DetSetVector<SimLink>& digiSimLinks,
397  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
398  HitType hitType
399  );
400 
401  // ----------member data ---------------------------
402  std::vector<edm::EDGetTokenT<edm::View<reco::Track> > > seedTokens_;
423  const bool includeSeeds_;
424  const bool includeAllHits_;
425 
426  TTree* t;
427  // event
431 
433  // tracks
434  // (first) index runs through tracks
435  std::vector<float> trk_px ;
436  std::vector<float> trk_py ;
437  std::vector<float> trk_pz ;
438  std::vector<float> trk_pt ;
439  std::vector<float> trk_inner_px ;
440  std::vector<float> trk_inner_py ;
441  std::vector<float> trk_inner_pz ;
442  std::vector<float> trk_inner_pt ;
443  std::vector<float> trk_outer_px ;
444  std::vector<float> trk_outer_py ;
445  std::vector<float> trk_outer_pz ;
446  std::vector<float> trk_outer_pt ;
447  std::vector<float> trk_eta ;
448  std::vector<float> trk_lambda ;
449  std::vector<float> trk_cotTheta ;
450  std::vector<float> trk_phi ;
451  std::vector<float> trk_dxy ;
452  std::vector<float> trk_dz ;
453  std::vector<float> trk_ptErr ;
454  std::vector<float> trk_etaErr ;
455  std::vector<float> trk_lambdaErr;
456  std::vector<float> trk_phiErr ;
457  std::vector<float> trk_dxyErr ;
458  std::vector<float> trk_dzErr ;
459  std::vector<float> trk_refpoint_x;
460  std::vector<float> trk_refpoint_y;
461  std::vector<float> trk_refpoint_z;
462  std::vector<float> trk_nChi2 ;
463  std::vector<int> trk_q ;
464  std::vector<unsigned int> trk_nValid ;
465  std::vector<unsigned int> trk_nInvalid;
466  std::vector<unsigned int> trk_nPixel ;
467  std::vector<unsigned int> trk_nStrip ;
468  std::vector<unsigned int> trk_nPixelLay;
469  std::vector<unsigned int> trk_nStripLay;
470  std::vector<unsigned int> trk_n3DLay ;
471  std::vector<unsigned int> trk_nOuterLost;
472  std::vector<unsigned int> trk_nInnerLost;
473  std::vector<unsigned int> trk_algo ;
474  std::vector<unsigned int> trk_originalAlgo;
475  std::vector<decltype(reco::TrackBase().algoMaskUL())> trk_algoMask;
476  std::vector<unsigned int> trk_stopReason;
477  std::vector<short> trk_isHP ;
478  std::vector<int> trk_seedIdx ;
479  std::vector<int> trk_vtxIdx;
480  std::vector<std::vector<float> > trk_shareFrac; // second index runs through matched TrackingParticles
481  std::vector<std::vector<int> > trk_simTrkIdx; // second index runs through matched TrackingParticles
482  std::vector<std::vector<int> > trk_hitIdx; // second index runs through hits
483  std::vector<std::vector<int> > trk_hitType; // second index runs through hits
485  // sim tracks
486  // (first) index runs through TrackingParticles
487  std::vector<int> sim_event ;
488  std::vector<int> sim_bunchCrossing;
489  std::vector<int> sim_pdgId ;
490  std::vector<float> sim_px ;
491  std::vector<float> sim_py ;
492  std::vector<float> sim_pz ;
493  std::vector<float> sim_pt ;
494  std::vector<float> sim_eta ;
495  std::vector<float> sim_phi ;
496  std::vector<float> sim_pca_pt ;
497  std::vector<float> sim_pca_eta ;
498  std::vector<float> sim_pca_lambda;
499  std::vector<float> sim_pca_cotTheta;
500  std::vector<float> sim_pca_phi ;
501  std::vector<float> sim_pca_dxy ;
502  std::vector<float> sim_pca_dz ;
503  std::vector<int> sim_q ;
504  std::vector<unsigned int> sim_nValid ;
505  std::vector<unsigned int> sim_nPixel ;
506  std::vector<unsigned int> sim_nStrip ;
507  std::vector<unsigned int> sim_nLay;
508  std::vector<unsigned int> sim_nPixelLay;
509  std::vector<unsigned int> sim_n3DLay ;
510  std::vector<std::vector<int> > sim_trkIdx; // second index runs through matched tracks
511  std::vector<std::vector<float> > sim_shareFrac; // second index runs through matched tracks
512  std::vector<int> sim_parentVtxIdx;
513  std::vector<std::vector<int> > sim_decayVtxIdx; // second index runs through decay vertices
514  std::vector<std::vector<int> > sim_simHitIdx; // second index runs through SimHits
516  // pixel hits
517  // (first) index runs through hits
518  std::vector<short> pix_isBarrel ;
519  std::vector<unsigned short> pix_det ;
520  std::vector<unsigned short> pix_lay ;
521  std::vector<unsigned int> pix_detId ;
522  std::vector<std::vector<int> > pix_trkIdx; // second index runs through tracks containing this hit
523  std::vector<std::vector<int> > pix_seeIdx; // second index runs through seeds containing this hit
524  std::vector<std::vector<int> > pix_simHitIdx; // second index runs through SimHits inducing this hit
525  std::vector<std::vector<float> > pix_chargeFraction; // second index runs through SimHits inducing this hit
526  std::vector<unsigned short> pix_simType;
527  std::vector<float> pix_x ;
528  std::vector<float> pix_y ;
529  std::vector<float> pix_z ;
530  std::vector<float> pix_xx ;
531  std::vector<float> pix_xy ;
532  std::vector<float> pix_yy ;
533  std::vector<float> pix_yz ;
534  std::vector<float> pix_zz ;
535  std::vector<float> pix_zx ;
536  std::vector<float> pix_radL ; //http://cmslxr.fnal.gov/lxr/source/DataFormats/GeometrySurface/interface/MediumProperties.h
537  std::vector<float> pix_bbxi ;
539  // strip hits
540  // (first) index runs through hits
541  std::vector<short> str_isBarrel ;
542  std::vector<short> str_isStereo ;
543  std::vector<unsigned short> str_det ;
544  std::vector<unsigned short> str_lay ;
545  std::vector<unsigned int> str_detId ;
546  std::vector<std::vector<int> > str_trkIdx; // second index runs through tracks containing this hit
547  std::vector<std::vector<int> > str_seeIdx; // second index runs through seeds containing this hitw
548  std::vector<std::vector<int> > str_simHitIdx; // second index runs through SimHits inducing this hit
549  std::vector<std::vector<float> > str_chargeFraction; // second index runs through SimHits inducing this hit
550  std::vector<unsigned short> str_simType;
551  std::vector<float> str_x ;
552  std::vector<float> str_y ;
553  std::vector<float> str_z ;
554  std::vector<float> str_xx ;
555  std::vector<float> str_xy ;
556  std::vector<float> str_yy ;
557  std::vector<float> str_yz ;
558  std::vector<float> str_zz ;
559  std::vector<float> str_zx ;
560  std::vector<float> str_radL ; //http://cmslxr.fnal.gov/lxr/source/DataFormats/GeometrySurface/interface/MediumProperties.h
561  std::vector<float> str_bbxi ;
563  // strip matched hits
564  // (first) index runs through hits
565  std::vector<short> glu_isBarrel ;
566  std::vector<unsigned int> glu_det ;
567  std::vector<unsigned int> glu_lay ;
568  std::vector<unsigned int> glu_detId ;
569  std::vector<int> glu_monoIdx ;
570  std::vector<int> glu_stereoIdx;
571  std::vector<std::vector<int> > glu_seeIdx; // second index runs through seeds containing this hit
572  std::vector<float> glu_x ;
573  std::vector<float> glu_y ;
574  std::vector<float> glu_z ;
575  std::vector<float> glu_xx ;
576  std::vector<float> glu_xy ;
577  std::vector<float> glu_yy ;
578  std::vector<float> glu_yz ;
579  std::vector<float> glu_zz ;
580  std::vector<float> glu_zx ;
581  std::vector<float> glu_radL ; //http://cmslxr.fnal.gov/lxr/source/DataFormats/GeometrySurface/interface/MediumProperties.h
582  std::vector<float> glu_bbxi ;
584  // invalid (missing/inactive/etc) hits
585  // (first) index runs through hits
586  std::vector<short> inv_isBarrel;
587  std::vector<unsigned short> inv_det;
588  std::vector<unsigned short> inv_lay;
589  std::vector<unsigned int> inv_detId;
590  std::vector<unsigned short> inv_type;
592  // sim hits
593  // (first) index runs through hits
594  std::vector<unsigned short> simhit_det;
595  std::vector<unsigned short> simhit_lay;
596  std::vector<unsigned int> simhit_detId;
597  std::vector<float> simhit_x;
598  std::vector<float> simhit_y;
599  std::vector<float> simhit_z;
600  std::vector<int> simhit_particle;
601  std::vector<short> simhit_process;
602  std::vector<float> simhit_eloss;
603  std::vector<float> simhit_tof;
604  //std::vector<unsigned int> simhit_simTrackId; // can be useful for debugging, but not much of general interest
605  std::vector<int> simhit_simTrkIdx;
606  std::vector<std::vector<int> > simhit_hitIdx; // second index runs through induced reco hits
607  std::vector<std::vector<int> > simhit_hitType; // second index runs through induced reco hits
609  // beam spot
610  float bsp_x;
611  float bsp_y;
612  float bsp_z;
613  float bsp_sigmax;
614  float bsp_sigmay;
615  float bsp_sigmaz;
617  // seeds
618  // (first) index runs through seeds
619  std::vector<short> see_fitok ;
620  std::vector<float> see_px ;
621  std::vector<float> see_py ;
622  std::vector<float> see_pz ;
623  std::vector<float> see_pt ;
624  std::vector<float> see_eta ;
625  std::vector<float> see_phi ;
626  std::vector<float> see_dxy ;
627  std::vector<float> see_dz ;
628  std::vector<float> see_ptErr ;
629  std::vector<float> see_etaErr ;
630  std::vector<float> see_phiErr ;
631  std::vector<float> see_dxyErr ;
632  std::vector<float> see_dzErr ;
633  std::vector<float> see_chi2 ;
634  std::vector<int> see_q ;
635  std::vector<unsigned int> see_nValid ;
636  std::vector<unsigned int> see_nPixel ;
637  std::vector<unsigned int> see_nGlued ;
638  std::vector<unsigned int> see_nStrip ;
639  std::vector<unsigned int> see_algo ;
640  std::vector<int> see_trkIdx;
641  std::vector<std::vector<float> > see_shareFrac; // second index runs through matched TrackingParticles
642  std::vector<std::vector<int> > see_simTrkIdx; // second index runs through matched TrackingParticles
643  std::vector<std::vector<int> > see_hitIdx; // second index runs through hits
644  std::vector<std::vector<int> > see_hitType; // second index runs through hits
645  //seed algo offset, index runs through iterations
646  std::vector<unsigned int> see_offset ;
647 
648 
650  // Vertices
651  // (first) index runs through vertices
652  std::vector<float> vtx_x;
653  std::vector<float> vtx_y;
654  std::vector<float> vtx_z;
655  std::vector<float> vtx_xErr;
656  std::vector<float> vtx_yErr;
657  std::vector<float> vtx_zErr;
658  std::vector<float> vtx_ndof;
659  std::vector<float> vtx_chi2;
660  std::vector<short> vtx_fake;
661  std::vector<short> vtx_valid;
662  std::vector<std::vector<int> > vtx_trkIdx; // second index runs through tracks used in the vertex fit
663 
665  // Tracking vertices
666  // (first) index runs through TrackingVertices
667  std::vector<int> simvtx_event;
668  std::vector<int> simvtx_bunchCrossing;
669  std::vector<unsigned int> simvtx_processType; // only from first SimVertex of TrackingVertex
670  std::vector<float> simvtx_x;
671  std::vector<float> simvtx_y;
672  std::vector<float> simvtx_z;
673  std::vector<std::vector<int> > simvtx_sourceSimIdx; // second index runs through source TrackingParticles
674  std::vector<std::vector<int> > simvtx_daughterSimIdx; // second index runs through daughter TrackingParticles
675  std::vector<int> simpv_idx;
676 };
677 
678 //
679 // constructors and destructor
680 //
682  seedTokens_(edm::vector_transform(iConfig.getUntrackedParameter<std::vector<edm::InputTag> >("seedTracks"), [&](const edm::InputTag& tag) {
683  return consumes<edm::View<reco::Track> >(tag);
684  })),
685  trackToken_(consumes<edm::View<reco::Track> >(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))),
686  clusterTPMapToken_(consumes<ClusterTPAssociation>(iConfig.getUntrackedParameter<edm::InputTag>("clusterTPMap"))),
687  simHitTPMapToken_(consumes<SimHitTPAssociationProducer::SimHitTPAssociationList>(iConfig.getUntrackedParameter<edm::InputTag>("simHitTPMap"))),
688  trackAssociatorToken_(consumes<reco::TrackToTrackingParticleAssociator>(iConfig.getUntrackedParameter<edm::InputTag>("trackAssociator"))),
689  pixelSimLinkToken_(consumes<edm::DetSetVector<PixelDigiSimLink> >(iConfig.getUntrackedParameter<edm::InputTag>("pixelDigiSimLink"))),
690  stripSimLinkToken_(consumes<edm::DetSetVector<StripDigiSimLink> >(iConfig.getUntrackedParameter<edm::InputTag>("stripDigiSimLink"))),
691  beamSpotToken_(consumes<reco::BeamSpot>(iConfig.getUntrackedParameter<edm::InputTag>("beamSpot"))),
692  pixelRecHitToken_(consumes<SiPixelRecHitCollection>(iConfig.getUntrackedParameter<edm::InputTag>("pixelRecHits"))),
693  stripRphiRecHitToken_(consumes<SiStripRecHit2DCollection>(iConfig.getUntrackedParameter<edm::InputTag>("stripRphiRecHits"))),
694  stripStereoRecHitToken_(consumes<SiStripRecHit2DCollection>(iConfig.getUntrackedParameter<edm::InputTag>("stripStereoRecHits"))),
695  stripMatchedRecHitToken_(consumes<SiStripMatchedRecHit2DCollection>(iConfig.getUntrackedParameter<edm::InputTag>("stripMatchedRecHits"))),
696  vertexToken_(consumes<reco::VertexCollection>(iConfig.getUntrackedParameter<edm::InputTag>("vertices"))),
697  trackingVertexToken_(consumes<TrackingVertexCollection>(iConfig.getUntrackedParameter<edm::InputTag>("trackingVertices"))),
698  tpNLayersToken_(consumes<edm::ValueMap<unsigned int> >(iConfig.getUntrackedParameter<edm::InputTag>("trackingParticleNlayers"))),
699  tpNPixelLayersToken_(consumes<edm::ValueMap<unsigned int> >(iConfig.getUntrackedParameter<edm::InputTag>("trackingParticleNpixellayers"))),
700  tpNStripStereoLayersToken_(consumes<edm::ValueMap<unsigned int> >(iConfig.getUntrackedParameter<edm::InputTag>("trackingParticleNstripstereolayers"))),
701  builderName_(iConfig.getUntrackedParameter<std::string>("TTRHBuilder")),
702  parametersDefinerName_(iConfig.getUntrackedParameter<std::string>("parametersDefiner")),
703  includeSeeds_(iConfig.getUntrackedParameter<bool>("includeSeeds")),
704  includeAllHits_(iConfig.getUntrackedParameter<bool>("includeAllHits"))
705 {
706  const bool tpRef = iConfig.getUntrackedParameter<bool>("trackingParticlesRef");
707  const auto tpTag = iConfig.getUntrackedParameter<edm::InputTag>("trackingParticles");
708  if(tpRef) {
709  trackingParticleRefToken_ = consumes<TrackingParticleRefVector>(tpTag);
710  }
711  else {
712  trackingParticleToken_ = consumes<TrackingParticleCollection>(tpTag);
713  }
714 
717  t = fs->make<TTree>("tree","tree");
718 
719  t->Branch("event" , &ev_event);
720  t->Branch("lumi" , &ev_lumi);
721  t->Branch("run" , &ev_run);
722 
723  //tracks
724  t->Branch("trk_px" , &trk_px);
725  t->Branch("trk_py" , &trk_py);
726  t->Branch("trk_pz" , &trk_pz);
727  t->Branch("trk_pt" , &trk_pt);
728  t->Branch("trk_inner_px" , &trk_inner_px);
729  t->Branch("trk_inner_py" , &trk_inner_py);
730  t->Branch("trk_inner_pz" , &trk_inner_pz);
731  t->Branch("trk_inner_pt" , &trk_inner_pt);
732  t->Branch("trk_outer_px" , &trk_outer_px);
733  t->Branch("trk_outer_py" , &trk_outer_py);
734  t->Branch("trk_outer_pz" , &trk_outer_pz);
735  t->Branch("trk_outer_pt" , &trk_outer_pt);
736  t->Branch("trk_eta" , &trk_eta);
737  t->Branch("trk_lambda" , &trk_lambda);
738  t->Branch("trk_cotTheta" , &trk_cotTheta);
739  t->Branch("trk_phi" , &trk_phi);
740  t->Branch("trk_dxy" , &trk_dxy );
741  t->Branch("trk_dz" , &trk_dz );
742  t->Branch("trk_ptErr" , &trk_ptErr );
743  t->Branch("trk_etaErr" , &trk_etaErr );
744  t->Branch("trk_lambdaErr", &trk_lambdaErr);
745  t->Branch("trk_phiErr" , &trk_phiErr );
746  t->Branch("trk_dxyErr" , &trk_dxyErr );
747  t->Branch("trk_dzErr" , &trk_dzErr );
748  t->Branch("trk_refpoint_x", &trk_refpoint_x);
749  t->Branch("trk_refpoint_y", &trk_refpoint_y);
750  t->Branch("trk_refpoint_z", &trk_refpoint_z);
751  t->Branch("trk_nChi2" , &trk_nChi2);
752  t->Branch("trk_q" , &trk_q);
753  t->Branch("trk_nValid" , &trk_nValid );
754  t->Branch("trk_nInvalid" , &trk_nInvalid);
755  t->Branch("trk_nPixel" , &trk_nPixel );
756  t->Branch("trk_nStrip" , &trk_nStrip );
757  t->Branch("trk_nPixelLay", &trk_nPixelLay);
758  t->Branch("trk_nStripLay", &trk_nStripLay);
759  t->Branch("trk_n3DLay" , &trk_n3DLay );
760  t->Branch("trk_nOuterLost", &trk_nOuterLost );
761  t->Branch("trk_nInnerLost", &trk_nInnerLost );
762  t->Branch("trk_algo" , &trk_algo );
763  t->Branch("trk_originalAlgo", &trk_originalAlgo);
764  t->Branch("trk_algoMask" , &trk_algoMask);
765  t->Branch("trk_stopReason", &trk_stopReason);
766  t->Branch("trk_isHP" , &trk_isHP );
768  t->Branch("trk_seedIdx" , &trk_seedIdx );
769  }
770  t->Branch("trk_vtxIdx" , &trk_vtxIdx);
771  t->Branch("trk_shareFrac", &trk_shareFrac);
772  t->Branch("trk_simTrkIdx", &trk_simTrkIdx );
773  if(includeAllHits_) {
774  t->Branch("trk_hitIdx" , &trk_hitIdx);
775  t->Branch("trk_hitType", &trk_hitType);
776  }
777  //sim tracks
778  t->Branch("sim_event" , &sim_event );
779  t->Branch("sim_bunchCrossing", &sim_bunchCrossing);
780  t->Branch("sim_pdgId" , &sim_pdgId );
781  t->Branch("sim_px" , &sim_px );
782  t->Branch("sim_py" , &sim_py );
783  t->Branch("sim_pz" , &sim_pz );
784  t->Branch("sim_pt" , &sim_pt );
785  t->Branch("sim_eta" , &sim_eta );
786  t->Branch("sim_phi" , &sim_phi );
787  t->Branch("sim_pca_pt" , &sim_pca_pt );
788  t->Branch("sim_pca_eta" , &sim_pca_eta );
789  t->Branch("sim_pca_lambda", &sim_pca_lambda);
790  t->Branch("sim_pca_cotTheta", &sim_pca_cotTheta);
791  t->Branch("sim_pca_phi" , &sim_pca_phi );
792  t->Branch("sim_pca_dxy" , &sim_pca_dxy );
793  t->Branch("sim_pca_dz" , &sim_pca_dz );
794  t->Branch("sim_q" , &sim_q );
795  t->Branch("sim_nValid" , &sim_nValid );
796  t->Branch("sim_nPixel" , &sim_nPixel );
797  t->Branch("sim_nStrip" , &sim_nStrip );
798  t->Branch("sim_nLay" , &sim_nLay );
799  t->Branch("sim_nPixelLay", &sim_nPixelLay);
800  t->Branch("sim_n3DLay" , &sim_n3DLay );
801  t->Branch("sim_trkIdx" , &sim_trkIdx );
802  t->Branch("sim_shareFrac", &sim_shareFrac);
803  t->Branch("sim_parentVtxIdx", &sim_parentVtxIdx);
804  t->Branch("sim_decayVtxIdx", &sim_decayVtxIdx);
805  if(includeAllHits_) {
806  t->Branch("sim_simHitIdx" , &sim_simHitIdx );
807  }
808  if(includeAllHits_) {
809  //pixels
810  t->Branch("pix_isBarrel" , &pix_isBarrel );
811  t->Branch("pix_det" , &pix_det );
812  t->Branch("pix_lay" , &pix_lay );
813  t->Branch("pix_detId" , &pix_detId );
814  t->Branch("pix_trkIdx" , &pix_trkIdx );
815  if(includeSeeds_) {
816  t->Branch("pix_seeIdx" , &pix_seeIdx );
817  }
818  t->Branch("pix_simHitIdx" , &pix_simHitIdx);
819  t->Branch("pix_chargeFraction", &pix_chargeFraction);
820  t->Branch("pix_simType", &pix_simType);
821  t->Branch("pix_x" , &pix_x );
822  t->Branch("pix_y" , &pix_y );
823  t->Branch("pix_z" , &pix_z );
824  t->Branch("pix_xx" , &pix_xx );
825  t->Branch("pix_xy" , &pix_xy );
826  t->Branch("pix_yy" , &pix_yy );
827  t->Branch("pix_yz" , &pix_yz );
828  t->Branch("pix_zz" , &pix_zz );
829  t->Branch("pix_zx" , &pix_zx );
830  t->Branch("pix_radL" , &pix_radL );
831  t->Branch("pix_bbxi" , &pix_bbxi );
832  t->Branch("pix_bbxi" , &pix_bbxi );
833  //strips
834  t->Branch("str_isBarrel" , &str_isBarrel );
835  t->Branch("str_isStereo" , &str_isStereo );
836  t->Branch("str_det" , &str_det );
837  t->Branch("str_lay" , &str_lay );
838  t->Branch("str_detId" , &str_detId );
839  t->Branch("str_trkIdx" , &str_trkIdx );
840  if(includeSeeds_) {
841  t->Branch("str_seeIdx" , &str_seeIdx );
842  }
843  t->Branch("str_simHitIdx" , &str_simHitIdx);
844  t->Branch("str_chargeFraction", &str_chargeFraction);
845  t->Branch("str_simType", &str_simType);
846  t->Branch("str_x" , &str_x );
847  t->Branch("str_y" , &str_y );
848  t->Branch("str_z" , &str_z );
849  t->Branch("str_xx" , &str_xx );
850  t->Branch("str_xy" , &str_xy );
851  t->Branch("str_yy" , &str_yy );
852  t->Branch("str_yz" , &str_yz );
853  t->Branch("str_zz" , &str_zz );
854  t->Branch("str_zx" , &str_zx );
855  t->Branch("str_radL" , &str_radL );
856  t->Branch("str_bbxi" , &str_bbxi );
857  //matched hits
858  t->Branch("glu_isBarrel" , &glu_isBarrel );
859  t->Branch("glu_det" , &glu_det );
860  t->Branch("glu_lay" , &glu_lay );
861  t->Branch("glu_detId" , &glu_detId );
862  t->Branch("glu_monoIdx" , &glu_monoIdx );
863  t->Branch("glu_stereoIdx" , &glu_stereoIdx);
864  if(includeSeeds_) {
865  t->Branch("glu_seeIdx" , &glu_seeIdx );
866  }
867  t->Branch("glu_x" , &glu_x );
868  t->Branch("glu_y" , &glu_y );
869  t->Branch("glu_z" , &glu_z );
870  t->Branch("glu_xx" , &glu_xx );
871  t->Branch("glu_xy" , &glu_xy );
872  t->Branch("glu_yy" , &glu_yy );
873  t->Branch("glu_yz" , &glu_yz );
874  t->Branch("glu_zz" , &glu_zz );
875  t->Branch("glu_zx" , &glu_zx );
876  t->Branch("glu_radL" , &glu_radL );
877  t->Branch("glu_bbxi" , &glu_bbxi );
878  //invalid hits
879  t->Branch("inv_isBarrel" , &inv_isBarrel );
880  t->Branch("inv_det" , &inv_det );
881  t->Branch("inv_lay" , &inv_lay );
882  t->Branch("inv_detId" , &inv_detId );
883  t->Branch("inv_type" , &inv_type );
884  //simhits
885  t->Branch("simhit_det" , &simhit_det);
886  t->Branch("simhit_lay" , &simhit_lay);
887  t->Branch("simhit_detId" , &simhit_detId);
888  t->Branch("simhit_x" , &simhit_x);
889  t->Branch("simhit_y" , &simhit_y);
890  t->Branch("simhit_z" , &simhit_z);
891  t->Branch("simhit_particle", &simhit_particle);
892  t->Branch("simhit_process" , &simhit_process);
893  t->Branch("simhit_eloss" , &simhit_eloss);
894  t->Branch("simhit_tof" , &simhit_tof);
895  //t->Branch("simhit_simTrackId", &simhit_simTrackId);
896  t->Branch("simhit_simTrkIdx", &simhit_simTrkIdx);
897  t->Branch("simhit_hitIdx" , &simhit_hitIdx);
898  t->Branch("simhit_hitType" , &simhit_hitType);
899  }
900  //beam spot
901  t->Branch("bsp_x" , &bsp_x , "bsp_x/F");
902  t->Branch("bsp_y" , &bsp_y , "bsp_y/F");
903  t->Branch("bsp_z" , &bsp_z , "bsp_z/F");
904  t->Branch("bsp_sigmax" , &bsp_sigmax , "bsp_sigmax/F");
905  t->Branch("bsp_sigmay" , &bsp_sigmay , "bsp_sigmay/F");
906  t->Branch("bsp_sigmaz" , &bsp_sigmaz , "bsp_sigmaz/F");
907  if(includeSeeds_) {
908  //seeds
909  t->Branch("see_fitok" , &see_fitok );
910  t->Branch("see_px" , &see_px );
911  t->Branch("see_py" , &see_py );
912  t->Branch("see_pz" , &see_pz );
913  t->Branch("see_pt" , &see_pt );
914  t->Branch("see_eta" , &see_eta );
915  t->Branch("see_phi" , &see_phi );
916  t->Branch("see_dxy" , &see_dxy );
917  t->Branch("see_dz" , &see_dz );
918  t->Branch("see_ptErr" , &see_ptErr );
919  t->Branch("see_etaErr" , &see_etaErr );
920  t->Branch("see_phiErr" , &see_phiErr );
921  t->Branch("see_dxyErr" , &see_dxyErr );
922  t->Branch("see_dzErr" , &see_dzErr );
923  t->Branch("see_chi2" , &see_chi2 );
924  t->Branch("see_q" , &see_q );
925  t->Branch("see_nValid" , &see_nValid );
926  t->Branch("see_nPixel" , &see_nPixel );
927  t->Branch("see_nGlued" , &see_nGlued );
928  t->Branch("see_nStrip" , &see_nStrip );
929  t->Branch("see_algo" , &see_algo );
930  t->Branch("see_trkIdx" , &see_trkIdx );
931  t->Branch("see_shareFrac", &see_shareFrac);
932  t->Branch("see_simTrkIdx", &see_simTrkIdx );
933  if(includeAllHits_) {
934  t->Branch("see_hitIdx" , &see_hitIdx );
935  t->Branch("see_hitType", &see_hitType );
936  }
937  //seed algo offset
938  t->Branch("see_offset" , &see_offset );
939  }
940 
941  //vertices
942  t->Branch("vtx_x" , &vtx_x);
943  t->Branch("vtx_y" , &vtx_y);
944  t->Branch("vtx_z" , &vtx_z);
945  t->Branch("vtx_xErr" , &vtx_xErr);
946  t->Branch("vtx_yErr" , &vtx_yErr);
947  t->Branch("vtx_zErr" , &vtx_zErr);
948  t->Branch("vtx_ndof" , &vtx_ndof);
949  t->Branch("vtx_chi2" , &vtx_chi2);
950  t->Branch("vtx_fake" , &vtx_fake);
951  t->Branch("vtx_valid" , &vtx_valid);
952  t->Branch("vtx_trkIdx" , &vtx_trkIdx);
953 
954  // tracking vertices
955  t->Branch("simvtx_event" , &simvtx_event );
956  t->Branch("simvtx_bunchCrossing", &simvtx_bunchCrossing);
957  t->Branch("simvtx_processType", &simvtx_processType);
958  t->Branch("simvtx_x" , &simvtx_x);
959  t->Branch("simvtx_y" , &simvtx_y);
960  t->Branch("simvtx_z" , &simvtx_z);
961  t->Branch("simvtx_sourceSimIdx", &simvtx_sourceSimIdx);
962  t->Branch("simvtx_daughterSimIdx", &simvtx_daughterSimIdx);
963 
964  t->Branch("simpv_idx" , &simpv_idx);
965 
966  //t->Branch("" , &);
967 }
968 
969 
971  // do anything here that needs to be done at desctruction time
972  // (e.g. close files, deallocate resources etc.)
973 }
974 
975 
976 //
977 // member functions
978 //
980 
981  ev_run = 0;
982  ev_lumi = 0;
983  ev_event = 0;
984 
985  //tracks
986  trk_px .clear();
987  trk_py .clear();
988  trk_pz .clear();
989  trk_pt .clear();
990  trk_inner_px .clear();
991  trk_inner_py .clear();
992  trk_inner_pz .clear();
993  trk_inner_pt .clear();
994  trk_outer_px .clear();
995  trk_outer_py .clear();
996  trk_outer_pz .clear();
997  trk_outer_pt .clear();
998  trk_eta .clear();
999  trk_lambda .clear();
1000  trk_cotTheta .clear();
1001  trk_phi .clear();
1002  trk_dxy .clear();
1003  trk_dz .clear();
1004  trk_ptErr .clear();
1005  trk_etaErr .clear();
1006  trk_lambdaErr.clear();
1007  trk_phiErr .clear();
1008  trk_dxyErr .clear();
1009  trk_dzErr .clear();
1010  trk_refpoint_x.clear();
1011  trk_refpoint_y.clear();
1012  trk_refpoint_z.clear();
1013  trk_nChi2 .clear();
1014  trk_q .clear();
1015  trk_nValid .clear();
1016  trk_nInvalid .clear();
1017  trk_nPixel .clear();
1018  trk_nStrip .clear();
1019  trk_nPixelLay.clear();
1020  trk_nStripLay.clear();
1021  trk_n3DLay .clear();
1022  trk_nOuterLost.clear();
1023  trk_nInnerLost.clear();
1024  trk_algo .clear();
1025  trk_originalAlgo.clear();
1026  trk_algoMask .clear();
1027  trk_stopReason.clear();
1028  trk_isHP .clear();
1029  trk_seedIdx .clear();
1030  trk_vtxIdx .clear();
1031  trk_shareFrac.clear();
1032  trk_simTrkIdx.clear();
1033  trk_hitIdx .clear();
1034  trk_hitType .clear();
1035  //sim tracks
1036  sim_event .clear();
1037  sim_bunchCrossing.clear();
1038  sim_pdgId .clear();
1039  sim_px .clear();
1040  sim_py .clear();
1041  sim_pz .clear();
1042  sim_pt .clear();
1043  sim_eta .clear();
1044  sim_phi .clear();
1045  sim_pca_pt .clear();
1046  sim_pca_eta .clear();
1047  sim_pca_lambda.clear();
1048  sim_pca_cotTheta.clear();
1049  sim_pca_phi .clear();
1050  sim_pca_dxy .clear();
1051  sim_pca_dz .clear();
1052  sim_q .clear();
1053  sim_nValid .clear();
1054  sim_nPixel .clear();
1055  sim_nStrip .clear();
1056  sim_nLay .clear();
1057  sim_nPixelLay.clear();
1058  sim_n3DLay .clear();
1059  sim_trkIdx .clear();
1060  sim_shareFrac.clear();
1061  sim_parentVtxIdx.clear();
1062  sim_decayVtxIdx.clear();
1063  sim_simHitIdx .clear();
1064  //pixels
1065  pix_isBarrel .clear();
1066  pix_det .clear();
1067  pix_lay .clear();
1068  pix_detId .clear();
1069  pix_trkIdx .clear();
1070  pix_seeIdx .clear();
1071  pix_simHitIdx.clear();
1072  pix_chargeFraction.clear();
1073  pix_simType.clear();
1074  pix_x .clear();
1075  pix_y .clear();
1076  pix_z .clear();
1077  pix_xx .clear();
1078  pix_xy .clear();
1079  pix_yy .clear();
1080  pix_yz .clear();
1081  pix_zz .clear();
1082  pix_zx .clear();
1083  pix_radL .clear();
1084  pix_bbxi .clear();
1085  //strips
1086  str_isBarrel .clear();
1087  str_isStereo .clear();
1088  str_det .clear();
1089  str_lay .clear();
1090  str_detId .clear();
1091  str_trkIdx .clear();
1092  str_seeIdx .clear();
1093  str_simHitIdx.clear();
1094  str_chargeFraction.clear();
1095  str_simType.clear();
1096  str_x .clear();
1097  str_y .clear();
1098  str_z .clear();
1099  str_xx .clear();
1100  str_xy .clear();
1101  str_yy .clear();
1102  str_yz .clear();
1103  str_zz .clear();
1104  str_zx .clear();
1105  str_radL .clear();
1106  str_bbxi .clear();
1107  //matched hits
1108  glu_isBarrel .clear();
1109  glu_det .clear();
1110  glu_lay .clear();
1111  glu_detId .clear();
1112  glu_monoIdx .clear();
1113  glu_stereoIdx.clear();
1114  glu_seeIdx .clear();
1115  glu_x .clear();
1116  glu_y .clear();
1117  glu_z .clear();
1118  glu_xx .clear();
1119  glu_xy .clear();
1120  glu_yy .clear();
1121  glu_yz .clear();
1122  glu_zz .clear();
1123  glu_zx .clear();
1124  glu_radL .clear();
1125  glu_bbxi .clear();
1126  //invalid hits
1127  inv_isBarrel .clear();
1128  inv_det .clear();
1129  inv_lay .clear();
1130  inv_detId .clear();
1131  inv_type .clear();
1132  // simhits
1133  simhit_det.clear();
1134  simhit_lay.clear();
1135  simhit_detId.clear();
1136  simhit_x.clear();
1137  simhit_y.clear();
1138  simhit_z.clear();
1139  simhit_particle.clear();
1140  simhit_process.clear();
1141  simhit_eloss.clear();
1142  simhit_tof.clear();
1143  //simhit_simTrackId.clear();
1144  simhit_simTrkIdx.clear();
1145  simhit_hitIdx.clear();
1146  simhit_hitType.clear();
1147  //beamspot
1148  bsp_x = -9999.;
1149  bsp_y = -9999.;
1150  bsp_z = -9999.;
1151  bsp_sigmax = -9999.;
1152  bsp_sigmay = -9999.;
1153  bsp_sigmaz = -9999.;
1154  //seeds
1155  see_fitok .clear();
1156  see_px .clear();
1157  see_py .clear();
1158  see_pz .clear();
1159  see_pt .clear();
1160  see_eta .clear();
1161  see_phi .clear();
1162  see_dxy .clear();
1163  see_dz .clear();
1164  see_ptErr .clear();
1165  see_etaErr .clear();
1166  see_phiErr .clear();
1167  see_dxyErr .clear();
1168  see_dzErr .clear();
1169  see_chi2 .clear();
1170  see_q .clear();
1171  see_nValid .clear();
1172  see_nPixel .clear();
1173  see_nGlued .clear();
1174  see_nStrip .clear();
1175  see_algo .clear();
1176  see_trkIdx .clear();
1177  see_shareFrac.clear();
1178  see_simTrkIdx.clear();
1179  see_hitIdx .clear();
1180  see_hitType .clear();
1181  //seed algo offset
1182  see_offset.clear();
1183 
1184  // vertices
1185  vtx_x.clear();
1186  vtx_y.clear();
1187  vtx_z.clear();
1188  vtx_xErr.clear();
1189  vtx_yErr.clear();
1190  vtx_zErr.clear();
1191  vtx_ndof.clear();
1192  vtx_chi2.clear();
1193  vtx_fake.clear();
1194  vtx_valid.clear();
1195  vtx_trkIdx.clear();
1196 
1197  // Tracking vertices
1198  simvtx_event.clear();
1199  simvtx_bunchCrossing.clear();
1200  simvtx_x.clear();
1201  simvtx_y.clear();
1202  simvtx_z.clear();
1203  simvtx_sourceSimIdx.clear();
1204  simvtx_daughterSimIdx.clear();
1205  simpv_idx.clear();
1206 }
1207 
1208 
1209 // ------------ method called for each event ------------
1211 
1212  using namespace edm;
1213  using namespace reco;
1214  using namespace std;
1215 
1217  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
1218 
1220  iSetup.get<TransientRecHitRecord>().get(builderName_,theTTRHBuilder);
1221 
1222  edm::ESHandle<TrackerTopology> tTopoHandle;
1223  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
1224  const TrackerTopology& tTopo = *tTopoHandle;
1225 
1226  edm::ESHandle<TrackerGeometry> geometryHandle;
1227  iSetup.get<TrackerDigiGeometryRecord>().get(geometryHandle);
1228  const TrackerGeometry &tracker = *geometryHandle;
1229 
1231  iEvent.getByToken(trackAssociatorToken_, theAssociator);
1232  const reco::TrackToTrackingParticleAssociator& associatorByHits = *theAssociator;
1233 
1234  LogDebug("TrackingNtuple") << "Analyzing new event";
1235 
1236  //initialize tree variables
1237  clearVariables();
1238 
1239  // FIXME: we really need to move to edm::View for reading the
1240  // TrackingParticles... Unfortunately it has non-trivial
1241  // consequences on the associator/association interfaces etc.
1243  TrackingParticleRefKeySet tmpTPkeys;
1244  const TrackingParticleRefVector *tmpTPptr = nullptr;
1246  edm::Handle<TrackingParticleRefVector> TPCollectionHRefVector;
1247 
1249  iEvent.getByToken(trackingParticleToken_, TPCollectionH);
1250  for(size_t i=0, size=TPCollectionH->size(); i<size; ++i) {
1251  tmpTP.push_back(TrackingParticleRef(TPCollectionH, i));
1252  }
1253  tmpTPptr = &tmpTP;
1254  }
1255  else {
1256  iEvent.getByToken(trackingParticleRefToken_, TPCollectionHRefVector);
1257  tmpTPptr = TPCollectionHRefVector.product();
1258  for(const auto& ref: *tmpTPptr) {
1259  tmpTPkeys.insert(ref.key());
1260  }
1261  }
1262  const TrackingParticleRefVector& tpCollection = *tmpTPptr;
1263 
1264  // Fill mapping from Ref::key() to index
1265  TrackingParticleRefKeyToIndex tpKeyToIndex;
1266  for(size_t i=0; i<tpCollection.size(); ++i) {
1267  tpKeyToIndex[tpCollection[i].key()] = i;
1268  }
1269 
1270  // tracking vertices
1272  iEvent.getByToken(trackingVertexToken_, htv);
1273  const TrackingVertexCollection& tvs = *htv;
1274 
1275  // Fill mapping from Ref::key() to index
1276  TrackingVertexRefVector tvRefs;
1277  TrackingVertexRefKeyToIndex tvKeyToIndex;
1278  for(size_t i=0; i<tvs.size(); ++i) {
1279  const TrackingVertex& v = tvs[i];
1280  if(v.eventId().bunchCrossing() != 0) // Ignore OOTPU; would be better to not to hardcode?
1281  continue;
1282  tvKeyToIndex[i] = tvRefs.size();
1283  tvRefs.push_back(TrackingVertexRef(htv, i));
1284  }
1285 
1286  //get association maps, etc.
1287  Handle<ClusterTPAssociation> pCluster2TPListH;
1288  iEvent.getByToken(clusterTPMapToken_, pCluster2TPListH);
1289  const ClusterTPAssociation& clusterToTPMap = *pCluster2TPListH;
1291  iEvent.getByToken(simHitTPMapToken_, simHitsTPAssoc);
1292 
1293  // SimHit key -> index mapping
1294  SimHitRefKeyToIndex simHitRefKeyToIndex;
1295 
1296  //make a list to link TrackingParticles to its simhits
1297  std::vector<TPHitIndex> tpHitList;
1298 
1299  std::set<edm::ProductID> hitProductIds;
1300  std::map<edm::ProductID, size_t> seedCollToOffset;
1301 
1302  ev_run = iEvent.id().run();
1303  ev_lumi = iEvent.id().luminosityBlock();
1304  ev_event = iEvent.id().event();
1305 
1306  // Digi->Sim links for pixels and strips
1307  edm::Handle<edm::DetSetVector<PixelDigiSimLink> > pixelDigiSimLinksHandle;
1308  iEvent.getByToken(pixelSimLinkToken_, pixelDigiSimLinksHandle);
1309  const auto& pixelDigiSimLinks = *pixelDigiSimLinksHandle;
1310 
1311  edm::Handle<edm::DetSetVector<StripDigiSimLink> > stripDigiSimLinksHandle;
1312  iEvent.getByToken(stripSimLinkToken_, stripDigiSimLinksHandle);
1313  const auto& stripDigiSimLinks = *stripDigiSimLinksHandle;
1314 
1315  //beamspot
1316  Handle<reco::BeamSpot> recoBeamSpotHandle;
1317  iEvent.getByToken(beamSpotToken_, recoBeamSpotHandle);
1318  BeamSpot const & bs = *recoBeamSpotHandle;
1319  fillBeamSpot(bs);
1320 
1321  //prapare list to link matched hits to collection
1322  vector<pair<int,int> > monoStereoClusterList;
1323  if(includeAllHits_) {
1324  // simhits
1325  fillSimHits(tracker, tpKeyToIndex, *simHitsTPAssoc, tTopo, simHitRefKeyToIndex, tpHitList);
1326 
1327  //pixel hits
1328  fillPixelHits(iEvent, clusterToTPMap, tpKeyToIndex, *simHitsTPAssoc, pixelDigiSimLinks, *theTTRHBuilder, tTopo, simHitRefKeyToIndex, hitProductIds);
1329 
1330  //strip hits
1331  fillStripRphiStereoHits(iEvent, clusterToTPMap, tpKeyToIndex, *simHitsTPAssoc, stripDigiSimLinks, *theTTRHBuilder, tTopo, simHitRefKeyToIndex, hitProductIds);
1332 
1333  //matched hits
1334  fillStripMatchedHits(iEvent, *theTTRHBuilder, tTopo, monoStereoClusterList);
1335  }
1336 
1337  //seeds
1338  if(includeSeeds_) {
1339  fillSeeds(iEvent, tpCollection, tpKeyToIndex, bs, associatorByHits, *theTTRHBuilder, theMF.product(), monoStereoClusterList, hitProductIds, seedCollToOffset);
1340  }
1341 
1342  //tracks
1343  edm::Handle<edm::View<reco::Track> > tracksHandle;
1344  iEvent.getByToken(trackToken_, tracksHandle);
1345  const edm::View<reco::Track>& tracks = *tracksHandle;
1346  // The associator interfaces really need to be fixed...
1348  for(edm::View<Track>::size_type i=0; i<tracks.size(); ++i) {
1349  trackRefs.push_back(tracks.refAt(i));
1350  }
1351  fillTracks(trackRefs, tpCollection, tpKeyToIndex, bs, associatorByHits, *theTTRHBuilder, tTopo, hitProductIds, seedCollToOffset);
1352 
1353  //tracking particles
1354  //sort association maps with simHits
1355  std::sort( tpHitList.begin(), tpHitList.end(), tpHitIndexListLessSort );
1356  fillTrackingParticles(iEvent, iSetup, trackRefs, tpCollection, tvKeyToIndex, associatorByHits, tpHitList);
1357 
1358  // vertices
1360  iEvent.getByToken(vertexToken_, vertices);
1361  fillVertices(*vertices, trackRefs);
1362 
1363  // tracking vertices
1364  fillTrackingVertices(tvRefs, tpKeyToIndex);
1365 
1366  t->Fill();
1367 
1368 }
1369 
1371  bsp_x = bs.x0();
1372  bsp_y = bs.y0();
1373  bsp_z = bs.x0();
1374  bsp_sigmax = bs.BeamWidthX();
1375  bsp_sigmay = bs.BeamWidthY();
1376  bsp_sigmaz = bs.sigmaZ();
1377 }
1378 
1379 namespace {
1380  template <typename SimLink> struct GetCluster;
1381  template <>
1382  struct GetCluster<PixelDigiSimLink> {
1383  static const SiPixelCluster& call(const OmniClusterRef& cluster) { return cluster.pixelCluster(); }
1384  };
1385  template <>
1386  struct GetCluster<StripDigiSimLink> {
1387  static const SiStripCluster& call(const OmniClusterRef& cluster) { return cluster.stripCluster(); }
1388  };
1389 }
1390 
1391 template <typename SimLink>
1393  DetId hitId, int clusterKey,
1395  const ClusterTPAssociation& clusterToTPMap,
1396  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
1398  const edm::DetSetVector<SimLink>& digiSimLinks,
1399  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
1400  HitType hitType
1401  ) {
1402  SimHitData ret;
1403 
1404  auto simTrackIdToChargeFraction = chargeFraction(GetCluster<SimLink>::call(cluster), hitId, digiSimLinks);
1405 
1406  ret.type = HitSimType::Noise;
1407  auto range = clusterToTPMap.equal_range( cluster );
1408  if( range.first != range.second ) {
1409  for( auto ip=range.first; ip != range.second; ++ip ) {
1410  const TrackingParticleRef& trackingParticle = ip->second;
1411 
1412  // Find out if the cluster is from signal/ITPU/OOTPU
1413  const auto event = trackingParticle->eventId().event();
1414  const auto bx = trackingParticle->eventId().bunchCrossing();
1416  if(bx == 0) {
1417  type = (event == 0 ? HitSimType::Signal : HitSimType::ITPileup);
1418  }
1419  ret.type = static_cast<HitSimType>(std::min(static_cast<int>(ret.type), static_cast<int>(type)));
1420 
1421  // Limit to only input TrackingParticles (usually signal+ITPU)
1422  auto tpIndex = tpKeyToIndex.find(trackingParticle.key());
1423  if( tpIndex == tpKeyToIndex.end())
1424  continue;
1425 
1426  //now get the corresponding sim hit
1427  std::pair<TrackingParticleRef, TrackPSimHitRef> simHitTPpairWithDummyTP(trackingParticle,TrackPSimHitRef());
1428  //SimHit is dummy: for simHitTPAssociationListGreater sorting only the TP is needed
1429  auto range = std::equal_range(simHitsTPAssoc.begin(), simHitsTPAssoc.end(),
1431  int simHitKey = -1;
1432  bool foundElectron = false;
1433  edm::ProductID simHitID;
1434  for(auto ip = range.first; ip != range.second; ++ip) {
1435  TrackPSimHitRef TPhit = ip->second;
1436  DetId dId = DetId(TPhit->detUnitId());
1437  if (dId.rawId()==hitId.rawId()) {
1438  // skip electron SimHits for non-electron TPs also here
1439  if(std::abs(TPhit->particleType()) == 11 && std::abs(trackingParticle->pdgId()) != 11) {
1440  foundElectron = true;
1441  continue;
1442  }
1443 
1444  simHitKey = TPhit.key();
1445  simHitID = TPhit.id();
1446  break;
1447  }
1448  }
1449  if(simHitKey < 0) {
1450  // In case we didn't find a simhit because of filtered-out
1451  // electron SimHit, just ignore the missing SimHit.
1452  if(foundElectron)
1453  continue;
1454 
1455  auto ex = cms::Exception("LogicError") << "Did not find SimHit for reco hit DetId " << hitId.rawId()
1456  << " for TP " << trackingParticle.key() << " bx:event " << bx << ":" << event
1457  << ".\nFound SimHits from detectors ";
1458  for(auto ip = range.first; ip != range.second; ++ip) {
1459  TrackPSimHitRef TPhit = ip->second;
1460  DetId dId = DetId(TPhit->detUnitId());
1461  ex << dId.rawId() << " ";
1462  }
1463  if(trackingParticle->eventId().event() != 0) {
1464  ex << "\nSince this is a TrackingParticle from pileup, check that you're running the pileup mixing in playback mode.";
1465  }
1466  throw ex;
1467  }
1468  auto simHitIndex = simHitRefKeyToIndex.at(std::make_pair(simHitKey, simHitID));
1469  ret.matchingSimHit.push_back(simHitIndex);
1470 
1471  double chargeFraction = 0.;
1472  for(const SimTrack& simtrk: trackingParticle->g4Tracks()) {
1473  auto found = simTrackIdToChargeFraction.find(simtrk.trackId());
1474  if(found != simTrackIdToChargeFraction.end()) {
1475  chargeFraction += found->second;
1476  }
1477  }
1478  ret.chargeFraction.push_back(chargeFraction);
1479 
1480  // only for debug prints
1481  ret.bunchCrossing.push_back(bx);
1482  ret.event.push_back(event);
1483 
1484  simhit_hitIdx[simHitIndex].push_back(clusterKey);
1485  simhit_hitType[simHitIndex].push_back(static_cast<int>(hitType));
1486  }
1487  }
1488 
1489  return ret;
1490 }
1491 
1493  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
1495  const TrackerTopology& tTopo,
1496  SimHitRefKeyToIndex& simHitRefKeyToIndex,
1497  std::vector<TPHitIndex>& tpHitList) {
1498 
1499  for(const auto& assoc: simHitsTPAssoc) {
1500  auto tpKey = assoc.first.key();
1501 
1502  // SimHitTPAssociationList can contain more TrackingParticles than
1503  // what are given to this EDAnalyzer, so we can filter those out here.
1504  auto found = tpKeyToIndex.find(tpKey);
1505  if(found == tpKeyToIndex.end())
1506  continue;
1507  const auto tpIndex = found->second;
1508 
1509  // skip non-tracker simhits (mostly muons)
1510  const auto& simhit = *(assoc.second);
1511  auto detId = DetId(simhit.detUnitId());
1512  if(detId.det() != DetId::Tracker) continue;
1513 
1514  // Skip electron SimHits for non-electron TrackingParticles to
1515  // filter out delta rays. The delta ray hits just confuse. If we
1516  // need them later, let's add them as a separate "collection" of
1517  // hits of a TP
1518  const TrackingParticle& tp = *(assoc.first);
1519  if(std::abs(simhit.particleType()) == 11 && std::abs(tp.pdgId()) != 11) continue;
1520 
1521  auto simHitKey = std::make_pair(assoc.second.key(), assoc.second.id());
1522 
1523  if(simHitRefKeyToIndex.find(simHitKey) != simHitRefKeyToIndex.end()) {
1524  for(const auto& assoc2: simHitsTPAssoc) {
1525  if(std::make_pair(assoc2.second.key(), assoc2.second.id()) == simHitKey) {
1526 
1527 #ifdef EDM_ML_DEBUG
1528  auto range1 = std::equal_range(simHitsTPAssoc.begin(), simHitsTPAssoc.end(),
1529  std::make_pair(assoc.first, TrackPSimHitRef()),
1531  auto range2 = std::equal_range(simHitsTPAssoc.begin(), simHitsTPAssoc.end(),
1532  std::make_pair(assoc2.first, TrackPSimHitRef()),
1534 
1535  LogTrace("TrackingNtuple") << "Earlier TP " << assoc2.first.key() << " SimTrack Ids";
1536  for(const auto& simTrack: assoc2.first->g4Tracks()) {
1537  edm::LogPrint("TrackingNtuple") << " SimTrack " << simTrack.trackId() << " BX:event " << simTrack.eventId().bunchCrossing() << ":" << simTrack.eventId().event();
1538  }
1539  for(auto iHit = range2.first; iHit != range2.second; ++iHit) {
1540  LogTrace("TrackingNtuple") << " SimHit " << iHit->second.key() << " " << iHit->second.id() << " tof " << iHit->second->tof() << " trackId " << iHit->second->trackId() << " BX:event " << iHit->second->eventId().bunchCrossing() << ":" << iHit->second->eventId().event();
1541  }
1542  LogTrace("TrackingNtuple") << "Current TP " << assoc.first.key() << " SimTrack Ids";
1543  for(const auto& simTrack: assoc.first->g4Tracks()) {
1544  edm::LogPrint("TrackingNtuple") << " SimTrack " << simTrack.trackId() << " BX:event " << simTrack.eventId().bunchCrossing() << ":" << simTrack.eventId().event();
1545  }
1546  for(auto iHit = range1.first; iHit != range1.second; ++iHit) {
1547  LogTrace("TrackingNtuple") << " SimHit " << iHit->second.key() << " " << iHit->second.id() << " tof " << iHit->second->tof() << " trackId " << iHit->second->trackId() << " BX:event " << iHit->second->eventId().bunchCrossing() << ":" << iHit->second->eventId().event();
1548  }
1549 #endif
1550 
1551  throw cms::Exception("LogicError") << "Got second time the SimHit " << simHitKey.first << " of " << simHitKey.second << ", first time with TrackingParticle " << assoc2.first.key() << ", now with " << tpKey;
1552  }
1553  }
1554  throw cms::Exception("LogicError") << "Got second time the SimHit " << simHitKey.first << " of " << simHitKey.second << ", now with TrackingParticle " << tpKey << ", but I didn't find the first occurrance!";
1555  }
1556 
1557  auto det = tracker.idToDetUnit(detId);
1558  if(!det)
1559  throw cms::Exception("LogicError") << "Did not find a det unit for DetId " << simhit.detUnitId() << " from tracker geometry";
1560 
1561  const auto pos = det->surface().toGlobal(simhit.localPosition());
1562  const float tof = simhit.timeOfFlight();
1563 
1564  const auto simHitIndex = simhit_detId.size();
1565  simHitRefKeyToIndex[simHitKey] = simHitIndex;
1566 
1567  simhit_det.push_back(detId.subdetId());
1568  simhit_lay.push_back(tTopo.layer(detId));
1569  simhit_detId.push_back(detId.rawId());
1570  simhit_x.push_back(pos.x());
1571  simhit_y.push_back(pos.y());
1572  simhit_z.push_back(pos.z());
1573  simhit_particle.push_back(simhit.particleType());
1574  simhit_process.push_back(simhit.processType());
1575  simhit_eloss.push_back(simhit.energyLoss());
1576  simhit_tof.push_back(tof);
1577  //simhit_simTrackId.push_back(simhit.trackId());
1578 
1579  simhit_simTrkIdx.push_back(tpIndex);
1580 
1581  simhit_hitIdx.emplace_back(); // filled in matchCluster
1582  simhit_hitType.emplace_back(); // filled in matchCluster
1583 
1584  tpHitList.emplace_back(tpKey, simHitIndex, tof, simhit.detUnitId());
1585  }
1586 }
1587 
1589  const ClusterTPAssociation& clusterToTPMap,
1590  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
1592  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink,
1593  const TransientTrackingRecHitBuilder& theTTRHBuilder,
1594  const TrackerTopology& tTopo,
1595  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
1596  std::set<edm::ProductID>& hitProductIds
1597  ) {
1599  iEvent.getByToken(pixelRecHitToken_, pixelHits);
1600  for (auto it = pixelHits->begin(); it!=pixelHits->end(); it++ ) {
1601  const DetId hitId = it->detId();
1602  for (auto hit = it->begin(); hit!=it->end(); hit++ ) {
1603  TransientTrackingRecHit::RecHitPointer ttrh = theTTRHBuilder.build(&*hit);
1604 
1605  hitProductIds.insert(hit->cluster().id());
1606 
1607  const int key = hit->cluster().key();
1608  const int lay = tTopo.layer(hitId);
1609  SimHitData simHitData = matchCluster(hit->firstClusterRef(), hitId, key, ttrh,
1610  clusterToTPMap, tpKeyToIndex, simHitsTPAssoc, digiSimLink, simHitRefKeyToIndex, HitType::Pixel);
1611 
1612  pix_isBarrel .push_back( hitId.subdetId()==1 );
1613  pix_det .push_back( hitId.subdetId() );
1614  pix_lay .push_back( lay );
1615  pix_detId .push_back( hitId.rawId() );
1616  pix_trkIdx .emplace_back(); // filled in fillTracks
1617  pix_seeIdx .emplace_back(); // filled in fillSeeds
1618  pix_simHitIdx.push_back( simHitData.matchingSimHit );
1619  pix_simType.push_back( static_cast<int>(simHitData.type) );
1620  pix_x .push_back( ttrh->globalPosition().x() );
1621  pix_y .push_back( ttrh->globalPosition().y() );
1622  pix_z .push_back( ttrh->globalPosition().z() );
1623  pix_xx .push_back( ttrh->globalPositionError().cxx() );
1624  pix_xy .push_back( ttrh->globalPositionError().cyx() );
1625  pix_yy .push_back( ttrh->globalPositionError().cyy() );
1626  pix_yz .push_back( ttrh->globalPositionError().czy() );
1627  pix_zz .push_back( ttrh->globalPositionError().czz() );
1628  pix_zx .push_back( ttrh->globalPositionError().czx() );
1629  pix_chargeFraction.push_back( simHitData.chargeFraction );
1630  pix_radL .push_back( ttrh->surface()->mediumProperties().radLen() );
1631  pix_bbxi .push_back( ttrh->surface()->mediumProperties().xi() );
1632  LogTrace("TrackingNtuple") << "pixHit cluster=" << key
1633  << " subdId=" << hitId.subdetId()
1634  << " lay=" << lay
1635  << " rawId=" << hitId.rawId()
1636  << " pos =" << ttrh->globalPosition()
1637  << " nMatchingSimHit=" << simHitData.matchingSimHit.size();
1638  if(!simHitData.matchingSimHit.empty()) {
1639  const auto simHitIdx = simHitData.matchingSimHit[0];
1640  LogTrace("TrackingNtuple") << " firstMatchingSimHit=" << simHitIdx
1641  << " simHitPos=" << GlobalPoint(simhit_x[simHitIdx], simhit_y[simHitIdx], simhit_z[simHitIdx])
1642  << " energyLoss=" << simhit_eloss[simHitIdx]
1643  << " particleType=" << simhit_particle[simHitIdx]
1644  << " processType=" << simhit_process[simHitIdx]
1645  << " bunchCrossing=" << simHitData.bunchCrossing[0]
1646  << " event=" << simHitData.event[0];
1647  }
1648  }
1649  }
1650 }
1651 
1652 
1654  const ClusterTPAssociation& clusterToTPMap,
1655  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
1657  const edm::DetSetVector<StripDigiSimLink>& digiSimLink,
1658  const TransientTrackingRecHitBuilder& theTTRHBuilder,
1659  const TrackerTopology& tTopo,
1660  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
1661  std::set<edm::ProductID>& hitProductIds
1662  ) {
1663  //index strip hit branches by cluster index
1665  iEvent.getByToken(stripRphiRecHitToken_, rphiHits);
1667  iEvent.getByToken(stripStereoRecHitToken_, stereoHits);
1668  int totalStripHits = rphiHits->dataSize()+stereoHits->dataSize();
1669  str_isBarrel .resize(totalStripHits);
1670  str_isStereo .resize(totalStripHits);
1671  str_det .resize(totalStripHits);
1672  str_lay .resize(totalStripHits);
1673  str_detId .resize(totalStripHits);
1674  str_trkIdx .resize(totalStripHits); // filled in fillTracks
1675  str_seeIdx .resize(totalStripHits); // filled in fillSeeds
1676  str_simHitIdx.resize(totalStripHits);
1677  str_simType .resize(totalStripHits);
1678  str_x .resize(totalStripHits);
1679  str_y .resize(totalStripHits);
1680  str_z .resize(totalStripHits);
1681  str_xx .resize(totalStripHits);
1682  str_xy .resize(totalStripHits);
1683  str_yy .resize(totalStripHits);
1684  str_yz .resize(totalStripHits);
1685  str_zz .resize(totalStripHits);
1686  str_zx .resize(totalStripHits);
1687  str_chargeFraction.resize(totalStripHits);
1688  str_radL .resize(totalStripHits);
1689  str_bbxi .resize(totalStripHits);
1690 
1691  auto fill = [&](const SiStripRecHit2DCollection& hits, const char *name, bool isStereo) {
1692  for(const auto& detset: hits) {
1693  const DetId hitId = detset.detId();
1694  for(const auto& hit: detset) {
1695  TransientTrackingRecHit::RecHitPointer ttrh = theTTRHBuilder.build(&hit);
1696 
1697  hitProductIds.insert(hit.cluster().id());
1698 
1699  const int key = hit.cluster().key();
1700  const int lay = tTopo.layer(hitId);
1701  SimHitData simHitData = matchCluster(hit.firstClusterRef(), hitId, key, ttrh,
1702  clusterToTPMap, tpKeyToIndex, simHitsTPAssoc, digiSimLink, simHitRefKeyToIndex, HitType::Strip);
1704  str_isStereo [key] = isStereo;
1705  str_det [key] = hitId.subdetId();
1706  str_lay [key] = lay;
1707  str_detId [key] = hitId.rawId();
1708  str_simHitIdx[key] = simHitData.matchingSimHit;
1709  str_simType [key] = static_cast<int>(simHitData.type);
1710  str_x [key] = ttrh->globalPosition().x();
1711  str_y [key] = ttrh->globalPosition().y();
1712  str_z [key] = ttrh->globalPosition().z();
1713  str_xx [key] = ttrh->globalPositionError().cxx();
1714  str_xy [key] = ttrh->globalPositionError().cyx();
1715  str_yy [key] = ttrh->globalPositionError().cyy();
1716  str_yz [key] = ttrh->globalPositionError().czy();
1717  str_zz [key] = ttrh->globalPositionError().czz();
1718  str_zx [key] = ttrh->globalPositionError().czx();
1719  str_chargeFraction[key] = simHitData.chargeFraction;
1720  str_radL [key] = ttrh->surface()->mediumProperties().radLen();
1721  str_bbxi [key] = ttrh->surface()->mediumProperties().xi();
1722  LogTrace("TrackingNtuple") << name << " cluster=" << key
1723  << " subdId=" << hitId.subdetId()
1724  << " lay=" << lay
1725  << " rawId=" << hitId.rawId()
1726  << " pos =" << ttrh->globalPosition()
1727  << " nMatchingSimHit=" << simHitData.matchingSimHit.size();
1728  if(!simHitData.matchingSimHit.empty()) {
1729  const auto simHitIdx = simHitData.matchingSimHit[0];
1730  LogTrace("TrackingNtuple") << " firstMatchingSimHit=" << simHitIdx
1731  << " simHitPos=" << GlobalPoint(simhit_x[simHitIdx], simhit_y[simHitIdx], simhit_z[simHitIdx])
1732  << " simHitPos=" << GlobalPoint(simhit_x[simHitIdx], simhit_y[simHitIdx], simhit_z[simHitIdx])
1733  << " energyLoss=" << simhit_eloss[simHitIdx]
1734  << " particleType=" << simhit_particle[simHitIdx]
1735  << " processType=" << simhit_process[simHitIdx]
1736  << " bunchCrossing=" << simHitData.bunchCrossing[0]
1737  << " event=" << simHitData.event[0];
1738  }
1739  }
1740  }
1741  };
1742 
1743  fill(*rphiHits, "stripRPhiHit", false);
1744  fill(*stereoHits, "stripStereoHit", true);
1745 }
1746 
1748  const TransientTrackingRecHitBuilder& theTTRHBuilder,
1749  const TrackerTopology& tTopo,
1750  std::vector<std::pair<int, int> >& monoStereoClusterList
1751  ) {
1753  iEvent.getByToken(stripMatchedRecHitToken_, matchedHits);
1754  for (auto it = matchedHits->begin(); it!=matchedHits->end(); it++ ) {
1755  const DetId hitId = it->detId();
1756  for (auto hit = it->begin(); hit!=it->end(); hit++ ) {
1757  TransientTrackingRecHit::RecHitPointer ttrh = theTTRHBuilder.build(&*hit);
1758  const int lay = tTopo.layer(hitId);
1759  monoStereoClusterList.emplace_back(hit->monoHit().cluster().key(),hit->stereoHit().cluster().key());
1760  glu_isBarrel .push_back( (hitId.subdetId()==StripSubdetector::TIB || hitId.subdetId()==StripSubdetector::TOB) );
1761  glu_det .push_back( hitId.subdetId() );
1762  glu_lay .push_back( tTopo.layer(hitId) );
1763  glu_detId .push_back( hitId.rawId() );
1764  glu_monoIdx .push_back( hit->monoHit().cluster().key() );
1765  glu_stereoIdx.push_back( hit->stereoHit().cluster().key() );
1766  glu_seeIdx .emplace_back(); // filled in fillSeeds
1767  glu_x .push_back( ttrh->globalPosition().x() );
1768  glu_y .push_back( ttrh->globalPosition().y() );
1769  glu_z .push_back( ttrh->globalPosition().z() );
1770  glu_xx .push_back( ttrh->globalPositionError().cxx() );
1771  glu_xy .push_back( ttrh->globalPositionError().cyx() );
1772  glu_yy .push_back( ttrh->globalPositionError().cyy() );
1773  glu_yz .push_back( ttrh->globalPositionError().czy() );
1774  glu_zz .push_back( ttrh->globalPositionError().czz() );
1775  glu_zx .push_back( ttrh->globalPositionError().czx() );
1776  glu_radL .push_back( ttrh->surface()->mediumProperties().radLen() );
1777  glu_bbxi .push_back( ttrh->surface()->mediumProperties().xi() );
1778  LogTrace("TrackingNtuple") << "stripMatchedHit"
1779  << " cluster0=" << hit->stereoHit().cluster().key()
1780  << " cluster1=" << hit->monoHit().cluster().key()
1781  << " subdId=" << hitId.subdetId()
1782  << " lay=" << lay
1783  << " rawId=" << hitId.rawId()
1784  << " pos =" << ttrh->globalPosition();
1785  }
1786  }
1787 }
1788 
1790  const TrackingParticleRefVector& tpCollection,
1791  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
1792  const reco::BeamSpot& bs,
1793  const reco::TrackToTrackingParticleAssociator& associatorByHits,
1794  const TransientTrackingRecHitBuilder& theTTRHBuilder,
1795  const MagneticField *theMF,
1796  const std::vector<std::pair<int, int> >& monoStereoClusterList,
1797  const std::set<edm::ProductID>& hitProductIds,
1798  std::map<edm::ProductID, size_t>& seedCollToOffset
1799  ) {
1800  TSCBLBuilderNoMaterial tscblBuilder;
1801  for(const auto& seedToken: seedTokens_) {
1802  edm::Handle<edm::View<reco::Track> > seedTracksHandle;
1803  iEvent.getByToken(seedToken, seedTracksHandle);
1804  const auto& seedTracks = *seedTracksHandle;
1805 
1806  if(seedTracks.empty())
1807  continue;
1808 
1809  // The associator interfaces really need to be fixed...
1810  edm::RefToBaseVector<reco::Track> seedTrackRefs;
1811  for(edm::View<reco::Track>::size_type i=0; i<seedTracks.size(); ++i) {
1812  seedTrackRefs.push_back(seedTracks.refAt(i));
1813  }
1814  reco::RecoToSimCollection recSimColl = associatorByHits.associateRecoToSim(seedTrackRefs, tpCollection);
1815 
1817  labelsForToken(seedToken, labels);
1818  TString label = labels.module;
1819  //format label to match algoName
1820  label.ReplaceAll("seedTracks", "");
1821  label.ReplaceAll("Seeds","");
1822  label.ReplaceAll("muonSeeded","muonSeededStep");
1823  int algo = reco::TrackBase::algoByName(label.Data());
1824 
1825  edm::ProductID id = seedTracks[0].seedRef().id();
1826  auto inserted = seedCollToOffset.emplace(id, see_fitok.size());
1827  if(!inserted.second)
1828  throw cms::Exception("Configuration") << "Trying to add seeds with ProductID " << id << " for a second time from collection " << labels.module << ", seed algo " << label << ". Typically this is caused by a configuration problem.";
1829  see_offset.push_back(see_fitok.size());
1830 
1831  LogTrace("TrackingNtuple") << "NEW SEED LABEL: " << label << " size: " << seedTracks.size() << " algo=" << algo
1832  << " ProductID " << id;
1833 
1834  for(const auto& seedTrackRef: seedTrackRefs) {
1835  const auto& seedTrack = *seedTrackRef;
1836  const auto& seedRef = seedTrack.seedRef();
1837  const auto& seed = *seedRef;
1838 
1839  if(seedRef.id() != id)
1840  throw cms::Exception("LogicError") << "All tracks in 'TracksFromSeeds' collection should point to seeds in the same collection. Now the element 0 had ProductID " << id << " while the element " << seedTrackRef.key() << " had " << seedTrackRef.id() << ". The source collection is " << labels.module << ".";
1841 
1842  std::vector<float> sharedFraction;
1843  std::vector<int> tpIdx;
1844  auto foundTPs = recSimColl.find(seedTrackRef);
1845  if (foundTPs != recSimColl.end()) {
1846  for(const auto tpQuality: foundTPs->val) {
1847  sharedFraction.push_back(tpQuality.second);
1848  tpIdx.push_back( tpKeyToIndex.at( tpQuality.first.key() ) );
1849  }
1850  }
1851 
1852 
1853  const bool seedFitOk = !trackFromSeedFitFailed(seedTrack);
1854  const int charge = seedTrack.charge();
1855  const float pt = seedFitOk ? seedTrack.pt() : 0;
1856  const float eta = seedFitOk ? seedTrack.eta() : 0;
1857  const float phi = seedFitOk ? seedTrack.phi() : 0;
1858  const int nHits = seedTrack.numberOfValidHits();
1859 
1860  const auto seedIndex = see_fitok.size();
1861 
1862  see_fitok .push_back(seedFitOk);
1863 
1864  see_px .push_back( seedFitOk ? seedTrack.px() : 0 );
1865  see_py .push_back( seedFitOk ? seedTrack.py() : 0 );
1866  see_pz .push_back( seedFitOk ? seedTrack.pz() : 0 );
1867  see_pt .push_back( pt );
1868  see_eta .push_back( eta );
1869  see_phi .push_back( phi );
1870  see_q .push_back( charge );
1871  see_nValid .push_back( nHits );
1872 
1873  see_dxy .push_back( seedFitOk ? seedTrack.dxy(bs.position()) : 0);
1874  see_dz .push_back( seedFitOk ? seedTrack.dz(bs.position()) : 0);
1875  see_ptErr .push_back( seedFitOk ? seedTrack.ptError() : 0);
1876  see_etaErr .push_back( seedFitOk ? seedTrack.etaError() : 0);
1877  see_phiErr .push_back( seedFitOk ? seedTrack.phiError() : 0);
1878  see_dxyErr .push_back( seedFitOk ? seedTrack.dxyError() : 0);
1879  see_dzErr .push_back( seedFitOk ? seedTrack.dzError() : 0);
1880  see_algo .push_back( algo );
1881 
1882  see_trkIdx .push_back(-1); // to be set correctly in fillTracks
1883  see_shareFrac.push_back( sharedFraction );
1884  see_simTrkIdx.push_back( tpIdx );
1885 
1887  /*
1888  TransientTrackingRecHit::RecHitPointer lastRecHit = theTTRHBuilder.build(&*(seed.recHits().second-1));
1889  TrajectoryStateOnSurface state = trajectoryStateTransform::transientState( itSeed->startingState(), lastRecHit->surface(), theMF);
1890  float pt = state.globalParameters().momentum().perp();
1891  float eta = state.globalParameters().momentum().eta();
1892  float phi = state.globalParameters().momentum().phi();
1893  see_px .push_back( state.globalParameters().momentum().x() );
1894  see_py .push_back( state.globalParameters().momentum().y() );
1895  see_pz .push_back( state.globalParameters().momentum().z() );
1896  */
1897 
1898  std::vector<int> hitIdx;
1899  std::vector<int> hitType;
1900 
1901  for (auto hit=seed.recHits().first; hit!=seed.recHits().second; ++hit) {
1902  TransientTrackingRecHit::RecHitPointer recHit = theTTRHBuilder.build(&*hit);
1903  int subid = recHit->geographicalId().subdetId();
1904  if (subid == (int) PixelSubdetector::PixelBarrel || subid == (int) PixelSubdetector::PixelEndcap) {
1905  const BaseTrackerRecHit* bhit = dynamic_cast<const BaseTrackerRecHit*>(&*recHit);
1906  const auto& clusterRef = bhit->firstClusterRef();
1907  const auto clusterKey = clusterRef.cluster_pixel().key();
1908  if(includeAllHits_) {
1909  checkProductID(hitProductIds, clusterRef.id(), "seed");
1910  pix_seeIdx[clusterKey].push_back(seedIndex);
1911  }
1912  hitIdx.push_back( clusterKey );
1913  hitType.push_back( static_cast<int>(HitType::Pixel) );
1914  } else {
1915  if (trackerHitRTTI::isMatched(*recHit)) {
1916  const SiStripMatchedRecHit2D * matchedHit = dynamic_cast<const SiStripMatchedRecHit2D *>(&*recHit);
1917  if(includeAllHits_) {
1918  checkProductID(hitProductIds, matchedHit->monoClusterRef().id(), "seed");
1919  checkProductID(hitProductIds, matchedHit->stereoClusterRef().id(), "seed");
1920  }
1921  int monoIdx = matchedHit->monoClusterRef().key();
1922  int stereoIdx = matchedHit->stereoClusterRef().key();
1923 
1924  std::vector<std::pair<int,int> >::const_iterator pos = find( monoStereoClusterList.begin(), monoStereoClusterList.end(), std::make_pair(monoIdx,stereoIdx) );
1925  const auto gluedIndex = std::distance(monoStereoClusterList.begin(), pos);
1926  if(includeAllHits_) glu_seeIdx[gluedIndex].push_back(seedIndex);
1927  hitIdx.push_back( gluedIndex );
1928  hitType.push_back( static_cast<int>(HitType::Glued) );
1929  } else {
1930  const BaseTrackerRecHit* bhit = dynamic_cast<const BaseTrackerRecHit*>(&*recHit);
1931  const auto& clusterRef = bhit->firstClusterRef();
1932  const auto clusterKey = clusterRef.cluster_strip().key();
1933  if(includeAllHits_) {
1934  checkProductID(hitProductIds, clusterRef.id(), "seed");
1935  str_seeIdx[clusterKey].push_back(seedIndex);
1936  }
1937  hitIdx.push_back( clusterKey );
1938  hitType.push_back( static_cast<int>(HitType::Strip) );
1939  }
1940  }
1941  }
1942  see_hitIdx .push_back( hitIdx );
1943  see_hitType .push_back( hitType );
1944  see_nPixel .push_back( std::count(hitType.begin(), hitType.end(), static_cast<int>(HitType::Pixel)) );
1945  see_nGlued .push_back( std::count(hitType.begin(), hitType.end(), static_cast<int>(HitType::Glued)) );
1946  see_nStrip .push_back( std::count(hitType.begin(), hitType.end(), static_cast<int>(HitType::Strip)) );
1947  //the part below is not strictly needed
1948  float chi2 = -1;
1949  if (nHits==2) {
1950  TransientTrackingRecHit::RecHitPointer recHit0 = theTTRHBuilder.build(&*(seed.recHits().first));
1951  TransientTrackingRecHit::RecHitPointer recHit1 = theTTRHBuilder.build(&*(seed.recHits().first+1));
1952  std::vector<GlobalPoint> gp(2);
1953  std::vector<GlobalError> ge(2);
1954  gp[0] = recHit0->globalPosition();
1955  ge[0] = recHit0->globalPositionError();
1956  gp[1] = recHit1->globalPosition();
1957  ge[1] = recHit1->globalPositionError();
1958  LogTrace("TrackingNtuple") << "seed " << seedTrackRef.key()
1959  << " pt=" << pt << " eta=" << eta << " phi=" << phi << " q=" << charge
1960  << " - PAIR - ids: " << recHit0->geographicalId().rawId() << " " << recHit1->geographicalId().rawId()
1961  << " hitpos: " << gp[0] << " " << gp[1]
1962  << " trans0: " << (recHit0->transientHits().size()>1 ? recHit0->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
1963  << " " << (recHit0->transientHits().size()>1 ? recHit0->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
1964  << " trans1: " << (recHit1->transientHits().size()>1 ? recHit1->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
1965  << " " << (recHit1->transientHits().size()>1 ? recHit1->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
1966  << " eta,phi: " << gp[0].eta() << "," << gp[0].phi();
1967  } else if (nHits==3) {
1968  TransientTrackingRecHit::RecHitPointer recHit0 = theTTRHBuilder.build(&*(seed.recHits().first));
1969  TransientTrackingRecHit::RecHitPointer recHit1 = theTTRHBuilder.build(&*(seed.recHits().first+1));
1970  TransientTrackingRecHit::RecHitPointer recHit2 = theTTRHBuilder.build(&*(seed.recHits().first+2));
1973  declareDynArray(bool,4, bl);
1974  gp[0] = recHit0->globalPosition();
1975  ge[0] = recHit0->globalPositionError();
1976  int subid0 = recHit0->geographicalId().subdetId();
1977  bl[0] = (subid0 == StripSubdetector::TIB || subid0 == StripSubdetector::TOB || subid0 == (int) PixelSubdetector::PixelBarrel);
1978  gp[1] = recHit1->globalPosition();
1979  ge[1] = recHit1->globalPositionError();
1980  int subid1 = recHit1->geographicalId().subdetId();
1981  bl[1] = (subid1 == StripSubdetector::TIB || subid1 == StripSubdetector::TOB || subid1 == (int) PixelSubdetector::PixelBarrel);
1982  gp[2] = recHit2->globalPosition();
1983  ge[2] = recHit2->globalPositionError();
1984  int subid2 = recHit2->geographicalId().subdetId();
1985  bl[2] = (subid2 == StripSubdetector::TIB || subid2 == StripSubdetector::TOB || subid2 == (int) PixelSubdetector::PixelBarrel);
1986  RZLine rzLine(gp,ge,bl);
1987  float seed_chi2 = rzLine.chi2();
1988  //float seed_pt = state.globalParameters().momentum().perp();
1989  float seed_pt = pt;
1990  LogTrace("TrackingNtuple") << "seed " << seedTrackRef.key()
1991  << " pt=" << pt << " eta=" << eta << " phi=" << phi << " q=" << charge
1992  << " - TRIPLET - ids: " << recHit0->geographicalId().rawId() << " " << recHit1->geographicalId().rawId() << " " << recHit2->geographicalId().rawId()
1993  << " hitpos: " << gp[0] << " " << gp[1] << " " << gp[2]
1994  << " trans0: " << (recHit0->transientHits().size()>1 ? recHit0->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
1995  << " " << (recHit0->transientHits().size()>1 ? recHit0->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
1996  << " trans1: " << (recHit1->transientHits().size()>1 ? recHit1->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
1997  << " " << (recHit1->transientHits().size()>1 ? recHit1->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
1998  << " trans2: " << (recHit2->transientHits().size()>1 ? recHit2->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
1999  << " " << (recHit2->transientHits().size()>1 ? recHit2->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
2000  << " local: " << recHit2->localPosition()
2001  //<< " tsos pos, mom: " << state.globalPosition()<<" "<<state.globalMomentum()
2002  << " eta,phi: " << gp[0].eta() << "," << gp[0].phi()
2003  << " pt,chi2: " << seed_pt << "," << seed_chi2;
2004  chi2 = seed_chi2;
2005  }
2006  see_chi2 .push_back( chi2 );
2007  }
2008  }
2009 }
2010 
2012  const TrackingParticleRefVector& tpCollection,
2013  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2014  const reco::BeamSpot& bs,
2015  const reco::TrackToTrackingParticleAssociator& associatorByHits,
2016  const TransientTrackingRecHitBuilder& theTTRHBuilder,
2017  const TrackerTopology& tTopo,
2018  const std::set<edm::ProductID>& hitProductIds,
2019  const std::map<edm::ProductID, size_t>& seedCollToOffset
2020  ) {
2021  reco::RecoToSimCollection recSimColl = associatorByHits.associateRecoToSim(tracks, tpCollection);
2023  labelsForToken(trackToken_, labels);
2024  LogTrace("TrackingNtuple") << "NEW TRACK LABEL: " << labels.module;
2025  for(size_t iTrack = 0; iTrack<tracks.size(); ++iTrack) {
2026  const auto& itTrack = tracks[iTrack];
2027  int nSimHits = 0;
2028  bool isSimMatched = false;
2029  std::vector<float> sharedFraction;
2030  std::vector<int> tpIdx;
2031  auto foundTPs = recSimColl.find(itTrack);
2032  if (foundTPs != recSimColl.end()) {
2033  if (!foundTPs->val.empty()) {
2034  nSimHits = foundTPs->val[0].first->numberOfTrackerHits();
2035  isSimMatched = true;
2036  }
2037  for(const auto tpQuality: foundTPs->val) {
2038  sharedFraction.push_back(tpQuality.second);
2039  tpIdx.push_back( tpKeyToIndex.at( tpQuality.first.key() ) );
2040  }
2041  }
2042  int charge = itTrack->charge();
2043  float pt = itTrack->pt();
2044  float eta = itTrack->eta();
2045  const double lambda = itTrack->lambda();
2046  float chi2 = itTrack->normalizedChi2();
2047  float phi = itTrack->phi();
2048  int nHits = itTrack->numberOfValidHits();
2049  const reco::HitPattern& hp = itTrack->hitPattern();
2050  trk_px .push_back(itTrack->px());
2051  trk_py .push_back(itTrack->py());
2052  trk_pz .push_back(itTrack->pz());
2053  trk_pt .push_back(pt);
2054  trk_inner_px.push_back(itTrack->innerMomentum().x());
2055  trk_inner_py.push_back(itTrack->innerMomentum().y());
2056  trk_inner_pz.push_back(itTrack->innerMomentum().z());
2057  trk_inner_pt.push_back(itTrack->innerMomentum().rho());
2058  trk_outer_px.push_back(itTrack->outerMomentum().x());
2059  trk_outer_py.push_back(itTrack->outerMomentum().y());
2060  trk_outer_pz.push_back(itTrack->outerMomentum().z());
2061  trk_outer_pt.push_back(itTrack->outerMomentum().rho());
2062  trk_eta .push_back(eta);
2063  trk_lambda .push_back(lambda);
2064  trk_cotTheta .push_back(1/tan(M_PI*0.5-lambda));
2065  trk_phi .push_back(phi);
2066  trk_dxy .push_back(itTrack->dxy(bs.position()));
2067  trk_dz .push_back(itTrack->dz(bs.position()));
2068  trk_ptErr .push_back(itTrack->ptError());
2069  trk_etaErr .push_back(itTrack->etaError());
2070  trk_lambdaErr.push_back(itTrack->lambdaError());
2071  trk_phiErr .push_back(itTrack->phiError());
2072  trk_dxyErr .push_back(itTrack->dxyError());
2073  trk_dzErr .push_back(itTrack->dzError());
2074  trk_refpoint_x.push_back(itTrack->vx());
2075  trk_refpoint_y.push_back(itTrack->vy());
2076  trk_refpoint_z.push_back(itTrack->vz());
2077  trk_nChi2 .push_back( itTrack->normalizedChi2());
2078  trk_shareFrac.push_back(sharedFraction);
2079  trk_q .push_back(charge);
2080  trk_nValid .push_back(hp.numberOfValidHits());
2082  trk_nPixel .push_back(hp.numberOfValidPixelHits());
2083  trk_nStrip .push_back(hp.numberOfValidStripHits());
2084  trk_nPixelLay.push_back(hp.pixelLayersWithMeasurement());
2085  trk_nStripLay.push_back(hp.stripLayersWithMeasurement());
2089  trk_algo .push_back(itTrack->algo());
2090  trk_originalAlgo.push_back(itTrack->originalAlgo());
2091  trk_algoMask .push_back(itTrack->algoMaskUL());
2092  trk_stopReason.push_back(itTrack->stopReason());
2093  trk_isHP .push_back(itTrack->quality(reco::TrackBase::highPurity));
2094  if(includeSeeds_) {
2095  auto offset = seedCollToOffset.find(itTrack->seedRef().id());
2096  if(offset == seedCollToOffset.end()) {
2097  throw cms::Exception("Configuration") << "Track algo '" << reco::TrackBase::algoName(itTrack->algo())
2098  << "' originalAlgo '" << reco::TrackBase::algoName(itTrack->originalAlgo())
2099  << "' refers to seed collection " << itTrack->seedRef().id()
2100  << ", but that seed collection is not given as an input. The following collections were given as an input " << make_ProductIDMapPrinter(seedCollToOffset);
2101  }
2102 
2103  const auto seedIndex = offset->second + itTrack->seedRef().key();
2104  trk_seedIdx .push_back(seedIndex);
2105  if(see_trkIdx[seedIndex] != -1) {
2106  throw cms::Exception("LogicError") << "Track index has already been set for seed " << seedIndex << " to " << see_trkIdx[seedIndex] << "; was trying to set it to " << iTrack;
2107  }
2108  see_trkIdx[seedIndex] = iTrack;
2109  }
2110  trk_vtxIdx .push_back(-1); // to be set correctly in fillVertices
2111  trk_simTrkIdx.push_back(tpIdx);
2112  LogTrace("TrackingNtuple") << "Track #" << itTrack.key() << " with q=" << charge
2113  << ", pT=" << pt << " GeV, eta: " << eta << ", phi: " << phi
2114  << ", chi2=" << chi2
2115  << ", Nhits=" << nHits
2116  << ", algo=" << itTrack->algoName(itTrack->algo()).c_str()
2117  << " hp=" << itTrack->quality(reco::TrackBase::highPurity)
2118  << " seed#=" << itTrack->seedRef().key()
2119  << " simMatch=" << isSimMatched
2120  << " nSimHits=" << nSimHits
2121  << " sharedFraction=" << (sharedFraction.empty()?-1:sharedFraction[0])
2122  << " tpIdx=" << (tpIdx.empty()?-1:tpIdx[0]);
2123  std::vector<int> hitIdx;
2124  std::vector<int> hitType;
2125 
2126  for(auto i=itTrack->recHitsBegin(); i!=itTrack->recHitsEnd(); i++) {
2127  TransientTrackingRecHit::RecHitPointer hit=theTTRHBuilder.build(&**i );
2128  DetId hitId = hit->geographicalId();
2129  LogTrace("TrackingNtuple") << "hit #" << std::distance(itTrack->recHitsBegin(), i) << " subdet=" << hitId.subdetId();
2130  if(hitId.det() != DetId::Tracker)
2131  continue;
2132 
2133  LogTrace("TrackingNtuple") << " " << subdetstring(hitId.subdetId()) << " " << tTopo.layer(hitId);
2134  bool isPixel = (hitId.subdetId() == (int) PixelSubdetector::PixelBarrel || hitId.subdetId() == (int) PixelSubdetector::PixelEndcap );
2135 
2136  if (hit->isValid()) {
2137  //ugly... but works
2138  const BaseTrackerRecHit* bhit = dynamic_cast<const BaseTrackerRecHit*>(&*hit);
2139  const auto& clusterRef = bhit->firstClusterRef();
2140  const auto clusterKey = clusterRef.isPixel() ? clusterRef.cluster_pixel().key() : clusterRef.cluster_strip().key();
2141 
2142  LogTrace("TrackingNtuple") << " id: " << hitId.rawId() << " - globalPos =" << hit->globalPosition()
2143  << " cluster=" << clusterKey
2144  << " eta,phi: " << hit->globalPosition().eta() << "," << hit->globalPosition().phi();
2145  if(includeAllHits_) {
2146  checkProductID(hitProductIds, clusterRef.id(), "track");
2147  if(isPixel) pix_trkIdx[clusterKey].push_back(iTrack);
2148  else str_trkIdx[clusterKey].push_back(iTrack);
2149  }
2150 
2151  hitIdx.push_back(clusterKey);
2152  hitType.push_back( static_cast<int>( isPixel ? HitType::Pixel : HitType::Strip ) );
2153  } else {
2154  LogTrace("TrackingNtuple") << " - invalid hit";
2155 
2156  hitIdx.push_back( inv_isBarrel.size() );
2157  hitType.push_back( static_cast<int>(HitType::Invalid) );
2158 
2159  inv_isBarrel.push_back( hitId.subdetId()==1 );
2160  inv_det .push_back( hitId.subdetId() );
2161  inv_lay .push_back( tTopo.layer(hitId) );
2162  inv_detId .push_back( hitId.rawId() );
2163  inv_type .push_back( hit->getType() );
2164 
2165  }
2166  }
2167 
2168  trk_hitIdx.push_back(hitIdx);
2169  trk_hitType.push_back(hitType);
2170  }
2171 }
2172 
2173 
2176  const TrackingParticleRefVector& tpCollection,
2177  const TrackingVertexRefKeyToIndex& tvKeyToIndex,
2178  const reco::TrackToTrackingParticleAssociator& associatorByHits,
2179  const std::vector<TPHitIndex>& tpHitList
2180  ) {
2181  edm::ESHandle<ParametersDefinerForTP> parametersDefinerH;
2182  iSetup.get<TrackAssociatorRecord>().get(parametersDefinerName_, parametersDefinerH);
2183  const ParametersDefinerForTP *parametersDefiner = parametersDefinerH.product();
2184 
2185  // Number of 3D layers for TPs
2187  iEvent.getByToken(tpNLayersToken_, tpNLayersH);
2188  const auto& nLayers_tPCeff = *tpNLayersH;
2189 
2190  iEvent.getByToken(tpNPixelLayersToken_, tpNLayersH);
2191  const auto& nPixelLayers_tPCeff = *tpNLayersH;
2192 
2193  iEvent.getByToken(tpNStripStereoLayersToken_, tpNLayersH);
2194  const auto& nStripMonoAndStereoLayers_tPCeff = *tpNLayersH;
2195 
2196  reco::SimToRecoCollection simRecColl = associatorByHits.associateSimToReco(tracks, tpCollection);
2197 
2198  for(const TrackingParticleRef& tp: tpCollection) {
2199  LogTrace("TrackingNtuple") << "tracking particle pt=" << tp->pt() << " eta=" << tp->eta() << " phi=" << tp->phi();
2200  bool isRecoMatched = false;
2201  std::vector<int> tkIdx;
2202  std::vector<float> sharedFraction;
2203  auto foundTracks = simRecColl.find(tp);
2204  if(foundTracks != simRecColl.end()) {
2205  isRecoMatched = true;
2206  for(const auto trackQuality: foundTracks->val) {
2207  sharedFraction.push_back(trackQuality.second);
2208  tkIdx.push_back(trackQuality.first.key());
2209  }
2210  }
2211  LogTrace("TrackingNtuple") << "matched to tracks = " << make_VectorPrinter(tkIdx) << " isRecoMatched=" << isRecoMatched;
2212  sim_event .push_back(tp->eventId().event());
2213  sim_bunchCrossing.push_back(tp->eventId().bunchCrossing());
2214  sim_pdgId .push_back(tp->pdgId());
2215  sim_px .push_back(tp->px());
2216  sim_py .push_back(tp->py());
2217  sim_pz .push_back(tp->pz());
2218  sim_pt .push_back(tp->pt());
2219  sim_eta .push_back(tp->eta());
2220  sim_phi .push_back(tp->phi());
2221  sim_q .push_back(tp->charge());
2222  sim_trkIdx .push_back(tkIdx);
2223  sim_shareFrac.push_back(sharedFraction);
2224  sim_parentVtxIdx.push_back( tvKeyToIndex.at(tp->parentVertex().key()) );
2225  std::vector<int> decayIdx;
2226  for(const auto& v: tp->decayVertices())
2227  decayIdx.push_back( tvKeyToIndex.at(v.key()) );
2228  sim_decayVtxIdx.push_back(decayIdx);
2229 
2230  //Calcualte the impact parameters w.r.t. PCA
2231  TrackingParticle::Vector momentum = parametersDefiner->momentum(iEvent,iSetup,tp);
2232  TrackingParticle::Point vertex = parametersDefiner->vertex(iEvent,iSetup,tp);
2233  float dxySim = (-vertex.x()*sin(momentum.phi())+vertex.y()*cos(momentum.phi()));
2234  float dzSim = vertex.z() - (vertex.x()*momentum.x()+vertex.y()*momentum.y())/sqrt(momentum.perp2())
2235  * momentum.z()/sqrt(momentum.perp2());
2236  const double lambdaSim = M_PI/2 - momentum.theta();
2237  sim_pca_pt .push_back(std::sqrt(momentum.perp2()));
2238  sim_pca_eta .push_back(momentum.Eta());
2239  sim_pca_lambda .push_back(lambdaSim);
2240  sim_pca_cotTheta .push_back(1/tan(M_PI*0.5-lambdaSim));
2241  sim_pca_phi .push_back(momentum.phi());
2242  sim_pca_dxy .push_back(dxySim);
2243  sim_pca_dz .push_back(dzSim);
2244 
2245  std::vector<int> hitIdx;
2246  int nPixel=0, nStrip=0;
2247  auto rangeHit = std::equal_range(tpHitList.begin(), tpHitList.end(), TPHitIndex(tp.key()), tpHitIndexListLess);
2248  for(auto ip = rangeHit.first; ip != rangeHit.second; ++ip) {
2249  auto type = HitType::Unknown;
2250  if(!simhit_hitType[ip->simHitIdx].empty())
2251  type = static_cast<HitType>(simhit_hitType[ip->simHitIdx][0]);
2252  LogTrace("TrackingNtuple") << "simhit=" << ip->simHitIdx << " type=" << static_cast<int>(type);
2253  hitIdx.push_back(ip->simHitIdx);
2254  const auto detid = DetId(simhit_detId[ip->simHitIdx]);
2255  if(detid.det() != DetId::Tracker) {
2256  throw cms::Exception("LogicError") << "Encountered SimHit for TP " << tp.key() << " with DetId " << detid.rawId() << " whose det() is not Tracker but " << detid.det();
2257  }
2258  const auto subdet = detid.subdetId();
2259  switch(subdet) {
2262  ++nPixel;
2263  break;
2264  case StripSubdetector::TIB:
2265  case StripSubdetector::TID:
2266  case StripSubdetector::TOB:
2267  case StripSubdetector::TEC:
2268  ++nStrip;
2269  break;
2270  default:
2271  throw cms::Exception("LogicError") << "Encountered SimHit for TP " << tp.key() << " with DetId " << detid.rawId() << " whose subdet is not recognized, is " << subdet;
2272  };
2273  }
2274  sim_nValid .push_back( hitIdx.size() );
2275  sim_nPixel .push_back( nPixel );
2276  sim_nStrip .push_back( nStrip );
2277 
2278  const auto nSimLayers = nLayers_tPCeff[tp];
2279  const auto nSimPixelLayers = nPixelLayers_tPCeff[tp];
2280  const auto nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tp];
2281  sim_nLay .push_back( nSimLayers );
2282  sim_nPixelLay.push_back( nSimPixelLayers );
2283  sim_n3DLay .push_back( nSimPixelLayers+nSimStripMonoAndStereoLayers );
2284 
2285  sim_simHitIdx.push_back(hitIdx);
2286  }
2287 }
2288 
2291  for(size_t iVertex=0, size=vertices.size(); iVertex<size; ++iVertex) {
2292  const reco::Vertex& vertex = vertices[iVertex];
2293  vtx_x.push_back(vertex.x());
2294  vtx_y.push_back(vertex.y());
2295  vtx_z.push_back(vertex.z());
2296  vtx_xErr.push_back(vertex.xError());
2297  vtx_yErr.push_back(vertex.yError());
2298  vtx_zErr.push_back(vertex.zError());
2299  vtx_chi2.push_back(vertex.chi2());
2300  vtx_ndof.push_back(vertex.ndof());
2301  vtx_fake.push_back(vertex.isFake());
2302  vtx_valid.push_back(vertex.isValid());
2303 
2304  std::vector<int> trkIdx;
2305  for(auto iTrack = vertex.tracks_begin(); iTrack != vertex.tracks_end(); ++iTrack) {
2306  // Ignore link if vertex was fit from a track collection different from the input
2307  if(iTrack->id() != tracks.id())
2308  continue;
2309 
2310  trkIdx.push_back(iTrack->key());
2311 
2312  if(trk_vtxIdx[iTrack->key()] != -1) {
2313  throw cms::Exception("LogicError") << "Vertex index has already been set for track " << iTrack->key() << " to " << trk_vtxIdx[iTrack->key()] << "; was trying to set it to " << iVertex;
2314  }
2315  trk_vtxIdx[iTrack->key()] = iVertex;
2316  }
2317  vtx_trkIdx.push_back(trkIdx);
2318  }
2319 }
2320 
2322  const TrackingParticleRefKeyToIndex& tpKeyToIndex
2323  ) {
2324  int current_event = -1;
2325  for(const auto& ref: trackingVertices) {
2326  const TrackingVertex v = *ref;
2327  if(v.eventId().event() != current_event) {
2328  // next PV
2329  current_event = v.eventId().event();
2330  simpv_idx.push_back(simvtx_x.size());
2331  }
2332 
2333  unsigned int processType = std::numeric_limits<unsigned int>::max();
2334  if(!v.g4Vertices().empty()) {
2335  processType = v.g4Vertices()[0].processType();
2336  }
2337 
2338  simvtx_event.push_back(v.eventId().event());
2339  simvtx_bunchCrossing.push_back(v.eventId().bunchCrossing());
2340  simvtx_processType.push_back(processType);
2341 
2342  simvtx_x.push_back(v.position().x());
2343  simvtx_y.push_back(v.position().y());
2344  simvtx_z.push_back(v.position().z());
2345 
2346  auto fill = [&](const TrackingParticleRefVector& tps, std::vector<int>& idx) {
2347  for(const auto& tpRef: tps) {
2348  auto found = tpKeyToIndex.find(tpRef.key());
2349  if(found != tpKeyToIndex.end()) {
2350  idx.push_back(tpRef.key());
2351  }
2352  }
2353  };
2354 
2355  std::vector<int> sourceIdx;
2356  std::vector<int> daughterIdx;
2357  fill(v.sourceTracks(), sourceIdx);
2358  fill(v.daughterTracks(), daughterIdx);
2359 
2360  simvtx_sourceSimIdx.push_back(sourceIdx);
2361  simvtx_daughterSimIdx.push_back(daughterIdx);
2362  }
2363 }
2364 
2365 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
2367  //The following says we do not know what parameters are allowed so do no validation
2368  // Please change this to state exactly what you do use, even if it is no parameters
2370  desc.addUntracked<std::vector<edm::InputTag> >("seedTracks", std::vector<edm::InputTag>{
2371  edm::InputTag("seedTracksinitialStepSeeds"),
2372  edm::InputTag("seedTracksdetachedTripletStepSeeds"),
2373  edm::InputTag("seedTrackspixelPairStepSeeds"),
2374  edm::InputTag("seedTrackslowPtTripletStepSeeds"),
2375  edm::InputTag("seedTracksmixedTripletStepSeeds"),
2376  edm::InputTag("seedTrackspixelLessStepSeeds"),
2377  edm::InputTag("seedTrackstobTecStepSeeds"),
2378  edm::InputTag("seedTracksjetCoreRegionalStepSeeds"),
2379  edm::InputTag("seedTracksmuonSeededSeedsInOut"),
2380  edm::InputTag("seedTracksmuonSeededSeedsOutIn")
2381  });
2382  desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
2383  desc.addUntracked<edm::InputTag>("trackingParticles", edm::InputTag("mix", "MergedTrackTruth"));
2384  desc.addUntracked<bool>("trackingParticlesRef", false);
2385  desc.addUntracked<edm::InputTag>("clusterTPMap", edm::InputTag("tpClusterProducer"));
2386  desc.addUntracked<edm::InputTag>("simHitTPMap", edm::InputTag("simHitTPAssocProducer"));
2387  desc.addUntracked<edm::InputTag>("trackAssociator", edm::InputTag("quickTrackAssociatorByHits"));
2388  desc.addUntracked<edm::InputTag>("pixelDigiSimLink", edm::InputTag("simSiPixelDigis"));
2389  desc.addUntracked<edm::InputTag>("stripDigiSimLink", edm::InputTag("simSiStripDigis"));
2390  desc.addUntracked<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
2391  desc.addUntracked<edm::InputTag>("pixelRecHits", edm::InputTag("siPixelRecHits"));
2392  desc.addUntracked<edm::InputTag>("stripRphiRecHits", edm::InputTag("siStripMatchedRecHits", "rphiRecHit"));
2393  desc.addUntracked<edm::InputTag>("stripStereoRecHits", edm::InputTag("siStripMatchedRecHits", "stereoRecHit"));
2394  desc.addUntracked<edm::InputTag>("stripMatchedRecHits", edm::InputTag("siStripMatchedRecHits", "matchedRecHit"));
2395  desc.addUntracked<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
2396  desc.addUntracked<edm::InputTag>("trackingVertices", edm::InputTag("mix", "MergedTrackTruth"));
2397  desc.addUntracked<edm::InputTag>("trackingParticleNlayers", edm::InputTag("trackingParticleNumberOfLayersProducer", "trackerLayers"));
2398  desc.addUntracked<edm::InputTag>("trackingParticleNpixellayers", edm::InputTag("trackingParticleNumberOfLayersProducer", "pixelLayers"));
2399  desc.addUntracked<edm::InputTag>("trackingParticleNstripstereolayers", edm::InputTag("trackingParticleNumberOfLayersProducer", "stripStereoLayers"));
2400  desc.addUntracked<std::string>("TTRHBuilder", "WithTrackAngle");
2401  desc.addUntracked<std::string>("parametersDefiner", "LhcParametersDefinerForTP");
2402  desc.addUntracked<bool>("includeSeeds", false);
2403  desc.addUntracked<bool>("includeAllHits", false);
2404  descriptions.add("trackingNtuple",desc);
2405 }
2406 
2407 //define this as a plug-in
#define LogDebug(id)
int adc(sample_type sample)
get the ADC sample (12 bits)
std::vector< unsigned short > str_lay
RunNumber_t run() const
Definition: EventID.h:39
std::vector< float > sim_pca_dz
edm::LuminosityBlockNumber_t ev_lumi
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< unsigned int > simvtx_processType
edm::EDGetTokenT< TrackingParticleRefVector > trackingParticleRefToken_
std::vector< unsigned int > sim_nLay
type
Definition: HCALResponse.h:21
beamSpotToken_(consumes< reco::BeamSpot >(iConfig.getUntrackedParameter< edm::InputTag >("beamSpot")))
EventNumber_t event() const
Definition: EventID.h:41
Map map_
unsigned int size_type
Definition: View.h:85
void fillTrackingVertices(const TrackingVertexRefVector &trackingVertices, const TrackingParticleRefKeyToIndex &tpKeyToIndex)
const TrackerGeomDet * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > stripMatchedRecHitToken_
std::vector< short > see_fitok
tpNLayersToken_(consumes< edm::ValueMap< unsigned int > >(iConfig.getUntrackedParameter< edm::InputTag >("trackingParticleNlayers")))
std::vector< short > vtx_fake
std::vector< float > simvtx_z
std::vector< std::vector< int > > see_hitType
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< SiStripRecHit2DCollection > stripRphiRecHitToken_
tuple ret
prodAgent to be discontinued
const TrackingParticleRefVector & sourceTracks() const
std::vector< float > trk_phi
SiPixelCluster const & pixelCluster() const
std::vector< float > sim_pca_cotTheta
std::vector< float > sim_pca_dxy
std::vector< unsigned int > trk_nOuterLost
std::vector< float > glu_xy
std::vector< float > glu_radL
std::vector< float > trk_inner_pz
int event() const
get the contents of the subdetector field (should be protected?)
std::vector< float > pix_y
std::vector< int > trk_vtxIdx
string fill
Definition: lumiContext.py:319
std::vector< std::vector< int > > str_trkIdx
std::vector< unsigned int > see_nValid
std::vector< float > str_yy
iterator find(det_id_type id)
Definition: DetSetVector.h:290
bool trackFromSeedFitFailed(const reco::Track &track)
std::vector< float > trk_outer_py
std::unordered_map< reco::RecoToSimCollection::index_type, size_t > TrackingParticleRefKeyToIndex
std::vector< float > pix_zz
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::vector< int > glu_monoIdx
std::vector< float > trk_eta
std::vector< short > glu_isBarrel
std::vector< int > sim_bunchCrossing
std::vector< unsigned int > glu_lay
SimHitData matchCluster(const OmniClusterRef &cluster, DetId hitId, int clusterKey, const TransientTrackingRecHit::RecHitPointer &ttrh, const ClusterTPAssociation &clusterToTPMap, const TrackingParticleRefKeyToIndex &tpKeyToIndex, const SimHitTPAssociationProducer::SimHitTPAssociationList &simHitsTPAssoc, const edm::DetSetVector< SimLink > &digiSimLinks, const SimHitRefKeyToIndex &simHitRefKeyToIndex, HitType hitType)
std::vector< float > see_phiErr
void fillStripMatchedHits(const edm::Event &iEvent, const TransientTrackingRecHitBuilder &theTTRHBuilder, const TrackerTopology &tTopo, std::vector< std::pair< int, int > > &monoStereoClusterList)
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:81
std::vector< std::vector< int > > simhit_hitIdx
trackingVertexToken_(consumes< TrackingVertexCollection >(iConfig.getUntrackedParameter< edm::InputTag >("trackingVertices")))
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
const_iterator end() const
last iterator over the map (read only)
std::vector< unsigned short > inv_lay
std::vector< float > str_x
std::vector< float > see_dzErr
vertexToken_(consumes< reco::VertexCollection >(iConfig.getUntrackedParameter< edm::InputTag >("vertices")))
std::vector< unsigned int > sim_n3DLay
std::vector< float > trk_cotTheta
stripStereoRecHitToken_(consumes< SiStripRecHit2DCollection >(iConfig.getUntrackedParameter< edm::InputTag >("stripStereoRecHits")))
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
std::vector< unsigned int > see_nStrip
std::vector< float > trk_px
double zError() const
error on z
Definition: Vertex.h:123
void fillPixelHits(const edm::Event &iEvent, const ClusterTPAssociation &clusterToTPMap, const TrackingParticleRefKeyToIndex &tpKeyToIndex, const SimHitTPAssociationProducer::SimHitTPAssociationList &simHitsTPAssoc, const edm::DetSetVector< PixelDigiSimLink > &digiSimLink, const TransientTrackingRecHitBuilder &theTTRHBuilder, const TrackerTopology &tTopo, const SimHitRefKeyToIndex &simHitRefKeyToIndex, std::set< edm::ProductID > &hitProductIds)
std::vector< unsigned short > pix_simType
std::vector< unsigned short > inv_type
std::vector< float > pix_zx
TPHitIndex(unsigned int tp=0, unsigned int simHit=0, float to=0, unsigned int id=0)
const std::vector< SimVertex > & g4Vertices() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< float > sim_phi
std::vector< std::vector< int > > trk_simTrkIdx
void fillStripRphiStereoHits(const edm::Event &iEvent, const ClusterTPAssociation &clusterToTPMap, const TrackingParticleRefKeyToIndex &tpKeyToIndex, const SimHitTPAssociationProducer::SimHitTPAssociationList &simHitsTPAssoc, const edm::DetSetVector< StripDigiSimLink > &digiSimLink, const TransientTrackingRecHitBuilder &theTTRHBuilder, const TrackerTopology &tTopo, const SimHitRefKeyToIndex &simHitRefKeyToIndex, std::set< edm::ProductID > &hitProductIds)
int numberOfValidHits() const
Definition: HitPattern.h:823
double y() const
y coordinate
Definition: Vertex.h:113
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > trackAssociatorToken_
OmniClusterRef const & stereoClusterRef() const
int pdgId() const
PDG ID.
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:68
edm::EDGetTokenT< SiStripRecHit2DCollection > stripStereoRecHitToken_
std::vector< float > trk_dxyErr
std::vector< float > str_yz
std::vector< float > trk_pt
std::vector< float > glu_x
std::vector< unsigned int > glu_det
std::vector< float > trk_inner_py
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< float > see_px
std::vector< float > see_chi2
const_iterator find(const key_type &k) const
find element with specified reference key
std::vector< float > glu_z
edm::EDGetTokenT< edm::View< reco::Track > > trackToken_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
void fillBeamSpot(const reco::BeamSpot &bs)
std::vector< float > trk_outer_px
void fillTracks(const edm::RefToBaseVector< reco::Track > &tracks, const TrackingParticleRefVector &tpCollection, const TrackingParticleRefKeyToIndex &tpKeyToIndex, const reco::BeamSpot &bs, const reco::TrackToTrackingParticleAssociator &associatorByHits, const TransientTrackingRecHitBuilder &theTTRHBuilder, const TrackerTopology &tTopo, const std::set< edm::ProductID > &hitProductIds, const std::map< edm::ProductID, size_t > &seedToCollIndex)
std::vector< std::vector< int > > trk_hitType
TrackingParticleRefKeyToIndex TrackingVertexRefKeyToIndex
unsigned long long EventNumber_t
int numberOfValidStripHits() const
Definition: HitPattern.h:853
std::vector< unsigned int > see_algo
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::vector< float > trk_inner_pt
uint16_t firstStrip() const
std::vector< short > simhit_process
std::pair< TrackPSimHitRef::key_type, edm::ProductID > SimHitFullKey
std::vector< std::vector< int > > str_seeIdx
std::vector< std::vector< int > > see_simTrkIdx
std::vector< int > simvtx_event
std::vector< float > str_radL
std::vector< unsigned short > simhit_det
std::vector< unsigned int > inv_detId
std::vector< int > simhit_simTrkIdx
key_type key() const
Accessor for product key.
Definition: Ref.h:264
std::vector< std::vector< float > > sim_shareFrac
std::vector< short > str_isStereo
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:499
static bool tpHitIndexListLess(const TPHitIndex &i, const TPHitIndex &j)
TrackingNtuple(const edm::ParameterSet &)
void fillTrackingParticles(const edm::Event &iEvent, const edm::EventSetup &iSetup, const edm::RefToBaseVector< reco::Track > &tracks, const TrackingParticleRefVector &tpCollection, const TrackingVertexRefKeyToIndex &tvKeyToIndex, const reco::TrackToTrackingParticleAssociator &associatorByHits, const std::vector< TPHitIndex > &tpHitList)
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
std::vector< float > sim_py
stripMatchedRecHitToken_(consumes< SiStripMatchedRecHit2DCollection >(iConfig.getUntrackedParameter< edm::InputTag >("stripMatchedRecHits")))
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
const auto tpTag
std::vector< float > sim_px
unsigned int LuminosityBlockNumber_t
std::vector< float > pix_xx
std::vector< std::vector< int > > sim_decayVtxIdx
std::vector< float > trk_refpoint_x
std::vector< float > pix_radL
std::vector< float > pix_bbxi
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
std::vector< int > simpv_idx
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > pixelSimLinkToken_
std::vector< unsigned int > trk_stopReason
std::vector< std::vector< int > > pix_seeIdx
int numberOfLostTrackerHits(HitCategory category) const
Definition: HitPattern.h:907
std::vector< unsigned short > str_simType
ClusterPixelRef cluster_pixel() const
std::vector< int > sim_q
std::vector< short > inv_isBarrel
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
math::XYZPointD Point
point in the space
std::vector< float > see_etaErr
std::vector< float > simhit_z
std::vector< float > trk_refpoint_y
tuple trackQuality
std::vector< int > sim_event
std::vector< unsigned int > trk_nStrip
SiStripCluster const & stripCluster() const
std::vector< float > chargeFraction
edm::EDGetTokenT< edm::ValueMap< unsigned int > > tpNStripStereoLayersToken_
std::string parametersDefinerName_
std::vector< unsigned int > trk_nPixel
std::vector< float > glu_y
std::vector< float > trk_pz
int iEvent
Definition: GenABIO.cc:230
std::vector< float > trk_dzErr
std::vector< float > trk_lambdaErr
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
Definition: HitPattern.cc:341
edm::EDGetTokenT< SiPixelRecHitCollection > pixelRecHitToken_
bool isNotFinite(T x)
Definition: isFinite.h:10
std::vector< unsigned short > pix_lay
std::vector< std::vector< int > > simvtx_sourceSimIdx
trackAssociatorToken_(consumes< reco::TrackToTrackingParticleAssociator >(iConfig.getUntrackedParameter< edm::InputTag >("trackAssociator")))
std::vector< float > trk_etaErr
std::vector< short > pix_isBarrel
std::vector< float > glu_yz
std::vector< float > sim_pca_phi
std::vector< unsigned int > trk_algo
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< float > vtx_y
std::vector< float > pix_z
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
int bunchCrossing() const
get the detector field from this detid
std::vector< int > bunchCrossing
std::vector< float > sim_eta
std::vector< unsigned int > trk_originalAlgo
usesResource(TFileService::kSharedResource)
std::vector< unsigned int > trk_nInnerLost
ClusterStripRef cluster_strip() const
std::vector< float > str_y
std::vector< unsigned short > pix_det
std::vector< int > sim_pdgId
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< int > see_q
std::vector< std::vector< int > > simhit_hitType
std::vector< float > trk_refpoint_z
std::vector< edm::EDGetTokenT< edm::View< reco::Track > > > seedTokens_
edm::EDGetTokenT< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitTPMapToken_
std::vector< float > pix_yz
std::vector< int > trk_seedIdx
std::vector< std::vector< float > > pix_chargeFraction
edm::RunNumber_t ev_run
std::vector< float > vtx_yErr
std::vector< std::vector< int > > pix_trkIdx
includeSeeds_(iConfig.getUntrackedParameter< bool >("includeSeeds"))
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< unsigned int > sim_nValid
std::vector< float > glu_yy
simHitTPMapToken_(consumes< SimHitTPAssociationProducer::SimHitTPAssociationList >(iConfig.getUntrackedParameter< edm::InputTag >("simHitTPMap")))
std::vector< float > vtx_ndof
double chi2() const
chi-squares
Definition: Vertex.h:98
int j
Definition: DBlmapReader.cc:9
std::vector< float > simvtx_x
double z() const
z coordinate
Definition: Vertex.h:115
virtual TrackingParticle::Vector momentum(const edm::Event &iEvent, const edm::EventSetup &iSetup, const Charge ch, const Point &vtx, const LorentzVector &lv) const
std::vector< float > str_zz
std::vector< float > sim_pca_pt
std::vector< float > see_dxyErr
bool isMatched(TrackingRecHit const &hit)
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
stripRphiRecHitToken_(consumes< SiStripRecHit2DCollection >(iConfig.getUntrackedParameter< edm::InputTag >("stripRphiRecHits")))
range equal_range(const OmniClusterRef &key) const
std::vector< float > see_pt
edm::EDGetTokenT< TrackingVertexCollection > trackingVertexToken_
std::vector< float > see_dxy
std::vector< std::vector< int > > glu_seeIdx
std::vector< unsigned int > trk_n3DLay
std::vector< std::vector< int > > sim_trkIdx
std::vector< float > trk_outer_pt
static bool tpHitIndexListLessSort(const TPHitIndex &i, const TPHitIndex &j)
std::vector< int > matchingSimHit
T min(T a, T b)
Definition: MathUtil.h:58
const bool includeSeeds_
size_type size() const
std::vector< float > trk_dz
pixelSimLinkToken_(consumes< edm::DetSetVector< PixelDigiSimLink > >(iConfig.getUntrackedParameter< edm::InputTag >("pixelDigiSimLink")))
std::vector< float > trk_ptErr
std::vector< unsigned int > simhit_detId
std::vector< unsigned int > trk_nStripLay
void fillSimHits(const TrackerGeometry &tracker, const TrackingParticleRefKeyToIndex &tpKeyToIndex, const SimHitTPAssociationProducer::SimHitTPAssociationList &simHitsTPAssoc, const TrackerTopology &tTopo, SimHitRefKeyToIndex &simHitRefKeyToIndex, std::vector< TPHitIndex > &tpHitList)
builderName_(iConfig.getUntrackedParameter< std::string >("TTRHBuilder"))
std::vector< float > see_phi
OmniClusterRef const & monoClusterRef() const
std::vector< float > vtx_z
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
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
char const * module
Definition: ProductLabels.h:5
bool isPixel() const
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::vector< float > see_pz
std::vector< float > trk_phiErr
std::vector< unsigned int > sim_nPixelLay
std::vector< float > trk_lambda
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:361
#define LogTrace(id)
std::vector< float > glu_zz
std::vector< float > sim_pca_lambda
std::vector< float > glu_zx
std::shared_ptr< TrackingRecHit const > RecHitPointer
double ndof() const
Definition: Vertex.h:105
#define M_PI
Definition: RZLine.h:12
std::vector< float > vtx_xErr
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< std::vector< float > > trk_shareFrac
unsigned int id
std::vector< float > sim_pz
std::vector< int > event
std::vector< std::vector< int > > sim_simHitIdx
edm::Ref< TrackingVertexCollection > TrackingVertexRef
std::vector< unsigned short > inv_det
edm::EventNumber_t ev_event
Definition: DetId.h:18
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
double x() const
x coordinate
Definition: Vertex.h:111
tpNPixelLayersToken_(consumes< edm::ValueMap< unsigned int > >(iConfig.getUntrackedParameter< edm::InputTag >("trackingParticleNpixellayers")))
std::vector< int > glu_stereoIdx
std::vector< unsigned short > simhit_lay
std::vector< float > trk_py
double xError() const
error on x
Definition: Vertex.h:119
std::vector< std::vector< int > > pix_simHitIdx
std::vector< float > trk_nChi2
bool isFake() const
Definition: Vertex.h:72
std::vector< unsigned short > str_det
std::vector< unsigned int > see_nGlued
std::vector< float > see_py
std::vector< float > pix_x
reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
std::vector< int > sim_parentVtxIdx
std::vector< float > see_ptErr
std::vector< float > str_z
tuple tracks
Definition: testEve_cfg.py:39
std::vector< float > str_zx
virtual OmniClusterRef const & firstClusterRef() const =0
std::vector< TrackingVertex > TrackingVertexCollection
const T & get() const
Definition: EventSetup.h:56
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
std::string algoName() const
Definition: TrackBase.h:503
int stripLayersWithMeasurement() const
Definition: HitPattern.h:1035
T const * product() const
Definition: ESHandle.h:86
tpNStripStereoLayersToken_(consumes< edm::ValueMap< unsigned int > >(iConfig.getUntrackedParameter< edm::InputTag >("trackingParticleNstripstereolayers")))
std::vector< short > trk_isHP
std::vector< float > str_xy
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
std::vector< std::vector< float > > str_chargeFraction
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int numberOfLostHits(HitCategory category) const
Definition: HitPattern.h:902
std::vector< std::vector< int > > trk_hitIdx
unsigned int layer(const DetId &id) const
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
std::vector< std::vector< float > > see_shareFrac
std::vector< int > trk_q
std::vector< unsigned int > sim_nPixel
std::vector< SimHitTPPair > SimHitTPAssociationList
const bool includeAllHits_
std::vector< short > vtx_valid
edm::EventID id() const
Definition: EventBase.h:58
const EncodedEventId & eventId() const
edm::EDGetTokenT< ClusterTPAssociation > clusterTPMapToken_
Pixel cluster – collection of neighboring pixels above threshold.
std::vector< std::vector< int > > vtx_trkIdx
edm::ProductID id() const
Pixel pixel(int i) const
std::vector< short > str_isBarrel
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
const TrackingParticleRefVector & daughterTracks() const
std::vector< float > glu_bbxi
std::vector< int > simhit_particle
std::vector< float > trk_outer_pz
edm::EDGetTokenT< edm::ValueMap< unsigned int > > tpNLayersToken_
std::vector< float > sim_pca_eta
void push_back(const RefToBase< T > &)
bool isPixel(HitType hitType)
std::map< SimHitFullKey, size_t > SimHitRefKeyToIndex
static int pixelToChannel(int row, int col)
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
double y0() const
y coordinate
Definition: BeamSpot.h:66
std::vector< float > simhit_y
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
std::vector< std::vector< int > > str_simHitIdx
std::string builderName_
std::vector< float > glu_xx
Monte Carlo truth information used for tracking validation.
edm::EDGetTokenT< edm::ValueMap< unsigned int > > tpNPixelLayersToken_
bool isUninitialized() const
Definition: EDGetToken.h:73
std::vector< unsigned int > trk_nPixelLay
std::vector< float > simhit_x
const Point & position() const
position
Definition: BeamSpot.h:62
std::vector< float > simvtx_y
std::vector< std::vector< int > > simvtx_daughterSimIdx
std::vector< float > str_xx
#define declareDynArray(T, n, x)
Definition: DynArray.h:59
unsigned int RunNumber_t
pixelRecHitToken_(consumes< SiPixelRecHitCollection >(iConfig.getUntrackedParameter< edm::InputTag >("pixelRecHits")))
std::vector< unsigned int > see_offset
reco::SimToRecoCollection associateSimToReco(const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
ProductIndex id() const
Definition: ProductID.h:38
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:76
std::vector< int > see_trkIdx
math::XYZVectorD Vector
point in the space
std::vector< float > simhit_tof
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
void fillVertices(const reco::VertexCollection &vertices, const edm::RefToBaseVector< reco::Track > &tracks)
std::vector< float > pix_xy
std::vector< float > trk_dxy
std::vector< float > sim_pt
std::vector< float > pix_yy
unsigned int key() const
std::unordered_set< reco::RecoToSimCollection::index_type > TrackingParticleRefKeySet
float chi2() const
Definition: RZLine.h:97
parametersDefinerName_(iConfig.getUntrackedParameter< std::string >("parametersDefiner"))
std::vector< unsigned int > trk_nInvalid
stripSimLinkToken_(consumes< edm::DetSetVector< StripDigiSimLink > >(iConfig.getUntrackedParameter< edm::InputTag >("stripDigiSimLink")))
std::vector< decltype(reco::TrackBase().algoMaskUL())> trk_algoMask
std::vector< std::vector< int > > see_hitIdx
clusterTPMapToken_(consumes< ClusterTPAssociation >(iConfig.getUntrackedParameter< edm::InputTag >("clusterTPMap")))
std::vector< float > vtx_x
std::vector< unsigned int > see_nPixel
tuple size
Write out results.
edm::Ref< TrackingParticleCollection > TrackingParticleRef
ProductID id() const
std::vector< float > see_eta
const std::vector< uint8_t > & amplitudes() const
std::vector< unsigned int > trk_nValid
std::vector< float > trk_inner_px
double yError() const
error on y
Definition: Vertex.h:121
std::vector< float > vtx_zErr
void fillSeeds(const edm::Event &iEvent, const TrackingParticleRefVector &tpCollection, const TrackingParticleRefKeyToIndex &tpKeyToIndex, const reco::BeamSpot &bs, const reco::TrackToTrackingParticleAssociator &associatorByHits, const TransientTrackingRecHitBuilder &theTTRHBuilder, const MagneticField *theMF, const std::vector< std::pair< int, int > > &monoStereoClusterList, const std::set< edm::ProductID > &hitProductIds, std::map< edm::ProductID, size_t > &seedToCollIndex)
std::vector< unsigned int > pix_detId
std::vector< float > simhit_eloss
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > stripSimLinkToken_
edm::Service< TFileService > fs
std::vector< float > vtx_chi2
std::vector< int > simvtx_bunchCrossing
std::vector< float > str_bbxi
virtual TrackingParticle::Point vertex(const edm::Event &iEvent, const edm::EventSetup &iSetup, const Charge ch, const Point &vtx, const LorentzVector &lv) const
std::vector< float > see_dz
std::vector< unsigned int > glu_detId
trackToken_(consumes< edm::View< reco::Track > >(iConfig.getUntrackedParameter< edm::InputTag >("tracks")))
const LorentzVector & position() const
double x0() const
x coordinate
Definition: BeamSpot.h:64
std::vector< unsigned int > sim_nStrip
int size() const
Definition: vlib.h:39
std::vector< unsigned int > str_detId