CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Validation/HcalDigis/src/HcalDigiTester.cc

Go to the documentation of this file.
00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 
00005 #include "Validation/HcalDigis/interface/HcalDigiTester.h"
00006 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00007 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00008 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
00009 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00010 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00011 #include "DataFormats/HcalDigi/interface/HcalQIESample.h"
00012 
00013 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00014 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00015 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00016 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00017 
00018 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00019 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
00020 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
00021 
00022 #include "DQMServices/Core/interface/DQMStore.h"
00023 
00024 #include "DataFormats/HcalDigi/interface/HBHEDataFrame.h"
00025 #include "DataFormats/HcalDigi/interface/HFDataFrame.h"
00026 #include "DataFormats/HcalDigi/interface/HODataFrame.h"
00027 #include <vector>
00028 #include <utility>
00029 #include <ostream>
00030 #include <string>
00031 #include <algorithm>
00032 #include <cmath>
00033 
00034 #include "CondFormats/HcalObjects/interface/HcalGain.h"
00035 #include "CondFormats/HcalObjects/interface/HcalGainWidth.h"
00036 #include "CondFormats/HcalObjects/interface/HcalPedestal.h"
00037 #include "CondFormats/HcalObjects/interface/HcalPedestalWidth.h"
00038 
00039 template<class Digi>
00040 
00041 void HcalDigiTester::reco(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00042   
00043   
00044   typename   edm::Handle<edm::SortedCollection<Digi> > digiCollection;
00045   typename edm::SortedCollection<Digi>::const_iterator digiItr;
00046      
00047   // ADC2fC 
00048   const HcalQIEShape* shape = conditions->getHcalShape();
00049   HcalCalibrations calibrations;
00050   CaloSamples tool;
00051 
00052 
00053   iEvent.getByLabel (inputTag_, digiCollection);
00054 
00055   int subdet = 0;
00056   if (hcalselector_ == "HB"  ) subdet = 1;
00057   if (hcalselector_ == "HE"  ) subdet = 2;
00058   if (hcalselector_ == "HO"  ) subdet = 3;
00059   if (hcalselector_ == "HF"  ) subdet = 4; 
00060 
00061   if(subdet == 1) nevent1++;
00062   if(subdet == 2) nevent2++;
00063   if(subdet == 3) nevent3++;
00064   if(subdet == 4) nevent4++;
00065   
00066   int zsign = 0;
00067   if (zside_ == "+")  zsign =  1;
00068   if (zside_ == "-")  zsign = -1;
00069 
00070   int ndigis = 0;
00071   //  amplitude for signal cell at diff. depths
00072   double ampl1_c    = 0.;
00073   double ampl2_c    = 0.;
00074   double ampl3_c    = 0.;
00075   double ampl4_c    = 0.;
00076   double ampl_c     = 0.;
00077 
00078   // is set to 1 if "seed" SimHit is found 
00079   int seedSimHit  = 0;
00080  
00081   //  std::cout << " HcalDigiTester::reco :  "
00082   //        << "subdet=" << subdet << "  noise="<< noise_ << std::endl;
00083  
00084   int ieta_Sim    =  9999;
00085   int iphi_Sim    =  9999;
00086   double emax_Sim = -9999.;
00087 
00088     
00089   // SimHits MC only
00090   if( mc_ == "yes") {
00091     edm::Handle<edm::PCaloHitContainer> hcalHits ;
00092     iEvent.getByLabel("g4SimHits","HcalHits",hcalHits); 
00093     const edm::PCaloHitContainer * simhitResult = hcalHits.product () ;
00094     
00095     
00096     if ( subdet != 0 && noise_ == 0) { // signal only SimHits
00097       
00098       for (std::vector<PCaloHit>::const_iterator simhits = simhitResult->begin ();         simhits != simhitResult->end () ;  ++simhits) {
00099         
00100         HcalDetId cell(simhits->id());
00101         double en    = simhits->energy();
00102         int sub      = cell.subdet();
00103         int ieta     = cell.ieta();
00104         if(ieta > 0) ieta--;
00105         int iphi     = cell.iphi()-1; 
00106         
00107         
00108         if(en > emax_Sim && sub == subdet) {
00109           emax_Sim = en;
00110           ieta_Sim = ieta;
00111           iphi_Sim = iphi;            
00112           // to limit "seed" SimHit energy in case of "multi" event  
00113           if (mode_ == "multi" && 
00114            ((sub == 4 && en < 100. && en > 1.) 
00115             || ((sub !=4) && en < 1. && en > 0.02))) 
00116             {
00117               seedSimHit = 1;            
00118               break;   
00119             }
00120         }
00121         
00122       } // end of SimHits cycle
00123       
00124       
00125       // found highest-energy SimHit for single-particle 
00126       if(mode_ != "multi" && emax_Sim > 0.) seedSimHit = 1;
00127     }   // end of SimHits
00128     
00129   } // end of mc_ == "yes"
00130 
00131   // CYCLE OVER CELLS ========================================================
00132   int Ndig = 0;
00133 
00134   /*
00135   std::cout << " HcalDigiTester::reco :     nevent 1,2,3,4 = "
00136             << nevent1 << " " << nevent2 << " " << nevent3 << " " 
00137             << nevent4 << std::endl;
00138   */
00139 
00140   for (digiItr=digiCollection->begin();digiItr!=digiCollection->end();digiItr++) {
00141     
00142     HcalDetId cell(digiItr->id()); 
00143     int depth = cell.depth();
00144     int iphi  = cell.iphi()-1;
00145     int ieta  = cell.ieta();
00146     if(ieta > 0) ieta--;
00147     int sub   = cell.subdet();
00148 
00149 
00150   //  amplitude for signal cell at diff. depths
00151     double ampl     = 0.;
00152     double ampl1    = 0.;
00153     double ampl2    = 0.;
00154     double ampl3    = 0.;
00155     double ampl4    = 0.;
00156     
00157     // Gains, pedestals (once !) and only for "noise" case  
00158     if ( ((nevent1 == 1 && subdet == 1) || 
00159           (nevent2 == 1 && subdet == 2) ||
00160           (nevent3 == 1 && subdet == 3) ||
00161           (nevent4 == 1 && subdet == 4)) && noise_ == 1 && sub == subdet) { 
00162 
00163       HcalGenericDetId hcalGenDetId(digiItr->id());
00164       const HcalPedestal* pedestal = conditions->getPedestal(hcalGenDetId);
00165       const HcalGain*  gain = conditions->getGain(hcalGenDetId); 
00166       const HcalGainWidth* gainWidth = 
00167         conditions->getGainWidth(hcalGenDetId); 
00168       const HcalPedestalWidth* pedWidth =
00169         conditions-> getPedestalWidth(hcalGenDetId);  
00170       
00171       double gainValue0 = gain->getValue(0);
00172       double gainValue1 = gain->getValue(1);
00173       double gainValue2 = gain->getValue(2);
00174       double gainValue3 = gain->getValue(3);
00175 
00176       double gainWidthValue0 = gainWidth->getValue(0);
00177       double gainWidthValue1 = gainWidth->getValue(1);
00178       double gainWidthValue2 = gainWidth->getValue(2);
00179       double gainWidthValue3 = gainWidth->getValue(3);
00180       
00181 
00182 
00183       // some printout
00184       /*
00185       std::cout <<  " subdet = " << sub << "  ieta, iphi, depth : " 
00186                 << ieta << " " << iphi << " " << depth 
00187                 << "  gain0 " << gainValue0 << "  gainWidth0 " 
00188                 << gainWidthValue0
00189                 << std::endl;
00190       */
00191       
00192       double pedValue0 = pedestal->getValue(0);
00193       double pedValue1 = pedestal->getValue(1);
00194       double pedValue2 = pedestal->getValue(2);
00195       double pedValue3 = pedestal->getValue(3);
00196       
00197       double pedWidth0 = pedWidth->getWidth(0);
00198       double pedWidth1 = pedWidth->getWidth(1);
00199       double pedWidth2 = pedWidth->getWidth(2);
00200       double pedWidth3 = pedWidth->getWidth(3);
00201       
00202       if (depth == 1) {
00203 
00204         //        std::cout <<  "          depth = " << depth << std::endl;
00205     
00206         monitor()->fillmeGain0Depth1(gainValue0);
00207         monitor()->fillmeGain1Depth1(gainValue1);
00208         monitor()->fillmeGain2Depth1(gainValue2);
00209         monitor()->fillmeGain3Depth1(gainValue3);
00210 
00211         monitor()->fillmeGainWidth0Depth1(gainWidthValue0);
00212         monitor()->fillmeGainWidth1Depth1(gainWidthValue1);
00213         monitor()->fillmeGainWidth2Depth1(gainWidthValue2);
00214         monitor()->fillmeGainWidth3Depth1(gainWidthValue3);
00215 
00216         monitor()->fillmePed0Depth1(pedValue0);
00217         monitor()->fillmePed1Depth1(pedValue1);
00218         monitor()->fillmePed2Depth1(pedValue2);
00219         monitor()->fillmePed3Depth1(pedValue3);
00220 
00221         monitor()->fillmePedWidth0Depth1(pedWidth0);
00222         monitor()->fillmePedWidth1Depth1(pedWidth1);
00223         monitor()->fillmePedWidth2Depth1(pedWidth2);
00224         monitor()->fillmePedWidth3Depth1(pedWidth3);
00225 
00226         monitor()->fillmeGainMap1  (double(ieta), double(iphi), gainValue0);
00227         monitor()->fillmePwidthMap1(double(ieta), double(iphi), pedWidth0) ;  
00228       }
00229 
00230       if (depth == 2) {
00231 
00232         //        std::cout <<  "          depth = " << depth << std::endl;
00233 
00234         monitor()->fillmeGain0Depth2(gainValue0);
00235         monitor()->fillmeGain1Depth2(gainValue1);
00236         monitor()->fillmeGain2Depth2(gainValue2);
00237         monitor()->fillmeGain3Depth2(gainValue3);
00238 
00239         monitor()->fillmeGainWidth0Depth2(gainWidthValue0);
00240         monitor()->fillmeGainWidth1Depth2(gainWidthValue1);
00241         monitor()->fillmeGainWidth2Depth2(gainWidthValue2);
00242         monitor()->fillmeGainWidth3Depth2(gainWidthValue3);
00243 
00244         monitor()->fillmePed0Depth2(pedValue0);
00245         monitor()->fillmePed1Depth2(pedValue1);
00246         monitor()->fillmePed2Depth2(pedValue2);
00247         monitor()->fillmePed3Depth2(pedValue3);
00248 
00249         monitor()->fillmePedWidth0Depth2(pedWidth0);
00250         monitor()->fillmePedWidth1Depth2(pedWidth1);
00251         monitor()->fillmePedWidth2Depth2(pedWidth2);
00252         monitor()->fillmePedWidth3Depth2(pedWidth3);
00253 
00254         monitor()->fillmeGainMap2  (double(ieta), double(iphi), gainValue0);
00255         monitor()->fillmePwidthMap2(double(ieta), double(iphi), pedWidth0) ;  
00256       }
00257 
00258       if (depth == 3) {
00259 
00260         //        std::cout <<  "          depth = " << depth << std::endl;
00261 
00262         monitor()->fillmeGain0Depth3(gainValue0);
00263         monitor()->fillmeGain1Depth3(gainValue1);
00264         monitor()->fillmeGain2Depth3(gainValue2);
00265         monitor()->fillmeGain3Depth3(gainValue3);
00266 
00267         monitor()->fillmeGainWidth0Depth3(gainWidthValue0);
00268         monitor()->fillmeGainWidth1Depth3(gainWidthValue1);
00269         monitor()->fillmeGainWidth2Depth3(gainWidthValue2);
00270         monitor()->fillmeGainWidth3Depth3(gainWidthValue3);
00271 
00272         monitor()->fillmePed0Depth3(pedValue0);
00273         monitor()->fillmePed1Depth3(pedValue1);
00274         monitor()->fillmePed2Depth3(pedValue2);
00275         monitor()->fillmePed3Depth3(pedValue3);
00276 
00277         monitor()->fillmePedWidth0Depth3(pedWidth0);
00278         monitor()->fillmePedWidth1Depth3(pedWidth1);
00279         monitor()->fillmePedWidth2Depth3(pedWidth2);
00280         monitor()->fillmePedWidth3Depth3(pedWidth3);
00281 
00282         monitor()->fillmeGainMap3  (double(ieta), double(iphi), gainValue0);
00283         monitor()->fillmePwidthMap3(double(ieta), double(iphi), pedWidth0) ;  
00284       }
00285 
00286       if (depth == 4) {
00287 
00288         //        std::cout <<  "          depth = " << depth << std::endl;
00289 
00290         monitor()->fillmeGain0Depth4(gainValue0);
00291         monitor()->fillmeGain1Depth4(gainValue1);
00292         monitor()->fillmeGain2Depth4(gainValue2);
00293         monitor()->fillmeGain3Depth4(gainValue3);
00294 
00295         monitor()->fillmeGainWidth0Depth4(gainWidthValue0);
00296         monitor()->fillmeGainWidth1Depth4(gainWidthValue1);
00297         monitor()->fillmeGainWidth2Depth4(gainWidthValue2);
00298         monitor()->fillmeGainWidth3Depth4(gainWidthValue3);
00299 
00300         monitor()->fillmePed0Depth4(pedValue0);
00301         monitor()->fillmePed1Depth4(pedValue1);
00302         monitor()->fillmePed2Depth4(pedValue2);
00303         monitor()->fillmePed3Depth4(pedValue3);
00304 
00305         monitor()->fillmePedWidth0Depth4(pedWidth0);
00306         monitor()->fillmePedWidth1Depth4(pedWidth1);
00307         monitor()->fillmePedWidth2Depth4(pedWidth2);
00308         monitor()->fillmePedWidth3Depth4(pedWidth3);
00309 
00310         monitor()->fillmeGainMap4  (double(ieta), double(iphi), gainValue0);
00311         monitor()->fillmePwidthMap4(double(ieta), double(iphi), pedWidth0) ;  
00312 
00313       }
00314 
00315     }     // end of event #1 
00316     //std::cout << "==== End of event noise block in cell cycle"  << std::endl;
00317 
00318 
00319 
00320     if ( sub == subdet)  Ndig++;  // subdet number of digi
00321     
00322 // No-noise case, only single  subdet selected  ===========================
00323 
00324     if ( sub == subdet && noise_ == 0 ) {   
00325 
00326       
00327       HcalCalibrations calibrations = conditions->getHcalCalibrations(cell);
00328 
00329       const HcalQIECoder* channelCoder = conditions->getHcalCoder(cell);
00330       HcalCoderDb coder (*channelCoder, *shape);
00331       coder.adc2fC(*digiItr,tool);
00332       
00333       double noiseADC =  (*digiItr)[0].adc();     
00334       double noisefC  =  tool[0];     
00335       
00336       // noise evaluations from "pre-samples"
00337       if(depth == 1) { 
00338         monitor()->fillmeADC0_depth1  (noiseADC);
00339         monitor()->fillmeADC0fC_depth1(noisefC);
00340       }
00341       if(depth == 2) { 
00342         monitor()->fillmeADC0_depth2  (noiseADC);
00343         monitor()->fillmeADC0fC_depth2(noisefC);
00344       }
00345       if(depth == 3) { 
00346         monitor()->fillmeADC0_depth3  (noiseADC);
00347         monitor()->fillmeADC0fC_depth3(noisefC);
00348       }
00349       if(depth == 4) { 
00350         monitor()->fillmeADC0_depth4  (noiseADC);
00351         monitor()->fillmeADC0fC_depth4(noisefC);
00352       }
00353 
00354       // OCCUPANCY maps filling
00355       double deta = double(ieta);
00356       double dphi = double(iphi);
00357       if(depth == 1)
00358       monitor()->fillmeOccupancy_map_depth1(deta, dphi); 
00359       if(depth == 2)
00360       monitor()->fillmeOccupancy_map_depth2(deta, dphi); 
00361       if(depth == 3)
00362       monitor()->fillmeOccupancy_map_depth3(deta, dphi); 
00363       if(depth == 4)
00364       monitor()->fillmeOccupancy_map_depth4(deta, dphi); 
00365       
00366       // Cycle on time slices
00367       // - for each Digi 
00368       // - for one Digi with max SimHits E in subdet
00369       
00370       int closen = 0;   // =1 if 1) seedSimHit = 1 and 2) the cell is the same
00371       if(ieta == ieta_Sim && iphi == iphi_Sim ) closen = seedSimHit;
00372 
00373       for  (int ii=0;ii<tool.size();ii++) {
00374         int capid  = (*digiItr)[ii].capid();
00375         // single ts amplitude
00376         double val = (tool[ii]-calibrations.pedestal(capid));
00377 
00378         if (val > 10.)  monitor()->fillmeAll10slices(double(ii), val);
00379         if (val > 100.) monitor()->fillmeAll10slices1D(double(ii), val);
00380         
00381         if( closen == 1 &&( ieta * zsign >= 0 )) { 
00382           monitor()->fillmeSignalTimeSlice(double(ii), val);
00383         }
00384 
00385 
00386         // HB/HE/HO
00387         if (subdet != 4 && ii>=4 && ii<=7) { 
00388           ampl += val;    
00389           if(depth == 1) ampl1 += val;   
00390           if(depth == 2) ampl2 += val;   
00391           if(depth == 3) ampl3 += val;   
00392           if(depth == 4) ampl4 += val;
00393           
00394           if( closen == 1 && ( ieta * zsign >= 0 )) { 
00395             ampl_c += val;        
00396             if(depth == 1) ampl1_c += val;   
00397             if(depth == 2) ampl2_c += val;   
00398             if(depth == 3) ampl3_c += val;   
00399             if(depth == 4) ampl4_c += val;
00400             
00401           }
00402         }
00403         
00404         // HF
00405         if (subdet == 4 && ii==3 )      {
00406           ampl += val;      
00407           if(depth == 1)  ampl1 += val;
00408           if(depth == 2)  ampl2 += val;
00409           if(depth == 3)  ampl3 += val;
00410           if(depth == 4)  ampl4 += val;
00411           if( closen == 1 && ( ieta * zsign >= 0 )) {       
00412             ampl_c += val;          
00413             if(depth == 1)  ampl1_c += val;
00414             if(depth == 2)  ampl2_c += val;
00415             if(depth == 3)  ampl3_c += val;
00416             if(depth == 4)  ampl4_c += val;
00417 
00418           }
00419         }
00420       }
00421       // end of time bucket sample      
00422       
00423       monitor()->fillmeAmplIetaIphi1(double(ieta),double(iphi), ampl1);
00424       monitor()->fillmeAmplIetaIphi2(double(ieta),double(iphi), ampl2);
00425       monitor()->fillmeAmplIetaIphi3(double(ieta),double(iphi), ampl3);
00426       monitor()->fillmeAmplIetaIphi4(double(ieta),double(iphi), ampl4);
00427       monitor()->fillmeSumAmp (ampl);
00428       
00429       
00430       if(ampl1 > 10. || ampl2 > 10.  || ampl3 > 10.  || ampl4 > 10. ) ndigis++;
00431       
00432       // fraction 5,6 bins if ampl. is big.
00433       if(ampl1 > 30. &&  depth == 1 && closen == 1 ) { 
00434           double fBin5  = tool[4] - calibrations.pedestal((*digiItr)[4].capid());
00435         double fBin67 = tool[5] + tool[6] 
00436           - calibrations.pedestal((*digiItr)[5].capid())
00437           - calibrations.pedestal((*digiItr)[6].capid());
00438         fBin5  /= ampl1;
00439         fBin67 /= ampl1;
00440         monitor()->fillmeBin5Frac (fBin5);
00441         monitor()->fillmeBin67Frac(fBin67);
00442       }
00443 
00444       monitor()->fillmeSignalAmp (ampl); 
00445       monitor()->fillmeSignalAmp1(ampl1); 
00446       monitor()->fillmeSignalAmp2(ampl2); 
00447       monitor()->fillmeSignalAmp3(ampl3); 
00448       monitor()->fillmeSignalAmp4(ampl4); 
00449     
00450       
00451     }   
00452   }    // End of CYCLE OVER CELLS =============================================
00453   
00454   
00455   if ( subdet != 0 && noise_ == 0) { // signal only, once per event 
00456 
00457     monitor()->fillmenDigis(ndigis);
00458     
00459     // SimHits once again !!!
00460     double eps    = 1.e-3;
00461     double ehits  = 0.; 
00462     double ehits1 = 0.; 
00463     double ehits2 = 0.; 
00464     double ehits3 = 0.; 
00465     double ehits4 = 0.; 
00466  
00467     if(mc_ == "yes") {
00468       edm::Handle<edm::PCaloHitContainer> hcalHits ;
00469       iEvent.getByLabel("g4SimHits","HcalHits",hcalHits); 
00470       const edm::PCaloHitContainer * simhitResult = hcalHits.product () ;
00471       for (std::vector<PCaloHit>::const_iterator simhits = simhitResult->begin ();         simhits != simhitResult->end () ;  ++simhits) {
00472         
00473         HcalDetId cell(simhits->id());
00474         int ieta   = cell.ieta();
00475         if(ieta > 0) ieta--;
00476         int iphi   = cell.iphi()-1; 
00477         int sub    = cell.subdet();
00478         
00479         // take cell already found to be max energy in a particular subdet
00480         if (sub == subdet && ieta == ieta_Sim && iphi == iphi_Sim){  
00481           int depth = cell.depth();
00482           double en = simhits->energy();
00483           
00484           ehits += en;
00485           if(depth == 1)  ehits1 += en; 
00486           if(depth == 2)  ehits2 += en; 
00487           if(depth == 3)  ehits3 += en; 
00488           if(depth == 4)  ehits4 += en; 
00489         }
00490       }
00491       
00492       if(ehits  > eps) monitor()->fillmeDigiSimhit (ehits,  ampl_c );
00493       if(ehits1 > eps) monitor()->fillmeDigiSimhit1(ehits1, ampl1_c);
00494       if(ehits2 > eps) monitor()->fillmeDigiSimhit2(ehits2, ampl2_c);
00495       if(ehits3 > eps) monitor()->fillmeDigiSimhit3(ehits3, ampl3_c);
00496       if(ehits4 > eps) monitor()->fillmeDigiSimhit4(ehits4, ampl4_c);
00497       
00498       if(ehits  > eps) monitor()->fillmeDigiSimhitProfile (ehits,  ampl_c );
00499       if(ehits1 > eps) monitor()->fillmeDigiSimhitProfile1(ehits1, ampl1_c);
00500       if(ehits2 > eps) monitor()->fillmeDigiSimhitProfile2(ehits2, ampl2_c);
00501       if(ehits3 > eps) monitor()->fillmeDigiSimhitProfile3(ehits3, ampl3_c);
00502       if(ehits4 > eps) monitor()->fillmeDigiSimhitProfile4(ehits4, ampl4_c);
00503       
00504       if(ehits  > eps) monitor()->fillmeRatioDigiSimhit (ampl_c  / ehits);
00505       if(ehits1 > eps) monitor()->fillmeRatioDigiSimhit1(ampl1_c / ehits1);
00506       if(ehits2 > eps) monitor()->fillmeRatioDigiSimhit2(ampl2_c / ehits2);
00507       if(ehits3 > eps) monitor()->fillmeRatioDigiSimhit3(ampl3_c / ehits3);
00508       if(ehits4 > eps) monitor()->fillmeRatioDigiSimhit4(ampl4_c / ehits4);
00509     } // end of if(mc_ == "yes")
00510    
00511     monitor()->fillmeNdigis(double(Ndig));
00512     
00513   } //  end of if( subdet != 0 && noise_ == 0) { // signal only 
00514 
00515 }
00516 
00517 
00518 HcalDigiTester::HcalDigiTester(const edm::ParameterSet& iConfig)
00519   : dbe_(edm::Service<DQMStore>().operator->()),
00520     inputTag_(iConfig.getParameter<edm::InputTag>("digiLabel")),
00521     outputFile_(iConfig.getUntrackedParameter<std::string>("outputFile", "")),
00522     hcalselector_(iConfig.getUntrackedParameter<std::string>("hcalselector", "all")),
00523     zside_(iConfig.getUntrackedParameter<std::string>("zside", "*")),
00524     mode_(iConfig.getUntrackedParameter<std::string>("mode", "multi")),
00525     mc_(iConfig.getUntrackedParameter<std::string>("mc", "no")),
00526     monitors_()
00527 {
00528   if ( outputFile_.size() != 0 ) {
00529     edm::LogInfo("OutputInfo") << " Hcal Digi Task histograms will be saved to '" << outputFile_.c_str() << "'";
00530   } else {
00531     edm::LogInfo("OutputInfo") << " Hcal Digi Task histograms will NOT be saved";
00532   }
00533 
00534 
00535 }
00536    
00537 
00538 HcalDigiTester::~HcalDigiTester() { }
00539 
00540 
00541 void HcalDigiTester::endRun() {
00542 
00543  if(noise_ != 1) {
00544 
00545    if( hcalselector_ == "all") {
00546     hcalselector_ = "HB";
00547     eval_occupancy();
00548     hcalselector_ = "HE";
00549     eval_occupancy();
00550     hcalselector_ = "HO";
00551     eval_occupancy();
00552     hcalselector_ = "HF";
00553     eval_occupancy();
00554    }
00555    else  // one of subsystem only
00556     eval_occupancy();
00557  }
00558 
00559 }
00560 
00561 
00562 
00563 void HcalDigiTester::endJob() {
00564 
00565   if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00566 
00567 }
00568 
00569 
00570   //occupancies evaluation
00571 void HcalDigiTester::eval_occupancy() {    
00572   
00573   int nx = 82;
00574   int ny = 72;
00575   float cnorm;
00576   float fev = float (nevtot);
00577   //    std::cout << "*** nevtot " <<  nevtot << std::endl; 
00578   
00579   float sumphi_1, sumphi_2, sumphi_3, sumphi_4;
00580   float phi_factor;  
00581   
00582   for (int i = 1; i <= nx; i++) {
00583     sumphi_1 = 0.;
00584     sumphi_2 = 0.;
00585     sumphi_3 = 0.;
00586     sumphi_4 = 0.;
00587     
00588     for (int j = 1; j <= ny; j++) {
00589       
00590       // occupancies
00591       cnorm = monitor()->getBinContent_depth1(i,j) / fev;   
00592       monitor()->setBinContent_depth1(i,j,cnorm);
00593       cnorm = monitor()->getBinContent_depth2(i,j) / fev;   
00594       monitor()->setBinContent_depth2(i,j,cnorm);
00595       cnorm = monitor()->getBinContent_depth3(i,j) / fev;   
00596       monitor()->setBinContent_depth3(i,j,cnorm);
00597       cnorm = monitor()->getBinContent_depth4(i,j) / fev;   
00598       monitor()->setBinContent_depth4(i,j,cnorm);
00599 
00600       sumphi_1 += monitor()->getBinContent_depth1(i,j);
00601       sumphi_2 += monitor()->getBinContent_depth2(i,j);
00602       sumphi_3 += monitor()->getBinContent_depth3(i,j);
00603       sumphi_4 += monitor()->getBinContent_depth4(i,j);
00604 
00605     }
00606     
00607     int ieta = i - 42;        // -41 -1, 0 40 
00608     if(ieta >=0 ) ieta +=1;   // -41 -1, 1 41  - to make it detector-like
00609     
00610     if(ieta >= -20 && ieta <= 20 )
00611       {phi_factor = 72.;}
00612     else {
00613       if(ieta >= 40 || ieta <= -40 ) {phi_factor = 18.;}
00614       else 
00615         phi_factor = 36.;
00616     }  
00617 
00618 
00619     if(ieta >= 0) ieta -= 1; // -41 -1, 0 40  - to bring back to histo num !!!
00620     double deta =  double(ieta);
00621 
00622     cnorm = sumphi_1 / phi_factor;
00623     monitor() -> fillmeOccupancy_vs_ieta_depth1(deta, cnorm);      
00624     cnorm = sumphi_2 / phi_factor;
00625     monitor() -> fillmeOccupancy_vs_ieta_depth2(deta, cnorm);
00626     cnorm = sumphi_3 / phi_factor;
00627     monitor() -> fillmeOccupancy_vs_ieta_depth3(deta, cnorm);
00628     cnorm = sumphi_4 / phi_factor;
00629     monitor() -> fillmeOccupancy_vs_ieta_depth4(deta, cnorm);
00630       
00631       
00632   }  // end of i-loop
00633   
00634 }
00635 
00636 void HcalDigiTester::beginJob() {
00637 
00638   nevent1 = 0;
00639   nevent2 = 0;
00640   nevent3 = 0;
00641   nevent4 = 0;
00642 
00643   nevtot  = 0;
00644 
00645 }
00646 
00647 
00648 HcalSubdetDigiMonitor * HcalDigiTester::monitor()
00649 {
00650   std::map<std::string, HcalSubdetDigiMonitor*>::iterator monitorItr
00651     = monitors_.find(hcalselector_);
00652 
00653   if(monitorItr == monitors_.end())
00654     {
00655       HcalSubdetDigiMonitor* m = new HcalSubdetDigiMonitor(dbe_, hcalselector_, noise_);
00656       std::pair<std::string, HcalSubdetDigiMonitor*> mapElement(
00657                                                                 hcalselector_, m);
00658       monitorItr = monitors_.insert(mapElement).first;
00659     }
00660   return monitorItr->second;
00661 }
00662 
00663 void 
00664 HcalDigiTester::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00665 {
00666 
00667 
00668   iSetup.get<CaloGeometryRecord>().get (geometry);
00669   iSetup.get<HcalDbRecord>().get(conditions);
00670 
00671 
00672   //  std::cout << " >>>>> HcalDigiTester::analyze  hcalselector = " 
00673   //        << hcalselector_ << std::endl;
00674 
00675   if( hcalselector_ != "all") {
00676     noise_ = 0;
00677     
00678     
00679 
00680     if (hcalselector_ == "HB" ) reco<HBHEDataFrame>(iEvent,iSetup);
00681     if (hcalselector_ == "HE" ) reco<HBHEDataFrame>(iEvent,iSetup);
00682     if (hcalselector_ == "HO" ) reco<HODataFrame>(iEvent,iSetup);
00683     if (hcalselector_ == "HF" ) reco<HFDataFrame>(iEvent,iSetup);  
00684 
00685     if (hcalselector_ == "noise") {
00686       noise_ = 1;
00687 
00688       //      std::cout << " >>>>> HcalDigiTester::analyze  entering noise " 
00689       //            << std::endl;
00690 
00691       
00692       hcalselector_ = "HB";
00693       reco<HBHEDataFrame>(iEvent,iSetup);
00694       hcalselector_ = "HE";
00695       reco<HBHEDataFrame>(iEvent,iSetup);
00696       hcalselector_ = "HO";
00697       reco<HODataFrame>(iEvent,iSetup);
00698       hcalselector_ = "HF";
00699       reco<HFDataFrame>(iEvent,iSetup);
00700       hcalselector_ = "noise";
00701     }
00702   }    
00703     // all subdetectors
00704   else {
00705     noise_ = 0;
00706     
00707     hcalselector_ = "HB";
00708     reco<HBHEDataFrame>(iEvent,iSetup);
00709     hcalselector_ = "HE";
00710     reco<HBHEDataFrame>(iEvent,iSetup);
00711     hcalselector_ = "HO";
00712     reco<HODataFrame>(iEvent,iSetup);
00713     hcalselector_ = "HF";
00714     reco<HFDataFrame>(iEvent,iSetup);
00715     hcalselector_ = "all";    
00716   }
00717 
00718   nevtot++;
00719 
00720 }
00721 
00722 double HcalDigiTester::dR(double eta1, double phi1, double eta2, double phi2) { 
00723   double PI = 3.1415926535898;
00724   double deltaphi= phi1 - phi2;
00725   if( phi2 > phi1 ) { deltaphi= phi2 - phi1;}
00726   if(deltaphi > PI) { deltaphi = 2.*PI - deltaphi;}
00727   double deltaeta = eta2 - eta1;
00728   double tmp = sqrt(deltaeta* deltaeta + deltaphi*deltaphi);
00729   return tmp;
00730 }
00731 
00732 
00733 DEFINE_FWK_MODULE (HcalDigiTester) ;