CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DQM/HcalMonitorTasks/src/HcalDetDiagLEDMonitor.cc

Go to the documentation of this file.
00001 #include "DQMServices/Core/interface/MonitorElement.h"
00002 // this is to retrieve HCAL digi's
00003 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00004 // to retrive trigger information (local runs only)
00005 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
00006 // to retrive GMT information, for cosmic runs muon triggers can be used as pedestal (global runs only)
00007 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
00008 // to retrive trigger desition words, to select pedestal (from hcal point of view) triggers (global runs only)
00009 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00010 
00011 #include "CondFormats/HcalObjects/interface/HcalLogicalMap.h"
00012 #include "DQM/HcalMonitorTasks/interface/HcalBaseDQMonitor.h"
00013 #include "DQM/HcalMonitorTasks/interface/HcalEtaPhiHists.h"
00014 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00015 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00016 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
00017 #include "DQM/HcalMonitorTasks/interface/HcalEtaPhiHists.h"
00018 #include "FWCore/Utilities/interface/InputTag.h"
00019 
00020 #include "TFile.h"
00021 #include "TTree.h"
00022 #include "TSystem.h"
00023 #include <math.h>
00024 #include <iostream>
00025 #include <fstream>
00026 
00027 
00028 class HcalDetDiagLEDData{
00029 public: 
00030    HcalDetDiagLEDData(){ 
00031              IsRefetence=false;
00032              status=0;
00033              reset();
00034           }
00035    void   reset(){
00036              Xe=XXe=Xt=XXt=n=0;
00037              overflow=0;
00038              undeflow=0;
00039           }
00040    void   add_statistics(double *data,int nTS){
00041              double e=GetEnergy(data,nTS);
00042              double t=GetTime(data,nTS);
00043              if(e<20) undeflow++; else if(e>10000) overflow++; else{
00044                 n++; Xe+=e; XXe+=e*e; Xt+=t; XXt+=t*t;
00045              }     
00046           }
00047    void   set_reference(float val,float rms){
00048              ref_led=val; ref_rms=rms;
00049              IsRefetence=true;
00050           }       
00051    void   change_status(int val){
00052              status|=val;
00053           }       
00054    int    get_status(){
00055              return status;
00056           }       
00057    bool   get_reference(double *val,double *rms){
00058              *val=ref_led; *rms=ref_rms;
00059              return IsRefetence;
00060           }       
00061    bool   get_average_led(double *ave,double *rms){
00062              if(n>0){ *ave=Xe/n; *rms=sqrt(XXe/n-(Xe*Xe)/(n*n));} else return false;
00063              return true; 
00064           }
00065    bool   get_average_time(double *ave,double *rms){
00066              if(n>0){ *ave=Xt/n; *rms=sqrt(XXt/n-(Xt*Xt)/(n*n));} else return false;
00067              return true; 
00068           }
00069    int    get_statistics(){
00070              return (int)n;
00071           } 
00072    int    get_overflow(){
00073              return overflow;
00074           }   
00075    int    get_undeflow(){
00076              return undeflow;
00077           }   
00078 private:   
00079    double GetEnergy(double *data,int n){
00080              int MaxI=0; double Energy,MaxE=0;
00081              for(int j=0;j<n;++j) if(MaxE<data[j]){ MaxE=data[j]; MaxI=j; }
00082              Energy=data[MaxI];
00083              if(MaxI>0) Energy+=data[MaxI-1];
00084              if(MaxI>1) Energy+=data[MaxI-2];
00085              if(MaxI<(n-1)) Energy+=data[MaxI+1];
00086              if(MaxI<(n-2)) Energy+=data[MaxI+2];
00087              return Energy;
00088           }
00089    double GetTime(double *data,int n=10){
00090              int MaxI=0; double Time=-9999,SumT=0,MaxT=-10;
00091              for(int j=0;j<n;++j) if(MaxT<data[j]){ MaxT=data[j]; MaxI=j; }
00092              Time=MaxI*data[MaxI];
00093              SumT=data[MaxI];
00094              if(MaxI>0){ Time+=(MaxI-1)*data[MaxI-1]; SumT+=data[MaxI-1]; }
00095              if(MaxI<(n-1)){ Time+=(MaxI+1)*data[MaxI+1]; SumT+=data[MaxI+1]; }
00096              Time=Time/SumT;
00097              return Time;
00098    }      
00099    int   overflow;
00100    int   undeflow;
00101    double Xe,XXe,Xt,XXt,n;
00102    bool  IsRefetence;
00103    float ref_led;
00104    float ref_rms;
00105    int   status;
00106 };
00107 
00108 class HcalDetDiagLEDMonitor:public HcalBaseDQMonitor {
00109 public:
00110   HcalDetDiagLEDMonitor(const edm::ParameterSet& ps); 
00111   ~HcalDetDiagLEDMonitor(); 
00112 
00113   void beginRun(const edm::Run& run, const edm::EventSetup& c);
00114   void setup();
00115   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup);// const HcalDbService& cond)
00116   void endRun(const edm::Run& run, const edm::EventSetup& c);
00117   void reset();
00118   void cleanup(); 
00119   void fillHistos();
00120   int  GetStatistics(){ return ievt_; }
00121 private:
00122   HcalElectronicsMap*      emap;
00123   void SaveReference();
00124   void LoadReference();
00125   void CheckStatus();
00126   
00127   HcalDetDiagLEDData* GetCalib(std::string sd,int eta,int phi){
00128     int SD=0,ETA=0,PHI=0;
00129     if(sd.compare("HB")==0) SD=1; 
00130     if(sd.compare("HE")==0) SD=2; 
00131     if(sd.compare("HO")==0) SD=3; 
00132     if(sd.compare("HF")==0) SD=4; 
00133     if(SD==1 || SD==2){
00134       if(eta>0) ETA=1; else ETA=-1;
00135       if(phi==71 ||phi==72 || phi==1 || phi==2) PHI=71; else PHI=((phi-3)/4)*4+3;
00136     }else if(SD==3){
00137       if(abs(eta)<=4){
00138         ETA=0;
00139         if(phi==71 ||phi==72 || phi==1 || phi==2 || phi==3 || phi==4) PHI=71; else PHI=((phi-5)/6)*6+5;
00140       }else{
00141         if(abs(eta)>4  && abs(eta)<=10)  ETA=1;
00142         if(abs(eta)>10 && abs(eta)<=15)  ETA=2;
00143         if(eta<0) ETA=-ETA;
00144         if(phi==71 ||phi==72 || (phi>=1 && phi<=10)) PHI=71; else PHI=((phi-11)/12)*12+11;
00145       }
00146     }else if(SD==4){
00147       if(eta>0) ETA=1; else ETA=-1;
00148       if(phi>=1  && phi<=18) PHI=1;
00149       if(phi>=19 && phi<=36) PHI=19;
00150       if(phi>=37 && phi<=54) PHI=37;
00151       if(phi>=55 && phi<=72) PHI=55;
00152     }
00153     return &calib_data[SD][ETA+2][PHI-1];
00154   };
00155   int         ievt_;
00156   int         run_number;
00157   int         dataset_seq_number;
00158   bool        IsReference;
00159   
00160   double      LEDMeanTreshold;
00161   double      LEDRmsTreshold;
00162    
00163   std::string ReferenceData;
00164   std::string ReferenceRun;
00165   std::string OutputFilePath;
00166   std::string XmlFilePath;
00167 
00168   MonitorElement *meEVT_,*meRUN_;
00169   MonitorElement *RefRun_;
00170   MonitorElement *Energy;
00171   MonitorElement *Time;
00172   MonitorElement *EnergyHF;
00173   MonitorElement *TimeHF;
00174   MonitorElement *Time2Dhbhehf;
00175   MonitorElement *Time2Dho;
00176   MonitorElement *Energy2Dhbhehf;
00177   MonitorElement *Energy2Dho;
00178   MonitorElement *EnergyRMS;
00179   MonitorElement *TimeRMS;
00180   MonitorElement *EnergyRMSHF;
00181   MonitorElement *TimeRMSHF;
00182   MonitorElement *EnergyCorr;
00183   MonitorElement *HBPphi;
00184   MonitorElement *HBMphi;
00185   MonitorElement *HEPphi;
00186   MonitorElement *HEMphi;
00187   MonitorElement *HFPphi;
00188   MonitorElement *HFMphi;
00189   MonitorElement *HO0phi;
00190   MonitorElement *HO1Pphi;
00191   MonitorElement *HO2Pphi;
00192   MonitorElement *HO1Mphi;
00193   MonitorElement *HO2Mphi;
00194 
00195   HcalDetDiagLEDData hb_data[85][72][4];
00196   HcalDetDiagLEDData he_data[85][72][4];
00197   HcalDetDiagLEDData ho_data[85][72][4];
00198   HcalDetDiagLEDData hf_data[85][72][4];
00199   HcalDetDiagLEDData calib_data[5][5][72];
00200   
00201   EtaPhiHists *ChannelsLEDEnergy;
00202   EtaPhiHists *ChannelsLEDEnergyRef;
00203   EtaPhiHists *ChannelStatusMissingChannels;
00204   EtaPhiHists *ChannelStatusUnstableChannels;
00205   EtaPhiHists *ChannelStatusUnstableLEDsignal;
00206   EtaPhiHists *ChannelStatusLEDMean;
00207   EtaPhiHists *ChannelStatusLEDRMS;
00208   EtaPhiHists *ChannelStatusTimeMean;
00209   EtaPhiHists *ChannelStatusTimeRMS;
00210 
00211   edm::InputTag digiLabel_;
00212   edm::InputTag calibDigiLabel_;
00213   edm::InputTag hcalTBTriggerDataTag_;
00214 
00215   std::map<unsigned int, int> KnownBadCells_;
00216 
00217   void fill_channel_status(std::string subdet,int eta,int phi,int depth,int type,double status);
00218   void   fill_energy(std::string subdet,int eta,int phi,int depth,double e,int type);
00219   double get_energy(std::string subdet,int eta,int phi,int depth,int type);
00220 };
00221 
00223 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,
00224                    13.5,15.,17.,19.,21.,23.,25.,27.,29.5,32.5,35.5,38.5,42.,46.,50.,54.5,59.5,
00225                    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,
00226                    124.5,129.5,137.,147.,157.,167.,177.,187.,197.,209.5,224.5,239.5,254.5,272.,
00227                    292.,312.,334.5,359.5,384.5,359.5,384.5,409.5,434.5,459.5,484.5,509.5,534.5,
00228                    559.5,584.5,609.5,634.5,659.5,684.5,709.5,747.,797.,847.,897.,947.,997.,
00229                    1047.,1109.5,1184.5,1259.5,1334.5,1422.,1522.,1622.,1734.5,1859.5,1984.5,
00230                    1859.5,1984.5,2109.5,2234.5,2359.5,2484.5,2609.5,2734.5,2859.5,2984.5,
00231                    3109.5,3234.5,3359.5,3484.5,3609.5,3797.,4047.,4297.,4547.,4797.,5047.,
00232                    5297.,5609.5,5984.5,6359.5,6734.5,7172.,7672.,8172.,8734.5,9359.5,9984.5};
00234 
00235 
00236 
00237 
00238 HcalDetDiagLEDMonitor::HcalDetDiagLEDMonitor(const edm::ParameterSet& ps) :
00239   hcalTBTriggerDataTag_(ps.getParameter<edm::InputTag>("hcalTBTriggerDataTag"))
00240 {
00241   ievt_=0;
00242   dataset_seq_number=1;
00243   run_number=-1;
00244   IsReference=false;
00245 
00246   Online_                = ps.getUntrackedParameter<bool>("online",false);
00247   mergeRuns_             = ps.getUntrackedParameter<bool>("mergeRuns",false);
00248   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00249   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00250   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00251   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00252     prefixME_.append("/");
00253   subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder","DetDiagLEDMonitor_Hcal");
00254   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00255     subdir_.append("/");
00256   subdir_=prefixME_+subdir_;
00257   AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00258   skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",false);
00259   NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00260   makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00261 
00262   LEDMeanTreshold  = ps.getUntrackedParameter<double>("LEDMeanTreshold" , 0.1);
00263   LEDRmsTreshold   = ps.getUntrackedParameter<double>("LEDRmsTreshold"  , 0.1);
00264   
00265   ReferenceData    = ps.getUntrackedParameter<std::string>("LEDReferenceData" ,"");
00266   OutputFilePath   = ps.getUntrackedParameter<std::string>("OutputFilePath", "");
00267   XmlFilePath      = ps.getUntrackedParameter<std::string>("XmlFilePath", "");
00268 
00269   digiLabel_       = ps.getUntrackedParameter<edm::InputTag>("digiLabel", edm::InputTag("hcalDigis"));
00270   calibDigiLabel_  = ps.getUntrackedParameter<edm::InputTag>("calibDigiLabel",edm::InputTag("hcalDigis"));
00271 
00272   emap=0;
00273   needLogicalMap_ = true;
00274 }
00275 
00276 HcalDetDiagLEDMonitor::~HcalDetDiagLEDMonitor(){}
00277 
00278 void HcalDetDiagLEDMonitor::cleanup(){
00279   if(dbe_){
00280     dbe_->setCurrentFolder(subdir_);
00281     dbe_->removeContents();
00282     dbe_ = 0;
00283   }
00284 } 
00285 void HcalDetDiagLEDMonitor::reset(){}
00286 
00287 void HcalDetDiagLEDMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c)
00288 {
00289   if (debug_>1) std::cout <<"HcalDetDiagLEDMonitor::beginRun"<<std::endl;
00290   HcalBaseDQMonitor::beginRun(run,c);
00291 
00292   if (tevt_==0) this->setup(); // set up histograms if they have not been created before
00293   if (mergeRuns_==false) this->reset();
00294 
00295   edm::ESHandle<HcalChannelQuality> p;
00296   c.get<HcalChannelQualityRcd>().get(p);
00297   HcalChannelQuality* chanquality= new HcalChannelQuality(*p.product());
00298   std::vector<DetId> mydetids = chanquality->getAllChannels();
00299   KnownBadCells_.clear();
00300 
00301   for (std::vector<DetId>::const_iterator i = mydetids.begin();i!=mydetids.end();++i){
00302      if (i->det()!=DetId::Hcal) continue; // not an hcal cell
00303      HcalDetId id=HcalDetId(*i);
00304      int status=(chanquality->getValues(id))->getValue();
00305      if((status & HcalChannelStatus::HcalCellOff) || (status & HcalChannelStatus::HcalCellMask)){
00306          KnownBadCells_[id.rawId()]=status;
00307      }
00308   } 
00309 
00310   return;
00311 } // void HcalNDetDiagLEDMonitor::beginRun(...)
00312 
00313 void HcalDetDiagLEDMonitor::setup(){
00314      // Call base class setup
00315      HcalBaseDQMonitor::setup();
00316      if (!dbe_) return;
00317 
00318      std::string name;
00319      dbe_->setCurrentFolder(subdir_);   
00320      meEVT_ = dbe_->bookInt("HcalDetDiagLEDMonitor Event Number");
00321      meRUN_ = dbe_->bookInt("HcalDetDiagLEDMonitor Run Number");
00322      ReferenceRun="UNKNOWN";
00323      LoadReference();
00324      dbe_->setCurrentFolder(subdir_);
00325      RefRun_= dbe_->bookString("HcalDetDiagLEDMonitor Reference Run",ReferenceRun);
00326      dbe_->setCurrentFolder(subdir_+"Summary Plots");
00327      
00328      name="HBHEHO LED Energy Distribution";               Energy         = dbe_->book1D(name,name,200,0,3000);
00329      name="HBHEHO LED Timing Distribution";               Time           = dbe_->book1D(name,name,200,0,10);
00330      name="HBHEHO LED Energy RMS_div_Energy Distribution";EnergyRMS      = dbe_->book1D(name,name,200,0,0.2);
00331      name="HBHEHO LED Timing RMS Distribution";           TimeRMS        = dbe_->book1D(name,name,200,0,0.4);
00332      name="HF LED Energy Distribution";                   EnergyHF       = dbe_->book1D(name,name,200,0,3000);
00333      name="HF LED Timing Distribution";                   TimeHF         = dbe_->book1D(name,name,200,0,10);
00334      name="HF LED Energy RMS_div_Energy Distribution";    EnergyRMSHF    = dbe_->book1D(name,name,200,0,0.5);
00335      name="HF LED Timing RMS Distribution";               TimeRMSHF      = dbe_->book1D(name,name,200,0,0.4);
00336      name="LED Energy Corr(PinDiod) Distribution";        EnergyCorr     = dbe_->book1D(name,name,200,0,10);
00337      name="LED Timing HBHEHF";                            Time2Dhbhehf   = dbe_->book2D(name,name,87,-43,43,74,0,73);
00338      name="LED Timing HO";                                Time2Dho       = dbe_->book2D(name,name,33,-16,16,74,0,73);
00339      name="LED Energy HBHEHF";                            Energy2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
00340      name="LED Energy HO";                                Energy2Dho     = dbe_->book2D(name,name,33,-16,16,74,0,73);
00341 
00342      name="HBP Average over HPD LED Ref";          HBPphi = dbe_->book2D(name,name,180,1,73,400,0,2);
00343      name="HBM Average over HPD LED Ref";          HBMphi = dbe_->book2D(name,name,180,1,73,400,0,2);
00344      name="HEP Average over HPD LED Ref";          HEPphi = dbe_->book2D(name,name,180,1,73,400,0,2);
00345      name="HEM Average over HPD LED Ref";          HEMphi = dbe_->book2D(name,name,180,1,73,400,0,2);
00346      name="HFP Average over RM LED Ref";           HFPphi = dbe_->book2D(name,name,180,1,37,400,0,2);
00347      name="HFM Average over RM LED Ref";           HFMphi = dbe_->book2D(name,name,180,1,37,400,0,2);
00348      name="HO0 Average over HPD LED Ref";          HO0phi = dbe_->book2D(name,name,180,1,49,400,0,2);
00349      name="HO1P Average over HPD LED Ref";         HO1Pphi= dbe_->book2D(name,name,180,1,49,400,0,2);
00350      name="HO2P Average over HPD LED Ref";         HO2Pphi= dbe_->book2D(name,name,180,1,49,400,0,2);
00351      name="HO1M Average over HPD LED Ref";         HO1Mphi= dbe_->book2D(name,name,180,1,49,400,0,2);
00352      name="HO2M Average over HPD LED Ref";         HO2Mphi= dbe_->book2D(name,name,180,1,49,400,0,2);
00353 
00354      ChannelsLEDEnergy = new EtaPhiHists();
00355      ChannelsLEDEnergy->setup(dbe_," Channel LED Energy");
00356      ChannelsLEDEnergyRef = new EtaPhiHists();
00357      ChannelsLEDEnergyRef->setup(dbe_," Channel LED Energy Reference");
00358      
00359      dbe_->setCurrentFolder(subdir_+"channel status");
00360      ChannelStatusMissingChannels = new EtaPhiHists();
00361      ChannelStatusMissingChannels->setup(dbe_," Missing Channels");
00362      ChannelStatusUnstableChannels = new EtaPhiHists();
00363      ChannelStatusUnstableChannels->setup(dbe_," Unstable Channels");
00364      ChannelStatusUnstableLEDsignal = new EtaPhiHists();
00365      ChannelStatusUnstableLEDsignal->setup(dbe_," Unstable LED");
00366      ChannelStatusLEDMean = new EtaPhiHists();
00367      ChannelStatusLEDMean->setup(dbe_," LED Mean");
00368      ChannelStatusLEDRMS = new EtaPhiHists();
00369      ChannelStatusLEDRMS->setup(dbe_," LED RMS");
00370      ChannelStatusTimeMean = new EtaPhiHists();
00371      ChannelStatusTimeMean->setup(dbe_," Time Mean");
00372      ChannelStatusTimeRMS = new EtaPhiHists();
00373      ChannelStatusTimeRMS->setup(dbe_," Time RMS");
00374 
00375      
00376 } 
00377 
00378 void HcalDetDiagLEDMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00379 int  eta,phi,depth,nTS;
00380    HcalBaseDQMonitor::getLogicalMap(iSetup);
00381    if (emap==0) {
00382      emap=new HcalElectronicsMap(logicalMap_->generateHcalElectronicsMap());
00383    }
00384 
00385    if(!dbe_) return; 
00386    bool LEDEvent=false;
00387    bool LocalRun=false;
00388    // for local runs 
00389 
00390    edm::Handle<HcalTBTriggerData> trigger_data;
00391    iEvent.getByLabel(hcalTBTriggerDataTag_, trigger_data);
00392    if(trigger_data.isValid()){
00393       if(trigger_data->triggerWord()==6){ LEDEvent=true;LocalRun=true;}
00394    } 
00395    if(!LocalRun) return;  
00396    if(!LEDEvent) return; 
00397    
00398    HcalBaseDQMonitor::analyze(iEvent, iSetup);
00399    meEVT_->Fill(++ievt_);
00400    run_number=iEvent.id().run();
00401    meRUN_->Fill(iEvent.id().run());
00402 
00403    double data[20];
00404 
00405    edm::Handle<HBHEDigiCollection> hbhe; 
00406    iEvent.getByLabel(digiLabel_, hbhe);
00407    if(hbhe.isValid()) for(HBHEDigiCollection::const_iterator digi=hbhe->begin();digi!=hbhe->end();digi++){
00408      eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00409      if(digi->id().subdet()==HcalBarrel){
00410        for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00411        hb_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00412      }   
00413      if(digi->id().subdet()==HcalEndcap){
00414        for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00415        he_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00416      }
00417    }   
00418 
00419    edm::Handle<HODigiCollection> ho; 
00420    iEvent.getByLabel(digiLabel_,ho);
00421    if(ho.isValid()) for(HODigiCollection::const_iterator digi=ho->begin();digi!=ho->end();digi++){
00422      eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00423      for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00424      ho_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00425    }   
00426 
00427    edm::Handle<HFDigiCollection> hf;
00428    iEvent.getByLabel(digiLabel_,hf);
00429    if(hf.isValid()) for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00430      eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00431      for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00432      hf_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00433    }   
00434  
00435    edm::Handle<HcalCalibDigiCollection> calib;
00436    iEvent.getByLabel(calibDigiLabel_, calib);
00437    if(calib.isValid())for(HcalCalibDigiCollection::const_iterator digi=calib->begin();digi!=calib->end();digi++){
00438      if(digi->id().cboxChannel()!=0 || digi->id().hcalSubdet()==0) continue; 
00439      nTS=digi->size();
00440      double e=0; 
00441      for(int i=0;i<nTS;i++){ data[i]=adc2fC[digi->sample(i).adc()&0xff]; e+=data[i];}
00442      if(e<15000) calib_data[digi->id().hcalSubdet()][digi->id().ieta()+2][digi->id().iphi()-1].add_statistics(data,nTS);
00443    }   
00444   
00445    if(((ievt_)%500)==0){
00446        fillHistos();
00447        CheckStatus(); 
00448    }
00449    return;
00450 }
00451 
00452 
00453 void HcalDetDiagLEDMonitor::fillHistos(){
00454   std::string subdet[4]={"HB","HE","HO","HF"};
00455     Energy->Reset();
00456    Time->Reset();
00457    EnergyRMS->Reset();
00458    TimeRMS->Reset();
00459    EnergyHF->Reset();
00460    TimeHF->Reset();
00461    EnergyRMSHF->Reset();
00462    TimeRMSHF->Reset();
00463    EnergyCorr->Reset();
00464    Time2Dhbhehf->Reset();
00465    Time2Dho->Reset();
00466    Energy2Dhbhehf->Reset();
00467    Energy2Dho->Reset();
00468    HBPphi->Reset();
00469    HBMphi->Reset();
00470    HEPphi->Reset();
00471    HEMphi->Reset();
00472    HFPphi->Reset();
00473    HFMphi->Reset();
00474    HO0phi->Reset();
00475    HO1Pphi->Reset();
00476    HO2Pphi->Reset();
00477    HO1Mphi->Reset();
00478    HO2Mphi->Reset();
00479    
00480    // HB histograms
00481    for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){ 
00482       double T=0,nT=0,E=0,nE=0;
00483       for(int depth=1;depth<=2;depth++){
00484          if(hb_data[eta+42][phi-1][depth-1].get_statistics()>100){
00485             double ave=0;
00486             double rms=0;
00487             double time=0;
00488             double time_rms=0;
00489             hb_data[eta+42][phi-1][depth-1].get_average_led(&ave,&rms);
00490             hb_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00491             Energy->Fill(ave);
00492             if(ave>0)EnergyRMS->Fill(rms/ave);
00493             Time->Fill(time);
00494             TimeRMS->Fill(time_rms);
00495             T+=time; nT++; E+=ave; nE++;
00496             if(GetCalib("HB",eta,phi)->get_statistics()>100){
00497               double ave_calib=0;
00498               double rms_calib=0;
00499               GetCalib("HB",eta,phi)->get_average_led(&ave_calib,&rms_calib);
00500               fill_energy("HB",eta,phi,depth,ave/ave_calib,1);
00501               EnergyCorr->Fill(ave_calib/ave);
00502             }
00503          }
00504       } 
00505       if(nT>0){Time2Dhbhehf->Fill(eta,phi,T/nT);Energy2Dhbhehf->Fill(eta,phi,E/nE); }
00506    } 
00507    // HE histograms
00508    for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
00509       double T=0,nT=0,E=0,nE=0;
00510       for(int depth=1;depth<=3;depth++){
00511          if(he_data[eta+42][phi-1][depth-1].get_statistics()>100){
00512             double ave=0;
00513             double rms=0;
00514             double time=0;
00515             double time_rms=0;
00516             he_data[eta+42][phi-1][depth-1].get_average_led(&ave,&rms);
00517             he_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00518             Energy->Fill(ave);
00519             if(ave>0)EnergyRMS->Fill(rms/ave);
00520             Time->Fill(time);
00521             T+=time; nT++; E+=ave; nE++;
00522             TimeRMS->Fill(time_rms);
00523             if(GetCalib("HE",eta,phi)->get_statistics()>100){
00524               double ave_calib=0;
00525               double rms_calib=0;
00526               GetCalib("HE",eta,phi)->get_average_led(&ave_calib,&rms_calib);
00527               fill_energy("HE",eta,phi,depth,ave/ave_calib,1);
00528               EnergyCorr->Fill(ave_calib/ave);
00529             }
00530          }
00531       }
00532       if(nT>0 && abs(eta)>16 ){Time2Dhbhehf->Fill(eta,phi,T/nT);   Energy2Dhbhehf->Fill(eta,phi,E/nE); }         
00533       if(nT>0 && abs(eta)>20 ){Time2Dhbhehf->Fill(eta,phi+1,T/nT); Energy2Dhbhehf->Fill(eta,phi+1,E/nE);}        
00534    } 
00535    // HF histograms
00536    for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
00537       double T=0,nT=0,E=0,nE=0;
00538       for(int depth=1;depth<=2;depth++){
00539          if(hf_data[eta+42][phi-1][depth-1].get_statistics()>100){
00540            double ave=0;
00541            double rms=0;
00542            double time=0;
00543            double time_rms=0;
00544            hf_data[eta+42][phi-1][depth-1].get_average_led(&ave,&rms);
00545            hf_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00546            EnergyHF->Fill(ave);
00547            if(ave>0)EnergyRMSHF->Fill(rms/ave);
00548            TimeHF->Fill(time);
00549            T+=time; nT++; E+=ave; nE++;
00550            TimeRMSHF->Fill(time_rms);
00551            if(GetCalib("HF",eta,phi)->get_statistics()>100){
00552              double ave_calib=0;
00553              double rms_calib=0;
00554              GetCalib("HF",eta,phi)->get_average_led(&ave_calib,&rms_calib);
00555              fill_energy("HF",eta,phi,depth,ave/ave_calib,1);
00556              EnergyCorr->Fill(ave_calib/ave);
00557            }
00558          }
00559       } 
00560       if(nT>0 && abs(eta)>29 ){ Time2Dhbhehf->Fill(eta,phi,T/nT); Time2Dhbhehf->Fill(eta,phi+1,T/nT);}   
00561       if(nT>0 && abs(eta)>29 ){ Energy2Dhbhehf->Fill(eta,phi,E/nE); Energy2Dhbhehf->Fill(eta,phi+1,E/nE);}       
00562    } 
00563    // HO histograms
00564    for(int eta=-10;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
00565       double T=0,nT=0,E=0,nE=0;
00566       if(eta>10 && !isSiPM(eta,phi,4)) continue;
00567       for(int depth=4;depth<=4;depth++){
00568          if(ho_data[eta+42][phi-1][depth-1].get_statistics()>100){
00569             double ave=0;
00570             double rms=0;
00571             double time=0;
00572             double time_rms=0;
00573             ho_data[eta+42][phi-1][depth-1].get_average_led(&ave,&rms);
00574             ho_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00575             Energy->Fill(ave);
00576             if(ave>0)EnergyRMS->Fill(rms/ave);
00577             Time->Fill(time);
00578             T+=time; nT++; E+=ave; nE++;
00579             TimeRMS->Fill(time_rms);
00580             if(GetCalib("HO",eta,phi)->get_statistics()>100){
00581               double ave_calib=0;
00582               double rms_calib=0;
00583               GetCalib("HO",eta,phi)->get_average_led(&ave_calib,&rms_calib);
00584               fill_energy("HO",eta,phi,depth,ave/ave_calib,1);
00585               EnergyCorr->Fill(ave_calib/ave);
00586             }
00587          }
00588       }
00589       if(nT>0){ Time2Dho->Fill(eta,phi,T/nT); Energy2Dho->Fill(eta,phi+1,E/nE) ;}
00590    } 
00591 
00592    double ave=0.,rms=0.,ave_calib=0.,rms_calib=0.;
00593    // HB Ref histograms
00594    for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
00595       if(hb_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms) && GetCalib("HB",eta,phi)->get_reference(&ave_calib,&rms_calib)){
00596             fill_energy("HB",eta,phi,depth,ave/ave_calib,2);
00597       }
00598    } 
00599    // HE Ref histograms
00600    for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=3;depth++){
00601       if(he_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms) && GetCalib("HE",eta,phi)->get_reference(&ave_calib,&rms_calib)){
00602             fill_energy("HE",eta,phi,depth,ave/ave_calib,2);
00603       }
00604    } 
00605    // HO Ref histograms
00606    for(int eta=-10;eta<=15;eta++) for(int phi=1;phi<=72;phi++) for(int depth=4;depth<=4;depth++){
00607       if(eta>10 && !isSiPM(eta,phi,4)) continue;
00608       if(ho_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms) && GetCalib("HO",eta,phi)->get_reference(&ave_calib,&rms_calib)){
00609             fill_energy("HO",eta,phi,depth,ave/ave_calib,2);
00610       }
00611    } 
00612    // HF Ref histograms
00613    for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
00614       if(hf_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms) && GetCalib("HF",eta,phi)->get_reference(&ave_calib,&rms_calib)){
00615             fill_energy("HF",eta,phi,depth,ave/ave_calib,2);
00616       }
00617    } 
00618 
00619   //fill RM histograms: this part is incomplete, will be modefied later 
00620   double hbp[18][4],nhbp[18][4],hbm[18][4],nhbm[18][4];
00621   double hep[18][4],nhep[18][4],hem[18][4],nhem[18][4];
00622   double hfp[18][4],nhfp[18][4],hfm[18][4],nhfm[18][4];
00623   double ho0[18][4],nho0[18][4];
00624   double ho1p[18][4],nho1p[18][4];
00625   double ho2p[18][4],nho2p[18][4];
00626   double ho1m[18][4],nho1m[18][4];
00627   double ho2m[18][4],nho2m[18][4];
00628   for(int i=0;i<18;i++) for(int j=0;j<4;j++)
00629    hbp[i][j]=nhbp[i][j]=hbm[i][j]=nhbm[i][j]=hep[i][j]=nhep[i][j]=hem[i][j]=nhem[i][j]=hfp[i][j]=nhfp[i][j]=hfm[i][j]=nhfm[i][j]=0;
00630   for(int i=0;i<18;i++) for(int j=0;j<4;j++)
00631    ho0[i][j]=nho0[i][j]=ho1p[i][j]=nho1p[i][j]=ho2p[i][j]=nho2p[i][j]=ho1m[i][j]=nho1m[i][j]=ho2m[i][j]=nho2m[i][j]=0;
00632 
00633    std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
00634    for(std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
00635       DetId detid=emap->lookup(*eid);
00636       if(detid.det()!=DetId::Hcal) continue;
00637       HcalGenericDetId gid(emap->lookup(*eid));
00638       if(!(!(gid.null()) && 
00639             (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
00640              gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap  ||
00641              gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
00642              gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
00643       int sd=0,eta=0,phi=0,depth=0; 
00644       if(gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel)      sd=0;
00645       else if(gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap) sd=1;
00646       else if(gid.genericSubdet()==HcalGenericDetId::HcalGenOuter)  sd=2;
00647       else if(gid.genericSubdet()==HcalGenericDetId::HcalGenForward)sd=3;
00648       HcalDetId hid(detid);
00649       if(KnownBadCells_.find(hid.rawId())==KnownBadCells_.end()) continue;
00650     
00651       eta=hid.ieta();
00652       phi=hid.iphi();
00653       depth=hid.depth(); 
00654       
00655       double ave =get_energy(subdet[sd],eta,phi,depth,1);
00656       double ref =get_energy(subdet[sd],eta,phi,depth,2);
00657 
00658       HcalFrontEndId  lmap_entry=logicalMap_->getHcalFrontEndId(hid);
00659       int rbx; 
00660       if(sd==0 || sd==1 || sd==3){
00661            sscanf(&(lmap_entry.rbx().c_str())[3],"%d",&rbx);
00662       }else{
00663            if(abs(eta)<5) sscanf(&(lmap_entry.rbx().c_str())[3],"%d",&rbx);
00664            if(abs(eta)>=5) sscanf(&(lmap_entry.rbx().c_str())[4],"%d",&rbx);           
00665       }
00666       if(ave>0 && ref>0){
00667            if(sd==0 && eta>0){ hbp[rbx-1][lmap_entry.rm()-1]+=ave/ref; nhbp[rbx-1][lmap_entry.rm()-1]++; }
00668            if(sd==0 && eta<0){ hbm[rbx-1][lmap_entry.rm()-1]+=ave/ref; nhbm[rbx-1][lmap_entry.rm()-1]++; }
00669            if(sd==1 && eta>0){ hep[rbx-1][lmap_entry.rm()-1]+=ave/ref; nhep[rbx-1][lmap_entry.rm()-1]++; }
00670            if(sd==1 && eta<0){ hem[rbx-1][lmap_entry.rm()-1]+=ave/ref; nhem[rbx-1][lmap_entry.rm()-1]++; }
00671            if(sd==3 && eta>0){ hfp[rbx-1][lmap_entry.rm()-1]+=ave/ref; nhfp[rbx-1][lmap_entry.rm()-1]++; }
00672            if(sd==3 && eta<0){ hfm[rbx-1][lmap_entry.rm()-1]+=ave/ref; nhfm[rbx-1][lmap_entry.rm()-1]++; }
00673            if(sd==2 && abs(eta)<5){ ho0[rbx-1][lmap_entry.rm()-1]+=ave/ref; nho0[rbx-1][lmap_entry.rm()-1]++; }
00674            if(sd==2 && eta>=5 && eta<=10){ ho1p[rbx-1][lmap_entry.rm()-1]+=ave/ref; nho1p[rbx-1][lmap_entry.rm()-1]++; }
00675            if(sd==2 && eta>=11 && eta<=15){ ho2p[rbx-1][lmap_entry.rm()-1]+=ave/ref; nho2p[rbx-1][lmap_entry.rm()-1]++; }
00676            if(sd==2 && eta>=-10 && eta<=-5){ ho1m[rbx-1][lmap_entry.rm()-1]+=ave/ref; nho1m[rbx-1][lmap_entry.rm()-1]++; }
00677            if(sd==2 && eta>=-15 && eta<=-11){ ho2m[rbx-1][lmap_entry.rm()-1]+=ave/ref; nho2m[rbx-1][lmap_entry.rm()-1]++; }
00678       }
00679   }  
00680   for(int i=0;i<18;i++)for(int j=0;j<4;j++){
00681      int phi=i*4+j+1; 
00682      if(nhbp[i][j]>1) HBPphi->Fill(phi+0.5,hbp[i][j]/nhbp[i][j]);
00683      if(nhbm[i][j]>1) HBMphi->Fill(phi+0.5,hbm[i][j]/nhbm[i][j]);
00684      if(nhep[i][j]>1) HEPphi->Fill(phi+0.5,hep[i][j]/nhep[i][j]);
00685      if(nhem[i][j]>1) HEMphi->Fill(phi+0.5,hem[i][j]/nhem[i][j]);
00686   }   
00687   for(int i=0;i<12;i++)for(int j=0;j<3;j++){
00688      int phi=i*3+j+1; 
00689      if(nhfp[i][j]>1) HFPphi->Fill(phi+0.5,hfp[i][j]/nhfp[i][j]);
00690      if(nhfm[i][j]>1) HFMphi->Fill(phi+0.5,hfm[i][j]/nhfm[i][j]);
00691   } 
00692   for(int i=0;i<12;i++)for(int j=0;j<4;j++){
00693      int phi=i*4+j+1; 
00694      if(nho0[i][j]>1) HO0phi->Fill(phi+0.5,ho0[i][j]/nho0[i][j]);
00695      if(nho1p[i][j]>1) HO1Pphi->Fill(phi+0.5,ho1p[i][j]/nho1p[i][j]);
00696      if(nho2p[i][j]>1) HO2Pphi->Fill(phi+0.5,ho2p[i][j]/nho2p[i][j]);
00697      if(nho1m[i][j]>1) HO1Mphi->Fill(phi+0.5,ho1m[i][j]/nho1m[i][j]);
00698      if(nho2m[i][j]>1) HO2Mphi->Fill(phi+0.5,ho2m[i][j]/nho2m[i][j]);
00699   } 
00700 } 
00701 
00702 void HcalDetDiagLEDMonitor::SaveReference(){
00703 double led,rms,Time,time_rms;
00704 int    Eta,Phi,Depth,Statistic,Status=0;
00705 char   Subdet[10],str[500];
00706        sprintf(str,"%sHcalDetDiagLEDData_run%06i_%i.root",OutputFilePath.c_str(),run_number,dataset_seq_number);
00707        TFile *theFile = new TFile(str, "RECREATE");
00708        if(!theFile->IsOpen()) return;
00709        theFile->cd();
00710        sprintf(str,"%d",run_number); TObjString run(str);    run.Write("run number");
00711        sprintf(str,"%d",ievt_);      TObjString events(str); events.Write("Total events processed");
00712        
00713        TTree *tree   =new TTree("HCAL LED data","HCAL LED data");
00714        if(tree==0)   return;
00715        tree->Branch("Subdet",   &Subdet,         "Subdet/C");
00716        tree->Branch("eta",      &Eta,            "Eta/I");
00717        tree->Branch("phi",      &Phi,            "Phi/I");
00718        tree->Branch("depth",    &Depth,          "Depth/I");
00719        tree->Branch("statistic",&Statistic,      "Statistic/I");
00720        tree->Branch("status",   &Status,         "Status/I");
00721        tree->Branch("led",      &led,            "led/D");
00722        tree->Branch("rms",      &rms,            "rms/D");
00723        tree->Branch("time",     &Time,           "time/D");
00724        tree->Branch("time_rms", &time_rms,       "time_rms/D");
00725        sprintf(Subdet,"HB");
00726        for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
00727           if((Statistic=hb_data[eta+42][phi-1][depth-1].get_statistics())>100){
00728              Eta=eta; Phi=phi; Depth=depth;
00729              Status=hb_data[eta+42][phi-1][depth-1].get_status();
00730              hb_data[eta+42][phi-1][depth-1].get_average_led(&led,&rms);
00731              hb_data[eta+42][phi-1][depth-1].get_average_time(&Time,&time_rms);
00732              tree->Fill();
00733           }
00734        } 
00735        sprintf(Subdet,"HE");
00736        for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=3;depth++){
00737          if((Statistic=he_data[eta+42][phi-1][depth-1].get_statistics())>100){
00738             Eta=eta; Phi=phi; Depth=depth;
00739             Status=he_data[eta+42][phi-1][depth-1].get_status();
00740             he_data[eta+42][phi-1][depth-1].get_average_led(&led,&rms);
00741             he_data[eta+42][phi-1][depth-1].get_average_time(&Time,&time_rms);
00742             tree->Fill();
00743          }
00744        } 
00745        sprintf(Subdet,"HO");
00746        for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++) for(int depth=4;depth<=4;depth++){
00747          if((Statistic=ho_data[eta+42][phi-1][depth-1].get_statistics())>100){
00748              Eta=eta; Phi=phi; Depth=depth;
00749              Status=ho_data[eta+42][phi-1][depth-1].get_status();
00750              ho_data[eta+42][phi-1][depth-1].get_average_led(&led,&rms);
00751              ho_data[eta+42][phi-1][depth-1].get_average_time(&Time,&time_rms);
00752              tree->Fill();
00753          }
00754        } 
00755        sprintf(Subdet,"HF");
00756        for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
00757          if((Statistic=hf_data[eta+42][phi-1][depth-1].get_statistics())>100){
00758              Eta=eta; Phi=phi; Depth=depth;
00759              Status=hf_data[eta+42][phi-1][depth-1].get_status();
00760              hf_data[eta+42][phi-1][depth-1].get_average_led(&led,&rms);
00761              hf_data[eta+42][phi-1][depth-1].get_average_time(&Time,&time_rms);
00762              tree->Fill();
00763          }
00764        }
00765        sprintf(Subdet,"CALIB_HB");
00766        for(int eta=-1;eta<=1;eta++) for(int phi=1;phi<=72;phi++){
00767           if((calib_data[1][eta+2][phi-1].get_statistics())>100){
00768              Eta=eta; Phi=phi; Depth=0;
00769              Status=calib_data[1][eta+2][phi-1].get_status();
00770              calib_data[1][eta+2][phi-1].get_average_led(&led,&rms);
00771              calib_data[1][eta+2][phi-1].get_average_time(&Time,&time_rms);
00772              tree->Fill();
00773           }
00774        } 
00775        sprintf(Subdet,"CALIB_HE");
00776        for(int eta=-1;eta<=1;eta++) for(int phi=1;phi<=72;phi++){
00777           if((calib_data[2][eta+2][phi-1].get_statistics())>100){
00778              Eta=eta; Phi=phi; Depth=0;
00779              Status=calib_data[2][eta+2][phi-1].get_status();
00780              calib_data[2][eta+2][phi-1].get_average_led(&led,&rms);
00781              calib_data[2][eta+2][phi-1].get_average_time(&Time,&time_rms);
00782              tree->Fill();
00783           }
00784        } 
00785        sprintf(Subdet,"CALIB_HO");
00786        for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
00787           if((calib_data[3][eta+2][phi-1].get_statistics())>100){
00788              Eta=eta; Phi=phi; Depth=0;
00789              Status=calib_data[3][eta+2][phi-1].get_status();
00790              calib_data[3][eta+2][phi-1].get_average_led(&led,&rms);
00791              calib_data[3][eta+2][phi-1].get_average_time(&Time,&time_rms);
00792              tree->Fill();
00793           }
00794        } 
00795        sprintf(Subdet,"CALIB_HF");
00796        for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
00797           if((calib_data[4][eta+2][phi-1].get_statistics())>100){
00798              Eta=eta; Phi=phi; Depth=0;
00799              Status=calib_data[4][eta+2][phi-1].get_status();
00800              calib_data[4][eta+2][phi-1].get_average_led(&led,&rms);
00801              calib_data[4][eta+2][phi-1].get_average_time(&Time,&time_rms);
00802              tree->Fill();
00803           }
00804        } 
00805        theFile->Write();
00806        theFile->Close();
00807 
00808 
00809    if(XmlFilePath.size()>0){
00810       //create XML file
00811       char TIME[40];
00812       Long_t t; t=time(0); strftime(TIME,30,"%F %T",localtime(&t));
00813 
00814       sprintf(str,"HcalDetDiagLED_%i_%i.xml",run_number,dataset_seq_number);
00815       std::string xmlName=str;
00816       ofstream xmlFile;
00817       xmlFile.open(xmlName.c_str());
00818 
00819       xmlFile<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
00820       xmlFile<<"<ROOT>\n";
00821       xmlFile<<"  <HEADER>\n";
00822       xmlFile<<"    <HINTS mode='only-det-root'/>\n";
00823       xmlFile<<"    <TYPE>\n";
00824       xmlFile<<"      <EXTENSION_TABLE_NAME>HCAL_DETMON_LED_LASER_V1</EXTENSION_TABLE_NAME>\n";
00825       xmlFile<<"      <NAME>HCAL LED [local]</NAME>\n";
00826       xmlFile<<"    </TYPE>\n";
00827       xmlFile<<"    <!-- run details -->\n";
00828       xmlFile<<"    <RUN>\n";
00829       xmlFile<<"      <RUN_TYPE>LOCAL-RUN</RUN_TYPE>\n";
00830       xmlFile<<"      <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
00831       xmlFile<<"      <RUN_BEGIN_TIMESTAMP>2009-01-01 00:00:00</RUN_BEGIN_TIMESTAMP>\n";
00832       xmlFile<<"      <COMMENT_DESCRIPTION>hcal LED data</COMMENT_DESCRIPTION>\n";
00833       xmlFile<<"      <LOCATION>P5</LOCATION>\n";
00834       xmlFile<<"      <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
00835       xmlFile<<"    </RUN>\n";
00836       xmlFile<<"  </HEADER>\n";
00837       xmlFile<<"  <DATA_SET>\n";
00838       xmlFile<<"     <!-- optional dataset metadata -->\n\n";
00839       xmlFile<<"     <SET_NUMBER>"<<dataset_seq_number<<"</SET_NUMBER>\n";
00840       xmlFile<<"     <SET_BEGIN_TIMESTAMP>2009-01-01 00:00:00</SET_BEGIN_TIMESTAMP>\n";
00841       xmlFile<<"     <SET_END_TIMESTAMP>2009-01-01 00:00:00</SET_END_TIMESTAMP>\n";
00842       xmlFile<<"     <NUMBER_OF_EVENTS_IN_SET>"<<ievt_<<"</NUMBER_OF_EVENTS_IN_SET>\n";
00843       xmlFile<<"     <COMMENT_DESCRIPTION>Automatic DQM output</COMMENT_DESCRIPTION>\n";
00844       xmlFile<<"     <DATA_FILE_NAME>"<< xmlName <<"</DATA_FILE_NAME>\n";
00845       xmlFile<<"     <IMAGE_FILE_NAME>data plot url or file path</IMAGE_FILE_NAME>\n";
00846       xmlFile<<"     <!-- who and when created this dataset-->\n\n";
00847       xmlFile<<"     <CREATE_TIMESTAMP>"<<TIME<<"</CREATE_TIMESTAMP>\n";
00848       xmlFile<<"     <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
00849       xmlFile<<"     <!-- version (string) and subversion (number) -->\n";
00850       xmlFile<<"     <!-- fields are used to read data back from the database -->\n\n";
00851       xmlFile<<"     <VERSION>"<<run_number<<dataset_seq_number<<"</VERSION>\n";
00852       xmlFile<<"     <SUBVERSION>1</SUBVERSION>\n";
00853       xmlFile<<"     <!--  Assign predefined dataset attributes -->\n\n";
00854       xmlFile<<"     <PREDEFINED_ATTRIBUTES>\n";
00855       xmlFile<<"        <ATTRIBUTE>\n";
00856       xmlFile<<"           <NAME>HCAL Dataset Status</NAME>\n";
00857       xmlFile<<"           <VALUE>VALID</VALUE>\n";
00858       xmlFile<<"        </ATTRIBUTE>\n";
00859       xmlFile<<"     </PREDEFINED_ATTRIBUTES>\n";
00860       xmlFile<<"     <!-- multiple data block records -->\n\n";
00861 
00862       std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
00863       for(std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
00864          DetId detid=emap->lookup(*eid);
00865          if (detid.det()!=DetId::Hcal) continue;
00866          HcalGenericDetId gid(emap->lookup(*eid));
00867          if(!(!(gid.null()) && 
00868             (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
00869              gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap  ||
00870              gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
00871              gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
00872          int eta,phi,depth; 
00873          std::string subdet="";
00874          HcalDetId hid(detid);
00875          eta=hid.ieta();
00876          phi=hid.iphi();
00877          depth=hid.depth(); 
00878          
00879          double e=0,e_rms=0,t=0,t_rms=0;
00880          if(detid.subdetId()==HcalBarrel){
00881              subdet="HB";
00882              Statistic=hb_data[eta+42][phi-1][depth-1].get_statistics();
00883              Status   =hb_data[eta+42][phi-1][depth-1].get_status();
00884              hb_data[eta+42][phi-1][depth-1].get_average_led(&e,&e_rms);
00885              hb_data[eta+42][phi-1][depth-1].get_average_time(&t,&t_rms);
00886          }else if(detid.subdetId()==HcalEndcap){
00887              subdet="HE";
00888              Statistic=he_data[eta+42][phi-1][depth-1].get_statistics();
00889              Status   =he_data[eta+42][phi-1][depth-1].get_status();
00890              he_data[eta+42][phi-1][depth-1].get_average_led(&e,&e_rms);
00891              he_data[eta+42][phi-1][depth-1].get_average_time(&t,&t_rms);
00892          }else if(detid.subdetId()==HcalForward){
00893              subdet="HF";
00894              Statistic=hf_data[eta+42][phi-1][depth-1].get_statistics();
00895              Status   =hf_data[eta+42][phi-1][depth-1].get_status();
00896              hf_data[eta+42][phi-1][depth-1].get_average_led(&e,&e_rms);
00897              hf_data[eta+42][phi-1][depth-1].get_average_time(&t,&t_rms);
00898          }else if(detid.subdetId()==HcalOuter){
00899              subdet="HO";
00900              Statistic=ho_data[eta+42][phi-1][depth-1].get_statistics();
00901              Status   =ho_data[eta+42][phi-1][depth-1].get_status();
00902              ho_data[eta+42][phi-1][depth-1].get_average_led(&e,&e_rms);
00903              ho_data[eta+42][phi-1][depth-1].get_average_time(&t,&t_rms);
00904          }else continue;
00905          xmlFile<<"       <DATA>\n";
00906          xmlFile<<"          <NUMBER_OF_EVENTS_USED>"<<Statistic<<"</NUMBER_OF_EVENTS_USED>\n";
00907          xmlFile<<"          <SIGNAL_MEAN>"<<e<<"</SIGNAL_MEAN>\n";
00908          xmlFile<<"          <SIGNAL_RMS>"<<e_rms<<"</SIGNAL_RMS>\n";
00909          xmlFile<<"          <TIME_MEAN>"<<t<<"</TIME_MEAN>\n";
00910          xmlFile<<"          <TIME_RMS>"<<t_rms<<"</TIME_RMS>\n";
00911          xmlFile<<"          <CHANNEL_STATUS_WORD>"<<Status<<"</CHANNEL_STATUS_WORD>\n";
00912          xmlFile<<"          <CHANNEL_OBJECTNAME>HcalDetId</CHANNEL_OBJECTNAME>\n";
00913          xmlFile<<"             <SUBDET>"<<subdet<<"</SUBDET>\n";
00914          xmlFile<<"             <IETA>"<<eta<<"</IETA>\n";
00915          xmlFile<<"             <IPHI>"<<phi<<"</IPHI>\n";
00916          xmlFile<<"             <DEPTH>"<<depth<<"</DEPTH>\n";
00917          xmlFile<<"             <TYPE>0</TYPE>\n";
00918          xmlFile<<"       </DATA>\n";
00919       }
00921       xmlFile<<"  </DATA_SET>\n";
00922       xmlFile<<"</ROOT>\n";
00923       xmlFile.close();
00924 
00925       //create CALIB XML file 
00926       sprintf(str,"HcalDetDiagLEDCalib_%i_%i.xml",run_number,dataset_seq_number);
00927       std::string xmlNameCalib=str;
00928       ofstream xmlFileCalib;
00929       xmlFileCalib.open(xmlNameCalib.c_str());
00930 
00931       xmlFileCalib<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
00932       xmlFileCalib<<"<ROOT>\n";
00933       xmlFileCalib<<"  <HEADER>\n";
00934       xmlFileCalib<<"    <HINTS mode='only-det-root'/>\n";
00935       xmlFileCalib<<"    <TYPE>\n";
00936       xmlFileCalib<<"      <EXTENSION_TABLE_NAME>HCAL_DETMON_LED_LASER_V1</EXTENSION_TABLE_NAME>\n";
00937       xmlFileCalib<<"      <NAME>HCAL LED CALIB [local]</NAME>\n";
00938       xmlFileCalib<<"    </TYPE>\n";
00939       xmlFileCalib<<"    <!-- run details -->\n";
00940       xmlFileCalib<<"    <RUN>\n";
00941       xmlFileCalib<<"      <RUN_TYPE>LOCAL-RUN</RUN_TYPE>\n";
00942       xmlFileCalib<<"      <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
00943       xmlFileCalib<<"      <RUN_BEGIN_TIMESTAMP>2009-01-01 00:00:00</RUN_BEGIN_TIMESTAMP>\n";
00944       xmlFileCalib<<"      <COMMENT_DESCRIPTION>hcal LED CALIB data</COMMENT_DESCRIPTION>\n";
00945       xmlFileCalib<<"      <LOCATION>P5</LOCATION>\n";
00946       xmlFileCalib<<"      <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
00947       xmlFileCalib<<"    </RUN>\n";
00948       xmlFileCalib<<"  </HEADER>\n";
00949       xmlFileCalib<<"  <DATA_SET>\n";
00950       xmlFileCalib<<"     <!-- optional dataset metadata -->\n\n";
00951       xmlFileCalib<<"     <SET_NUMBER>"<<dataset_seq_number<<"</SET_NUMBER>\n";
00952       xmlFileCalib<<"     <SET_BEGIN_TIMESTAMP>2009-01-01 00:00:00</SET_BEGIN_TIMESTAMP>\n";
00953       xmlFileCalib<<"     <SET_END_TIMESTAMP>2009-01-01 00:00:00</SET_END_TIMESTAMP>\n";
00954       xmlFileCalib<<"     <NUMBER_OF_EVENTS_IN_SET>"<<ievt_<<"</NUMBER_OF_EVENTS_IN_SET>\n";
00955       xmlFileCalib<<"     <COMMENT_DESCRIPTION>Automatic DQM output</COMMENT_DESCRIPTION>\n";
00956       xmlFileCalib<<"     <DATA_FILE_NAME>"<< xmlNameCalib <<"</DATA_FILE_NAME>\n";
00957       xmlFileCalib<<"     <IMAGE_FILE_NAME>data plot url or file path</IMAGE_FILE_NAME>\n";
00958       xmlFileCalib<<"     <!-- who and when created this dataset-->\n\n";
00959       xmlFileCalib<<"     <CREATE_TIMESTAMP>"<<TIME<<"</CREATE_TIMESTAMP>\n";
00960       xmlFileCalib<<"     <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
00961       xmlFileCalib<<"     <!-- version (string) and subversion (number) -->\n";
00962       xmlFileCalib<<"     <!-- fields are used to read data back from the database -->\n\n";
00963       xmlFileCalib<<"     <VERSION>"<<run_number<<dataset_seq_number<<"</VERSION>\n";
00964       xmlFileCalib<<"     <SUBVERSION>1</SUBVERSION>\n";
00965       xmlFileCalib<<"     <!--  Assign predefined dataset attributes -->\n\n";
00966       xmlFileCalib<<"     <PREDEFINED_ATTRIBUTES>\n";
00967       xmlFileCalib<<"        <ATTRIBUTE>\n";
00968       xmlFileCalib<<"           <NAME>HCAL Dataset Status</NAME>\n";
00969       xmlFileCalib<<"           <VALUE>VALID</VALUE>\n";
00970       xmlFileCalib<<"        </ATTRIBUTE>\n";
00971       xmlFileCalib<<"     </PREDEFINED_ATTRIBUTES>\n";
00972       xmlFileCalib<<"     <!-- multiple data block records -->\n\n";
00973 
00974       for(int sd=1;sd<=4;sd++) for(int eta=-2;eta<=2;eta++) for(int phi=1;phi<=72;phi++){
00975          std::string subdet="";
00976          if(sd==1) subdet="HB";
00977          if(sd==2) subdet="HE";
00978          if(sd==3) subdet="HO";
00979          if(sd==4) subdet="HF";
00980          if((calib_data[sd][eta+2][phi-1].get_statistics())>100){
00981              double e=0,e_rms=0,t=0,t_rms=0;
00982              Status=calib_data[sd][eta+2][phi-1].get_status();
00983              Statistic=calib_data[sd][eta+2][phi-1].get_statistics(); 
00984              calib_data[sd][eta+2][phi-1].get_average_led(&e,&e_rms);
00985              calib_data[sd][eta+2][phi-1].get_average_time(&t,&t_rms);
00986              xmlFileCalib<<"       <DATA>\n";
00987              xmlFileCalib<<"          <NUMBER_OF_EVENTS_USED>"<<Statistic<<"</NUMBER_OF_EVENTS_USED>\n";
00988              xmlFileCalib<<"          <SIGNAL_MEAN>"<<e<<"</SIGNAL_MEAN>\n";
00989              xmlFileCalib<<"          <SIGNAL_RMS>"<<e_rms<<"</SIGNAL_RMS>\n";
00990              xmlFileCalib<<"          <TIME_MEAN>"<<t<<"</TIME_MEAN>\n";
00991              xmlFileCalib<<"          <TIME_RMS>"<<t_rms<<"</TIME_RMS>\n";
00992              xmlFileCalib<<"          <CHANNEL_STATUS_WORD>"<<Status<<"</CHANNEL_STATUS_WORD>\n";
00993              xmlFileCalib<<"          <CHANNEL_OBJECTNAME>HcalDetId</CHANNEL_OBJECTNAME>\n";
00994              xmlFileCalib<<"             <SUBDET>"<<subdet<<"</SUBDET>\n";
00995              xmlFileCalib<<"             <IETA>"<<eta<<"</IETA>\n";
00996              xmlFileCalib<<"             <IPHI>"<<phi<<"</IPHI>\n";
00997              xmlFileCalib<<"             <DEPTH>"<<0<<"</DEPTH>\n";
00998              xmlFileCalib<<"             <TYPE>0</TYPE>\n";
00999              xmlFileCalib<<"       </DATA>\n";  
01000          }
01001       }
01003       xmlFileCalib<<"  </DATA_SET>\n";
01004       xmlFileCalib<<"</ROOT>\n";
01005       xmlFileCalib.close();
01006 
01007       sprintf(str,"zip %s.zip %s %s",xmlName.c_str(),xmlName.c_str(),xmlNameCalib.c_str());
01008       system(str);
01009       sprintf(str,"rm -f %s %s",xmlName.c_str(),xmlNameCalib.c_str());
01010       system(str);
01011       sprintf(str,"mv -f %s.zip %s",xmlName.c_str(),XmlFilePath.c_str());
01012       system(str);
01013    }
01014 
01015 
01016    dataset_seq_number++;
01017 }
01018 
01019 void HcalDetDiagLEDMonitor::LoadReference(){
01020 double led,rms;
01021 int Eta,Phi,Depth;
01022 char subdet[10];
01023 TFile *f;
01024    if(gSystem->AccessPathName(ReferenceData.c_str())) return;
01025    f = new TFile(ReferenceData.c_str(),"READ");
01026    if(!f->IsOpen()) return ;
01027    TObjString *STR=(TObjString *)f->Get("run number");
01028    if(STR){ std::string Ref(STR->String()); ReferenceRun=Ref;}
01029    TTree*  t=(TTree*)f->Get("HCAL LED data");
01030    if(!t) return;
01031    t->SetBranchAddress("Subdet",   subdet);
01032    t->SetBranchAddress("eta",      &Eta);
01033    t->SetBranchAddress("phi",      &Phi);
01034    t->SetBranchAddress("depth",    &Depth);
01035    t->SetBranchAddress("led",      &led);
01036    t->SetBranchAddress("rms",      &rms);
01037    for(int ievt=0;ievt<t->GetEntries();ievt++){
01038 
01039      t->GetEntry(ievt);
01040      if(strcmp(subdet,"HB")==0) hb_data[Eta+42][Phi-1][Depth-1].set_reference(led,rms);
01041      if(strcmp(subdet,"HE")==0) he_data[Eta+42][Phi-1][Depth-1].set_reference(led,rms);
01042      if(strcmp(subdet,"HO")==0) ho_data[Eta+42][Phi-1][Depth-1].set_reference(led,rms);
01043      if(strcmp(subdet,"HF")==0) hf_data[Eta+42][Phi-1][Depth-1].set_reference(led,rms);
01044      if(strcmp(subdet,"CALIB_HB")==0) calib_data[1][Eta+2][Phi-1].set_reference(led,rms);
01045      if(strcmp(subdet,"CALIB_HE")==0) calib_data[2][Eta+2][Phi-1].set_reference(led,rms);
01046      if(strcmp(subdet,"CALIB_HO")==0) calib_data[3][Eta+2][Phi-1].set_reference(led,rms);
01047      if(strcmp(subdet,"CALIB_HF")==0) calib_data[4][Eta+2][Phi-1].set_reference(led,rms);
01048    }
01049    f->Close();
01050    IsReference=true;
01051 } 
01052 void HcalDetDiagLEDMonitor::CheckStatus(){
01053    for(int i=0;i<4;i++){
01054       ChannelStatusMissingChannels->depth[i]->Reset();
01055       ChannelStatusUnstableChannels->depth[i]->Reset();
01056       ChannelStatusUnstableLEDsignal->depth[i]->Reset();
01057       ChannelStatusLEDMean->depth[i]->Reset();
01058       ChannelStatusLEDRMS->depth[i]->Reset();
01059       ChannelStatusTimeMean->depth[i]->Reset();
01060       ChannelStatusTimeRMS->depth[i]->Reset();
01061    }
01062   
01063    std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
01064    for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++) {
01065       DetId detid=emap->lookup(*eid);
01066       if (detid.det()!=DetId::Hcal) continue;
01067       HcalGenericDetId gid(emap->lookup(*eid));
01068       if(!(!(gid.null()) && 
01069             (gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
01070              gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap  ||
01071              gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
01072              gid.genericSubdet()==HcalGenericDetId::HcalGenOuter))) continue;
01073       int eta=0,phi=0,depth=0;
01074       if(KnownBadCells_.find(gid.rawId())==KnownBadCells_.end()) continue;
01075 
01076       HcalDetId hid(detid);
01077       eta=hid.ieta();
01078       phi=hid.iphi();
01079       depth=hid.depth(); 
01080       
01081       double AVE_TIME=Time->getMean();
01082       if(detid.subdetId()==HcalBarrel){
01083          int stat=hb_data[eta+42][phi-1][depth-1].get_statistics()+
01084                    hb_data[eta+42][phi-1][depth-1].get_overflow()+hb_data[eta+42][phi-1][depth-1].get_undeflow();
01085          if(stat==0){ 
01086              fill_channel_status("HB",eta,phi,depth,1,1); 
01087              hb_data[eta+42][phi-1][depth-1].change_status(1); 
01088          }
01089          if(stat>0 && stat!=(ievt_)){ 
01090              fill_channel_status("HB",eta,phi,depth,2,(double)stat/(double)(ievt_)); 
01091              hb_data[eta+42][phi-1][depth-1].change_status(2); 
01092          }
01093          if(hb_data[eta+42][phi-1][depth-1].get_statistics()>100){ 
01094              double ave=0;
01095              double rms=0;
01096              hb_data[eta+42][phi-1][depth-1].get_average_time(&ave,&rms);
01097              if((AVE_TIME-ave)>0.75 || (AVE_TIME-ave)<-0.75){
01098                 fill_channel_status("HB",eta,phi,depth,6,AVE_TIME-ave); 
01099                 hb_data[eta+42][phi-1][depth-1].change_status(8); 
01100              }
01101          }  
01102          stat=hb_data[eta+42][phi-1][depth-1].get_undeflow();     
01103          if(stat>0){ 
01104              fill_channel_status("HB",eta,phi,depth,3,(double)stat/(double)(ievt_)); 
01105              hb_data[eta+42][phi-1][depth-1].change_status(4); 
01106          }    
01107       } 
01108       if(detid.subdetId()==HcalEndcap){
01109          int stat=he_data[eta+42][phi-1][depth-1].get_statistics()+
01110                    he_data[eta+42][phi-1][depth-1].get_overflow()+he_data[eta+42][phi-1][depth-1].get_undeflow();
01111          if(stat==0){ 
01112              fill_channel_status("HE",eta,phi,depth,1,1); 
01113              he_data[eta+42][phi-1][depth-1].change_status(1); 
01114          }
01115          if(stat>0 && stat!=(ievt_)){ 
01116              fill_channel_status("HE",eta,phi,depth,2,(double)stat/(double)(ievt_)); 
01117              he_data[eta+42][phi-1][depth-1].change_status(2); 
01118          }
01119          if(he_data[eta+42][phi-1][depth-1].get_statistics()>100){ 
01120              double ave=0;
01121              double rms=0;
01122              he_data[eta+42][phi-1][depth-1].get_average_time(&ave,&rms);
01123              if((AVE_TIME-ave)>0.75 || (AVE_TIME-ave)<-0.75){ 
01124                 fill_channel_status("HE",eta,phi,depth,6,AVE_TIME-ave); 
01125                 he_data[eta+42][phi-1][depth-1].change_status(8); 
01126              }  
01127          }  
01128          stat=he_data[eta+42][phi-1][depth-1].get_undeflow();     
01129          if(stat>0){ 
01130              fill_channel_status("HE",eta,phi,depth,3,(double)stat/(double)(ievt_)); 
01131              he_data[eta+42][phi-1][depth-1].change_status(4); 
01132          }  
01133       } 
01134       if(detid.subdetId()==HcalOuter){
01135          int stat=ho_data[eta+42][phi-1][depth-1].get_statistics()+
01136                    ho_data[eta+42][phi-1][depth-1].get_overflow()+ho_data[eta+42][phi-1][depth-1].get_undeflow();
01137          if(stat==0){ 
01138              fill_channel_status("HO",eta,phi,depth,1,1); 
01139              ho_data[eta+42][phi-1][depth-1].change_status(1); 
01140          }
01141          if(stat>0 && stat!=(ievt_)){ 
01142              fill_channel_status("HO",eta,phi,depth,2,(double)stat/(double)(ievt_)); 
01143              ho_data[eta+42][phi-1][depth-1].change_status(2); 
01144          }
01145          if(ho_data[eta+42][phi-1][depth-1].get_statistics()>100){ 
01146              double ave=0;
01147              double rms=0;
01148              ho_data[eta+42][phi-1][depth-1].get_average_time(&ave,&rms);
01149              if((AVE_TIME-ave)>0.75 || (AVE_TIME-ave)<-0.75){
01150                 fill_channel_status("HO",eta,phi,depth,6,AVE_TIME-ave); 
01151                 ho_data[eta+42][phi-1][depth-1].change_status(8);
01152              } 
01153          }  
01154          stat=ho_data[eta+42][phi-1][depth-1].get_undeflow();     
01155          if(stat>0){ 
01156              fill_channel_status("HO",eta,phi,depth,3,(double)stat/(double)(ievt_)); 
01157              ho_data[eta+42][phi-1][depth-1].change_status(4); 
01158          }  
01159       } 
01160       if(detid.subdetId()==HcalForward){
01161          AVE_TIME=TimeHF->getMean();
01162          int stat=hf_data[eta+42][phi-1][depth-1].get_statistics()+
01163                    hf_data[eta+42][phi-1][depth-1].get_overflow()+hf_data[eta+42][phi-1][depth-1].get_undeflow();
01164          if(stat==0){ 
01165              fill_channel_status("HF",eta,phi,depth,1,1); 
01166              hf_data[eta+42][phi-1][depth-1].change_status(1); 
01167          }
01168          if(stat>0 && stat!=(ievt_)){ 
01169              fill_channel_status("HF",eta,phi,depth,2,(double)stat/(double)(ievt_)); 
01170              hf_data[eta+42][phi-1][depth-1].change_status(2); 
01171          }
01172          if(hf_data[eta+42][phi-1][depth-1].get_statistics()>100){ 
01173              double ave=0;
01174              double rms=0;
01175              hf_data[eta+42][phi-1][depth-1].get_average_time(&ave,&rms);
01176              if((AVE_TIME-ave)>0.75 || (AVE_TIME-ave)<-0.75){
01177                 fill_channel_status("HF",eta,phi,depth,6,AVE_TIME-ave); 
01178                 hf_data[eta+42][phi-1][depth-1].change_status(8);
01179              } 
01180          }  
01181          stat=hf_data[eta+42][phi-1][depth-1].get_undeflow();     
01182          if(stat>0){ 
01183              fill_channel_status("HF",eta,phi,depth,3,(double)stat/(double)(ievt_)); 
01184              hf_data[eta+42][phi-1][depth-1].change_status(4); 
01185          }  
01186       } 
01187    }
01188 }
01189 void HcalDetDiagLEDMonitor::fill_energy(std::string subdet,int eta,int phi,int depth,double e,int type){ 
01190   int subdetval=-1;
01191   if (subdet.compare("HB")==0) subdetval=(int)HcalBarrel;
01192   else if (subdet.compare("HE")==0) subdetval=(int)HcalEndcap;
01193   else if (subdet.compare("HO")==0) subdetval=(int)HcalOuter;
01194   else if (subdet.compare("HF")==0) subdetval=(int)HcalForward;
01195   else return;
01196 
01197   int ietabin=CalcEtaBin(subdetval, eta, depth)+1;
01198   if(type==1) ChannelsLEDEnergy->depth[depth-1]   ->setBinContent(ietabin,phi,e);
01199   else if(type==2) ChannelsLEDEnergyRef->depth[depth-1]->setBinContent(ietabin,phi,e);
01200 }
01201 
01202 double HcalDetDiagLEDMonitor::get_energy(std::string subdet,int eta,int phi,int depth,int type){
01203   int subdetval=-1;
01204   if (subdet.compare("HB")==0) subdetval=(int)HcalBarrel;
01205   else if (subdet.compare("HE")==0) subdetval=(int)HcalEndcap;
01206   else if (subdet.compare("HO")==0) subdetval=(int)HcalOuter;
01207   else if (subdet.compare("HF")==0) subdetval=(int)HcalForward;
01208   else return -1.0;
01209 
01210   int ietabin=CalcEtaBin(subdetval, eta, depth)+1;
01211   if(type==1) return ChannelsLEDEnergy->depth[depth-1]  ->getBinContent(ietabin, phi);
01212   else if(type==2) return ChannelsLEDEnergyRef->depth[depth-1] ->getBinContent(ietabin,phi);
01213   return -1.0;
01214 }
01215 
01216 void HcalDetDiagLEDMonitor::fill_channel_status(std::string subdet,int eta,int phi,int depth,int type,double status){
01217   int subdetval=-1;
01218   if (subdet.compare("HB")==0) subdetval=(int)HcalBarrel;
01219   else if (subdet.compare("HE")==0) subdetval=(int)HcalEndcap;
01220   else if (subdet.compare("HO")==0) subdetval=(int)HcalOuter;
01221   else if (subdet.compare("HF")==0) subdetval=(int)HcalForward;
01222   else return;
01223   int ietabin=CalcEtaBin(subdetval, eta, depth)+1;
01224 
01225    if(type==1) ChannelStatusMissingChannels->depth[depth-1]  ->setBinContent(ietabin,phi,status);
01226    if(type==2) ChannelStatusUnstableChannels->depth[depth-1] ->setBinContent(ietabin,phi,status);
01227    if(type==3) ChannelStatusUnstableLEDsignal->depth[depth-1]->setBinContent(ietabin,phi,status);
01228    if(type==4) ChannelStatusLEDMean->depth[depth-1]          ->setBinContent(ietabin,phi,status);
01229    if(type==5) ChannelStatusLEDRMS->depth[depth-1]           ->setBinContent(ietabin,phi,status);
01230    if(type==6) ChannelStatusTimeMean->depth[depth-1]         ->setBinContent(ietabin,phi,status);
01231    if(type==7) ChannelStatusTimeRMS->depth[depth-1]          ->setBinContent(ietabin,phi,status);
01232 }
01233 void HcalDetDiagLEDMonitor::endRun(const edm::Run& run, const edm::EventSetup& c){   
01234    if(ievt_>=100){
01235       fillHistos();
01236       CheckStatus();
01237       SaveReference(); 
01238    }   
01239 } 
01240 DEFINE_FWK_MODULE (HcalDetDiagLEDMonitor);
01241