CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDetDiagLaserMonitor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalDetDiagLaserMonitor
4 // Class: HcalDetDiagLaserMonitor
5 //
13 //
14 // Original Author: Dmitry Vishnevskiy,591 R-013,+41227674265,
15 // Created: Wed Mar 3 12:14:16 CET 2010
16 // $Id: HcalDetDiagLaserMonitor.cc,v 1.17 2011/05/24 14:40:28 dma Exp $
17 //
18 //
19 
25 
29 
32 
33 #include <math.h>
34 
35 // this is to retrieve HCAL digi's
37 // to retrive trigger information (local runs only)
39 
42 
49 
50 #include "TFile.h"
51 #include "TTree.h"
52 #include "TSystem.h"
53 #include "TF1.h"
54 
57 
58 #include <iostream>
59 #include <fstream>
60 
62 static const float adc2fC[128]={-0.5,0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5, 10.5,11.5,12.5,
63  13.5,15.,17.,19.,21.,23.,25.,27.,29.5,32.5,35.5,38.5,42.,46.,50.,54.5,59.5,
64  64.5,59.5,64.5,69.5,74.5,79.5,84.5,89.5,94.5,99.5,104.5,109.5,114.5,119.5,
65  124.5,129.5,137.,147.,157.,167.,177.,187.,197.,209.5,224.5,239.5,254.5,272.,
66  292.,312.,334.5,359.5,384.5,359.5,384.5,409.5,434.5,459.5,484.5,509.5,534.5,
67  559.5,584.5,609.5,634.5,659.5,684.5,709.5,747.,797.,847.,897.,947.,997.,
68  1047.,1109.5,1184.5,1259.5,1334.5,1422.,1522.,1622.,1734.5,1859.5,1984.5,
69  1859.5,1984.5,2109.5,2234.5,2359.5,2484.5,2609.5,2734.5,2859.5,2984.5,
70  3109.5,3234.5,3359.5,3484.5,3609.5,3797.,4047.,4297.,4547.,4797.,5047.,
71  5297.,5609.5,5984.5,6359.5,6734.5,7172.,7672.,8172.,8734.5,9359.5,9984.5};
73 typedef struct{
74 int eta;
75 int phi;
76 int depth;
77 }Raddam_ch;
78 
79 Raddam_ch RADDAM_CH[56]={{-30,35,1},{-30,71,1},{-32,15,1},{-32,51,1},{-34,35,1},{-34,71,1},{-36,15,1},
80  {-36,51,1},{-38,35,1},{-38,71,1},{-40,15,1},{-40,51,1},{-41,35,1},{-41,71,1},
81  {30,21,1}, {30,57,1}, {32,1,1}, {32,37,1}, {34,21,1}, {34,57,1}, {36,1,1 },
82  {36,37,1}, {38,21,1}, {38,57,1}, {40,35,1}, {40,71,1}, {41,19,1}, {41,55,1 },
83  {-30,15,2},{-30,51,2},{-32,35,2},{-32,71,2},{-34,15,2},{-34,51,2},{-36,35,2},
84  {-36,71,2},{-38,15,2},{-38,51,2},{-40,35,2},{-40,71,2},{-41,15,2},{-41,51,2},
85  {30,1,2}, {30,37,2}, {32,21,2}, {32,57,2}, {34,1,2}, {34,37,2}, {36,21,2 },
86  {36,57,2}, {38,1,2}, {38,37,2}, {40,19,2}, {40,55,2}, {41,35,2}, {41,71,2}};
88  public:
90  for(int i=0;i<128;i++) s1_adc[i]=s2_adc[i]=0;
94  }
96  int TOTEVNT;
97  int CUT1EVNT;
98  int CUT2EVNT;
99  float S1MEAN,S2MEAN;
100  float S1RMS,S2RMS;
104  float S1CHI2,S2CHI2;
105  float S1NDF,S2NDF;
107  int s1_adc[128];
108  int s2_adc[128];
109 };
110 
112 
114 public:
116  IsRefetence=false;
119  status=0;
120  reset();
121  reset1();
122  }
123  void reset(){
124  Xe=XXe=Xt=XXt=n=0;
125  overflow=0;
126  undeflow=0;
127  }
128  void reset1(){
129  Xe1=XXe1=Xt1=XXt1=n1=0;
130  overflow1=0;
131  undeflow1=0;
132  }
133  void add_statistics(double *data,int nTS){
134  double e=GetEnergy(data,nTS);
135  double t=GetTime(data,nTS);
136  if(e<20){ undeflow++;undeflow1++; }else if(e>10000){ overflow++;overflow1++; }else{
137  n++; Xe+=e; XXe+=e*e; Xt+=t; XXt+=t*t;
138  n1++; Xe1+=e; XXe1+=e*e; Xt1+=t; XXt1+=t*t;
139  }
140  }
141  void set_reference(float val,float rms,float time,float time_rms){
142  ref_amp=val; ref_rms=rms;
143  ref_time=time; ref_time_rms=time_rms;
144  IsRefetence=true;
145  }
146  void set_data(float val,float rms,float time,float time_rms){
147  ds_amp=val; ds_rms=rms;
148  ds_time=time; ds_time_rms=time_rms;
149  }
150  void change_status(int val){
151  status|=val;
152  }
153  int get_status(){
154  return status;
155  }
156  bool get_reference(double *val,double *rms,double *time,double *time_rms){
157  *val=ref_amp; *rms=ref_rms;
158  *time=ref_time; *time_rms=ref_time_rms;
159  return IsRefetence;
160  }
161  bool get_average_amp(double *ave,double *rms){
162  if(ds_time>-10){ *ave=ds_amp; *rms=ds_rms; return true; }
163  if(n>0){ *ave=Xe/n; *rms=sqrt(XXe/n-(Xe*Xe)/(n*n));} else return false;
164  return true;
165  }
166  bool get_average_time(double *ave,double *rms){
167  if(ds_time>-10){ *ave=ds_time; *rms=ds_time_rms; return true; }
168  if(n>0){ *ave=Xt/n; *rms=sqrt(XXt/n-(Xt*Xt)/(n*n));} else return false;
169  return true;
170  }
172  return (int)n;
173  }
174  void set_statistics(int stat){
175  n=stat;
176  }
177  void set_statistics1(int stat){
178  n1=stat;
179  }
181  return overflow;
182  }
184  return undeflow;
185  }
186  bool get_average_amp1(double *ave,double *rms){
187  if(ds_time>-10){ *ave=ds_amp; *rms=ds_rms; return true; }
188  if(n1>0){ *ave=Xe1/n1; *rms=sqrt(XXe1/n1-(Xe1*Xe1)/(n1*n1));} else return false;
189  return true;
190  }
191  bool get_average_time1(double *ave,double *rms){
192  if(ds_time>-10){ *ave=ds_time; *rms=ds_time_rms; return true; }
193  if(n1>0){ *ave=Xt1/n1; *rms=sqrt(XXt1/n1-(Xt1*Xt1)/(n1*n1));} else return false;
194  return true;
195  }
197  return (int)n1;
198  }
200  return overflow1;
201  }
203  return undeflow1;
204  }
205  double GetEnergy(double *data,int n){
206  int MaxI=0; double Energy,MaxE=0;
207  for(int j=0;j<n;++j) if(MaxE<data[j]){ MaxE=data[j]; MaxI=j; }
208  Energy=data[MaxI];
209  if(MaxI>0) Energy+=data[MaxI-1];
210  if(MaxI>1) Energy+=data[MaxI-2];
211  if(MaxI<(n-1)) Energy+=data[MaxI+1];
212  if(MaxI<(n-2)) Energy+=data[MaxI+2];
213  return Energy;
214  }
215  double GetTime(double *data,int n=10){
216  int MaxI=-100; double Time=-9999,SumT=0,MaxT=-10;
217  for(int j=0;j<n;++j) if(MaxT<data[j]){ MaxT=data[j]; MaxI=j; }
218  if (MaxI>=0) // dummy protection so that compiler doesn't think MaxI=-100
219  {
220  Time=MaxI*data[MaxI];
221  SumT=data[MaxI];
222  if(MaxI>0){ Time+=(MaxI-1)*data[MaxI-1]; SumT+=data[MaxI-1]; }
223  if(MaxI<(n-1)){ Time+=(MaxI+1)*data[MaxI+1]; SumT+=data[MaxI+1]; }
224  Time=Time/SumT;
225  }
226  return Time;
227  }
228  int overflow;
229  int undeflow;
232  double Xe,XXe,Xt,XXt,n;
233  double Xe1,XXe1,Xt1,XXt1,n1;
235  float ref_amp;
236  float ref_rms;
237  float ref_time;
239  float ds_amp;
240  float ds_rms;
241  float ds_time;
242  float ds_time_rms;
243  int status;
245 };
246 
248  public:
251 
252  private:
253  HcalDetDiagLaserData* GetCalib(std::string sd,int eta,int phi){
254  int SD=0,ETA=0,PHI=0;
255  if(sd.compare("HB")==0) SD=1;
256  if(sd.compare("HE")==0) SD=2;
257  if(sd.compare("HO")==0) SD=3;
258  if(sd.compare("HF")==0) SD=4;
259  if(SD==1 || SD==2){
260  if(eta>0) ETA=1; else ETA=-1;
261  if(phi==71 ||phi==72 || phi==1 || phi==2) PHI=71; else PHI=((phi-3)/4)*4+3;
262  }else if(SD==3){
263  if(abs(eta)<=4){
264  ETA=0;
265  if(phi==71 ||phi==72 || phi==1 || phi==2 || phi==3 || phi==4) PHI=71; else PHI=((phi-5)/6)*6+5;
266  }else{
267  if(abs(eta)>4 && abs(eta)<=10) ETA=1;
268  if(abs(eta)>10 && abs(eta)<=15) ETA=2;
269  if(eta<0) ETA=-ETA;
270  if(phi==71 ||phi==72 || (phi>=1 && phi<=10)) PHI=71; else PHI=((phi-11)/12)*12+11;
271  }
272  }else if(SD==4){
273  if(eta>0) ETA=1; else ETA=-1;
274  if(phi>=1 && phi<=18) PHI=1;
275  if(phi>=19 && phi<=36) PHI=19;
276  if(phi>=37 && phi<=54) PHI=37;
277  if(phi>=55 && phi<=72) PHI=55;
278  }
279  return &calib_data[SD][ETA+2][PHI-1];
280  };
281  void beginRun(const edm::Run& run, const edm::EventSetup& c);
282  void endRun(const edm::Run& run, const edm::EventSetup& c);
283  void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c) ;
284  void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c);
285  void analyze(const edm::Event&, const edm::EventSetup&);
286 
290 
291  void SaveReference();
292  void SaveRaddamData();
293  void LoadReference();
294  void LoadDataset();
295 
296  bool get_ave_rbx(int sd,int side,int rbx,float *ave,float *rms);
297  bool get_ave_subdet(int sd,float *ave_t,float *ave_e,float *ave_t_r,float *ave_e_r);
298  void fillHistos(int sd);
299  void fillProblems(int sd);
302 
303  int ievt_;
308  int nHB,nHE,nHO,nHF;
309  std::string ReferenceData;
310  std::string ReferenceRun;
311  std::string OutputFilePath;
312  std::string XmlFilePath;
313  std::string baseFolder_;
314  std::string prefixME_;
315  bool Online_;
316  bool Overwrite;
317 
318  // to create html from processed dataset
319  std::string DatasetName;
320  std::string htmlOutputPath;
322 
337 
346 
351 
353  TH1F *S1[56],*S2[56];
354 
357  std::vector<std::string> problemnames_;
358 
361 
367 
368  std::map<unsigned int, int> KnownBadCells_;
369 };
370 
372  ievt_=-1;
373  emap=0;
375  run_number=-1;
376  IsReference=false;
377  LocalRun=RaddamRun=false;
378  createHTMLonly=false;
379  nHB=nHE=nHO=nHF=0;
381 
382  inputLabelDigi_ = iConfig.getUntrackedParameter<edm::InputTag>("digiLabel",edm::InputTag("hcalDigis"));
383  calibDigiLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("calibDigiLabel",edm::InputTag("hcalDigis"));
384 
385  ReferenceData = iConfig.getUntrackedParameter<std::string>("LaserReferenceData" ,"");
386  OutputFilePath = iConfig.getUntrackedParameter<std::string>("OutputFilePath", "");
387  DatasetName = iConfig.getUntrackedParameter<std::string>("LaserDatasetName", "");
388  htmlOutputPath = iConfig.getUntrackedParameter<std::string>("htmlOutputPath", "");
389  XmlFilePath = iConfig.getUntrackedParameter<std::string>("XmlFilePath", "");
390  Online_ = iConfig.getUntrackedParameter<bool> ("online",false);
391  Overwrite = iConfig.getUntrackedParameter<bool> ("Overwrite",true);
392  prefixME_ = iConfig.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
393  if (prefixME_.size()>0 && prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
394  prefixME_.append("/");
395  subdir_ = iConfig.getUntrackedParameter<std::string>("TaskFolder","DetDiagPedestalMonitor_Hcal/");
396  if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
397  subdir_.append("/");
398  subdir_=prefixME_+subdir_;
399  debug_ = iConfig.getUntrackedParameter<int>("debug",0);
400 
401  LaserTimingThreshold = iConfig.getUntrackedParameter<double>("LaserTimingThreshold",0.2);
402  LaserEnergyThreshold = iConfig.getUntrackedParameter<double>("LaserEnergyThreshold",0.1);
403  RaddamThreshold1 = iConfig.getUntrackedParameter<double>("RaddamThreshold1",10.0);
404  RaddamThreshold2 = iConfig.getUntrackedParameter<double>("RaddamThreshold2",0.95);
405 }
408  c.get<HcalChannelQualityRcd>().get(p);
409  HcalChannelQuality* chanquality= new HcalChannelQuality(*p.product());
410  std::vector<DetId> mydetids = chanquality->getAllChannels();
411  KnownBadCells_.clear();
412 
413  for (std::vector<DetId>::const_iterator i = mydetids.begin();i!=mydetids.end();++i){
414  if (i->det()!=DetId::Hcal) continue; // not an hcal cell
415  HcalDetId id=HcalDetId(*i);
416  int status=(chanquality->getValues(id))->getValue();
418  KnownBadCells_[id.rawId()]=status;
419  }
420  }
421 
422  edm::ESHandle<HcalDbService> conditions_;
423  c.get<HcalDbRecord>().get(conditions_);
424  emap=conditions_->getHcalMapping();
425 
427  if (!dbe_) return;
428  std::string name;
429 
431  meEVT_ = dbe_->bookInt("HcalDetDiagLaserMonitor Event Number");
432  meRUN_ = dbe_->bookInt("HcalDetDiagLaserMonitor Run Number");
433 
434  ReferenceRun="UNKNOWN";
435  LoadReference();
436  LoadDataset();
437  if(DatasetName.size()>0 && createHTMLonly){
438  char str[200]; sprintf(str,"%sHcalDetDiagLaserData_run%i_%i/",htmlOutputPath.c_str(),run_number,dataset_seq_number);
439  htmlFolder=dbe_->bookString("HcalDetDiagLaserMonitor HTML folder",str);
440  MonitorElement *me;
441  dbe_->setCurrentFolder(prefixME_+"HcalInfo");
442  me=dbe_->bookInt("HBpresent");
443  if(nHB>0) me->Fill(1);
444  me=dbe_->bookInt("HEpresent");
445  if(nHE>0) me->Fill(1);
446  me=dbe_->bookInt("HOpresent");
447  if(nHO>0) me->Fill(1);
448  me=dbe_->bookInt("HFpresent");
449  if(nHF>0) me->Fill(1);
450  }
452  ProblemCellsByDepth_timing->setup(dbe_," Problem Bad Laser Timing");
453  for(unsigned int i=0;i<ProblemCellsByDepth_timing->depth.size();i++)
454  problemnames_.push_back(ProblemCellsByDepth_timing->depth[i]->getName());
456  ProblemCellsByDepth_energy->setup(dbe_," Problem Bad Laser Energy");
457  for(unsigned int i=0;i<ProblemCellsByDepth_energy->depth.size();i++)
458  problemnames_.push_back(ProblemCellsByDepth_energy->depth[i]->getName());
459 
460  dbe_->setCurrentFolder(subdir_+"Summary Plots");
461 
462  name="HBHE Laser Energy Distribution"; hbheEnergy = dbe_->book1D(name,name,200,0,3000);
463  name="HBHE Laser Timing Distribution"; hbheTime = dbe_->book1D(name,name,200,0,10);
464  name="HBHE Laser Energy RMS_div_Energy Distribution"; hbheEnergyRMS = dbe_->book1D(name,name,200,0,0.5);
465  name="HBHE Laser Timing RMS Distribution"; hbheTimeRMS = dbe_->book1D(name,name,200,0,1);
466  name="HO Laser Energy Distribution"; hoEnergy = dbe_->book1D(name,name,200,0,3000);
467  name="HO Laser Timing Distribution"; hoTime = dbe_->book1D(name,name,200,0,10);
468  name="HO Laser Energy RMS_div_Energy Distribution"; hoEnergyRMS = dbe_->book1D(name,name,200,0,0.5);
469  name="HO Laser Timing RMS Distribution"; hoTimeRMS = dbe_->book1D(name,name,200,0,1);
470  name="HF Laser Energy Distribution"; hfEnergy = dbe_->book1D(name,name,200,0,3000);
471  name="HF Laser Timing Distribution"; hfTime = dbe_->book1D(name,name,200,0,10);
472  name="HF Laser Energy RMS_div_Energy Distribution"; hfEnergyRMS = dbe_->book1D(name,name,200,0,0.7);
473  name="HF Laser Timing RMS Distribution"; hfTimeRMS = dbe_->book1D(name,name,200,0,1);
474 
475  name="Laser Timing HBHEHF"; Time2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
476  name="Laser Timing HO"; Time2Dho = dbe_->book2D(name,name,33,-16,16,74,0,73);
477  name="Laser Energy HBHEHF"; Energy2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
478  name="Laser Energy HO"; Energy2Dho = dbe_->book2D(name,name,33,-16,16,74,0,73);
479  name="HBHEHF Laser (Timing-Ref)+1"; refTime2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
480  name="HO Laser (Timing-Ref)+1"; refTime2Dho = dbe_->book2D(name,name,33,-16,16,74,0,73);
481  name="HBHEHF Laser Energy_div_Ref"; refEnergy2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
482  name="HO Laser Energy_div_Ref"; refEnergy2Dho = dbe_->book2D(name,name,33,-16,16,74,0,73);
483 
484  name="HB RBX average Time-Ref"; hb_time_rbx = dbe_->book1D(name,name,36,0.5,36.5);
485  name="HE RBX average Time-Ref"; he_time_rbx = dbe_->book1D(name,name,36,0.5,36.5);
486  name="HO RBX average Time-Ref"; ho_time_rbx = dbe_->book1D(name,name,36,0.5,36.5);
487  name="HF RoBox average Time-Ref"; hf_time_rbx = dbe_->book1D(name,name,24,0.5,24.5);
488 
489  char str[200];
490  for(int i=1;i<=18;i++){ sprintf(str,"HBM%02i",i); hb_time_rbx->setBinLabel(i,str); }
491  for(int i=1;i<=18;i++){ sprintf(str,"HBP%02i",i); hb_time_rbx->setBinLabel(i+18,str); }
492  for(int i=1;i<=18;i++){ sprintf(str,"HEM%02i",i); he_time_rbx->setBinLabel(i,str); }
493  for(int i=1;i<=18;i++){ sprintf(str,"HEP%02i",i); he_time_rbx->setBinLabel(i+18,str); }
494  for(int i=1;i<=12;i++){ sprintf(str,"HFM%02i",i); hf_time_rbx->setBinLabel(i,str); }
495  for(int i=1;i<=12;i++){ sprintf(str,"HFP%02i",i); hf_time_rbx->setBinLabel(i+12,str); }
496  for(int i=1;i<=6;i++){ sprintf(str,"HO2M%02i",i*2); ho_time_rbx->setBinLabel(i,str); }
497  for(int i=1;i<=6;i++){ sprintf(str,"HO1M%02i",i*2); ho_time_rbx->setBinLabel(i+6,str); }
498  for(int i=1;i<=12;i++){ sprintf(str,"HO0%02i",i); ho_time_rbx->setBinLabel(i+12,str); }
499  for(int i=1;i<=6;i++){ sprintf(str,"HO1P%02i",i*2); ho_time_rbx->setBinLabel(i+24,str); }
500  for(int i=1;i<=6;i++){ sprintf(str,"HO2P%02i",i*2); ho_time_rbx->setBinLabel(i+30,str); }
501 
502  Time2Dhbhehf->setAxisTitle("i#eta",1);
503  Time2Dhbhehf->setAxisTitle("i#phi",2);
504  Time2Dho->setAxisTitle("i#eta",1);
505  Time2Dho->setAxisTitle("i#phi",2);
506  Energy2Dhbhehf->setAxisTitle("i#eta",1);
507  Energy2Dhbhehf->setAxisTitle("i#phi",2);
508  Energy2Dho->setAxisTitle("i#eta",1);
509  Energy2Dho->setAxisTitle("i#phi",2);
510  refTime2Dhbhehf->setAxisTitle("i#eta",1);
511  refTime2Dhbhehf->setAxisTitle("i#phi",2);
512  refTime2Dho->setAxisTitle("i#eta",1);
513  refTime2Dho->setAxisTitle("i#phi",2);
514  refEnergy2Dhbhehf->setAxisTitle("i#eta",1);
515  refEnergy2Dhbhehf->setAxisTitle("i#phi",2);
516  refEnergy2Dho->setAxisTitle("i#eta",1);
517  refEnergy2Dho->setAxisTitle("i#phi",2);
518 
520  refTime2Dho->setAxisRange(0,2,3);
521  refEnergy2Dhbhehf->setAxisRange(0.5,1.5,3);
522  refEnergy2Dho->setAxisRange(0.5,1.5,3);
523 
525  RefRun_= dbe_->bookString("HcalDetDiagLaserMonitor Reference Run",ReferenceRun);
526 
527  dbe_->setCurrentFolder(subdir_+"Raddam Plots");
528  for(int i=0;i<56;i++){
529  sprintf(str,"RADDAM (%i %i)",RADDAM_CH[i].eta,RADDAM_CH[i].phi);
530  Raddam[i] = dbe_->book1D(str,str,10,-0.5,9.5);
531  }
532 
533  dbe_->setCurrentFolder(subdir_+"Plots for client");
535  ProblemCellsByDepth_timing_val->setup(dbe_," Laser Timing difference");
537  ProblemCellsByDepth_energy_val->setup(dbe_," Laser Energy difference");
538 }
539 
540 
542 
543 }
544 
545 // ------------ method called to for each event ------------
547  if(createHTMLonly) return;
548  HcalBaseDQMonitor::analyze(iEvent,iSetup); // base class increments ievt_, etc. counters
549 
550 int eta,phi,depth,nTS;
551 static bool HBHEseq,HOseq,HFseq;
552 static int lastHBHEorbit,lastHOorbit,lastHForbit,nChecksHBHE,nChecksHO,nChecksHF,ievt_hbhe,ievt_ho,ievt_hf;
553  if(ievt_==-1){
554  ievt_=0;HBHEseq=HOseq=HFseq=false; lastHBHEorbit=lastHOorbit=lastHForbit=-1;nChecksHBHE=nChecksHO=nChecksHF=0;
555  ievt_hbhe=0,ievt_ho=0,ievt_hf=0;
556  }
557 
558  if(!dbe_) return;
559  bool LaserEvent=false;
560  bool LaserRaddam=false;
561  int orbit=iEvent.orbitNumber();
562  meRUN_->Fill(iEvent.id().run());
563  // for local runs
564  edm::Handle<HcalTBTriggerData> trigger_data;
565  iEvent.getByType(trigger_data);
566  if(trigger_data.isValid()){
567  if(trigger_data->wasLaserTrigger()) LaserEvent=true;
568  LocalRun=true;
569  }
570  if(!LocalRun && Online_){
571  if(HBHEseq && (orbit-lastHBHEorbit)>(11223*10) && ievt_hbhe>40){
572  HBHEseq=false;
576  nChecksHBHE++;
577  ievt_hbhe=0;
578  for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) hb_data[i][j][k].reset();
579  for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) he_data[i][j][k].reset();
580  }
581  if(HOseq && (orbit-lastHOorbit)>(11223*10) && ievt_ho>40){
582  HOseq=false;
585  nChecksHO++;
586  ievt_ho=0;
587  for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) ho_data[i][j][k].reset();
588  }
589  if(HFseq && (orbit-lastHForbit)>(11223*10) && ievt_hf>40){
590  HFseq=false;
593  nChecksHF++;
594  ievt_hf=0;
595  if(nChecksHF==1 || (nChecksHF>1 && ((nChecksHF-1)%12)==0)){
596  SaveReference();
597  }
598  for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) hf_data[i][j][k].reset();
599  }
600  }
601 
602  // Abort Gap laser
603  if(LocalRun==false || LaserEvent==false){
605  iEvent.getByType(rawdata);
606  //checking FEDs for calibration information
608  const FEDRawData& fedData = rawdata->FEDData(i) ;
609  if ( fedData.size() < 24 ) continue ;
610  int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
611  if(value==hc_HBHEHPD){ HBHEseq=true; HOseq=HFseq=false; lastHBHEorbit=orbit; ievt_hbhe++; }
612  if(value==hc_HOHPD){ HOseq=true; HBHEseq=HFseq=false; lastHOorbit=orbit; ievt_ho++; }
613  if(value==hc_HFPMT){ HFseq=true; HBHEseq=HOseq=false; lastHForbit=orbit; ievt_hf++; }
614 
615  if(value==hc_HBHEHPD || value==hc_HOHPD || value==hc_HFPMT){ LaserEvent=true; break;}
616  if(value==hc_RADDAM){ LaserEvent=true; LaserRaddam=true; break;}
617  }
618  }
619  if(!LaserEvent) return;
621  iEvent.getByLabel(inputLabelDigi_,hbhe);
623  iEvent.getByLabel(inputLabelDigi_,ho);
625  iEvent.getByLabel(inputLabelDigi_,hf);
627  iEvent.getByLabel(calibDigiLabel_, calib);
628 
629  if(LocalRun && LaserEvent){
630  int N=0;
631  if(hf.isValid()){
632  for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
633  eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth();
634  float e=0;
635  for(int i=0;i<digi->size();i++) e+=adc2fC[digi->sample(i).adc()&0xff]-2.5;
636  if(e>40){ N++;}
637  }
638  }
639  if(N>50 && N<57){ RaddamRun=true; /*LaserRaddam=true;*/}
640  }
641  if(RaddamRun){
642  if(hf.isValid()){
643  for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
644  eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
645  int N;
646  for(N=0;N<56;N++)if(eta==RADDAM_CH[N].eta && phi==RADDAM_CH[N].phi && depth==RADDAM_CH[N].depth) break;
647  if(N==56) continue;
648  float max1=0,max2=0;
649  int nmax1=0,nmax2=0;
650  for(int i=0;i<nTS;i++){
651  if(max1<adc2fC[digi->sample(i).adc()&0xff]){ nmax1=i; max1=adc2fC[digi->sample(i).adc()&0xff]; }
652  }
653  Raddam_data[N].TOTEVNT++;
654  for(int i=0;i<nTS;i++){
655  if(i==nmax1) continue;
656  if(max2<adc2fC[digi->sample(i).adc()&0xff]){ nmax2=i; max2=adc2fC[digi->sample(i).adc()&0xff]; }
657  }
658  if(nmax1>nmax2){
659  int tmp1=nmax2;
660  nmax2=nmax1;nmax1=tmp1;
661  }
662  if(nmax1==0 || nmax2==(nTS-1)) continue;
663  if(nmax2!=(nmax1+1)) continue;
664 
665  if(max1<RaddamThreshold1 || max2<RaddamThreshold1) continue;
666  Raddam_data[N].CUT1EVNT++;
667  max1-=2.5; max2-=2.5;
668  float S2=max1+max2;
669  float S4=S2+adc2fC[digi->sample(nmax1-1).adc()&0xff]+adc2fC[digi->sample(nmax2+1).adc()&0xff]-5.0;
670  if((S2/S4)<RaddamThreshold2) continue;
671  Raddam_data[N].CUT2EVNT++;
672  Raddam_data[N].s1_adc[digi->sample(nmax1).adc()&0xff]++;
673  Raddam_data[N].s2_adc[digi->sample(nmax2).adc()&0xff]++;
674  }
675  }
676  }
677 
678  meEVT_->Fill(++ievt_);
679  run_number=iEvent.id().run();
680  double data[20];
681  if(!LaserRaddam){
682  if(hbhe.isValid()){
683  for(HBHEDigiCollection::const_iterator digi=hbhe->begin();digi!=hbhe->end();digi++){
684  eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
685  double ped=(adc2fC[digi->sample(0).adc()&0xff]+adc2fC[digi->sample(1).adc()&0xff])/2.0;
686  if(digi->id().subdet()==HcalBarrel){
687  for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
688  hb_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
689  }
690  if(digi->id().subdet()==HcalEndcap){
691  for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
692  he_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
693  }
694  }
695  }
696  if(ho.isValid()){
697  for(HODigiCollection::const_iterator digi=ho->begin();digi!=ho->end();digi++){
698  eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
699  double ped=(adc2fC[digi->sample(0).adc()&0xff]+adc2fC[digi->sample(1).adc()&0xff])/2.0;
700  if((eta>=11 && eta<=15 && phi>=59 && phi<=70) || (eta>=5 && eta<=10 && phi>=47 && phi<=58)){
701  for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
702  }else{
703  for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
704  }
705  ho_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
706  }
707  }
708  if(hf.isValid()){
709  for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
710  eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
711  double ped=adc2fC[digi->sample(0).adc()&0xff];
712  for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
713  hf_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
714  }
715  }
716  if(calib.isValid())for(HcalCalibDigiCollection::const_iterator digi=calib->begin();digi!=calib->end();digi++){
717  if(digi->id().cboxChannel()!=0 || digi->id().hcalSubdet()==0) continue;
718  nTS=digi->size();
719  float e=0;
720  for(int i=0;i<nTS;i++){ data[i]=adc2fC[digi->sample(i).adc()&0xff]; e+=data[i];}
721  if(e<15000) calib_data[digi->id().hcalSubdet()][digi->id().ieta()+2][digi->id().iphi()-1].add_statistics(data,nTS);
722  }
723  }else{ //Raddam
724  if(hf.isValid()){
725  for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
726  eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
727  int N;
728  for(N=0;N<56;N++)if(eta==RADDAM_CH[N].eta && phi==RADDAM_CH[N].phi && depth==RADDAM_CH[N].depth) break;
729  if(N==56) continue;
730  for(int i=0;i<nTS;i++) Raddam[N]->Fill(i,adc2fC[digi->sample(i).adc()&0xff]-2.5);
731 
732  }
733  }
734  }
735 }
736 bool HcalDetDiagLaserMonitor::get_ave_subdet(int sd,float *ave_t,float *ave_e,float *ave_t_r,float *ave_e_r){
737 double T=0,nT=0,E=0,nE=0,Tr=0,nTr=0,Er=0,nEr=0;
738  if(sd==HcalBarrel) for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){
739  for(int depth=1;depth<=2;depth++){
740  if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
741  double ave=0,rms=0,time=0,time_rms=0;
742  hb_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
743  hb_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
744  T+=time; nT++; E+=ave; nE++;
745  if(hb_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
746  Tr+=time; nTr++; Er+=ave; nEr++;}
747  }
748  }
749  }
750  // HE histograms
751  if(sd==HcalEndcap) for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
752  for(int depth=1;depth<=3;depth++){
753  if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
754  double ave=0; double rms=0; double time=0; double time_rms=0;
755  he_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
756  he_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
757  T+=time; nT++; E+=ave; nE++;
758  if(he_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
759  Tr+=time; nTr++; Er+=ave; nEr++;}
760  }
761  }
762  }
763  // HF histograms
764  if(sd==HcalForward) for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
765  for(int depth=1;depth<=2;depth++){
766  if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
767  double ave=0; double rms=0; double time=0; double time_rms=0;
768  hf_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
769  hf_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
770  T+=time; nT++; E+=ave; nE++;
771  if(hf_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
772  Tr+=time; nTr++; Er+=ave; nEr++;}
773  }
774  }
775  }
776  // HO histograms
777  if(sd==HcalOuter) for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
778  for(int depth=4;depth<=4;depth++){
779  if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
780  double ave=0; double rms=0; double time=0; double time_rms=0;
781  ho_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
782  ho_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
783  T+=time; nT++; E+=ave; nE++;
784  if(ho_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
785  Tr+=time; nTr++; Er+=ave; nEr++;}
786  }
787  }
788  }
789  if(nT<200 || nE<200 || nTr<200 || nEr<200) return false;
790  *ave_t=T/nT;
791  *ave_e=E/nE;
792  *ave_t_r=Tr/nTr;
793  *ave_e_r=Er/nEr;
794  return true;
795 }
796 
798 float ave_t,ave_e,ave_t_r,ave_e_r;
799  if(!get_ave_subdet(sd,&ave_t,&ave_e,&ave_t_r,&ave_e_r)) return;
800 
801  for(int i=0;i<4;i++){
804  }
805 
806  std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
807  for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
808  DetId detid=emap->lookup(*eid);
809  if (detid.det()!=DetId::Hcal) continue;
810  HcalGenericDetId gid(emap->lookup(*eid));
811  if(!(!(gid.null()) &&
812  (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
813  gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap ||
814  gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
815  gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
816  int eta=0,phi=0,depth=0;
817  HcalDetId hid(detid);
818  if(KnownBadCells_.find(hid.rawId())==KnownBadCells_.end()) continue;
819  eta=hid.ieta();
820  phi=hid.iphi();
821  depth=hid.depth();
822 
823  int e=CalcEtaBin(sd,eta,depth)+1;
824  if(detid.subdetId()==HcalBarrel && sd==HcalBarrel){
825  double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
826  if(!hb_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
827  if(!hb_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
828  if(!hb_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
829  hb_data[eta+42][phi-1][depth-1].nChecks++;
830  float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
831  if(diff_t>LaserTimingThreshold){
832  hb_data[eta+42][phi-1][depth-1].nBadTime++;
833  ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
834  }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0);
835  if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
836  float diff_e=((VAL/ave_e))/(val/ave_e_r);
837  if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
838  hb_data[eta+42][phi-1][depth-1].nBadEnergy++;
839  ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
840  }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
841  }
842  }
843  if(detid.subdetId()==HcalEndcap && sd==HcalEndcap){
844  double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
845  if(!he_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
846  if(!he_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
847  if(!he_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
848  he_data[eta+42][phi-1][depth-1].nChecks++;
849  float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
850  if(diff_t>LaserTimingThreshold){
851  he_data[eta+42][phi-1][depth-1].nBadTime++;
852  ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
853  }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0);
854  if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
855  float diff_e=((VAL/ave_e))/(val/ave_e_r);
856  if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
857  he_data[eta+42][phi-1][depth-1].nBadEnergy++;
858  ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
859  }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
860  }
861  }
862  if(detid.subdetId()==HcalOuter && sd==HcalOuter){
863  double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
864  if(!ho_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
865  if(!ho_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
866  if(!ho_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
867  ho_data[eta+42][phi-1][depth-1].nChecks++;
868  float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
869  if(diff_t>LaserTimingThreshold){
870  ho_data[eta+42][phi-1][depth-1].nBadTime++;
871  ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
872  }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0);
873  if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
874  float diff_e=((VAL/ave_e))/(val/ave_e_r);
875  if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
876  ho_data[eta+42][phi-1][depth-1].nBadEnergy++;
877  ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
878  }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
879  }
880  }
881  if(detid.subdetId()==HcalForward && sd==HcalForward){
882  double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
883  if(!hf_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
884  if(!hf_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
885  if(!hf_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
886  hf_data[eta+42][phi-1][depth-1].nChecks++;
887  float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
888  if(diff_t>LaserTimingThreshold){
889  hf_data[eta+42][phi-1][depth-1].nBadTime++;
890  ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
891  }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0);
892  if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
893  float diff_e=((VAL/ave_e))/(val/ave_e_r);
894  if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
895  hf_data[eta+42][phi-1][depth-1].nBadEnergy++;
896  ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
897  }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
898  }
899  }
900  }
901  for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
902  DetId detid=emap->lookup(*eid);
903  if (detid.det()!=DetId::Hcal) continue;
904  HcalGenericDetId gid(emap->lookup(*eid));
905  if(!(!(gid.null()) &&
906  (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
907  gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap ||
908  gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
909  gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
910  int eta=0,phi=0,depth=0;
911  HcalDetId hid(detid);
912  eta=hid.ieta();
913  phi=hid.iphi();
914  depth=hid.depth();
915 
916  if(detid.subdetId()==HcalBarrel){
917  if(hb_data[eta+42][phi-1][depth-1].nBadTime>0){
918  int e=CalcEtaBin(HcalBarrel,eta,depth)+1;
919  double val=hb_data[eta+42][phi-1][depth-1].nBadTime/hb_data[eta+42][phi-1][depth-1].nChecks;
920  ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
921  }
922  if(hb_data[eta+42][phi-1][depth-1].nBadEnergy>0){
923  int e=CalcEtaBin(HcalBarrel,eta,depth)+1;
924  double val=hb_data[eta+42][phi-1][depth-1].nBadEnergy/hb_data[eta+42][phi-1][depth-1].nChecks;
925  ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
926  }
927  }
928  if(detid.subdetId()==HcalEndcap){
929  if(he_data[eta+42][phi-1][depth-1].nBadTime>0){
930  int e=CalcEtaBin(HcalEndcap,eta,depth)+1;
931  double val=he_data[eta+42][phi-1][depth-1].nBadTime/he_data[eta+42][phi-1][depth-1].nChecks;
932  ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
933  }
934  if(he_data[eta+42][phi-1][depth-1].nBadEnergy>0){
935  int e=CalcEtaBin(HcalEndcap,eta,depth)+1;
936  double val=he_data[eta+42][phi-1][depth-1].nBadEnergy/he_data[eta+42][phi-1][depth-1].nChecks;
937  ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
938  }
939  }
940  if(detid.subdetId()==HcalOuter){
941  if(ho_data[eta+42][phi-1][depth-1].nBadTime>0){
942  int e=CalcEtaBin(HcalOuter,eta,depth)+1;
943  double val=ho_data[eta+42][phi-1][depth-1].nBadTime/ho_data[eta+42][phi-1][depth-1].nChecks;
944  ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
945  }
946  if(ho_data[eta+42][phi-1][depth-1].nBadEnergy>0){
947  int e=CalcEtaBin(HcalOuter,eta,depth)+1;
948  double val=ho_data[eta+42][phi-1][depth-1].nBadEnergy/ho_data[eta+42][phi-1][depth-1].nChecks;
949  ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
950  }
951  }
952  if(detid.subdetId()==HcalForward){
953  if(hf_data[eta+42][phi-1][depth-1].nBadTime>0){
954  int e=CalcEtaBin(HcalForward,eta,depth)+1;
955  double val=hf_data[eta+42][phi-1][depth-1].nBadTime/hf_data[eta+42][phi-1][depth-1].nChecks;
956  ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
957  }
958  if(hf_data[eta+42][phi-1][depth-1].nBadEnergy>0){
959  int e=CalcEtaBin(HcalForward,eta,depth)+1;
960  double val=hf_data[eta+42][phi-1][depth-1].nBadEnergy/hf_data[eta+42][phi-1][depth-1].nChecks;
961  ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
962  }
963  }
964  }
965 }
966 
967 bool HcalDetDiagLaserMonitor::get_ave_rbx(int sd,int side,int rbx,float *ave,float *rms){
968  double xt=0,xxt=0;
969  int eta_min=0,eta_max=0,n=0;
970  if(sd==HcalBarrel){
971  if(side>0){eta_min=1; eta_max=29;}
972  if(side<0){eta_min=-29; eta_max=-1;}
973  if(rbx==1){
974  for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++)for(int k=1;k<=3;k++){
975  double val,rms,time,time_rms;
976  double TIME,TIME_RMS;
977  if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
978  if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
979  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
980  }
981  for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=2;j++)for(int k=1;k<=3;k++){
982  double val,rms,time,time_rms;
983  double TIME,TIME_RMS;
984  if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
985  if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
986  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
987  }
988 
989  }else{
990  for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*4-1);j<=((rbx-1)*4+2);j++)for(int k=1;k<=3;k++){
991  double val,rms,time,time_rms;
992  double TIME,TIME_RMS;
993  if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
994  if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
995  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
996  }
997  }
998  }
999  if(sd==HcalEndcap){
1000  if(side>0){eta_min=1; eta_max=29;}
1001  if(side<0){eta_min=-29; eta_max=-1;}
1002  if(rbx==1){
1003  for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++)for(int k=1;k<=3;k++){
1004  double val,rms,time,time_rms;
1005  double TIME,TIME_RMS;
1006  if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1007  if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
1008  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1009  }
1010  for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=2;j++)for(int k=1;k<=3;k++){
1011  double val,rms,time,time_rms;
1012  double TIME,TIME_RMS;
1013  if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1014  if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
1015  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1016  }
1017 
1018  }else{
1019  for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*4-1);j<=((rbx-1)*4+2);j++)for(int k=1;k<=3;k++){
1020  double val,rms,time,time_rms;
1021  double TIME,TIME_RMS;
1022  if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1023  if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
1024  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1025  }
1026  }
1027  }
1028  if(sd==HcalForward){
1029  if(side>0){eta_min=29; eta_max=40;}
1030  if(side<0){eta_min=-40; eta_max=-29;}
1031  for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*6+1);j<=((rbx-1)*6+6);j++)for(int k=1;k<=2;k++){
1032  double val,rms,time,time_rms;
1033  double TIME,TIME_RMS;
1034  if(!hf_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1035  if(!hf_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
1036  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1037  }
1038  }
1039  if(sd==HcalOuter){
1040  if(side==0){
1041  eta_min=-4,eta_max=4;
1042  if(rbx==1){
1043  for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++){
1044  double val,rms,time,time_rms;
1045  double TIME,TIME_RMS;
1046  if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1047  if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
1048  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1049  }
1050  for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=4;j++){
1051  double val,rms,time,time_rms;
1052  double TIME,TIME_RMS;
1053  if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1054  if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
1055  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1056  }
1057 
1058  }else{
1059  for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*6-1);j<=((rbx-1)*6+4);j++){
1060  double val,rms,time,time_rms;
1061  double TIME,TIME_RMS;
1062  if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1063  if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
1064  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1065  }
1066  }
1067  }
1068  if(side==-1){ eta_min=-10,eta_max=-5;}
1069  if(side==-2){ eta_min=-15,eta_max=-11;}
1070  if(side==1) { eta_min=5, eta_max=10;}
1071  if(side==2) { eta_min=11, eta_max=15;}
1072  if(side!=0){
1073  if(rbx==1){
1074  for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++){
1075  double val,rms,time,time_rms;
1076  double TIME,TIME_RMS;
1077  if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1078  if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
1079  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1080  }
1081  for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=10;j++){
1082  double val,rms,time,time_rms;
1083  double TIME,TIME_RMS;
1084  if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1085  if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
1086  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1087  }
1088 
1089  }else{
1090  for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*12-1);j<=((rbx-1)*12+10);j++){
1091  double val,rms,time,time_rms;
1092  double TIME,TIME_RMS;
1093  if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1094  if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
1095  xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
1096  }
1097  }
1098  }
1099  }
1100  if(n<10) return false;
1101  *ave=xt/n;
1102  *rms=sqrt(xxt/n-(xt*xt)/(n*n));
1103  return true;
1104 }
1105 
1106 
1108  if(sd==HcalBarrel || sd==HcalEndcap){
1109  hbheEnergy->Reset();
1110  hbheTime->Reset();
1111  hbheEnergyRMS->Reset();
1112  hbheTimeRMS->Reset();
1113  hb_time_rbx->Reset();
1114  he_time_rbx->Reset();
1115  }
1116  if(sd==HcalOuter){
1117  hoEnergy->Reset();
1118  hoTime->Reset();
1119  hoEnergyRMS->Reset();
1120  hoTimeRMS->Reset();
1121  Time2Dho->Reset();
1122  Energy2Dho->Reset();
1123  refTime2Dho->Reset();
1124  refEnergy2Dho->Reset();
1125  ho_time_rbx->Reset();
1126  }
1127  if(sd==HcalForward){
1128  hfEnergy->Reset();
1129  hfTime->Reset();
1130  hfEnergyRMS->Reset();
1131  hfTimeRMS->Reset();
1132  hf_time_rbx->Reset();
1133  }
1134  if(sd==HcalBarrel || sd==HcalEndcap){
1135  // HB histograms
1136  for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){
1137  double T=0,nT=0,E=0,nE=0;
1138  for(int depth=1;depth<=2;depth++){
1139  if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
1140  double ave=0;
1141  double rms=0;
1142  double time=0;
1143  double time_rms=0;
1144  hb_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
1145  hb_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
1146  hbheEnergy->Fill(ave);
1147  if(ave>0)hbheEnergyRMS->Fill(rms/ave);
1148  hbheTime->Fill(time);
1149  hbheTimeRMS->Fill(time_rms);
1150  T+=time; nT++; E+=ave; nE++;
1151  }
1152  }
1153  if(nT>0){Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT);Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); }
1154  }
1155  // HE histograms
1156  for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
1157  double T=0,nT=0,E=0,nE=0;
1158  for(int depth=1;depth<=3;depth++){
1159  if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
1160  double ave=0; double rms=0; double time=0; double time_rms=0;
1161  he_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
1162  he_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
1163  hbheEnergy->Fill(ave);
1164  if(ave>0)hbheEnergyRMS->Fill(rms/ave);
1165  hbheTime->Fill(time);
1166  hbheTimeRMS->Fill(time_rms);
1167  T+=time; nT++; E+=ave; nE++;
1168  }
1169  }
1170  if(nT>0 && abs(eta)>16 ){Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT); Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); }
1171  if(nT>0 && abs(eta)>20 ){Time2Dhbhehf->setBinContent(eta+44,phi+2,T/nT); Energy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);}
1172  }
1173  }
1174  if(sd==HcalForward){
1175  // HF histograms
1176  for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
1177  double T=0,nT=0,E=0,nE=0;
1178  for(int depth=1;depth<=2;depth++){
1179  if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
1180  double ave=0; double rms=0; double time=0; double time_rms=0;
1181  hf_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
1182  hf_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
1183  hfEnergy->Fill(ave);
1184  if(ave>0)hfEnergyRMS->Fill(rms/ave);
1185  hfTime->Fill(time);
1186  T+=time; nT++; E+=ave; nE++;
1187  hfTimeRMS->Fill(time_rms);
1188  }
1189  }
1190  if(nT>0 && abs(eta)>29 ){ Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT); Time2Dhbhehf->setBinContent(eta+44,phi+2,T/nT);}
1191  if(nT>0 && abs(eta)>29 ){ Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); Energy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);}
1192  }
1193  }
1194  if(sd==HcalOuter){
1195  // HO histograms
1196  for(int eta=-10;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
1197  if(eta>10 && !isSiPM(eta,phi,4)) continue;
1198  double T=0,nT=0,E=0,nE=0;
1199  for(int depth=4;depth<=4;depth++){
1200  if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
1201  double ave=0; double rms=0; double time=0; double time_rms=0;
1202  ho_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
1203  ho_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
1204  hoEnergy->Fill(ave);
1205  if(ave>0)hoEnergyRMS->Fill(rms/ave);
1206  hoTime->Fill(time);
1207  T+=time; nT++; E+=ave; nE++;
1208  hoTimeRMS->Fill(time_rms);
1209  }
1210  }
1211  if(nT>0){ Time2Dho->Fill(eta,phi,T/nT); Energy2Dho->Fill(eta,phi+1,E/nE) ;}
1212  }
1213  }
1214 
1215  // compare with reference...
1216  if(sd==HcalBarrel || sd==HcalEndcap){
1217  for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){
1218  double T=0,nT=0,E=0,nE=0;
1219  for(int depth=1;depth<=2;depth++){
1220  if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
1221  double val=0,rms=0,time=0,time_rms=0;
1222  double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
1223  if(!hb_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1224  if(!hb_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
1225  if(!hb_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
1226  E+=VAL/val; nE++;
1227  T+=TIME-time; nT++;
1228  }
1229  }
1230  if(nE>0) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);
1231  if(nT>0){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+1,TTT); }
1232  }
1233  for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
1234  double T=0,nT=0,E=0,nE=0;
1235  for(int depth=1;depth<=3;depth++){
1236  if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
1237  double val=0,rms=0,time=0,time_rms=0;
1238  double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
1239  if(!he_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1240  if(!he_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
1241  if(!he_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
1242  E+=VAL/val; nE++;
1243  T+=TIME-time; nT++;
1244  }
1245  }
1246  if(nE>0 && abs(eta)>16) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);
1247  if(nT>0 && abs(eta)>16){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+1,TTT); }
1248  if(nE>0 && abs(eta)>20) refEnergy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);
1249  if(nT>0 && abs(eta)>20){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+2,TTT); }
1250  }
1251  }
1252  if(sd==HcalForward){
1253  for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
1254  double T=0,nT=0,E=0,nE=0;
1255  for(int depth=1;depth<=2;depth++){
1256  if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
1257  double val=0,rms=0,time=0,time_rms=0;
1258  double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
1259  if(!hf_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1260  if(!hf_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
1261  if(!hf_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
1262  E+=VAL/val; nE++;
1263  T+=TIME-time; nT++;
1264  }
1265  }
1266  if(nE>0 && abs(eta)>29) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);
1267  if(nT>0 && abs(eta)>29){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+1,TTT); }
1268  if(nE>0 && abs(eta)>29) refEnergy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);
1269  if(nT>0 && abs(eta)>29){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+2,TTT); }
1270  }
1271  }
1272  if(sd==HcalOuter){
1273  for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
1274  if(eta>10 && !isSiPM(eta,phi,4)) continue;
1275  double T=0,nT=0,E=0,nE=0;
1276  for(int depth=4;depth<=4;depth++){
1277  if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
1278  double val=0,rms=0,time=0,time_rms=0;
1279  double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
1280  if(!ho_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
1281  if(!ho_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
1282  if(!ho_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
1283  E+=VAL/val; nE++;
1284  T+=TIME-time; nT++;
1285  }
1286  }
1287  if(nE>0) refEnergy2Dho->Fill(eta,phi,E/nE);
1288  if(nT>0){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dho->Fill(eta,phi,TTT);}
1289  }
1290  }
1292  float min,max;
1293  if(sd==HcalBarrel || sd==HcalEndcap){
1294  min=100;max=-100;
1295  for(int i=1;i<=18;i++){
1296  float ave=-10,rms=-10;
1297  if(get_ave_rbx(HcalBarrel,-1,i,&ave,&rms)){
1298  hb_time_rbx->setBinContent(i,ave);
1300  if(ave<min) min=ave;
1301  if(ave>max) max=ave;
1302  }
1303  }
1304  for(int i=1;i<=18;i++){
1305  float ave=-10,rms=-10;
1306  if(get_ave_rbx(HcalBarrel,1,i,&ave,&rms)){
1307  hb_time_rbx->setBinContent(i+18,ave);
1309  if(ave<min) min=ave;
1310  if(ave>max) max=ave;
1311  }
1312  }
1313  if(max>-100)hb_time_rbx->setAxisRange(min-1,max+1,2);
1314  min=100;max=-100;
1315  for(int i=1;i<=18;i++){
1316  float ave=-10,rms=-10;
1317  if(get_ave_rbx(HcalEndcap,-1,i,&ave,&rms)){
1318  he_time_rbx->setBinContent(i,ave);
1320  if(ave<min) min=ave;
1321  if(ave>max) max=ave;
1322  }
1323  }
1324  for(int i=1;i<=18;i++){
1325  float ave=-10,rms=-10;
1326  if(get_ave_rbx(HcalEndcap,1,i,&ave,&rms)){
1327  he_time_rbx->setBinContent(i+18,ave);
1329  if(ave<min) min=ave;
1330  if(ave>max) max=ave;
1331  }
1332  }
1333  if(max>-100)he_time_rbx->setAxisRange(min-1,max+1,2);
1334  }
1336  if(sd==HcalOuter){
1337  min=100;max=-100;
1338  for(int i=1;i<=6;i++){
1339  float ave=-10,rms=-10;
1340  if(get_ave_rbx(HcalOuter,-2,i,&ave,&rms)){
1341  ho_time_rbx->setBinContent(i,ave);
1343  if(ave<min) min=ave;
1344  if(ave>max) max=ave;
1345  }
1346  }
1347  for(int i=1;i<=6;i++){
1348  float ave=-10,rms=-10;
1349  if(get_ave_rbx(HcalOuter,-1,i,&ave,&rms)){
1350  ho_time_rbx->setBinContent(i+6,ave);
1352  if(ave<min) min=ave;
1353  if(ave>max) max=ave;
1354  }
1355  }
1356  for(int i=1;i<=12;i++){
1357  float ave=-10,rms=-10;
1358  if(get_ave_rbx(HcalOuter,0,i,&ave,&rms)){
1359  ho_time_rbx->setBinContent(i+12,ave);
1361  if(ave<min) min=ave;
1362  if(ave>max) max=ave;
1363  }
1364  }
1365  for(int i=1;i<=6;i++){
1366  float ave=-10,rms=-10;
1367  if(get_ave_rbx(HcalOuter,1,i,&ave,&rms)){
1368  ho_time_rbx->setBinContent(i+24,ave);
1370  if(ave<min) min=ave;
1371  if(ave>max) max=ave;
1372  }
1373  }
1374  for(int i=1;i<=6;i++){
1375  float ave=-10,rms=-10;
1376  if(get_ave_rbx(HcalOuter,2,i,&ave,&rms)){
1377  ho_time_rbx->setBinContent(i+30,ave);
1379  if(ave<min) min=ave;
1380  if(ave>max) max=ave;
1381  }
1382  }
1383  if(max>-100)ho_time_rbx->setAxisRange(min-1,max+1,2);
1384  }
1386  if(sd==HcalForward){
1387  min=100;max=-100;
1388  for(int i=1;i<=12;i++){
1389  float ave=-10,rms=-10;
1390  if(get_ave_rbx(HcalForward,-1,i,&ave,&rms)){
1391  hf_time_rbx->setBinContent(i,ave);
1393  if(ave<min) min=ave;
1394  if(ave>max) max=ave;
1395  }
1396  }
1397  for(int i=1;i<=12;i++){
1398  float ave=-10,rms=-10;
1399  if(get_ave_rbx(HcalForward,1,i,&ave,&rms)){
1400  hf_time_rbx->setBinContent(i+12,ave);
1402  if(ave<min) min=ave;
1403  if(ave>max) max=ave;
1404  }
1405  }
1406  if(max>-100)hf_time_rbx->setAxisRange(min-1,max+1,2);
1407  }
1408 }
1409 
1411 double amp,rms,Time,time_rms;
1412 int Eta,Phi,Depth,Statistic,Status=0;
1413 char Subdet[10],str[500];
1414  if(OutputFilePath.size()>0){
1415  if(!Overwrite){
1416  sprintf(str,"%sHcalDetDiagLaserData_run%06i_%i.root",OutputFilePath.c_str(),run_number,dataset_seq_number);
1417  }else{
1418  sprintf(str,"%sHcalDetDiagLaserData.root",OutputFilePath.c_str());
1419  }
1420  TFile *theFile = new TFile(str, "RECREATE");
1421  if(!theFile->IsOpen()) return;
1422  theFile->cd();
1423  sprintf(str,"%d",run_number); TObjString run(str); run.Write("run number");
1424  sprintf(str,"%d",ievt_); TObjString events(str); events.Write("Total events processed");
1425  sprintf(str,"%d",dataset_seq_number); TObjString dsnum(str); dsnum.Write("Dataset number");
1426  Long_t t; t=time(0); strftime(str,30,"%F %T",localtime(&t)); TObjString tm(str); tm.Write("Dataset creation time");
1427 
1428  TTree *tree =new TTree("HCAL Laser data","HCAL Laser data");
1429  if(tree==0) return;
1430  tree->Branch("Subdet", &Subdet, "Subdet/C");
1431  tree->Branch("eta", &Eta, "Eta/I");
1432  tree->Branch("phi", &Phi, "Phi/I");
1433  tree->Branch("depth", &Depth, "Depth/I");
1434  tree->Branch("statistic",&Statistic, "Statistic/I");
1435  tree->Branch("status", &Status, "Status/I");
1436  tree->Branch("amp", &amp, "amp/D");
1437  tree->Branch("rms", &rms, "rms/D");
1438  tree->Branch("time", &Time, "time/D");
1439  tree->Branch("time_rms", &time_rms, "time_rms/D");
1440  sprintf(Subdet,"HB");
1441  for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
1442  if((Statistic=hb_data[eta+42][phi-1][depth-1].get_statistics1())>10){
1443  Eta=eta; Phi=phi; Depth=depth;
1444  Status=hb_data[eta+42][phi-1][depth-1].get_status();
1445  hb_data[eta+42][phi-1][depth-1].get_average_amp1(&amp,&rms);
1446  hb_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
1447  tree->Fill();
1448  }
1449  }
1450  sprintf(Subdet,"HE");
1451  for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=3;depth++){
1452  if((Statistic=he_data[eta+42][phi-1][depth-1].get_statistics1())>10){
1453  Eta=eta; Phi=phi; Depth=depth;
1454  Status=he_data[eta+42][phi-1][depth-1].get_status();
1455  he_data[eta+42][phi-1][depth-1].get_average_amp1(&amp,&rms);
1456  he_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
1457  tree->Fill();
1458  }
1459  }
1460  sprintf(Subdet,"HO");
1461  for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++) for(int depth=4;depth<=4;depth++){
1462  if((Statistic=ho_data[eta+42][phi-1][depth-1].get_statistics1())>10){
1463  Eta=eta; Phi=phi; Depth=depth;
1464  Status=ho_data[eta+42][phi-1][depth-1].get_status();
1465  ho_data[eta+42][phi-1][depth-1].get_average_amp1(&amp,&rms);
1466  ho_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
1467  tree->Fill();
1468  }
1469  }
1470  sprintf(Subdet,"HF");
1471  for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
1472  if((Statistic=hf_data[eta+42][phi-1][depth-1].get_statistics1())>10){
1473  Eta=eta; Phi=phi; Depth=depth;
1474  Status=hf_data[eta+42][phi-1][depth-1].get_status();
1475  hf_data[eta+42][phi-1][depth-1].get_average_amp1(&amp,&rms);
1476  hf_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
1477  tree->Fill();
1478  }
1479  }
1480  sprintf(Subdet,"CALIB_HB");
1481  for(int eta=-1;eta<=1;eta++) for(int phi=1;phi<=72;phi++){
1482  if((Statistic=calib_data[1][eta+2][phi-1].get_statistics1())>10){
1483  Eta=eta; Phi=phi; Depth=0;
1484  Status=calib_data[1][eta+2][phi-1].get_status();
1485  calib_data[1][eta+2][phi-1].get_average_amp1(&amp,&rms);
1486  calib_data[1][eta+2][phi-1].get_average_time1(&Time,&time_rms);
1487  tree->Fill();
1488  }
1489  }
1490  sprintf(Subdet,"CALIB_HE");
1491  for(int eta=-1;eta<=1;eta++) for(int phi=1;phi<=72;phi++){
1492  if((Statistic=calib_data[2][eta+2][phi-1].get_statistics1())>10){
1493  Eta=eta; Phi=phi; Depth=0;
1494  Status=calib_data[2][eta+2][phi-1].get_status();
1495  calib_data[2][eta+2][phi-1].get_average_amp1(&amp,&rms);
1496  calib_data[2][eta+2][phi-1].get_average_time1(&Time,&time_rms);
1497  tree->Fill();
1498  }
1499  }
1500  sprintf(Subdet,"CALIB_HO");
1501  for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
1502  if((Statistic=calib_data[3][eta+2][phi-1].get_statistics1())>10){
1503  Eta=eta; Phi=phi; Depth=0;
1504  Status=calib_data[3][eta+2][phi-1].get_status();
1505  calib_data[3][eta+2][phi-1].get_average_amp1(&amp,&rms);
1506  calib_data[3][eta+2][phi-1].get_average_time1(&Time,&time_rms);
1507  tree->Fill();
1508  }
1509  }
1510  sprintf(Subdet,"CALIB_HF");
1511  for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
1512  if((Statistic=calib_data[4][eta+2][phi-1].get_statistics1())>10){
1513  Eta=eta; Phi=phi; Depth=0;
1514  Status=calib_data[4][eta+2][phi-1].get_status();
1515  calib_data[4][eta+2][phi-1].get_average_amp1(&amp,&rms);
1516  calib_data[4][eta+2][phi-1].get_average_time1(&Time,&time_rms);
1517  tree->Fill();
1518  }
1519  }
1520  theFile->Write();
1521  theFile->Close();
1522  }
1523  if(XmlFilePath.size()>0){
1524  char TIME[40];
1525  Long_t t; t=time(0); strftime(TIME,30,"%F %T",localtime(&t));
1526  //create XML file
1527  if(!Overwrite){
1528  sprintf(str,"HcalDetDiagLaser_%i_%i.xml",run_number,dataset_seq_number);
1529  }else{
1530  sprintf(str,"HcalDetDiagLaser.xml");
1531  }
1532  std::string xmlName=str;
1533  ofstream xmlFile;
1534  xmlFile.open(xmlName.c_str());
1535 
1536  xmlFile<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
1537  xmlFile<<"<ROOT>\n";
1538  xmlFile<<" <HEADER>\n";
1539  xmlFile<<" <HINTS mode='only-det-root'/>\n";
1540  xmlFile<<" <TYPE>\n";
1541  xmlFile<<" <EXTENSION_TABLE_NAME>HCAL_DETMON_LED_LASER_V1</EXTENSION_TABLE_NAME>\n";
1542  xmlFile<<" <NAME>HCAL Laser HBHE HPD [abort gap global]</NAME>\n";
1543  xmlFile<<" </TYPE>\n";
1544  xmlFile<<" <!-- run details -->\n";
1545  xmlFile<<" <RUN>\n";
1546  xmlFile<<" <RUN_TYPE>GLOBAL-RUN</RUN_TYPE>\n";
1547  xmlFile<<" <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
1548  xmlFile<<" <RUN_BEGIN_TIMESTAMP>2009-01-01 00:00:00</RUN_BEGIN_TIMESTAMP>\n";
1549  xmlFile<<" <COMMENT_DESCRIPTION>hcal laser data</COMMENT_DESCRIPTION>\n";
1550  xmlFile<<" <LOCATION>P5</LOCATION>\n";
1551  xmlFile<<" <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
1552  xmlFile<<" </RUN>\n";
1553  xmlFile<<" </HEADER>\n";
1554  xmlFile<<" <DATA_SET>\n";
1555  xmlFile<<" <!-- optional dataset metadata -->\n\n";
1556  xmlFile<<" <SET_NUMBER>"<<dataset_seq_number<<"</SET_NUMBER>\n";
1557  xmlFile<<" <SET_BEGIN_TIMESTAMP>2009-01-01 00:00:00</SET_BEGIN_TIMESTAMP>\n";
1558  xmlFile<<" <SET_END_TIMESTAMP>2009-01-01 00:00:00</SET_END_TIMESTAMP>\n";
1559  xmlFile<<" <NUMBER_OF_EVENTS_IN_SET>"<<ievt_<<"</NUMBER_OF_EVENTS_IN_SET>\n";
1560  xmlFile<<" <COMMENT_DESCRIPTION>Automatic DQM output</COMMENT_DESCRIPTION>\n";
1561  xmlFile<<" <DATA_FILE_NAME>"<< xmlName <<"</DATA_FILE_NAME>\n";
1562  xmlFile<<" <IMAGE_FILE_NAME>data plot url or file path</IMAGE_FILE_NAME>\n";
1563  xmlFile<<" <!-- who and when created this dataset-->\n\n";
1564  xmlFile<<" <CREATE_TIMESTAMP>"<<TIME<<"</CREATE_TIMESTAMP>\n";
1565  xmlFile<<" <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
1566  xmlFile<<" <!-- version (string) and subversion (number) -->\n";
1567  xmlFile<<" <!-- fields are used to read data back from the database -->\n\n";
1568  xmlFile<<" <VERSION>"<<run_number<<dataset_seq_number<<"</VERSION>\n";
1569  xmlFile<<" <SUBVERSION>1</SUBVERSION>\n";
1570  xmlFile<<" <!-- Assign predefined dataset attributes -->\n\n";
1571  xmlFile<<" <PREDEFINED_ATTRIBUTES>\n";
1572  xmlFile<<" <ATTRIBUTE>\n";
1573  xmlFile<<" <NAME>HCAL Dataset Status</NAME>\n";
1574  xmlFile<<" <VALUE>VALID</VALUE>\n";
1575  xmlFile<<" </ATTRIBUTE>\n";
1576  xmlFile<<" </PREDEFINED_ATTRIBUTES>\n";
1577  xmlFile<<" <!-- multiple data block records -->\n\n";
1578 
1579  std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
1580  for(std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
1581  DetId detid=emap->lookup(*eid);
1582  if (detid.det()!=DetId::Hcal) continue;
1583  HcalGenericDetId gid(emap->lookup(*eid));
1584  if(!(!(gid.null()) &&
1585  (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
1586  gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap ||
1587  gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
1588  gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
1589  int eta,phi,depth;
1590  std::string subdet="";
1591  HcalDetId hid(detid);
1592  eta=hid.ieta();
1593  phi=hid.iphi();
1594  depth=hid.depth();
1595 
1596  double e=0,e_rms=0,t=0,t_rms=0;
1597  if(detid.subdetId()==HcalBarrel){
1598  subdet="HB";
1599  Statistic=hb_data[eta+42][phi-1][depth-1].get_statistics1();
1600  Status =hb_data[eta+42][phi-1][depth-1].get_status();
1601  hb_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
1602  hb_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
1603  }else if(detid.subdetId()==HcalEndcap){
1604  subdet="HE";
1605  Statistic=he_data[eta+42][phi-1][depth-1].get_statistics1();
1606  Status =he_data[eta+42][phi-1][depth-1].get_status();
1607  he_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
1608  he_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
1609  }else if(detid.subdetId()==HcalForward){
1610  subdet="HF";
1611  Statistic=hf_data[eta+42][phi-1][depth-1].get_statistics1();
1612  Status =hf_data[eta+42][phi-1][depth-1].get_status();
1613  hf_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
1614  hf_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
1615  }else if(detid.subdetId()==HcalOuter){
1616  subdet="HO";
1617  Statistic=ho_data[eta+42][phi-1][depth-1].get_statistics1();
1618  Status =ho_data[eta+42][phi-1][depth-1].get_status();
1619  ho_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
1620  ho_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
1621  }else continue;
1622  xmlFile<<" <DATA>\n";
1623  xmlFile<<" <NUMBER_OF_EVENTS_USED>"<<Statistic<<"</NUMBER_OF_EVENTS_USED>\n";
1624  xmlFile<<" <SIGNAL_MEAN>"<<e<<"</SIGNAL_MEAN>\n";
1625  xmlFile<<" <SIGNAL_RMS>"<<e_rms<<"</SIGNAL_RMS>\n";
1626  xmlFile<<" <TIME_MEAN>"<<t<<"</TIME_MEAN>\n";
1627  xmlFile<<" <TIME_RMS>"<<t_rms<<"</TIME_RMS>\n";
1628  xmlFile<<" <CHANNEL_STATUS_WORD>"<<Status<<"</CHANNEL_STATUS_WORD>\n";
1629  xmlFile<<" <CHANNEL_OBJECTNAME>HcalDetId</CHANNEL_OBJECTNAME>\n";
1630  xmlFile<<" <SUBDET>"<<subdet<<"</SUBDET>\n";
1631  xmlFile<<" <IETA>"<<eta<<"</IETA>\n";
1632  xmlFile<<" <IPHI>"<<phi<<"</IPHI>\n";
1633  xmlFile<<" <DEPTH>"<<depth<<"</DEPTH>\n";
1634  xmlFile<<" <TYPE>0</TYPE>\n";
1635  xmlFile<<" </DATA>\n";
1636  }
1638  xmlFile<<" </DATA_SET>\n";
1639  xmlFile<<"</ROOT>\n";
1640  xmlFile.close();
1641 
1642 
1643  //create CALIB XML file
1644  sprintf(str,"HcalDetDiagLaserCalib_%i_%i.xml",run_number,dataset_seq_number);
1645  std::string xmlNameCalib=str;
1646  ofstream xmlFileCalib;
1647  xmlFileCalib.open(xmlNameCalib.c_str());
1648 
1649  xmlFileCalib<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
1650  xmlFileCalib<<"<ROOT>\n";
1651  xmlFileCalib<<" <HEADER>\n";
1652  xmlFileCalib<<" <HINTS mode='only-det-root'/>\n";
1653  xmlFileCalib<<" <TYPE>\n";
1654  xmlFileCalib<<" <EXTENSION_TABLE_NAME>HCAL_DETMON_LED_LASER_V1</EXTENSION_TABLE_NAME>\n";
1655  xmlFileCalib<<" <NAME>HCAL Laser CALIB [abort gap global]</NAME>\n";
1656  xmlFileCalib<<" </TYPE>\n";
1657  xmlFileCalib<<" <!-- run details -->\n";
1658  xmlFileCalib<<" <RUN>\n";
1659  xmlFileCalib<<" <RUN_TYPE>Global-RUN</RUN_TYPE>\n";
1660  xmlFileCalib<<" <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
1661  xmlFileCalib<<" <RUN_BEGIN_TIMESTAMP>2009-01-01 00:00:00</RUN_BEGIN_TIMESTAMP>\n";
1662  xmlFileCalib<<" <COMMENT_DESCRIPTION>hcal Laser CALIB data</COMMENT_DESCRIPTION>\n";
1663  xmlFileCalib<<" <LOCATION>P5</LOCATION>\n";
1664  xmlFileCalib<<" <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
1665  xmlFileCalib<<" </RUN>\n";
1666  xmlFileCalib<<" </HEADER>\n";
1667  xmlFileCalib<<" <DATA_SET>\n";
1668  xmlFileCalib<<" <!-- optional dataset metadata -->\n\n";
1669  xmlFileCalib<<" <SET_NUMBER>"<<dataset_seq_number<<"</SET_NUMBER>\n";
1670  xmlFileCalib<<" <SET_BEGIN_TIMESTAMP>2009-01-01 00:00:00</SET_BEGIN_TIMESTAMP>\n";
1671  xmlFileCalib<<" <SET_END_TIMESTAMP>2009-01-01 00:00:00</SET_END_TIMESTAMP>\n";
1672  xmlFileCalib<<" <NUMBER_OF_EVENTS_IN_SET>"<<ievt_<<"</NUMBER_OF_EVENTS_IN_SET>\n";
1673  xmlFileCalib<<" <COMMENT_DESCRIPTION>Automatic DQM output</COMMENT_DESCRIPTION>\n";
1674  xmlFileCalib<<" <DATA_FILE_NAME>"<< xmlNameCalib <<"</DATA_FILE_NAME>\n";
1675  xmlFileCalib<<" <IMAGE_FILE_NAME>data plot url or file path</IMAGE_FILE_NAME>\n";
1676  xmlFileCalib<<" <!-- who and when created this dataset-->\n\n";
1677  xmlFileCalib<<" <CREATE_TIMESTAMP>"<<TIME<<"</CREATE_TIMESTAMP>\n";
1678  xmlFileCalib<<" <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
1679  xmlFileCalib<<" <!-- version (string) and subversion (number) -->\n";
1680  xmlFileCalib<<" <!-- fields are used to read data back from the database -->\n\n";
1681  xmlFileCalib<<" <VERSION>"<<run_number<<dataset_seq_number<<"</VERSION>\n";
1682  xmlFileCalib<<" <SUBVERSION>1</SUBVERSION>\n";
1683  xmlFileCalib<<" <!-- Assign predefined dataset attributes -->\n\n";
1684  xmlFileCalib<<" <PREDEFINED_ATTRIBUTES>\n";
1685  xmlFileCalib<<" <ATTRIBUTE>\n";
1686  xmlFileCalib<<" <NAME>HCAL Dataset Status</NAME>\n";
1687  xmlFileCalib<<" <VALUE>VALID</VALUE>\n";
1688  xmlFileCalib<<" </ATTRIBUTE>\n";
1689  xmlFileCalib<<" </PREDEFINED_ATTRIBUTES>\n";
1690  xmlFileCalib<<" <!-- multiple data block records -->\n\n";
1691 
1692  for(int sd=1;sd<=4;sd++) for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
1693  std::string subdet="";
1694  if(sd==1) subdet="HB";
1695  if(sd==2) subdet="HE";
1696  if(sd==3) subdet="HO";
1697  if(sd==4) subdet="HF";
1698  if((calib_data[sd][eta+2][phi-1].get_statistics())>100){
1699  double e=0,e_rms=0,t=0,t_rms=0;
1700  Status=calib_data[sd][eta+2][phi-1].get_status();
1701  Statistic=calib_data[sd][eta+2][phi-1].get_statistics1();
1702  calib_data[sd][eta+2][phi-1].get_average_amp1(&e,&e_rms);
1703  calib_data[sd][eta+2][phi-1].get_average_time1(&t,&t_rms);
1704  xmlFileCalib<<" <DATA>\n";
1705  xmlFileCalib<<" <NUMBER_OF_EVENTS_USED>"<<Statistic<<"</NUMBER_OF_EVENTS_USED>\n";
1706  xmlFileCalib<<" <SIGNAL_MEAN>"<<e<<"</SIGNAL_MEAN>\n";
1707  xmlFileCalib<<" <SIGNAL_RMS>"<<e_rms<<"</SIGNAL_RMS>\n";
1708  xmlFileCalib<<" <TIME_MEAN>"<<t<<"</TIME_MEAN>\n";
1709  xmlFileCalib<<" <TIME_RMS>"<<t_rms<<"</TIME_RMS>\n";
1710  xmlFileCalib<<" <CHANNEL_STATUS_WORD>"<<Status<<"</CHANNEL_STATUS_WORD>\n";
1711  xmlFileCalib<<" <CHANNEL_OBJECTNAME>HcalDetId</CHANNEL_OBJECTNAME>\n";
1712  xmlFileCalib<<" <SUBDET>"<<subdet<<"</SUBDET>\n";
1713  xmlFileCalib<<" <IETA>"<<eta<<"</IETA>\n";
1714  xmlFileCalib<<" <IPHI>"<<phi<<"</IPHI>\n";
1715  xmlFileCalib<<" <DEPTH>"<<0<<"</DEPTH>\n";
1716  xmlFileCalib<<" <TYPE>0</TYPE>\n";
1717  xmlFileCalib<<" </DATA>\n";
1718  }
1719  }
1721  xmlFileCalib<<" </DATA_SET>\n";
1722  xmlFileCalib<<"</ROOT>\n";
1723  xmlFileCalib.close();
1724 
1725  sprintf(str,"zip %s.zip %s %s",xmlName.c_str(),xmlName.c_str(),xmlNameCalib.c_str());
1726  system(str);
1727  sprintf(str,"rm -f %s %s",xmlName.c_str(),xmlNameCalib.c_str());
1728  system(str);
1729  sprintf(str,"mv -f %s.zip %s",xmlName.c_str(),XmlFilePath.c_str());
1730  system(str);
1731 
1732  }
1733  for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) hb_data[i][j][k].reset1();
1734  for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) he_data[i][j][k].reset1();
1735  for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) ho_data[i][j][k].reset1();
1736  for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) hf_data[i][j][k].reset1();
1737  for(int i=1;i<=4;i++)for(int j=-2;j<=2;j++)for(int k=1;k<=72;k++)calib_data[i][j][k].reset1();
1738  ievt_=0;
1740 }
1742 double amp,rms,time,time_rms;
1743 int Eta,Phi,Depth;
1744 char subdet[10];
1745 TFile *f;
1746  if(gSystem->AccessPathName(ReferenceData.c_str())) return;
1747  f = new TFile(ReferenceData.c_str(),"READ");
1748 
1749  if(!f->IsOpen()) return ;
1750  TObjString *STR=(TObjString *)f->Get("run number");
1751 
1752  if(STR){ std::string Ref(STR->String()); ReferenceRun=Ref;}
1753 
1754  TTree* t=(TTree*)f->Get("HCAL Laser data");
1755  if(!t) return;
1756  t->SetBranchAddress("Subdet", subdet);
1757  t->SetBranchAddress("eta", &Eta);
1758  t->SetBranchAddress("phi", &Phi);
1759  t->SetBranchAddress("depth", &Depth);
1760  t->SetBranchAddress("amp", &amp);
1761  t->SetBranchAddress("rms", &rms);
1762  t->SetBranchAddress("time", &time);
1763  t->SetBranchAddress("time_rms", &time_rms);
1764  for(int ievt=0;ievt<t->GetEntries();ievt++){
1765  t->GetEntry(ievt);
1766  if(strcmp(subdet,"HB")==0) hb_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
1767  if(strcmp(subdet,"HE")==0) he_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
1768  if(strcmp(subdet,"HO")==0) ho_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
1769  if(strcmp(subdet,"HF")==0) hf_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
1770  if(strcmp(subdet,"CALIB_HB")==0) calib_data[1][Eta+2][Phi-1].set_reference(amp,rms,time,time_rms);
1771  if(strcmp(subdet,"CALIB_HE")==0) calib_data[2][Eta+2][Phi-1].set_reference(amp,rms,time,time_rms);
1772  if(strcmp(subdet,"CALIB_HO")==0) calib_data[3][Eta+2][Phi-1].set_reference(amp,rms,time,time_rms);
1773  if(strcmp(subdet,"CALIB_HF")==0) calib_data[4][Eta+2][Phi-1].set_reference(amp,rms,time,time_rms);
1774  }
1775  f->Close();
1776  IsReference=true;
1777 }
1779 double amp,rms,time,time_rms;
1780 int Eta,Phi,Depth,Statistic;
1781 char subdet[10];
1782 TFile *f;
1783  if(DatasetName.size()==0) return;
1784  createHTMLonly=true;
1785  if(gSystem->AccessPathName(DatasetName.c_str())) return;
1786  f = new TFile(DatasetName.c_str(),"READ");
1787 
1788  if(!f->IsOpen()) return ;
1789 
1790  TTree* t=0;
1791  t=(TTree*)f->Get("HCAL Laser data");
1792  if(!t) return;
1793  t->SetBranchAddress("Subdet", subdet);
1794  t->SetBranchAddress("eta", &Eta);
1795  t->SetBranchAddress("phi", &Phi);
1796  t->SetBranchAddress("depth", &Depth);
1797  t->SetBranchAddress("amp", &amp);
1798  t->SetBranchAddress("rms", &rms);
1799  t->SetBranchAddress("time", &time);
1800  t->SetBranchAddress("time_rms", &time_rms);
1801  t->SetBranchAddress("statistic",&Statistic);
1802  for(int ievt=0;ievt<t->GetEntries();ievt++){
1803  t->GetEntry(ievt);
1804  if(strcmp(subdet,"HB")==0){ nHB++;
1805  hb_data[Eta+42][Phi-1][Depth-1].set_data(amp,rms,time,time_rms);
1806  hb_data[Eta+42][Phi-1][Depth-1].set_statistics(Statistic);
1807  hb_data[Eta+42][Phi-1][Depth-1].set_statistics1(Statistic);
1808  }
1809  if(strcmp(subdet,"HE")==0){ nHE++;
1810  he_data[Eta+42][Phi-1][Depth-1].set_data(amp,rms,time,time_rms);
1811  he_data[Eta+42][Phi-1][Depth-1].set_statistics(Statistic);
1812  he_data[Eta+42][Phi-1][Depth-1].set_statistics1(Statistic);
1813  }
1814  if(strcmp(subdet,"HO")==0){ nHO++;
1815  ho_data[Eta+42][Phi-1][Depth-1].set_data(amp,rms,time,time_rms);
1816  ho_data[Eta+42][Phi-1][Depth-1].set_statistics(Statistic);
1817  ho_data[Eta+42][Phi-1][Depth-1].set_statistics1(Statistic);
1818  }
1819  if(strcmp(subdet,"HF")==0){ nHF++;
1820  hf_data[Eta+42][Phi-1][Depth-1].set_data(amp,rms,time,time_rms);
1821  hf_data[Eta+42][Phi-1][Depth-1].set_statistics(Statistic);
1822  hf_data[Eta+42][Phi-1][Depth-1].set_statistics1(Statistic);
1823  }
1824  if(strcmp(subdet,"CALIB_HB")==0){
1825  calib_data[1][Eta+2][Phi-1].set_data(amp,rms,time,time_rms);
1826  calib_data[1][Eta+2][Phi-1].set_statistics(Statistic);
1827  calib_data[1][Eta+2][Phi-1].set_statistics1(Statistic);
1828  }
1829  if(strcmp(subdet,"CALIB_HE")==0){
1830  calib_data[2][Eta+2][Phi-1].set_data(amp,rms,time,time_rms);
1831  calib_data[2][Eta+2][Phi-1].set_statistics(Statistic);
1832  calib_data[2][Eta+2][Phi-1].set_statistics1(Statistic);
1833  }
1834  if(strcmp(subdet,"CALIB_HO")==0){
1835  calib_data[3][Eta+2][Phi-1].set_data(amp,rms,time,time_rms);
1836  calib_data[3][Eta+2][Phi-1].set_statistics(Statistic);
1837  calib_data[3][Eta+2][Phi-1].set_statistics1(Statistic);
1838  }
1839  if(strcmp(subdet,"CALIB_HF")==0){
1840  calib_data[4][Eta+2][Phi-1].set_data(amp,rms,time,time_rms);
1841  calib_data[4][Eta+2][Phi-1].set_statistics(Statistic);
1842  calib_data[4][Eta+2][Phi-1].set_statistics1(Statistic);
1843  }
1844  }
1845  TObjString *STR1=(TObjString *)f->Get("run number");
1846  if(STR1){ int run; sscanf(STR1->String(),"%i",&run); meRUN_->Fill(run); run_number=run;}
1847 
1848  TObjString *STR2=(TObjString *)f->Get("Total events processed");
1849  if(STR2){ int events; sscanf(STR2->String(),"%i",&events); meEVT_->Fill(events); ievt_=events;}
1850 
1851  TObjString *STR3=(TObjString *)f->Get("Dataset number");
1852  if(STR3){ int ds; sscanf(STR3->String(),"%i",&ds); dataset_seq_number=ds;}
1853  f->Close();
1854 }
1855 
1857 float adc_range[20]={14,28,40,52,67,132,202,262,322,397,722,1072,1372,1672,2047,3672,5422,6922,8422,10297};
1858 int adc_bins[20]={1,2,3,4,5,5,10,15,20,25,25,50,75,100,125,125,250,375,500,625};
1859 char str[100];
1860  TF1 *fitFunc = new TF1("fitFunc","gaus");
1861  if(fitFunc==0) return;
1862  for(int i=0;i<56;i++){
1863  float sum1=0,sum2=0,n=0;
1864  S1[i]=S2[i]=0;
1865  for(int j=0;j<128;j++){
1866  sum1+=(adc2fC[j]-2.5)*Raddam_data[i].s1_adc[j];
1867  sum2+=(adc2fC[j]-2.5)*Raddam_data[i].s2_adc[j];
1868  n+=Raddam_data[i].s1_adc[j];
1869  }
1870  if(n<100) continue;
1871  sum1=sum1/n;
1872  sum2=sum2/n;
1873  int N=0;
1874  int Ws1=1,Ws2=1;
1875  for(N=1;N<19;N++) if(sum1>adc_range[N-1] && sum1<adc_range[N]) break;
1876  Ws1=adc_bins[N+1];
1877  for(N=1;N<19;N++) if(sum2>adc_range[N-1] && sum2<adc_range[N]) break;
1878  Ws2=adc_bins[N+1];
1879  sprintf(str,"Raddam(%i,%i,%i) S1",RADDAM_CH[i].eta,RADDAM_CH[i].phi,RADDAM_CH[i].depth);
1880  S1[i]=new TH1F(str,str,10000/Ws1,0,10000);
1881  sprintf(str,"Raddam(%i,%i,%i) S2",RADDAM_CH[i].eta,RADDAM_CH[i].phi,RADDAM_CH[i].depth);
1882  S2[i]=new TH1F(str,str,10000/Ws1,0,10000);
1883  for(int j=0;j<128;j++){
1884  S1[i]->Fill(adc2fC[j]-2.5,Raddam_data[i].s1_adc[j]);
1885  S2[i]->Fill(adc2fC[j]-2.5,Raddam_data[i].s2_adc[j]);
1886  }
1887  double parm[3];
1888  S1[i]->Fit("fitFunc");
1889  S1[i]->GetFunction("fitFunc")->GetParameters(parm);
1890  Raddam_data[i].S1MEAN=S1[i]->GetMean();
1891  Raddam_data[i].S1RMS=S1[i]->GetRMS();
1892  Raddam_data[i].S1FITMEAN=parm[1];
1893  Raddam_data[i].S1FITMEANER=S1[i]->GetFunction("fitFunc")->GetParError(1);
1894  Raddam_data[i].S1FITSIGMA=parm[2];
1895  Raddam_data[i].S1CHI2=S1[i]->GetFunction("fitFunc")->GetChisquare();
1896  Raddam_data[i].S1NDF=S1[i]->GetFunction("fitFunc")->GetNDF();
1897  Raddam_data[i].S1BINWIDTH=Ws1;
1898  S2[i]->Fit("fitFunc");
1899  S2[i]->GetFunction("fitFunc")->GetParameters(parm);
1900  Raddam_data[i].S2MEAN=S2[i]->GetMean();
1901  Raddam_data[i].S2RMS=S2[i]->GetRMS();
1902  Raddam_data[i].S2FITMEAN=parm[1];
1903  Raddam_data[i].S2FITMEANER=S2[i]->GetFunction("fitFunc")->GetParError(1);
1904  Raddam_data[i].S2FITSIGMA=parm[2];
1905  Raddam_data[i].S2CHI2=S2[i]->GetFunction("fitFunc")->GetChisquare();
1906  Raddam_data[i].S2NDF=S2[i]->GetFunction("fitFunc")->GetNDF();
1907  Raddam_data[i].S2BINWIDTH=Ws2;
1908  }
1909  if(XmlFilePath.size()>0){
1910  char TIME[40];
1911  Long_t t; t=time(0); strftime(TIME,30,"%F %T",localtime(&t));
1912  //create XML file
1913  if(!Overwrite){
1914  sprintf(str,"HcalDetDiagRaddam_%i_%i.xml",run_number,dataset_seq_number);
1915  }else{
1916  sprintf(str,"HcalDetDiagRaddam.xml");
1917  }
1918  std::string xmlName=str;
1919  ofstream xmlFile;
1920  xmlFile.open(xmlName.c_str());
1921  xmlFile<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
1922  xmlFile<<"<ROOT>\n";
1923  xmlFile<<" <HEADER>\n";
1924  xmlFile<<" <TYPE>\n";
1925  xmlFile<<" <EXTENSION_TABLE_NAME>HCAL_RADDAM</EXTENSION_TABLE_NAME>\n";
1926  xmlFile<<" <NAME>HCAL Raddam</NAME>\n";
1927  xmlFile<<" </TYPE>\n";
1928  xmlFile<<" <!-- run details -->\n";
1929  xmlFile<<" <RUN>\n";
1930  xmlFile<<" <RUN_TYPE>TEST LOCAL-RUN</RUN_TYPE>\n";
1931  xmlFile<<" <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
1932  xmlFile<<" <RUN_BEGIN_TIMESTAMP>"<<TIME<<"</RUN_BEGIN_TIMESTAMP>\n";
1933  xmlFile<<" <COMMENT_DESCRIPTION>hcal raddam data</COMMENT_DESCRIPTION>\n";
1934  xmlFile<<" <LOCATION>P5</LOCATION>\n";
1935  xmlFile<<" <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
1936  xmlFile<<" </RUN>\n";
1937  xmlFile<<" </HEADER>\n";
1938  xmlFile<<" <DATA_SET>\n";
1939  xmlFile<<" <COMMENT_DESCRIPTION>Test Raddam data</COMMENT_DESCRIPTION>\n";
1940  xmlFile<<" <CREATE_TIMESTAMP>"<<TIME<<"</CREATE_TIMESTAMP>\n";
1941  xmlFile<<" <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
1942  xmlFile<<" <VERSION>Test_Version_1</VERSION>\n";
1943 
1944  for(int i=0;i<56;i++){
1945  xmlFile<<" <DATA>\n";
1946  xmlFile<<" <SUBDET>HF</SUBDET>\n";
1947  xmlFile<<" <IETA>"<<RADDAM_CH[i].eta<<"</IETA>\n";
1948  xmlFile<<" <IPHI>"<<RADDAM_CH[i].phi<<"</IPHI>\n";
1949  xmlFile<<" <DEPTH>"<<RADDAM_CH[i].depth<<"</DEPTH>\n";
1950 
1951  xmlFile<<" <TOTEVNT>"<<Raddam_data[i].TOTEVNT<<"</TOTEVNT>\n";
1952  xmlFile<<" <CUT1EVNT>"<<Raddam_data[i].CUT1EVNT<<"</CUT1EVNT>\n";
1953  xmlFile<<" <CUT2EVNT>"<<Raddam_data[i].CUT2EVNT<<"</CUT2EVNT>\n";
1954 
1955  xmlFile<<" <S1MEAN>"<<Raddam_data[i].S1MEAN <<"</S1MEAN>\n";
1956  xmlFile<<" <S1RMS>"<<Raddam_data[i].S1RMS <<"</S1RMS>\n";
1957  xmlFile<<" <S1FITMEAN>"<<Raddam_data[i].S1FITMEAN <<"</S1FITMEAN>\n";
1958  xmlFile<<" <S1FITMEANER>"<<Raddam_data[i].S1FITMEANER <<"</S1FITMEANER>\n";
1959  xmlFile<<" <S1FITSIGMA>"<<Raddam_data[i].S1FITSIGMA <<"</S1FITSIGMA>\n";
1960  xmlFile<<" <S1CHI2>"<<Raddam_data[i].S1CHI2 <<"</S1CHI2>\n";
1961  xmlFile<<" <S1NDF>"<<Raddam_data[i].S1NDF <<"</S1NDF>\n";
1962  xmlFile<<" <S1BINWIDTH>"<<Raddam_data[i].S1BINWIDTH <<"</S1BINWIDTH>\n";
1963 
1964  xmlFile<<" <S2MEAN>"<<Raddam_data[i].S2MEAN <<"</S2MEAN>\n";
1965  xmlFile<<" <S2RMS>"<<Raddam_data[i].S2RMS <<"</S2RMS>\n";
1966  xmlFile<<" <S2FITMEAN>"<<Raddam_data[i].S2FITMEAN <<"</S2FITMEAN>\n";
1967  xmlFile<<" <S2FITMEANER>"<<Raddam_data[i].S2FITMEANER <<"</S2FITMEANER>\n";
1968  xmlFile<<" <S2FITSIGMA>"<<Raddam_data[i].S2FITSIGMA <<"</S2FITSIGMA>\n";
1969  xmlFile<<" <S2CHI2>"<<Raddam_data[i].S2CHI2 <<"</S2CHI2>\n";
1970  xmlFile<<" <S2NDF>"<<Raddam_data[i].S2NDF <<"</S2NDF>\n";
1971  xmlFile<<" <S2BINWIDTH>"<<Raddam_data[i].S2BINWIDTH <<"</S2BINWIDTH>\n";
1972  xmlFile<<" </DATA>\n";
1973  }
1974  xmlFile<<" </DATA_SET>\n";
1975  xmlFile<<"</ROOT>\n";
1976 
1977  xmlFile.close();
1978  sprintf(str,"zip %s.zip %s",xmlName.c_str(),xmlName.c_str());
1979  system(str);
1980  sprintf(str,"rm -f %s",xmlName.c_str());
1981  system(str);
1982  sprintf(str,"mv -f %s.zip %s",xmlName.c_str(),XmlFilePath.c_str());
1983  system(str);
1984  }
1985  if(OutputFilePath.size()>0){
1986  if(!Overwrite){
1987  sprintf(str,"%sHcalDetDiagRaddamData_run%06i_%i.root",OutputFilePath.c_str(),run_number,dataset_seq_number);
1988  }else{
1989  sprintf(str,"%sHcalDetDiagRaddamData.root",OutputFilePath.c_str());
1990  }
1991  TFile *theFile = new TFile(str, "RECREATE");
1992  if(!theFile->IsOpen()) return;
1993  theFile->cd();
1994  for(int i=0;i<56;i++){
1995  if(S1[i]!=0)S1[i]->Write();
1996  if(S2[i]!=0)S2[i]->Write();
1997  }
1998  theFile->Write();
1999  theFile->Close();
2000  }
2001 }
2002 
2004  if(RaddamRun){
2005  SaveRaddamData();
2006  }
2007  if((LocalRun || !Online_ || createHTMLonly) && ievt_>10){
2015  if(!RaddamRun)SaveReference();
2016  }
2017 }
2018 
2021 
2022 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
void add_statistics(double *data, int nTS)
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
double GetEnergy(double *data, int n)
HcalDetDiagLaserData * GetCalib(std::string sd, int eta, int phi)
virtual void analyze(const edm::Event &e, const edm::EventSetup &c)
void set_reference(float val, float rms, float time, float time_rms)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
void setAxisRange(double xmin, double xmax, int axis=1)
set x-, y- or z-axis range (axis=1, 2, 3 respectively)
bool get_average_amp(double *ave, double *rms)
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
bool get_average_amp1(double *ave, double *rms)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void beginRun(const edm::Run &run, const edm::EventSetup &c)
static const float adc2fC[128]
const HcalElectronicsMap * emap
std::vector< T >::const_iterator const_iterator
void setup(DQMStore *&m_dbe, std::string Name, std::string Units="")
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
#define abs(x)
Definition: mlp_lapack.h:159
bool getByType(Handle< PROD > &result) const
Definition: Event.h:397
#define min(a, b)
Definition: mlp_lapack.h:161
bool get_ave_subdet(int sd, float *ave_t, float *ave_e, float *ave_t_r, float *ave_e_r)
HcalRaddamData Raddam_data[56]
T eta() const
bool get_ave_rbx(int sd, int side, int rbx, float *ave, float *rms)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
bool get_average_time(double *ave, double *rms)
std::map< unsigned int, int > KnownBadCells_
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
Raddam_ch RADDAM_CH[56]
void endRun(const edm::Run &run, const edm::EventSetup &c)
bool isSiPM(int ieta, int iphi, int depth)
int depth() const
get the tower depth
Definition: HcalDetId.h:42
#define ETA
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
int iEvent
Definition: GenABIO.cc:243
std::vector< MonitorElement * > depth
const T & max(const T &a, const T &b)
MonitorElement * bookString(const char *name, const char *value)
Book string.
Definition: DQMStore.cc:480
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
std::vector< DetId > getAllChannels() const
T sqrt(T t)
Definition: SSEVec.h:28
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
int j
Definition: DBlmapReader.cc:9
double f[11][100]
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
int orbitNumber() const
Definition: EventBase.h:63
bool isValid() const
Definition: HandleBase.h:76
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
int k[5][pyjets_maxn]
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
Definition: DetId.h:20
HcalDetDiagLaserData hb_data[85][72][4]
HcalDetDiagLaserMonitor(const edm::ParameterSet &)
bool get_average_time1(double *ave, double *rms)
const T & get() const
Definition: EventSetup.h:55
#define PHI
T const * product() const
Definition: ESHandle.h:62
virtual void reset(void)
bool xmlFile(const std::string fParam)
int CalcEtaBin(int subdet, int ieta, int depth)
double GetTime(double *data, int n=10)
edm::EventID id() const
Definition: EventBase.h:56
HcalDetDiagLaserData hf_data[85][72][4]
tuple events
Definition: patZpeak.py:19
void analyze(const edm::Event &, const edm::EventSetup &)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
bool get_reference(double *val, double *rms, double *time, double *time_rms)
void set_data(float val, float rms, float time, float time_rms)
tuple status
Definition: ntuplemaker.py:245
HcalDetDiagLaserData he_data[85][72][4]
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:421
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:642
virtual void setup(void)
const Item * getValues(DetId fId) const
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
long double T
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
std::vector< std::string > problemnames_
void Reset(void)
reset ME (ie. contents, errors, etc)
HcalDetDiagLaserData ho_data[85][72][4]
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
HcalDetDiagLaserData calib_data[5][5][72]
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
TrackTransientTrack TTT
Definition: Run.h:32
Definition: DDAxes.h:10