CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CalibCalorimetry/HcalStandardModules/src/HFLightCalRand.cc

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