CMS 3D CMS Logo

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 
63 
68 
71 
80 
83 
85 #include "HepPDT/ParticleID.hh"
86 
88 
90 
91 #include <set>
92 #include <map>
93 #include <unordered_set>
94 #include <unordered_map>
95 #include <tuple>
96 #include <utility>
97 
98 #include "TTree.h"
99 
100 /*
101 todo:
102 add refitted hit position after track/seed fit
103 add local angle, path length!
104 */
105 
106 namespace {
107  std::string subdetstring(int subdet) {
108  switch(subdet) {
109  case StripSubdetector::TIB: return "- TIB";
110  case StripSubdetector::TOB: return "- TOB";
111  case StripSubdetector::TEC: return "- TEC";
112  case StripSubdetector::TID: return "- TID";
113  case PixelSubdetector::PixelBarrel: return "- PixBar";
114  case PixelSubdetector::PixelEndcap: return "- PixFwd";
115  default: return "UNKNOWN TRACKER HIT TYPE";
116  }
117  }
118 
119  struct ProductIDSetPrinter {
120  ProductIDSetPrinter(const std::set<edm::ProductID>& set): set_(set) {}
121 
122  void print(std::ostream& os) const {
123  for(const auto& item: set_) {
124  os << item << " ";
125  }
126  }
127 
128  const std::set<edm::ProductID>& set_;
129  };
130  std::ostream& operator<<(std::ostream& os, const ProductIDSetPrinter& o) {
131  o.print(os);
132  return os;
133  }
134  template <typename T>
135  struct ProductIDMapPrinter {
136  ProductIDMapPrinter(const std::map<edm::ProductID, T>& map): map_(map) {}
137 
138  void print(std::ostream& os) const {
139  for(const auto& item: map_) {
140  os << item.first << " ";
141  }
142  }
143 
144  const std::map<edm::ProductID, T>& map_;
145  };
146  template <typename T>
147  auto make_ProductIDMapPrinter(const std::map<edm::ProductID, T>& map) {
148  return ProductIDMapPrinter<T>(map);
149  }
150  template <typename T>
151  std::ostream& operator<<(std::ostream& os, const ProductIDMapPrinter<T>& o) {
152  o.print(os);
153  return os;
154  }
155 
156  template <typename T>
157  struct VectorPrinter {
158  VectorPrinter(const std::vector<T>& vec): vec_(vec) {}
159 
160  void print(std::ostream& os) const {
161  for(const auto& item: vec_) {
162  os << item << " ";
163  }
164  }
165 
166  const std::vector<T>& vec_;
167  };
168  template <typename T>
169  auto make_VectorPrinter(const std::vector<T>& vec) {
170  return VectorPrinter<T>(vec);
171  }
172  template <typename T>
173  std::ostream& operator<<(std::ostream& os, const VectorPrinter<T>& o) {
174  o.print(os);
175  return os;
176  }
177 
178  void checkProductID(const std::set<edm::ProductID>& set, const edm::ProductID& id, const char *name) {
179  if(set.find(id) == set.end())
180  throw cms::Exception("Configuration") << "Got " << name << " with a hit with ProductID " << id
181  << " which does not match to the set of ProductID's for the hits: "
182  << ProductIDSetPrinter(set)
183  << ". Usually this is caused by a wrong hit collection in the configuration.";
184  }
185 
186  template <typename SimLink, typename Func>
187  void forEachMatchedSimLink(const edm::DetSet<SimLink>& digiSimLinks, uint32_t channel, Func func) {
188  for(const auto& link: digiSimLinks) {
189  if(link.channel() == channel) {
190  func(link);
191  }
192  }
193  }
194 
195 
197  template <typename ...Args> void call_nop(Args&&... args) {}
198 
199  template <typename ...Types>
200  class CombineDetId {
201  public:
202  CombineDetId() {}
203 
206  unsigned int operator[](size_t i) const {
207  return std::get<0>(content_)[i];
208  }
209 
210  template <typename ...Args>
211  void book(Args&&... args) {
212  impl([&](auto& vec) { vec.book(std::forward<Args>(args)...); });
213  }
214 
215  template <typename ...Args>
216  void push_back(Args&&... args) {
217  impl([&](auto& vec) { vec.push_back(std::forward<Args>(args)...); });
218  }
219 
220  template <typename ...Args>
221  void resize(Args&&... args) {
222  impl([&](auto& vec) { vec.resize(std::forward<Args>(args)...); });
223  }
224 
225  template <typename ...Args>
226  void set(Args&&... args) {
227  impl([&](auto& vec) { vec.set(std::forward<Args>(args)...); });
228  }
229 
230  void clear() {
231  impl([&](auto& vec) { vec.clear(); });
232  }
233 
234  private:
235  // Trick to not repeate std::index_sequence_for in each of the methods above
236  template <typename F>
237  void impl(F&& func) {
238  impl2(std::index_sequence_for<Types...>{}, std::forward<F>(func));
239  }
240 
241  // Trick to exploit parameter pack expansion in function call
242  // arguments to call a member function for each tuple element
243  // (with the same signature). The comma operator is needed to
244  // return a value from the expression as an argument for the
245  // call_nop.
246  template <std::size_t ...Is, typename F>
247  void impl2(std::index_sequence<Is...>, F&& func) {
248  call_nop( (func(std::get<Is>(content_)) , 0)...);
249  }
250 
251  std::tuple<Types...> content_;
252  };
253 
254 
255  std::map<unsigned int, double> chargeFraction(const SiPixelCluster& cluster, const DetId& detId,
256  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink) {
257  std::map<unsigned int, double> simTrackIdToAdc;
258 
259  auto idetset = digiSimLink.find(detId);
260  if(idetset == digiSimLink.end())
261  return simTrackIdToAdc;
262 
263  double adcSum = 0;
265  for(int iPix=0; iPix != cluster.size(); ++iPix) {
266  const SiPixelCluster::Pixel& pixel = cluster.pixel(iPix);
267  adcSum += pixel.adc;
268  uint32_t channel = PixelChannelIdentifier::pixelToChannel(pixel.x, pixel.y);
269  forEachMatchedSimLink(*idetset, channel, [&](const PixelDigiSimLink& simLink){
270  double& adc = simTrackIdToAdc[simLink.SimTrackId()];
271  adc += pixel.adc*simLink.fraction();
272  });
273  }
274 
275  for(auto& pair: simTrackIdToAdc) {
276  if(adcSum == 0.)
277  pair.second = 0.;
278  else
279  pair.second /= adcSum;
280  }
281 
282  return simTrackIdToAdc;
283  }
284 
285  std::map<unsigned int, double> chargeFraction(const SiStripCluster& cluster, const DetId& detId,
286  const edm::DetSetVector<StripDigiSimLink>& digiSimLink) {
287  std::map<unsigned int, double> simTrackIdToAdc;
288 
289  auto idetset = digiSimLink.find(detId);
290  if(idetset == digiSimLink.end())
291  return simTrackIdToAdc;
292 
293  double adcSum = 0;
295  int first = cluster.firstStrip();
296  for(size_t i=0; i<cluster.amplitudes().size(); ++i) {
297  adcSum += cluster.amplitudes()[i];
298  forEachMatchedSimLink(*idetset, first+i, [&](const StripDigiSimLink& simLink){
299  double& adc = simTrackIdToAdc[simLink.SimTrackId()];
300  adc += cluster.amplitudes()[i]*simLink.fraction();
301  });
302 
303  for(const auto& pair: simTrackIdToAdc) {
304  simTrackIdToAdc[pair.first] = (adcSum != 0. ? pair.second/adcSum : 0.);
305  }
306 
307  }
308  return simTrackIdToAdc;
309  }
310 
311 
312  std::map<unsigned int, double> chargeFraction(const Phase2TrackerCluster1D& cluster, const DetId& detId,
313  const edm::DetSetVector<StripDigiSimLink>& digiSimLink) {
314  std::map<unsigned int, double> simTrackIdToAdc;
315  throw cms::Exception("LogicError") << "Not possible to use StripDigiSimLink with Phase2TrackerCluster1D! ";
316  return simTrackIdToAdc;
317  }
318 
319  //In the OT, there is no measurement of the charge, so no ADC value.
320  //Only in the SSA chip (so in PSs) you have one "threshold" flag that tells you if the charge of at least one strip in the cluster exceeded 1.2 MIPs.
321  std::map<unsigned int, double> chargeFraction(const Phase2TrackerCluster1D& cluster, const DetId& detId,
322  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink) {
323  std::map<unsigned int, double> simTrackIdToAdc;
324  return simTrackIdToAdc;
325  }
326 
327 }
328 
329 //
330 // class declaration
331 //
332 
333 class TrackingNtuple : public edm::one::EDAnalyzer<edm::one::SharedResources> {
334 public:
335  explicit TrackingNtuple(const edm::ParameterSet&);
336  ~TrackingNtuple();
337 
338  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
339 
340 
341 private:
342  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
343 
344  void clearVariables();
345 
346  // This pattern is copied from QuickTrackAssociatorByHitsImpl. If
347  // further needs arises, it wouldn't hurt to abstract it somehow.
348  typedef std::unordered_set<reco::RecoToSimCollection::index_type> TrackingParticleRefKeySet;
349  typedef std::unordered_map<reco::RecoToSimCollection::index_type, size_t> TrackingParticleRefKeyToIndex;
350  typedef TrackingParticleRefKeyToIndex TrackingVertexRefKeyToIndex;
351  typedef std::pair<TrackPSimHitRef::key_type, edm::ProductID> SimHitFullKey;
352  typedef std::map<SimHitFullKey, size_t> SimHitRefKeyToIndex;
353 
354  enum class HitType {
355  Pixel = 0,
356  Strip = 1,
357  Glued = 2,
358  Invalid = 3,
359  Phase2OT = 4,
360  Unknown = 99
361  };
362 
363  // This gives the "best" classification of a reco hit
364  // In case of reco hit mathing to multiple sim, smaller number is
365  // considered better
366  // To be kept in synch with class HitSimType in ntuple.py
367  enum class HitSimType {
368  Signal = 0,
369  ITPileup = 1,
370  OOTPileup = 2,
371  Noise = 3,
372  Unknown = 99
373  };
374 
375  using MVACollection = std::vector<float>;
376  using QualityMaskCollection = std::vector<unsigned char>;
377 
378  struct TPHitIndex {
379  TPHitIndex(unsigned int tp=0, unsigned int simHit=0, float to=0, unsigned int id=0): tpKey(tp), simHitIdx(simHit), tof(to), detId(id) {}
380  unsigned int tpKey;
381  unsigned int simHitIdx;
382  float tof;
383  unsigned int detId;
384  };
385  static bool tpHitIndexListLess(const TPHitIndex& i, const TPHitIndex& j) { return (i.tpKey < j.tpKey); }
386  static bool tpHitIndexListLessSort(const TPHitIndex& i, const TPHitIndex& j) {
387  if(i.tpKey == j.tpKey) {
389  return i.detId < j.detId;
390  }
391  return i.tof < j.tof; // works as intended if either one is NaN
392  }
393  return i.tpKey < j.tpKey;
394  }
395 
396  void fillBeamSpot(const reco::BeamSpot& bs);
397  void fillPixelHits(const edm::Event& iEvent,
398  const ClusterTPAssociation& clusterToTPMap,
399  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
401  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink,
402  const TransientTrackingRecHitBuilder& theTTRHBuilder,
403  const TrackerTopology& tTopo,
404  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
405  std::set<edm::ProductID>& hitProductIds
406  );
407 
408  void fillStripRphiStereoHits(const edm::Event& iEvent,
409  const ClusterTPAssociation& clusterToTPMap,
410  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
412  const edm::DetSetVector<StripDigiSimLink>& digiSimLink,
413  const TransientTrackingRecHitBuilder& theTTRHBuilder,
414  const TrackerTopology& tTopo,
415  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
416  std::set<edm::ProductID>& hitProductIds
417  );
418 
419  void fillStripMatchedHits(const edm::Event& iEvent,
420  const TransientTrackingRecHitBuilder& theTTRHBuilder,
421  const TrackerTopology& tTopo,
422  std::vector<std::pair<int, int> >& monoStereoClusterList
423  );
424 
425  void fillPhase2OTHits(const edm::Event& iEvent,
426  const ClusterTPAssociation& clusterToTPMap,
427  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
429  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink,
430  const TransientTrackingRecHitBuilder& theTTRHBuilder,
431  const TrackerTopology& tTopo,
432  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
433  std::set<edm::ProductID>& hitProductIds
434  );
435 
436  void fillSeeds(const edm::Event& iEvent,
437  const TrackingParticleRefVector& tpCollection,
438  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
439  const reco::BeamSpot& bs,
440  const reco::TrackToTrackingParticleAssociator& associatorByHits,
441  const TransientTrackingRecHitBuilder& theTTRHBuilder,
442  const MagneticField *theMF,
443  const std::vector<std::pair<int, int> >& monoStereoClusterList,
444  const std::set<edm::ProductID>& hitProductIds,
445  std::map<edm::ProductID, size_t>& seedToCollIndex
446  );
447 
449  const TrackingParticleRefVector& tpCollection,
450  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
451  const reco::BeamSpot& bs,
453  const reco::TrackToTrackingParticleAssociator& associatorByHits,
454  const TransientTrackingRecHitBuilder& theTTRHBuilder,
455  const TrackerTopology& tTopo,
456  const std::set<edm::ProductID>& hitProductIds,
457  const std::map<edm::ProductID, size_t>& seedToCollIndex,
458  const std::vector<const MVACollection *>& mvaColls,
459  const std::vector<const QualityMaskCollection *>& qualColls
460  );
461 
462  void fillSimHits(const TrackerGeometry& tracker,
463  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
465  const TrackerTopology& tTopo,
466  SimHitRefKeyToIndex& simHitRefKeyToIndex,
467  std::vector<TPHitIndex>& tpHitList);
468 
469  void fillTrackingParticles(const edm::Event& iEvent, const edm::EventSetup& iSetup,
470  const edm::RefToBaseVector<reco::Track>& tracks,
471  const reco::BeamSpot& bs,
472  const TrackingParticleRefVector& tpCollection,
473  const TrackingVertexRefKeyToIndex& tvKeyToIndex,
474  const reco::TrackToTrackingParticleAssociator& associatorByHits,
475  const std::vector<TPHitIndex>& tpHitList
476  );
477 
478  void fillTrackingParticlesForSeeds(const TrackingParticleRefVector& tpCollection,
479  const reco::SimToRecoCollection& simRecColl,
480  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
481  const unsigned int seedOffset
482  );
483 
484  void fillVertices(const reco::VertexCollection& vertices,
485  const edm::RefToBaseVector<reco::Track>& tracks);
486 
487  void fillTrackingVertices(const TrackingVertexRefVector& trackingVertices,
488  const TrackingParticleRefKeyToIndex& tpKeyToIndex
489  );
490 
491 
492 
493  struct SimHitData {
494  std::vector<int> matchingSimHit;
495  std::vector<float> chargeFraction;
496  std::vector<int> bunchCrossing;
497  std::vector<int> event;
499  };
500 
501  template <typename SimLink>
502  SimHitData matchCluster(const OmniClusterRef& cluster,
503  DetId hitId, int clusterKey,
505  const ClusterTPAssociation& clusterToTPMap,
506  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
508  const edm::DetSetVector<SimLink>& digiSimLinks,
509  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
510  HitType hitType
511  );
512 
513  // ----------member data ---------------------------
514  std::vector<edm::EDGetTokenT<edm::View<reco::Track> > > seedTokens_;
515  std::vector<edm::EDGetTokenT<std::vector<short> > > seedStopReasonTokens_;
517  std::vector<std::tuple<edm::EDGetTokenT<MVACollection>, edm::EDGetTokenT<QualityMaskCollection> > > mvaQualityCollectionTokens_;
526  bool includeStripHits_, includePhase2OTHits_;
540  const bool includeSeeds_;
541  const bool includeAllHits_;
542  const bool includeMVA_;
544 
546 
547  TTree* t;
548 
549  // DetId branches
550 #define BOOK(name) tree->Branch((prefix+"_"+#name).c_str(), &name);
551  class DetIdCommon {
552  public:
554 
555  unsigned int operator[](size_t i) const {
556  return detId[i];
557  }
558 
559  void book(const std::string& prefix, TTree *tree) {
560  BOOK(detId);
561  BOOK(subdet);
562  BOOK(layer);
563  BOOK(side);
564  BOOK(module);
565  }
566 
567  void push_back(const TrackerTopology& tTopo, const DetId& id) {
568  detId .push_back(id.rawId() );
569  subdet.push_back(id.subdetId() );
570  layer .push_back(tTopo.layer(id) );
571  module.push_back(tTopo.module(id));
572 
573  unsigned short s = 0;
574  switch(id.subdetId()) {
576  s = tTopo.tibSide(id);
577  break;
579  s = tTopo.tobSide(id);
580  break;
581  default:
582  s = tTopo.side(id);
583  }
584  side.push_back(s);
585  }
586 
587  void resize(size_t size) {
588  detId.resize(size);
589  subdet.resize(size);
590  layer.resize(size);
591  side.resize(size);
592  module.resize(size);
593  }
594 
595  void set(size_t index, const TrackerTopology& tTopo, const DetId& id) {
596  detId [index] = id.rawId();
597  subdet[index] = id.subdetId();
598  layer [index] = tTopo.layer(id);
599  side [index] = tTopo.side(id);
600  module[index] = tTopo.module(id);
601  }
602 
603  void clear() {
604  detId.clear();
605  subdet.clear();
606  layer.clear();
607  side.clear();
608  module.clear();
609  }
610 
611  private:
612  std::vector<unsigned int> detId;
613  std::vector<unsigned short> subdet;
614  std::vector<unsigned short> layer; // or disk/wheel
615  std::vector<unsigned short> side;
616  std::vector<unsigned short> module;
617  };
618 
620  public:
622 
623  void book(const std::string& prefix, TTree *tree) {
624  BOOK(ladder);
625  BOOK(blade);
626  BOOK(panel);
627  }
628 
629  void push_back(const TrackerTopology& tTopo, const DetId& id) {
630  const bool isBarrel = id.subdetId() == PixelSubdetector::PixelBarrel;
631  ladder.push_back( isBarrel ? tTopo.pxbLadder(id) : 0 );
632  blade .push_back( isBarrel ? 0 : tTopo.pxfBlade(id) );
633  panel .push_back( isBarrel ? 0 : tTopo.pxfPanel(id) );
634  }
635 
636  void clear() {
637  ladder.clear();
638  blade.clear();
639  panel.clear();
640  }
641 
642  private:
643  std::vector<unsigned short> ladder;
644  std::vector<unsigned short> blade;
645  std::vector<unsigned short> panel;
646  };
647 
649  public:
651 
652  void book(const std::string& prefix, TTree *tree) {
653  BOOK(order);
654  BOOK(ring);
655  BOOK(rod);
656  }
657 
658  void push_back(const TrackerTopology& tTopo, const DetId& id) {
659  const auto parsed = parse(tTopo, id);
660  order .push_back(parsed.order );
661  ring .push_back(parsed.ring );
662  rod .push_back(parsed.rod );
663  }
664 
665  void resize(size_t size) {
666  order.resize(size);
667  ring.resize(size);
668  rod.resize(size);
669  }
670 
671  void set(size_t index, const TrackerTopology& tTopo, const DetId& id) {
672  const auto parsed = parse(tTopo, id);
673  order [index] = parsed.order ;
674  ring [index] = parsed.ring ;
675  rod [index] = parsed.rod ;
676  }
677 
678  void clear() {
679  order.clear();
680  ring.clear();
681  rod.clear();
682  }
683 
684  private:
685  struct Parsed {
686  // use int here instead of short to avoid compilation errors due
687  // to narrowing conversion (less boilerplate than explicit static_casts)
688  unsigned int order = 0;
689  unsigned int ring = 0;
690  unsigned int rod = 0;
691  };
692  Parsed parse(const TrackerTopology& tTopo, const DetId& id) const {
693  switch(id.subdetId()) {
695  return Parsed{tTopo.tibOrder(id), 0, 0};
697  return Parsed{tTopo.tidOrder(id), tTopo.tidRing(id), 0};
699  return Parsed{0, 0, tTopo.tobRod(id)};
701  return Parsed{tTopo.tecOrder(id), tTopo.tecRing(id), 0};
702  default:
703  return Parsed{};
704  };
705  }
706 
707  std::vector<unsigned short> order;
708  std::vector<unsigned short> ring;
709  std::vector<unsigned short> rod;
710  };
711 
713  public:
715 
716  void book(const std::string& prefix, TTree *tree) {
717  BOOK(string);
718  BOOK(petalNumber);
719  BOOK(isStereo);
720  BOOK(isRPhi);
721  BOOK(isGlued);
722  }
723 
724  void push_back(const TrackerTopology& tTopo, const DetId& id) {
725  const auto parsed = parse(tTopo, id);
726  string .push_back(parsed.string );
727  petalNumber.push_back(parsed.petalNumber);
728  isStereo .push_back(tTopo.isStereo(id));
729  isRPhi .push_back(tTopo.isRPhi(id));
730  isGlued .push_back(parsed.glued);
731  }
732 
733  void resize(size_t size) {
734  string .resize(size);
735  petalNumber.resize(size);
736  isStereo .resize(size);
737  isRPhi .resize(size);
738  isGlued .resize(size);
739  }
740 
741  void set(size_t index, const TrackerTopology& tTopo, const DetId& id) {
742  const auto parsed = parse(tTopo, id);
743  string [index] = parsed.string ;
744  petalNumber[index] = parsed.petalNumber;
745  isStereo [index] = tTopo.isStereo(id);
746  isRPhi [index] = tTopo.isRPhi(id);
747  isGlued [index] = parsed.glued;
748  }
749 
750  void clear() {
751  string.clear();
752  isStereo.clear();
753  isRPhi.clear();
754  isGlued.clear();
755  petalNumber.clear();
756  }
757 
758  private:
759  struct Parsed {
760  // use int here instead of short to avoid compilation errors due
761  // to narrowing conversion (less boilerplate than explicit static_casts)
762  unsigned int string = 0;
763  unsigned int petalNumber = 0;
764  bool glued = false;
765  };
766  Parsed parse(const TrackerTopology& tTopo, const DetId& id) const {
767  switch(id.subdetId()) {
769  return Parsed{tTopo.tibString(id), 0, tTopo.tibIsDoubleSide(id)};
771  return Parsed{0, 0, tTopo.tidIsDoubleSide(id)};
773  return Parsed{0, 0, tTopo.tobIsDoubleSide(id)};
775  return Parsed{0, tTopo.tecPetalNumber(id), tTopo.tecIsDoubleSide(id)};
776  default:
777  return Parsed{};
778  }
779  }
780 
781  std::vector<unsigned short> string;
782  std::vector<unsigned short> petalNumber;
783  std::vector<unsigned short> isStereo;
784  std::vector<unsigned short> isRPhi;
785  std::vector<unsigned short> isGlued;
786  };
787 
789  public:
791 
792  void book(const std::string& prefix, TTree *tree) {
793  BOOK(isLower);
794  BOOK(isUpper);
795  BOOK(isStack);
796  }
797 
798  void push_back(const TrackerTopology& tTopo, const DetId& id) {
799  isLower.push_back(tTopo.isLower(id));
800  isUpper.push_back(tTopo.isUpper(id));
801  isStack.push_back(tTopo.stack(id) == 0); // equivalent to *IsDoubleSide() but without the hardcoded layer+ring requirements
802  }
803 
804  void clear() {
805  isLower.clear();
806  isUpper.clear();
807  isStack.clear();
808  }
809 
810  private:
811  std::vector<unsigned short> isLower;
812  std::vector<unsigned short> isUpper;
813  std::vector<unsigned short> isStack;
814  };
815 #undef BOOK
816 
817  using DetIdPixel = CombineDetId<DetIdCommon, DetIdPixelOnly>;
818  using DetIdStrip = CombineDetId<DetIdCommon, DetIdOTCommon, DetIdStripOnly>;
819  using DetIdPhase2OT = CombineDetId<DetIdCommon, DetIdOTCommon, DetIdPhase2OTOnly>;
820  using DetIdAll = CombineDetId<DetIdCommon, DetIdPixelOnly, DetIdOTCommon, DetIdStripOnly>;
821  using DetIdAllPhase2 = CombineDetId<DetIdCommon, DetIdPixelOnly, DetIdOTCommon, DetIdPhase2OTOnly>;
822 
823  // event
827 
829  // tracks
830  // (first) index runs through tracks
831  std::vector<float> trk_px ;
832  std::vector<float> trk_py ;
833  std::vector<float> trk_pz ;
834  std::vector<float> trk_pt ;
835  std::vector<float> trk_inner_px ;
836  std::vector<float> trk_inner_py ;
837  std::vector<float> trk_inner_pz ;
838  std::vector<float> trk_inner_pt ;
839  std::vector<float> trk_outer_px ;
840  std::vector<float> trk_outer_py ;
841  std::vector<float> trk_outer_pz ;
842  std::vector<float> trk_outer_pt ;
843  std::vector<float> trk_eta ;
844  std::vector<float> trk_lambda ;
845  std::vector<float> trk_cotTheta ;
846  std::vector<float> trk_phi ;
847  std::vector<float> trk_dxy ;
848  std::vector<float> trk_dz ;
849  std::vector<float> trk_dxyPV ;
850  std::vector<float> trk_dzPV ;
851  std::vector<float> trk_dxyClosestPV;
852  std::vector<float> trk_dzClosestPV;
853  std::vector<float> trk_ptErr ;
854  std::vector<float> trk_etaErr ;
855  std::vector<float> trk_lambdaErr;
856  std::vector<float> trk_phiErr ;
857  std::vector<float> trk_dxyErr ;
858  std::vector<float> trk_dzErr ;
859  std::vector<float> trk_refpoint_x;
860  std::vector<float> trk_refpoint_y;
861  std::vector<float> trk_refpoint_z;
862  std::vector<float> trk_nChi2 ;
863  std::vector<float> trk_nChi2_1Dmod;
864  std::vector<float> trk_ndof ;
865  std::vector<std::vector<float>> trk_mvas;
866  std::vector<std::vector<unsigned short>> trk_qualityMasks;
867  std::vector<int> trk_q ;
868  std::vector<unsigned int> trk_nValid ;
869  std::vector<unsigned int> trk_nInvalid;
870  std::vector<unsigned int> trk_nPixel ;
871  std::vector<unsigned int> trk_nStrip ;
872  std::vector<unsigned int> trk_nOuterLost;
873  std::vector<unsigned int> trk_nInnerLost;
874  std::vector<unsigned int> trk_nPixelLay;
875  std::vector<unsigned int> trk_nStripLay;
876  std::vector<unsigned int> trk_n3DLay ;
877  std::vector<unsigned int> trk_nLostLay;
878  std::vector<unsigned int> trk_algo ;
879  std::vector<unsigned int> trk_originalAlgo;
880  std::vector<decltype(reco::TrackBase().algoMaskUL())> trk_algoMask;
881  std::vector<unsigned short> trk_stopReason;
882  std::vector<short> trk_isHP ;
883  std::vector<int> trk_seedIdx ;
884  std::vector<int> trk_vtxIdx;
885  std::vector<short> trk_isTrue;
886  std::vector<std::vector<float> > trk_shareFrac; // second index runs through matched TrackingParticles
887  std::vector<std::vector<int> > trk_simTrkIdx; // second index runs through matched TrackingParticles
888  std::vector<std::vector<int> > trk_hitIdx; // second index runs through hits
889  std::vector<std::vector<int> > trk_hitType; // second index runs through hits
891  // sim tracks
892  // (first) index runs through TrackingParticles
893  std::vector<int> sim_event ;
894  std::vector<int> sim_bunchCrossing;
895  std::vector<int> sim_pdgId ;
896  std::vector<std::vector<int> >sim_genPdgIds;
897  std::vector<int> sim_isFromBHadron;
898  std::vector<float> sim_px ;
899  std::vector<float> sim_py ;
900  std::vector<float> sim_pz ;
901  std::vector<float> sim_pt ;
902  std::vector<float> sim_eta ;
903  std::vector<float> sim_phi ;
904  std::vector<float> sim_pca_pt ;
905  std::vector<float> sim_pca_eta ;
906  std::vector<float> sim_pca_lambda;
907  std::vector<float> sim_pca_cotTheta;
908  std::vector<float> sim_pca_phi ;
909  std::vector<float> sim_pca_dxy ;
910  std::vector<float> sim_pca_dz ;
911  std::vector<int> sim_q ;
912  std::vector<unsigned int> sim_nValid ;
913  std::vector<unsigned int> sim_nPixel ;
914  std::vector<unsigned int> sim_nStrip ;
915  std::vector<unsigned int> sim_nLay;
916  std::vector<unsigned int> sim_nPixelLay;
917  std::vector<unsigned int> sim_n3DLay ;
918  std::vector<std::vector<int> > sim_trkIdx; // second index runs through matched tracks
919  std::vector<std::vector<float> > sim_shareFrac; // second index runs through matched tracks
920  std::vector<std::vector<int> > sim_seedIdx; // second index runs through matched seeds
921  std::vector<int> sim_parentVtxIdx;
922  std::vector<std::vector<int> > sim_decayVtxIdx; // second index runs through decay vertices
923  std::vector<std::vector<int> > sim_simHitIdx; // second index runs through SimHits
925  // pixel hits
926  // (first) index runs through hits
927  std::vector<short> pix_isBarrel ;
929  std::vector<std::vector<int> > pix_trkIdx; // second index runs through tracks containing this hit
930  std::vector<std::vector<int> > pix_seeIdx; // second index runs through seeds containing this hit
931  std::vector<std::vector<int> > pix_simHitIdx; // second index runs through SimHits inducing this hit
932  std::vector<std::vector<float> > pix_chargeFraction; // second index runs through SimHits inducing this hit
933  std::vector<unsigned short> pix_simType;
934  std::vector<float> pix_x ;
935  std::vector<float> pix_y ;
936  std::vector<float> pix_z ;
937  std::vector<float> pix_xx ;
938  std::vector<float> pix_xy ;
939  std::vector<float> pix_yy ;
940  std::vector<float> pix_yz ;
941  std::vector<float> pix_zz ;
942  std::vector<float> pix_zx ;
943  std::vector<float> pix_radL ; //http://cmslxr.fnal.gov/lxr/source/DataFormats/GeometrySurface/interface/MediumProperties.h
944  std::vector<float> pix_bbxi ;
946  // strip hits
947  // (first) index runs through hits
948  std::vector<short> str_isBarrel ;
950  std::vector<std::vector<int> > str_trkIdx; // second index runs through tracks containing this hit
951  std::vector<std::vector<int> > str_seeIdx; // second index runs through seeds containing this hit
952  std::vector<std::vector<int> > str_simHitIdx; // second index runs through SimHits inducing this hit
953  std::vector<std::vector<float> > str_chargeFraction; // second index runs through SimHits inducing this hit
954  std::vector<unsigned short> str_simType;
955  std::vector<float> str_x ;
956  std::vector<float> str_y ;
957  std::vector<float> str_z ;
958  std::vector<float> str_xx ;
959  std::vector<float> str_xy ;
960  std::vector<float> str_yy ;
961  std::vector<float> str_yz ;
962  std::vector<float> str_zz ;
963  std::vector<float> str_zx ;
964  std::vector<float> str_radL ; //http://cmslxr.fnal.gov/lxr/source/DataFormats/GeometrySurface/interface/MediumProperties.h
965  std::vector<float> str_bbxi ;
967  // strip matched hits
968  // (first) index runs through hits
969  std::vector<short> glu_isBarrel ;
971  std::vector<int> glu_monoIdx ;
972  std::vector<int> glu_stereoIdx;
973  std::vector<std::vector<int> > glu_seeIdx; // second index runs through seeds containing this hit
974  std::vector<float> glu_x ;
975  std::vector<float> glu_y ;
976  std::vector<float> glu_z ;
977  std::vector<float> glu_xx ;
978  std::vector<float> glu_xy ;
979  std::vector<float> glu_yy ;
980  std::vector<float> glu_yz ;
981  std::vector<float> glu_zz ;
982  std::vector<float> glu_zx ;
983  std::vector<float> glu_radL ; //http://cmslxr.fnal.gov/lxr/source/DataFormats/GeometrySurface/interface/MediumProperties.h
984  std::vector<float> glu_bbxi ;
986  // phase2 Outer Tracker hits
987  // (first) index runs through hits
988  std::vector<short> ph2_isBarrel ;
990  std::vector<std::vector<int> > ph2_trkIdx; // second index runs through tracks containing this hit
991  std::vector<std::vector<int> > ph2_seeIdx; // second index runs through seeds containing this hit
992  std::vector<std::vector<int> > ph2_simHitIdx; // second index runs through SimHits inducing this hit
993  //std::vector<std::vector<float> > ph2_chargeFraction; // Not supported at the moment for Phase2
994  std::vector<unsigned short> ph2_simType;
995  std::vector<float> ph2_x ;
996  std::vector<float> ph2_y ;
997  std::vector<float> ph2_z ;
998  std::vector<float> ph2_xx ;
999  std::vector<float> ph2_xy ;
1000  std::vector<float> ph2_yy ;
1001  std::vector<float> ph2_yz ;
1002  std::vector<float> ph2_zz ;
1003  std::vector<float> ph2_zx ;
1004  std::vector<float> ph2_radL ; //http://cmslxr.fnal.gov/lxr/source/DataFormats/GeometrySurface/interface/MediumProperties.h
1005  std::vector<float> ph2_bbxi ;
1006 
1008  // invalid (missing/inactive/etc) hits
1009  // (first) index runs through hits
1010  std::vector<short> inv_isBarrel;
1013  std::vector<unsigned short> inv_type;
1015  // sim hits
1016  // (first) index runs through hits
1019  std::vector<float> simhit_x;
1020  std::vector<float> simhit_y;
1021  std::vector<float> simhit_z;
1022  std::vector<int> simhit_particle;
1023  std::vector<short> simhit_process;
1024  std::vector<float> simhit_eloss;
1025  std::vector<float> simhit_tof;
1026  //std::vector<unsigned int> simhit_simTrackId; // can be useful for debugging, but not much of general interest
1027  std::vector<int> simhit_simTrkIdx;
1028  std::vector<std::vector<int> > simhit_hitIdx; // second index runs through induced reco hits
1029  std::vector<std::vector<int> > simhit_hitType; // second index runs through induced reco hits
1031  // beam spot
1032  float bsp_x;
1033  float bsp_y;
1034  float bsp_z;
1035  float bsp_sigmax;
1036  float bsp_sigmay;
1037  float bsp_sigmaz;
1039  // seeds
1040  // (first) index runs through seeds
1041  std::vector<short> see_fitok ;
1042  std::vector<float> see_px ;
1043  std::vector<float> see_py ;
1044  std::vector<float> see_pz ;
1045  std::vector<float> see_pt ;
1046  std::vector<float> see_eta ;
1047  std::vector<float> see_phi ;
1048  std::vector<float> see_dxy ;
1049  std::vector<float> see_dz ;
1050  std::vector<float> see_ptErr ;
1051  std::vector<float> see_etaErr ;
1052  std::vector<float> see_phiErr ;
1053  std::vector<float> see_dxyErr ;
1054  std::vector<float> see_dzErr ;
1055  std::vector<float> see_chi2 ;
1056  std::vector<float> see_statePt;
1057  std::vector<float> see_stateTrajX;
1058  std::vector<float> see_stateTrajY;
1059  std::vector<float> see_stateTrajPx;
1060  std::vector<float> see_stateTrajPy;
1061  std::vector<float> see_stateTrajPz;
1062  std::vector<int> see_q ;
1063  std::vector<unsigned int> see_nValid ;
1064  std::vector<unsigned int> see_nPixel ;
1065  std::vector<unsigned int> see_nGlued ;
1066  std::vector<unsigned int> see_nStrip ;
1067  std::vector<unsigned int> see_nPhase2OT;
1068  std::vector<unsigned int> see_algo ;
1069  std::vector<unsigned short> see_stopReason;
1070  std::vector<int> see_trkIdx;
1071  std::vector<short> see_isTrue;
1072  std::vector<std::vector<float> > see_shareFrac; // second index runs through matched TrackingParticles
1073  std::vector<std::vector<int> > see_simTrkIdx; // second index runs through matched TrackingParticles
1074  std::vector<std::vector<int> > see_hitIdx; // second index runs through hits
1075  std::vector<std::vector<int> > see_hitType; // second index runs through hits
1076  //seed algo offset, index runs through iterations
1077  std::vector<unsigned int> see_offset ;
1078 
1079 
1081  // Vertices
1082  // (first) index runs through vertices
1083  std::vector<float> vtx_x;
1084  std::vector<float> vtx_y;
1085  std::vector<float> vtx_z;
1086  std::vector<float> vtx_xErr;
1087  std::vector<float> vtx_yErr;
1088  std::vector<float> vtx_zErr;
1089  std::vector<float> vtx_ndof;
1090  std::vector<float> vtx_chi2;
1091  std::vector<short> vtx_fake;
1092  std::vector<short> vtx_valid;
1093  std::vector<std::vector<int> > vtx_trkIdx; // second index runs through tracks used in the vertex fit
1094 
1096  // Tracking vertices
1097  // (first) index runs through TrackingVertices
1098  std::vector<int> simvtx_event;
1099  std::vector<int> simvtx_bunchCrossing;
1100  std::vector<unsigned int> simvtx_processType; // only from first SimVertex of TrackingVertex
1101  std::vector<float> simvtx_x;
1102  std::vector<float> simvtx_y;
1103  std::vector<float> simvtx_z;
1104  std::vector<std::vector<int> > simvtx_sourceSimIdx; // second index runs through source TrackingParticles
1105  std::vector<std::vector<int> > simvtx_daughterSimIdx; // second index runs through daughter TrackingParticles
1106  std::vector<int> simpv_idx;
1107 };
1108 
1109 //
1110 // constructors and destructor
1111 //
1113  trackToken_(consumes<edm::View<reco::Track> >(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))),
1114  clusterTPMapToken_(consumes<ClusterTPAssociation>(iConfig.getUntrackedParameter<edm::InputTag>("clusterTPMap"))),
1115  simHitTPMapToken_(consumes<SimHitTPAssociationProducer::SimHitTPAssociationList>(iConfig.getUntrackedParameter<edm::InputTag>("simHitTPMap"))),
1116  trackAssociatorToken_(consumes<reco::TrackToTrackingParticleAssociator>(iConfig.getUntrackedParameter<edm::InputTag>("trackAssociator"))),
1117  pixelSimLinkToken_(consumes<edm::DetSetVector<PixelDigiSimLink> >(iConfig.getUntrackedParameter<edm::InputTag>("pixelDigiSimLink"))),
1118  stripSimLinkToken_(consumes<edm::DetSetVector<StripDigiSimLink> >(iConfig.getUntrackedParameter<edm::InputTag>("stripDigiSimLink"))),
1119  siphase2OTSimLinksToken_(consumes<edm::DetSetVector<PixelDigiSimLink> >(iConfig.getUntrackedParameter<edm::InputTag>("phase2OTSimLink"))),
1120  includeStripHits_(iConfig.getUntrackedParameter<edm::InputTag>("stripDigiSimLink").label() != ""),
1121  includePhase2OTHits_(iConfig.getUntrackedParameter<edm::InputTag>("phase2OTSimLink").label() != ""),
1122  beamSpotToken_(consumes<reco::BeamSpot>(iConfig.getUntrackedParameter<edm::InputTag>("beamSpot"))),
1123  pixelRecHitToken_(consumes<SiPixelRecHitCollection>(iConfig.getUntrackedParameter<edm::InputTag>("pixelRecHits"))),
1124  stripRphiRecHitToken_(consumes<SiStripRecHit2DCollection>(iConfig.getUntrackedParameter<edm::InputTag>("stripRphiRecHits"))),
1125  stripStereoRecHitToken_(consumes<SiStripRecHit2DCollection>(iConfig.getUntrackedParameter<edm::InputTag>("stripStereoRecHits"))),
1126  stripMatchedRecHitToken_(consumes<SiStripMatchedRecHit2DCollection>(iConfig.getUntrackedParameter<edm::InputTag>("stripMatchedRecHits"))),
1127  phase2OTRecHitToken_(consumes<Phase2TrackerRecHit1DCollectionNew>(iConfig.getUntrackedParameter<edm::InputTag>("phase2OTRecHits"))),
1128  vertexToken_(consumes<reco::VertexCollection>(iConfig.getUntrackedParameter<edm::InputTag>("vertices"))),
1129  trackingVertexToken_(consumes<TrackingVertexCollection>(iConfig.getUntrackedParameter<edm::InputTag>("trackingVertices"))),
1130  tpNLayersToken_(consumes<edm::ValueMap<unsigned int> >(iConfig.getUntrackedParameter<edm::InputTag>("trackingParticleNlayers"))),
1131  tpNPixelLayersToken_(consumes<edm::ValueMap<unsigned int> >(iConfig.getUntrackedParameter<edm::InputTag>("trackingParticleNpixellayers"))),
1132  tpNStripStereoLayersToken_(consumes<edm::ValueMap<unsigned int> >(iConfig.getUntrackedParameter<edm::InputTag>("trackingParticleNstripstereolayers"))),
1133  builderName_(iConfig.getUntrackedParameter<std::string>("TTRHBuilder")),
1134  parametersDefinerName_(iConfig.getUntrackedParameter<std::string>("parametersDefiner")),
1135  includeSeeds_(iConfig.getUntrackedParameter<bool>("includeSeeds")),
1136  includeAllHits_(iConfig.getUntrackedParameter<bool>("includeAllHits")),
1137  includeMVA_(iConfig.getUntrackedParameter<bool>("includeMVA")),
1138  includeTrackingParticles_(iConfig.getUntrackedParameter<bool>("includeTrackingParticles"))
1139 {
1140  if(includeSeeds_) {
1141  seedTokens_ = edm::vector_transform(iConfig.getUntrackedParameter<std::vector<edm::InputTag> >("seedTracks"), [&](const edm::InputTag& tag) {
1142  return consumes<edm::View<reco::Track> >(tag);
1143  });
1144  seedStopReasonTokens_ = edm::vector_transform(iConfig.getUntrackedParameter<std::vector<edm::InputTag> >("trackCandidates"), [&](const edm::InputTag& tag) {
1145  return consumes<std::vector<short> >(tag);
1146  });
1147  if(seedTokens_.size() != seedStopReasonTokens_.size()) {
1148  throw cms::Exception("Configuration") << "Got " << seedTokens_.size() << " seed collections, but " << seedStopReasonTokens_.size() << " track candidate collections";
1149  }
1150  }
1151 
1152  if(includeAllHits_) {
1153  if(includeStripHits_ && includePhase2OTHits_) {
1154  throw cms::Exception("Configuration") << "Both stripDigiSimLink and phase2OTSimLink are set, please set only either one (this information is used to infer if you're running phase0/1 or phase2 detector)";
1155  }
1156  if(!includeStripHits_ && !includePhase2OTHits_) {
1157  throw cms::Exception("Configuration") << "Neither stripDigiSimLink or phase2OTSimLink are set, please set either one.";
1158  }
1159  }
1160 
1161  const bool tpRef = iConfig.getUntrackedParameter<bool>("trackingParticlesRef");
1162  const auto tpTag = iConfig.getUntrackedParameter<edm::InputTag>("trackingParticles");
1163  if(tpRef) {
1164  trackingParticleRefToken_ = consumes<TrackingParticleRefVector>(tpTag);
1165  }
1166  else {
1167  trackingParticleToken_ = consumes<TrackingParticleCollection>(tpTag);
1168  }
1169 
1170  tracer_.depth(-2); // as in SimTracker/TrackHistory/src/TrackClassifier.cc
1171 
1172  if(includeMVA_) {
1173  mvaQualityCollectionTokens_ = edm::vector_transform(iConfig.getUntrackedParameter<std::vector<std::string> >("trackMVAs"),
1174  [&](const std::string& tag) {
1175  return std::make_tuple(consumes<MVACollection>(edm::InputTag(tag, "MVAValues")),
1176  consumes<QualityMaskCollection>(edm::InputTag(tag, "QualityMasks")));
1177  });
1178  }
1179 
1180  usesResource(TFileService::kSharedResource);
1182  t = fs->make<TTree>("tree","tree");
1183 
1184  t->Branch("event" , &ev_event);
1185  t->Branch("lumi" , &ev_lumi);
1186  t->Branch("run" , &ev_run);
1187 
1188  //tracks
1189  t->Branch("trk_px" , &trk_px);
1190  t->Branch("trk_py" , &trk_py);
1191  t->Branch("trk_pz" , &trk_pz);
1192  t->Branch("trk_pt" , &trk_pt);
1193  t->Branch("trk_inner_px" , &trk_inner_px);
1194  t->Branch("trk_inner_py" , &trk_inner_py);
1195  t->Branch("trk_inner_pz" , &trk_inner_pz);
1196  t->Branch("trk_inner_pt" , &trk_inner_pt);
1197  t->Branch("trk_outer_px" , &trk_outer_px);
1198  t->Branch("trk_outer_py" , &trk_outer_py);
1199  t->Branch("trk_outer_pz" , &trk_outer_pz);
1200  t->Branch("trk_outer_pt" , &trk_outer_pt);
1201  t->Branch("trk_eta" , &trk_eta);
1202  t->Branch("trk_lambda" , &trk_lambda);
1203  t->Branch("trk_cotTheta" , &trk_cotTheta);
1204  t->Branch("trk_phi" , &trk_phi);
1205  t->Branch("trk_dxy" , &trk_dxy );
1206  t->Branch("trk_dz" , &trk_dz );
1207  t->Branch("trk_dxyPV" , &trk_dxyPV );
1208  t->Branch("trk_dzPV" , &trk_dzPV );
1209  t->Branch("trk_dxyClosestPV", &trk_dxyClosestPV );
1210  t->Branch("trk_dzClosestPV", &trk_dzClosestPV );
1211  t->Branch("trk_ptErr" , &trk_ptErr );
1212  t->Branch("trk_etaErr" , &trk_etaErr );
1213  t->Branch("trk_lambdaErr", &trk_lambdaErr);
1214  t->Branch("trk_phiErr" , &trk_phiErr );
1215  t->Branch("trk_dxyErr" , &trk_dxyErr );
1216  t->Branch("trk_dzErr" , &trk_dzErr );
1217  t->Branch("trk_refpoint_x", &trk_refpoint_x);
1218  t->Branch("trk_refpoint_y", &trk_refpoint_y);
1219  t->Branch("trk_refpoint_z", &trk_refpoint_z);
1220  t->Branch("trk_nChi2" , &trk_nChi2);
1221  t->Branch("trk_nChi2_1Dmod", &trk_nChi2_1Dmod);
1222  t->Branch("trk_ndof" , &trk_ndof);
1223  if(includeMVA_) {
1224  trk_mvas.resize(mvaQualityCollectionTokens_.size());
1225  trk_qualityMasks.resize(mvaQualityCollectionTokens_.size());
1226  if(!trk_mvas.empty()) {
1227  t->Branch("trk_mva" , &(trk_mvas[0]));
1228  t->Branch("trk_qualityMask", &(trk_qualityMasks[0]));
1229  for(size_t i=1; i<trk_mvas.size(); ++i) {
1230  t->Branch(("trk_mva"+std::to_string(i+1)).c_str(), &(trk_mvas[i]));
1231  t->Branch(("trk_qualityMask"+std::to_string(i+1)).c_str(), &(trk_qualityMasks[i]));
1232  }
1233  }
1234  }
1235  t->Branch("trk_q" , &trk_q);
1236  t->Branch("trk_nValid" , &trk_nValid );
1237  t->Branch("trk_nInvalid" , &trk_nInvalid);
1238  t->Branch("trk_nPixel" , &trk_nPixel );
1239  t->Branch("trk_nStrip" , &trk_nStrip );
1240  t->Branch("trk_nOuterLost", &trk_nOuterLost );
1241  t->Branch("trk_nInnerLost", &trk_nInnerLost );
1242  t->Branch("trk_nPixelLay", &trk_nPixelLay);
1243  t->Branch("trk_nStripLay", &trk_nStripLay);
1244  t->Branch("trk_n3DLay" , &trk_n3DLay );
1245  t->Branch("trk_nLostLay" , &trk_nLostLay );
1246  t->Branch("trk_algo" , &trk_algo );
1247  t->Branch("trk_originalAlgo", &trk_originalAlgo);
1248  t->Branch("trk_algoMask" , &trk_algoMask);
1249  t->Branch("trk_stopReason", &trk_stopReason);
1250  t->Branch("trk_isHP" , &trk_isHP );
1251  if(includeSeeds_) {
1252  t->Branch("trk_seedIdx" , &trk_seedIdx );
1253  }
1254  t->Branch("trk_vtxIdx" , &trk_vtxIdx);
1255  if(includeTrackingParticles_) {
1256  t->Branch("trk_shareFrac", &trk_shareFrac);
1257  t->Branch("trk_simTrkIdx", &trk_simTrkIdx );
1258  }
1259  else {
1260  t->Branch("trk_isTrue", &trk_isTrue);
1261  }
1262  if(includeAllHits_) {
1263  t->Branch("trk_hitIdx" , &trk_hitIdx);
1264  t->Branch("trk_hitType", &trk_hitType);
1265  }
1266  if(includeTrackingParticles_) {
1267  //sim tracks
1268  t->Branch("sim_event" , &sim_event );
1269  t->Branch("sim_bunchCrossing", &sim_bunchCrossing);
1270  t->Branch("sim_pdgId" , &sim_pdgId );
1271  t->Branch("sim_genPdgIds", &sim_genPdgIds);
1272  t->Branch("sim_isFromBHadron", &sim_isFromBHadron);
1273  t->Branch("sim_px" , &sim_px );
1274  t->Branch("sim_py" , &sim_py );
1275  t->Branch("sim_pz" , &sim_pz );
1276  t->Branch("sim_pt" , &sim_pt );
1277  t->Branch("sim_eta" , &sim_eta );
1278  t->Branch("sim_phi" , &sim_phi );
1279  t->Branch("sim_pca_pt" , &sim_pca_pt );
1280  t->Branch("sim_pca_eta" , &sim_pca_eta );
1281  t->Branch("sim_pca_lambda", &sim_pca_lambda);
1282  t->Branch("sim_pca_cotTheta", &sim_pca_cotTheta);
1283  t->Branch("sim_pca_phi" , &sim_pca_phi );
1284  t->Branch("sim_pca_dxy" , &sim_pca_dxy );
1285  t->Branch("sim_pca_dz" , &sim_pca_dz );
1286  t->Branch("sim_q" , &sim_q );
1287  t->Branch("sim_nValid" , &sim_nValid );
1288  t->Branch("sim_nPixel" , &sim_nPixel );
1289  t->Branch("sim_nStrip" , &sim_nStrip );
1290  t->Branch("sim_nLay" , &sim_nLay );
1291  t->Branch("sim_nPixelLay", &sim_nPixelLay);
1292  t->Branch("sim_n3DLay" , &sim_n3DLay );
1293  t->Branch("sim_trkIdx" , &sim_trkIdx );
1294  t->Branch("sim_shareFrac", &sim_shareFrac);
1295  if(includeSeeds_) {
1296  t->Branch("sim_seedIdx" , &sim_seedIdx );
1297  }
1298  t->Branch("sim_parentVtxIdx", &sim_parentVtxIdx);
1299  t->Branch("sim_decayVtxIdx", &sim_decayVtxIdx);
1300  if(includeAllHits_) {
1301  t->Branch("sim_simHitIdx" , &sim_simHitIdx );
1302  }
1303  }
1304  if(includeAllHits_) {
1305  //pixels
1306  t->Branch("pix_isBarrel" , &pix_isBarrel );
1307  pix_detId.book("pix", t);
1308  t->Branch("pix_trkIdx" , &pix_trkIdx );
1309  if(includeSeeds_) {
1310  t->Branch("pix_seeIdx" , &pix_seeIdx );
1311  }
1312  t->Branch("pix_simHitIdx" , &pix_simHitIdx);
1313  t->Branch("pix_chargeFraction", &pix_chargeFraction);
1314  t->Branch("pix_simType", &pix_simType);
1315  t->Branch("pix_x" , &pix_x );
1316  t->Branch("pix_y" , &pix_y );
1317  t->Branch("pix_z" , &pix_z );
1318  t->Branch("pix_xx" , &pix_xx );
1319  t->Branch("pix_xy" , &pix_xy );
1320  t->Branch("pix_yy" , &pix_yy );
1321  t->Branch("pix_yz" , &pix_yz );
1322  t->Branch("pix_zz" , &pix_zz );
1323  t->Branch("pix_zx" , &pix_zx );
1324  t->Branch("pix_radL" , &pix_radL );
1325  t->Branch("pix_bbxi" , &pix_bbxi );
1326  t->Branch("pix_bbxi" , &pix_bbxi );
1327  //strips
1328  if(includeStripHits_){
1329  t->Branch("str_isBarrel" , &str_isBarrel );
1330  str_detId.book("str", t);
1331  t->Branch("str_trkIdx" , &str_trkIdx );
1332  if(includeSeeds_) {
1333  t->Branch("str_seeIdx" , &str_seeIdx );
1334  }
1335  t->Branch("str_simHitIdx" , &str_simHitIdx);
1336  t->Branch("str_chargeFraction", &str_chargeFraction);
1337  t->Branch("str_simType", &str_simType);
1338  t->Branch("str_x" , &str_x );
1339  t->Branch("str_y" , &str_y );
1340  t->Branch("str_z" , &str_z );
1341  t->Branch("str_xx" , &str_xx );
1342  t->Branch("str_xy" , &str_xy );
1343  t->Branch("str_yy" , &str_yy );
1344  t->Branch("str_yz" , &str_yz );
1345  t->Branch("str_zz" , &str_zz );
1346  t->Branch("str_zx" , &str_zx );
1347  t->Branch("str_radL" , &str_radL );
1348  t->Branch("str_bbxi" , &str_bbxi );
1349  //matched hits
1350  t->Branch("glu_isBarrel" , &glu_isBarrel );
1351  glu_detId.book("glu", t);
1352  t->Branch("glu_monoIdx" , &glu_monoIdx );
1353  t->Branch("glu_stereoIdx" , &glu_stereoIdx);
1354  if(includeSeeds_) {
1355  t->Branch("glu_seeIdx" , &glu_seeIdx );
1356  }
1357  t->Branch("glu_x" , &glu_x );
1358  t->Branch("glu_y" , &glu_y );
1359  t->Branch("glu_z" , &glu_z );
1360  t->Branch("glu_xx" , &glu_xx );
1361  t->Branch("glu_xy" , &glu_xy );
1362  t->Branch("glu_yy" , &glu_yy );
1363  t->Branch("glu_yz" , &glu_yz );
1364  t->Branch("glu_zz" , &glu_zz );
1365  t->Branch("glu_zx" , &glu_zx );
1366  t->Branch("glu_radL" , &glu_radL );
1367  t->Branch("glu_bbxi" , &glu_bbxi );
1368  }
1369  //phase2 OT
1370  if(includePhase2OTHits_){
1371  t->Branch("ph2_isBarrel" , &ph2_isBarrel );
1372  ph2_detId.book("ph2", t);
1373  t->Branch("ph2_trkIdx" , &ph2_trkIdx );
1374  if(includeSeeds_) {
1375  t->Branch("ph2_seeIdx" , &ph2_seeIdx );
1376  }
1377  t->Branch("ph2_simHitIdx" , &ph2_simHitIdx);
1378  t->Branch("ph2_simType", &ph2_simType);
1379  t->Branch("ph2_x" , &ph2_x );
1380  t->Branch("ph2_y" , &ph2_y );
1381  t->Branch("ph2_z" , &ph2_z );
1382  t->Branch("ph2_xx" , &ph2_xx );
1383  t->Branch("ph2_xy" , &ph2_xy );
1384  t->Branch("ph2_yy" , &ph2_yy );
1385  t->Branch("ph2_yz" , &ph2_yz );
1386  t->Branch("ph2_zz" , &ph2_zz );
1387  t->Branch("ph2_zx" , &ph2_zx );
1388  t->Branch("ph2_radL" , &ph2_radL );
1389  t->Branch("ph2_bbxi" , &ph2_bbxi );
1390  t->Branch("ph2_bbxi" , &ph2_bbxi );
1391  }
1392  //invalid hits
1393  t->Branch("inv_isBarrel" , &inv_isBarrel );
1394  if(includeStripHits_) inv_detId.book("inv", t);
1395  else inv_detId_phase2.book("inv", t);
1396  t->Branch("inv_type" , &inv_type );
1397  //simhits
1398  if(includeStripHits_) simhit_detId.book("simhit", t);
1399  else simhit_detId_phase2.book("simhit", t);
1400  t->Branch("simhit_x" , &simhit_x);
1401  t->Branch("simhit_y" , &simhit_y);
1402  t->Branch("simhit_z" , &simhit_z);
1403  t->Branch("simhit_particle", &simhit_particle);
1404  t->Branch("simhit_process" , &simhit_process);
1405  t->Branch("simhit_eloss" , &simhit_eloss);
1406  t->Branch("simhit_tof" , &simhit_tof);
1407  //t->Branch("simhit_simTrackId", &simhit_simTrackId);
1408  t->Branch("simhit_simTrkIdx", &simhit_simTrkIdx);
1409  t->Branch("simhit_hitIdx" , &simhit_hitIdx);
1410  t->Branch("simhit_hitType" , &simhit_hitType);
1411  }
1412  //beam spot
1413  t->Branch("bsp_x" , &bsp_x , "bsp_x/F");
1414  t->Branch("bsp_y" , &bsp_y , "bsp_y/F");
1415  t->Branch("bsp_z" , &bsp_z , "bsp_z/F");
1416  t->Branch("bsp_sigmax" , &bsp_sigmax , "bsp_sigmax/F");
1417  t->Branch("bsp_sigmay" , &bsp_sigmay , "bsp_sigmay/F");
1418  t->Branch("bsp_sigmaz" , &bsp_sigmaz , "bsp_sigmaz/F");
1419  if(includeSeeds_) {
1420  //seeds
1421  t->Branch("see_fitok" , &see_fitok );
1422  t->Branch("see_px" , &see_px );
1423  t->Branch("see_py" , &see_py );
1424  t->Branch("see_pz" , &see_pz );
1425  t->Branch("see_pt" , &see_pt );
1426  t->Branch("see_eta" , &see_eta );
1427  t->Branch("see_phi" , &see_phi );
1428  t->Branch("see_dxy" , &see_dxy );
1429  t->Branch("see_dz" , &see_dz );
1430  t->Branch("see_ptErr" , &see_ptErr );
1431  t->Branch("see_etaErr" , &see_etaErr );
1432  t->Branch("see_phiErr" , &see_phiErr );
1433  t->Branch("see_dxyErr" , &see_dxyErr );
1434  t->Branch("see_dzErr" , &see_dzErr );
1435  t->Branch("see_chi2" , &see_chi2 );
1436  t->Branch("see_statePt" , &see_statePt );
1437  t->Branch("see_stateTrajX", &see_stateTrajX);
1438  t->Branch("see_stateTrajY", &see_stateTrajY);
1439  t->Branch("see_stateTrajPx", &see_stateTrajPx);
1440  t->Branch("see_stateTrajPy", &see_stateTrajPy);
1441  t->Branch("see_stateTrajPz", &see_stateTrajPz);
1442  t->Branch("see_q" , &see_q );
1443  t->Branch("see_nValid" , &see_nValid );
1444  t->Branch("see_nPixel" , &see_nPixel );
1445  t->Branch("see_nGlued" , &see_nGlued );
1446  t->Branch("see_nStrip" , &see_nStrip );
1447  t->Branch("see_nPhase2OT", &see_nPhase2OT);
1448  t->Branch("see_algo" , &see_algo );
1449  t->Branch("see_stopReason", &see_stopReason);
1450  t->Branch("see_trkIdx" , &see_trkIdx );
1451  if(includeTrackingParticles_) {
1452  t->Branch("see_shareFrac", &see_shareFrac);
1453  t->Branch("see_simTrkIdx", &see_simTrkIdx );
1454  }
1455  else {
1456  t->Branch("see_isTrue", &see_isTrue);
1457  }
1458  if(includeAllHits_) {
1459  t->Branch("see_hitIdx" , &see_hitIdx );
1460  t->Branch("see_hitType", &see_hitType );
1461  }
1462  //seed algo offset
1463  t->Branch("see_offset" , &see_offset );
1464  }
1465 
1466  //vertices
1467  t->Branch("vtx_x" , &vtx_x);
1468  t->Branch("vtx_y" , &vtx_y);
1469  t->Branch("vtx_z" , &vtx_z);
1470  t->Branch("vtx_xErr" , &vtx_xErr);
1471  t->Branch("vtx_yErr" , &vtx_yErr);
1472  t->Branch("vtx_zErr" , &vtx_zErr);
1473  t->Branch("vtx_ndof" , &vtx_ndof);
1474  t->Branch("vtx_chi2" , &vtx_chi2);
1475  t->Branch("vtx_fake" , &vtx_fake);
1476  t->Branch("vtx_valid" , &vtx_valid);
1477  t->Branch("vtx_trkIdx" , &vtx_trkIdx);
1478 
1479  // tracking vertices
1480  t->Branch("simvtx_event" , &simvtx_event );
1481  t->Branch("simvtx_bunchCrossing", &simvtx_bunchCrossing);
1482  t->Branch("simvtx_processType", &simvtx_processType);
1483  t->Branch("simvtx_x" , &simvtx_x);
1484  t->Branch("simvtx_y" , &simvtx_y);
1485  t->Branch("simvtx_z" , &simvtx_z);
1486  t->Branch("simvtx_sourceSimIdx", &simvtx_sourceSimIdx);
1487  t->Branch("simvtx_daughterSimIdx", &simvtx_daughterSimIdx);
1488 
1489  t->Branch("simpv_idx" , &simpv_idx);
1490 
1491  //t->Branch("" , &);
1492 }
1493 
1494 
1496  // do anything here that needs to be done at desctruction time
1497  // (e.g. close files, deallocate resources etc.)
1498 }
1499 
1500 
1501 //
1502 // member functions
1503 //
1505 
1506  ev_run = 0;
1507  ev_lumi = 0;
1508  ev_event = 0;
1509 
1510  //tracks
1511  trk_px .clear();
1512  trk_py .clear();
1513  trk_pz .clear();
1514  trk_pt .clear();
1515  trk_inner_px .clear();
1516  trk_inner_py .clear();
1517  trk_inner_pz .clear();
1518  trk_inner_pt .clear();
1519  trk_outer_px .clear();
1520  trk_outer_py .clear();
1521  trk_outer_pz .clear();
1522  trk_outer_pt .clear();
1523  trk_eta .clear();
1524  trk_lambda .clear();
1525  trk_cotTheta .clear();
1526  trk_phi .clear();
1527  trk_dxy .clear();
1528  trk_dz .clear();
1529  trk_dxyPV .clear();
1530  trk_dzPV .clear();
1531  trk_dxyClosestPV.clear();
1532  trk_dzClosestPV.clear();
1533  trk_ptErr .clear();
1534  trk_etaErr .clear();
1535  trk_lambdaErr.clear();
1536  trk_phiErr .clear();
1537  trk_dxyErr .clear();
1538  trk_dzErr .clear();
1539  trk_refpoint_x.clear();
1540  trk_refpoint_y.clear();
1541  trk_refpoint_z.clear();
1542  trk_nChi2 .clear();
1543  trk_nChi2_1Dmod.clear();
1544  trk_ndof .clear();
1545  for(auto& mva: trk_mvas) {
1546  mva.clear();
1547  }
1548  for(auto& mask: trk_qualityMasks) {
1549  mask.clear();
1550  }
1551  trk_q .clear();
1552  trk_nValid .clear();
1553  trk_nInvalid .clear();
1554  trk_nPixel .clear();
1555  trk_nStrip .clear();
1556  trk_nOuterLost.clear();
1557  trk_nInnerLost.clear();
1558  trk_nPixelLay.clear();
1559  trk_nStripLay.clear();
1560  trk_n3DLay .clear();
1561  trk_nLostLay .clear();
1562  trk_algo .clear();
1563  trk_originalAlgo.clear();
1564  trk_algoMask .clear();
1565  trk_stopReason.clear();
1566  trk_isHP .clear();
1567  trk_seedIdx .clear();
1568  trk_vtxIdx .clear();
1569  trk_isTrue .clear();
1570  trk_shareFrac.clear();
1571  trk_simTrkIdx.clear();
1572  trk_hitIdx .clear();
1573  trk_hitType .clear();
1574  //sim tracks
1575  sim_event .clear();
1576  sim_bunchCrossing.clear();
1577  sim_pdgId .clear();
1578  sim_genPdgIds.clear();
1579  sim_isFromBHadron.clear();
1580  sim_px .clear();
1581  sim_py .clear();
1582  sim_pz .clear();
1583  sim_pt .clear();
1584  sim_eta .clear();
1585  sim_phi .clear();
1586  sim_pca_pt .clear();
1587  sim_pca_eta .clear();
1588  sim_pca_lambda.clear();
1589  sim_pca_cotTheta.clear();
1590  sim_pca_phi .clear();
1591  sim_pca_dxy .clear();
1592  sim_pca_dz .clear();
1593  sim_q .clear();
1594  sim_nValid .clear();
1595  sim_nPixel .clear();
1596  sim_nStrip .clear();
1597  sim_nLay .clear();
1598  sim_nPixelLay.clear();
1599  sim_n3DLay .clear();
1600  sim_trkIdx .clear();
1601  sim_seedIdx .clear();
1602  sim_shareFrac.clear();
1603  sim_parentVtxIdx.clear();
1604  sim_decayVtxIdx.clear();
1605  sim_simHitIdx .clear();
1606  //pixels
1607  pix_isBarrel .clear();
1608  pix_detId .clear();
1609  pix_trkIdx .clear();
1610  pix_seeIdx .clear();
1611  pix_simHitIdx.clear();
1612  pix_chargeFraction.clear();
1613  pix_simType.clear();
1614  pix_x .clear();
1615  pix_y .clear();
1616  pix_z .clear();
1617  pix_xx .clear();
1618  pix_xy .clear();
1619  pix_yy .clear();
1620  pix_yz .clear();
1621  pix_zz .clear();
1622  pix_zx .clear();
1623  pix_radL .clear();
1624  pix_bbxi .clear();
1625  //strips
1626  str_isBarrel .clear();
1627  str_detId .clear();
1628  str_trkIdx .clear();
1629  str_seeIdx .clear();
1630  str_simHitIdx.clear();
1631  str_chargeFraction.clear();
1632  str_simType.clear();
1633  str_x .clear();
1634  str_y .clear();
1635  str_z .clear();
1636  str_xx .clear();
1637  str_xy .clear();
1638  str_yy .clear();
1639  str_yz .clear();
1640  str_zz .clear();
1641  str_zx .clear();
1642  str_radL .clear();
1643  str_bbxi .clear();
1644  //matched hits
1645  glu_isBarrel .clear();
1646  glu_detId .clear();
1647  glu_monoIdx .clear();
1648  glu_stereoIdx.clear();
1649  glu_seeIdx .clear();
1650  glu_x .clear();
1651  glu_y .clear();
1652  glu_z .clear();
1653  glu_xx .clear();
1654  glu_xy .clear();
1655  glu_yy .clear();
1656  glu_yz .clear();
1657  glu_zz .clear();
1658  glu_zx .clear();
1659  glu_radL .clear();
1660  glu_bbxi .clear();
1661  //phase2 OT
1662  ph2_isBarrel .clear();
1663  ph2_detId .clear();
1664  ph2_trkIdx .clear();
1665  ph2_seeIdx .clear();
1666  ph2_simHitIdx.clear();
1667  ph2_simType.clear();
1668  ph2_x .clear();
1669  ph2_y .clear();
1670  ph2_z .clear();
1671  ph2_xx .clear();
1672  ph2_xy .clear();
1673  ph2_yy .clear();
1674  ph2_yz .clear();
1675  ph2_zz .clear();
1676  ph2_zx .clear();
1677  ph2_radL .clear();
1678  ph2_bbxi .clear();
1679  //invalid hits
1680  inv_isBarrel .clear();
1681  inv_detId .clear();
1682  inv_detId_phase2.clear();
1683  inv_type .clear();
1684  // simhits
1685  simhit_detId.clear();
1686  simhit_detId_phase2.clear();
1687  simhit_x.clear();
1688  simhit_y.clear();
1689  simhit_z.clear();
1690  simhit_particle.clear();
1691  simhit_process.clear();
1692  simhit_eloss.clear();
1693  simhit_tof.clear();
1694  //simhit_simTrackId.clear();
1695  simhit_simTrkIdx.clear();
1696  simhit_hitIdx.clear();
1697  simhit_hitType.clear();
1698  //beamspot
1699  bsp_x = -9999.;
1700  bsp_y = -9999.;
1701  bsp_z = -9999.;
1702  bsp_sigmax = -9999.;
1703  bsp_sigmay = -9999.;
1704  bsp_sigmaz = -9999.;
1705  //seeds
1706  see_fitok .clear();
1707  see_px .clear();
1708  see_py .clear();
1709  see_pz .clear();
1710  see_pt .clear();
1711  see_eta .clear();
1712  see_phi .clear();
1713  see_dxy .clear();
1714  see_dz .clear();
1715  see_ptErr .clear();
1716  see_etaErr .clear();
1717  see_phiErr .clear();
1718  see_dxyErr .clear();
1719  see_dzErr .clear();
1720  see_chi2 .clear();
1721  see_statePt.clear();
1722  see_stateTrajX.clear();
1723  see_stateTrajY.clear();
1724  see_stateTrajPx.clear();
1725  see_stateTrajPy.clear();
1726  see_stateTrajPz.clear();
1727  see_q .clear();
1728  see_nValid .clear();
1729  see_nPixel .clear();
1730  see_nGlued .clear();
1731  see_nStrip .clear();
1732  see_nPhase2OT.clear();
1733  see_algo .clear();
1734  see_stopReason.clear();
1735  see_trkIdx .clear();
1736  if(includeTrackingParticles_) {
1737  see_shareFrac.clear();
1738  see_simTrkIdx.clear();
1739  }
1740  see_hitIdx .clear();
1741  see_hitType .clear();
1742  //seed algo offset
1743  see_offset.clear();
1744 
1745  // vertices
1746  vtx_x.clear();
1747  vtx_y.clear();
1748  vtx_z.clear();
1749  vtx_xErr.clear();
1750  vtx_yErr.clear();
1751  vtx_zErr.clear();
1752  vtx_ndof.clear();
1753  vtx_chi2.clear();
1754  vtx_fake.clear();
1755  vtx_valid.clear();
1756  vtx_trkIdx.clear();
1757 
1758  // Tracking vertices
1759  simvtx_event.clear();
1760  simvtx_bunchCrossing.clear();
1761  simvtx_x.clear();
1762  simvtx_y.clear();
1763  simvtx_z.clear();
1764  simvtx_sourceSimIdx.clear();
1765  simvtx_daughterSimIdx.clear();
1766  simpv_idx.clear();
1767 }
1768 
1769 
1770 // ------------ method called for each event ------------
1771 void TrackingNtuple::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
1772 
1773  using namespace edm;
1774  using namespace reco;
1775  using namespace std;
1776 
1778  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
1779 
1781  iSetup.get<TransientRecHitRecord>().get(builderName_,theTTRHBuilder);
1782 
1783  edm::ESHandle<TrackerTopology> tTopoHandle;
1784  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
1785  const TrackerTopology& tTopo = *tTopoHandle;
1786 
1787  edm::ESHandle<TrackerGeometry> geometryHandle;
1788  iSetup.get<TrackerDigiGeometryRecord>().get(geometryHandle);
1789  const TrackerGeometry &tracker = *geometryHandle;
1790 
1792  iEvent.getByToken(trackAssociatorToken_, theAssociator);
1793  const reco::TrackToTrackingParticleAssociator& associatorByHits = *theAssociator;
1794 
1795  LogDebug("TrackingNtuple") << "Analyzing new event";
1796 
1797  //initialize tree variables
1798  clearVariables();
1799 
1800  // FIXME: we really need to move to edm::View for reading the
1801  // TrackingParticles... Unfortunately it has non-trivial
1802  // consequences on the associator/association interfaces etc.
1804  TrackingParticleRefKeySet tmpTPkeys;
1805  const TrackingParticleRefVector *tmpTPptr = nullptr;
1807  edm::Handle<TrackingParticleRefVector> TPCollectionHRefVector;
1808 
1809  if(!trackingParticleToken_.isUninitialized()) {
1810  iEvent.getByToken(trackingParticleToken_, TPCollectionH);
1811  for(size_t i=0, size=TPCollectionH->size(); i<size; ++i) {
1812  tmpTP.push_back(TrackingParticleRef(TPCollectionH, i));
1813  }
1814  tmpTPptr = &tmpTP;
1815  }
1816  else {
1817  iEvent.getByToken(trackingParticleRefToken_, TPCollectionHRefVector);
1818  tmpTPptr = TPCollectionHRefVector.product();
1819  for(const auto& ref: *tmpTPptr) {
1820  tmpTPkeys.insert(ref.key());
1821  }
1822  }
1823  const TrackingParticleRefVector& tpCollection = *tmpTPptr;
1824 
1825  // Fill mapping from Ref::key() to index
1826  TrackingParticleRefKeyToIndex tpKeyToIndex;
1827  for(size_t i=0; i<tpCollection.size(); ++i) {
1828  tpKeyToIndex[tpCollection[i].key()] = i;
1829  }
1830 
1831  // tracking vertices
1833  iEvent.getByToken(trackingVertexToken_, htv);
1834  const TrackingVertexCollection& tvs = *htv;
1835 
1836  // Fill mapping from Ref::key() to index
1837  TrackingVertexRefVector tvRefs;
1838  TrackingVertexRefKeyToIndex tvKeyToIndex;
1839  for(size_t i=0; i<tvs.size(); ++i) {
1840  const TrackingVertex& v = tvs[i];
1841  if(v.eventId().bunchCrossing() != 0) // Ignore OOTPU; would be better to not to hardcode?
1842  continue;
1843  tvKeyToIndex[i] = tvRefs.size();
1844  tvRefs.push_back(TrackingVertexRef(htv, i));
1845  }
1846 
1847  //get association maps, etc.
1848  Handle<ClusterTPAssociation> pCluster2TPListH;
1849  iEvent.getByToken(clusterTPMapToken_, pCluster2TPListH);
1850  const ClusterTPAssociation& clusterToTPMap = *pCluster2TPListH;
1852  iEvent.getByToken(simHitTPMapToken_, simHitsTPAssoc);
1853 
1854  // SimHit key -> index mapping
1855  SimHitRefKeyToIndex simHitRefKeyToIndex;
1856 
1857  //make a list to link TrackingParticles to its simhits
1858  std::vector<TPHitIndex> tpHitList;
1859 
1860  std::set<edm::ProductID> hitProductIds;
1861  std::map<edm::ProductID, size_t> seedCollToOffset;
1862 
1863  ev_run = iEvent.id().run();
1864  ev_lumi = iEvent.id().luminosityBlock();
1865  ev_event = iEvent.id().event();
1866 
1867  // Digi->Sim links for pixels and strips
1868  edm::Handle<edm::DetSetVector<PixelDigiSimLink> > pixelDigiSimLinksHandle;
1869  iEvent.getByToken(pixelSimLinkToken_, pixelDigiSimLinksHandle);
1870  const auto& pixelDigiSimLinks = *pixelDigiSimLinksHandle;
1871 
1872  edm::Handle<edm::DetSetVector<StripDigiSimLink> > stripDigiSimLinksHandle;
1873  iEvent.getByToken(stripSimLinkToken_, stripDigiSimLinksHandle);
1874 
1875  // Phase2 OT DigiSimLink
1876  edm::Handle<edm::DetSetVector<PixelDigiSimLink> > siphase2OTSimLinksHandle;
1877  iEvent.getByToken(siphase2OTSimLinksToken_, siphase2OTSimLinksHandle);
1878 
1879  //beamspot
1880  Handle<reco::BeamSpot> recoBeamSpotHandle;
1881  iEvent.getByToken(beamSpotToken_, recoBeamSpotHandle);
1882  BeamSpot const & bs = *recoBeamSpotHandle;
1883  fillBeamSpot(bs);
1884 
1885 
1886  //prapare list to link matched hits to collection
1887  vector<pair<int,int> > monoStereoClusterList;
1888  if(includeAllHits_) {
1889  // simhits
1890  fillSimHits(tracker, tpKeyToIndex, *simHitsTPAssoc, tTopo, simHitRefKeyToIndex, tpHitList);
1891 
1892  //pixel hits
1893  fillPixelHits(iEvent, clusterToTPMap, tpKeyToIndex, *simHitsTPAssoc, pixelDigiSimLinks, *theTTRHBuilder, tTopo, simHitRefKeyToIndex, hitProductIds);
1894 
1895  //strip hits
1896  if(includeStripHits_){
1897  LogDebug("TrackingNtuple") << "foundStripSimLink" ;
1898  const auto& stripDigiSimLinks = *stripDigiSimLinksHandle;
1899  fillStripRphiStereoHits(iEvent, clusterToTPMap, tpKeyToIndex, *simHitsTPAssoc, stripDigiSimLinks, *theTTRHBuilder, tTopo, simHitRefKeyToIndex, hitProductIds);
1900 
1901  //matched hits
1902  fillStripMatchedHits(iEvent, *theTTRHBuilder, tTopo, monoStereoClusterList);
1903  }
1904 
1905  if(includePhase2OTHits_){
1906  LogDebug("TrackingNtuple") << "foundPhase2OTSimLinks" ;
1907  const auto& phase2OTSimLinks = *siphase2OTSimLinksHandle;
1908  fillPhase2OTHits(iEvent, clusterToTPMap, tpKeyToIndex, *simHitsTPAssoc, phase2OTSimLinks, *theTTRHBuilder, tTopo, simHitRefKeyToIndex, hitProductIds);
1909  }
1910  }
1911 
1912  //seeds
1913  if(includeSeeds_) {
1914  fillSeeds(iEvent, tpCollection, tpKeyToIndex, bs, associatorByHits, *theTTRHBuilder, theMF.product(), monoStereoClusterList, hitProductIds, seedCollToOffset);
1915  }
1916 
1917  //tracks
1918  edm::Handle<edm::View<reco::Track> > tracksHandle;
1919  iEvent.getByToken(trackToken_, tracksHandle);
1920  const edm::View<reco::Track>& tracks = *tracksHandle;
1921  // The associator interfaces really need to be fixed...
1923  for(edm::View<Track>::size_type i=0; i<tracks.size(); ++i) {
1924  trackRefs.push_back(tracks.refAt(i));
1925  }
1926  std::vector<const MVACollection *> mvaColls;
1927  std::vector<const QualityMaskCollection *> qualColls;
1928  if(includeMVA_) {
1931 
1932  for(const auto& tokenTpl: mvaQualityCollectionTokens_) {
1933  iEvent.getByToken(std::get<0>(tokenTpl), hmva);
1934  iEvent.getByToken(std::get<1>(tokenTpl), hqual);
1935 
1936  mvaColls.push_back(hmva.product());
1937  qualColls.push_back(hqual.product());
1938  if(mvaColls.back()->size() != tracks.size()) {
1939  throw cms::Exception("Configuration") << "Inconsistency in track collection and MVA sizes. Track collection has " << tracks.size() << " tracks, whereas the MVA " << (mvaColls.size()-1) << " has " << mvaColls.back()->size() << " entries. Double-check your configuration.";
1940  }
1941  if(qualColls.back()->size() != tracks.size()) {
1942  throw cms::Exception("Configuration") << "Inconsistency in track collection and quality mask sizes. Track collection has " << tracks.size() << " tracks, whereas the quality mask " << (qualColls.size()-1) << " has " << qualColls.back()->size() << " entries. Double-check your configuration.";
1943  }
1944  }
1945  }
1946 
1948  iEvent.getByToken(vertexToken_, vertices);
1949 
1950  fillTracks(trackRefs, tpCollection, tpKeyToIndex, bs, *vertices, associatorByHits, *theTTRHBuilder, tTopo, hitProductIds, seedCollToOffset, mvaColls, qualColls);
1951 
1952  //tracking particles
1953  //sort association maps with simHits
1954  std::sort( tpHitList.begin(), tpHitList.end(), tpHitIndexListLessSort );
1955  fillTrackingParticles(iEvent, iSetup, trackRefs, bs, tpCollection, tvKeyToIndex, associatorByHits, tpHitList);
1956 
1957  // vertices
1958  fillVertices(*vertices, trackRefs);
1959 
1960  // tracking vertices
1961  fillTrackingVertices(tvRefs, tpKeyToIndex);
1962 
1963  t->Fill();
1964 
1965 }
1966 
1968  bsp_x = bs.x0();
1969  bsp_y = bs.y0();
1970  bsp_z = bs.x0();
1971  bsp_sigmax = bs.BeamWidthX();
1972  bsp_sigmay = bs.BeamWidthY();
1973  bsp_sigmaz = bs.sigmaZ();
1974 }
1975 
1976 namespace {
1977  template <typename SimLink> struct GetCluster;
1978  template <>
1979  struct GetCluster<PixelDigiSimLink> {
1980  static const SiPixelCluster& call(const OmniClusterRef& cluster) { return cluster.pixelCluster(); }
1981  };
1982  template <>
1983  struct GetCluster<StripDigiSimLink> {
1984  static const SiStripCluster& call(const OmniClusterRef& cluster) { return cluster.stripCluster(); }
1985  };
1986 }
1987 
1988 template <typename SimLink>
1990  DetId hitId, int clusterKey,
1992  const ClusterTPAssociation& clusterToTPMap,
1993  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
1995  const edm::DetSetVector<SimLink>& digiSimLinks,
1996  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
1997  HitType hitType
1998  ) {
1999  SimHitData ret;
2000 
2001  std::map<unsigned int, double> simTrackIdToChargeFraction;
2002  if(hitType == HitType::Phase2OT) simTrackIdToChargeFraction = chargeFraction(cluster.phase2OTCluster(), hitId, digiSimLinks);
2003  else simTrackIdToChargeFraction = chargeFraction(GetCluster<SimLink>::call(cluster), hitId, digiSimLinks);
2004 
2005  ret.type = HitSimType::Noise;
2006  auto range = clusterToTPMap.equal_range( cluster );
2007  if( range.first != range.second ) {
2008  for( auto ip=range.first; ip != range.second; ++ip ) {
2009  const TrackingParticleRef& trackingParticle = ip->second;
2010 
2011  // Find out if the cluster is from signal/ITPU/OOTPU
2012  const auto event = trackingParticle->eventId().event();
2013  const auto bx = trackingParticle->eventId().bunchCrossing();
2015  if(bx == 0) {
2016  type = (event == 0 ? HitSimType::Signal : HitSimType::ITPileup);
2017  }
2018  ret.type = static_cast<HitSimType>(std::min(static_cast<int>(ret.type), static_cast<int>(type)));
2019 
2020  // Limit to only input TrackingParticles (usually signal+ITPU)
2021  auto tpIndex = tpKeyToIndex.find(trackingParticle.key());
2022  if( tpIndex == tpKeyToIndex.end())
2023  continue;
2024 
2025  //now get the corresponding sim hit
2026  std::pair<TrackingParticleRef, TrackPSimHitRef> simHitTPpairWithDummyTP(trackingParticle,TrackPSimHitRef());
2027  //SimHit is dummy: for simHitTPAssociationListGreater sorting only the TP is needed
2028  auto range = std::equal_range(simHitsTPAssoc.begin(), simHitsTPAssoc.end(),
2030  int simHitKey = -1;
2031  bool foundElectron = false;
2032  edm::ProductID simHitID;
2033  for(auto ip = range.first; ip != range.second; ++ip) {
2034  TrackPSimHitRef TPhit = ip->second;
2035  DetId dId = DetId(TPhit->detUnitId());
2036  if (dId.rawId()==hitId.rawId()) {
2037  // skip electron SimHits for non-electron TPs also here
2038  if(std::abs(TPhit->particleType()) == 11 && std::abs(trackingParticle->pdgId()) != 11) {
2039  foundElectron = true;
2040  continue;
2041  }
2042 
2043  simHitKey = TPhit.key();
2044  simHitID = TPhit.id();
2045  break;
2046  }
2047  }
2048  if(simHitKey < 0) {
2049  // In case we didn't find a simhit because of filtered-out
2050  // electron SimHit, just ignore the missing SimHit.
2051  if(foundElectron)
2052  continue;
2053 
2054  auto ex = cms::Exception("LogicError") << "Did not find SimHit for reco hit DetId " << hitId.rawId()
2055  << " for TP " << trackingParticle.key() << " bx:event " << bx << ":" << event
2056  << ".\nFound SimHits from detectors ";
2057  for(auto ip = range.first; ip != range.second; ++ip) {
2058  TrackPSimHitRef TPhit = ip->second;
2059  DetId dId = DetId(TPhit->detUnitId());
2060  ex << dId.rawId() << " ";
2061  }
2062  if(trackingParticle->eventId().event() != 0) {
2063  ex << "\nSince this is a TrackingParticle from pileup, check that you're running the pileup mixing in playback mode.";
2064  }
2065  throw ex;
2066  }
2067  auto simHitIndex = simHitRefKeyToIndex.at(std::make_pair(simHitKey, simHitID));
2068  ret.matchingSimHit.push_back(simHitIndex);
2069 
2070  double chargeFraction = 0.;
2071  for(const SimTrack& simtrk: trackingParticle->g4Tracks()) {
2072  auto found = simTrackIdToChargeFraction.find(simtrk.trackId());
2073  if(found != simTrackIdToChargeFraction.end()) {
2074  chargeFraction += found->second;
2075  }
2076  }
2077  ret.chargeFraction.push_back(chargeFraction);
2078 
2079  // only for debug prints
2080  ret.bunchCrossing.push_back(bx);
2081  ret.event.push_back(event);
2082 
2083  simhit_hitIdx[simHitIndex].push_back(clusterKey);
2084  simhit_hitType[simHitIndex].push_back(static_cast<int>(hitType));
2085  }
2086  }
2087 
2088  return ret;
2089 }
2090 
2092  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2094  const TrackerTopology& tTopo,
2095  SimHitRefKeyToIndex& simHitRefKeyToIndex,
2096  std::vector<TPHitIndex>& tpHitList) {
2097 
2098  for(const auto& assoc: simHitsTPAssoc) {
2099  auto tpKey = assoc.first.key();
2100 
2101  // SimHitTPAssociationList can contain more TrackingParticles than
2102  // what are given to this EDAnalyzer, so we can filter those out here.
2103  auto found = tpKeyToIndex.find(tpKey);
2104  if(found == tpKeyToIndex.end())
2105  continue;
2106  const auto tpIndex = found->second;
2107 
2108  // skip non-tracker simhits (mostly muons)
2109  const auto& simhit = *(assoc.second);
2110  auto detId = DetId(simhit.detUnitId());
2111  if(detId.det() != DetId::Tracker) continue;
2112 
2113  // Skip electron SimHits for non-electron TrackingParticles to
2114  // filter out delta rays. The delta ray hits just confuse. If we
2115  // need them later, let's add them as a separate "collection" of
2116  // hits of a TP
2117  const TrackingParticle& tp = *(assoc.first);
2118  if(std::abs(simhit.particleType()) == 11 && std::abs(tp.pdgId()) != 11) continue;
2119 
2120  auto simHitKey = std::make_pair(assoc.second.key(), assoc.second.id());
2121 
2122  if(simHitRefKeyToIndex.find(simHitKey) != simHitRefKeyToIndex.end()) {
2123  for(const auto& assoc2: simHitsTPAssoc) {
2124  if(std::make_pair(assoc2.second.key(), assoc2.second.id()) == simHitKey) {
2125 
2126 #ifdef EDM_ML_DEBUG
2127  auto range1 = std::equal_range(simHitsTPAssoc.begin(), simHitsTPAssoc.end(),
2128  std::make_pair(assoc.first, TrackPSimHitRef()),
2130  auto range2 = std::equal_range(simHitsTPAssoc.begin(), simHitsTPAssoc.end(),
2131  std::make_pair(assoc2.first, TrackPSimHitRef()),
2133 
2134  LogTrace("TrackingNtuple") << "Earlier TP " << assoc2.first.key() << " SimTrack Ids";
2135  for(const auto& simTrack: assoc2.first->g4Tracks()) {
2136  edm::LogPrint("TrackingNtuple") << " SimTrack " << simTrack.trackId() << " BX:event " << simTrack.eventId().bunchCrossing() << ":" << simTrack.eventId().event();
2137  }
2138  for(auto iHit = range2.first; iHit != range2.second; ++iHit) {
2139  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();
2140  }
2141  LogTrace("TrackingNtuple") << "Current TP " << assoc.first.key() << " SimTrack Ids";
2142  for(const auto& simTrack: assoc.first->g4Tracks()) {
2143  edm::LogPrint("TrackingNtuple") << " SimTrack " << simTrack.trackId() << " BX:event " << simTrack.eventId().bunchCrossing() << ":" << simTrack.eventId().event();
2144  }
2145  for(auto iHit = range1.first; iHit != range1.second; ++iHit) {
2146  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();
2147  }
2148 #endif
2149 
2150  throw cms::Exception("LogicError") << "Got second time the SimHit " << simHitKey.first << " of " << simHitKey.second << ", first time with TrackingParticle " << assoc2.first.key() << ", now with " << tpKey;
2151  }
2152  }
2153  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!";
2154  }
2155 
2156  auto det = tracker.idToDetUnit(detId);
2157  if(!det)
2158  throw cms::Exception("LogicError") << "Did not find a det unit for DetId " << simhit.detUnitId() << " from tracker geometry";
2159 
2160  const auto pos = det->surface().toGlobal(simhit.localPosition());
2161  const float tof = simhit.timeOfFlight();
2162 
2163  const auto simHitIndex = simhit_x.size();
2164  simHitRefKeyToIndex[simHitKey] = simHitIndex;
2165 
2166  if(includeStripHits_) simhit_detId.push_back(tTopo, detId);
2167  else simhit_detId_phase2.push_back(tTopo, detId);
2168  simhit_x.push_back(pos.x());
2169  simhit_y.push_back(pos.y());
2170  simhit_z.push_back(pos.z());
2171  simhit_particle.push_back(simhit.particleType());
2172  simhit_process.push_back(simhit.processType());
2173  simhit_eloss.push_back(simhit.energyLoss());
2174  simhit_tof.push_back(tof);
2175  //simhit_simTrackId.push_back(simhit.trackId());
2176 
2177  simhit_simTrkIdx.push_back(tpIndex);
2178 
2179  simhit_hitIdx.emplace_back(); // filled in matchCluster
2180  simhit_hitType.emplace_back(); // filled in matchCluster
2181 
2182  tpHitList.emplace_back(tpKey, simHitIndex, tof, simhit.detUnitId());
2183  }
2184 }
2185 
2187  const ClusterTPAssociation& clusterToTPMap,
2188  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2190  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink,
2191  const TransientTrackingRecHitBuilder& theTTRHBuilder,
2192  const TrackerTopology& tTopo,
2193  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2194  std::set<edm::ProductID>& hitProductIds
2195  ) {
2197  iEvent.getByToken(pixelRecHitToken_, pixelHits);
2198  for (auto it = pixelHits->begin(); it!=pixelHits->end(); it++ ) {
2199  const DetId hitId = it->detId();
2200  for (auto hit = it->begin(); hit!=it->end(); hit++ ) {
2201  TransientTrackingRecHit::RecHitPointer ttrh = theTTRHBuilder.build(&*hit);
2202 
2203  hitProductIds.insert(hit->cluster().id());
2204 
2205  const int key = hit->cluster().key();
2206  const int lay = tTopo.layer(hitId);
2207  SimHitData simHitData = matchCluster(hit->firstClusterRef(), hitId, key, ttrh,
2208  clusterToTPMap, tpKeyToIndex, simHitsTPAssoc, digiSimLink, simHitRefKeyToIndex, HitType::Pixel);
2209 
2210  pix_isBarrel .push_back( hitId.subdetId()==1 );
2211  pix_detId .push_back( tTopo, hitId );
2212  pix_trkIdx .emplace_back(); // filled in fillTracks
2213  pix_seeIdx .emplace_back(); // filled in fillSeeds
2214  pix_simHitIdx.push_back( simHitData.matchingSimHit );
2215  pix_simType.push_back( static_cast<int>(simHitData.type) );
2216  pix_x .push_back( ttrh->globalPosition().x() );
2217  pix_y .push_back( ttrh->globalPosition().y() );
2218  pix_z .push_back( ttrh->globalPosition().z() );
2219  pix_xx .push_back( ttrh->globalPositionError().cxx() );
2220  pix_xy .push_back( ttrh->globalPositionError().cyx() );
2221  pix_yy .push_back( ttrh->globalPositionError().cyy() );
2222  pix_yz .push_back( ttrh->globalPositionError().czy() );
2223  pix_zz .push_back( ttrh->globalPositionError().czz() );
2224  pix_zx .push_back( ttrh->globalPositionError().czx() );
2225  pix_chargeFraction.push_back( simHitData.chargeFraction );
2226  pix_radL .push_back( ttrh->surface()->mediumProperties().radLen() );
2227  pix_bbxi .push_back( ttrh->surface()->mediumProperties().xi() );
2228  LogTrace("TrackingNtuple") << "pixHit cluster=" << key
2229  << " subdId=" << hitId.subdetId()
2230  << " lay=" << lay
2231  << " rawId=" << hitId.rawId()
2232  << " pos =" << ttrh->globalPosition()
2233  << " nMatchingSimHit=" << simHitData.matchingSimHit.size();
2234  if(!simHitData.matchingSimHit.empty()) {
2235  const auto simHitIdx = simHitData.matchingSimHit[0];
2236  LogTrace("TrackingNtuple") << " firstMatchingSimHit=" << simHitIdx
2237  << " simHitPos=" << GlobalPoint(simhit_x[simHitIdx], simhit_y[simHitIdx], simhit_z[simHitIdx])
2238  << " energyLoss=" << simhit_eloss[simHitIdx]
2239  << " particleType=" << simhit_particle[simHitIdx]
2240  << " processType=" << simhit_process[simHitIdx]
2241  << " bunchCrossing=" << simHitData.bunchCrossing[0]
2242  << " event=" << simHitData.event[0];
2243  }
2244  }
2245  }
2246 }
2247 
2248 
2250  const ClusterTPAssociation& clusterToTPMap,
2251  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2253  const edm::DetSetVector<StripDigiSimLink>& digiSimLink,
2254  const TransientTrackingRecHitBuilder& theTTRHBuilder,
2255  const TrackerTopology& tTopo,
2256  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2257  std::set<edm::ProductID>& hitProductIds
2258  ) {
2259  //index strip hit branches by cluster index
2261  iEvent.getByToken(stripRphiRecHitToken_, rphiHits);
2263  iEvent.getByToken(stripStereoRecHitToken_, stereoHits);
2264  int totalStripHits = rphiHits->dataSize()+stereoHits->dataSize();
2265  str_isBarrel .resize(totalStripHits);
2266  str_detId .resize(totalStripHits);
2267  str_trkIdx .resize(totalStripHits); // filled in fillTracks
2268  str_seeIdx .resize(totalStripHits); // filled in fillSeeds
2269  str_simHitIdx.resize(totalStripHits);
2270  str_simType .resize(totalStripHits);
2271  str_x .resize(totalStripHits);
2272  str_y .resize(totalStripHits);
2273  str_z .resize(totalStripHits);
2274  str_xx .resize(totalStripHits);
2275  str_xy .resize(totalStripHits);
2276  str_yy .resize(totalStripHits);
2277  str_yz .resize(totalStripHits);
2278  str_zz .resize(totalStripHits);
2279  str_zx .resize(totalStripHits);
2280  str_chargeFraction.resize(totalStripHits);
2281  str_radL .resize(totalStripHits);
2282  str_bbxi .resize(totalStripHits);
2283 
2284  auto fill = [&](const SiStripRecHit2DCollection& hits, const char *name) {
2285  for(const auto& detset: hits) {
2286  const DetId hitId = detset.detId();
2287  for(const auto& hit: detset) {
2288  TransientTrackingRecHit::RecHitPointer ttrh = theTTRHBuilder.build(&hit);
2289 
2290  hitProductIds.insert(hit.cluster().id());
2291 
2292  const int key = hit.cluster().key();
2293  const int lay = tTopo.layer(hitId);
2294  SimHitData simHitData = matchCluster(hit.firstClusterRef(), hitId, key, ttrh,
2295  clusterToTPMap, tpKeyToIndex, simHitsTPAssoc, digiSimLink, simHitRefKeyToIndex, HitType::Strip);
2297  str_detId.set(key, tTopo, hitId);
2298  str_simHitIdx[key] = simHitData.matchingSimHit;
2299  str_simType [key] = static_cast<int>(simHitData.type);
2300  str_x [key] = ttrh->globalPosition().x();
2301  str_y [key] = ttrh->globalPosition().y();
2302  str_z [key] = ttrh->globalPosition().z();
2303  str_xx [key] = ttrh->globalPositionError().cxx();
2304  str_xy [key] = ttrh->globalPositionError().cyx();
2305  str_yy [key] = ttrh->globalPositionError().cyy();
2306  str_yz [key] = ttrh->globalPositionError().czy();
2307  str_zz [key] = ttrh->globalPositionError().czz();
2308  str_zx [key] = ttrh->globalPositionError().czx();
2309  str_chargeFraction[key] = simHitData.chargeFraction;
2310  str_radL [key] = ttrh->surface()->mediumProperties().radLen();
2311  str_bbxi [key] = ttrh->surface()->mediumProperties().xi();
2312  LogTrace("TrackingNtuple") << name << " cluster=" << key
2313  << " subdId=" << hitId.subdetId()
2314  << " lay=" << lay
2315  << " rawId=" << hitId.rawId()
2316  << " pos =" << ttrh->globalPosition()
2317  << " nMatchingSimHit=" << simHitData.matchingSimHit.size();
2318  if(!simHitData.matchingSimHit.empty()) {
2319  const auto simHitIdx = simHitData.matchingSimHit[0];
2320  LogTrace("TrackingNtuple") << " firstMatchingSimHit=" << simHitIdx
2321  << " simHitPos=" << GlobalPoint(simhit_x[simHitIdx], simhit_y[simHitIdx], simhit_z[simHitIdx])
2322  << " simHitPos=" << GlobalPoint(simhit_x[simHitIdx], simhit_y[simHitIdx], simhit_z[simHitIdx])
2323  << " energyLoss=" << simhit_eloss[simHitIdx]
2324  << " particleType=" << simhit_particle[simHitIdx]
2325  << " processType=" << simhit_process[simHitIdx]
2326  << " bunchCrossing=" << simHitData.bunchCrossing[0]
2327  << " event=" << simHitData.event[0];
2328  }
2329  }
2330  }
2331  };
2332 
2333  fill(*rphiHits, "stripRPhiHit");
2334  fill(*stereoHits, "stripStereoHit");
2335 }
2336 
2338  const TransientTrackingRecHitBuilder& theTTRHBuilder,
2339  const TrackerTopology& tTopo,
2340  std::vector<std::pair<int, int> >& monoStereoClusterList
2341  ) {
2343  iEvent.getByToken(stripMatchedRecHitToken_, matchedHits);
2344  for (auto it = matchedHits->begin(); it!=matchedHits->end(); it++ ) {
2345  const DetId hitId = it->detId();
2346  for (auto hit = it->begin(); hit!=it->end(); hit++ ) {
2347  TransientTrackingRecHit::RecHitPointer ttrh = theTTRHBuilder.build(&*hit);
2348  const int lay = tTopo.layer(hitId);
2349  monoStereoClusterList.emplace_back(hit->monoHit().cluster().key(),hit->stereoHit().cluster().key());
2350  glu_isBarrel .push_back( (hitId.subdetId()==StripSubdetector::TIB || hitId.subdetId()==StripSubdetector::TOB) );
2351  glu_detId .push_back( tTopo, hitId );
2352  glu_monoIdx .push_back( hit->monoHit().cluster().key() );
2353  glu_stereoIdx.push_back( hit->stereoHit().cluster().key() );
2354  glu_seeIdx .emplace_back(); // filled in fillSeeds
2355  glu_x .push_back( ttrh->globalPosition().x() );
2356  glu_y .push_back( ttrh->globalPosition().y() );
2357  glu_z .push_back( ttrh->globalPosition().z() );
2358  glu_xx .push_back( ttrh->globalPositionError().cxx() );
2359  glu_xy .push_back( ttrh->globalPositionError().cyx() );
2360  glu_yy .push_back( ttrh->globalPositionError().cyy() );
2361  glu_yz .push_back( ttrh->globalPositionError().czy() );
2362  glu_zz .push_back( ttrh->globalPositionError().czz() );
2363  glu_zx .push_back( ttrh->globalPositionError().czx() );
2364  glu_radL .push_back( ttrh->surface()->mediumProperties().radLen() );
2365  glu_bbxi .push_back( ttrh->surface()->mediumProperties().xi() );
2366  LogTrace("TrackingNtuple") << "stripMatchedHit"
2367  << " cluster0=" << hit->stereoHit().cluster().key()
2368  << " cluster1=" << hit->monoHit().cluster().key()
2369  << " subdId=" << hitId.subdetId()
2370  << " lay=" << lay
2371  << " rawId=" << hitId.rawId()
2372  << " pos =" << ttrh->globalPosition();
2373  }
2374  }
2375 }
2376 
2378  const ClusterTPAssociation& clusterToTPMap,
2379  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2381  const edm::DetSetVector<PixelDigiSimLink>& digiSimLink,
2382  const TransientTrackingRecHitBuilder& theTTRHBuilder,
2383  const TrackerTopology& tTopo,
2384  const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2385  std::set<edm::ProductID>& hitProductIds
2386  ) {
2388  iEvent.getByToken(phase2OTRecHitToken_, phase2OTHits);
2389  for (auto it = phase2OTHits->begin(); it!=phase2OTHits->end(); it++ ) {
2390  const DetId hitId = it->detId();
2391  for (auto hit = it->begin(); hit!=it->end(); hit++ ) {
2392  TransientTrackingRecHit::RecHitPointer ttrh = theTTRHBuilder.build(&*hit);
2393 
2394  hitProductIds.insert(hit->cluster().id());
2395 
2396  const int key = hit->cluster().key();
2397  const int lay = tTopo.layer(hitId);
2398  SimHitData simHitData = matchCluster(hit->firstClusterRef(), hitId, key, ttrh,
2399  clusterToTPMap, tpKeyToIndex, simHitsTPAssoc, digiSimLink, simHitRefKeyToIndex, HitType::Phase2OT);
2400 
2401  ph2_isBarrel .push_back( hitId.subdetId()==1 );
2402  ph2_detId .push_back( tTopo, hitId );
2403  ph2_trkIdx .emplace_back(); // filled in fillTracks
2404  ph2_seeIdx .emplace_back(); // filled in fillSeeds
2405  ph2_simHitIdx.push_back( simHitData.matchingSimHit );
2406  ph2_simType.push_back( static_cast<int>(simHitData.type) );
2407  ph2_x .push_back( ttrh->globalPosition().x() );
2408  ph2_y .push_back( ttrh->globalPosition().y() );
2409  ph2_z .push_back( ttrh->globalPosition().z() );
2410  ph2_xx .push_back( ttrh->globalPositionError().cxx() );
2411  ph2_xy .push_back( ttrh->globalPositionError().cyx() );
2412  ph2_yy .push_back( ttrh->globalPositionError().cyy() );
2413  ph2_yz .push_back( ttrh->globalPositionError().czy() );
2414  ph2_zz .push_back( ttrh->globalPositionError().czz() );
2415  ph2_zx .push_back( ttrh->globalPositionError().czx() );
2416  ph2_radL .push_back( ttrh->surface()->mediumProperties().radLen() );
2417  ph2_bbxi .push_back( ttrh->surface()->mediumProperties().xi() );
2418 
2419  LogTrace("TrackingNtuple") << "phase2 OT cluster=" << key
2420  << " subdId=" << hitId.subdetId()
2421  << " lay=" << lay
2422  << " rawId=" << hitId.rawId()
2423  << " pos =" << ttrh->globalPosition()
2424  << " nMatchingSimHit=" << simHitData.matchingSimHit.size();
2425 
2426  if(!simHitData.matchingSimHit.empty()) {
2427  const auto simHitIdx = simHitData.matchingSimHit[0];
2428  LogTrace("TrackingNtuple") << " firstMatchingSimHit=" << simHitIdx
2429  << " simHitPos=" << GlobalPoint(simhit_x[simHitIdx], simhit_y[simHitIdx], simhit_z[simHitIdx])
2430  << " energyLoss=" << simhit_eloss[simHitIdx]
2431  << " particleType=" << simhit_particle[simHitIdx]
2432  << " processType=" << simhit_process[simHitIdx]
2433  << " bunchCrossing=" << simHitData.bunchCrossing[0]
2434  << " event=" << simHitData.event[0];
2435  }
2436  }
2437  }
2438 }
2439 
2440 
2442  const TrackingParticleRefVector& tpCollection,
2443  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2444  const reco::BeamSpot& bs,
2445  const reco::TrackToTrackingParticleAssociator& associatorByHits,
2446  const TransientTrackingRecHitBuilder& theTTRHBuilder,
2447  const MagneticField *theMF,
2448  const std::vector<std::pair<int, int> >& monoStereoClusterList,
2449  const std::set<edm::ProductID>& hitProductIds,
2450  std::map<edm::ProductID, size_t>& seedCollToOffset
2451  ) {
2452  TSCBLBuilderNoMaterial tscblBuilder;
2453  for(size_t iColl=0; iColl < seedTokens_.size(); ++iColl) {
2454  const auto& seedToken = seedTokens_[iColl];
2455 
2456  edm::Handle<edm::View<reco::Track> > seedTracksHandle;
2457  iEvent.getByToken(seedToken, seedTracksHandle);
2458  const auto& seedTracks = *seedTracksHandle;
2459 
2460  if(seedTracks.empty())
2461  continue;
2462 
2464  labelsForToken(seedToken, labels);
2465 
2466  const auto& seedStopReasonToken = seedStopReasonTokens_[iColl];
2467  edm::Handle<std::vector<short> > seedStopReasonHandle;
2468  iEvent.getByToken(seedStopReasonToken, seedStopReasonHandle);
2469  const auto& seedStopReasons = *seedStopReasonHandle;
2470  if(seedTracks.size() != seedStopReasons.size()) {
2472  labelsForToken(seedStopReasonToken, labels2);
2473 
2474  throw cms::Exception("LogicError") << "Got " << seedTracks.size() << " seeds, but " << seedStopReasons.size() << " seed stopping reasons for collections " << labels.module << ", " << labels2.module;
2475  }
2476 
2477  // The associator interfaces really need to be fixed...
2478  edm::RefToBaseVector<reco::Track> seedTrackRefs;
2479  for(edm::View<reco::Track>::size_type i=0; i<seedTracks.size(); ++i) {
2480  seedTrackRefs.push_back(seedTracks.refAt(i));
2481  }
2482  reco::RecoToSimCollection recSimColl = associatorByHits.associateRecoToSim(seedTrackRefs, tpCollection);
2483  reco::SimToRecoCollection simRecColl = associatorByHits.associateSimToReco(seedTrackRefs, tpCollection);
2484 
2485  TString label = labels.module;
2486  //format label to match algoName
2487  label.ReplaceAll("seedTracks", "");
2488  label.ReplaceAll("Seeds","");
2489  label.ReplaceAll("muonSeeded","muonSeededStep");
2490  int algo = reco::TrackBase::algoByName(label.Data());
2491 
2492  edm::ProductID id = seedTracks[0].seedRef().id();
2493  const auto offset = see_fitok.size();
2494  auto inserted = seedCollToOffset.emplace(id, offset);
2495  if(!inserted.second)
2496  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.";
2497  see_offset.push_back(offset);
2498 
2499  LogTrace("TrackingNtuple") << "NEW SEED LABEL: " << label << " size: " << seedTracks.size() << " algo=" << algo
2500  << " ProductID " << id;
2501 
2502  for(size_t iSeed=0; iSeed < seedTrackRefs.size(); ++iSeed) {
2503  const auto& seedTrackRef = seedTrackRefs[iSeed];
2504  const auto& seedTrack = *seedTrackRef;
2505  const auto& seedRef = seedTrack.seedRef();
2506  const auto& seed = *seedRef;
2507 
2508  const auto seedStopReason = seedStopReasons[iSeed];
2509 
2510  if(seedRef.id() != id)
2511  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 << ".";
2512 
2513  std::vector<float> sharedFraction;
2514  std::vector<int> tpIdx;
2515  auto foundTPs = recSimColl.find(seedTrackRef);
2516  if (foundTPs != recSimColl.end()) {
2517  for(const auto tpQuality: foundTPs->val) {
2518  sharedFraction.push_back(tpQuality.second);
2519  tpIdx.push_back( tpKeyToIndex.at( tpQuality.first.key() ) );
2520  }
2521  }
2522 
2523 
2524  const bool seedFitOk = !trackFromSeedFitFailed(seedTrack);
2525  const int charge = seedTrack.charge();
2526  const float pt = seedFitOk ? seedTrack.pt() : 0;
2527  const float eta = seedFitOk ? seedTrack.eta() : 0;
2528  const float phi = seedFitOk ? seedTrack.phi() : 0;
2529  const int nHits = seedTrack.numberOfValidHits();
2530 
2531  const auto seedIndex = see_fitok.size();
2532 
2533  see_fitok .push_back(seedFitOk);
2534 
2535  see_px .push_back( seedFitOk ? seedTrack.px() : 0 );
2536  see_py .push_back( seedFitOk ? seedTrack.py() : 0 );
2537  see_pz .push_back( seedFitOk ? seedTrack.pz() : 0 );
2538  see_pt .push_back( pt );
2539  see_eta .push_back( eta );
2540  see_phi .push_back( phi );
2541  see_q .push_back( charge );
2542  see_nValid .push_back( nHits );
2543 
2544  see_dxy .push_back( seedFitOk ? seedTrack.dxy(bs.position()) : 0);
2545  see_dz .push_back( seedFitOk ? seedTrack.dz(bs.position()) : 0);
2546  see_ptErr .push_back( seedFitOk ? seedTrack.ptError() : 0);
2547  see_etaErr .push_back( seedFitOk ? seedTrack.etaError() : 0);
2548  see_phiErr .push_back( seedFitOk ? seedTrack.phiError() : 0);
2549  see_dxyErr .push_back( seedFitOk ? seedTrack.dxyError() : 0);
2550  see_dzErr .push_back( seedFitOk ? seedTrack.dzError() : 0);
2551  see_algo .push_back( algo );
2552  see_stopReason.push_back( seedStopReason );
2553 
2554  const auto& state = seedTrack.seedRef()->startingState();
2555  const auto& pos = state.parameters().position();
2556  const auto& mom = state.parameters().momentum();
2557  see_statePt.push_back(state.pt());
2558  see_stateTrajX.push_back(pos.x());
2559  see_stateTrajY.push_back(pos.y());
2560  see_stateTrajPx.push_back(mom.x());
2561  see_stateTrajPy.push_back(mom.y());
2562  see_stateTrajPz.push_back(mom.z());
2563 
2564  see_trkIdx .push_back(-1); // to be set correctly in fillTracks
2565  if(includeTrackingParticles_) {
2566  see_shareFrac.push_back( sharedFraction );
2567  see_simTrkIdx.push_back( tpIdx );
2568  }
2569  else {
2570  see_isTrue.push_back(!tpIdx.empty());
2571  }
2572 
2574  /*
2575  TransientTrackingRecHit::RecHitPointer lastRecHit = theTTRHBuilder.build(&*(seed.recHits().second-1));
2576  TrajectoryStateOnSurface state = trajectoryStateTransform::transientState( itSeed->startingState(), lastRecHit->surface(), theMF);
2577  float pt = state.globalParameters().momentum().perp();
2578  float eta = state.globalParameters().momentum().eta();
2579  float phi = state.globalParameters().momentum().phi();
2580  see_px .push_back( state.globalParameters().momentum().x() );
2581  see_py .push_back( state.globalParameters().momentum().y() );
2582  see_pz .push_back( state.globalParameters().momentum().z() );
2583  */
2584 
2585  std::vector<int> hitIdx;
2586  std::vector<int> hitType;
2587 
2588  for (auto hit=seed.recHits().first; hit!=seed.recHits().second; ++hit) {
2590  int subid = recHit->geographicalId().subdetId();
2591  if (subid == (int) PixelSubdetector::PixelBarrel || subid == (int) PixelSubdetector::PixelEndcap) {
2592  const BaseTrackerRecHit* bhit = dynamic_cast<const BaseTrackerRecHit*>(&*recHit);
2593  const auto& clusterRef = bhit->firstClusterRef();
2594  const auto clusterKey = clusterRef.cluster_pixel().key();
2595  if(includeAllHits_) {
2596  checkProductID(hitProductIds, clusterRef.id(), "seed");
2597  pix_seeIdx[clusterKey].push_back(seedIndex);
2598  }
2599  hitIdx.push_back( clusterKey );
2600  hitType.push_back( static_cast<int>(HitType::Pixel) );
2601  } else if (subid == (int) StripSubdetector::TOB || subid == (int) StripSubdetector::TID ||
2602  subid == (int) StripSubdetector::TIB || subid == (int) StripSubdetector::TEC) {
2603  if (trackerHitRTTI::isMatched(*recHit)) {
2604  const SiStripMatchedRecHit2D * matchedHit = dynamic_cast<const SiStripMatchedRecHit2D *>(&*recHit);
2605  if(includeAllHits_) {
2606  checkProductID(hitProductIds, matchedHit->monoClusterRef().id(), "seed");
2607  checkProductID(hitProductIds, matchedHit->stereoClusterRef().id(), "seed");
2608  }
2609  int monoIdx = matchedHit->monoClusterRef().key();
2610  int stereoIdx = matchedHit->stereoClusterRef().key();
2611 
2612  std::vector<std::pair<int,int> >::const_iterator pos = find( monoStereoClusterList.begin(), monoStereoClusterList.end(), std::make_pair(monoIdx,stereoIdx) );
2613  const auto gluedIndex = std::distance(monoStereoClusterList.begin(), pos);
2614  if(includeAllHits_) glu_seeIdx[gluedIndex].push_back(seedIndex);
2615  hitIdx.push_back( gluedIndex );
2616  hitType.push_back( static_cast<int>(HitType::Glued) );
2617  } else {
2618  const BaseTrackerRecHit* bhit = dynamic_cast<const BaseTrackerRecHit*>(&*recHit);
2619  const auto& clusterRef = bhit->firstClusterRef();
2620  unsigned int clusterKey;
2621  if(clusterRef.isPhase2()){
2622  clusterKey = clusterRef.cluster_phase2OT().key();
2623  } else {
2624  clusterKey = clusterRef.cluster_strip().key();
2625  }
2626 
2627  if(includeAllHits_) {
2628  checkProductID(hitProductIds, clusterRef.id(), "seed");
2629  if(clusterRef.isPhase2()){
2630  ph2_seeIdx[clusterKey].push_back(seedIndex);
2631  } else {
2632  str_seeIdx[clusterKey].push_back(seedIndex);
2633  }
2634  }
2635 
2636  hitIdx.push_back( clusterKey );
2637  if(clusterRef.isPhase2()){
2638  hitType.push_back( static_cast<int>(HitType::Phase2OT) );
2639  } else {
2640  hitType.push_back( static_cast<int>(HitType::Strip) );
2641  }
2642  }
2643  } else {
2644  LogTrace("TrackingNtuple") << " not pixel and not Strip detector";
2645  }
2646  }
2647  see_hitIdx .push_back( hitIdx );
2648  see_hitType .push_back( hitType );
2649  see_nPixel .push_back( std::count(hitType.begin(), hitType.end(), static_cast<int>(HitType::Pixel)) );
2650  see_nGlued .push_back( std::count(hitType.begin(), hitType.end(), static_cast<int>(HitType::Glued)) );
2651  see_nStrip .push_back( std::count(hitType.begin(), hitType.end(), static_cast<int>(HitType::Strip)) );
2652  see_nPhase2OT.push_back( std::count(hitType.begin(), hitType.end(), static_cast<int>(HitType::Phase2OT)) );
2653  //the part below is not strictly needed
2654  float chi2 = -1;
2655  if (nHits==2) {
2656  TransientTrackingRecHit::RecHitPointer recHit0 = theTTRHBuilder.build(&*(seed.recHits().first));
2657  TransientTrackingRecHit::RecHitPointer recHit1 = theTTRHBuilder.build(&*(seed.recHits().first+1));
2658  std::vector<GlobalPoint> gp(2);
2659  std::vector<GlobalError> ge(2);
2660  gp[0] = recHit0->globalPosition();
2661  ge[0] = recHit0->globalPositionError();
2662  gp[1] = recHit1->globalPosition();
2663  ge[1] = recHit1->globalPositionError();
2664  LogTrace("TrackingNtuple") << "seed " << seedTrackRef.key()
2665  << " pt=" << pt << " eta=" << eta << " phi=" << phi << " q=" << charge
2666  << " - PAIR - ids: " << recHit0->geographicalId().rawId() << " " << recHit1->geographicalId().rawId()
2667  << " hitpos: " << gp[0] << " " << gp[1]
2668  << " trans0: " << (recHit0->transientHits().size()>1 ? recHit0->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
2669  << " " << (recHit0->transientHits().size()>1 ? recHit0->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
2670  << " trans1: " << (recHit1->transientHits().size()>1 ? recHit1->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
2671  << " " << (recHit1->transientHits().size()>1 ? recHit1->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
2672  << " eta,phi: " << gp[0].eta() << "," << gp[0].phi();
2673  } else if (nHits==3) {
2674  TransientTrackingRecHit::RecHitPointer recHit0 = theTTRHBuilder.build(&*(seed.recHits().first));
2675  TransientTrackingRecHit::RecHitPointer recHit1 = theTTRHBuilder.build(&*(seed.recHits().first+1));
2676  TransientTrackingRecHit::RecHitPointer recHit2 = theTTRHBuilder.build(&*(seed.recHits().first+2));
2679  declareDynArray(bool,4, bl);
2680  gp[0] = recHit0->globalPosition();
2681  ge[0] = recHit0->globalPositionError();
2682  int subid0 = recHit0->geographicalId().subdetId();
2683  bl[0] = (subid0 == StripSubdetector::TIB || subid0 == StripSubdetector::TOB || subid0 == (int) PixelSubdetector::PixelBarrel);
2684  gp[1] = recHit1->globalPosition();
2685  ge[1] = recHit1->globalPositionError();
2686  int subid1 = recHit1->geographicalId().subdetId();
2687  bl[1] = (subid1 == StripSubdetector::TIB || subid1 == StripSubdetector::TOB || subid1 == (int) PixelSubdetector::PixelBarrel);
2688  gp[2] = recHit2->globalPosition();
2689  ge[2] = recHit2->globalPositionError();
2690  int subid2 = recHit2->geographicalId().subdetId();
2691  bl[2] = (subid2 == StripSubdetector::TIB || subid2 == StripSubdetector::TOB || subid2 == (int) PixelSubdetector::PixelBarrel);
2692  RZLine rzLine(gp,ge,bl);
2693  float seed_chi2 = rzLine.chi2();
2694  //float seed_pt = state.globalParameters().momentum().perp();
2695  float seed_pt = pt;
2696  LogTrace("TrackingNtuple") << "seed " << seedTrackRef.key()
2697  << " pt=" << pt << " eta=" << eta << " phi=" << phi << " q=" << charge
2698  << " - TRIPLET - ids: " << recHit0->geographicalId().rawId() << " " << recHit1->geographicalId().rawId() << " " << recHit2->geographicalId().rawId()
2699  << " hitpos: " << gp[0] << " " << gp[1] << " " << gp[2]
2700  << " trans0: " << (recHit0->transientHits().size()>1 ? recHit0->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
2701  << " " << (recHit0->transientHits().size()>1 ? recHit0->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
2702  << " trans1: " << (recHit1->transientHits().size()>1 ? recHit1->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
2703  << " " << (recHit1->transientHits().size()>1 ? recHit1->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
2704  << " trans2: " << (recHit2->transientHits().size()>1 ? recHit2->transientHits()[0]->globalPosition() : GlobalPoint(0,0,0))
2705  << " " << (recHit2->transientHits().size()>1 ? recHit2->transientHits()[1]->globalPosition() : GlobalPoint(0,0,0))
2706  << " local: " << recHit2->localPosition()
2707  //<< " tsos pos, mom: " << state.globalPosition()<<" "<<state.globalMomentum()
2708  << " eta,phi: " << gp[0].eta() << "," << gp[0].phi()
2709  << " pt,chi2: " << seed_pt << "," << seed_chi2;
2710  chi2 = seed_chi2;
2711  }
2712  see_chi2 .push_back( chi2 );
2713  }
2714 
2715  fillTrackingParticlesForSeeds(tpCollection, simRecColl, tpKeyToIndex, offset);
2716  }
2717 }
2718 
2720  const TrackingParticleRefVector& tpCollection,
2721  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2722  const reco::BeamSpot& bs,
2723  const reco::VertexCollection& vertices,
2724  const reco::TrackToTrackingParticleAssociator& associatorByHits,
2725  const TransientTrackingRecHitBuilder& theTTRHBuilder,
2726  const TrackerTopology& tTopo,
2727  const std::set<edm::ProductID>& hitProductIds,
2728  const std::map<edm::ProductID, size_t>& seedCollToOffset,
2729  const std::vector<const MVACollection *>& mvaColls,
2730  const std::vector<const QualityMaskCollection *>& qualColls
2731  ) {
2732  reco::RecoToSimCollection recSimColl = associatorByHits.associateRecoToSim(tracks, tpCollection);
2734  labelsForToken(trackToken_, labels);
2735  LogTrace("TrackingNtuple") << "NEW TRACK LABEL: " << labels.module;
2736 
2737  auto pvPosition = vertices[0].position();
2738 
2739  for(size_t iTrack = 0; iTrack<tracks.size(); ++iTrack) {
2740  const auto& itTrack = tracks[iTrack];
2741  int nSimHits = 0;
2742  bool isSimMatched = false;
2743  std::vector<float> sharedFraction;
2744  std::vector<int> tpIdx;
2745  auto foundTPs = recSimColl.find(itTrack);
2746  if (foundTPs != recSimColl.end()) {
2747  if (!foundTPs->val.empty()) {
2748  nSimHits = foundTPs->val[0].first->numberOfTrackerHits();
2749  isSimMatched = true;
2750  }
2751  for(const auto tpQuality: foundTPs->val) {
2752  sharedFraction.push_back(tpQuality.second);
2753  tpIdx.push_back( tpKeyToIndex.at( tpQuality.first.key() ) );
2754  }
2755  }
2756  int charge = itTrack->charge();
2757  float pt = itTrack->pt();
2758  float eta = itTrack->eta();
2759  const double lambda = itTrack->lambda();
2760  float chi2 = itTrack->normalizedChi2();
2761  float ndof = itTrack->ndof();
2762  float phi = itTrack->phi();
2763  int nHits = itTrack->numberOfValidHits();
2764  const reco::HitPattern& hp = itTrack->hitPattern();
2765 
2766  float chi2_1Dmod = chi2;
2767  int count1dhits = 0;
2768  for(auto iHit = itTrack->recHitsBegin(), iEnd=itTrack->recHitsEnd(); iHit != iEnd; ++iHit) {
2769  const TrackingRecHit& hit = **iHit;
2770  if(hit.isValid() && typeid(hit) == typeid(SiStripRecHit1D))
2771  ++count1dhits;
2772  }
2773  if(count1dhits > 0) {
2774  chi2_1Dmod = (chi2+count1dhits)/(ndof+count1dhits);
2775  }
2776 
2777  Point bestPV = getBestVertex(*itTrack, vertices);
2778 
2779  trk_px .push_back(itTrack->px());
2780  trk_py .push_back(itTrack->py());
2781  trk_pz .push_back(itTrack->pz());
2782  trk_pt .push_back(pt);
2783  trk_inner_px.push_back(itTrack->innerMomentum().x());
2784  trk_inner_py.push_back(itTrack->innerMomentum().y());
2785  trk_inner_pz.push_back(itTrack->innerMomentum().z());
2786  trk_inner_pt.push_back(itTrack->innerMomentum().rho());
2787  trk_outer_px.push_back(itTrack->outerMomentum().x());
2788  trk_outer_py.push_back(itTrack->outerMomentum().y());
2789  trk_outer_pz.push_back(itTrack->outerMomentum().z());
2790  trk_outer_pt.push_back(itTrack->outerMomentum().rho());
2791  trk_eta .push_back(eta);
2792  trk_lambda .push_back(lambda);
2793  trk_cotTheta .push_back(1/tan(M_PI*0.5-lambda));
2794  trk_phi .push_back(phi);
2795  trk_dxy .push_back(itTrack->dxy(bs.position()));
2796  trk_dz .push_back(itTrack->dz(bs.position()));
2797  trk_dxyPV .push_back(itTrack->dxy(pvPosition));
2798  trk_dzPV .push_back(itTrack->dz(pvPosition));
2799  trk_dxyClosestPV.push_back(itTrack->dxy(bestPV));
2800  trk_dzClosestPV .push_back(itTrack->dz(bestPV));
2801  trk_ptErr .push_back(itTrack->ptError());
2802  trk_etaErr .push_back(itTrack->etaError());
2803  trk_lambdaErr.push_back(itTrack->lambdaError());
2804  trk_phiErr .push_back(itTrack->phiError());
2805  trk_dxyErr .push_back(itTrack->dxyError());
2806  trk_dzErr .push_back(itTrack->dzError());
2807  trk_refpoint_x.push_back(itTrack->vx());
2808  trk_refpoint_y.push_back(itTrack->vy());
2809  trk_refpoint_z.push_back(itTrack->vz());
2810  trk_nChi2 .push_back(chi2);
2811  trk_nChi2_1Dmod.push_back(chi2_1Dmod);
2812  trk_ndof .push_back(ndof);
2813  trk_q .push_back(charge);
2814  trk_nValid .push_back(hp.numberOfValidHits());
2815  trk_nInvalid .push_back(hp.numberOfLostHits(reco::HitPattern::TRACK_HITS));
2816  trk_nPixel .push_back(hp.numberOfValidPixelHits());
2817  trk_nStrip .push_back(hp.numberOfValidStripHits());
2818  trk_nOuterLost.push_back(hp.numberOfLostTrackerHits(reco::HitPattern::MISSING_OUTER_HITS));
2819  trk_nInnerLost.push_back(hp.numberOfLostTrackerHits(reco::HitPattern::MISSING_INNER_HITS));
2820  trk_nPixelLay.push_back(hp.pixelLayersWithMeasurement());
2821  trk_nStripLay.push_back(hp.stripLayersWithMeasurement());
2824  trk_algo .push_back(itTrack->algo());
2825  trk_originalAlgo.push_back(itTrack->originalAlgo());
2826  trk_algoMask .push_back(itTrack->algoMaskUL());
2827  trk_stopReason.push_back(itTrack->stopReason());
2828  trk_isHP .push_back(itTrack->quality(reco::TrackBase::highPurity));
2829  if(includeMVA_) {
2830  for(size_t i=0; i<trk_mvas.size(); ++i) {
2831  trk_mvas [i].push_back( (*(mvaColls [i]))[iTrack] );
2832  trk_qualityMasks[i].push_back( (*(qualColls[i]))[iTrack] );
2833  }
2834  }
2835  if(includeSeeds_) {
2836  auto offset = seedCollToOffset.find(itTrack->seedRef().id());
2837  if(offset == seedCollToOffset.end()) {
2838  throw cms::Exception("Configuration") << "Track algo '" << reco::TrackBase::algoName(itTrack->algo())
2839  << "' originalAlgo '" << reco::TrackBase::algoName(itTrack->originalAlgo())
2840  << "' refers to seed collection " << itTrack->seedRef().id()
2841  << ", but that seed collection is not given as an input. The following collections were given as an input " << make_ProductIDMapPrinter(seedCollToOffset);
2842  }
2843 
2844  const auto seedIndex = offset->second + itTrack->seedRef().key();
2845  trk_seedIdx .push_back(seedIndex);
2846  if(see_trkIdx[seedIndex] != -1) {
2847  throw cms::Exception("LogicError") << "Track index has already been set for seed " << seedIndex << " to " << see_trkIdx[seedIndex] << "; was trying to set it to " << iTrack;
2848  }
2849  see_trkIdx[seedIndex] = iTrack;
2850  }
2851  trk_vtxIdx .push_back(-1); // to be set correctly in fillVertices
2852  if(includeTrackingParticles_) {
2853  trk_simTrkIdx.push_back(tpIdx);
2854  trk_shareFrac.push_back(sharedFraction);
2855  }
2856  else {
2857  trk_isTrue.push_back(!tpIdx.empty());
2858  }
2859  LogTrace("TrackingNtuple") << "Track #" << itTrack.key() << " with q=" << charge
2860  << ", pT=" << pt << " GeV, eta: " << eta << ", phi: " << phi
2861  << ", chi2=" << chi2
2862  << ", Nhits=" << nHits
2863  << ", algo=" << itTrack->algoName(itTrack->algo()).c_str()
2864  << " hp=" << itTrack->quality(reco::TrackBase::highPurity)
2865  << " seed#=" << itTrack->seedRef().key()
2866  << " simMatch=" << isSimMatched
2867  << " nSimHits=" << nSimHits
2868  << " sharedFraction=" << (sharedFraction.empty()?-1:sharedFraction[0])
2869  << " tpIdx=" << (tpIdx.empty()?-1:tpIdx[0]);
2870  std::vector<int> hitIdx;
2871  std::vector<int> hitType;
2872 
2873  for(auto i=itTrack->recHitsBegin(); i!=itTrack->recHitsEnd(); i++) {
2874  TransientTrackingRecHit::RecHitPointer hit=theTTRHBuilder.build(&**i );
2875  DetId hitId = hit->geographicalId();
2876  LogTrace("TrackingNtuple") << "hit #" << std::distance(itTrack->recHitsBegin(), i) << " subdet=" << hitId.subdetId();
2877  if(hitId.det() != DetId::Tracker)
2878  continue;
2879 
2880  LogTrace("TrackingNtuple") << " " << subdetstring(hitId.subdetId()) << " " << tTopo.layer(hitId);
2881 
2882  if (hit->isValid()) {
2883  //ugly... but works
2884  const BaseTrackerRecHit* bhit = dynamic_cast<const BaseTrackerRecHit*>(&*hit);
2885  const auto& clusterRef = bhit->firstClusterRef();
2886  unsigned int clusterKey;
2887  if(clusterRef.isPixel()){
2888  clusterKey = clusterRef.cluster_pixel().key();
2889  } else if(clusterRef.isPhase2()){
2890  clusterKey = clusterRef.cluster_phase2OT().key();
2891  } else {
2892  clusterKey = clusterRef.cluster_strip().key();
2893  }
2894 
2895  LogTrace("TrackingNtuple") << " id: " << hitId.rawId() << " - globalPos =" << hit->globalPosition()
2896  << " cluster=" << clusterKey
2897  << " clusterRef ID=" << clusterRef.id()
2898  << " eta,phi: " << hit->globalPosition().eta() << "," << hit->globalPosition().phi();
2899  if(includeAllHits_) {
2900  checkProductID(hitProductIds, clusterRef.id(), "track");
2901  if(clusterRef.isPixel()){
2902  pix_trkIdx[clusterKey].push_back(iTrack);
2903  } else if(clusterRef.isPhase2()){
2904  ph2_trkIdx[clusterKey].push_back(iTrack);
2905  } else {
2906  str_trkIdx[clusterKey].push_back(iTrack);
2907  }
2908 
2909  }
2910 
2911  hitIdx.push_back(clusterKey);
2912  if(clusterRef.isPixel()){
2913  hitType.push_back( static_cast<int>(HitType::Pixel));
2914  } else if(clusterRef.isPhase2()){
2915  hitType.push_back( static_cast<int>(HitType::Phase2OT));
2916  } else {
2917  hitType.push_back( static_cast<int>(HitType::Strip));
2918  }
2919  } else {
2920  LogTrace("TrackingNtuple") << " - invalid hit";
2921 
2922  hitIdx.push_back( inv_isBarrel.size() );
2923  hitType.push_back( static_cast<int>(HitType::Invalid) );
2924 
2925  inv_isBarrel.push_back( hitId.subdetId()==1 );
2926  if(includeStripHits_) inv_detId.push_back( tTopo, hitId );
2927  else inv_detId_phase2.push_back( tTopo, hitId );
2928  inv_type .push_back( hit->getType() );
2929 
2930  }
2931  }
2932 
2933  trk_hitIdx.push_back(hitIdx);
2934  trk_hitType.push_back(hitType);
2935  }
2936 }
2937 
2938 
2940  const edm::RefToBaseVector<reco::Track>& tracks,
2941  const reco::BeamSpot& bs,
2942  const TrackingParticleRefVector& tpCollection,
2943  const TrackingVertexRefKeyToIndex& tvKeyToIndex,
2944  const reco::TrackToTrackingParticleAssociator& associatorByHits,
2945  const std::vector<TPHitIndex>& tpHitList
2946  ) {
2947  edm::ESHandle<ParametersDefinerForTP> parametersDefinerH;
2948  iSetup.get<TrackAssociatorRecord>().get(parametersDefinerName_, parametersDefinerH);
2949  const ParametersDefinerForTP *parametersDefiner = parametersDefinerH.product();
2950 
2951  // Number of 3D layers for TPs
2953  iEvent.getByToken(tpNLayersToken_, tpNLayersH);
2954  const auto& nLayers_tPCeff = *tpNLayersH;
2955 
2956  iEvent.getByToken(tpNPixelLayersToken_, tpNLayersH);
2957  const auto& nPixelLayers_tPCeff = *tpNLayersH;
2958 
2959  iEvent.getByToken(tpNStripStereoLayersToken_, tpNLayersH);
2960  const auto& nStripMonoAndStereoLayers_tPCeff = *tpNLayersH;
2961 
2962  reco::SimToRecoCollection simRecColl = associatorByHits.associateSimToReco(tracks, tpCollection);
2963 
2964  for(const TrackingParticleRef& tp: tpCollection) {
2965  LogTrace("TrackingNtuple") << "tracking particle pt=" << tp->pt() << " eta=" << tp->eta() << " phi=" << tp->phi();
2966  bool isRecoMatched = false;
2967  std::vector<int> tkIdx;
2968  std::vector<float> sharedFraction;
2969  auto foundTracks = simRecColl.find(tp);
2970  if(foundTracks != simRecColl.end()) {
2971  isRecoMatched = true;
2972  for(const auto trackQuality: foundTracks->val) {
2973  sharedFraction.push_back(trackQuality.second);
2974  tkIdx.push_back(trackQuality.first.key());
2975  }
2976  }
2977 
2978  sim_genPdgIds.emplace_back();
2979  for(const auto& genRef: tp->genParticles()) {
2980  if(genRef.isNonnull())
2981  sim_genPdgIds.back().push_back(genRef->pdgId());
2982  }
2983 
2984  bool isFromBHadron = false;
2985  // Logic is similar to SimTracker/TrackHistory
2986  if(tracer_.evaluate(tp)) { // ignore TP if history can not be traced
2987  // following is from TrackClassifier::processesAtGenerator()
2988  HistoryBase::RecoGenParticleTrail const & recoGenParticleTrail = tracer_.recoGenParticleTrail();
2989  for(const auto& particle: recoGenParticleTrail) {
2990  HepPDT::ParticleID particleID(particle->pdgId());
2991  if(particleID.hasBottom()) {
2992  isFromBHadron = true;
2993  break;
2994  }
2995  }
2996  }
2997 
2998  LogTrace("TrackingNtuple") << "matched to tracks = " << make_VectorPrinter(tkIdx) << " isRecoMatched=" << isRecoMatched;
2999  sim_event .push_back(tp->eventId().event());
3000  sim_bunchCrossing.push_back(tp->eventId().bunchCrossing());
3001  sim_pdgId .push_back(tp->pdgId());
3002  sim_isFromBHadron.push_back(isFromBHadron);
3003  sim_px .push_back(tp->px());
3004  sim_py .push_back(tp->py());
3005  sim_pz .push_back(tp->pz());
3006  sim_pt .push_back(tp->pt());
3007  sim_eta .push_back(tp->eta());
3008  sim_phi .push_back(tp->phi());
3009  sim_q .push_back(tp->charge());
3010  sim_trkIdx .push_back(tkIdx);
3011  sim_shareFrac.push_back(sharedFraction);
3012  sim_parentVtxIdx.push_back( tvKeyToIndex.at(tp->parentVertex().key()) );
3013  std::vector<int> decayIdx;
3014  for(const auto& v: tp->decayVertices())
3015  decayIdx.push_back( tvKeyToIndex.at(v.key()) );
3016  sim_decayVtxIdx.push_back(decayIdx);
3017 
3018  //Calcualte the impact parameters w.r.t. PCA
3019  TrackingParticle::Vector momentum = parametersDefiner->momentum(iEvent,iSetup,tp);
3020  TrackingParticle::Point vertex = parametersDefiner->vertex(iEvent,iSetup,tp);
3021  auto dxySim = TrackingParticleIP::dxy(vertex, momentum, bs.position());
3022  auto dzSim = TrackingParticleIP::dz(vertex, momentum, bs.position());
3023  const double lambdaSim = M_PI/2 - momentum.theta();
3024  sim_pca_pt .push_back(std::sqrt(momentum.perp2()));
3025  sim_pca_eta .push_back(momentum.Eta());
3026  sim_pca_lambda .push_back(lambdaSim);
3027  sim_pca_cotTheta .push_back(1/tan(M_PI*0.5-lambdaSim));
3028  sim_pca_phi .push_back(momentum.phi());
3029  sim_pca_dxy .push_back(dxySim);
3030  sim_pca_dz .push_back(dzSim);
3031 
3032  std::vector<int> hitIdx;
3033  int nPixel=0, nStrip=0;
3034  auto rangeHit = std::equal_range(tpHitList.begin(), tpHitList.end(), TPHitIndex(tp.key()), tpHitIndexListLess);
3035  for(auto ip = rangeHit.first; ip != rangeHit.second; ++ip) {
3036  auto type = HitType::Unknown;
3037  if(!simhit_hitType[ip->simHitIdx].empty())
3038  type = static_cast<HitType>(simhit_hitType[ip->simHitIdx][0]);
3039  LogTrace("TrackingNtuple") << "simhit=" << ip->simHitIdx << " type=" << static_cast<int>(type);
3040  hitIdx.push_back(ip->simHitIdx);
3041  const auto detid = DetId(includeStripHits_ ? simhit_detId[ip->simHitIdx] : simhit_detId_phase2[ip->simHitIdx]);
3042  if(detid.det() != DetId::Tracker) {
3043  throw cms::Exception("LogicError") << "Encountered SimHit for TP " << tp.key() << " with DetId " << detid.rawId() << " whose det() is not Tracker but " << detid.det();
3044  }
3045  const auto subdet = detid.subdetId();
3046  switch(subdet) {
3049  ++nPixel;
3050  break;
3051  case StripSubdetector::TIB:
3052  case StripSubdetector::TID:
3053  case StripSubdetector::TOB:
3054  case StripSubdetector::TEC:
3055  ++nStrip;
3056  break;
3057  default:
3058  throw cms::Exception("LogicError") << "Encountered SimHit for TP " << tp.key() << " with DetId " << detid.rawId() << " whose subdet is not recognized, is " << subdet;
3059  };
3060  }
3061  sim_nValid .push_back( hitIdx.size() );
3062  sim_nPixel .push_back( nPixel );
3063  sim_nStrip .push_back( nStrip );
3064 
3065  const auto nSimLayers = nLayers_tPCeff[tp];
3066  const auto nSimPixelLayers = nPixelLayers_tPCeff[tp];
3067  const auto nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tp];
3068  sim_nLay .push_back( nSimLayers );
3069  sim_nPixelLay.push_back( nSimPixelLayers );
3070  sim_n3DLay .push_back( nSimPixelLayers+nSimStripMonoAndStereoLayers );
3071 
3072  sim_simHitIdx.push_back(hitIdx);
3073  }
3074 }
3075 
3076 // called from fillSeeds
3078  const reco::SimToRecoCollection& simRecColl,
3079  const TrackingParticleRefKeyToIndex& tpKeyToIndex,
3080  const unsigned int seedOffset) {
3081  if(sim_seedIdx.empty()) // first call
3082  sim_seedIdx.resize(tpCollection.size());
3083 
3084  for(const auto& keyVal: simRecColl) {
3085  const auto& tpRef = keyVal.key;
3086  auto found = tpKeyToIndex.find(tpRef.key());
3087  if(found == tpKeyToIndex.end())
3088  throw cms::Exception("Assert") << __FILE__ << ":" << __LINE__ << " fillTrackingParticlesForSeeds: tpRef.key() " << tpRef.key() << " not found from tpKeyToIndex. tpKeyToIndex size " << tpKeyToIndex.size();
3089  const auto tpIndex = found->second;
3090  for(const auto& pair: keyVal.val) {
3091  const auto& seedRef = pair.first->seedRef();
3092  sim_seedIdx[tpIndex].push_back(seedOffset + seedRef.key());
3093  }
3094  }
3095 }
3096 
3097 
3099  const edm::RefToBaseVector<reco::Track>& tracks) {
3100  for(size_t iVertex=0, size=vertices.size(); iVertex<size; ++iVertex) {
3101  const reco::Vertex& vertex = vertices[iVertex];
3102  vtx_x.push_back(vertex.x());
3103  vtx_y.push_back(vertex.y());
3104  vtx_z.push_back(vertex.z());
3105  vtx_xErr.push_back(vertex.xError());
3106  vtx_yErr.push_back(vertex.yError());
3107  vtx_zErr.push_back(vertex.zError());
3108  vtx_chi2.push_back(vertex.chi2());
3109  vtx_ndof.push_back(vertex.ndof());
3110  vtx_fake.push_back(vertex.isFake());
3111  vtx_valid.push_back(vertex.isValid());
3112 
3113  std::vector<int> trkIdx;
3114  for(auto iTrack = vertex.tracks_begin(); iTrack != vertex.tracks_end(); ++iTrack) {
3115  // Ignore link if vertex was fit from a track collection different from the input
3116  if(iTrack->id() != tracks.id())
3117  continue;
3118 
3119  trkIdx.push_back(iTrack->key());
3120 
3121  if(trk_vtxIdx[iTrack->key()] != -1) {
3122  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;
3123  }
3124  trk_vtxIdx[iTrack->key()] = iVertex;
3125  }
3126  vtx_trkIdx.push_back(trkIdx);
3127  }
3128 }
3129 
3131  const TrackingParticleRefKeyToIndex& tpKeyToIndex
3132  ) {
3133  int current_event = -1;
3134  for(const auto& ref: trackingVertices) {
3135  const TrackingVertex v = *ref;
3136  if(v.eventId().event() != current_event) {
3137  // next PV
3138  current_event = v.eventId().event();
3139  simpv_idx.push_back(simvtx_x.size());
3140  }
3141 
3142  unsigned int processType = std::numeric_limits<unsigned int>::max();
3143  if(!v.g4Vertices().empty()) {
3144  processType = v.g4Vertices()[0].processType();
3145  }
3146 
3147  simvtx_event.push_back(v.eventId().event());
3148  simvtx_bunchCrossing.push_back(v.eventId().bunchCrossing());
3149  simvtx_processType.push_back(processType);
3150 
3151  simvtx_x.push_back(v.position().x());
3152  simvtx_y.push_back(v.position().y());
3153  simvtx_z.push_back(v.position().z());
3154 
3155  auto fill = [&](const TrackingParticleRefVector& tps, std::vector<int>& idx) {
3156  for(const auto& tpRef: tps) {
3157  auto found = tpKeyToIndex.find(tpRef.key());
3158  if(found != tpKeyToIndex.end()) {
3159  idx.push_back(found->second);
3160  }
3161  }
3162  };
3163 
3164  std::vector<int> sourceIdx;
3165  std::vector<int> daughterIdx;
3166  fill(v.sourceTracks(), sourceIdx);
3167  fill(v.daughterTracks(), daughterIdx);
3168 
3169  simvtx_sourceSimIdx.push_back(sourceIdx);
3170  simvtx_daughterSimIdx.push_back(daughterIdx);
3171  }
3172 }
3173 
3174 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
3176  //The following says we do not know what parameters are allowed so do no validation
3177  // Please change this to state exactly what you do use, even if it is no parameters
3179  desc.addUntracked<std::vector<edm::InputTag> >("seedTracks", std::vector<edm::InputTag>{
3180  edm::InputTag("seedTracksinitialStepSeeds"),
3181  edm::InputTag("seedTracksdetachedTripletStepSeeds"),
3182  edm::InputTag("seedTrackspixelPairStepSeeds"),
3183  edm::InputTag("seedTrackslowPtTripletStepSeeds"),
3184  edm::InputTag("seedTracksmixedTripletStepSeeds"),
3185  edm::InputTag("seedTrackspixelLessStepSeeds"),
3186  edm::InputTag("seedTrackstobTecStepSeeds"),
3187  edm::InputTag("seedTracksjetCoreRegionalStepSeeds"),
3188  edm::InputTag("seedTracksmuonSeededSeedsInOut"),
3189  edm::InputTag("seedTracksmuonSeededSeedsOutIn")
3190  });
3191  desc.addUntracked<std::vector<edm::InputTag> >("trackCandidates", std::vector<edm::InputTag>{
3192  edm::InputTag("initialStepTrackCandidates"),
3193  edm::InputTag("detachedTripletStepTrackCandidates"),
3194  edm::InputTag("pixelPairStepTrackCandidates"),
3195  edm::InputTag("lowPtTripletStepTrackCandidates"),
3196  edm::InputTag("mixedTripletStepTrackCandidates"),
3197  edm::InputTag("pixelLessStepTrackCandidates"),
3198  edm::InputTag("tobTecStepTrackCandidates"),
3199  edm::InputTag("jetCoreRegionalStepTrackCandidates"),
3200  edm::InputTag("muonSeededTrackCandidatesInOut"),
3201  edm::InputTag("muonSeededTrackCandidatesOutIn")
3202  });
3203  desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
3204  desc.addUntracked<std::vector<std::string> >("trackMVAs", std::vector<std::string>{{"generalTracks"}});
3205  desc.addUntracked<edm::InputTag>("trackingParticles", edm::InputTag("mix", "MergedTrackTruth"));
3206  desc.addUntracked<bool>("trackingParticlesRef", false);
3207  desc.addUntracked<edm::InputTag>("clusterTPMap", edm::InputTag("tpClusterProducer"));
3208  desc.addUntracked<edm::InputTag>("simHitTPMap", edm::InputTag("simHitTPAssocProducer"));
3209  desc.addUntracked<edm::InputTag>("trackAssociator", edm::InputTag("quickTrackAssociatorByHits"));
3210  desc.addUntracked<edm::InputTag>("pixelDigiSimLink", edm::InputTag("simSiPixelDigis"));
3211  desc.addUntracked<edm::InputTag>("stripDigiSimLink", edm::InputTag("simSiStripDigis"));
3212  desc.addUntracked<edm::InputTag>("phase2OTSimLink", edm::InputTag(""));
3213  desc.addUntracked<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
3214  desc.addUntracked<edm::InputTag>("pixelRecHits", edm::InputTag("siPixelRecHits"));
3215  desc.addUntracked<edm::InputTag>("stripRphiRecHits", edm::InputTag("siStripMatchedRecHits", "rphiRecHit"));
3216  desc.addUntracked<edm::InputTag>("stripStereoRecHits", edm::InputTag("siStripMatchedRecHits", "stereoRecHit"));
3217  desc.addUntracked<edm::InputTag>("stripMatchedRecHits", edm::InputTag("siStripMatchedRecHits", "matchedRecHit"));
3218  desc.addUntracked<edm::InputTag>("phase2OTRecHits", edm::InputTag("siPhase2RecHits"));
3219  desc.addUntracked<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
3220  desc.addUntracked<edm::InputTag>("trackingVertices", edm::InputTag("mix", "MergedTrackTruth"));
3221  desc.addUntracked<edm::InputTag>("trackingParticleNlayers", edm::InputTag("trackingParticleNumberOfLayersProducer", "trackerLayers"));
3222  desc.addUntracked<edm::InputTag>("trackingParticleNpixellayers", edm::InputTag("trackingParticleNumberOfLayersProducer", "pixelLayers"));
3223  desc.addUntracked<edm::InputTag>("trackingParticleNstripstereolayers", edm::InputTag("trackingParticleNumberOfLayersProducer", "stripStereoLayers"));
3224  desc.addUntracked<std::string>("TTRHBuilder", "WithTrackAngle");
3225  desc.addUntracked<std::string>("parametersDefiner", "LhcParametersDefinerForTP");
3226  desc.addUntracked<bool>("includeSeeds", false);
3227  desc.addUntracked<bool>("includeAllHits", false);
3228  desc.addUntracked<bool>("includeMVA", true);
3229  desc.addUntracked<bool>("includeTrackingParticles", true);
3230  descriptions.add("trackingNtuple",desc);
3231 }
3232 
3233 //define this as a plug-in
#define LogDebug(id)
int adc(sample_type sample)
get the ADC sample (12 bits)
RunNumber_t run() const
Definition: EventID.h:39
size
Write out results.
std::vector< float > sim_pca_dz
edm::LuminosityBlockNumber_t ev_lumi
std::vector< float > trk_nChi2_1Dmod
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< unsigned int > simvtx_processType
Parsed parse(const TrackerTopology &tTopo, const DetId &id) const
edm::EDGetTokenT< TrackingParticleRefVector > trackingParticleRefToken_
std::vector< unsigned int > sim_nLay
type
Definition: HCALResponse.h:21
std::vector< float > ph2_radL
std::vector< float > trk_dxyPV
EventNumber_t event() const
Definition: EventID.h:41
Map map_
unsigned int size_type
Definition: View.h:90
void fillTrackingVertices(const TrackingVertexRefVector &trackingVertices, const TrackingParticleRefKeyToIndex &tpKeyToIndex)
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > stripMatchedRecHitToken_
T getUntrackedParameter(std::string const &, T const &) const
std::vector< short > see_fitok
Phase2Cluster1DRef cluster_phase2OT() const
std::vector< short > vtx_fake
std::vector< float > simvtx_z
std::vector< std::vector< int > > see_hitType
std::vector< float > trk_dzClosestPV
edm::EDGetTokenT< SiStripRecHit2DCollection > stripRphiRecHitToken_
Phase2TrackerCluster1D const & phase2OTCluster() const
const TrackingParticleRefVector & sourceTracks() const
std::vector< short > ph2_isBarrel
bool tecIsDoubleSide(const DetId &id) const
TrackAssociatorByHitsImpl::SimHitTPAssociationList SimHitTPAssociationList
DetIdStrip str_detId
std::vector< float > trk_phi
SiPixelCluster const & pixelCluster() const
std::vector< float > sim_pca_cotTheta
bool tobIsDoubleSide(const DetId &id) const
const_iterator end(bool update=false) const
std::vector< float > sim_pca_dxy
void book(const std::string &prefix, TTree *tree)
std::vector< float > see_stateTrajX
std::vector< unsigned int > trk_nOuterLost
size_type dataSize() const
std::vector< float > glu_xy
std::vector< short > trk_isTrue
std::vector< std::vector< int > > ph2_seeIdx
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 > see_stateTrajPy
std::vector< float > pix_y
std::vector< int > trk_vtxIdx
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 tibIsDoubleSide(const DetId &id) const
bool trackFromSeedFitFailed(const reco::Track &track)
std::vector< float > trk_outer_py
std::unordered_map< reco::RecoToSimCollection::index_type, size_t > TrackingParticleRefKeyToIndex
unsigned int tibString(const DetId &id) const
std::vector< float > pix_zz
unsigned int tidRing(const DetId &id) const
std::vector< unsigned short > layer
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::vector< float > ph2_bbxi
std::vector< int > glu_monoIdx
std::vector< float > trk_eta
module()
Definition: vlib.cc:994
std::vector< short > glu_isBarrel
std::vector< unsigned short > order
std::vector< int > sim_bunchCrossing
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
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
const_iterator end() const
last iterator over the map (read only)
std::vector< float > str_x
std::vector< float > see_dzErr
std::vector< unsigned int > sim_n3DLay
std::vector< float > trk_cotTheta
CombineDetId< DetIdCommon, DetIdOTCommon, DetIdStripOnly > DetIdStrip
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< unsigned int > see_nStrip
def analyze(function, filename, filter=None)
Definition: Profiling.py:11
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 > see_stateTrajPz
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
std::vector< float > trk_dzPV
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
void push_back(const TrackerTopology &tTopo, const DetId &id)
std::vector< float > trk_pt
unsigned int tecRing(const DetId &id) const
ring id
std::vector< float > glu_x
std::vector< float > trk_inner_py
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
std::vector< float > see_stateTrajY
edm::EDGetTokenT< edm::View< reco::Track > > trackToken_
CombineDetId< DetIdCommon, DetIdPixelOnly, DetIdOTCommon, DetIdPhase2OTOnly > DetIdAllPhase2
CombineDetId< DetIdCommon, DetIdPixelOnly > DetIdPixel
unsigned int pxbLadder(const DetId &id) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
unsigned int side(const DetId &id) const
void fillBeamSpot(const reco::BeamSpot &bs)
std::vector< unsigned short > see_stopReason
std::vector< float > trk_outer_px
std::vector< std::vector< int > > trk_hitType
DetIdPixel pix_detId
std::vector< float > ph2_xx
TrackingParticleRefKeyToIndex TrackingVertexRefKeyToIndex
unsigned long long EventNumber_t
std::vector< std::vector< int > > ph2_trkIdx
int numberOfValidStripHits() const
Definition: HitPattern.h:853
#define BOOK(name)
edm::EDGetTokenT< Phase2TrackerRecHit1DCollectionNew > phase2OTRecHitToken_
bool isStereo(const DetId &id) const
size_type size() const
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::vector< unsigned short > module
std::pair< TrackPSimHitRef::key_type, edm::ProductID > SimHitFullKey
CombineDetId< DetIdCommon, DetIdOTCommon, DetIdPhase2OTOnly > DetIdPhase2OT
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< int > simhit_simTrkIdx
key_type key() const
Accessor for product key.
Definition: Ref.h:265
std::vector< std::vector< float > > sim_shareFrac
std::vector< unsigned short > trk_stopReason
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:493
std::vector< unsigned short > ladder
static bool tpHitIndexListLess(const TPHitIndex &i, const TPHitIndex &j)
TrackingNtuple(const edm::ParameterSet &)
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
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
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
std::vector< std::vector< float > > trk_mvas
void fillPhase2OTHits(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< float > ph2_zx
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
std::vector< int > simpv_idx
std::vector< unsigned char > QualityMaskCollection
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > pixelSimLinkToken_
CombineDetId< DetIdCommon, DetIdPixelOnly, DetIdOTCommon, DetIdStripOnly > DetIdAll
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 > see_isTrue
std::vector< short > inv_isBarrel
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
std::vector< unsigned short > ring
void fillTracks(const edm::RefToBaseVector< reco::Track > &tracks, const TrackingParticleRefVector &tpCollection, const TrackingParticleRefKeyToIndex &tpKeyToIndex, const reco::BeamSpot &bs, const reco::VertexCollection &vertices, const reco::TrackToTrackingParticleAssociator &associatorByHits, const TransientTrackingRecHitBuilder &theTTRHBuilder, const TrackerTopology &tTopo, const std::set< edm::ProductID > &hitProductIds, const std::map< edm::ProductID, size_t > &seedToCollIndex, const std::vector< const MVACollection * > &mvaColls, const std::vector< const QualityMaskCollection * > &qualColls)
RefToBase< value_type > refAt(size_type i) const
bool isLower(const DetId &id) const
math::XYZPointD Point
point in the space
std::vector< float > see_etaErr
std::vector< float > simhit_z
std::vector< float > ph2_z
std::vector< float > ph2_yy
Parsed parse(const TrackerTopology &tTopo, const DetId &id) const
std::vector< float > trk_refpoint_y
std::vector< unsigned int > trk_nLostLay
std::vector< float > MVACollection
unsigned int module(const DetId &id) const
std::vector< int > sim_event
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::vector< unsigned int > trk_nStrip
SiStripCluster const & stripCluster() const
std::vector< const reco::GenParticle * > RecoGenParticleTrail
reco::GenParticle trail type.
Definition: HistoryBase.h:21
std::vector< float > chargeFraction
edm::EDGetTokenT< edm::ValueMap< unsigned int > > tpNStripStereoLayersToken_
unsigned int tibSide(const DetId &id) const
std::string parametersDefinerName_
std::vector< unsigned int > trk_nPixel
std::vector< float > glu_y
void fillTrackingParticles(const edm::Event &iEvent, const edm::EventSetup &iSetup, const edm::RefToBaseVector< reco::Track > &tracks, const reco::BeamSpot &bs, const TrackingParticleRefVector &tpCollection, const TrackingVertexRefKeyToIndex &tvKeyToIndex, const reco::TrackToTrackingParticleAssociator &associatorByHits, const std::vector< TPHitIndex > &tpHitList)
std::vector< unsigned short > panel
std::vector< float > trk_pz
int iEvent
Definition: GenABIO.cc:230
std::vector< float > trk_dzErr
std::vector< unsigned short > isStereo
std::vector< float > trk_lambdaErr
std::vector< unsigned short > isUpper
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
Definition: HitPattern.cc:335
edm::EDGetTokenT< SiPixelRecHitCollection > pixelRecHitToken_
std::vector< float > ph2_y
bool isNotFinite(T x)
Definition: isFinite.h:10
std::vector< std::tuple< edm::EDGetTokenT< MVACollection >, edm::EDGetTokenT< QualityMaskCollection > > > mvaQualityCollectionTokens_
std::vector< std::vector< int > > simvtx_sourceSimIdx
std::vector< float > trk_etaErr
std::vector< short > pix_isBarrel
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > siphase2OTSimLinksToken_
std::vector< float > glu_yz
std::vector< float > sim_pca_phi
auto dz(const T_Vertex &vertex, const T_Momentum &momentum, const T_Point &point)
std::vector< unsigned int > trk_algo
simTrack
per collection params
void fillTrackingParticlesForSeeds(const TrackingParticleRefVector &tpCollection, const reco::SimToRecoCollection &simRecColl, const TrackingParticleRefKeyToIndex &tpKeyToIndex, const unsigned int seedOffset)
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
std::vector< float > ph2_xy
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< float > vtx_y
std::vector< float > pix_z
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
int bunchCrossing() const
get the detector field from this detid
std::vector< int > bunchCrossing
std::vector< float > sim_eta
std::vector< unsigned short > blade
std::vector< unsigned int > trk_originalAlgo
std::vector< unsigned int > trk_nInnerLost
std::vector< float > str_y
std::vector< int > sim_pdgId
std::vector< int > see_q
std::vector< std::vector< int > > simhit_hitType
std::vector< float > trk_refpoint_z
unsigned int tobSide(const DetId &id) const
math::XYZPoint Point
std::vector< edm::EDGetTokenT< edm::View< reco::Track > > > seedTokens_
edm::EDGetTokenT< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitTPMapToken_
std::vector< float > pix_yz
std::vector< std::vector< int > > sim_genPdgIds
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
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
std::vector< float > vtx_ndof
double chi2() const
chi-squares
Definition: Vertex.h:98
std::vector< std::vector< int > > ph2_simHitIdx
std::vector< float > simvtx_x
double z() const
z coordinate
Definition: Vertex.h:115
T operator[](int i) const
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
DetIdAllPhase2 inv_detId_phase2
std::vector< float > sim_pca_pt
DetIdPhase2OT ph2_detId
std::vector< float > see_dxyErr
bool isMatched(TrackingRecHit const &hit)
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
range equal_range(const OmniClusterRef &key) const
std::vector< float > see_pt
std::vector< unsigned int > see_nPhase2OT
std::vector< edm::EDGetTokenT< std::vector< short > > > seedStopReasonTokens_
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
Definition: Types.py:1
std::vector< float > trk_outer_pt
#define end
Definition: vmac.h:37
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_
const bool includeTrackingParticles_
size_type size() const
std::vector< float > trk_dz
std::vector< float > trk_ptErr
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)
std::vector< float > see_phi
OmniClusterRef const & monoClusterRef() const
std::vector< float > vtx_z
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
std::vector< float > see_pz
void book(const std::string &prefix, TTree *tree)
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 > see_stateTrajPx
std::vector< float > glu_zx
std::shared_ptr< TrackingRecHit const > RecHitPointer
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
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
bool isUpper(const DetId &id) const
std::vector< float > sim_pz
std::vector< int > event
std::vector< std::vector< int > > sim_simHitIdx
edm::Ref< TrackingVertexCollection > TrackingVertexRef
std::vector< unsigned short > isGlued
edm::EventNumber_t ev_event
void push_back(const TrackerTopology &tTopo, const DetId &id)
Definition: DetId.h:18
std::vector< unsigned short > isRPhi
std::vector< float > ph2_x
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleToken_
double x() const
x coordinate
Definition: Vertex.h:111
std::vector< int > glu_stereoIdx
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< std::vector< unsigned short > > trk_qualityMasks
void book(const std::string &prefix, TTree *tree)
def parse(path, config)
Definition: dumpparser.py:13
T const * product() const
Definition: Handle.h:81
std::vector< unsigned int > see_nGlued
std::vector< float > see_py
std::vector< float > pix_x
std::vector< unsigned int > detId
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
const bool includeMVA_
std::vector< float > str_z
std::vector< unsigned short > isStack
std::vector< float > str_zx
uint32_t stack(const DetId &id) const
std::vector< TrackingVertex > TrackingVertexCollection
HistoryBase tracer_
const T & get() const
Definition: EventSetup.h:55
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
std::string algoName() const
Definition: TrackBase.h:508
bool tidIsDoubleSide(const DetId &id) const
int stripLayersWithMeasurement() const
Definition: HitPattern.h:1035
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
bool isValid() const
void push_back(const TrackerTopology &tTopo, const DetId &id)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< unsigned short > isLower
unsigned int tecOrder(const DetId &id) const
Base class to all the history types.
Definition: HistoryBase.h:12
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_
int trackerLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:529
std::vector< short > vtx_valid
bool evaluate(TrackingParticleRef tpr)
Evaluate track history using a TrackingParticleRef.
Definition: HistoryBase.h:122
edm::EventID id() const
Definition: EventBase.h:60
const EncodedEventId & eventId() const
edm::EDGetTokenT< ClusterTPAssociation > clusterTPMapToken_
unsigned int tidOrder(const DetId &id) const
Pixel cluster – collection of neighboring pixels above threshold.
fixed size matrix
std::vector< std::vector< int > > vtx_trkIdx
edm::ProductID id() const
HLT enums.
Pixel pixel(int i) const
void push_back(const TrackerTopology &tTopo, const DetId &id)
std::vector< short > str_isBarrel
auto dxy(const T_Vertex &vertex, const T_Momentum &momentum, const T_Point &point)
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
void depth(int d)
Set the depth of the history.
Definition: HistoryBase.h:53
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< unsigned short > ph2_simType
std::vector< float > sim_pca_eta
void push_back(const RefToBase< T > &)
virtual OmniClusterRef const & firstClusterRef() const =0
std::vector< float > ph2_yz
std::vector< unsigned short > string
Point getBestVertex(reco::Track const &trk, reco::VertexCollection const &vertices, const size_t minNtracks=2)
Definition: getBestVertex.h:8
std::map< SimHitFullKey, size_t > SimHitRefKeyToIndex
static int pixelToChannel(int row, int col)
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
std::vector< unsigned short > rod
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
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
std::vector< float > trk_dxyClosestPV
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
std::vector< std::vector< int > > str_simHitIdx
std::vector< float > see_statePt
std::string builderName_
std::vector< float > trk_ndof
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
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
unsigned int tecPetalNumber(const DetId &id) const
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
std::vector< unsigned int > see_offset
Definition: tree.py:1
std::vector< float > ph2_zz
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
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:76
void book(const std::string &prefix, TTree *tree)
bool isRPhi(const DetId &id) const
std::vector< int > see_trkIdx
unsigned int tobRod(const DetId &id) const
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
math::XYZVectorD Vector
point in the space
std::vector< unsigned short > side
std::vector< float > simhit_tof
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
std::vector< std::vector< int > > sim_seedIdx
void fillVertices(const reco::VertexCollection &vertices, const edm::RefToBaseVector< reco::Track > &tracks)
std::vector< float > pix_xy
std::vector< unsigned short > subdet
std::vector< float > trk_dxy
RecoGenParticleTrail const & recoGenParticleTrail() const
Return all reco::GenParticle in the history.
Definition: HistoryBase.h:83
void book(const std::string &prefix, TTree *tree)
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
std::vector< unsigned int > trk_nInvalid
std::vector< decltype(reco::TrackBase().algoMaskUL())> trk_algoMask
std::vector< std::vector< int > > see_hitIdx
T const * product() const
Definition: ESHandle.h:86
Definition: vlib.h:208
std::vector< float > vtx_x
void push_back(const TrackerTopology &tTopo, const DetId &id)
std::vector< unsigned int > see_nPixel
edm::Ref< TrackingParticleCollection > TrackingParticleRef
ProductID id() const
std::vector< unsigned short > petalNumber
std::vector< float > see_eta
const std::vector< uint8_t > & amplitudes() const
unsigned int pxfPanel(const DetId &id) const
DetIdAllPhase2 simhit_detId_phase2
std::vector< unsigned int > trk_nValid
unsigned int pxfBlade(const DetId &id) const
std::vector< float > trk_inner_px
DetIdStrip glu_detId
double yError() const
error on y
Definition: Vertex.h:121
const_iterator begin(bool update=false) const
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< float > vtx_zErr
unsigned int operator[](size_t i) const
std::vector< float > simhit_eloss
Definition: event.py:1
std::vector< int > sim_isFromBHadron
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > stripSimLinkToken_
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
unsigned int tibOrder(const DetId &id) const
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