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