CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GammaJetAnalysis.cc
Go to the documentation of this file.
1 // user include files
2 #include "GammaJetAnalysis.h"
3 
7 /* #include "FWCore/Framework/interface/MakerMacros.h" */
10 
13 
24 //#include "DataFormats/JetReco/interface/GenJetfwd.h"
27 
32 
35 #include "HepMC/GenParticle.h"
36 #include "HepMC/GenVertex.h"
37 #include "TFile.h"
38 #include "TTree.h"
39 
40 
41 using namespace std;
42 namespace cms
43 {
44 GammaJetAnalysis::GammaJetAnalysis(const edm::ParameterSet& iConfig)
45 {
46  // get names of modules, producing object collections
47 
48  nameProd_ = iConfig.getUntrackedParameter<std::string>("nameProd");
49  jetCalo_ = iConfig.getUntrackedParameter<std::string>("jetCalo","GammaJetJetBackToBackCollection");
50  gammaClus_ = iConfig.getUntrackedParameter<std::string>("gammaClus","GammaJetGammaBackToBackCollection");
51  ecalInput_=iConfig.getUntrackedParameter<std::string>("ecalInput","GammaJetEcalRecHitCollection");
52  hbheInput_ = iConfig.getUntrackedParameter<std::string>("hbheInput");
53  hoInput_ = iConfig.getUntrackedParameter<std::string>("hoInput");
54  hfInput_ = iConfig.getUntrackedParameter<std::string>("hfInput");
55  Tracks_ = iConfig.getUntrackedParameter<std::string>("Tracks","GammaJetTracksCollection");
56  CutOnEgammaEnergy_ = iConfig.getParameter<double>("CutOnEgammaEnergy");
57 
58  myName = iConfig.getParameter<std::string> ("textout");
59  useMC = iConfig.getParameter<bool>("useMCInfo");
60  allowMissingInputs_=iConfig.getUntrackedParameter<bool>("AllowMissingInputs",false);
61  // get name of output file with histogramms
62  fOutputFileName = iConfig.getUntrackedParameter<string>("HistOutFile");
63  risol[0] = 0.5;
64  risol[1] = 0.7;
65  risol[2] = 1.0;
66 
67  ecut[0][0] = 0.09;
68  ecut[0][1] = 0.18;
69  ecut[0][2] = 0.27;
70 
71  ecut[1][0] = 0.45;
72  ecut[1][1] = 0.9;
73  ecut[1][2] = 1.35;
74 
75  ecut[2][0] = 0.5;
76  ecut[2][1] = 1.;
77  ecut[2][2] = 1.5;
78 }
79 
80 
81 GammaJetAnalysis::~GammaJetAnalysis()
82 {
83 
84  // do anything here that needs to be done at desctruction time
85  // (e.g. close files, deallocate resources etc.)
86 
87 }
88 
90 {
91  hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
92  myTree = new TTree("GammaJet","GammaJet Tree");
93  myTree->Branch("run", &run, "run/I");
94  myTree->Branch("event", &event, "event/I");
95 
96  NumRecoJets = 0;
97  NumGenJets = 0;
98  NumRecoGamma = 0;
99  NumRecoTrack = 0;
100  NumPart = 0;
101 // Jet block
102  myTree->Branch("NumRecoJets", &NumRecoJets, "NumRecoJets/I");
103  myTree->Branch("JetRecoEt", JetRecoEt, "JetRecoEt[10]/F");
104  myTree->Branch("JetRecoEta", JetRecoEta, "JetRecoEta[10]/F");
105  myTree->Branch("JetRecoPhi", JetRecoPhi, "JetRecoPhi[10]/F");
106  myTree->Branch("JetRecoType", JetRecoType, "JetRecoType[10]/F");
107 
108 // Gamma block for ECAL isolated gammas
109  myTree->Branch("NumRecoGamma", &NumRecoGamma, "NumRecoGamma/I");
110  myTree->Branch("EcalClusDet", &EcalClusDet, "EcalClusDet[20]/I");
111  myTree->Branch("GammaRecoEt", GammaRecoEt, "GammaRecoEt[20]/F");
112  myTree->Branch("GammaRecoEta", GammaRecoEta, "GammaRecoEta[20]/F");
113  myTree->Branch("GammaRecoPhi", GammaRecoPhi, "GammaRecoPhi[20]/F");
114  myTree->Branch("GammaIsoEcal", GammaIsoEcal, "GammaIsoEcal[9][20]/F");
115 
116 // Tracks block
117  myTree->Branch("NumRecoTrack", &NumRecoTrack, "NumRecoTrack/I");
118  myTree->Branch("TrackRecoEt", TrackRecoEt, "TrackRecoEt[200]/F");
119  myTree->Branch("TrackRecoEta", TrackRecoEta, "TrackRecoEta[200]/F");
120  myTree->Branch("TrackRecoPhi", TrackRecoPhi, "TrackRecoPhi[200]/F");
121 
122 // end of tree declaration
123 
124 // edm::ESHandle<CaloGeometry> pG;
125 // iSetup.get<CaloGeometryRecord>().get(pG);
126 // geo = pG.product();
127 
128  myout_part = new ofstream((myName+"_part.dat").c_str());
129  if(!myout_part) cout << " Output file not open!!! "<<endl;
130  myout_hcal = new ofstream((myName+"_hcal.dat").c_str());
131  if(!myout_hcal) cout << " Output file not open!!! "<<endl;
132  myout_ecal = new ofstream((myName+"_ecal.dat").c_str());
133  if(!myout_ecal) cout << " Output file not open!!! "<<endl;
134 
135  myout_jet = new ofstream((myName+"_jet.dat").c_str());
136  if(!myout_jet) cout << " Output file not open!!! "<<endl;
137  myout_photon = new ofstream((myName+"_photon.dat").c_str());
138  if(!myout_photon) cout << " Output file not open!!! "<<endl;
139 
140 
141 }
142 
143 void GammaJetAnalysis::endJob()
144 {
145 
146  cout << "===== Start writing user histograms =====" << endl;
147  hOutputFile->SetCompressionLevel(2);
148  hOutputFile->cd();
149  myTree->Write();
150  hOutputFile->Close() ;
151  cout << "===== End writing user histograms =======" << endl;
152 }
153 
154 
155 //
156 // member functions
157 //
158 
159 // ------------ method called to produce the data ------------
160 void
162 {
163 
165  iSetup.get<CaloGeometryRecord>().get(pG);
166  geo = pG.product();
167 
168 
169  using namespace edm;
170  std::vector<Provenance const*> theProvenance;
171  iEvent.getAllProvenance(theProvenance);
172 // for( std::vector<Provenance const*>::const_iterator ip = theProvenance.begin();
173 // ip != theProvenance.end(); ip++)
174 // {
175 // cout<<" Print all module/label names "<<(**ip).moduleName()<<" "<<(**ip).moduleLabel()<<
176 // " "<<(**ip).productInstanceName()<<endl;
177 // }
178 // Load generator information
179 // write HEPEVT block into file
180  run = iEvent.id().run();
181  event = iEvent.id().event();
182  (*myout_part)<<"Event "<<iEvent.id().run()<<" "<<iEvent.id().event()<<endl;
183  (*myout_jet)<<"Event "<<iEvent.id().run()<<" "<<iEvent.id().event()<<endl;
184  (*myout_hcal)<<"Event "<<iEvent.id().run()<<" "<<iEvent.id().event()<<endl;
185  (*myout_ecal)<<"Event "<<iEvent.id().run()<<" "<<iEvent.id().event()<<endl;
186  (*myout_photon)<<"Event "<<iEvent.id().run()<<" "<<iEvent.id().event()<<endl;
187 
188 
189  std::vector<edm::InputTag>::const_iterator ic;
190  int jettype = 0;
191  int jetexist = -100;
192  int reco = 1;
193  double etlost = -100.1;
194 
195  NumRecoJets = 0;
196 
197  try {
198 
200  iEvent.getByLabel(nameProd_, jetCalo_, jets);
201  reco::CaloJetCollection::const_iterator jet = jets->begin ();
202  cout<<" Size of Calo jets "<<jets->size()<<endl;
203  jettype++;
204 
205  if(jets->size() > 0 )
206  {
207  int ij = 0;
208  for (; jet != jets->end (); jet++)
209  {
210  cout<<" Jet et "<<(*jet).et()<<" "<<(*jet).eta()<<" "<<(*jet).phi()<<endl;
211  ij++;
212  if(ij<4) (*myout_jet)<<jettype<<" "<<reco<<" "<<ij<<" "<<(*jet).et()<<" "<<(*jet).eta()<<" "<<(*jet).phi()
213  <<" "<<iEvent.id().event()<<endl;
214  jetexist = ij;
215  if( NumRecoJets < 8 )
216  {
217  JetRecoEt[NumRecoJets] = (*jet).et();
218  JetRecoEta[NumRecoJets] = (*jet).eta();
219  JetRecoPhi[NumRecoJets] = (*jet).phi();
220  JetRecoType[NumRecoJets] = jettype;
221  NumRecoJets++;
222  }
223  }
224  }
225  } catch (cms::Exception& e) { // can't find it!
226  if (!allowMissingInputs_) {
227  cout<< " Calojets are missed "<<endl;
228  throw e;
229  }
230  }
231 
232  cout<<" We filled CaloJet part "<<jetexist<<endl;
233 
234  if( jetexist < 0 ) (*myout_jet)<<jetexist<<" "<<reco<<" "<<etlost
235  <<" "<<etlost<<" "<<etlost
236  <<" "<<iEvent.id().event()<<endl;
237 // Load EcalRecHits
238 
239  std::vector<edm::InputTag>::const_iterator i;
240  vector<CaloRecHit> theRecHits;
241 
242  try {
243 
245  iEvent.getByLabel(nameProd_, ecalInput_,ec);
246 
247  for(EcalRecHitCollection::const_iterator recHit = (*ec).begin();
248  recHit != (*ec).end(); ++recHit)
249  {
250 // EcalBarrel = 1, EcalEndcap = 2
251 
252  GlobalPoint pos = geo->getPosition(recHit->detid());
253  theRecHits.push_back(*recHit);
254 
255  if( (*recHit).energy()> ecut[recHit->detid().subdetId()-1][0] )
256  (*myout_ecal)<<recHit->detid().subdetId()<<" "<<(*recHit).energy()<<" "<<pos.phi()<<" "<<pos.eta()
257  <<" "<<iEvent.id().event()<<endl;
258 
259  }
260 
261  } catch (cms::Exception& e) { // can't find it!
262  if (!allowMissingInputs_) {
263  cout<<" Ecal collection is missed "<<endl;
264  throw e;
265  }
266  }
267 
268  cout<<" Fill EcalRecHits "<<endl;
269 // cout<<" Start to get hbhe "<<endl;
270 // Hcal Barrel and endcap for isolation
271  try {
273  iEvent.getByLabel(nameProd_,hbheInput_,hbhe);
274 
275 // (*myout_hcal)<<(*hbhe).size()<<endl;
276  for(HBHERecHitCollection::const_iterator hbheItr = (*hbhe).begin();
277 
278  hbheItr != (*hbhe).end(); ++hbheItr)
279  {
280  DetId id = (hbheItr)->detid();
281  GlobalPoint pos = geo->getPosition(hbheItr->detid());
282  (*myout_hcal)<<id.subdetId()<<" "<<(*hbheItr).energy()<<" "<<pos.phi()<<
283  " "<<pos.eta()<<" "<<iEvent.id().event()<<endl;
284  theRecHits.push_back(*hbheItr);
285 
286  }
287  } catch (cms::Exception& e) { // can't find it!
288  if (!allowMissingInputs_) {
289  cout<<" HBHE collection is missed "<<endl;
290  throw e;
291  }
292  }
293 
294 
295  for(int i = 0; i<9; i++)
296  {
297  for(int j= 0; j<10; j++) GammaIsoEcal[i][j] = 0.;
298  }
299 
300 // Load Ecal clusters
301  jetexist = -100;
302  int barrel = 1;
303  NumRecoGamma = 0;
304 
305  try {
306  int ij = 0;
307  // Get island super clusters after energy correction
309  iEvent.getByLabel(nameProd_,gammaClus_, eclus);
310  const reco::SuperClusterCollection* correctedSuperClusters=eclus.product();
311  // loop over the super clusters and fill the histogram
312  for(reco::SuperClusterCollection::const_iterator aClus = correctedSuperClusters->begin();
313  aClus != correctedSuperClusters->end(); aClus++) {
314  double vet = aClus->energy()/cosh(aClus->eta());
315  cout<<" Supercluster " << ij<<" Et "<< vet <<" energy "<<aClus->energy()<<" eta "<<aClus->eta()<<" Cut "<<CutOnEgammaEnergy_<<endl;
316 
317  if(vet>CutOnEgammaEnergy_) {
318  ij++;
319  float gammaiso_ecal[9] = {0.,0.,0.,0.,0.,0.,0.,0.,0.};
320  for(vector<CaloRecHit>::iterator it = theRecHits.begin(); it != theRecHits.end(); it++)
321  {
322  GlobalPoint pos = geo->getPosition(it->detid());
323  double eta = pos.eta();
324  double phi = pos.phi();
325  double deta = fabs(eta-aClus->eta());
326  double dphi = fabs(phi-aClus->phi());
327  if(dphi>4.*atan(1.)) dphi = 8.*atan(1.)-dphi;
328  double dr = sqrt(deta*deta+dphi*dphi);
329 
330  double rmin = 0.07;
331  if( fabs(aClus->eta()) > 1.47 ) rmin = 0.07*(fabs(aClus->eta())-.47)*1.2;
332  if( fabs(aClus->eta()) > 2.2 ) rmin = 0.07*(fabs(aClus->eta())-.47)*1.4;
333 
334  int itype_ecal = 0;
335  double ecutn = 0.;
336  for (int i = 0; i<3; i++)
337  {
338  for (int j = 0; j<3; j++)
339  {
340 
341  if(it->detid().det() == DetId::Ecal )
342  {
343  if(it->detid().subdetId() == 1) ecutn = ecut[0][j];
344  if(it->detid().subdetId() == 2) ecutn = ecut[1][j];
345  if( dr>rmin && dr<risol[i])
346  {
347  if((*it).energy() > ecutn) gammaiso_ecal[itype_ecal] = gammaiso_ecal[itype_ecal]+(*it).energy()/cosh(eta);
348  }
349  }
350 
351  if(it->detid().det() == DetId::Hcal )
352  {
353  ecutn = ecut[2][j];
354  if( dr>rmin && dr<risol[i])
355  {
356  if((*it).energy() > ecutn)
357  {
358  gammaiso_ecal[itype_ecal] = gammaiso_ecal[itype_ecal]+(*it).energy()/cosh(eta);
359  }
360  }
361  }
362  jetexist = ij;
363  itype_ecal++;
364 
365  } // Ecal
366  } // cycle on iso radii
367  } // cycle on rechits
368 
369 
370 // Fill Tree
371  if( NumRecoGamma < 10 )
372  {
373  for (int ii = 0; ii<9 ; ii++)
374  {
375  GammaIsoEcal[ii][NumRecoGamma] = gammaiso_ecal[ii];
376  }
377  EcalClusDet[NumRecoGamma] = 1;
378  GammaRecoEt[NumRecoGamma] = vet;
379  GammaRecoEta[NumRecoGamma] = aClus->eta();
380  GammaRecoPhi[NumRecoGamma] = aClus->phi();
381  NumRecoGamma++;
382  }
383  (*myout_photon)<<ij<<" "<<barrel<<" "<<vet<<" "<<aClus->eta()<<" "<<aClus->phi()<<" "<<iEvent.id().event()<<endl;
384  (*myout_photon)<<ij<<" "<<gammaiso_ecal[0]<<" "<<gammaiso_ecal[1] <<" "<<gammaiso_ecal[2]<<" "<<gammaiso_ecal[3]
385  <<" "<<gammaiso_ecal[4]<<" "<<gammaiso_ecal[5]<<" "<<gammaiso_ecal[6]<<" "<<gammaiso_ecal[7]<<" "<<gammaiso_ecal[8]<<endl;
386 
387  jetexist = ij;
388  } //vet
389  } // number of superclusters
390  } catch (cms::Exception& e) { // can't find it!
391  if (!allowMissingInputs_) {
392  cout<<" Ecal barrel clusters are missed "<<endl;
393  throw e;
394  }
395  }
396 
397  cout<<" After iso cuts "<<jetexist<<endl;
398 
399  double ecluslost = -100.1;
400  if(jetexist<0) (*myout_photon)<<jetexist<<" "<<barrel<<" "<<ecluslost<<" "<<ecluslost
401  <<" "<<ecluslost<<" "<<iEvent.id().event()<<endl;
402 
403  cout<<" Event is ready "<<endl;
404 
405  myTree->Fill();
406 
407 } // analyze method
408 } // namespace cms
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Event.cc:70
int i
Definition: DBlmapReader.cc:9
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
std::vector< EcalRecHit >::const_iterator const_iterator
T eta() const
void beginJob()
Definition: Breakpoints.cc:15
int iEvent
Definition: GenABIO.cc:243
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
T sqrt(T t)
Definition: SSEVec.h:46
vector< PseudoJet > jets
int j
Definition: DBlmapReader.cc:9
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:74
T eta() const
Definition: PV3DBase.h:75
edm::EventID id() const
Definition: EventBase.h:56
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10