00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020 #include "DQM/HcalMonitorTasks/interface/HcalBaseDQMonitor.h"
00021 #include "FWCore/Framework/interface/Frameworkfwd.h"
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "FWCore/Framework/interface/MakerMacros.h"
00024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00025
00026 #include "DQMServices/Core/interface/DQMStore.h"
00027 #include "DQMServices/Core/interface/MonitorElement.h"
00028 #include "DQM/HcalMonitorTasks/interface/HcalBaseMonitor.h"
00029
00030 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00031 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00032
00033 #include <math.h>
00034
00035
00036 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00037
00038 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
00039
00040 #include "CalibCalorimetry/HcalAlgos/interface/HcalLogicalMapGenerator.h"
00041 #include "CondFormats/HcalObjects/interface/HcalLogicalMap.h"
00042
00043 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
00044 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00045 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00046 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00047 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
00048 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00049
00050 #include "TFile.h"
00051 #include "TTree.h"
00052 #include "TSystem.h"
00053
00054 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00055 #include "DQM/HcalMonitorTasks/interface/HcalEtaPhiHists.h"
00056
00057 #include <iostream>
00058 #include <fstream>
00059
00061 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,
00062 13.5,15.,17.,19.,21.,23.,25.,27.,29.5,32.5,35.5,38.5,42.,46.,50.,54.5,59.5,
00063 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,
00064 124.5,129.5,137.,147.,157.,167.,177.,187.,197.,209.5,224.5,239.5,254.5,272.,
00065 292.,312.,334.5,359.5,384.5,359.5,384.5,409.5,434.5,459.5,484.5,509.5,534.5,
00066 559.5,584.5,609.5,634.5,659.5,684.5,709.5,747.,797.,847.,897.,947.,997.,
00067 1047.,1109.5,1184.5,1259.5,1334.5,1422.,1522.,1622.,1734.5,1859.5,1984.5,
00068 1859.5,1984.5,2109.5,2234.5,2359.5,2484.5,2609.5,2734.5,2859.5,2984.5,
00069 3109.5,3234.5,3359.5,3484.5,3609.5,3797.,4047.,4297.,4547.,4797.,5047.,
00070 5297.,5609.5,5984.5,6359.5,6734.5,7172.,7672.,8172.,8734.5,9359.5,9984.5};
00072 typedef struct{
00073 int eta;
00074 int phi;
00075 }Raddam_ch;
00076 Raddam_ch RADDAM_CH[56]={{-30,15},{-32,15},{-34,15},{-36,15},{-38,15},{-40,15},{-41,15},
00077 {-30,35},{-32,35},{-34,35},{-36,35},{-38,35},{-40,35},{-41,35},
00078 {-30,51},{-32,51},{-34,51},{-36,51},{-38,51},{-40,51},{-41,51},
00079 {-30,71},{-32,71},{-34,71},{-36,71},{-38,71},{-40,71},{-41,71},
00080 {30, 01},{32, 01},{34, 01},{36, 01},{38, 01},{40, 71},{41, 71},
00081 {30, 21},{32, 21},{34, 21},{36, 21},{38, 21},{40, 19},{41, 19},
00082 {30, 37},{32, 37},{34, 37},{36, 37},{38, 37},{40, 35},{41, 35},
00083 {30, 57},{32, 57},{34, 57},{36, 57},{38, 57},{40, 55},{41, 55}};
00084
00085 class HcalDetDiagLaserData{
00086 public:
00087 HcalDetDiagLaserData(){
00088 IsRefetence=false;
00089 nChecks=0;nBadTime=0;nBadEnergy=0;
00090 status=0;
00091 reset();
00092 reset1();
00093 }
00094 void reset(){
00095 Xe=XXe=Xt=XXt=n=0;
00096 overflow=0;
00097 undeflow=0;
00098 }
00099 void reset1(){
00100 Xe1=XXe1=Xt1=XXt1=n1=0;
00101 overflow1=0;
00102 undeflow1=0;
00103 }
00104 void add_statistics(double *data,int nTS){
00105 double e=GetEnergy(data,nTS);
00106 double t=GetTime(data,nTS);
00107 if(e<20){ undeflow++;undeflow1++; }else if(e>10000){ overflow++;overflow1++; }else{
00108 n++; Xe+=e; XXe+=e*e; Xt+=t; XXt+=t*t;
00109 n1++; Xe1+=e; XXe1+=e*e; Xt1+=t; XXt1+=t*t;
00110 }
00111 }
00112 void set_reference(float val,float rms,float time,float time_rms){
00113 ref_amp=val; ref_rms=rms;
00114 ref_time=time; ref_time_rms=time_rms;
00115 IsRefetence=true;
00116 }
00117 void change_status(int val){
00118 status|=val;
00119 }
00120 int get_status(){
00121 return status;
00122 }
00123 bool get_reference(double *val,double *rms,double *time,double *time_rms){
00124 *val=ref_amp; *rms=ref_rms;
00125 *time=ref_time; *time_rms=ref_time_rms;
00126 return IsRefetence;
00127 }
00128 bool get_average_amp(double *ave,double *rms){
00129 if(n>0){ *ave=Xe/n; *rms=sqrt(XXe/n-(Xe*Xe)/(n*n));} else return false;
00130 return true;
00131 }
00132 bool get_average_time(double *ave,double *rms){
00133 if(n>0){ *ave=Xt/n; *rms=sqrt(XXt/n-(Xt*Xt)/(n*n));} else return false;
00134 return true;
00135 }
00136 int get_statistics(){
00137 return (int)n;
00138 }
00139 int get_overflow(){
00140 return overflow;
00141 }
00142 int get_undeflow(){
00143 return undeflow;
00144 }
00145 bool get_average_amp1(double *ave,double *rms){
00146 if(n1>0){ *ave=Xe1/n1; *rms=sqrt(XXe1/n1-(Xe1*Xe1)/(n1*n1));} else return false;
00147 return true;
00148 }
00149 bool get_average_time1(double *ave,double *rms){
00150 if(n1>0){ *ave=Xt1/n1; *rms=sqrt(XXt1/n1-(Xt1*Xt1)/(n1*n1));} else return false;
00151 return true;
00152 }
00153 int get_statistics1(){
00154 return (int)n1;
00155 }
00156 int get_overflow1(){
00157 return overflow1;
00158 }
00159 int get_undeflow1(){
00160 return undeflow1;
00161 }
00162 double GetEnergy(double *data,int n){
00163 int MaxI=0; double Energy,MaxE=0;
00164 for(int j=0;j<n;++j) if(MaxE<data[j]){ MaxE=data[j]; MaxI=j; }
00165 Energy=data[MaxI];
00166 if(MaxI>0) Energy+=data[MaxI-1];
00167 if(MaxI>1) Energy+=data[MaxI-2];
00168 if(MaxI<(n-1)) Energy+=data[MaxI+1];
00169 if(MaxI<(n-2)) Energy+=data[MaxI+2];
00170 return Energy;
00171 }
00172 double GetTime(double *data,int n=10){
00173 int MaxI=-100; double Time=-9999,SumT=0,MaxT=-10;
00174 for(int j=0;j<n;++j) if(MaxT<data[j]){ MaxT=data[j]; MaxI=j; }
00175 if (MaxI>=0)
00176 {
00177 Time=MaxI*data[MaxI];
00178 SumT=data[MaxI];
00179 if(MaxI>0){ Time+=(MaxI-1)*data[MaxI-1]; SumT+=data[MaxI-1]; }
00180 if(MaxI<(n-1)){ Time+=(MaxI+1)*data[MaxI+1]; SumT+=data[MaxI+1]; }
00181 Time=Time/SumT;
00182 }
00183 return Time;
00184 }
00185 int overflow;
00186 int undeflow;
00187 int overflow1;
00188 int undeflow1;
00189 double Xe,XXe,Xt,XXt,n;
00190 double Xe1,XXe1,Xt1,XXt1,n1;
00191 bool IsRefetence;
00192 float ref_amp;
00193 float ref_rms;
00194 float ref_time;
00195 float ref_time_rms;
00196 int status;
00197 float nChecks,nBadTime,nBadEnergy;
00198 };
00199
00200 class HcalDetDiagLaserMonitor : public HcalBaseDQMonitor {
00201 public:
00202 explicit HcalDetDiagLaserMonitor(const edm::ParameterSet&);
00203 ~HcalDetDiagLaserMonitor();
00204
00205 private:
00206 void beginRun(const edm::Run& run, const edm::EventSetup& c);
00207 void endRun(const edm::Run& run, const edm::EventSetup& c);
00208 void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c) ;
00209 void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c);
00210 void analyze(const edm::Event&, const edm::EventSetup&);
00211
00212 const HcalElectronicsMap *emap;
00213 edm::InputTag inputLabelDigi_;
00214
00215 void SaveReference();
00216 void LoadReference();
00217 bool get_ave_rbx(int sd,int side,int rbx,float *ave,float *rms);
00218 bool get_ave_subdet(int sd,float *ave_t,float *ave_e,float *ave_t_r,float *ave_e_r);
00219 void fillHistos(int sd);
00220 void fillProblems(int sd);
00221 int nHBHEchecks,nHOchecks,nHFchecks;
00222 double LaserTimingThreshold,LaserEnergyThreshold;
00223
00224 int ievt_;
00225 int run_number;
00226 int dataset_seq_number;
00227 bool IsReference;
00228 bool LocalRun;
00229
00230 std::string ReferenceData;
00231 std::string ReferenceRun;
00232 std::string OutputFilePath;
00233 std::string XmlFilePath;
00234 std::string baseFolder_;
00235 std::string prefixME_;
00236 edm::InputTag rawdatalabel_;
00237 bool Online_;
00238 bool Overwrite;
00239
00240 MonitorElement *meEVT_,*meRUN_;
00241 MonitorElement *RefRun_;
00242 MonitorElement *hbheEnergy;
00243 MonitorElement *hbheTime;
00244 MonitorElement *hbheEnergyRMS;
00245 MonitorElement *hbheTimeRMS;
00246 MonitorElement *hoEnergy;
00247 MonitorElement *hoTime;
00248 MonitorElement *hoEnergyRMS;
00249 MonitorElement *hoTimeRMS;
00250 MonitorElement *hfEnergy;
00251 MonitorElement *hfTime;
00252 MonitorElement *hfEnergyRMS;
00253 MonitorElement *hfTimeRMS;
00254
00255 MonitorElement *Time2Dhbhehf;
00256 MonitorElement *Time2Dho;
00257 MonitorElement *Energy2Dhbhehf;
00258 MonitorElement *Energy2Dho;
00259 MonitorElement *refTime2Dhbhehf;
00260 MonitorElement *refTime2Dho;
00261 MonitorElement *refEnergy2Dhbhehf;
00262 MonitorElement *refEnergy2Dho;
00263
00264 MonitorElement *hb_time_rbx;
00265 MonitorElement *he_time_rbx;
00266 MonitorElement *ho_time_rbx;
00267 MonitorElement *hf_time_rbx;
00268
00269 MonitorElement *Raddam[56];
00270
00271 EtaPhiHists* ProblemCellsByDepth_timing;
00272 EtaPhiHists* ProblemCellsByDepth_energy;
00273 std::vector<std::string> problemnames_;
00274
00275 EtaPhiHists* ProblemCellsByDepth_timing_val;
00276 EtaPhiHists* ProblemCellsByDepth_energy_val;
00277
00278 HcalDetDiagLaserData hb_data[85][72][4];
00279 HcalDetDiagLaserData he_data[85][72][4];
00280 HcalDetDiagLaserData ho_data[85][72][4];
00281 HcalDetDiagLaserData hf_data[85][72][4];
00282 };
00283
00284 HcalDetDiagLaserMonitor::HcalDetDiagLaserMonitor(const edm::ParameterSet& iConfig){
00285 ievt_=-1;
00286 emap=0;
00287 dataset_seq_number=1;
00288 run_number=-1;
00289 IsReference=false;
00290 LocalRun=false;
00291 nHBHEchecks=nHOchecks=nHFchecks=0;
00292
00293 inputLabelDigi_ = iConfig.getUntrackedParameter<edm::InputTag>("digiLabel");
00294 ReferenceData = iConfig.getUntrackedParameter<std::string>("LaserReferenceData" ,"");
00295 OutputFilePath = iConfig.getUntrackedParameter<std::string>("OutputFilePath", "");
00296 XmlFilePath = iConfig.getUntrackedParameter<std::string>("XmlFilePath", "");
00297 Online_ = iConfig.getUntrackedParameter<bool> ("online",false);
00298 Overwrite = iConfig.getUntrackedParameter<bool> ("Overwrite",true);
00299 prefixME_ = iConfig.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00300 if (prefixME_.size()>0 && prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00301 prefixME_.append("/");
00302 subdir_ = iConfig.getUntrackedParameter<std::string>("TaskFolder","DetDiagPedestalMonitor_Hcal/");
00303 if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00304 subdir_.append("/");
00305 subdir_=prefixME_+subdir_;
00306 debug_ = iConfig.getUntrackedParameter<int>("debug",0);
00307 rawdatalabel_ = iConfig.getUntrackedParameter<edm::InputTag>("RawDataLabel");
00308
00309
00310 LaserTimingThreshold = iConfig.getUntrackedParameter<double>("LaserTimingThreshold",0.2);
00311 LaserEnergyThreshold = iConfig.getUntrackedParameter<double>("LaserEnergyThreshold",0.1);
00312 }
00313 void HcalDetDiagLaserMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c){
00314
00315 edm::ESHandle<HcalDbService> conditions_;
00316 c.get<HcalDbRecord>().get(conditions_);
00317 emap=conditions_->getHcalMapping();
00318
00319 HcalBaseDQMonitor::setup();
00320 if (!dbe_) return;
00321 std::string name;
00322
00323 dbe_->setCurrentFolder(subdir_);
00324 meEVT_ = dbe_->bookInt("HcalDetDiagLaserMonitor Event Number");
00325 meRUN_ = dbe_->bookInt("HcalDetDiagLaserMonitor Run Number");
00326
00327 ProblemCellsByDepth_timing = new EtaPhiHists();
00328 ProblemCellsByDepth_timing->setup(dbe_," Problem Bad Laser Timing");
00329 for(unsigned int i=0;i<ProblemCellsByDepth_timing->depth.size();i++)
00330 problemnames_.push_back(ProblemCellsByDepth_timing->depth[i]->getName());
00331 ProblemCellsByDepth_energy = new EtaPhiHists();
00332 ProblemCellsByDepth_energy->setup(dbe_," Problem Bad Laser Energy");
00333 for(unsigned int i=0;i<ProblemCellsByDepth_energy->depth.size();i++)
00334 problemnames_.push_back(ProblemCellsByDepth_energy->depth[i]->getName());
00335
00336 dbe_->setCurrentFolder(subdir_+"Summary Plots");
00337
00338 name="HBHE Laser Energy Distribution"; hbheEnergy = dbe_->book1D(name,name,200,0,3000);
00339 name="HBHE Laser Timing Distribution"; hbheTime = dbe_->book1D(name,name,200,0,10);
00340 name="HBHE Laser Energy RMS_div_Energy Distribution"; hbheEnergyRMS = dbe_->book1D(name,name,200,0,0.5);
00341 name="HBHE Laser Timing RMS Distribution"; hbheTimeRMS = dbe_->book1D(name,name,200,0,1);
00342 name="HO Laser Energy Distribution"; hoEnergy = dbe_->book1D(name,name,200,0,3000);
00343 name="HO Laser Timing Distribution"; hoTime = dbe_->book1D(name,name,200,0,10);
00344 name="HO Laser Energy RMS_div_Energy Distribution"; hoEnergyRMS = dbe_->book1D(name,name,200,0,0.5);
00345 name="HO Laser Timing RMS Distribution"; hoTimeRMS = dbe_->book1D(name,name,200,0,1);
00346 name="HF Laser Energy Distribution"; hfEnergy = dbe_->book1D(name,name,200,0,3000);
00347 name="HF Laser Timing Distribution"; hfTime = dbe_->book1D(name,name,200,0,10);
00348 name="HF Laser Energy RMS_div_Energy Distribution"; hfEnergyRMS = dbe_->book1D(name,name,200,0,0.7);
00349 name="HF Laser Timing RMS Distribution"; hfTimeRMS = dbe_->book1D(name,name,200,0,1);
00350
00351 name="Laser Timing HBHEHF"; Time2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
00352 name="Laser Timing HO"; Time2Dho = dbe_->book2D(name,name,33,-16,16,74,0,73);
00353 name="Laser Energy HBHEHF"; Energy2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
00354 name="Laser Energy HO"; Energy2Dho = dbe_->book2D(name,name,33,-16,16,74,0,73);
00355 name="HBHEHF Laser (Timing-Ref)+1"; refTime2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
00356 name="HO Laser (Timing-Ref)+1"; refTime2Dho = dbe_->book2D(name,name,33,-16,16,74,0,73);
00357 name="HBHEHF Laser Energy_div_Ref"; refEnergy2Dhbhehf = dbe_->book2D(name,name,87,-43,43,74,0,73);
00358 name="HO Laser Energy_div_Ref"; refEnergy2Dho = dbe_->book2D(name,name,33,-16,16,74,0,73);
00359
00360 name="HB RBX average Time-Ref"; hb_time_rbx = dbe_->book1D(name,name,36,0.5,36.5);
00361 name="HE RBX average Time-Ref"; he_time_rbx = dbe_->book1D(name,name,36,0.5,36.5);
00362 name="HO RBX average Time-Ref"; ho_time_rbx = dbe_->book1D(name,name,36,0.5,36.5);
00363 name="HF RoBox average Time-Ref"; hf_time_rbx = dbe_->book1D(name,name,24,0.5,24.5);
00364
00365 char str[200];
00366 for(int i=1;i<=18;i++){ sprintf(str,"HBM%02i",i); hb_time_rbx->setBinLabel(i,str); }
00367 for(int i=1;i<=18;i++){ sprintf(str,"HBP%02i",i); hb_time_rbx->setBinLabel(i+18,str); }
00368 for(int i=1;i<=18;i++){ sprintf(str,"HEM%02i",i); he_time_rbx->setBinLabel(i,str); }
00369 for(int i=1;i<=18;i++){ sprintf(str,"HEP%02i",i); he_time_rbx->setBinLabel(i+18,str); }
00370 for(int i=1;i<=12;i++){ sprintf(str,"HFM%02i",i); hf_time_rbx->setBinLabel(i,str); }
00371 for(int i=1;i<=12;i++){ sprintf(str,"HFP%02i",i); hf_time_rbx->setBinLabel(i+12,str); }
00372 for(int i=1;i<=6;i++){ sprintf(str,"HO2M%02i",i*2); ho_time_rbx->setBinLabel(i,str); }
00373 for(int i=1;i<=6;i++){ sprintf(str,"HO1M%02i",i*2); ho_time_rbx->setBinLabel(i+6,str); }
00374 for(int i=1;i<=12;i++){ sprintf(str,"HO0%02i",i); ho_time_rbx->setBinLabel(i+12,str); }
00375 for(int i=1;i<=6;i++){ sprintf(str,"HO1P%02i",i*2); ho_time_rbx->setBinLabel(i+24,str); }
00376 for(int i=1;i<=6;i++){ sprintf(str,"HO2P%02i",i*2); ho_time_rbx->setBinLabel(i+30,str); }
00377
00378 Time2Dhbhehf->setAxisTitle("i#eta",1);
00379 Time2Dhbhehf->setAxisTitle("i#phi",2);
00380 Time2Dho->setAxisTitle("i#eta",1);
00381 Time2Dho->setAxisTitle("i#phi",2);
00382 Energy2Dhbhehf->setAxisTitle("i#eta",1);
00383 Energy2Dhbhehf->setAxisTitle("i#phi",2);
00384 Energy2Dho->setAxisTitle("i#eta",1);
00385 Energy2Dho->setAxisTitle("i#phi",2);
00386 refTime2Dhbhehf->setAxisTitle("i#eta",1);
00387 refTime2Dhbhehf->setAxisTitle("i#phi",2);
00388 refTime2Dho->setAxisTitle("i#eta",1);
00389 refTime2Dho->setAxisTitle("i#phi",2);
00390 refEnergy2Dhbhehf->setAxisTitle("i#eta",1);
00391 refEnergy2Dhbhehf->setAxisTitle("i#phi",2);
00392 refEnergy2Dho->setAxisTitle("i#eta",1);
00393 refEnergy2Dho->setAxisTitle("i#phi",2);
00394
00395 refTime2Dhbhehf->setAxisRange(0,2,3);
00396 refTime2Dho->setAxisRange(0,2,3);
00397 refEnergy2Dhbhehf->setAxisRange(0.5,1.5,3);
00398 refEnergy2Dho->setAxisRange(0.5,1.5,3);
00399
00400 ReferenceRun="UNKNOWN";
00401 LoadReference();
00402 dbe_->setCurrentFolder(subdir_);
00403 RefRun_= dbe_->bookString("HcalDetDiagLaserMonitor Reference Run",ReferenceRun);
00404
00405 dbe_->setCurrentFolder(subdir_+"Raddam Plots");
00406 for(int i=0;i<56;i++){
00407 sprintf(str,"RADDAM (%i %i)",RADDAM_CH[i].eta,RADDAM_CH[i].phi);
00408 Raddam[i] = dbe_->book1D(str,str,10,-0.5,9.5);
00409 }
00410 dbe_->setCurrentFolder(subdir_+"Plots for client");
00411 ProblemCellsByDepth_timing_val = new EtaPhiHists();
00412 ProblemCellsByDepth_timing_val->setup(dbe_," Laser Timing difference");
00413 ProblemCellsByDepth_energy_val = new EtaPhiHists();
00414 ProblemCellsByDepth_energy_val->setup(dbe_," Laser Energy difference");
00415 }
00416
00417
00418 HcalDetDiagLaserMonitor::~HcalDetDiagLaserMonitor(){
00419
00420 }
00421
00422
00423 void HcalDetDiagLaserMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00424 HcalBaseDQMonitor::analyze(iEvent,iSetup);
00425
00426 int eta,phi,depth,nTS;
00427 static bool HBHEseq,HOseq,HFseq;
00428 static int lastHBHEorbit,lastHOorbit,lastHForbit,nChecksHBHE,nChecksHO,nChecksHF,ievt_hbhe,ievt_ho,ievt_hf;
00429 if(ievt_==-1){
00430 ievt_=0;HBHEseq=HOseq=HFseq=false; lastHBHEorbit=lastHOorbit=lastHForbit=-1;nChecksHBHE=nChecksHO=nChecksHF=0;
00431 ievt_hbhe=0,ievt_ho=0,ievt_hf=0;
00432 }
00433
00434 if(!dbe_) return;
00435 bool LaserEvent=false;
00436 bool LaserRaddam=false;
00437 int orbit=iEvent.orbitNumber();
00438 meRUN_->Fill(iEvent.id().run());
00439
00440 edm::Handle<HcalTBTriggerData> trigger_data;
00441 iEvent.getByType(trigger_data);
00442 if(trigger_data.isValid()){
00443 if(trigger_data->wasLaserTrigger()) LaserEvent=true;
00444 LocalRun=true;
00445 }
00446 if(!LocalRun && Online_){
00447 if(HBHEseq && (orbit-lastHBHEorbit)>(11223*10) && ievt_hbhe>40){
00448 HBHEseq=false;
00449 fillHistos(HcalBarrel);
00450 fillProblems(HcalBarrel);
00451 fillProblems(HcalEndcap);
00452 nChecksHBHE++;
00453 ievt_hbhe=0;
00454 for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) hb_data[i][j][k].reset();
00455 for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) he_data[i][j][k].reset();
00456 }
00457 if(HOseq && (orbit-lastHOorbit)>(11223*10) && ievt_ho>40){
00458 HOseq=false;
00459 fillHistos(HcalOuter);
00460 fillProblems(HcalOuter);
00461 nChecksHO++;
00462 ievt_ho=0;
00463 for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) ho_data[i][j][k].reset();
00464 }
00465 if(HFseq && (orbit-lastHForbit)>(11223*10) && ievt_hf>40){
00466 HFseq=false;
00467 fillHistos(HcalForward);
00468 fillProblems(HcalForward);
00469 nChecksHF++;
00470 ievt_hf=0;
00471 if(nChecksHF==1 || (nChecksHF>1 && ((nChecksHF-1)%12)==0)){
00472 SaveReference();
00473 }
00474 for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) hf_data[i][j][k].reset();
00475 }
00476 }
00477
00478
00479 if(LocalRun==false || LaserEvent==false){
00480 edm::Handle<FEDRawDataCollection> rawdata;
00481 iEvent.getByLabel(rawdatalabel_,rawdata);
00482
00483 for (int i=FEDNumbering::MINHCALFEDID;i<=FEDNumbering::MAXHCALFEDID; i++) {
00484 const FEDRawData& fedData = rawdata->FEDData(i) ;
00485 if ( fedData.size() < 24 ) continue ;
00486 int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
00487 if(value==hc_HBHEHPD){ HBHEseq=true; HOseq=HFseq=false; lastHBHEorbit=orbit; ievt_hbhe++; }
00488 if(value==hc_HOHPD){ HOseq=true; HBHEseq=HFseq=false; lastHOorbit=orbit; ievt_ho++; }
00489 if(value==hc_HFPMT){ HFseq=true; HBHEseq=HOseq=false; lastHForbit=orbit; ievt_hf++; }
00490
00491 if(value==hc_HBHEHPD || value==hc_HOHPD || value==hc_HFPMT){ LaserEvent=true; break;}
00492 if(value==hc_RADDAM){ LaserEvent=true; LaserRaddam=true; break;}
00493 }
00494 }
00495 if(!LaserEvent) return;
00496
00497 meEVT_->Fill(++ievt_);
00498 run_number=iEvent.id().run();
00499 double data[20];
00500 if(!LaserRaddam){
00501 edm::Handle<HBHEDigiCollection> hbhe;
00502 iEvent.getByLabel(inputLabelDigi_,hbhe);
00503 if(hbhe.isValid()){
00504 for(HBHEDigiCollection::const_iterator digi=hbhe->begin();digi!=hbhe->end();digi++){
00505 eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00506 if(digi->id().subdet()==HcalBarrel){
00507 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00508 hb_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00509 }
00510 if(digi->id().subdet()==HcalEndcap){
00511 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00512 he_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00513 }
00514 }
00515 }
00516 edm::Handle<HODigiCollection> ho;
00517 iEvent.getByLabel(inputLabelDigi_,ho);
00518 if(ho.isValid()){
00519 for(HODigiCollection::const_iterator digi=ho->begin();digi!=ho->end();digi++){
00520 eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00521 if((eta>=11 && eta<=15 && phi>=59 && phi<=70) || (eta>=5 && eta<=10 && phi>=47 && phi<=58)){
00522 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-11.0;
00523 }else{
00524 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00525 }
00526 ho_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00527 }
00528 }
00529 edm::Handle<HFDigiCollection> hf;
00530 iEvent.getByLabel(inputLabelDigi_,hf);
00531 if(hf.isValid()){
00532 for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00533 eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00534 for(int i=0;i<nTS;i++) data[i]=adc2fC[digi->sample(i).adc()&0xff]-2.5;
00535 hf_data[eta+42][phi-1][depth-1].add_statistics(data,nTS);
00536 }
00537 }
00538 }else{
00539 edm::Handle<HFDigiCollection> hf;
00540 iEvent.getByLabel(inputLabelDigi_,hf);
00541 if(hf.isValid()){
00542 for(HFDigiCollection::const_iterator digi=hf->begin();digi!=hf->end();digi++){
00543 eta=digi->id().ieta(); phi=digi->id().iphi(); depth=digi->id().depth(); nTS=digi->size();
00544 int N;
00545 for(N=0;N<56;N++)if(eta==RADDAM_CH[N].eta && phi==RADDAM_CH[N].phi) break;
00546 if(N==56) continue;
00547 for(int i=0;i<nTS;i++) Raddam[N]->Fill(i,adc2fC[digi->sample(i).adc()&0xff]-2.5);
00548
00549 }
00550 }
00551 }
00552 }
00553 bool HcalDetDiagLaserMonitor::get_ave_subdet(int sd,float *ave_t,float *ave_e,float *ave_t_r,float *ave_e_r){
00554 double T=0,nT=0,E=0,nE=0,Tr=0,nTr=0,Er=0,nEr=0;
00555 if(sd==HcalBarrel) for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){
00556 for(int depth=1;depth<=2;depth++){
00557 if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
00558 double ave=0,rms=0,time=0,time_rms=0;
00559 hb_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00560 hb_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00561 T+=time; nT++; E+=ave; nE++;
00562 if(hb_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
00563 Tr+=time; nTr++; Er+=ave; nEr++;}
00564 }
00565 }
00566 }
00567
00568 if(sd==HcalEndcap) for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
00569 for(int depth=1;depth<=3;depth++){
00570 if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
00571 double ave=0; double rms=0; double time=0; double time_rms=0;
00572 he_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00573 he_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00574 T+=time; nT++; E+=ave; nE++;
00575 if(he_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
00576 Tr+=time; nTr++; Er+=ave; nEr++;}
00577 }
00578 }
00579 }
00580
00581 if(sd==HcalForward) for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
00582 for(int depth=1;depth<=2;depth++){
00583 if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
00584 double ave=0; double rms=0; double time=0; double time_rms=0;
00585 hf_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00586 hf_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00587 T+=time; nT++; E+=ave; nE++;
00588 if(hf_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
00589 Tr+=time; nTr++; Er+=ave; nEr++;}
00590 }
00591 }
00592 }
00593
00594 if(sd==HcalOuter) for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
00595 for(int depth=4;depth<=4;depth++){
00596 if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
00597 double ave=0; double rms=0; double time=0; double time_rms=0;
00598 ho_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00599 ho_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00600 T+=time; nT++; E+=ave; nE++;
00601 if(ho_data[eta+42][phi-1][depth-1].get_reference(&ave,&rms,&time,&time_rms)){
00602 Tr+=time; nTr++; Er+=ave; nEr++;}
00603 }
00604 }
00605 }
00606 if(nT<200 || nE<200 || nTr<200 || nEr<200) return false;
00607 *ave_t=T/nT;
00608 *ave_e=E/nE;
00609 *ave_t_r=Tr/nTr;
00610 *ave_e_r=Er/nEr;
00611 return true;
00612 }
00613
00614 void HcalDetDiagLaserMonitor::fillProblems(int sd){
00615 float ave_t,ave_e,ave_t_r,ave_e_r;
00616 if(!get_ave_subdet(sd,&ave_t,&ave_e,&ave_t_r,&ave_e_r)) return;
00617
00618 for(int i=0;i<4;i++){
00619 ProblemCellsByDepth_energy->depth[i]->Reset();
00620 ProblemCellsByDepth_timing->depth[i]->Reset();
00621 }
00622
00623 std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
00624 for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
00625 DetId detid=emap->lookup(*eid);
00626 if (detid.det()!=DetId::Hcal) continue;
00627 HcalGenericDetId gid(emap->lookup(*eid));
00628 if (gid.null())
00629 continue;
00630 if (gid.genericSubdet()!=HcalGenericDetId::HcalGenBarrel &&
00631 gid.genericSubdet()!=HcalGenericDetId::HcalGenEndcap &&
00632 gid.genericSubdet()!=HcalGenericDetId::HcalGenForward &&
00633 gid.genericSubdet()!=HcalGenericDetId::HcalGenOuter)
00634 continue;
00635 int eta=0,phi=0,depth=0;
00636 HcalDetId hid(detid);
00637 eta=hid.ieta();
00638 phi=hid.iphi();
00639 depth=hid.depth();
00640
00641 int e=CalcEtaBin(sd,eta,depth)+1;
00642 if(detid.subdetId()==HcalBarrel && sd==HcalBarrel){
00643 double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
00644 if(!hb_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00645 if(!hb_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
00646 if(!hb_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
00647 hb_data[eta+42][phi-1][depth-1].nChecks++;
00648 float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
00649 if(diff_t>LaserTimingThreshold){
00650 hb_data[eta+42][phi-1][depth-1].nBadTime++;
00651 ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
00652 }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0);
00653 if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
00654 float diff_e=((VAL/ave_e))/(val/ave_e_r);
00655 if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
00656 hb_data[eta+42][phi-1][depth-1].nBadEnergy++;
00657 ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
00658 }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
00659 }
00660 }
00661 if(detid.subdetId()==HcalEndcap && sd==HcalEndcap){
00662 double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
00663 if(!he_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00664 if(!he_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
00665 if(!he_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
00666 he_data[eta+42][phi-1][depth-1].nChecks++;
00667 float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
00668 if(diff_t>LaserTimingThreshold){
00669 he_data[eta+42][phi-1][depth-1].nBadTime++;
00670 ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
00671 }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0);
00672 if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
00673 float diff_e=((VAL/ave_e))/(val/ave_e_r);
00674 if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
00675 he_data[eta+42][phi-1][depth-1].nBadEnergy++;
00676 ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
00677 }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
00678 }
00679 }
00680 if(detid.subdetId()==HcalOuter && sd==HcalOuter){
00681 double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
00682 if(!ho_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00683 if(!ho_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
00684 if(!ho_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
00685 ho_data[eta+42][phi-1][depth-1].nChecks++;
00686 float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
00687 if(diff_t>LaserTimingThreshold){
00688 ho_data[eta+42][phi-1][depth-1].nBadTime++;
00689 ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
00690 }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0);
00691 if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
00692 float diff_e=((VAL/ave_e))/(val/ave_e_r);
00693 if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
00694 ho_data[eta+42][phi-1][depth-1].nBadEnergy++;
00695 ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
00696 }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
00697 }
00698 }
00699 if(detid.subdetId()==HcalForward && sd==HcalForward){
00700 double val=0,rms=0,time=0,time_rms=0,VAL=0,RMS=0,TIME=0,TIME_RMS=0;
00701 if(!hf_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00702 if(!hf_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
00703 if(!hf_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
00704 hf_data[eta+42][phi-1][depth-1].nChecks++;
00705 float diff_t=(TIME-ave_t)-(time-ave_t_r); if(diff_t<0) diff_t=-diff_t;
00706 if(diff_t>LaserTimingThreshold){
00707 hf_data[eta+42][phi-1][depth-1].nBadTime++;
00708 ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,(TIME-ave_t)-(time-ave_t_r));
00709 }else ProblemCellsByDepth_timing_val->depth[depth-1]->setBinContent(e,phi,0);
00710 if(VAL!=0 && val!=0 && ave_e!=0 && ave_e_r!=0){
00711 float diff_e=((VAL/ave_e))/(val/ave_e_r);
00712 if(diff_e>(1+LaserEnergyThreshold) ||diff_e<(1-LaserEnergyThreshold) ){
00713 hf_data[eta+42][phi-1][depth-1].nBadEnergy++;
00714 ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,((VAL/ave_e))/(val/ave_e_r));
00715 }else ProblemCellsByDepth_energy_val->depth[depth-1]->setBinContent(e,phi,0);
00716 }
00717 }
00718 }
00719 for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
00720 DetId detid=emap->lookup(*eid);
00721 if (detid.det()!=DetId::Hcal) continue;
00722 HcalGenericDetId gid(emap->lookup(*eid));
00723 if (gid.null())
00724 continue;
00725 if (gid.genericSubdet()!=HcalGenericDetId::HcalGenBarrel &&
00726 gid.genericSubdet()!=HcalGenericDetId::HcalGenEndcap &&
00727 gid.genericSubdet()!=HcalGenericDetId::HcalGenForward &&
00728 gid.genericSubdet()!=HcalGenericDetId::HcalGenOuter)
00729 continue;
00730
00731 int eta=0,phi=0,depth=0;
00732 HcalDetId hid(detid);
00733 eta=hid.ieta();
00734 phi=hid.iphi();
00735 depth=hid.depth();
00736
00737 if(detid.subdetId()==HcalBarrel){
00738 if(hb_data[eta+42][phi-1][depth-1].nBadTime>0){
00739 int e=CalcEtaBin(HcalBarrel,eta,depth)+1;
00740 double val=hb_data[eta+42][phi-1][depth-1].nBadTime/hb_data[eta+42][phi-1][depth-1].nChecks;
00741 ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
00742 }
00743 if(hb_data[eta+42][phi-1][depth-1].nBadEnergy>0){
00744 int e=CalcEtaBin(HcalBarrel,eta,depth)+1;
00745 double val=hb_data[eta+42][phi-1][depth-1].nBadEnergy/hb_data[eta+42][phi-1][depth-1].nChecks;
00746 ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
00747 }
00748 }
00749 if(detid.subdetId()==HcalEndcap){
00750 if(he_data[eta+42][phi-1][depth-1].nBadTime>0){
00751 int e=CalcEtaBin(HcalEndcap,eta,depth)+1;
00752 double val=he_data[eta+42][phi-1][depth-1].nBadTime/he_data[eta+42][phi-1][depth-1].nChecks;
00753 ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
00754 }
00755 if(he_data[eta+42][phi-1][depth-1].nBadEnergy>0){
00756 int e=CalcEtaBin(HcalEndcap,eta,depth)+1;
00757 double val=he_data[eta+42][phi-1][depth-1].nBadEnergy/he_data[eta+42][phi-1][depth-1].nChecks;
00758 ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
00759 }
00760 }
00761 if(detid.subdetId()==HcalOuter){
00762 if(ho_data[eta+42][phi-1][depth-1].nBadTime>0){
00763 int e=CalcEtaBin(HcalOuter,eta,depth)+1;
00764 double val=ho_data[eta+42][phi-1][depth-1].nBadTime/ho_data[eta+42][phi-1][depth-1].nChecks;
00765 ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
00766 }
00767 if(ho_data[eta+42][phi-1][depth-1].nBadEnergy>0){
00768 int e=CalcEtaBin(HcalOuter,eta,depth)+1;
00769 double val=ho_data[eta+42][phi-1][depth-1].nBadEnergy/ho_data[eta+42][phi-1][depth-1].nChecks;
00770 ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
00771 }
00772 }
00773 if(detid.subdetId()==HcalForward){
00774 if(hf_data[eta+42][phi-1][depth-1].nBadTime>0){
00775 int e=CalcEtaBin(HcalForward,eta,depth)+1;
00776 double val=hf_data[eta+42][phi-1][depth-1].nBadTime/hf_data[eta+42][phi-1][depth-1].nChecks;
00777 ProblemCellsByDepth_timing->depth[depth-1]->setBinContent(e,phi,val);
00778 }
00779 if(hf_data[eta+42][phi-1][depth-1].nBadEnergy>0){
00780 int e=CalcEtaBin(HcalForward,eta,depth)+1;
00781 double val=hf_data[eta+42][phi-1][depth-1].nBadEnergy/hf_data[eta+42][phi-1][depth-1].nChecks;
00782 ProblemCellsByDepth_energy->depth[depth-1]->setBinContent(e,phi,val);
00783 }
00784 }
00785 }
00786 }
00787
00788 bool HcalDetDiagLaserMonitor::get_ave_rbx(int sd,int side,int rbx,float *ave,float *rms){
00789 double xt=0,xxt=0;
00790 int eta_min=0,eta_max=0,n=0;
00791 if(sd==HcalBarrel){
00792 if(side>0){eta_min=1; eta_max=29;}
00793 if(side<0){eta_min=-29; eta_max=-1;}
00794 if(rbx==1){
00795 for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++)for(int k=1;k<=3;k++){
00796 double val,rms,time,time_rms;
00797 double TIME,TIME_RMS;
00798 if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00799 if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00800 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00801 }
00802 for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=2;j++)for(int k=1;k<=3;k++){
00803 double val,rms,time,time_rms;
00804 double TIME,TIME_RMS;
00805 if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00806 if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00807 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00808 }
00809
00810 }else{
00811 for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*4-1);j<=((rbx-1)*4+2);j++)for(int k=1;k<=3;k++){
00812 double val,rms,time,time_rms;
00813 double TIME,TIME_RMS;
00814 if(!hb_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00815 if(!hb_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00816 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00817 }
00818 }
00819 }
00820 if(sd==HcalEndcap){
00821 if(side>0){eta_min=1; eta_max=29;}
00822 if(side<0){eta_min=-29; eta_max=-1;}
00823 if(rbx==1){
00824 for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++)for(int k=1;k<=3;k++){
00825 double val,rms,time,time_rms;
00826 double TIME,TIME_RMS;
00827 if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00828 if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00829 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00830 }
00831 for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=2;j++)for(int k=1;k<=3;k++){
00832 double val,rms,time,time_rms;
00833 double TIME,TIME_RMS;
00834 if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00835 if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00836 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00837 }
00838
00839 }else{
00840 for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*4-1);j<=((rbx-1)*4+2);j++)for(int k=1;k<=3;k++){
00841 double val,rms,time,time_rms;
00842 double TIME,TIME_RMS;
00843 if(!he_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00844 if(!he_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00845 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00846 }
00847 }
00848 }
00849 if(sd==HcalForward){
00850 if(side>0){eta_min=29; eta_max=40;}
00851 if(side<0){eta_min=-40; eta_max=-29;}
00852 for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*6+1);j<=((rbx-1)*6+6);j++)for(int k=1;k<=2;k++){
00853 double val,rms,time,time_rms;
00854 double TIME,TIME_RMS;
00855 if(!hf_data[i+42][j-1][k-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00856 if(!hf_data[i+42][j-1][k-1].get_average_time(&TIME,&TIME_RMS)) continue;
00857 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00858 }
00859 }
00860 if(sd==HcalOuter){
00861 if(side==0){
00862 eta_min=-4,eta_max=4;
00863 if(rbx==1){
00864 for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++){
00865 double val,rms,time,time_rms;
00866 double TIME,TIME_RMS;
00867 if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00868 if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
00869 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00870 }
00871 for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=4;j++){
00872 double val,rms,time,time_rms;
00873 double TIME,TIME_RMS;
00874 if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00875 if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
00876 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00877 }
00878
00879 }else{
00880 for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*6-1);j<=((rbx-1)*6+4);j++){
00881 double val,rms,time,time_rms;
00882 double TIME,TIME_RMS;
00883 if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00884 if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
00885 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00886 }
00887 }
00888 }
00889 if(side==-1){ eta_min=-10,eta_max=-5;}
00890 if(side==-2){ eta_min=-15,eta_max=-11;}
00891 if(side==1) { eta_min=5, eta_max=10;}
00892 if(side==2) { eta_min=11, eta_max=15;}
00893 if(side!=0){
00894 if(rbx==1){
00895 for(int i=eta_min;i<=eta_max;i++) for(int j=71;j<=72;j++){
00896 double val,rms,time,time_rms;
00897 double TIME,TIME_RMS;
00898 if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00899 if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
00900 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00901 }
00902 for(int i=eta_min;i<=eta_max;i++) for(int j=1;j<=10;j++){
00903 double val,rms,time,time_rms;
00904 double TIME,TIME_RMS;
00905 if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00906 if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
00907 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00908 }
00909
00910 }else{
00911 for(int i=eta_min;i<=eta_max;i++) for(int j=((rbx-1)*12-1);j<=((rbx-1)*12+10);j++){
00912 double val,rms,time,time_rms;
00913 double TIME,TIME_RMS;
00914 if(!ho_data[i+42][j-1][4-1].get_reference(&val,&rms,&time,&time_rms)) continue;
00915 if(!ho_data[i+42][j-1][4-1].get_average_time(&TIME,&TIME_RMS)) continue;
00916 xt+=TIME-time; xxt+=(TIME-time)*(TIME-time); n++;
00917 }
00918 }
00919 }
00920 }
00921 if(n<10) return false;
00922 *ave=xt/n;
00923 *rms=sqrt(xxt/n-(xt*xt)/(n*n));
00924 return true;
00925 }
00926
00927
00928 void HcalDetDiagLaserMonitor::fillHistos(int sd){
00929 if(sd==HcalBarrel || sd==HcalEndcap){
00930 hbheEnergy->Reset();
00931 hbheTime->Reset();
00932 hbheEnergyRMS->Reset();
00933 hbheTimeRMS->Reset();
00934 hb_time_rbx->Reset();
00935 he_time_rbx->Reset();
00936 }
00937 if(sd==HcalOuter){
00938 hoEnergy->Reset();
00939 hoTime->Reset();
00940 hoEnergyRMS->Reset();
00941 hoTimeRMS->Reset();
00942 Time2Dho->Reset();
00943 Energy2Dho->Reset();
00944 refTime2Dho->Reset();
00945 refEnergy2Dho->Reset();
00946 ho_time_rbx->Reset();
00947 }
00948 if(sd==HcalForward){
00949 hfEnergy->Reset();
00950 hfTime->Reset();
00951 hfEnergyRMS->Reset();
00952 hfTimeRMS->Reset();
00953 hf_time_rbx->Reset();
00954 }
00955 if(sd==HcalBarrel || sd==HcalEndcap){
00956
00957 for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){
00958 double T=0,nT=0,E=0,nE=0;
00959 for(int depth=1;depth<=2;depth++){
00960 if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
00961 double ave=0;
00962 double rms=0;
00963 double time=0;
00964 double time_rms=0;
00965 hb_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00966 hb_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00967 hbheEnergy->Fill(ave);
00968 if(ave>0)hbheEnergyRMS->Fill(rms/ave);
00969 hbheTime->Fill(time);
00970 hbheTimeRMS->Fill(time_rms);
00971 T+=time; nT++; E+=ave; nE++;
00972 }
00973 }
00974 if(nT>0){Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT);Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); }
00975 }
00976
00977 for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
00978 double T=0,nT=0,E=0,nE=0;
00979 for(int depth=1;depth<=3;depth++){
00980 if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
00981 double ave=0; double rms=0; double time=0; double time_rms=0;
00982 he_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
00983 he_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
00984 hbheEnergy->Fill(ave);
00985 if(ave>0)hbheEnergyRMS->Fill(rms/ave);
00986 hbheTime->Fill(time);
00987 hbheTimeRMS->Fill(time_rms);
00988 T+=time; nT++; E+=ave; nE++;
00989 }
00990 }
00991 if(nT>0 && abs(eta)>16 ){Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT); Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); }
00992 if(nT>0 && abs(eta)>20 ){Time2Dhbhehf->setBinContent(eta+44,phi+2,T/nT); Energy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);}
00993 }
00994 }
00995 if(sd==HcalForward){
00996
00997 for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
00998 double T=0,nT=0,E=0,nE=0;
00999 for(int depth=1;depth<=2;depth++){
01000 if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
01001 double ave=0; double rms=0; double time=0; double time_rms=0;
01002 hf_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
01003 hf_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
01004 hfEnergy->Fill(ave);
01005 if(ave>0)hfEnergyRMS->Fill(rms/ave);
01006 hfTime->Fill(time);
01007 T+=time; nT++; E+=ave; nE++;
01008 hfTimeRMS->Fill(time_rms);
01009 }
01010 }
01011 if(nT>0 && abs(eta)>29 ){ Time2Dhbhehf->setBinContent(eta+44,phi+1,T/nT); Time2Dhbhehf->setBinContent(eta+44,phi+2,T/nT);}
01012 if(nT>0 && abs(eta)>29 ){ Energy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE); Energy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);}
01013 }
01014 }
01015 if(sd==HcalOuter){
01016
01017 for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
01018 double T=0,nT=0,E=0,nE=0;
01019 for(int depth=4;depth<=4;depth++){
01020 if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
01021 double ave=0; double rms=0; double time=0; double time_rms=0;
01022 ho_data[eta+42][phi-1][depth-1].get_average_amp(&ave,&rms);
01023 ho_data[eta+42][phi-1][depth-1].get_average_time(&time,&time_rms);
01024 hoEnergy->Fill(ave);
01025 if(ave>0)hoEnergyRMS->Fill(rms/ave);
01026 hoTime->Fill(time);
01027 T+=time; nT++; E+=ave; nE++;
01028 hoTimeRMS->Fill(time_rms);
01029 }
01030 }
01031 if(nT>0){ Time2Dho->Fill(eta,phi,T/nT); Energy2Dho->Fill(eta,phi+1,E/nE) ;}
01032 }
01033 }
01034
01035
01036 if(sd==HcalBarrel || sd==HcalEndcap){
01037 for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++){
01038 double T=0,nT=0,E=0,nE=0;
01039 for(int depth=1;depth<=2;depth++){
01040 if(hb_data[eta+42][phi-1][depth-1].get_statistics()>10){
01041 double val=0,rms=0,time=0,time_rms=0;
01042 double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
01043 if(!hb_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01044 if(!hb_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
01045 if(!hb_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
01046 E+=VAL/val; nE++;
01047 T+=TIME-time; nT++;
01048 }
01049 }
01050 if(nE>0) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);
01051 if(nT>0){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+1,TTT); }
01052 }
01053 for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++){
01054 double T=0,nT=0,E=0,nE=0;
01055 for(int depth=1;depth<=3;depth++){
01056 if(he_data[eta+42][phi-1][depth-1].get_statistics()>10){
01057 double val=0,rms=0,time=0,time_rms=0;
01058 double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
01059 if(!he_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01060 if(!he_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
01061 if(!he_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
01062 E+=VAL/val; nE++;
01063 T+=TIME-time; nT++;
01064 }
01065 }
01066 if(nE>0 && abs(eta)>16) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);
01067 if(nT>0 && abs(eta)>16){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+1,TTT); }
01068 if(nE>0 && abs(eta)>20) refEnergy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);
01069 if(nT>0 && abs(eta)>20){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+2,TTT); }
01070 }
01071 }
01072 if(sd==HcalForward){
01073 for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++){
01074 double T=0,nT=0,E=0,nE=0;
01075 for(int depth=1;depth<=2;depth++){
01076 if(hf_data[eta+42][phi-1][depth-1].get_statistics()>10){
01077 double val=0,rms=0,time=0,time_rms=0;
01078 double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
01079 if(!hf_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01080 if(!hf_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
01081 if(!hf_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
01082 E+=VAL/val; nE++;
01083 T+=TIME-time; nT++;
01084 }
01085 }
01086 if(nE>0 && abs(eta)>29) refEnergy2Dhbhehf->setBinContent(eta+44,phi+1,E/nE);
01087 if(nT>0 && abs(eta)>29){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+1,TTT); }
01088 if(nE>0 && abs(eta)>29) refEnergy2Dhbhehf->setBinContent(eta+44,phi+2,E/nE);
01089 if(nT>0 && abs(eta)>29){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dhbhehf->setBinContent(eta+44,phi+2,TTT); }
01090 }
01091 }
01092 if(sd==HcalOuter){
01093 for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++){
01094 double T=0,nT=0,E=0,nE=0;
01095 for(int depth=4;depth<=4;depth++){
01096 if(ho_data[eta+42][phi-1][depth-1].get_statistics()>10){
01097 double val=0,rms=0,time=0,time_rms=0;
01098 double VAL=0,RMS=0,TIME=0,TIME_RMS=0;
01099 if(!ho_data[eta+42][phi-1][depth-1].get_reference(&val,&rms,&time,&time_rms)) continue;
01100 if(!ho_data[eta+42][phi-1][depth-1].get_average_amp(&VAL,&RMS)) continue;
01101 if(!ho_data[eta+42][phi-1][depth-1].get_average_time(&TIME,&TIME_RMS)) continue;
01102 E+=VAL/val; nE++;
01103 T+=TIME-time; nT++;
01104 }
01105 }
01106 if(nE>0) refEnergy2Dho->Fill(eta,phi,E/nE);
01107 if(nT>0){ double TTT=T/nT+1; if(TTT<0.01) TTT=0.01; refTime2Dho->Fill(eta,phi,TTT);}
01108 }
01109 }
01111 float min,max;
01112 if(sd==HcalBarrel || sd==HcalEndcap){
01113 min=100;max=-100;
01114 for(int i=1;i<=18;i++){
01115 float ave=-10,rms=-10;
01116 if(get_ave_rbx(HcalBarrel,-1,i,&ave,&rms)){
01117 hb_time_rbx->setBinContent(i,ave);
01118 hb_time_rbx->setBinError(i,rms);
01119 if(ave<min) min=ave;
01120 if(ave>max) max=ave;
01121 }
01122 }
01123 for(int i=1;i<=18;i++){
01124 float ave=-10,rms=-10;
01125 if(get_ave_rbx(HcalBarrel,1,i,&ave,&rms)){
01126 hb_time_rbx->setBinContent(i+18,ave);
01127 hb_time_rbx->setBinError(i+18,rms);
01128 if(ave<min) min=ave;
01129 if(ave>max) max=ave;
01130 }
01131 }
01132 if(max>-100)hb_time_rbx->setAxisRange(min-1,max+1,2);
01133 min=100;max=-100;
01134 for(int i=1;i<=18;i++){
01135 float ave=-10,rms=-10;
01136 if(get_ave_rbx(HcalEndcap,-1,i,&ave,&rms)){
01137 he_time_rbx->setBinContent(i,ave);
01138 he_time_rbx->setBinError(i,rms);
01139 if(ave<min) min=ave;
01140 if(ave>max) max=ave;
01141 }
01142 }
01143 for(int i=1;i<=18;i++){
01144 float ave=-10,rms=-10;
01145 if(get_ave_rbx(HcalEndcap,1,i,&ave,&rms)){
01146 he_time_rbx->setBinContent(i+18,ave);
01147 he_time_rbx->setBinError(i+18,rms);
01148 if(ave<min) min=ave;
01149 if(ave>max) max=ave;
01150 }
01151 }
01152 if(max>-100)he_time_rbx->setAxisRange(min-1,max+1,2);
01153 }
01155 if(sd==HcalOuter){
01156 min=100;max=-100;
01157 for(int i=1;i<=6;i++){
01158 float ave=-10,rms=-10;
01159 if(get_ave_rbx(HcalOuter,-2,i,&ave,&rms)){
01160 ho_time_rbx->setBinContent(i,ave);
01161 ho_time_rbx->setBinError(i,rms);
01162 if(ave<min) min=ave;
01163 if(ave>max) max=ave;
01164 }
01165 }
01166 for(int i=1;i<=6;i++){
01167 float ave=-10,rms=-10;
01168 if(get_ave_rbx(HcalOuter,-1,i,&ave,&rms)){
01169 ho_time_rbx->setBinContent(i+6,ave);
01170 ho_time_rbx->setBinError(i+6,rms);
01171 if(ave<min) min=ave;
01172 if(ave>max) max=ave;
01173 }
01174 }
01175 for(int i=1;i<=12;i++){
01176 float ave=-10,rms=-10;
01177 if(get_ave_rbx(HcalOuter,0,i,&ave,&rms)){
01178 ho_time_rbx->setBinContent(i+12,ave);
01179 ho_time_rbx->setBinError(i+12,rms);
01180 if(ave<min) min=ave;
01181 if(ave>max) max=ave;
01182 }
01183 }
01184 for(int i=1;i<=6;i++){
01185 float ave=-10,rms=-10;
01186 if(get_ave_rbx(HcalOuter,1,i,&ave,&rms)){
01187 ho_time_rbx->setBinContent(i+24,ave);
01188 ho_time_rbx->setBinError(i+24,rms);
01189 if(ave<min) min=ave;
01190 if(ave>max) max=ave;
01191 }
01192 }
01193 for(int i=1;i<=6;i++){
01194 float ave=-10,rms=-10;
01195 if(get_ave_rbx(HcalOuter,2,i,&ave,&rms)){
01196 ho_time_rbx->setBinContent(i+30,ave);
01197 ho_time_rbx->setBinError(i+30,rms);
01198 if(ave<min) min=ave;
01199 if(ave>max) max=ave;
01200 }
01201 }
01202 if(max>-100)ho_time_rbx->setAxisRange(min-1,max+1,2);
01203 }
01205 if(sd==HcalForward){
01206 min=100;max=-100;
01207 for(int i=1;i<=12;i++){
01208 float ave=-10,rms=-10;
01209 if(get_ave_rbx(HcalForward,-1,i,&ave,&rms)){
01210 hf_time_rbx->setBinContent(i,ave);
01211 hf_time_rbx->setBinError(i,rms);
01212 if(ave<min) min=ave;
01213 if(ave>max) max=ave;
01214 }
01215 }
01216 for(int i=1;i<=12;i++){
01217 float ave=-10,rms=-10;
01218 if(get_ave_rbx(HcalForward,1,i,&ave,&rms)){
01219 hf_time_rbx->setBinContent(i+12,ave);
01220 hf_time_rbx->setBinError(i+12,rms);
01221 if(ave<min) min=ave;
01222 if(ave>max) max=ave;
01223 }
01224 }
01225 if(max>-100)hf_time_rbx->setAxisRange(min-1,max+1,2);
01226 }
01227 }
01228
01229 void HcalDetDiagLaserMonitor::SaveReference(){
01230 double amp,rms,Time,time_rms;
01231 int Eta,Phi,Depth,Statistic,Status=0;
01232 char Subdet[10],str[500];
01233 if(OutputFilePath.size()>0){
01234 if(!Overwrite){
01235 sprintf(str,"%sHcalDetDiagLaserData_run%06i_%i.root",OutputFilePath.c_str(),run_number,dataset_seq_number);
01236 }else{
01237 sprintf(str,"%sHcalDetDiagLaserData.root",OutputFilePath.c_str());
01238 }
01239 TFile *theFile = new TFile(str, "RECREATE");
01240 if(!theFile->IsOpen()) return;
01241 theFile->cd();
01242 sprintf(str,"%d",run_number); TObjString run(str); run.Write("run number");
01243 sprintf(str,"%d",ievt_); TObjString events(str); events.Write("Total events processed");
01244 sprintf(str,"%d",dataset_seq_number); TObjString dsnum(str); dsnum.Write("Dataset number");
01245 Long_t t; t=time(0); strftime(str,30,"%F %T",localtime(&t)); TObjString tm(str); tm.Write("Dataset creation time");
01246
01247 TTree *tree =new TTree("HCAL Laser data","HCAL Laser data");
01248 if(tree==0) return;
01249 tree->Branch("Subdet", &Subdet, "Subdet/C");
01250 tree->Branch("eta", &Eta, "Eta/I");
01251 tree->Branch("phi", &Phi, "Phi/I");
01252 tree->Branch("depth", &Depth, "Depth/I");
01253 tree->Branch("statistic",&Statistic, "Statistic/I");
01254 tree->Branch("status", &Status, "Status/I");
01255 tree->Branch("amp", &, "amp/D");
01256 tree->Branch("rms", &rms, "rms/D");
01257 tree->Branch("time", &Time, "time/D");
01258 tree->Branch("time_rms", &time_rms, "time_rms/D");
01259 sprintf(Subdet,"HB");
01260 for(int eta=-16;eta<=16;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
01261 if((Statistic=hb_data[eta+42][phi-1][depth-1].get_statistics1())>10){
01262 Eta=eta; Phi=phi; Depth=depth;
01263 Status=hb_data[eta+42][phi-1][depth-1].get_status();
01264 hb_data[eta+42][phi-1][depth-1].get_average_amp1(&,&rms);
01265 hb_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
01266 tree->Fill();
01267 }
01268 }
01269 sprintf(Subdet,"HE");
01270 for(int eta=-29;eta<=29;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=3;depth++){
01271 if((Statistic=he_data[eta+42][phi-1][depth-1].get_statistics1())>10){
01272 Eta=eta; Phi=phi; Depth=depth;
01273 Status=he_data[eta+42][phi-1][depth-1].get_status();
01274 he_data[eta+42][phi-1][depth-1].get_average_amp1(&,&rms);
01275 he_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
01276 tree->Fill();
01277 }
01278 }
01279 sprintf(Subdet,"HO");
01280 for(int eta=-15;eta<=15;eta++) for(int phi=1;phi<=72;phi++) for(int depth=4;depth<=4;depth++){
01281 if((Statistic=ho_data[eta+42][phi-1][depth-1].get_statistics1())>10){
01282 Eta=eta; Phi=phi; Depth=depth;
01283 Status=ho_data[eta+42][phi-1][depth-1].get_status();
01284 ho_data[eta+42][phi-1][depth-1].get_average_amp1(&,&rms);
01285 ho_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
01286 tree->Fill();
01287 }
01288 }
01289 sprintf(Subdet,"HF");
01290 for(int eta=-42;eta<=42;eta++) for(int phi=1;phi<=72;phi++) for(int depth=1;depth<=2;depth++){
01291 if((Statistic=hf_data[eta+42][phi-1][depth-1].get_statistics1())>10){
01292 Eta=eta; Phi=phi; Depth=depth;
01293 Status=hf_data[eta+42][phi-1][depth-1].get_status();
01294 hf_data[eta+42][phi-1][depth-1].get_average_amp1(&,&rms);
01295 hf_data[eta+42][phi-1][depth-1].get_average_time1(&Time,&time_rms);
01296 tree->Fill();
01297 }
01298 }
01299 theFile->Write();
01300 theFile->Close();
01301 }
01302 if(XmlFilePath.size()>0){
01303
01304 if(!Overwrite){
01305 sprintf(str,"HcalDetDiagLaser_%i_%i.xml",run_number,dataset_seq_number);
01306 }else{
01307 sprintf(str,"HcalDetDiagLaser.xml");
01308 }
01309 std::string xmlName=str;
01310 ofstream xmlFile;
01311 xmlFile.open(xmlName.c_str());
01312
01313 xmlFile<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
01314 xmlFile<<"<ROOT>\n";
01315 xmlFile<<" <HEADER>\n";
01316 xmlFile<<" <HINTS mode='only-det-root'/>\n";
01317 xmlFile<<" <TYPE>\n";
01318 xmlFile<<" <EXTENSION_TABLE_NAME>HCAL_DETMON_LED_LASER_V1</EXTENSION_TABLE_NAME>\n";
01319 xmlFile<<" <NAME>HCAL Laser HBHE HPD [abort gap global]</NAME>\n";
01320 xmlFile<<" </TYPE>\n";
01321 xmlFile<<" <!-- run details -->\n";
01322 xmlFile<<" <RUN>\n";
01323 xmlFile<<" <RUN_TYPE>GLOBAL-RUN</RUN_TYPE>\n";
01324 xmlFile<<" <RUN_NUMBER>"<<run_number<<"</RUN_NUMBER>\n";
01325 xmlFile<<" <RUN_BEGIN_TIMESTAMP>2009-01-01 00:00:00</RUN_BEGIN_TIMESTAMP>\n";
01326 xmlFile<<" <COMMENT_DESCRIPTION>hcal laser data</COMMENT_DESCRIPTION>\n";
01327 xmlFile<<" <LOCATION>P5</LOCATION>\n";
01328 xmlFile<<" <INITIATED_BY_USER>dma</INITIATED_BY_USER>\n";
01329 xmlFile<<" </RUN>\n";
01330 xmlFile<<" </HEADER>\n";
01331 xmlFile<<" <DATA_SET>\n";
01332 xmlFile<<" <!-- optional dataset metadata -->\n\n";
01333 xmlFile<<" <SET_NUMBER>"<<dataset_seq_number<<"</SET_NUMBER>\n";
01334 xmlFile<<" <SET_BEGIN_TIMESTAMP>2009-01-01 00:00:00</SET_BEGIN_TIMESTAMP>\n";
01335 xmlFile<<" <SET_END_TIMESTAMP>2009-01-01 00:00:00</SET_END_TIMESTAMP>\n";
01336 xmlFile<<" <NUMBER_OF_EVENTS_IN_SET>"<<ievt_<<"</NUMBER_OF_EVENTS_IN_SET>\n";
01337 xmlFile<<" <COMMENT_DESCRIPTION>Automatic DQM output</COMMENT_DESCRIPTION>\n";
01338 xmlFile<<" <DATA_FILE_NAME>"<< xmlName <<"</DATA_FILE_NAME>\n";
01339 xmlFile<<" <IMAGE_FILE_NAME>data plot url or file path</IMAGE_FILE_NAME>\n";
01340 xmlFile<<" <!-- who and when created this dataset-->\n\n";
01341 Long_t t; t=time(0); strftime(str,30,"%F %T",localtime(&t));
01342 xmlFile<<" <CREATE_TIMESTAMP>"<<str<<"</CREATE_TIMESTAMP>\n";
01343 xmlFile<<" <CREATED_BY_USER>dma</CREATED_BY_USER>\n";
01344 xmlFile<<" <!-- version (string) and subversion (number) -->\n";
01345 xmlFile<<" <!-- fields are used to read data back from the database -->\n\n";
01346 xmlFile<<" <VERSION>"<<run_number<<dataset_seq_number<<"</VERSION>\n";
01347 xmlFile<<" <SUBVERSION>1</SUBVERSION>\n";
01348 xmlFile<<" <!-- Assign predefined dataset attributes -->\n\n";
01349 xmlFile<<" <PREDEFINED_ATTRIBUTES>\n";
01350 xmlFile<<" <ATTRIBUTE>\n";
01351 xmlFile<<" <NAME>HCAL Dataset Status</NAME>\n";
01352 xmlFile<<" <VALUE>VALID</VALUE>\n";
01353 xmlFile<<" </ATTRIBUTE>\n";
01354 xmlFile<<" </PREDEFINED_ATTRIBUTES>\n";
01355 xmlFile<<" <!-- multiple data block records -->\n\n";
01356
01357 std::vector <HcalElectronicsId> AllElIds = emap->allElectronicsIdPrecision();
01358 for(std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin(); eid != AllElIds.end(); eid++){
01359 DetId detid=emap->lookup(*eid);
01360 if (detid.det()!=DetId::Hcal) continue;
01361 HcalGenericDetId gid(emap->lookup(*eid));
01362 if (gid.null())
01363 continue;
01364 if (gid.genericSubdet()!=HcalGenericDetId::HcalGenBarrel &&
01365 gid.genericSubdet()!=HcalGenericDetId::HcalGenEndcap &&
01366 gid.genericSubdet()!=HcalGenericDetId::HcalGenForward &&
01367 gid.genericSubdet()!=HcalGenericDetId::HcalGenOuter)
01368 continue;
01369 int eta,phi,depth;
01370 std::string subdet="";
01371 HcalDetId hid(detid);
01372 eta=hid.ieta();
01373 phi=hid.iphi();
01374 depth=hid.depth();
01375
01376 double e=0,e_rms=0,t=0,t_rms=0;
01377 if(detid.subdetId()==HcalBarrel){
01378 subdet="HB";
01379 Statistic=hb_data[eta+42][phi-1][depth-1].get_statistics1();
01380 Status =hb_data[eta+42][phi-1][depth-1].get_status();
01381 hb_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
01382 hb_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
01383 }else if(detid.subdetId()==HcalEndcap){
01384 subdet="HE";
01385 Statistic=he_data[eta+42][phi-1][depth-1].get_statistics1();
01386 Status =he_data[eta+42][phi-1][depth-1].get_status();
01387 he_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
01388 he_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
01389 }else if(detid.subdetId()==HcalForward){
01390 subdet="HF";
01391 Statistic=hf_data[eta+42][phi-1][depth-1].get_statistics1();
01392 Status =hf_data[eta+42][phi-1][depth-1].get_status();
01393 hf_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
01394 hf_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
01395 }else if(detid.subdetId()==HcalOuter){
01396 subdet="HO";
01397 Statistic=ho_data[eta+42][phi-1][depth-1].get_statistics1();
01398 Status =ho_data[eta+42][phi-1][depth-1].get_status();
01399 ho_data[eta+42][phi-1][depth-1].get_average_amp1(&e,&e_rms);
01400 ho_data[eta+42][phi-1][depth-1].get_average_time1(&t,&t_rms);
01401 }else continue;
01402 xmlFile<<" <DATA>\n";
01403 xmlFile<<" <NUMBER_OF_EVENTS_USED>"<<Statistic<<"</NUMBER_OF_EVENTS_USED>\n";
01404 xmlFile<<" <SIGNAL_MEAN>"<<e<<"</SIGNAL_MEAN>\n";
01405 xmlFile<<" <SIGNAL_RMS>"<<e_rms<<"</SIGNAL_RMS>\n";
01406 xmlFile<<" <TIME_MEAN>"<<t<<"</TIME_MEAN>\n";
01407 xmlFile<<" <TIME_RMS>"<<t_rms<<"</TIME_RMS>\n";
01408 xmlFile<<" <CHANNEL_STATUS_WORD>"<<Status<<"</CHANNEL_STATUS_WORD>\n";
01409 xmlFile<<" <CHANNEL_OBJECTNAME>HcalDetId</CHANNEL_OBJECTNAME>\n";
01410 xmlFile<<" <SUBDET>"<<subdet<<"</SUBDET>\n";
01411 xmlFile<<" <IETA>"<<eta<<"</IETA>\n";
01412 xmlFile<<" <IPHI>"<<phi<<"</IPHI>\n";
01413 xmlFile<<" <DEPTH>"<<depth<<"</DEPTH>\n";
01414 xmlFile<<" <TYPE>0</TYPE>\n";
01415 xmlFile<<" </DATA>\n";
01416 }
01418 xmlFile<<" </DATA_SET>\n";
01419 xmlFile<<"</ROOT>\n";
01420 xmlFile.close();
01421 sprintf(str,"zip %s.zip %s",xmlName.c_str(),xmlName.c_str());
01422 system(str);
01423 sprintf(str,"rm -f %s",xmlName.c_str());
01424 system(str);
01425 sprintf(str,"mv -f %s.zip %s",xmlName.c_str(),XmlFilePath.c_str());
01426 system(str);
01427 }
01428 for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) hb_data[i][j][k].reset1();
01429 for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) he_data[i][j][k].reset1();
01430 for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) ho_data[i][j][k].reset1();
01431 for(int i=0;i<85;i++)for(int j=0;j<72;j++)for(int k=0;k<4;k++) hf_data[i][j][k].reset1();
01432 ievt_=0;
01433 dataset_seq_number++;
01434 }
01435 void HcalDetDiagLaserMonitor::LoadReference(){
01436 double amp,rms,time,time_rms;
01437 int Eta,Phi,Depth;
01438 char subdet[10];
01439 TFile *f;
01440 if(gSystem->AccessPathName(ReferenceData.c_str())) return;
01441 f = new TFile(ReferenceData.c_str(),"READ");
01442
01443 if(!f->IsOpen()) return ;
01444 TObjString *STR=(TObjString *)f->Get("run number");
01445
01446 if(STR){ std::string Ref(STR->String()); ReferenceRun=Ref;}
01447
01448 TTree* t=(TTree*)f->Get("HCAL Laser data");
01449 if(!t) return;
01450 t->SetBranchAddress("Subdet", subdet);
01451 t->SetBranchAddress("eta", &Eta);
01452 t->SetBranchAddress("phi", &Phi);
01453 t->SetBranchAddress("depth", &Depth);
01454 t->SetBranchAddress("amp", &);
01455 t->SetBranchAddress("rms", &rms);
01456 t->SetBranchAddress("time", &time);
01457 t->SetBranchAddress("time_rms", &time_rms);
01458
01459 for(int ievt=0;ievt<t->GetEntries();ievt++){
01460 t->GetEntry(ievt);
01461 if(strcmp(subdet,"HB")==0) hb_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
01462 if(strcmp(subdet,"HE")==0) he_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
01463 if(strcmp(subdet,"HO")==0) ho_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
01464 if(strcmp(subdet,"HF")==0) hf_data[Eta+42][Phi-1][Depth-1].set_reference(amp,rms,time,time_rms);
01465 }
01466 f->Close();
01467 IsReference=true;
01468 }
01469
01470 void HcalDetDiagLaserMonitor::endRun(const edm::Run& run, const edm::EventSetup& c) {
01471 if((LocalRun || !Online_) && ievt_>10){
01472 fillHistos(HcalBarrel);
01473 fillHistos(HcalOuter);
01474 fillHistos(HcalForward);
01475 fillProblems(HcalBarrel);
01476 fillProblems(HcalEndcap);
01477 fillProblems(HcalOuter);
01478 fillProblems(HcalForward);
01479 SaveReference();
01480 }
01481 }
01482
01483 void HcalDetDiagLaserMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c){}
01484 void HcalDetDiagLaserMonitor::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c){}
01485
01486
01487 DEFINE_FWK_MODULE(HcalDetDiagLaserMonitor);