CMS 3D CMS Logo

GSFTrackImporter.cc
Go to the documentation of this file.
13 
15 public:
17  : BlockElementImporterBase(conf, sumes),
18  _src(sumes.consumes<reco::GsfPFRecTrackCollection>(conf.getParameter<edm::InputTag>("source"))),
19  _isSecondary(conf.getParameter<bool>("gsfsAreSecondary")),
20  _superClustersArePF(conf.getParameter<bool>("superClustersArePF")) {}
21 
22  void importToBlock(const edm::Event&, ElementList&) const override;
23 
24 private:
27 };
28 
30 
32  auto gsftracks = e.getHandle(_src);
33  elems.reserve(elems.size() + gsftracks->size());
34  // setup our elements so that all the SCs are grouped together
35  auto SCs_end =
36  std::partition(elems.begin(), elems.end(), [](const auto& a) { return a->type() == reco::PFBlockElement::SC; });
37  // insert gsf tracks and SCs, binding pre-existing SCs to ECAL-Driven GSF
38  auto bgsf = gsftracks->cbegin();
39  auto egsf = gsftracks->cend();
40  for (auto gsftrack = bgsf; gsftrack != egsf; ++gsftrack) {
41  reco::GsfPFRecTrackRef gsfref(gsftracks, std::distance(bgsf, gsftrack));
42  const reco::GsfTrackRef& basegsfref = gsftrack->gsfTrackRef();
43  const auto& gsfextraref = basegsfref->extra();
44  // import associated super clusters
45  if (gsfextraref.isAvailable() && gsfextraref->seedRef().isAvailable()) {
46  reco::ElectronSeedRef seedref = gsfextraref->seedRef().castTo<reco::ElectronSeedRef>();
47  if (seedref.isAvailable() && seedref->isEcalDriven()) {
48  reco::SuperClusterRef scref = seedref->caloCluster().castTo<reco::SuperClusterRef>();
49  if (scref.isNonnull()) {
50  // explicitly veto HGCal super clusters
51  if (scref->seed()->seed().det() == DetId::HGCalEE || scref->seed()->seed().det() == DetId::HGCalHSi ||
52  scref->seed()->seed().det() == DetId::HGCalHSc || scref->seed()->seed().det() == DetId::Forward)
53  continue;
54  PFBlockElementSCEqual myEqual(scref);
55  auto sc_elem = std::find_if(elems.begin(), SCs_end, myEqual);
56  if (sc_elem != SCs_end) {
57  reco::PFBlockElementSuperCluster* scbe = static_cast<reco::PFBlockElementSuperCluster*>(sc_elem->get());
58  scbe->setFromGsfElectron(true);
59  } else {
61  scbe->setFromGsfElectron(true);
63  SCs_end = elems.emplace(SCs_end, scbe);
64  ++SCs_end; // point to element *after* the new one
65  }
66  }
67  }
68  } // gsf extra ref?
69  // cache the SC_end offset
70  size_t SCs_end_position = std::distance(elems.begin(), SCs_end);
71  // get track momentum information
72  const std::vector<reco::PFTrajectoryPoint>& PfGsfPoint = gsftrack->trajectoryPoints();
73  unsigned int c_gsf = 0;
74  bool PassTracker = false;
75  unsigned int IndexPout = 0;
76  for (const auto& pfGsfPoint : PfGsfPoint) {
77  if (pfGsfPoint.isValid()) {
78  int layGsfP = pfGsfPoint.layer();
79  if (layGsfP == -1)
80  PassTracker = true;
81  else if (PassTracker && layGsfP > 0) {
82  IndexPout = c_gsf - 1;
83  break;
84  }
85  ++c_gsf;
86  }
87  }
88  const math::XYZTLorentzVector& pin = PfGsfPoint[0].momentum();
89  const math::XYZTLorentzVector& pout = PfGsfPoint[IndexPout].momentum();
91  if (_isSecondary) {
93  }
94  elems.emplace_back(temp);
95  // import brems from this primary gsf
96  for (const auto& brem : gsfref->PFRecBrem()) {
97  const unsigned TrajP = brem.indTrajPoint();
98  if (TrajP != 99) {
99  const double DP = brem.DeltaP();
100  const double sDP = brem.SigmaDeltaP();
101  elems.emplace_back(new reco::PFBlockElementBrem(gsfref, DP, sDP, TrajP));
102  }
103  }
104  // protect against reallocations, create a fresh iterator
105  SCs_end = elems.begin() + SCs_end_position;
106  } // loop on gsf tracks
107  elems.shrink_to_fit();
108 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
const bool _isSecondary
void setFromGsfElectron(bool val)
set provenance
bool isAvailable() const
Definition: Ref.h:537
GSFTrackImporter(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:547
std::vector< GsfPFRecTrack > GsfPFRecTrackCollection
collection of GsfPFRecTrack objects
void importToBlock(const edm::Event &, ElementList &) const override
void setTrackType(TrackType trType, bool value) override
the trackType
fixed size matrix
HLT enums.
double a
Definition: hdecay.h:119
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
edm::EDGetTokenT< reco::GsfPFRecTrackCollection > _src
const bool _superClustersArePF