CMS 3D CMS Logo

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