CMS 3D CMS Logo

EcalTrigPrimAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: EcalTrigPrimAnalyzer
4 //
10 //
11 //
12 // Original Author: Ursula Berthon, Stephanie Baffioni, Pascal Paganini
13 // Created: Thu Jul 4 11:38:38 CEST 2005
14 //
15 //
16 
17 // system include files
18 #include <memory>
19 #include <utility>
20 
21 // user include files
25 
30 
35 
40 
42 
43 #include "EcalTrigPrimAnalyzer.h"
44 
45 #include <TMath.h>
46 
47 using namespace edm;
49 
51 
52 {
53  ecal_parts_.push_back("Barrel");
54  ecal_parts_.push_back("Endcap");
55 
56  histfile_ = new TFile("histos.root", "RECREATE");
57  tree_ = new TTree("TPGtree", "TPGtree");
58  tree_->Branch("iphi", &iphi_, "iphi/I");
59  tree_->Branch("ieta", &ieta_, "ieta/I");
60  tree_->Branch("eRec", &eRec_, "eRec/F");
61  tree_->Branch("tpgADC", &tpgADC_, "tpgADC/I");
62  tree_->Branch("tpgGeV", &tpgGeV_, "tpgGeV/F");
63  tree_->Branch("ttf", &ttf_, "ttf/I");
64  tree_->Branch("fg", &fg_, "fg/I");
65  for (unsigned int i = 0; i < 2; ++i) {
66  ecal_et_[i] = new TH1I(ecal_parts_[i].c_str(), "Et", 255, 0, 255);
67  char title[30];
68  sprintf(title, "%s_ttf", ecal_parts_[i].c_str());
69  ecal_tt_[i] = new TH1I(title, "TTF", 10, 0, 10);
70  sprintf(title, "%s_fgvb", ecal_parts_[i].c_str());
71  ecal_fgvb_[i] = new TH1I(title, "FGVB", 10, 0, 10);
72  }
73 
74  recHits_ = iConfig.getParameter<bool>("AnalyzeRecHits");
75  label_ = iConfig.getParameter<edm::InputTag>("inputTP");
76  if (recHits_) {
77  hTPvsRechit_ =
78  new TH2F("TP_vs_RecHit", "TP vs rechit", 256, -1, 255, 255, 0, 255);
79  hTPoverRechit_ = new TH1F("TP_over_RecHit", "TP over rechit", 500, 0, 4);
80  rechits_labelEB_ = iConfig.getParameter<edm::InputTag>("inputRecHitsEB");
81  rechits_labelEE_ = iConfig.getParameter<edm::InputTag>("inputRecHitsEE");
82  }
83 }
84 
86 
87  // do anything here that needs to be done at desctruction time
88  // (e.g. close files, deallocate resources etc.)
89 
90  histfile_->Write();
91  histfile_->Close();
92 }
93 
94 //
95 // member functions
96 //
97 
98 // ------------ method called to analyze the data ------------
100  const edm::EventSetup &iSetup) {
101  using namespace edm;
102  using namespace std;
103 
104  // Get input
106  iEvent.getByLabel(label_, tp);
107  for (unsigned int i = 0; i < tp.product()->size(); i++) {
108  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
109  int subdet = d.id().subDet() - 1;
110  if (subdet == 0) {
111  ecal_et_[subdet]->Fill(d.compressedEt());
112  } else {
113  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28) {
114  if (i % 2)
115  ecal_et_[subdet]->Fill(d.compressedEt() * 2.);
116  } else
117  ecal_et_[subdet]->Fill(d.compressedEt());
118  }
119  ecal_tt_[subdet]->Fill(d.ttFlag());
120  ecal_fgvb_[subdet]->Fill(d.fineGrain());
121  }
122  if (!recHits_)
123  return;
124 
125  // comparison with RecHits
126  edm::Handle<EcalRecHitCollection> rechit_EB_col;
127  iEvent.getByLabel(rechits_labelEB_, rechit_EB_col);
128 
129  edm::Handle<EcalRecHitCollection> rechit_EE_col;
130  iEvent.getByLabel(rechits_labelEE_, rechit_EE_col);
131 
132  edm::ESHandle<CaloGeometry> theGeometry;
133  edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle;
134  edm::ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle;
135  iSetup.get<CaloGeometryRecord>().get(theGeometry);
136  iSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap",
137  theEndcapGeometry_handle);
138  iSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",
139  theBarrelGeometry_handle);
140 
141  const CaloSubdetectorGeometry *theEndcapGeometry =
142  theEndcapGeometry_handle.product();
143  const CaloSubdetectorGeometry *theBarrelGeometry =
144  theBarrelGeometry_handle.product();
146  iSetup.get<IdealGeometryRecord>().get(eTTmap_);
147 
148  map<EcalTrigTowerDetId, float> mapTow_Et;
149 
150  for (unsigned int i = 0; i < rechit_EB_col.product()->size(); i++) {
151  const EBDetId &myid1 = (*rechit_EB_col.product())[i].id();
152  EcalTrigTowerDetId towid1 = myid1.tower();
153  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
154  float Etsum = ((*rechit_EB_col.product())[i].energy()) * sin(theta);
155  bool test_alreadyin = false;
156  map<EcalTrigTowerDetId, float>::iterator ittest = mapTow_Et.find(towid1);
157  if (ittest != mapTow_Et.end())
158  test_alreadyin = true;
159  if (test_alreadyin)
160  continue;
161  unsigned int j = i + 1;
162  bool loopend = false;
163  unsigned int count = 0;
164  while (j < rechit_EB_col.product()->size() && !loopend) {
165  count++;
166  const EBDetId &myid2 = (*rechit_EB_col.product())[j].id();
167  EcalTrigTowerDetId towid2 = myid2.tower();
168  if (towid1 == towid2) {
169  float theta =
170  theBarrelGeometry->getGeometry(myid2)->getPosition().theta();
171  Etsum += (*rechit_EB_col.product())[j].energy() * sin(theta);
172  }
173  j++;
174  if (count > 1800)
175  loopend = true;
176  }
177  mapTow_Et.insert(pair<EcalTrigTowerDetId, float>(towid1, Etsum));
178  }
179 
180  for (unsigned int i = 0; i < rechit_EE_col.product()->size(); i++) {
181  const EEDetId &myid1 = (*rechit_EE_col.product())[i].id();
182  EcalTrigTowerDetId towid1 = (*eTTmap_).towerOf(myid1);
183  float theta = theEndcapGeometry->getGeometry(myid1)->getPosition().theta();
184  float Etsum = (*rechit_EE_col.product())[i].energy() * sin(theta);
185  bool test_alreadyin = false;
186  map<EcalTrigTowerDetId, float>::iterator ittest = mapTow_Et.find(towid1);
187  if (ittest != mapTow_Et.end())
188  test_alreadyin = true;
189  if (test_alreadyin)
190  continue;
191  unsigned int j = i + 1;
192  bool loopend = false;
193  unsigned int count = 0;
194  while (j < rechit_EE_col.product()->size() && !loopend) {
195  const EEDetId &myid2 = (*rechit_EE_col.product())[j].id();
196  EcalTrigTowerDetId towid2 = (*eTTmap_).towerOf(myid2);
197  if (towid1 == towid2) {
198  float theta =
199  theEndcapGeometry->getGeometry(myid2)->getPosition().theta();
200  Etsum += (*rechit_EE_col.product())[j].energy() * sin(theta);
201  }
202  // else loopend=true;
203  j++;
204  if (count > 500)
205  loopend = true;
206  }
207  // alreadyin_EE.push_back(towid1);
208  mapTow_Et.insert(pair<EcalTrigTowerDetId, float>(towid1, Etsum));
209  }
210 
211  EcalTPGScale ecalScale;
212  ecalScale.setEventSetup(iSetup);
213  for (unsigned int i = 0; i < tp.product()->size(); i++) {
214  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
215  const EcalTrigTowerDetId TPtowid = d.id();
216  map<EcalTrigTowerDetId, float>::iterator it = mapTow_Et.find(TPtowid);
217  float Et = ecalScale.getTPGInGeV(d.compressedEt(), TPtowid);
218  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28)
219  Et *= 2;
220  iphi_ = TPtowid.iphi();
221  ieta_ = TPtowid.ieta();
222  tpgADC_ = d.compressedEt();
223  tpgGeV_ = Et;
224  ttf_ = d.ttFlag();
225  fg_ = d.fineGrain();
226  if (it != mapTow_Et.end()) {
227  hTPvsRechit_->Fill(it->second, Et);
228  hTPoverRechit_->Fill(Et / it->second);
229  eRec_ = it->second;
230  }
231  tree_->Fill();
232  }
233 }
234 
236  for (unsigned int i = 0; i < 2; ++i) {
237  ecal_et_[i]->Write();
238  ecal_tt_[i]->Write();
239  ecal_fgvb_[i]->Write();
240  }
241  if (recHits_) {
242  hTPvsRechit_->Write();
243  hTPoverRechit_->Write();
244  }
245 }
T getParameter(std::string const &) const
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:19
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi)
Definition: EcalTPGScale.cc:24
int ieta() const
get the tower ieta
void analyze(const edm::Event &, const edm::EventSetup &) override
int compressedEt() const
get the encoded/compressed Et of interesting sample
int iEvent
Definition: GenABIO.cc:224
int ietaAbs() const
get the absolute value of the tower ieta
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
EcalTrigPrimAnalyzer(const edm::ParameterSet &)
int iphi() const
get the tower iphi
const EcalTrigTowerDetId & id() const
T const * product() const
Definition: Handle.h:74
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:71
bool fineGrain() const
get the fine-grain bit of interesting sample
int ttFlag() const
get the Trigger tower Flag of interesting sample
T const * product() const
Definition: ESHandle.h:86