00001 #ifndef RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecWeightsAlgo_HH
00002 #define RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecWeightsAlgo_HH
00003
00014 #include "Math/SVector.h"
00015 #include "Math/SMatrix.h"
00016 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitRecAbsAlgo.h"
00017 #include "CondFormats/EcalObjects/interface/EcalWeightSet.h"
00018 #include <vector>
00019
00020 template<class C> class EcalUncalibRecHitRecWeightsAlgo : public EcalUncalibRecHitRecAbsAlgo<C>
00021 {
00022 public:
00023
00024 virtual ~EcalUncalibRecHitRecWeightsAlgo<C>() { };
00025
00027 virtual EcalUncalibratedRecHit makeRecHit(const C& dataFrame, const double* pedestals,
00028 const double* gainRatios,
00029 const EcalWeightSet::EcalWeightMatrix** weights,
00030 const EcalWeightSet::EcalChi2WeightMatrix** chi2Matrix) {
00031 double amplitude_(-1.), pedestal_(-1.), jitter_(-1.), chi2_(-1.);
00032
00033
00034 ROOT::Math::SVector<double,C::MAXSAMPLES> frame;
00035 int gainId0 = 1;
00036 int iGainSwitch = 0;
00037 for(int iSample = 0; iSample < C::MAXSAMPLES; iSample++) {
00038 int gainId = dataFrame.sample(iSample).gainId();
00039
00040 if (gainId == 0 ) gainId = 3;
00041 if (gainId != gainId0) iGainSwitch = 1;
00042 if (!iGainSwitch)
00043 frame(iSample) = double(dataFrame.sample(iSample).adc());
00044 else
00045 frame(iSample) = double(((double)(dataFrame.sample(iSample).adc()) - pedestals[gainId-1]) * gainRatios[gainId-1]);
00046 }
00047
00048
00049 ROOT::Math::SVector <double,3> param = (*(weights[iGainSwitch])) * frame;
00050 amplitude_ = param(EcalUncalibRecHitRecAbsAlgo<C>::iAmplitude);
00051 pedestal_ = param(EcalUncalibRecHitRecAbsAlgo<C>::iPedestal);
00052 if (amplitude_) jitter_ = param(EcalUncalibRecHitRecAbsAlgo<C>::iTime);
00053
00054 chi2_ = ROOT::Math::Similarity((*(chi2Matrix[iGainSwitch])),frame);
00055 return EcalUncalibratedRecHit( dataFrame.id(), amplitude_, pedestal_, jitter_, chi2_);
00056 }
00057 };
00058 #endif