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 
44 
46  conf_(config),
47  theNavigationSchool_(0),
48  theOutInSeedFinder_(0),
49  theOutInTrackFinder_(0),
50  theInOutSeedFinder_(0),
51  theInOutTrackFinder_(0)
52 {
53  //std::cout << "ConversionTrackCandidateProducer CTOR " << "\n";
54  nEvt_=0;
55 
56  // use onfiguration file to setup input/output collection names
57 
58 
59  bcBarrelCollection_ = conf_.getParameter<edm::InputTag>("bcBarrelCollection");
60  bcEndcapCollection_ = conf_.getParameter<edm::InputTag>("bcEndcapCollection");
61 
62  scHybridBarrelProducer_ = conf_.getParameter<edm::InputTag>("scHybridBarrelProducer");
63  scIslandEndcapProducer_ = conf_.getParameter<edm::InputTag>("scIslandEndcapProducer");
64 
65  OutInTrackCandidateCollection_ = conf_.getParameter<std::string>("outInTrackCandidateCollection");
66  InOutTrackCandidateCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateCollection");
67 
68 
69  OutInTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("outInTrackCandidateSCAssociationCollection");
70  InOutTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateSCAssociationCollection");
71 
72  barrelecalCollection_ = conf_.getParameter<edm::InputTag>("barrelEcalRecHitCollection");
73  endcapecalCollection_ = conf_.getParameter<edm::InputTag>("endcapEcalRecHitCollection");
74 
76  hOverEConeSize_ = conf_.getParameter<double>("hOverEConeSize");
77  maxHOverE_ = conf_.getParameter<double>("maxHOverE");
78  minSCEt_ = conf_.getParameter<double>("minSCEt");
79  isoConeR_ = conf_.getParameter<double>("isoConeR");
80  isoInnerConeR_ = conf_.getParameter<double>("isoInnerConeR");
81  isoEtaSlice_ = conf_.getParameter<double>("isoEtaSlice");
82  isoEtMin_ = conf_.getParameter<double>("isoEtMin");
83  isoEMin_ = conf_.getParameter<double>("isoEMin");
84  vetoClusteredHits_ = conf_.getParameter<bool>("vetoClusteredHits");
85  useNumXtals_ = conf_.getParameter<bool>("useNumXstals");
86  ecalIsoCut_offset_ = conf_.getParameter<double>("ecalIsoCut_offset");
87  ecalIsoCut_slope_ = conf_.getParameter<double>("ecalIsoCut_slope");
88 
89  //Flags and Severities to be excluded from photon calculations
90  const std::vector<std::string> flagnamesEB =
91  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
92 
93  const std::vector<std::string> flagnamesEE =
94  config.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
95 
96  flagsexclEB_=
97  StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
98 
100  StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
101 
102  const std::vector<std::string> severitynamesEB =
103  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
104 
106  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
107 
108  const std::vector<std::string> severitynamesEE =
109  config.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
110 
112  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
113 
114 
115  // Register the product
116  produces< TrackCandidateCollection > (OutInTrackCandidateCollection_);
117  produces< TrackCandidateCollection > (InOutTrackCandidateCollection_);
118 
119  produces< reco::TrackCandidateCaloClusterPtrAssociation > ( OutInTrackSuperClusterAssociationCollection_);
120  produces< reco::TrackCandidateCaloClusterPtrAssociation > ( InOutTrackSuperClusterAssociationCollection_);
121 
122 
123 }
124 
126 
128 
129 
130  theOutInSeedFinder_->setEventSetup(theEventSetup);
131  theInOutSeedFinder_->setEventSetup(theEventSetup);
132  theOutInTrackFinder_->setEventSetup(theEventSetup);
133  theInOutTrackFinder_->setEventSetup(theEventSetup);
134 
135 
136 }
137 
138 
140 
142  theEventSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
144 
145  // get the Out In Seed Finder
147 
148  // get the Out In Track Finder
149  theOutInTrackFinder_ = new OutInConversionTrackFinder ( theEventSetup, conf_ );
150 
151 
152  // get the In Out Seed Finder
154 
155 
156  // get the In Out Track Finder
157  theInOutTrackFinder_ = new InOutConversionTrackFinder ( theEventSetup, conf_ );
158 }
159 
160 
162  delete theOutInSeedFinder_;
163  delete theOutInTrackFinder_;
164  delete theInOutSeedFinder_;
165  delete theInOutTrackFinder_;
166 }
167 
168 
169 
170 
172 
173  using namespace edm;
174  nEvt_++;
175  // std::cout << "ConversionTrackCandidateProducer Analyzing event number " << theEvent.id() << " Global Counter " << nEvt_ << "\n";
176 
177 
178 
179  setEventSetup( theEventSetup );
180  theOutInSeedFinder_->setEvent(theEvent);
181  theInOutSeedFinder_->setEvent(theEvent);
182  theOutInTrackFinder_->setEvent(theEvent);
183  theInOutTrackFinder_->setEvent(theEvent);
184 
185 // Set the navigation school
187 
188  //
189  // create empty output collections
190  //
191  // Out In Track Candidates
192  std::auto_ptr<TrackCandidateCollection> outInTrackCandidate_p(new TrackCandidateCollection);
193  // In Out Track Candidates
194  std::auto_ptr<TrackCandidateCollection> inOutTrackCandidate_p(new TrackCandidateCollection);
195  // Track Candidate calo Cluster Association
196  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> outInAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
197  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> inOutAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
198 
199  // Get the basic cluster collection in the Barrel
200  bool validBarrelBCHandle=true;
202  theEvent.getByLabel(bcBarrelCollection_, bcBarrelHandle);
203  if (!bcBarrelHandle.isValid()) {
204  edm::LogError("ConversionTrackCandidateProducer") << "Error! Can't get the product "<<bcBarrelCollection_.label();
205  validBarrelBCHandle=false;
206  }
207 
208 
209  // Get the basic cluster collection in the Endcap
210  bool validEndcapBCHandle=true;
212  theEvent.getByLabel(bcEndcapCollection_, bcEndcapHandle);
213  if (!bcEndcapHandle.isValid()) {
214  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<bcEndcapCollection_.label();
215  validEndcapBCHandle=false;
216  }
217 
218 
219 
220  // Get the Super Cluster collection in the Barrel
221  bool validBarrelSCHandle=true;
223  theEvent.getByLabel(scHybridBarrelProducer_,scBarrelHandle);
224  if (!scBarrelHandle.isValid()) {
225  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<scHybridBarrelProducer_.label();
226  validBarrelSCHandle=false;
227  }
228 
229 
230  // Get the Super Cluster collection in the Endcap
231  bool validEndcapSCHandle=true;
233  theEvent.getByLabel(scIslandEndcapProducer_,scEndcapHandle);
234  if (!scEndcapHandle.isValid()) {
235  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<scIslandEndcapProducer_.label();
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.getByLabel(hcalTowers_, hcalTowersHandle);
246 
247  edm::Handle<EcalRecHitCollection> ecalhitsCollEB;
248  edm::Handle<EcalRecHitCollection> ecalhitsCollEE;
249 
250  theEvent.getByLabel(endcapecalCollection_, ecalhitsCollEE);
251  theEvent.getByLabel(barrelecalCollection_, ecalhitsCollEB);
252 
254  theEventSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
255  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
256 
257  std::auto_ptr<CaloRecHitMetaCollectionV> RecHitsEE(0);
258  RecHitsEE = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(ecalhitsCollEE.product()));
259 
260  std::auto_ptr<CaloRecHitMetaCollectionV> RecHitsEB(0);
261  RecHitsEB = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(ecalhitsCollEB.product()));
262 
263 
264  caloPtrVecOutIn_.clear();
265  caloPtrVecInOut_.clear();
266 
267  bool isBarrel=true;
268  if ( validBarrelBCHandle && validBarrelSCHandle )
269  buildCollections(isBarrel, scBarrelHandle, bcBarrelHandle, ecalhitsCollEB, &(*RecHitsEB), sevLevel, hcalTowersHandle, *outInTrackCandidate_p, *inOutTrackCandidate_p, caloPtrVecOutIn_, caloPtrVecInOut_);
270 
271  if ( validEndcapBCHandle && validEndcapSCHandle ) {
272  isBarrel=false;
273  buildCollections(isBarrel, scEndcapHandle, bcEndcapHandle, ecalhitsCollEE, &(*RecHitsEE), sevLevel, hcalTowersHandle, *outInTrackCandidate_p, *inOutTrackCandidate_p, caloPtrVecOutIn_, caloPtrVecInOut_);
274  }
275 
276 
277  // std::cout << " ConversionTrackCandidateProducer caloPtrVecOutIn_ size " << caloPtrVecOutIn_.size() << " caloPtrVecInOut_ size " << caloPtrVecInOut_.size() << "\n";
278 
279 
280 
281  // put all products in the event
282  // Barrel
283  //std::cout << "ConversionTrackCandidateProducer Putting in the event " << (*outInTrackCandidate_p).size() << " Out In track Candidates " << "\n";
284  const edm::OrphanHandle<TrackCandidateCollection> refprodOutInTrackC = theEvent.put( outInTrackCandidate_p, OutInTrackCandidateCollection_ );
285  //std::cout << "ConversionTrackCandidateProducer refprodOutInTrackC size " << (*(refprodOutInTrackC.product())).size() << "\n";
286  //
287  //std::cout << "ConversionTrackCandidateProducer Putting in the event " << (*inOutTrackCandidate_p).size() << " In Out track Candidates " << "\n";
288  const edm::OrphanHandle<TrackCandidateCollection> refprodInOutTrackC = theEvent.put( inOutTrackCandidate_p, InOutTrackCandidateCollection_ );
289  //std::cout << "ConversionTrackCandidateProducer refprodInOutTrackC size " << (*(refprodInOutTrackC.product())).size() << "\n";
290 
291 
292  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerOI(*outInAssoc_p);
293  fillerOI.insert(refprodOutInTrackC, caloPtrVecOutIn_.begin(), caloPtrVecOutIn_.end());
294  fillerOI.fill();
295  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerIO(*inOutAssoc_p);
296  fillerIO.insert(refprodInOutTrackC, caloPtrVecInOut_.begin(), caloPtrVecInOut_.end());
297  fillerIO.fill();
298 
299 
300 
301  // std::cout << "ConversionTrackCandidateProducer Putting in the event OutIn track - SC association: size " << (*outInAssoc_p).size() << "\n";
302  theEvent.put( outInAssoc_p, OutInTrackSuperClusterAssociationCollection_);
303 
304  // std::cout << "ConversionTrackCandidateProducer Putting in the event InOut track - SC association: size " << (*inOutAssoc_p).size() << "\n";
305  theEvent.put( inOutAssoc_p, InOutTrackSuperClusterAssociationCollection_);
306 
309 
310 
311 
312 }
313 
314 
316  const edm::Handle<edm::View<reco::CaloCluster> > & scHandle,
317  const edm::Handle<edm::View<reco::CaloCluster> > & bcHandle,
318  edm::Handle<EcalRecHitCollection> ecalRecHitHandle,
319  CaloRecHitMetaCollectionV* ecalRecHits,
320  const EcalSeverityLevelAlgo* sevLevel,
321  //edm::ESHandle<EcalChannelStatus> chStatus,
322  //const EcalChannelStatus* chStatus,
323  const edm::Handle<CaloTowerCollection> & hcalTowersHandle,
324  TrackCandidateCollection& outInTrackCandidates,
325  TrackCandidateCollection& inOutTrackCandidates,
326  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
327  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO )
328 
329 {
330 
331  // std::cout << "ConversionTrackCandidateProducer builcollections bc size " << bcHandle->size() << "\n";
332  //const CaloGeometry* geometry = theCaloGeom_.product();
333 
334  // Loop over SC in the barrel and reconstruct converted photons
335  for (unsigned i = 0; i < scHandle->size(); ++i ) {
336 
337  reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
338 
339  // preselection based in Et and H/E cut.
340  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
341  const reco::CaloCluster* pClus=&(*aClus);
342  const reco::SuperCluster* sc=dynamic_cast<const reco::SuperCluster*>(pClus);
343  double scEt = sc->energy()/cosh(sc->eta());
344  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
345  EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
346  double HoE = towerIso.getTowerESum(sc)/sc->energy();
347  if (HoE >= maxHOverE_) continue;
348 
352  isoEtaSlice_,
353  isoEtMin_,
354  isoEMin_,
355  theCaloGeom_,
356  &(*ecalRecHits),
357  sevLevel,
358  DetId::Ecal);
359 
362  if (isBarrel) {
363  ecalIso.doFlagChecks(flagsexclEB_);
364  ecalIso.doSeverityChecks(ecalRecHitHandle.product(), severitiesexclEB_);
365  } else {
366  ecalIso.doFlagChecks(flagsexclEE_);
367  ecalIso.doSeverityChecks(ecalRecHitHandle.product(), severitiesexclEE_);
368  }
369 
370  double ecalIsolation = ecalIso.getEtSum(sc);
371  if ( ecalIsolation > ecalIsoCut_offset_ + ecalIsoCut_slope_*scEt ) continue;
372 
373  // Now launch the seed finding
374  theOutInSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
375  theOutInSeedFinder_->makeSeeds( bcHandle );
376 
377  std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(theOutInSeedFinder_->seeds(), outInTrackCandidates);
378 
379  theInOutSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
380  theInOutSeedFinder_->setTracks( theOutInTracks );
381  theInOutSeedFinder_->makeSeeds( bcHandle);
382 
383  std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(theInOutSeedFinder_->seeds(), inOutTrackCandidates);
384 
385  // Debug
386  // 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";
387 
388 
390  for (std::vector<Trajectory>::const_iterator it = theOutInTracks.begin(); it != theOutInTracks.end(); ++it) {
391  caloPtrVecOutIn_.push_back(aClus);
392  // std::cout << "ConversionTrackCandidateProducer Barrel OutIn Tracks Number of hits " << (*it).foundHits() << "\n";
393  }
394 
395  for (std::vector<Trajectory>::const_iterator it = theInOutTracks.begin(); it != theInOutTracks.end(); ++it) {
396  caloPtrVecInOut_.push_back(aClus);
397  // std::cout << "ConversionTrackCandidateProducer Barrel InOut Tracks Number of hits " << (*it).foundHits() << "\n";
398  }
399  }
400 }
401 
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:123
int i
Definition: DBlmapReader.cc:9
void setTracks(std::vector< Trajectory > const &in)
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
void doSeverityChecks(const EcalRecHitCollection *const recHits, const std::vector< int > v)
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
std::vector< edm::Ptr< reco::CaloCluster > > caloPtrVecInOut_
void doFlagChecks(const std::vector< int > v)
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:160
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:85
void setEvent(const edm::Event &e)
virtual void makeSeeds(const edm::Handle< edm::View< reco::CaloCluster > > &allBc) const
double energy() const
cluster energy
Definition: CaloCluster.h:120
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)
virtual void endRun(edm::Run &, edm::EventSetup const &es)
ConversionTrackCandidateProducer(const edm::ParameterSet &ps)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
double getTowerESum(const reco::Candidate *, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
std::vector< edm::Ptr< reco::CaloCluster > > caloPtrVecOutIn_
TrajectorySeedCollection & seeds()
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:74
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
std::string const & label() const
Definition: InputTag.h:25
virtual std::vector< Trajectory > tracks(const TrajectorySeedCollection seeds, TrackCandidateCollection &candidates) const
void setVetoClustered(bool b=true)
SimpleCaloRecHitMetaCollection< EcalRecHitCollection > EcalRecHitMetaCollection
virtual void beginRun(edm::Run &, edm::EventSetup const &es)
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:33