CMS 3D CMS Logo

EEBeamCaloTask.cc

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

Generated on Tue Jun 9 17:32:52 2009 for CMSSW by  doxygen 1.5.4