CMS 3D CMS Logo

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