CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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, 84, -42., 42., 72, 0., 72.);
00153       sprintf  (histo, "emap_depth2" );
00154       emap_depth2 = dbe_->book2D(histo, histo, 84, -42., 42., 72, 0., 72.);
00155       sprintf  (histo, "emap_depth3" );
00156       emap_depth3 = dbe_->book2D(histo, histo, 84, -42., 42., 72, 0., 72.);
00157       sprintf  (histo, "emap_depth4" );
00158       emap_depth4 = dbe_->book2D(histo, histo, 84, -42., 42., 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       // to distinguish HE and HF
00974       if( depth == 1 || depth == 2 ) {
00975         int ieta1 =  ieta;
00976         if(sub == 4) { 
00977           if (ieta1 < 0) ieta1--;
00978           else  ieta1++;   
00979         }
00980         if (depth == 1) emap_depth1->Fill(double(ieta1), double(iphi), en);
00981         if (depth == 2) emap_depth2->Fill(double(ieta1), double(iphi), en);
00982       }
00983 
00984       if( depth == 3) emap_depth3->Fill(double(ieta), double(iphi), en);
00985       if( depth == 4) emap_depth4->Fill(double(ieta), double(iphi), en);
00986       
00987       if (depth == 1 && sub == 1 ) {
00988         emean_vs_ieta_HB1->Fill(double(ieta), en);
00989         occupancy_map_HB1->Fill(double(ieta), double(iphi));          
00990         if(useAllHistos_){
00991           emean_seqHB1->Fill(double(index), en);
00992         }
00993       }
00994       if (depth == 2  && sub == 1) {
00995         emean_vs_ieta_HB2->Fill(double(ieta), en);
00996         occupancy_map_HB2->Fill(double(ieta), double(iphi));          
00997         if(useAllHistos_){
00998           emean_seqHB2->Fill(double(index), en);
00999         }
01000       }
01001       if (depth == 1 && sub == 2) {
01002         emean_vs_ieta_HE1->Fill(double(ieta), en);
01003         occupancy_map_HE1->Fill(double(ieta), double(iphi));   
01004         if(useAllHistos_){
01005           emean_seqHE1->Fill(double(index), en);
01006         }
01007       }
01008       if (depth == 2 && sub == 2) {
01009         emean_vs_ieta_HE2->Fill(double(ieta), en);
01010         occupancy_map_HE2->Fill(double(ieta), double(iphi));          
01011         if(useAllHistos_){
01012           emean_seqHE2->Fill(double(index), en);
01013         }
01014       }
01015       if (depth == 3 && sub == 2) {
01016         emean_vs_ieta_HE3->Fill(double(ieta), en);
01017         occupancy_map_HE3->Fill(double(ieta), double(iphi));          
01018         if(useAllHistos_){
01019           emean_seqHE3->Fill(double(index), en);
01020         }
01021       }
01022       if (depth == 4 ) {
01023         emean_vs_ieta_HO->Fill(double(ieta), en);
01024         occupancy_map_HO->Fill(double(ieta), double(iphi));          
01025         if(useAllHistos_){
01026           emean_seqHO->Fill(double(index), en);
01027         }
01028       }
01029       if (depth == 1 && sub == 4) {
01030         emean_vs_ieta_HF1->Fill(double(ieta), en);
01031         occupancy_map_HF1->Fill(double(ieta), double(iphi));          
01032         if(useAllHistos_){
01033           emean_seqHF1->Fill(double(index), en);
01034         }
01035       }
01036       if (depth == 2 && sub == 4) {
01037         emean_vs_ieta_HF2->Fill(double(ieta), en);
01038         occupancy_map_HF2->Fill(double(ieta), double(iphi));          
01039         if(useAllHistos_){
01040           emean_seqHF2->Fill(double(index), en);
01041         }
01042       }
01043     }
01044     
01045 
01046     if( r < partR ) {
01047       if (depth == 1) ehcal_coneMC_1 += en; 
01048       if (depth == 2) ehcal_coneMC_2 += en; 
01049       if (depth == 3) ehcal_coneMC_3 += en; 
01050       if (depth == 4) ehcal_coneMC_4 += en; 
01051     }
01052     
01053     //32-bit status word  
01054     uint32_t statadd;
01055     unsigned int isw67 = 0;
01056     for (unsigned int isw = 0; isw < 32; isw++){
01057       statadd = 0x1<<(isw);
01058       if (stwd & statadd){
01059         if      (sub == 1) RecHit_StatusWord_HB->Fill(isw);
01060         else if (sub == 2) RecHit_StatusWord_HE->Fill(isw);
01061         else if (sub == 3) RecHit_StatusWord_HO->Fill(isw);
01062         else if (sub == 4){
01063           RecHit_StatusWord_HF->Fill(isw);
01064           if (isw == 6) isw67 += 1;
01065           if (isw == 7) isw67 += 2;
01066         }
01067       }
01068     }
01069     if (isw67 != 0 && useAllHistos_) RecHit_StatusWord_HF67->Fill(isw67); //This one is not drawn
01070 
01071     for (unsigned int isw =0; isw < 32; isw++){
01072       statadd = 0x1<<(isw);
01073       if( auxstwd & statadd ){
01074         if      (sub == 1) RecHit_Aux_StatusWord_HB->Fill(isw);
01075         else if (sub == 2) RecHit_Aux_StatusWord_HE->Fill(isw);
01076         else if (sub == 3) RecHit_Aux_StatusWord_HO->Fill(isw);
01077         else if (sub == 4) RecHit_Aux_StatusWord_HF->Fill(isw);
01078       }
01079 
01080     }
01081 
01082   } 
01083  
01084   //  std::cout << "*** 4-2" << std::endl; 
01085   
01086   if( subdet_ == 6 && useAllHistos_) {               // ZS plots; not drawn
01087     ZS_nHB1->Fill(double(nhb1));  
01088     ZS_nHB2->Fill(double(nhb2));  
01089     ZS_nHE1->Fill(double(nhe1));  
01090     ZS_nHE2->Fill(double(nhe2));  
01091     ZS_nHE3->Fill(double(nhe3));  
01092     ZS_nHO ->Fill(double(nho));  
01093     ZS_nHF1->Fill(double(nhf1));  
01094     ZS_nHF2->Fill(double(nhf2));  
01095   }
01096   else{ 
01097     Nhb->Fill(double(nhb1 + nhb2));
01098     Nhe->Fill(double(nhe1 + nhe2 + nhe3));
01099     Nho->Fill(double(nho));
01100     Nhf->Fill(double(nhf1 + nhf2));
01101 
01102     //These are not drawn
01103     if(imc != 0 && useAllHistos_) {
01104       map_econe_depth1->Fill(eta_MC, phi_MC, ehcal_coneMC_1);
01105       map_econe_depth2->Fill(eta_MC, phi_MC, ehcal_coneMC_2);
01106       map_econe_depth3->Fill(eta_MC, phi_MC, ehcal_coneMC_3);
01107       map_econe_depth4->Fill(eta_MC, phi_MC, ehcal_coneMC_4);
01108     }
01109   }
01110 
01111   //  std::cout << "*** 5" << std::endl; 
01112     
01113 
01114   //  NOISE ================================================================= 
01115   //Not drawn
01116   if (hcalselector_ == "noise" && useAllHistos_) {
01117     for (unsigned int i = 0; i < cen.size(); i++) {
01118       
01119       int sub   = csub[i];
01120       int depth = cdepth[i];
01121       double en = cen[i]; 
01122       
01123       if (sub == 1) e_hb->Fill(en);
01124       if (sub == 2) e_he->Fill(en);  
01125       if (sub == 3) e_ho->Fill(en);  
01126       if (sub == 4) {
01127         if(depth == 1)  
01128           e_hfl->Fill(en);  
01129         else 
01130           e_hfs->Fill(en);  
01131       }
01132     }
01133   }
01134 
01135   //===========================================================================
01136   // SUBSYSTEMS,  
01137   //===========================================================================
01138   
01139   else if ((subdet_ != 6) && (subdet_ != 0)) {
01140 
01141     //       std::cout << "*** 6" << std::endl; 
01142     
01143     
01144     double clusEta = 999.;
01145     double clusPhi = 999.; 
01146     double clusEn  = 0.;
01147     
01148     double HcalCone_d1 = 0.;
01149     double HcalCone_d2 = 0.;
01150     double HcalCone_d3 = 0.;
01151     double HcalCone_d4 = 0.;
01152     double HcalCone    = 0.;
01153 
01154     int ietaMax1  =  9999;
01155     int ietaMax2  =  9999;
01156     int ietaMax3  =  9999;
01157     int ietaMax4  =  9999;
01158     int ietaMax   =  9999;
01159     double enMax1 = -9999.;
01160     double enMax2 = -9999.;
01161     double enMax3 = -9999.;
01162     double enMax4 = -9999.;
01163     //    double enMax  = -9999.;
01164     double etaMax =  9999.;
01165 
01166     /*
01167     std::cout << "*** point 5-1" << "  eta_MC, phi_MC    etaHot,  phiHot = "
01168               << eta_MC  << ", " << phi_MC << "   "
01169               << etaHot  << ", " << phiHot  
01170               << std::endl;
01171     */
01172 
01173     //   CYCLE over cells ====================================================
01174 
01175     for (unsigned int i = 0; i < cen.size(); i++) {
01176       int sub    = csub[i];
01177       int depth  = cdepth[i];
01178       double eta = ceta[i]; 
01179       double phi = cphi[i]; 
01180       double en  = cen[i]; 
01181       double t   = ctime[i];
01182       int   ieta = cieta[i];
01183 
01184       double rhot = dR(etaHot, phiHot, eta, phi); 
01185       if(rhot < partR && en > 1.) { 
01186         clusEta = (clusEta * clusEn + eta * en)/(clusEn + en);
01187         clusPhi = phi12(clusPhi, clusEn, phi, en); 
01188         clusEn += en;
01189       }
01190 
01191       nrechits++;           
01192       eHcal += en;
01193       if(en > 1. ) nrechitsThresh++;
01194 
01195       double r    = dR(eta_MC, phi_MC, eta, phi);
01196       if( r < partR ){
01197         if(sub == 1)   eHcalConeHB += en;
01198         if(sub == 2)   eHcalConeHE += en;
01199         if(sub == 3)   eHcalConeHO += en;
01200         if(sub == 4) {
01201           eHcalConeHF += en;
01202           if (depth == 1) eHcalConeHFL += en;
01203           else            eHcalConeHFS += en;
01204         }
01205         eHcalCone += en;
01206         nrechitsCone++;
01207 
01208         // search for most energetic cell at the given depth in the cone
01209         if(depth == 1) {
01210           HcalCone_d1 += en;
01211           if(enMax1 < en) {
01212             enMax1   = en;
01213             ietaMax1 = ieta;
01214           }
01215         }
01216         if(depth == 2) {
01217           HcalCone_d2 += en;
01218           if(enMax2 < en) {
01219             enMax2   = en;
01220             ietaMax2 = ieta;
01221           }
01222         }
01223         if(depth == 3) {
01224           HcalCone_d3 += en;
01225           if(enMax3 < en) {
01226             enMax3   = en;
01227             ietaMax3 = ieta;
01228           }
01229         }
01230         if(depth == 4) {
01231           HcalCone_d4 += en;
01232           if(enMax4 < en) {
01233             enMax4   = en;
01234             ietaMax4 = ieta;
01235           }
01236         }
01237 
01238         if(depth != 4) {
01239           HcalCone += en;
01240         }
01241 
01242 
01243         // regardless of the depths (but excluding HO), just hottest cell
01244         /*
01245         if(depth != 4) {
01246           if(enMax   < en) {
01247             enMax   = en;
01248             ietaMax = ieta;
01249           }
01250         }   
01251         */
01252 
01253         // alternative: ietamax -> closest to MC eta  !!!
01254         float eta_diff = fabs(eta_MC - eta);
01255         if(eta_diff < etaMax) {
01256           etaMax  = eta_diff; 
01257           ietaMax = ieta; 
01258         }
01259       }
01260       
01261       //The energy and overall timing histos are drawn while
01262       //the ones split by depth are not
01263       if(sub == 1 && (subdet_ == 1 || subdet_ == 5)) {  
01264         meTimeHB->Fill(t);
01265         meRecHitsEnergyHB->Fill(en);
01266         
01267         meTE_Low_HB->Fill( en, t);
01268         meTE_HB->Fill( en, t);
01269         meTE_High_HB->Fill( en, t);
01270         meTEprofileHB_Low->Fill(en, t);
01271         meTEprofileHB->Fill(en, t);
01272         meTEprofileHB_High->Fill(en, t);
01273 
01274         if (useAllHistos_){
01275           if      (depth == 1) meTE_HB1->Fill( en, t);
01276           else if (depth == 2) meTE_HB2->Fill( en, t);
01277         }
01278       }     
01279       if(sub == 2 && (subdet_ == 2 || subdet_ == 5)) {  
01280         meTimeHE->Fill(t);
01281         meRecHitsEnergyHE->Fill(en);
01282 
01283         meTE_Low_HE->Fill( en, t);
01284         meTE_HE->Fill( en, t);
01285         meTEprofileHE_Low->Fill(en, t);
01286         meTEprofileHE->Fill(en, t);
01287 
01288         if (useAllHistos_){
01289           if      (depth == 1) meTE_HE1->Fill( en, t);
01290           else if (depth == 2) meTE_HE2->Fill( en, t);
01291         }
01292       }
01293       if(sub == 4 && (subdet_ == 4 || subdet_ == 5)) {  
01294         meTimeHF->Fill(t);
01295         meRecHitsEnergyHF->Fill(en);      
01296 
01297         meTE_Low_HF->Fill(en, t);
01298         meTE_HF->Fill(en, t);
01299         meTEprofileHF_Low->Fill(en, t);
01300         meTEprofileHF->Fill(en, t);
01301 
01302         if (useAllHistos_){
01303           if   (depth == 1) meTE_HFL->Fill( en, t);
01304           else              meTE_HFS->Fill( en, t);
01305         }
01306       }
01307       if(sub == 3 && (subdet_ == 3 || subdet_ == 5)) {  
01308         meTimeHO->Fill(t);
01309         meRecHitsEnergyHO->Fill(en);
01310 
01311         meTE_HO->Fill( en, t);
01312         meTE_High_HO->Fill( en, t);
01313         meTEprofileHO->Fill(en, t);
01314         meTEprofileHO_High->Fill(en, t);
01315       }
01316     }
01317 
01318     if(imc != 0) {
01319       //Cone by depth are not drawn, the others are used for pion scan
01320       if (useAllHistos_){
01321         meEnConeEtaProfile_depth1->Fill(double(ietaMax1), HcalCone_d1);
01322         meEnConeEtaProfile_depth2->Fill(double(ietaMax2), HcalCone_d2);
01323         meEnConeEtaProfile_depth3->Fill(double(ietaMax3), HcalCone_d3);
01324         meEnConeEtaProfile_depth4->Fill(double(ietaMax4), HcalCone_d4);
01325       }
01326       meEnConeEtaProfile       ->Fill(double(ietaMax),  HcalCone);   // 
01327       meEnConeEtaProfile_E     ->Fill(double(ietaMax), eEcalCone);   
01328       meEnConeEtaProfile_EH    ->Fill(double(ietaMax),  HcalCone+eEcalCone); 
01329     }
01330 
01331     //     std::cout << "*** 7" << std::endl; 
01332 
01333     
01334     // Single particle samples ONLY !  ======================================
01335     // Fill up some histos for "integrated" subsustems. 
01336     // These are not drawn
01337     if(etype_ == 1 && useAllHistos_) {
01338 
01339       /*
01340       std::cout << "*** point 7-1" << "  eta_MC, phi_MC   clusEta, clusPhi = "
01341                 << eta_MC  << ", " << phi_MC << "   "
01342                 << clusEta << ", " << clusPhi 
01343                 << std::endl;
01344       */    
01345 
01346       double phidev = dPhiWsign(clusPhi, phi_MC);
01347       meDeltaPhi->Fill(eta_MC, phidev);
01348       double etadev = clusEta - eta_MC;
01349       meDeltaEta->Fill(eta_MC, etadev);
01350 
01351       if(subdet_ == 1) {
01352         meSumRecHitsEnergyHB->Fill(eHcal);
01353         if(imc != 0) meSumRecHitsEnergyConeHB->Fill(eHcalConeHB);    
01354         if(imc != 0) meNumRecHitsConeHB->Fill(double(nrechitsCone));
01355         meNumRecHitsThreshHB->Fill(double(nrechitsThresh));
01356       }
01357 
01358       if(subdet_ == 2) {
01359         meSumRecHitsEnergyHE->Fill(eHcal);
01360         if(imc != 0) meSumRecHitsEnergyConeHE->Fill(eHcalConeHE);    
01361         if(imc != 0) meNumRecHitsConeHE->Fill(double(nrechitsCone));
01362         meNumRecHitsThreshHE->Fill(double(nrechitsThresh));
01363       }
01364 
01365       if(subdet_ == 3) {
01366         meSumRecHitsEnergyHO->Fill(eHcal);
01367         if(imc != 0) meSumRecHitsEnergyConeHO->Fill(eHcalConeHO);    
01368         if(imc != 0) meNumRecHitsConeHO->Fill(double(nrechitsCone));
01369         meNumRecHitsThreshHO->Fill(double(nrechitsThresh));
01370       }
01371 
01372       if(subdet_ == 4) {
01373         if(eHcalConeHF > eps ) {
01374           meSumRecHitsEnergyHF ->Fill(eHcal);
01375           if(imc != 0) { 
01376             meSumRecHitsEnergyConeHF ->Fill(eHcalConeHF);    
01377             meNumRecHitsConeHF->Fill(double(nrechitsCone));
01378             meSumRecHitsEnergyConeHFL ->Fill(eHcalConeHFL);    
01379             meSumRecHitsEnergyConeHFS ->Fill(eHcalConeHFS);    
01380           }
01381         }
01382       }
01383 
01384       //         std::cout << "*** 8" << std::endl; 
01385 
01386 
01387       // Also combine with ECAL if needed 
01388       if(subdet_ == 1  && ecalselector_ == "yes") {
01389         
01390         /*
01391           std::cout << "*** point 8-1" 
01392           << "  eEcalB " << eEcalB << "  eHcal " << eHcal
01393           << "  eEcalCone " <<  eEcalCone << "  eHcalCone " 
01394                   << eHcalCone
01395                   << "  numrechitsEcal " <<  numrechitsEcal
01396                   << std::endl;
01397                   
01398         */
01399         
01400         meEcalHcalEnergyHB->Fill(eEcalB+eHcal);
01401         meEcalHcalEnergyConeHB->Fill(eEcalCone+eHcalCone);
01402         meNumEcalRecHitsConeHB->Fill(double(numrechitsEcal));
01403         
01404       }
01405       
01406       if(subdet_ == 2  && ecalselector_ == "yes"){
01407         
01408         /*
01409           std::cout << "*** point 8-2a" 
01410           << "  eEcalE " << eEcalE << "  eHcal " << eHcal
01411           << "  eEcalCone " <<  eEcalCone << "  eHcalCone " 
01412           << eHcalCone
01413           << "  numrechitsEcal " <<  numrechitsEcal
01414           << std::endl;
01415         */
01416         
01417         meEcalHcalEnergyHE->Fill(eEcalE+eHcal);
01418         if(imc != 0) meEcalHcalEnergyConeHE->Fill(eEcalCone+eHcalCone);
01419         if(imc != 0) meNumEcalRecHitsConeHE->Fill(double(numrechitsEcal));
01420       } 
01421 
01422       // Banana plots finally
01423       if(imc != 0) {
01424         if(subdet_ == 1 && ecalselector_ == "yes")
01425           meEnergyHcalVsEcalHB -> Fill(eEcalCone,eHcalCone);
01426         if(subdet_ == 2 && ecalselector_ == "yes") 
01427           meEnergyHcalVsEcalHE -> Fill(eEcalCone,eHcalCone);
01428       }
01429     }
01430   }
01431   //  std::cout << "*** 9" << std::endl; 
01432 
01433 
01434   //===========================================================================
01435   // Getting SimHits
01436   //===========================================================================
01437 
01438   if(subdet_ > 0 && subdet_ < 6 && imc !=0 && !famos_  ) {  // not noise 
01439 
01440     double maxES = -9999.;
01441     double etaHotS = 1000.;
01442     double phiHotS = 1000.;
01443     
01444     edm::Handle<PCaloHitContainer> hcalHits;
01445     ev.getByLabel("g4SimHits","HcalHits",hcalHits);
01446     const PCaloHitContainer * SimHitResult = hcalHits.product () ;
01447     
01448     double enSimHits    = 0.;
01449     double enSimHitsHB  = 0.;
01450     double enSimHitsHE  = 0.;
01451     double enSimHitsHO  = 0.;
01452     double enSimHitsHF  = 0.;
01453     double enSimHitsHFL = 0.;
01454     double enSimHitsHFS = 0.;
01455     // sum of SimHits in the cone 
01456     
01457     for (std::vector<PCaloHit>::const_iterator SimHits = SimHitResult->begin () ; SimHits != SimHitResult->end(); ++SimHits) {
01458       HcalDetId cell(SimHits->id());
01459       int sub =  cell.subdet();
01460       const CaloCellGeometry* cellGeometry =
01461         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01462       double etaS = cellGeometry->getPosition().eta () ;
01463       double phiS = cellGeometry->getPosition().phi () ;
01464       double en   = SimHits->energy();    
01465 
01466       double emin = 0.01;
01467       if(fabs(etaS) > 3.) emin = 1.;   
01468 
01469       double r  = dR(eta_MC, phi_MC, etaS, phiS);
01470       if( r < searchR ) { // search for hottest cell in a big cone
01471         if(maxES < en && en > emin ) {
01472           maxES    = en;
01473           etaHotS  = etaS;
01474           phiHotS  = phiS;
01475         }
01476       }
01477        
01478       if ( r < partR ){ // just energy in the small cone
01479         enSimHits += en;
01480         if(sub == 1) enSimHitsHB += en; 
01481         if(sub == 2) enSimHitsHE += en; 
01482         if(sub == 3) enSimHitsHO += en; 
01483         if(sub == 4) {
01484           enSimHitsHF += en;
01485           int depth = cell.depth();
01486           if(depth == 1) enSimHitsHFL += en;
01487           else           enSimHitsHFS += en;
01488         } 
01489       }
01490     }
01491 
01492 
01493     // Second look over SimHits: cluster finding
01494 
01495     double clusEta = 999.;
01496     double clusPhi = 999.; 
01497     double clusEn  = 0.;
01498 
01499     for (std::vector<PCaloHit>::const_iterator SimHits = SimHitResult->begin () ; SimHits != SimHitResult->end(); ++SimHits) {
01500      HcalDetId cell(SimHits->id());
01501 
01502       const CaloCellGeometry* cellGeometry =
01503         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01504       double etaS = cellGeometry->getPosition().eta () ;
01505       double phiS = cellGeometry->getPosition().phi () ;
01506       double en   =  SimHits->energy();    
01507 
01508       double emin = 0.01;
01509       if(fabs(etaS) > 3.) emin = 1.; 
01510 
01511       double rhot = dR(etaHotS, phiHotS, etaS, phiS); 
01512       if(rhot < partR && en > emin) { 
01513         clusEta = (clusEta * clusEn + etaS * en)/(clusEn + en);
01514         clusPhi = phi12(clusPhi, clusEn, phiS, en); 
01515         clusEn += en;
01516       }
01517     }
01518 
01519     // SimHits cluster deviation from MC (eta, phi)
01520     // These are not drawn
01521     if (useAllHistos_){
01522       if(etype_ == 1) {
01523         double phidev = dPhiWsign(clusPhi, phi_MC);
01524         meDeltaPhiS->Fill(eta_MC, phidev);
01525         double etadev = clusEta - eta_MC;
01526         meDeltaEtaS->Fill(eta_MC, etadev);
01527       }
01528       // Now some histos with SimHits
01529     
01530       if(subdet_ == 4 || subdet_ == 5) {
01531         if(eHcalConeHF > eps) {
01532           meRecHitSimHitHF->Fill( enSimHitsHF, eHcalConeHF );
01533           meRecHitSimHitProfileHF->Fill( enSimHitsHF, eHcalConeHF);
01534           
01535           meRecHitSimHitHFL->Fill( enSimHitsHFL, eHcalConeHFL );
01536           meRecHitSimHitProfileHFL->Fill( enSimHitsHFL, eHcalConeHFL);
01537           meRecHitSimHitHFS->Fill( enSimHitsHFS, eHcalConeHFS );
01538           meRecHitSimHitProfileHFS->Fill( enSimHitsHFS, eHcalConeHFS);       
01539         }
01540       }
01541       if(subdet_ == 1  || subdet_ == 5) { 
01542         meRecHitSimHitHB->Fill( enSimHitsHB,eHcalConeHB );
01543         meRecHitSimHitProfileHB->Fill( enSimHitsHB,eHcalConeHB);
01544       }
01545       if(subdet_ == 2  || subdet_ == 5) { 
01546         meRecHitSimHitHE->Fill( enSimHitsHE,eHcalConeHE );
01547         meRecHitSimHitProfileHE->Fill( enSimHitsHE,eHcalConeHE);
01548       }
01549       if(subdet_ == 3  || subdet_ == 5) { 
01550         meRecHitSimHitHO->Fill( enSimHitsHO,eHcalConeHO );
01551         meRecHitSimHitProfileHO->Fill( enSimHitsHO,eHcalConeHO);
01552       }
01553     }
01554   }
01555 
01556   nevtot++;
01557 }
01558 
01559 
01561 void HcalRecHitsValidation::fillRecHitsTmp(int subdet_, edm::Event const& ev){
01562   
01563   using namespace edm;
01564   
01565   
01566   // initialize data vectors
01567   csub.clear();
01568   cen.clear();
01569   ceta.clear();
01570   cphi.clear();
01571   ctime.clear();
01572   cieta.clear();
01573   ciphi.clear();
01574   cdepth.clear();
01575   cz.clear();
01576   cstwd.clear();
01577   cauxstwd.clear();
01578   hcalHBSevLvlVec.clear();
01579   hcalHESevLvlVec.clear();
01580   hcalHFSevLvlVec.clear();
01581   hcalHOSevLvlVec.clear(); 
01582 
01583   if( subdet_ == 1 || subdet_ == 2  || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
01584     
01585     //HBHE
01586     edm::Handle<HBHERecHitCollection> hbhecoll;
01587     ev.getByLabel(theHBHERecHitCollectionLabel, hbhecoll);
01588     
01589     for (HBHERecHitCollection::const_iterator j=hbhecoll->begin(); j != hbhecoll->end(); j++) {
01590       HcalDetId cell(j->id());
01591       const CaloCellGeometry* cellGeometry =
01592         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01593       double eta  = cellGeometry->getPosition().eta () ;
01594       double phi  = cellGeometry->getPosition().phi () ;
01595       double zc   = cellGeometry->getPosition().z ();
01596       int sub     = cell.subdet();
01597       int depth   = cell.depth();
01598       int inteta  = cell.ieta();
01599       if(inteta > 0) inteta -= 1;
01600       int intphi  = cell.iphi()-1;
01601       double en   = j->energy();
01602       double t    = j->time();
01603       int stwd    = j->flags();
01604       int auxstwd = j->aux();
01605       
01606       int serivityLevel = hcalSevLvl( (CaloRecHit*) &*j );
01607       if( cell.subdet()==HcalBarrel ){
01608          hcalHBSevLvlVec.push_back(serivityLevel);
01609       }else if (cell.subdet()==HcalEndcap ){
01610          hcalHESevLvlVec.push_back(serivityLevel);
01611       } 
01612       
01613       if((iz > 0 && eta > 0.) || (iz < 0 && eta <0.) || iz == 0) { 
01614         
01615         csub.push_back(sub);
01616         cen.push_back(en);
01617         ceta.push_back(eta);
01618         cphi.push_back(phi);
01619         ctime.push_back(t);
01620         cieta.push_back(inteta);
01621         ciphi.push_back(intphi);
01622         cdepth.push_back(depth);
01623         cz.push_back(zc);
01624         cstwd.push_back(stwd);
01625         cauxstwd.push_back(auxstwd);
01626       }
01627     }
01628     
01629   }
01630 
01631   if( subdet_ == 4 || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
01632 
01633     //HF
01634     edm::Handle<HFRecHitCollection> hfcoll;
01635     ev.getByLabel(theHFRecHitCollectionLabel, hfcoll);
01636 
01637     for (HFRecHitCollection::const_iterator j = hfcoll->begin(); j != hfcoll->end(); j++) {
01638       HcalDetId cell(j->id());
01639       const CaloCellGeometry* cellGeometry =
01640         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01641       double eta   = cellGeometry->getPosition().eta () ;
01642       double phi   = cellGeometry->getPosition().phi () ;
01643       double zc     = cellGeometry->getPosition().z ();
01644       int sub      = cell.subdet();
01645       int depth    = cell.depth();
01646       int inteta   = cell.ieta();
01647       if(inteta > 0) inteta -= 1;
01648       int intphi   = cell.iphi()-1;
01649       double en    = j->energy();
01650       double t     = j->time();
01651       int stwd     = j->flags();
01652       int auxstwd  = j->aux();
01653 
01654       int serivityLevel = hcalSevLvl( (CaloRecHit*) &*j );
01655       if( cell.subdet()==HcalForward ){
01656          hcalHFSevLvlVec.push_back(serivityLevel);
01657       } 
01658 
01659       if((iz > 0 && eta > 0.) || (iz < 0 && eta <0.) || iz == 0) { 
01660         
01661         csub.push_back(sub);
01662         cen.push_back(en);
01663         ceta.push_back(eta);
01664         cphi.push_back(phi);
01665         ctime.push_back(t);
01666         cieta.push_back(inteta);
01667         ciphi.push_back(intphi);
01668         cdepth.push_back(depth);
01669         cz.push_back(zc);
01670         cstwd.push_back(stwd);
01671         cauxstwd.push_back(auxstwd);
01672       }
01673     }
01674   }
01675 
01676   //HO
01677   if( subdet_ == 3 || subdet_ == 5 || subdet_ == 6 || subdet_ == 0) {
01678   
01679     edm::Handle<HORecHitCollection> hocoll;
01680     ev.getByLabel(theHORecHitCollectionLabel, hocoll);
01681     
01682     for (HORecHitCollection::const_iterator j = hocoll->begin(); j != hocoll->end(); j++) {
01683       HcalDetId cell(j->id());
01684       const CaloCellGeometry* cellGeometry =
01685         geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
01686       double eta   = cellGeometry->getPosition().eta () ;
01687       double phi   = cellGeometry->getPosition().phi () ;
01688       double zc    = cellGeometry->getPosition().z ();
01689       int sub      = cell.subdet();
01690       int depth    = cell.depth();
01691       int inteta   = cell.ieta();
01692       if(inteta > 0) inteta -= 1;
01693       int intphi   = cell.iphi()-1;
01694       double t     = j->time();
01695       double en    = j->energy();
01696       int stwd     = j->flags();
01697       int auxstwd  = j->aux();
01698 
01699       int serivityLevel = hcalSevLvl( (CaloRecHit*) &*j );
01700       if( cell.subdet()==HcalOuter ){
01701          hcalHOSevLvlVec.push_back(serivityLevel);
01702       } 
01703       
01704       if((iz > 0 && eta > 0.) || (iz < 0 && eta <0.) || iz == 0) { 
01705         csub.push_back(sub);
01706         cen.push_back(en);
01707         ceta.push_back(eta);
01708         cphi.push_back(phi);
01709         ctime.push_back(t);
01710         cieta.push_back(inteta);
01711         ciphi.push_back(intphi);
01712         cdepth.push_back(depth);
01713         cz.push_back(zc);
01714         cstwd.push_back(stwd);
01715         cauxstwd.push_back(auxstwd);
01716       }
01717     }
01718   }
01719 }
01720 
01721 double HcalRecHitsValidation::dR(double eta1, double phi1, double eta2, double phi2) { 
01722   double PI = 3.1415926535898;
01723   double deltaphi= phi1 - phi2;
01724   if( phi2 > phi1 ) { deltaphi= phi2 - phi1;}
01725   if(deltaphi > PI) { deltaphi = 2.*PI - deltaphi;}
01726   double deltaeta = eta2 - eta1;
01727   double tmp = sqrt(deltaeta* deltaeta + deltaphi*deltaphi);
01728   return tmp;
01729 }
01730 
01731 double HcalRecHitsValidation::phi12(double phi1, double en1, double phi2, double en2) {
01732   // weighted mean value of phi1 and phi2
01733   
01734   double tmp;
01735   double PI = 3.1415926535898;
01736   double a1 = phi1; double a2  = phi2;
01737 
01738   if( a1 > 0.5*PI  && a2 < 0.) a2 += 2*PI; 
01739   if( a2 > 0.5*PI  && a1 < 0.) a1 += 2*PI; 
01740   tmp = (a1 * en1 + a2 * en2)/(en1 + en2);
01741   if(tmp > PI) tmp -= 2.*PI; 
01742  
01743   return tmp;
01744 
01745 }
01746 
01747 double HcalRecHitsValidation::dPhiWsign(double phi1, double phi2) {
01748   // clockwise      phi2 w.r.t phi1 means "+" phi distance
01749   // anti-clockwise phi2 w.r.t phi1 means "-" phi distance 
01750 
01751   double PI = 3.1415926535898;
01752   double a1 = phi1; double a2  = phi2;
01753   double tmp =  a2 - a1;
01754   if( a1*a2 < 0.) {
01755     if(a1 > 0.5 * PI)  tmp += 2.*PI;
01756     if(a2 > 0.5 * PI)  tmp -= 2.*PI;
01757   }
01758   return tmp;
01759 
01760 }
01761 
01762 int HcalRecHitsValidation::hcalSevLvl(const CaloRecHit* hit){
01763 
01764    const DetId id = hit->detid();
01765 
01766    const uint32_t recHitFlag = hit->flags();
01767    const uint32_t dbStatusFlag = theHcalChStatus->getValues(id)->getValue();
01768 
01769    int severityLevel = theHcalSevLvlComputer->getSeverityLevel(id, recHitFlag, dbStatusFlag);
01770 
01771    return severityLevel;
01772 
01773 } 
01774 
01775 DEFINE_FWK_MODULE(HcalRecHitsValidation);
01776