CMS 3D CMS Logo

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