CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
24 
28 
33 
35 
37 
38 #include "EcalTrigPrimAnalyzer.h"
39 
40 #include <TMath.h>
41 
42 using namespace edm;
44 
46  : tokens_(consumesCollector())
47 
48 {
49  ecal_parts_.push_back("Barrel");
50  ecal_parts_.push_back("Endcap");
51 
52  histfile_ = new TFile("histos.root", "RECREATE");
53  tree_ = new TTree("TPGtree", "TPGtree");
54  tree_->Branch("iphi", &iphi_, "iphi/I");
55  tree_->Branch("ieta", &ieta_, "ieta/I");
56  tree_->Branch("eRec", &eRec_, "eRec/F");
57  tree_->Branch("tpgADC", &tpgADC_, "tpgADC/I");
58  tree_->Branch("tpgGeV", &tpgGeV_, "tpgGeV/F");
59  tree_->Branch("ttf", &ttf_, "ttf/I");
60  tree_->Branch("fg", &fg_, "fg/I");
61  for (unsigned int i = 0; i < 2; ++i) {
62  ecal_et_[i] = new TH1I(ecal_parts_[i].c_str(), "Et", 255, 0, 255);
63  char title[30];
64  sprintf(title, "%s_ttf", ecal_parts_[i].c_str());
65  ecal_tt_[i] = new TH1I(title, "TTF", 10, 0, 10);
66  sprintf(title, "%s_fgvb", ecal_parts_[i].c_str());
67  ecal_fgvb_[i] = new TH1I(title, "FGVB", 10, 0, 10);
68  }
69 
70  recHits_ = iConfig.getParameter<bool>("AnalyzeRecHits");
71  label_ = iConfig.getParameter<edm::InputTag>("inputTP");
72  if (recHits_) {
73  hTPvsRechit_ = new TH2F("TP_vs_RecHit", "TP vs rechit", 256, -1, 255, 255, 0, 255);
74  hTPoverRechit_ = new TH1F("TP_over_RecHit", "TP over rechit", 500, 0, 4);
75  rechits_labelEB_ = iConfig.getParameter<edm::InputTag>("inputRecHitsEB");
76  rechits_labelEE_ = iConfig.getParameter<edm::InputTag>("inputRecHitsEE");
77  geomToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
78  endcapGeomToken_ = esConsumes<CaloSubdetectorGeometry, EcalEndcapGeometryRecord>(edm::ESInputTag("", "EcalEndcap"));
79  barrelGeomToken_ = esConsumes<CaloSubdetectorGeometry, EcalBarrelGeometryRecord>(edm::ESInputTag("", "EcalBarrel"));
80  eTTmapToken_ = esConsumes<EcalTrigTowerConstituentsMap, IdealGeometryRecord>();
81  }
82 }
83 
85  // do anything here that needs to be done at desctruction time
86  // (e.g. close files, deallocate resources etc.)
87 
88  histfile_->Write();
89  histfile_->Close();
90 }
91 
92 //
93 // member functions
94 //
95 
96 // ------------ method called to analyze the data ------------
98  using namespace edm;
99  using namespace std;
100 
101  // Get input
103  iEvent.getByLabel(label_, tp);
104  for (unsigned int i = 0; i < tp.product()->size(); i++) {
105  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
106  int subdet = d.id().subDet() - 1;
107  if (subdet == 0) {
108  ecal_et_[subdet]->Fill(d.compressedEt());
109  } else {
110  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28) {
111  if (i % 2)
112  ecal_et_[subdet]->Fill(d.compressedEt() * 2.);
113  } else
114  ecal_et_[subdet]->Fill(d.compressedEt());
115  }
116  ecal_tt_[subdet]->Fill(d.ttFlag());
117  ecal_fgvb_[subdet]->Fill(d.fineGrain());
118  }
119  if (!recHits_)
120  return;
121 
122  // comparison with RecHits
123  edm::Handle<EcalRecHitCollection> rechit_EB_col;
124  iEvent.getByLabel(rechits_labelEB_, rechit_EB_col);
125 
126  edm::Handle<EcalRecHitCollection> rechit_EE_col;
127  iEvent.getByLabel(rechits_labelEE_, rechit_EE_col);
128 
129  edm::ESHandle<CaloGeometry> theGeometry = iSetup.getHandle(geomToken_);
130  edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle = iSetup.getHandle(barrelGeomToken_);
131  edm::ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle = iSetup.getHandle(endcapGeomToken_);
132 
133  const CaloSubdetectorGeometry *theEndcapGeometry = theEndcapGeometry_handle.product();
134  const CaloSubdetectorGeometry *theBarrelGeometry = theBarrelGeometry_handle.product();
136 
137  map<EcalTrigTowerDetId, float> mapTow_Et;
138 
139  for (unsigned int i = 0; i < rechit_EB_col.product()->size(); i++) {
140  const EBDetId &myid1 = (*rechit_EB_col.product())[i].id();
141  EcalTrigTowerDetId towid1 = myid1.tower();
142  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
143  float Etsum = ((*rechit_EB_col.product())[i].energy()) * sin(theta);
144  bool test_alreadyin = false;
145  map<EcalTrigTowerDetId, float>::iterator ittest = mapTow_Et.find(towid1);
146  if (ittest != mapTow_Et.end())
147  test_alreadyin = true;
148  if (test_alreadyin)
149  continue;
150  unsigned int j = i + 1;
151  bool loopend = false;
152  unsigned int count = 0;
153  while (j < rechit_EB_col.product()->size() && !loopend) {
154  count++;
155  const EBDetId &myid2 = (*rechit_EB_col.product())[j].id();
156  EcalTrigTowerDetId towid2 = myid2.tower();
157  if (towid1 == towid2) {
158  float theta = theBarrelGeometry->getGeometry(myid2)->getPosition().theta();
159  Etsum += (*rechit_EB_col.product())[j].energy() * sin(theta);
160  }
161  j++;
162  if (count > 1800)
163  loopend = true;
164  }
165  mapTow_Et.insert(pair<EcalTrigTowerDetId, float>(towid1, Etsum));
166  }
167 
168  for (unsigned int i = 0; i < rechit_EE_col.product()->size(); i++) {
169  const EEDetId &myid1 = (*rechit_EE_col.product())[i].id();
170  EcalTrigTowerDetId towid1 = (*eTTmap_).towerOf(myid1);
171  float theta = theEndcapGeometry->getGeometry(myid1)->getPosition().theta();
172  float Etsum = (*rechit_EE_col.product())[i].energy() * sin(theta);
173  bool test_alreadyin = false;
174  map<EcalTrigTowerDetId, float>::iterator ittest = mapTow_Et.find(towid1);
175  if (ittest != mapTow_Et.end())
176  test_alreadyin = true;
177  if (test_alreadyin)
178  continue;
179  unsigned int j = i + 1;
180  bool loopend = false;
181  unsigned int count = 0;
182  while (j < rechit_EE_col.product()->size() && !loopend) {
183  const EEDetId &myid2 = (*rechit_EE_col.product())[j].id();
184  EcalTrigTowerDetId towid2 = (*eTTmap_).towerOf(myid2);
185  if (towid1 == towid2) {
186  float theta = theEndcapGeometry->getGeometry(myid2)->getPosition().theta();
187  Etsum += (*rechit_EE_col.product())[j].energy() * sin(theta);
188  }
189  // else loopend=true;
190  j++;
191  if (count > 500)
192  loopend = true;
193  }
194  // alreadyin_EE.push_back(towid1);
195  mapTow_Et.insert(pair<EcalTrigTowerDetId, float>(towid1, Etsum));
196  }
197 
198  EcalTPGScale ecalScale(tokens_, iSetup);
199  for (unsigned int i = 0; i < tp.product()->size(); i++) {
200  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
201  const EcalTrigTowerDetId TPtowid = d.id();
202  map<EcalTrigTowerDetId, float>::iterator it = mapTow_Et.find(TPtowid);
203  float Et = ecalScale.getTPGInGeV(d.compressedEt(), TPtowid);
204  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28)
205  Et *= 2;
206  iphi_ = TPtowid.iphi();
207  ieta_ = TPtowid.ieta();
208  tpgADC_ = d.compressedEt();
209  tpgGeV_ = Et;
210  ttf_ = d.ttFlag();
211  fg_ = d.fineGrain();
212  if (it != mapTow_Et.end()) {
213  hTPvsRechit_->Fill(it->second, Et);
214  hTPoverRechit_->Fill(Et / it->second);
215  eRec_ = it->second;
216  }
217  tree_->Fill();
218  }
219 }
220 
222  for (unsigned int i = 0; i < 2; ++i) {
223  ecal_et_[i]->Write();
224  ecal_tt_[i]->Write();
225  ecal_fgvb_[i]->Write();
226  }
227  if (recHits_) {
228  hTPvsRechit_->Write();
229  hTPoverRechit_->Write();
230  }
231 }
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomToken_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
int ieta() const
get the tower ieta
tuple d
Definition: ztail.py:151
void analyze(const edm::Event &, const edm::EventSetup &) override
int compressedEt() const
get the encoded/compressed Et of interesting sample
edm::ESGetToken< CaloSubdetectorGeometry, EcalBarrelGeometryRecord > barrelGeomToken_
int iEvent
Definition: GenABIO.cc:224
int ietaAbs() const
get the absolute value of the tower ieta
edm::ESGetToken< CaloSubdetectorGeometry, EcalEndcapGeometryRecord > endcapGeomToken_
std::vector< std::string > ecal_parts_
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:500
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi) const
Definition: EcalTPGScale.cc:17
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > eTTmapToken_
std::vector< edm::EDGetTokenT< int > > tokens_
EcalTrigPrimAnalyzer(const edm::ParameterSet &)
int iphi() const
get the tower iphi
const EcalTrigTowerDetId & id() const
EcalTPGScale::Tokens tokens_
edm::InputTag rechits_labelEE_
edm::InputTag rechits_labelEB_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
bool fineGrain() const
get the fine-grain bit of interesting sample
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
int ttFlag() const
get the Trigger tower Flag of interesting sample