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 //
29 
36 
38  conf_(config),
39  theNavigationSchool_(0),
40  theOutInSeedFinder_(0),
41  theOutInTrackFinder_(0),
42  theInOutSeedFinder_(0),
43  theInOutTrackFinder_(0)
44 {
45 
46 
47 
48  //std::cout << "ConversionTrackCandidateProducer CTOR " << "\n";
49  nEvt_=0;
50 
51  // use onfiguration file to setup input/output collection names
52 
53 
54  bcBarrelCollection_ = conf_.getParameter<edm::InputTag>("bcBarrelCollection");
55  bcEndcapCollection_ = conf_.getParameter<edm::InputTag>("bcEndcapCollection");
56 
57  scHybridBarrelProducer_ = conf_.getParameter<edm::InputTag>("scHybridBarrelProducer");
58  scIslandEndcapProducer_ = conf_.getParameter<edm::InputTag>("scIslandEndcapProducer");
59 
60  OutInTrackCandidateCollection_ = conf_.getParameter<std::string>("outInTrackCandidateCollection");
61  InOutTrackCandidateCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateCollection");
62 
63 
64  OutInTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("outInTrackCandidateSCAssociationCollection");
65  InOutTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateSCAssociationCollection");
66 
68  hOverEConeSize_ = conf_.getParameter<double>("hOverEConeSize");
69  maxHOverE_ = conf_.getParameter<double>("maxHOverE");
70  minSCEt_ = conf_.getParameter<double>("minSCEt");
71 
72 
73  // Register the product
74  produces< TrackCandidateCollection > (OutInTrackCandidateCollection_);
75  produces< TrackCandidateCollection > (InOutTrackCandidateCollection_);
76 
77  produces< reco::TrackCandidateCaloClusterPtrAssociation > ( OutInTrackSuperClusterAssociationCollection_);
78  produces< reco::TrackCandidateCaloClusterPtrAssociation > ( InOutTrackSuperClusterAssociationCollection_);
79 
80 
81 }
82 
84 
86 
87 
88  theOutInSeedFinder_->setEventSetup(theEventSetup);
89  theInOutSeedFinder_->setEventSetup(theEventSetup);
90  theOutInTrackFinder_->setEventSetup(theEventSetup);
91  theInOutTrackFinder_->setEventSetup(theEventSetup);
92 
93 }
94 
95 
97 
99  theEventSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
101 
102  // get the Out In Seed Finder
104 
105  // get the Out In Track Finder
106  theOutInTrackFinder_ = new OutInConversionTrackFinder ( theEventSetup, conf_ );
107 
108 
109  // get the In Out Seed Finder
111 
112 
113  // get the In Out Track Finder
114  theInOutTrackFinder_ = new InOutConversionTrackFinder ( theEventSetup, conf_ );
115 
116 
117 }
118 
119 
121  delete theOutInSeedFinder_;
122  delete theOutInTrackFinder_;
123  delete theInOutSeedFinder_;
124  delete theInOutTrackFinder_;
125 }
126 
127 
128 
129 
131 
132  using namespace edm;
133  nEvt_++;
134  // std::cout << "ConversionTrackCandidateProducer Analyzing event number " << theEvent.id() << " Global Counter " << nEvt_ << "\n";
135 
136 
137 
138  setEventSetup( theEventSetup );
139  theOutInSeedFinder_->setEvent(theEvent);
140  theInOutSeedFinder_->setEvent(theEvent);
141  theOutInTrackFinder_->setEvent(theEvent);
142  theInOutTrackFinder_->setEvent(theEvent);
143 
144 // Set the navigation school
146 
147  //
148  // create empty output collections
149  //
150  // Out In Track Candidates
151  std::auto_ptr<TrackCandidateCollection> outInTrackCandidate_p(new TrackCandidateCollection);
152  // In Out Track Candidates
153  std::auto_ptr<TrackCandidateCollection> inOutTrackCandidate_p(new TrackCandidateCollection);
154  // Track Candidate calo Cluster Association
155  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> outInAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
156  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> inOutAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
157 
158  // Get the basic cluster collection in the Barrel
159  bool validBarrelBCHandle=true;
161  theEvent.getByLabel(bcBarrelCollection_, bcBarrelHandle);
162  if (!bcBarrelHandle.isValid()) {
163  edm::LogError("ConversionTrackCandidateProducer") << "Error! Can't get the product "<<bcBarrelCollection_.label();
164  validBarrelBCHandle=false;
165  }
166 
167 
168  // Get the basic cluster collection in the Endcap
169  bool validEndcapBCHandle=true;
171  theEvent.getByLabel(bcEndcapCollection_, bcEndcapHandle);
172  if (!bcEndcapHandle.isValid()) {
173  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<bcEndcapCollection_.label();
174  validEndcapBCHandle=false;
175  }
176 
177 
178 
179  // Get the Super Cluster collection in the Barrel
180  bool validBarrelSCHandle=true;
182  theEvent.getByLabel(scHybridBarrelProducer_,scBarrelHandle);
183  if (!scBarrelHandle.isValid()) {
184  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<scHybridBarrelProducer_.label();
185  validBarrelSCHandle=false;
186  }
187 
188 
189  // Get the Super Cluster collection in the Endcap
190  bool validEndcapSCHandle=true;
192  theEvent.getByLabel(scIslandEndcapProducer_,scEndcapHandle);
193  if (!scEndcapHandle.isValid()) {
194  edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<scIslandEndcapProducer_.label();
195  validEndcapSCHandle=false;
196  }
197 
198 
199  // get the geometry from the event setup:
200  theEventSetup.get<CaloGeometryRecord>().get(theCaloGeom_);
201 
202  // get Hcal towers collection
203  Handle<CaloTowerCollection> hcalTowersHandle;
204  theEvent.getByLabel(hcalTowers_, hcalTowersHandle);
205 
206 
207  caloPtrVecOutIn_.clear();
208  caloPtrVecInOut_.clear();
209 
210  if ( validBarrelBCHandle && validBarrelSCHandle )
211  buildCollections(scBarrelHandle, bcBarrelHandle, hcalTowersHandle, *outInTrackCandidate_p,*inOutTrackCandidate_p,caloPtrVecOutIn_,caloPtrVecInOut_ );
212  if ( validEndcapBCHandle && validEndcapSCHandle )
213  buildCollections(scEndcapHandle, bcEndcapHandle, hcalTowersHandle, *outInTrackCandidate_p,*inOutTrackCandidate_p,caloPtrVecOutIn_,caloPtrVecInOut_ );
214 
215 
216 
217 
218  // std::cout << " ConversionTrackCandidateProducer caloPtrVecOutIn_ size " << caloPtrVecOutIn_.size() << " caloPtrVecInOut_ size " << caloPtrVecInOut_.size() << "\n";
219 
220 
221 
222  // put all products in the event
223  // Barrel
224  //std::cout << "ConversionTrackCandidateProducer Putting in the event " << (*outInTrackCandidate_p).size() << " Out In track Candidates " << "\n";
225  const edm::OrphanHandle<TrackCandidateCollection> refprodOutInTrackC = theEvent.put( outInTrackCandidate_p, OutInTrackCandidateCollection_ );
226  //std::cout << "ConversionTrackCandidateProducer refprodOutInTrackC size " << (*(refprodOutInTrackC.product())).size() << "\n";
227  //
228  //std::cout << "ConversionTrackCandidateProducer Putting in the event " << (*inOutTrackCandidate_p).size() << " In Out track Candidates " << "\n";
229  const edm::OrphanHandle<TrackCandidateCollection> refprodInOutTrackC = theEvent.put( inOutTrackCandidate_p, InOutTrackCandidateCollection_ );
230  //std::cout << "ConversionTrackCandidateProducer refprodInOutTrackC size " << (*(refprodInOutTrackC.product())).size() << "\n";
231 
232 
233  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerOI(*outInAssoc_p);
234  fillerOI.insert(refprodOutInTrackC, caloPtrVecOutIn_.begin(), caloPtrVecOutIn_.end());
235  fillerOI.fill();
236  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerIO(*inOutAssoc_p);
237  fillerIO.insert(refprodInOutTrackC, caloPtrVecInOut_.begin(), caloPtrVecInOut_.end());
238  fillerIO.fill();
239 
240 
241 
242  // std::cout << "ConversionTrackCandidateProducer Putting in the event OutIn track - SC association: size " << (*outInAssoc_p).size() << "\n";
243  theEvent.put( outInAssoc_p, OutInTrackSuperClusterAssociationCollection_);
244 
245  // std::cout << "ConversionTrackCandidateProducer Putting in the event InOut track - SC association: size " << (*inOutAssoc_p).size() << "\n";
246  theEvent.put( inOutAssoc_p, InOutTrackSuperClusterAssociationCollection_);
247 
250 
251 
252 
253 }
254 
255 
257  const edm::Handle<edm::View<reco::CaloCluster> > & bcHandle,
258  const edm::Handle<CaloTowerCollection> & hcalTowersHandle,
259  TrackCandidateCollection& outInTrackCandidates,
260  TrackCandidateCollection& inOutTrackCandidates,
261  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
262  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO )
263 
264 {
265 
266  // std::cout << "ConversionTrackCandidateProducer builcollections bc size " << bcHandle->size() << "\n";
267  //const CaloGeometry* geometry = theCaloGeom_.product();
268 
269  // Loop over SC in the barrel and reconstruct converted photons
270  for (unsigned i = 0; i < scHandle->size(); ++i ) {
271 
272  reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
273 
274  // preselection based in Et and H/E cut.
275  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
276  const reco::CaloCluster* pClus=&(*aClus);
277  const reco::SuperCluster* sc=dynamic_cast<const reco::SuperCluster*>(pClus);
278  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
279  EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
280  double HoE=towerIso.getTowerESum(sc)/sc->energy();
281  if (HoE>=maxHOverE_) continue;
283 
284  theOutInSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
285  theOutInSeedFinder_->makeSeeds( bcHandle );
286 
287  std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(theOutInSeedFinder_->seeds(), outInTrackCandidates);
288 
289 
290  theInOutSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
291  theInOutSeedFinder_->setTracks( theOutInTracks );
292  theInOutSeedFinder_->makeSeeds( bcHandle);
293 
294  std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(theInOutSeedFinder_->seeds(), inOutTrackCandidates);
295 
296 
297  // Debug
298  // 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";
299 
300 
302  for (std::vector<Trajectory>::const_iterator it = theOutInTracks.begin(); it != theOutInTracks.end(); ++it) {
303  caloPtrVecOutIn_.push_back(aClus);
304  // std::cout << "ConversionTrackCandidateProducer Barrel OutIn Tracks Number of hits " << (*it).foundHits() << "\n";
305  }
306 
307  for (std::vector<Trajectory>::const_iterator it = theInOutTracks.begin(); it != theInOutTracks.end(); ++it) {
308  caloPtrVecInOut_.push_back(aClus);
309  // std::cout << "ConversionTrackCandidateProducer Barrel InOut Tracks Number of hits " << (*it).foundHits() << "\n";
310  }
311 
312 
313 
314 
315 
316 
317  }
318 
319 
320 
321 }
322 
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)
double getTowerESum(const reco::Candidate *) 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_
virtual std::vector< Trajectory > tracks(const TrajectorySeedCollection seeds, TrackCandidateCollection &candidate) const
OutInConversionTrackFinder * theOutInTrackFinder_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
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
InOutConversionTrackFinder * theInOutTrackFinder_
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:355
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 buildCollections(const edm::Handle< edm::View< reco::CaloCluster > > &scHandle, const edm::Handle< edm::View< reco::CaloCluster > > &bcHandle, 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 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:32