CMS 3D CMS Logo

EcalRecHitProducer.cc

Go to the documentation of this file.
00001 
00010 #include "RecoLocalCalo/EcalRecProducers/interface/EcalRecHitProducer.h"
00011 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalRecHitSimpleAlgo.h"
00012 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00013 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00014 #include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h"
00015 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
00016 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00017 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00018 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
00019 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"
00020 
00021 #include "DataFormats/Common/interface/Handle.h"
00022 #include "FWCore/Framework/interface/ESHandle.h"
00023 
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 
00026 #include <iostream>
00027 #include <cmath>
00028 #include <vector>
00029 
00030 //#include "CondFormats/EcalObjects/interface/EcalPedestals.h"
00031 //#include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
00032 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00033 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00034 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00035 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00036 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00037 
00038 
00039 
00040 EcalRecHitProducer::EcalRecHitProducer(const edm::ParameterSet& ps) {
00041 
00042    EBuncalibRecHitCollection_ = ps.getParameter<edm::InputTag>("EBuncalibRecHitCollection");
00043    EEuncalibRecHitCollection_ = ps.getParameter<edm::InputTag>("EEuncalibRecHitCollection");
00044    EBrechitCollection_        = ps.getParameter<std::string>("EBrechitCollection");
00045    EErechitCollection_        = ps.getParameter<std::string>("EErechitCollection");
00046    //   nMaxPrintout_            = ps.getUntrackedParameter<int>("nMaxPrintout",10);
00047 
00048    EBalgo_ = new EcalRecHitSimpleAlgo();
00049    EEalgo_ = new EcalRecHitSimpleAlgo();
00050 
00051    produces< EBRecHitCollection >(EBrechitCollection_);
00052    produces< EERecHitCollection >(EErechitCollection_);
00053 
00054    v_chstatus_ = ps.getParameter<std::vector<int> >("ChannelStatusToBeExcluded");
00055    //   nEvt_ = 0; // reset local event counter
00056 }
00057 
00058 EcalRecHitProducer::~EcalRecHitProducer() {
00059 
00060   if (EBalgo_) delete EBalgo_;
00061   if (EEalgo_) delete EEalgo_;
00062 
00063 }
00064 
00065 void
00066 EcalRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
00067 
00068    using namespace edm;
00069 
00070    //   nEvt_++;
00071 
00072    Handle< EBUncalibratedRecHitCollection > pEBUncalibRecHits;
00073    Handle< EEUncalibratedRecHitCollection > pEEUncalibRecHits;
00074 
00075    const EBUncalibratedRecHitCollection*  EBuncalibRecHits = 0;
00076    const EEUncalibratedRecHitCollection*  EEuncalibRecHits = 0; 
00077 
00078    if ( EBuncalibRecHitCollection_.label() != "" && EBuncalibRecHitCollection_.instance() != "" ) {
00079            evt.getByLabel( EBuncalibRecHitCollection_, pEBUncalibRecHits);
00080            if ( pEBUncalibRecHits.isValid() ) {
00081                    EBuncalibRecHits = pEBUncalibRecHits.product(); // get a ptr to the product
00082 #ifdef DEBUG
00083                    LogDebug("EcalRecHitDebug") << "total # EB uncalibrated rechits: " << EBuncalibRecHits->size();
00084 #endif
00085            } else {
00086                    edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBuncalibRecHitCollection_;
00087            }
00088    }
00089 
00090    if ( EEuncalibRecHitCollection_.label() != "" && EEuncalibRecHitCollection_.instance() != "" ) {
00091            evt.getByLabel( EEuncalibRecHitCollection_, pEEUncalibRecHits);
00092            if ( pEEUncalibRecHits.isValid() ) {
00093                    EEuncalibRecHits = pEEUncalibRecHits.product(); // get a ptr to the product
00094 #ifdef DEBUG
00095                    LogDebug("EcalRecHitDebug") << "total # EE uncalibrated rechits: " << EEuncalibRecHits->size();
00096 #endif
00097            } else {
00098                    edm::LogError("EcalRecHitError") << "Error! can't get the product " << EEuncalibRecHitCollection_;
00099            }
00100    }
00101 
00102    // collection of rechits to put in the event
00103    std::auto_ptr< EBRecHitCollection > EBrechits( new EBRecHitCollection );
00104    std::auto_ptr< EERecHitCollection > EErechits( new EERecHitCollection );
00105 
00106    // now fetch all conditions we nEEd to make rechits
00107    edm::ESHandle<EcalADCToGeVConstant> pAgc;
00108    es.get<EcalADCToGeVConstantRcd>().get(pAgc);
00109    const EcalADCToGeVConstant* agc = pAgc.product();
00110    //
00111    // use this value in the algorithm
00112    EBalgo_->setADCToGeVConstant(float(agc->getEBValue()));
00113    EEalgo_->setADCToGeVConstant(float(agc->getEEValue()));
00114    // Intercalib constants
00115    edm::ESHandle<EcalIntercalibConstants> pIcal;
00116    es.get<EcalIntercalibConstantsRcd>().get(pIcal);
00117    const EcalIntercalibConstants* ical = pIcal.product();
00118    const EcalIntercalibConstantMap& icalMap=ical->getMap();
00119 #ifdef DEBUG
00120    LogDebug("EcalRecHitDebug") << "Global EB ADC->GeV scale: " << agc->getEBValue() << " GeV/ADC count" ;
00121 #endif
00122    // ADC -> GeV Scale
00123 
00124    edm::ESHandle<EcalLaserDbService> pLaser;
00125    es.get<EcalLaserDbRecord>().get( pLaser );
00126 
00127    // channel status map
00128    edm::ESHandle<EcalChannelStatus> pChStatus;
00129    es.get<EcalChannelStatusRcd>().get( pChStatus );
00130    const EcalChannelStatus* chStatus = pChStatus.product();
00131 
00132    if (EBuncalibRecHits)
00133      {
00134        
00135        // loop over uncalibrated rechits to make calibrated ones
00136        for(EBUncalibratedRecHitCollection::const_iterator it  = EBuncalibRecHits->begin(); it != EBuncalibRecHits->end(); ++it) {
00137          
00138          // check if status flag is valid -- FIXME: specialize flags
00139          EcalChannelStatusMap::const_iterator chit = chStatus->find(it->id());
00140          EcalChannelStatusCode chStatusCode = 1;
00141          if ( chit != chStatus->end() ) {
00142                  chStatusCode = *chit;
00143          } else {
00144                  edm::LogError("EcalRecHitError") << "No channel status found for xtal " << EBDetId(it->id()) << "! something wrong with EcalChannelStatus in your DB? ";
00145          }
00146          if ( v_chstatus_.size() > 0) {
00147                  std::vector<int>::const_iterator res = std::find( v_chstatus_.begin(), v_chstatus_.end(), chStatusCode.getStatusCode() );
00148                  if ( res != v_chstatus_.end() ) {
00149                          continue;
00150                  }
00151          }
00152 
00153          // find intercalib constant for this xtal
00154          EcalIntercalibConstantMap::const_iterator icalit=icalMap.find(it->id());
00155          EcalIntercalibConstant icalconst = 1;
00156          if( icalit!=icalMap.end() ){
00157            icalconst = (*icalit);
00158            //      LogDebug("EcalRecHitDebug") << "Found intercalib for xtal " << EBDetId(it->id()).ic() << " " << icalconst ;
00159          } else {
00160            edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(it->id()) << "! something wrong with EcalIntercalibConstants in your DB? " ;
00161          }
00162          // get laser coefficient
00163          float lasercalib = pLaser->getLaserCorrection( EBDetId(it->id()), evt.time() );
00164          
00165          // make the rechit and put in the output collection
00166          // must implement op= for EcalRecHit
00167          EcalRecHit aHit( EBalgo_->makeRecHit(*it, icalconst * lasercalib) );
00168          EBrechits->push_back( aHit );
00169          
00170 #ifdef DEBUG     
00171          if(it->amplitude()>0.) 
00172            {
00173              LogDebug("EcalRecHitDebug") << "processed UncalibRecHit with rawId: "
00174                                              << it->id().rawId() << "\n"
00175                                              << "uncalib rechit amplitude: " << it->amplitude()
00176                                              << " calib rechit energy: " << aHit.energy()
00177                ;
00178            }
00179 #endif
00180        }
00181      }
00182 
00183    if (EEuncalibRecHits)
00184      {
00185        // loop over uncalibrated rechits to make calibrated ones
00186        for(EEUncalibratedRecHitCollection::const_iterator it  = EEuncalibRecHits->begin(); it != EEuncalibRecHits->end(); ++it) {
00187          
00188          // check if status flag is valid -- FIXME: specialize flags
00189          EcalChannelStatusMap::const_iterator chit = chStatus->find(it->id());
00190          EcalChannelStatusCode chStatusCode = 1;
00191          if ( chit != chStatus->end() ) {
00192                  chStatusCode = *chit;
00193          } else {
00194                  edm::LogError("EcalRecHitError") << "No channel status found for xtal " << EBDetId(it->id()) << "! something wrong with EcalChannelStatus in your DB? ";
00195          }
00196          if ( v_chstatus_.size() > 0) {
00197                  std::vector<int>::const_iterator res = std::find( v_chstatus_.begin(), v_chstatus_.end(), chStatusCode.getStatusCode() );
00198                  if ( res != v_chstatus_.end() ) {
00199                          continue;
00200                  }
00201          }
00202 
00203          // find intercalib constant for this xtal
00204          EcalIntercalibConstantMap::const_iterator icalit=icalMap.find(it->id());
00205          EcalIntercalibConstant icalconst = 1;
00206          if( icalit!=icalMap.end() ){
00207            icalconst = (*icalit);
00208            // LogDebug("EcalRecHitDebug") << "Found intercalib for xtal " << EEDetId(it->id()).ic() << " " << icalconst ;
00209          } else {
00210            edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EEDetId(it->id()) << "! something wrong with EcalIntercalibConstants in your DB? "
00211              ;
00212          }
00213          // get laser coefficient
00214          float lasercalib = pLaser->getLaserCorrection( EEDetId(it->id()), evt.time() );
00215          
00216          // make the rechit and put in the output collection
00217          // must implement op= for EcalRecHit
00218          EcalRecHit aHit( EEalgo_->makeRecHit(*it, icalconst * lasercalib) );
00219          EErechits->push_back( aHit );
00220          
00221 #ifdef DEBUG
00222          if(it->amplitude()>0.) 
00223            {
00224              LogDebug("EcalRecHitDebug") << "processed UncalibRecHit with rawId: "
00225                                              << it->id().rawId() << "\n"
00226                                              << "uncalib rechit amplitude: " << it->amplitude()
00227                                              << " calib rechit energy: " << aHit.energy()
00228                ;
00229            }
00230 #endif
00231        }
00232      }
00233    // put the collection of recunstructed hits in the event   
00234    LogInfo("EcalRecHitInfo") << "total # EB calibrated rechits: " << EBrechits->size()
00235      ;
00236    LogInfo("EcalRecHitInfo") << "total # EE calibrated rechits: " << EErechits->size()
00237      ;
00238 
00239    evt.put( EBrechits, EBrechitCollection_ );
00240    evt.put( EErechits, EErechitCollection_ );
00241 } //produce()
00242 

Generated on Tue Jun 9 17:43:47 2009 for CMSSW by  doxygen 1.5.4