CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  if (recHits_) {
70  hTPvsTow_ieta_= new TH2F("TP_vs_Tow_ieta","TP vs Tow ieta ; i#eta(tow); i#eta(tp)",200,-100,100,200,-100,100);
71 
72  hTPvsRechit_= new TH2F("TP_vs_RecHit","TP vs rechit Et;E_{T}(rh) (GeV);E_{T}(tp) (GeV)",100,0,50,100,0,50);
73  hTPoverRechit_= new TH1F("TP_over_RecHit","Et(TP/rechit); E_{T}(tp)/E_{T}(rh); Counts",500,0,4);
74  hRechitEt_= new TH1F("RecHitEt","E_{T};E_{T}(rh) (GeV);Counts",100,0,50);
75  hTPEt_= new TH1F("TPEt","E_{T}{tp);E_{T}(rh) (GeV);Count",100,0,50);
76  hRatioEt_ = new TH1F("RatioTPoverRH","Et",100,0,50);
77  hAllRechitEt_= new TH1F("AllRecHit","Et",100,0,50);
78 
79  hTP_iphiVsieta_= new TH2F("TP_iphiVsieta","TP i#phi vs i#eta ; i#eta(tp); i#phi(tp)",10,70,80,10,340,350);
80  hRH_iphiVsieta_= new TH2F("RH_iphiVsieta","RH i#phi vs i#eta ; i#eta(rh); i#phi(rh)",10,70,80,10,340,350);
81  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);
82  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);
83 
84 
85  }
86 }
87 
88 
90 {
91 
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 
95  histfile_->Write();
96  histfile_->Close();
97 
98 }
99 
101  iSetup.get<IdealGeometryRecord>().get(eTTmap_);
102 }
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to analyze the data ------------
109 void
111 {
112  using namespace edm;
113  using namespace std;
114  nEvents_++;
115 
116  if ( nEvents_==1) this->init(iSetup);
117 
118  // Get input
120  iEvent.getByToken(primToken_,tp);
121  //
122  /*
123  edm::Handle<EBDigiCollection> barrelDigiHandle;
124  const EBDigiCollection *ebdigi=NULL;
125  iEvent.getByToken(tokenEBdigi_,barrelDigiHandle);
126  ebdigi=barrelDigiHandle.product();
127  */
128 
129 
130 
131  for (unsigned int i=0;i<tp.product()->size();i++) {
132  EcalEBTriggerPrimitiveDigi d=(*(tp.product()))[i];
133  int subdet=0;
134  if (subdet==0) {
135  ecal_et_[subdet]->Fill(d.compressedEt());
136  }
137  }
138  if (!recHits_) return;
139 
140  // comparison with RecHits
141  edm::Handle<EcalRecHitCollection> rechit_EB_col;
142  iEvent.getByToken(rechits_labelEB_,rechit_EB_col);
143 
144 
145  edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle;
146  iSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
147  const CaloSubdetectorGeometry *theBarrelGeometry;
148  theBarrelGeometry = &(*theBarrelGeometry_handle);
149 
150  if (debug_) 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;
151 
152  //if ( iEvent.id().event() != 648) return;
153 
154  //EcalEBTPGScale ecalScale ;
155  EcalTPGScale ecalScale ;
156  ecalScale.setEventSetup(iSetup) ;
157 
158 
159  // for(unsigned int iDigi = 0; iDigi < ebdigi->size() ; ++iDigi) {
160  // EBDataFrame myFrame((*ebdigi)[iDigi]);
161  // const EBDetId & myId = myFrame.id();
162 
163 
164  for (unsigned int i=0;i<tp.product()->size();i++) {
165  EcalEBTriggerPrimitiveDigi d=(*(tp.product()))[i];
166  const EBDetId TPid= d.id();
167  // if ( myId != TPid ) continue;
168 
169 
170  /*
171  int index=getIndex(ebdigi,coarser);
172  std::cout << " Same xTal " << myId << " " << TPid << " coarser " << coarser << " index " << index << std::endl;
173  double Et = ecalScale.getTPGInGeV(d.compressedEt(), coarser) ;
174  */
175  float Et=d.compressedEt()*0.5;
176  if ( Et==0) continue;
177 
178  // EcalTrigTowerDetId coarser=(*eTTmap_).towerOf(myId);
179  // does not work float etaTow = theBarrelGeometry->getGeometry(coarser)->getPosition().theta();
180  // float etaTP = theBarrelGeometry->getGeometry(TPid)->getPosition().eta();
181  // does not work hTPvsTow_eta_->Fill ( etaTow, etaTP );
182  // hTPvsTow_ieta_->Fill ( coarser.ieta(), TPid.ieta() );
183 
184 
185  tpIphi_ = TPid.iphi() ;
186  tpIeta_ = TPid.ieta() ;
187  tpgADC_ = d.compressedEt();
188  tpgGeV_ = Et ;
189 
190  hTP_iphiVsieta_->Fill(TPid.ieta(), TPid.iphi(), Et);
191  hTP_iphiVsieta_fullrange_->Fill(TPid.ieta(), TPid.iphi(), Et);
192 
193  for (unsigned int j=0;j<rechit_EB_col.product()->size();j++) {
194  const EBDetId & myid1=(*rechit_EB_col.product())[j].id();
195  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
196  float rhEt=((*rechit_EB_col.product())[j].energy())*sin(theta);
197  if ( myid1 == TPid ) {
198  if (debug_) std::cout << " Analyzer same cristal " << myid1 << " " << TPid << std::endl;
199  // if ( rhEt < 1.5 && Et > 10 ) {
200  // 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;
201  //std::cout << " TP compressed et " << d.compressedEt() << " Et in GeV " << Et << " RH Et " << rhEt << " Et/rhEt " << Et/rhEt << std::endl;
202  //}
203 
204  //std::cout << " TP out " << d << std::endl;
205 
206  // for (int isam=0;isam< d.size();++isam) {
207  // std::cout << " d[isam].raw() " << d[isam].raw() << std::endl;
208  //}
209 
210  rhIphi_ = myid1.iphi() ;
211  rhIeta_ = myid1.ieta() ;
212  hRH_iphiVsieta_->Fill(myid1.ieta(), myid1.iphi(), rhEt);
213  hRH_iphiVsieta_fullrange_->Fill(myid1.ieta(), myid1.iphi(), rhEt);
214 
215  hTPvsRechit_->Fill(rhEt,Et);
216  hTPoverRechit_->Fill(Et/rhEt);
217  if (debug_) std::cout << " TP compressed et " << d.compressedEt() << " Et in GeV " << Et << " RH Et " << rhEt << " Et/rhEt " << Et/rhEt << std::endl;
218  hRechitEt_->Fill(rhEt);
219  hTPEt_->Fill(Et);
220  if ( rhEt < 1000000) eRec_ = rhEt;
221  tree_->Fill() ;
222  }
223 
224  }
225 
226  } // end loop over TP collection
227 
228  // } // end loop over digi collection
229 
230  hRatioEt_->Divide( hTPEt_, hRechitEt_);
231 
232  for (unsigned int j=0;j<rechit_EB_col.product()->size();j++) {
233  const EBDetId & myid1=(*rechit_EB_col.product())[j].id();
234  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
235  float rhEt=((*rechit_EB_col.product())[j].energy())*sin(theta);
236  if ( rhEt >0 )
237  hAllRechitEt_ ->Fill(rhEt);
238  }
239 
240 
241 
242 }
243 
244 void
246  for (unsigned int i=0;i<ecal_parts_.size();++i) {
247  ecal_et_[i]->Write();
248  ecal_tt_[i]->Write();
249  ecal_fgvb_[i]->Write();
250  }
251 
252 
253  if (recHits_) {
254  hTPvsTow_ieta_->Write();
255  hTPvsTow_eta_->Write();
256  hTPvsRechit_->Write();
257  hTPoverRechit_->Write();
258  hAllRechitEt_->Write();
259  hRechitEt_->Write();
260  hTPEt_->Write();
261  hRatioEt_->Write();
262  hTP_iphiVsieta_->Write();
263  hRH_iphiVsieta_->Write();
264  hTP_iphiVsieta_fullrange_->Write();
265  hRH_iphiVsieta_fullrange_->Write();
266 
267  }
268 }
269 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:19
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
int compressedEt() const
get the encoded/compressed Et of interesting sample
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
tuple d
Definition: ztail.py:151
int iEvent
Definition: GenABIO.cc:230
int j
Definition: DBlmapReader.cc:9
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
EcalEBTrigPrimAnalyzer(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:56
edm::EventID id() const
Definition: EventBase.h:58
tuple cout
Definition: gather_cfg.py:145
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
void init(const edm::EventSetup &)