CMS 3D CMS Logo

ConversionTrackCandidateProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
4 
5 // Framework
13 //
17 //
19 //
21 // Abstract classes for the conversion tracking components
24 // Class header file
26 //
37 
45 
48 
49 namespace {
50  auto createBaseCkfTrajectoryBuilder(const edm::ParameterSet& pset, edm::ConsumesCollector&& iC) {
51  return BaseCkfTrajectoryBuilderFactory::get()->create(pset.getParameter<std::string>("ComponentType"), pset, iC);
52  }
53 } // namespace
54 
56  : theTrajectoryBuilder_(createBaseCkfTrajectoryBuilder(
57  config.getParameter<edm::ParameterSet>("TrajectoryBuilderPSet"), consumesCollector())),
58  theOutInSeedFinder_(new OutInConversionSeedFinder(config, consumesCollector())),
59  theOutInTrackFinder_(new OutInConversionTrackFinder(config, theTrajectoryBuilder_.get())),
60  theInOutSeedFinder_(new InOutConversionSeedFinder(config, consumesCollector())),
61  theInOutTrackFinder_(new InOutConversionTrackFinder(config, theTrajectoryBuilder_.get())) {
62  //std::cout << "ConversionTrackCandidateProducer CTOR " << "\n";
63  nEvt_ = 0;
64 
65  // use onfiguration file to setup input/output collection names
66 
68  consumes<edm::View<reco::CaloCluster> >(config.getParameter<edm::InputTag>("bcBarrelCollection"));
70  consumes<edm::View<reco::CaloCluster> >(config.getParameter<edm::InputTag>("bcEndcapCollection"));
71 
73  consumes<edm::View<reco::CaloCluster> >(config.getParameter<edm::InputTag>("scHybridBarrelProducer"));
75  consumes<edm::View<reco::CaloCluster> >(config.getParameter<edm::InputTag>("scIslandEndcapProducer"));
76 
77  OutInTrackCandidateCollection_ = config.getParameter<std::string>("outInTrackCandidateCollection");
78  InOutTrackCandidateCollection_ = config.getParameter<std::string>("inOutTrackCandidateCollection");
79 
81  config.getParameter<std::string>("outInTrackCandidateSCAssociationCollection");
83  config.getParameter<std::string>("inOutTrackCandidateSCAssociationCollection");
84 
86  consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("barrelEcalRecHitCollection"));
88  consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("endcapEcalRecHitCollection"));
89  hcalTowers_ = consumes<CaloTowerCollection>(config.getParameter<edm::InputTag>("hcalTowers"));
90  measurementTrkEvtToken_ = consumes<MeasurementTrackerEvent>(edm::InputTag("MeasurementTrackerEvent"));
91  hOverEConeSize_ = config.getParameter<double>("hOverEConeSize");
92  maxHOverE_ = config.getParameter<double>("maxHOverE");
93  minSCEt_ = config.getParameter<double>("minSCEt");
94  isoConeR_ = config.getParameter<double>("isoConeR");
95  isoInnerConeR_ = config.getParameter<double>("isoInnerConeR");
96  isoEtaSlice_ = config.getParameter<double>("isoEtaSlice");
97  isoEtMin_ = config.getParameter<double>("isoEtMin");
98  isoEMin_ = config.getParameter<double>("isoEMin");
99  vetoClusteredHits_ = config.getParameter<bool>("vetoClusteredHits");
100  useNumXtals_ = config.getParameter<bool>("useNumXstals");
101  ecalIsoCut_offset_ = config.getParameter<double>("ecalIsoCut_offset");
102  ecalIsoCut_slope_ = config.getParameter<double>("ecalIsoCut_slope");
103 
104  //Flags and Severities to be excluded from photon calculations
105  const std::vector<std::string> flagnamesEB =
106  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
107 
108  const std::vector<std::string> flagnamesEE =
109  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
110 
111  flagsexclEB_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
112 
113  flagsexclEE_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
114 
115  const std::vector<std::string> severitynamesEB =
116  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
117 
118  severitiesexclEB_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
119 
120  const std::vector<std::string> severitynamesEE =
121  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
122 
123  severitiesexclEE_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
124 
125  // Register the product
126  produces<TrackCandidateCollection>(OutInTrackCandidateCollection_);
127  produces<TrackCandidateCollection>(InOutTrackCandidateCollection_);
128 
129  produces<reco::TrackCandidateCaloClusterPtrAssociation>(OutInTrackSuperClusterAssociationCollection_);
130  produces<reco::TrackCandidateCaloClusterPtrAssociation>(InOutTrackSuperClusterAssociationCollection_);
131 }
132 
134 
136  theOutInSeedFinder_->setEventSetup(theEventSetup);
137  theInOutSeedFinder_->setEventSetup(theEventSetup);
138  theOutInTrackFinder_->setEventSetup(theEventSetup);
139  theInOutTrackFinder_->setEventSetup(theEventSetup);
140 }
141 
144  theEventSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
145  const NavigationSchool* navigation = nav.product();
146  theTrajectoryBuilder_->setNavigationSchool(navigation);
147  theOutInSeedFinder_->setNavigationSchool(navigation);
148  theInOutSeedFinder_->setNavigationSchool(navigation);
149 }
150 
152  using namespace edm;
153  nEvt_++;
154  // std::cout << "ConversionTrackCandidateProducer Analyzing event number " << theEvent.id() << " Global Counter " << nEvt_ << "\n";
155 
156  // get the trajectory builder and initialize it with the data
158  theEvent.getByToken(measurementTrkEvtToken_, data);
159  theTrajectoryBuilder_->setEvent(theEvent, theEventSetup, &*data);
160 
161  // this need to be done after the initialization of the TrajectoryBuilder!
162  setEventSetup(theEventSetup);
163 
164  theOutInSeedFinder_->setEvent(theEvent);
165  theInOutSeedFinder_->setEvent(theEvent);
166 
167  //
168  // create empty output collections
169  //
170  // Out In Track Candidates
171  auto outInTrackCandidate_p = std::make_unique<TrackCandidateCollection>();
172  // In Out Track Candidates
173  auto inOutTrackCandidate_p = std::make_unique<TrackCandidateCollection>();
174  // Track Candidate calo Cluster Association
175  auto outInAssoc_p = std::make_unique<reco::TrackCandidateCaloClusterPtrAssociation>();
176  auto inOutAssoc_p = std::make_unique<reco::TrackCandidateCaloClusterPtrAssociation>();
177 
178  // Get the basic cluster collection in the Barrel
179  bool validBarrelBCHandle = true;
181  theEvent.getByToken(bcBarrelCollection_, bcBarrelHandle);
182  if (!bcBarrelHandle.isValid()) {
183  edm::LogError("ConversionTrackCandidateProducer") << "Error! Can't get the Barrel Basic Clusters!";
184  validBarrelBCHandle = false;
185  }
186 
187  // Get the basic cluster collection in the Endcap
188  bool validEndcapBCHandle = true;
190  theEvent.getByToken(bcEndcapCollection_, bcEndcapHandle);
191  if (!bcEndcapHandle.isValid()) {
192  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the Endcap Basic Clusters";
193  validEndcapBCHandle = false;
194  }
195 
196  // Get the Super Cluster collection in the Barrel
197  bool validBarrelSCHandle = true;
199  theEvent.getByToken(scHybridBarrelProducer_, scBarrelHandle);
200  if (!scBarrelHandle.isValid()) {
201  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the barrel superclusters!";
202  validBarrelSCHandle = false;
203  }
204 
205  // Get the Super Cluster collection in the Endcap
206  bool validEndcapSCHandle = true;
208  theEvent.getByToken(scIslandEndcapProducer_, scEndcapHandle);
209  if (!scEndcapHandle.isValid()) {
210  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the endcap superclusters!";
211  validEndcapSCHandle = false;
212  }
213 
214  // get the geometry from the event setup:
215  theEventSetup.get<CaloGeometryRecord>().get(theCaloGeom_);
216 
217  // get Hcal towers collection
218  Handle<CaloTowerCollection> hcalTowersHandle;
219  theEvent.getByToken(hcalTowers_, hcalTowersHandle);
220 
221  edm::Handle<EcalRecHitCollection> ecalhitsCollEB;
222  edm::Handle<EcalRecHitCollection> ecalhitsCollEE;
223 
224  theEvent.getByToken(endcapecalCollection_, ecalhitsCollEE);
225  theEvent.getByToken(barrelecalCollection_, ecalhitsCollEB);
226 
228  theEventSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
229  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
230 
231  caloPtrVecOutIn_.clear();
232  caloPtrVecInOut_.clear();
233 
234  bool isBarrel = true;
235  if (validBarrelBCHandle && validBarrelSCHandle)
236  buildCollections(isBarrel,
237  scBarrelHandle,
238  bcBarrelHandle,
239  ecalhitsCollEB,
240  *ecalhitsCollEB,
241  sevLevel,
242  hcalTowersHandle,
243  *outInTrackCandidate_p,
244  *inOutTrackCandidate_p,
247 
248  if (validEndcapBCHandle && validEndcapSCHandle) {
249  isBarrel = false;
250  buildCollections(isBarrel,
251  scEndcapHandle,
252  bcEndcapHandle,
253  ecalhitsCollEE,
254  *ecalhitsCollEE,
255  sevLevel,
256  hcalTowersHandle,
257  *outInTrackCandidate_p,
258  *inOutTrackCandidate_p,
261  }
262 
263  // std::cout << " ConversionTrackCandidateProducer caloPtrVecOutIn_ size " << caloPtrVecOutIn_.size() << " caloPtrVecInOut_ size " << caloPtrVecInOut_.size() << "\n";
264 
265  // put all products in the event
266  // Barrel
267  //std::cout << "ConversionTrackCandidateProducer Putting in the event " << (*outInTrackCandidate_p).size() << " Out In track Candidates " << "\n";
268  const edm::OrphanHandle<TrackCandidateCollection> refprodOutInTrackC =
269  theEvent.put(std::move(outInTrackCandidate_p), OutInTrackCandidateCollection_);
270  //std::cout << "ConversionTrackCandidateProducer refprodOutInTrackC size " << (*(refprodOutInTrackC.product())).size() << "\n";
271  //
272  //std::cout << "ConversionTrackCandidateProducer Putting in the event " << (*inOutTrackCandidate_p).size() << " In Out track Candidates " << "\n";
273  const edm::OrphanHandle<TrackCandidateCollection> refprodInOutTrackC =
274  theEvent.put(std::move(inOutTrackCandidate_p), InOutTrackCandidateCollection_);
275  //std::cout << "ConversionTrackCandidateProducer refprodInOutTrackC size " << (*(refprodInOutTrackC.product())).size() << "\n";
276 
277  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerOI(*outInAssoc_p);
278  fillerOI.insert(refprodOutInTrackC, caloPtrVecOutIn_.begin(), caloPtrVecOutIn_.end());
279  fillerOI.fill();
280  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerIO(*inOutAssoc_p);
281  fillerIO.insert(refprodInOutTrackC, caloPtrVecInOut_.begin(), caloPtrVecInOut_.end());
282  fillerIO.fill();
283 
284  // std::cout << "ConversionTrackCandidateProducer Putting in the event OutIn track - SC association: size " << (*outInAssoc_p).size() << "\n";
286 
287  // std::cout << "ConversionTrackCandidateProducer Putting in the event InOut track - SC association: size " << (*inOutAssoc_p).size() << "\n";
289 
290  theOutInSeedFinder_->clear();
291  theInOutSeedFinder_->clear();
292 }
293 
295  const edm::Handle<edm::View<reco::CaloCluster> >& scHandle,
296  const edm::Handle<edm::View<reco::CaloCluster> >& bcHandle,
297  edm::Handle<EcalRecHitCollection> ecalRecHitHandle,
298  const EcalRecHitCollection& ecalRecHits,
299  const EcalSeverityLevelAlgo* sevLevel,
300  //edm::ESHandle<EcalChannelStatus> chStatus,
301  //const EcalChannelStatus* chStatus,
302  const edm::Handle<CaloTowerCollection>& hcalTowersHandle,
303  TrackCandidateCollection& outInTrackCandidates,
304  TrackCandidateCollection& inOutTrackCandidates,
305  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
306  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO)
307 
308 {
309  //std::cout << "ConversionTrackCandidateProducer is barrel " << isBarrel << "\n";
310  //std::cout << "ConversionTrackCandidateProducer builcollections sc size " << scHandle->size() << "\n";
311  //std::cout << "ConversionTrackCandidateProducer builcollections bc size " << bcHandle->size() << "\n";
312  //const CaloGeometry* geometry = theCaloGeom_.product();
313 
314  // Loop over SC in the barrel and reconstruct converted photons
315  for (auto const& aClus : scHandle->ptrs()) {
316  // preselection based in Et and H/E cut.
317  if (aClus->energy() / cosh(aClus->eta()) <= minSCEt_)
318  continue;
319  if (aClus->eta() > 1.479 && aClus->eta() < 1.556)
320  continue;
321 
322  const reco::CaloCluster* pClus = &(*aClus);
323  const reco::SuperCluster* sc = dynamic_cast<const reco::SuperCluster*>(pClus);
324  double scEt = sc->energy() / cosh(sc->eta());
325  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
326  EgammaTowerIsolation towerIso(hOverEConeSize_, 0., 0., -1, hcalTowersColl);
327  double HoE = towerIso.getTowerESum(sc) / sc->energy();
328  if (HoE >= maxHOverE_)
329  continue;
330 
332  EgammaRecHitIsolation ecalIso(
334 
337  if (isBarrel) {
338  ecalIso.doFlagChecks(flagsexclEB_);
339  ecalIso.doSeverityChecks(ecalRecHitHandle.product(), severitiesexclEB_);
340  } else {
341  ecalIso.doFlagChecks(flagsexclEE_);
342  ecalIso.doSeverityChecks(ecalRecHitHandle.product(), severitiesexclEE_);
343  }
344 
345  double ecalIsolation = ecalIso.getEtSum(sc);
346  if (ecalIsolation > ecalIsoCut_offset_ + ecalIsoCut_slope_ * scEt)
347  continue;
348 
349  // Now launch the seed finding
350  theOutInSeedFinder_->setCandidate(pClus->energy(),
351  GlobalPoint(pClus->position().x(), pClus->position().y(), pClus->position().z()));
352  theOutInSeedFinder_->makeSeeds(bcHandle);
353 
354  std::vector<Trajectory> theOutInTracks =
355  theOutInTrackFinder_->tracks(theOutInSeedFinder_->seeds(), outInTrackCandidates);
356 
357  theInOutSeedFinder_->setCandidate(pClus->energy(),
358  GlobalPoint(pClus->position().x(), pClus->position().y(), pClus->position().z()));
359  theInOutSeedFinder_->setTracks(theOutInTracks);
360  theInOutSeedFinder_->makeSeeds(bcHandle);
361 
362  std::vector<Trajectory> theInOutTracks =
363  theInOutTrackFinder_->tracks(theInOutSeedFinder_->seeds(), inOutTrackCandidates);
364 
365  // Debug
366  // std::cout << "ConversionTrackCandidateProducer theOutInTracks.size() " << theOutInTracks.size() << " theInOutTracks.size() " << theInOutTracks.size() << " Event pointer to out in track size barrel " << outInTrackCandidates.size() << " in out track size " << inOutTrackCandidates.size() << "\n";
367 
369  for (std::vector<Trajectory>::const_iterator it = theOutInTracks.begin(); it != theOutInTracks.end(); ++it) {
370  caloPtrVecOutIn_.push_back(aClus);
371  // std::cout << "ConversionTrackCandidateProducer Barrel OutIn Tracks Number of hits " << (*it).foundHits() << "\n";
372  }
373 
374  for (std::vector<Trajectory>::const_iterator it = theInOutTracks.begin(); it != theInOutTracks.end(); ++it) {
375  caloPtrVecInOut_.push_back(aClus);
376  // std::cout << "ConversionTrackCandidateProducer Barrel InOut Tracks Number of hits " << (*it).foundHits() << "\n";
377  }
378  }
379 }
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:153
std::unique_ptr< OutInConversionSeedFinder > theOutInSeedFinder_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scIslandEndcapProducer_
double getEtSum(const reco::Candidate *emObject) const
std::vector< TrackCandidate > TrackCandidateCollection
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
edm::EDGetTokenT< EcalRecHitCollection > endcapecalCollection_
Definition: config.py:1
std::vector< edm::Ptr< reco::CaloCluster > > caloPtrVecInOut_
edm::EDGetTokenT< MeasurementTrackerEvent > measurementTrkEvtToken_
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder_
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:180
void doFlagChecks(const std::vector< int > &v)
std::unique_ptr< OutInConversionTrackFinder > theOutInTrackFinder_
void setUseNumCrystals(bool b=true)
double energy() const
cluster energy
Definition: CaloCluster.h:148
edm::EDGetTokenT< CaloTowerCollection > hcalTowers_
bool isValid() const
Definition: HandleBase.h:70
double getTowerESum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
ConversionTrackCandidateProducer(const edm::ParameterSet &ps)
void doSeverityChecks(const EcalRecHitCollection *const recHits, const std::vector< int > &v)
std::unique_ptr< InOutConversionSeedFinder > theInOutSeedFinder_
std::vector< edm::Ptr< reco::CaloCluster > > caloPtrVecOutIn_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scHybridBarrelProducer_
T const * product() const
Definition: Handle.h:69
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcBarrelCollection_
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void setVetoClustered(bool b=true)
T get() const
Definition: EventSetup.h:73
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcEndcapCollection_
std::unique_ptr< InOutConversionTrackFinder > theInOutTrackFinder_
void buildCollections(bool detector, const edm::Handle< edm::View< reco::CaloCluster > > &scHandle, const edm::Handle< edm::View< reco::CaloCluster > > &bcHandle, edm::Handle< EcalRecHitCollection > ecalRecHitHandle, const EcalRecHitCollection &ecalRecHits, const EcalSeverityLevelAlgo *sevLev, const edm::Handle< CaloTowerCollection > &hcalTowersHandle, TrackCandidateCollection &outInTracks, TrackCandidateCollection &inOutTracks, std::vector< edm::Ptr< reco::CaloCluster > > &vecRecOI, std::vector< edm::Ptr< reco::CaloCluster > > &vecRecIO)
void produce(edm::Event &evt, const edm::EventSetup &es) override
void beginRun(edm::Run const &, edm::EventSetup const &es) final
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< EcalRecHitCollection > barrelecalCollection_
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45