CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoLocalCalo/EcalRecProducers/plugins/EcalUncalibRecHitWorkerGlobal.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalUncalibRecHitWorkerGlobal.h"
00002 
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 
00008 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
00009 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
00010 #include "CondFormats/DataRecord/interface/EcalWeightXtalGroupsRcd.h"
00011 #include "CondFormats/DataRecord/interface/EcalTBWeightsRcd.h"
00012 #include "CondFormats/DataRecord/interface/EcalSampleMaskRcd.h"
00013 #include "CondFormats/DataRecord/interface/EcalTimeCalibConstantsRcd.h"
00014 #include "CondFormats/DataRecord/interface/EcalTimeOffsetConstantRcd.h"
00015 
00016 EcalUncalibRecHitWorkerGlobal::EcalUncalibRecHitWorkerGlobal(const edm::ParameterSet&ps) :
00017         EcalUncalibRecHitWorkerBaseClass(ps)
00018 {
00019         // ratio method parameters
00020         EBtimeFitParameters_ = ps.getParameter<std::vector<double> >("EBtimeFitParameters"); 
00021         EEtimeFitParameters_ = ps.getParameter<std::vector<double> >("EEtimeFitParameters"); 
00022         EBamplitudeFitParameters_ = ps.getParameter<std::vector<double> >("EBamplitudeFitParameters");
00023         EEamplitudeFitParameters_ = ps.getParameter<std::vector<double> >("EEamplitudeFitParameters");
00024         EBtimeFitLimits_.first  = ps.getParameter<double>("EBtimeFitLimits_Lower");
00025         EBtimeFitLimits_.second = ps.getParameter<double>("EBtimeFitLimits_Upper");
00026         EEtimeFitLimits_.first  = ps.getParameter<double>("EEtimeFitLimits_Lower");
00027         EEtimeFitLimits_.second = ps.getParameter<double>("EEtimeFitLimits_Upper");
00028         EBtimeConstantTerm_=ps.getParameter<double>("EBtimeConstantTerm");
00029         EBtimeNconst_=ps.getParameter<double>("EBtimeNconst");
00030         EEtimeConstantTerm_=ps.getParameter<double>("EEtimeConstantTerm");
00031         EEtimeNconst_=ps.getParameter<double>("EEtimeNconst");
00032         outOfTimeThreshG12pEB_ = ps.getParameter<double>("outOfTimeThresholdGain12pEB");
00033         outOfTimeThreshG12mEB_ = ps.getParameter<double>("outOfTimeThresholdGain12mEB");
00034         outOfTimeThreshG61pEB_ = ps.getParameter<double>("outOfTimeThresholdGain61pEB");
00035         outOfTimeThreshG61mEB_ = ps.getParameter<double>("outOfTimeThresholdGain61mEB");
00036         outOfTimeThreshG12pEE_ = ps.getParameter<double>("outOfTimeThresholdGain12pEE");
00037         outOfTimeThreshG12mEE_ = ps.getParameter<double>("outOfTimeThresholdGain12mEE");
00038         outOfTimeThreshG61pEE_ = ps.getParameter<double>("outOfTimeThresholdGain61pEE");
00039         outOfTimeThreshG61mEE_ = ps.getParameter<double>("outOfTimeThresholdGain61mEE");
00040         amplitudeThreshEB_ = ps.getParameter<double>("amplitudeThresholdEB");
00041         amplitudeThreshEE_ = ps.getParameter<double>("amplitudeThresholdEE");
00042         // amplitude-dependent correction of time
00043         doEBtimeCorrection_      = ps.getParameter<bool>("doEBtimeCorrection");
00044         doEEtimeCorrection_      = ps.getParameter<bool>("doEEtimeCorrection");
00045         EBtimeCorrAmplitudeBins_ = ps.getParameter<std::vector<double> >("EBtimeCorrAmplitudeBins"); 
00046         EBtimeCorrShiftBins_     = ps.getParameter<std::vector<double> >("EBtimeCorrShiftBins"); 
00047         EEtimeCorrAmplitudeBins_ = ps.getParameter<std::vector<double> >("EEtimeCorrAmplitudeBins"); 
00048         EEtimeCorrShiftBins_     = ps.getParameter<std::vector<double> >("EEtimeCorrShiftBins"); 
00049         if(EBtimeCorrAmplitudeBins_.size() != EBtimeCorrShiftBins_.size()) {
00050           doEBtimeCorrection_ = false;
00051           edm::LogError("EcalRecHitError") << "Size of EBtimeCorrAmplitudeBins different from EBtimeCorrShiftBins. Forcing no time corrections for EB. ";
00052         }
00053         if(EEtimeCorrAmplitudeBins_.size() != EEtimeCorrShiftBins_.size()) {
00054           doEEtimeCorrection_ = false;
00055           edm::LogError("EcalRecHitError") << "Size of EEtimeCorrAmplitudeBins different from EEtimeCorrShiftBins. Forcing no time corrections for EE. ";
00056         }
00057 
00058         // spike threshold
00059         ebSpikeThresh_ = ps.getParameter<double>("ebSpikeThreshold");
00060         // leading edge parameters
00061         ebPulseShape_ = ps.getParameter<std::vector<double> >("ebPulseShape");
00062         eePulseShape_ = ps.getParameter<std::vector<double> >("eePulseShape");
00063         // chi2 parameters
00064         kPoorRecoFlagEB_ = ps.getParameter<bool>("kPoorRecoFlagEB");
00065         kPoorRecoFlagEE_ = ps.getParameter<bool>("kPoorRecoFlagEE");;
00066         chi2ThreshEB_=ps.getParameter<double>("chi2ThreshEB_");
00067         chi2ThreshEE_=ps.getParameter<double>("chi2ThreshEE_");
00068         EBchi2Parameters_ = ps.getParameter<std::vector<double> >("EBchi2Parameters");
00069         EEchi2Parameters_ = ps.getParameter<std::vector<double> >("EEchi2Parameters");
00070 }
00071 
00072 void
00073 EcalUncalibRecHitWorkerGlobal::set(const edm::EventSetup& es)
00074 {
00075         // common setup
00076         es.get<EcalGainRatiosRcd>().get(gains);
00077         es.get<EcalPedestalsRcd>().get(peds);
00078 
00079         // for the weights method
00080         es.get<EcalWeightXtalGroupsRcd>().get(grps);
00081         es.get<EcalTBWeightsRcd>().get(wgts);
00082 
00083         // which of the samples need be used
00084         es.get<EcalSampleMaskRcd>().get(sampleMaskHand_);
00085 
00086         // for the ratio method
00087 
00088         // for the leading edge method
00089         es.get<EcalTimeCalibConstantsRcd>().get(itime);
00090         es.get<EcalTimeOffsetConstantRcd>().get(offtime);
00091 }
00092 
00093 
00094 // check saturation: 5 samples with gainId = 0
00095 template < class C >
00096 int EcalUncalibRecHitWorkerGlobal::isSaturated(const C & dataFrame)
00097 {
00098         //bool saturated_ = 0;
00099         int cnt;
00100         for (int j = 0; j < C::MAXSAMPLES - 5; ++j) {
00101                 cnt = 0;
00102                 for (int i = j; i < (j + 5) && i < C::MAXSAMPLES; ++i) {
00103                         if ( dataFrame.sample(i).gainId() == 0 ) ++cnt;
00104                 }
00105                 if ( cnt == 5 ) return j-1 ; // the last unsaturated sample
00106         }
00107         return -1; // no saturation found
00108 }
00109 
00110 
00111 double EcalUncalibRecHitWorkerGlobal::timeCorrectionEB(float ampliEB){
00112   // computed initially in ns. Than turned in the BX's, as EcalUncalibratedRecHit need be.
00113   double theCorrection=0;
00114 
00115   
00116   int myBin = -1;
00117   for (int bin=0; bin<(int)EBtimeCorrAmplitudeBins_.size(); bin++ ){
00118     if(ampliEB > EBtimeCorrAmplitudeBins_.at(bin)) {
00119       myBin = bin;     }
00120     else break;
00121   }
00122   
00123   if (myBin == -1)
00124     {
00125       theCorrection = EBtimeCorrShiftBins_.at(0);
00126     }    
00127   else if  ( myBin == ((int)(EBtimeCorrAmplitudeBins_.size()-1))   ) 
00128     {
00129       theCorrection = EBtimeCorrShiftBins_.at( myBin );      
00130     }    
00131   else if  ( -1 < myBin   &&   myBin <  ((int)EBtimeCorrAmplitudeBins_.size()-1) )
00132     {
00133       // interpolate linearly between two assingned points
00134       theCorrection  = ( EBtimeCorrShiftBins_.at(myBin+1) - EBtimeCorrShiftBins_.at(myBin) );
00135       theCorrection *= ( ((double)ampliEB) -  EBtimeCorrAmplitudeBins_.at(myBin) ) / ( EBtimeCorrAmplitudeBins_.at(myBin+1) - EBtimeCorrAmplitudeBins_.at(myBin) );
00136       theCorrection += EBtimeCorrShiftBins_.at(myBin);
00137     }
00138   else
00139     {
00140       edm::LogError("EcalRecHitError") << "Assigning time correction impossible. Setting it to 0 ";
00141       theCorrection = 0.;
00142     }
00143 
00144   // convert ns into clocks
00145   return theCorrection/25.;
00146 }
00147 
00148 
00149 double EcalUncalibRecHitWorkerGlobal::timeCorrectionEE(float ampliEE){
00150   // computed initially in ns. Than turned in the BX's, as EcalUncalibratedRecHit need be.
00151   double theCorrection=0;
00152   
00153   int myBin = -1;
00154   for (int bin=0; bin<(int)EEtimeCorrAmplitudeBins_.size(); bin++ ){
00155     if(ampliEE > EEtimeCorrAmplitudeBins_.at(bin)) {
00156       myBin = bin;     }
00157     else break;
00158   }
00159   
00160   if (myBin == -1)
00161     {
00162       theCorrection = EEtimeCorrShiftBins_.at(0);
00163     }    
00164   else if  ( myBin == ((int)(EEtimeCorrAmplitudeBins_.size()-1))   ) 
00165     {
00166       theCorrection = EEtimeCorrShiftBins_.at( myBin );      
00167     }    
00168   else if  ( -1 < myBin   &&   myBin <  ((int)EEtimeCorrAmplitudeBins_.size()-1) )
00169     {
00170       // interpolate linearly between two assingned points
00171       theCorrection  = ( EEtimeCorrShiftBins_.at(myBin+1) - EEtimeCorrShiftBins_.at(myBin) );
00172       theCorrection *= ( ((double)ampliEE) -  EEtimeCorrAmplitudeBins_.at(myBin) ) / ( EEtimeCorrAmplitudeBins_.at(myBin+1) - EEtimeCorrAmplitudeBins_.at(myBin) );
00173       theCorrection += EEtimeCorrShiftBins_.at(myBin);
00174     }
00175   else
00176     {
00177       edm::LogError("EcalRecHitError") << "Assigning time correction impossible. Setting it to 0 ";
00178       theCorrection = 0.;
00179     }
00180   
00181   // convert ns into clocks
00182   return theCorrection/25.;
00183 }
00184 
00185 
00186 
00187 
00188 bool
00189 EcalUncalibRecHitWorkerGlobal::run( const edm::Event & evt,
00190                 const EcalDigiCollection::const_iterator & itdg,
00191                 EcalUncalibratedRecHitCollection & result )
00192 {
00193         DetId detid(itdg->id());
00194 
00195         const EcalSampleMask  *sampleMask_ = sampleMaskHand_.product();        
00196 
00197         // intelligence for recHit computation
00198         EcalUncalibratedRecHit uncalibRecHit;
00199         
00200         
00201         const EcalPedestals::Item * aped = 0;
00202         const EcalMGPAGainRatio * aGain = 0;
00203         const EcalXtalGroupId * gid = 0;
00204         float offsetTime = 0;
00205 
00206         if (detid.subdetId()==EcalEndcap) {
00207                 unsigned int hashedIndex = EEDetId(detid).hashedIndex();
00208                 aped  = &peds->endcap(hashedIndex);
00209                 aGain = &gains->endcap(hashedIndex);
00210                 gid   = &grps->endcap(hashedIndex);
00211                 offsetTime = offtime->getEEValue();
00212         } else {
00213                 unsigned int hashedIndex = EBDetId(detid).hashedIndex();
00214                 aped  = &peds->barrel(hashedIndex);
00215                 aGain = &gains->barrel(hashedIndex);
00216                 gid   = &grps->barrel(hashedIndex);
00217                 offsetTime = offtime->getEBValue();
00218         }
00219 
00220         pedVec[0] = aped->mean_x12;
00221         pedVec[1] = aped->mean_x6;
00222         pedVec[2] = aped->mean_x1;
00223         pedRMSVec[0] = aped->rms_x12;
00224         pedRMSVec[1] = aped->rms_x6;
00225         pedRMSVec[2] = aped->rms_x1;
00226         gainRatios[0] = 1.;
00227         gainRatios[1] = aGain->gain12Over6();
00228         gainRatios[2] = aGain->gain6Over1()*aGain->gain12Over6();
00229 
00230         // compute the right bin of the pulse shape using time calibration constants
00231         EcalTimeCalibConstantMap::const_iterator it = itime->find( detid );
00232         EcalTimeCalibConstant itimeconst = 0;
00233         if( it != itime->end() ) {
00234                   itimeconst = (*it);
00235         } else {
00236                   edm::LogError("EcalRecHitError") << "No time intercalib const found for xtal "
00237                   << detid.rawId()
00238                   << "! something wrong with EcalTimeCalibConstants in your DB? ";
00239         }
00240 
00241 
00242         // === amplitude computation ===
00243         int leadingSample = -1;
00244         if (detid.subdetId()==EcalEndcap) {
00245                 leadingSample = ((EcalDataFrame)(*itdg)).lastUnsaturatedSample();
00246         } else {
00247                 leadingSample = ((EcalDataFrame)(*itdg)).lastUnsaturatedSample();
00248         }
00249 
00250         if ( leadingSample >= 0 ) { // saturation
00251                 if ( leadingSample != 4 ) {
00252                         // all samples different from the fifth are not reliable for the amplitude estimation
00253                         // put by default the energy at the saturation threshold and flag as saturated
00254                         float sratio = 1;
00255                         if ( detid.subdetId()==EcalBarrel) {
00256                                 sratio = ebPulseShape_[5] / ebPulseShape_[4];
00257                         } else {
00258                                 sratio = eePulseShape_[5] / eePulseShape_[4];
00259                         }
00260                         uncalibRecHit = EcalUncalibratedRecHit( (*itdg).id(), 4095*12*sratio, 0, 0, 0);
00261                         uncalibRecHit.setFlagBit( EcalUncalibratedRecHit::kSaturated );
00262                 } else {
00263                         // float clockToNsConstant = 25.;
00264                         // reconstruct the rechit
00265                         if (detid.subdetId()==EcalEndcap) {
00266                                 leadingEdgeMethod_endcap_.setPulseShape( eePulseShape_ );
00267                                 // float mult = (float)eePulseShape_.size() / (float)(*itdg).size();
00268                                 // bin (or some analogous mapping) will be used instead of the leadingSample
00269                                 //int bin  = (int)(( (mult * leadingSample + mult/2) * clockToNsConstant + itimeconst ) / clockToNsConstant);
00270                                 // bin is not uset for the moment
00271                                 leadingEdgeMethod_endcap_.setLeadingEdgeSample( leadingSample );
00272                                 uncalibRecHit = leadingEdgeMethod_endcap_.makeRecHit(*itdg, pedVec, gainRatios, 0, 0);
00273                                 uncalibRecHit.setFlagBit( EcalUncalibratedRecHit::kLeadingEdgeRecovered );
00274                                 leadingEdgeMethod_endcap_.setLeadingEdgeSample( -1 );
00275                         } else {
00276                                 leadingEdgeMethod_barrel_.setPulseShape( ebPulseShape_ );
00277                                 // float mult = (float)ebPulseShape_.size() / (float)(*itdg).size();
00278                                 // bin (or some analogous mapping) will be used instead of the leadingSample
00279                                 //int bin  = (int)(( (mult * leadingSample + mult/2) * clockToNsConstant + itimeconst ) / clockToNsConstant);
00280                                 // bin is not uset for the moment
00281                                 leadingEdgeMethod_barrel_.setLeadingEdgeSample( leadingSample );
00282                                 uncalibRecHit = leadingEdgeMethod_barrel_.makeRecHit(*itdg, pedVec, gainRatios, 0, 0);
00283                                 uncalibRecHit.setFlagBit( EcalUncalibratedRecHit::kLeadingEdgeRecovered );
00284                                 leadingEdgeMethod_barrel_.setLeadingEdgeSample( -1 );
00285                         }
00286                 }
00287                 // do not propagate the default chi2 = -1 value to the calib rechit (mapped to 64), set it to 0 when saturation
00288                 uncalibRecHit.setChi2(0);
00289                 uncalibRecHit.setOutOfTimeChi2(0);
00290         } else {
00291                 // weights method
00292                 EcalTBWeights::EcalTDCId tdcid(1);
00293                 EcalTBWeights::EcalTBWeightMap const & wgtsMap = wgts->getMap();
00294                 EcalTBWeights::EcalTBWeightMap::const_iterator wit;
00295                 wit = wgtsMap.find( std::make_pair(*gid,tdcid) );
00296                 if( wit == wgtsMap.end() ) {
00297                         edm::LogError("EcalUncalibRecHitError") << "No weights found for EcalGroupId: " 
00298                                 << gid->id() << " and  EcalTDCId: " << tdcid
00299                                 << "\n  skipping digi with id: " << detid.rawId();
00300 
00301                         return false;
00302                 }
00303                 const EcalWeightSet& wset = wit->second; // this is the EcalWeightSet
00304 
00305                 const EcalWeightSet::EcalWeightMatrix& mat1 = wset.getWeightsBeforeGainSwitch();
00306                 const EcalWeightSet::EcalWeightMatrix& mat2 = wset.getWeightsAfterGainSwitch();
00307 
00308                 weights[0] = &mat1;
00309                 weights[1] = &mat2;
00310 
00311                 // get uncalibrated recHit from weights
00312                 if (detid.subdetId()==EcalEndcap) {
00313                      uncalibRecHit = weightsMethod_endcap_.makeRecHit(*itdg, pedVec, pedRMSVec, gainRatios, weights, testbeamEEShape);
00314                 } else {
00315                      uncalibRecHit = weightsMethod_barrel_.makeRecHit(*itdg, pedVec, pedRMSVec, gainRatios, weights, testbeamEBShape);
00316                 }
00317 
00318                 // === time computation ===
00319                 // ratio method
00320                 float const clockToNsConstant = 25.;
00321                 if (detid.subdetId()==EcalEndcap) {
00322                                 ratioMethod_endcap_.init( *itdg, *sampleMask_, pedVec, pedRMSVec, gainRatios );
00323                                 ratioMethod_endcap_.computeTime( EEtimeFitParameters_, EEtimeFitLimits_, EEamplitudeFitParameters_ );
00324                                 ratioMethod_endcap_.computeAmplitude( EEamplitudeFitParameters_);
00325                                 EcalUncalibRecHitRatioMethodAlgo<EEDataFrame>::CalculatedRecHit crh = ratioMethod_endcap_.getCalculatedRecHit();
00326                                 double theTimeCorrectionEE=0;
00327                                 if(doEEtimeCorrection_) theTimeCorrectionEE = timeCorrectionEE( uncalibRecHit.amplitude() );
00328                                 uncalibRecHit.setJitter( crh.timeMax - 5 + theTimeCorrectionEE);
00329                                 uncalibRecHit.setJitterError( std::sqrt(pow(crh.timeError,2) + std::pow(EEtimeConstantTerm_,2)/std::pow(clockToNsConstant,2)) );
00330                                 uncalibRecHit.setOutOfTimeEnergy( crh.amplitudeMax );
00331                                 // consider flagging as kOutOfTime only if above noise
00332                                 if (uncalibRecHit.amplitude() > pedRMSVec[0] * amplitudeThreshEE_){
00333                                   float outOfTimeThreshP = outOfTimeThreshG12pEE_;
00334                                   float outOfTimeThreshM = outOfTimeThreshG12mEE_;
00335                                   // determine if gain has switched away from gainId==1 (x12 gain)
00336                                   // and determine cuts (number of 'sigmas') to ose for kOutOfTime
00337                                   // >3k ADC is necessasry condition for gain switch to occur
00338                                   if (uncalibRecHit.amplitude() > 3000.){
00339                                     for (int iSample = 0; iSample < EEDataFrame::MAXSAMPLES; iSample++) {
00340                                       int GainId = ((EcalDataFrame)(*itdg)).sample(iSample).gainId();
00341                                       if (GainId!=1) {
00342                                         outOfTimeThreshP = outOfTimeThreshG61pEE_;
00343                                         outOfTimeThreshM = outOfTimeThreshG61mEE_;
00344                                         break;
00345                                       }
00346                                     }}
00347                                   float correctedTime = (crh.timeMax-5) * clockToNsConstant + itimeconst + offsetTime;
00348                                   float cterm         = EEtimeConstantTerm_;
00349                                   float sigmaped      = pedRMSVec[0];  // approx for lower gains
00350                                   float nterm         = EEtimeNconst_*sigmaped/uncalibRecHit.amplitude();
00351                                   float sigmat        = std::sqrt( nterm*nterm  + cterm*cterm   );
00352                                   if ( ( correctedTime > sigmat*outOfTimeThreshP )   ||
00353                                        ( correctedTime < (-1.*sigmat*outOfTimeThreshM) )) 
00354                                     {  uncalibRecHit.setFlagBit( EcalUncalibratedRecHit::kOutOfTime ); }
00355                                 }
00356                                 
00357                 } else {
00358                                 ratioMethod_barrel_.init( *itdg, *sampleMask_, pedVec, pedRMSVec, gainRatios );
00359                                 ratioMethod_barrel_.fixMGPAslew(*itdg);
00360                                 ratioMethod_barrel_.computeTime( EBtimeFitParameters_, EBtimeFitLimits_, EBamplitudeFitParameters_ );
00361                                 ratioMethod_barrel_.computeAmplitude( EBamplitudeFitParameters_);
00362                                 EcalUncalibRecHitRatioMethodAlgo<EBDataFrame>::CalculatedRecHit crh = ratioMethod_barrel_.getCalculatedRecHit();
00363                                 double theTimeCorrectionEB=0;
00364                                 if(doEBtimeCorrection_) theTimeCorrectionEB = timeCorrectionEB( uncalibRecHit.amplitude() );
00365 
00366                                 uncalibRecHit.setJitter( crh.timeMax - 5 + theTimeCorrectionEB);
00367 
00368                                 uncalibRecHit.setJitterError( std::sqrt(std::pow(crh.timeError,2) + std::pow(EBtimeConstantTerm_,2)/std::pow(clockToNsConstant,2)) );
00369                                 uncalibRecHit.setOutOfTimeEnergy( crh.amplitudeMax );
00370                                 // consider flagging as kOutOfTime only if above noise
00371                                 if (uncalibRecHit.amplitude() > pedRMSVec[0] * amplitudeThreshEB_){
00372                                   float outOfTimeThreshP = outOfTimeThreshG12pEB_;
00373                                   float outOfTimeThreshM = outOfTimeThreshG12mEB_;
00374                                   // determine if gain has switched away from gainId==1 (x12 gain)
00375                                   // and determine cuts (number of 'sigmas') to ose for kOutOfTime
00376                                   // >3k ADC is necessasry condition for gain switch to occur
00377                                   if (uncalibRecHit.amplitude() > 3000.){
00378                                     for (int iSample = 0; iSample < EBDataFrame::MAXSAMPLES; iSample++) {
00379                                       int GainId = ((EcalDataFrame)(*itdg)).sample(iSample).gainId();
00380                                       if (GainId!=1) {
00381                                         outOfTimeThreshP = outOfTimeThreshG61pEB_;
00382                                         outOfTimeThreshM = outOfTimeThreshG61mEB_;
00383                                         break;}
00384                                     } }
00385                                   float correctedTime = (crh.timeMax-5) * clockToNsConstant + itimeconst + offsetTime;
00386                                   float cterm         = EBtimeConstantTerm_;
00387                                   float sigmaped      = pedRMSVec[0];  // approx for lower gains
00388                                   float nterm         = EBtimeNconst_*sigmaped/uncalibRecHit.amplitude();
00389                                   float sigmat        = std::sqrt( nterm*nterm  + cterm*cterm   );
00390                                   if ( ( correctedTime > sigmat*outOfTimeThreshP )   ||
00391                                        ( correctedTime < (-1.*sigmat*outOfTimeThreshM) )) 
00392                                     {   uncalibRecHit.setFlagBit( EcalUncalibratedRecHit::kOutOfTime );  }
00393                                 }
00394                 }
00395                 
00396                 // === chi2express ===
00397                 if (detid.subdetId()==EcalEndcap) {
00398                       
00399                     double amplitude = uncalibRecHit.amplitude();
00400                     double amplitudeOutOfTime = uncalibRecHit.outOfTimeEnergy();
00401                     double jitter= uncalibRecHit.jitter();
00402 
00403 
00404                 
00405                     EcalUncalibRecHitRecChi2Algo<EEDataFrame>chi2expressEE_(
00406                                                                             *itdg, 
00407                                                                             amplitude, 
00408                                                                             (itimeconst + offsetTime), 
00409                                                                             amplitudeOutOfTime, 
00410                                                                             jitter, 
00411                                                                             pedVec, 
00412                                                                             pedRMSVec, 
00413                                                                             gainRatios, 
00414                                                                             testbeamEEShape,
00415                                                                             EEchi2Parameters_
00416                     );
00417                     double chi2 = chi2expressEE_.chi2();
00418                     uncalibRecHit.setChi2(chi2);
00419                     double chi2OutOfTime = chi2expressEE_.chi2OutOfTime();
00420                     uncalibRecHit.setOutOfTimeChi2(chi2OutOfTime);
00421 
00422                     if(kPoorRecoFlagEE_)
00423                     {
00424                         if(chi2>chi2ThreshEE_)uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kPoorReco);
00425                     }                           
00426                         
00427                 } else {
00428                     double amplitude = uncalibRecHit.amplitude();
00429                     double amplitudeOutOfTime = uncalibRecHit.outOfTimeEnergy();
00430                     double jitter= uncalibRecHit.jitter();
00431                   
00432                     EcalUncalibRecHitRecChi2Algo<EBDataFrame>chi2expressEB_(
00433                                                                             *itdg, 
00434                                                                             amplitude, 
00435                                                                             (itimeconst + offsetTime), 
00436                                                                             amplitudeOutOfTime, 
00437                                                                             jitter, 
00438                                                                             pedVec, 
00439                                                                             pedRMSVec, 
00440                                                                             gainRatios, 
00441                                                                             testbeamEBShape,
00442                                                                             EBchi2Parameters_           
00443                     );
00444                     double chi2 = chi2expressEB_.chi2();
00445                     uncalibRecHit.setChi2(chi2);
00446                     double chi2OutOfTime = chi2expressEB_.chi2OutOfTime();
00447                     uncalibRecHit.setOutOfTimeChi2(chi2OutOfTime);
00448 
00449                     if(kPoorRecoFlagEB_)
00450                     {
00451                         if(chi2>chi2ThreshEB_)uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kPoorReco);
00452                     }                           
00453                 }
00454         }
00455 
00456         // set flags if gain switch has occurred
00457         if( ((EcalDataFrame)(*itdg)).hasSwitchToGain6()  ) uncalibRecHit.setFlagBit( EcalUncalibratedRecHit::kHasSwitchToGain6 );
00458         if( ((EcalDataFrame)(*itdg)).hasSwitchToGain1()  ) uncalibRecHit.setFlagBit( EcalUncalibratedRecHit::kHasSwitchToGain1 );
00459 
00460         // put the recHit in the collection
00461         if (detid.subdetId()==EcalEndcap) {
00462                 result.push_back( uncalibRecHit );
00463         } else {
00464                 result.push_back( uncalibRecHit );
00465         }
00466 
00467         return true;
00468 }
00469 
00470 #include "FWCore/Framework/interface/MakerMacros.h"
00471 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerFactory.h"
00472 DEFINE_EDM_PLUGIN( EcalUncalibRecHitWorkerFactory, EcalUncalibRecHitWorkerGlobal, "EcalUncalibRecHitWorkerGlobal" );