00001
00002
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
00035 bool verbose = false;
00036 }
00037
00038 HFPreLightCal::HFPreLightCal (const edm::ParameterSet& fConfiguration) {
00039
00040 histfile = fConfiguration.getUntrackedParameter<string>("rootPreFile");
00041 textfile = fConfiguration.getUntrackedParameter<string>("textPreFile");
00042 }
00043
00044 HFPreLightCal::~HFPreLightCal () {
00045
00046 }
00047
00048 void HFPreLightCal::beginJob(const edm::EventSetup& fSetup) {
00049
00050 char htit[64];
00051 std::cout<<std::endl<<"HFPreLightCal beginJob: --> ";
00052
00053 mFile = new TFile (histfile.c_str(),"RECREATE");
00054 if ((tFile = fopen(textfile.c_str(),"w"))==NULL) {
00055 printf("\nNo textfile open\n\n");
00056 std::cout<<"Problem with output Pre-textFILE => exit"<<std::endl;
00057 exit(1);
00058 }
00059
00060 htsmax = new TH1F("htsmax","Max TS",100,0,10);
00061 htspinmax = new TH1F("htspinmax","Max TS PIN",100,0,10);
00062
00063 for (int i=0;i<13;i++) for (int j=0;j<36;j++) for (int k=0;k<2;k++) {
00064 if (i>10 && j%2==0) continue;
00065 sprintf(htit,"tspre_+%d_%d_%d",i+29,j*2+1,k+1);
00066 hts[i][j][k] = new TH1F(htit,htit,10,-0.5,9.5);
00067 sprintf(htit,"tspre_-%d_%d_%d",i+29,j*2+1,k+1);
00068 hts[i+13][j][k] = new TH1F(htit,htit,10,-0.5,9.5);
00069 }
00070
00071 for (int i=0;i<4;i++) for (int j=0;j<3;j++) {
00072 sprintf(htit,"tspre_PIN%d_+Q%d",j+1,i+1);
00073 htspin[i][j] = new TH1F(htit,htit,10,-0.5,9.5);
00074 sprintf(htit,"tspre_PIN%d_-Q%d",j+1,i+1);
00075 htspin[i+4][j] = new TH1F(htit,htit,10,-0.5,9.5);
00076 }
00077 std::cout<<"histfile="<<histfile.c_str()<<" textfile="<<textfile.c_str()<<std::endl;
00078 return;
00079 }
00080
00081 void HFPreLightCal::endJob(void)
00082 {
00083 Double_t sum,cont;
00084 Int_t tsmax;
00085
00086 std::cout<<std::endl<<"HFPreLightCal endJob --> ";
00087
00088 for (int i=0;i<26;i++) for (int j=0;j<36;j++) for (int k=0;k<2;k++) {
00089 if (i>10 && i<13 && j%2==0) continue;
00090 if (i>23 && j%2==0) continue;
00091 sum=tsmax=0;
00092 for (int ii=1; ii<=10; ii++) {
00093 cont = hts[i][j][k]->GetBinContent(ii);
00094 if (ii<3) cont=cont-(hts[i][j][k]->GetBinContent(ii+4)+hts[i][j][k]->GetBinContent(ii+8))/2;
00095 else if (ii<5) cont=cont-hts[i][j][k]->GetBinContent(ii+4);
00096 else if (ii<7) cont=cont-(hts[i][j][k]->GetBinContent(ii-4)+hts[i][j][k]->GetBinContent(ii+4))/2;
00097 else if (ii<9) cont=cont-hts[i][j][k]->GetBinContent(ii-4);
00098 else cont=cont-(hts[i][j][k]->GetBinContent(ii-4)+hts[i][j][k]->GetBinContent(ii-8))/2;
00099 if (cont>sum) {
00100 sum = cont;
00101 tsmax=ii;
00102 }
00103 }
00104 htsmax->Fill(tsmax);
00105 if (i<13) fprintf(tFile," %d %d %d %d\n",i+29,j*2+1,k+1,tsmax);
00106 else fprintf(tFile," %d %d %d %d\n",13-i-29,j*2+1,k+1,tsmax);
00107 }
00108
00109 for (int i=0;i<8;i++) for (int j=0;j<3;j++) {
00110 sum=tsmax=0;
00111 tsmax = htspin[i][j]->GetMaximumBin();
00112 htspinmax->Fill(tsmax);
00113 if (i<4) fprintf(tFile,"%d %d %d\n",i+1,j+1,tsmax);
00114 else fprintf(tFile,"%d %d %d\n",-i+3,j+1,tsmax);
00115 }
00116
00117 mFile->Write();
00118 mFile->Close();
00119 fclose(tFile);
00120 std::cout<<" Nevents = "<<event_NN<<std::endl;
00121 return;
00122 }
00123
00124 void HFPreLightCal::analyze(const edm::Event& fEvent, const edm::EventSetup& fSetup) {
00125
00126
00127 edm::EventID eventId = fEvent.id();
00128 int runNumber = eventId.run ();
00129 int eventNumber = eventId.event ();
00130 if (run_NN==0) run_NN=runNumber;
00131 event_NN++;
00132 if (verbose) std::cout << "========================================="<<std::endl
00133 << "run/event: "<<runNumber<<'/'<<eventNumber<<std::endl;
00134
00135
00136 edm::Handle<HcalCalibDigiCollection> calib;
00137 fEvent.getByType(calib);
00138 if (verbose) std::cout<<"Analysis-> total CAL digis= "<<calib->size()<<std::endl;
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 edm::Handle<HFDigiCollection> hf_digi;
00165 fEvent.getByType(hf_digi);
00166 if (verbose) std::cout<<"Analysis-> total HF digis= "<<hf_digi->size()<<std::endl;
00167
00168 for (unsigned ihit = 0; ihit < hf_digi->size (); ++ihit) {
00169 const HFDataFrame& frame = (*hf_digi)[ihit];
00170 HcalDetId detId = frame.id();
00171 int ieta = detId.ieta();
00172 int iphi = detId.iphi();
00173 int depth = detId.depth();
00174 if (verbose) std::cout <<"HF digi # " <<ihit<<": eta/phi/depth: "
00175 <<ieta<<'/'<<iphi<<'/'<< depth << std::endl;
00176
00177 if (ieta>0) ieta = ieta-29;
00178 else ieta = 13-ieta-29;
00179
00180 for (int isample = 0; isample < frame.size(); ++isample) {
00181 int adc = frame[isample].adc();
00182 int capid = frame[isample].capid ();
00183 double linear_ADC = frame[isample].nominal_fC();
00184 double nominal_fC = detId.subdet () == HcalForward ? 2.6 * linear_ADC : linear_ADC;
00185
00186 if (verbose) std::cout << "Analysis-> HF sample # " << isample
00187 << ", capid=" << capid
00188 << ": ADC=" << adc
00189 << ", linearized ADC=" << linear_ADC
00190 << ", nominal fC=" << nominal_fC << std::endl;
00191
00192 hts[ieta][(iphi-1)/2][depth-1]->Fill(isample,linear_ADC);
00193 }
00194 }
00195 return;
00196 }
00197