CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQM/HcalMonitorTasks/src/HcalDetDiagPedestalMonitor.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HcalDetDiagPedestalMonitor
00004 // Class:      HcalDetDiagPedestalMonitor
00005 // 
00013 //
00014 // Original Author:  Dmitry Vishnevskiy,591 R-013,+41227674265,
00015 //         Created:  Tue Mar  9 12:59:18 CET 2010
00016 // $Id: HcalDetDiagPedestalMonitor.cc,v 1.16 2010/04/08 15:43:17 temple Exp $
00017 //
00018 //
00019 // user include files
00020 #include "FWCore/Framework/interface/Frameworkfwd.h"
00021 #include "FWCore/Framework/interface/Event.h"
00022 #include "FWCore/Framework/interface/MakerMacros.h"
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 #include "DQMServices/Core/interface/MonitorElement.h"
00027 #include "DQM/HcalMonitorTasks/interface/HcalBaseMonitor.h"
00028 
00029 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00030 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00031 
00032 #include <math.h>
00033 // this is to retrieve HCAL digi's
00034 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00035 // to retrive trigger information (local runs only)
00036 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
00037 
00038 #include "CalibCalorimetry/HcalAlgos/interface/HcalLogicalMapGenerator.h"
00039 #include "CondFormats/HcalObjects/interface/HcalLogicalMap.h"
00040 
00041 #include "DQM/HcalMonitorTasks/interface/HcalBaseDQMonitor.h"
00042 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00043 #include "DQM/HcalMonitorTasks/interface/HcalEtaPhiHists.h"
00044 
00045 #include "TFile.h"
00046 #include "TTree.h"
00047 #include "TSystem.h"
00048 
00049 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00050 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00051 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00052 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
00053 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00054 
00055 #include <iostream>
00056 #include <fstream>
00057 
00058 class HcalDetDiagPedestalData{
00059 public: 
00060    HcalDetDiagPedestalData(){ 
00061              reset();
00062              IsReference=false;
00063              status=0; 
00064              nChecks=nMissing=nBadPed=nBadRms=nUnstable=0;  
00065           }
00066    void   reset(){
00067              for(int i=0;i<128;i++) adc[i]=0; 
00068              overflow=0;
00069           }       
00070    void   add_statistics(unsigned int val){
00071              if(val<25) adc[val&0x7F]++; else overflow++;    
00072           }
00073    void   set_reference(float val,float rms){
00074              ref_ped=val; ref_rms=rms;
00075              IsReference=true;
00076           }       
00077    void   change_status(int val){
00078              status|=val;
00079           }       
00080    int    get_status(){
00081              return status;
00082           }       
00083    bool   get_reference(double *val,double *rms){
00084              *val=ref_ped; *rms=ref_rms;
00085              return IsReference;
00086           }       
00087    bool   get_average(double *ave,double *rms){
00088              double Sum=0,nSum=0; 
00089              int from,to,max=adc[0],maxi=0;
00090              for(int i=1;i<25;i++) if(adc[i]>max){ max=adc[i]; maxi=i;} 
00091              from=0; to=maxi+6;
00092              for(int i=from;i<=to;i++){
00093                 Sum+=i*adc[i];
00094                 nSum+=adc[i];
00095              } 
00096              if(nSum>0) *ave=Sum/nSum; else return false;
00097              Sum=0;
00098              for(int i=from;i<=to;i++) Sum+=adc[i]*(i-*ave)*(i-*ave);
00099              *rms=sqrt(Sum/nSum);
00100              return true; 
00101           }
00102    int    get_statistics(){
00103              int nSum=0;  
00104              for(int i=0;i<25;i++) nSum+=adc[i];
00105              return nSum;
00106           } 
00107    int    get_overflow(){
00108              return overflow;
00109           }   
00110    float   nChecks;
00111    float   nMissing;
00112    float   nUnstable;
00113    float   nBadPed;
00114    float   nBadRms;
00115 private:   
00116    int   adc[128];
00117    int   overflow;
00118    bool  IsReference;
00119    float ref_ped;
00120    float ref_rms;
00121    int   status;
00122 };
00123 
00124 
00125 class HcalDetDiagPedestalMonitor : public HcalBaseDQMonitor {
00126    public:
00127       explicit HcalDetDiagPedestalMonitor(const edm::ParameterSet&);
00128       ~HcalDetDiagPedestalMonitor();
00129 
00130 
00131    private:
00132       void SaveReference();
00133       void LoadReference();
00134       void CheckStatus();
00135       void fillHistos();
00136 
00137       const HcalElectronicsMap  *emap;
00138       edm::InputTag inputLabelDigi_;
00139       edm::InputTag  inputLabelRawData_;
00140 
00141       void beginRun(const edm::Run& run, const edm::EventSetup& c);  
00142       void endRun(const edm::Run& run, const edm::EventSetup& c);
00143       void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c) ;
00144       void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c);
00145       void analyze(const edm::Event&, const edm::EventSetup&);
00146 
00147       int         ievt_;
00148       int         run_number;
00149       int         dataset_seq_number;
00150       bool        IsReference;
00151       bool        LocalRun;
00152 
00153       double      HBMeanTreshold;
00154       double      HBRmsTreshold;
00155       double      HEMeanTreshold;
00156       double      HERmsTreshold;
00157       double      HOMeanTreshold;
00158       double      HORmsTreshold;
00159       double      HFMeanTreshold;
00160       double      HFRmsTreshold;
00161 
00162       std::string ReferenceData;
00163       std::string ReferenceRun;
00164       std::string OutputFilePath;
00165       std::string XmlFilePath;
00166 
00167       std::string prefixME_;
00168       bool        Online_;
00169       bool        Overwrite;
00170 
00171       MonitorElement *meEVT_,*meRUN_;
00172       MonitorElement *RefRun_;
00173       MonitorElement *PedestalsAve4HB;
00174       MonitorElement *PedestalsAve4HE;
00175       MonitorElement *PedestalsAve4HO;
00176       MonitorElement *PedestalsAve4HF;
00177       MonitorElement *PedestalsAve4Simp;
00178  
00179       MonitorElement *PedestalsAve4HBref;
00180       MonitorElement *PedestalsAve4HEref;
00181       MonitorElement *PedestalsAve4HOref;
00182       MonitorElement *PedestalsAve4HFref;
00183       MonitorElement *PedestalsRmsHB;
00184       MonitorElement *PedestalsRmsHE;
00185       MonitorElement *PedestalsRmsHO;
00186       MonitorElement *PedestalsRmsHF;
00187       MonitorElement *PedestalsRmsSimp;
00188   
00189       MonitorElement *PedestalsRmsHBref;
00190       MonitorElement *PedestalsRmsHEref;
00191       MonitorElement *PedestalsRmsHOref;
00192       MonitorElement *PedestalsRmsHFref;
00193   
00194       MonitorElement *Pedestals2DRmsHBHEHF;
00195       MonitorElement *Pedestals2DRmsHO;
00196       MonitorElement *Pedestals2DHBHEHF;
00197       MonitorElement *Pedestals2DHO;
00198       MonitorElement *Pedestals2DErrorHBHEHF;
00199       MonitorElement *Pedestals2DErrorHO;
00200  
00201       EtaPhiHists* ProblemCellsByDepth_missing;
00202       EtaPhiHists* ProblemCellsByDepth_unstable;
00203       EtaPhiHists* ProblemCellsByDepth_badped;
00204       EtaPhiHists* ProblemCellsByDepth_badrms;
00205 
00206       EtaPhiHists* ProblemCellsByDepth_missing_val;
00207       EtaPhiHists* ProblemCellsByDepth_unstable_val;
00208       EtaPhiHists* ProblemCellsByDepth_badped_val;
00209       EtaPhiHists* ProblemCellsByDepth_badrms_val;
00210       std::vector<std::string> problemnames_;
00211  
00212       HcalDetDiagPedestalData hb_data[85][72][4][4];
00213       HcalDetDiagPedestalData he_data[85][72][4][4];
00214       HcalDetDiagPedestalData ho_data[85][72][4][4];
00215       HcalDetDiagPedestalData hf_data[85][72][4][4];
00216 };
00217 
00218 HcalDetDiagPedestalMonitor::HcalDetDiagPedestalMonitor(const edm::ParameterSet& iConfig){
00219   ievt_=-1;
00220   emap=0;
00221   dataset_seq_number=1;
00222   run_number=-1;
00223   IsReference=false;
00224   LocalRun=false;
00225 
00226   inputLabelDigi_    = iConfig.getUntrackedParameter<edm::InputTag>("digiLabel");
00227   inputLabelRawData_ = iConfig.getUntrackedParameter<edm::InputTag>("rawDataLabel");
00228   ReferenceData    = iConfig.getUntrackedParameter<std::string>("PedestalReferenceData" ,"");
00229   OutputFilePath   = iConfig.getUntrackedParameter<std::string>("OutputFilePath", "");
00230   XmlFilePath      = iConfig.getUntrackedParameter<std::string>("XmlFilePath", "");
00231   Online_          = iConfig.getUntrackedParameter<bool>  ("online",false);
00232   Overwrite        = iConfig.getUntrackedParameter<bool>  ("Overwrite",true);
00233 
00234   prefixME_        = iConfig.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00235   if (prefixME_.size()>0 && prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00236     prefixME_.append("/");
00237   subdir_          = iConfig.getUntrackedParameter<std::string>("TaskFolder","DetDiagPedestalMonitor_Hcal/");
00238   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00239     subdir_.append("/");
00240   subdir_=prefixME_+subdir_;
00241 
00242   HBMeanTreshold   = iConfig.getUntrackedParameter<double>("HBMeanPedestalTreshold" , 0.2);
00243   HBRmsTreshold    = iConfig.getUntrackedParameter<double>("HBRmsPedestalTreshold"  , 0.3);
00244   HEMeanTreshold   = iConfig.getUntrackedParameter<double>("HEMeanPedestalTreshold" , 0.2);
00245   HERmsTreshold    = iConfig.getUntrackedParameter<double>("HERmsPedestalTreshold"  , 0.3);
00246   HOMeanTreshold   = iConfig.getUntrackedParameter<double>("HOMeanPedestalTreshold" , 0.2);
00247   HORmsTreshold    = iConfig.getUntrackedParameter<double>("HORmsPedestalTreshold"  , 0.3);
00248   HFMeanTreshold   = iConfig.getUntrackedParameter<double>("HFMeanPedestalTreshold" , 0.2);
00249   HFRmsTreshold    = iConfig.getUntrackedParameter<double>("HFRmsPedestalTreshold"  , 0.3);
00250 }
00251 HcalDetDiagPedestalMonitor::~HcalDetDiagPedestalMonitor(){}
00252 
00253 void HcalDetDiagPedestalMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c){
00254   edm::ESHandle<HcalDbService> conditions_;
00255   c.get<HcalDbRecord>().get(conditions_);
00256   emap=conditions_->getHcalMapping();
00257 
00258   HcalBaseDQMonitor::setup();
00259   if (!dbe_) return;
00260   std::string name;
00261 
00262   dbe_->setCurrentFolder(subdir_);   
00263   meEVT_ = dbe_->bookInt("HcalDetDiagPedestalMonitor Event Number");
00264   meRUN_ = dbe_->bookInt("HcalDetDiagPedestalMonitor Run Number");
00265 
00266   ProblemCellsByDepth_missing = new EtaPhiHists();
00267   ProblemCellsByDepth_missing->setup(dbe_," Problem Missing Channels");
00268   for(unsigned int i=0;i<ProblemCellsByDepth_missing->depth.size();i++)
00269           problemnames_.push_back(ProblemCellsByDepth_missing->depth[i]->getName());
00270   ProblemCellsByDepth_unstable = new EtaPhiHists();
00271   ProblemCellsByDepth_unstable->setup(dbe_," Problem Unstable Channels");
00272   for(unsigned int i=0;i<ProblemCellsByDepth_unstable->depth.size();i++)
00273           problemnames_.push_back(ProblemCellsByDepth_unstable->depth[i]->getName());
00274   ProblemCellsByDepth_badped = new EtaPhiHists();
00275   ProblemCellsByDepth_badped->setup(dbe_," Problem Bad Pedestal Value");
00276   for(unsigned int i=0;i<ProblemCellsByDepth_badped->depth.size();i++)
00277           problemnames_.push_back(ProblemCellsByDepth_badped->depth[i]->getName());
00278   ProblemCellsByDepth_badrms = new EtaPhiHists();
00279   ProblemCellsByDepth_badrms->setup(dbe_," Problem Bad Rms Value");
00280   for(unsigned int i=0;i<ProblemCellsByDepth_badrms->depth.size();i++)
00281           problemnames_.push_back(ProblemCellsByDepth_badrms->depth[i]->getName());
00282 
00283   dbe_->setCurrentFolder(subdir_+"Summary Plots");
00284   name="HB Pedestal Distribution (average over 4 caps)";           PedestalsAve4HB = dbe_->book1D(name,name,200,0,6);
00285   name="HE Pedestal Distribution (average over 4 caps)";           PedestalsAve4HE = dbe_->book1D(name,name,200,0,6);
00286   name="HO Pedestal Distribution (average over 4 caps)";           PedestalsAve4HO = dbe_->book1D(name,name,200,0,6);
00287   name="HF Pedestal Distribution (average over 4 caps)";           PedestalsAve4HF = dbe_->book1D(name,name,200,0,6);
00288   name="SIPM Pedestal Distribution (average over 4 caps)";         PedestalsAve4Simp = dbe_->book1D(name,name,200,5,15);
00289      
00290   name="HB Pedestal-Reference Distribution (average over 4 caps)"; PedestalsAve4HBref= dbe_->book1D(name,name,1500,-3,3);
00291   name="HE Pedestal-Reference Distribution (average over 4 caps)"; PedestalsAve4HEref= dbe_->book1D(name,name,1500,-3,3);
00292   name="HO Pedestal-Reference Distribution (average over 4 caps)"; PedestalsAve4HOref= dbe_->book1D(name,name,1500,-3,3);
00293   name="HF Pedestal-Reference Distribution (average over 4 caps)"; PedestalsAve4HFref= dbe_->book1D(name,name,1500,-3,3);
00294     
00295   name="HB Pedestal RMS Distribution (individual cap)";            PedestalsRmsHB = dbe_->book1D(name,name,200,0,2);
00296   name="HE Pedestal RMS Distribution (individual cap)";            PedestalsRmsHE = dbe_->book1D(name,name,200,0,2);
00297   name="HO Pedestal RMS Distribution (individual cap)";            PedestalsRmsHO = dbe_->book1D(name,name,200,0,2);
00298   name="HF Pedestal RMS Distribution (individual cap)";            PedestalsRmsHF = dbe_->book1D(name,name,200,0,2);
00299   name="SIPM Pedestal RMS Distribution (individual cap)";          PedestalsRmsSimp = dbe_->book1D(name,name,200,0,4);
00300      
00301   name="HB Pedestal_rms-Reference_rms Distribution";               PedestalsRmsHBref = dbe_->book1D(name,name,1500,-3,3);
00302   name="HE Pedestal_rms-Reference_rms Distribution";               PedestalsRmsHEref = dbe_->book1D(name,name,1500,-3,3);
00303   name="HO Pedestal_rms-Reference_rms Distribution";               PedestalsRmsHOref = dbe_->book1D(name,name,1500,-3,3);
00304   name="HF Pedestal_rms-Reference_rms Distribution";               PedestalsRmsHFref = dbe_->book1D(name,name,1500,-3,3);
00305      
00306   name="HBHEHF pedestal mean map";       Pedestals2DHBHEHF      = dbe_->book2D(name,name,87,-43,43,74,0,73);
00307   name="HO pedestal mean map";           Pedestals2DHO          = dbe_->book2D(name,name,33,-16,16,74,0,73);
00308   name="HBHEHF pedestal rms map";        Pedestals2DRmsHBHEHF   = dbe_->book2D(name,name,87,-43,43,74,0,73);
00309   name="HO pedestal rms map";            Pedestals2DRmsHO       = dbe_->book2D(name,name,33,-16,16,74,0,73);
00310   name="HBHEHF pedestal problems map";   Pedestals2DErrorHBHEHF = dbe_->book2D(name,name,87,-43,43,74,0,73);
00311   name="HO pedestal problems map";       Pedestals2DErrorHO     = dbe_->book2D(name,name,33,-16,16,74,0,73);
00312 
00313   Pedestals2DHBHEHF->setAxisRange(1,5,3);
00314   Pedestals2DHO->setAxisRange(1,5,3);
00315   Pedestals2DRmsHBHEHF->setAxisRange(0,2,3);
00316   Pedestals2DRmsHO->setAxisRange(0,2,3);
00317 
00318   Pedestals2DHBHEHF->setAxisTitle("i#eta",1);
00319   Pedestals2DHBHEHF->setAxisTitle("i#phi",2);
00320   Pedestals2DHO->setAxisTitle("i#eta",1);
00321   Pedestals2DHO->setAxisTitle("i#phi",2);
00322   Pedestals2DRmsHBHEHF->setAxisTitle("i#eta",1);
00323   Pedestals2DRmsHBHEHF->setAxisTitle("i#phi",2);
00324   Pedestals2DRmsHO->setAxisTitle("i#eta",1);
00325   Pedestals2DRmsHO->setAxisTitle("i#phi",2);
00326   Pedestals2DErrorHBHEHF->setAxisTitle("i#eta",1);
00327   Pedestals2DErrorHBHEHF->setAxisTitle("i#phi",2);
00328   Pedestals2DErrorHO->setAxisTitle("i#eta",1);
00329   Pedestals2DErrorHO->setAxisTitle("i#phi",2);
00330   PedestalsAve4HB->setAxisTitle("ADC counts",1);
00331   PedestalsAve4HE->setAxisTitle("ADC counts",1);
00332   PedestalsAve4HO->setAxisTitle("ADC counts",1);
00333   PedestalsAve4HF->setAxisTitle("ADC counts",1);
00334   PedestalsAve4Simp->setAxisTitle("ADC counts",1);
00335   PedestalsAve4HBref->setAxisTitle("ADC counts",1);
00336   PedestalsAve4HEref->setAxisTitle("ADC counts",1);
00337   PedestalsAve4HOref->setAxisTitle("ADC counts",1);
00338   PedestalsAve4HFref->setAxisTitle("ADC counts",1);
00339   PedestalsRmsHB->setAxisTitle("ADC counts",1);
00340   PedestalsRmsHE->setAxisTitle("ADC counts",1);
00341   PedestalsRmsHO->setAxisTitle("ADC counts",1);
00342   PedestalsRmsHF->setAxisTitle("ADC counts",1);
00343   PedestalsRmsSimp->setAxisTitle("ADC counts",1);
00344   PedestalsRmsHBref->setAxisTitle("ADC counts",1);
00345   PedestalsRmsHEref->setAxisTitle("ADC counts",1);
00346   PedestalsRmsHOref->setAxisTitle("ADC counts",1);
00347   PedestalsRmsHFref->setAxisTitle("ADC counts",1);
00348 
00349   ReferenceRun="UNKNOWN";
00350   LoadReference();
00351   dbe_->setCurrentFolder(subdir_);
00352   RefRun_= dbe_->bookString("HcalDetDiagLaserMonitor Reference Run",ReferenceRun);
00353 
00354   dbe_->setCurrentFolder(subdir_+"Plots for client");
00355   ProblemCellsByDepth_missing_val = new EtaPhiHists();
00356   ProblemCellsByDepth_missing_val->setup(dbe_," Missing channels");
00357   ProblemCellsByDepth_unstable_val = new EtaPhiHists();
00358   ProblemCellsByDepth_unstable_val->setup(dbe_," Channel instability value");
00359   ProblemCellsByDepth_badped_val = new EtaPhiHists();
00360   ProblemCellsByDepth_badped_val->setup(dbe_," Bad Pedestal-Ref Value");
00361   ProblemCellsByDepth_badrms_val = new EtaPhiHists();
00362   ProblemCellsByDepth_badrms_val->setup(dbe_," Bad Rms-ref Value");
00363 }
00364 
00365 
00366 
00367 void HcalDetDiagPedestalMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00368   HcalBaseDQMonitor::analyze(iEvent, iSetup); // increments counters
00369 int  eta,phi,depth,nTS;
00370 static bool PEDseq;
00371 static int  lastPEDorbit,nChecksPED;
00372    if(ievt_==-1){ ievt_=0; PEDseq=false; lastPEDorbit=-1;nChecksPED=0; }
00373    int orbit=iEvent.orbitNumber();
00374    meRUN_->Fill(iEvent.id().run());
00375 
00376    bool PedestalEvent=false;
00377 
00378    // for local runs 
00379    edm::Handle<HcalTBTriggerData> trigger_data;
00380    iEvent.getByType(trigger_data);
00381    if(trigger_data.isValid()){
00382        if(trigger_data->triggerWord()==5) PedestalEvent=true;
00383        LocalRun=true;
00384    }
00385    if(LocalRun && !PedestalEvent) return; 
00386 
00387 
00388   if(!LocalRun && Online_){
00389       if(PEDseq && (orbit-lastPEDorbit)>(11223*10) && ievt_>500){
00390          PEDseq=false;
00391          fillHistos();
00392          CheckStatus();
00393          nChecksPED++;
00394          if(nChecksPED==1 || (nChecksPED>1 && ((nChecksPED-1)%12)==0)){
00395              SaveReference();
00396          }
00397          for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++)for(int l=0;l<4;l++) hb_data[i][j][k][l].reset();
00398          for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++)for(int l=0;l<4;l++) he_data[i][j][k][l].reset();
00399          for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++)for(int l=0;l<4;l++) ho_data[i][j][k][l].reset();
00400          for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++)for(int l=0;l<4;l++) hf_data[i][j][k][l].reset();
00401          ievt_=0;
00402       }
00403    }
00404 
00405   
00406    // Abort Gap pedestals 
00407    int calibType = -1 ;
00408    if(LocalRun==false){
00409        edm::Handle<FEDRawDataCollection> rawdata;
00410        iEvent.getByLabel(inputLabelRawData_,rawdata);
00411        //checking FEDs for calibration information
00412        for (int i=FEDNumbering::MINHCALFEDID;i<=FEDNumbering::MAXHCALFEDID; i++){
00413          const FEDRawData& fedData = rawdata->FEDData(i) ;
00414          if ( fedData.size() < 24 ) continue ;
00415          int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
00416          if ( calibType < 0 )  calibType = value ;
00417          if(value==hc_Pedestal){   PEDseq=true;  lastPEDorbit=orbit; break;} 
00418        }
00419    }
00420    if(!LocalRun && calibType!=hc_Pedestal) return; 
00421 
00422    ievt_++;
00423    meEVT_->Fill(ievt_);
00424    run_number=iEvent.id().run();
00425 
00426    edm::Handle<HBHEDigiCollection> hbhe; 
00427    iEvent.getByLabel(inputLabelDigi_,hbhe);
00428    if(hbhe.isValid()){
00429          if(hbhe->size()<30 && calibType==hc_Pedestal){
00430              ievt_--;
00431              meEVT_->Fill(ievt_);
00432              return;     
00433          }
00434          for(HBHEDigiCollection::const_iterator digi=hbhe->begin();digi!=hbhe->end();digi++){
00435              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00436              if(nTS>8) nTS=8;
00437              if(nTS<8) continue;
00438              if(digi->id().subdet()==HcalBarrel){
00439                 for(int i=0;i<nTS;i++) hb_data[eta+42][phi-1][depth-1][digi->sample(i).capid()].add_statistics(digi->sample(i).adc());
00440              }   
00441              if(digi->id().subdet()==HcalEndcap){
00442                 for(int i=0;i<nTS;i++) he_data[eta+42][phi-1][depth-1][digi->sample(i).capid()].add_statistics(digi->sample(i).adc());
00443              }
00444          }   
00445    }
00446    edm::Handle<HODigiCollection> ho; 
00447    iEvent.getByLabel(inputLabelDigi_,ho);
00448    if(ho.isValid()){
00449          for(HODigiCollection::const_iterator digi=ho->begin();digi!=ho->end();digi++){
00450              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00451              if(nTS>8) nTS=8;
00452              if(nTS<8) continue;
00453              for(int i=0;i<nTS;i++) ho_data[eta+42][phi-1][depth-1][digi->sample(i).capid()].add_statistics(digi->sample(i).adc());
00454          }   
00455    }
00456    edm::Handle<HFDigiCollection> hf;
00457    iEvent.getByLabel(inputLabelDigi_,hf);
00458    if(hf.isValid()){
00459          for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00460              eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00461              if(nTS>8) nTS=8;
00462              if(nTS<8) continue;
00463              for(int i=0;i<nTS;i++) hf_data[eta+42][phi-1][depth-1][digi->sample(i).capid()].add_statistics(digi->sample(i).adc());
00464          }   
00465    }
00466 }
00467 
00468 void HcalDetDiagPedestalMonitor::fillHistos(){
00469    PedestalsRmsHB->Reset();
00470    PedestalsAve4HB->Reset();
00471    PedestalsRmsHE->Reset();
00472    PedestalsAve4HE->Reset();
00473    PedestalsRmsHO->Reset();
00474    PedestalsAve4HO->Reset();
00475    PedestalsRmsHF->Reset();
00476    PedestalsAve4HF->Reset();
00477    PedestalsRmsSimp->Reset();
00478    PedestalsAve4Simp->Reset();
00479    Pedestals2DRmsHBHEHF->Reset();
00480    Pedestals2DRmsHO->Reset();
00481    Pedestals2DHBHEHF->Reset();
00482    Pedestals2DHO->Reset();
00483    // HBHEHF summary map
00484    for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){ 
00485       double PED=0,RMS=0,nped=0,nrms=0,ave=0,rms=0;
00486       for(int depth=1;depth<=3;depth++){
00487          if(hb_data[eta+42][phi-1][depth-1][0].get_statistics()>100){
00488             hb_data[eta+42][phi-1][depth-1][0].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++;
00489             hb_data[eta+42][phi-1][depth-1][1].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00490             hb_data[eta+42][phi-1][depth-1][2].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00491             hb_data[eta+42][phi-1][depth-1][3].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00492          }
00493          if(he_data[eta+42][phi-1][depth-1][0].get_statistics()>100){
00494             he_data[eta+42][phi-1][depth-1][0].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++;
00495             he_data[eta+42][phi-1][depth-1][1].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00496             he_data[eta+42][phi-1][depth-1][2].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00497             he_data[eta+42][phi-1][depth-1][3].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00498          }
00499          if(hf_data[eta+42][phi-1][depth-1][0].get_statistics()>100){
00500             hf_data[eta+42][phi-1][depth-1][0].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++;
00501             hf_data[eta+42][phi-1][depth-1][1].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00502             hf_data[eta+42][phi-1][depth-1][2].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00503             hf_data[eta+42][phi-1][depth-1][3].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00504          }
00505       }
00506       if(nped>0) Pedestals2DHBHEHF->Fill(eta,phi,PED/nped);
00507       if(nrms>0) Pedestals2DRmsHBHEHF->Fill(eta,phi,RMS/nrms); 
00508       if(nped>0 && abs(eta)>20) Pedestals2DHBHEHF->Fill(eta,phi+1,PED/nped);
00509       if(nrms>0 && abs(eta)>20) Pedestals2DRmsHBHEHF->Fill(eta,phi+1,RMS/nrms); 
00510    }
00511    // HO summary map
00512    for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){ 
00513       double PED=0,RMS=0,nped=0,nrms=0,ave,rms;
00514       if(ho_data[eta+42][phi-1][4-1][0].get_statistics()>100){
00515          ho_data[eta+42][phi-1][4-1][0].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++;
00516          ho_data[eta+42][phi-1][4-1][1].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00517          ho_data[eta+42][phi-1][4-1][2].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00518          ho_data[eta+42][phi-1][4-1][3].get_average(&ave,&rms); PED+=ave; nped++; RMS+=rms; nrms++; 
00519       }
00520       if(nped>0) Pedestals2DHO->Fill(eta,phi,PED/nped);
00521       if(nrms>0) Pedestals2DRmsHO->Fill(eta,phi,RMS/nrms); 
00522    }
00523    // HB histograms
00524    for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
00525       if(hb_data[eta+42][phi-1][depth-1][0].get_statistics()>100){
00526           double ave,rms,sum=0;
00527           hb_data[eta+42][phi-1][depth-1][0].get_average(&ave,&rms); sum+=ave; PedestalsRmsHB->Fill(rms);
00528           hb_data[eta+42][phi-1][depth-1][1].get_average(&ave,&rms); sum+=ave; PedestalsRmsHB->Fill(rms);
00529           hb_data[eta+42][phi-1][depth-1][2].get_average(&ave,&rms); sum+=ave; PedestalsRmsHB->Fill(rms);
00530           hb_data[eta+42][phi-1][depth-1][3].get_average(&ave,&rms); sum+=ave; PedestalsRmsHB->Fill(rms);
00531           PedestalsAve4HB->Fill(sum/4.0);
00532       }
00533    } 
00534    // HE histograms
00535    for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=3;depth++){
00536       if(he_data[eta+42][phi-1][depth-1][0].get_statistics()>100){
00537           double ave=0,rms=0,sum=0;
00538           he_data[eta+42][phi-1][depth-1][0].get_average(&ave,&rms); sum+=ave; PedestalsRmsHE->Fill(rms);
00539           he_data[eta+42][phi-1][depth-1][1].get_average(&ave,&rms); sum+=ave; PedestalsRmsHE->Fill(rms);
00540           he_data[eta+42][phi-1][depth-1][2].get_average(&ave,&rms); sum+=ave; PedestalsRmsHE->Fill(rms);
00541           he_data[eta+42][phi-1][depth-1][3].get_average(&ave,&rms); sum+=ave; PedestalsRmsHE->Fill(rms);
00542           PedestalsAve4HE->Fill(sum/4.0);
00543       }
00544    } 
00545    // HO histograms
00546    for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++) for(int depth=4;depth<=4;depth++){
00547       if(ho_data[eta+42][phi-1][depth-1][0].get_statistics()>100){
00548           double ave,rms,sum=0;
00549           if((eta>=11 && eta<=15 && phi>=59 && phi<=70) || (eta>=5 && eta<=10 && phi>=47 && phi<=58)){
00550              ho_data[eta+42][phi-1][depth-1][0].get_average(&ave,&rms); sum+=ave; PedestalsRmsSimp->Fill(rms);
00551              ho_data[eta+42][phi-1][depth-1][1].get_average(&ave,&rms); sum+=ave; PedestalsRmsSimp->Fill(rms);
00552              ho_data[eta+42][phi-1][depth-1][2].get_average(&ave,&rms); sum+=ave; PedestalsRmsSimp->Fill(rms);
00553              ho_data[eta+42][phi-1][depth-1][3].get_average(&ave,&rms); sum+=ave; PedestalsRmsSimp->Fill(rms);
00554              PedestalsAve4Simp->Fill(sum/4.0);    
00555           }else{
00556              ho_data[eta+42][phi-1][depth-1][0].get_average(&ave,&rms); sum+=ave; PedestalsRmsHO->Fill(rms);
00557              ho_data[eta+42][phi-1][depth-1][1].get_average(&ave,&rms); sum+=ave; PedestalsRmsHO->Fill(rms);
00558              ho_data[eta+42][phi-1][depth-1][2].get_average(&ave,&rms); sum+=ave; PedestalsRmsHO->Fill(rms);
00559              ho_data[eta+42][phi-1][depth-1][3].get_average(&ave,&rms); sum+=ave; PedestalsRmsHO->Fill(rms);
00560              PedestalsAve4HO->Fill(sum/4.0);
00561           }
00562       }
00563    } 
00564    // HF histograms
00565    for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
00566       if(hf_data[eta+42][phi-1][depth-1][0].get_statistics()>100){
00567           double ave,rms,sum=0;
00568           hf_data[eta+42][phi-1][depth-1][0].get_average(&ave,&rms); sum+=ave; PedestalsRmsHF->Fill(rms);
00569           hf_data[eta+42][phi-1][depth-1][1].get_average(&ave,&rms); sum+=ave; PedestalsRmsHF->Fill(rms);
00570           hf_data[eta+42][phi-1][depth-1][2].get_average(&ave,&rms); sum+=ave; PedestalsRmsHF->Fill(rms);
00571           hf_data[eta+42][phi-1][depth-1][3].get_average(&ave,&rms); sum+=ave; PedestalsRmsHF->Fill(rms);
00572           PedestalsAve4HF->Fill(sum/4.0);
00573       }
00574    } 
00575 } 
00576 void HcalDetDiagPedestalMonitor::CheckStatus(){
00577    for(int i=0;i<4;i++){
00578       ProblemCellsByDepth_missing->depth[i]->Reset();
00579       ProblemCellsByDepth_unstable->depth[i]->Reset();
00580       ProblemCellsByDepth_badped->depth[i]->Reset();
00581       ProblemCellsByDepth_badrms->depth[i]->Reset();
00582    }
00583    PedestalsRmsHBref->Reset();
00584    PedestalsAve4HBref->Reset();
00585    PedestalsRmsHEref->Reset();
00586    PedestalsAve4HEref->Reset();
00587    PedestalsRmsHOref->Reset();
00588    PedestalsAve4HOref->Reset();
00589    PedestalsRmsHFref->Reset();
00590    PedestalsAve4HFref->Reset();
00591      
00592    Pedestals2DErrorHBHEHF->Reset();
00593    Pedestals2DErrorHO->Reset();
00594 
00595    if(emap==0) return;
00596    
00597    std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
00598    for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++) {
00599      DetId detid=emap->lookup(*eid);
00600      if (detid.det()!=DetId::Hcal) continue;
00601      HcalGenericDetId gid(emap->lookup(*eid));
00602      if (gid.null()) 
00603        continue;
00604      if (gid.genericSubdet()!=HcalGenericDetId::HcalGenBarrel &&
00605          gid.genericSubdet()!=HcalGenericDetId::HcalGenEndcap  &&
00606          gid.genericSubdet()!=HcalGenericDetId::HcalGenForward &&
00607          gid.genericSubdet()!=HcalGenericDetId::HcalGenOuter)
00608        continue;
00609 
00610      int eta=0,phi=0,depth=0;
00611 
00612      HcalDetId hid(detid);
00613      eta=hid.ieta();
00614      phi=hid.iphi();
00615      depth=hid.depth(); 
00616 
00617      int sd=detid.subdetId();
00618      if(sd==HcalBarrel){
00619           int ovf=hb_data[eta+42][phi-1][depth-1][0].get_overflow();
00620           int stat=hb_data[eta+42][phi-1][depth-1][0].get_statistics()+ovf;
00621           double status=0;
00622           double ped[4],rms[4],ped_ref[4],rms_ref[4]; 
00623           hb_data[eta+42][phi-1][depth-1][0].nChecks++;
00624           if(stat==0){ 
00625               status=1;
00626               int e=CalcEtaBin(sd,eta,depth)+1; 
00627               hb_data[eta+42][phi-1][depth-1][0].nMissing++;
00628               double val=hb_data[eta+42][phi-1][depth-1][0].nMissing/hb_data[eta+42][phi-1][depth-1][0].nChecks;
00629               ProblemCellsByDepth_missing->depth[depth-1]->setBinContent(e,phi,val);
00630               ProblemCellsByDepth_missing_val->depth[depth-1]->setBinContent(e,phi,1);
00631           }
00632           if(status) hb_data[eta+42][phi-1][depth-1][0].change_status(1); 
00633           if(stat>0 && stat!=(ievt_*2)){ status=(double)stat/(double)(ievt_*2); 
00634               if(status<0.995){ 
00635                 int e=CalcEtaBin(sd,eta,depth)+1; 
00636                 hb_data[eta+42][phi-1][depth-1][0].nUnstable++;
00637                 double val=hb_data[eta+42][phi-1][depth-1][0].nUnstable/hb_data[eta+42][phi-1][depth-1][0].nChecks;
00638                 ProblemCellsByDepth_unstable->depth[depth-1]->setBinContent(e,phi,val);
00639                 ProblemCellsByDepth_unstable_val->depth[depth-1]->setBinContent(e,phi,status);
00640                 hb_data[eta+42][phi-1][depth-1][0].change_status(2);
00641               }
00642           }
00643           if(hb_data[eta+42][phi-1][depth-1][0].get_reference(&ped_ref[0],&rms_ref[0]) 
00644                                                          && hb_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0])){
00645              hb_data[eta+42][phi-1][depth-1][1].get_reference(&ped_ref[1],&rms_ref[1]);
00646              hb_data[eta+42][phi-1][depth-1][2].get_reference(&ped_ref[2],&rms_ref[2]);
00647              hb_data[eta+42][phi-1][depth-1][3].get_reference(&ped_ref[3],&rms_ref[3]);
00648              hb_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
00649              hb_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
00650              hb_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
00651              double ave=(ped[0]+ped[1]+ped[2]+ped[3])/4.0; 
00652              double ave_ref=(ped_ref[0]+ped_ref[1]+ped_ref[2]+ped_ref[3])/4.0; 
00653              double deltaPed=ave-ave_ref; PedestalsAve4HBref->Fill(deltaPed); if(deltaPed<0) deltaPed=-deltaPed;
00654              double deltaRms=rms[0]-rms_ref[0]; PedestalsRmsHBref->Fill(deltaRms); if(deltaRms<0) deltaRms=-deltaRms;
00655              for(int i=1;i<4;i++){
00656                 double tmp=rms[i]-rms_ref[i]; PedestalsRmsHBref->Fill(tmp); 
00657                 if(fabs(tmp)>fabs(deltaRms)) deltaRms=tmp;
00658              }
00659              if(deltaPed>HBMeanTreshold){ 
00660                  int e=CalcEtaBin(sd,eta,depth)+1; 
00661                  hb_data[eta+42][phi-1][depth-1][0].nBadPed++;
00662                  double val=hb_data[eta+42][phi-1][depth-1][0].nBadPed/hb_data[eta+42][phi-1][depth-1][0].nChecks;
00663                  ProblemCellsByDepth_badped_val->depth[depth-1]->setBinContent(e,phi,ave-ave_ref);
00664                  ProblemCellsByDepth_badped->depth[depth-1]->setBinContent(e,phi,val);
00665                  Pedestals2DErrorHBHEHF->Fill(eta,phi,1);
00666              }
00667              if(deltaRms>HBRmsTreshold){  
00668                  int e=CalcEtaBin(sd,eta,depth)+1; 
00669                  hb_data[eta+42][phi-1][depth-1][0].nBadRms++;
00670                  double val=hb_data[eta+42][phi-1][depth-1][0].nBadRms/hb_data[eta+42][phi-1][depth-1][0].nChecks;
00671                  ProblemCellsByDepth_badrms->depth[depth-1]->setBinContent(e,phi,val);
00672                  ProblemCellsByDepth_badrms_val->depth[depth-1]->setBinContent(e,phi,deltaRms);
00673                  Pedestals2DErrorHBHEHF->Fill(eta,phi,1);
00674              }
00675           } 
00676       }
00677       if(sd==HcalEndcap){
00678           int ovf=he_data[eta+42][phi-1][depth-1][0].get_overflow();
00679           int stat=he_data[eta+42][phi-1][depth-1][0].get_statistics()+ovf;
00680           double status=0; 
00681           double ped[4],rms[4],ped_ref[4],rms_ref[4]; 
00682           he_data[eta+42][phi-1][depth-1][0].nChecks++;
00683           if(stat==0){ 
00684               status=1;
00685               int e=CalcEtaBin(sd,eta,depth)+1; 
00686               he_data[eta+42][phi-1][depth-1][0].nMissing++;
00687               double val=he_data[eta+42][phi-1][depth-1][0].nMissing/he_data[eta+42][phi-1][depth-1][0].nChecks;
00688               ProblemCellsByDepth_missing->depth[depth-1]->setBinContent(e,phi,val);
00689               ProblemCellsByDepth_missing_val->depth[depth-1]->setBinContent(e,phi,1);
00690           }
00691           if(status) he_data[eta+42][phi-1][depth-1][0].change_status(1); 
00692           if(stat>0 && stat!=(ievt_*2)){ status=(double)stat/(double)(ievt_*2);
00693              if(status<0.995){ 
00694                 int e=CalcEtaBin(sd,eta,depth)+1; 
00695                 he_data[eta+42][phi-1][depth-1][0].nUnstable++;
00696                 double val=he_data[eta+42][phi-1][depth-1][0].nUnstable/he_data[eta+42][phi-1][depth-1][0].nChecks;
00697                 ProblemCellsByDepth_unstable->depth[depth-1]->setBinContent(e,phi,val);
00698                 ProblemCellsByDepth_unstable_val->depth[depth-1]->setBinContent(e,phi,status);
00699                 he_data[eta+42][phi-1][depth-1][0].change_status(2); 
00700              }
00701           }
00702           if(he_data[eta+42][phi-1][depth-1][0].get_reference(&ped_ref[0],&rms_ref[0]) 
00703                                                          && he_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0])){
00704              he_data[eta+42][phi-1][depth-1][1].get_reference(&ped_ref[1],&rms_ref[1]);
00705              he_data[eta+42][phi-1][depth-1][2].get_reference(&ped_ref[2],&rms_ref[2]);
00706              he_data[eta+42][phi-1][depth-1][3].get_reference(&ped_ref[3],&rms_ref[3]);
00707              he_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
00708              he_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
00709              he_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
00710              double ave=(ped[0]+ped[1]+ped[2]+ped[3])/4.0; 
00711              double ave_ref=(ped_ref[0]+ped_ref[1]+ped_ref[2]+ped_ref[3])/4.0; 
00712              double deltaPed=ave-ave_ref; PedestalsAve4HEref->Fill(deltaPed); if(deltaPed<0) deltaPed=-deltaPed;
00713              double deltaRms=rms[0]-rms_ref[0]; PedestalsRmsHEref->Fill(deltaRms); if(deltaRms<0) deltaRms=-deltaRms;
00714              for(int i=1;i<4;i++){
00715                 double tmp=rms[i]-rms_ref[i]; PedestalsRmsHEref->Fill(tmp); 
00716                 if(fabs(tmp)>fabs(deltaRms)) deltaRms=tmp;
00717              }
00718              if(deltaPed>HEMeanTreshold){
00719                  int e=CalcEtaBin(sd,eta,depth)+1; 
00720                  he_data[eta+42][phi-1][depth-1][0].nBadPed++;
00721                  double val=he_data[eta+42][phi-1][depth-1][0].nBadPed/he_data[eta+42][phi-1][depth-1][0].nChecks;
00722                  ProblemCellsByDepth_badped->depth[depth-1]->setBinContent(e,phi,val);
00723                  ProblemCellsByDepth_badped_val->depth[depth-1]->setBinContent(e,phi,ave-ave_ref);
00724                  Pedestals2DErrorHBHEHF->Fill(eta,phi,1);
00725              }
00726              if(deltaRms>HERmsTreshold){ 
00727                  int e=CalcEtaBin(sd,eta,depth)+1; 
00728                  he_data[eta+42][phi-1][depth-1][0].nBadRms++;
00729                  double val=he_data[eta+42][phi-1][depth-1][0].nBadRms/he_data[eta+42][phi-1][depth-1][0].nChecks;
00730                  ProblemCellsByDepth_badrms->depth[depth-1]->setBinContent(e,phi,val);
00731                  ProblemCellsByDepth_badrms_val->depth[depth-1]->setBinContent(e,phi,deltaRms);
00732                  Pedestals2DErrorHBHEHF->Fill(eta,phi,1);
00733              }
00734           } 
00735       }
00736       if(sd==HcalOuter){
00737           int ovf=ho_data[eta+42][phi-1][depth-1][0].get_overflow(); 
00738           int stat=ho_data[eta+42][phi-1][depth-1][0].get_statistics()+ovf;
00739           double status=0; 
00740           double ped[4],rms[4],ped_ref[4],rms_ref[4]; 
00741           ho_data[eta+42][phi-1][depth-1][0].nChecks++;
00742           if(stat==0){ 
00743               status=1; 
00744               int e=CalcEtaBin(sd,eta,depth)+1; 
00745               ho_data[eta+42][phi-1][depth-1][0].nMissing++;
00746               double val=ho_data[eta+42][phi-1][depth-1][0].nMissing/ho_data[eta+42][phi-1][depth-1][0].nChecks;
00747               ProblemCellsByDepth_missing->depth[depth-1]->setBinContent(e,phi,val);
00748               ProblemCellsByDepth_missing_val->depth[depth-1]->setBinContent(e,phi,1);
00749           }
00750           if(status) ho_data[eta+42][phi-1][depth-1][0].change_status(1); 
00751           if(stat>0 && stat!=(ievt_*2)){ status=(double)stat/(double)(ievt_*2); 
00752              if(status<0.995){ 
00753                 int e=CalcEtaBin(sd,eta,depth)+1; 
00754                 ho_data[eta+42][phi-1][depth-1][0].nUnstable++;
00755                 double val=ho_data[eta+42][phi-1][depth-1][0].nUnstable/ho_data[eta+42][phi-1][depth-1][0].nChecks;
00756                 ProblemCellsByDepth_unstable->depth[depth-1]->setBinContent(e,phi,val);
00757                 ProblemCellsByDepth_unstable_val->depth[depth-1]->setBinContent(e,phi,status);
00758                 ho_data[eta+42][phi-1][depth-1][0].change_status(2); 
00759              }
00760           }
00761           if(ho_data[eta+42][phi-1][depth-1][0].get_reference(&ped_ref[0],&rms_ref[0]) 
00762                                                          && ho_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0])){
00763              ho_data[eta+42][phi-1][depth-1][1].get_reference(&ped_ref[1],&rms_ref[1]);
00764              ho_data[eta+42][phi-1][depth-1][2].get_reference(&ped_ref[2],&rms_ref[2]);
00765              ho_data[eta+42][phi-1][depth-1][3].get_reference(&ped_ref[3],&rms_ref[3]);
00766              ho_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
00767              ho_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
00768              ho_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
00769              
00770              double THRESTHOLD=HORmsTreshold;
00771              if((eta>=11 && eta<=15 && phi>=59 && phi<=70) || (eta>=5 && eta<=10 && phi>=47 && phi<=58))THRESTHOLD*=2; 
00772              double ave=(ped[0]+ped[1]+ped[2]+ped[3])/4.0; 
00773              double ave_ref=(ped_ref[0]+ped_ref[1]+ped_ref[2]+ped_ref[3])/4.0; 
00774              double deltaPed=ave-ave_ref; PedestalsAve4HOref->Fill(deltaPed);if(deltaPed<0) deltaPed=-deltaPed;
00775              double deltaRms=rms[0]-rms_ref[0]; PedestalsRmsHOref->Fill(deltaRms); if(deltaRms<0) deltaRms=-deltaRms;
00776              for(int i=1;i<4;i++){
00777                 double tmp=rms[i]-rms_ref[i]; PedestalsRmsHOref->Fill(tmp); 
00778                 if(fabs(tmp)>fabs(deltaRms)) deltaRms=tmp;
00779              }
00780              if(deltaPed>HOMeanTreshold){ 
00781                  int e=CalcEtaBin(sd,eta,depth)+1; 
00782                  ho_data[eta+42][phi-1][depth-1][0].nBadPed++;
00783                  double val=ho_data[eta+42][phi-1][depth-1][0].nBadPed/ho_data[eta+42][phi-1][depth-1][0].nChecks;
00784                  ProblemCellsByDepth_badped->depth[depth-1]->setBinContent(e,phi,val);
00785                  ProblemCellsByDepth_badped_val->depth[depth-1]->setBinContent(e,phi,ave-ave_ref);
00786                  Pedestals2DErrorHO->Fill(eta,phi,1);
00787              }
00788              if(deltaRms>THRESTHOLD){ 
00789                  int e=CalcEtaBin(sd,eta,depth)+1; 
00790                  ho_data[eta+42][phi-1][depth-1][0].nBadRms++;
00791                  double val=ho_data[eta+42][phi-1][depth-1][0].nBadRms/ho_data[eta+42][phi-1][depth-1][0].nChecks;
00792                  ProblemCellsByDepth_badrms->depth[depth-1]->setBinContent(e,phi,val);
00793                  ProblemCellsByDepth_badrms_val->depth[depth-1]->setBinContent(e,phi,deltaRms);
00794                  Pedestals2DErrorHO->Fill(eta,phi,1);
00795              }
00796           } 
00797       }
00798       if(sd==HcalForward){
00799           int ovf=hf_data[eta+42][phi-1][depth-1][0].get_overflow();
00800           int stat=hf_data[eta+42][phi-1][depth-1][0].get_statistics()+ovf;
00801           double status=0; 
00802           double ped[4],rms[4],ped_ref[4],rms_ref[4]; 
00803           hf_data[eta+42][phi-1][depth-1][0].nChecks++;
00804           if(stat==0){ 
00805              status=1;                    
00806              int e=CalcEtaBin(sd,eta,depth)+1; 
00807              hf_data[eta+42][phi-1][depth-1][0].nMissing++;
00808              double val=hf_data[eta+42][phi-1][depth-1][0].nMissing/hf_data[eta+42][phi-1][depth-1][0].nChecks;
00809              ProblemCellsByDepth_missing->depth[depth-1]->setBinContent(e,phi,val);
00810              ProblemCellsByDepth_missing_val->depth[depth-1]->setBinContent(e,phi,1);
00811           }
00812           if(status) hf_data[eta+42][phi-1][depth-1][0].change_status(1); 
00813           if(stat>0 && stat!=(ievt_*2)){ status=(double)stat/(double)(ievt_*2); 
00814              if(status<0.995){ 
00815                 int e=CalcEtaBin(sd,eta,depth)+1; 
00816                 hf_data[eta+42][phi-1][depth-1][0].nUnstable++;
00817                 double val=hf_data[eta+42][phi-1][depth-1][0].nUnstable/hf_data[eta+42][phi-1][depth-1][0].nChecks;
00818                 ProblemCellsByDepth_unstable->depth[depth-1]->setBinContent(e,phi,val);
00819                 ProblemCellsByDepth_unstable_val->depth[depth-1]->setBinContent(e,phi,status);
00820                 hf_data[eta+42][phi-1][depth-1][0].change_status(2); 
00821              }
00822           }
00823           if(hf_data[eta+42][phi-1][depth-1][0].get_reference(&ped_ref[0],&rms_ref[0]) 
00824                                                          && hf_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0])){
00825              hf_data[eta+42][phi-1][depth-1][1].get_reference(&ped_ref[1],&rms_ref[1]);
00826              hf_data[eta+42][phi-1][depth-1][2].get_reference(&ped_ref[2],&rms_ref[2]);
00827              hf_data[eta+42][phi-1][depth-1][3].get_reference(&ped_ref[3],&rms_ref[3]);
00828              hf_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
00829              hf_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
00830              hf_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
00831              double ave=(ped[0]+ped[1]+ped[2]+ped[3])/4.0; 
00832              double ave_ref=(ped_ref[0]+ped_ref[1]+ped_ref[2]+ped_ref[3])/4.0; 
00833              double deltaPed=ave-ave_ref; PedestalsAve4HFref->Fill(deltaPed); if(deltaPed<0) deltaPed=-deltaPed;
00834              double deltaRms=rms[0]-rms_ref[0]; PedestalsRmsHFref->Fill(deltaRms); if(deltaRms<0) deltaRms=-deltaRms;
00835              for(int i=1;i<4;i++){
00836                 double tmp=rms[i]-rms_ref[i]; PedestalsRmsHFref->Fill(tmp); 
00837                 if(fabs(tmp)>fabs(deltaRms)) deltaRms=tmp;
00838              }
00839              if(deltaPed>HFMeanTreshold){ 
00840                  int e=CalcEtaBin(sd,eta,depth)+1; 
00841                  hf_data[eta+42][phi-1][depth-1][0].nBadPed++;
00842                  double val=hf_data[eta+42][phi-1][depth-1][0].nBadPed/hf_data[eta+42][phi-1][depth-1][0].nChecks;
00843                  ProblemCellsByDepth_badped->depth[depth-1]->setBinContent(e,phi,val);
00844                  ProblemCellsByDepth_badped_val->depth[depth-1]->setBinContent(e,phi,ave-ave_ref);
00845                  Pedestals2DErrorHBHEHF->Fill(eta,phi,1);
00846              }
00847              if(deltaRms>HFRmsTreshold){ 
00848                  int e=CalcEtaBin(sd,eta,depth)+1; 
00849                  hf_data[eta+42][phi-1][depth-1][0].nBadRms++;
00850                  double val=hf_data[eta+42][phi-1][depth-1][0].nBadRms/hf_data[eta+42][phi-1][depth-1][0].nChecks;
00851                  ProblemCellsByDepth_badrms->depth[depth-1]->setBinContent(e,phi,val);
00852                  ProblemCellsByDepth_badrms_val->depth[depth-1]->setBinContent(e,phi,deltaRms);
00853                  Pedestals2DErrorHBHEHF->Fill(eta,phi,1);
00854              }
00855           } 
00856       }
00857    }
00858 }
00859 
00860 void HcalDetDiagPedestalMonitor::endRun(const edm::Run& run, const edm::EventSetup& c){
00861     if((LocalRun || !Online_) && ievt_>=100){
00862        fillHistos();
00863        CheckStatus();
00864        SaveReference();
00865     }
00866 }
00867 
00868 void HcalDetDiagPedestalMonitor::SaveReference(){
00869 double ped[4],rms[4];
00870 int    Eta,Phi,Depth,Statistic,Status=0;
00871 char   Subdet[10],str[500];
00872    if(OutputFilePath.size()>0){
00873        if(!Overwrite){
00874           sprintf(str,"%sHcalDetDiagPedestalData_run%06i_%i.root",OutputFilePath.c_str(),run_number,dataset_seq_number);
00875        }else{
00876           sprintf(str,"%sHcalDetDiagPedestalData.root",OutputFilePath.c_str());
00877        }
00878        TFile *theFile = new TFile(str, "RECREATE");
00879        if(!theFile->IsOpen()) return;
00880        theFile->cd();
00881        sprintf(str,"%d",run_number);              TObjString run(str);    run.Write("run number");
00882        sprintf(str,"%d",ievt_);                   TObjString events(str); events.Write("Total events processed");
00883        sprintf(str,"%d",dataset_seq_number);      TObjString dsnum(str);  dsnum.Write("Dataset number");
00884        Long_t t; t=time(0); strftime(str,30,"%F %T",localtime(&t)); TObjString tm(str);  tm.Write("Dataset creation time");
00885 
00886        TTree *tree   =new TTree("HCAL Pedestal data","HCAL Pedestal data");
00887        if(tree==0)   return;
00888        tree->Branch("Subdet",   &Subdet,         "Subdet/C");
00889        tree->Branch("eta",      &Eta,            "Eta/I");
00890        tree->Branch("phi",      &Phi,            "Phi/I");
00891        tree->Branch("depth",    &Depth,          "Depth/I");
00892        tree->Branch("statistic",&Statistic,      "Statistic/I");
00893        tree->Branch("status",   &Status,         "Status/I");
00894        tree->Branch("cap0_ped", &ped[0],         "cap0_ped/D");
00895        tree->Branch("cap0_rms", &rms[0],         "cap0_rms/D");
00896        tree->Branch("cap1_ped", &ped[1],         "cap1_ped/D");
00897        tree->Branch("cap1_rms", &rms[1],         "cap1_rms/D");
00898        tree->Branch("cap2_ped", &ped[2],         "cap2_ped/D");
00899        tree->Branch("cap2_rms", &rms[2],         "cap2_rms/D");
00900        tree->Branch("cap3_ped", &ped[3],         "cap3_ped/D");
00901        tree->Branch("cap3_rms", &rms[3],         "cap3_rms/D");
00902        sprintf(Subdet,"HB");
00903        for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
00904           if((Statistic=hb_data[eta+42][phi-1][depth-1][0].get_statistics())>100){
00905              Eta=eta; Phi=phi; Depth=depth;
00906              Status=hb_data[eta+42][phi-1][depth-1][0].get_status();
00907              hb_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0]);
00908              hb_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
00909              hb_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
00910              hb_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
00911              tree->Fill();
00912           }
00913        } 
00914        sprintf(Subdet,"HE");
00915        for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=3;depth++){
00916          if((Statistic=he_data[eta+42][phi-1][depth-1][0].get_statistics())>100){
00917             Eta=eta; Phi=phi; Depth=depth;
00918             Status=he_data[eta+42][phi-1][depth-1][0].get_status();
00919             he_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0]);
00920             he_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
00921             he_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
00922             he_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
00923             tree->Fill();
00924          }
00925       } 
00926       sprintf(Subdet,"HO");
00927       for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++) for(int depth=4;depth<=4;depth++){
00928          if((Statistic=ho_data[eta+42][phi-1][depth-1][0].get_statistics())>100){
00929              Eta=eta; Phi=phi; Depth=depth;
00930              Status=ho_data[eta+42][phi-1][depth-1][0].get_status();
00931              ho_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0]);
00932              ho_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
00933              ho_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
00934              ho_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
00935              tree->Fill();
00936          }
00937       } 
00938       sprintf(Subdet,"HF");
00939       for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
00940          if((Statistic=hf_data[eta+42][phi-1][depth-1][0].get_statistics())>100){
00941              Eta=eta; Phi=phi; Depth=depth;
00942              Status=hf_data[eta+42][phi-1][depth-1][0].get_status();
00943              hf_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0]);
00944              hf_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
00945              hf_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
00946              hf_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
00947              tree->Fill();
00948          }
00949       }
00950       theFile->Write();
00951       theFile->Close();
00952    }
00953    if(XmlFilePath.size()>0){
00954       //create XML file
00955       if(!Overwrite){
00956          sprintf(str,"HcalDetDiagPedestals_%i_%i.xml",run_number,dataset_seq_number);
00957       }else{
00958          sprintf(str,"HcalDetDiagPedestals.xml");
00959       }
00960       std::string xmlName=str;
00961       ofstream xmlFile;
00962       xmlFile.open(xmlName.c_str());
00963 
00964       xmlFile<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
00965       xmlFile<<"<ROOT>\n";
00966       xmlFile<<"  <HEADER>\n";
00967       xmlFile<<"    <HINTS mode='only-det-root'/>\n";
00968       xmlFile<<"    <TYPE>\n";
00969       xmlFile<<"      <EXTENSION_TABLE_NAME>HCAL_DETMON_PEDESTALS_V1</EXTENSION_TABLE_NAME>\n";
00970       xmlFile<<"      <NAME>HCAL Pedestals [abort gap global]</NAME>\n";
00971       xmlFile<<"    </TYPE>\n";
00972       xmlFile<<"    <!-- run details -->\n";
00973       xmlFile<<"    <RUN>\n";
00974       xmlFile<<"      <RUN_TYPE>GLOBAL-RUN</RUN_TYPE>\n";
00975       xmlFile<<"      <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
00976       xmlFile<<"      <RUN_BEGIN_TIMESTAMP>2009-01-01 00:00:00</RUN_BEGIN_TIMESTAMP>\n";
00977       xmlFile<<"      <COMMENT_DESCRIPTION>hcal ped data</COMMENT_DESCRIPTION>\n";
00978       xmlFile<<"      <LOCATION>P5</LOCATION>\n";
00979       xmlFile<<"      <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
00980       xmlFile<<"    </RUN>\n";
00981       xmlFile<<"  </HEADER>\n";
00982       xmlFile<<"  <DATA_SET>\n";
00983       xmlFile<<"     <!-- optional dataset metadata -->\n\n";
00984       xmlFile<<"     <SET_NUMBER>"<<dataset_seq_number<<"</SET_NUMBER>\n";
00985       xmlFile<<"     <SET_BEGIN_TIMESTAMP>2009-01-01 00:00:00</SET_BEGIN_TIMESTAMP>\n";
00986       xmlFile<<"     <SET_END_TIMESTAMP>2009-01-01 00:00:00</SET_END_TIMESTAMP>\n";
00987       xmlFile<<"     <NUMBER_OF_EVENTS_IN_SET>"<<ievt_<<"</NUMBER_OF_EVENTS_IN_SET>\n";
00988       xmlFile<<"     <COMMENT_DESCRIPTION>Automatic DQM output</COMMENT_DESCRIPTION>\n";
00989       xmlFile<<"     <DATA_FILE_NAME>"<< xmlName <<"</DATA_FILE_NAME>\n";
00990       xmlFile<<"     <IMAGE_FILE_NAME>data plot url or file path</IMAGE_FILE_NAME>\n";
00991       xmlFile<<"     <!-- who and when created this dataset-->\n\n";
00992       Long_t t; t=time(0); strftime(str,30,"%F %T",localtime(&t));
00993       xmlFile<<"     <CREATE_TIMESTAMP>"<<str<<"</CREATE_TIMESTAMP>\n";
00994       xmlFile<<"     <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
00995       xmlFile<<"     <!-- version (string) and subversion (number) -->\n";
00996       xmlFile<<"     <!-- fields are used to read data back from the database -->\n\n";
00997       xmlFile<<"     <VERSION>"<<run_number<<dataset_seq_number<<"</VERSION>\n";
00998       xmlFile<<"     <SUBVERSION>1</SUBVERSION>\n";
00999       xmlFile<<"     <!--  Assign predefined dataset attributes -->\n\n";
01000       xmlFile<<"     <PREDEFINED_ATTRIBUTES>\n";
01001       xmlFile<<"        <ATTRIBUTE>\n";
01002       xmlFile<<"           <NAME>HCAL Dataset Status</NAME>\n";
01003       xmlFile<<"           <VALUE>VALID</VALUE>\n";
01004       xmlFile<<"        </ATTRIBUTE>\n";
01005       xmlFile<<"     </PREDEFINED_ATTRIBUTES>\n";
01006       xmlFile<<"     <!-- multiple data block records -->\n\n";
01007 
01008       std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
01009       for(std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
01010          DetId detid=emap->lookup(*eid);
01011          if (detid.det()!=DetId::Hcal) continue;
01012          HcalGenericDetId gid(emap->lookup(*eid));
01013          if (gid.null()) 
01014            continue;
01015          if (gid.genericSubdet()!=HcalGenericDetId::HcalGenBarrel &&
01016              gid.genericSubdet()!=HcalGenericDetId::HcalGenEndcap  &&
01017              gid.genericSubdet()!=HcalGenericDetId::HcalGenForward &&
01018              gid.genericSubdet()!=HcalGenericDetId::HcalGenOuter)
01019            continue;
01020 
01021          int eta,phi,depth; 
01022          std::string subdet="";
01023          HcalDetId hid(detid);
01024          eta=hid.ieta();
01025          phi=hid.iphi();
01026          depth=hid.depth(); 
01027       
01028          double ped[4]={0,0,0,0},rms[4]={0,0,0,0};
01029          if(detid.subdetId()==HcalBarrel){
01030              subdet="HB";
01031              Statistic=hb_data[eta+42][phi-1][depth-1][0].get_statistics();
01032              Status   =hb_data[eta+42][phi-1][depth-1][0].get_status();
01033              hb_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0]);
01034              hb_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
01035              hb_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
01036              hb_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
01037          }else if(detid.subdetId()==HcalEndcap){
01038              subdet="HE";
01039              he_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0]);
01040              he_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
01041              he_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
01042              he_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
01043              Statistic=he_data[eta+42][phi-1][depth-1][0].get_statistics();
01044              Status   =he_data[eta+42][phi-1][depth-1][0].get_status();
01045          }else if(detid.subdetId()==HcalForward){
01046              subdet="HF";
01047              hf_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0]);
01048              hf_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
01049              hf_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
01050              hf_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
01051              Statistic=hf_data[eta+42][phi-1][depth-1][0].get_statistics();
01052              Status   =hf_data[eta+42][phi-1][depth-1][0].get_status();
01053          }else if(detid.subdetId()==HcalOuter){
01054              subdet="HO";
01055              ho_data[eta+42][phi-1][depth-1][0].get_average(&ped[0],&rms[0]);
01056              ho_data[eta+42][phi-1][depth-1][1].get_average(&ped[1],&rms[1]);
01057              ho_data[eta+42][phi-1][depth-1][2].get_average(&ped[2],&rms[2]);
01058              ho_data[eta+42][phi-1][depth-1][3].get_average(&ped[3],&rms[3]);
01059              Statistic=ho_data[eta+42][phi-1][depth-1][0].get_statistics();
01060              Status   =ho_data[eta+42][phi-1][depth-1][0].get_status();
01061          }else continue;
01062          xmlFile<<"       <DATA>\n";
01063          xmlFile<<"          <NUMBER_OF_EVENTS_USED>"<<Statistic<<"</NUMBER_OF_EVENTS_USED>\n";
01064          xmlFile<<"          <MEAN0>"<<ped[0]<<"</MEAN0>\n";
01065          xmlFile<<"          <MEAN1>"<<ped[1]<<"</MEAN1>\n";
01066          xmlFile<<"          <MEAN2>"<<ped[2]<<"</MEAN2>\n";
01067          xmlFile<<"          <MEAN3>"<<ped[3]<<"</MEAN3>\n";
01068          xmlFile<<"          <RMS0>"<<rms[0]<<"</RMS0>\n";
01069          xmlFile<<"          <RMS1>"<<rms[1]<<"</RMS1>\n";
01070          xmlFile<<"          <RMS2>"<<rms[2]<<"</RMS2>\n";
01071          xmlFile<<"          <RMS3>"<<rms[3]<<"</RMS3>\n";
01072          xmlFile<<"          <CHANNEL_STATUS_WORD>"<<Status<<"</CHANNEL_STATUS_WORD>\n";
01073          xmlFile<<"          <CHANNEL_OBJECTNAME>HcalDetId</CHANNEL_OBJECTNAME>\n";
01074          xmlFile<<"             <SUBDET>"<<subdet<<"</SUBDET>\n";
01075          xmlFile<<"             <IETA>"<<eta<<"</IETA>\n";
01076          xmlFile<<"             <IPHI>"<<phi<<"</IPHI>\n";
01077          xmlFile<<"             <DEPTH>"<<depth<<"</DEPTH>\n";
01078          xmlFile<<"             <TYPE>0</TYPE>\n";
01079          xmlFile<<"       </DATA>\n";
01080       }
01082       xmlFile<<"  </DATA_SET>\n";
01083       xmlFile<<"</ROOT>\n";
01084       xmlFile.close();
01085       sprintf(str,"zip %s.zip %s",xmlName.c_str(),xmlName.c_str());
01086       system(str);
01087       sprintf(str,"rm -f %s",xmlName.c_str());
01088       system(str);
01089       sprintf(str,"mv -f %s.zip %s",xmlName.c_str(),XmlFilePath.c_str());
01090       system(str);
01091    }
01092    dataset_seq_number++;
01093 }
01094 
01095 void HcalDetDiagPedestalMonitor::LoadReference(){
01096   double ped[4],rms[4];
01097   int Eta,Phi,Depth;
01098   char subdet[10];
01099   TFile *f;
01100   if(gSystem->AccessPathName(ReferenceData.c_str())) return;
01101   f = new TFile(ReferenceData.c_str(),"READ");
01102   if(!f->IsOpen()) return ;
01103   TObjString *STR=(TObjString *)f->Get("run number");
01104   
01105   if(STR){ std::string Ref(STR->String()); ReferenceRun=Ref;}
01106   
01107   TTree*  t=(TTree*)f->Get("HCAL Pedestal data");
01108   if(!t) return;
01109   t->SetBranchAddress("Subdet",   subdet);
01110   t->SetBranchAddress("eta",      &Eta);
01111   t->SetBranchAddress("phi",      &Phi);
01112   t->SetBranchAddress("depth",    &Depth);
01113   t->SetBranchAddress("cap0_ped", &ped[0]);
01114   t->SetBranchAddress("cap0_rms", &rms[0]);
01115   t->SetBranchAddress("cap1_ped", &ped[1]);
01116   t->SetBranchAddress("cap1_rms", &rms[1]);
01117   t->SetBranchAddress("cap2_ped", &ped[2]);
01118   t->SetBranchAddress("cap2_rms", &rms[2]);
01119   t->SetBranchAddress("cap3_ped", &ped[3]);
01120   t->SetBranchAddress("cap3_rms", &rms[3]);
01121   for(int ievt=0;ievt<t->GetEntries();ievt++){
01122     t->GetEntry(ievt);
01123     if(strcmp(subdet,"HB")==0){
01124       hb_data[Eta+42][Phi-1][Depth-1][0].set_reference(ped[0],rms[0]);
01125       hb_data[Eta+42][Phi-1][Depth-1][1].set_reference(ped[1],rms[1]);
01126       hb_data[Eta+42][Phi-1][Depth-1][2].set_reference(ped[2],rms[2]);
01127       hb_data[Eta+42][Phi-1][Depth-1][3].set_reference(ped[3],rms[3]);
01128     }
01129     if(strcmp(subdet,"HE")==0){
01130       he_data[Eta+42][Phi-1][Depth-1][0].set_reference(ped[0],rms[0]);
01131       he_data[Eta+42][Phi-1][Depth-1][1].set_reference(ped[1],rms[1]);
01132       he_data[Eta+42][Phi-1][Depth-1][2].set_reference(ped[2],rms[2]);
01133       he_data[Eta+42][Phi-1][Depth-1][3].set_reference(ped[3],rms[3]);
01134     }
01135     if(strcmp(subdet,"HO")==0){
01136       ho_data[Eta+42][Phi-1][Depth-1][0].set_reference(ped[0],rms[0]);
01137       ho_data[Eta+42][Phi-1][Depth-1][1].set_reference(ped[1],rms[1]);
01138       ho_data[Eta+42][Phi-1][Depth-1][2].set_reference(ped[2],rms[2]);
01139       ho_data[Eta+42][Phi-1][Depth-1][3].set_reference(ped[3],rms[3]);
01140     }
01141     if(strcmp(subdet,"HF")==0){
01142       hf_data[Eta+42][Phi-1][Depth-1][0].set_reference(ped[0],rms[0]);
01143       hf_data[Eta+42][Phi-1][Depth-1][1].set_reference(ped[1],rms[1]);
01144       hf_data[Eta+42][Phi-1][Depth-1][2].set_reference(ped[2],rms[2]);
01145       hf_data[Eta+42][Phi-1][Depth-1][3].set_reference(ped[3],rms[3]);
01146     }
01147   }
01148   f->Close();
01149   IsReference=true;
01150 } 
01151 
01152 void HcalDetDiagPedestalMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c){}
01153 void HcalDetDiagPedestalMonitor::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c){}
01154 
01155 //define this as a plug-in
01156 DEFINE_FWK_MODULE(HcalDetDiagPedestalMonitor);