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