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
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
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  std::auto_ptr<TrackCandidateCollection> outInTrackCandidate_p(new TrackCandidateCollection);
189  // In Out Track Candidates
190  std::auto_ptr<TrackCandidateCollection> inOutTrackCandidate_p(new TrackCandidateCollection);
191  // Track Candidate calo Cluster Association
192  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> outInAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
193  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> inOutAssoc_p(new 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( 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( 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";
295  theEvent.put( outInAssoc_p, OutInTrackSuperClusterAssociationCollection_);
296 
297  // std::cout << "ConversionTrackCandidateProducer Putting in the event InOut track - SC association: size " << (*inOutAssoc_p).size() << "\n";
298  theEvent.put( inOutAssoc_p, InOutTrackSuperClusterAssociationCollection_);
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 builcollections bc size " << bcHandle->size() << "\n";
325  //const CaloGeometry* geometry = theCaloGeom_.product();
326 
327  // Loop over SC in the barrel and reconstruct converted photons
328  for (unsigned i = 0; i < scHandle->size(); ++i ) {
329 
330  reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
331 
332  // preselection based in Et and H/E cut.
333  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
334  if (aClus->eta() > 1.479 && aClus->eta() < 1.556 ) continue;
335 
336  const reco::CaloCluster* pClus=&(*aClus);
337  const reco::SuperCluster* sc=dynamic_cast<const reco::SuperCluster*>(pClus);
338  double scEt = sc->energy()/cosh(sc->eta());
339  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
340  EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
341  double HoE = towerIso.getTowerESum(sc)/sc->energy();
342  if (HoE >= maxHOverE_) continue;
343 
347  isoEtaSlice_,
348  isoEtMin_,
349  isoEMin_,
350  theCaloGeom_,
351  ecalRecHits,
352  sevLevel,
353  DetId::Ecal);
354 
357  if (isBarrel) {
358  ecalIso.doFlagChecks(flagsexclEB_);
359  ecalIso.doSeverityChecks(ecalRecHitHandle.product(), severitiesexclEB_);
360  } else {
361  ecalIso.doFlagChecks(flagsexclEE_);
362  ecalIso.doSeverityChecks(ecalRecHitHandle.product(), severitiesexclEE_);
363  }
364 
365  double ecalIsolation = ecalIso.getEtSum(sc);
366  if ( ecalIsolation > ecalIsoCut_offset_ + ecalIsoCut_slope_*scEt ) continue;
367 
368  // Now launch the seed finding
369  theOutInSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
370  theOutInSeedFinder_->makeSeeds( bcHandle );
371 
372  std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(theOutInSeedFinder_->seeds(), outInTrackCandidates);
373 
374  theInOutSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
375  theInOutSeedFinder_->setTracks( theOutInTracks );
376  theInOutSeedFinder_->makeSeeds( bcHandle);
377 
378  std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(theInOutSeedFinder_->seeds(), inOutTrackCandidates);
379 
380  // Debug
381  // 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";
382 
383 
385  for (std::vector<Trajectory>::const_iterator it = theOutInTracks.begin(); it != theOutInTracks.end(); ++it) {
386  caloPtrVecOutIn_.push_back(aClus);
387  // std::cout << "ConversionTrackCandidateProducer Barrel OutIn Tracks Number of hits " << (*it).foundHits() << "\n";
388  }
389 
390  for (std::vector<Trajectory>::const_iterator it = theInOutTracks.begin(); it != theInOutTracks.end(); ++it) {
391  caloPtrVecInOut_.push_back(aClus);
392  // std::cout << "ConversionTrackCandidateProducer Barrel InOut Tracks Number of hits " << (*it).foundHits() << "\n";
393  }
394  }
395 }
396 
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:126
std::unique_ptr< OutInConversionSeedFinder > theOutInSeedFinder_
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scIslandEndcapProducer_
double getEtSum(const reco::Candidate *emObject) const
bool isBarrel(GeomDetEnumerators::SubDetector m)
std::vector< TrackCandidate > TrackCandidateCollection
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
edm::EDGetTokenT< EcalRecHitCollection > endcapecalCollection_
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:163
void doFlagChecks(const std::vector< int > &v)
std::unique_ptr< OutInConversionTrackFinder > theOutInTrackFinder_
void setUseNumCrystals(bool b=true)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
double energy() const
cluster energy
Definition: CaloCluster.h:121
edm::EDGetTokenT< CaloTowerCollection > hcalTowers_
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
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
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)
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcEndcapCollection_
std::unique_ptr< InOutConversionTrackFinder > theInOutTrackFinder_
virtual void beginRun(edm::Run const &, edm::EventSetup const &es) overridefinal
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)
virtual void produce(edm::Event &evt, const edm::EventSetup &es) override
edm::EDGetTokenT< EcalRecHitCollection > barrelecalCollection_
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:41