CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTrigPrimAnalyzerMIPs.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: EcalTrigPrimAnalyzerMIPs
4 //
5 //
6 // Original Author: Pascal Paganini
7 //
8 //
9 
10 
11 // system include files
12 #include <memory>
13 #include <utility>
14 
15 // user include files
19 
23 
31 
37 
39 
41 
42 #include <TMath.h>
43 
44 using namespace edm;
46 
48  : nevt_(0)
49 {
50  label_= iConfig.getParameter<std::string>("Label");
51  producer_= iConfig.getParameter<std::string>("Producer");
52  digi_label_= iConfig.getParameter<std::string>("DigiLabel");
53  digi_producer_= iConfig.getParameter<std::string>("DigiProducer");
54  emul_label_= iConfig.getParameter<std::string>("EmulLabel");
55  emul_producer_= iConfig.getParameter<std::string>("EmulProducer");
56 
57 
58  histfile_ = new TFile("histos.root","RECREATE");
59 
60  // general tree
61  tree_ = new TTree("TPGtree","TPGtree");
62  tree_->Branch("iphi",&iphi_,"iphi/I");
63  tree_->Branch("ieta",&ieta_,"ieta/I");
64  tree_->Branch("eRec",&eRec_,"eRec/F");
65  tree_->Branch("mean",&mean_,"mean/F");
66  tree_->Branch("data0",&data0_,"data0/F");
67  tree_->Branch("data1",&data1_,"data1/F");
68  tree_->Branch("data2",&data2_,"data2/F");
69  tree_->Branch("data3",&data3_,"data3/F");
70  tree_->Branch("data4",&data4_,"data4/F");
71  tree_->Branch("data5",&data5_,"data5/F");
72  tree_->Branch("data6",&data6_,"data6/F");
73  tree_->Branch("data7",&data7_,"data7/F");
74  tree_->Branch("data8",&data8_,"data8/F");
75  tree_->Branch("data9",&data9_,"data9/F");
76  tree_->Branch("tpgADC",&tpgADC_,"tpgADC/I");
77  tree_->Branch("tpgGeV",&tpgGeV_,"tpgGeV/F");
78  tree_->Branch("tpgEmul0",&tpgEmul0_,"tpgEmul0/I");
79  tree_->Branch("tpgEmul1",&tpgEmul1_,"tpgEmul1/I");
80  tree_->Branch("tpgEmul2",&tpgEmul2_,"tpgEmul2/I");
81  tree_->Branch("tpgEmul3",&tpgEmul3_,"tpgEmul3/I");
82  tree_->Branch("tpgEmul4",&tpgEmul4_,"tpgEmul4/I");
83  tree_->Branch("ttf",&ttf_,"ttf/I");
84  tree_->Branch("fg",&fg_,"fg/I");
85  tree_->Branch("nevt",&nevt_,"nevt/I");
86  tree_->Branch("nXtal",&nXtal_,"nXtal/I");
87  tree_->Branch("sample",&sample_,"sample/F");
88 
89  // tree to analyze missing FEDs
90  fedtree_ = new TTree("fedtree","fedtree");
91  fedtree_->Branch("fedId",&fedId_,"fedId/I");
92  fedtree_->Branch("fedSize",&fedSize_,"fedSize/I");
93 
94  // tree for TOP-Bottom coincidence
95  treetopbot_ = new TTree("topbottree", "topbottree") ;
96  treetopbot_->Branch("nevt",&nevt_,"nevt/I");
97  treetopbot_->Branch("iphitop",&iphitop_,"iphitop/I");
98  treetopbot_->Branch("ietatop",&ietatop_,"ietatop/I");
99  treetopbot_->Branch("Etop",&Etop_,"Etop/F");
100  treetopbot_->Branch("Ntop",&Ntop_,"Ntop/I");
101  treetopbot_->Branch("iphibot",&iphibot_,"iphibot/I");
102  treetopbot_->Branch("ietabot",&ietabot_,"ietabot/I");
103  treetopbot_->Branch("Ebot",&Ebot_,"Ebot/F");
104  treetopbot_->Branch("Nbot",&Nbot_,"Nbot/I");
105 
106 }
107 
108 
110 {
111  histfile_->Write();
112  histfile_->Close();
113 }
114 
115 
116 //
117 // member functions
118 //
119 
120 // ------------ method called to analyze the data ------------
122 {
123  using namespace edm;
124  using namespace std;
125 
126 
127 
129  iEvent.getByType(rawdata);
130  for (int id= 0; id<=FEDNumbering::MAXFEDID; ++id){
131  if (id < 600 || id > 654) continue;
132  const FEDRawData& data = rawdata->FEDData(id);
133  fedId_ = id ;
134  fedSize_ = data.size() ;
135  fedtree_->Fill() ;
136  }
137 
138 
139  map<EcalTrigTowerDetId, towerEner> mapTower ;
140  map<EcalTrigTowerDetId, towerEner>::iterator itTT ;
141 
142  // Get digi input
144  iEvent.getByLabel(digi_label_, digi_producer_, digi);
145  for (unsigned int i=0;i<digi.product()->size();i++) {
146  const EBDataFrame & df = (*(digi.product()))[i];
147 
148  int gain, adc ;
149  float E_xtal = 0. ;
150  int theSamp = 0 ;
151  float mean = 0., max = -999 ;
152  for (int samp = 0 ; samp<10 ; samp++) {
153  adc = df[samp].adc() ;
154  if (samp<2) mean += adc ;
155  if (adc>max) {
156  max = adc ;
157  theSamp = samp ;
158  }
159  }
160  mean /= 2 ;
161  if (mean>0 && max > mean + 10) {
162  gain = df[theSamp].gainId() ;
163  adc = df[theSamp].adc() ;
164  if (gain == 1) E_xtal = (adc-mean) ;
165  if (gain == 2) E_xtal = 2.*(adc-mean) ;
166  if (gain == 3) E_xtal = 12.*(adc-mean) ;
167  if (gain == 0) E_xtal = 12.*(adc-mean) ;
168  }
169  const EBDetId & id=df.id();
170  const EcalTrigTowerDetId towid= id.tower();
171  itTT = mapTower.find(towid) ;
172  if (itTT != mapTower.end()) {
173  (itTT->second).eRec_ += E_xtal ;
174  (itTT->second).sample_ += E_xtal*theSamp ;
175  for (int samp = 0 ; samp<10 ; samp++) (itTT->second).data_[samp] += df[samp].adc()-mean ;
176  if (E_xtal != 0) {
177  (itTT->second).nXtal_ ++ ;
178  (itTT->second).mean_ += mean ;
179  }
180  }
181  else {
182  towerEner tE ;
183  tE.eRec_ = E_xtal ;
184  tE.sample_ += E_xtal*theSamp ;
185  for (int samp = 0 ; samp<10 ; samp++) tE.data_[samp] = df[samp].adc()-mean ;
186  if (E_xtal != 0) {
187  tE.nXtal_ ++ ;
188  tE.mean_ = mean ;
189  }
190  mapTower[towid] = tE ;
191  }
192  }
193 
194 
195 
196  // Get Emulators TP
198  iEvent.getByLabel(emul_label_, emul_producer_, tpEmul);
199  for (unsigned int i=0;i<tpEmul.product()->size();i++) {
200  EcalTriggerPrimitiveDigi d = (*(tpEmul.product()))[i];
201  const EcalTrigTowerDetId TPtowid= d.id();
202  itTT = mapTower.find(TPtowid) ;
203 
204  if (itTT != mapTower.end()) {
205  (itTT->second).tpgEmul0_ = (d[0].raw() & 0x1ff) ;
206  (itTT->second).tpgEmul1_ = (d[1].raw() & 0x1ff) ;
207  (itTT->second).tpgEmul2_ = (d[2].raw() & 0x1ff) ;
208  (itTT->second).tpgEmul3_ = (d[3].raw() & 0x1ff) ;
209  (itTT->second).tpgEmul4_ = (d[4].raw() & 0x1ff) ;
210  }
211  else {
212  towerEner tE ;
213  tE.tpgEmul0_ = (d[0].raw() & 0x1ff) ;
214  tE.tpgEmul1_ = (d[1].raw() & 0x1ff) ;
215  tE.tpgEmul2_ = (d[2].raw() & 0x1ff) ;
216  tE.tpgEmul3_ = (d[3].raw() & 0x1ff) ;
217  tE.tpgEmul4_ = (d[4].raw() & 0x1ff) ;
218  mapTower[TPtowid] = tE ;
219  }
220  }
221 
222 
223 
224  // Get TP data
226  iEvent.getByLabel(label_,producer_,tp);
227  EcalTPGScale ecalScale;
228  ecalScale.setEventSetup(iSetup) ;
229  for (unsigned int i=0;i<tp.product()->size();i++) {
230  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
231  const EcalTrigTowerDetId TPtowid= d.id();
232  float Et = ecalScale.getTPGInGeV(d) ;
233  if (d.id().ietaAbs()==27 || d.id().ietaAbs()==28) Et*=2;
234 
235  itTT = mapTower.find(TPtowid) ;
236  if (itTT != mapTower.end()) {
237  (itTT->second).iphi_ = TPtowid.iphi() ;
238  (itTT->second).ieta_ = TPtowid.ieta() ;
239  (itTT->second).tpgADC_ = d.compressedEt() ;
240  (itTT->second).tpgGeV_ = Et ;
241  (itTT->second).ttf_ = d.ttFlag() ;
242  (itTT->second).fg_ = d.fineGrain() ;
243  }
244  else {
245  towerEner tE ;
246  tE.iphi_ = TPtowid.iphi() ;
247  tE.ieta_ = TPtowid.ieta() ;
248  tE.tpgADC_ = d.compressedEt() ;
249  tE.tpgGeV_ = Et ;
250  tE.ttf_ = d.ttFlag() ;
251  tE.fg_ = d.fineGrain() ;
252  mapTower[TPtowid] = tE ;
253  }
254 
255  }
256 
257 
258 
259  // fill tree
260  if (mapTower.size()>0) nevt_++ ;
261  for (itTT = mapTower.begin() ; itTT != mapTower.end() ; ++itTT ) {
262  iphi_ = (itTT->second).iphi_ ;
263  ieta_ = (itTT->second).ieta_ ;
264  tpgADC_ = (itTT->second).tpgADC_ ;
265  tpgGeV_ = (itTT->second).tpgGeV_ ;
266  tpgEmul0_ = (itTT->second).tpgEmul0_ ;
267  tpgEmul1_ = (itTT->second).tpgEmul1_ ;
268  tpgEmul2_ = (itTT->second).tpgEmul2_ ;
269  tpgEmul3_ = (itTT->second).tpgEmul3_ ;
270  tpgEmul4_ = (itTT->second).tpgEmul4_ ;
271  ttf_ = (itTT->second).ttf_ ;
272  fg_ = (itTT->second).fg_ ;
273  eRec_ = (itTT->second).eRec_ ;
274  mean_ = (itTT->second).mean_ ;
275  data0_ = (itTT->second).data_[0] ;
276  data1_ = (itTT->second).data_[1] ;
277  data2_ = (itTT->second).data_[2] ;
278  data3_ = (itTT->second).data_[3] ;
279  data4_ = (itTT->second).data_[4] ;
280  data5_ = (itTT->second).data_[5] ;
281  data6_ = (itTT->second).data_[6] ;
282  data7_ = (itTT->second).data_[7] ;
283  data8_ = (itTT->second).data_[8] ;
284  data9_ = (itTT->second).data_[9] ;
285  nXtal_ = (itTT->second).nXtal_ ;
286  sample_ = 0 ;
287  if (eRec_>0) sample_ = (itTT->second).sample_/eRec_ ;
288  tree_->Fill() ;
289 
290 // int maxtpg = 0 ;
291 // if (tpgEmul0_ > tpgEmul1_ && tpgEmul0_ > tpgEmul2_ && tpgEmul0_ > tpgEmul3_ && tpgEmul0_ > tpgEmul4_) maxtpg = tpgEmul0_ ;
292 // if (tpgEmul1_ > tpgEmul0_ && tpgEmul1_ > tpgEmul2_ && tpgEmul1_ > tpgEmul3_ && tpgEmul1_ > tpgEmul4_) maxtpg = tpgEmul1_ ;
293 // if (tpgEmul2_ > tpgEmul1_ && tpgEmul2_ > tpgEmul0_ && tpgEmul2_ > tpgEmul3_ && tpgEmul2_ > tpgEmul4_) maxtpg = tpgEmul2_ ;
294 // if (tpgEmul3_ > tpgEmul1_ && tpgEmul3_ > tpgEmul2_ && tpgEmul3_ > tpgEmul0_ && tpgEmul3_ > tpgEmul4_) maxtpg = tpgEmul3_ ;
295 // if (tpgEmul4_ > tpgEmul1_ && tpgEmul4_ > tpgEmul2_ && tpgEmul4_ > tpgEmul3_ && tpgEmul4_ > tpgEmul0_) maxtpg = tpgEmul4_ ;
296 
297 // if (maxtpg>=40) {
298 
299 // int phiArray[19] = {19, 11, 12, 55, 56, 57, 58, 51, 52, 53, 54, 55, 56, 57, 58, 15, 16, 17, 18} ;
300 // int etaArray[19] = {15, 9, 9, 12, 12, 12, 12, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6} ;
301 
302 // for (int bad=0 ; bad<19 ; bad++) {
303 
304 // if (iphi_==phiArray[bad] && ieta_==etaArray[bad]) {
305 // std::cout<<"nevt "<<nevt_<<" "<<iphi_<<" "<<ieta_<<std::endl ;
306 
307 // float max = 0. ;
308 // int xtal_iphi = 0, xtal_ieta = 0, xtal_ic = 0, xtal_sm = 0 ;
309 // for (unsigned int i=0;i<digi.product()->size();i++) {
310 // const EBDataFrame & df = (*(digi.product()))[i];
311 // const EBDetId & id=df.id();
312 // const EcalTrigTowerDetId towid= id.tower();
313 // if (towid.iphi()== phiArray[bad] && towid.ieta()== etaArray[bad]) {
314 
315 // float mean = (df[0].adc()+df[1].adc())/2. ;
316 // float adc = 0. ;
317 // for (int s=0 ; s<10 ; s++) if (df[s].adc() > adc) adc = df[s].adc() ;
318 // adc -= mean ;
319 
320 // if (adc>max) {
321 // max = adc ;
322 // xtal_iphi = id.iphi() ;
323 // xtal_ieta = id.ieta() ;
324 // xtal_ic = id.ic() ;
325 // xtal_sm = id.ism() ;
326 // }
327 
328 // }
329 // }
330 // std::cout<<xtal_iphi<<" "<<xtal_ieta<<" "<<xtal_ic<<" "<<xtal_sm<<" "<<max<<std::endl ;
331 // }
332 // }
333 // }
334 
335 
336  }
337 
338 
339 // trying to find coincidence :
340  float E_max_top = 0., E_max_bot = 0.;
341  EBDetId idRef_top, idRef_bot ;
342  for (unsigned int i=0;i<digi.product()->size();i++) {
343  const EBDataFrame & df = (*(digi.product()))[i];
344  const EBDetId & id=df.id();
345  const EcalTrigTowerDetId towid= id.tower();
346 
347  // lets's exclude noisy tower:
348  bool good(true) ;
349  if (towid.ieta() == 15 && towid.iphi() == 19) good = false ;
350  if (towid.ieta() == 9 && towid.iphi() == 11) good = false ;
351  if (towid.ieta() == 9 && towid.iphi() == 12) good = false ;
352  if (towid.ieta() == 12 && towid.iphi()>54 && towid.iphi()<59) good = false ;
353  if (towid.ieta() == 5 && towid.iphi()>50 && towid.iphi()<55) good = false ;
354  if (towid.ieta() == 6 && towid.iphi()>54 && towid.iphi()<59) good = false ;
355  if (towid.ieta() == 6 && towid.iphi()>14 && towid.iphi()<19) good = false ;
356 
357  if (good) {
358 
359  // top:
360  if (id.ism() >= 4 && id.ism() <= 7) {
361  // get the most energetic xtal:
362  int adc ;
363  float E_xtal = 0. ;
364  float mean = 0.5*(df[0].adc()+df[1].adc()) ;
365  float max = -999 ;
366  for (int samp = 0 ; samp<10 ; samp++) {
367  adc = df[samp].adc() ;
368  if (adc>max) max = adc ;
369  }
370  if (mean>0 && max > mean + 10) E_xtal = (adc-mean) ;
371  if (E_xtal > E_max_top) {
372  E_max_top = E_xtal ;
373  idRef_top = id ;
374  }
375  }
376 
377  // bottom:
378  if (id.ism() >= 14 && id.ism() <= 16) {
379  int adc ;
380  float E_xtal = 0. ;
381  float mean = 0.5*(df[0].adc()+df[1].adc()) ;
382  float max = -999 ;
383  for (int samp = 0 ; samp<10 ; samp++) {
384  adc = df[samp].adc() ;
385  if (adc>max) max = adc ;
386  }
387  if (mean>0 && max > mean + 10) E_xtal = (adc-mean) ;
388  if (E_xtal > E_max_bot) {
389  E_max_bot = E_xtal ;
390  idRef_bot = id ;
391  }
392  }
393 
394  }
395  }
396  if (E_max_top >0 && E_max_bot>0) {
397  std::cout<<nevt_<<std::endl ;
398  std::cout<<idRef_top.iphi()<<" "<<idRef_top.ieta()<<" "<<idRef_top.ic()<<" "<<idRef_top.ism()<<" "<<E_max_top<<std::endl ;
399  std::cout<<idRef_bot.iphi()<<" "<<idRef_bot.ieta()<<" "<<idRef_bot.ic()<<" "<<idRef_bot.ism()<<" "<<E_max_bot<<std::endl ;
400 
401  // now lets make a 3x3 window
402  int rangePhitop[3] = {idRef_top.iphi()-1, idRef_top.iphi(), idRef_top.iphi()+1} ;
403  int rangeEtatop[3] = {idRef_top.ieta()-1, idRef_top.ieta(), idRef_top.ieta()+1} ;
404  int rangePhibot[3] = {idRef_bot.iphi()-1, idRef_bot.iphi(), idRef_bot.iphi()+1} ;
405  int rangeEtabot[3] = {idRef_bot.ieta()-1, idRef_bot.ieta(), idRef_bot.ieta()+1} ;
406  for (int i=0 ; i<3 ; i++) {
407  if (rangePhitop[i] <= 0) rangePhitop[i] += 360 ;
408  if (rangePhitop[i] > 360) rangePhitop[i] -= 360 ;
409  if (rangeEtatop[i] <= 0 || rangeEtatop[i]>85) rangeEtatop[i] = 999999 ;
410  if (rangePhibot[i] <= 0) rangePhibot[i] += 360 ;
411  if (rangePhibot[i] > 360) rangePhibot[i] -= 360 ;
412  if (rangeEtabot[i] <= 0 || rangeEtabot[i]>85) rangeEtabot[i] = 999999 ;
413  }
414 
415  Etop_ = 0. ;
416  Ebot_ = 0. ;
417  Ntop_ = 0 ;
418  Nbot_ = 0 ;
419  for (unsigned int i=0;i<digi.product()->size();i++) {
420  const EBDataFrame & df = (*(digi.product()))[i];
421  const EBDetId & id=df.id();
422  int adc ;
423  float E_xtal = 0. ;
424  float mean = 0.5*(df[0].adc()+df[1].adc()) ;
425  float max = -999 ;
426  for (int samp = 0 ; samp<10 ; samp++) {
427  adc = df[samp].adc() ;
428  if (adc>max) max = adc ;
429  }
430  E_xtal = (adc-mean) ;
431 
432  for (int phiIndex=0 ; phiIndex<3 ; phiIndex++)
433  for (int etaIndex = 0 ; etaIndex<3 ; etaIndex++) {
434  if (id.iphi() == rangePhitop[phiIndex] && id.ieta() == rangeEtatop[etaIndex]) {
435  Etop_ += E_xtal ;
436  Ntop_ ++ ;
437  }
438  if (id.iphi() == rangePhibot[phiIndex] && id.ieta() == rangeEtabot[etaIndex]) {
439  Ebot_ += E_xtal ;
440  Nbot_ ++ ;
441  }
442  }
443  }
444 
445  iphitop_ = idRef_top.iphi() ;
446  ietatop_ = idRef_top.ieta() ;
447  iphibot_ = idRef_bot.iphi() ;
448  ietabot_ = idRef_bot.ieta() ;
449  treetopbot_->Fill() ;
450  }
451 
452 }
453 
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
key_type id() const
Definition: EBDataFrame.h:32
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:19
bool getByType(Handle< PROD > &result) const
Definition: Event.h:398
EcalTrigPrimAnalyzerMIPs(const edm::ParameterSet &)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
int ieta() const
get the tower ieta
int compressedEt() const
get the encoded/compressed Et of interesting sample
int iEvent
Definition: GenABIO.cc:243
const T & max(const T &a, const T &b)
int ietaAbs() const
get the absolute value of the tower ieta
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
int iphi() const
get the tower iphi
const EcalTrigTowerDetId & id() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool fineGrain() const
get the fine-grain bit of interesting sample
tuple cout
Definition: gather_cfg.py:121
dictionary rawdata
Definition: lumiPlot.py:393
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
int ttFlag() const
get the Trigger tower Flag of interesting sample
virtual void analyze(const edm::Event &, const edm::EventSetup &)