CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloTowerAnalyzer.cc
Go to the documentation of this file.
2 // author: Bobby Scurlock, University of Florida
3 // first version 12/18/2006
4 // modified: Mike Schmitt
5 // date: 02.28.2007
6 // note: code rewrite
7 
11 
18 
26 
29 
34 
36 
39 
43 
44 //#include "Geometry/Vector/interface/GlobalPoint.h"
47 
48 #include <vector>
49 #include <utility>
50 #include <ostream>
51 #include <fstream>
52 #include <string>
53 #include <algorithm>
54 #include <cmath>
55 #include <memory>
56 #include <TLorentzVector.h>
58 
59 using namespace reco;
60 
62 {
63 
64  caloTowersLabel_ = iConfig.getParameter<edm::InputTag>("CaloTowersLabel");
65  HLTResultsLabel_ = iConfig.getParameter<edm::InputTag>("HLTResultsLabel");
66  HcalNoiseSummaryTag_ = iConfig.getParameter<edm::InputTag>("HcalNoiseSummary");
67 
68  if(iConfig.exists("HLTBitLabels"))
69  HLTBitLabel_ = iConfig.getParameter<std::vector<edm::InputTag> >("HLTBitLabels");
70 
71  debug_ = iConfig.getParameter<bool>("Debug");
72  finebinning_ = iConfig.getUntrackedParameter<bool>("FineBinning");
73  allhist_ = iConfig.getUntrackedParameter<bool>("AllHist");
74  FolderName_ = iConfig.getUntrackedParameter<std::string>("FolderName");
75 
76  hltselection_ = iConfig.getUntrackedParameter<bool>("HLTSelection");
77 
78 }
79 
80 
81 void CaloTowerAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
82 {
83  Nevents = 0;
84  // get ahold of back-end interface
86 
87  if (dbe_) {
88 
89  dbe_->setCurrentFolder(FolderName_);
90 
91  //Store number of events which pass each HLT bit
92  for(unsigned int i = 0 ; i < HLTBitLabel_.size() ; i++ )
93  {
94  if( HLTBitLabel_[i].label().size() )
95  {
96  hCT_NEvents_HLT.push_back( dbe_->book1D("METTask_CT_"+HLTBitLabel_[i].label(),HLTBitLabel_[i].label(),2,-0.5,1.5) );
97  }
98  }
99 
100  //--Store number of events used
101  hCT_Nevents = dbe_->book1D("METTask_CT_Nevents","",1,0,1);
102  //--Data integrated over all events and stored by CaloTower(ieta,iphi)
103  hCT_et_ieta_iphi = dbe_->book2D("METTask_CT_et_ieta_iphi","",83,-41,42, 72,1,73);
104  hCT_et_ieta_iphi->getTH2F()->SetOption("colz");
105  hCT_et_ieta_iphi->setAxisTitle("ieta",1);
106  hCT_et_ieta_iphi->setAxisTitle("ephi",2);
107 
108  hCT_emEt_ieta_iphi = dbe_->book2D("METTask_CT_emEt_ieta_iphi","",83,-41,42, 72,1,73);
109  hCT_emEt_ieta_iphi->getTH2F()->SetOption("colz");
110  hCT_emEt_ieta_iphi->setAxisTitle("ieta",1);
111  hCT_emEt_ieta_iphi->setAxisTitle("ephi",2);
112  hCT_hadEt_ieta_iphi = dbe_->book2D("METTask_CT_hadEt_ieta_iphi","",83,-41,42, 72,1,73);
113  hCT_hadEt_ieta_iphi->getTH2F()->SetOption("colz");
114  hCT_hadEt_ieta_iphi->setAxisTitle("ieta",1);
115  hCT_hadEt_ieta_iphi->setAxisTitle("ephi",2);
116  hCT_outerEt_ieta_iphi = dbe_->book2D("METTask_CT_outerEt_ieta_iphi","",83,-41,42, 72,1,73);
117  hCT_outerEt_ieta_iphi->getTH2F()->SetOption("colz");
118  hCT_outerEt_ieta_iphi->setAxisTitle("ieta",1);
119  hCT_outerEt_ieta_iphi->setAxisTitle("ephi",2);
120  hCT_Occ_ieta_iphi = dbe_->book2D("METTask_CT_Occ_ieta_iphi","",83,-41,42, 72,1,73);
121  hCT_Occ_ieta_iphi->getTH2F()->SetOption("colz");
122  hCT_Occ_ieta_iphi->setAxisTitle("ieta",1);
123  hCT_Occ_ieta_iphi->setAxisTitle("ephi",2);
124  //--Data over eta-rings
125 
126  // CaloTower values
127  if(allhist_){
128  if(finebinning_)
129  {
130 
131  hCT_etvsieta = dbe_->book2D("METTask_CT_etvsieta","", 83,-41,42, 10001,0,1001);
132  hCT_Minetvsieta = dbe_->book2D("METTask_CT_Minetvsieta","", 83,-41,42, 10001,0,1001);
133  hCT_Maxetvsieta = dbe_->book2D("METTask_CT_Maxetvsieta","", 83,-41,42, 10001,0,1001);
134  hCT_emEtvsieta = dbe_->book2D("METTask_CT_emEtvsieta","",83,-41,42, 10001,0,1001);
135  hCT_hadEtvsieta = dbe_->book2D("METTask_CT_hadEtvsieta","",83,-41,42, 10001,0,1001);
136  hCT_outerEtvsieta = dbe_->book2D("METTask_CT_outerEtvsieta","",83,-41,42, 10001,0,1001);
137  // Integrated over phi
138 
139  hCT_Occvsieta = dbe_->book2D("METTask_CT_Occvsieta","",83,-41,42, 84,0,84);
140  hCT_SETvsieta = dbe_->book2D("METTask_CT_SETvsieta","",83,-41,42, 20001,0,2001);
141  hCT_METvsieta = dbe_->book2D("METTask_CT_METvsieta","",83,-41,42, 20001,0,2001);
142  hCT_METPhivsieta = dbe_->book2D("METTask_CT_METPhivsieta","",83,-41,42, 80,-4,4);
143  hCT_MExvsieta = dbe_->book2D("METTask_CT_MExvsieta","",83,-41,42, 10001,-500,501);
144  hCT_MEyvsieta = dbe_->book2D("METTask_CT_MEyvsieta","",83,-41,42, 10001,-500,501);
145  }
146  else
147  {
148 
149  if(allhist_){
150  hCT_etvsieta = dbe_->book2D("METTask_CT_etvsieta","", 83,-41,42, 200,-0.5,999.5);
151  hCT_Minetvsieta = dbe_->book2D("METTask_CT_Minetvsieta","", 83,-41,42, 200,-0.5,999.5);
152  hCT_Maxetvsieta = dbe_->book2D("METTask_CT_Maxetvsieta","", 83,-41,42, 200,-0.5,999.5);
153  hCT_emEtvsieta = dbe_->book2D("METTask_CT_emEtvsieta","",83,-41,42, 200,-0.5,999.5);
154  hCT_hadEtvsieta = dbe_->book2D("METTask_CT_hadEtvsieta","",83,-41,42, 200,-0.5,999.5);
155  hCT_outerEtvsieta = dbe_->book2D("METTask_CT_outerEtvsieta","",83,-41,42, 80,-0.5,399.5);
156  // Integrated over phi
157  }
158 
159  hCT_Occvsieta = dbe_->book2D("METTask_CT_Occvsieta","",83,-41,42, 73,-0.5,72.5);
160  hCT_SETvsieta = dbe_->book2D("METTask_CT_SETvsieta","",83,-41,42, 200,-0.5,1999.5);
161  hCT_METvsieta = dbe_->book2D("METTask_CT_METvsieta","",83,-41,42, 200,-0.5,1999.5);
162  hCT_METPhivsieta = dbe_->book2D("METTask_CT_METPhivsieta","",83,-41,42, 80,-4,4);
163  hCT_MExvsieta = dbe_->book2D("METTask_CT_MExvsieta","",83,-41,42, 100,-499.5,499.5);
164  hCT_MEyvsieta = dbe_->book2D("METTask_CT_MEyvsieta","",83,-41,42, 100,-499.5,499.5);
165 
166  }
167  } // allhist
168  }
169 }
170 
172 {
173  // Get HLT Results
174  edm::Handle<edm::TriggerResults> TheHLTResults;
175  iEvent.getByLabel( HLTResultsLabel_ , TheHLTResults);
176 
177  bool EventPasses = true;
178 
179  // Make sure handle is valid
180  if( TheHLTResults.isValid() && hltselection_ )
181  {
182  //Get HLT Names
183  const edm::TriggerNames & TheTriggerNames = iEvent.triggerNames(*TheHLTResults);
184 
185  for( unsigned int index = 0 ; index < HLTBitLabel_.size(); index++)
186  {
187  if( HLTBitLabel_[index].label().size() )
188  {
189  //Change the default value since HLT requirement has been issued by the user
190  if( index == 0 ) EventPasses = false;
191  //Get the HLT bit and check to make sure it is valid
192  unsigned int bit = TheTriggerNames.triggerIndex( HLTBitLabel_[index].label().c_str());
193  if( bit < TheHLTResults->size() )
194  {
195  //If any of the HLT names given by the user accept, then the event passes
196  if( TheHLTResults->accept( bit ) && !TheHLTResults->error( bit ) )
197  {
198  EventPasses = true;
199  hCT_NEvents_HLT[index]->Fill(1);
200  }
201  else
202  hCT_NEvents_HLT[index]->Fill(0);
203  }
204  else
205  {
206  edm::LogInfo("OutputInfo")
207  << "The HLT Trigger Name : " << HLTBitLabel_[index].label() << " is not valid for this trigger table " << std::endl;
208  }
209  }
210  }
211  }
212 
213  if( !EventPasses && hltselection_ )
214  return;
215 
216  //----------GREG & CHRIS' idea---///
217  float ETTowerMin = -1; //GeV
218  float METRingMin = -2; // GeV
219 
220  Nevents++;
221  hCT_Nevents->Fill(0);
222 
223  // ==========================================================
224  // Retrieve!
225  // ==========================================================
226 
228  iEvent.getByLabel(caloTowersLabel_, towers);
229 
230  if( (!towers.isValid())) {
231  edm::LogInfo("")<<"CaloTowers "<< caloTowersLabel_<<" not found!"<<std::endl;
232  return;
233  }
234 
235 
236  edm::Handle<HcalNoiseSummary> HNoiseSummary;
237  iEvent.getByLabel(HcalNoiseSummaryTag_,HNoiseSummary);
238  if (!HNoiseSummary.isValid()) {
239  LogDebug("") << "CaloTowerAnalyzer: Could not find Hcal NoiseSummary product" << std::endl;
240  }
241 
242  bool bHcalNoiseFilter = HNoiseSummary->passLooseNoiseFilter();
243  if(!bHcalNoiseFilter) return;
244 
245  edm::View<Candidate>::const_iterator towerCand = towers->begin();
246 
247  // ==========================================================
248  // Fill Histograms!
249  // ==========================================================
250 
251  int CTmin_iphi = 99, CTmax_iphi = -99;
252  int CTmin_ieta = 99, CTmax_ieta = -99;
253 
254  TLorentzVector vMET_EtaRing[83];
255  int ActiveRing[83];
256  int NActiveTowers[83];
257  double SET_EtaRing[83];
258  double MinEt_EtaRing[83];
259  double MaxEt_EtaRing[83];
260  for (int i=0;i<83; i++)
261  {
262  ActiveRing[i] = 0;
263  NActiveTowers[i] = 0;
264  SET_EtaRing[i] = 0;
265  MinEt_EtaRing[i] = 0;
266  MaxEt_EtaRing[i] = 0;
267  }
268 
269  //rcr for (calotower = towerCollection->begin(); calotower != towerCollection->end(); calotower++) {
270 
271  for ( ; towerCand != towers->end(); towerCand++)
272  {
273  const Candidate* candidate = &(*towerCand);
274  if (candidate)
275  {
276  const CaloTower* calotower = dynamic_cast<const CaloTower*> (candidate);
277  if (calotower){
278  //math::RhoEtaPhiVector Momentum = calotower->momentum();
279  double Tower_ET = calotower->et();
280  //double Tower_Energy = calotower->energy();
281  // double Tower_Eta = calotower->eta();
282  double Tower_Phi = calotower->phi();
283  //double Tower_EMEnergy = calotower->emEnergy();
284  //double Tower_HadEnergy = calotower->hadEnergy();
285  double Tower_OuterEt = calotower->outerEt();
286  double Tower_EMEt = calotower->emEt();
287  double Tower_HadEt = calotower->hadEt();
288  //int Tower_EMLV1 = calotower->emLvl1();
289  //int Tower_HadLV1 = calotower->hadLv11();
290  int Tower_ieta = calotower->id().ieta();
291  int Tower_iphi = calotower->id().iphi();
292  int EtaRing = 41+Tower_ieta;
293  ActiveRing[EtaRing] = 1;
294  NActiveTowers[EtaRing]++;
295  SET_EtaRing[EtaRing]+=Tower_ET;
296  TLorentzVector v_;
297  v_.SetPtEtaPhiE(Tower_ET, 0, Tower_Phi, Tower_ET);
298  if (Tower_ET>ETTowerMin)
299  vMET_EtaRing[EtaRing]-=v_;
300 
301  // Fill Histograms
302  hCT_Occ_ieta_iphi->Fill(Tower_ieta,Tower_iphi);
303  hCT_et_ieta_iphi->Fill(Tower_ieta,Tower_iphi,Tower_ET);
304  hCT_emEt_ieta_iphi->Fill(Tower_ieta,Tower_iphi,Tower_EMEt);
305  hCT_hadEt_ieta_iphi->Fill(Tower_ieta,Tower_iphi,Tower_HadEt);
306  hCT_outerEt_ieta_iphi->Fill(Tower_ieta,Tower_iphi,Tower_OuterEt);
307 
308  if (allhist_){
309  hCT_etvsieta->Fill(Tower_ieta, Tower_ET);
310  hCT_emEtvsieta->Fill(Tower_ieta, Tower_EMEt);
311  hCT_hadEtvsieta->Fill(Tower_ieta,Tower_HadEt);
312  hCT_outerEtvsieta->Fill(Tower_ieta,Tower_OuterEt);
313  }
314 
315  if (Tower_ET > MaxEt_EtaRing[EtaRing])
316  MaxEt_EtaRing[EtaRing] = Tower_ET;
317  if (Tower_ET < MinEt_EtaRing[EtaRing] && Tower_ET>0)
318  MinEt_EtaRing[EtaRing] = Tower_ET;
319 
320 
321  if (Tower_ieta < CTmin_ieta) CTmin_ieta = Tower_ieta;
322  if (Tower_ieta > CTmax_ieta) CTmax_ieta = Tower_ieta;
323  if (Tower_iphi < CTmin_iphi) CTmin_iphi = Tower_iphi;
324  if (Tower_iphi > CTmax_iphi) CTmax_iphi = Tower_iphi;
325  } //end if (calotower) ..
326  } // end if(candidate) ...
327 
328  } // end loop over towers
329 
330  // Fill eta-ring MET quantities
331  if (allhist_){
332  for (int iEtaRing=0; iEtaRing<83; iEtaRing++)
333  {
334  hCT_Minetvsieta->Fill(iEtaRing-41, MinEt_EtaRing[iEtaRing]);
335  hCT_Maxetvsieta->Fill(iEtaRing-41, MaxEt_EtaRing[iEtaRing]);
336 
337  if (ActiveRing[iEtaRing])
338  {
339  if (vMET_EtaRing[iEtaRing].Pt()>METRingMin)
340  {
341  hCT_METPhivsieta->Fill(iEtaRing-41, vMET_EtaRing[iEtaRing].Phi());
342  hCT_MExvsieta->Fill(iEtaRing-41, vMET_EtaRing[iEtaRing].Px());
343  hCT_MEyvsieta->Fill(iEtaRing-41, vMET_EtaRing[iEtaRing].Py());
344  hCT_METvsieta->Fill(iEtaRing-41, vMET_EtaRing[iEtaRing].Pt());
345  }
346  hCT_SETvsieta->Fill(iEtaRing-41, SET_EtaRing[iEtaRing]);
347  hCT_Occvsieta->Fill(iEtaRing-41, NActiveTowers[iEtaRing]);
348  }
349  } // ietaring
350  } // allhist_
351 
352  edm::LogInfo("OutputInfo") << "CT ieta range: " << CTmin_ieta << " " << CTmax_ieta;
353  edm::LogInfo("OutputInfo") << "CT iphi range: " << CTmin_iphi << " " << CTmax_iphi;
354 
355 }
356 
358 {
359 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:208
const std::string & label
Definition: MVAComputer.cc:186
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:519
double hadEt() const
Definition: CaloTower.h:85
double outerEt() const
Definition: CaloTower.h:86
bool exists(std::string const &parameterName) const
checks if a parameter exists
CaloTowerAnalyzer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
int iphi() const
get the tower iphi
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
DQMStore * dbe_
CaloTowerDetId id() const
Definition: CaloTower.h:72
virtual void analyze(const edm::Event &, const edm::EventSetup &)
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
double et(double vtxZ) const
Definition: CaloTower.h:101
int ieta() const
get the tower ieta
TH2F * getTH2F(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:647
virtual double phi() const
momentum azimuthal angle
virtual void endJob()
double emEt() const
Definition: CaloTower.h:84
tuple size
Write out results.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
Definition: Run.h:31