CMS 3D CMS Logo

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