CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/CalibCalorimetry/HcalStandardModules/src/HFLightCal.cc

Go to the documentation of this file.
00001 // Analysis of HF LED/Laser run: 
00002 // SPE calibration for low light intensity or raw SPE calibration for high light intensity
00003 // and HF performance based on this analysis
00004 //
00005 // Igor Vodopiyanov. Oct-2007 .... update Sept-2008
00006 // Thanks G.Safronov, M.Mohammadi, F.Ratnikov
00007 //
00008 #include <memory>
00009 #include <string>
00010 #include <iostream>
00011 
00012 #include "TH1F.h"
00013 #include "TH2F.h"
00014 #include "TFile.h"
00015 #include "math.h"
00016 #include "TMath.h"
00017 #include "TF1.h"
00018 
00019 #include "CalibCalorimetry/HcalStandardModules/interface/HFLightCal.h"
00020 
00021 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00022 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00023 
00024 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00025 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00026 #include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
00027 #include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 #include "FWCore/Framework/interface/EventSetup.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 
00034 using namespace std;
00035 Int_t Nev, runN=0, eventN=0;
00036 Int_t itsmax[26][36][2];
00037 Int_t itspinmax[8][3];
00038 
00039 namespace {
00040   //bool verbose = true;
00041   bool verbose = false;
00042 }
00043 
00044 HFLightCal::HFLightCal (const edm::ParameterSet& fConfiguration) :
00045   hfDigiCollectionTag_(fConfiguration.getParameter<edm::InputTag>("hfDigiCollectionTag")),
00046   hcalCalibDigiCollectionTag_(fConfiguration.getParameter<edm::InputTag>("hcalCalibDigiCollectionTag")) {
00047 
00048   //std::string histfile = fConfiguration.getUntrackedParameter<string>("rootFile");
00049   histfile = fConfiguration.getUntrackedParameter<string>("rootFile");
00050   textfile = fConfiguration.getUntrackedParameter<string>("textFile");
00051   prefile = fConfiguration.getUntrackedParameter<string>("preFile");
00052 }
00053 
00054 HFLightCal::~HFLightCal () {
00055   //delete mFile;
00056 }
00057 
00058 void HFLightCal::beginJob() {
00059 
00060   char htit[64];
00061   Int_t neta,nphi,ndepth,nmax,nquad,npin;
00062 
00063   std::cout<<std::endl<<"HFLightCal beginJob: --> "<<std::endl;
00064 
00065   // Read info about signal timing in TS from PreAnalysis
00066   mFile = new TFile (histfile.c_str(),"RECREATE");
00067   if ((tFile = fopen(textfile.c_str(),"w"))==NULL) {
00068     printf("\nNo output textfile open\n\n");
00069     std::cout<<"Problem with output textFILE => exit"<<std::endl;
00070     exit(1);
00071   }
00072   //if ((preFile = fopen("hf_preanal.txt","r"))==NULL){
00073   if ((preFile = fopen(prefile.c_str(),"r"))==NULL){
00074     printf("\nNo input pre-file open\n\n");
00075     std::cout<<"Problem with input textFILE => exit"<<std::endl;
00076     exit(1);
00077   }
00078   rewind(preFile);
00079   for (int i=0; i<1728; i++) {
00080     fscanf(preFile,"%d%d%d%d\r",&neta,&nphi,&ndepth,&nmax);
00081     //std::cout<<neta<<"  "<<nphi<<"  "<<ndepth<<"  "<<nmax<<std::endl;
00082     if (neta>=29 && neta<=41 && nphi<72 && nphi>0 && ndepth>0 && ndepth<=2) 
00083       itsmax[neta-29][(nphi-1)/2][ndepth-1] = nmax;
00084     else if (neta<=-29 && neta>=-41 && nphi<72 && nphi>0 && ndepth>0 && ndepth<=2) 
00085       itsmax[13-neta-29][(nphi-1)/2][ndepth-1] = nmax;
00086     else {
00087       std::cout<<"Input pre-file: wrong channel record:"<<std::endl;
00088       std::cout<<"eta="<<neta<<"  phi="<<nphi<<"  depth="<<ndepth<<"  max="<<nmax<<std::endl;
00089     }
00090   }
00091   for (int i=0; i<24; i++) {
00092     fscanf(preFile,"%d%d%d\r",&nquad,&npin,&nmax);
00093     //std::cout<<nquad<<"  "<<npin<<"  "<<nmax<<std::endl;
00094     if (nquad>0 && nquad<=4 && npin<=3 && npin>0) 
00095       itspinmax[nquad-1][npin-1] = nmax;
00096     else if (nquad<0 && nquad>=-4 && npin<=3 && npin>0) 
00097       itspinmax[4-nquad-1][npin-1] = nmax;
00098     else {
00099       std::cout<<"Input pre-file: wrong PIN record:"<<std::endl;
00100       std::cout<<"quad="<<nquad<<"  pin="<<npin<<"  max="<<nmax<<std::endl;
00101     }
00102   }
00103 
00104   // General Histos
00105   htmax = new TH1F("htmax","Max TS",10,-0.5,9.5);
00106   htmean = new TH1F("htmean","Mean signal TS",100,0,10);
00107   hsignalmean = new TH1F("hsignalmean","Mean ADC 4maxTS",1201,-25,30000);
00108   hsignalrms = new TH1F("hsignalrms","RMS ADC 4maxTS",500,0,500);
00109   hpedmean = new TH1F("hpedmean","Mean ADC 4lowTS",200,-10,90);
00110   hpedrms = new TH1F("hpedrms","RMS ADC 4lowTS",200,0,100);
00111   hspes = new TH1F("hspes","SPE if measured",200,0,40);
00112   hnpevar = new TH1F("hnpevar","~N PE input",500,0,500);
00113   hsignalmapP = new TH2F("hsignalmapP","Mean(Response) - Mean(Pedestal) HFP;#eta;#phi",26,28.5,41.5,36,0,72);
00114   hsignalRMSmapP = new TH2F("hsignalRMSmapP","RMS Response HFP;#eta;#phi",26,28.5,41.5,36,0,72);
00115   hnpemapP = new TH2F("hnpemapP","~N PE input HFP;#eta;#phi",26,28.5,41.5,36,0,72);
00116   hnpemapP->SetOption("COLZ");hsignalmapP->SetOption("COLZ");hsignalRMSmapP->SetOption("COLZ");
00117   hsignalmapM = new TH2F("hsignalmapM","Mean(Response) - Mean(Pedestal) HFM;#eta;#phi",26,-41.5,-28.5,36,0,72);
00118   hsignalRMSmapM = new TH2F("hsignalRMSmapM","RMS Response HFM;#eta;#phi",26,-41.5,-28.5,36,0,72);
00119   hnpemapM = new TH2F("hnpemapM","~N PE input HFM;#eta;#phi",26,-41.5,-28.5,36,0,72);
00120   hnpemapM->SetOption("COLZ");hsignalmapM->SetOption("COLZ");hsignalRMSmapM->SetOption("COLZ");
00121   // Channel-by-channel histos
00122   for (int i=0;i<13;i++) for (int j=0;j<36;j++) for (int k=0;k<2;k++) {
00123     if (i>10 && j%2==0) continue;
00124     sprintf(htit,"ts_+%d_%d_%d",i+29,j*2+1,k+1);
00125     hts[i][j][k] = new TH1F(htit,htit,10,-0.5,9.5); // TimeSlices (pulse shape)
00126     sprintf(htit,"tsmean_+%d_%d_%d",i+29,j*2+1,k+1);
00127     htsm[i][j][k] = new TH1F(htit,htit,100,0,10);   // Mean signal time estimated from TS 
00128     sprintf(htit,"sp_+%d_%d_%d",i+29,j*2+1,k+1);
00129     hsp[i][j][k] = new TH1F(htit,htit,1201,-25,30000); // Big-scale spectrum (linear ADC)
00130     sprintf(htit,"spe_+%d_%d_%d",i+29,j*2+1,k+1);
00131     hspe[i][j][k] = new TH1F(htit,htit,200,-9.5,190.5); // Small-scale spectrum (linear ADC)
00132     sprintf(htit,"ped_+%d_%d_%d",i+29,j*2+1,k+1);
00133     hped[i][j][k] = new TH1F(htit,htit,200,-9.5,190.5); // Pedestal spectrum
00134     sprintf(htit,"ts_-%d_%d_%d",i+29,j*2+1,k+1);
00135     hts[i+13][j][k] = new TH1F(htit,htit,10,-0.5,9.5);
00136     sprintf(htit,"tsmean_-%d_%d_%d",i+29,j*2+1,k+1);
00137     htsm[i+13][j][k] = new TH1F(htit,htit,100,0,10);  
00138     sprintf(htit,"sp_-%d_%d_%d",i+29,j*2+1,k+1);
00139     hsp[i+13][j][k] = new TH1F(htit,htit,1201,-25,30000);
00140     sprintf(htit,"spe_-%d_%d_%d",i+29,j*2+1,k+1);
00141     hspe[i+13][j][k] = new TH1F(htit,htit,200,-9.5,190.5); 
00142     sprintf(htit,"ped_-%d_%d_%d",i+29,j*2+1,k+1);
00143     hped[i+13][j][k] = new TH1F(htit,htit,200,-9.5,190.5); 
00144   } 
00145   // PIN-diodes histos
00146   for (int i=0;i<4;i++) for (int j=0;j<3;j++) {
00147     sprintf(htit,"ts_PIN%d_+Q%d",j+1,i+1);
00148     htspin[i][j] = new TH1F(htit,htit,10,-0.5,9.5);
00149     sprintf(htit,"sp_PIN%d_+Q%d",j+1,i+1);
00150     hsppin[i][j] = new TH1F(htit,htit,1601,-25,40000);
00151     sprintf(htit,"spe_PIN%d_+Q%d",j+1,i+1);
00152     hspepin[i][j] = new TH1F(htit,htit,200,-9.5,190.5);
00153     sprintf(htit,"ped_PIN%d_+Q%d",j+1,i+1);
00154     hpedpin[i][j] = new TH1F(htit,htit,200,-9.5,190.5);
00155     sprintf(htit,"tsmean_PIN%d_+Q%d",j+1,i+1);
00156     htsmpin[i][j] = new TH1F(htit,htit,100,0,10);  
00157     sprintf(htit,"ts_PIN%d_-Q%d",j+1,i+1);
00158     htspin[i+4][j] = new TH1F(htit,htit,10,-0.5,9.5);
00159     sprintf(htit,"sp_PIN%d_-Q%d",j+1,i+1);
00160     hsppin[i+4][j] = new TH1F(htit,htit,1601,-25,40000);
00161     sprintf(htit,"spe_PIN%d_-Q%d",j+1,i+1);
00162     hspepin[i+4][j] = new TH1F(htit,htit,200,-9.5,190.5);
00163     sprintf(htit,"ped_PIN%d_-Q%d",j+1,i+1);
00164     hpedpin[i+4][j] = new TH1F(htit,htit,200,-9.5,190.5);
00165     sprintf(htit,"tsmean_PIN%d_-Q%d",j+1,i+1);
00166     htsmpin[i+4][j] = new TH1F(htit,htit,100,0,10);  
00167   }
00168   std::cout<<std::endl<<"histfile="<<histfile.c_str()<<"  textfile="<<textfile.c_str()<<std::endl;
00169   return;
00170 }
00171 
00172 void HistSpecs(TH1F* hist, Double_t &mean, Double_t &rms, Double_t range=4) {
00173   Double_t xmin,xmax;
00174   mean=hist->GetMean();
00175   rms=hist->GetRMS();
00176   xmin=hist->GetXaxis()->GetXmin();
00177   xmax=hist->GetXaxis()->GetXmax();
00178   hist->SetAxisRange(mean-range*rms-100,mean+range*rms+100);
00179   mean=hist->GetMean();
00180   rms=hist->GetRMS();
00181   hist->SetAxisRange(mean-range*rms-100,mean+range*rms+100);
00182   mean=hist->GetMean();
00183   rms=hist->GetRMS();
00184   hist->SetAxisRange(xmin,xmax);
00185   return;
00186 }
00187 
00188 Double_t FitFun(Double_t *x, Double_t *par) { 
00189 // Spectra fit function: Pedestal Gaussian + asymmetric 1PE + 2PE +3PE peaks
00190 
00191   Double_t sum,xx,A0,C0,r0,sigma0,mean1,sigma1,A1,C1,r1,mean2,sigma2,A2,C2,r2,mean3,sigma3,A3,C3,r3;
00192 
00193   const Double_t k0=2.0, k1=1.6, k2=2.0;
00194 
00195   xx=x[0];
00196   sigma0 = par[2];
00197   A0 = 2*Nev/(2+2*par[0]+par[0]*par[0]+pow(par[0],3)/3+pow(par[0],4)/12+
00198               pow(par[0],5)/60+pow(par[0],6)/360);
00199   r0 = ((xx-par[1])/sigma0);
00200   C0 = 1/(sigma0* TMath::Exp(-k0*k0/2)/k0 +
00201           sigma0*sqrt(2*3.14159)*0.5*(1+TMath::Erf(k0/1.41421)));
00202   //sum = 1/(sqrt(2*3.14159)*par[2])*A0*TMath::Exp(-0.5*r0*r0);
00203   if(r0 < k0) sum = C0*A0*TMath::Exp(-0.5*r0*r0);
00204   else sum = C0*A0*TMath::Exp(0.5*k0*k0-k0*r0);
00205 
00206   mean1 = par[1]+par[3];
00207   sigma1 = par[4];
00208   //sigma1 = 1.547+0.125*par[3]+0.004042*par[3]*par[3];
00209   //sigma1 = (sigma1+(9.1347e-3+3.845e-2*par[3])*par[4]*2.0)*par[2];
00210   A1 = A0*par[0];
00211   C1 = 1/(sigma1* TMath::Exp(-k1*k1/2)/k1 +
00212           sigma1*sqrt(2*3.14159)*0.5*(1+TMath::Erf(k1/1.41421)));
00213   r1 = ((xx-mean1)/sigma1);
00214   if(r1 < k1) sum += C1*A1*TMath::Exp(-0.5*r1*r1);
00215   else sum += C1*A1*TMath::Exp(0.5*k1*k1-k1*r1);
00216 
00217   mean2 = 2*par[3]+par[1];
00218   sigma2 = sqrt(2*sigma1*sigma1 - pow(par[2],2));
00219   //A2 = A0*par[5]*par[0]*par[0]/2;
00220   A2 = A0*par[0]*par[0]/2;
00221   C2 = 1/(sigma2* TMath::Exp(-k2*k2/2)/k2 +
00222           sigma2*sqrt(2*3.14159)*0.5*(1+TMath::Erf(k2/1.41421)));
00223   r2 = ((xx-mean2)/sigma2);
00224   if(r2 < k2) sum += C2*A2*TMath::Exp(-0.5*r2*r2);
00225   else sum += C2*A2*TMath::Exp(0.5*k2*k2-k2*r2);
00226 
00227   mean3 = 3*par[3]+par[1];
00228   sigma3 = sqrt(3*sigma1*sigma1 - 2*pow(par[2],2));
00229   A3 = A0*par[0]*par[0]*par[0]/6;
00230   C3 = 1/(sigma3*sqrt(2*3.14159));
00231   r3 = ((xx-mean3)/sigma3);
00232   sum += C3*A3*TMath::Exp(-0.5*r3*r3);
00233 
00234   return sum;
00235 }
00236 
00237 void HFLightCal::endJob(void)
00238 {
00239   Double_t mean,rms,meanped,rmsped,npevar;
00240   Double_t par[5],dspe=0,dnpe;
00241   Int_t tsmax,intspe;
00242   std::cout<<std::endl<<"HFLightCal endJob --> ";
00243   fprintf(tFile,"#RunN %d   Events processed %d",runN,eventN);
00244 
00245   for (int i=0;i<26;i++) for (int j=0;j<36;j++) for (int k=0;k<2;k++) {
00246     if (i>10 && i<13 && j%2==0) continue;
00247     if (i>23 && j%2==0) continue;
00248     meanped=rmsped=mean=rms=0;
00249     if (hsp[i][j][k]->Integral()>0) {
00250       HistSpecs(hped[i][j][k],meanped,rmsped);
00251       HistSpecs(hsp[i][j][k],mean,rms);
00252       if (hspe[i][j][k]->Integral()>hsp[i][j][k]->Integral()*0.9 || mean<100) {
00253         HistSpecs(hspe[i][j][k],mean,rms);
00254       }
00255       hsignalmean->Fill(mean);
00256       hsignalrms->Fill(rms);
00257       hpedmean->Fill(meanped);
00258       hpedrms->Fill(rmsped);
00259     }
00260   }
00261 
00262   meanped=hpedmean->GetMean();
00263   rmsped=hpedrms->GetMean();
00264   mean=hsignalmean->GetMean();
00265   rms=hsignalrms->GetMean();
00266   fprintf(tFile,"   MeanInput=<%.2f> [linADCcount]   RMS=<%.2f>\n",mean,rms);
00267   fprintf(tFile,"#eta/phi/depth  sum4maxTS     RMS      ~N_PE  sum4lowTS     RMS  maxTS  SPE +/- Err   Comment\n");
00268   TF1* fPed = new TF1("fPed","gaus",0,120);
00269   fPed->SetNpx(200);
00270   TF1 *fTot = new TF1("fTot",FitFun ,0,200,5);
00271   fTot->SetNpx(800);
00272   for (int i=0;i<26;i++) for (int j=0;j<36;j++) for (int k=0;k<2;k++) {
00273     if (i>10 && i<13 && j%2==0) continue;
00274     if (i>23 && j%2==0) continue;
00275     HistSpecs(hped[i][j][k],meanped,rmsped);
00276     HistSpecs(hsp[i][j][k],mean,rms);
00277     par[3]=0;
00278     if (hspe[i][j][k]->Integral()>hsp[i][j][k]->Integral()*0.9 || mean<100) {
00279       HistSpecs(hspe[i][j][k],mean,rms);
00280       if (hspe[i][j][k]->Integral(1,(int) (meanped+3*rmsped+12))/Nev>0.1) {
00281         //if (hspe[i][j][k]->Integral()>100 && mean-meanped<100) {
00282         if (mean+rms*3-meanped-rmsped*3>2 && rmsped>0) { // SPE fit if low intensity>0
00283           par[1] = meanped;
00284           par[2] = rmsped;
00285           par[0] = hped[i][j][k]->GetMaximum();
00286           fPed->SetParameters(par);
00287           hped[i][j][k]->Fit(fPed,"BQ0");
00288           fPed->GetParameters(&par[0]);
00289           hped[i][j][k]->Fit(fPed,"B0Q","",par[1]-par[2]*3,par[1]+par[2]*3);
00290           fPed->GetParameters(par);
00291           hped[i][j][k]->Fit(fPed,"BLIQ","",par[1]-par[2]*3,par[1]+par[2]*3);
00292           fPed->GetParameters(&par[0]);
00293           Nev = (int) hspe[i][j][k]->Integral();
00294           par[0]=0.1;
00295           par[3]=10;
00296           par[4]=6;
00297           fTot->SetParameters(par);
00298           fTot->SetParLimits(0,0,2);
00299           //fTot->FixParameter(1,par[1]);
00300           fTot->SetParLimits(1,par[1]-1,par[1]+1);
00301           fTot->FixParameter(2,par[2]);
00302           fTot->SetParLimits(3,1.2,100);
00303           //fTot->SetParLimits(4,-1.64,1.64);
00304           //fTot->SetParLimits(5,0.5,3);
00305           hspe[i][j][k]->Fit(fTot,"BLEQ","");
00306           fTot->GetParameters(par);
00307           hspe[i][j][k]->Fit(fTot,"BLEQ","",-10,par[1]+par[3]*5);
00308           fTot->GetParameters(par);
00309           dspe=fTot->GetParError(3);
00310           dnpe=fTot->GetParError(0);
00311           if (par[3]<1.21 || dnpe>par[0]) par[3]=-1;
00312           else if (par[0]>1.96 || par[3]>49) par[3]=0;
00313           else {
00314             hspes->Fill(par[3]);
00315           }
00316         } 
00317       }
00318     }
00319 
00320     // NPE
00321     npevar=0;
00322     if (par[3]>0) npevar=par[0];                          // NPE from SPE fit
00323     else {                                                // NPE from high intensity signal
00324       if (hspe[i][j][k]->Integral()>hsp[i][j][k]->Integral()*0.98) {
00325         HistSpecs(hspe[i][j][k],mean,rms,3);
00326       }
00327       else {
00328         HistSpecs(hsp[i][j][k],mean,rms,3);
00329       }
00330       if (rmsped>0) {
00331         if (rms*rms-rmsped*rmsped>1 && mean>meanped) {
00332           npevar=(mean-meanped)*(mean-meanped)/(rms*rms-rmsped*rmsped);
00333         }
00334         else if (mean<100) {
00335           intspe=int(hspe[i][j][k]->Integral());
00336           hspe[i][j][k]->SetAxisRange(meanped+rmsped*4,300);
00337           npevar=hspe[i][j][k]->Integral()/intspe;
00338           if (npevar>0.01) npevar=-1;
00339           else npevar=0;
00340           hspe[i][j][k]->SetAxisRange(-20,300);
00341         }
00342       }
00343     }
00344     if (npevar>5.0e-5) hnpevar->Fill(npevar);
00345 
00346     if (i<13) {
00347       hsignalmapP->Fill(i+28.6+k/2.0,j*2+1,mean-meanped); 
00348       hsignalRMSmapP->Fill(i+28.6+k/2.0,j*2+1,rms);
00349       if (npevar>0) hnpemapP->Fill(i+28.6+k/2.0,j*2+1,npevar);
00350       fprintf(tFile,"%3d%4d%5d  %11.2f%8.2f",i+29,j*2+1,k+1,mean,rms);
00351     }
00352     else {
00353       fprintf(tFile,"%3d%4d%5d  %11.2f%8.2f",13-i-29,j*2+1,k+1,mean,rms);
00354       hsignalmapM->Fill(13-i-28.6-k/2.0,j*2+1,mean-meanped);
00355       hsignalRMSmapM->Fill(13-i-28.6-k/2.0,j*2+1,rms);
00356       if (npevar>0) hnpemapM->Fill(13-i-28.6-k/2.0,j*2+1,npevar);
00357     }
00358     if (npevar>0) fprintf(tFile,"  %9.4f",npevar);
00359     else  fprintf(tFile,"      0    ");
00360     fprintf(tFile,"   %8.2f%8.2f",meanped,rmsped);
00361     tsmax=hts[i][j][k]->GetMaximumBin()-1;
00362     fprintf(tFile," %4d",tsmax);
00363     if (par[3]>0 && par[3]<99)  fprintf(tFile,"%8.2f%7.2f",par[3],dspe);
00364     else if (npevar>0) fprintf(tFile,"%8.2f    0  ",(mean-meanped)/npevar);
00365     else fprintf(tFile,"     0      0  ");
00366 
00367     // Diagnostics 
00368     fprintf(tFile,"    ");
00369     if (hsp[i][j][k]->GetEntries()<=0) fprintf(tFile,"NoSignal\n");
00370     else if (hsp[i][j][k]->GetEntries()<=10) fprintf(tFile,"Nev<10\n");
00371     else {
00372       if (hsp[i][j][k]->Integral()<=10 || mean>12000)  fprintf(tFile,"SignalOffRange\n");
00373       else {
00374         if (hsp[i][j][k]->Integral()<100)  fprintf(tFile,"Nev<100/");
00375         if (npevar>0 && par[3]>0 && (npevar*Nev<10 || npevar<0.001)) 
00376           fprintf(tFile,"LowSignal/");
00377         else if (npevar==0 && fabs(mean-meanped)<3) fprintf(tFile,"LowSignal/");
00378         if (par[3]<0)  fprintf(tFile,"BadFit/");
00379         else if (par[3]==0)  fprintf(tFile,"NoSPEFit/");
00380         else if (par[3]>0 && npevar>1)   fprintf(tFile,"NPE>1/");
00381         if (npevar<0)   fprintf(tFile,"Problem/");
00382         if (mean<2) fprintf(tFile,"LowMean/");
00383         if (rms<0.5) fprintf(tFile,"LowRMS/"); 
00384         if (meanped<-1) fprintf(tFile,"LowPed/");
00385         else if (meanped>25) fprintf(tFile,"HighPed/"); 
00386         if (rmsped<0.5 && rmsped>0) fprintf(tFile,"NarrowPed/"); 
00387         else if (rmsped>10) fprintf(tFile,"WidePed/");
00388         if (hped[i][j][k]->GetBinContent(201)>10) fprintf(tFile,"PedOffRange"); 
00389         fprintf(tFile,"-\n");
00390       }
00391     }
00392   }
00393 
00394   for (int i=0;i<8;i++) for (int j=0;j<3;j++) {
00395     HistSpecs(hpedpin[i][j],meanped,rmsped);
00396     HistSpecs(hsppin[i][j],mean,rms);
00397     if (hspepin[i][j]->Integral()>hsppin[i][j]->Integral()*0.9 || mean<100) {
00398       HistSpecs(hspepin[i][j],mean,rms);
00399     }
00400     if (i<4) fprintf(tFile," PIN%d  +Q%d  %12.2f  %6.2f",j+1,i+1,mean,rms);
00401     else fprintf(tFile," PIN%d  -Q%d  %12.2f  %6.2f",j+1,i-3,mean,rms);
00402     fprintf(tFile,"  %15.2f  %6.2f",meanped,rmsped);
00403     tsmax=htspin[i][j]->GetMaximumBin()-1;
00404     fprintf(tFile,"  %4d\n",tsmax);
00405   } 
00406 
00407   mFile->Write();
00408   mFile->Close();
00409   fclose(tFile);
00410   std::cout<<std::endl<<" --endJob-- done"<<std::endl;
00411   return;
00412 }
00413 
00414 void HFLightCal::analyze(const edm::Event& fEvent, const edm::EventSetup& fSetup) {
00415 
00416   // event ID
00417   edm::EventID eventId = fEvent.id();
00418   int runNer = eventId.run ();
00419   int eventNumber = eventId.event ();
00420   if (runN==0) runN=runNer;
00421   eventN++;
00422   if (verbose) std::cout << "========================================="<<std::endl
00423                          << "run/event: "<<runNer<<'/'<<eventNumber<<std::endl;
00424 
00425   Double_t buf[20];
00426   Double_t maxADC,signal,ped=0,meant;
00427   Int_t maxisample=0,i1=3,i2=6;
00428 
00429   // HF PIN-diodes
00430   edm::Handle<HcalCalibDigiCollection> calib;  
00431   fEvent.getByLabel(hcalCalibDigiCollectionTag_, calib);
00432   if (verbose) std::cout<<"Analysis-> total CAL digis= "<<calib->size()<<std::endl;
00433 
00434   /* COMMENTED OUT by J. Mans (7-28-2008) as major changes needed with new Calib DetId 
00435    re-commented out by R.Ofierzynski (11.Nov.2008) - to be able to provide a consistent code for CMSSW_3_0_0_pre3:
00436    major changes are needed for the new Calib DetId which does not have the old methods any more
00437 
00438   for (unsigned j = 0; j < calib->size (); ++j) {
00439     const HcalCalibDataFrame digi = (*calib)[j];
00440     HcalElectronicsId elecId = digi.elecId();
00441     HcalCalibDetId calibId = digi.id();
00442     if (verbose) std::cout<<calibId.sectorString().c_str()<<" "<<calibId.rbx()<<" "<<elecId.fiberChanId()<<std::endl;
00443     int isector = calibId.rbx()-1;
00444     int ipin = elecId.fiberChanId();
00445     int iside = -1;
00446     if (calibId.sectorString() == "HFP") iside = 0; 
00447     else if (calibId.sectorString() == "HFM") iside = 4;
00448     maxisample = itspinmax[isector+iside][ipin]-1;
00449 
00450     if (iside != -1) {
00451       for (int isample = 0; isample < digi.size(); ++isample) {
00452         int adc = digi[isample].adc();
00453         int capid = digi[isample].capid ();
00454         double linear_ADC = digi[isample].nominal_fC();
00455         if (verbose) std::cout<<"PIN linear_ADC = "<<linear_ADC<<"  atMAXTS="<<maxisample<<std::endl;
00456         htspin[isector+iside][ipin]->Fill(isample,linear_ADC);
00457         buf[isample]=linear_ADC;
00458       }
00459       i1=maxisample-1;
00460       i2=maxisample+2;
00461       if (i1<0) {i1=0;i2=3;}
00462       else if (i2>9) {i1=6;i2=9;} 
00463       if      (i1==0) ped=buf[8]+buf[9]+buf[6]+buf[7];
00464       else if (i1==1) ped=buf[8]+buf[9]+buf[6]+buf[7];
00465       else if (i1==2) ped=buf[0]+buf[1]+buf[6]+buf[7];
00466       else if (i1==3) ped=buf[0]+buf[1]+buf[2]+buf[7];
00467       else if (i1>=4) ped=buf[0]+buf[1]+buf[2]+buf[3];
00468       signal=0;
00469       for (ii=0;ii<4;ii++) signal+=TMath::Max(buf[ii+i1],ped/4.0);
00470       hsppin[isector+iside][ipin]->Fill(signal);
00471       hspepin[isector+iside][ipin]->Fill(signal);
00472       hpedpin[isector+iside][ipin]->Fill(ped);
00473 
00474       // Mean signal time estimation
00475       ped=ped/4;
00476       meant=0;
00477       for (ii=0;ii<4;ii++) meant+=(TMath::Max(buf[ii+i1],ped)-ped)*(ii+i1);
00478       if (signal-ped*4>0) meant/=(signal-ped*4); 
00479       else meant=i1+1;
00480       htsmpin[isector+iside][ipin]->Fill(meant);
00481     }
00482   }
00483   */  
00484 
00485   // HF
00486   edm::Handle<HFDigiCollection> hf_digi;
00487   fEvent.getByLabel(hfDigiCollectionTag_, hf_digi);
00488   if (verbose) std::cout<<"Analysis-> total HF digis= "<<hf_digi->size()<<std::endl;
00489 
00490   for (unsigned ihit = 0; ihit < hf_digi->size (); ++ihit) {
00491     const HFDataFrame& frame = (*hf_digi)[ihit];
00492     HcalDetId detId = frame.id();
00493     int ieta = detId.ieta();
00494     int iphi = detId.iphi();
00495     int depth = detId.depth();
00496     if (verbose) std::cout <<"HF digi # " <<ihit<<": eta/phi/depth: "
00497                            <<ieta<<'/'<<iphi<<'/'<< depth << std::endl;
00498 
00499     if (ieta>0) ieta = ieta-29;
00500     else ieta = 13-ieta-29;
00501 
00502     for (int ii=0; ii<10; ii++) buf[ii]=0;
00503     maxADC=-99;
00504     for (int isample = 0; isample < frame.size(); ++isample) {
00505       int adc = frame[isample].adc();
00506       int capid = frame[isample].capid ();
00507       double linear_ADC = frame[isample].nominal_fC();
00508       double nominal_fC = detId.subdet () == HcalForward ? 2.6 *  linear_ADC : linear_ADC;
00509 
00510       if (verbose) std::cout << "Analysis->     HF sample # " << isample 
00511                              << ", capid=" << capid 
00512                              << ": ADC=" << adc 
00513                              << ", linearized ADC=" << linear_ADC
00514                              << ", nominal fC=" << nominal_fC <<std::endl;
00515 
00516       hts[ieta][(iphi-1)/2][depth-1]->Fill(isample,linear_ADC);
00517       buf[isample]=linear_ADC;
00518       /*
00519       if (maxADC<linear_ADC) {
00520         maxADC=linear_ADC;
00521         maxisample=isample;
00522       }
00523       */
00524     }
00525 
00526     maxADC=-99;
00527     for (int ii=0; ii<frame.size(); ii++) {
00528       signal=buf[ii];
00529       if      (ii<2) signal -= (buf[ii+4]+buf[ii+8])/2.0;
00530       else if (ii<4) signal -= buf[ii+4];
00531       else if (ii<6) signal -= (buf[ii+4]+buf[ii-4])/2.0;
00532       else if (ii<8) signal -= buf[ii-4];
00533       else           signal -= (buf[ii-4]+buf[ii-8])/2.0;
00534       if (signal>maxADC) {
00535         maxADC=signal;
00536         maxisample=ii;
00537       }
00538     }
00539     //maxisample=itsmax[ieta][(iphi-1)/2][depth-1]-1;
00540     if (abs(maxisample-itsmax[ieta][(iphi-1)/2][depth-1]+1)>1)  maxisample=itsmax[ieta][(iphi-1)/2][depth-1]-1;
00541     if (verbose) std::cout<<eventNumber<<"/"<<ihit<<": maxTS="<<maxisample<<endl;
00542 
00543     // Signal = four capIDs found by PreAnal, Pedestal = four capIDs off the signal
00544     htmax->Fill(maxisample);
00545     i1=maxisample-1;
00546     i2=maxisample+2;
00547     if (i1<0) {i1=0;i2=3;}
00548     else if (i2>9) {i1=6;i2=9;} 
00549     else if (i2<9 && maxisample<=itsmax[ieta][(iphi-1)/2][depth-1]-1) {
00550       if (buf[i1]<buf[i2+1]) {i1=i1+1;i2=i2+1;}
00551     }
00552     signal=buf[i1]+buf[i1+1]+buf[i1+2]+buf[i1+3];
00553     hsp[ieta][(iphi-1)/2][depth-1]->Fill(signal);
00554     hspe[ieta][(iphi-1)/2][depth-1]->Fill(signal);
00555     /*
00556     if      (i1==0) ped=(buf[4]+buf[8])/2.0+(buf[5]+buf[9])/2.0+buf[6]+buf[7];
00557     else if (i1==1) ped=(buf[0]+buf[8])/2.0+(buf[5]+buf[9])/2.0+buf[6]+buf[7];
00558     else if (i1==2) ped=(buf[0]+buf[8])/2.0+(buf[1]+buf[9])/2.0+buf[6]+buf[7];
00559     else if (i1==3) ped=(buf[0]+buf[8])/2.0+(buf[1]+buf[9])/2.0+buf[2]+buf[7];
00560     else if (i1==4) ped=(buf[0]+buf[8])/2.0+(buf[1]+buf[9])/2.0+buf[2]+buf[3];
00561     else if (i1==5) ped=(buf[0]+buf[4])/2.0+(buf[1]+buf[9])/2.0+buf[2]+buf[3];
00562     else if (i1==6) ped=(buf[0]+buf[4])/2.0+(buf[1]+buf[5])/2.0+buf[2]+buf[3];
00563     */
00564     
00565     if      (i1<2) ped=buf[8]+buf[9]+buf[6]+buf[7];
00566     else if (i1==2) ped=buf[6]+buf[9]+buf[7]+buf[0];
00567     else if (i1==3) ped=buf[0]+buf[1]+buf[2]+buf[7];
00568     else if (i1>=4) ped=buf[0]+buf[1]+buf[2]+buf[3];
00569     
00570     hped[ieta][(iphi-1)/2][depth-1]->Fill(ped);
00571 
00572     // Mean signal time estimation
00573     ped=ped/4;
00574     meant=(buf[i1]-ped)*i1+(buf[i1+1]-ped)*(i1+1)+(buf[i1+2]-ped)*(i1+2)+(buf[i1+3]-ped)*(i1+3);
00575     meant /= (buf[i1]-ped)+(buf[i1+1]-ped)+(buf[i1+2]-ped)+(buf[i1+3]-ped);
00576     htmean->Fill(meant);
00577     htsm[ieta][(iphi-1)/2][depth-1]->Fill(meant);
00578   }
00579 }
00580