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 
18 // system include files
19 #include <memory>
20 #include <utility>
21 
22 // user include files
26 
31 
36 
41 
43 
44 #include "EcalTrigPrimAnalyzer.h"
45 
46 #include <TMath.h>
47 
48 using namespace edm;
50 
52 
53 {
54  ecal_parts_.push_back("Barrel");
55  ecal_parts_.push_back("Endcap");
56 
57  histfile_=new TFile("histos.root","RECREATE");
58  tree_ = new TTree("TPGtree","TPGtree");
59  tree_->Branch("iphi",&iphi_,"iphi/I");
60  tree_->Branch("ieta",&ieta_,"ieta/I");
61  tree_->Branch("eRec",&eRec_,"eRec/F");
62  tree_->Branch("tpgADC",&tpgADC_,"tpgADC/I");
63  tree_->Branch("tpgGeV",&tpgGeV_,"tpgGeV/F");
64  tree_->Branch("ttf",&ttf_,"ttf/I");
65  tree_->Branch("fg",&fg_,"fg/I");
66  for (unsigned int i=0;i<2;++i) {
67  ecal_et_[i]=new TH1I(ecal_parts_[i].c_str(),"Et",255,0,255);
68  char title[30];
69  sprintf(title,"%s_ttf",ecal_parts_[i].c_str());
70  ecal_tt_[i]=new TH1I(title,"TTF",10,0,10);
71  sprintf(title,"%s_fgvb",ecal_parts_[i].c_str());
72  ecal_fgvb_[i]=new TH1I(title,"FGVB",10,0,10);
73  }
74 
75  recHits_= iConfig.getParameter<bool>("AnalyzeRecHits");
76  label_=iConfig.getParameter<edm::InputTag>("inputTP");
77  if (recHits_) {
78  hTPvsRechit_= 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 
85 
87 {
88 
89  // do anything here that needs to be done at desctruction time
90  // (e.g. close files, deallocate resources etc.)
91 
92  histfile_->Write();
93  histfile_->Close();
94 
95 }
96 
97 
98 //
99 // member functions
100 //
101 
102 // ------------ method called to analyze the data ------------
103 void
105 {
106  using namespace edm;
107  using namespace std;
108 
109  // Get input
111  iEvent.getByLabel(label_,tp);
112  for (unsigned int i=0;i<tp.product()->size();i++) {
113  EcalTriggerPrimitiveDigi d=(*(tp.product()))[i];
114  int subdet=d.id().subDet()-1;
115  if (subdet==0) {
116  ecal_et_[subdet]->Fill(d.compressedEt());
117  }
118  else {
119  if (d.id().ietaAbs()==27 || d.id().ietaAbs()==28) {
120  if (i%2) ecal_et_[subdet]->Fill(d.compressedEt()*2.);
121  }
122  else ecal_et_[subdet]->Fill(d.compressedEt());
123  }
124  ecal_tt_[subdet]->Fill(d.ttFlag());
125  ecal_fgvb_[subdet]->Fill(d.fineGrain());
126 
127  }
128  if (!recHits_) return;
129 
130  // comparison with RecHits
131  edm::Handle<EcalRecHitCollection> rechit_EB_col;
132  iEvent.getByLabel(rechits_labelEB_,rechit_EB_col);
133 
134  edm::Handle<EcalRecHitCollection> rechit_EE_col;
135  iEvent.getByLabel(rechits_labelEE_,rechit_EE_col);
136 
137 
138  edm::ESHandle<CaloGeometry> theGeometry;
139  edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle;
140  edm::ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle;
141  iSetup.get<CaloGeometryRecord>().get( theGeometry );
142  iSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap",theEndcapGeometry_handle);
143  iSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
144 
145  const CaloSubdetectorGeometry* theEndcapGeometry = theEndcapGeometry_handle.product();
146  const CaloSubdetectorGeometry* theBarrelGeometry = theBarrelGeometry_handle.product();
148  iSetup.get<IdealGeometryRecord>().get(eTTmap_);
149 
150  map<EcalTrigTowerDetId, float> mapTow_Et;
151 
152 
153  for (unsigned int i=0;i<rechit_EB_col.product()->size();i++) {
154  const EBDetId & myid1=(*rechit_EB_col.product())[i].id();
155  EcalTrigTowerDetId towid1= myid1.tower();
156  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
157  float Etsum=((*rechit_EB_col.product())[i].energy())*sin(theta);
158  bool test_alreadyin= false;
159  map<EcalTrigTowerDetId, float>::iterator ittest= mapTow_Et.find(towid1);
160  if (ittest!= mapTow_Et.end()) test_alreadyin=true;
161  if (test_alreadyin) continue;
162  unsigned int j=i+1;
163  bool loopend=false;
164  unsigned int count=0;
165  while( j<rechit_EB_col.product()->size() && !loopend){
166  count++;
167  const EBDetId & myid2=(*rechit_EB_col.product())[j].id();
168  EcalTrigTowerDetId towid2= myid2.tower();
169  if( towid1==towid2 ) {
170  float theta=theBarrelGeometry->getGeometry(myid2)->getPosition().theta();
171  Etsum += (*rechit_EB_col.product())[j].energy()*sin(theta);
172  }
173  j++;
174  if (count>1800) loopend=true;
175  }
176  mapTow_Et.insert(pair<EcalTrigTowerDetId,float>(towid1, Etsum));
177  }
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()) test_alreadyin=true;
188  if (test_alreadyin) continue;
189  unsigned int j=i+1;
190  bool loopend=false;
191  unsigned int count=0;
192  while( j<rechit_EE_col.product()->size() && !loopend){
193  const EEDetId & myid2=(*rechit_EE_col.product())[j].id();
194  EcalTrigTowerDetId towid2= (*eTTmap_).towerOf(myid2);
195  if( towid1==towid2 ) {
196  float theta=theEndcapGeometry->getGeometry(myid2)->getPosition().theta();
197  Etsum += (*rechit_EE_col.product())[j].energy()*sin(theta);
198  }
199  // else loopend=true;
200  j++;
201  if (count>500) loopend=true;
202  }
203  // alreadyin_EE.push_back(towid1);
204  mapTow_Et.insert(pair<EcalTrigTowerDetId,float>(towid1, Etsum));
205  }
206 
207 
208  EcalTPGScale ecalScale ;
209  ecalScale.setEventSetup(iSetup) ;
210  for (unsigned int i=0;i<tp.product()->size();i++) {
211  EcalTriggerPrimitiveDigi d=(*(tp.product()))[i];
212  const EcalTrigTowerDetId TPtowid= d.id();
213  map<EcalTrigTowerDetId, float>::iterator it= mapTow_Et.find(TPtowid);
214  float Et = ecalScale.getTPGInGeV(d.compressedEt(), TPtowid) ;
215  if (d.id().ietaAbs()==27 || d.id().ietaAbs()==28) Et*=2;
216  iphi_ = TPtowid.iphi() ;
217  ieta_ = TPtowid.ieta() ;
218  tpgADC_ = d.compressedEt() ;
219  tpgGeV_ = Et ;
220  ttf_ = d.ttFlag() ;
221  fg_ = d.fineGrain() ;
222  if (it!= mapTow_Et.end()) {
223  hTPvsRechit_->Fill(it->second,Et);
224  hTPoverRechit_->Fill(Et/it->second);
225  eRec_ = it->second ;
226  }
227  tree_->Fill() ;
228  }
229 
230 }
231 
232 void
234  for (unsigned int i=0;i<2;++i) {
235  ecal_et_[i]->Write();
236  ecal_tt_[i]->Write();
237  ecal_fgvb_[i]->Write();
238  }
239  if (recHits_) {
240  hTPvsRechit_->Write();
241  hTPoverRechit_->Write();
242  }
243 }
244 
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:230
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:59
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
EcalTrigPrimAnalyzer(const edm::ParameterSet &)
int iphi() const
get the tower iphi
const EcalTrigTowerDetId & id() const
T const * product() const
Definition: Handle.h:81
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.
const T & get() const
Definition: EventSetup.h:59
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
HLT enums.
size_type size() const
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