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