CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaGammaJetProducer.cc
Go to the documentation of this file.
5 
6 using namespace edm;
7 using namespace std;
8 using namespace reco;
9 
10 //namespace cms
11 //{
12 
14 {
15  // Take input
16 
17  tok_hbhe_= consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
18  tok_ho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"));
19  tok_hf_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInput"));
20 
21  mInputCalo = iConfig.getParameter<std::vector<edm::InputTag> >("srcCalo");
22  ecalLabels_=iConfig.getParameter<std::vector<edm::InputTag> >("ecalInputs");
23 
24  unsigned nLabels = mInputCalo.size();
25  for ( unsigned i=0; i != nLabels; i++ )
26  toks_calo_.push_back( consumes<reco::CaloJetCollection>( mInputCalo[i] ) );
27 
28  nLabels = ecalLabels_.size();
29  for ( unsigned i=0; i != nLabels; i++ )
30  toks_ecal_.push_back( consumes<EcalRecHitCollection>( ecalLabels_[i] ) );
31 
32 
33  tok_inputTrack_ = consumes<reco::TrackCollection>(iConfig.getUntrackedParameter<std::string>("inputTrackLabel","generalTracks"));
34  correctedIslandBarrelSuperClusterCollection_ = iConfig.getParameter<std::string>("correctedIslandBarrelSuperClusterCollection");
35  correctedIslandBarrelSuperClusterProducer_ = iConfig.getParameter<std::string>("correctedIslandBarrelSuperClusterProducer");
36  tok_EBSC_ = consumes<reco::SuperClusterCollection>(
37  edm::InputTag(correctedIslandBarrelSuperClusterProducer_,
38  correctedIslandBarrelSuperClusterCollection_));
39 
40  correctedIslandEndcapSuperClusterCollection_ = iConfig.getParameter<std::string>("correctedIslandEndcapSuperClusterCollection");
41  correctedIslandEndcapSuperClusterProducer_ = iConfig.getParameter<std::string>("correctedIslandEndcapSuperClusterProducer");
42  tok_EESC_ = consumes<reco::SuperClusterCollection>(
43  edm::InputTag(correctedIslandEndcapSuperClusterProducer_,
44  correctedIslandEndcapSuperClusterCollection_));
45 
46  allowMissingInputs_=iConfig.getUntrackedParameter<bool>("AllowMissingInputs",true);
47 
48 
49  //register your products
50  produces<reco::TrackCollection>("GammaJetTracksCollection");
51  produces<EcalRecHitCollection>("GammaJetEcalRecHitCollection");
52  produces<HBHERecHitCollection>("GammaJetHBHERecHitCollection");
53  produces<HORecHitCollection>("GammaJetHORecHitCollection");
54  produces<HFRecHitCollection>("GammaJetHFRecHitCollection");
55  produces<CaloJetCollection>("GammaJetJetBackToBackCollection");
56  produces<reco::SuperClusterCollection>("GammaJetGammaBackToBackCollection");
57 
58 
59 
60 }
62 {
63 }
64 
66 {
67 
68 
69 }
70 
71 
72 // ------------ method called to produce the data ------------
73 void
75 {
76  using namespace edm;
77  using namespace std;
78 
80  iSetup.get<CaloGeometryRecord>().get(pG);
81  geo = pG.product();
82 
83 // Produced collections
84 
85  std::auto_ptr<reco::SuperClusterCollection> result (new reco::SuperClusterCollection); //Corrected jets
86  std::auto_ptr<CaloJetCollection> resultjet (new CaloJetCollection); //Corrected jets
87  std::auto_ptr<EcalRecHitCollection> miniEcalRecHitCollection(new EcalRecHitCollection);
88  std::auto_ptr<HBHERecHitCollection> miniHBHERecHitCollection(new HBHERecHitCollection);
89  std::auto_ptr<HORecHitCollection> miniHORecHitCollection(new HORecHitCollection);
90  std::auto_ptr<HFRecHitCollection> miniHFRecHitCollection(new HFRecHitCollection);
91  std::auto_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
92 
93 
94 // Get Corrected supercluster collection
95  int nclusb = 0;
96  int ncluse = 0;
97  reco::SuperClusterCollection::const_iterator maxclusbarrel;
98  reco::SuperClusterCollection::const_iterator maxclusendcap;
99 
100  double vetmax = -100.;
101  Handle<reco::SuperClusterCollection> pCorrectedIslandBarrelSuperClusters;
102  iEvent.getByToken(tok_EBSC_,
103  pCorrectedIslandBarrelSuperClusters);
104  if (!pCorrectedIslandBarrelSuperClusters.isValid()) {
105  // can't find it!
106  if (!allowMissingInputs_) {
107  *pCorrectedIslandBarrelSuperClusters; // will throw the proper exception
108  }
109  } else {
110  const reco::SuperClusterCollection* correctedIslandBarrelSuperClusters = pCorrectedIslandBarrelSuperClusters.product();
111 
112  // loop over the super clusters and find the highest
113  maxclusbarrel = correctedIslandBarrelSuperClusters->begin();
114  for(reco::SuperClusterCollection::const_iterator aClus = correctedIslandBarrelSuperClusters->begin();
115  aClus != correctedIslandBarrelSuperClusters->end(); aClus++) {
116  double vet = aClus->energy()/cosh(aClus->eta());
117  cout<<" Barrel supercluster " << vet <<" energy "<<aClus->energy()<<" eta "<<aClus->eta()<<endl;
118  if(vet>20.) {
119  if(vet > vetmax)
120  {
121  vetmax = vet;
122  maxclusbarrel = aClus;
123  nclusb = 1;
124  }
125  }
126  }
127 
128  }
129 
130  Handle<reco::SuperClusterCollection> pCorrectedIslandEndcapSuperClusters;
131  iEvent.getByToken(tok_EESC_,
132  pCorrectedIslandEndcapSuperClusters);
133  if (!pCorrectedIslandEndcapSuperClusters.isValid()) {
134  // can't find it!
135  if (!allowMissingInputs_) {
136  *pCorrectedIslandEndcapSuperClusters; // will throw the proper exception
137  }
138  } else {
139  const reco::SuperClusterCollection* correctedIslandEndcapSuperClusters = pCorrectedIslandEndcapSuperClusters.product();
140 
141  // loop over the super clusters and find the highest
142  maxclusendcap = correctedIslandEndcapSuperClusters->end();
143  double vetmaxe = vetmax;
144  for(reco::SuperClusterCollection::const_iterator aClus = correctedIslandEndcapSuperClusters->begin();
145  aClus != correctedIslandEndcapSuperClusters->end(); aClus++) {
146  double vet = aClus->energy()/cosh(aClus->eta());
147  // cout<<" Endcap supercluster " << vet <<" energy "<<aClus->energy()<<" eta "<<aClus->eta()<<endl;
148  if(vet>20.) {
149  if(vet > vetmaxe)
150  {
151  vetmaxe = vet;
152  maxclusendcap = aClus;
153  ncluse = 1;
154  }
155  }
156  }
157  }
158 
159  cout<<" Number of gammas "<<nclusb<<" "<<ncluse<<endl;
160 
161  if( nclusb == 0 && ncluse == 0 ) {
162 
163  iEvent.put( outputTColl, "GammaJetTracksCollection");
164  iEvent.put( miniEcalRecHitCollection, "GammaJetEcalRecHitCollection");
165  iEvent.put( miniHBHERecHitCollection, "GammaJetHBHERecHitCollection");
166  iEvent.put( miniHORecHitCollection, "GammaJetHORecHitCollection");
167  iEvent.put( miniHFRecHitCollection, "GammaJetHFRecHitCollection");
168  iEvent.put( result, "GammaJetGammaBackToBackCollection");
169  iEvent.put( resultjet, "GammaJetJetBackToBackCollection");
170 
171  return;
172  }
173 
174  double phigamma = -100.;
175  double etagamma = -100.;
176  if(ncluse == 1)
177  {
178  result->push_back(*maxclusendcap);
179  phigamma = (*maxclusendcap).phi();
180  etagamma = (*maxclusendcap).eta();
181 
182  } else
183  {
184  result->push_back(*maxclusbarrel);
185  phigamma = (*maxclusbarrel).phi();
186  etagamma = (*maxclusbarrel).eta();
187  }
188 
189 // cout<<" Size of egamma clusters "<<result->size()<<endl;
190 
191 //
192 // Jet Collection
193 // Find jet in the angle ~ +- 170 degrees
194 //
195 
196  double phijet = -100.;
197  double etajet = -100.;
198  double phijet0 = -100.;
199  double etajet0 = -100.;
200 
201  std::vector<edm::EDGetTokenT<reco::CaloJetCollection> >::const_iterator ic;
202  for (ic=toks_calo_.begin(); ic!=toks_calo_.end(); ic++) {
203 
205  iEvent.getByToken(*ic, jets);
206  if (!jets.isValid()) {
207  // can't find it!
208  if (!allowMissingInputs_) {
209  *jets; // will throw the proper exception
210  }
211  } else {
212  reco::CaloJetCollection::const_iterator jet = jets->begin ();
213 
214  // cout<<" Size of jets "<<jets->size()<<endl;
215 
216  if( jets->size() == 0 ) continue;
217 
218  int iejet = 0;
219  int numjet = 0;
220 
221  for (; jet != jets->end (); jet++)
222  {
223  phijet0 = (*jet).phi();
224  etajet0 = (*jet).eta();
225 
226 // Only 3 jets are kept
227  numjet++;
228  if(numjet > 3) break;
229 
230  cout<<" phi,eta "<< phigamma<<" "<< etagamma<<" "<<phijet0<<" "<<etajet0<<endl;
231 
232 // Find jet back to gamma
233 
234  double dphi = fabs(phigamma-phijet0);
235  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
236  double deta = fabs(etagamma-etajet0);
237  double dr = sqrt(dphi*dphi+deta*deta);
238  if(dr < 0.5 ) continue;
239  resultjet->push_back ((*jet));
240 
241  dphi = dphi*180./(4.*atan(1.));
242  if( fabs(dphi-180) < 30. )
243  {
244  // cout<<" Jet is found "<<endl;
245  iejet = 1;
246  phijet = (*jet).phi();
247  etajet = (*jet).eta();
248  } // dphi
249  } //jet collection
250  if(iejet == 0) resultjet->clear();
251  }
252  } // Jet collection
253 
254  if( resultjet->size() == 0 ) {
255 
256  iEvent.put( outputTColl, "GammaJetTracksCollection");
257  iEvent.put( miniEcalRecHitCollection, "GammaJetEcalRecHitCollection");
258  iEvent.put( miniHBHERecHitCollection, "GammaJetHBHERecHitCollection");
259  iEvent.put( miniHORecHitCollection, "GammaJetHORecHitCollection");
260  iEvent.put( miniHFRecHitCollection, "GammaJetHFRecHitCollection");
261  iEvent.put( result, "GammaJetGammaBackToBackCollection");
262  iEvent.put( resultjet, "GammaJetJetBackToBackCollection");
263 
264  return;
265  }
266  // cout<<" Accepted event "<<resultjet->size()<<" PHI gamma "<<phigamma<<std::endl;
267 //
268 // Add Ecal, Hcal RecHits around Egamma caluster
269 //
270 
271 // Load EcalRecHits
272 
273 
274  std::vector<edm::EDGetTokenT<EcalRecHitCollection> >::const_iterator i;
275  for (i=toks_ecal_.begin(); i!=toks_ecal_.end(); i++) {
277  iEvent.getByToken(*i,ec);
278  if (!ec.isValid()) {
279  // can't find it!
280  if (!allowMissingInputs_) {
281  cout<<" No ECAL input "<<endl;
282  *ec; // will throw the proper exception
283  }
284  } else {
285  for(EcalRecHitCollection::const_iterator recHit = (*ec).begin();
286  recHit != (*ec).end(); ++recHit)
287  {
288 // EcalBarrel = 1, EcalEndcap = 2
289  GlobalPoint pos = geo->getPosition(recHit->detid());
290  double phihit = pos.phi();
291  double etahit = pos.eta();
292 
293  double dphi = fabs(phigamma - phihit);
294  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
295  double deta = fabs(etagamma - etahit);
296  double dr = sqrt(dphi*dphi + deta*deta);
297  if(dr<1.) miniEcalRecHitCollection->push_back(*recHit);
298 
299  dphi = fabs(phijet - phihit);
300  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
301  deta = fabs(etajet - etahit);
302  dr = sqrt(dphi*dphi + deta*deta);
303  if(dr<1.4) miniEcalRecHitCollection->push_back(*recHit);
304 
305  }
306  }
307  }
308 
309 // cout<<" Ecal is done "<<endl;
310 
312  iEvent.getByToken(tok_hbhe_,hbhe);
313  if (!hbhe.isValid()) {
314  // can't find it!
315  if (!allowMissingInputs_) {
316  *hbhe; // will throw the proper exception
317  }
318  } else {
319  const HBHERecHitCollection Hithbhe = *(hbhe.product());
320  for(HBHERecHitCollection::const_iterator hbheItr=Hithbhe.begin(); hbheItr!=Hithbhe.end(); hbheItr++)
321  {
322  GlobalPoint pos = geo->getPosition(hbheItr->detid());
323  double phihit = pos.phi();
324  double etahit = pos.eta();
325 
326  double dphi = fabs(phigamma - phihit);
327  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
328  double deta = fabs(etagamma - etahit);
329  double dr = sqrt(dphi*dphi + deta*deta);
330 
331 
332  if(dr<1.) miniHBHERecHitCollection->push_back(*hbheItr);
333  dphi = fabs(phijet - phihit);
334  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
335  deta = fabs(etajet - etahit);
336  dr = sqrt(dphi*dphi + deta*deta);
337  if(dr<1.4) miniHBHERecHitCollection->push_back(*hbheItr);
338  }
339  }
340 
341 // cout<<" HBHE is done "<<endl;
342 
344  iEvent.getByToken(tok_ho_,ho);
345  if (!ho.isValid()) {
346  // can't find it!
347  if (!allowMissingInputs_) {
348  *ho; // will throw the proper exception
349  }
350  } else {
351  const HORecHitCollection Hitho = *(ho.product());
352  for(HORecHitCollection::const_iterator hoItr=Hitho.begin(); hoItr!=Hitho.end(); hoItr++)
353  {
354  GlobalPoint pos = geo->getPosition(hoItr->detid());
355  double phihit = pos.phi();
356  double etahit = pos.eta();
357 
358  double dphi = fabs(phigamma - phihit);
359  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
360  double deta = fabs(etagamma - etahit);
361  double dr = sqrt(dphi*dphi + deta*deta);
362 
363  if(dr<1.) miniHORecHitCollection->push_back(*hoItr);
364  dphi = fabs(phijet - phihit);
365  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
366  deta = fabs(etajet - etahit);
367  dr = sqrt(dphi*dphi + deta*deta);
368  if(dr<1.4) miniHORecHitCollection->push_back(*hoItr);
369 
370  }
371  }
372 
373  // cout<<" HO is done "<<endl;
374 
376  iEvent.getByToken(tok_hf_,hf);
377  if (!hf.isValid()) {
378  // can't find it!
379  if (!allowMissingInputs_) {
380  *hf; // will throw the proper exception
381  }
382  } else {
383  const HFRecHitCollection Hithf = *(hf.product());
384  // cout<<" Size of HF collection "<<Hithf.size()<<endl;
385  for(HFRecHitCollection::const_iterator hfItr=Hithf.begin(); hfItr!=Hithf.end(); hfItr++)
386  {
387  GlobalPoint pos = geo->getPosition(hfItr->detid());
388 
389  double phihit = pos.phi();
390  double etahit = pos.eta();
391 
392  double dphi = fabs(phigamma - phihit);
393  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
394  double deta = fabs(etagamma - etahit);
395  double dr = sqrt(dphi*dphi + deta*deta);
396 
397  if(dr<1.) miniHFRecHitCollection->push_back(*hfItr);
398  dphi = fabs(phijet - phihit);
399  if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
400  deta = fabs(etajet - etahit);
401  dr = sqrt(dphi*dphi + deta*deta);
402 
403  if( dr < 1.4 ) miniHFRecHitCollection->push_back(*hfItr);
404  }
405  }
406 
407  // cout<<" Size of mini HF collection "<<miniHFRecHitCollection->size()<<endl;
408 
409 
410 // Track Collection
411  edm::Handle<reco::TrackCollection> trackCollection;
412  iEvent.getByToken(tok_inputTrack_,trackCollection);
413  if (!trackCollection.isValid()) {
414  // can't find it!
415  if (!allowMissingInputs_) {
416  *trackCollection; // will throw the proper exception
417  }
418  } else {
419  const reco::TrackCollection tC = *(trackCollection.product());
420 
421  //Create empty output collections
422 
423 
424  for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++)
425  {
426 
427  double deta = track->momentum().eta() - etagamma;
428 
429  double dphi = fabs(track->momentum().phi() - phigamma);
430 
431  if (dphi > atan(1.)*4.) dphi = 8.*atan(1.) - dphi;
432  double ddir1 = sqrt(deta*deta+dphi*dphi);
433 
434 
435 
436  deta = track->momentum().eta() - etajet;
437  dphi = fabs(track->momentum().phi() - phijet);
438  if (dphi > atan(1.)*4.) dphi = 8.*atan(1.) - dphi;
439  double ddir2 = sqrt(deta*deta+dphi*dphi);
440 
441  if( ddir1 < 1.4 || ddir2 < 1.4)
442  {
443  outputTColl->push_back(*track);
444  }
445  }
446  }
447 
448  //Put selected information in the event
449 
450  iEvent.put( outputTColl, "GammaJetTracksCollection");
451  iEvent.put( miniEcalRecHitCollection, "GammaJetEcalRecHitCollection");
452  iEvent.put( miniHBHERecHitCollection, "GammaJetHBHERecHitCollection");
453  iEvent.put( miniHORecHitCollection, "GammaJetHORecHitCollection");
454  iEvent.put( miniHFRecHitCollection, "GammaJetHFRecHitCollection");
455  iEvent.put( result, "GammaJetGammaBackToBackCollection");
456  iEvent.put( resultjet, "GammaJetJetBackToBackCollection");
457 }
458 //}
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
virtual void produce(edm::Event &, const edm::EventSetup &)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
std::vector< EcalRecHit >::const_iterator const_iterator
int iEvent
Definition: GenABIO.cc:230
AlCaGammaJetProducer(const edm::ParameterSet &)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
T sqrt(T t)
Definition: SSEVec.h:48
vector< PseudoJet > jets
tuple result
Definition: query.py:137
bool isValid() const
Definition: HandleBase.h:76
const_iterator end() const
const T & get() const
Definition: EventSetup.h:55
T eta() const
Definition: PV3DBase.h:76
tuple cout
Definition: gather_cfg.py:121
const_iterator begin() const
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects