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 
248 
249 
250 
251 }
252 
253 
255  const edm::Handle<edm::View<reco::CaloCluster> > & bcHandle,
256  const edm::Handle<CaloTowerCollection> & hcalTowersHandle,
257  TrackCandidateCollection& outInTrackCandidates,
258  TrackCandidateCollection& inOutTrackCandidates,
259  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
260  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO )
261 
262 {
263 
264  // std::cout << "ConversionTrackCandidateProducer builcollections bc size " << bcHandle->size() << "\n";
265  //const CaloGeometry* geometry = theCaloGeom_.product();
266 
267  // Loop over SC in the barrel and reconstruct converted photons
268  for (unsigned i = 0; i < scHandle->size(); ++i ) {
269 
270  reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
271 
272  // preselection based in Et and H/E cut.
273  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
274  const reco::CaloCluster* pClus=&(*aClus);
275  const reco::SuperCluster* sc=dynamic_cast<const reco::SuperCluster*>(pClus);
276  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
277  EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
278  double HoE=towerIso.getTowerESum(sc)/sc->energy();
279  if (HoE>=maxHOverE_) continue;
281 
282  theOutInSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
283  theOutInSeedFinder_->makeSeeds( bcHandle );
284 
285  std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(theOutInSeedFinder_->seeds(), outInTrackCandidates);
286 
287 
288  theInOutSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
289  theInOutSeedFinder_->setTracks( theOutInTracks );
290  theInOutSeedFinder_->makeSeeds( bcHandle);
291 
292  std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(theInOutSeedFinder_->seeds(), inOutTrackCandidates);
293 
294 
295  // Debug
296  // 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";
297 
298 
300  for (std::vector<Trajectory>::const_iterator it = theOutInTracks.begin(); it != theOutInTracks.end(); ++it) {
301  caloPtrVecOutIn_.push_back(aClus);
302  // std::cout << "ConversionTrackCandidateProducer Barrel OutIn Tracks Number of hits " << (*it).foundHits() << "\n";
303  }
304 
305  for (std::vector<Trajectory>::const_iterator it = theInOutTracks.begin(); it != theInOutTracks.end(); ++it) {
306  caloPtrVecInOut_.push_back(aClus);
307  // std::cout << "ConversionTrackCandidateProducer Barrel InOut Tracks Number of hits " << (*it).foundHits() << "\n";
308  }
309 
310 
311 
312 
313 
314 
315  }
316 
317 
318 
319 }
320 
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:112
int i
Definition: DBlmapReader.cc:9
void setTracks(std::vector< Trajectory > 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:52
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< edm::Ptr< reco::CaloCluster > > caloPtrVecInOut_
TrajectorySeedCollection seeds()
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:109
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:359
std::vector< edm::Ptr< reco::CaloCluster > > caloPtrVecOutIn_
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)
tuple config
Definition: cmsDriver.py:17
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:31