CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConversionTrackCandidateProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
4 
5 // Framework
12 //
16 //
18 //
20 // Abstract classes for the conversion tracking components
23 // Class header file
25 //
35 
43 
46 
47 
49  conf_(config),
50  theNavigationSchool_(0),
51  theOutInSeedFinder_(0),
52  theOutInTrackFinder_(0),
53  theInOutSeedFinder_(0),
54  theInOutTrackFinder_(0)
55 {
56  //std::cout << "ConversionTrackCandidateProducer CTOR " << "\n";
57  nEvt_=0;
58 
59  // use onfiguration file to setup input/output collection names
60 
61 
63  consumes<edm::View<reco::CaloCluster> >(conf_.getParameter<edm::InputTag>("bcBarrelCollection"));
65  consumes<edm::View<reco::CaloCluster> >(conf_.getParameter<edm::InputTag>("bcEndcapCollection"));
66 
68  consumes<edm::View<reco::CaloCluster> >(conf_.getParameter<edm::InputTag>("scHybridBarrelProducer"));
70  consumes<edm::View<reco::CaloCluster> >(conf_.getParameter<edm::InputTag>("scIslandEndcapProducer"));
71 
72  OutInTrackCandidateCollection_ = conf_.getParameter<std::string>("outInTrackCandidateCollection");
73  InOutTrackCandidateCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateCollection");
74 
75 
76  OutInTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("outInTrackCandidateSCAssociationCollection");
77  InOutTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateSCAssociationCollection");
78 
80  consumes<EcalRecHitCollection>(conf_.getParameter<edm::InputTag>("barrelEcalRecHitCollection"));
82  consumes<EcalRecHitCollection>(conf_.getParameter<edm::InputTag>("endcapEcalRecHitCollection"));
83 
84  hcalTowers_ =
85  consumes<CaloTowerCollection>(conf_.getParameter<edm::InputTag>("hcalTowers"));
86  hOverEConeSize_ = conf_.getParameter<double>("hOverEConeSize");
87  maxHOverE_ = conf_.getParameter<double>("maxHOverE");
88  minSCEt_ = conf_.getParameter<double>("minSCEt");
89  isoConeR_ = conf_.getParameter<double>("isoConeR");
90  isoInnerConeR_ = conf_.getParameter<double>("isoInnerConeR");
91  isoEtaSlice_ = conf_.getParameter<double>("isoEtaSlice");
92  isoEtMin_ = conf_.getParameter<double>("isoEtMin");
93  isoEMin_ = conf_.getParameter<double>("isoEMin");
94  vetoClusteredHits_ = conf_.getParameter<bool>("vetoClusteredHits");
95  useNumXtals_ = conf_.getParameter<bool>("useNumXstals");
96  ecalIsoCut_offset_ = conf_.getParameter<double>("ecalIsoCut_offset");
97  ecalIsoCut_slope_ = conf_.getParameter<double>("ecalIsoCut_slope");
98 
99  //Flags and Severities to be excluded from photon calculations
100  const std::vector<std::string> flagnamesEB =
101  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
102 
103  const std::vector<std::string> flagnamesEE =
104  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
105 
106  flagsexclEB_=
107  StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
108 
109  flagsexclEE_=
110  StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
111 
112  const std::vector<std::string> severitynamesEB =
113  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
114 
116  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
117 
118  const std::vector<std::string> severitynamesEE =
119  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
120 
122  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
123 
124  // TrajectoryBuilder name
125  trajectoryBuilderName_ = conf_.getParameter<std::string>("TrajectoryBuilder");
126 
127  // Register the product
128  produces< TrackCandidateCollection > (OutInTrackCandidateCollection_);
129  produces< TrackCandidateCollection > (InOutTrackCandidateCollection_);
130 
131  produces< reco::TrackCandidateCaloClusterPtrAssociation > ( OutInTrackSuperClusterAssociationCollection_);
132  produces< reco::TrackCandidateCaloClusterPtrAssociation > ( InOutTrackSuperClusterAssociationCollection_);
133 
134 
135 }
136 
138 
140 
141 
142  theOutInSeedFinder_->setEventSetup(theEventSetup);
143  theInOutSeedFinder_->setEventSetup(theEventSetup);
144  theOutInTrackFinder_->setEventSetup(theEventSetup);
145  theInOutTrackFinder_->setEventSetup(theEventSetup);
146 
147 
148 }
149 
150 
152 
154  theEventSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
156 
157  // get the Out In Seed Finder
159 
160  // get the Out In Track Finder
161  theOutInTrackFinder_ = new OutInConversionTrackFinder ( theEventSetup, conf_ );
162 
163 
164  // get the In Out Seed Finder
166 
167 
168  // get the In Out Track Finder
169  theInOutTrackFinder_ = new InOutConversionTrackFinder ( theEventSetup, conf_ );
170 }
171 
172 
174  delete theOutInSeedFinder_;
175  delete theOutInTrackFinder_;
176  delete theInOutSeedFinder_;
177  delete theInOutTrackFinder_;
178 }
179 
180 
181 
182 
184 
185  using namespace edm;
186  nEvt_++;
187  // std::cout << "ConversionTrackCandidateProducer Analyzing event number " << theEvent.id() << " Global Counter " << nEvt_ << "\n";
188 
189 
190 
191  setEventSetup( theEventSetup );
192 
193  // get the trajectory builder and initialize it with the data
196  theEvent.getByLabel(edm::InputTag("MeasurementTrackerEvent"), data);
197  std::auto_ptr<BaseCkfTrajectoryBuilder> trajectoryBuilder;
198  trajectoryBuilder.reset((dynamic_cast<const BaseCkfTrajectoryBuilder &>(*theTrajectoryBuilder_)).clone(&*data));
199 
200  theOutInSeedFinder_->setEvent(theEvent);
201  theInOutSeedFinder_->setEvent(theEvent);
202  theOutInTrackFinder_->setTrajectoryBuilder(*trajectoryBuilder);
203  theInOutTrackFinder_->setTrajectoryBuilder(*trajectoryBuilder);
204 
205 // Set the navigation school
207 
208  //
209  // create empty output collections
210  //
211  // Out In Track Candidates
212  std::auto_ptr<TrackCandidateCollection> outInTrackCandidate_p(new TrackCandidateCollection);
213  // In Out Track Candidates
214  std::auto_ptr<TrackCandidateCollection> inOutTrackCandidate_p(new TrackCandidateCollection);
215  // Track Candidate calo Cluster Association
216  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> outInAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
217  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> inOutAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
218 
219  // Get the basic cluster collection in the Barrel
220  bool validBarrelBCHandle=true;
222  theEvent.getByToken(bcBarrelCollection_, bcBarrelHandle);
223  if (!bcBarrelHandle.isValid()) {
224  edm::LogError("ConversionTrackCandidateProducer")
225  << "Error! Can't get the Barrel Basic Clusters!";
226  validBarrelBCHandle=false;
227  }
228 
229 
230  // Get the basic cluster collection in the Endcap
231  bool validEndcapBCHandle=true;
233  theEvent.getByToken(bcEndcapCollection_, bcEndcapHandle);
234  if (!bcEndcapHandle.isValid()) {
235  edm::LogError("CoonversionTrackCandidateProducer")
236  << "Error! Can't get the Endcap Basic Clusters";
237  validEndcapBCHandle=false;
238  }
239 
240 
241 
242  // Get the Super Cluster collection in the Barrel
243  bool validBarrelSCHandle=true;
245  theEvent.getByToken(scHybridBarrelProducer_,scBarrelHandle);
246  if (!scBarrelHandle.isValid()) {
247  edm::LogError("CoonversionTrackCandidateProducer")
248  << "Error! Can't get the barrel superclusters!";
249  validBarrelSCHandle=false;
250  }
251 
252 
253  // Get the Super Cluster collection in the Endcap
254  bool validEndcapSCHandle=true;
256  theEvent.getByToken(scIslandEndcapProducer_,scEndcapHandle);
257  if (!scEndcapHandle.isValid()) {
258  edm::LogError("CoonversionTrackCandidateProducer")
259  << "Error! Can't get the endcap superclusters!";
260  validEndcapSCHandle=false;
261  }
262 
263 
264  // get the geometry from the event setup:
265  theEventSetup.get<CaloGeometryRecord>().get(theCaloGeom_);
266 
267  // get Hcal towers collection
268  Handle<CaloTowerCollection> hcalTowersHandle;
269  theEvent.getByToken(hcalTowers_, hcalTowersHandle);
270 
271  edm::Handle<EcalRecHitCollection> ecalhitsCollEB;
272  edm::Handle<EcalRecHitCollection> ecalhitsCollEE;
273 
274  theEvent.getByToken(endcapecalCollection_, ecalhitsCollEE);
275  theEvent.getByToken(barrelecalCollection_, ecalhitsCollEB);
276 
278  theEventSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
279  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
280 
281  std::auto_ptr<CaloRecHitMetaCollectionV> RecHitsEE(0);
282  RecHitsEE = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(ecalhitsCollEE.product()));
283 
284  std::auto_ptr<CaloRecHitMetaCollectionV> RecHitsEB(0);
285  RecHitsEB = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(ecalhitsCollEB.product()));
286 
287 
288  caloPtrVecOutIn_.clear();
289  caloPtrVecInOut_.clear();
290 
291  bool isBarrel=true;
292  if ( validBarrelBCHandle && validBarrelSCHandle )
293  buildCollections(isBarrel, scBarrelHandle, bcBarrelHandle, ecalhitsCollEB, &(*RecHitsEB), sevLevel, hcalTowersHandle, *outInTrackCandidate_p, *inOutTrackCandidate_p, caloPtrVecOutIn_, caloPtrVecInOut_);
294 
295  if ( validEndcapBCHandle && validEndcapSCHandle ) {
296  isBarrel=false;
297  buildCollections(isBarrel, scEndcapHandle, bcEndcapHandle, ecalhitsCollEE, &(*RecHitsEE), sevLevel, hcalTowersHandle, *outInTrackCandidate_p, *inOutTrackCandidate_p, caloPtrVecOutIn_, caloPtrVecInOut_);
298  }
299 
300 
301  // std::cout << " ConversionTrackCandidateProducer caloPtrVecOutIn_ size " << caloPtrVecOutIn_.size() << " caloPtrVecInOut_ size " << caloPtrVecInOut_.size() << "\n";
302 
303 
304 
305  // put all products in the event
306  // Barrel
307  //std::cout << "ConversionTrackCandidateProducer Putting in the event " << (*outInTrackCandidate_p).size() << " Out In track Candidates " << "\n";
308  const edm::OrphanHandle<TrackCandidateCollection> refprodOutInTrackC = theEvent.put( outInTrackCandidate_p, OutInTrackCandidateCollection_ );
309  //std::cout << "ConversionTrackCandidateProducer refprodOutInTrackC size " << (*(refprodOutInTrackC.product())).size() << "\n";
310  //
311  //std::cout << "ConversionTrackCandidateProducer Putting in the event " << (*inOutTrackCandidate_p).size() << " In Out track Candidates " << "\n";
312  const edm::OrphanHandle<TrackCandidateCollection> refprodInOutTrackC = theEvent.put( inOutTrackCandidate_p, InOutTrackCandidateCollection_ );
313  //std::cout << "ConversionTrackCandidateProducer refprodInOutTrackC size " << (*(refprodInOutTrackC.product())).size() << "\n";
314 
315 
316  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerOI(*outInAssoc_p);
317  fillerOI.insert(refprodOutInTrackC, caloPtrVecOutIn_.begin(), caloPtrVecOutIn_.end());
318  fillerOI.fill();
319  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerIO(*inOutAssoc_p);
320  fillerIO.insert(refprodInOutTrackC, caloPtrVecInOut_.begin(), caloPtrVecInOut_.end());
321  fillerIO.fill();
322 
323 
324 
325  // std::cout << "ConversionTrackCandidateProducer Putting in the event OutIn track - SC association: size " << (*outInAssoc_p).size() << "\n";
326  theEvent.put( outInAssoc_p, OutInTrackSuperClusterAssociationCollection_);
327 
328  // std::cout << "ConversionTrackCandidateProducer Putting in the event InOut track - SC association: size " << (*inOutAssoc_p).size() << "\n";
329  theEvent.put( inOutAssoc_p, InOutTrackSuperClusterAssociationCollection_);
330 
333 
334 
335 
336 }
337 
338 
340  const edm::Handle<edm::View<reco::CaloCluster> > & scHandle,
341  const edm::Handle<edm::View<reco::CaloCluster> > & bcHandle,
342  edm::Handle<EcalRecHitCollection> ecalRecHitHandle,
343  CaloRecHitMetaCollectionV* ecalRecHits,
344  const EcalSeverityLevelAlgo* sevLevel,
345  //edm::ESHandle<EcalChannelStatus> chStatus,
346  //const EcalChannelStatus* chStatus,
347  const edm::Handle<CaloTowerCollection> & hcalTowersHandle,
348  TrackCandidateCollection& outInTrackCandidates,
349  TrackCandidateCollection& inOutTrackCandidates,
350  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
351  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO )
352 
353 {
354 
355  // std::cout << "ConversionTrackCandidateProducer builcollections bc size " << bcHandle->size() << "\n";
356  //const CaloGeometry* geometry = theCaloGeom_.product();
357 
358  // Loop over SC in the barrel and reconstruct converted photons
359  for (unsigned i = 0; i < scHandle->size(); ++i ) {
360 
361  reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
362 
363  // preselection based in Et and H/E cut.
364  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
365  if (aClus->eta() > 1.479 && aClus->eta() < 1.556 ) continue;
366 
367  const reco::CaloCluster* pClus=&(*aClus);
368  const reco::SuperCluster* sc=dynamic_cast<const reco::SuperCluster*>(pClus);
369  double scEt = sc->energy()/cosh(sc->eta());
370  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
371  EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
372  double HoE = towerIso.getTowerESum(sc)/sc->energy();
373  if (HoE >= maxHOverE_) continue;
374 
378  isoEtaSlice_,
379  isoEtMin_,
380  isoEMin_,
381  theCaloGeom_,
382  &(*ecalRecHits),
383  sevLevel,
384  DetId::Ecal);
385 
388  if (isBarrel) {
389  ecalIso.doFlagChecks(flagsexclEB_);
390  ecalIso.doSeverityChecks(ecalRecHitHandle.product(), severitiesexclEB_);
391  } else {
392  ecalIso.doFlagChecks(flagsexclEE_);
393  ecalIso.doSeverityChecks(ecalRecHitHandle.product(), severitiesexclEE_);
394  }
395 
396  double ecalIsolation = ecalIso.getEtSum(sc);
397  if ( ecalIsolation > ecalIsoCut_offset_ + ecalIsoCut_slope_*scEt ) continue;
398 
399  // Now launch the seed finding
400  theOutInSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
401  theOutInSeedFinder_->makeSeeds( bcHandle );
402 
403  std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(theOutInSeedFinder_->seeds(), outInTrackCandidates);
404 
405  theInOutSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
406  theInOutSeedFinder_->setTracks( theOutInTracks );
407  theInOutSeedFinder_->makeSeeds( bcHandle);
408 
409  std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(theInOutSeedFinder_->seeds(), inOutTrackCandidates);
410 
411  // Debug
412  // 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";
413 
414 
416  for (std::vector<Trajectory>::const_iterator it = theOutInTracks.begin(); it != theOutInTracks.end(); ++it) {
417  caloPtrVecOutIn_.push_back(aClus);
418  // std::cout << "ConversionTrackCandidateProducer Barrel OutIn Tracks Number of hits " << (*it).foundHits() << "\n";
419  }
420 
421  for (std::vector<Trajectory>::const_iterator it = theInOutTracks.begin(); it != theInOutTracks.end(); ++it) {
422  caloPtrVecInOut_.push_back(aClus);
423  // std::cout << "ConversionTrackCandidateProducer Barrel InOut Tracks Number of hits " << (*it).foundHits() << "\n";
424  }
425  }
426 }
427 
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:124
int i
Definition: DBlmapReader.cc:9
void setTracks(std::vector< Trajectory > const &in)
virtual void endRun(edm::Run const &, edm::EventSetup const &es) overridefinal
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
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:52
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
void setTrajectoryBuilder(const TrajectoryBuilder &builder)
edm::EDGetTokenT< EcalRecHitCollection > endcapecalCollection_
std::vector< edm::Ptr< reco::CaloCluster > > caloPtrVecInOut_
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:161
void doFlagChecks(const std::vector< int > &v)
virtual std::vector< Trajectory > tracks(const TrajectorySeedCollection &seeds, TrackCandidateCollection &candidate) const
void setUseNumCrystals(bool b=true)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::ESHandle< TrajectoryBuilder > theTrajectoryBuilder_
virtual void makeSeeds(const edm::Handle< edm::View< reco::CaloCluster > > &allBc) const
double energy() const
cluster energy
Definition: CaloCluster.h:120
edm::EDGetTokenT< CaloTowerCollection > hcalTowers_
void buildCollections(bool detector, const edm::Handle< edm::View< reco::CaloCluster > > &scHandle, const edm::Handle< edm::View< reco::CaloCluster > > &bcHandle, edm::Handle< EcalRecHitCollection > ecalRecHitHandle, CaloRecHitMetaCollectionV *metaEcalRecHits, 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)
double getTowerESum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
ConversionTrackCandidateProducer(const edm::ParameterSet &ps)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
void doSeverityChecks(const EcalRecHitCollection *const recHits, const std::vector< int > &v)
std::vector< edm::Ptr< reco::CaloCluster > > caloPtrVecOutIn_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scHybridBarrelProducer_
TrajectorySeedCollection & seeds()
virtual std::vector< Trajectory > tracks(const TrajectorySeedCollection &seeds, TrackCandidateCollection &candidates) const
void setEvent(const edm::Event &e)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
virtual void setCandidate(float e, GlobalPoint pos) const
T const * product() const
Definition: Handle.h:81
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcBarrelCollection_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void setVetoClustered(bool b=true)
SimpleCaloRecHitMetaCollection< EcalRecHitCollection > EcalRecHitMetaCollection
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcEndcapCollection_
tuple clone
Definition: statics.py:58
virtual void beginRun(edm::Run const &, edm::EventSetup const &es) overridefinal
edm::EDGetTokenT< EcalRecHitCollection > barrelecalCollection_
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
virtual void makeSeeds(const edm::Handle< edm::View< reco::CaloCluster > > &allBc) const
Definition: Run.h:41