CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CalibCalorimetry/HcalAlgos/src/HcalPedestalAnalysis.cc

Go to the documentation of this file.
00001 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00002 #include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
00003 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
00004 #include "CondFormats/HcalObjects/interface/HcalPedestalWidths.h"
00005 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00006 #include "CalibCalorimetry/HcalAlgos/interface/HcalPedestalAnalysis.h"
00007 #include "TFile.h"
00008 #include <math.h>
00009 
00010 //
00011 // Michal Szleper, Mar 30, 2007
00012 //
00013 
00014 using namespace std;
00015 
00016 HcalPedestalAnalysis::HcalPedestalAnalysis(const edm::ParameterSet& ps)
00017   : fRefPedestals (0),
00018     fRefPedestalWidths (0),
00019     fRawPedestals (0),
00020     fRawPedestalWidths (0),
00021     fValPedestals (0),
00022     fValPedestalWidths (0)
00023 {
00024   fTopology=0;
00025   m_coder = 0;
00026   m_shape = 0;
00027   evt=0;
00028   sample=0;
00029   m_file=0;
00030   m_AllPedsOK=0;
00031   for(int i=0; i<4; i++) m_stat[i]=0;
00032   for(int k=0;k<4;k++) state.push_back(true);
00033 
00034 // user cfg parameters
00035   m_outputFileMean = ps.getUntrackedParameter<string>("outputFileMeans", "");
00036   if ( m_outputFileMean.size() != 0 ) {
00037     cout << "Hcal pedestal means will be saved to " << m_outputFileMean.c_str() << endl;
00038   } 
00039   m_outputFileWidth = ps.getUntrackedParameter<string>("outputFileWidths", "");
00040   if ( m_outputFileWidth.size() != 0 ) {
00041     cout << "Hcal pedestal widths will be saved to " << m_outputFileWidth.c_str() << endl;
00042   } 
00043   m_outputFileROOT = ps.getUntrackedParameter<string>("outputFileHist", "");
00044   if ( m_outputFileROOT.size() != 0 ) {
00045     cout << "Hcal pedestal histograms will be saved to " << m_outputFileROOT.c_str() << endl;
00046   } 
00047   m_nevtsample = ps.getUntrackedParameter<int>("nevtsample",0);
00048 // for compatibility with previous versions
00049   if(m_nevtsample==9999999) m_nevtsample=0;
00050   m_pedsinADC = ps.getUntrackedParameter<int>("pedsinADC",0);
00051   m_hiSaveflag = ps.getUntrackedParameter<int>("hiSaveflag",0);
00052   m_pedValflag = ps.getUntrackedParameter<int>("pedValflag",0);
00053   if(m_pedValflag<0) m_pedValflag=0;
00054   if (m_nevtsample>0 && m_pedValflag>0) {
00055     cout<<"WARNING - incompatible cfg options: nevtsample = "<<m_nevtsample<<", pedValflag = "<<m_pedValflag<<endl;
00056     cout<<"Setting pedValflag = 0"<<endl;
00057     m_pedValflag=0;
00058   }
00059   if(m_pedValflag>1) m_pedValflag=1;
00060   m_startTS = ps.getUntrackedParameter<int>("firstTS", 0);
00061   if(m_startTS<0) m_startTS=0;
00062   m_endTS = ps.getUntrackedParameter<int>("lastTS", 9);
00063 
00064   fTopology=new HcalTopology(HcalTopologyMode::LHC,2,3);
00065 
00066 //  m_logFile.open("HcalPedestalAnalysis.log");
00067 
00068   hbHists.ALLPEDS = new TH1F("HBHE All Pedestals","HBHE All Peds",10,0,9);
00069   hbHists.PEDRMS= new TH1F("HBHE All Pedestal Widths","HBHE All Pedestal RMS",100,0,3);
00070   hbHists.PEDMEAN= new TH1F("HBHE All Pedestal Means","HBHE All Pedestal Means",100,0,9);
00071   hbHists.CHI2= new TH1F("HBHE Chi2/ndf for whole range Gauss fit","HBHE Chi2/ndf Gauss",200,0.,50.);
00072 
00073   hoHists.ALLPEDS = new TH1F("HO All Pedestals","HO All Peds",10,0,9);
00074   hoHists.PEDRMS= new TH1F("HO All Pedestal Widths","HO All Pedestal RMS",100,0,3);
00075   hoHists.PEDMEAN= new TH1F("HO All Pedestal Means","HO All Pedestal Means",100,0,9);
00076   hoHists.CHI2= new TH1F("HO Chi2/ndf for whole range Gauss fit","HO Chi2/ndf Gauss",200,0.,50.);
00077 
00078   hfHists.ALLPEDS = new TH1F("HF All Pedestals","HF All Peds",10,0,9);
00079   hfHists.PEDRMS= new TH1F("HF All Pedestal Widths","HF All Pedestal RMS",100,0,3);
00080   hfHists.PEDMEAN= new TH1F("HF All Pedestal Means","HF All Pedestal Means",100,0,9);
00081   hfHists.CHI2= new TH1F("HF Chi2/ndf for whole range Gauss fit","HF Chi2/ndf Gauss",200,0.,50.);
00082 }
00083 
00084 //-----------------------------------------------------------------------------
00085 HcalPedestalAnalysis::~HcalPedestalAnalysis(){
00086 
00087   for(_meot=hbHists.PEDTRENDS.begin(); _meot!=hbHists.PEDTRENDS.end(); _meot++){
00088     for(int i=0; i<16; i++) _meot->second[i].first->Delete();
00089   }
00090   for(_meot=hoHists.PEDTRENDS.begin(); _meot!=hoHists.PEDTRENDS.end(); _meot++){
00091     for(int i=0; i<16; i++) _meot->second[i].first->Delete();
00092   }
00093   for(_meot=hfHists.PEDTRENDS.begin(); _meot!=hfHists.PEDTRENDS.end(); _meot++){
00094     for(int i=0; i<16; i++) _meot->second[i].first->Delete();
00095   }
00096   hbHists.ALLPEDS->Delete();
00097   hbHists.PEDRMS->Delete();
00098   hbHists.PEDMEAN->Delete();
00099   hbHists.CHI2->Delete();
00100 
00101   hoHists.ALLPEDS->Delete();
00102   hoHists.PEDRMS->Delete();
00103   hoHists.PEDMEAN->Delete();
00104   hoHists.CHI2->Delete();
00105 
00106   hfHists.ALLPEDS->Delete();
00107   hfHists.PEDRMS->Delete();
00108   hfHists.PEDMEAN->Delete();
00109   hfHists.CHI2->Delete();
00110 }
00111 
00112 //-----------------------------------------------------------------------------
00113 void HcalPedestalAnalysis::setup(const std::string& m_outputFileROOT) {
00114   // open the histogram file, create directories within
00115   m_file=new TFile(m_outputFileROOT.c_str(),"RECREATE");
00116   m_file->mkdir("HB");
00117   m_file->cd();
00118   m_file->mkdir("HO");
00119   m_file->cd();
00120   m_file->mkdir("HF");
00121   m_file->cd();
00122 }
00123 
00124 //-----------------------------------------------------------------------------
00125 void HcalPedestalAnalysis::processEvent(const HBHEDigiCollection& hbhe,
00126                                         const HODigiCollection& ho,
00127                                         const HFDigiCollection& hf,
00128                                         const HcalDbService& cond)
00129 {
00130   evt++;
00131   sample=1;
00132   evt_curr=evt;
00133   if(m_nevtsample>0) {
00134     sample = (evt-1)/m_nevtsample +1;
00135     evt_curr = evt%m_nevtsample;
00136     if(evt_curr==0)evt_curr=m_nevtsample;
00137   }
00138 
00139   // Get data for every CAPID.
00140   // HBHE
00141   try{
00142     if(!hbhe.size()) throw (int)hbhe.size();
00143     for (HBHEDigiCollection::const_iterator j=hbhe.begin(); j!=hbhe.end(); j++){
00144       const HBHEDataFrame digi = (const HBHEDataFrame)(*j);
00145       m_coder = cond.getHcalCoder(digi.id());
00146       m_shape = cond.getHcalShape(m_coder);
00147       for(int k=0; k<(int)state.size();k++) state[k]=true;
00148 // here we loop over pairs of time slices, it is more convenient
00149 // in order to extract the correlation matrix
00150       for (int i=m_startTS; i<digi.size() && i<=m_endTS; i++) {
00151         for(int flag=0; flag<4; flag++){
00152           if(i+flag<digi.size() && i+flag<=m_endTS){
00153             per2CapsHists(flag,0,digi.id(),digi.sample(i),digi.sample(i+flag),hbHists.PEDTRENDS,cond);
00154           }
00155         }
00156       }
00157       if(m_startTS==0 && m_endTS>4){
00158         AllChanHists(digi.id(),digi.sample(0),digi.sample(1),digi.sample(2),digi.sample(3),digi.sample(4),digi.sample(5),hbHists.PEDTRENDS);
00159       }
00160     }
00161   }
00162   catch (int i ) {
00163 //    m_logFile<< "Event with " << i<<" HBHE Digis passed." << std::endl;
00164   } 
00165   // HO
00166   try{
00167     if(!ho.size()) throw (int)ho.size();
00168     for (HODigiCollection::const_iterator j=ho.begin(); j!=ho.end(); j++){
00169       const HODataFrame digi = (const HODataFrame)(*j);
00170       m_coder = cond.getHcalCoder(digi.id());
00171       for (int i=m_startTS; i<digi.size() && i<=m_endTS; i++) {    
00172         for(int flag=0; flag<4; flag++){
00173           if(i+flag<digi.size() && i+flag<=m_endTS){
00174             per2CapsHists(flag,1,digi.id(),digi.sample(i),digi.sample(i+flag),hoHists.PEDTRENDS,cond);
00175           }
00176         }
00177       }
00178       if(m_startTS==0 && m_endTS>4){
00179         AllChanHists(digi.id(),digi.sample(0),digi.sample(1),digi.sample(2),digi.sample(3),digi.sample(4),digi.sample(5),hoHists.PEDTRENDS);
00180       }
00181     }        
00182   } 
00183   catch (int i ) {
00184 //    m_logFile << "Event with " << i<<" HO Digis passed." << std::endl;
00185   } 
00186   // HF
00187   try{
00188     if(!hf.size()) throw (int)hf.size();
00189     for (HFDigiCollection::const_iterator j=hf.begin(); j!=hf.end(); j++){
00190       const HFDataFrame digi = (const HFDataFrame)(*j);
00191       m_coder = cond.getHcalCoder(digi.id());
00192       for (int i=m_startTS; i<digi.size() && i<=m_endTS; i++) {
00193         for(int flag=0; flag<4; flag++){
00194           if(i+flag<digi.size() && i+flag<=m_endTS){
00195             per2CapsHists(flag,2,digi.id(),digi.sample(i),digi.sample(i+flag),hfHists.PEDTRENDS,cond);
00196           }
00197         }
00198       }
00199       if(m_startTS==0 && m_endTS>4){
00200         AllChanHists(digi.id(),digi.sample(0),digi.sample(1),digi.sample(2),digi.sample(3),digi.sample(4),digi.sample(5),hfHists.PEDTRENDS);
00201       }
00202     }
00203   } 
00204   catch (int i ) {
00205 //    m_logFile << "Event with " << i<<" HF Digis passed." << std::endl;
00206   } 
00207   // Call the function every m_nevtsample events
00208   if(m_nevtsample>0) {
00209     if(evt%m_nevtsample==0) SampleAnalysis();
00210   }
00211 }
00212 
00213 //-----------------------------------------------------------------------------
00214 void HcalPedestalAnalysis::per2CapsHists(int flag, int id, const HcalDetId detid, const HcalQIESample& qie1, const HcalQIESample& qie2, map<HcalDetId, map<int,PEDBUNCH> > &toolT, const HcalDbService& cond) {
00215 
00216 // this function is due to be called for every time slice, it fills either a charge
00217 // histo for a single capID (flag=0) or a product histo for two capIDs (flag>0)
00218 
00219   static const int bins=10;
00220   static const int bins2=100;
00221   float lo=-0.5; float hi=9.5;
00222   map<int,PEDBUNCH> _mei;
00223   static map<HcalDetId, map<int,float> > QieCalibMap;
00224   string type = "HBHE";
00225 
00226   if(id==0){
00227     if(detid.ieta()<16) type = "HB";
00228     if(detid.ieta()>16) type = "HE";
00229     if(detid.ieta()==16){
00230       if(detid.depth()<3) type = "HB";
00231       if(detid.depth()==3) type = "HE";
00232     }
00233   } 
00234   else if(id==1) type = "HO";
00235   else if(id==2) type = "HF"; 
00236 
00237   _meot = toolT.find(detid);
00238 
00239 // if histos for the current channel do not exist, first create them,
00240   if (_meot==toolT.end()){
00241     map<int,PEDBUNCH> insert;
00242     map<int,float> qiecalib;
00243     char name[1024];
00244     for(int i=0; i<4; i++){
00245       lo=-0.5;
00246       // fix from Andy: if you convert to fC and then bin in units of 1, you may 'skip' a bin while
00247       // filling, since the ADCs are quantized
00248       if (m_pedsinADC) hi=9.5;
00249       else hi = 11.5;
00250       sprintf(name,"%s Pedestal, eta=%d phi=%d d=%d cap=%d",type.c_str(),detid.ieta(),detid.iphi(),detid.depth(),i);  
00251       insert[i].first =  new TH1F(name,name,bins,lo,hi);
00252       sprintf(name,"%s Product, eta=%d phi=%d d=%d caps=%d*%d",type.c_str(),detid.ieta(),detid.iphi(),detid.depth(),i,(i+1)%4);  
00253       insert[4+i].first = new TH1F(name,name,bins2,0.,100.);
00254       sprintf(name,"%s Product, eta=%d phi=%d d=%d caps=%d*%d",type.c_str(),detid.ieta(),detid.iphi(),detid.depth(),i,(i+2)%4);  
00255       insert[8+i].first = new TH1F(name,name,bins2,0.,100.);
00256       sprintf(name,"%s Product, eta=%d phi=%d d=%d caps=%d*%d",type.c_str(),detid.ieta(),detid.iphi(),detid.depth(),i,(i+3)%4);  
00257       insert[12+i].first = new TH1F(name,name,bins2,0.,100.);
00258     }
00259     sprintf(name,"%s Signal in TS 4+5, eta=%d phi=%d d=%d",type.c_str(),detid.ieta(),detid.iphi(),detid.depth());  
00260     insert[16].first = new TH1F(name,name,21,-0.5,20.5);
00261     sprintf(name,"%s Signal in TS 4+5-2-3, eta=%d phi=%d d=%d",type.c_str(),detid.ieta(),detid.iphi(),detid.depth());  
00262     insert[17].first = new TH1F(name,name,21,-10.5,10.5);
00263     sprintf(name,"%s Signal in TS 4+5-(0+1+2+3)/2., eta=%d phi=%d d=%d",type.c_str(),detid.ieta(),detid.iphi(),detid.depth());  
00264     insert[18].first = new TH1F(name,name,21,-10.5,10.5);
00265     toolT[detid] = insert;
00266     _meot = toolT.find(detid);
00267 // store QIE calibrations in a map for later reuse
00268     QieCalibMap[detid]=qiecalib;
00269   }
00270 
00271   _mei = _meot->second;
00272 
00273   const HcalQIECoder* coder = cond.getHcalCoder(detid);
00274   const HcalQIEShape* shape = cond.getHcalShape(coder);
00275   float charge1 = coder->charge(*shape,qie1.adc(),qie1.capid());
00276   float charge2 = coder->charge(*shape,qie2.adc(),qie2.capid());
00277 
00278 // fill single capID histo
00279   if(flag==0){
00280     if(m_nevtsample>0) {
00281       if((evt-1)%m_nevtsample==0 && state[qie1.capid()]){
00282         state[qie1.capid()]=false; 
00283         _mei[qie1.capid()].first->Reset();
00284         _mei[qie1.capid()+4].first->Reset();
00285         _mei[qie1.capid()+8].first->Reset();
00286         _mei[qie1.capid()+12].first->Reset();
00287       }
00288     }
00289     if (qie1.adc()<bins){
00290       if (m_pedsinADC) _mei[qie1.capid()].first->Fill(qie1.adc());
00291       else _mei[qie1.capid()].first->Fill(charge1); 
00292     }
00293     else if(qie1.adc()>=bins){
00294       _mei[qie1.capid()].first->AddBinContent(bins+1,1);
00295     }
00296   }
00297 
00298 // fill 2 capID histo
00299   if(flag>0){
00300     map<int,float> qiecalib = QieCalibMap[detid];
00301     //float charge1=(qie1.adc()-qiecalib[qie1.capid()+4])/qiecalib[qie1.capid()];
00302     //float charge2=(qie2.adc()-qiecalib[qie2.capid()+4])/qiecalib[qie2.capid()];
00303     if (charge1*charge2<bins2){
00304       _mei[qie1.capid()+4*flag].first->Fill(charge1*charge2);
00305     }
00306     else{
00307       _mei[qie1.capid()+4*flag].first->Fill(bins2);
00308     }
00309   }
00310 
00311   if(flag==0){
00312     if(id==0) hbHists.ALLPEDS->Fill(qie1.adc());
00313     else if(id==1) hoHists.ALLPEDS->Fill(qie1.adc());
00314     else if(id==2) hfHists.ALLPEDS->Fill(qie1.adc());
00315   }
00316 }
00317 
00318 //-----------------------------------------------------------------------------
00319 void HcalPedestalAnalysis::AllChanHists(const HcalDetId detid, const HcalQIESample& qie0, const HcalQIESample& qie1, const HcalQIESample& qie2, const HcalQIESample& qie3, const HcalQIESample& qie4, const HcalQIESample& qie5, map<HcalDetId, map<int,PEDBUNCH> > &toolT) { 
00320 
00321 // this function is due to be called for every channel
00322 
00323   _meot = toolT.find(detid);
00324   map<int,PEDBUNCH> _mei = _meot->second;
00325   _mei[16].first->Fill(qie4.adc()+qie5.adc()-1.);
00326   _mei[17].first->Fill(qie4.adc()+qie5.adc()-qie2.adc()-qie3.adc());
00327   _mei[18].first->Fill(qie4.adc()+qie5.adc()-(qie0.adc()+qie1.adc()+qie2.adc()+qie3.adc())/2.);
00328 }
00329 
00330 //-----------------------------------------------------------------------------
00331 void HcalPedestalAnalysis::SampleAnalysis(){
00332   // it is called every m_nevtsample events (a sample) and the end of run
00333   char PedSampleNum[20];
00334 
00335 // Compute pedestal constants for each HBHE, HO, HF
00336   sprintf(PedSampleNum,"HB_Sample%d",sample);
00337   m_file->cd();
00338   m_file->mkdir(PedSampleNum);
00339   m_file->cd(PedSampleNum);
00340   GetPedConst(hbHists.PEDTRENDS,hbHists.PEDMEAN,hbHists.PEDRMS);
00341   sprintf(PedSampleNum,"HO_Sample%d",sample);
00342   m_file->cd();
00343   m_file->mkdir(PedSampleNum);
00344   m_file->cd(PedSampleNum);
00345   GetPedConst(hoHists.PEDTRENDS,hoHists.PEDMEAN,hoHists.PEDRMS);
00346   sprintf(PedSampleNum,"HF_Sample%d",sample);
00347   m_file->cd();
00348   m_file->mkdir(PedSampleNum);
00349   m_file->cd(PedSampleNum);
00350   GetPedConst(hfHists.PEDTRENDS,hfHists.PEDMEAN,hfHists.PEDRMS);
00351 }
00352 
00353 //-----------------------------------------------------------------------------
00354 void HcalPedestalAnalysis::GetPedConst(map<HcalDetId, map<int,PEDBUNCH> > &toolT, TH1F* PedMeans, TH1F* PedWidths)
00355 {
00356 // Completely rewritten version oct 2006
00357 // Compute pedestal constants and fill into HcalPedestals and HcalPedestalWidths objects
00358   float cap[4]; float sig[4][4]; float dcap[4]; float dsig[4][4]; float chi2[4];
00359 
00360   for(_meot=toolT.begin(); _meot!=toolT.end(); _meot++){
00361     HcalDetId detid = _meot->first;
00362 
00363 // take mean and width from a Gaussian fit or directly from the histo
00364     if(fitflag>0){
00365       for (int i=0; i<4; i++) {
00366         TF1 *fit = _meot->second[i].first->GetFunction("gaus");
00367         chi2[i]=0;
00368         if(fit->GetNDF()!=0) chi2[i]=fit->GetChisquare()/fit->GetNDF();
00369         cap[i]=fit->GetParameter(1);
00370         sig[i][i]=fit->GetParameter(2);
00371         dcap[i]=fit->GetParError(1);
00372         dsig[i][i]=fit->GetParError(2);
00373       }
00374     }
00375     else{
00376       for (int i=0; i<4; i++) {
00377         cap[i]=_meot->second[i].first->GetMean();
00378         sig[i][i]=_meot->second[i].first->GetRMS();
00379         m_stat[i]=0;
00380 
00381         for(int j=m_startTS; j<m_endTS+1; j++){
00382           m_stat[i]+=_meot->second[i].first->GetBinContent(j+1);
00383         }
00384         dcap[i] = sig[i][i]/sqrt(m_stat[i]);
00385 //        dsig[i][i] = dcap[i]*sig[i][i]/cap[i];
00386         dsig[i][i] = sig[i][i]/sqrt(2.*m_stat[i]);
00387         chi2[i]=0.;
00388       }
00389     }
00390 
00391     for (int i=0; i<4; i++) {
00392       if(m_hiSaveflag>0) {
00393         if (m_pedsinADC)
00394         _meot->second[i].first->GetXaxis()->SetTitle("ADC");
00395         else _meot->second[i].first->GetXaxis()->SetTitle("Charge, fC");
00396         _meot->second[i].first->GetYaxis()->SetTitle("CapID samplings");
00397         _meot->second[i].first->Write();
00398       }
00399       if(m_nevtsample>0) {
00400         _meot->second[i].second.first[0].push_back(cap[i]);
00401         _meot->second[i].second.first[1].push_back(dcap[i]);
00402         _meot->second[i].second.first[2].push_back(sig[i][i]);
00403         _meot->second[i].second.first[3].push_back(dsig[i][i]);
00404         _meot->second[i].second.first[4].push_back(chi2[i]);
00405       }
00406       PedMeans->Fill(cap[i]);
00407       PedWidths->Fill(sig[i][i]);
00408     }
00409 
00410 // special histos for Shuichi
00411     if(m_hiSaveflag==-100){
00412       for(int i=16; i<19; i++){
00413         if (m_pedsinADC)
00414         _meot->second[i].first->GetXaxis()->SetTitle("ADC");
00415         else _meot->second[i].first->GetXaxis()->SetTitle("Charge, fC");
00416         _meot->second[i].first->GetYaxis()->SetTitle("Events");
00417         _meot->second[i].first->Write();
00418       }
00419     }
00420 
00421 // diagonal sigma is width squared
00422     sig[0][0]=sig[0][0]*sig[0][0];
00423     sig[1][1]=sig[1][1]*sig[1][1];
00424     sig[2][2]=sig[2][2]*sig[2][2];
00425     sig[3][3]=sig[3][3]*sig[3][3];
00426 
00427 // off diagonal sigmas (correlations) are computed from 3 histograms
00428 // here we still have all 4*3=12 combinations
00429     sig[0][1]= _meot->second[4].first->GetMean()-cap[0]*cap[1];
00430     sig[0][2]= _meot->second[8].first->GetMean()-cap[0]*cap[2];
00431     sig[1][2]= _meot->second[5].first->GetMean()-cap[1]*cap[2];
00432     sig[1][3]= _meot->second[9].first->GetMean()-cap[1]*cap[3];
00433     sig[2][3]= _meot->second[6].first->GetMean()-cap[2]*cap[3];
00434     sig[0][3]= _meot->second[12].first->GetMean()-cap[0]*cap[3];
00435     sig[1][0]= _meot->second[13].first->GetMean()-cap[1]*cap[0];
00436     sig[2][0]= _meot->second[10].first->GetMean()-cap[2]*cap[0];
00437     sig[2][1]= _meot->second[14].first->GetMean()-cap[2]*cap[1];
00438     sig[3][1]= _meot->second[11].first->GetMean()-cap[3]*cap[1];
00439     sig[3][2]= _meot->second[15].first->GetMean()-cap[3]*cap[2];
00440     sig[3][0]= _meot->second[7].first->GetMean()-cap[3]*cap[0];
00441 
00442 // there is no proper error calculation for the correlation coefficients
00443     for(int i=0; i<4; i++){
00444       if(m_nevtsample>0) {
00445         _meot->second[i].second.first[5].push_back(sig[i][(i+1)%4]);
00446         _meot->second[i].second.first[6].push_back(2*sig[i][i]*dsig[i][i]);
00447         _meot->second[i].second.first[7].push_back(sig[i][(i+2)%4]);
00448         _meot->second[i].second.first[8].push_back(2*sig[i][i]*dsig[i][i]);
00449         _meot->second[i].second.first[9].push_back(sig[i][(i+3)%4]);
00450         _meot->second[i].second.first[10].push_back(2*sig[i][i]*dsig[i][i]);
00451       }
00452 // save product histos if desired
00453       if(m_hiSaveflag>10) {
00454         if (m_pedsinADC)
00455         _meot->second[i+4].first->GetXaxis()->SetTitle("ADC^2");
00456         else _meot->second[i+4].first->GetXaxis()->SetTitle("Charge^2, fC^2");
00457         _meot->second[i+4].first->GetYaxis()->SetTitle("2-CapID samplings");
00458         _meot->second[i+4].first->Write();
00459         if (m_pedsinADC)
00460         _meot->second[i+8].first->GetXaxis()->SetTitle("ADC^2");
00461         else _meot->second[i+8].first->GetXaxis()->SetTitle("Charge^2, fC^2");
00462         _meot->second[i+8].first->GetYaxis()->SetTitle("2-CapID samplings");
00463         _meot->second[i+8].first->Write();
00464         if (m_pedsinADC)
00465         _meot->second[i+12].first->GetXaxis()->SetTitle("ADC^2");
00466         else _meot->second[i+12].first->GetXaxis()->SetTitle("Charge^2, fC^2");
00467         _meot->second[i+12].first->GetYaxis()->SetTitle("2-CapID samplings");
00468         _meot->second[i+12].first->Write();
00469       }
00470     }
00471 
00472 // fill the objects - at this point only close and medium correlations are stored
00473 // and the matrix is assumed symmetric
00474     if (m_nevtsample<1) {
00475       sig[1][0]=sig[0][1];
00476       sig[2][0]=sig[0][2];
00477       sig[2][1]=sig[1][2];
00478       sig[3][1]=sig[1][3];
00479       sig[3][2]=sig[2][3];
00480       sig[0][3]=sig[3][0];
00481       if (fRawPedestals)
00482         {
00483           HcalPedestal item(detid,cap[0],cap[1],cap[2],cap[3]);
00484           fRawPedestals->addValues(item);
00485         }
00486       if (fRawPedestalWidths) 
00487         {
00488           HcalPedestalWidth widthsp(detid);
00489           widthsp.setSigma(0,0,sig[0][0]);
00490           widthsp.setSigma(0,1,sig[0][1]);
00491           widthsp.setSigma(0,2,sig[0][2]);
00492           widthsp.setSigma(1,1,sig[1][1]);
00493           widthsp.setSigma(1,2,sig[1][2]);
00494           widthsp.setSigma(1,3,sig[1][3]);
00495           widthsp.setSigma(2,2,sig[2][2]);
00496           widthsp.setSigma(2,3,sig[2][3]);
00497           widthsp.setSigma(3,3,sig[3][3]);
00498           widthsp.setSigma(3,0,sig[0][3]);
00499           fRawPedestalWidths->addValues(widthsp);
00500         }
00501     }
00502   }
00503 }
00504 
00505 //-----------------------------------------------------------------------------
00506 int HcalPedestalAnalysis::done(const HcalPedestals* fInputPedestals, 
00507                                 const HcalPedestalWidths* fInputPedestalWidths,
00508                                 HcalPedestals* fOutputPedestals, 
00509                                 HcalPedestalWidths* fOutputPedestalWidths)
00510 {
00511    int nstat[4];
00512 
00513 // Pedestal objects
00514   // inputs...
00515   fRefPedestals = fInputPedestals;
00516   fRefPedestalWidths = fInputPedestalWidths;
00517   
00518   // outputs...
00519   if(m_pedValflag>0) {
00520     fValPedestals = fOutputPedestals;
00521     fValPedestalWidths = fOutputPedestalWidths;
00522     fRawPedestals = new HcalPedestals(fTopology,m_pedsinADC);
00523     fRawPedestalWidths = new HcalPedestalWidths(fTopology,m_pedsinADC);
00524   }
00525   else {
00526     fRawPedestals = fOutputPedestals;
00527     fRawPedestalWidths = fOutputPedestalWidths;
00528     fValPedestals = new HcalPedestals(fTopology,m_pedsinADC);
00529     fValPedestalWidths = new HcalPedestalWidths(fTopology,m_pedsinADC);
00530   }
00531 
00532 // compute pedestal constants
00533   if(m_nevtsample<1) SampleAnalysis();
00534   if(m_nevtsample>0) {
00535     if(evt%m_nevtsample!=0) SampleAnalysis();
00536   }
00537 
00538 // trending histos
00539   if(m_nevtsample>0){
00540     m_file->cd();
00541     m_file->cd("HB");
00542     Trendings(hbHists.PEDTRENDS,hbHists.CHI2,hbHists.CAPID_AVERAGE,hbHists.CAPID_CHI2);
00543     m_file->cd();
00544     m_file->cd("HO");
00545     Trendings(hoHists.PEDTRENDS,hoHists.CHI2,hoHists.CAPID_AVERAGE,hoHists.CAPID_CHI2);
00546     m_file->cd();
00547     m_file->cd("HF");
00548     Trendings(hfHists.PEDTRENDS,hfHists.CHI2,hfHists.CAPID_AVERAGE,hfHists.CAPID_CHI2);
00549   }
00550 
00551   if (m_nevtsample<1) {
00552 
00553 // pedestal validation: m_AllPedsOK=-1 means not validated,
00554 //                                   0 everything OK,
00555 //                                   N>0 : mod(N,100000) drifts + width changes
00556 //                                         int(N/100000) missing channels
00557     m_AllPedsOK=-1;
00558     if(m_pedValflag>0) {
00559       for (int i=0; i<4; i++) nstat[i]=(int)m_stat[i];
00560       int NPedErrors=HcalPedVal(nstat,fRefPedestals,fRefPedestalWidths,
00561                             fRawPedestals,fRawPedestalWidths,
00562                             fValPedestals,fValPedestalWidths);
00563       m_AllPedsOK=NPedErrors;
00564     }
00565 // setting m_AllPedsOK=-2 will inhibit writing pedestals out
00566 //    if(m_pedValflag==1){
00567 //      if(evt<100)m_AllPedsOK=-2;
00568 //    }
00569 
00570   }
00571 
00572   // Write other histograms.
00573   // HB
00574   m_file->cd();
00575   m_file->cd("HB");
00576   hbHists.ALLPEDS->Write();
00577   hbHists.PEDRMS->Write();
00578   hbHists.PEDMEAN->Write();
00579   // HO
00580   m_file->cd();
00581   m_file->cd("HO");
00582   hoHists.ALLPEDS->Write();
00583   hoHists.PEDRMS->Write();
00584   hoHists.PEDMEAN->Write();
00585   // HF
00586   m_file->cd();
00587   m_file->cd("HF");
00588   hfHists.ALLPEDS->Write();
00589   hfHists.PEDRMS->Write();
00590   hfHists.PEDMEAN->Write();
00591 
00592   m_file->Close();
00593   cout << "Hcal histograms written to " << m_outputFileROOT.c_str() << endl;
00594   return (int)m_AllPedsOK;
00595 }
00596 
00597 //-----------------------------------------------------------------------------
00598 void HcalPedestalAnalysis::Trendings(map<HcalDetId, map<int,PEDBUNCH> > &toolT, TH1F* Chi2, TH1F* CapidAverage, TH1F* CapidChi2){
00599 
00600 // check stability of pedestal constants in a single long run
00601 
00602   map<int, std::vector<double> > AverageValues;
00603 
00604   for(_meot=toolT.begin(); _meot!=toolT.end(); _meot++){
00605     for(int i=0; i<4; i++){
00606       char name[1024];
00607       HcalDetId detid = _meot->first;
00608       sprintf(name,"Pedestal trend, eta=%d phi=%d d=%d cap=%d",detid.ieta(),detid.iphi(),detid.depth(),i);
00609       int bins = _meot->second[i].second.first[0].size();
00610       float lo =0.5;
00611       float hi = (float)bins+0.5;
00612       _meot->second[i].second.second.push_back(new TH1F(name,name,bins,lo,hi));
00613       sprintf(name,"Width trend, eta=%d phi=%d d=%d cap=%d",detid.ieta(),detid.iphi(),detid.depth(),i);
00614       bins = _meot->second[i].second.first[2].size();
00615       hi = (float)bins+0.5;
00616       _meot->second[i].second.second.push_back(new TH1F(name,name,bins,lo,hi));
00617       sprintf(name,"Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",detid.ieta(),detid.iphi(),detid.depth(),i,(i+1)%4);
00618       bins = _meot->second[i].second.first[5].size();
00619       hi = (float)bins+0.5;
00620       _meot->second[i].second.second.push_back(new TH1F(name,name,bins,lo,hi));
00621 /*      sprintf(name,"Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",detid.ieta(),detid.iphi(),detid.depth(),i,(i+2)%4);
00622       bins = _meot->second[i].second.first[7].size();
00623       hi = (float)bins+0.5;
00624       _meot->second[i].second.second.push_back(new TH1F(name,name,bins,lo,hi));
00625       sprintf(name,"Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",detid.ieta(),detid.iphi(),detid.depth(),i,(i+3)%4);
00626       bins = _meot->second[i].second.first[9].size();
00627       hi = (float)bins+0.5;
00628       _meot->second[i].second.second.push_back(new TH1F(name,name,bins,lo,hi)); */
00629 
00630       std::vector<double>::iterator sample_it;
00631       // Pedestal mean - put content and errors
00632       int j=0;
00633       for(sample_it=_meot->second[i].second.first[0].begin();
00634           sample_it!=_meot->second[i].second.first[0].end();sample_it++){
00635         _meot->second[i].second.second[0]->SetBinContent(++j,*sample_it);
00636       }
00637       j=0;
00638       for(sample_it=_meot->second[i].second.first[1].begin();
00639           sample_it!=_meot->second[i].second.first[1].end();sample_it++){
00640         _meot->second[i].second.second[0]->SetBinError(++j,*sample_it);
00641       }
00642       // fit with a constant - extract parameters
00643       _meot->second[i].second.second[0]->Fit("pol0","Q");
00644       TF1 *fit = _meot->second[i].second.second[0]->GetFunction("pol0");
00645       AverageValues[0].push_back(fit->GetParameter(0));
00646       AverageValues[1].push_back(fit->GetParError(0));
00647       if(sample>1)
00648       AverageValues[2].push_back(fit->GetChisquare()/fit->GetNDF());
00649       else
00650       AverageValues[2].push_back(fit->GetChisquare());
00651       sprintf(name,"Sample (%d events)",m_nevtsample);
00652       _meot->second[i].second.second[0]->GetXaxis()->SetTitle(name);
00653       _meot->second[i].second.second[0]->GetYaxis()->SetTitle("Pedestal value");
00654       _meot->second[i].second.second[0]->Write();
00655       // Pedestal width - put content and errors
00656       j=0;
00657       for(sample_it=_meot->second[i].second.first[2].begin();
00658           sample_it!=_meot->second[i].second.first[2].end();sample_it++){
00659         _meot->second[i].second.second[1]->SetBinContent(++j,*sample_it);
00660       }
00661       j=0;
00662       for(sample_it=_meot->second[i].second.first[3].begin();
00663           sample_it!=_meot->second[i].second.first[3].end();sample_it++){
00664         _meot->second[i].second.second[1]->SetBinError(++j,*sample_it);
00665       }
00666       _meot->second[i].second.second[1]->GetXaxis()->SetTitle(name);
00667       _meot->second[i].second.second[1]->GetYaxis()->SetTitle("Pedestal width");
00668       _meot->second[i].second.second[1]->Write();
00669       // Correlation coeffs - put contents and errors
00670       j=0;
00671       for(sample_it=_meot->second[i].second.first[5].begin();
00672           sample_it!=_meot->second[i].second.first[5].end();sample_it++){
00673         _meot->second[i].second.second[2]->SetBinContent(++j,*sample_it);
00674       }
00675       j=0;
00676       for(sample_it=_meot->second[i].second.first[6].begin();
00677           sample_it!=_meot->second[i].second.first[6].end();sample_it++){
00678         _meot->second[i].second.second[2]->SetBinError(++j,*sample_it);
00679       }
00680       _meot->second[i].second.second[2]->GetXaxis()->SetTitle(name);
00681       _meot->second[i].second.second[2]->GetYaxis()->SetTitle("Close correlation");
00682       _meot->second[i].second.second[2]->Write();
00683  /*     j=0;
00684       for(sample_it=_meot->second[i].second.first[7].begin();
00685           sample_it!=_meot->second[i].second.first[7].end();sample_it++){
00686         _meot->second[i].second.second[3]->SetBinContent(++j,*sample_it);
00687       }
00688       j=0;
00689       for(sample_it=_meot->second[i].second.first[8].begin();
00690           sample_it!=_meot->second[i].second.first[8].end();sample_it++){
00691         _meot->second[i].second.second[3]->SetBinError(++j,*sample_it);
00692       }
00693       _meot->second[i].second.second[3]->GetXaxis()->SetTitle(name);
00694       _meot->second[i].second.second[3]->GetYaxis()->SetTitle("Intermediate correlation");
00695       _meot->second[i].second.second[3]->Write();
00696       j=0;
00697       for(sample_it=_meot->second[i].second.first[9].begin();
00698           sample_it!=_meot->second[i].second.first[9].end();sample_it++){
00699         _meot->second[i].second.second[4]->SetBinContent(++j,*sample_it);
00700       }
00701       j=0;
00702       for(sample_it=_meot->second[i].second.first[10].begin();
00703           sample_it!=_meot->second[i].second.first[10].end();sample_it++){
00704         _meot->second[i].second.second[4]->SetBinError(++j,*sample_it);
00705       }
00706       _meot->second[i].second.second[4]->GetXaxis()->SetTitle(name);
00707       _meot->second[i].second.second[4]->GetYaxis()->SetTitle("Distant correlation");
00708       _meot->second[i].second.second[4]->Write(); */
00709       // chi2
00710       j=0;
00711       for(sample_it=_meot->second[i].second.first[4].begin();
00712           sample_it!=_meot->second[i].second.first[4].end();sample_it++){
00713         Chi2->Fill(*sample_it);
00714       }
00715     }
00716   }
00717   CapidAverage= new TH1F("Constant fit: Pedestal Values",
00718                          "Constant fit: Pedestal Values",
00719                          AverageValues[0].size(),0.,AverageValues[0].size());
00720   std::vector<double>::iterator sample_it;
00721   int j=0;
00722   for(sample_it=AverageValues[0].begin();
00723       sample_it!=AverageValues[0].end();sample_it++){
00724     CapidAverage->SetBinContent(++j,*sample_it);
00725   }
00726   j=0;
00727   for(sample_it=AverageValues[1].begin();
00728       sample_it!=AverageValues[1].end();sample_it++){
00729     CapidAverage->SetBinError(++j,*sample_it);
00730   }
00731   CapidChi2= new TH1F("Constant fit: Chi2/ndf",
00732                       "Constant fit: Chi2/ndf",
00733                       AverageValues[2].size(),0.,AverageValues[2].size());
00734   j=0;
00735   for(sample_it=AverageValues[2].begin();
00736       sample_it!=AverageValues[2].end();sample_it++){
00737     CapidChi2->SetBinContent(++j,*sample_it);
00738     //CapidChi2->SetBinError(++j,0);
00739   }
00740   Chi2->GetXaxis()->SetTitle("Chi2/ndf");
00741   Chi2->GetYaxis()->SetTitle("50 x [(16+2) x 4 x 4] `events`");
00742   Chi2->Write();
00743   CapidAverage->GetYaxis()->SetTitle("Pedestal value");
00744   CapidAverage->GetXaxis()->SetTitle("(16+2) x 4 x 4 `events`");
00745   CapidAverage->Write();
00746   CapidChi2->GetYaxis()->SetTitle("Chi2/ndf");
00747   CapidChi2->GetXaxis()->SetTitle("(16+2) x 4 x 4 `events`");
00748   CapidChi2->Write();
00749 
00750 }
00751 
00752 //-----------------------------------------------------------------------------
00753 int HcalPedestalAnalysis::HcalPedVal(int nstat[4], const HcalPedestals* fRefPedestals, 
00754                                 const HcalPedestalWidths* fRefPedestalWidths,
00755                                 HcalPedestals* fRawPedestals,
00756                                 HcalPedestalWidths* fRawPedestalWidths,
00757                                 HcalPedestals* fValPedestals, 
00758                                 HcalPedestalWidths* fValPedestalWidths)
00759 {
00760 // new version of pedestal validation - it is designed to be as independent of
00761 // all the rest as possible - you only need to provide valid pedestal objects
00762 // and a vector of statistics per capID to use this as standalone code
00763   HcalDetId detid;
00764   float RefPedVals[4]; float RefPedSigs[4][4];
00765   float RawPedVals[4]; float RawPedSigs[4][4];
00766   map<HcalDetId,bool> isinRaw;
00767   map<HcalDetId,bool> isinRef;
00768   std::vector<DetId> RefChanns=fRefPedestals->getAllChannels();
00769   std::vector<DetId> RawChanns=fRawPedestals->getAllChannels();
00770   std::ofstream PedValLog;
00771   PedValLog.open("HcalPedVal.log");
00772 
00773   if(nstat[0]+nstat[1]+nstat[2]+nstat[3]<2500) PedValLog<<"HcalPedVal: warning - low statistics"<<std::endl;
00774 // find complete list of channels in current data and reference
00775   for (int i=0; i<(int)RawChanns.size(); i++){
00776     isinRef[HcalDetId(RawChanns[i])]=false;
00777   }
00778   for (int i=0; i<(int)RefChanns.size(); i++){
00779     detid=HcalDetId(RefChanns[i]);
00780     isinRaw[detid]=false;
00781     isinRef[detid]=true;
00782   }
00783   for (int i=0; i<(int)RawChanns.size(); i++){
00784     detid=HcalDetId(RawChanns[i]);
00785     isinRaw[detid]=true;
00786     if (isinRef[detid]==false) {
00787       PedValLog<<"HcalPedVal: channel "<<detid<<" not found in reference set"<<std::endl;
00788       std::cerr<<"HcalPedVal: channel "<<detid<<" not found in reference set"<<std::endl;
00789     }
00790   }
00791 
00792 // main loop over channels
00793   int erflag=0;
00794   for (int i=0; i<(int)RefChanns.size(); i++){
00795     detid=HcalDetId(RefChanns[i]);
00796     for (int icap=0; icap<4; icap++) {
00797       RefPedVals[icap]=fRefPedestals->getValues(detid)->getValue(icap);
00798       for (int icap2=icap; icap2<4; icap2++) {
00799         RefPedSigs[icap][icap2]=fRefPedestalWidths->getValues(detid)->getSigma(icap,icap2);
00800         if(icap2!=icap)RefPedSigs[icap2][icap]=RefPedSigs[icap][icap2];
00801       }
00802     }
00803 
00804 // read new raw values
00805     if(isinRaw[detid]) {
00806       for (int icap=0; icap<4; icap++) {
00807         RawPedVals[icap]=fRawPedestals->getValues(detid)->getValue(icap);
00808         for (int icap2=icap; icap2<4; icap2++) {
00809           RawPedSigs[icap][icap2]=fRawPedestalWidths->getValues(detid)->getSigma(icap,icap2);
00810           if(icap2!=icap)RawPedSigs[icap2][icap]=RawPedSigs[icap][icap2];
00811         }
00812       }
00813 
00814 // first quick check if raw values make sense: if not, the channel is treated like absent
00815       for (int icap=0; icap<4; icap++) {
00816         if(RawPedVals[icap]<1. || RawPedSigs[icap][icap]<0.01) isinRaw[detid]=false;
00817         for (int icap2=icap; icap2<4; icap2++){
00818           if(fabs(RawPedSigs[icap][icap2]/sqrt(RawPedSigs[icap][icap]*RawPedSigs[icap2][icap2]))>1.) isinRaw[detid]=false;
00819         }
00820       }
00821     }
00822 
00823 // check raw values against reference
00824     if(isinRaw[detid]) {
00825       for (int icap=0; icap<4; icap++) {
00826         int icap2=(icap+1)%4;
00827         float width=sqrt(RawPedSigs[icap][icap]);
00828         float erof1=width/sqrt((float)nstat[icap]);
00829         float erof2=sqrt(erof1*erof1+RawPedSigs[icap][icap]/(float)nstat[icap]);
00830         float erofwidth=width/sqrt(2.*nstat[icap]);
00831         float diffof1=RawPedVals[icap]-RefPedVals[icap];
00832         float diffof2=RawPedVals[icap]+RawPedVals[icap2]-RefPedVals[icap]-RefPedVals[icap2];
00833         float diffofw=width-sqrt(RefPedSigs[icap][icap]);
00834 
00835 // validation in 2 TS for HB, HE, HO, in 1 TS for HF
00836         int nTS=2;
00837         if(detid.subdet()==HcalForward) nTS=1;
00838         if(nTS==1 && fabs(diffof1)>0.5+erof1) { 
00839           erflag+=1;
00840           PedValLog<<"HcalPedVal: drift in channel "<<detid<<" cap "<<icap<<": "<<RawPedVals[icap]<<" - "<<RefPedVals[icap]<<" = "<<diffof1<<std::endl;
00841         }
00842         if(nTS==2 && fabs(diffof2)>0.5+erof2) { 
00843           erflag+=1;
00844           PedValLog<<"HcalPedVal: drift in channel "<<detid<<" caps "<<icap<<"+"<<icap2<<": "<<RawPedVals[icap]<<"+"<<RawPedVals[icap2]<<" - "<<RefPedVals[icap]<<"+"<<RefPedVals[icap2]<<" = "<<diffof2<<std::endl;
00845         }
00846         if(fabs(diffofw)>0.15*width+erofwidth) {
00847           erflag+=1;
00848           PedValLog<<"HcalPedVal: width changed in channel "<<detid<<" cap "<<icap<<": "<<width<<" - "<<sqrt(RefPedSigs[icap][icap])<<" = "<<diffofw<<std::endl;
00849         }
00850       }
00851     }
00852 
00853 // for disconnected/bad channels restore reference values
00854     else {
00855       PedValLog<<"HcalPedVal: no valid data from channel "<<detid<<std::endl;
00856       erflag+=100000;
00857       HcalPedestal item(detid,RefPedVals[0],RefPedVals[1],RefPedVals[2],RefPedVals[3]);
00858       fValPedestals->addValues(item);
00859       HcalPedestalWidth widthsp(detid);
00860       for (int icap=0; icap<4; icap++) {
00861         for (int icap2=icap; icap2<4; icap2++) widthsp.setSigma(icap2,icap,RefPedSigs[icap2][icap]);
00862       }
00863       fValPedestalWidths->addValues(widthsp);
00864     }
00865 
00866 // end of channel loop
00867   }
00868 
00869   if(erflag==0) PedValLog<<"HcalPedVal: all pedestals checked OK"<<std::endl;
00870 
00871 // now construct the remaining part of the validated objects
00872 // if nothing changed outside tolerance, validated set = reference set
00873   if(erflag%100000 == 0) {
00874     for (int i=0; i<(int)RefChanns.size(); i++){
00875       detid=HcalDetId(RefChanns[i]);
00876       if (isinRaw[detid]) {
00877         HcalPedestalWidth widthsp(detid);
00878         for (int icap=0; icap<4; icap++) {
00879           RefPedVals[icap]=fRefPedestals->getValues(detid)->getValue(icap);
00880           for (int icap2=icap; icap2<4; icap2++) {
00881             RefPedSigs[icap][icap2]=fRefPedestalWidths->getValues(detid)->getSigma(icap,icap2);
00882             if(icap2!=icap)RefPedSigs[icap2][icap]=RefPedSigs[icap][icap2];
00883             widthsp.setSigma(icap2,icap,RefPedSigs[icap2][icap]);
00884           }
00885         }
00886         fValPedestalWidths->addValues(widthsp);
00887         HcalPedestal item(detid,RefPedVals[0],RefPedVals[1],RefPedVals[2],RefPedVals[3]);
00888         fValPedestals->addValues(item);
00889       }
00890     }
00891   }
00892 
00893 // if anything changed, validated set = raw set + reference for missing/bad channels
00894   else {
00895     for (int i=0; i<(int)RawChanns.size(); i++){
00896       detid=HcalDetId(RawChanns[i]);
00897       if (isinRaw[detid]) {
00898         HcalPedestalWidth widthsp(detid);
00899         for (int icap=0; icap<4; icap++) {
00900           RawPedVals[icap]=fRawPedestals->getValues(detid)->getValue(icap);
00901           for (int icap2=icap; icap2<4; icap2++) {
00902             RawPedSigs[icap][icap2]=fRawPedestalWidths->getValues(detid)->getSigma(icap,icap2);
00903             if(icap2!=icap)RawPedSigs[icap2][icap]=RawPedSigs[icap][icap2];
00904             widthsp.setSigma(icap2,icap,RawPedSigs[icap2][icap]);
00905           }
00906         }
00907         fValPedestalWidths->addValues(widthsp);
00908         HcalPedestal item(detid,RawPedVals[0],RawPedVals[1],RawPedVals[2],RawPedVals[3]);
00909         fValPedestals->addValues(item);
00910       }
00911     }
00912   }
00913   return erflag;
00914 }
00915