CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CalibCalorimetry/HcalStandardModules/src/HFPreLightCal.cc

Go to the documentation of this file.
00001 // Pre-Analysis for HFLightCal:
00002 // finding time position of signal in TS
00003 //
00004 #include <memory>
00005 #include <string>
00006 #include <iostream>
00007 
00008 #include "TH1F.h"
00009 #include "TH2F.h"
00010 #include "TFile.h"
00011 #include "math.h"
00012 #include "TMath.h"
00013 #include "TF1.h"
00014 
00015 #include "CalibCalorimetry/HcalStandardModules/interface/HFPreLightCal.h"
00016 
00017 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00018 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00019 
00020 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00021 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00022 #include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
00023 #include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
00024 
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include "FWCore/Framework/interface/EventSetup.h"
00028 #include "FWCore/Framework/interface/ESHandle.h"
00029 
00030 using namespace std;
00031 Int_t run_NN=0, event_NN=0;
00032 
00033 namespace {
00034   //bool verbose = true;
00035   bool verbose = false;
00036 }
00037 
00038 HFPreLightCal::HFPreLightCal (const edm::ParameterSet& fConfiguration) :
00039   hfDigiCollectionTag_(fConfiguration.getParameter<edm::InputTag>("hfDigiCollectionTag")),
00040   hcalCalibDigiCollectionTag_(fConfiguration.getParameter<edm::InputTag>("hcalCalibDigiCollectionTag")) {
00041 
00042   //std::string histfile = fConfiguration.getUntrackedParameter<string>("rootFile");
00043   histfile = fConfiguration.getUntrackedParameter<string>("rootPreFile");
00044   textfile = fConfiguration.getUntrackedParameter<string>("textPreFile");
00045 }
00046 
00047 HFPreLightCal::~HFPreLightCal () {
00048   //delete mFile;
00049 }
00050 
00051 void HFPreLightCal::beginJob() {
00052 
00053   char htit[64];
00054   std::cout<<std::endl<<"HFPreLightCal beginJob: --> ";
00055 
00056   mFile = new TFile (histfile.c_str(),"RECREATE");
00057   if ((tFile = fopen(textfile.c_str(),"w"))==NULL) {
00058     printf("\nNo textfile open\n\n");
00059     std::cout<<"Problem with output Pre-textFILE => exit"<<std::endl;
00060     exit(1);
00061   }
00062   // Histos
00063   htsmax = new TH1F("htsmax","Max TS",100,0,10);
00064   htspinmax = new TH1F("htspinmax","Max TS PIN",100,0,10);
00065   // Channel-by-channel histos
00066   for (int i=0;i<13;i++) for (int j=0;j<36;j++) for (int k=0;k<2;k++) {
00067     if (i>10 && j%2==0) continue;
00068     sprintf(htit,"tspre_+%d_%d_%d",i+29,j*2+1,k+1);
00069     hts[i][j][k] = new TH1F(htit,htit,10,-0.5,9.5); // TimeSlices (pulse shape)
00070     sprintf(htit,"tspre_-%d_%d_%d",i+29,j*2+1,k+1);
00071     hts[i+13][j][k] = new TH1F(htit,htit,10,-0.5,9.5); // TimeSlices (pulse shape)
00072   } 
00073   // PIN-diodes histos
00074   for (int i=0;i<4;i++) for (int j=0;j<3;j++) {
00075     sprintf(htit,"tspre_PIN%d_+Q%d",j+1,i+1);
00076     htspin[i][j] = new TH1F(htit,htit,10,-0.5,9.5);
00077     sprintf(htit,"tspre_PIN%d_-Q%d",j+1,i+1);
00078     htspin[i+4][j] = new TH1F(htit,htit,10,-0.5,9.5);
00079   }
00080   std::cout<<"histfile="<<histfile.c_str()<<"  textfile="<<textfile.c_str()<<std::endl;
00081   return;
00082 }
00083 
00084 void HFPreLightCal::endJob(void)
00085 {
00086   Double_t sum,cont;
00087   Int_t tsmax;
00088 
00089   std::cout<<std::endl<<"HFPreLightCal endJob --> ";
00090 
00091   for (int i=0;i<26;i++) for (int j=0;j<36;j++) for (int k=0;k<2;k++) {
00092     if (i>10 && i<13 && j%2==0) continue;
00093     if (i>23 && j%2==0) continue;
00094     sum=tsmax=0;
00095     for (int ii=1; ii<=10; ii++) {
00096       cont = hts[i][j][k]->GetBinContent(ii);
00097       if (ii<3) cont=cont-(hts[i][j][k]->GetBinContent(ii+4)+hts[i][j][k]->GetBinContent(ii+8))/2;
00098       else if (ii<5) cont=cont-hts[i][j][k]->GetBinContent(ii+4);
00099       else if (ii<7) cont=cont-(hts[i][j][k]->GetBinContent(ii-4)+hts[i][j][k]->GetBinContent(ii+4))/2;
00100       else if (ii<9) cont=cont-hts[i][j][k]->GetBinContent(ii-4);
00101       else cont=cont-(hts[i][j][k]->GetBinContent(ii-4)+hts[i][j][k]->GetBinContent(ii-8))/2;
00102       if (cont>sum) {
00103         sum = cont;
00104         tsmax=ii;
00105       }
00106     }
00107     htsmax->Fill(tsmax);
00108     if (i<13) fprintf(tFile," %d  %d  %d  %d\n",i+29,j*2+1,k+1,tsmax);
00109     else      fprintf(tFile," %d  %d  %d  %d\n",13-i-29,j*2+1,k+1,tsmax);
00110   }
00111 
00112   for (int i=0;i<8;i++) for (int j=0;j<3;j++) {
00113     sum=tsmax=0;
00114     tsmax = htspin[i][j]->GetMaximumBin();
00115     htspinmax->Fill(tsmax);
00116     if (i<4) fprintf(tFile,"%d  %d  %d\n",i+1,j+1,tsmax);
00117     else     fprintf(tFile,"%d  %d  %d\n",-i+3,j+1,tsmax);
00118   } 
00119 
00120   mFile->Write();
00121   mFile->Close();
00122   fclose(tFile);
00123   std::cout<<" Nevents = "<<event_NN<<std::endl;
00124   return;
00125 }
00126 
00127 void HFPreLightCal::analyze(const edm::Event& fEvent, const edm::EventSetup& fSetup) {
00128 
00129   // event ID
00130   edm::EventID eventId = fEvent.id();
00131   int runNumber = eventId.run ();
00132   int eventNumber = eventId.event ();
00133   if (run_NN==0) run_NN=runNumber;
00134   event_NN++;
00135   if (verbose) std::cout << "========================================="<<std::endl
00136                          << "run/event: "<<runNumber<<'/'<<eventNumber<<std::endl;
00137 
00138   // HF PIN-diodes
00139   edm::Handle<HcalCalibDigiCollection> calib;  
00140   fEvent.getByLabel(hcalCalibDigiCollectionTag_, calib);
00141   if (verbose) std::cout<<"Analysis-> total CAL digis= "<<calib->size()<<std::endl;
00142   /* COMMENTED OUT by J. Mans (7-28-2008) as major changes needed with new Calib DetId 
00143 
00144   for (unsigned j = 0; j < calib->size (); ++j) {
00145     const HcalCalibDataFrame digi = (*calib)[j];
00146     HcalElectronicsId elecId = digi.elecId();
00147     HcalCalibDetId calibId = digi.id();
00148     if (verbose) std::cout<<calibId.sectorString().c_str()<<" "<<calibId.rbx()<<" "<<elecId.fiberChanId()<<std::endl;
00149     int isector = calibId.rbx()-1;
00150     int ipin = elecId.fiberChanId();
00151     int iside = -1;
00152     if (calibId.sectorString() == "HFP") iside = 0; 
00153     else if (calibId.sectorString() == "HFM") iside = 4;
00154 
00155     if (iside != -1) {
00156       for (int isample = 0; isample < digi.size(); ++isample) {
00157         int adc = digi[isample].adc();
00158         int capid = digi[isample].capid ();
00159         double linear_ADC = digi[isample].nominal_fC();
00160         if (verbose) std::cout<<"PIN linear_ADC = "<<linear_ADC<<std::endl;
00161         htspin[isector+iside][ipin]->Fill(isample,linear_ADC);
00162       }
00163     }
00164   }
00165   */  
00166   // HF
00167   edm::Handle<HFDigiCollection> hf_digi;
00168   fEvent.getByLabel(hfDigiCollectionTag_, hf_digi);
00169   if (verbose) std::cout<<"Analysis-> total HF digis= "<<hf_digi->size()<<std::endl;
00170 
00171   for (unsigned ihit = 0; ihit < hf_digi->size (); ++ihit) {
00172     const HFDataFrame& frame = (*hf_digi)[ihit];
00173     HcalDetId detId = frame.id();
00174     int ieta = detId.ieta();
00175     int iphi = detId.iphi();
00176     int depth = detId.depth();
00177     if (verbose) std::cout <<"HF digi # " <<ihit<<": eta/phi/depth: "
00178                            <<ieta<<'/'<<iphi<<'/'<< depth << std::endl;
00179 
00180     if (ieta>0) ieta = ieta-29;
00181     else ieta = 13-ieta-29;
00182 
00183     for (int isample = 0; isample < frame.size(); ++isample) {
00184       int adc = frame[isample].adc();
00185       int capid = frame[isample].capid ();
00186       double linear_ADC = frame[isample].nominal_fC();
00187       double nominal_fC = detId.subdet () == HcalForward ? 2.6 *  linear_ADC : linear_ADC;
00188 
00189       if (verbose) std::cout << "Analysis->     HF sample # " << isample 
00190                              << ", capid=" << capid 
00191                              << ": ADC=" << adc 
00192                              << ", linearized ADC=" << linear_ADC
00193                              << ", nominal fC=" << nominal_fC << std::endl;
00194 
00195       hts[ieta][(iphi-1)/2][depth-1]->Fill(isample,linear_ADC);
00196     }
00197   }
00198   return;
00199 }
00200