Go to the documentation of this file.00001
00008 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalUncalibRecHitWorkerFixedAlphaBetaFit.h"
00009
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014
00015 #include "DataFormats/Common/interface/Handle.h"
00016
00017 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00018 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00019
00020 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
00021 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
00022
00023 #include "CondFormats/EcalObjects/interface/EcalMGPAGainRatio.h"
00024 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
00025 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
00026
00027 #include <iostream>
00028 #include <cmath>
00029 #include <fstream>
00030
00031 EcalUncalibRecHitWorkerFixedAlphaBetaFit::EcalUncalibRecHitWorkerFixedAlphaBetaFit(const edm::ParameterSet& ps) :
00032 EcalUncalibRecHitWorkerBaseClass( ps )
00033 {
00034 alphaEB_= ps.getParameter<double>("alphaEB");
00035 betaEB_= ps.getParameter<double>("betaEB");
00036 alphaEE_= ps.getParameter<double>("alphaEE");
00037 betaEE_= ps.getParameter<double>("betaEE");
00038
00039 alphabetaFilename_= ps.getUntrackedParameter<std::string>("AlphaBetaFilename","NOFILE");
00040 useAlphaBetaArray_=setAlphaBeta();
00041 if ( !useAlphaBetaArray_ ) {
00042 edm::LogInfo("EcalUncalibRecHitError") << " No alfa-beta file found. Using the deafult values.";
00043 }
00044
00045 algoEB_.SetMinAmpl( ps.getParameter<double> ("MinAmplBarrel") );
00046 algoEE_.SetMinAmpl( ps.getParameter<double> ("MinAmplEndcap") );
00047
00048 bool dyn_pede = ps.getParameter<bool>("UseDynamicPedestal");
00049 algoEB_.SetDynamicPedestal(dyn_pede);
00050 algoEE_.SetDynamicPedestal(dyn_pede);
00051 }
00052
00053
00054 void
00055 EcalUncalibRecHitWorkerFixedAlphaBetaFit::set(const edm::EventSetup& es)
00056 {
00057
00058 LogDebug("EcalUncalibRecHitDebug") << "fetching gainRatios....";
00059 es.get<EcalGainRatiosRcd>().get(pRatio);
00060 LogDebug("EcalUncalibRecHitDebug") << "done." ;
00061
00062
00063 LogDebug("EcalUncalibRecHitDebug") << "fetching pedestals....";
00064 es.get<EcalPedestalsRcd>().get( pedHandle );
00065 LogDebug("EcalUncalibRecHitDebug") << "done." ;
00066 }
00067
00068
00069 bool
00070 EcalUncalibRecHitWorkerFixedAlphaBetaFit::setAlphaBeta(){
00071 std::ifstream file(alphabetaFilename_.c_str());
00072 if (! file.is_open())
00073 return false;
00074
00075 alphaBetaValues_.resize(36);
00076
00077 char buffer[100];
00078 int sm, cry,ret;
00079 float a,b;
00080 std::pair<double,double> p(-1,-1);
00081
00082 while( ! file.getline(buffer,100).eof() ){
00083 ret=sscanf(buffer,"%d %d %f %f", &sm, &cry, &a, &b);
00084 if ((ret!=4)||
00085 (sm<=0) ||(sm>36)||
00086 (cry<=0)||(cry>1700)){
00087
00088 continue;
00089 }
00090
00091 if (alphaBetaValues_[sm-1].size()==0){
00092 alphaBetaValues_[sm-1].resize(1700,p);
00093 }
00094 alphaBetaValues_[sm-1][cry-1].first = a;
00095 alphaBetaValues_[sm-1][cry-1].second = b;
00096
00097 }
00098
00099 file.close();
00100 return true;
00101 }
00102
00103 bool
00104 EcalUncalibRecHitWorkerFixedAlphaBetaFit::run(const edm::Event& evt,
00105 const EcalDigiCollection::const_iterator & itdg,
00106 EcalUncalibratedRecHitCollection & result)
00107 {
00108
00109 const EcalGainRatioMap& gainMap = pRatio.product()->getMap();
00110 EcalGainRatioMap::const_iterator gainIter;
00111 EcalMGPAGainRatio aGain;
00112
00113 const EcalPedestalsMap & pedMap = pedHandle.product()->getMap();
00114 EcalPedestalsMapIterator pedIter;
00115 EcalPedestals::Item aped;
00116
00117 DetId detid( itdg->id() );
00118
00119
00120
00121 pedIter = pedMap.find(itdg->id());
00122 if( pedIter != pedMap.end() ) {
00123 aped = (*pedIter);
00124 } else {
00125 edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find pedestals for channel: ";
00126 if ( detid.subdetId() == EcalBarrel ) {
00127 edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId( detid );
00128 } else {
00129 edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId( detid );
00130 }
00131 edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
00132 return false;
00133 }
00134 double pedVec[3];
00135 pedVec[0] = aped.mean_x12;
00136 pedVec[1] = aped.mean_x6;
00137 pedVec[2] = aped.mean_x1;
00138
00139
00140
00141 gainIter = gainMap.find(itdg->id());
00142 if( gainIter != gainMap.end() ) {
00143 aGain = (*gainIter);
00144 } else {
00145 edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find gain ratios for channel: ";
00146 if ( detid.subdetId() == EcalBarrel ) {
00147 edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId( detid );
00148 } else {
00149 edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId( detid );
00150 }
00151 edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
00152 return false;
00153 }
00154 double gainRatios[3];
00155 gainRatios[0] = 1.;
00156 gainRatios[1] = aGain.gain12Over6();
00157 gainRatios[2] = aGain.gain6Over1()*aGain.gain12Over6();
00158
00159 if ( detid.subdetId() == EcalBarrel ) {
00160
00161 EBDetId ebDetId( detid );
00162 double a, b;
00163 if (useAlphaBetaArray_){
00164 if ( alphaBetaValues_[ ebDetId.ism()-1 ].size() != 0 ) {
00165 a = alphaBetaValues_[ebDetId.ism()-1][ebDetId.ic()-1].first;
00166 b = alphaBetaValues_[ebDetId.ism()-1][ebDetId.ic()-1].second;
00167 if ( ( a == -1 ) && ( b == -1 ) ) {
00168 a = alphaEB_;
00169 b = betaEB_;
00170 }
00171 } else {
00172 a = alphaEB_;
00173 b = betaEB_;
00174 }
00175 } else {
00176 a = alphaEB_;
00177 b = betaEB_;
00178 }
00179 algoEB_.SetAlphaBeta(a,b);
00180 result.push_back( algoEB_.makeRecHit( *itdg, pedVec, gainRatios, 0, 0) );
00181 } else {
00182
00183 algoEE_.SetAlphaBeta(alphaEE_,betaEE_);
00184 result.push_back( algoEE_.makeRecHit(*itdg, pedVec, gainRatios, 0 , 0) );
00185 }
00186 return true;
00187 }
00188
00189 #include "FWCore/Framework/interface/MakerMacros.h"
00190 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerFactory.h"
00191 DEFINE_EDM_PLUGIN( EcalUncalibRecHitWorkerFactory, EcalUncalibRecHitWorkerFixedAlphaBetaFit, "EcalUncalibRecHitWorkerFixedAlphaBetaFit" );