CMS 3D CMS Logo

EcalEBTrigPrimAnalyzer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <utility>
4 
5 // user include files
9 
14 
16 
19 
24 
25 //#include "CalibCalorimetry/EcalTPGTools/interface/EcalEBTPGScale.h"
27 
28 #include "EcalEBTrigPrimAnalyzer.h"
29 
30 #include <TMath.h>
31 
32 using namespace edm;
34 
36 
37 {
38  ecal_parts_.push_back("Barrel");
39 
40  histfile_=new TFile("histos.root","RECREATE");
41  tree_ = new TTree("TPGtree","TPGtree");
42  tree_->Branch("tpIphi",&tpIphi_,"tpIphi/I");
43  tree_->Branch("tpIeta",&tpIeta_,"tpIeta/I");
44  tree_->Branch("rhIphi",&rhIphi_,"rhIphi/I");
45  tree_->Branch("rhIeta",&rhIeta_,"rhIeta/I");
46  tree_->Branch("eRec",&eRec_,"eRec/F");
47  tree_->Branch("tpgADC",&tpgADC_,"tpgADC/I");
48  tree_->Branch("tpgGeV",&tpgGeV_,"tpgGeV/F");
49  tree_->Branch("ttf",&ttf_,"ttf/I");
50  tree_->Branch("fg",&fg_,"fg/I");
51  for (unsigned int i=0;i<ecal_parts_.size();++i) {
52  char title[30];
53  sprintf(title,"%s_Et",ecal_parts_[i].c_str());
54  ecal_et_[i]=new TH1I(title,"Et",255,0,255);
55  sprintf(title,"%s_ttf",ecal_parts_[i].c_str());
56  ecal_tt_[i]=new TH1I(title,"TTF",10,0,10);
57  sprintf(title,"%s_fgvb",ecal_parts_[i].c_str());
58  ecal_fgvb_[i]=new TH1I(title,"FGVB",10,0,10);
59  }
60 
61  recHits_= iConfig.getParameter<bool>("AnalyzeRecHits");
62  debug_= iConfig.getParameter<bool>("Debug");
63  rechits_labelEB_=consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("inputRecHitsEB"));
64  primToken_=consumes<EcalEBTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("inputTP"));
65  tokenEBdigi_=consumes<EBDigiCollection>(iConfig.getParameter<edm::InputTag>("barrelEcalDigis"));
66  nEvents_=0;
67 
68  hTPvsTow_eta_= new TH2F("TP_vs_Tow_eta","TP vs Tow eta ; #eta(tow); #eta(tp)",50,-2.5,2.5,50,-2.5,2.5);
69  hAllTPperEvt_ = new TH1F("AllTPperEvt","TP per Event; N_{TP}; ", 100, 0., 20000.);
70  hTPperEvt_ = new TH1F("TPperEvt","N_{TP} per Event; N_{TP}; ", 100, 0., 500.);
71  hTP_iphiVsieta_= new TH2F("TP_iphiVsieta","TP i#phi vs i#eta ; i#eta(tp); i#phi(tp)",10,70,80,10,340,350);
72  hTP_iphiVsieta_fullrange_= new TH2F("TP_iphiVsieta_fullrange","TP i#phi vs i#eta ; i#eta(tp); i#phi(tp)",200,-100,100,350,0,350);
73 
74  if (recHits_) {
75  hTPvsTow_ieta_= new TH2F("TP_vs_Tow_ieta","TP vs Tow ieta ; i#eta(tow); i#eta(tp)",200,-100,100,200,-100,100);
76 
77  hTPvsRechit_= new TH2F("TP_vs_RecHit","TP vs rechit Et;E_{T}(rh) (GeV);E_{T}(tp) (GeV)",100,0,50,100,0,50);
78  hDeltaEt_ = new TH1F("DeltaEt","[Et(rh)-Et(TP)]/Et(rh); [E_{T}(rh)-E_{T}(tp)]/E_{T}(rh); Counts",200,-1,1);
79  hTPoverRechit_= new TH1F("TP_over_RecHit","Et(TP/rechit); E_{T}(tp)/E_{T}(rh); Counts",200,0,2);
80  hRechitEt_= new TH1F("RecHitEt","E_{T};E_{T}(rh) (GeV);Counts",100,0,50);
81  hTPEt_= new TH1F("TPEt","E_{T}{tp);E_{T}(rh) (GeV);Count",100,0,50);
82  hRatioEt_ = new TH1F("RatioTPoverRH","Et",100,0,50);
83  hAllRechitEt_= new TH1F("AllRecHit","Et",100,0,50);
84 
85  hRH_iphiVsieta_= new TH2F("RH_iphiVsieta","RH i#phi vs i#eta ; i#eta(rh); i#phi(rh)",10,70,80,10,340,350);
86  hRH_iphiVsieta_fullrange_= new TH2F("RH_iphiVsieta_fullrange","RH i#phi vs i#eta ; i#eta(rh); i#phi(rh)",200,-100,100,350,0,350);
87 
88 
89  }
90 }
91 
92 
94 {
95 
96  // do anything here that needs to be done at desctruction time
97  // (e.g. close files, deallocate resources etc.)
98 
99  histfile_->Write();
100  histfile_->Close();
101 
102 }
103 
105  iSetup.get<IdealGeometryRecord>().get(eTTmap_);
106 }
107 
108 //
109 // member functions
110 //
111 
112 // ------------ method called to analyze the data ------------
113 void
115 {
116  using namespace edm;
117  using namespace std;
118  nEvents_++;
119 
120  if ( nEvents_==1) this->init(iSetup);
121 
122  // Get input
124  iEvent.getByToken(primToken_,tp);
125  //
126  /*
127  edm::Handle<EBDigiCollection> barrelDigiHandle;
128  const EBDigiCollection *ebdigi=NULL;
129  iEvent.getByToken(tokenEBdigi_,barrelDigiHandle);
130  ebdigi=barrelDigiHandle.product();
131  */
132 
133 
134 
135  for (unsigned int i=0;i<tp.product()->size();i++) {
137  int subdet=0;
138  if (subdet==0) {
139  ecal_et_[subdet]->Fill(d.encodedEt());
140  }
141  }
142 
143 
144  // if (!recHits_) return;
145 
146  edm::Handle<EcalRecHitCollection> rechit_EB_col;
147  if ( recHits_ ) {
148  // get the RecHits
149  iEvent.getByToken(rechits_labelEB_,rechit_EB_col);
150  }
151 
152  edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle;
153  iSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
154  const CaloSubdetectorGeometry *theBarrelGeometry = theBarrelGeometry_handle.product();
155 
156  if (debug_) { std::cout << " TP analyzer =================> Treating event "<<iEvent.id() << " Number of TPs " << tp.product()->size() << std::endl;
157  if ( recHits_ ) std::cout << " Number of EB rechits "<< rechit_EB_col.product()->size() << std::endl;
158  }
159  hAllTPperEvt_->Fill(float(tp.product()->size()));
160 
161  //if ( iEvent.id().event() != 648) return;
162 
163  //EcalEBTPGScale ecalScale ;
164  EcalTPGScale ecalScale ;
165  ecalScale.setEventSetup(iSetup) ;
166 
167 
168  // for(unsigned int iDigi = 0; iDigi < ebdigi->size() ; ++iDigi) {
169  // EBDataFrame myFrame((*ebdigi)[iDigi]);
170  // const EBDetId & myId = myFrame.id();
171 
172  int nTP=0;
173  for (unsigned int i=0;i<tp.product()->size();i++) {
175  const EBDetId TPid= d.id();
176  // if ( myId != TPid ) continue;
177 
178 
179  /*
180  int index=getIndex(ebdigi,coarser);
181  std::cout << " Same xTal " << myId << " " << TPid << " coarser " << coarser << " index " << index << std::endl;
182  double Et = ecalScale.getTPGInGeV(d.encodedEt(), coarser) ;
183  */
184  //this works if the energy is compressed into 8 bits float Et=d.compressedEt()/2.; // 2ADC counts/GeV
185  float Et=d.encodedEt()/8.; // 8 ADCcounts/GeV
186  if ( Et<= 5 ) continue;
187  //if ( Et<= 0 ) continue;
188  nTP++;
189 
190  std::cout << " TP digi size " << d.size() << std::endl;
191  for (int iBx=0;iBx<d.size();iBx++) {
192  std::cout << " TP samples " << d.sample(iBx) << std::endl;
193 
194  }
195 
196  // EcalTrigTowerDetId coarser=(*eTTmap_).towerOf(myId);
197  // does not work float etaTow = theBarrelGeometry->getGeometry(coarser)->getPosition().theta();
198  // float etaTP = theBarrelGeometry->getGeometry(TPid)->getPosition().eta();
199  // does not work hTPvsTow_eta_->Fill ( etaTow, etaTP );
200  // hTPvsTow_ieta_->Fill ( coarser.ieta(), TPid.ieta() );
201 
202 
203  tpIphi_ = TPid.iphi() ;
204  tpIeta_ = TPid.ieta() ;
205  tpgADC_ = d.encodedEt();
206  tpgGeV_ = Et ;
207 
208  hTP_iphiVsieta_->Fill(TPid.ieta(), TPid.iphi(), Et);
209  hTP_iphiVsieta_fullrange_->Fill(TPid.ieta(), TPid.iphi(), Et);
210 
211 
212  if ( recHits_ ) {
213  for (unsigned int j=0;j<rechit_EB_col.product()->size();j++) {
214  const EBDetId & myid1=(*rechit_EB_col.product())[j].id();
215  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
216  float rhEt=((*rechit_EB_col.product())[j].energy())*sin(theta);
217  if ( myid1 == TPid ) {
218  if (debug_) std::cout << " Analyzer same cristal " << myid1 << " " << TPid << std::endl;
219  // if ( rhEt < 1.5 && Et > 10 ) {
220  // std::cout << " TP analyzer =================> Treating event "<<iEvent.id()<< ", Number of EB rechits "<< rechit_EB_col.product()->size() << " Number of TPs " << tp.product()->size() << std::endl;
221  //std::cout << " TP compressed et " << d.encodedEt() << " Et in GeV " << Et << " RH Et " << rhEt << " Et/rhEt " << Et/rhEt << std::endl;
222  //}
223 
224  //std::cout << " TP out " << d << std::endl;
225 
226  // for (int isam=0;isam< d.size();++isam) {
227  // std::cout << " d[isam].raw() " << d[isam].raw() << std::endl;
228  //}
229 
230  rhIphi_ = myid1.iphi() ;
231  rhIeta_ = myid1.ieta() ;
232  hRH_iphiVsieta_->Fill(myid1.ieta(), myid1.iphi(), rhEt);
233  hRH_iphiVsieta_fullrange_->Fill(myid1.ieta(), myid1.iphi(), rhEt);
234 
235  hTPvsRechit_->Fill(rhEt,Et);
236  hTPoverRechit_->Fill(Et/rhEt);
237  hDeltaEt_ ->Fill ((rhEt-Et)/rhEt);
238  if (debug_) std::cout << " TP compressed et " << d.encodedEt() << " Et in GeV " << Et << " RH Et " << rhEt << " Et/rhEt " << Et/rhEt << std::endl;
239  hRechitEt_->Fill(rhEt);
240  hTPEt_->Fill(Et);
241  if ( rhEt < 1000000) eRec_ = rhEt;
242  tree_->Fill() ;
243  }
244 
245  } // end loop of recHits
246  } // if recHits
247 
248  } // end loop over TP collection
249 
250  // } // end loop over digi collection
251 
252  hTPperEvt_->Fill(float(nTP));
253 
254  if ( recHits_) {
255  hRatioEt_->Divide( hTPEt_, hRechitEt_);
256  for (unsigned int j=0;j<rechit_EB_col.product()->size();j++) {
257  const EBDetId & myid1=(*rechit_EB_col.product())[j].id();
258  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
259  float rhEt=((*rechit_EB_col.product())[j].energy())*sin(theta);
260  if ( rhEt >0 )
261  hAllRechitEt_ ->Fill(rhEt);
262  }
263  }
264 
265 
266 }
267 
268 void
270  for (unsigned int i=0;i<ecal_parts_.size();++i) {
271  ecal_et_[i]->Write();
272  ecal_tt_[i]->Write();
273  ecal_fgvb_[i]->Write();
274  }
275 
276 
277  hAllTPperEvt_->Write();
278  hTPperEvt_->Write();
279 
280  if (recHits_) {
281  hTPvsTow_ieta_->Write();
282  hTPvsTow_eta_->Write();
283  hTPvsRechit_->Write();
284  hTPoverRechit_->Write();
285  hAllRechitEt_->Write();
286  hRechitEt_->Write();
287  hDeltaEt_ ->Write();
288  hTPEt_->Write();
289  hRatioEt_->Write();
290  hTP_iphiVsieta_->Write();
291  hRH_iphiVsieta_->Write();
292  hTP_iphiVsieta_fullrange_->Write();
293  hRH_iphiVsieta_fullrange_->Write();
294 
295  }
296 }
297 
T getParameter(std::string const &) const
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:19
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
int init
Definition: HydjetWrapper.h:67
Geom::Theta< T > theta() const
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
int iEvent
Definition: GenABIO.cc:230
const EcalEBTriggerPrimitiveSample & sample(int i) const
int encodedEt() const
get the 10 bits Et of interesting sample
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
EcalEBTrigPrimAnalyzer(const edm::ParameterSet &)
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.
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:62
void analyze(const edm::Event &, const edm::EventSetup &) override
void init(const edm::EventSetup &)
T const * product() const
Definition: ESHandle.h:86