CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Validation/HcalHits/src/ZdcSimHitStudy.cc

Go to the documentation of this file.
00001 #include "Validation/HcalHits/interface/ZdcSimHitStudy.h"
00002 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
00003 
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00006 
00007 ZdcSimHitStudy::ZdcSimHitStudy(const edm::ParameterSet& ps) {
00008 
00009   g4Label  = ps.getUntrackedParameter<std::string>("moduleLabel","g4SimHits");
00010   zdcHits = ps.getUntrackedParameter<std::string>("HitCollection","ZdcHits");
00011   outFile_ = ps.getUntrackedParameter<std::string>("outputFile", "zdcHitStudy.root");
00012   verbose_ = ps.getUntrackedParameter<bool>("Verbose", false);
00013   checkHit_= true;
00014 
00015   edm::LogInfo("ZdcSimHitStudy") 
00016     //std::cout
00017     << "Module Label: " << g4Label << "   Hits: "
00018     << zdcHits << " / "<< checkHit_ 
00019     << "   Output: " << outFile_;
00020 
00021   dbe_ = edm::Service<DQMStore>().operator->();
00022   if (dbe_) {
00023     if (verbose_) {
00024       dbe_->setVerbose(1);
00025       sleep (3);
00026       dbe_->showDirStructure();
00027     } else {
00028       dbe_->setVerbose(0);
00029     }
00030   }
00031 }
00032 
00033 ZdcSimHitStudy::~ZdcSimHitStudy() {}
00034 
00035 void ZdcSimHitStudy::beginJob() {
00036   if (dbe_) {
00037     dbe_->setCurrentFolder("ZdcHitsV/ZdcSimHitsTask");
00038     //Histograms for Hits
00039     if (checkHit_) {
00040       meAllZdcNHit_ = dbe_->book1D("Hit01","Number of All Hits in Zdc",100,0.,100.);
00041       meBadZdcDetHit_= dbe_->book1D("Hit02","Hits with wrong Det in Zdc",100,0.,100.);
00042       meBadZdcSecHit_= dbe_->book1D("Hit03","Hits with wrong Section in Zdc",100,0.,100.);
00043       meBadZdcIdHit_ = dbe_->book1D("Hit04","Hits with wrong ID in Zdc",100,0.,100.);
00044       meZdcNHitEM_   = dbe_->book1D("Hit05","Number of Hits in Zdc EM",100,0.,100.);
00045       meZdcNHitHad_   = dbe_->book1D("Hit06","Number of Hits in Zdc Had",100,0.,100.);
00046       meZdcNHitLum_   = dbe_->book1D("Hit07","Number of Hits in Zdc Lum",100,0.,100.);
00047       meZdcDetectHit_= dbe_->book1D("Hit08","Calo Detector ID",50,0.,50.);
00048       meZdcSideHit_ = dbe_->book1D("Hit09","Side in Zdc",4,-2,2.);
00049       meZdcSectionHit_   = dbe_->book1D("Hit10","Section in Zdc",4,0.,4.);
00050       meZdcChannelHit_   = dbe_->book1D("Hit11","Channel in Zdc",10,0.,10.);
00051       meZdcEnergyHit_= dbe_->book1D("Hit12","Hits Energy",4000,0.,8000.);
00052       meZdcHadEnergyHit_= dbe_->book1D("Hit13","Hits Energy in Had Section",4000,0.,8000.);
00053       meZdcEMEnergyHit_ = dbe_->book1D("Hit14","Hits Energy in EM Section",4000,0.,8000.);
00054       meZdcTimeHit_  = dbe_->book1D("Hit15","Time in Zdc",300,0.,600.);
00055       meZdcTimeWHit_ = dbe_->book1D("Hit16","Time in Zdc (E wtd)", 300,0.,600.);
00056       meZdc10Ene_ = dbe_->book1D("Hit17","Log10Energy in Zdc", 140, -20., 20. );
00057       meZdcHadL10EneP_ = dbe_->bookProfile("Hit18","Log10Energy in Had Zdc vs Hit contribution", 140, -1., 20., 100, 0., 1. );
00058       meZdcEML10EneP_ = dbe_->bookProfile("Hit19","Log10Energy in EM Zdc vs Hit contribution", 140, -1., 20., 100, 0., 1. );
00059       meZdcEHadCh_ = dbe_->book2D("Hit20","Zdc Had Section Energy vs Channel", 4000, 0., 8000., 6, 0., 6. );
00060       meZdcEEMCh_ = dbe_->book2D("Hit21","Zdc EM Section Energy vs Channel", 4000, 0., 8000., 6, 0., 6. );
00061       meZdcETime_ = dbe_->book2D("Hit22","Hits Zdc Energy vs Time", 4000, 0., 8000., 300, 0., 600. );
00062       meZdcEneEmN1_  = dbe_->book1D("HitVal01","Energy EM module N1",4000,0.,8000.);
00063       meZdcEneEmN2_  = dbe_->book1D("HitVal02","Energy EM module N2",4000,0.,8000.);
00064       meZdcEneEmN3_  = dbe_->book1D("HitVal03","Energy EM module N3",4000,0.,8000.);
00065       meZdcEneEmN4_  = dbe_->book1D("HitVal04","Energy EM module N4",4000,0.,8000.);
00066       meZdcEneEmN5_  = dbe_->book1D("HitVal05","Energy EM module N5",4000,0.,8000.);
00067       meZdcEneHadN1_ = dbe_->book1D("HitVal06","Energy HAD module N1",4000,0.,8000.);
00068       meZdcEneHadN2_ = dbe_->book1D("HitVal07","Energy HAD module N2",4000,0.,8000.);
00069       meZdcEneHadN3_ = dbe_->book1D("HitVal08","Energy HAD module N3",4000,0.,8000.);
00070       meZdcEneHadN4_ = dbe_->book1D("HitVal09","Energy HAD module N4",4000,0.,8000.);
00071       meZdcEneTEmN1_ = dbe_->book2D("HitVal11","Energy EM mod N1 vs Time", 4000, 0., 8000., 300, 0., 600. );
00072       meZdcEneTEmN2_ = dbe_->book2D("HitVal12","Energy EM mod N2 vs Time", 4000, 0., 8000., 300, 0., 600. ); 
00073       meZdcEneTEmN3_ = dbe_->book2D("HitVal13","Energy EM mod N3 vs Time", 4000, 0., 8000., 300, 0., 600. );
00074       meZdcEneTEmN4_ = dbe_->book2D("HitVal14","Energy EM mod N4 vs Time", 4000, 0., 8000., 300, 0., 600. );
00075       meZdcEneTEmN5_ = dbe_->book2D("HitVal15","Energy EM mod N5 vs Time", 4000, 0., 8000., 300, 0., 600. );
00076       meZdcEneTHadN1_ = dbe_->book2D("HitVal16","Energy HAD mod N1 vs Time", 4000, 0., 8000., 300, 0., 600. );
00077       meZdcEneTHadN2_ = dbe_->book2D("HitVal17","Energy HAD mod N2 vs Time", 4000, 0., 8000., 300, 0., 600. ); 
00078       meZdcEneTHadN3_ = dbe_->book2D("HitVal18","Energy HAD mod N3 vs Time", 4000, 0., 8000., 300, 0., 600. );
00079       meZdcEneTHadN4_ = dbe_->book2D("HitVal19","Energy HAD mod N4 vs Time", 4000, 0., 8000., 300, 0., 600. );
00080       meZdcEneHadNTot_ = dbe_->book1D("HitVal20","Total HAD Energy N",4000,0.,8000.);
00081       meZdcEneEmNTot_  = dbe_->book1D("HitVal21","Total EM Energy N",4000,0.,8000.);
00082       meZdcEneNTot_    = dbe_->book1D("HitVal22","Total Energy N",4000,0.,8000.);
00083       meZdcEneEmP1_  = dbe_->book1D("HitVal23","Energy EM module P1",4000,0.,8000.);
00084       meZdcEneEmP2_  = dbe_->book1D("HitVal24","Energy EM module P2",4000,0.,8000.);
00085       meZdcEneEmP3_  = dbe_->book1D("HitVal25","Energy EM module P3",4000,0.,8000.);
00086       meZdcEneEmP4_  = dbe_->book1D("HitVal26","Energy EM module P4",4000,0.,8000.);
00087       meZdcEneEmP5_  = dbe_->book1D("HitVal27","Energy EM module P5",4000,0.,8000.);
00088       meZdcEneHadP1_ = dbe_->book1D("HitVal29","Energy HAD module P1",4000,0.,8000.);
00089       meZdcEneHadP2_ = dbe_->book1D("HitVal29","Energy HAD module P2",4000,0.,8000.);
00090       meZdcEneHadP3_ = dbe_->book1D("HitVal30","Energy HAD module P3",4000,0.,8000.);
00091       meZdcEneHadP4_ = dbe_->book1D("HitVal31","Energy HAD module P4",4000,0.,8000.);
00092       meZdcEneTEmP1_ = dbe_->book2D("HitVal32","Energy EM mod P1 vs Time", 4000, 0., 8000., 300, 0., 600. );
00093       meZdcEneTEmP2_ = dbe_->book2D("HitVal33","Energy EM mod P2 vs Time", 4000, 0., 8000., 300, 0., 600. ); 
00094       meZdcEneTEmP3_ = dbe_->book2D("HitVal34","Energy EM mod P3 vs Time", 4000, 0., 8000., 300, 0., 600. );
00095       meZdcEneTEmP4_ = dbe_->book2D("HitVal35","Energy EM mod P4 vs Time", 4000, 0., 8000., 300, 0., 600. );
00096       meZdcEneTEmP5_ = dbe_->book2D("HitVal36","Energy EM mod P5 vs Time", 4000, 0., 8000., 300, 0., 600. );
00097       meZdcEneTHadP1_ = dbe_->book2D("HitVal37","Energy HAD mod P1 vs Time", 4000, 0., 8000., 300, 0., 600. );
00098       meZdcEneTHadP2_ = dbe_->book2D("HitVal38","Energy HAD mod P2 vs Time", 4000, 0., 8000., 300, 0., 600. ); 
00099       meZdcEneTHadP3_ = dbe_->book2D("HitVal39","Energy HAD mod P3 vs Time", 4000, 0., 8000., 300, 0., 600. );
00100       meZdcEneTHadP4_ = dbe_->book2D("HitVal40","Energy HAD mod P4 vs Time", 4000, 0., 8000., 300, 0., 600. );
00101       meZdcEneHadPTot_ = dbe_->book1D("HitVal41","Total HAD Energy P",4000,0.,8000.);
00102       meZdcEneEmPTot_  = dbe_->book1D("HitVal42","Total EM Energy P",4000,0.,8000.);
00103       meZdcEnePTot_    = dbe_->book1D("HitVal43","Total Energy P",4000,0.,8000.);
00104       meZdcCorEEmNEHadN_= dbe_->book2D("HitVal47","Energy EMN vs HADN", 4000, 0., 8000.,4000, 0., 8000.);
00105       meZdcCorEEmPEHadP_= dbe_->book2D("HitVal44","Energy EMP vs HADP", 4000, 0., 8000.,4000, 0., 8000.);
00106       meZdcCorEtotNEtotP_ = dbe_->book2D("HitVal45","Energy N vs P", 4000, 0., 8000.,4000, 0., 8000.);
00107       meZdcEneTot_ = dbe_->book1D("HitVal46","Total Energy ZDCs",4000,0.,8000.);
00108     }
00109   }
00110 }
00111 
00112 void ZdcSimHitStudy::endJob() {
00113   if (dbe_ && outFile_.size() > 0) dbe_->save(outFile_);
00114 }
00115 
00116 void ZdcSimHitStudy::analyze(const edm::Event& e, const edm::EventSetup& ) {
00117 
00118   LogDebug("ZdcSimHitStudy") 
00119     //std::cout
00120     << "Run = " << e.id().run() << " Event = " 
00121     << e.id().event();
00122   //std::cout<<std::endl;
00123   
00124   std::vector<PCaloHit>               caloHits;
00125   edm::Handle<edm::PCaloHitContainer> hitsZdc;
00126 
00127   bool getHits = false;
00128   if (checkHit_) {
00129     e.getByLabel(g4Label,zdcHits,hitsZdc); 
00130     if (hitsZdc.isValid()) getHits = true;
00131   }
00132 
00133   LogDebug("ZdcSim") << "ZdcValidation: Input flags Hits " << getHits;
00134 
00135   if (getHits) {
00136     caloHits.insert(caloHits.end(),hitsZdc->begin(),hitsZdc->end());
00137     LogDebug("ZdcSimHitStudy") 
00138       //std::cout
00139       << "ZdcValidation: Hit buffer " 
00140       << caloHits.size();
00141       //<< std::endl;
00142     analyzeHits (caloHits);
00143   }
00144 }
00145 
00146 void ZdcSimHitStudy::analyzeHits(std::vector<PCaloHit>& hits){
00147   int nHit = hits.size();
00148   int nZdcEM = 0, nZdcHad = 0, nZdcLum = 0; 
00149   int nBad1=0, nBad2=0, nBad=0;
00150   std::vector<double> encontZdcEM(140, 0.);
00151   std::vector<double> encontZdcHad(140, 0.);
00152   double entotZdcEM = 0;
00153   double entotZdcHad = 0;
00154  
00155   enetotEmN = 0;
00156   enetotHadN = 0.;
00157   enetotN = 0;  
00158   enetotEmP = 0;
00159   enetotHadP = 0;
00160   enetotP = 0;
00161   enetot = 0;
00162   
00163   for (int i=0; i<nHit; i++) {
00164     double energy    = hits[i].energy();
00165     double log10en   = log10(energy);
00166     int log10i       = int( (log10en+10.)*10. );
00167     double time      = hits[i].time();
00168     unsigned int id_ = hits[i].id();
00169     HcalZDCDetId id  = HcalZDCDetId(id_);
00170     int det          = id.det();
00171     int side         = id.zside();
00172     int section      = id.section();
00173     int channel      = id.channel();
00174 
00175     FillHitValHist(side,section,channel,energy,time);
00176   
00177     
00178     LogDebug("ZdcSimHitStudy") 
00179       //std::cout
00180       << "Hit[" << i << "] ID " << std::hex << id_ 
00181       << std::dec <<" DetID "<<id
00182       << " Det "<< det << " side "<< side 
00183       << " Section " << section
00184       << " channel "<< channel
00185       << " E " << energy 
00186       << " time \n" << time;
00187       //<<std::endl;
00188 
00189     if(det == 5) { // Check DetId.h
00190       if(section == HcalZDCDetId::EM)nZdcEM++;
00191       else if(section == HcalZDCDetId::HAD)nZdcHad++;
00192       else if(section == HcalZDCDetId::LUM)nZdcLum++;
00193       else    { nBad++;  nBad2++;}
00194     } else    { nBad++;  nBad1++;}
00195     if (dbe_) {
00196       meZdcDetectHit_->Fill(double(det));
00197       if (det ==  5) {
00198         meZdcSideHit_->Fill(double(side));
00199         meZdcSectionHit_->Fill(double(section));
00200         meZdcChannelHit_->Fill(double(channel));
00201         meZdcEnergyHit_->Fill(energy);
00202       if(section == HcalZDCDetId::EM){
00203         meZdcEMEnergyHit_->Fill(energy);
00204         meZdcEEMCh_->Fill(energy,channel);
00205         if( log10i >=0 && log10i < 140 )encontZdcEM[log10i] += energy;
00206         entotZdcEM += energy;
00207       }
00208       if(section == HcalZDCDetId::HAD){
00209         meZdcHadEnergyHit_->Fill(energy);
00210         meZdcEHadCh_->Fill(energy,channel);
00211         if( log10i >=0 && log10i < 140 )encontZdcHad[log10i] += energy;
00212         entotZdcHad += energy;
00213       } 
00214       meZdcTimeHit_->Fill(time);
00215       meZdcTimeWHit_->Fill(double(time),energy);
00216       meZdc10Ene_->Fill(log10en);
00217       meZdcETime_->Fill(energy, double(time));
00218       }
00219     }
00220   }
00221 
00222   if( entotZdcEM  != 0 ) for( int i=0; i<140; i++ ) meZdcEML10EneP_->Fill( -10.+(float(i)+0.5)/10., encontZdcEM[i]/entotZdcEM);
00223   if( entotZdcHad != 0 ) for( int i=0; i<140; i++ ) meZdcHadL10EneP_->Fill( -10.+(float(i)+0.5)/10.,encontZdcHad[i]/entotZdcHad);
00224   
00225   if (dbe_ && nHit>0) {
00226     meAllZdcNHit_->Fill(double(nHit));
00227     meBadZdcDetHit_->Fill(double(nBad1));
00228     meBadZdcSecHit_->Fill(double(nBad2));
00229     meBadZdcIdHit_->Fill(double(nBad));
00230     meZdcNHitEM_->Fill(double(nZdcEM));
00231     meZdcNHitHad_->Fill(double(nZdcHad));
00232     meZdcNHitLum_->Fill(double(nZdcLum)); 
00233     meZdcEnePTot_->Fill(enetotP);
00234     meZdcEneHadNTot_->Fill(enetotHadN);
00235     meZdcEneHadPTot_->Fill(enetotHadP);
00236     meZdcEneEmNTot_->Fill(enetotEmN);
00237     meZdcEneEmPTot_->Fill(enetotEmP);
00238     meZdcCorEEmNEHadN_->Fill(enetotEmN,enetotHadN);
00239     meZdcCorEEmPEHadP_->Fill(enetotEmP,enetotHadP);
00240     meZdcCorEtotNEtotP_->Fill(enetotN,enetotP);
00241     meZdcEneTot_->Fill(enetot);
00242   }
00243   LogDebug("HcalSimHitStudy") 
00244   //std::cout
00245     <<"HcalSimHitStudy::analyzeHits: Had " << nZdcHad 
00246     << " EM "<< nZdcEM
00247     << " Bad " << nBad << " All " << nHit;
00248     //<<std::endl;
00249 }
00250 
00251 int ZdcSimHitStudy::FillHitValHist(int side,int section,int channel,double energy,double time){  
00252   enetot += enetot;
00253   if(side == -1){
00254     enetotN += energy;
00255     if(section == HcalZDCDetId::EM){
00256       enetotEmN += energy;
00257       switch(channel){
00258       case 1 :
00259         meZdcEneEmN1_->Fill(energy);
00260         meZdcEneTEmN1_->Fill(energy,time);
00261         break;
00262       case 2 :
00263        meZdcEneEmN2_->Fill(energy);
00264        meZdcEneTEmN2_->Fill(energy,time);
00265         break;
00266       case 3 :
00267         meZdcEneEmN3_->Fill(energy);
00268        meZdcEneTEmN3_->Fill(energy,time);
00269         break;
00270       case 4 :
00271         meZdcEneEmN4_->Fill(energy);
00272         meZdcEneTEmN4_->Fill(energy,time);
00273         break; 
00274      case 5 :
00275         meZdcEneEmN4_->Fill(energy);
00276         meZdcEneTEmN4_->Fill(energy,time);
00277         break;
00278       }
00279     }
00280     if(section == HcalZDCDetId::HAD){
00281       enetotHadN += energy;
00282       switch(channel){
00283       case 1 :
00284         meZdcEneHadN1_->Fill(energy);
00285         meZdcEneTHadN1_->Fill(energy,time);
00286         break;
00287       case 2 :
00288         meZdcEneHadN2_->Fill(energy);
00289         meZdcEneTHadN2_->Fill(energy,time);
00290         break;
00291       case 3 :
00292         meZdcEneHadN3_->Fill(energy);
00293         meZdcEneTHadN3_->Fill(energy,time);
00294         break;
00295       case 4 :
00296         meZdcEneHadN4_->Fill(energy);
00297         meZdcEneTHadN4_->Fill(energy,time);
00298         break;
00299       }
00300     }
00301   }
00302   if(side == 1){
00303     enetotP += energy;
00304     if(section == HcalZDCDetId::EM){
00305       enetotEmP += energy;
00306       switch(channel){
00307       case 1 :
00308         meZdcEneEmP1_->Fill(energy);
00309         meZdcEneTEmP1_->Fill(energy,time);
00310         break;
00311       case 2 :
00312         meZdcEneEmP2_->Fill(energy);
00313         meZdcEneTEmP2_->Fill(energy,time);
00314         break;
00315       case 3 :
00316         meZdcEneEmP3_->Fill(energy);
00317         meZdcEneTEmP3_->Fill(energy,time);
00318         break;
00319       case 4 :
00320         meZdcEneEmP4_->Fill(energy);
00321         meZdcEneTEmP4_->Fill(energy,time);
00322         break; 
00323       case 5 :
00324         meZdcEneEmP4_->Fill(energy);
00325         meZdcEneTEmP4_->Fill(energy,time);
00326         break;
00327       }
00328     }
00329     if(section == HcalZDCDetId::HAD){
00330       enetotHadP += energy;
00331       switch(channel){
00332       case 1 :
00333         meZdcEneHadP1_->Fill(energy);
00334         meZdcEneTHadP1_->Fill(energy,time);
00335         break;
00336       case 2 :
00337         meZdcEneHadP2_->Fill(energy);
00338         meZdcEneTHadP2_->Fill(energy,time);
00339         break;
00340       case 3 :
00341         meZdcEneHadP3_->Fill(energy);
00342         meZdcEneTHadP3_->Fill(energy,time);
00343         break;
00344       case 4 :
00345         meZdcEneHadP4_->Fill(energy);
00346         meZdcEneTHadP4_->Fill(energy,time);
00347         break;
00348       }
00349     }
00350   }       
00351   return 0;
00352 }
00353   
00354  
00355 
00356 
00357 
00358 
00359 
00360 
00361 
00362 
00363 
00364 
00365 
00366 
00367 
00368