CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 // Original Author:  Steven Won
00002 //         Created:  Fri May  2 15:34:43 CEST 2008
00003 // Written to replace the combination of HcalPedestalAnalyzer and HcalPedestalAnalysis 
00004 // This code runs 1000x faster and produces all outputs from a single run
00005 // (ADC, fC in .txt plus an .xml file)
00006 //
00007 // $Id: HcalPedestalsAnalysis.cc,v 1.25 2012/11/13 03:30:20 dlange Exp $
00008 
00009 #include <memory>
00010 #include "CalibCalorimetry/HcalStandardModules/interface/HcalPedestalsAnalysis.h"
00011 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00012 
00013 HcalPedestalsAnalysis::HcalPedestalsAnalysis(const edm::ParameterSet& ps) :
00014    hbheDigiCollectionTag_(ps.getParameter<edm::InputTag>("hbheDigiCollectionTag")),
00015    hoDigiCollectionTag_(ps.getParameter<edm::InputTag>("hoDigiCollectionTag")),
00016    hfDigiCollectionTag_(ps.getParameter<edm::InputTag>("hfDigiCollectionTag")) {
00017 
00018    std::cout << "Code version 10.6\n";
00019    hiSaveFlag = ps.getUntrackedParameter<bool>("hiSaveFlag", false);
00020    dumpXML = ps.getUntrackedParameter<bool>("dumpXML", true);
00021    verboseflag = ps.getUntrackedParameter<bool>("verbose", false);
00022    firstTS = ps.getUntrackedParameter<int>("firstTS", 0);
00023    lastTS = ps.getUntrackedParameter<int>("lastTS", 9);   
00024    firsttime = true;
00025    ievt = 0;
00026 
00027    rawPedsItem = 0;
00028    rawWidthsItem = 0;
00029    rawPedsItemfc = 0;
00030    rawWidthsItemfc = 0;
00031 }
00032 
00033 
00034 HcalPedestalsAnalysis::~HcalPedestalsAnalysis()
00035 {}
00036 
00037 void HcalPedestalsAnalysis::endJob()
00038 {
00039 //   std::cout << "NEvents " << ievt << std::endl;
00040    if(ievt < 1000) return;
00041    std::string ievt_string;
00042    std::stringstream tempstringout;
00043    tempstringout << ievt;
00044    ievt_string = tempstringout.str();
00045    pedsADCfilename += ievt_string;
00046    pedsADCfilename += ".txt";
00047    //Calculate pedestal constants
00048    std::cout << "Calculating Pedestal constants...\n";
00049    std::vector<NewPedBunch>::iterator bunch_it;
00050    for(bunch_it=Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
00051    {
00052       if(bunch_it->usedflag){
00053 
00054       if(verboseflag) std::cout << "Analyzing channel " << bunch_it->detid << std::endl;
00055       //pedestal constant is the mean
00056       if(bunch_it->num[0][0]!=0) bunch_it->cap[0] /= bunch_it->num[0][0];
00057       if(bunch_it->num[1][1]!=0) bunch_it->cap[1] /= bunch_it->num[1][1];
00058       if(bunch_it->num[2][2]!=0) bunch_it->cap[2] /= bunch_it->num[2][2];
00059       if(bunch_it->num[3][3]!=0) bunch_it->cap[3] /= bunch_it->num[3][3];
00060       if(bunch_it->num[0][0]!=0) bunch_it->capfc[0] /= bunch_it->num[0][0];
00061       if(bunch_it->num[1][1]!=0) bunch_it->capfc[1] /= bunch_it->num[1][1];
00062       if(bunch_it->num[2][2]!=0) bunch_it->capfc[2] /= bunch_it->num[2][2];
00063       if(bunch_it->num[3][3]!=0) bunch_it->capfc[3] /= bunch_it->num[3][3];
00064       bunch_it->sig[0][0] = (bunch_it->prod[0][0]/bunch_it->num[0][0])-(bunch_it->cap[0]*bunch_it->cap[0]);
00065       bunch_it->sig[0][1] = (bunch_it->prod[0][1]/bunch_it->num[0][1])-(bunch_it->cap[0]*bunch_it->cap[1]);
00066       bunch_it->sig[0][2] = (bunch_it->prod[0][2]/bunch_it->num[0][2])-(bunch_it->cap[0]*bunch_it->cap[2]);
00067       bunch_it->sig[0][3] = (bunch_it->prod[0][3]/bunch_it->num[0][3])-(bunch_it->cap[0]*bunch_it->cap[3]);
00068       bunch_it->sig[1][0] = (bunch_it->prod[1][0]/bunch_it->num[1][0])-(bunch_it->cap[1]*bunch_it->cap[0]);
00069       bunch_it->sig[1][1] = (bunch_it->prod[1][1]/bunch_it->num[1][1])-(bunch_it->cap[1]*bunch_it->cap[1]);
00070       bunch_it->sig[1][2] = (bunch_it->prod[1][2]/bunch_it->num[1][2])-(bunch_it->cap[1]*bunch_it->cap[2]);
00071       bunch_it->sig[1][3] = (bunch_it->prod[1][3]/bunch_it->num[1][3])-(bunch_it->cap[1]*bunch_it->cap[3]);
00072       bunch_it->sig[2][0] = (bunch_it->prod[2][0]/bunch_it->num[2][0])-(bunch_it->cap[2]*bunch_it->cap[0]);
00073       bunch_it->sig[2][1] = (bunch_it->prod[2][1]/bunch_it->num[2][1])-(bunch_it->cap[2]*bunch_it->cap[1]);
00074       bunch_it->sig[2][2] = (bunch_it->prod[2][2]/bunch_it->num[2][2])-(bunch_it->cap[2]*bunch_it->cap[2]);
00075       bunch_it->sig[2][3] = (bunch_it->prod[2][3]/bunch_it->num[2][3])-(bunch_it->cap[2]*bunch_it->cap[3]);
00076       bunch_it->sig[3][0] = (bunch_it->prod[3][0]/bunch_it->num[3][0])-(bunch_it->cap[3]*bunch_it->cap[0]);
00077       bunch_it->sig[3][1] = (bunch_it->prod[3][1]/bunch_it->num[3][1])-(bunch_it->cap[3]*bunch_it->cap[1]);
00078       bunch_it->sig[3][2] = (bunch_it->prod[3][2]/bunch_it->num[3][2])-(bunch_it->cap[3]*bunch_it->cap[2]);
00079       bunch_it->sig[3][3] = (bunch_it->prod[3][3]/bunch_it->num[3][3])-(bunch_it->cap[3]*bunch_it->cap[3]);
00080 
00081       bunch_it->sigfc[0][0] = (bunch_it->prodfc[0][0]/bunch_it->num[0][0])-(bunch_it->capfc[0]*bunch_it->capfc[0]);
00082       bunch_it->sigfc[0][1] = (bunch_it->prodfc[0][1]/bunch_it->num[0][1])-(bunch_it->capfc[0]*bunch_it->capfc[1]);
00083       bunch_it->sigfc[0][2] = (bunch_it->prodfc[0][2]/bunch_it->num[0][2])-(bunch_it->capfc[0]*bunch_it->capfc[2]);
00084       bunch_it->sigfc[0][3] = (bunch_it->prodfc[0][3]/bunch_it->num[0][3])-(bunch_it->capfc[0]*bunch_it->capfc[3]);
00085       bunch_it->sigfc[1][0] = (bunch_it->prodfc[1][0]/bunch_it->num[1][0])-(bunch_it->capfc[1]*bunch_it->capfc[0]);
00086       bunch_it->sigfc[1][1] = (bunch_it->prodfc[1][1]/bunch_it->num[1][1])-(bunch_it->capfc[1]*bunch_it->capfc[1]);
00087       bunch_it->sigfc[1][2] = (bunch_it->prodfc[1][2]/bunch_it->num[1][2])-(bunch_it->capfc[1]*bunch_it->capfc[2]);
00088       bunch_it->sigfc[1][3] = (bunch_it->prodfc[1][3]/bunch_it->num[1][3])-(bunch_it->capfc[1]*bunch_it->capfc[3]);
00089       bunch_it->sigfc[2][0] = (bunch_it->prodfc[2][0]/bunch_it->num[2][0])-(bunch_it->capfc[2]*bunch_it->capfc[0]);
00090       bunch_it->sigfc[2][1] = (bunch_it->prodfc[2][1]/bunch_it->num[2][1])-(bunch_it->capfc[2]*bunch_it->capfc[1]);
00091       bunch_it->sigfc[2][2] = (bunch_it->prodfc[2][2]/bunch_it->num[2][2])-(bunch_it->capfc[2]*bunch_it->capfc[2]);
00092       bunch_it->sigfc[2][3] = (bunch_it->prodfc[2][3]/bunch_it->num[2][3])-(bunch_it->capfc[2]*bunch_it->capfc[3]);
00093       bunch_it->sigfc[3][0] = (bunch_it->prodfc[3][0]/bunch_it->num[3][0])-(bunch_it->capfc[3]*bunch_it->capfc[0]);
00094       bunch_it->sigfc[3][1] = (bunch_it->prodfc[3][1]/bunch_it->num[3][1])-(bunch_it->capfc[3]*bunch_it->capfc[1]);
00095       bunch_it->sigfc[3][2] = (bunch_it->prodfc[3][2]/bunch_it->num[3][2])-(bunch_it->capfc[3]*bunch_it->capfc[2]);
00096       bunch_it->sigfc[3][3] = (bunch_it->prodfc[3][3]/bunch_it->num[3][3])-(bunch_it->capfc[3]*bunch_it->capfc[3]);
00097 
00098       if(bunch_it->detid.subdet() == 1){
00099          for(int i = 0; i != 4; i++){
00100             HBMeans->Fill(bunch_it->cap[i]);
00101             HBWidths->Fill(bunch_it->sig[i][i]);
00102          }
00103       }
00104       if(bunch_it->detid.subdet() == 2){
00105          for(int i = 0; i != 4; i++){
00106             HEMeans->Fill(bunch_it->cap[i]);
00107             HEWidths->Fill(bunch_it->sig[i][i]);
00108          }
00109       }
00110       if(bunch_it->detid.subdet() == 3){
00111          for(int i = 0; i != 4; i++){
00112             HOMeans->Fill(bunch_it->cap[i]);
00113             HOWidths->Fill(bunch_it->sig[i][i]);
00114          }
00115       }
00116       if(bunch_it->detid.subdet() == 4){
00117          for(int i = 0; i != 4; i++){
00118             HFMeans->Fill(bunch_it->cap[i]);
00119             HFWidths->Fill(bunch_it->sig[i][i]);
00120          }
00121       }
00122 
00123       const HcalPedestal item(bunch_it->detid, bunch_it->cap[0], bunch_it->cap[1], bunch_it->cap[2], bunch_it->cap[3],
00124                               bunch_it->sig[0][0], bunch_it->sig[1][1], bunch_it->sig[2][2], bunch_it->sig[3][3]);
00125       rawPedsItem->addValues(item);
00126       HcalPedestalWidth widthsp(bunch_it->detid);
00127       widthsp.setSigma(0,0,bunch_it->sig[0][0]);
00128       widthsp.setSigma(0,1,bunch_it->sig[0][1]);
00129       widthsp.setSigma(0,2,bunch_it->sig[0][2]);
00130       widthsp.setSigma(0,3,bunch_it->sig[0][3]);
00131       widthsp.setSigma(1,1,bunch_it->sig[1][1]);
00132       widthsp.setSigma(1,2,bunch_it->sig[1][2]);
00133       widthsp.setSigma(1,3,bunch_it->sig[1][3]);
00134       widthsp.setSigma(2,2,bunch_it->sig[2][2]);
00135       widthsp.setSigma(2,3,bunch_it->sig[2][3]);
00136       widthsp.setSigma(3,3,bunch_it->sig[3][3]);
00137       rawWidthsItem->addValues(widthsp);
00138 
00139       const HcalPedestal itemfc(bunch_it->detid, bunch_it->capfc[0], bunch_it->capfc[1], bunch_it->capfc[2], bunch_it->capfc[3],
00140                               bunch_it->sigfc[0][0], bunch_it->sigfc[1][1], bunch_it->sigfc[2][2], bunch_it->sigfc[3][3]);
00141       rawPedsItemfc->addValues(itemfc);
00142       HcalPedestalWidth widthspfc(bunch_it->detid);
00143       widthspfc.setSigma(0,0,bunch_it->sigfc[0][0]);
00144       widthspfc.setSigma(0,1,bunch_it->sigfc[0][1]);
00145       widthspfc.setSigma(0,2,bunch_it->sigfc[0][2]);
00146       widthspfc.setSigma(0,3,bunch_it->sigfc[0][3]);
00147       widthspfc.setSigma(1,1,bunch_it->sigfc[1][1]);
00148       widthspfc.setSigma(1,2,bunch_it->sigfc[1][2]);
00149       widthspfc.setSigma(1,3,bunch_it->sigfc[1][3]);
00150       widthspfc.setSigma(2,2,bunch_it->sigfc[2][2]);
00151       widthspfc.setSigma(2,3,bunch_it->sigfc[2][3]);
00152       widthspfc.setSigma(3,3,bunch_it->sigfc[3][3]);
00153       rawWidthsItemfc->addValues(widthspfc);
00154       }
00155    }
00156 
00157     // dump the resulting list of pedestals into a file
00158     std::ofstream outStream1(pedsADCfilename.c_str());
00159     HcalDbASCIIIO::dumpObject (outStream1, (*rawPedsItem) );
00160 //    std::ofstream outStream2(widthsADCfilename.c_str());
00161 //    HcalDbASCIIIO::dumpObject (outStream2, (*rawWidthsItem) );
00162 //
00163 //    std::ofstream outStream3(pedsfCfilename.c_str());
00164 //    HcalDbASCIIIO::dumpObject (outStream3, (*rawPedsItemfc) );
00165 //    std::ofstream outStream4(widthsfCfilename.c_str());
00166 //    HcalDbASCIIIO::dumpObject (outStream4, (*rawWidthsItemfc) );
00167 //
00168 //    if(dumpXML){
00169 //       std::ofstream outStream5(XMLfilename.c_str());
00170 //       HcalDbXml::dumpObject (outStream5, runnum, 0, 2147483647, XMLtag, 1, (*rawPedsItem), (*rawWidthsItem)); 
00171 //    }
00172 //
00173     if(hiSaveFlag){
00174        theFile->Write();
00175     }else{
00176        theFile->cd();
00177        theFile->cd("HB");
00178        HBMeans->Write();
00179        HBWidths->Write();
00180        theFile->cd();
00181        theFile->cd("HF");
00182        HFMeans->Write();
00183        HFWidths->Write();
00184        theFile->cd();
00185        theFile->cd("HE");
00186        HEMeans->Write();
00187        HEWidths->Write();
00188        theFile->cd();
00189        theFile->cd("HO");
00190        HOMeans->Write();
00191        HOWidths->Write();
00192     }
00193 
00194     std::cout << "Writing ROOT file... ";
00195     theFile->Close();
00196     std::cout << "ROOT file closed.\n";
00197     
00198     delete rawPedsItem;
00199     delete rawWidthsItem;
00200     delete rawPedsItemfc;
00201     delete rawWidthsItemfc;   
00202 }
00203 
00204 // ------------ method called to for each event  ------------
00205 void
00206 HcalPedestalsAnalysis::analyze(const edm::Event& e, const edm::EventSetup& iSetup)
00207 {
00208    using namespace edm;
00209    using namespace std;
00210 
00211    edm::Handle<HBHEDigiCollection> hbhe;              e.getByLabel(hbheDigiCollectionTag_, hbhe);
00212    edm::Handle<HODigiCollection> ho;                  e.getByLabel(hoDigiCollectionTag_, ho);
00213    edm::Handle<HFDigiCollection> hf;                  e.getByLabel(hfDigiCollectionTag_, hf);
00214    edm::ESHandle<HcalDbService> conditions;
00215    iSetup.get<HcalDbRecord>().get(conditions);
00216 
00217 
00218    if(firsttime)
00219    {
00220 
00221      edm::ESHandle<HcalTopology> topology;
00222      iSetup.get<IdealGeometryRecord>().get( topology );
00223      theTopology=new HcalTopology(*topology);
00224 
00225      rawPedsItem = new HcalPedestals(theTopology,true);
00226      rawWidthsItem = new HcalPedestalWidths(theTopology,true);
00227      rawPedsItemfc = new HcalPedestals(theTopology,false);
00228      rawWidthsItemfc = new HcalPedestalWidths(theTopology,false);
00229 
00230       runnum = e.id().run();
00231       std::string runnum_string;
00232       std::stringstream tempstringout;
00233       tempstringout << runnum;
00234       runnum_string = tempstringout.str();
00235       ROOTfilename = runnum_string + "-peds_ADC.root";
00236       pedsADCfilename = runnum_string + "-peds_ADC_";
00237       pedsfCfilename = runnum_string + "-peds_fC.txt";
00238       widthsADCfilename = runnum_string + "-widths_ADC.txt";
00239       widthsfCfilename = runnum_string + "-widths_fC.txt";
00240       XMLfilename = runnum_string + "-peds_ADC_complete.xml"; 
00241       XMLtag = "Hcal_pedestals_" + runnum_string;
00242 
00243       theFile = new TFile(ROOTfilename.c_str(), "RECREATE");
00244       theFile->cd();
00245       // Create sub-directories
00246       theFile->mkdir("HB"); 
00247       theFile->mkdir("HE");
00248       theFile->mkdir("HF");
00249       theFile->mkdir("HO");
00250       theFile->cd();
00251 
00252       HBMeans = new TH1F("All Ped Means HB","All Ped Means HB", 100, 0, 9);
00253       HBWidths = new TH1F("All Ped Widths HB","All Ped Widths HB", 100, 0, 3);
00254       HEMeans = new TH1F("All Ped Means HE","All Ped Means HE", 100, 0, 9);
00255       HEWidths = new TH1F("All Ped Widths HE","All Ped Widths HE", 100, 0, 3);
00256       HFMeans = new TH1F("All Ped Means HF","All Ped Means HF", 100, 0, 9);
00257       HFWidths = new TH1F("All Ped Widths HF","All Ped Widths HF", 100, 0, 3);
00258       HOMeans = new TH1F("All Ped Means HO","All Ped Means HO", 100, 0, 9);
00259       HOWidths = new TH1F("All Ped Widths HO","All Ped Widths HO", 100, 0, 3);
00260 
00261       edm::ESHandle<HcalElectronicsMap> refEMap;
00262       iSetup.get<HcalElectronicsMapRcd>().get(refEMap);
00263       const HcalElectronicsMap* myRefEMap = refEMap.product();
00264       std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
00265       for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
00266       {     
00267          HcalGenericDetId mygenid(it->rawId());
00268          if(mygenid.isHcalDetId())
00269          {
00270             NewPedBunch a;
00271             HcalDetId chanid(mygenid.rawId());
00272             a.detid = chanid;
00273             a.usedflag = false;
00274             for(int i = 0; i != 4; i++)
00275             {
00276                a.cap[i] = 0;
00277                a.capfc[i] = 0;
00278                for(int j = 0; j != 4; j++)
00279                {
00280                   a.sig[i][j] = 0;
00281                   a.sigfc[i][j] = 0;
00282                   a.prod[i][j] = 0;
00283                   a.prodfc[i][j] = 0;
00284                   a.num[i][j] = 0;
00285                }
00286             }
00287             Bunches.push_back(a);
00288          }
00289       }
00290       firsttime = false;
00291    }
00292 
00293    std::vector<NewPedBunch>::iterator bunch_it;
00294 
00295    for(HBHEDigiCollection::const_iterator j = hbhe->begin(); j != hbhe->end(); j++)
00296    {
00297       const HBHEDataFrame digi = (const HBHEDataFrame)(*j);
00298       for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
00299          if(bunch_it->detid.rawId() == digi.id().rawId()) break;
00300       bunch_it->usedflag = true;
00301       for(int ts = firstTS; ts != lastTS+1; ts++)
00302       {
00303          const HcalQIECoder* coder = conditions->getHcalCoder(digi.id().rawId());
00304          const HcalQIEShape* shape = conditions->getHcalShape(coder);
00305          bunch_it->num[digi.sample(ts).capid()][digi.sample(ts).capid()] += 1;
00306          bunch_it->cap[digi.sample(ts).capid()] += digi.sample(ts).adc();
00307          double charge1 = coder->charge(*shape, digi.sample(ts).adc(), digi.sample(ts).capid());
00308          bunch_it->capfc[digi.sample(ts).capid()] += charge1;
00309          bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts).capid()] += (digi.sample(ts).adc() * digi.sample(ts).adc());
00310          bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts).capid()] += charge1 * charge1;
00311          if((ts+1 < digi.size()) && (ts+1 < lastTS)){
00312             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += digi.sample(ts).adc()*digi.sample(ts+1).adc();
00313             double charge2 = coder->charge(*shape, digi.sample(ts+1).adc(), digi.sample(ts+1).capid());
00314             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += charge1*charge2;
00315             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += 1;
00316          }
00317          if((ts+2 < digi.size()) && (ts+2 < lastTS)){
00318             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += digi.sample(ts).adc()*digi.sample(ts+2).adc();
00319             double charge2 = coder->charge(*shape, digi.sample(ts+2).adc(), digi.sample(ts+2).capid());
00320             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += charge1*charge2;
00321             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += 1;
00322          }
00323          if((ts+3 < digi.size()) && (ts+3 < lastTS)){
00324             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += digi.sample(ts).adc()*digi.sample(ts+3).adc();
00325             double charge2 = coder->charge(*shape, digi.sample(ts+3).adc(), digi.sample(ts+3).capid());
00326             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += charge1*charge2;
00327             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += 1;
00328          }
00329       }
00330    }
00331 
00332    for(HODigiCollection::const_iterator j = ho->begin(); j != ho->end(); j++)
00333    {
00334       const HODataFrame digi = (const HODataFrame)(*j);
00335       for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
00336          if(bunch_it->detid.rawId() == digi.id().rawId()) break;
00337       bunch_it->usedflag = true;
00338       for(int ts = firstTS; ts <= lastTS; ts++)
00339       {
00340          const HcalQIECoder* coder = conditions->getHcalCoder(digi.id().rawId());
00341          const HcalQIEShape* shape = conditions->getHcalShape(coder);
00342          bunch_it->num[digi.sample(ts).capid()][digi.sample(ts).capid()] += 1;
00343          bunch_it->cap[digi.sample(ts).capid()] += digi.sample(ts).adc();
00344          double charge1 = coder->charge(*shape, digi.sample(ts).adc(), digi.sample(ts).capid());
00345          bunch_it->capfc[digi.sample(ts).capid()] += charge1;
00346          bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts).capid()] += (digi.sample(ts).adc() * digi.sample(ts).adc());
00347          bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts).capid()] += charge1 * charge1;
00348          if((ts+1 < digi.size()) && (ts+1 < lastTS)){
00349             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += digi.sample(ts).adc()*digi.sample(ts+1).adc();
00350             double charge2 = coder->charge(*shape, digi.sample(ts+1).adc(), digi.sample(ts+1).capid());
00351             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += charge1*charge2;
00352             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += 1;
00353          }
00354          if((ts+2 < digi.size()) && (ts+2 < lastTS)){
00355             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += digi.sample(ts).adc()*digi.sample(ts+2).adc();
00356             double charge2 = coder->charge(*shape, digi.sample(ts+2).adc(), digi.sample(ts+2).capid());
00357             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += charge1*charge2;
00358             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += 1;
00359          }
00360          if((ts+3 < digi.size()) && (ts+3 < lastTS)){
00361             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += digi.sample(ts).adc()*digi.sample(ts+3).adc();
00362             double charge2 = coder->charge(*shape, digi.sample(ts+3).adc(), digi.sample(ts+3).capid());
00363             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += charge1*charge2;
00364             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += 1;
00365          }
00366       }
00367    }
00368 
00369    for(HFDigiCollection::const_iterator j = hf->begin(); j != hf->end(); j++)
00370    {
00371       const HFDataFrame digi = (const HFDataFrame)(*j);
00372       for(bunch_it = Bunches.begin(); bunch_it != Bunches.end(); bunch_it++)
00373          if(bunch_it->detid.rawId() == digi.id().rawId()) break;
00374       bunch_it->usedflag = true;
00375       for(int ts = firstTS; ts <= lastTS; ts++)
00376       {
00377          const HcalQIECoder* coder = conditions->getHcalCoder(digi.id().rawId());
00378          const HcalQIEShape* shape = conditions->getHcalShape(coder);
00379          bunch_it->num[digi.sample(ts).capid()][digi.sample(ts).capid()] += 1;
00380          bunch_it->cap[digi.sample(ts).capid()] += digi.sample(ts).adc();
00381          double charge1 = coder->charge(*shape, digi.sample(ts).adc(), digi.sample(ts).capid());
00382          bunch_it->capfc[digi.sample(ts).capid()] += charge1;
00383          bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts).capid()] += (digi.sample(ts).adc() * digi.sample(ts).adc());
00384          bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts).capid()] += charge1 * charge1;
00385          if((ts+1 < digi.size()) && (ts+1 < lastTS)){
00386             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += digi.sample(ts).adc()*digi.sample(ts+1).adc();
00387             double charge2 = coder->charge(*shape, digi.sample(ts+1).adc(), digi.sample(ts+1).capid());
00388             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += charge1*charge2;
00389             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+1).capid()] += 1;
00390          }
00391          if((ts+2 < digi.size()) && (ts+2 < lastTS)){
00392             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += digi.sample(ts).adc()*digi.sample(ts+2).adc();
00393             double charge2 = coder->charge(*shape, digi.sample(ts+2).adc(), digi.sample(ts+2).capid());
00394             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += charge1*charge2;
00395             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+2).capid()] += 1;
00396          }
00397          if((ts+3 < digi.size()) && (ts+3 < lastTS)){
00398             bunch_it->prod[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += digi.sample(ts).adc()*digi.sample(ts+3).adc();
00399             double charge2 = coder->charge(*shape, digi.sample(ts+3).adc(), digi.sample(ts+3).capid());
00400             bunch_it->prodfc[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += charge1*charge2;
00401             bunch_it->num[digi.sample(ts).capid()][digi.sample(ts+3).capid()] += 1;
00402          }
00403       }
00404    }
00405 
00406 //this is the last brace
00407 ievt++;
00408 }
00409 
00410 //define this as a plug-in
00411 DEFINE_FWK_MODULE(HcalPedestalsAnalysis);