CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/EcalEndcapMonitorTasks/src/EEBeamCaloTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EEBeamCaloTask.cc
00003  *
00004  * $Date: 2010/08/30 13:14:09 $
00005  * $Revision: 1.42 $
00006  * \author A. Ghezzi
00007  *
00008  */
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 
00016 #include "DQMServices/Core/interface/MonitorElement.h"
00017 
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 
00020 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00021 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00022 #include "DataFormats/EcalDigi/interface/EBDataFrame.h"
00023 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00024 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00025 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00026 
00027 #include "TBDataFormats/EcalTBObjects/interface/EcalTBCollections.h"
00028 
00029 #include "DQM/EcalCommon/interface/Numbers.h"
00030 
00031 #include "DQM/EcalEndcapMonitorTasks/interface/EEBeamCaloTask.h"
00032 
00033 EEBeamCaloTask::EEBeamCaloTask(const edm::ParameterSet& ps){
00034 
00035   init_ = false;
00036 
00037   dqmStore_ = edm::Service<DQMStore>().operator->();
00038 
00039   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00040 
00041   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00042 
00043   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00044 
00045   EcalTBEventHeader_ = ps.getParameter<edm::InputTag>("EcalTBEventHeader");
00046   EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
00047   EBDigiCollection_ = ps.getParameter<edm::InputTag>("EBDigiCollection");
00048   EcalUncalibratedRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalUncalibratedRecHitCollection");
00049 
00050   for (int i = 0; i < cryInArray_ ; i++) {
00051     meBBCaloPulseProf_[i]=0;
00052     meBBCaloPulseProfG12_[i]=0;
00053     meBBCaloGains_[i]=0;
00054     meBBCaloEne_[i]=0;
00055 
00056     //meBBCaloPulseProfMoving_[i]=0;
00057     //meBBCaloPulseProfG12Moving_[i]=0;
00058     //meBBCaloGainsMoving_[i]=0;
00059     //meBBCaloEneMoving_[i]=0;
00060   }
00061 
00062   meBBCaloCryRead_ = 0;
00063   //meBBCaloCryReadMoving_ = 0;
00064 
00065   meBBNumCaloCryRead_ = 0;
00066   meBBCaloAllNeededCry_ = 0;
00067 
00068   meBBCaloE3x3_ = 0;
00069   meBBCaloE3x3Moving_ = 0;
00070 
00071   meBBCaloCryOnBeam_ = 0;
00072   meBBCaloMaxEneCry_ = 0;
00073   TableMoving_ = 0;
00074 
00075   CrystalsDone_ = 0;
00076   CrystalInBeam_vs_Event_ = 0;
00077   meEEBCaloReadCryErrors_ = 0;
00078   meEEBCaloE1vsCry_ = 0;
00079   meEEBCaloE3x3vsCry_ = 0;
00080   meEEBCaloEntriesVsCry_ = 0;
00081   meEEBCaloBeamCentered_ = 0;
00082 
00083   meEEBCaloE1MaxCry_ = 0;
00084 //   for(int u=0;u<851;u++){
00085 //     meBBCaloE3x3Cry_[u]=0;
00086 //     meBBCaloE1Cry_[u]=0;
00087 //   }
00088 
00089   meEEBCaloDesync_ = 0;
00090 
00091 }
00092 
00093 EEBeamCaloTask::~EEBeamCaloTask(){
00094 
00095 }
00096 
00097 void EEBeamCaloTask::beginJob(void){
00098 
00099   ievt_ = 0;
00100 
00101   profileArranged_ = false;
00102 
00103   if ( dqmStore_ ) {
00104     dqmStore_->setCurrentFolder(prefixME_ + "/EEBeamCaloTask");
00105     dqmStore_->rmdir(prefixME_ + "/EEBeamCaloTask");
00106   }
00107 
00108 }
00109 
00110 void EEBeamCaloTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00111 
00112   Numbers::initGeometry(c, false);
00113 
00114   if ( ! mergeRuns_ ) this->reset();
00115 
00116 }
00117 
00118 void EEBeamCaloTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00119 
00120 }
00121 
00122 void EEBeamCaloTask::reset(void) {
00123 
00124     for (int i = 0; i < cryInArray_ ; i++) {
00125       if ( meBBCaloPulseProf_[i] ) meBBCaloPulseProf_[i]->Reset();
00126       if ( meBBCaloPulseProfG12_[i] ) meBBCaloPulseProfG12_[i]->Reset();
00127       if ( meBBCaloGains_[i] ) meBBCaloGains_[i]->Reset();
00128       if ( meBBCaloEne_[i] ) meBBCaloEne_[i]->Reset();
00129 
00130 //       if ( meBBCaloPulseProfMoving_[i] ) meBBCaloPulseProfMoving_[i]->Reset();
00131 //       if ( meBBCaloPulseProfG12Moving_[i] ) meBBCaloPulseProfG12Moving_[i]->Reset();
00132 //       if ( meBBCaloGainsMoving_[i] ) meBBCaloGainsMoving_[i]->Reset();
00133 //       if ( meBBCaloEneMoving_[i] ) meBBCaloEneMoving_[i]->Reset();
00134     }
00135 
00136 //     for(int u=0; u< 1701;u++){
00137 //       if ( meBBCaloE3x3Cry_[u] ) meBBCaloE3x3Cry_[u]->Reset();
00138 //       if ( meBBCaloE1Cry_[u] ) meBBCaloE1Cry_[u]->Reset();
00139 //     }
00140 
00141     if ( meBBCaloCryRead_ ) meBBCaloCryRead_->Reset();
00142 //    if ( meBBCaloCryReadMoving_ ) meBBCaloCryReadMoving_->Reset();
00143     if ( meBBCaloAllNeededCry_ ) meBBCaloAllNeededCry_->Reset();
00144     if ( meBBNumCaloCryRead_ ) meBBNumCaloCryRead_->Reset();
00145     if ( meBBCaloE3x3_ ) meBBCaloE3x3_->Reset();
00146     if ( meBBCaloE3x3Moving_ ) meBBCaloE3x3Moving_->Reset();
00147     if ( meBBCaloCryOnBeam_ ) meBBCaloCryOnBeam_->Reset();
00148     if ( meBBCaloMaxEneCry_ ) meBBCaloMaxEneCry_->Reset();
00149     if ( TableMoving_ ) TableMoving_->Reset();
00150     if ( CrystalsDone_ ) CrystalsDone_->Reset();
00151     if ( CrystalInBeam_vs_Event_ ) CrystalInBeam_vs_Event_->Reset();
00152     if( meEEBCaloReadCryErrors_ ) meEEBCaloReadCryErrors_->Reset();
00153     if( meEEBCaloE1vsCry_ ) meEEBCaloE1vsCry_->Reset();
00154     if( meEEBCaloE3x3vsCry_ ) meEEBCaloE3x3vsCry_->Reset();
00155     if( meEEBCaloEntriesVsCry_ )  meEEBCaloEntriesVsCry_->Reset();
00156     if( meEEBCaloBeamCentered_ ) meEEBCaloBeamCentered_->Reset();
00157     if( meEEBCaloE1MaxCry_ ) meEEBCaloE1MaxCry_->Reset();
00158     if( meEEBCaloDesync_ ) meEEBCaloDesync_->Reset();
00159 
00160 }
00161 
00162 void EEBeamCaloTask::setup(void){
00163 
00164   init_ = true;
00165   profileArranged_= false;
00166   char histo[200];
00167 
00168   PreviousTableStatus_[0]=0;//let's start with stable...
00169   PreviousTableStatus_[1]=0;//let's start with stable...
00170 
00171   PreviousCrystalinBeam_[0] = 0;
00172   PreviousCrystalinBeam_[1] = 0;
00173   PreviousCrystalinBeam_[2] = -1;
00174   // PreviousCrystalinBeam_[2] = -1 is needed to have a correct step vs cry matching
00175   lastStableStatus_=0;
00176   for(int u=0;u<10;u++){cib_[u]=0;}
00177   changed_tb_status_= false;
00178   changed_cry_in_beam_ = false;
00179   evt_after_change_ =0;
00180   wasFakeChange_= false;
00181   table_step_=1;
00182   crystal_step_=1;
00183   event_last_reset_ = 0;
00184   last_cry_in_beam_ = 0;
00185   previous_cry_in_beam_ = 1;
00186 
00187   if ( dqmStore_ ) {
00188     dqmStore_->setCurrentFolder(prefixME_ + "/EEBeamCaloTask");
00189 
00190     for (int i = 0; i < cryInArray_ ; i++) {
00191       sprintf(histo, "EEBCT pulse profile cry %01d", i+1);
00192       //considering the gain the range is 4096*12 ~ 50000
00193       meBBCaloPulseProf_[i] = dqmStore_->bookProfile(histo, histo, 10,0.,10.,50000,0.,50000.,"s");
00194 
00195       sprintf(histo, "EEBCT pulse profile in G12 cry %01d", i+1);
00196       meBBCaloPulseProfG12_[i] = dqmStore_->bookProfile(histo, histo, 10,0.,10.,4096,0.,4096.,"s");
00197       meBBCaloPulseProfG12_[i]->setAxisTitle("#sample", 1);
00198       meBBCaloPulseProfG12_[i]->setAxisTitle("ADC", 2);
00199 
00200       sprintf(histo, "EEBCT found gains cry %01d", i+1);
00201       meBBCaloGains_[i] =  dqmStore_->book1D(histo,histo,14,0.,14.);
00202       meBBCaloGains_[i]->setAxisTitle("gain", 1);
00203       // g1-> bin 2, g6-> bin 7, g12-> bin 13
00204 
00205       sprintf(histo, "EEBCT rec energy cry %01d", i+1);
00206       meBBCaloEne_[i] =  dqmStore_->book1D(histo,histo,500,0.,9000.);
00207       meBBCaloEne_[i]->setAxisTitle("rec ene (ADC)", 1);
00208       //9000 ADC in G12 equivalent is about 330 GeV
00209 
00211 
00212 //       sprintf(histo, "EEBCT pulse profile moving table cry %01d", i+1);
00213 //       //considering the gain the range is 4096*12 ~ 50000
00214 //       meBBCaloPulseProfMoving_[i] = dqmStore_->bookProfile(histo, histo, 10,0.,10.,50000,0.,50000.,"s");
00215 
00216 //       sprintf(histo, "EEBCT pulse profile in G12 moving table cry %01d", i+1);
00217 //       meBBCaloPulseProfG12Moving_[i] = dqmStore_->bookProfile(histo, histo, 10,0.,10.,4096,0.,4096.,"s");
00218 
00219 //       sprintf(histo, "EEBCT found gains moving table cry %01d", i+1);
00220 //       meBBCaloGainsMoving_[i] =  dqmStore_->book1D(histo,histo,14,0.,14.);
00221 //       // g1-> bin 2, g6-> bin 7, g12-> bin 13
00222 
00223 //       sprintf(histo, "EEBCT rec energy moving table cry %01d", i+1);
00224 //       meBBCaloEneMoving_[i] =  dqmStore_->book1D(histo,histo,2000,0.,9000.);
00225 //       //9000 ADC in G12 equivalent is about 330 GeV
00226 
00227     }
00228 
00229 //     dqmStore_->setCurrentFolder(prefixME_ + "/EEBeamCaloTask/EnergyHistos");
00230 //     for(int u=0; u< 851;u++){
00231 //       sprintf(histo, "EEBCT rec Ene sum 3x3 cry: %04d",u);
00232 //       meBBCaloE3x3Cry_[u] = dqmStore_->book1D(histo,histo,1000,0.,4500.);
00233 
00234 //       sprintf(histo, "EEBCT rec Energy1 cry: %04d",u);
00235 //       meBBCaloE1Cry_[u] = dqmStore_->book1D(histo,histo,1000,0.,4500.);
00236 //     }
00237 
00238 //     dqmStore_->setCurrentFolder(prefixME_ + "/EEBeamCaloTask");
00239     sprintf(histo, "EEBCT readout crystals");
00240     meBBCaloCryRead_ =  dqmStore_->book2D(histo,histo,9,-4.,5.,9,-4.,5.);
00241     //matrix of readout crystal around cry in beam
00242 
00243     //sprintf(histo, "EEBCT readout crystals table moving");
00244     //meBBCaloCryReadMoving_ =  dqmStore_->book2D(histo,histo,9,-4.,5.,9,-4.,5.);
00245     //matrix of readout crystal around cry in beam
00246 
00247     sprintf(histo, "EEBCT all needed crystals readout");
00248     meBBCaloAllNeededCry_ = dqmStore_->book1D(histo,histo,3,-1.,2.);
00249     // not all needed cry are readout-> bin 1, all needed cry are readout-> bin 3
00250 
00251     sprintf(histo, "EEBCT readout crystals number");
00252     meBBNumCaloCryRead_ = dqmStore_->book1D(histo,histo,851,0.,851.);
00253     meBBNumCaloCryRead_->setAxisTitle("number of read crystals", 1);
00254 
00255     sprintf(histo, "EEBCT rec Ene sum 3x3");
00256     meBBCaloE3x3_ = dqmStore_->book1D(histo,histo,500,0.,9000.);
00257     meBBCaloE3x3_->setAxisTitle("rec ene (ADC)", 1);
00258     //9000 ADC in G12 equivalent is about 330 GeV
00259 
00260     sprintf(histo, "EEBCT rec Ene sum 3x3 table moving");
00261     meBBCaloE3x3Moving_ = dqmStore_->book1D(histo,histo,500,0.,9000.);
00262     //9000 ADC in G12 equivalent is about 330 GeV
00263 
00264     sprintf(histo, "EEBCT crystal on beam");
00265     meBBCaloCryOnBeam_ = dqmStore_->book2D(histo, histo, 85, 0., 85., 20, 0., 20.);
00266 
00267     sprintf(histo, "EEBCT crystal with maximum rec energy");
00268     meBBCaloMaxEneCry_ = dqmStore_->book2D(histo, histo, 85, 0., 85., 20, 0., 20.);
00269 
00270     sprintf(histo, "EEBCT table is moving");
00271     TableMoving_ = dqmStore_->book1D(histo,histo,2,0.,1.1);
00272     TableMoving_->setAxisTitle("table status (0=stable, 1=moving)", 1);
00273     //table is moving-> bin 2, table is not moving-> bin 1
00274 
00275     sprintf(histo, "EEBCT crystals done");
00276     CrystalsDone_ = dqmStore_->book1D(histo,histo,850,1.,851.);
00277     CrystalsDone_->setAxisTitle("crystal", 1);
00278     CrystalsDone_->setAxisTitle("step in the scan", 2);
00279     //for a crystal done the corresponing bin is filled with the step in the
00280     //autoscan pertainig to the given crystales
00281 
00282     sprintf(histo, "EEBCT crystal in beam vs event");
00283     CrystalInBeam_vs_Event_ = dqmStore_->bookProfile(histo, histo, 20000,0.,400000.,1802,-101.,851.,"s");
00284     CrystalInBeam_vs_Event_->setAxisTitle("event", 1);
00285     CrystalInBeam_vs_Event_->setAxisTitle("crystal in beam", 2);
00286     // 1 bin each 20 events
00287     // when table is moving for just one events fill with -100
00288 
00289     sprintf(histo, "EEBCT readout crystals errors");
00290     meEEBCaloReadCryErrors_ = dqmStore_->book1D(histo, histo, 425,1.,86.);
00291     meEEBCaloReadCryErrors_->setAxisTitle("step in the scan", 1);
00292 
00293     sprintf(histo, "EEBCT average rec energy in the single crystal");
00294     //meEEBCaloE1vsCry_ = dqmStore_->book1D(histo, histo, 85,1.,86.);
00295     meEEBCaloE1vsCry_ = dqmStore_->bookProfile(histo, histo, 850,1.,851.,500,0.,9000.,"s");
00296     meEEBCaloE1vsCry_->setAxisTitle("crystal", 1);
00297     meEEBCaloE1vsCry_->setAxisTitle("rec energy (ADC)", 2);
00298 
00299     sprintf(histo, "EEBCT average rec energy in the 3x3 array");
00300     //meEEBCaloE3x3vsCry_= dqmStore_->book1D(histo, histo,85,1.,86.);
00301     meEEBCaloE3x3vsCry_ = dqmStore_->bookProfile(histo, histo, 850,1.,851.,500,0.,9000.,"s");
00302     meEEBCaloE3x3vsCry_->setAxisTitle("crystal", 1);
00303     meEEBCaloE3x3vsCry_->setAxisTitle("rec energy (ADC)", 2);
00304 
00305     sprintf(histo, "EEBCT number of entries");
00306     meEEBCaloEntriesVsCry_ = dqmStore_->book1D(histo, histo,850,1.,851.);
00307     meEEBCaloEntriesVsCry_->setAxisTitle("crystal", 1);
00308     meEEBCaloEntriesVsCry_->setAxisTitle("number of events (prescaled)", 2);
00309 
00310     sprintf(histo, "EEBCT energy deposition in the 3x3");
00311     meEEBCaloBeamCentered_ = dqmStore_->book2D(histo, histo,3,-1.5,1.5,3,-1.5,1.5);
00312     meEEBCaloBeamCentered_->setAxisTitle("\\Delta \\eta", 1);
00313     meEEBCaloBeamCentered_->setAxisTitle("\\Delta \\phi", 2);
00314 
00315     sprintf(histo, "EEBCT E1 in the max cry");
00316     meEEBCaloE1MaxCry_= dqmStore_->book1D(histo,histo,500,0.,9000.);
00317     meEEBCaloE1MaxCry_->setAxisTitle("rec Ene (ADC)", 1);
00318 
00319     sprintf(histo, "EEBCT Desynchronization vs step");
00320     meEEBCaloDesync_= dqmStore_->book1D(histo, histo, 85 ,1.,86.);
00321     meEEBCaloDesync_->setAxisTitle("step", 1);
00322     meEEBCaloDesync_->setAxisTitle("Desynchronized events", 2);
00323 
00324   }
00325 
00326 }
00327 
00328 void EEBeamCaloTask::cleanup(void){
00329 
00330   if ( ! init_ ) return;
00331 
00332   if ( dqmStore_ ) {
00333     dqmStore_->setCurrentFolder(prefixME_ + "/EEBeamCaloTask");
00334     for (int i = 0; i < cryInArray_ ; i++) {
00335       if ( meBBCaloPulseProf_[i] ) dqmStore_->removeElement( meBBCaloPulseProf_[i]->getName() );
00336       meBBCaloPulseProf_[i] = 0;
00337       if ( meBBCaloPulseProfG12_[i] ) dqmStore_->removeElement( meBBCaloPulseProfG12_[i]->getName() );
00338       meBBCaloPulseProfG12_[i] = 0;
00339       if ( meBBCaloGains_[i] ) dqmStore_->removeElement( meBBCaloGains_[i]->getName() );
00340       meBBCaloGains_[i] = 0;
00341       if ( meBBCaloEne_[i] ) dqmStore_->removeElement( meBBCaloEne_[i]->getName() );
00342       meBBCaloEne_[i] = 0;
00343 
00344 //       if ( meBBCaloPulseProfMoving_[i] ) dqmStore_->removeElement( meBBCaloPulseProfMoving_[i]->getName() );
00345 //       meBBCaloPulseProfMoving_[i] = 0;
00346 //       if ( meBBCaloPulseProfG12Moving_[i] ) dqmStore_->removeElement( meBBCaloPulseProfG12Moving_[i]->getName() );
00347 //       meBBCaloPulseProfG12Moving_[i] = 0;
00348 //       if ( meBBCaloGainsMoving_[i] ) dqmStore_->removeElement( meBBCaloGainsMoving_[i]->getName() );
00349 //       meBBCaloGainsMoving_[i] = 0;
00350 //       if ( meBBCaloEneMoving_[i] ) dqmStore_->removeElement( meBBCaloEneMoving_[i]->getName() );
00351 //       meBBCaloEneMoving_[i] = 0;
00352     }
00353 
00354 //     dqmStore_->setCurrentFolder(prefixME_ + "/EEBeamCaloTask/EnergyHistos");
00355 //     for(int u=0; u< 851;u++){
00356 //       if ( meBBCaloE3x3Cry_[u] ) dqmStore_->removeElement( meBBCaloE3x3Cry_[u]->getName() );
00357 //       meBBCaloE3x3Cry_[u] = 0;
00358 //       if ( meBBCaloE1Cry_[u] ) dqmStore_->removeElement( meBBCaloE1Cry_[u]->getName() );
00359 //       meBBCaloE1Cry_[u] = 0;
00360 //     }
00361 
00362 //     dqmStore_->setCurrentFolder(prefixME_ + "/EEBeamCaloTask");
00363     if ( meBBCaloCryRead_ ) dqmStore_->removeElement( meBBCaloCryRead_->getName() );
00364     meBBCaloCryRead_ = 0;
00365 //    if ( meBBCaloCryReadMoving_ ) dqmStore_->removeElement( meBBCaloCryReadMoving_->getName() );
00366 //    meBBCaloCryReadMoving_ = 0;
00367     if ( meBBCaloAllNeededCry_ ) dqmStore_->removeElement( meBBCaloAllNeededCry_->getName() );
00368     meBBCaloAllNeededCry_ = 0;
00369     if ( meBBNumCaloCryRead_ ) dqmStore_->removeElement( meBBNumCaloCryRead_->getName() );
00370     meBBNumCaloCryRead_ = 0;
00371     if ( meBBCaloE3x3_ ) dqmStore_->removeElement( meBBCaloE3x3_->getName() );
00372     meBBCaloE3x3_ = 0;
00373     if ( meBBCaloE3x3Moving_ ) dqmStore_->removeElement( meBBCaloE3x3Moving_->getName() );
00374     meBBCaloE3x3Moving_ = 0;
00375     if ( meBBCaloCryOnBeam_ ) dqmStore_->removeElement( meBBCaloCryOnBeam_->getName() );
00376     meBBCaloCryOnBeam_ = 0;
00377     if ( meBBCaloMaxEneCry_ ) dqmStore_->removeElement( meBBCaloMaxEneCry_->getName() );
00378     meBBCaloMaxEneCry_ = 0;
00379     if ( TableMoving_ ) dqmStore_->removeElement( TableMoving_->getName() );
00380     TableMoving_ = 0;
00381     if ( CrystalsDone_ ) dqmStore_->removeElement( CrystalsDone_->getName() );
00382     CrystalsDone_ = 0;
00383     if ( CrystalInBeam_vs_Event_ ) dqmStore_->removeElement( CrystalInBeam_vs_Event_->getName() );
00384     CrystalInBeam_vs_Event_ = 0;
00385     if( meEEBCaloReadCryErrors_ ) dqmStore_->removeElement( meEEBCaloReadCryErrors_->getName() );
00386     meEEBCaloReadCryErrors_ = 0;
00387     if( meEEBCaloE1vsCry_ ) dqmStore_->removeElement( meEEBCaloE1vsCry_->getName() );
00388     meEEBCaloE1vsCry_ = 0;
00389     if( meEEBCaloE3x3vsCry_ ) dqmStore_->removeElement( meEEBCaloE3x3vsCry_->getName() );
00390     meEEBCaloE3x3vsCry_ = 0;
00391     if( meEEBCaloEntriesVsCry_ )  dqmStore_->removeElement( meEEBCaloEntriesVsCry_->getName() );
00392     meEEBCaloEntriesVsCry_ = 0;
00393     if( meEEBCaloBeamCentered_ ) dqmStore_->removeElement( meEEBCaloBeamCentered_->getName() );
00394     meEEBCaloBeamCentered_ = 0;
00395     if( meEEBCaloE1MaxCry_ ) dqmStore_->removeElement(meEEBCaloE1MaxCry_->getName() );
00396     meEEBCaloE1MaxCry_ = 0;
00397     if( meEEBCaloDesync_ ) dqmStore_->removeElement(meEEBCaloDesync_->getName() );
00398     meEEBCaloDesync_ = 0;
00399   }
00400 
00401   init_ = false;
00402 
00403 }
00404 
00405 void EEBeamCaloTask::endJob(void){
00406 
00407   edm::LogInfo("EEBeamCaloTask") << "analyzed " << ievt_ << " events";
00408 
00409   if ( enableCleanup_ ) this->cleanup();
00410 
00411 }
00412 
00413 void EEBeamCaloTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00414 
00415   bool enable = false;
00416 
00417   edm::Handle<EcalRawDataCollection> dcchs;
00418 
00419   if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00420 
00421     for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00422 
00423       if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
00424 
00425       if ( dcchItr->getRunType() == EcalDCCHeaderBlock::BEAMH4 ||
00426            dcchItr->getRunType() == EcalDCCHeaderBlock::BEAMH2 ) enable = true;
00427     }
00428 
00429   } else {
00430     edm::LogWarning("EEBeamCaloTask") << EcalRawDataCollection_ << " not available";
00431   }
00432 
00433   if ( ! enable ) return;
00434   if ( ! init_ ) this->setup();
00435   ievt_++;
00436 
00437   edm::Handle<EcalTBEventHeader> pEventHeader;
00438   const EcalTBEventHeader* evtHeader=0;
00439 
00440   if ( e.getByLabel(EcalTBEventHeader_, pEventHeader) ) {
00441     evtHeader = pEventHeader.product(); // get a ptr to the product
00442   } else {
00443     std::cerr << "Error! can't get the product for the event header" << std::endl;
00444   }
00445 
00446   //FIX ME, in the task we should use LV1 instead of ievt_ (prescaling)
00447   int cry_in_beam = 0;
00448   bool tb_moving = false;//just for test, to be filled with info from the event
00449   int event = 0;
00450 
00451   if(evtHeader){
00452     //cry_in_beam = evtHeader->nominalCrystalInBeam();
00453     cry_in_beam = evtHeader->crystalInBeam();
00454     tb_moving = evtHeader->tableIsMoving();
00455     event = evtHeader->eventNumber();
00456     if( evtHeader->syncError() ) {meEEBCaloDesync_->Fill(crystal_step_);}
00457   }
00458   else {
00459     cry_in_beam =   previous_cry_in_beam_;
00460     tb_moving = lastStableStatus_;
00461     event = previous_ev_num_ +10;
00462   }
00463 
00464   previous_cry_in_beam_ = cry_in_beam;
00465   previous_ev_num_ = event;
00466 
00467   //cry_in_beam = 702;//just for test, to be filled with info from the event
00468 
00469   bool reset_histos_stable = false;
00470   bool reset_histos_moving = false;
00471 
00472   bool skip_this_event = false;
00473 
00474 //   if(ievt_ > 500){tb_moving=true; }
00475 //   if(ievt_ > 1000){tb_moving=false; cry_in_beam = 703;}
00476 //   if(ievt_ > 2000){tb_moving=true; }
00477 //   if(ievt_ > 2500){tb_moving=false; cry_in_beam = 704;}
00478 //   if(ievt_ == 3000){cry_in_beam = 702;}
00479 //   if(ievt_ == 3001){cry_in_beam = 703;}
00480 //   if(ievt_ > 3500){tb_moving=true; }
00481 
00482 //   if(ievt_ > 3300){tb_moving=true; }
00483 //   if(ievt_ > 6100){tb_moving=false; cry_in_beam = 705;}
00484 //   if(ievt_ == 6201){tb_moving=true; }
00485 //   if(ievt_ > 9000){tb_moving=true; }
00486 //   if(ievt_ == 11021){tb_moving=false; }
00487 //   if(ievt_ > 12100){tb_moving=false; cry_in_beam = 706;}
00488 //   if(ievt_ > 15320){tb_moving=true; }
00489 //   if(ievt_ > 15500){tb_moving=false; cry_in_beam = 707;}
00490 
00491 
00492  //  //if(ievt_ > 20){tb_moving=true; }
00493 //   //  if(ievt_ == 23){tb_moving=true; }
00494 //   if(ievt_ > 50){tb_moving=false; cry_in_beam = 705;}
00495 //   //if(ievt_ > 90 ){tb_moving=true; }
00496 //   if(ievt_ == 65){tb_moving=false; }
00497 //   if(ievt_ > 110){tb_moving=false; cry_in_beam = 706;}
00498 //   if(ievt_ == 116){cry_in_beam = 709;}
00499 //   //if(ievt_ > 115){tb_moving=true; }
00500 //   if(ievt_ > 150){tb_moving=false; cry_in_beam = 707;}
00501 
00502   //   #include "DQM/EcalEndcapMonitorTasks/interface/cry_in_beam_run_ecs73214.h"
00503 
00504   if(ievt_ < 3){last_cry_in_beam_ = cry_in_beam;}
00505 
00506   if(tb_moving){
00507 
00508     TableMoving_->Fill(1);
00509     if( PreviousTableStatus_[0] == 0 &&  PreviousTableStatus_[1] == 1 && lastStableStatus_ == 0){
00510       reset_histos_moving=true;
00511       wasFakeChange_ = false;
00512       // ! Warning! This works in the assumption that the crystal in beam stay the same
00513       // while the tb is moving and is set to the new one only when the table
00514       // reaches the new position
00515       lastStableStatus_ = 1;
00516 
00517     }
00518     else if( PreviousTableStatus_[1] == 0) {
00519       skip_this_event=true;
00520       changed_tb_status_ = true;
00521       wasFakeChange_ = true;
00522     }
00523     // just skip the first event when the table change status
00524     PreviousTableStatus_[0] = PreviousTableStatus_[1];
00525     PreviousTableStatus_[1] = 1;
00526   }//end of if(tb_moving)
00527 
00528   else {// table is not moving
00529 
00530     TableMoving_->Fill(0);
00531     if( PreviousTableStatus_[0] == 1 &&  PreviousTableStatus_[1] == 0 && lastStableStatus_ == 1){
00532       //reset_histos_stable = true;
00533       wasFakeChange_ = false;
00534       lastStableStatus_ = 0;
00535     }
00536     else if(PreviousTableStatus_[1] == 1) {
00537       skip_this_event=true;
00538       changed_tb_status_ = true;
00539       wasFakeChange_ = true;
00540     }
00541     // just skip the first event when the table change status
00542     PreviousTableStatus_[0]=PreviousTableStatus_[1];
00543     PreviousTableStatus_[1]=0;
00544 
00545     // check also whether cry in beam  has changed
00546     if(  PreviousCrystalinBeam_[0] == PreviousCrystalinBeam_[1]  &&   PreviousCrystalinBeam_[1] != PreviousCrystalinBeam_[2] && PreviousCrystalinBeam_[2] == cry_in_beam ){
00547       reset_histos_stable=true;
00548       wasFakeChange_ = false;
00549     }
00550     else if (PreviousCrystalinBeam_[2] != cry_in_beam){
00551       changed_cry_in_beam_ = true;
00552       skip_this_event=true;
00553       wasFakeChange_ = true;
00554     }
00555     // }
00556 
00557     PreviousCrystalinBeam_[0] = PreviousCrystalinBeam_[1];
00558     PreviousCrystalinBeam_[1] = PreviousCrystalinBeam_[2];
00559     PreviousCrystalinBeam_[2] =  cry_in_beam;
00560   }
00561   //if (! changed_tb_status_ && ! changed_cry_in_beam_ ){// standard data taking
00562 
00563     if( !tb_moving ) {CrystalInBeam_vs_Event_->Fill(event,float(cry_in_beam));}
00564     else{CrystalInBeam_vs_Event_->Fill(event,-100); }
00565     if ( !profileArranged_ ){
00566       float dd=0;
00567       int mbin =0;
00568       for( int bin=1; bin < 20001; bin++ ){
00569         float temp = CrystalInBeam_vs_Event_->getBinContent(bin);
00570         if(temp>0){ dd= temp+0.01; mbin=bin; break;}
00571       }
00572       if(mbin >0) { CrystalInBeam_vs_Event_->Fill(20*mbin-1,dd);}
00573       profileArranged_ = true;
00574     }
00575 
00576     // }
00577 //   else{ // here there is either a step or a daq error
00578 //     // keep 10 events in a buffer waiting to decide for the step or the error
00579 //     if(tb_moving){cib_[evt_after_change_]=-100;}
00580 //     else {cib_[evt_after_change_]=cry_in_beam;}
00581 
00582 //     if(evt_after_change_ >= 9){
00583 //       evt_after_change_ =0;
00584 //       if(wasFakeChange_){// here is an error: put the 10 events in the profile
00585 //      for(int u=0; u<10; u++){
00586 //        CrystalInBeam_vs_Event_->Fill(ievt_-9+u , cib_[u]);
00587 //      }
00588 //       }
00589 //       //for a real change just skip the first 10 events after change
00590 //       changed_tb_status_=false;
00591 //       changed_cry_in_beam_ = false;
00592 //     }
00593 //     else{evt_after_change_ ++;}
00594 //   }
00595 
00596   if(reset_histos_moving){
00597     edm::LogInfo("EEBeamCaloTask") << "event " << ievt_ << " resetting histos for moving table!! ";
00598 
00599     //     meEEBCaloE1vsCry_->setBinContent(crystal_step_ , meBBCaloEne_[4]->getMean() );
00600     //     meEEBCaloE1vsCry_->setBinError(crystal_step_ , meBBCaloEne_[4]->getRMS() );
00601     //     meEEBCaloE3x3vsCry_->setBinContent(crystal_step_ , meBBCaloE3x3_->getMean() );
00602     //     meEEBCaloE3x3vsCry_->setBinError(crystal_step_ , meBBCaloE3x3_->getRMS() );
00603 
00604     //     meEEBCaloEntriesVsCry_->setBinContent(crystal_step_ ,  meBBCaloE3x3_->getEntries() );
00605 
00606     table_step_++;
00607 
00608 
00609     //here the follwowing histos should be reset
00610     // for (int u=0;u<cryInArray_;u++){
00611     //  meBBCaloPulseProfMoving_[u]->Reset();
00612     //  meBBCaloPulseProfG12Moving_[u]->Reset();
00613     //  meBBCaloGainsMoving_[u]->Reset();
00614     //  meBBCaloEneMoving_[u]->Reset();
00615     // }
00616     // meBBCaloCryReadMoving_->Reset();
00617     meBBCaloE3x3Moving_->Reset();
00618 
00619   }
00620 
00621 
00622   if(reset_histos_stable){
00623     if( event - event_last_reset_ > 30){//to be tuned, to avoid a double reset for the change in the table status and
00624                                         //in the crystal in beam. This works ONLY if the crystal in beam stay the same
00625                                         // while the table is moving.
00626                                         //One can also think to remove the reset of the histograms when the table change
00627                                         // status from moving to stable, and to leave the reset only if the cry_in_beam changes.
00628 
00629       edm::LogInfo("EEBeamCaloTask") << "event " << ievt_ << " resetting histos for stable table!! ";
00630 
00631       //       meEEBCaloE1vsCry_->setBinContent(crystal_step_ , meBBCaloEne_[4]->getMean() );
00632       //       meEEBCaloE1vsCry_->setBinError(crystal_step_ , meBBCaloEne_[4]->getRMS() );
00633       //       meEEBCaloE3x3vsCry_->setBinContent(crystal_step_ , meBBCaloE3x3_->getMean() );
00634       //       meEEBCaloE3x3vsCry_->setBinError(crystal_step_ , meBBCaloE3x3_->getRMS() );
00635       //       //
00636       //       meEEBCaloEntriesVsCry_->setBinContent(crystal_step_ ,  meBBCaloE3x3_->getEntries() );
00637 
00638       event_last_reset_ = event;
00639 
00640       last_cry_in_beam_ = cry_in_beam;
00641       crystal_step_++;
00642 
00643       //here the follwowing histos should be reset
00644       for (int u=0;u<cryInArray_;u++){
00645         meBBCaloPulseProf_[u]->Reset();
00646         meBBCaloPulseProfG12_[u]->Reset();
00647         meBBCaloGains_[u]->Reset();
00648         meBBCaloEne_[u]->Reset();
00649       }
00650       meBBCaloCryRead_->Reset();
00651       meBBCaloE3x3_->Reset();
00652       meEEBCaloBeamCentered_->Reset();
00653     }
00654   }
00655 
00656  if(skip_this_event){
00657    edm::LogInfo("EEBeamCaloTask") << "event " << event <<" analyzed: "<<ievt_ << " : skipping this event!! ";
00658    return;}
00659 
00660  // now CrystalsDone_ contains the crystal on beam at the beginning fo a new step, and not when it has finished !!
00661  // <5 just to avoid that we skip the event just after the reset and we do not set CrystalsDone_ .
00662  // if( ievt_ - event_last_reset_ < 5){ CrystalsDone_->setBinContent(cry_in_beam , crystal_step_ );}
00663  CrystalsDone_->setBinContent(cry_in_beam , crystal_step_ );
00664   int eta_c = ( cry_in_beam-1)/20 ;
00665   int phi_c = ( cry_in_beam-1)%20 ;
00666 
00667   float xie = eta_c + 0.5;
00668   float xip = phi_c + 0.5;
00669   if (!tb_moving) {meBBCaloCryOnBeam_->Fill(xie,xip);}
00670 
00671   edm::Handle<EBDigiCollection> digis;
00672   e.getByLabel(EBDigiCollection_, digis);
00673   int nebd = digis->size();
00674 
00675   meBBNumCaloCryRead_->Fill(nebd);
00676 
00677   //matrix 7x7 around cry in beam
00678   int cry_to_beRead[49]; //0 or -1 for non existing crystals (eg 852)
00679   for(int u=0;u<49;u++){cry_to_beRead[u]=0;}
00680   // chech that all the crystals in the 7x7 exist
00681   for(int de=-3; de<4; de++){
00682     for(int dp=-3; dp<4; dp++){
00683       //int cry_num = (phi_c+dp) + 20*(eta_c+de) +1;
00684       int u = de -7*dp + 24;
00685       bool existing_cry = (phi_c+dp) >= 0 && (phi_c+dp) <= 19 && (eta_c+de) >=0 && (eta_c+de) <= 84;
00686       if(!existing_cry){cry_to_beRead[u]=-1;}
00687     }
00688   }
00689 
00690 
00691   meEEBCaloEntriesVsCry_->Fill(cry_in_beam);
00692 
00693   for ( EBDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
00694 
00695     EBDetId id = digiItr->id();
00696 
00697     int ic = id.ic();
00698     int ie = (ic-1)/20;
00699     int ip = (ic-1)%20;
00700 
00701     int deta_c= ie - eta_c;
00702     int dphi_c= ip - phi_c;
00703     if (! tb_moving){meBBCaloCryRead_->Fill(deta_c, dphi_c);}
00704     //else {meBBCaloCryReadMoving_->Fill(deta_c, dphi_c);}
00705 
00706     if(std::abs(deta_c) > 3 || std::abs(dphi_c) > 3){continue;}
00707     int i_toBeRead = deta_c -7*dphi_c + 24;
00708     if( i_toBeRead > -1 &&  i_toBeRead <49){
00709       cry_to_beRead[i_toBeRead]++;
00710       //if( (ievt_ == 4000 || ievt_ == 13000 || ievt_ == 13002 ) &&   i_toBeRead == 5){ cry_to_beRead[i_toBeRead] -=1;}
00711     }
00712 
00713     if(std::abs(deta_c) > 1 || std::abs(dphi_c) > 1){continue;}
00714     int i_in_array = deta_c -3*dphi_c + 4;
00715 
00716     if( i_in_array < 0 || i_in_array > 8 ){continue;}
00717 
00718     EBDataFrame dataframe = (*digiItr);
00719 
00720     for (int i = 0; i < 10; i++) {
00721       int adc = dataframe.sample(i).adc();
00722       int gainid = dataframe.sample(i).gainId();
00723       //if( (ievt_ == 15400 || ievt_ == 15600 || ievt_ == 15700 ) &&   i_in_array == 4 && i == 4){ gainid =2;}
00724       //if( (ievt_ == 15400 || ievt_ == 15600 || ievt_ == 15700 ) &&   i_in_array == 6 && i == 6){ gainid =3;}
00725 
00726       if ( gainid == 1 ){// gain 12
00727         if(! tb_moving){
00728           meBBCaloPulseProfG12_[i_in_array]->Fill(i,float(adc));
00729           meBBCaloPulseProf_[i_in_array]->Fill(i,float(adc));
00730           meBBCaloGains_[i_in_array]->Fill(12);
00731         }
00732         //else{
00733         //  meBBCaloPulseProfG12Moving_[i_in_array]->Fill(i,float(adc));
00734         //  meBBCaloPulseProfMoving_[i_in_array]->Fill(i,float(adc));
00735         //  meBBCaloGainsMoving_[i_in_array]->Fill(12);
00736         //}
00737       }
00738       else if ( gainid == 2 ){// gain 6
00739         float val = (float(adc)-defaultPede_)*2 + defaultPede_;
00740         if(! tb_moving){
00741           meBBCaloPulseProf_[i_in_array]->Fill(i,val);
00742           meBBCaloGains_[i_in_array]->Fill(6);
00743         }
00744         //else{
00745         //  meBBCaloPulseProfMoving_[i_in_array]->Fill(i,val);
00746         //  meBBCaloGainsMoving_[i_in_array]->Fill(6);
00747         //}
00748       }
00749       else if ( gainid == 3 ){// gain 1
00750         float val = (float(adc)-defaultPede_)*12 + defaultPede_;
00751         if(! tb_moving){
00752         meBBCaloPulseProf_[i_in_array]->Fill(i,val);
00753         meBBCaloGains_[i_in_array]->Fill(1);
00754         }
00755         //else{
00756         //meBBCaloPulseProfMoving_[i_in_array]->Fill(i,val);
00757         //meBBCaloGainsMoving_[i_in_array]->Fill(1);
00758         //}
00759       }
00760     }// end of loop over samples
00761   }// end of loop over digis
00762 
00763   //now  if everything was correct cry_to_beRead should be filled with 1 or -1 but not 0
00764   bool all_cry_readout = true;
00765 
00766   // if( ievt_ == 4000 || ievt_ == 13000 || ievt_ == 13002 ) {all_cry_readout = false;}
00767   if(all_cry_readout){ meBBCaloAllNeededCry_->Fill(1.5);}//bin3
00768   else {
00769     meBBCaloAllNeededCry_->Fill(-0.5);//bin1
00770     if( tb_moving ) {meEEBCaloReadCryErrors_->Fill( crystal_step_+0.5 );}
00771     else {meEEBCaloReadCryErrors_->Fill( crystal_step_ );}
00772   }
00773 
00774   //the part involving rechits
00775 
00776   edm::Handle<EcalUncalibratedRecHitCollection> hits;
00777   e.getByLabel(EcalUncalibratedRecHitCollection_, hits);
00778   int neh = hits->size();
00779   LogDebug("EEBeamCaloTask") << "event " << event <<" analyzed: "<< ievt_ << " hits collection size " << neh;
00780   float ene3x3=0;
00781   float maxEne = 0;
00782   int ieM =-1, ipM = -1;//for the crystal with maximum energy deposition
00783   float cryInBeamEne =0;
00784   for ( EcalUncalibratedRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
00785 
00786     EBDetId id = hitItr->id();
00787 
00788     int ic = id.ic();
00789     int ie = (ic-1)/20;
00790     int ip = (ic-1)%20;
00791 
00792     int deta_c= ie - eta_c;
00793     int dphi_c= ip - phi_c;
00794 
00795     int i_in_array = deta_c -3*dphi_c + 4;
00796 
00797     float R_ene = hitItr->amplitude();
00798     if ( R_ene <= 0. ) R_ene = 0.0;
00799     if(R_ene > maxEne){
00800       maxEne=R_ene;
00801       ieM =ie; ipM = ip;
00802     }
00803     if(std::abs(deta_c) > 1 || std::abs(dphi_c) > 1){continue;}
00804     meEEBCaloBeamCentered_->Fill(deta_c,dphi_c,R_ene);
00805 
00806     if( i_in_array < 0 || i_in_array > 8 ){continue;}
00807 
00808     if(i_in_array == 4){cryInBeamEne = R_ene;}
00809     if(! tb_moving){meBBCaloEne_[i_in_array]->Fill(R_ene);}
00810     //else{meBBCaloEneMoving_[i_in_array]->Fill(R_ene);}
00811     ene3x3 += R_ene;
00812 
00813   }//end of loop over rechits
00814 
00815   if (!tb_moving){
00816     meBBCaloE3x3_->Fill(ene3x3);
00817     meEEBCaloE1vsCry_->Fill(cry_in_beam , cryInBeamEne );
00818     meEEBCaloE3x3vsCry_->Fill(cry_in_beam, ene3x3 );
00819     //     if( cry_in_beam > 0 && cry_in_beam < 851){
00820     //       meBBCaloE3x3Cry_[cry_in_beam]->Fill(ene3x3);
00821     //       meBBCaloE1Cry_[cry_in_beam]->Fill(cryInBeamEne);
00822     //     }
00823     meBBCaloMaxEneCry_->Fill(ieM,ipM);
00824     meEEBCaloE1MaxCry_->Fill(maxEne);
00825   }
00826   else{meBBCaloE3x3Moving_->Fill(ene3x3);}
00828 }
00829