CMS 3D CMS Logo

EcalWeightUncalibRecHitProducer.cc

Go to the documentation of this file.
00001 
00010 #include "RecoLocalCalo/EcalRecProducers/interface/EcalWeightUncalibRecHitProducer.h"
00011 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00012 #include "DataFormats/EcalDigi/interface/EcalMGPASample.h"
00013 #include "DataFormats/Common/interface/Handle.h"
00014 
00015 #include <iostream>
00016 #include <iomanip>
00017 #include <cmath>
00018 
00019 #include "FWCore/Framework/interface/ESHandle.h"
00020 
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
00024 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
00025 
00026 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00027 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00028 
00029 #include "CondFormats/EcalObjects/interface/EcalXtalGroupId.h"
00030 #include "CondFormats/EcalObjects/interface/EcalWeightXtalGroups.h"
00031 #include "CondFormats/DataRecord/interface/EcalWeightXtalGroupsRcd.h"
00032 
00033 #include "CondFormats/EcalObjects/interface/EcalWeight.h"
00034 #include "CondFormats/EcalObjects/interface/EcalWeightSet.h"
00035 #include "CondFormats/EcalObjects/interface/EcalTBWeights.h"
00036 #include "CondFormats/DataRecord/interface/EcalTBWeightsRcd.h"
00037 
00038 #include "CondFormats/EcalObjects/interface/EcalMGPAGainRatio.h"
00039 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
00040 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
00041 
00042 #include "Math/SVector.h"
00043 #include "Math/SMatrix.h"
00044 #include <vector>
00045 
00046 EcalWeightUncalibRecHitProducer::EcalWeightUncalibRecHitProducer(const edm::ParameterSet& ps) {
00047 
00048    EBdigiCollection_ = ps.getParameter<edm::InputTag>("EBdigiCollection");
00049    EEdigiCollection_ = ps.getParameter<edm::InputTag>("EEdigiCollection");
00050    EBhitCollection_  = ps.getParameter<std::string>("EBhitCollection");
00051    EEhitCollection_  = ps.getParameter<std::string>("EEhitCollection");
00052    produces< EBUncalibratedRecHitCollection >(EBhitCollection_);
00053    produces< EEUncalibratedRecHitCollection >(EEhitCollection_);
00054 }
00055 
00056 EcalWeightUncalibRecHitProducer::~EcalWeightUncalibRecHitProducer() {
00057 }
00058 
00059 void
00060 EcalWeightUncalibRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
00061 
00062    using namespace edm;
00063 
00064    Handle< EBDigiCollection > pEBDigis;
00065    Handle< EEDigiCollection > pEEDigis;
00066 
00067    const EBDigiCollection* EBdigis =0;
00068    const EEDigiCollection* EEdigis =0;
00069 
00070    if ( EBdigiCollection_.label() != "" && EBdigiCollection_.instance() != "" ) {
00071            evt.getByLabel( EBdigiCollection_, pEBDigis);
00072            //evt.getByLabel( digiProducer_, pEBDigis);
00073            if ( pEBDigis.isValid() ) {
00074                    EBdigis = pEBDigis.product(); // get a ptr to the produc
00075                    edm::LogInfo("EcalUncalibRecHitInfo") << "total # EBdigis: " << EBdigis->size() ;
00076            } else {
00077                    edm::LogError("EcalUncalibRecHitError") << "Error! can't get the product " << EBdigiCollection_;
00078            }
00079    }
00080 
00081    if ( EEdigiCollection_.label() != "" && EEdigiCollection_.instance() != "" ) {
00082            evt.getByLabel( EEdigiCollection_, pEEDigis);
00083            //evt.getByLabel( digiProducer_, pEEDigis);
00084            if ( pEEDigis.isValid() ) {
00085                    EEdigis = pEEDigis.product(); // get a ptr to the product
00086                    edm::LogInfo("EcalUncalibRecHitInfo") << "total # EEdigis: " << EEdigis->size() ;
00087            } else {
00088                    edm::LogError("EcalUncalibRecHitError") << "Error! can't get the product " << EEdigiCollection_;
00089            }
00090    }
00091 
00092     // fetch map of groups of xtals
00093 #ifdef DEBUG
00094    LogDebug("EcalUncalibRecHitDebug") << "fetching gainRatios....";
00095 #endif
00096     edm::ESHandle<EcalWeightXtalGroups> pGrp;
00097     es.get<EcalWeightXtalGroupsRcd>().get(pGrp);
00098     const EcalWeightXtalGroups & grps = *pGrp.product();
00099 
00100    // Gain Ratios
00101    edm::ESHandle<EcalGainRatios> pRatio;
00102    es.get<EcalGainRatiosRcd>().get(pRatio);
00103    const EcalGainRatios& gains = *pRatio.product(); // gain ratios
00104 
00105    // fetch TB weights
00106 #ifdef DEBUG
00107    LogDebug("EcalUncalibRecHitDebug") <<"Fetching EcalTBWeights from DB " ;
00108 #endif
00109    edm::ESHandle<EcalTBWeights> pWgts;
00110    es.get<EcalTBWeightsRcd>().get(pWgts);
00111    const EcalTBWeights & wgts = *pWgts.product();
00112    EcalTBWeights::EcalTBWeightMap const & wgtsMap = wgts.getMap();
00113 #ifdef DEBUG
00114    LogDebug("EcalUncalibRecHitDebug") << "EcalTBWeightMap.size(): " << std::setprecision(3) << wgtsMap.size() ;
00115 #endif
00116 
00117    // fetch the pedestals from the cond DB via EventSetup
00118 #ifdef DEBUG
00119    LogDebug("EcalUncalibRecHitDebug") << "fetching pedestals....";
00120 #endif
00121    edm::ESHandle<EcalPedestals> pedHandle;
00122    es.get<EcalPedestalsRcd>().get( pedHandle );
00123    const EcalPedestals & peds = *pedHandle.product(); // pedestals
00124 #ifdef DEBUG
00125    LogDebug("EcalUncalibRecHitDebug") << "done." ;
00126 #endif
00127    // collection of reco'ed ampltudes to put in the event
00128 
00129    std::auto_ptr< EBUncalibratedRecHitCollection > EBuncalibRechits( new EBUncalibratedRecHitCollection );
00130    std::auto_ptr< EEUncalibratedRecHitCollection > EEuncalibRechits( new EEUncalibratedRecHitCollection );
00131 
00132    EcalTBWeights::EcalTBWeightMap::const_iterator wit; //weights iterator 
00133 
00134    // loop over EB digis
00135    if (EBdigis)
00136      {
00137        EBuncalibRechits->reserve(EBdigis->size());
00138        for(EBDigiCollection::const_iterator itdg = EBdigis->begin(); itdg != EBdigis->end(); ++itdg) {
00139          unsigned int hashedIndex = EBDetId(itdg->id()).hashedIndex();
00140 
00141          //     counter_++; // verbosity counter
00142 
00143          // find pedestals for this channel
00144 #ifdef DEBUG
00145          LogDebug("EcalUncalibRecHitDebug") << "looking up pedestal for crystal: " << EBDetId(itdg->id()) ;
00146 #endif
00147          const EcalPedestals::Item& aped =  peds.barrel(hashedIndex);
00148          double pedVec[3];
00149          pedVec[0]=aped.mean_x12;pedVec[1]=aped.mean_x6;pedVec[2]=aped.mean_x1;
00150 
00151          // find gain ratios
00152 #ifdef DEBUG
00153          LogDebug("EcalUncalibRecHitDebug") << "looking up gainRatios for crystal: " << EBDetId(itdg->id()) ;
00154 #endif
00155          const EcalMGPAGainRatio& aGain = gains.barrel(hashedIndex);
00156          double gainRatios[3];
00157          gainRatios[0]=1.;gainRatios[1]=aGain.gain12Over6();gainRatios[2]=aGain.gain6Over1()*aGain.gain12Over6();
00158 
00159          // lookup group ID for this channel
00160          const EcalXtalGroupId& gid = grps.barrel(hashedIndex);  
00161          // use a fake TDC iD for now until it become available in raw data
00162          EcalTBWeights::EcalTDCId tdcid(1);
00163          
00164          // now lookup the correct weights in the map
00165          wit = wgtsMap.find( std::make_pair(gid,tdcid) );
00166          if( wit == wgtsMap.end() ) {  // no weights found for this group ID
00167            edm::LogError("EcalUncalibRecHitError") << "No weights found for EcalGroupId: " << gid.id() << " and  EcalTDCId: " << tdcid
00168                                                    << "\n  skipping digi with id: " << EBDetId(itdg->id())
00169              ;
00170            continue;
00171          }
00172          const EcalWeightSet& wset = wit->second; // this is the EcalWeightSet
00173 
00174          // EcalWeightMatrix is vec<vec:double>>
00175 #ifdef DEBUG
00176          LogDebug("EcalUncalibRecHitDebug") << "accessing matrices of weights...";
00177 #endif
00178          const EcalWeightSet::EcalWeightMatrix& mat1 = wset.getWeightsBeforeGainSwitch();
00179          const EcalWeightSet::EcalWeightMatrix& mat2 = wset.getWeightsAfterGainSwitch();
00180          const EcalWeightSet::EcalChi2WeightMatrix& mat3 = wset.getChi2WeightsBeforeGainSwitch();
00181          const EcalWeightSet::EcalChi2WeightMatrix& mat4 = wset.getChi2WeightsAfterGainSwitch();
00182 #ifdef DEBUG
00183          LogDebug("EcalUncalibRecHitDebug") << "done." ;
00184 #endif
00185          // build CLHEP weight matrices
00186          const EcalWeightSet::EcalWeightMatrix* weights[2];
00187          weights[0]=&mat1;
00188          weights[1]=&mat2;
00189 //       weights.push_back(clmat1);
00190 //       weights.push_back(clmat2);
00191 //       LogDebug("EcalUncalibRecHitDebug") << "weights before switch:\n" << clmat1 ;
00192 //       LogDebug("EcalUncalibRecHitDebug") << "weights after switch:\n" << clmat2 ;
00193 
00194 
00195          // build CLHEP chi2  matrices
00196          const EcalWeightSet::EcalChi2WeightMatrix* chi2mat[2];
00197          chi2mat[0]=&mat3;
00198          chi2mat[1]=&mat4;
00199 
00200          //if(!counterExceeded()) LogDebug("EcalUncalibRecHitDebug") << "chi2 matrix before switch:\n" << clmat3 ;
00201          //if(!counterExceeded()) LogDebug("EcalUncalibRecHitDebug") << "chi2 matrix after switch:\n" << clmat4 ;
00202 
00203          EcalUncalibratedRecHit aHit =
00204            EBalgo_.makeRecHit(*itdg, pedVec, gainRatios, weights, chi2mat);
00205          EBuncalibRechits->push_back( aHit );
00206 
00207 #ifdef DEBUG
00208          if(aHit.amplitude()>0.) {
00209            LogDebug("EcalUncalibRecHitDebug") << "processed EBDataFrame with id: "
00210                                               << EBDetId(itdg->id()) << "\n"
00211                                               << "uncalib rechit amplitude: " << aHit.amplitude()
00212              ;
00213          }
00214 #endif
00215        }
00216      }
00217 
00218    // loop over EB digis
00219    if (EEdigis)
00220      {
00221        EEuncalibRechits->reserve(EEdigis->size());
00222        for(EEDigiCollection::const_iterator itdg = EEdigis->begin(); itdg != EEdigis->end(); ++itdg) {
00223          unsigned int hashedIndex = EEDetId(itdg->id()).hashedIndex();
00224          //     counter_++; // verbosity counter
00225 
00226          // find pedestals for this channel
00227 #ifdef DEBUG
00228          LogDebug("EcalUncalibRecHitDebug") << "looking up pedestal for crystal: " << EEDetId(itdg->id()) ;
00229 #endif
00230 
00231          const EcalPedestals::Item& aped =  peds.endcap(hashedIndex);
00232          double pedVec[3];
00233          pedVec[0]=aped.mean_x12;pedVec[1]=aped.mean_x6;pedVec[2]=aped.mean_x1;
00234 
00235          // find gain ratios
00236 #ifdef DEBUG
00237          LogDebug("EcalUncalibRecHitDebug") << "looking up gainRatios for crystal: " << EEDetId(itdg->id()) ;
00238 #endif
00239          const EcalMGPAGainRatio& aGain = gains.endcap(hashedIndex);
00240          double gainRatios[3];
00241          gainRatios[0]=1.;gainRatios[1]=aGain.gain12Over6();gainRatios[2]=aGain.gain6Over1()*aGain.gain12Over6();
00242 
00243          // lookup group ID for this channel
00244          const EcalXtalGroupId& gid = grps.endcap(hashedIndex);  
00245          // use a fake TDC iD for now until it become available in raw data
00246          EcalTBWeights::EcalTDCId tdcid(1);
00247          
00248          // now lookup the correct weights in the map
00249          wit = wgtsMap.find( std::make_pair(gid,tdcid) );
00250          if( wit == wgtsMap.end() ) {  // no weights found for this group ID
00251            edm::LogError("EcalUncalibRecHitError") << "No weights found for EcalGroupId: " << gid.id() << " and  EcalTDCId: " << tdcid
00252                                                    << "\n  skipping digi with id: " << EEDetId(itdg->id())
00253              ;
00254            continue;
00255          }
00256          const EcalWeightSet& wset = wit->second; // this is the EcalWeightSet
00257 
00258          // EcalWeightMatrix is vec<vec:double>>
00259 #ifdef DEBUG
00260          LogDebug("EcalUncalibRecHitDebug") << "accessing matrices of weights...";
00261 #endif
00262          const EcalWeightSet::EcalWeightMatrix& mat1 = wset.getWeightsBeforeGainSwitch();
00263          const EcalWeightSet::EcalWeightMatrix& mat2 = wset.getWeightsAfterGainSwitch();
00264          const EcalWeightSet::EcalChi2WeightMatrix& mat3 = wset.getChi2WeightsBeforeGainSwitch();
00265          const EcalWeightSet::EcalChi2WeightMatrix& mat4 = wset.getChi2WeightsAfterGainSwitch();
00266 #ifdef DEBUG
00267          LogDebug("EcalUncalibRecHitDebug") << "done." ;
00268 #endif
00269          // build CLHEP weight matrices
00270          const EcalWeightSet::EcalWeightMatrix* weights[2];
00271          weights[0]=&mat1;
00272          weights[1]=&mat2;
00273 //       weights.push_back(clmat1);
00274 //       weights.push_back(clmat2);
00275 //       LogDebug("EcalUncalibRecHitDebug") << "weights before switch:\n" << clmat1 ;
00276 //       LogDebug("EcalUncalibRecHitDebug") << "weights after switch:\n" << clmat2 ;
00277 
00278 
00279          // build CLHEP chi2  matrices
00280          const EcalWeightSet::EcalChi2WeightMatrix* chi2mat[2];
00281          chi2mat[0]=&mat3;
00282          chi2mat[1]=&mat4;
00283 
00284          //if(!counterExceeded()) LogDebug("EcalUncalibRecHitDebug") << "chi2 matrix before switch:\n" << clmat3 ;
00285          //if(!counterExceeded()) LogDebug("EcalUncalibRecHitDebug") << "chi2 matrix after switch:\n" << clmat4 ;
00286 
00287          EcalUncalibratedRecHit aHit =
00288            EEalgo_.makeRecHit(*itdg, pedVec, gainRatios, weights, chi2mat);
00289          EEuncalibRechits->push_back( aHit );
00290 
00291 #ifdef DEBUG
00292          if(aHit.amplitude()>0.) {
00293            LogDebug("EcalUncalibRecHitDebug") << "processed EEDataFrame with id: "
00294                                               << EEDetId(itdg->id()) << "\n"
00295                                               << "uncalib rechit amplitude: " << aHit.amplitude()
00296              ;
00297          }
00298 #endif
00299        }
00300      }
00301 
00302    // put the collection of recunstructed hits in the event
00303    evt.put( EBuncalibRechits, EBhitCollection_ );
00304    evt.put( EEuncalibRechits, EEhitCollection_ );
00305 //    evt.put( EEuncalibRechits, EEhitCollection_ );
00306 }
00307 
00308 
00309 

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