CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQMOffline/Hcal/src/CaloTowersAnalyzer.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Hcal/interface/CaloTowersAnalyzer.h"
00002 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00003 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00004 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00005 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00006 
00007 CaloTowersAnalyzer::CaloTowersAnalyzer(edm::ParameterSet const& conf):
00008   theCaloTowerCollectionLabel(conf.getUntrackedParameter<edm::InputTag>("CaloTowerCollectionLabel"))
00009 {
00010   // DQM ROOT output
00011   outputFile_ = conf.getUntrackedParameter<std::string>("outputFile", "myfile.root");
00012 
00013   hcalselector_ = conf.getUntrackedParameter<std::string>("hcalselector", "all");
00014 
00015   useAllHistos_ = conf.getUntrackedParameter<bool>("useAllHistos", false);
00016 
00017   etaMin[0] = 0.;
00018   etaMax[0] = 1.4;
00019   etaMin[1] = 1.4;
00020   etaMax[1] = 2.9;
00021   etaMin[2] = 2.9;
00022   etaMax[2] = 5.2;
00023 
00024   isub = 0;
00025   if(hcalselector_ == "HB") isub = 1;
00026   if(hcalselector_ == "HE") isub = 2;
00027   if(hcalselector_ == "HF") isub = 3;
00028 
00029   if ( outputFile_.size() != 0 ) {
00030     edm::LogInfo("OutputInfo") << " Hcal RecHit Task histograms will be saved to '" << outputFile_.c_str() << "'";
00031   } else {
00032     edm::LogInfo("OutputInfo") << " Hcal RecHit Task histograms will NOT be saved";
00033   }
00034   
00035   dbe_ = 0;
00036   // get hold of back-end interface
00037   dbe_ = edm::Service<DQMStore>().operator->();
00038    
00039   // const char * sub = hcalselector_.c_str();
00040 
00041   Char_t histo[100];
00042 
00043   if ( dbe_ ) {
00044     dbe_->setCurrentFolder("CaloTowersD/CaloTowersTask");
00045   }
00046 
00047   //These two histos are not drawn by our macros, but they are used
00048   //in the EndJob for norms and such so I am leaving them alone for now
00049   //-------------------------------------------------------------------------------------------
00050   sprintf  (histo, "Ntowers_per_event_vs_ieta" );
00051   Ntowers_vs_ieta = dbe_->book1D(histo, histo, 82, -41., 41.);
00052   
00053   sprintf  (histo, "CaloTowersTask_map_Nentries" );
00054   mapEnergy_N = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00055   //-------------------------------------------------------------------------------------------
00056 
00057   //These the single pion scan histos
00058   //-------------------------------------------------------------------------------------------
00059   //The first three are not used
00060   if (useAllHistos_){
00061     sprintf  (histo, "emean_vs_ieta_E" );
00062     emean_vs_ieta_E = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000., "s");
00063     sprintf  (histo, "emean_vs_ieta_H" );
00064     emean_vs_ieta_H = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000., "s");
00065     sprintf  (histo, "emean_vs_ieta_EH" );
00066     emean_vs_ieta_EH = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000., "s");
00067   }
00068   //These are drawn
00069   sprintf  (histo, "emean_vs_ieta_E1" );
00070   emean_vs_ieta_E1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000., "s");
00071   sprintf  (histo, "emean_vs_ieta_H1" );
00072   emean_vs_ieta_H1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000., "s");
00073   sprintf  (histo, "emean_vs_ieta_EH1" );
00074   emean_vs_ieta_EH1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000., "s");
00075   //-------------------------------------------------------------------------------------------
00076 
00077   //Map energy histos are not drawn
00078   if (useAllHistos_){
00079     sprintf  (histo, "CaloTowersTask_map_energy_E" );
00080     mapEnergy_E = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00081     sprintf  (histo, "CaloTowersTask_map_energy_H");
00082     mapEnergy_H = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00083     sprintf  (histo, "CaloTowersTask_map_energy_EH" );
00084     mapEnergy_EH = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00085   }
00086 
00087   //All ECAL cell histos are used
00088   // XXX: ECAL 0-25 [0-26, 26 bins]   HCAL 0-4 [0-5, 5 bins]
00089   sprintf  (histo, "number_of_bad_cells_Ecal_EB");
00090   numBadCellsEcal_EB = dbe_->book1D(histo, histo, 26, 0, 26);
00091   sprintf  (histo, "number_of_bad_cells_Ecal_EE");
00092   numBadCellsEcal_EE = dbe_->book1D(histo, histo, 26, 0, 26);
00093   sprintf  (histo, "number_of_recovered_cells_Ecal_EB");
00094   numRcvCellsEcal_EB = dbe_->book1D(histo, histo, 26, 0, 26);
00095   sprintf  (histo, "number_of_recovered_cells_Ecal_EE");
00096   numRcvCellsEcal_EE = dbe_->book1D(histo, histo, 26, 0, 26);
00097   sprintf  (histo, "number_of_problematic_cells_Ecal_EB");
00098   numPrbCellsEcal_EB = dbe_->book1D(histo, histo, 26, 0, 26);
00099   sprintf  (histo, "number_of_problematic_cells_Ecal_EE");
00100   numPrbCellsEcal_EE = dbe_->book1D(histo, histo, 26, 0, 26); 
00101 
00102   //Occupancy vs. ieta is drawn, occupancy map is needed to draw it 
00103   sprintf  (histo, "CaloTowersTask_map_occupancy" );
00104   occupancy_map = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00105 
00106   sprintf  (histo, "CaloTowersTask_occupancy_vs_ieta" );
00107   occupancy_vs_ieta = dbe_->book1D(histo, histo, 82, -41, 41);
00108   
00109   if( isub == 1 || isub == 0) {
00110     //All cell histos are used
00111     sprintf  (histo, "number_of_bad_cells_Hcal_HB");
00112     numBadCellsHcal_HB = dbe_->book1D(histo, histo, 5, 0, 5);
00113     sprintf  (histo, "number_of_recovered_cells_Hcal_HB");
00114     numRcvCellsHcal_HB = dbe_->book1D(histo, histo, 5, 0, 5);
00115     sprintf  (histo, "number_of_problematic_cells_Hcal_HB");
00116     numPrbCellsHcal_HB = dbe_->book1D(histo, histo, 5, 0, 5); 
00117     
00118     //These are the five oldest CaloTower histos used: NTowers, E in HCAL/ECAL, MET and SET
00119     //-------------------------------------------------------------------------------------------
00120     sprintf (histo, "CaloTowersTask_energy_HCAL_HB" ) ;
00121     meEnergyHcal_HB    = dbe_->book1D(histo, histo, 4100, -200, 8000);  
00122     
00123     sprintf (histo, "CaloTowersTask_energy_ECAL_HB" ) ;
00124     meEnergyEcal_HB    = dbe_->book1D(histo, histo, 3100, -200, 6000); 
00125     
00126     sprintf (histo, "CaloTowersTask_number_of_fired_towers_HB" ) ;
00127     meNumFiredTowers_HB = dbe_->book1D(histo, histo, 1000, 0, 2000); 
00128 
00129     sprintf  (histo, "CaloTowersTask_MET_HB" ) ;
00130     MET_HB = dbe_->book1D(histo, histo, 3000, 0. , 3000. ) ;
00131     
00132     sprintf  (histo, "CaloTowersTask_SET_HB" ) ;
00133     SET_HB = dbe_->book1D(histo, histo, 8000, 0. , 8000. ) ;
00134     //-------------------------------------------------------------------------------------------
00135 
00136     //Timing histos and profiles -- all six are necessary
00137     //-------------------------------------------------------------------------------------------
00138     sprintf  (histo, "CaloTowersTask_EM_Timing_HB" ) ;
00139     emTiming_HB = dbe_->book1D(histo, histo, 110, -120., 100. ) ;
00140 
00141     sprintf  (histo, "CaloTowersTask_HAD_Timing_HB" ) ;
00142     hadTiming_HB = dbe_->book1D(histo, histo, 70, -48., 92. ) ;
00143 
00144     //Energy-Timing histos are divided into low, medium and high to reduce memory usage
00145     //EM
00146     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_Low_HB" ) ;
00147     emEnergyTiming_Low_HB = dbe_->book2D(histo, histo, 40, 0. , 40., 110, -120., 100.  ) ;
00148 
00149     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_HB" ) ;
00150     emEnergyTiming_HB = dbe_->book2D(histo, histo, 200, 0. , 400., 110, -120., 100.  ) ;
00151 
00152     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_High_HB" ) ;
00153     emEnergyTiming_High_HB = dbe_->book2D(histo, histo, 200, 0. , 3000., 110, -120., 100.  ) ;
00154 
00155     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_profile_Low_HB" ) ;
00156     emEnergyTiming_profile_Low_HB = dbe_->bookProfile(histo, histo, 40, 0. , 40., 110, -120., 100.  ) ;
00157 
00158     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_profile_HB" ) ;
00159     emEnergyTiming_profile_HB = dbe_->bookProfile(histo, histo, 200, 0. , 400., 110, -120., 100.  ) ;
00160 
00161     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_profile_High_HB" ) ;
00162     emEnergyTiming_profile_High_HB = dbe_->bookProfile(histo, histo, 200, 0. , 3000., 110, -120., 100.  ) ;
00163 
00164     //HAD
00165     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_Low_HB" ) ;
00166     hadEnergyTiming_Low_HB = dbe_->book2D(histo, histo, 40, 0. , 40., 70, -48., 92. ) ;
00167 
00168     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_HB" ) ;
00169     hadEnergyTiming_HB = dbe_->book2D(histo, histo, 100, 0. , 200., 70, -48., 92. ) ;
00170 
00171     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_High_HB" ) ;
00172     hadEnergyTiming_High_HB = dbe_->book2D(histo, histo, 300, 0. , 3000., 70, -48., 92. ) ;
00173 
00174     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_profile_Low_HB" ) ;
00175     hadEnergyTiming_profile_Low_HB = dbe_->bookProfile(histo, histo, 40, 0. , 40., 70, -48., 92. ) ;
00176 
00177     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_profile_HB" ) ;
00178     hadEnergyTiming_profile_HB = dbe_->bookProfile(histo, histo, 100, 0. , 200., 70, -48., 92. ) ;
00179 
00180     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_profile_High_HB" ) ;
00181     hadEnergyTiming_profile_High_HB = dbe_->bookProfile(histo, histo, 300, 0. , 3000., 70, -48., 92. ) ;
00182     //-------------------------------------------------------------------------------------------
00183 
00184     //Everything else is not drawn
00185     if (useAllHistos_){
00186       sprintf (histo, "CaloTowersTask_sum_of_energy_HCAL_vs_ECAL_HB") ;
00187       meEnergyHcalvsEcal_HB    = dbe_->book2D(histo, histo, 500, 0., 500., 500, 0., 500.);
00188       
00189       sprintf (histo, "CaloTowersTask_energy_OUTER_HB" ) ;
00190       meEnergyHO_HB    = dbe_->book1D(histo, histo, 1640, -200, 8000);   
00191       
00192       sprintf (histo, "CaloTowersTask_energy_of_ECAL_component_of_tower_HB" ) ;
00193       meEnergyEcalTower_HB = dbe_->book1D(histo, histo, 440, -200, 2000); 
00194       
00195       sprintf (histo, "CaloTowersTask_energy_of_HCAL_component_of_tower_HB" ) ;
00196       meEnergyHcalTower_HB = dbe_->book1D(histo, histo, 440 , -200 , 2000); 
00197       
00198       sprintf  (histo, "CaloTowersTask_energy_HcalPlusEcalPlusHO_HB" ) ;
00199       meTotEnergy_HB = dbe_->book1D(histo, histo,400, 0., 2000.) ;
00200       
00201       sprintf  (histo, "CaloTowersTask_map_energy_HB" );
00202       mapEnergy_HB = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00203       sprintf  (histo, "CaloTowersTask_map_energy_HCAL_HB");
00204       mapEnergyHcal_HB = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00205       sprintf  (histo, "CaloTowersTask_map_energy_ECAL_HB" );
00206       mapEnergyEcal_HB = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00207       
00208       sprintf  (histo, "CaloTowersTask_phi_MET_HB" ) ;
00209       phiMET_HB = dbe_->book1D(histo, histo, 72, -3.1415926535898, 3.1415926535898 ) ;
00210     }
00211   } 
00212   
00213   if( isub == 2 || isub == 0) {
00214     //All cell histos are used
00215     sprintf  (histo, "number_of_bad_cells_Hcal_HE");
00216     numBadCellsHcal_HE = dbe_->book1D(histo, histo, 5, 0, 5);
00217     sprintf  (histo, "number_of_recovered_cells_Hcal_HE");
00218     numRcvCellsHcal_HE = dbe_->book1D(histo, histo, 5, 0, 5);
00219     sprintf  (histo, "number_of_problematic_cells_Hcal_HE");
00220     numPrbCellsHcal_HE = dbe_->book1D(histo, histo, 5, 0, 5); 
00221 
00222     //These are the five oldest CaloTower histos used: NTowers, E in HCAL/ECAL, MET and SET
00223     //-------------------------------------------------------------------------------------------
00224     sprintf (histo, "CaloTowersTask_energy_HCAL_HE" ) ;
00225     meEnergyHcal_HE    = dbe_->book1D(histo, histo, 440, -200, 2000);  
00226     
00227     sprintf (histo, "CaloTowersTask_energy_ECAL_HE" ) ;
00228     meEnergyEcal_HE    = dbe_->book1D(histo, histo, 440, -200, 2000); 
00229     
00230     sprintf (histo, "CaloTowersTask_number_of_fired_towers_HE" ) ;
00231     meNumFiredTowers_HE = dbe_->book1D(histo, histo, 1000, 0, 2000); 
00232 
00233     sprintf  (histo, "CaloTowersTask_MET_HE" ) ;
00234     MET_HE = dbe_->book1D(histo, histo, 1000, 0. , 1000. ) ;
00235     
00236     sprintf  (histo, "CaloTowersTask_SET_HE" ) ;
00237     SET_HE = dbe_->book1D(histo, histo, 2000, 0. , 2000. ) ;
00238     //-------------------------------------------------------------------------------------------
00239 
00240     //Timing histos and profiles -- all six are necessary
00241     //-------------------------------------------------------------------------------------------
00242     sprintf  (histo, "CaloTowersTask_EM_Timing_HE" ) ;
00243     emTiming_HE = dbe_->book1D(histo, histo, 110, -120., 100. ) ;
00244 
00245     sprintf  (histo, "CaloTowersTask_HAD_Timing_HE" ) ;
00246     hadTiming_HE = dbe_->book1D(histo, histo, 70, -48., 92. ) ;
00247 
00248     //Energy-Timing histos are divided into low and normal to reduce memory usage
00249     //EM
00250     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_Low_HE" ) ;
00251     emEnergyTiming_Low_HE = dbe_->book2D(histo, histo, 160, 0. , 160., 110, -120., 100.  ) ;
00252 
00253     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_HE" ) ;
00254     emEnergyTiming_HE = dbe_->book2D(histo, histo, 200, 0. , 800., 110, -120., 100.  ) ;
00255 
00256     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_profile_Low_HE" ) ;
00257     emEnergyTiming_profile_Low_HE = dbe_->bookProfile(histo, histo, 160, 0. , 160., 110, -120., 100.  ) ;
00258 
00259     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_profile_HE" ) ;
00260     emEnergyTiming_profile_HE = dbe_->bookProfile(histo, histo, 200, 0. , 800., 110, -120., 100.  ) ;
00261 
00262     //HAD
00263     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_Low_HE" ) ;
00264     hadEnergyTiming_Low_HE = dbe_->book2D(histo, histo, 160, 0. , 160., 70, -48., 92. ) ;
00265 
00266     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_HE" ) ;
00267     hadEnergyTiming_HE = dbe_->book2D(histo, histo, 200, 0. , 800., 70, -48., 92. ) ;
00268 
00269     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_profile_Low_HE" ) ;
00270     hadEnergyTiming_profile_Low_HE = dbe_->bookProfile(histo, histo, 160, 0. , 160., 70, -48., 92. ) ;
00271 
00272     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_profile_HE" ) ;
00273     hadEnergyTiming_profile_HE = dbe_->bookProfile(histo, histo, 200, 0. , 800., 70, -48., 92. ) ;
00274     //-------------------------------------------------------------------------------------------
00275 
00276     //Everything else is not drawn
00277     if (useAllHistos_){
00278       sprintf (histo, "CaloTowersTask_sum_of_energy_HCAL_vs_ECAL_HE") ;
00279       meEnergyHcalvsEcal_HE    = dbe_->book2D(histo, histo, 500, 0., 500., 500, 0., 500.);
00280       
00281       sprintf (histo, "CaloTowersTask_energy_OUTER_HE" ) ;
00282       meEnergyHO_HE    = dbe_->book1D(histo, histo, 440, -200, 2000);   
00283       
00284       sprintf (histo, "CaloTowersTask_energy_of_ECAL_component_of_tower_HE" ) ;
00285       meEnergyEcalTower_HE = dbe_->book1D(histo, histo, 1100, -200, 2000); 
00286       
00287       sprintf (histo, "CaloTowersTask_energy_of_HCAL_component_of_tower_HE" ) ;
00288       meEnergyHcalTower_HE = dbe_->book1D(histo, histo, 1100 , -200 , 2000); 
00289       
00290       sprintf  (histo, "CaloTowersTask_energy_HcalPlusEcalPlusHO_HE" ) ;
00291       meTotEnergy_HE = dbe_->book1D(histo, histo,400, 0., 2000.) ;
00292       
00293       sprintf  (histo, "CaloTowersTask_map_energy_HE" );
00294       mapEnergy_HE = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00295       sprintf  (histo, "CaloTowersTask_map_energy_HCAL_HE");
00296       mapEnergyHcal_HE = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00297       sprintf  (histo, "CaloTowersTask_map_energy_ECAL_HE" );
00298       mapEnergyEcal_HE = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00299       
00300       sprintf  (histo, "CaloTowersTask_phi_MET_HE" ) ;
00301       phiMET_HE = dbe_->book1D(histo, histo, 72, -3.1415926535898, 3.1415926535898 ) ;
00302     }
00303   }
00304 
00305 
00306   if( isub == 3 || isub == 0) {
00307     //All cell histos are used
00308     sprintf  (histo, "number_of_bad_cells_Hcal_HF");
00309     numBadCellsHcal_HF = dbe_->book1D(histo, histo, 5, 0, 5);
00310     sprintf  (histo, "number_of_recovered_cells_Hcal_HF");
00311     numRcvCellsHcal_HF = dbe_->book1D(histo, histo, 5, 0, 5);
00312     sprintf  (histo, "number_of_problematic_cells_Hcal_HF");
00313     numPrbCellsHcal_HF = dbe_->book1D(histo, histo, 5, 0, 5); 
00314 
00315     //These are the five oldest CaloTower histos used: NTowers, E in HCAL/ECAL, MET and SET
00316     //-------------------------------------------------------------------------------------------
00317     sprintf (histo, "CaloTowersTask_energy_HCAL_HF" ) ;
00318     meEnergyHcal_HF    = dbe_->book1D(histo, histo, 440, -200, 2000);  
00319     
00320     sprintf (histo, "CaloTowersTask_energy_ECAL_HF" ) ;
00321     meEnergyEcal_HF    = dbe_->book1D(histo, histo, 440, -200, 2000); 
00322 
00323     sprintf (histo, "CaloTowersTask_number_of_fired_towers_HF" ) ;
00324     meNumFiredTowers_HF = dbe_->book1D(histo, histo, 1000, 0, 2000); 
00325 
00326     sprintf  (histo, "CaloTowersTask_MET_HF" ) ;
00327     MET_HF = dbe_->book1D(histo, histo, 500, 0. , 500. ) ;
00328     
00329     sprintf  (histo, "CaloTowersTask_SET_HF" ) ;
00330     SET_HF = dbe_->book1D(histo, histo, 200, 0. , 200. ) ;
00331     //-------------------------------------------------------------------------------------------
00332 
00333     //Timing histos and profiles -- all six are necessary
00334     //-------------------------------------------------------------------------------------------
00335     sprintf  (histo, "CaloTowersTask_EM_Timing_HF" ) ;
00336     emTiming_HF = dbe_->book1D(histo, histo, 110, -120., 100. ) ;
00337 
00338     sprintf  (histo, "CaloTowersTask_HAD_Timing_HF" ) ;
00339     hadTiming_HF = dbe_->book1D(histo, histo, 70, -48., 92. ) ;
00340 
00341     //EM
00342     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_HF" ) ;
00343     emEnergyTiming_HF = dbe_->book2D(histo, histo, 150, 0. , 300., 110, -120., 100.  ) ;
00344 
00345     sprintf  (histo, "CaloTowersTask_EM_Energy_Timing_profile_HF" ) ;
00346     emEnergyTiming_profile_HF = dbe_->bookProfile(histo, histo, 150, 0. , 300., 110, -120., 100.  ) ;
00347 
00348     //HAD (requires two different sets of histograms to lower RAM usage)
00349     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_Low_HF" ) ;
00350     hadEnergyTiming_Low_HF = dbe_->book2D(histo, histo, 40, 0. , 40., 70, -48., 92. ) ;
00351 
00352     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_HF" ) ;
00353     hadEnergyTiming_HF = dbe_->book2D(histo, histo, 200, 0. , 600., 70, -48., 92. ) ;
00354 
00355     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_profile_Low_HF" ) ;
00356     hadEnergyTiming_profile_Low_HF = dbe_->bookProfile(histo, histo, 40, 0. , 40., 70, -48., 92. ) ;
00357 
00358     sprintf  (histo, "CaloTowersTask_HAD_Energy_Timing_profile_HF" ) ;
00359     hadEnergyTiming_profile_HF = dbe_->bookProfile(histo, histo, 200, 0. , 600., 70, -48., 92. ) ;
00360     //-------------------------------------------------------------------------------------------
00361 
00362     //Everything else is not drawn
00363     if (useAllHistos_){
00364       sprintf (histo, "CaloTowersTask_sum_of_energy_HCAL_vs_ECAL_HF") ;
00365       meEnergyHcalvsEcal_HF    = dbe_->book2D(histo, histo, 500, 0., 500., 500, 0., 500.);
00366       
00367       sprintf (histo, "CaloTowersTask_energy_OUTER_HF" ) ;
00368       meEnergyHO_HF    = dbe_->book1D(histo, histo, 440, -200, 2000);   
00369       
00370       sprintf (histo, "CaloTowersTask_energy_of_ECAL_component_of_tower_HF" ) ;
00371       meEnergyEcalTower_HF = dbe_->book1D(histo, histo, 440, -200, 2000); 
00372       
00373       sprintf (histo, "CaloTowersTask_energy_of_HCAL_component_of_tower_HF" ) ;
00374       meEnergyHcalTower_HF = dbe_->book1D(histo, histo, 440 , -200 , 2000); 
00375       
00376       sprintf  (histo, "CaloTowersTask_energy_HcalPlusEcalPlusHO_HF" ) ;
00377       meTotEnergy_HF = dbe_->book1D(histo, histo, 400, 0., 2000.) ;
00378       
00379       sprintf  (histo, "CaloTowersTask_map_energy_HF" );
00380       mapEnergy_HF = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00381       sprintf  (histo, "CaloTowersTask_map_energy_HCAL_HF");
00382       mapEnergyHcal_HF = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00383       sprintf  (histo, "CaloTowersTask_map_energy_ECAL_HF" );
00384       mapEnergyEcal_HF = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00385       
00386       sprintf  (histo, "CaloTowersTask_phi_MET_HF" ) ;
00387       phiMET_HF = dbe_->book1D(histo, histo, 72, -3.1415926535898, 3.1415926535898 ) ;
00388     }
00389   }
00390 
00391 }
00392 
00393 
00394 void CaloTowersAnalyzer::beginRun() {}
00395 
00396 void CaloTowersAnalyzer::endRun() {}
00397 
00398 CaloTowersAnalyzer::~CaloTowersAnalyzer() {
00399   
00400 }
00401 
00402 void CaloTowersAnalyzer::endJob() {
00403   if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00404 }
00405 
00406 void CaloTowersAnalyzer::beginJob(){ nevent = 0; }
00407 
00408 void CaloTowersAnalyzer::analyze(edm::Event const& event, edm::EventSetup const& c) {
00409 
00410   nevent++;
00411 
00412   edm::Handle<CaloTowerCollection> towers;
00413   event.getByLabel(theCaloTowerCollectionLabel,towers);
00414   CaloTowerCollection::const_iterator cal;
00415 
00416   double met;
00417   double phimet;
00418 
00419   // ieta scan 
00420   //double partR  = 0.3;
00421   //double Rmin   = 9999.;
00422   //double Econe  = 0.;
00423   //double Hcone  = 0.;
00424   //double Ee1    = 0.;
00425   //double Eh1    = 0.;
00426 
00427   // HB   
00428   double sumEnergyHcal_HB = 0.;
00429   double sumEnergyEcal_HB = 0.;
00430   double sumEnergyHO_HB   = 0.;
00431   Int_t numFiredTowers_HB = 0;
00432   double metx_HB   =  0.;
00433   double mety_HB   =  0.;
00434   double metz_HB   =  0.;
00435   double sEt_HB    =  0.;
00436   // HE   
00437   double sumEnergyHcal_HE = 0.;
00438   double sumEnergyEcal_HE = 0.;
00439   double sumEnergyHO_HE   = 0.;
00440   Int_t numFiredTowers_HE = 0;
00441   double metx_HE   =  0.;
00442   double mety_HE   =  0.;
00443   double metz_HE   =  0.;
00444   double sEt_HE    =  0.;
00445   // HF   
00446   double sumEnergyHcal_HF = 0.;
00447   double sumEnergyEcal_HF = 0.;
00448   double sumEnergyHO_HF   = 0.;
00449   Int_t numFiredTowers_HF = 0;
00450   double metx_HF   =  0.;
00451   double mety_HF   =  0.;
00452   double metz_HF   =  0.;
00453   double sEt_HF    =  0.;
00454 
00455   for ( cal = towers->begin(); cal != towers->end(); ++cal ) {
00456     
00457     double eE     = cal->emEnergy();
00458     double eH     = cal->hadEnergy();
00459     double eHO    = cal->outerEnergy();
00460     double etaT   = cal->eta();
00461     //    double phiT   = cal->phi();
00462     double en     = cal->energy();
00463     double etT    = cal->et();
00464     double had_tm = cal->hcalTime();
00465     double em_tm  = cal->ecalTime();
00466 
00467     int numBadEcalCells = cal->numBadEcalCells();
00468     int numRcvEcalCells = cal->numRecoveredEcalCells();
00469     int numPrbEcalCells = cal->numProblematicEcalCells();
00470 
00471     int numBadHcalCells = cal->numBadHcalCells();
00472     int numRcvHcalCells = cal->numRecoveredHcalCells();
00473     int numPrbHcalCells = cal->numProblematicHcalCells(); 
00474 
00475     math::RhoEtaPhiVector mom(cal->et(), cal->eta(), cal->phi());
00476                               //  Vector mom  = cal->momentum(); 
00477   
00478     // cell properties    
00479     CaloTowerDetId idT = cal->id();
00480     int ieta = idT.ieta();
00481     if(ieta > 0) ieta -= 1;
00482     int iphi = idT.iphi();
00483 
00484     // ecal:  0 EcalBarrel  1 EcalEndcap
00485     // hcal:  0 hcalBarrel  1 HcalEndcap  2 HcalForward
00486     std::vector<int> inEcals(2), inHcals(3);
00487     unsigned int constitSize = cal->constituentsSize();
00488     for(unsigned int ic=0; ic<constitSize; ic++){
00489        DetId detId = cal->constituent(ic);
00490        if(detId.det() == DetId::Ecal){
00491           if( detId.subdetId()==EcalBarrel ) inEcals[0] =1;
00492           else if( detId.subdetId()==EcalEndcap ) inEcals[1] =1;
00493        }
00494        if(detId.det() == DetId::Hcal){
00495           if( HcalDetId(detId).subdet()==HcalBarrel ) inHcals[0] =1;
00496           else if( HcalDetId(detId).subdet()==HcalEndcap ) inHcals[1] =1;
00497           else if( HcalDetId(detId).subdet()==HcalForward ) inHcals[2] =1;
00498        }
00499     }
00500     //All cell histos are used
00501     if( inEcals[0] ) {
00502        numBadCellsEcal_EB->Fill(numBadEcalCells);
00503        numRcvCellsEcal_EB->Fill(numRcvEcalCells);
00504        numPrbCellsEcal_EB->Fill(numPrbEcalCells);
00505     }
00506     if( inEcals[1] ) {
00507        numBadCellsEcal_EE->Fill(numBadEcalCells);
00508        numRcvCellsEcal_EE->Fill(numRcvEcalCells);
00509        numPrbCellsEcal_EE->Fill(numPrbEcalCells);
00510     } 
00511     
00512     //Ntowers is used in EndJob, occupancy_map is used for occupancy vs ieta
00513     Ntowers_vs_ieta -> Fill(double(ieta),1.);
00514     occupancy_map -> Fill(double(ieta),double(iphi));
00515     
00516 
00517     if((isub == 0 || isub == 1) 
00518        && (fabs(etaT) <  etaMax[0] && fabs(etaT) >= etaMin[0] )) {
00519       
00520       //All cell histos are used
00521       numBadCellsHcal_HB->Fill(numBadHcalCells);
00522       numRcvCellsHcal_HB->Fill(numRcvHcalCells);
00523       numPrbCellsHcal_HB->Fill(numPrbHcalCells);
00524       
00525       //Map energy histos are not used
00526       if (useAllHistos_){
00527         mapEnergy_HB     -> Fill(double(ieta), double(iphi), en); 
00528         mapEnergyHcal_HB -> Fill(double(ieta), double(iphi), eH); 
00529         mapEnergyEcal_HB -> Fill(double(ieta), double(iphi), eE); 
00530       }
00531       //      std::cout << " e_ecal = " << eE << std::endl;
00532       
00533       //  simple sums
00534       sumEnergyHcal_HB += eH;
00535       sumEnergyEcal_HB += eE;
00536       sumEnergyHO_HB   += eHO;
00537       
00538       numFiredTowers_HB++;
00539       
00540       //Not used
00541       if (useAllHistos_){
00542         meEnergyEcalTower_HB->Fill(eE);
00543         meEnergyHcalTower_HB->Fill(eH);    
00544       }
00545       
00546       // MET, SET & phimet
00547       //  double  etT = cal->et();
00548       metx_HB += mom.x();   
00549       mety_HB += mom.y();  //etT * sin(phiT);          
00550       sEt_HB  += etT;
00551 
00552       //Timing (all histos are used)
00553       emTiming_HB->Fill(em_tm);
00554       hadTiming_HB->Fill(had_tm);
00555 
00556       emEnergyTiming_Low_HB->Fill(eE, em_tm);
00557       emEnergyTiming_HB->Fill(eE, em_tm);
00558       emEnergyTiming_High_HB->Fill(eE, em_tm);
00559       emEnergyTiming_profile_Low_HB->Fill(eE, em_tm);
00560       emEnergyTiming_profile_HB->Fill(eE, em_tm);
00561       emEnergyTiming_profile_High_HB->Fill(eE, em_tm);
00562 
00563       hadEnergyTiming_Low_HB->Fill(eH, had_tm); 
00564       hadEnergyTiming_HB->Fill(eH, had_tm); 
00565       hadEnergyTiming_High_HB->Fill(eH, had_tm); 
00566       hadEnergyTiming_profile_Low_HB->Fill(eH, had_tm);     
00567       hadEnergyTiming_profile_HB->Fill(eH, had_tm);     
00568       hadEnergyTiming_profile_High_HB->Fill(eH, had_tm);     
00569     }
00570    
00571     if((isub == 0 || isub == 2) 
00572        && (fabs(etaT) <  etaMax[1] && fabs(etaT) >= etaMin[1] )) {
00573      
00574       //All cell histos are used
00575       numBadCellsHcal_HE->Fill(numBadHcalCells);
00576       numRcvCellsHcal_HE->Fill(numRcvHcalCells);
00577       numPrbCellsHcal_HE->Fill(numPrbHcalCells);
00578     
00579       //Map energy histos are not used
00580       if (useAllHistos_){
00581         mapEnergy_HE     -> Fill(double(ieta), double(iphi), en); 
00582         mapEnergyHcal_HE -> Fill(double(ieta), double(iphi), eH); 
00583         mapEnergyEcal_HE -> Fill(double(ieta), double(iphi), eE); 
00584       }
00585       //      std::cout << " e_ecal = " << eE << std::endl;
00586       
00587       //  simple sums
00588       sumEnergyHcal_HE += eH;
00589       sumEnergyEcal_HE += eE;
00590       sumEnergyHO_HE   += eHO;
00591       
00592       numFiredTowers_HE++;
00593       
00594       //Not used
00595       if (useAllHistos_){
00596         meEnergyEcalTower_HE->Fill(eE);
00597         meEnergyHcalTower_HE->Fill(eH);    
00598       }
00599       // MET, SET & phimet
00600       //  double  etT = cal->et();
00601       metx_HE += mom.x();   
00602       mety_HE += mom.y();  //etT * sin(phiT);          
00603       sEt_HE  += etT;    
00604 
00605       //Timing (all histos are used)
00606       emTiming_HE->Fill(em_tm);
00607       hadTiming_HE->Fill(had_tm);
00608 
00609       emEnergyTiming_Low_HE->Fill(eE, em_tm);
00610       emEnergyTiming_HE->Fill(eE, em_tm);
00611       emEnergyTiming_profile_Low_HE->Fill(eE, em_tm);
00612       emEnergyTiming_profile_HE->Fill(eE, em_tm);
00613 
00614       hadEnergyTiming_Low_HE->Fill(eH, had_tm);     
00615       hadEnergyTiming_HE->Fill(eH, had_tm);   
00616       hadEnergyTiming_profile_Low_HE->Fill(eH, had_tm);     
00617       hadEnergyTiming_profile_HE->Fill(eH, had_tm);     
00618     }
00619 
00620     if((isub == 0 || isub == 3) 
00621        && (fabs(etaT) <  etaMax[2] && fabs(etaT) >= etaMin[2] )) {
00622       
00623       //All cell histos are used
00624       numBadCellsHcal_HF->Fill(numBadHcalCells);
00625       numRcvCellsHcal_HF->Fill(numRcvHcalCells);
00626       numPrbCellsHcal_HF->Fill(numPrbHcalCells);
00627      
00628       //Map energy histos are not used
00629       if (useAllHistos_){
00630         mapEnergy_HF     -> Fill(double(ieta), double(iphi), en); 
00631         mapEnergyHcal_HF -> Fill(double(ieta), double(iphi), eH); 
00632         mapEnergyEcal_HF -> Fill(double(ieta), double(iphi), eE); 
00633       }
00634       //      std::cout << " e_ecal = " << eE << std::endl;
00635       
00636       //  simple sums
00637       sumEnergyHcal_HF += eH;
00638       sumEnergyEcal_HF += eE;
00639       sumEnergyHO_HF   += eHO;
00640       
00641       numFiredTowers_HF++;
00642       
00643       //Not used
00644       if (useAllHistos_){
00645         meEnergyEcalTower_HF->Fill(eE);
00646         meEnergyHcalTower_HF->Fill(eH);    
00647       }
00648       // MET, SET & phimet
00649       //  double  etT = cal->et();
00650       metx_HF += mom.x();   
00651       mety_HF += mom.y();  //etT * sin(phiT);          
00652       sEt_HF  += etT;    
00653 
00654       //Timing (all histos are used)
00655       emTiming_HF->Fill(em_tm);
00656       hadTiming_HF->Fill(had_tm);
00657       emEnergyTiming_HF->Fill(eE, em_tm);
00658       emEnergyTiming_profile_HF->Fill(eE, em_tm);
00659 
00660       hadEnergyTiming_Low_HF->Fill(eH, had_tm);     
00661       hadEnergyTiming_HF->Fill(eH, had_tm);     
00662       hadEnergyTiming_profile_Low_HF->Fill(eH, had_tm);     
00663       hadEnergyTiming_profile_HF->Fill(eH, had_tm);     
00664     }
00665 
00666 
00667 
00668   } // end of Towers cycle 
00669 
00670   //These are the six single pion histos; only the second set is used
00671 
00672   if(isub == 0 || isub == 1) {
00673     met    = sqrt(metx_HB*metx_HB + mety_HB*mety_HB);
00674     Vector metv(metx_HB,mety_HB,metz_HB);
00675     phimet = metv.phi();
00676 
00677     //Five oldest drawn histos first; the rest are not used
00678     meEnergyHcal_HB->      Fill(sumEnergyHcal_HB);
00679     meEnergyEcal_HB->      Fill(sumEnergyEcal_HB);
00680     meNumFiredTowers_HB->  Fill(numFiredTowers_HB);
00681     MET_HB    -> Fill (met); 
00682     SET_HB    -> Fill (sEt_HB); 
00683     
00684     if (useAllHistos_){
00685       meEnergyHcalvsEcal_HB->Fill(sumEnergyEcal_HB, sumEnergyHcal_HB);
00686       meEnergyHO_HB->        Fill(sumEnergyHO_HB);
00687       meTotEnergy_HB->       Fill(sumEnergyHcal_HB+sumEnergyEcal_HB
00688                                   +sumEnergyHO_HB);    
00689       phiMET_HB -> Fill (phimet);
00690     } 
00691   }    
00692 
00693 
00694   if(isub == 0 || isub == 2) {
00695     met    = sqrt(metx_HE*metx_HE + mety_HE*mety_HE);
00696     Vector metv(metx_HE,mety_HE,metz_HE);
00697     phimet = metv.phi();
00698 
00699     //Five oldest drawn histos first; the rest are not used
00700     meEnergyHcal_HE->      Fill(sumEnergyHcal_HE);
00701     meEnergyEcal_HE->      Fill(sumEnergyEcal_HE);
00702     meNumFiredTowers_HE->  Fill(numFiredTowers_HE);
00703     MET_HE    -> Fill (met); 
00704     SET_HE    -> Fill (sEt_HE); 
00705     
00706     if (useAllHistos_){
00707       meEnergyHcalvsEcal_HE->Fill(sumEnergyEcal_HE, sumEnergyHcal_HE);
00708       meEnergyHO_HE->        Fill(sumEnergyHO_HE);
00709       meTotEnergy_HE->       Fill(sumEnergyHcal_HE+sumEnergyEcal_HE
00710                                   +sumEnergyHO_HE);    
00711       phiMET_HE -> Fill (phimet); 
00712     }
00713   }
00714 
00715   if(isub == 0 || isub == 3) {
00716     met    = sqrt(metx_HF*metx_HF + mety_HF*mety_HF);
00717     Vector metv(metx_HF,mety_HF,metz_HF);
00718     phimet = metv.phi();
00719     
00720     //Five oldest drawn histos first; the rest are not used
00721     meEnergyHcal_HF->      Fill(sumEnergyHcal_HF);
00722     meEnergyEcal_HF->      Fill(sumEnergyEcal_HF);
00723     meNumFiredTowers_HF->  Fill(numFiredTowers_HF);
00724     MET_HF    -> Fill (met); 
00725     SET_HF    -> Fill (sEt_HF); 
00726 
00727     if (useAllHistos_){
00728       meEnergyHcalvsEcal_HF->Fill(sumEnergyEcal_HF, sumEnergyHcal_HF);
00729       meEnergyHO_HF->        Fill(sumEnergyHO_HF);
00730       meTotEnergy_HF->       Fill(sumEnergyHcal_HF+sumEnergyEcal_HF
00731                                   +sumEnergyHO_HF);    
00732       phiMET_HF -> Fill (phimet);
00733     }
00734   }
00735 
00736 }
00737 
00738 double CaloTowersAnalyzer::dR(double eta1, double phi1, double eta2, double phi2) { 
00739   double PI = 3.1415926535898;
00740   double deltaphi= phi1 - phi2;
00741   if( phi2 > phi1 ) { deltaphi= phi2 - phi1;}
00742   if(deltaphi > PI) { deltaphi = 2.*PI - deltaphi;}
00743   double deltaeta = eta2 - eta1;
00744   double tmp = sqrt(deltaeta* deltaeta + deltaphi*deltaphi);
00745   return tmp;
00746 }
00747 
00748 DEFINE_FWK_MODULE(CaloTowersAnalyzer);
00749