CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/RecoTBCalo/HcalPlotter/src/HcalQLPlotAnalAlgos.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HcalQLPlotAnal
00004 // Class:      HcalQLPlotAnal
00005 // 
00013 //
00014 // Original Author:  Phillip R. Dudero
00015 //         Created:  Tue Jan 16 21:11:37 CST 2007
00016 // $Id: HcalQLPlotAnalAlgos.cc,v 1.4 2008/01/05 22:27:39 elmer Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <math.h>
00024 
00025 // user include files
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 #include "FWCore/Utilities/interface/Exception.h"
00028 #include "RecoTBCalo/HcalPlotter/src/HcalQLPlotAnalAlgos.h"
00029 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
00030 #include "DataFormats/HcalRecHit/interface/HcalCalibRecHit.h"
00031 #include "TH1.h"
00032 
00033 //
00034 // constants, enums and typedefs
00035 //
00036 
00037 //
00038 // static data member definitions
00039 //
00040 
00041 //
00042 // constructors and destructor
00043 //
00044 HcalQLPlotAnalAlgos::HcalQLPlotAnalAlgos(const char *outputFilename,
00045                                          edm::ParameterSet histoParams)
00046 {
00047   triggerID_=HcalQLPlotHistoMgr::UNKNOWN;
00048 
00049   mf_     = new TFile(outputFilename,"RECREATE");
00050   histos_ = new HcalQLPlotHistoMgr(mf_,histoParams);
00051 }
00052 
00053 
00054 //
00055 // member functions
00056 //
00057 
00058 void HcalQLPlotAnalAlgos::end(void)
00059 {
00060   mf_->Write();
00061 }
00062 
00063 void HcalQLPlotAnalAlgos::SetEventType(const HcalTBTriggerData& trigd)
00064 {
00065   if( trigd.wasInSpillPedestalTrigger()  ||
00066       trigd.wasOutSpillPedestalTrigger() ||
00067       trigd.wasSpillIgnorantPedestalTrigger() )
00068                                 triggerID_=HcalQLPlotHistoMgr::PEDESTAL;
00069   if( trigd.wasLEDTrigger() )   triggerID_=HcalQLPlotHistoMgr::LED;
00070   if( trigd.wasLaserTrigger() ) triggerID_=HcalQLPlotHistoMgr::LASER;
00071   if( trigd.wasBeamTrigger() )  triggerID_=HcalQLPlotHistoMgr::BEAM;
00072 
00073   if( triggerID_ == HcalQLPlotHistoMgr::UNKNOWN) {
00074     edm::LogError("HcalQLPlotAnalAlgos::begin") <<
00075       "Trigger Type unrecognized, aborting";
00076     std::exception e;
00077     throw e;
00078   }
00079 }
00080 
00081 void HcalQLPlotAnalAlgos::processRH(const HBHERecHitCollection& hbherhc,
00082                                     const HBHEDigiCollection& hbhedgc)
00083 {
00084   HBHERecHitCollection::const_iterator it;
00085 
00086   for (it  = hbherhc.begin(); 
00087        it != hbherhc.end();
00088        it++) {
00089     HcalDetId id (it->id());
00090     HcalElectronicsId eid;
00091     HBHEDigiCollection::const_iterator dit = hbhedgc.find(id);
00092     if (dit != hbhedgc.end())
00093       eid = dit->elecId();
00094     else {
00095       edm::LogWarning("HcalQLPlotAnalAlgos::processRH") <<
00096         "No digi found for id" << id;
00097       continue;
00098     }
00099 
00100     TH1* ehist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::ENERGY,triggerID_);
00101     if (ehist){
00102       ehist->Fill(it->energy());
00103     }
00104 
00105     TH1* thist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::TIME,triggerID_);
00106     if (thist){
00107       thist->Fill(it->time());
00108     }
00109   }
00110 }
00111 
00112 void HcalQLPlotAnalAlgos::processRH(const HORecHitCollection& horhc,
00113                                     const HODigiCollection& hodgc)
00114 {
00115   HORecHitCollection::const_iterator it;
00116 
00117   for (it  = horhc.begin(); 
00118        it != horhc.end();
00119        it++) {
00120     HcalDetId id (it->id());
00121     HcalElectronicsId eid;
00122     HODigiCollection::const_iterator dit = hodgc.find(id);
00123     if (dit != hodgc.end())
00124       eid = dit->elecId();
00125     else {
00126       edm::LogWarning("HcalQLPlotAnalAlgos::processRH") <<
00127         "No digi found for id" << id;
00128       continue;
00129     }
00130 
00131     TH1* ehist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::ENERGY,triggerID_);
00132     if (ehist){
00133       ehist->Fill(it->energy());
00134     }
00135 
00136     TH1* thist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::TIME,triggerID_);
00137     if (thist){
00138       thist->Fill(it->time());
00139     }
00140   }
00141 }
00142 
00143 void HcalQLPlotAnalAlgos::processRH(const HFRecHitCollection& hfrhc,
00144                                     const HFDigiCollection& hfdgc)
00145 {
00146   HFRecHitCollection::const_iterator it;
00147 
00148   for (it  = hfrhc.begin(); 
00149        it != hfrhc.end();
00150        it++) {
00151     HcalDetId id (it->id());
00152     HcalElectronicsId eid;
00153     HFDigiCollection::const_iterator dit = hfdgc.find(id);
00154     if (dit != hfdgc.end())
00155       eid = dit->elecId();
00156     else {
00157       edm::LogWarning("HcalQLPlotAnalAlgos::processRH") <<
00158         "No digi found for id" << id;
00159       continue;
00160     }
00161 
00162     TH1* ehist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::ENERGY,triggerID_);
00163     if (ehist){
00164       ehist->Fill(it->energy());
00165     }
00166 
00167     TH1* thist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::TIME,triggerID_);
00168     if (thist){
00169       thist->Fill(it->time());
00170     }
00171   }
00172 }
00173 
00174 void HcalQLPlotAnalAlgos::processDigi(const HBHEDigiCollection& hbhedigic)
00175 {
00176   HBHEDigiCollection::const_iterator it;
00177 
00178   for (it  = hbhedigic.begin(); 
00179        it != hbhedigic.end();
00180        it++) {
00181     HcalDetId id (it->id());
00182     HcalElectronicsId eid (it->elecId());
00183 
00184     TH1* phist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::PULSE,triggerID_);
00185     if (phist){
00186       for (int bin=0; bin<it->size(); bin++)
00187         phist->Fill(bin*1.0,(*it)[bin].nominal_fC());
00188     }
00189 
00190     if (triggerID_ == HcalQLPlotHistoMgr::PEDESTAL) {
00191       phist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::ADC,triggerID_);
00192       if (phist){
00193         for (int bin=0; bin<it->size(); bin++)
00194           phist->Fill((*it)[bin].adc());
00195       }
00196     }
00197   }
00198 }
00199 
00200 void HcalQLPlotAnalAlgos::processDigi(const HODigiCollection& hodigic)
00201 {
00202   HODigiCollection::const_iterator it;
00203 
00204   for (it  = hodigic.begin(); 
00205        it != hodigic.end();
00206        it++) {
00207     HcalDetId id (it->id());
00208     HcalElectronicsId eid (it->elecId());
00209 
00210     TH1* phist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::PULSE,triggerID_);
00211     if (phist){
00212       for (int bin=0; bin<it->size(); bin++)
00213         phist->Fill(bin*1.0,(*it)[bin].nominal_fC());
00214     }
00215 
00216     if (triggerID_ == HcalQLPlotHistoMgr::PEDESTAL) {
00217       phist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::ADC,triggerID_);
00218       if (phist){
00219         for (int bin=0; bin<it->size(); bin++)
00220           phist->Fill((*it)[bin].adc());
00221       }
00222     }
00223   }
00224 }
00225 
00226 void HcalQLPlotAnalAlgos::processDigi(const HFDigiCollection& hfdigic)
00227 {
00228   HFDigiCollection::const_iterator it;
00229 
00230   for (it  = hfdigic.begin(); 
00231        it != hfdigic.end();
00232        it++) {
00233     HcalDetId id (it->id());
00234     HcalElectronicsId eid (it->elecId());
00235 
00236     TH1* phist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::PULSE,triggerID_);
00237     if (phist){
00238       for (int bin=0; bin<it->size(); bin++)
00239         phist->Fill(bin*1.0,(*it)[bin].nominal_fC());
00240     }
00241 
00242     if (triggerID_ == HcalQLPlotHistoMgr::PEDESTAL) {
00243       phist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::ADC,triggerID_);
00244       if (phist){
00245         for (int bin=0; bin<it->size(); bin++)
00246           phist->Fill((*it)[bin].adc());
00247       }
00248     }
00249   }
00250 }
00251 
00252 HcalCalibRecHit HcalQLPlotAnalAlgos::recoCalib(const HcalCalibDataFrame& cdigi,
00253                                                double calibFC2GeV)
00254 {
00255   double nominal_ped = (cdigi[0].nominal_fC() + cdigi[1].nominal_fC())/2.0;
00256 
00257   double totamp = 0.0;
00258   double maxA = -1e99;
00259   int    maxI = -1;
00260   for (int i=0; i<cdigi.size(); i++) {
00261     double ampl = (cdigi[i].nominal_fC()-nominal_ped)*calibFC2GeV;
00262     totamp += ampl;
00263 
00264     if (ampl > maxA) {
00265       maxA = ampl;
00266       maxI = i;
00267     }
00268   }
00269 
00270   maxA=fabs(maxA);
00271   float t0 = (maxI > 0) ? (fabs((cdigi[maxI-1].nominal_fC()-nominal_ped))*calibFC2GeV):0.0;
00272   float t2 = fabs((cdigi[maxI+1].nominal_fC()-nominal_ped)*calibFC2GeV);    
00273   float wpksamp = (maxA + 2.0*t2) / (t0 + maxA + t2);
00274   float time = (maxI - cdigi.presamples() + wpksamp)*25.0;
00275 
00276   return HcalCalibRecHit(cdigi.id(),totamp,time);    
00277 }
00278 
00279 void HcalQLPlotAnalAlgos::processDigi(const HcalCalibDigiCollection& calibdigic,
00280                                       double calibFC2GeV)
00281 {
00282   HcalCalibDigiCollection::const_iterator it;
00283 
00284   for (it  = calibdigic.begin(); 
00285        it != calibdigic.end();
00286        it++) {
00287     HcalCalibDetId     id (it->id());
00288     HcalElectronicsId eid (it->elecId());
00289 
00290     TH1* phist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::PULSE,triggerID_);
00291     if (phist){
00292       for (int bin=0; bin<it->size(); bin++)
00293         phist->Fill(bin*1.0,(*it)[bin].nominal_fC());
00294     }
00295 
00296     // HACK-reco the calib digi into a rechit:
00297     //
00298     HcalCalibRecHit rh = recoCalib(*it, calibFC2GeV);
00299 
00300     TH1* ehist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::ENERGY,triggerID_);
00301     if (ehist){
00302       ehist->Fill(rh.amplitude());
00303     }
00304 
00305     TH1* thist=histos_->GetAHistogram(id,eid,HcalQLPlotHistoMgr::TIME,triggerID_);
00306     if (thist){
00307       thist->Fill(rh.time());
00308     }
00309   }
00310 }
00311