CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DQM/HcalMonitorTasks/src/HcalDetDiagLaserMonitor.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HcalDetDiagLaserMonitor
00004 // Class:      HcalDetDiagLaserMonitor
00005 // 
00013 //
00014 // Original Author:  Dmitry Vishnevskiy,591 R-013,+41227674265,
00015 //         Created:  Wed Mar  3 12:14:16 CET 2010
00016 // $Id: HcalDetDiagLaserMonitor.cc,v 1.18 2011/06/30 07:37:20 dma Exp $
00017 //
00018 //
00019 
00020 #include "DQM/HcalMonitorTasks/interface/HcalBaseDQMonitor.h"
00021 #include "FWCore/Framework/interface/Frameworkfwd.h"
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "FWCore/Framework/interface/MakerMacros.h"
00024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00025 
00026 #include "DQMServices/Core/interface/DQMStore.h"
00027 #include "DQMServices/Core/interface/MonitorElement.h"
00028 #include "DQM/HcalMonitorTasks/interface/HcalBaseMonitor.h"
00029 
00030 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00031 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00032 
00033 #include <math.h>
00034 
00035 // this is to retrieve HCAL digi's
00036 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00037 // to retrive trigger information (local runs only)
00038 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
00039 
00040 #include "CalibCalorimetry/HcalAlgos/interface/HcalLogicalMapGenerator.h"
00041 #include "CondFormats/HcalObjects/interface/HcalLogicalMap.h"
00042  
00043 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
00044 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00045 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00046 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00047 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
00048 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00049 
00050 #include "TFile.h"
00051 #include "TTree.h"
00052 #include "TSystem.h"
00053 #include "TF1.h"
00054 
00055 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00056 #include "DQM/HcalMonitorTasks/interface/HcalEtaPhiHists.h"
00057 
00058 #include <iostream>
00059 #include <fstream>
00060 
00062 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,
00063                    13.5,15.,17.,19.,21.,23.,25.,27.,29.5,32.5,35.5,38.5,42.,46.,50.,54.5,59.5,
00064                    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,
00065                    124.5,129.5,137.,147.,157.,167.,177.,187.,197.,209.5,224.5,239.5,254.5,272.,
00066                    292.,312.,334.5,359.5,384.5,359.5,384.5,409.5,434.5,459.5,484.5,509.5,534.5,
00067                    559.5,584.5,609.5,634.5,659.5,684.5,709.5,747.,797.,847.,897.,947.,997.,
00068                    1047.,1109.5,1184.5,1259.5,1334.5,1422.,1522.,1622.,1734.5,1859.5,1984.5,
00069                    1859.5,1984.5,2109.5,2234.5,2359.5,2484.5,2609.5,2734.5,2859.5,2984.5,
00070                    3109.5,3234.5,3359.5,3484.5,3609.5,3797.,4047.,4297.,4547.,4797.,5047.,
00071                    5297.,5609.5,5984.5,6359.5,6734.5,7172.,7672.,8172.,8734.5,9359.5,9984.5};
00073 typedef struct{
00074 int eta;
00075 int phi;
00076 int depth;
00077 }Raddam_ch;
00078 
00079 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},
00080                          {-36,51,1},{-38,35,1},{-38,71,1},{-40,15,1},{-40,51,1},{-41,35,1},{-41,71,1},
00081                          {30,21,1}, {30,57,1}, {32,1,1},  {32,37,1}, {34,21,1}, {34,57,1}, {36,1,1  },
00082                          {36,37,1}, {38,21,1}, {38,57,1}, {40,35,1}, {40,71,1}, {41,19,1}, {41,55,1 },
00083                          {-30,15,2},{-30,51,2},{-32,35,2},{-32,71,2},{-34,15,2},{-34,51,2},{-36,35,2},
00084                          {-36,71,2},{-38,15,2},{-38,51,2},{-40,35,2},{-40,71,2},{-41,15,2},{-41,51,2},
00085                          {30,1,2},  {30,37,2}, {32,21,2}, {32,57,2}, {34,1,2},  {34,37,2}, {36,21,2 },
00086                          {36,57,2}, {38,1,2},  {38,37,2}, {40,19,2}, {40,55,2}, {41,35,2}, {41,71,2}};
00087 class HcalRaddamData{
00088   public:
00089    HcalRaddamData(){
00090       for(int i=0;i<128;i++) s1_adc[i]=s2_adc[i]=0;
00091       TOTEVNT=CUT1EVNT=CUT2EVNT=S1MEAN=S2MEAN=S1RMS=S2RMS=0;
00092       S1FITMEAN=S2FITMEAN=S1FITMEANER=S2FITMEANER=S1FITSIGMA=S2FITSIGMA=0;
00093       S1CHI2=S2CHI2=S1NDF=S2NDF=S1BINWIDTH=S2BINWIDTH=0;
00094    }
00095    ~HcalRaddamData(){};
00096    int TOTEVNT;
00097    int CUT1EVNT;
00098    int CUT2EVNT;
00099    float S1MEAN,S2MEAN;
00100    float S1RMS,S2RMS;
00101    float S1FITMEAN,S2FITMEAN;
00102    float S1FITMEANER,S2FITMEANER;
00103    float S1FITSIGMA,S2FITSIGMA;
00104    float S1CHI2,S2CHI2;
00105    float S1NDF,S2NDF;
00106    float S1BINWIDTH,S2BINWIDTH;
00107    int s1_adc[128];
00108    int s2_adc[128];
00109 };
00110 
00111 HcalRaddamData Raddam_data[56];
00112 
00113 class HcalDetDiagLaserData{
00114 public: 
00115    HcalDetDiagLaserData(){ 
00116              IsRefetence=false;
00117              ds_amp=ds_rms=ds_time=ds_time_rms=-100;
00118              nChecks=0;nBadTime=0;nBadEnergy=0;
00119              status=0;
00120              reset();
00121              reset1();
00122           }
00123    void   reset(){
00124              Xe=XXe=Xt=XXt=n=0;
00125              overflow=0;
00126              undeflow=0;
00127           }
00128    void   reset1(){
00129              Xe1=XXe1=Xt1=XXt1=n1=0;
00130              overflow1=0;
00131              undeflow1=0;
00132           }
00133    void   add_statistics(double *data,int nTS){
00134              double e=GetEnergy(data,nTS);
00135              double t=GetTime(data,nTS);
00136              if(e<20){ undeflow++;undeflow1++; }else if(e>10000){ overflow++;overflow1++; }else{
00137                 n++; Xe+=e; XXe+=e*e; Xt+=t; XXt+=t*t;
00138                 n1++; Xe1+=e; XXe1+=e*e; Xt1+=t; XXt1+=t*t;
00139              }     
00140           }
00141    void   set_reference(float val,float rms,float time,float time_rms){
00142              ref_amp=val; ref_rms=rms;
00143              ref_time=time; ref_time_rms=time_rms;
00144              IsRefetence=true;
00145           }       
00146    void   set_data(float val,float rms,float time,float time_rms){
00147              ds_amp=val; ds_rms=rms;
00148              ds_time=time; ds_time_rms=time_rms;
00149           }       
00150    void   change_status(int val){
00151              status|=val;
00152           }       
00153    int    get_status(){
00154              return status;
00155           }       
00156    bool   get_reference(double *val,double *rms,double *time,double *time_rms){
00157              *val=ref_amp; *rms=ref_rms;
00158              *time=ref_time; *time_rms=ref_time_rms;
00159              return IsRefetence;
00160           }       
00161    bool   get_average_amp(double *ave,double *rms){
00162              if(ds_time>-10){ *ave=ds_amp; *rms=ds_rms; return true; }
00163              if(n>0){ *ave=Xe/n; *rms=sqrt(XXe/n-(Xe*Xe)/(n*n));} else return false;
00164              return true; 
00165           }
00166    bool   get_average_time(double *ave,double *rms){
00167              if(ds_time>-10){ *ave=ds_time; *rms=ds_time_rms; return true; }
00168              if(n>0){ *ave=Xt/n; *rms=sqrt(XXt/n-(Xt*Xt)/(n*n));} else return false;
00169              return true; 
00170           }
00171    int    get_statistics(){
00172              return (int)n;
00173           } 
00174    void   set_statistics(int stat){
00175              n=stat;
00176           } 
00177    void   set_statistics1(int stat){
00178              n1=stat;
00179           } 
00180    int    get_overflow(){
00181              return overflow;
00182           }   
00183    int    get_undeflow(){
00184              return undeflow;
00185           }   
00186    bool   get_average_amp1(double *ave,double *rms){
00187              if(ds_time>-10){ *ave=ds_amp; *rms=ds_rms; return true; }
00188              if(n1>0){ *ave=Xe1/n1; *rms=sqrt(XXe1/n1-(Xe1*Xe1)/(n1*n1));} else return false;
00189              return true; 
00190           }
00191    bool   get_average_time1(double *ave,double *rms){
00192              if(ds_time>-10){ *ave=ds_time; *rms=ds_time_rms; return true; }
00193              if(n1>0){ *ave=Xt1/n1; *rms=sqrt(XXt1/n1-(Xt1*Xt1)/(n1*n1));} else return false;
00194              return true; 
00195           }
00196    int    get_statistics1(){
00197              return (int)n1;
00198           } 
00199    int    get_overflow1(){
00200              return overflow1;
00201           }   
00202    int    get_undeflow1(){
00203              return undeflow1;
00204           }
00205    double GetEnergy(double *data,int n){
00206              int MaxI=0; double Energy,MaxE=0;
00207              for(int j=0;j<n;++j) if(MaxE<data[j]){ MaxE=data[j]; MaxI=j; }
00208              Energy=data[MaxI];
00209              if(MaxI>0) Energy+=data[MaxI-1];
00210              if(MaxI>1) Energy+=data[MaxI-2];
00211              if(MaxI<(n-1)) Energy+=data[MaxI+1];
00212              if(MaxI<(n-2)) Energy+=data[MaxI+2];
00213              return Energy;
00214           }
00215    double GetTime(double *data,int n=10){
00216              int MaxI=-100; double Time=-9999,SumT=0,MaxT=-10;
00217              for(int j=0;j<n;++j) if(MaxT<data[j]){ MaxT=data[j]; MaxI=j; }
00218              if (MaxI>=0) // dummy protection so that compiler doesn't think MaxI=-100
00219                {
00220                  Time=MaxI*data[MaxI];
00221                  SumT=data[MaxI];
00222                  if(MaxI>0){ Time+=(MaxI-1)*data[MaxI-1]; SumT+=data[MaxI-1]; }
00223                  if(MaxI<(n-1)){ Time+=(MaxI+1)*data[MaxI+1]; SumT+=data[MaxI+1]; }
00224                  Time=Time/SumT;
00225                }
00226              return Time;
00227          }
00228    int    overflow;
00229    int    undeflow;
00230    int    overflow1;
00231    int    undeflow1;
00232    double Xe,XXe,Xt,XXt,n;
00233    double Xe1,XXe1,Xt1,XXt1,n1;
00234    bool   IsRefetence;
00235    float  ref_amp;
00236    float  ref_rms;
00237    float  ref_time;
00238    float  ref_time_rms;
00239    float  ds_amp;
00240    float  ds_rms;
00241    float  ds_time;
00242    float  ds_time_rms;
00243    int    status;
00244    float    nChecks,nBadTime,nBadEnergy;
00245 };
00246 
00247 class HcalDetDiagLaserMonitor : public HcalBaseDQMonitor {
00248    public:
00249       explicit HcalDetDiagLaserMonitor(const edm::ParameterSet&);
00250       ~HcalDetDiagLaserMonitor();
00251 
00252    private:
00253       HcalDetDiagLaserData* GetCalib(std::string sd,int eta,int phi){
00254         int SD=0,ETA=0,PHI=0;
00255         if(sd.compare("HB")==0) SD=1; 
00256         if(sd.compare("HE")==0) SD=2; 
00257         if(sd.compare("HO")==0) SD=3; 
00258         if(sd.compare("HF")==0) SD=4; 
00259         if(SD==1 || SD==2){
00260           if(eta>0) ETA=1; else ETA=-1;
00261           if(phi==71 ||phi==72 || phi==1 || phi==2) PHI=71; else PHI=((phi-3)/4)*4+3;
00262         }else if(SD==3){
00263           if(abs(eta)<=4){
00264           ETA=0;
00265           if(phi==71 ||phi==72 || phi==1 || phi==2 || phi==3 || phi==4) PHI=71; else PHI=((phi-5)/6)*6+5;
00266         }else{
00267           if(abs(eta)>4  && abs(eta)<=10)  ETA=1;
00268           if(abs(eta)>10 && abs(eta)<=15)  ETA=2;
00269           if(eta<0) ETA=-ETA;
00270           if(phi==71 ||phi==72 || (phi>=1 && phi<=10)) PHI=71; else PHI=((phi-11)/12)*12+11;
00271         }
00272         }else if(SD==4){
00273           if(eta>0) ETA=1; else ETA=-1;
00274           if(phi>=1  && phi<=18) PHI=1;
00275           if(phi>=19 && phi<=36) PHI=19;
00276           if(phi>=37 && phi<=54) PHI=37;
00277           if(phi>=55 && phi<=72) PHI=55;
00278       }
00279       return &calib_data[SD][ETA+2][PHI-1];
00280       };   
00281       void beginRun(const edm::Run& run, const edm::EventSetup& c);  
00282       void endRun(const edm::Run& run, const edm::EventSetup& c);
00283       void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c) ;
00284       void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c);
00285       void analyze(const edm::Event&, const edm::EventSetup&);
00286 
00287       const HcalElectronicsMap  *emap;
00288       edm::InputTag inputLabelDigi_;
00289       edm::InputTag calibDigiLabel_;
00290 
00291       void SaveReference();
00292       void SaveRaddamData();
00293       void LoadReference();
00294       void LoadDataset();
00295 
00296       bool get_ave_rbx(int sd,int side,int rbx,float *ave,float *rms);
00297       bool get_ave_subdet(int sd,float *ave_t,float *ave_e,float *ave_t_r,float *ave_e_r);
00298       void fillHistos(int sd);
00299       void fillProblems(int sd);
00300       int  nHBHEchecks,nHOchecks,nHFchecks;
00301       double LaserTimingThreshold,LaserEnergyThreshold,RaddamThreshold1,RaddamThreshold2;
00302 
00303       int         ievt_;
00304       int         run_number;
00305       int         dataset_seq_number;
00306       bool        IsReference;
00307       bool        LocalRun,RaddamRun;
00308       int         nHB,nHE,nHO,nHF;
00309       std::string ReferenceData;
00310       std::string ReferenceRun;
00311       std::string OutputFilePath;
00312       std::string XmlFilePath;
00313       std::string baseFolder_;
00314       std::string prefixME_;
00315       bool        Online_;
00316       bool        Overwrite;
00317 
00318       // to create html from processed dataset
00319       std::string DatasetName;
00320       std::string htmlOutputPath;
00321       bool createHTMLonly;
00322 
00323       MonitorElement *meEVT_,*meRUN_,*htmlFolder;
00324       MonitorElement *RefRun_;
00325       MonitorElement *hbheEnergy;
00326       MonitorElement *hbheTime;
00327       MonitorElement *hbheEnergyRMS;
00328       MonitorElement *hbheTimeRMS;
00329       MonitorElement *hoEnergy;
00330       MonitorElement *hoTime;
00331       MonitorElement *hoEnergyRMS;
00332       MonitorElement *hoTimeRMS;
00333       MonitorElement *hfEnergy;
00334       MonitorElement *hfTime;
00335       MonitorElement *hfEnergyRMS;
00336       MonitorElement *hfTimeRMS;
00337 
00338       MonitorElement *Time2Dhbhehf;
00339       MonitorElement *Time2Dho;
00340       MonitorElement *Energy2Dhbhehf;
00341       MonitorElement *Energy2Dho;
00342       MonitorElement *refTime2Dhbhehf;
00343       MonitorElement *refTime2Dho;
00344       MonitorElement *refEnergy2Dhbhehf;
00345       MonitorElement *refEnergy2Dho;
00346 
00347       MonitorElement *hb_time_rbx;
00348       MonitorElement *he_time_rbx;
00349       MonitorElement *ho_time_rbx;
00350       MonitorElement *hf_time_rbx;
00351 
00352       MonitorElement *Raddam[56];
00353       TH1F *S1[56],*S2[56];
00354 
00355       EtaPhiHists* ProblemCellsByDepth_timing;
00356       EtaPhiHists* ProblemCellsByDepth_energy;
00357       std::vector<std::string> problemnames_;
00358 
00359       EtaPhiHists* ProblemCellsByDepth_timing_val;
00360       EtaPhiHists* ProblemCellsByDepth_energy_val;
00361 
00362       HcalDetDiagLaserData hb_data[85][72][4];
00363       HcalDetDiagLaserData he_data[85][72][4];
00364       HcalDetDiagLaserData ho_data[85][72][4];
00365       HcalDetDiagLaserData hf_data[85][72][4];
00366       HcalDetDiagLaserData calib_data[5][5][72];
00367 
00368       std::map<unsigned int, int> KnownBadCells_;
00369 };
00370 
00371 HcalDetDiagLaserMonitor::HcalDetDiagLaserMonitor(const edm::ParameterSet& iConfig){
00372   ievt_=-1;
00373   emap=0;
00374   dataset_seq_number=1;
00375   run_number=-1;
00376   IsReference=false;
00377   LocalRun=RaddamRun=false;
00378   createHTMLonly=false;
00379   nHB=nHE=nHO=nHF=0;
00380   nHBHEchecks=nHOchecks=nHFchecks=0;
00381 
00382   inputLabelDigi_  = iConfig.getUntrackedParameter<edm::InputTag>("digiLabel",edm::InputTag("hcalDigis"));
00383   calibDigiLabel_  = iConfig.getUntrackedParameter<edm::InputTag>("calibDigiLabel",edm::InputTag("hcalDigis"));
00384 
00385   ReferenceData    = iConfig.getUntrackedParameter<std::string>("LaserReferenceData" ,"");
00386   OutputFilePath   = iConfig.getUntrackedParameter<std::string>("OutputFilePath", "");
00387   DatasetName      = iConfig.getUntrackedParameter<std::string>("LaserDatasetName", "");
00388   htmlOutputPath   = iConfig.getUntrackedParameter<std::string>("htmlOutputPath", "");
00389   XmlFilePath      = iConfig.getUntrackedParameter<std::string>("XmlFilePath", "");
00390   Online_          = iConfig.getUntrackedParameter<bool>  ("online",false);
00391   Overwrite        = iConfig.getUntrackedParameter<bool>  ("Overwrite",true);
00392   prefixME_        = iConfig.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00393   if (prefixME_.size()>0 && prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00394   prefixME_.append("/");
00395   subdir_          = iConfig.getUntrackedParameter<std::string>("TaskFolder","DetDiagPedestalMonitor_Hcal/");
00396   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00397     subdir_.append("/");
00398   subdir_=prefixME_+subdir_;
00399   debug_           = iConfig.getUntrackedParameter<int>("debug",0);
00400 
00401   LaserTimingThreshold = iConfig.getUntrackedParameter<double>("LaserTimingThreshold",0.2);
00402   LaserEnergyThreshold = iConfig.getUntrackedParameter<double>("LaserEnergyThreshold",0.1);
00403   RaddamThreshold1     = iConfig.getUntrackedParameter<double>("RaddamThreshold1",10.0);
00404   RaddamThreshold2     = iConfig.getUntrackedParameter<double>("RaddamThreshold2",0.95);
00405 }
00406 void HcalDetDiagLaserMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c){
00407   edm::ESHandle<HcalChannelQuality> p;
00408   c.get<HcalChannelQualityRcd>().get(p);
00409   HcalChannelQuality* chanquality= new HcalChannelQuality(*p.product());
00410   std::vector<DetId> mydetids = chanquality->getAllChannels();
00411   KnownBadCells_.clear();
00412 
00413   for (std::vector<DetId>::const_iterator i = mydetids.begin();i!=mydetids.end();++i){
00414      if (i->det()!=DetId::Hcal) continue; // not an hcal cell
00415      HcalDetId id=HcalDetId(*i);
00416      int status=(chanquality->getValues(id))->getValue();
00417      if((status & HcalChannelStatus::HcalCellOff) || (status & HcalChannelStatus::HcalCellMask)){
00418          KnownBadCells_[id.rawId()]=status;
00419      }
00420   } 
00421 
00422   edm::ESHandle<HcalDbService> conditions_;
00423   c.get<HcalDbRecord>().get(conditions_);
00424   emap=conditions_->getHcalMapping();
00425   
00426   HcalBaseDQMonitor::setup();
00427   if (!dbe_) return;
00428   std::string name;
00429  
00430   dbe_->setCurrentFolder(subdir_);   
00431   meEVT_ = dbe_->bookInt("HcalDetDiagLaserMonitor Event Number");
00432   meRUN_ = dbe_->bookInt("HcalDetDiagLaserMonitor Run Number");
00433 
00434   ReferenceRun="UNKNOWN";
00435   LoadReference();
00436   LoadDataset();
00437   if(DatasetName.size()>0 && createHTMLonly){
00438      char str[200]; sprintf(str,"%sHcalDetDiagLaserData_run%i_%i/",htmlOutputPath.c_str(),run_number,dataset_seq_number);
00439      htmlFolder=dbe_->bookString("HcalDetDiagLaserMonitor HTML folder",str);
00440      MonitorElement *me;
00441      dbe_->setCurrentFolder(prefixME_+"HcalInfo");
00442      me=dbe_->bookInt("HBpresent");
00443      if(nHB>0) me->Fill(1);
00444      me=dbe_->bookInt("HEpresent");
00445      if(nHE>0) me->Fill(1);
00446      me=dbe_->bookInt("HOpresent");
00447      if(nHO>0) me->Fill(1);
00448      me=dbe_->bookInt("HFpresent");
00449      if(nHF>0) me->Fill(1);
00450   }
00451   ProblemCellsByDepth_timing = new EtaPhiHists();
00452   ProblemCellsByDepth_timing->setup(dbe_," Problem Bad Laser Timing");
00453   for(unsigned int i=0;i<ProblemCellsByDepth_timing->depth.size();i++)
00454           problemnames_.push_back(ProblemCellsByDepth_timing->depth[i]->getName());
00455   ProblemCellsByDepth_energy = new EtaPhiHists();
00456   ProblemCellsByDepth_energy->setup(dbe_," Problem Bad Laser Energy");
00457   for(unsigned int i=0;i<ProblemCellsByDepth_energy->depth.size();i++)
00458           problemnames_.push_back(ProblemCellsByDepth_energy->depth[i]->getName());
00459 
00460   dbe_->setCurrentFolder(subdir_+"Summary Plots");
00461      
00462   name="HBHE Laser Energy Distribution";                hbheEnergy        = dbe_->book1D(name,name,200,0,3000);
00463   name="HBHE Laser Timing Distribution";                hbheTime          = dbe_->book1D(name,name,200,0,10);
00464   name="HBHE Laser Energy RMS_div_Energy Distribution"; hbheEnergyRMS     = dbe_->book1D(name,name,200,0,0.5);
00465   name="HBHE Laser Timing RMS Distribution";            hbheTimeRMS       = dbe_->book1D(name,name,200,0,1);
00466   name="HO Laser Energy Distribution";                  hoEnergy          = dbe_->book1D(name,name,200,0,3000);
00467   name="HO Laser Timing Distribution";                  hoTime            = dbe_->book1D(name,name,200,0,10);
00468   name="HO Laser Energy RMS_div_Energy Distribution";   hoEnergyRMS       = dbe_->book1D(name,name,200,0,0.5);
00469   name="HO Laser Timing RMS Distribution";              hoTimeRMS         = dbe_->book1D(name,name,200,0,1);
00470   name="HF Laser Energy Distribution";                  hfEnergy          = dbe_->book1D(name,name,200,0,3000);
00471   name="HF Laser Timing Distribution";                  hfTime            = dbe_->book1D(name,name,200,0,10);
00472   name="HF Laser Energy RMS_div_Energy Distribution";   hfEnergyRMS       = dbe_->book1D(name,name,200,0,0.7);
00473   name="HF Laser Timing RMS Distribution";              hfTimeRMS         = dbe_->book1D(name,name,200,0,1);
00474      
00475   name="Laser Timing HBHEHF";                           Time2Dhbhehf      = dbe_->book2D(name,name,87,-43,43,74,0,73);
00476   name="Laser Timing HO";                               Time2Dho          = dbe_->book2D(name,name,33,-16,16,74,0,73);
00477   name="Laser Energy HBHEHF";                           Energy2Dhbhehf    = dbe_->book2D(name,name,87,-43,43,74,0,73);
00478   name="Laser Energy HO";                               Energy2Dho        = dbe_->book2D(name,name,33,-16,16,74,0,73);
00479   name="HBHEHF Laser (Timing-Ref)+1";                   refTime2Dhbhehf   = dbe_->book2D(name,name,87,-43,43,74,0,73);
00480   name="HO Laser (Timing-Ref)+1";                       refTime2Dho       = dbe_->book2D(name,name,33,-16,16,74,0,73);
00481   name="HBHEHF Laser Energy_div_Ref";                   refEnergy2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
00482   name="HO Laser Energy_div_Ref";                       refEnergy2Dho     = dbe_->book2D(name,name,33,-16,16,74,0,73);
00483      
00484   name="HB RBX average Time-Ref";                       hb_time_rbx       = dbe_->book1D(name,name,36,0.5,36.5);
00485   name="HE RBX average Time-Ref";                       he_time_rbx       = dbe_->book1D(name,name,36,0.5,36.5);
00486   name="HO RBX average Time-Ref";                       ho_time_rbx       = dbe_->book1D(name,name,36,0.5,36.5);
00487   name="HF RoBox average Time-Ref";                     hf_time_rbx       = dbe_->book1D(name,name,24,0.5,24.5);
00488   
00489   char str[200];
00490   for(int i=1;i<=18;i++){ sprintf(str,"HBM%02i",i);     hb_time_rbx->setBinLabel(i,str);    }
00491   for(int i=1;i<=18;i++){ sprintf(str,"HBP%02i",i);     hb_time_rbx->setBinLabel(i+18,str); }
00492   for(int i=1;i<=18;i++){ sprintf(str,"HEM%02i",i);     he_time_rbx->setBinLabel(i,str);    }
00493   for(int i=1;i<=18;i++){ sprintf(str,"HEP%02i",i);     he_time_rbx->setBinLabel(i+18,str); }
00494   for(int i=1;i<=12;i++){ sprintf(str,"HFM%02i",i);     hf_time_rbx->setBinLabel(i,str);    }
00495   for(int i=1;i<=12;i++){ sprintf(str,"HFP%02i",i);     hf_time_rbx->setBinLabel(i+12,str); }
00496   for(int i=1;i<=6;i++){  sprintf(str,"HO2M%02i",i*2);  ho_time_rbx->setBinLabel(i,str);    }
00497   for(int i=1;i<=6;i++){  sprintf(str,"HO1M%02i",i*2);  ho_time_rbx->setBinLabel(i+6,str);  }
00498   for(int i=1;i<=12;i++){ sprintf(str,"HO0%02i",i);     ho_time_rbx->setBinLabel(i+12,str); }
00499   for(int i=1;i<=6;i++){  sprintf(str,"HO1P%02i",i*2);  ho_time_rbx->setBinLabel(i+24,str); }
00500   for(int i=1;i<=6;i++){  sprintf(str,"HO2P%02i",i*2);  ho_time_rbx->setBinLabel(i+30,str); }
00501 
00502   Time2Dhbhehf->setAxisTitle("i#eta",1);
00503   Time2Dhbhehf->setAxisTitle("i#phi",2);
00504   Time2Dho->setAxisTitle("i#eta",1);
00505   Time2Dho->setAxisTitle("i#phi",2);
00506   Energy2Dhbhehf->setAxisTitle("i#eta",1);
00507   Energy2Dhbhehf->setAxisTitle("i#phi",2);
00508   Energy2Dho->setAxisTitle("i#eta",1);
00509   Energy2Dho->setAxisTitle("i#phi",2);
00510   refTime2Dhbhehf->setAxisTitle("i#eta",1);
00511   refTime2Dhbhehf->setAxisTitle("i#phi",2);
00512   refTime2Dho->setAxisTitle("i#eta",1);
00513   refTime2Dho->setAxisTitle("i#phi",2);
00514   refEnergy2Dhbhehf->setAxisTitle("i#eta",1);
00515   refEnergy2Dhbhehf->setAxisTitle("i#phi",2);
00516   refEnergy2Dho->setAxisTitle("i#eta",1);
00517   refEnergy2Dho->setAxisTitle("i#phi",2);
00518 
00519   refTime2Dhbhehf->setAxisRange(0,2,3);
00520   refTime2Dho->setAxisRange(0,2,3);
00521   refEnergy2Dhbhehf->setAxisRange(0.5,1.5,3);
00522   refEnergy2Dho->setAxisRange(0.5,1.5,3);
00523 
00524   dbe_->setCurrentFolder(subdir_);
00525   RefRun_= dbe_->bookString("HcalDetDiagLaserMonitor Reference Run",ReferenceRun);
00526 
00527   dbe_->setCurrentFolder(subdir_+"Raddam Plots");
00528   for(int i=0;i<56;i++){
00529      sprintf(str,"RADDAM (%i %i)",RADDAM_CH[i].eta,RADDAM_CH[i].phi);
00530      Raddam[i] = dbe_->book1D(str,str,10,-0.5,9.5); 
00531   }
00532 
00533   dbe_->setCurrentFolder(subdir_+"Plots for client");
00534   ProblemCellsByDepth_timing_val = new EtaPhiHists();
00535   ProblemCellsByDepth_timing_val->setup(dbe_," Laser Timing difference");
00536   ProblemCellsByDepth_energy_val = new EtaPhiHists();
00537   ProblemCellsByDepth_energy_val->setup(dbe_," Laser Energy difference");
00538 }
00539 
00540 
00541 HcalDetDiagLaserMonitor::~HcalDetDiagLaserMonitor(){
00542 
00543 }
00544 
00545 // ------------ method called to for each event  ------------
00546 void HcalDetDiagLaserMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00547  if(createHTMLonly) return;
00548   HcalBaseDQMonitor::analyze(iEvent,iSetup); // base class increments ievt_, etc. counters
00549  
00550 int  eta,phi,depth,nTS;
00551 static bool HBHEseq,HOseq,HFseq;
00552 static int  lastHBHEorbit,lastHOorbit,lastHForbit,nChecksHBHE,nChecksHO,nChecksHF,ievt_hbhe,ievt_ho,ievt_hf;
00553    if(ievt_==-1){ 
00554        ievt_=0;HBHEseq=HOseq=HFseq=false; lastHBHEorbit=lastHOorbit=lastHForbit=-1;nChecksHBHE=nChecksHO=nChecksHF=0; 
00555        ievt_hbhe=0,ievt_ho=0,ievt_hf=0;
00556    }
00557 
00558    if(!dbe_) return; 
00559    bool LaserEvent=false;
00560    bool LaserRaddam=false;
00561    int orbit=iEvent.orbitNumber();
00562    meRUN_->Fill(iEvent.id().run());
00563    // for local runs 
00564    edm::Handle<HcalTBTriggerData> trigger_data;
00565    iEvent.getByType(trigger_data);
00566    if(trigger_data.isValid()){
00567        if(trigger_data->wasLaserTrigger()) LaserEvent=true;
00568        LocalRun=true;
00569    }
00570    if(!LocalRun && Online_){
00571       if(HBHEseq && (orbit-lastHBHEorbit)>(11223*10) && ievt_hbhe>40){
00572          HBHEseq=false;
00573          fillHistos(HcalBarrel);
00574          fillProblems(HcalBarrel);
00575          fillProblems(HcalEndcap);
00576          nChecksHBHE++;
00577          ievt_hbhe=0;
00578          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();
00579          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();
00580       }
00581       if(HOseq && (orbit-lastHOorbit)>(11223*10) && ievt_ho>40){
00582          HOseq=false;
00583          fillHistos(HcalOuter);
00584          fillProblems(HcalOuter);
00585          nChecksHO++; 
00586          ievt_ho=0;
00587          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();
00588       }
00589       if(HFseq && (orbit-lastHForbit)>(11223*10) && ievt_hf>40){
00590          HFseq=false;
00591          fillHistos(HcalForward);
00592          fillProblems(HcalForward);
00593          nChecksHF++; 
00594          ievt_hf=0;
00595          if(nChecksHF==1 || (nChecksHF>1 && ((nChecksHF-1)%12)==0)){
00596              SaveReference();
00597          }
00598          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();
00599       }
00600    }
00601 
00602    // Abort Gap laser 
00603    if(LocalRun==false || LaserEvent==false){
00604        edm::Handle<FEDRawDataCollection> rawdata;
00605        iEvent.getByType(rawdata);
00606        //checking FEDs for calibration information
00607        for (int i=FEDNumbering::MINHCALFEDID;i<=FEDNumbering::MAXHCALFEDID; i++) {
00608           const FEDRawData& fedData = rawdata->FEDData(i) ;
00609           if ( fedData.size() < 24 ) continue ;
00610           int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
00611           if(value==hc_HBHEHPD){ HBHEseq=true; HOseq=HFseq=false; lastHBHEorbit=orbit; ievt_hbhe++; }
00612           if(value==hc_HOHPD){   HOseq=true; HBHEseq=HFseq=false; lastHOorbit=orbit;   ievt_ho++;   }
00613           if(value==hc_HFPMT){   HFseq=true; HBHEseq=HOseq=false; lastHForbit=orbit;   ievt_hf++;   }
00614           
00615           if(value==hc_HBHEHPD || value==hc_HOHPD || value==hc_HFPMT){ LaserEvent=true; break;}
00616           if(value==hc_RADDAM){ LaserEvent=true; LaserRaddam=true; break;} 
00617        }
00618    }   
00619    if(!LaserEvent) return;
00620    edm::Handle<HBHEDigiCollection> hbhe; 
00621    iEvent.getByLabel(inputLabelDigi_,hbhe);
00622    edm::Handle<HODigiCollection> ho; 
00623    iEvent.getByLabel(inputLabelDigi_,ho);
00624    edm::Handle<HFDigiCollection> hf;
00625    iEvent.getByLabel(inputLabelDigi_,hf);
00626    edm::Handle<HcalCalibDigiCollection> calib;
00627    iEvent.getByLabel(calibDigiLabel_, calib); 
00628 
00629    if(LocalRun && LaserEvent){
00630       int N=0; 
00631       if(hf.isValid()){
00632          for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00633              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth();
00634              float e=0;
00635              for(int i=0;i<digi->size();i++) e+=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00636              if(e>40){ N++;}
00637          }
00638       }
00639       if(N>50 && N<57){ RaddamRun=true; /*LaserRaddam=true;*/}
00640    }
00641    if(RaddamRun){
00642       if(hf.isValid()){
00643          for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00644              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00645              int N;
00646              for(N=0;N<56;N++)if(eta==RADDAM_CH[N].eta && phi==RADDAM_CH[N].phi && depth==RADDAM_CH[N].depth) break;
00647              if(N==56) continue; 
00648              float max1=0,max2=0;
00649              int   nmax1=0,nmax2=0;
00650              for(int i=0;i<nTS;i++){
00651                   if(max1<adc2fC[digi->sample(i).adc()&0xff]){ nmax1=i; max1=adc2fC[digi->sample(i).adc()&0xff]; }
00652              }
00653              Raddam_data[N].TOTEVNT++;
00654              for(int i=0;i<nTS;i++){
00655                   if(i==nmax1) continue;
00656                   if(max2<adc2fC[digi->sample(i).adc()&0xff]){ nmax2=i; max2=adc2fC[digi->sample(i).adc()&0xff]; }
00657              }
00658              if(nmax1>nmax2){
00659                 int tmp1=nmax2;
00660                 nmax2=nmax1;nmax1=tmp1;
00661              }
00662              if(nmax1==0 || nmax2==(nTS-1)) continue;
00663              if(nmax2!=(nmax1+1)) continue;
00664      
00665              if(max1<RaddamThreshold1 || max2<RaddamThreshold1) continue;
00666              Raddam_data[N].CUT1EVNT++;
00667              max1-=2.5; max2-=2.5;
00668              float S2=max1+max2;
00669              float S4=S2+adc2fC[digi->sample(nmax1-1).adc()&0xff]+adc2fC[digi->sample(nmax2+1).adc()&0xff]-5.0;
00670              if((S2/S4)<RaddamThreshold2) continue;
00671              Raddam_data[N].CUT2EVNT++;
00672              Raddam_data[N].s1_adc[digi->sample(nmax1).adc()&0xff]++;
00673              Raddam_data[N].s2_adc[digi->sample(nmax2).adc()&0xff]++;
00674          }
00675       }
00676    }
00677 
00678    meEVT_->Fill(++ievt_);
00679    run_number=iEvent.id().run();
00680    double data[20];
00681    if(!LaserRaddam){
00682       if(hbhe.isValid()){
00683          for(HBHEDigiCollection::const_iterator digi=hbhe->begin();digi!=hbhe->end();digi++){
00684              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00685              double ped=(adc2fC[digi->sample(0).adc()&0xff]+adc2fC[digi->sample(1).adc()&0xff])/2.0;
00686              if(digi->id().subdet()==HcalBarrel){
00687                 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
00688                 hb_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00689              }   
00690              if(digi->id().subdet()==HcalEndcap){
00691                 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
00692                 he_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00693              }
00694          }
00695       }
00696       if(ho.isValid()){
00697          for(HODigiCollection::const_iterator digi=ho->begin();digi!=ho->end();digi++){
00698              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00699              double ped=(adc2fC[digi->sample(0).adc()&0xff]+adc2fC[digi->sample(1).adc()&0xff])/2.0;
00700              if((eta>=11 && eta<=15 && phi>=59 && phi<=70) || (eta>=5 && eta<=10 && phi>=47 && phi<=58)){
00701                 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
00702              }else{
00703                 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
00704              }
00705              ho_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00706          }
00707       }
00708       if(hf.isValid()){
00709          for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00710              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00711              double ped=adc2fC[digi->sample(0).adc()&0xff];
00712              for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-ped;
00713              hf_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00714          }   
00715       }
00716       if(calib.isValid())for(HcalCalibDigiCollection::const_iterator digi=calib->begin();digi!=calib->end();digi++){
00717          if(digi->id().cboxChannel()!=0 || digi->id().hcalSubdet()==0) continue; 
00718          nTS=digi->size();
00719          float e=0;
00720          for(int i=0;i<nTS;i++){ data[i]=adc2fC[digi->sample(i).adc()&0xff]; e+=data[i];} 
00721          if(e<15000) calib_data[digi->id().hcalSubdet()][digi->id().ieta()+2][digi->id().iphi()-1].add_statistics(data,nTS);
00722       }
00723    }else{ //Raddam
00724       if(hf.isValid()){
00725          for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00726              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00727              int N;
00728              for(N=0;N<56;N++)if(eta==RADDAM_CH[N].eta && phi==RADDAM_CH[N].phi && depth==RADDAM_CH[N].depth) break;
00729              if(N==56) continue;      
00730              for(int i=0;i<nTS;i++) Raddam[N]->Fill(i,adc2fC[digi->sample(i).adc()&0xff]-2.5);
00731              
00732          }   
00733       }
00734    }
00735 }
00736 bool HcalDetDiagLaserMonitor::get_ave_subdet(int sd,float *ave_t,float *ave_e,float *ave_t_r,float *ave_e_r){
00737 double T=0,nT=0,E=0,nE=0,Tr=0,nTr=0,Er=0,nEr=0;
00738    if(sd==HcalBarrel) for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){ 
00739       for(int depth=1;depth<=2;depth++){
00740          if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
00741             double ave=0,rms=0,time=0,time_rms=0;
00742             hb_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00743             hb_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00744             T+=time; nT++; E+=ave; nE++;
00745             if(hb_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
00746               Tr+=time; nTr++; Er+=ave; nEr++;}
00747          }
00748       } 
00749    } 
00750    // HE histograms
00751    if(sd==HcalEndcap) for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
00752       for(int depth=1;depth<=3;depth++){
00753          if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
00754             double ave=0; double rms=0; double time=0; double time_rms=0;
00755             he_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00756             he_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00757             T+=time; nT++; E+=ave; nE++;
00758             if(he_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
00759               Tr+=time; nTr++; Er+=ave; nEr++;}
00760         }
00761       }
00762    } 
00763    // HF histograms
00764    if(sd==HcalForward) for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
00765       for(int depth=1;depth<=2;depth++){
00766          if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
00767             double ave=0; double rms=0; double time=0; double time_rms=0;
00768             hf_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00769             hf_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00770             T+=time; nT++; E+=ave; nE++;
00771             if(hf_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
00772               Tr+=time; nTr++; Er+=ave; nEr++;}
00773          }
00774       } 
00775    } 
00776    // HO histograms
00777    if(sd==HcalOuter) for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
00778       for(int depth=4;depth<=4;depth++){
00779          if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
00780             double ave=0; double rms=0; double time=0; double time_rms=0;
00781             ho_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00782             ho_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00783             T+=time; nT++; E+=ave; nE++;
00784             if(ho_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
00785               Tr+=time; nTr++; Er+=ave; nEr++;}
00786          }
00787       }
00788    } 
00789    if(nT<200 || nE<200 || nTr<200 || nEr<200) return false;
00790    *ave_t=T/nT;
00791    *ave_e=E/nE;
00792    *ave_t_r=Tr/nTr;
00793    *ave_e_r=Er/nEr;
00794    return true;
00795 }
00796 
00797 void HcalDetDiagLaserMonitor::fillProblems(int sd){
00798 float ave_t,ave_e,ave_t_r,ave_e_r;
00799    if(!get_ave_subdet(sd,&ave_t,&ave_e,&ave_t_r,&ave_e_r)) return;
00800 
00801    for(int i=0;i<4;i++){
00802       ProblemCellsByDepth_energy->depth[i]->Reset();
00803       ProblemCellsByDepth_timing->depth[i]->Reset();
00804    }
00805 
00806    std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
00807    for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
00808      DetId detid=emap->lookup(*eid);
00809      if (detid.det()!=DetId::Hcal) continue;
00810      HcalGenericDetId gid(emap->lookup(*eid));
00811      if(!(!(gid.null()) && 
00812             (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
00813              gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap  ||
00814              gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
00815              gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
00816      int eta=0,phi=0,depth=0;
00817      HcalDetId hid(detid);
00818      if(KnownBadCells_.find(hid.rawId())==KnownBadCells_.end()) continue;
00819      eta=hid.ieta();
00820      phi=hid.iphi();
00821      depth=hid.depth();
00822 
00823      int e=CalcEtaBin(sd,eta,depth)+1;
00824      if(detid.subdetId()==HcalBarrel && sd==HcalBarrel){
00825         double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
00826         if(!hb_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00827         if(!hb_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
00828         if(!hb_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
00829         hb_data[eta+42][phi-1][depth-1].nChecks++;
00830         float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
00831         if(diff_t>LaserTimingThreshold){
00832              hb_data[eta+42][phi-1][depth-1].nBadTime++; 
00833              ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
00834         }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0); 
00835         if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
00836           float diff_e=((VAL/ave_e))/(val/ave_e_r);
00837           if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
00838                hb_data[eta+42][phi-1][depth-1].nBadEnergy++;
00839                ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
00840           }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
00841         }
00842      }
00843      if(detid.subdetId()==HcalEndcap && sd==HcalEndcap){
00844         double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
00845         if(!he_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00846         if(!he_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
00847         if(!he_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
00848         he_data[eta+42][phi-1][depth-1].nChecks++;
00849         float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
00850         if(diff_t>LaserTimingThreshold){
00851           he_data[eta+42][phi-1][depth-1].nBadTime++;
00852           ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
00853         }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0); 
00854         if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
00855           float diff_e=((VAL/ave_e))/(val/ave_e_r);
00856           if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
00857             he_data[eta+42][phi-1][depth-1].nBadEnergy++;
00858             ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
00859           }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
00860         }
00861      }
00862      if(detid.subdetId()==HcalOuter && sd==HcalOuter){
00863         double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
00864         if(!ho_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00865         if(!ho_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
00866         if(!ho_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
00867         ho_data[eta+42][phi-1][depth-1].nChecks++;
00868         float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
00869         if(diff_t>LaserTimingThreshold){
00870            ho_data[eta+42][phi-1][depth-1].nBadTime++;
00871            ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
00872         }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0); 
00873         if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
00874           float diff_e=((VAL/ave_e))/(val/ave_e_r);
00875           if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
00876             ho_data[eta+42][phi-1][depth-1].nBadEnergy++;
00877             ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
00878           }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
00879         }
00880      }
00881      if(detid.subdetId()==HcalForward && sd==HcalForward){
00882         double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
00883         if(!hf_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00884         if(!hf_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
00885         if(!hf_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
00886         hf_data[eta+42][phi-1][depth-1].nChecks++;
00887         float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
00888         if(diff_t>LaserTimingThreshold){
00889            hf_data[eta+42][phi-1][depth-1].nBadTime++;
00890            ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
00891         }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0); 
00892         if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
00893           float diff_e=((VAL/ave_e))/(val/ave_e_r);
00894           if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
00895             hf_data[eta+42][phi-1][depth-1].nBadEnergy++;
00896             ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
00897           }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
00898         }
00899      }
00900    }
00901    for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
00902      DetId detid=emap->lookup(*eid);
00903      if (detid.det()!=DetId::Hcal) continue;
00904      HcalGenericDetId gid(emap->lookup(*eid));
00905      if(!(!(gid.null()) && 
00906             (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
00907              gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap  ||
00908              gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
00909              gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
00910      int eta=0,phi=0,depth=0;
00911      HcalDetId hid(detid);
00912      eta=hid.ieta();
00913      phi=hid.iphi();
00914      depth=hid.depth();
00915    
00916      if(detid.subdetId()==HcalBarrel){
00917         if(hb_data[eta+42][phi-1][depth-1].nBadTime>0){
00918            int e=CalcEtaBin(HcalBarrel,eta,depth)+1; 
00919            double val=hb_data[eta+42][phi-1][depth-1].nBadTime/hb_data[eta+42][phi-1][depth-1].nChecks;
00920            ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
00921         } 
00922         if(hb_data[eta+42][phi-1][depth-1].nBadEnergy>0){
00923            int e=CalcEtaBin(HcalBarrel,eta,depth)+1; 
00924            double val=hb_data[eta+42][phi-1][depth-1].nBadEnergy/hb_data[eta+42][phi-1][depth-1].nChecks;
00925            ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
00926         } 
00927      }
00928      if(detid.subdetId()==HcalEndcap){
00929         if(he_data[eta+42][phi-1][depth-1].nBadTime>0){
00930            int e=CalcEtaBin(HcalEndcap,eta,depth)+1; 
00931            double val=he_data[eta+42][phi-1][depth-1].nBadTime/he_data[eta+42][phi-1][depth-1].nChecks;
00932            ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
00933         } 
00934         if(he_data[eta+42][phi-1][depth-1].nBadEnergy>0){
00935            int e=CalcEtaBin(HcalEndcap,eta,depth)+1; 
00936            double val=he_data[eta+42][phi-1][depth-1].nBadEnergy/he_data[eta+42][phi-1][depth-1].nChecks;
00937            ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
00938         } 
00939      }
00940      if(detid.subdetId()==HcalOuter){
00941         if(ho_data[eta+42][phi-1][depth-1].nBadTime>0){
00942            int e=CalcEtaBin(HcalOuter,eta,depth)+1; 
00943            double val=ho_data[eta+42][phi-1][depth-1].nBadTime/ho_data[eta+42][phi-1][depth-1].nChecks;
00944            ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
00945         } 
00946         if(ho_data[eta+42][phi-1][depth-1].nBadEnergy>0){
00947            int e=CalcEtaBin(HcalOuter,eta,depth)+1; 
00948            double val=ho_data[eta+42][phi-1][depth-1].nBadEnergy/ho_data[eta+42][phi-1][depth-1].nChecks;
00949            ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val); 
00950         } 
00951      }
00952      if(detid.subdetId()==HcalForward){
00953         if(hf_data[eta+42][phi-1][depth-1].nBadTime>0){
00954            int e=CalcEtaBin(HcalForward,eta,depth)+1; 
00955            double val=hf_data[eta+42][phi-1][depth-1].nBadTime/hf_data[eta+42][phi-1][depth-1].nChecks;
00956            ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
00957         } 
00958         if(hf_data[eta+42][phi-1][depth-1].nBadEnergy>0){
00959            int e=CalcEtaBin(HcalForward,eta,depth)+1; 
00960            double val=hf_data[eta+42][phi-1][depth-1].nBadEnergy/hf_data[eta+42][phi-1][depth-1].nChecks;
00961            ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
00962         } 
00963      }
00964    }
00965 }
00966 
00967 bool HcalDetDiagLaserMonitor::get_ave_rbx(int sd,int side,int rbx,float *ave,float *rms){
00968    double xt=0,xxt=0; 
00969    int eta_min=0,eta_max=0,n=0;
00970    if(sd==HcalBarrel){
00971       if(side>0){eta_min=1; eta_max=29;}
00972       if(side<0){eta_min=-29; eta_max=-1;}
00973       if(rbx==1){
00974          for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++)for(int k=1;k<=3;k++){
00975            double val,rms,time,time_rms;
00976            double TIME,TIME_RMS;
00977            if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00978            if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00979            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00980          }
00981          for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=2;j++)for(int k=1;k<=3;k++){
00982            double val,rms,time,time_rms;
00983            double TIME,TIME_RMS;
00984            if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00985            if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00986            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00987          }
00988       
00989       }else{
00990          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++){
00991            double val,rms,time,time_rms;
00992            double TIME,TIME_RMS;
00993            if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00994            if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00995            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00996          }
00997       }
00998    }
00999    if(sd==HcalEndcap){
01000       if(side>0){eta_min=1; eta_max=29;}
01001       if(side<0){eta_min=-29; eta_max=-1;}
01002       if(rbx==1){
01003          for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++)for(int k=1;k<=3;k++){
01004            double val,rms,time,time_rms;
01005            double TIME,TIME_RMS;
01006            if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01007            if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
01008            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01009          }
01010          for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=2;j++)for(int k=1;k<=3;k++){
01011            double val,rms,time,time_rms;
01012            double TIME,TIME_RMS;
01013            if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01014            if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
01015            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01016          }
01017       
01018       }else{
01019          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++){
01020            double val,rms,time,time_rms;
01021            double TIME,TIME_RMS;
01022            if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01023            if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
01024            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01025          }
01026       }
01027    }  
01028    if(sd==HcalForward){
01029       if(side>0){eta_min=29; eta_max=40;}
01030       if(side<0){eta_min=-40; eta_max=-29;}
01031       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++){
01032            double val,rms,time,time_rms;
01033            double TIME,TIME_RMS;
01034            if(!hf_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01035            if(!hf_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
01036            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01037       }
01038    }   
01039    if(sd==HcalOuter){
01040       if(side==0){
01041         eta_min=-4,eta_max=4;
01042         if(rbx==1){
01043           for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++){
01044            double val,rms,time,time_rms;
01045            double TIME,TIME_RMS;
01046            if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01047            if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
01048            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01049           }
01050           for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=4;j++){
01051            double val,rms,time,time_rms;
01052            double TIME,TIME_RMS;
01053            if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01054            if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
01055            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01056           }
01057         
01058         }else{
01059           for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*6-1);j<=((rbx-1)*6+4);j++){
01060            double val,rms,time,time_rms;
01061            double TIME,TIME_RMS;
01062            if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01063            if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
01064            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01065           }
01066         }
01067       }
01068       if(side==-1){ eta_min=-10,eta_max=-5;} 
01069       if(side==-2){ eta_min=-15,eta_max=-11;} 
01070       if(side==1) { eta_min=5,  eta_max=10;} 
01071       if(side==2) { eta_min=11, eta_max=15;}
01072       if(side!=0){
01073         if(rbx==1){
01074           for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++){
01075            double val,rms,time,time_rms;
01076            double TIME,TIME_RMS;
01077            if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01078            if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
01079            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01080           }
01081           for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=10;j++){
01082            double val,rms,time,time_rms;
01083            double TIME,TIME_RMS;
01084            if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01085            if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
01086            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01087           }
01088         
01089         }else{
01090           for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*12-1);j<=((rbx-1)*12+10);j++){
01091            double val,rms,time,time_rms;
01092            double TIME,TIME_RMS;
01093            if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01094            if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
01095            xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
01096           }
01097         }      
01098       } 
01099    }
01100    if(n<10) return false;
01101    *ave=xt/n;
01102    *rms=sqrt(xxt/n-(xt*xt)/(n*n));
01103    return true; 
01104 }
01105 
01106 
01107 void HcalDetDiagLaserMonitor::fillHistos(int sd){
01108    if(sd==HcalBarrel || sd==HcalEndcap){
01109       hbheEnergy->Reset();
01110       hbheTime->Reset();
01111       hbheEnergyRMS->Reset();
01112       hbheTimeRMS->Reset();
01113       hb_time_rbx->Reset();
01114       he_time_rbx->Reset();
01115    }
01116    if(sd==HcalOuter){
01117       hoEnergy->Reset();
01118       hoTime->Reset();
01119       hoEnergyRMS->Reset();
01120       hoTimeRMS->Reset();
01121       Time2Dho->Reset();
01122       Energy2Dho->Reset();
01123       refTime2Dho->Reset(); 
01124       refEnergy2Dho->Reset();
01125       ho_time_rbx->Reset();
01126    }
01127    if(sd==HcalForward){
01128       hfEnergy->Reset();
01129       hfTime->Reset();
01130       hfEnergyRMS->Reset();
01131       hfTimeRMS->Reset();
01132       hf_time_rbx->Reset();
01133    }
01134    if(sd==HcalBarrel || sd==HcalEndcap){
01135      // HB histograms
01136      for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){ 
01137         double T=0,nT=0,E=0,nE=0;
01138         for(int depth=1;depth<=2;depth++){
01139            if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
01140               double ave=0;
01141               double rms=0;
01142               double time=0; 
01143               double time_rms=0;
01144               hb_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
01145               hb_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
01146               hbheEnergy->Fill(ave);
01147               if(ave>0)hbheEnergyRMS->Fill(rms/ave);
01148               hbheTime->Fill(time);
01149               hbheTimeRMS->Fill(time_rms);
01150               T+=time; nT++; E+=ave; nE++;
01151            }
01152         } 
01153         if(nT>0){Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT);Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); }
01154      } 
01155      // HE histograms
01156      for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
01157         double T=0,nT=0,E=0,nE=0;
01158         for(int depth=1;depth<=3;depth++){
01159            if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
01160               double ave=0; double rms=0; double time=0; double time_rms=0;
01161               he_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
01162               he_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
01163               hbheEnergy->Fill(ave);
01164               if(ave>0)hbheEnergyRMS->Fill(rms/ave);
01165               hbheTime->Fill(time);
01166               hbheTimeRMS->Fill(time_rms);
01167               T+=time; nT++; E+=ave; nE++;
01168            }
01169         }
01170         if(nT>0 && abs(eta)>16 ){Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT); Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); }     
01171         if(nT>0 && abs(eta)>20 ){Time2Dhbhehf->setBinContent(eta+44,phi+2,T/nT); Energy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);}      
01172      } 
01173    }
01174    if(sd==HcalForward){
01175      // HF histograms
01176      for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
01177         double T=0,nT=0,E=0,nE=0;
01178         for(int depth=1;depth<=2;depth++){
01179            if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
01180               double ave=0; double rms=0; double time=0; double time_rms=0;
01181               hf_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
01182               hf_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
01183               hfEnergy->Fill(ave);
01184               if(ave>0)hfEnergyRMS->Fill(rms/ave);
01185               hfTime->Fill(time);
01186               T+=time; nT++; E+=ave; nE++;
01187               hfTimeRMS->Fill(time_rms);
01188            }
01189         }       
01190         if(nT>0 && abs(eta)>29 ){ Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT);   Time2Dhbhehf->setBinContent(eta+44,phi+2,T/nT);}     
01191         if(nT>0 && abs(eta)>29 ){ Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); Energy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);}   
01192      }
01193    } 
01194    if(sd==HcalOuter){
01195      // HO histograms
01196      for(int eta=-10;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
01197         if(eta>10 && !isSiPM(eta,phi,4)) continue;
01198         double T=0,nT=0,E=0,nE=0;
01199         for(int depth=4;depth<=4;depth++){
01200            if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
01201               double ave=0; double rms=0; double time=0; double time_rms=0;
01202               ho_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
01203               ho_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
01204               hoEnergy->Fill(ave);
01205               if(ave>0)hoEnergyRMS->Fill(rms/ave);
01206               hoTime->Fill(time);
01207               T+=time; nT++; E+=ave; nE++;
01208               hoTimeRMS->Fill(time_rms);
01209            }
01210         }
01211         if(nT>0){ Time2Dho->Fill(eta,phi,T/nT); Energy2Dho->Fill(eta,phi+1,E/nE) ;}
01212      } 
01213    }
01214 
01215    // compare with reference...
01216    if(sd==HcalBarrel || sd==HcalEndcap){
01217      for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){ 
01218         double T=0,nT=0,E=0,nE=0;
01219         for(int depth=1;depth<=2;depth++){
01220            if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
01221              double val=0,rms=0,time=0,time_rms=0;
01222              double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
01223              if(!hb_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01224              if(!hb_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
01225              if(!hb_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
01226              E+=VAL/val; nE++;
01227              T+=TIME-time; nT++;
01228            }  
01229         }
01230         if(nE>0) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);  
01231         if(nT>0){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01;  refTime2Dhbhehf->setBinContent(eta+44,phi+1,TTT); } 
01232      } 
01233      for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
01234         double T=0,nT=0,E=0,nE=0;
01235         for(int depth=1;depth<=3;depth++){
01236            if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
01237              double val=0,rms=0,time=0,time_rms=0;
01238              double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
01239              if(!he_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01240              if(!he_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
01241              if(!he_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
01242              E+=VAL/val; nE++;
01243              T+=TIME-time; nT++;
01244            }  
01245         }
01246         if(nE>0 && abs(eta)>16) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);  
01247         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); } 
01248         if(nE>0 && abs(eta)>20) refEnergy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);  
01249         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); }  
01250      } 
01251    }
01252    if(sd==HcalForward){
01253      for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
01254         double T=0,nT=0,E=0,nE=0;
01255         for(int depth=1;depth<=2;depth++){
01256            if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
01257              double val=0,rms=0,time=0,time_rms=0;
01258              double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
01259              if(!hf_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01260              if(!hf_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
01261              if(!hf_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
01262              E+=VAL/val; nE++;
01263              T+=TIME-time; nT++;
01264            }  
01265         }
01266         if(nE>0 && abs(eta)>29) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);  
01267         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); }
01268         if(nE>0 && abs(eta)>29) refEnergy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);  
01269         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); } 
01270      }
01271    } 
01272    if(sd==HcalOuter){
01273      for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
01274         if(eta>10 && !isSiPM(eta,phi,4)) continue;
01275         double T=0,nT=0,E=0,nE=0;
01276         for(int depth=4;depth<=4;depth++){
01277            if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
01278              double val=0,rms=0,time=0,time_rms=0;
01279              double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
01280              if(!ho_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01281              if(!ho_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
01282              if(!ho_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
01283              E+=VAL/val; nE++;
01284              T+=TIME-time; nT++;
01285            }  
01286          }
01287         if(nE>0) refEnergy2Dho->Fill(eta,phi,E/nE);  
01288         if(nT>0){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dho->Fill(eta,phi,TTT);}  
01289      } 
01290    }
01292   float min,max;
01293   if(sd==HcalBarrel || sd==HcalEndcap){
01294     min=100;max=-100;
01295     for(int i=1;i<=18;i++){
01296       float ave=-10,rms=-10;
01297       if(get_ave_rbx(HcalBarrel,-1,i,&ave,&rms)){
01298         hb_time_rbx->setBinContent(i,ave);
01299         hb_time_rbx->setBinError(i,rms);
01300         if(ave<min) min=ave;
01301         if(ave>max) max=ave;
01302       }
01303     }
01304     for(int i=1;i<=18;i++){
01305       float ave=-10,rms=-10;
01306       if(get_ave_rbx(HcalBarrel,1,i,&ave,&rms)){
01307         hb_time_rbx->setBinContent(i+18,ave);
01308         hb_time_rbx->setBinError(i+18,rms);
01309         if(ave<min) min=ave;
01310         if(ave>max) max=ave;
01311       }
01312     }
01313     if(max>-100)hb_time_rbx->setAxisRange(min-1,max+1,2);
01314     min=100;max=-100;
01315     for(int i=1;i<=18;i++){
01316       float ave=-10,rms=-10;
01317       if(get_ave_rbx(HcalEndcap,-1,i,&ave,&rms)){
01318         he_time_rbx->setBinContent(i,ave);
01319         he_time_rbx->setBinError(i,rms);
01320         if(ave<min) min=ave;
01321         if(ave>max) max=ave;
01322       }
01323     }
01324     for(int i=1;i<=18;i++){
01325       float ave=-10,rms=-10;
01326       if(get_ave_rbx(HcalEndcap,1,i,&ave,&rms)){
01327         he_time_rbx->setBinContent(i+18,ave);
01328         he_time_rbx->setBinError(i+18,rms);
01329         if(ave<min) min=ave;
01330         if(ave>max) max=ave;
01331       }
01332     }
01333     if(max>-100)he_time_rbx->setAxisRange(min-1,max+1,2);
01334   }
01336   if(sd==HcalOuter){
01337     min=100;max=-100;
01338     for(int i=1;i<=6;i++){
01339       float ave=-10,rms=-10;
01340       if(get_ave_rbx(HcalOuter,-2,i,&ave,&rms)){
01341         ho_time_rbx->setBinContent(i,ave);
01342         ho_time_rbx->setBinError(i,rms);
01343         if(ave<min) min=ave;
01344         if(ave>max) max=ave;
01345       }
01346     }
01347     for(int i=1;i<=6;i++){
01348       float ave=-10,rms=-10;
01349       if(get_ave_rbx(HcalOuter,-1,i,&ave,&rms)){
01350         ho_time_rbx->setBinContent(i+6,ave);
01351         ho_time_rbx->setBinError(i+6,rms);
01352         if(ave<min) min=ave;
01353         if(ave>max) max=ave;
01354       }
01355     }
01356     for(int i=1;i<=12;i++){
01357       float ave=-10,rms=-10;
01358       if(get_ave_rbx(HcalOuter,0,i,&ave,&rms)){
01359         ho_time_rbx->setBinContent(i+12,ave);
01360         ho_time_rbx->setBinError(i+12,rms);
01361         if(ave<min) min=ave;
01362         if(ave>max) max=ave;
01363       }
01364     }
01365     for(int i=1;i<=6;i++){
01366       float ave=-10,rms=-10;
01367       if(get_ave_rbx(HcalOuter,1,i,&ave,&rms)){
01368         ho_time_rbx->setBinContent(i+24,ave);
01369         ho_time_rbx->setBinError(i+24,rms);
01370         if(ave<min) min=ave;
01371         if(ave>max) max=ave;
01372       }
01373     }
01374     for(int i=1;i<=6;i++){
01375       float ave=-10,rms=-10;
01376       if(get_ave_rbx(HcalOuter,2,i,&ave,&rms)){
01377         ho_time_rbx->setBinContent(i+30,ave);
01378         ho_time_rbx->setBinError(i+30,rms);
01379         if(ave<min) min=ave;
01380         if(ave>max) max=ave;
01381       }
01382     }
01383     if(max>-100)ho_time_rbx->setAxisRange(min-1,max+1,2);
01384   }
01386   if(sd==HcalForward){
01387     min=100;max=-100;
01388     for(int i=1;i<=12;i++){
01389       float ave=-10,rms=-10;
01390       if(get_ave_rbx(HcalForward,-1,i,&ave,&rms)){
01391         hf_time_rbx->setBinContent(i,ave);
01392         hf_time_rbx->setBinError(i,rms);
01393         if(ave<min) min=ave;
01394         if(ave>max) max=ave;
01395       }
01396     }
01397     for(int i=1;i<=12;i++){
01398       float ave=-10,rms=-10;
01399       if(get_ave_rbx(HcalForward,1,i,&ave,&rms)){
01400         hf_time_rbx->setBinContent(i+12,ave);
01401         hf_time_rbx->setBinError(i+12,rms);
01402         if(ave<min) min=ave;
01403         if(ave>max) max=ave;
01404       }
01405     }
01406     if(max>-100)hf_time_rbx->setAxisRange(min-1,max+1,2);
01407   }
01408 } 
01409 
01410 void HcalDetDiagLaserMonitor::SaveReference(){
01411 double amp,rms,Time,time_rms;
01412 int    Eta,Phi,Depth,Statistic,Status=0;
01413 char   Subdet[10],str[500];
01414    if(OutputFilePath.size()>0){
01415        if(!Overwrite){
01416           sprintf(str,"%sHcalDetDiagLaserData_run%06i_%i.root",OutputFilePath.c_str(),run_number,dataset_seq_number);
01417        }else{
01418           sprintf(str,"%sHcalDetDiagLaserData.root",OutputFilePath.c_str());
01419        }
01420        TFile *theFile = new TFile(str, "RECREATE");
01421        if(!theFile->IsOpen()) return;
01422        theFile->cd();
01423        sprintf(str,"%d",run_number); TObjString run(str);    run.Write("run number");
01424        sprintf(str,"%d",ievt_);      TObjString events(str); events.Write("Total events processed");
01425        sprintf(str,"%d",dataset_seq_number);      TObjString dsnum(str);  dsnum.Write("Dataset number");
01426        Long_t t; t=time(0); strftime(str,30,"%F %T",localtime(&t)); TObjString tm(str);  tm.Write("Dataset creation time");
01427 
01428        TTree *tree   =new TTree("HCAL Laser data","HCAL Laser data");
01429        if(tree==0)   return;
01430        tree->Branch("Subdet",   &Subdet,         "Subdet/C");
01431        tree->Branch("eta",      &Eta,            "Eta/I");
01432        tree->Branch("phi",      &Phi,            "Phi/I");
01433        tree->Branch("depth",    &Depth,          "Depth/I");
01434        tree->Branch("statistic",&Statistic,      "Statistic/I");
01435        tree->Branch("status",   &Status,         "Status/I");
01436        tree->Branch("amp",      &amp,            "amp/D");
01437        tree->Branch("rms",      &rms,            "rms/D");
01438        tree->Branch("time",     &Time,           "time/D");
01439        tree->Branch("time_rms", &time_rms,       "time_rms/D");
01440        sprintf(Subdet,"HB");
01441        for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
01442           if((Statistic=hb_data[eta+42][phi-1][depth-1].get_statistics1())>10){
01443              Eta=eta; Phi=phi; Depth=depth;
01444              Status=hb_data[eta+42][phi-1][depth-1].get_status();
01445              hb_data[eta+42][phi-1][depth-1].get_average_amp1(&amp,&rms);
01446              hb_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
01447              tree->Fill();
01448           }
01449        } 
01450        sprintf(Subdet,"HE");
01451        for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=3;depth++){
01452          if((Statistic=he_data[eta+42][phi-1][depth-1].get_statistics1())>10){
01453             Eta=eta; Phi=phi; Depth=depth;
01454             Status=he_data[eta+42][phi-1][depth-1].get_status();
01455             he_data[eta+42][phi-1][depth-1].get_average_amp1(&amp,&rms);
01456             he_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
01457             tree->Fill();
01458          }
01459        } 
01460        sprintf(Subdet,"HO");
01461        for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++) for(int depth=4;depth<=4;depth++){
01462          if((Statistic=ho_data[eta+42][phi-1][depth-1].get_statistics1())>10){
01463              Eta=eta; Phi=phi; Depth=depth;
01464              Status=ho_data[eta+42][phi-1][depth-1].get_status();
01465              ho_data[eta+42][phi-1][depth-1].get_average_amp1(&amp,&rms);
01466              ho_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
01467              tree->Fill();
01468          }
01469        } 
01470        sprintf(Subdet,"HF");
01471        for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
01472          if((Statistic=hf_data[eta+42][phi-1][depth-1].get_statistics1())>10){
01473              Eta=eta; Phi=phi; Depth=depth;
01474              Status=hf_data[eta+42][phi-1][depth-1].get_status();
01475              hf_data[eta+42][phi-1][depth-1].get_average_amp1(&amp,&rms);
01476              hf_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
01477              tree->Fill();
01478          }
01479        }
01480        sprintf(Subdet,"CALIB_HB");
01481        for(int eta=-1;eta<=1;eta++) for(int phi=1;phi<=72;phi++){
01482           if((Statistic=calib_data[1][eta+2][phi-1].get_statistics1())>10){
01483              Eta=eta; Phi=phi; Depth=0;
01484              Status=calib_data[1][eta+2][phi-1].get_status();
01485              calib_data[1][eta+2][phi-1].get_average_amp1(&amp,&rms);
01486              calib_data[1][eta+2][phi-1].get_average_time1(&Time,&time_rms);
01487              tree->Fill();
01488           }
01489        } 
01490        sprintf(Subdet,"CALIB_HE");
01491        for(int eta=-1;eta<=1;eta++) for(int phi=1;phi<=72;phi++){
01492           if((Statistic=calib_data[2][eta+2][phi-1].get_statistics1())>10){
01493              Eta=eta; Phi=phi; Depth=0;
01494              Status=calib_data[2][eta+2][phi-1].get_status();
01495              calib_data[2][eta+2][phi-1].get_average_amp1(&amp,&rms);
01496              calib_data[2][eta+2][phi-1].get_average_time1(&Time,&time_rms);
01497              tree->Fill();
01498           }
01499        } 
01500        sprintf(Subdet,"CALIB_HO");
01501        for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
01502           if((Statistic=calib_data[3][eta+2][phi-1].get_statistics1())>10){
01503              Eta=eta; Phi=phi; Depth=0;
01504              Status=calib_data[3][eta+2][phi-1].get_status();
01505              calib_data[3][eta+2][phi-1].get_average_amp1(&amp,&rms);
01506              calib_data[3][eta+2][phi-1].get_average_time1(&Time,&time_rms);
01507              tree->Fill();
01508           }
01509        } 
01510        sprintf(Subdet,"CALIB_HF");
01511        for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
01512           if((Statistic=calib_data[4][eta+2][phi-1].get_statistics1())>10){
01513              Eta=eta; Phi=phi; Depth=0;
01514              Status=calib_data[4][eta+2][phi-1].get_status();
01515              calib_data[4][eta+2][phi-1].get_average_amp1(&amp,&rms);
01516              calib_data[4][eta+2][phi-1].get_average_time1(&Time,&time_rms);
01517              tree->Fill();
01518           }
01519        } 
01520        theFile->Write();
01521        theFile->Close();
01522    }
01523    if(XmlFilePath.size()>0){
01524       char TIME[40];
01525       Long_t t; t=time(0); strftime(TIME,30,"%F %T",localtime(&t));
01526       //create XML file
01527       if(!Overwrite){
01528          sprintf(str,"HcalDetDiagLaser_%i_%i.xml",run_number,dataset_seq_number);
01529       }else{
01530          sprintf(str,"HcalDetDiagLaser.xml");
01531       }
01532       std::string xmlName=str;
01533       ofstream xmlFile;
01534       xmlFile.open(xmlName.c_str());
01535 
01536       xmlFile<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
01537       xmlFile<<"<ROOT>\n";
01538       xmlFile<<"  <HEADER>\n";
01539       xmlFile<<"    <HINTS mode='only-det-root'/>\n";
01540       xmlFile<<"    <TYPE>\n";
01541       xmlFile<<"      <EXTENSION_TABLE_NAME>HCAL_DETMON_LED_LASER_V1</EXTENSION_TABLE_NAME>\n";
01542       xmlFile<<"      <NAME>HCAL Laser HBHE HPD [abort gap global]</NAME>\n";
01543       xmlFile<<"    </TYPE>\n";
01544       xmlFile<<"    <!-- run details -->\n";
01545       xmlFile<<"    <RUN>\n";
01546       xmlFile<<"      <RUN_TYPE>GLOBAL-RUN</RUN_TYPE>\n";
01547       xmlFile<<"      <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
01548       xmlFile<<"      <RUN_BEGIN_TIMESTAMP>2009-01-01 00:00:00</RUN_BEGIN_TIMESTAMP>\n";
01549       xmlFile<<"      <COMMENT_DESCRIPTION>hcal laser data</COMMENT_DESCRIPTION>\n";
01550       xmlFile<<"      <LOCATION>P5</LOCATION>\n";
01551       xmlFile<<"      <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
01552       xmlFile<<"    </RUN>\n";
01553       xmlFile<<"  </HEADER>\n";
01554       xmlFile<<"  <DATA_SET>\n";
01555       xmlFile<<"     <!-- optional dataset metadata -->\n\n";
01556       xmlFile<<"     <SET_NUMBER>"<<dataset_seq_number<<"</SET_NUMBER>\n";
01557       xmlFile<<"     <SET_BEGIN_TIMESTAMP>2009-01-01 00:00:00</SET_BEGIN_TIMESTAMP>\n";
01558       xmlFile<<"     <SET_END_TIMESTAMP>2009-01-01 00:00:00</SET_END_TIMESTAMP>\n";
01559       xmlFile<<"     <NUMBER_OF_EVENTS_IN_SET>"<<ievt_<<"</NUMBER_OF_EVENTS_IN_SET>\n";
01560       xmlFile<<"     <COMMENT_DESCRIPTION>Automatic DQM output</COMMENT_DESCRIPTION>\n";
01561       xmlFile<<"     <DATA_FILE_NAME>"<< xmlName <<"</DATA_FILE_NAME>\n";
01562       xmlFile<<"     <IMAGE_FILE_NAME>data plot url or file path</IMAGE_FILE_NAME>\n";
01563       xmlFile<<"     <!-- who and when created this dataset-->\n\n";
01564       xmlFile<<"     <CREATE_TIMESTAMP>"<<TIME<<"</CREATE_TIMESTAMP>\n";
01565       xmlFile<<"     <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
01566       xmlFile<<"     <!-- version (string) and subversion (number) -->\n";
01567       xmlFile<<"     <!-- fields are used to read data back from the database -->\n\n";
01568       xmlFile<<"     <VERSION>"<<run_number<<dataset_seq_number<<"</VERSION>\n";
01569       xmlFile<<"     <SUBVERSION>1</SUBVERSION>\n";
01570       xmlFile<<"     <!--  Assign predefined dataset attributes -->\n\n";
01571       xmlFile<<"     <PREDEFINED_ATTRIBUTES>\n";
01572       xmlFile<<"        <ATTRIBUTE>\n";
01573       xmlFile<<"           <NAME>HCAL Dataset Status</NAME>\n";
01574       xmlFile<<"           <VALUE>VALID</VALUE>\n";
01575       xmlFile<<"        </ATTRIBUTE>\n";
01576       xmlFile<<"     </PREDEFINED_ATTRIBUTES>\n";
01577       xmlFile<<"     <!-- multiple data block records -->\n\n";
01578 
01579       std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
01580       for(std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
01581          DetId detid=emap->lookup(*eid);
01582          if (detid.det()!=DetId::Hcal) continue;
01583          HcalGenericDetId gid(emap->lookup(*eid));
01584          if(!(!(gid.null()) && 
01585             (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
01586              gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap  ||
01587              gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
01588              gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
01589          int eta,phi,depth; 
01590          std::string subdet="";
01591          HcalDetId hid(detid);
01592          eta=hid.ieta();
01593          phi=hid.iphi();
01594          depth=hid.depth(); 
01595          
01596          double e=0,e_rms=0,t=0,t_rms=0;
01597          if(detid.subdetId()==HcalBarrel){
01598              subdet="HB";
01599              Statistic=hb_data[eta+42][phi-1][depth-1].get_statistics1();
01600              Status   =hb_data[eta+42][phi-1][depth-1].get_status();
01601              hb_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
01602              hb_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
01603          }else if(detid.subdetId()==HcalEndcap){
01604              subdet="HE";
01605              Statistic=he_data[eta+42][phi-1][depth-1].get_statistics1();
01606              Status   =he_data[eta+42][phi-1][depth-1].get_status();
01607              he_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
01608              he_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
01609          }else if(detid.subdetId()==HcalForward){
01610              subdet="HF";
01611              Statistic=hf_data[eta+42][phi-1][depth-1].get_statistics1();
01612              Status   =hf_data[eta+42][phi-1][depth-1].get_status();
01613              hf_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
01614              hf_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
01615          }else if(detid.subdetId()==HcalOuter){
01616              subdet="HO";
01617              Statistic=ho_data[eta+42][phi-1][depth-1].get_statistics1();
01618              Status   =ho_data[eta+42][phi-1][depth-1].get_status();
01619              ho_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
01620              ho_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
01621          }else continue;
01622          xmlFile<<"       <DATA>\n";
01623          xmlFile<<"          <NUMBER_OF_EVENTS_USED>"<<Statistic<<"</NUMBER_OF_EVENTS_USED>\n";
01624          xmlFile<<"          <SIGNAL_MEAN>"<<e<<"</SIGNAL_MEAN>\n";
01625          xmlFile<<"          <SIGNAL_RMS>"<<e_rms<<"</SIGNAL_RMS>\n";
01626          xmlFile<<"          <TIME_MEAN>"<<t<<"</TIME_MEAN>\n";
01627          xmlFile<<"          <TIME_RMS>"<<t_rms<<"</TIME_RMS>\n";
01628          xmlFile<<"          <CHANNEL_STATUS_WORD>"<<Status<<"</CHANNEL_STATUS_WORD>\n";
01629          xmlFile<<"          <CHANNEL_OBJECTNAME>HcalDetId</CHANNEL_OBJECTNAME>\n";
01630          xmlFile<<"             <SUBDET>"<<subdet<<"</SUBDET>\n";
01631          xmlFile<<"             <IETA>"<<eta<<"</IETA>\n";
01632          xmlFile<<"             <IPHI>"<<phi<<"</IPHI>\n";
01633          xmlFile<<"             <DEPTH>"<<depth<<"</DEPTH>\n";
01634          xmlFile<<"             <TYPE>0</TYPE>\n";
01635          xmlFile<<"       </DATA>\n";
01636       }
01638       xmlFile<<"  </DATA_SET>\n";
01639       xmlFile<<"</ROOT>\n";
01640       xmlFile.close();
01641 
01642 
01643       //create CALIB XML file 
01644       sprintf(str,"HcalDetDiagLaserCalib_%i_%i.xml",run_number,dataset_seq_number);
01645       std::string xmlNameCalib=str;
01646       ofstream xmlFileCalib;
01647       xmlFileCalib.open(xmlNameCalib.c_str());
01648 
01649       xmlFileCalib<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
01650       xmlFileCalib<<"<ROOT>\n";
01651       xmlFileCalib<<"  <HEADER>\n";
01652       xmlFileCalib<<"    <HINTS mode='only-det-root'/>\n";
01653       xmlFileCalib<<"    <TYPE>\n";
01654       xmlFileCalib<<"      <EXTENSION_TABLE_NAME>HCAL_DETMON_LED_LASER_V1</EXTENSION_TABLE_NAME>\n";
01655       xmlFileCalib<<"      <NAME>HCAL Laser CALIB [abort gap global]</NAME>\n";
01656       xmlFileCalib<<"    </TYPE>\n";
01657       xmlFileCalib<<"    <!-- run details -->\n";
01658       xmlFileCalib<<"    <RUN>\n";
01659       xmlFileCalib<<"      <RUN_TYPE>Global-RUN</RUN_TYPE>\n";
01660       xmlFileCalib<<"      <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
01661       xmlFileCalib<<"      <RUN_BEGIN_TIMESTAMP>2009-01-01 00:00:00</RUN_BEGIN_TIMESTAMP>\n";
01662       xmlFileCalib<<"      <COMMENT_DESCRIPTION>hcal Laser CALIB data</COMMENT_DESCRIPTION>\n";
01663       xmlFileCalib<<"      <LOCATION>P5</LOCATION>\n";
01664       xmlFileCalib<<"      <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
01665       xmlFileCalib<<"    </RUN>\n";
01666       xmlFileCalib<<"  </HEADER>\n";
01667       xmlFileCalib<<"  <DATA_SET>\n";
01668       xmlFileCalib<<"     <!-- optional dataset metadata -->\n\n";
01669       xmlFileCalib<<"     <SET_NUMBER>"<<dataset_seq_number<<"</SET_NUMBER>\n";
01670       xmlFileCalib<<"     <SET_BEGIN_TIMESTAMP>2009-01-01 00:00:00</SET_BEGIN_TIMESTAMP>\n";
01671       xmlFileCalib<<"     <SET_END_TIMESTAMP>2009-01-01 00:00:00</SET_END_TIMESTAMP>\n";
01672       xmlFileCalib<<"     <NUMBER_OF_EVENTS_IN_SET>"<<ievt_<<"</NUMBER_OF_EVENTS_IN_SET>\n";
01673       xmlFileCalib<<"     <COMMENT_DESCRIPTION>Automatic DQM output</COMMENT_DESCRIPTION>\n";
01674       xmlFileCalib<<"     <DATA_FILE_NAME>"<< xmlNameCalib <<"</DATA_FILE_NAME>\n";
01675       xmlFileCalib<<"     <IMAGE_FILE_NAME>data plot url or file path</IMAGE_FILE_NAME>\n";
01676       xmlFileCalib<<"     <!-- who and when created this dataset-->\n\n";
01677       xmlFileCalib<<"     <CREATE_TIMESTAMP>"<<TIME<<"</CREATE_TIMESTAMP>\n";
01678       xmlFileCalib<<"     <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
01679       xmlFileCalib<<"     <!-- version (string) and subversion (number) -->\n";
01680       xmlFileCalib<<"     <!-- fields are used to read data back from the database -->\n\n";
01681       xmlFileCalib<<"     <VERSION>"<<run_number<<dataset_seq_number<<"</VERSION>\n";
01682       xmlFileCalib<<"     <SUBVERSION>1</SUBVERSION>\n";
01683       xmlFileCalib<<"     <!--  Assign predefined dataset attributes -->\n\n";
01684       xmlFileCalib<<"     <PREDEFINED_ATTRIBUTES>\n";
01685       xmlFileCalib<<"        <ATTRIBUTE>\n";
01686       xmlFileCalib<<"           <NAME>HCAL Dataset Status</NAME>\n";
01687       xmlFileCalib<<"           <VALUE>VALID</VALUE>\n";
01688       xmlFileCalib<<"        </ATTRIBUTE>\n";
01689       xmlFileCalib<<"     </PREDEFINED_ATTRIBUTES>\n";
01690       xmlFileCalib<<"     <!-- multiple data block records -->\n\n";
01691 
01692       for(int sd=1;sd<=4;sd++) for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
01693          std::string subdet="";
01694          if(sd==1) subdet="HB";
01695          if(sd==2) subdet="HE";
01696          if(sd==3) subdet="HO";
01697          if(sd==4) subdet="HF";
01698          if((calib_data[sd][eta+2][phi-1].get_statistics())>100){
01699              double e=0,e_rms=0,t=0,t_rms=0;
01700              Status=calib_data[sd][eta+2][phi-1].get_status();
01701              Statistic=calib_data[sd][eta+2][phi-1].get_statistics1(); 
01702              calib_data[sd][eta+2][phi-1].get_average_amp1(&e,&e_rms);
01703              calib_data[sd][eta+2][phi-1].get_average_time1(&t,&t_rms);
01704              xmlFileCalib<<"       <DATA>\n";
01705              xmlFileCalib<<"          <NUMBER_OF_EVENTS_USED>"<<Statistic<<"</NUMBER_OF_EVENTS_USED>\n";
01706              xmlFileCalib<<"          <SIGNAL_MEAN>"<<e<<"</SIGNAL_MEAN>\n";
01707              xmlFileCalib<<"          <SIGNAL_RMS>"<<e_rms<<"</SIGNAL_RMS>\n";
01708              xmlFileCalib<<"          <TIME_MEAN>"<<t<<"</TIME_MEAN>\n";
01709              xmlFileCalib<<"          <TIME_RMS>"<<t_rms<<"</TIME_RMS>\n";
01710              xmlFileCalib<<"          <CHANNEL_STATUS_WORD>"<<Status<<"</CHANNEL_STATUS_WORD>\n";
01711              xmlFileCalib<<"          <CHANNEL_OBJECTNAME>HcalDetId</CHANNEL_OBJECTNAME>\n";
01712              xmlFileCalib<<"             <SUBDET>"<<subdet<<"</SUBDET>\n";
01713              xmlFileCalib<<"             <IETA>"<<eta<<"</IETA>\n";
01714              xmlFileCalib<<"             <IPHI>"<<phi<<"</IPHI>\n";
01715              xmlFileCalib<<"             <DEPTH>"<<0<<"</DEPTH>\n";
01716              xmlFileCalib<<"             <TYPE>0</TYPE>\n";
01717              xmlFileCalib<<"       </DATA>\n";  
01718          }
01719       }
01721       xmlFileCalib<<"  </DATA_SET>\n";
01722       xmlFileCalib<<"</ROOT>\n";
01723       xmlFileCalib.close();
01724 
01725       sprintf(str,"zip %s.zip %s %s",xmlName.c_str(),xmlName.c_str(),xmlNameCalib.c_str());
01726       system(str);
01727       sprintf(str,"rm -f %s %s",xmlName.c_str(),xmlNameCalib.c_str());
01728       system(str);
01729       sprintf(str,"mv -f %s.zip %s",xmlName.c_str(),XmlFilePath.c_str());
01730       system(str);
01731 
01732    }
01733    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();
01734    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();
01735    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();
01736    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();
01737    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();
01738    ievt_=0;
01739    dataset_seq_number++;
01740 }
01741 void HcalDetDiagLaserMonitor::LoadReference(){
01742 double amp,rms,time,time_rms;
01743 int Eta,Phi,Depth;
01744 char subdet[10];
01745 TFile *f;
01746  if(gSystem->AccessPathName(ReferenceData.c_str())) return;
01747  f = new TFile(ReferenceData.c_str(),"READ");
01748  
01749  if(!f->IsOpen()) return ;
01750  TObjString *STR=(TObjString *)f->Get("run number");
01751  
01752  if(STR){ std::string Ref(STR->String()); ReferenceRun=Ref;}
01753  
01754       TTree*  t=(TTree*)f->Get("HCAL Laser data");
01755       if(!t) return;
01756       t->SetBranchAddress("Subdet",   subdet);
01757       t->SetBranchAddress("eta",      &Eta);
01758       t->SetBranchAddress("phi",      &Phi);
01759       t->SetBranchAddress("depth",    &Depth);
01760       t->SetBranchAddress("amp",      &amp);
01761       t->SetBranchAddress("rms",      &rms);
01762       t->SetBranchAddress("time",     &time);
01763       t->SetBranchAddress("time_rms", &time_rms);
01764       for(int ievt=0;ievt<t->GetEntries();ievt++){
01765          t->GetEntry(ievt);
01766          if(strcmp(subdet,"HB")==0) hb_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
01767          if(strcmp(subdet,"HE")==0) he_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
01768          if(strcmp(subdet,"HO")==0) ho_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
01769          if(strcmp(subdet,"HF")==0) hf_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
01770          if(strcmp(subdet,"CALIB_HB")==0) calib_data[1][Eta+2][Phi-1].set_reference(amp,rms,time,time_rms);
01771          if(strcmp(subdet,"CALIB_HE")==0) calib_data[2][Eta+2][Phi-1].set_reference(amp,rms,time,time_rms);
01772          if(strcmp(subdet,"CALIB_HO")==0) calib_data[3][Eta+2][Phi-1].set_reference(amp,rms,time,time_rms);
01773          if(strcmp(subdet,"CALIB_HF")==0) calib_data[4][Eta+2][Phi-1].set_reference(amp,rms,time,time_rms);
01774      }
01775       f->Close();
01776       IsReference=true;
01777 } 
01778 void HcalDetDiagLaserMonitor::LoadDataset(){
01779 double amp,rms,time,time_rms;
01780 int Eta,Phi,Depth,Statistic;
01781 char subdet[10];
01782 TFile *f;
01783       if(DatasetName.size()==0) return;
01784       createHTMLonly=true;
01785       if(gSystem->AccessPathName(DatasetName.c_str())) return;
01786       f = new TFile(DatasetName.c_str(),"READ");
01787  
01788       if(!f->IsOpen()) return ;
01789 
01790       TTree*  t=0;
01791       t=(TTree*)f->Get("HCAL Laser data");
01792       if(!t) return;
01793       t->SetBranchAddress("Subdet",   subdet);
01794       t->SetBranchAddress("eta",      &Eta);
01795       t->SetBranchAddress("phi",      &Phi);
01796       t->SetBranchAddress("depth",    &Depth);
01797       t->SetBranchAddress("amp",      &amp);
01798       t->SetBranchAddress("rms",      &rms);
01799       t->SetBranchAddress("time",     &time);
01800       t->SetBranchAddress("time_rms", &time_rms);
01801       t->SetBranchAddress("statistic",&Statistic);
01802       for(int ievt=0;ievt<t->GetEntries();ievt++){
01803          t->GetEntry(ievt);
01804          if(strcmp(subdet,"HB")==0){ nHB++;
01805             hb_data[Eta+42][Phi-1][Depth-1].set_data(amp,rms,time,time_rms);
01806             hb_data[Eta+42][Phi-1][Depth-1].set_statistics(Statistic);
01807             hb_data[Eta+42][Phi-1][Depth-1].set_statistics1(Statistic);
01808          }
01809          if(strcmp(subdet,"HE")==0){ nHE++; 
01810             he_data[Eta+42][Phi-1][Depth-1].set_data(amp,rms,time,time_rms);
01811             he_data[Eta+42][Phi-1][Depth-1].set_statistics(Statistic);
01812             he_data[Eta+42][Phi-1][Depth-1].set_statistics1(Statistic);
01813          }
01814          if(strcmp(subdet,"HO")==0){ nHO++;
01815             ho_data[Eta+42][Phi-1][Depth-1].set_data(amp,rms,time,time_rms);
01816             ho_data[Eta+42][Phi-1][Depth-1].set_statistics(Statistic);
01817             ho_data[Eta+42][Phi-1][Depth-1].set_statistics1(Statistic);
01818          }
01819          if(strcmp(subdet,"HF")==0){ nHF++;
01820             hf_data[Eta+42][Phi-1][Depth-1].set_data(amp,rms,time,time_rms);
01821             hf_data[Eta+42][Phi-1][Depth-1].set_statistics(Statistic);
01822             hf_data[Eta+42][Phi-1][Depth-1].set_statistics1(Statistic);
01823         }
01824         if(strcmp(subdet,"CALIB_HB")==0){
01825             calib_data[1][Eta+2][Phi-1].set_data(amp,rms,time,time_rms);
01826             calib_data[1][Eta+2][Phi-1].set_statistics(Statistic);
01827             calib_data[1][Eta+2][Phi-1].set_statistics1(Statistic);
01828         }
01829         if(strcmp(subdet,"CALIB_HE")==0){
01830             calib_data[2][Eta+2][Phi-1].set_data(amp,rms,time,time_rms);
01831             calib_data[2][Eta+2][Phi-1].set_statistics(Statistic);
01832             calib_data[2][Eta+2][Phi-1].set_statistics1(Statistic);
01833         }
01834         if(strcmp(subdet,"CALIB_HO")==0){
01835             calib_data[3][Eta+2][Phi-1].set_data(amp,rms,time,time_rms);
01836             calib_data[3][Eta+2][Phi-1].set_statistics(Statistic);
01837             calib_data[3][Eta+2][Phi-1].set_statistics1(Statistic);
01838         }
01839         if(strcmp(subdet,"CALIB_HF")==0){
01840             calib_data[4][Eta+2][Phi-1].set_data(amp,rms,time,time_rms);
01841             calib_data[4][Eta+2][Phi-1].set_statistics(Statistic);
01842             calib_data[4][Eta+2][Phi-1].set_statistics1(Statistic); 
01843         }
01844       }
01845       TObjString *STR1=(TObjString *)f->Get("run number");
01846       if(STR1){ int run; sscanf(STR1->String(),"%i",&run); meRUN_->Fill(run); run_number=run;}
01847 
01848       TObjString *STR2=(TObjString *)f->Get("Total events processed");
01849       if(STR2){ int events; sscanf(STR2->String(),"%i",&events); meEVT_->Fill(events); ievt_=events;}
01850 
01851       TObjString *STR3=(TObjString *)f->Get("Dataset number");
01852       if(STR3){ int ds; sscanf(STR3->String(),"%i",&ds); dataset_seq_number=ds;}
01853       f->Close(); 
01854 } 
01855 
01856 void HcalDetDiagLaserMonitor::SaveRaddamData(){
01857 float adc_range[20]={14,28,40,52,67,132,202,262,322,397,722,1072,1372,1672,2047,3672,5422,6922,8422,10297};
01858 int   adc_bins[20]={1,2,3,4,5,5,10,15,20,25,25,50,75,100,125,125,250,375,500,625};
01859 char str[100];
01860       TF1 *fitFunc = new TF1("fitFunc","gaus");
01861       if(fitFunc==0) return;
01862       for(int i=0;i<56;i++){
01863           float sum1=0,sum2=0,n=0;
01864           S1[i]=S2[i]=0;
01865           for(int j=0;j<128;j++){
01866             sum1+=(adc2fC[j]-2.5)*Raddam_data[i].s1_adc[j];
01867             sum2+=(adc2fC[j]-2.5)*Raddam_data[i].s2_adc[j];
01868             n+=Raddam_data[i].s1_adc[j];
01869           }
01870           if(n<100) continue;
01871           sum1=sum1/n;
01872           sum2=sum2/n;
01873           int N=0;
01874           int Ws1=1,Ws2=1;
01875           for(N=1;N<19;N++) if(sum1>adc_range[N-1] && sum1<adc_range[N]) break;
01876           Ws1=adc_bins[N+1];
01877           for(N=1;N<19;N++) if(sum2>adc_range[N-1] && sum2<adc_range[N]) break;
01878           Ws2=adc_bins[N+1];
01879           sprintf(str,"Raddam(%i,%i,%i) S1",RADDAM_CH[i].eta,RADDAM_CH[i].phi,RADDAM_CH[i].depth);
01880           S1[i]=new TH1F(str,str,10000/Ws1,0,10000);
01881           sprintf(str,"Raddam(%i,%i,%i) S2",RADDAM_CH[i].eta,RADDAM_CH[i].phi,RADDAM_CH[i].depth);
01882           S2[i]=new TH1F(str,str,10000/Ws1,0,10000);
01883           for(int j=0;j<128;j++){
01884             S1[i]->Fill(adc2fC[j]-2.5,Raddam_data[i].s1_adc[j]);
01885             S2[i]->Fill(adc2fC[j]-2.5,Raddam_data[i].s2_adc[j]); 
01886           }
01887           double parm[3];
01888           S1[i]->Fit("fitFunc");
01889           S1[i]->GetFunction("fitFunc")->GetParameters(parm);
01890           Raddam_data[i].S1MEAN=S1[i]->GetMean();
01891           Raddam_data[i].S1RMS=S1[i]->GetRMS();
01892           Raddam_data[i].S1FITMEAN=parm[1];
01893           Raddam_data[i].S1FITMEANER=S1[i]->GetFunction("fitFunc")->GetParError(1);
01894           Raddam_data[i].S1FITSIGMA=parm[2];
01895           Raddam_data[i].S1CHI2=S1[i]->GetFunction("fitFunc")->GetChisquare();
01896           Raddam_data[i].S1NDF=S1[i]->GetFunction("fitFunc")->GetNDF();
01897           Raddam_data[i].S1BINWIDTH=Ws1;
01898           S2[i]->Fit("fitFunc");
01899           S2[i]->GetFunction("fitFunc")->GetParameters(parm);
01900           Raddam_data[i].S2MEAN=S2[i]->GetMean();
01901           Raddam_data[i].S2RMS=S2[i]->GetRMS();
01902           Raddam_data[i].S2FITMEAN=parm[1];
01903           Raddam_data[i].S2FITMEANER=S2[i]->GetFunction("fitFunc")->GetParError(1);
01904           Raddam_data[i].S2FITSIGMA=parm[2];
01905           Raddam_data[i].S2CHI2=S2[i]->GetFunction("fitFunc")->GetChisquare();
01906           Raddam_data[i].S2NDF=S2[i]->GetFunction("fitFunc")->GetNDF();
01907           Raddam_data[i].S2BINWIDTH=Ws2;
01908       }
01909       if(XmlFilePath.size()>0){
01910           char TIME[40];
01911           Long_t t; t=time(0); strftime(TIME,30,"%F %T",localtime(&t));      
01912           //create XML file
01913           if(!Overwrite){
01914              sprintf(str,"HcalDetDiagRaddam_%i_%i.xml",run_number,dataset_seq_number);
01915           }else{
01916              sprintf(str,"HcalDetDiagRaddam.xml");
01917           }
01918           std::string xmlName=str;
01919           ofstream xmlFile;
01920           xmlFile.open(xmlName.c_str());
01921           xmlFile<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n";
01922           xmlFile<<"<ROOT>\n";
01923           xmlFile<<"  <HEADER>\n";
01924           xmlFile<<"    <TYPE>\n";
01925           xmlFile<<"      <EXTENSION_TABLE_NAME>HCAL_RADDAM</EXTENSION_TABLE_NAME>\n";
01926           xmlFile<<"      <NAME>HCAL Raddam</NAME>\n";
01927           xmlFile<<"    </TYPE>\n";
01928           xmlFile<<"    <!-- run details -->\n";
01929           xmlFile<<"    <RUN>\n";
01930           xmlFile<<"      <RUN_TYPE>TEST LOCAL-RUN</RUN_TYPE>\n";
01931           xmlFile<<"      <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
01932           xmlFile<<"      <RUN_BEGIN_TIMESTAMP>"<<TIME<<"</RUN_BEGIN_TIMESTAMP>\n";
01933           xmlFile<<"      <COMMENT_DESCRIPTION>hcal raddam data</COMMENT_DESCRIPTION>\n";
01934           xmlFile<<"      <LOCATION>P5</LOCATION>\n";
01935           xmlFile<<"      <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
01936           xmlFile<<"    </RUN>\n";
01937           xmlFile<<"  </HEADER>\n";
01938           xmlFile<<"  <DATA_SET>\n";
01939           xmlFile<<"     <COMMENT_DESCRIPTION>Test Raddam data</COMMENT_DESCRIPTION>\n";
01940           xmlFile<<"     <CREATE_TIMESTAMP>"<<TIME<<"</CREATE_TIMESTAMP>\n";
01941           xmlFile<<"     <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
01942           xmlFile<<"     <VERSION>Test_Version_1</VERSION>\n";
01943  
01944           for(int i=0;i<56;i++){
01945              xmlFile<<"     <DATA>\n";
01946              xmlFile<<"        <SUBDET>HF</SUBDET>\n";
01947              xmlFile<<"        <IETA>"<<RADDAM_CH[i].eta<<"</IETA>\n";
01948              xmlFile<<"        <IPHI>"<<RADDAM_CH[i].phi<<"</IPHI>\n";
01949              xmlFile<<"        <DEPTH>"<<RADDAM_CH[i].depth<<"</DEPTH>\n";
01950 
01951              xmlFile<<"        <TOTEVNT>"<<Raddam_data[i].TOTEVNT<<"</TOTEVNT>\n";
01952              xmlFile<<"        <CUT1EVNT>"<<Raddam_data[i].CUT1EVNT<<"</CUT1EVNT>\n";
01953              xmlFile<<"        <CUT2EVNT>"<<Raddam_data[i].CUT2EVNT<<"</CUT2EVNT>\n";
01954 
01955              xmlFile<<"        <S1MEAN>"<<Raddam_data[i].S1MEAN <<"</S1MEAN>\n";
01956              xmlFile<<"        <S1RMS>"<<Raddam_data[i].S1RMS <<"</S1RMS>\n";
01957              xmlFile<<"        <S1FITMEAN>"<<Raddam_data[i].S1FITMEAN <<"</S1FITMEAN>\n";
01958              xmlFile<<"        <S1FITMEANER>"<<Raddam_data[i].S1FITMEANER <<"</S1FITMEANER>\n";
01959              xmlFile<<"        <S1FITSIGMA>"<<Raddam_data[i].S1FITSIGMA <<"</S1FITSIGMA>\n";
01960              xmlFile<<"        <S1CHI2>"<<Raddam_data[i].S1CHI2 <<"</S1CHI2>\n";
01961              xmlFile<<"        <S1NDF>"<<Raddam_data[i].S1NDF <<"</S1NDF>\n";
01962              xmlFile<<"        <S1BINWIDTH>"<<Raddam_data[i].S1BINWIDTH <<"</S1BINWIDTH>\n";
01963 
01964              xmlFile<<"        <S2MEAN>"<<Raddam_data[i].S2MEAN <<"</S2MEAN>\n";
01965              xmlFile<<"        <S2RMS>"<<Raddam_data[i].S2RMS <<"</S2RMS>\n";
01966              xmlFile<<"        <S2FITMEAN>"<<Raddam_data[i].S2FITMEAN <<"</S2FITMEAN>\n";
01967              xmlFile<<"        <S2FITMEANER>"<<Raddam_data[i].S2FITMEANER <<"</S2FITMEANER>\n";
01968              xmlFile<<"        <S2FITSIGMA>"<<Raddam_data[i].S2FITSIGMA <<"</S2FITSIGMA>\n";
01969              xmlFile<<"        <S2CHI2>"<<Raddam_data[i].S2CHI2 <<"</S2CHI2>\n";
01970              xmlFile<<"        <S2NDF>"<<Raddam_data[i].S2NDF <<"</S2NDF>\n";
01971              xmlFile<<"        <S2BINWIDTH>"<<Raddam_data[i].S2BINWIDTH <<"</S2BINWIDTH>\n";
01972              xmlFile<<"    </DATA>\n";
01973           }
01974           xmlFile<<"  </DATA_SET>\n";
01975           xmlFile<<"</ROOT>\n";
01976 
01977           xmlFile.close();
01978           sprintf(str,"zip %s.zip %s",xmlName.c_str(),xmlName.c_str());
01979           system(str);
01980           sprintf(str,"rm -f %s",xmlName.c_str());
01981           system(str);
01982           sprintf(str,"mv -f %s.zip %s",xmlName.c_str(),XmlFilePath.c_str());
01983           system(str);
01984       }
01985       if(OutputFilePath.size()>0){
01986          if(!Overwrite){
01987             sprintf(str,"%sHcalDetDiagRaddamData_run%06i_%i.root",OutputFilePath.c_str(),run_number,dataset_seq_number);
01988          }else{
01989             sprintf(str,"%sHcalDetDiagRaddamData.root",OutputFilePath.c_str());
01990          }
01991          TFile *theFile = new TFile(str, "RECREATE");
01992          if(!theFile->IsOpen()) return;
01993          theFile->cd();
01994          for(int i=0;i<56;i++){
01995             if(S1[i]!=0)S1[i]->Write();
01996             if(S2[i]!=0)S2[i]->Write();
01997          }
01998          theFile->Write();
01999          theFile->Close();
02000       } 
02001 }
02002 
02003 void HcalDetDiagLaserMonitor::endRun(const edm::Run& run, const edm::EventSetup& c) {
02004     if(RaddamRun){
02005        SaveRaddamData();
02006     }
02007     if((LocalRun || !Online_ || createHTMLonly) && ievt_>10){
02008        fillHistos(HcalBarrel);
02009        fillHistos(HcalOuter);
02010        fillHistos(HcalForward);
02011        fillProblems(HcalBarrel);
02012        fillProblems(HcalEndcap);
02013        fillProblems(HcalOuter); 
02014        fillProblems(HcalForward); 
02015        if(!RaddamRun)SaveReference();
02016     }
02017 }
02018 
02019 void HcalDetDiagLaserMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c){}
02020 void HcalDetDiagLaserMonitor::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c){}
02021 
02022 //define this as a plug-in
02023 DEFINE_FWK_MODULE(HcalDetDiagLaserMonitor);