CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Validation/HcalRecHits/src/HcalRecHitsValidation.cc

Go to the documentation of this file.
00001 #include "Validation/HcalRecHits/interface/HcalRecHitsValidation.h"
00002 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00003 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00004 
00005 HcalRecHitsValidation::HcalRecHitsValidation(edm::ParameterSet const& conf) {
00006   // DQM ROOT output
00007   outputFile_ = conf.getUntrackedParameter<std::string>("outputFile", "myfile.root");
00008   
00009   if ( outputFile_.size() != 0 ) {
00010     edm::LogInfo("OutputInfo") << " Hcal RecHit Task histograms will be saved to '" << outputFile_.c_str() << "'";
00011   } else {
00012     edm::LogInfo("OutputInfo") << " Hcal RecHit Task histograms will NOT be saved";
00013   }
00014   
00015   nevtot = 0;
00016   
00017   dbe_ = 0;
00018   // get hold of back-end interface
00019   dbe_ = edm::Service<DQMStore>().operator->();
00020    
00021   Char_t histo[200];
00022 
00023   hcalselector_ = conf.getUntrackedParameter<std::string>("hcalselector", "all");
00024   ecalselector_ = conf.getUntrackedParameter<std::string>("ecalselector", "yes");
00025   eventype_     = conf.getUntrackedParameter<std::string>("eventype", "single");
00026   sign_         = conf.getUntrackedParameter<std::string>("sign", "*");
00027   mc_           = conf.getUntrackedParameter<std::string>("mc", "yes");
00028   famos_        = conf.getUntrackedParameter<bool>("Famos", false);
00029   useAllHistos_ = conf.getUntrackedParameter<bool>("useAllHistos", false);
00030 
00031   //Collections
00032   theHBHERecHitCollectionLabel = conf.getUntrackedParameter<edm::InputTag>("HBHERecHitCollectionLabel");
00033   theHFRecHitCollectionLabel   = conf.getUntrackedParameter<edm::InputTag>("HFRecHitCollectionLabel");
00034   theHORecHitCollectionLabel   = conf.getUntrackedParameter<edm::InputTag>("HORecHitCollectionLabel");
00035 
00036   //  std::cout << "*** famos_ = " << famos_ << std::endl; 
00037 
00038   subdet_ = 5;
00039   if (hcalselector_ == "noise") subdet_ = 0;
00040   if (hcalselector_ == "HB"   ) subdet_ = 1;
00041   if (hcalselector_ == "HE"   ) subdet_ = 2;
00042   if (hcalselector_ == "HO"   ) subdet_ = 3;
00043   if (hcalselector_ == "HF"   ) subdet_ = 4;
00044   if (hcalselector_ == "all"  ) subdet_ = 5;
00045   if (hcalselector_ == "ZS"   ) subdet_ = 6;
00046 
00047   etype_ = 1;
00048   if (eventype_ == "multi") etype_ = 2;
00049 
00050   iz = 1;
00051   if(sign_ == "-") iz = -1;
00052   if(sign_ == "*") iz = 0;
00053 
00054   imc = 1;
00055   if(mc_ == "no") imc = 0;
00056 
00057   if ( dbe_ ) {
00058     dbe_->setCurrentFolder("HcalRecHitsV/HcalRecHitTask");
00059 
00060     // General counters (drawn)
00061     sprintf  (histo, "N_HB" );
00062     Nhb = dbe_->book1D(histo, histo, 2600,0.,2600.);
00063     sprintf  (histo, "N_HE" );
00064     Nhe = dbe_->book1D(histo, histo, 2600,0.,2600.);
00065     sprintf  (histo, "N_HO" );
00066     Nho = dbe_->book1D(histo, histo, 2200,0.,2200.);
00067     sprintf  (histo, "N_HF" );
00068     Nhf = dbe_->book1D(histo, histo, 1800,0., 1800.);
00069 
00070     // ZS
00071     if(subdet_ == 6) {
00072 
00073       for (unsigned int i1 = 0;  i1 < 82; i1++) {
00074         for (unsigned int i2 = 0;  i2 < 72; i2++) {
00075           for (unsigned int i3 = 0;  i3 < 4;  i3++) {
00076             for (unsigned int i4 = 0;  i4 < 4;  i4++) {
00077               emap_min [i1][i2][i3][i4] = 99999.;     
00078             }
00079           }
00080         }
00081       }
00082 
00083       //None of the ZS histos are drawn
00084       if (useAllHistos_){
00085         sprintf  (histo, "ZSmin_map_depth1" );
00086         map_depth1 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00087         sprintf  (histo, "ZSmin_map_depth2" );
00088         map_depth2 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00089         sprintf  (histo, "ZSmin_map_depth3" );
00090         map_depth3 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00091         sprintf  (histo, "ZSmin_map_depth4" );
00092         map_depth4 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00093         
00094       
00095         sprintf  (histo, "ZS_Nreco_HB1" );
00096         ZS_nHB1 = dbe_->book1D(histo, histo, 2500, 0., 2500.);
00097         sprintf  (histo, "ZS_Nreco_HB2" );
00098         ZS_nHB2 = dbe_->book1D(histo, histo,  500, 0.,  500.);
00099         sprintf  (histo, "ZS_Nreco_HE1" );
00100         ZS_nHE1 = dbe_->book1D(histo, histo, 2000, 0., 2000.);
00101         sprintf  (histo, "ZS_Nreco_HE2" );
00102         ZS_nHE2 = dbe_->book1D(histo, histo, 2000, 0., 2000.);
00103         sprintf  (histo, "ZS_Nreco_HE3" );
00104         ZS_nHE3 = dbe_->book1D(histo, histo,  500, 0.,  500.);
00105         sprintf  (histo, "ZS_Nreco_HO" );
00106         ZS_nHO  = dbe_->book1D(histo, histo, 2500, 0., 2500.);
00107         sprintf  (histo, "ZS_Nreco_HF1" );
00108         ZS_nHF1 = dbe_->book1D(histo, histo, 1000, 0., 1000.);
00109         sprintf  (histo, "ZS_Nreco_HF2" );
00110         ZS_nHF2 = dbe_->book1D(histo, histo, 1000, 0., 1000.);
00111       
00112         sprintf  (histo, "ZSmin_simple1D_HB1" );
00113         ZS_HB1 = dbe_->book1D(histo, histo,120, -2., 10.);
00114         sprintf  (histo, "ZSmin_simple1D_HB2" );
00115         ZS_HB2 = dbe_->book1D(histo, histo,120, -2., 10.);
00116         sprintf  (histo, "ZSmin_simple1D_HE1" );
00117         ZS_HE1 = dbe_->book1D(histo, histo,120, -2., 10.);
00118         sprintf  (histo, "ZSmin_simple1D_HE2" );
00119         ZS_HE2 = dbe_->book1D(histo, histo,120, -2., 10.);
00120         sprintf  (histo, "ZSmin_simple1D_HE3" );
00121         ZS_HE3 = dbe_->book1D(histo, histo,120, -2., 10.);
00122         sprintf  (histo, "ZSmin_simple1D_HO" );
00123         ZS_HO = dbe_->book1D(histo, histo,120, -2., 10.);
00124         sprintf  (histo, "ZSmin_simple1D_HF1" );
00125         ZS_HF1 = dbe_->book1D(histo, histo,200, -10., 10.);
00126         sprintf  (histo, "ZSmin_simple1D_HF2" );
00127         ZS_HF2 = dbe_->book1D(histo, histo,200, -10., 10.);
00128         
00129         sprintf  (histo, "ZSmin_sequential1D_HB1" );
00130         ZS_seqHB1 = dbe_->book1D(histo, histo,2400, -1200., 1200.);
00131         sprintf  (histo, "ZSmin_sequential1D_HB2" );
00132         ZS_seqHB2 = dbe_->book1D(histo, histo,2400, -1200., 1200.);
00133         sprintf  (histo, "ZSmin_sequential1D_HE1" );
00134         ZS_seqHE1 = dbe_->book1D(histo, histo,4400, -2200., 2200.);
00135         sprintf  (histo, "ZSmin_sequential1D_HE2" );
00136         ZS_seqHE2 = dbe_->book1D(histo, histo,4400, -2200., 2200.);
00137         sprintf  (histo, "ZSmin_sequential1D_HE3" );
00138         ZS_seqHE3 = dbe_->book1D(histo, histo,4400, -2200., 2200.);
00139         sprintf  (histo, "ZSmin_sequential1D_HO" );
00140         ZS_seqHO  = dbe_->book1D(histo, histo,2400, -1200., 1200.);
00141         sprintf  (histo, "ZSmin_sequential1D_HF1" );
00142         ZS_seqHF1 = dbe_->book1D(histo, histo,6000, -3000., 3000.);
00143         sprintf  (histo, "ZSmin_sequential1D_HF2" );
00144         ZS_seqHF2 = dbe_->book1D(histo, histo,6000, -3000., 3000.);
00145       }
00146     }
00147 
00148     // ALL others, except ZS
00149     else {
00150   
00151       sprintf  (histo, "emap_depth1" );
00152       emap_depth1 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00153       sprintf  (histo, "emap_depth2" );
00154       emap_depth2 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00155       sprintf  (histo, "emap_depth3" );
00156       emap_depth3 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00157       sprintf  (histo, "emap_depth4" );
00158       emap_depth4 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00159       
00160       if (useAllHistos_){
00161         
00162         if (ecalselector_ == "yes") {
00163           sprintf  (histo, "map_ecal" );
00164           map_ecal = dbe_->book2D(histo, histo, 70, -3.045, 3.045, 72, -3.1415926536, 3.1415926536);
00165         }
00166       }
00167       
00168       //The mean energy histos are drawn, but not the RMS or emean seq
00169       sprintf  (histo, "emean_vs_ieta_HB1" );
00170       emean_vs_ieta_HB1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s");
00171       sprintf  (histo, "emean_vs_ieta_HB2" );
00172       emean_vs_ieta_HB2 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s");
00173       sprintf  (histo, "emean_vs_ieta_HE1" );
00174       emean_vs_ieta_HE1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10. ,2000., "s" );
00175       sprintf  (histo, "emean_vs_ieta_HE2" );
00176       emean_vs_ieta_HE2 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s");
00177       sprintf  (histo, "emean_vs_ieta_HE3" );
00178       emean_vs_ieta_HE3 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s" );
00179       sprintf  (histo, "emean_vs_ieta_HO" );
00180       emean_vs_ieta_HO = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s" );
00181       sprintf  (histo, "emean_vs_ieta_HF1" );
00182       emean_vs_ieta_HF1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s" );
00183       sprintf  (histo, "emean_vs_ieta_HF2" );
00184       emean_vs_ieta_HF2 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2010, -10., 2000., "s" );
00185 
00186       if (useAllHistos_){
00187         sprintf  (histo, "RMS_vs_ieta_HB1" );
00188         RMS_vs_ieta_HB1 = dbe_->book1D(histo, histo, 82, -41., 41.);
00189         sprintf  (histo, "RMS_vs_ieta_HB2" );
00190         RMS_vs_ieta_HB2 = dbe_->book1D(histo, histo, 82, -41., 41.);
00191         sprintf  (histo, "RMS_vs_ieta_HE1" );
00192         RMS_vs_ieta_HE1 = dbe_->book1D(histo, histo, 82, -41., 41.);
00193         sprintf  (histo, "RMS_vs_ieta_HE2" );
00194         RMS_vs_ieta_HE2 = dbe_->book1D(histo, histo, 82, -41., 41.);
00195         sprintf  (histo, "RMS_vs_ieta_HE3" );
00196         RMS_vs_ieta_HE3 = dbe_->book1D(histo, histo, 82, -41., 41.);
00197         sprintf  (histo, "RMS_vs_ieta_HO" );
00198         RMS_vs_ieta_HO = dbe_->book1D(histo, histo, 82, -41., 41.);
00199         sprintf  (histo, "RMS_vs_ieta_HF1" );
00200         RMS_vs_ieta_HF1 = dbe_->book1D(histo, histo, 82, -41., 41.);
00201         sprintf  (histo, "RMS_vs_ieta_HF2" );
00202         RMS_vs_ieta_HF2 = dbe_->book1D(histo, histo, 82, -41., 41.);
00203         
00204         // Sequential emean and RMS
00205         sprintf  (histo, "emean_seq_HB1" );
00206         emean_seqHB1 = dbe_->bookProfile(histo, histo, 2400, -1200., 1200.,  2010, -10., 2000., "s" );
00207         sprintf  (histo, "emean_seq_HB2" );
00208         emean_seqHB2 = dbe_->bookProfile(histo, histo, 2400, -1200., 1200.,  2010, -10., 2000., "s" );
00209         sprintf  (histo, "emean_seq_HE1" );
00210         emean_seqHE1 = dbe_->bookProfile(histo, histo, 4400, -2200., 2200.,  2010, -10., 2000., "s" );
00211         sprintf  (histo, "emean_seq_HE2" );
00212         emean_seqHE2 = dbe_->bookProfile(histo, histo, 4400, -2200., 2200.,  2010, -10., 2000., "s" );
00213         sprintf  (histo, "emean_seq_HE3" );
00214         emean_seqHE3 = dbe_->bookProfile(histo, histo, 4400, -2200., 2200.,  2010, -10., 2000., "s" );
00215         sprintf  (histo, "emean_seq_HO" );
00216         emean_seqHO = dbe_->bookProfile(histo, histo,  2400, -1200., 1200.,  2010, -10., 2000., "s" );
00217         sprintf  (histo, "emean_seq_HF1" );
00218         emean_seqHF1 = dbe_->bookProfile(histo, histo, 6000, -3000., 3000.,  2010, -10., 2000., "s" );
00219         sprintf  (histo, "emean_seq_HF2" );
00220         emean_seqHF2 = dbe_->bookProfile(histo, histo, 6000, -3000., 3000.,  2010, -10., 2000., "s" );
00221         
00222         sprintf  (histo, "RMS_seq_HB1" );
00223         RMS_seq_HB1 = dbe_->book1D(histo, histo, 2400, -1200., 1200.);
00224         sprintf  (histo, "RMS_seq_HB2" );
00225         RMS_seq_HB2 = dbe_->book1D(histo, histo, 2400, -1200., 1200.);
00226         sprintf  (histo, "RMS_seq_HE1" );
00227         RMS_seq_HE1 = dbe_->book1D(histo, histo, 4400, -2200., 2200.);
00228         sprintf  (histo, "RMS_seq_HE2" );
00229         RMS_seq_HE2 = dbe_->book1D(histo, histo, 4400, -2200., 2200.);
00230         sprintf  (histo, "RMS_seq_HE3" );
00231         RMS_seq_HE3 = dbe_->book1D(histo, histo, 4400, -2200., 2200.);
00232         sprintf  (histo, "RMS_seq_HO" );
00233         RMS_seq_HO = dbe_->book1D(histo, histo, 2400, -1200., 1200.);
00234         sprintf  (histo, "RMS_seq_HF1" );
00235         RMS_seq_HF1 = dbe_->book1D(histo, histo, 6000, -3000., 3000.);
00236         sprintf  (histo, "RMS_seq_HF2" );
00237         RMS_seq_HF2 = dbe_->book1D(histo, histo, 6000, -3000., 3000.);
00238       }
00239       // Occupancy
00240       //The only occupancy histos drawn are occupancy vs. ieta
00241       //but the maps are needed because this is where the latter are filled from
00242       sprintf  (histo, "occupancy_map_HB1" );
00243       occupancy_map_HB1 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00244       sprintf  (histo, "occupancy_map_HB2" );
00245       occupancy_map_HB2 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00246       sprintf  (histo, "occupancy_map_HE1" );
00247       occupancy_map_HE1 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00248       sprintf  (histo, "occupancy_map_HE2" );
00249       occupancy_map_HE2 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);      
00250       sprintf  (histo, "occupancy_map_HE3" );
00251       occupancy_map_HE3 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00252       sprintf  (histo, "occupancy_map_HO" );
00253       occupancy_map_HO = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);      
00254       sprintf  (histo, "occupancy_map_HF1" );
00255       occupancy_map_HF1 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00256       sprintf  (histo, "occupancy_map_HF2" );
00257       occupancy_map_HF2 = dbe_->book2D(histo, histo, 82, -41., 41., 72, 0., 72.);
00258       
00259       //These are drawn
00260       sprintf  (histo, "occupancy_vs_ieta_HB1" );
00261       occupancy_vs_ieta_HB1 = dbe_->book1D(histo, histo, 82, -41., 41.);
00262       sprintf  (histo, "occupancy_vs_ieta_HB2" );
00263       occupancy_vs_ieta_HB2 = dbe_->book1D(histo, histo, 82, -41., 41.);
00264       sprintf  (histo, "occupancy_vs_ieta_HE1" );
00265       occupancy_vs_ieta_HE1 = dbe_->book1D(histo, histo, 82, -41., 41.);
00266       sprintf  (histo, "occupancy_vs_ieta_HE2" );
00267       occupancy_vs_ieta_HE2 = dbe_->book1D(histo, histo, 82, -41., 41.);
00268       sprintf  (histo, "occupancy_vs_ieta_HE3" );
00269       occupancy_vs_ieta_HE3 = dbe_->book1D(histo, histo, 82, -41., 41.);
00270       sprintf  (histo, "occupancy_vs_ieta_HO" );
00271       occupancy_vs_ieta_HO = dbe_->book1D(histo, histo, 82, -41., 41.);
00272       sprintf  (histo, "occupancy_vs_ieta_HF1" );
00273       occupancy_vs_ieta_HF1 = dbe_->book1D(histo, histo, 82, -41., 41.);
00274       sprintf  (histo, "occupancy_vs_ieta_HF2" );
00275       occupancy_vs_ieta_HF2 = dbe_->book1D(histo, histo, 82, -41., 41.);
00276       
00277       //These are not
00278       if (useAllHistos_){
00279         sprintf  (histo, "occ_sequential1D_HB1" );
00280         occupancy_seqHB1 = dbe_->book1D(histo, histo,2400, -1200., 1200.);
00281         sprintf  (histo, "occ_sequential1D_HB2" );
00282         occupancy_seqHB2 = dbe_->book1D(histo, histo,2400, -1200., 1200.);
00283         sprintf  (histo, "occ_sequential1D_HE1" );
00284         occupancy_seqHE1 = dbe_->book1D(histo, histo,4400, -2200., 2200.);
00285         sprintf  (histo, "occ_sequential1D_HE2" );
00286         occupancy_seqHE2 = dbe_->book1D(histo, histo,4400, -2200., 2200.);
00287         sprintf  (histo, "occ_sequential1D_HE3" );
00288         occupancy_seqHE3 = dbe_->book1D(histo, histo,4400, -2200., 2200.);
00289         sprintf  (histo, "occ_sequential1D_HO" );
00290         occupancy_seqHO  = dbe_->book1D(histo, histo,2400, -1200., 1200.);
00291         sprintf  (histo, "occ_sequential1D_HF1" );
00292         occupancy_seqHF1 = dbe_->book1D(histo, histo,6000, -3000., 3000.);
00293         sprintf  (histo, "occ_sequential1D_HF2" );
00294         occupancy_seqHF2 = dbe_->book1D(histo, histo,6000, -3000., 3000.);
00295       }
00296 
00297       //All status word histos except HF67 are drawn
00298       sprintf (histo, "HcalRecHitTask_RecHit_StatusWord_HB" ) ;
00299       RecHit_StatusWord_HB = dbe_->book1D(histo, histo, 32 , -0.5, 31.5); 
00300       
00301       sprintf (histo, "HcalRecHitTask_RecHit_StatusWord_HE" ) ;
00302       RecHit_StatusWord_HE = dbe_->book1D(histo, histo, 32 , -0.5, 31.5); 
00303 
00304       sprintf (histo, "HcalRecHitTask_RecHit_StatusWord_HF" ) ;
00305       RecHit_StatusWord_HF = dbe_->book1D(histo, histo, 32 , -0.5, 31.5); 
00306 
00307       if (useAllHistos_){
00308         sprintf (histo, "HcalRecHitTask_RecHit_StatusWord_HF67" ) ;
00309         RecHit_StatusWord_HF67 = dbe_->book1D(histo, histo, 3 , 0.5, 3.5); 
00310       }
00311       sprintf (histo, "HcalRecHitTask_RecHit_StatusWord_HO" ) ;
00312       RecHit_StatusWord_HO = dbe_->book1D(histo, histo, 32 , -0.5, 31.5); 
00313 
00314       //Aux status word histos
00315       sprintf (histo, "HcalRecHitTask_RecHit_Aux_StatusWord_HB" ) ;
00316       RecHit_Aux_StatusWord_HB = dbe_->book1D(histo, histo, 32 , -0.5, 31.5); 
00317       
00318       sprintf (histo, "HcalRecHitTask_RecHit_Aux_StatusWord_HE" ) ;
00319       RecHit_Aux_StatusWord_HE = dbe_->book1D(histo, histo, 32 , -0.5, 31.5); 
00320 
00321       sprintf (histo, "HcalRecHitTask_RecHit_Aux_StatusWord_HF" ) ;
00322       RecHit_Aux_StatusWord_HF = dbe_->book1D(histo, histo, 32 , -0.5, 31.5); 
00323 
00324       sprintf (histo, "HcalRecHitTask_RecHit_Aux_StatusWord_HO" ) ;
00325       RecHit_Aux_StatusWord_HO = dbe_->book1D(histo, histo, 32 , -0.5, 31.5); 
00326 
00327       //These are not drawn
00328       if(imc !=0 && useAllHistos_) { 
00329         sprintf  (histo, "map_econe_depth1" );
00330         map_econe_depth1 =
00331           dbe_->book2D(histo, histo, 520, -5.2, 5.2, 72, -3.1415926536, 3.1415926536);
00332         sprintf  (histo, "map_econe_depth2" );
00333         map_econe_depth2 =
00334           dbe_->book2D(histo, histo, 520, -5.2, 5.2, 72, -3.1415926536, 3.1415926536);
00335         sprintf  (histo, "map_econe_depth3" );
00336         map_econe_depth3 =
00337           dbe_->book2D(histo, histo, 520, -5.2, 5.2, 72, -3.1415926536, 3.1415926536);
00338         sprintf  (histo, "map_econe_depth4" );
00339         map_econe_depth4 =
00340           dbe_->book2D(histo, histo, 520, -5.2, 5.2, 72, -3.1415926536, 3.1415926536);
00341       }
00342     }  // end-of (subdet_ =! 6)
00343 
00344     //======================= Now various cases one by one ===================
00345 
00346     //Histograms drawn for single pion scan
00347     if(subdet_ != 0 && imc != 0) { // just not for noise  
00348       sprintf (histo, "HcalRecHitTask_En_rechits_cone_profile_vs_ieta_all_depths");
00349       meEnConeEtaProfile = dbe_->bookProfile(histo, histo, 82, -41., 41.,        2100, -100., 2000.);  
00350       
00351       sprintf (histo, "HcalRecHitTask_En_rechits_cone_profile_vs_ieta_all_depths_E");
00352       meEnConeEtaProfile_E = dbe_->bookProfile(histo, histo, 82, -41., 41.,      2100, -100., 2000.);  
00353       
00354       sprintf (histo, "HcalRecHitTask_En_rechits_cone_profile_vs_ieta_all_depths_EH");
00355       meEnConeEtaProfile_EH = dbe_->bookProfile(histo, histo, 82, -41., 41.,     2100, -100., 2000.);  
00356     }
00357     //The other cone profile, delta ieta/phi and noise histos are not drawn
00358     if (useAllHistos_){
00359       if(subdet_ != 0 && imc != 0) { // just not for noise  
00360         
00361         //    meEnConeEtaProfiel_depth1->Fill(eta_RecHit, HcalCone_d1);
00362         
00363         sprintf (histo, "HcalRecHitTask_En_rechits_cone_profile_vs_ieta_depth1");
00364         meEnConeEtaProfile_depth1 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000.);   
00365         
00366         sprintf (histo, "HcalRecHitTask_En_rechits_cone_profile_vs_ieta_depth2");
00367         meEnConeEtaProfile_depth2 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000.);  
00368         
00369         sprintf (histo, "HcalRecHitTask_En_rechits_cone_profile_vs_ieta_depth3");
00370         meEnConeEtaProfile_depth3 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000.);  
00371         
00372         sprintf (histo, "HcalRecHitTask_En_rechits_cone_profile_vs_ieta_depth4");
00373         meEnConeEtaProfile_depth4 = dbe_->bookProfile(histo, histo, 82, -41., 41., 2100, -100., 2000.);  
00374         
00375       }
00376       
00377       if(etype_ == 1 && subdet_ != 0) { // single part., not for noise
00378         
00379         sprintf  (histo, "Delta_phi_cluster-MC");
00380         meDeltaPhi =  dbe_->book2D(histo, histo, 520, -5.2, 5.2, 60, -0.6, 0.6);
00381         
00382         sprintf  (histo, "Delta_eta_cluster-MC");
00383         meDeltaEta =  dbe_->book2D(histo, histo, 520, -5.2, 5.2, 60, -0.6, 0.6);
00384       
00385         sprintf  (histo, "Delta_phi_simcluster-MC");
00386         meDeltaPhiS =  dbe_->book2D(histo, histo, 520, -5.2, 5.2, 60, -0.6, 0.6);
00387         
00388         sprintf  (histo, "Delta_eta_simcluster-MC");
00389         meDeltaEtaS =  dbe_->book2D(histo, histo, 520, -5.2, 5.2, 60, -0.6, 0.6);
00390       }
00391       // NOISE-specific
00392       
00393       if (hcalselector_ == "noise" ){
00394         
00395         sprintf  (histo, "e_hb" ) ;
00396         e_hb = dbe_->book1D(histo, histo,1000, -5., 5.);
00397         sprintf  (histo, "e_he" ) ;
00398         e_he = dbe_->book1D(histo, histo,1000, -5., 5.);
00399         sprintf  (histo, "e_ho" ) ;
00400         e_ho = dbe_->book1D(histo, histo,1000, -5., 5.);
00401         sprintf  (histo, "e_hfl" ) ;
00402         e_hfl = dbe_->book1D(histo, histo,2000, -10., 10.);
00403         sprintf  (histo, "e_hfs" ) ;
00404         e_hfs = dbe_->book1D(histo, histo,2000, -10., 10.);
00405       }
00406     }
00407     // ************** HB **********************************
00408     if (subdet_ == 1 || subdet_ == 5 ){
00409 
00410       //Only severity level, energy of rechits and overall HB timing histos are drawn  
00411       if (useAllHistos_){
00412         if(etype_ == 1 && subdet_ == 1 ) { 
00413           if(imc != 0) {
00414             sprintf (histo, "HcalRecHitTask_number_of_rechits_in_cone_HB" ) ;
00415             meNumRecHitsConeHB    = dbe_->book1D(histo, histo, 100, 0., 100.);
00416             
00417             sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_in_cone_HB" ) ;
00418             meSumRecHitsEnergyConeHB = dbe_->book1D(histo,histo, 60 ,-20., 280.);
00419           }
00420           
00421           sprintf (histo, "HcalRecHitTask_number_of_rechits_above_1GeV_HB");
00422           meNumRecHitsThreshHB = dbe_->book1D(histo, histo,  30, 0., 30.); 
00423           
00424           sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_HB" ) ;
00425           meSumRecHitsEnergyHB = dbe_->book1D(histo,histo, 60 , -20., 280.);
00426         
00427           if (ecalselector_ == "yes") {  
00428             if(imc != 0) {
00429               sprintf (histo, "HcalRecHitTask_number_of_ecalrechits_in_cone_HB");
00430               meNumEcalRecHitsConeHB = dbe_->book1D(histo, histo, 300, 0., 300.);           
00431               sprintf (histo, "HcalRecHitTask_energy_ecal_plus_hcal_in_cone_HB");
00432               meEcalHcalEnergyConeHB =  dbe_->book1D(histo,histo, 60 , -20., 280.);
00433             }
00434             
00435             sprintf (histo, "HcalRecHitTask_energy_hcal_vs_ecal_HB");
00436             meEnergyHcalVsEcalHB = dbe_->book2D(histo, histo, 300, 0., 150., 300, 0., 150.);    
00437             sprintf (histo, "HcalRecHitTask_energy_ecal_plus_hcal_HB" ) ;
00438             meEcalHcalEnergyHB = dbe_->book1D(histo,histo, 60 , -20., 280.);
00439           }
00440         }
00441       }
00442       
00443       sprintf(histo, "HcalRecHitTask_severityLevel_HB");
00444       sevLvl_HB = dbe_->book1D(histo, histo, 25, -0.5, 24.5); 
00445 
00446       sprintf (histo, "HcalRecHitTask_energy_of_rechits_HB" ) ;
00447       meRecHitsEnergyHB = dbe_->book1D(histo, histo, 2010 , -10. , 2000.); 
00448       
00449       sprintf (histo, "HcalRecHitTask_timing_HB" ) ;
00450       meTimeHB = dbe_->book1D(histo, histo, 70, -48., 92.); 
00451 
00452       //High, medium and low histograms to reduce RAM usage
00453       sprintf (histo, "HcalRecHitTask_timing_vs_energy_Low_HB" ) ;
00454       meTE_Low_HB = dbe_->book2D(histo, histo, 50, -5., 45.,  70, -48., 92.);
00455 
00456       sprintf (histo, "HcalRecHitTask_timing_vs_energy_HB" ) ;
00457       meTE_HB = dbe_->book2D(histo, histo, 150, -5., 295.,  70, -48., 92.);
00458 
00459       sprintf (histo, "HcalRecHitTask_timing_vs_energy_High_HB" ) ;
00460       meTE_High_HB = dbe_->book2D(histo, histo, 150, -5., 2995.,  70, -48., 92.);
00461       
00462       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_Low_HB" ) ;
00463       meTEprofileHB_Low = dbe_->bookProfile(histo, histo, 50, -5., 45., 70, -48., 92.); 
00464 
00465       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_HB" ) ;
00466       meTEprofileHB = dbe_->bookProfile(histo, histo, 150, -5., 295., 70, -48., 92.); 
00467 
00468       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_High_HB" ) ;
00469       meTEprofileHB_High = dbe_->bookProfile(histo, histo, 150, -5., 2995., 70, -48., 92.); 
00470 
00471       //Timing by depth and rechits vs simhits are not drawn
00472       if (useAllHistos_){
00473         sprintf (histo, "HcalRecHitTask_timing_vs_energy_HB_depth1" ) ;
00474         meTE_HB1 = dbe_->book2D(histo, histo, 3000, -5., 2995.,  70, -48., 92.);
00475         
00476         sprintf (histo, "HcalRecHitTask_timing_vs_energy_HB_depth2" ) ;
00477         meTE_HB2 = dbe_->book2D(histo, histo, 3000, -5., 2995.,  70, -48., 92.);
00478         
00479         if(imc != 0) {
00480           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_HB");
00481           meRecHitSimHitHB = dbe_->book2D(histo, histo, 120, 0., 1.2,  300, 0., 150.);
00482           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_profile_HB");
00483           meRecHitSimHitProfileHB = dbe_->bookProfile(histo, histo, 120, 0., 1.2, 500, 0., 500.);  
00484         }      
00485       }
00486     }
00487     
00488     // ********************** HE ************************************
00489     if ( subdet_ == 2 || subdet_ == 5 ){
00490 
00491       //None of these are drawn
00492       if (useAllHistos_){
00493         if(etype_ == 1 && subdet_ == 2 ) { 
00494           
00495           if(imc != 0) {
00496             sprintf (histo, "HcalRecHitTask_number_of_rechits_in_cone_HE" ) ;
00497             meNumRecHitsConeHE    = dbe_->book1D(histo, histo, 100, 0., 100.);
00498             
00499             sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_in_cone_HE" ) ;
00500             meSumRecHitsEnergyConeHE = dbe_->book1D(histo,histo, 60 ,-20., 280.);
00501           }     
00502           
00503           sprintf (histo, "HcalRecHitTask_number_of_rechits_above_1GeV_HE");
00504           meNumRecHitsThreshHE = dbe_->book1D(histo, histo,  30, 0., 30.);  
00505           
00506           sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_HE" ) ;
00507           meSumRecHitsEnergyHE = dbe_->book1D(histo,histo, 60 , -20., 280.);
00508           
00509           if (ecalselector_ == "yes") {         
00510             sprintf (histo, "HcalRecHitTask_energy_ecal_plus_hcal_HE" ) ;
00511             meEcalHcalEnergyHE = dbe_->book1D(histo,histo, 80, -20., 380.);
00512             
00513             sprintf (histo, "HcalRecHitTask_energy_hcal_vs_ecal_HE");
00514             meEnergyHcalVsEcalHE = dbe_->book2D(histo, histo, 300, 0., 150., 300, 0., 150.);
00515             if(imc != 0) {
00516               sprintf (histo, "HcalRecHitTask_number_of_ecalrechits_in_cone_HE");
00517               meNumEcalRecHitsConeHE = dbe_->book1D(histo, histo, 300, 0., 300.);   
00518               sprintf (histo, "HcalRecHitTask_energy_ecal_plus_hcal_in_cone_HE");
00519               meEcalHcalEnergyConeHE =  dbe_->book1D(histo,histo, 60,-20., 280.);
00520             }
00521           }           
00522         }
00523       }
00524       
00525       //Only severity level, energy of rechits and overall HB timing histos are drawn  
00526       sprintf(histo, "HcalRecHitTask_severityLevel_HE");
00527       sevLvl_HE = dbe_->book1D(histo, histo, 25, -0.5, 24.5); 
00528       
00529       sprintf (histo, "HcalRecHitTask_energy_of_rechits_HE" ) ;
00530       meRecHitsEnergyHE = dbe_->book1D(histo, histo, 510, -10., 500.); 
00531       
00532       sprintf (histo, "HcalRecHitTask_timing_HE" ) ;
00533       meTimeHE = dbe_->book1D(histo, histo, 70, -48., 92.); 
00534       
00535       sprintf (histo, "HcalRecHitTask_timing_vs_energy_Low_HE" ) ;
00536       meTE_Low_HE = dbe_->book2D(histo, histo, 80, -5., 75.,  70, -48., 92.);
00537 
00538       sprintf (histo, "HcalRecHitTask_timing_vs_energy_HE" ) ;
00539       meTE_HE = dbe_->book2D(histo, histo, 200, -5., 395.,  70, -48., 92.);
00540       
00541       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_Low_HE" ) ;
00542       meTEprofileHE_Low = dbe_->bookProfile(histo, histo, 80, -5., 75., 70, -48., 92.); 
00543 
00544       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_HE" ) ;
00545       meTEprofileHE = dbe_->bookProfile(histo, histo, 200, -5., 395., 70, -48., 92.); 
00546 
00547       //Timing by depth and rechits vs simhits are not drawn
00548       if (useAllHistos_){
00549         sprintf (histo, "HcalRecHitTask_timing_vs_energy_HE_depth1" ) ;
00550         meTE_HE1 = dbe_->book2D(histo, histo, 1000, -5., 995., 70, -48., 92.);
00551         
00552         sprintf (histo, "HcalRecHitTask_timing_vs_energy_HE_depth2" ) ;
00553         meTE_HE2 = dbe_->book2D(histo, histo, 1000, -5., 995.,  70, -48., 92.);
00554         
00555         if(imc != 0) {
00556           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_HE");
00557           meRecHitSimHitHE = dbe_->book2D(histo, histo, 120, 0., 0.6,  300, 0., 150.);
00558           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_profile_HE");
00559           meRecHitSimHitProfileHE = dbe_->bookProfile(histo, histo, 120, 0., 0.6, 500, 0., 500.);  
00560         }
00561       }
00562       
00563     }
00564 
00565     // ************** HO ****************************************
00566     if ( subdet_ == 3 || subdet_ == 5  ){
00567       
00568       //Only severity level, energy of rechits and overall HB timing histos are drawn  
00569       if (useAllHistos_){
00570         if(etype_ == 1 && subdet_ == 3) { 
00571           if (imc != 0) {
00572             sprintf (histo, "HcalRecHitTask_number_of_rechits_in_cone_HO" ) ;
00573             meNumRecHitsConeHO    = dbe_->book1D(histo, histo, 100, 0 , 100.);
00574             
00575             sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_in_cone_HO" ) ;
00576             meSumRecHitsEnergyConeHO = dbe_->book1D(histo,histo, 80 ,-20., 380.);
00577           }
00578           
00579           sprintf (histo, "HcalRecHitTask_number_of_rechits_above_1GeV_HO");
00580           meNumRecHitsThreshHO = dbe_->book1D(histo, histo,   100, 0., 100.);   
00581           
00582           sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_HO" ) ;
00583           meSumRecHitsEnergyHO = dbe_->book1D(histo,histo, 80 , -20., 380.);
00584         }
00585       }      
00586       
00587       sprintf(histo, "HcalRecHitTask_severityLevel_HO");
00588       sevLvl_HO = dbe_->book1D(histo, histo, 25, -0.5, 24.5); 
00589 
00590       sprintf (histo, "HcalRecHitTask_energy_of_rechits_HO" ) ;
00591       meRecHitsEnergyHO = dbe_->book1D(histo, histo, 510 , -10. , 500.); 
00592       
00593       sprintf (histo, "HcalRecHitTask_timing_HO" ) ;
00594       meTimeHO = dbe_->book1D(histo, histo, 70, -48., 92.); 
00595       
00596       sprintf (histo, "HcalRecHitTask_timing_vs_energy_HO" ) ;
00597       meTE_HO= dbe_->book2D(histo, histo, 60, -5., 55., 70, -48., 92.);
00598 
00599       sprintf (histo, "HcalRecHitTask_timing_vs_energy_High_HO" ) ;
00600       meTE_High_HO= dbe_->book2D(histo, histo, 100, -5., 995., 70, -48., 92.);
00601       
00602       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_HO" ) ;
00603       meTEprofileHO = dbe_->bookProfile(histo, histo, 60, -5., 55.,  70, -48., 92.); 
00604 
00605       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_High_HO" ) ;
00606       meTEprofileHO_High = dbe_->bookProfile(histo, histo, 100, -5., 995.,  70, -48., 92.); 
00607       
00608       //Rechits vs simhits are not drawn
00609       if (useAllHistos_){
00610         if(imc != 0) {
00611           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_HO");
00612           meRecHitSimHitHO = dbe_->book2D(histo, histo, 150, 0., 1.5,  350, 0., 350.);
00613           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_profile_HO");
00614           meRecHitSimHitProfileHO = dbe_->bookProfile(histo, histo, 150, 0., 1.5, 500, 0., 500.);  
00615         }
00616       }
00617     }   
00618   
00619     // ********************** HF ************************************
00620     if ( subdet_ == 4 || subdet_ == 5 ){
00621 
00622       //Only severity level, energy of rechits and overall HB timing histos are drawn  
00623       if (useAllHistos_){
00624         if(etype_ == 1 &&  subdet_ == 4) { 
00625           
00626           if(imc != 0) {
00627             sprintf (histo, "HcalRecHitTask_number_of_rechits_in_cone_HF" ) ;
00628             meNumRecHitsConeHF    = dbe_->book1D(histo, histo, 30, 0 , 30.);
00629             
00630             sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_in_cone_HF" ) ;
00631             meSumRecHitsEnergyConeHF = dbe_->book1D(histo,histo,100, -20., 180.);
00632             
00633             sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_in_cone_HFL" );
00634             meSumRecHitsEnergyConeHFL = dbe_->book1D(histo,histo,100,-20., 180.);
00635             
00636             sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_in_cone_HFS");
00637             meSumRecHitsEnergyConeHFS = dbe_->book1D(histo,histo,100,-20., 180.);
00638           }
00639           sprintf (histo, "HcalRecHitTask_sum_of_rechits_energy_HF" ) ;
00640           meSumRecHitsEnergyHF = dbe_->book1D(histo,histo, 80 , -20., 380.);  
00641         }
00642       }
00643       
00644       sprintf(histo, "HcalRecHitTask_severityLevel_HF");
00645       sevLvl_HF = dbe_->book1D(histo, histo, 25, -0.5, 24.5); 
00646 
00647       sprintf (histo, "HcalRecHitTask_energy_of_rechits_HF" ) ;
00648       meRecHitsEnergyHF = dbe_->book1D(histo, histo, 1010 , -10. , 1000.); 
00649 
00650       sprintf (histo, "HcalRecHitTask_timing_HF" ) ;
00651       meTimeHF = dbe_->book1D(histo, histo, 70, -48., 92.); 
00652       
00653       sprintf (histo, "HcalRecHitTask_timing_vs_energy_Low_HF" ) ;
00654       meTE_Low_HF = dbe_->book2D(histo, histo, 100, -5., 195., 70, -48., 92.);
00655 
00656       sprintf (histo, "HcalRecHitTask_timing_vs_energy_HF" ) ;
00657       meTE_HF = dbe_->book2D(histo, histo, 200, -5., 995., 70, -48., 92.);
00658       
00659       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_Low_HF" ) ;
00660       meTEprofileHF_Low = dbe_->bookProfile(histo, histo, 100, -5., 195., 70, -48., 92.); 
00661 
00662       sprintf (histo, "HcalRecHitTask_timing_vs_energy_profile_HF" ) ;
00663       meTEprofileHF = dbe_->bookProfile(histo, histo, 200, -5., 995., 70, -48., 92.); 
00664 
00665       //Timing by L/S and rechits vs simhits are not drawn
00666       if (useAllHistos_){
00667         sprintf (histo, "HcalRecHitTask_timing_vs_energy_HFL" ) ;
00668         meTE_HFL = dbe_->book2D(histo, histo, 1000, -5., 995., 70, -48., 92.);
00669         
00670         sprintf (histo, "HcalRecHitTask_timing_vs_energy_HFS" ) ;
00671         meTE_HFS = dbe_->book2D(histo, histo, 1000, -5., 995., 70, -48., 92.);
00672         
00673         if(imc != 0) {
00674           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_HF");
00675           meRecHitSimHitHF  = dbe_->book2D(histo, histo, 50, 0., 50., 150, 0., 150.);      
00676           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_HFL");
00677           meRecHitSimHitHFL = dbe_->book2D(histo, histo, 50, 0., 50., 150, 0., 150.);      
00678           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_HFS");
00679           meRecHitSimHitHFS = dbe_->book2D(histo, histo, 50, 0., 50., 150, 0., 150.);
00680           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_profile_HF");
00681           meRecHitSimHitProfileHF  = dbe_->bookProfile(histo, histo, 50, 0., 50., 500, 0., 500.);  
00682           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_profile_HFL");
00683           meRecHitSimHitProfileHFL = dbe_->bookProfile(histo, histo, 50, 0., 50., 500, 0., 500.);  
00684           sprintf (histo, "HcalRecHitTask_energy_rechits_vs_simhits_profile_HFS");
00685           meRecHitSimHitProfileHFS = dbe_->bookProfile(histo, histo, 50, 0., 50., 500, 0., 500.);  
00686         }
00687       }
00688     }
00689   }  //end-of if(_dbe) 
00690 
00691 }
00692 
00693 
00694 HcalRecHitsValidation::~HcalRecHitsValidation() { }
00695 
00696 void HcalRecHitsValidation::endJob() { }
00697 
00698 
00699 void HcalRecHitsValidation::beginJob(){ }
00700 
00701 void HcalRecHitsValidation::analyze(edm::Event const& ev, edm::EventSetup const& c) {
00702 
00703   using namespace edm;
00704 
00705   // cuts for each subdet_ector mimiking  "Scheme B"
00706   //  double cutHB = 0.9, cutHE = 1.4, cutHO = 1.1, cutHFL = 1.2, cutHFS = 1.8; 
00707 
00708   // energy in HCAL
00709   double eHcal        = 0.;
00710   double eHcalCone    = 0.;  
00711   double eHcalConeHB  = 0.;  
00712   double eHcalConeHE  = 0.;  
00713   double eHcalConeHO  = 0.;  
00714   double eHcalConeHF  = 0.;  
00715   double eHcalConeHFL = 0.;  
00716   double eHcalConeHFS = 0.;  
00717   // Total numbet of RecHits in HCAL, in the cone, above 1 GeV theshold
00718   int nrechits       = 0;
00719   int nrechitsCone   = 0;
00720   int nrechitsThresh = 0;
00721 
00722   // energy in ECAL
00723   double eEcal       = 0.;
00724   double eEcalB      = 0.;
00725   double eEcalE      = 0.;
00726   double eEcalCone   = 0.;
00727   int numrechitsEcal = 0;
00728 
00729   // MC info 
00730   double phi_MC = -999999.;  // phi of initial particle from HepMC
00731   double eta_MC = -999999.;  // eta of initial particle from HepMC
00732   bool MC = false;
00733 
00734   // HCAL energy around MC eta-phi at all depths;
00735   double partR = 0.3;
00736   double ehcal_coneMC_1 = 0.;
00737   double ehcal_coneMC_2 = 0.;
00738   double ehcal_coneMC_3 = 0.;
00739   double ehcal_coneMC_4 = 0.;
00740 
00741   // Cone size for serach of the hottest HCAL cell around MC
00742   double searchR = 1.0; 
00743   double eps     = 0.001;
00744 
00745   // Single particle samples: actual eta-phi position of cluster around
00746   // hottest cell
00747   double etaHot  = 99999.; 
00748   double phiHot  = 99999.; 
00749   int    ietahot = 1000;
00750   int    iphihot = 1000;
00751 
00752   // MC information
00753 
00754   //  std::cout << "*** 1" << std::endl; 
00755 
00756 
00757   if(imc != 0) { 
00758 
00759   edm::Handle<edm::HepMCProduct> evtMC;
00760   //  ev.getByLabel("VtxSmeared",evtMC);
00761   ev.getByLabel("generator",evtMC);  // generator in late 310_preX
00762   if (!evtMC.isValid()) {
00763     std::cout << "no HepMCProduct found" << std::endl;    
00764   } else {
00765     MC=true;
00766     //    std::cout << "*** source HepMCProduct found"<< std::endl;
00767   }  
00768 
00769   // MC particle with highest pt is taken as a direction reference  
00770   double maxPt = -99999.;
00771   int npart    = 0;
00772   const HepMC::GenEvent * myGenEvent = evtMC->GetEvent();
00773   for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
00774         p != myGenEvent->particles_end(); ++p ) {
00775     double phip = (*p)->momentum().phi();
00776     double etap = (*p)->momentum().eta();
00777     //    phi_MC = phip;
00778     //    eta_MC = etap;
00779     double pt  = (*p)->momentum().perp();
00780     if(pt > maxPt) { npart++; maxPt = pt; phi_MC = phip; eta_MC = etap; }
00781   }
00782   //  std::cout << "*** Max pT = " << maxPt <<  std::endl;  
00783 
00784   }
00785 
00786   //   std::cout << "*** 2" << std::endl; 
00787   //   previously was:  c.get<IdealGeometryRecord>().get (geometry);
00788   c.get<CaloGeometryRecord>().get (geometry);
00789 
00790   // HCAL channel status map ****************************************
00791   edm::ESHandle<HcalChannelQuality> hcalChStatus;
00792   c.get<HcalChannelQualityRcd>().get( hcalChStatus );
00793   theHcalChStatus = hcalChStatus.product();
00794   // Assignment of severity levels **********************************
00795   edm::ESHandle<HcalSeverityLevelComputer> hcalSevLvlComputerHndl;
00796   c.get<HcalSeverityLevelComputerRcd>().get(hcalSevLvlComputerHndl);
00797   theHcalSevLvlComputer = hcalSevLvlComputerHndl.product(); 
00798 
00799   // Fill working vectors of HCAL RecHits quantities (all of these are drawn)
00800   fillRecHitsTmp(subdet_, ev); 
00801 
00802   // HB   
00803   if( subdet_ ==5 || subdet_ == 1 ){ 
00804      for(unsigned int iv=0; iv<hcalHBSevLvlVec.size(); iv++){
00805         sevLvl_HB->Fill(hcalHBSevLvlVec[iv]);
00806      }    
00807   }
00808   // HE   
00809   if( subdet_ ==5 || subdet_ == 2 ){
00810      for(unsigned int iv=0; iv<hcalHESevLvlVec.size(); iv++){
00811         sevLvl_HE->Fill(hcalHESevLvlVec[iv]);
00812      }
00813   }
00814   // HO 
00815   if( subdet_ ==5 || subdet_ == 3 ){
00816      for(unsigned int iv=0; iv<hcalHOSevLvlVec.size(); iv++){
00817         sevLvl_HO->Fill(hcalHOSevLvlVec[iv]);
00818      }
00819   }
00820   // HF 
00821   if( subdet_ ==5 || subdet_ == 4 ){
00822      for(unsigned int iv=0; iv<hcalHFSevLvlVec.size(); iv++){
00823         sevLvl_HF->Fill(hcalHFSevLvlVec[iv]);
00824      }
00825   } 
00826 
00827   //  std::cout << "*** 3" << std::endl; 
00828 
00829 
00830   //===========================================================================
00831   // IN ALL other CASES : ieta-iphi maps 
00832   //===========================================================================
00833 
00834   // ECAL 
00835   if(ecalselector_ == "yes" && (subdet_ == 1 || subdet_ == 2 || subdet_ == 5)) {
00836     Handle<EBRecHitCollection> rhitEB;
00837 
00838 
00839       ev.getByLabel("ecalRecHit","EcalRecHitsEB", rhitEB);
00840 
00841     EcalRecHitCollection::const_iterator RecHit = rhitEB.product()->begin();  
00842     EcalRecHitCollection::const_iterator RecHitEnd = rhitEB.product()->end();  
00843     
00844     for (; RecHit != RecHitEnd ; ++RecHit) {
00845       EBDetId EBid = EBDetId(RecHit->id());
00846        
00847       const CaloCellGeometry* cellGeometry =
00848         geometry->getSubdetectorGeometry (EBid)->getGeometry (EBid) ;
00849       double eta = cellGeometry->getPosition ().eta () ;
00850       double phi = cellGeometry->getPosition ().phi () ;
00851       double en  = RecHit->energy();
00852       eEcal  += en;
00853       eEcalB += en;
00854 
00855       if (useAllHistos_) map_ecal->Fill(eta, phi, en);
00856 
00857       double r   = dR(eta_MC, phi_MC, eta, phi);
00858       if( r < partR)  {
00859         eEcalCone += en;
00860         numrechitsEcal++; 
00861       }
00862     }
00863 
00864     
00865     Handle<EERecHitCollection> rhitEE;
00866  
00867       ev.getByLabel("ecalRecHit","EcalRecHitsEE", rhitEE);
00868 
00869     RecHit = rhitEE.product()->begin();  
00870     RecHitEnd = rhitEE.product()->end();  
00871     
00872     for (; RecHit != RecHitEnd ; ++RecHit) {
00873       EEDetId EEid = EEDetId(RecHit->id());
00874       
00875       const CaloCellGeometry* cellGeometry =
00876         geometry->getSubdetectorGeometry (EEid)->getGeometry (EEid) ;
00877       double eta = cellGeometry->getPosition ().eta () ;
00878       double phi = cellGeometry->getPosition ().phi () ;        
00879       double en   = RecHit->energy();
00880       eEcal  += en;
00881       eEcalE += en;
00882 
00883       if (useAllHistos_) map_ecal->Fill(eta, phi, en);
00884 
00885       double r   = dR(eta_MC, phi_MC, eta, phi);
00886       if( r < partR)  {
00887         eEcalCone += en;
00888         numrechitsEcal++; 
00889       }
00890     }
00891   }     // end of ECAL selection 
00892 
00893 
00894   //     std::cout << "*** 4" << std::endl; 
00895 
00896 
00897   // Counting, including ZS items
00898   // Filling HCAL maps  ----------------------------------------------------
00899   double maxE = -99999.;
00900   
00901   int nhb1 = 0;
00902   int nhb2 = 0;
00903   int nhe1 = 0;
00904   int nhe2 = 0;
00905   int nhe3 = 0;
00906   int nho  = 0;
00907   int nhf1 = 0;
00908   int nhf2 = 0;  
00909   
00910   for (unsigned int i = 0; i < cen.size(); i++) {
00911     
00912     int sub       = csub[i];
00913     int depth     = cdepth[i];
00914     int ieta      = cieta[i]; 
00915     int iphi      = ciphi[i]; 
00916     double en     = cen[i]; 
00917     double eta    = ceta[i]; 
00918     double phi    = cphi[i]; 
00919     uint32_t stwd = cstwd[i];
00920     uint32_t auxstwd = cauxstwd[i];
00921     //    double z   = cz[i];
00922 
00923     int index = ieta * 72 + iphi; //  for sequential histos
00924     
00925     /*   
00926          std::cout << "*** point 4-1" << " ieta, iphi, depth, sub = "
00927          << ieta << ", " << iphi << ", " << depth << ", " << sub  
00928          << std::endl;
00929     */
00930     
00931     
00932     if( sub == 1 && depth == 1)  nhb1++;
00933     if( sub == 1 && depth == 2)  nhb2++;
00934     if( sub == 2 && depth == 1)  nhe1++;
00935     if( sub == 2 && depth == 2)  nhe2++;
00936     if( sub == 2 && depth == 3)  nhe3++;
00937     if( sub == 3 && depth == 4)  nho++;
00938     if( sub == 4 && depth == 1)  nhf1++;
00939     if( sub == 4 && depth == 2)  nhf2++;
00940     
00941     if( subdet_ == 6) {                                    // ZS specific
00942       if( en < emap_min[ieta+41][iphi][depth-1][sub-1] )
00943         emap_min[ieta+41][iphi][depth-1][sub-1] = en;
00944     }
00945     
00946     double emin = 1.;
00947     if(fabs(eta) > 3.) emin = 5.; 
00948     
00949     double r  = dR(eta_MC, phi_MC, eta, phi);
00950     if( r < searchR ) { // search for hottest cell in a big cone
00951       if(maxE < en && en > emin) {
00952         maxE    = en;
00953         etaHot  = eta;
00954         phiHot  = phi;
00955         ietahot = ieta;
00956         iphihot = iphi;
00957       }
00958     }
00959 
00960     /*   
00961     if(ieta == 27 ) { 
00962       std::cout << "*** ieta=28, iphi = " << iphi << "  det = " 
00963                 << sub << "  depth = " << depth << std::endl;
00964     }
00965     */
00966 
00967     if( subdet_ != 6) {  
00968 
00969       //      std::cout << "*** 4-1" << std::endl; 
00970       //The emean_vs_ieta histos are drawn as well as the e_maps
00971 
00972 
00973       if( depth == 1) emap_depth1->Fill(double(ieta), double(iphi), en);
00974       if( depth == 2) emap_depth2->Fill(double(ieta), double(iphi), en);
00975       if( depth == 3) emap_depth3->Fill(double(ieta), double(iphi), en);
00976       if( depth == 4) emap_depth4->Fill(double(ieta), double(iphi), en);
00977       
00978       if (depth == 1 && sub == 1 ) {
00979         emean_vs_ieta_HB1->Fill(double(ieta), en);
00980         occupancy_map_HB1->Fill(double(ieta), double(iphi));          
00981         if(useAllHistos_){
00982           emean_seqHB1->Fill(double(index), en);
00983         }
00984       }
00985       if (depth == 2  && sub == 1) {
00986         emean_vs_ieta_HB2->Fill(double(ieta), en);
00987         occupancy_map_HB2->Fill(double(ieta), double(iphi));          
00988         if(useAllHistos_){
00989           emean_seqHB2->Fill(double(index), en);
00990         }
00991       }
00992       if (depth == 1 && sub == 2) {
00993         emean_vs_ieta_HE1->Fill(double(ieta), en);
00994         occupancy_map_HE1->Fill(double(ieta), double(iphi));   
00995         if(useAllHistos_){
00996           emean_seqHE1->Fill(double(index), en);
00997         }
00998       }
00999       if (depth == 2 && sub == 2) {
01000         emean_vs_ieta_HE2->Fill(double(ieta), en);
01001         occupancy_map_HE2->Fill(double(ieta), double(iphi));          
01002         if(useAllHistos_){
01003           emean_seqHE2->Fill(double(index), en);
01004         }
01005       }
01006       if (depth == 3 && sub == 2) {
01007         emean_vs_ieta_HE3->Fill(double(ieta), en);
01008         occupancy_map_HE3->Fill(double(ieta), double(iphi));          
01009         if(useAllHistos_){
01010           emean_seqHE3->Fill(double(index), en);
01011         }
01012       }
01013       if (depth == 4 ) {
01014         emean_vs_ieta_HO->Fill(double(ieta), en);
01015         occupancy_map_HO->Fill(double(ieta), double(iphi));          
01016         if(useAllHistos_){
01017           emean_seqHO->Fill(double(index), en);
01018         }
01019       }
01020       if (depth == 1 && sub == 4) {
01021         emean_vs_ieta_HF1->Fill(double(ieta), en);
01022         occupancy_map_HF1->Fill(double(ieta), double(iphi));          
01023         if(useAllHistos_){
01024           emean_seqHF1->Fill(double(index), en);
01025         }
01026       }
01027       if (depth == 2 && sub == 4) {
01028         emean_vs_ieta_HF2->Fill(double(ieta), en);
01029         occupancy_map_HF2->Fill(double(ieta), double(iphi));          
01030         if(useAllHistos_){
01031           emean_seqHF2->Fill(double(index), en);
01032         }
01033       }
01034     }
01035     
01036 
01037     if( r < partR ) {
01038       if (depth == 1) ehcal_coneMC_1 += en; 
01039       if (depth == 2) ehcal_coneMC_2 += en; 
01040       if (depth == 3) ehcal_coneMC_3 += en; 
01041       if (depth == 4) ehcal_coneMC_4 += en; 
01042     }
01043     
01044     //32-bit status word  
01045     uint32_t statadd;
01046     unsigned int isw67 = 0;
01047     for (unsigned int isw = 0; isw < 32; isw++){
01048       statadd = 0x1<<(isw);
01049       if (stwd & statadd){
01050         if      (sub == 1) RecHit_StatusWord_HB->Fill(isw);
01051         else if (sub == 2) RecHit_StatusWord_HE->Fill(isw);
01052         else if (sub == 3) RecHit_StatusWord_HO->Fill(isw);
01053         else if (sub == 4){
01054           RecHit_StatusWord_HF->Fill(isw);
01055           if (isw == 6) isw67 += 1;
01056           if (isw == 7) isw67 += 2;
01057         }
01058       }
01059     }
01060     if (isw67 != 0 && useAllHistos_) RecHit_StatusWord_HF67->Fill(isw67); //This one is not drawn
01061 
01062     for (unsigned int isw =0; isw < 32; isw++){
01063       statadd = 0x1<<(isw);
01064       if( auxstwd & statadd ){
01065         if      (sub == 1) RecHit_Aux_StatusWord_HB->Fill(isw);
01066         else if (sub == 2) RecHit_Aux_StatusWord_HE->Fill(isw);
01067         else if (sub == 3) RecHit_Aux_StatusWord_HO->Fill(isw);
01068         else if (sub == 4) RecHit_Aux_StatusWord_HF->Fill(isw);
01069       }
01070 
01071     }
01072 
01073   } 
01074  
01075   //  std::cout << "*** 4-2" << std::endl; 
01076   
01077   if( subdet_ == 6 && useAllHistos_) {               // ZS plots; not drawn
01078     ZS_nHB1->Fill(double(nhb1));  
01079     ZS_nHB2->Fill(double(nhb2));  
01080     ZS_nHE1->Fill(double(nhe1));  
01081     ZS_nHE2->Fill(double(nhe2));  
01082     ZS_nHE3->Fill(double(nhe3));  
01083     ZS_nHO ->Fill(double(nho));  
01084     ZS_nHF1->Fill(double(nhf1));  
01085     ZS_nHF2->Fill(double(nhf2));  
01086   }
01087   else{ 
01088     Nhb->Fill(double(nhb1 + nhb2));
01089     Nhe->Fill(double(nhe1 + nhe2 + nhe3));
01090     Nho->Fill(double(nho));
01091     Nhf->Fill(double(nhf1 + nhf2));
01092 
01093     //These are not drawn
01094     if(imc != 0 && useAllHistos_) {
01095       map_econe_depth1->Fill(eta_MC, phi_MC, ehcal_coneMC_1);
01096       map_econe_depth2->Fill(eta_MC, phi_MC, ehcal_coneMC_2);
01097       map_econe_depth3->Fill(eta_MC, phi_MC, ehcal_coneMC_3);
01098       map_econe_depth4->Fill(eta_MC, phi_MC, ehcal_coneMC_4);
01099     }
01100   }
01101 
01102   //  std::cout << "*** 5" << std::endl; 
01103     
01104 
01105   //  NOISE ================================================================= 
01106   //Not drawn
01107   if (hcalselector_ == "noise" && useAllHistos_) {
01108     for (unsigned int i = 0; i < cen.size(); i++) {
01109       
01110       int sub   = csub[i];
01111       int depth = cdepth[i];
01112       double en = cen[i]; 
01113       
01114       if (sub == 1) e_hb->Fill(en);
01115       if (sub == 2) e_he->Fill(en);  
01116       if (sub == 3) e_ho->Fill(en);  
01117       if (sub == 4) {
01118         if(depth == 1)  
01119           e_hfl->Fill(en);  
01120         else 
01121           e_hfs->Fill(en);  
01122       }
01123     }
01124   }
01125 
01126   //===========================================================================
01127   // SUBSYSTEMS,  
01128   //===========================================================================
01129   
01130   else if ((subdet_ != 6) && (subdet_ != 0)) {
01131 
01132     //       std::cout << "*** 6" << std::endl; 
01133     
01134     
01135     double clusEta = 999.;
01136     double clusPhi = 999.; 
01137     double clusEn  = 0.;
01138     
01139     double HcalCone_d1 = 0.;
01140     double HcalCone_d2 = 0.;
01141     double HcalCone_d3 = 0.;
01142     double HcalCone_d4 = 0.;
01143     double HcalCone    = 0.;
01144 
01145     int ietaMax1  =  9999;
01146     int ietaMax2  =  9999;
01147     int ietaMax3  =  9999;
01148     int ietaMax4  =  9999;
01149     int ietaMax   =  9999;
01150     double enMax1 = -9999.;
01151     double enMax2 = -9999.;
01152     double enMax3 = -9999.;
01153     double enMax4 = -9999.;
01154     //    double enMax  = -9999.;
01155     double etaMax =  9999.;
01156 
01157     /*
01158     std::cout << "*** point 5-1" << "  eta_MC, phi_MC    etaHot,  phiHot = "
01159               << eta_MC  << ", " << phi_MC << "   "
01160               << etaHot  << ", " << phiHot  
01161               << std::endl;
01162     */
01163 
01164     //   CYCLE over cells ====================================================
01165 
01166     for (unsigned int i = 0; i < cen.size(); i++) {
01167       int sub    = csub[i];
01168       int depth  = cdepth[i];
01169       double eta = ceta[i]; 
01170       double phi = cphi[i]; 
01171       double en  = cen[i]; 
01172       double t   = ctime[i];
01173       int   ieta = cieta[i];
01174 
01175       double rhot = dR(etaHot, phiHot, eta, phi); 
01176       if(rhot < partR && en > 1.) { 
01177         clusEta = (clusEta * clusEn + eta * en)/(clusEn + en);
01178         clusPhi = phi12(clusPhi, clusEn, phi, en); 
01179         clusEn += en;
01180       }
01181 
01182       nrechits++;           
01183       eHcal += en;
01184       if(en > 1. ) nrechitsThresh++;
01185 
01186       double r    = dR(eta_MC, phi_MC, eta, phi);
01187       if( r < partR ){
01188         if(sub == 1)   eHcalConeHB += en;
01189         if(sub == 2)   eHcalConeHE += en;
01190         if(sub == 3)   eHcalConeHO += en;
01191         if(sub == 4) {
01192           eHcalConeHF += en;
01193           if (depth == 1) eHcalConeHFL += en;
01194           else            eHcalConeHFS += en;
01195         }
01196         eHcalCone += en;
01197         nrechitsCone++;
01198 
01199         // search for most energetic cell at the given depth in the cone
01200         if(depth == 1) {
01201           HcalCone_d1 += en;
01202           if(enMax1 < en) {
01203             enMax1   = en;
01204             ietaMax1 = ieta;
01205           }
01206         }
01207         if(depth == 2) {
01208           HcalCone_d2 += en;
01209           if(enMax2 < en) {
01210             enMax2   = en;
01211             ietaMax2 = ieta;
01212           }
01213         }
01214         if(depth == 3) {
01215           HcalCone_d3 += en;
01216           if(enMax3 < en) {
01217             enMax3   = en;
01218             ietaMax3 = ieta;
01219           }
01220         }
01221         if(depth == 4) {
01222           HcalCone_d4 += en;
01223           if(enMax4 < en) {
01224             enMax4   = en;
01225             ietaMax4 = ieta;
01226           }
01227         }
01228 
01229         if(depth != 4) {
01230           HcalCone += en;
01231         }
01232 
01233 
01234         // regardless of the depths (but excluding HO), just hottest cell
01235         /*
01236         if(depth != 4) {
01237           if(enMax   < en) {
01238             enMax   = en;
01239             ietaMax = ieta;
01240           }
01241         }   
01242         */
01243 
01244         // alternative: ietamax -> closest to MC eta  !!!
01245         float eta_diff = fabs(eta_MC - eta);
01246         if(eta_diff < etaMax) {
01247           etaMax  = eta_diff; 
01248           ietaMax = ieta; 
01249         }
01250       }
01251       
01252       //The energy and overall timing histos are drawn while
01253       //the ones split by depth are not
01254       if(sub == 1 && (subdet_ == 1 || subdet_ == 5)) {  
01255         meTimeHB->Fill(t);
01256         meRecHitsEnergyHB->Fill(en);
01257         
01258         meTE_Low_HB->Fill( en, t);
01259         meTE_HB->Fill( en, t);
01260         meTE_High_HB->Fill( en, t);
01261         meTEprofileHB_Low->Fill(en, t);
01262         meTEprofileHB->Fill(en, t);
01263         meTEprofileHB_High->Fill(en, t);
01264 
01265         if (useAllHistos_){
01266           if      (depth == 1) meTE_HB1->Fill( en, t);
01267           else if (depth == 2) meTE_HB2->Fill( en, t);
01268         }
01269       }     
01270       if(sub == 2 && (subdet_ == 2 || subdet_ == 5)) {  
01271         meTimeHE->Fill(t);
01272         meRecHitsEnergyHE->Fill(en);
01273 
01274         meTE_Low_HE->Fill( en, t);
01275         meTE_HE->Fill( en, t);
01276         meTEprofileHE_Low->Fill(en, t);
01277         meTEprofileHE->Fill(en, t);
01278 
01279         if (useAllHistos_){
01280           if      (depth == 1) meTE_HE1->Fill( en, t);
01281           else if (depth == 2) meTE_HE2->Fill( en, t);
01282         }
01283       }
01284       if(sub == 4 && (subdet_ == 4 || subdet_ == 5)) {  
01285         meTimeHF->Fill(t);
01286         meRecHitsEnergyHF->Fill(en);      
01287 
01288         meTE_Low_HF->Fill(en, t);
01289         meTE_HF->Fill(en, t);
01290         meTEprofileHF_Low->Fill(en, t);
01291         meTEprofileHF->Fill(en, t);
01292 
01293         if (useAllHistos_){
01294           if   (depth == 1) meTE_HFL->Fill( en, t);
01295           else              meTE_HFS->Fill( en, t);
01296         }
01297       }
01298       if(sub == 3 && (subdet_ == 3 || subdet_ == 5)) {  
01299         meTimeHO->Fill(t);
01300         meRecHitsEnergyHO->Fill(en);
01301 
01302         meTE_HO->Fill( en, t);
01303         meTE_High_HO->Fill( en, t);
01304         meTEprofileHO->Fill(en, t);
01305         meTEprofileHO_High->Fill(en, t);
01306       }
01307     }
01308 
01309     if(imc != 0) {
01310       //Cone by depth are not drawn, the others are used for pion scan
01311       if (useAllHistos_){
01312         meEnConeEtaProfile_depth1->Fill(double(ietaMax1), HcalCone_d1);
01313         meEnConeEtaProfile_depth2->Fill(double(ietaMax2), HcalCone_d2);
01314         meEnConeEtaProfile_depth3->Fill(double(ietaMax3), HcalCone_d3);
01315         meEnConeEtaProfile_depth4->Fill(double(ietaMax4), HcalCone_d4);
01316       }
01317       meEnConeEtaProfile       ->Fill(double(ietaMax),  HcalCone);   // 
01318       meEnConeEtaProfile_E     ->Fill(double(ietaMax), eEcalCone);   
01319       meEnConeEtaProfile_EH    ->Fill(double(ietaMax),  HcalCone+eEcalCone); 
01320     }
01321 
01322     //     std::cout << "*** 7" << std::endl; 
01323 
01324     
01325     // Single particle samples ONLY !  ======================================
01326     // Fill up some histos for "integrated" subsustems. 
01327     // These are not drawn
01328     if(etype_ == 1 && useAllHistos_) {
01329 
01330       /*
01331       std::cout << "*** point 7-1" << "  eta_MC, phi_MC   clusEta, clusPhi = "
01332                 << eta_MC  << ", " << phi_MC << "   "
01333                 << clusEta << ", " << clusPhi 
01334                 << std::endl;
01335       */    
01336 
01337       double phidev = dPhiWsign(clusPhi, phi_MC);
01338       meDeltaPhi->Fill(eta_MC, phidev);
01339       double etadev = clusEta - eta_MC;
01340       meDeltaEta->Fill(eta_MC, etadev);
01341 
01342       if(subdet_ == 1) {
01343         meSumRecHitsEnergyHB->Fill(eHcal);
01344         if(imc != 0) meSumRecHitsEnergyConeHB->Fill(eHcalConeHB);    
01345         if(imc != 0) meNumRecHitsConeHB->Fill(double(nrechitsCone));
01346         meNumRecHitsThreshHB->Fill(double(nrechitsThresh));
01347       }
01348 
01349       if(subdet_ == 2) {
01350         meSumRecHitsEnergyHE->Fill(eHcal);
01351         if(imc != 0) meSumRecHitsEnergyConeHE->Fill(eHcalConeHE);    
01352         if(imc != 0) meNumRecHitsConeHE->Fill(double(nrechitsCone));
01353         meNumRecHitsThreshHE->Fill(double(nrechitsThresh));
01354       }
01355 
01356       if(subdet_ == 3) {
01357         meSumRecHitsEnergyHO->Fill(eHcal);
01358         if(imc != 0) meSumRecHitsEnergyConeHO->Fill(eHcalConeHO);    
01359         if(imc != 0) meNumRecHitsConeHO->Fill(double(nrechitsCone));
01360         meNumRecHitsThreshHO->Fill(double(nrechitsThresh));
01361       }
01362 
01363       if(subdet_ == 4) {
01364         if(eHcalConeHF > eps ) {
01365           meSumRecHitsEnergyHF ->Fill(eHcal);
01366           if(imc != 0) { 
01367             meSumRecHitsEnergyConeHF ->Fill(eHcalConeHF);    
01368             meNumRecHitsConeHF->Fill(double(nrechitsCone));
01369             meSumRecHitsEnergyConeHFL ->Fill(eHcalConeHFL);    
01370             meSumRecHitsEnergyConeHFS ->Fill(eHcalConeHFS);    
01371           }
01372         }
01373       }
01374 
01375       //         std::cout << "*** 8" << std::endl; 
01376 
01377 
01378       // Also combine with ECAL if needed 
01379       if(subdet_ == 1  && ecalselector_ == "yes") {
01380         
01381         /*
01382           std::cout << "*** point 8-1" 
01383           << "  eEcalB " << eEcalB << "  eHcal " << eHcal
01384           << "  eEcalCone " <<  eEcalCone << "  eHcalCone " 
01385                   << eHcalCone
01386                   << "  numrechitsEcal " <<  numrechitsEcal
01387                   << std::endl;
01388                   
01389         */
01390         
01391         meEcalHcalEnergyHB->Fill(eEcalB+eHcal);
01392         meEcalHcalEnergyConeHB->Fill(eEcalCone+eHcalCone);
01393         meNumEcalRecHitsConeHB->Fill(double(numrechitsEcal));
01394         
01395       }
01396       
01397       if(subdet_ == 2  && ecalselector_ == "yes"){
01398         
01399         /*
01400           std::cout << "*** point 8-2a" 
01401           << "  eEcalE " << eEcalE << "  eHcal " << eHcal
01402           << "  eEcalCone " <<  eEcalCone << "  eHcalCone " 
01403           << eHcalCone
01404           << "  numrechitsEcal " <<  numrechitsEcal
01405           << std::endl;
01406         */
01407         
01408         meEcalHcalEnergyHE->Fill(eEcalE+eHcal);
01409         if(imc != 0) meEcalHcalEnergyConeHE->Fill(eEcalCone+eHcalCone);
01410         if(imc != 0) meNumEcalRecHitsConeHE->Fill(double(numrechitsEcal));
01411       } 
01412 
01413       // Banana plots finally
01414       if(imc != 0) {
01415         if(subdet_ == 1 && ecalselector_ == "yes")
01416           meEnergyHcalVsEcalHB -> Fill(eEcalCone,eHcalCone);
01417         if(subdet_ == 2 && ecalselector_ == "yes") 
01418           meEnergyHcalVsEcalHE -> Fill(eEcalCone,eHcalCone);
01419       }
01420     }
01421   }
01422   //  std::cout << "*** 9" << std::endl; 
01423 
01424 
01425   //===========================================================================
01426   // Getting SimHits
01427   //===========================================================================
01428 
01429   if(subdet_ > 0 && subdet_ < 6 && imc !=0 && !famos_  ) {  // not noise 
01430 
01431     double maxES = -9999.;
01432     double etaHotS = 1000.;
01433     double phiHotS = 1000.;
01434     
01435     edm::Handle<PCaloHitContainer> hcalHits;
01436     ev.getByLabel("g4SimHits","HcalHits",hcalHits);
01437     const PCaloHitContainer * SimHitResult = hcalHits.product () ;
01438     
01439     double enSimHits    = 0.;
01440     double enSimHitsHB  = 0.;
01441     double enSimHitsHE  = 0.;
01442     double enSimHitsHO  = 0.;
01443     double enSimHitsHF  = 0.;
01444     double enSimHitsHFL = 0.;
01445     double enSimHitsHFS = 0.;
01446     // sum of SimHits in the cone 
01447     
01448     for (std::vector<PCaloHit>::const_iterator SimHits = SimHitResult->begin () ; SimHits != SimHitResult->end(); ++SimHits) {
01449       HcalDetId cell(SimHits->id());
01450       int sub =  cell.subdet();
01451       const CaloCellGeometry* cellGeometry =
01452         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01453       double etaS = cellGeometry->getPosition().eta () ;
01454       double phiS = cellGeometry->getPosition().phi () ;
01455       double en   = SimHits->energy();    
01456 
01457       double emin = 0.01;
01458       if(fabs(etaS) > 3.) emin = 1.;   
01459 
01460       double r  = dR(eta_MC, phi_MC, etaS, phiS);
01461       if( r < searchR ) { // search for hottest cell in a big cone
01462         if(maxES < en && en > emin ) {
01463           maxES    = en;
01464           etaHotS  = etaS;
01465           phiHotS  = phiS;
01466         }
01467       }
01468        
01469       if ( r < partR ){ // just energy in the small cone
01470         enSimHits += en;
01471         if(sub == 1) enSimHitsHB += en; 
01472         if(sub == 2) enSimHitsHE += en; 
01473         if(sub == 3) enSimHitsHO += en; 
01474         if(sub == 4) {
01475           enSimHitsHF += en;
01476           int depth = cell.depth();
01477           if(depth == 1) enSimHitsHFL += en;
01478           else           enSimHitsHFS += en;
01479         } 
01480       }
01481     }
01482 
01483 
01484     // Second look over SimHits: cluster finding
01485 
01486     double clusEta = 999.;
01487     double clusPhi = 999.; 
01488     double clusEn  = 0.;
01489 
01490     for (std::vector<PCaloHit>::const_iterator SimHits = SimHitResult->begin () ; SimHits != SimHitResult->end(); ++SimHits) {
01491      HcalDetId cell(SimHits->id());
01492 
01493       const CaloCellGeometry* cellGeometry =
01494         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01495       double etaS = cellGeometry->getPosition().eta () ;
01496       double phiS = cellGeometry->getPosition().phi () ;
01497       double en   =  SimHits->energy();    
01498 
01499       double emin = 0.01;
01500       if(fabs(etaS) > 3.) emin = 1.; 
01501 
01502       double rhot = dR(etaHotS, phiHotS, etaS, phiS); 
01503       if(rhot < partR && en > emin) { 
01504         clusEta = (clusEta * clusEn + etaS * en)/(clusEn + en);
01505         clusPhi = phi12(clusPhi, clusEn, phiS, en); 
01506         clusEn += en;
01507       }
01508     }
01509 
01510     // SimHits cluster deviation from MC (eta, phi)
01511     // These are not drawn
01512     if (useAllHistos_){
01513       if(etype_ == 1) {
01514         double phidev = dPhiWsign(clusPhi, phi_MC);
01515         meDeltaPhiS->Fill(eta_MC, phidev);
01516         double etadev = clusEta - eta_MC;
01517         meDeltaEtaS->Fill(eta_MC, etadev);
01518       }
01519       // Now some histos with SimHits
01520     
01521       if(subdet_ == 4 || subdet_ == 5) {
01522         if(eHcalConeHF > eps) {
01523           meRecHitSimHitHF->Fill( enSimHitsHF, eHcalConeHF );
01524           meRecHitSimHitProfileHF->Fill( enSimHitsHF, eHcalConeHF);
01525           
01526           meRecHitSimHitHFL->Fill( enSimHitsHFL, eHcalConeHFL );
01527           meRecHitSimHitProfileHFL->Fill( enSimHitsHFL, eHcalConeHFL);
01528           meRecHitSimHitHFS->Fill( enSimHitsHFS, eHcalConeHFS );
01529           meRecHitSimHitProfileHFS->Fill( enSimHitsHFS, eHcalConeHFS);       
01530         }
01531       }
01532       if(subdet_ == 1  || subdet_ == 5) { 
01533         meRecHitSimHitHB->Fill( enSimHitsHB,eHcalConeHB );
01534         meRecHitSimHitProfileHB->Fill( enSimHitsHB,eHcalConeHB);
01535       }
01536       if(subdet_ == 2  || subdet_ == 5) { 
01537         meRecHitSimHitHE->Fill( enSimHitsHE,eHcalConeHE );
01538         meRecHitSimHitProfileHE->Fill( enSimHitsHE,eHcalConeHE);
01539       }
01540       if(subdet_ == 3  || subdet_ == 5) { 
01541         meRecHitSimHitHO->Fill( enSimHitsHO,eHcalConeHO );
01542         meRecHitSimHitProfileHO->Fill( enSimHitsHO,eHcalConeHO);
01543       }
01544     }
01545   }
01546 
01547   nevtot++;
01548 }
01549 
01550 
01552 void HcalRecHitsValidation::fillRecHitsTmp(int subdet_, edm::Event const& ev){
01553   
01554   using namespace edm;
01555   
01556   
01557   // initialize data vectors
01558   csub.clear();
01559   cen.clear();
01560   ceta.clear();
01561   cphi.clear();
01562   ctime.clear();
01563   cieta.clear();
01564   ciphi.clear();
01565   cdepth.clear();
01566   cz.clear();
01567   cstwd.clear();
01568   cauxstwd.clear();
01569   hcalHBSevLvlVec.clear();
01570   hcalHESevLvlVec.clear();
01571   hcalHFSevLvlVec.clear();
01572   hcalHOSevLvlVec.clear(); 
01573 
01574   if( subdet_ == 1 || subdet_ == 2  || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
01575     
01576     //HBHE
01577     edm::Handle<HBHERecHitCollection> hbhecoll;
01578     ev.getByLabel(theHBHERecHitCollectionLabel, hbhecoll);
01579     
01580     for (HBHERecHitCollection::const_iterator j=hbhecoll->begin(); j != hbhecoll->end(); j++) {
01581       HcalDetId cell(j->id());
01582       const CaloCellGeometry* cellGeometry =
01583         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01584       double eta  = cellGeometry->getPosition().eta () ;
01585       double phi  = cellGeometry->getPosition().phi () ;
01586       double zc   = cellGeometry->getPosition().z ();
01587       int sub     = cell.subdet();
01588       int depth   = cell.depth();
01589       int inteta  = cell.ieta();
01590       if(inteta > 0) inteta -= 1;
01591       int intphi  = cell.iphi()-1;
01592       double en   = j->energy();
01593       double t    = j->time();
01594       int stwd    = j->flags();
01595       int auxstwd = j->aux();
01596       
01597       int serivityLevel = hcalSevLvl( (CaloRecHit*) &*j );
01598       if( cell.subdet()==HcalBarrel ){
01599          hcalHBSevLvlVec.push_back(serivityLevel);
01600       }else if (cell.subdet()==HcalEndcap ){
01601          hcalHESevLvlVec.push_back(serivityLevel);
01602       } 
01603       
01604       if((iz > 0 && eta > 0.) || (iz < 0 && eta <0.) || iz == 0) { 
01605         
01606         csub.push_back(sub);
01607         cen.push_back(en);
01608         ceta.push_back(eta);
01609         cphi.push_back(phi);
01610         ctime.push_back(t);
01611         cieta.push_back(inteta);
01612         ciphi.push_back(intphi);
01613         cdepth.push_back(depth);
01614         cz.push_back(zc);
01615         cstwd.push_back(stwd);
01616         cauxstwd.push_back(auxstwd);
01617       }
01618     }
01619     
01620   }
01621 
01622   if( subdet_ == 4 || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
01623 
01624     //HF
01625     edm::Handle<HFRecHitCollection> hfcoll;
01626     ev.getByLabel(theHFRecHitCollectionLabel, hfcoll);
01627 
01628     for (HFRecHitCollection::const_iterator j = hfcoll->begin(); j != hfcoll->end(); j++) {
01629       HcalDetId cell(j->id());
01630       const CaloCellGeometry* cellGeometry =
01631         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01632       double eta   = cellGeometry->getPosition().eta () ;
01633       double phi   = cellGeometry->getPosition().phi () ;
01634       double zc     = cellGeometry->getPosition().z ();
01635       int sub      = cell.subdet();
01636       int depth    = cell.depth();
01637       int inteta   = cell.ieta();
01638       if(inteta > 0) inteta -= 1;
01639       int intphi   = cell.iphi()-1;
01640       double en    = j->energy();
01641       double t     = j->time();
01642       int stwd     = j->flags();
01643       int auxstwd  = j->aux();
01644 
01645       int serivityLevel = hcalSevLvl( (CaloRecHit*) &*j );
01646       if( cell.subdet()==HcalForward ){
01647          hcalHFSevLvlVec.push_back(serivityLevel);
01648       } 
01649 
01650       if((iz > 0 && eta > 0.) || (iz < 0 && eta <0.) || iz == 0) { 
01651         
01652         csub.push_back(sub);
01653         cen.push_back(en);
01654         ceta.push_back(eta);
01655         cphi.push_back(phi);
01656         ctime.push_back(t);
01657         cieta.push_back(inteta);
01658         ciphi.push_back(intphi);
01659         cdepth.push_back(depth);
01660         cz.push_back(zc);
01661         cstwd.push_back(stwd);
01662         cauxstwd.push_back(auxstwd);
01663       }
01664     }
01665   }
01666 
01667   //HO
01668   if( subdet_ == 3 || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
01669   
01670     edm::Handle<HORecHitCollection> hocoll;
01671     ev.getByLabel(theHORecHitCollectionLabel, hocoll);
01672     
01673     for (HORecHitCollection::const_iterator j = hocoll->begin(); j != hocoll->end(); j++) {
01674       HcalDetId cell(j->id());
01675       const CaloCellGeometry* cellGeometry =
01676         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01677       double eta   = cellGeometry->getPosition().eta () ;
01678       double phi   = cellGeometry->getPosition().phi () ;
01679       double zc    = cellGeometry->getPosition().z ();
01680       int sub      = cell.subdet();
01681       int depth    = cell.depth();
01682       int inteta   = cell.ieta();
01683       if(inteta > 0) inteta -= 1;
01684       int intphi   = cell.iphi()-1;
01685       double t     = j->time();
01686       double en    = j->energy();
01687       int stwd     = j->flags();
01688       int auxstwd  = j->aux();
01689 
01690       int serivityLevel = hcalSevLvl( (CaloRecHit*) &*j );
01691       if( cell.subdet()==HcalOuter ){
01692          hcalHOSevLvlVec.push_back(serivityLevel);
01693       } 
01694       
01695       if((iz > 0 && eta > 0.) || (iz < 0 && eta <0.) || iz == 0) { 
01696         csub.push_back(sub);
01697         cen.push_back(en);
01698         ceta.push_back(eta);
01699         cphi.push_back(phi);
01700         ctime.push_back(t);
01701         cieta.push_back(inteta);
01702         ciphi.push_back(intphi);
01703         cdepth.push_back(depth);
01704         cz.push_back(zc);
01705         cstwd.push_back(stwd);
01706         cauxstwd.push_back(auxstwd);
01707       }
01708     }
01709   }
01710 }
01711 
01712 double HcalRecHitsValidation::dR(double eta1, double phi1, double eta2, double phi2) { 
01713   double PI = 3.1415926535898;
01714   double deltaphi= phi1 - phi2;
01715   if( phi2 > phi1 ) { deltaphi= phi2 - phi1;}
01716   if(deltaphi > PI) { deltaphi = 2.*PI - deltaphi;}
01717   double deltaeta = eta2 - eta1;
01718   double tmp = sqrt(deltaeta* deltaeta + deltaphi*deltaphi);
01719   return tmp;
01720 }
01721 
01722 double HcalRecHitsValidation::phi12(double phi1, double en1, double phi2, double en2) {
01723   // weighted mean value of phi1 and phi2
01724   
01725   double tmp;
01726   double PI = 3.1415926535898;
01727   double a1 = phi1; double a2  = phi2;
01728 
01729   if( a1 > 0.5*PI  && a2 < 0.) a2 += 2*PI; 
01730   if( a2 > 0.5*PI  && a1 < 0.) a1 += 2*PI; 
01731   tmp = (a1 * en1 + a2 * en2)/(en1 + en2);
01732   if(tmp > PI) tmp -= 2.*PI; 
01733  
01734   return tmp;
01735 
01736 }
01737 
01738 double HcalRecHitsValidation::dPhiWsign(double phi1, double phi2) {
01739   // clockwise      phi2 w.r.t phi1 means "+" phi distance
01740   // anti-clockwise phi2 w.r.t phi1 means "-" phi distance 
01741 
01742   double PI = 3.1415926535898;
01743   double a1 = phi1; double a2  = phi2;
01744   double tmp =  a2 - a1;
01745   if( a1*a2 < 0.) {
01746     if(a1 > 0.5 * PI)  tmp += 2.*PI;
01747     if(a2 > 0.5 * PI)  tmp -= 2.*PI;
01748   }
01749   return tmp;
01750 
01751 }
01752 
01753 int HcalRecHitsValidation::hcalSevLvl(const CaloRecHit* hit){
01754 
01755    const DetId id = hit->detid();
01756 
01757    const uint32_t recHitFlag = hit->flags();
01758    const uint32_t dbStatusFlag = theHcalChStatus->getValues(id)->getValue();
01759 
01760    int severityLevel = theHcalSevLvlComputer->getSeverityLevel(id, recHitFlag, dbStatusFlag);
01761 
01762    return severityLevel;
01763 
01764 } 
01765 
01766 DEFINE_FWK_MODULE(HcalRecHitsValidation);
01767