CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitRecWeightsAlgo.h

Go to the documentation of this file.
00001 #ifndef RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecWeightsAlgo_HH
00002 #define RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecWeightsAlgo_HH
00003 
00018 #include "Math/SVector.h"
00019 #include "Math/SMatrix.h"
00020 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitRecAbsAlgo.h"
00021 #include "CondFormats/EcalObjects/interface/EcalWeightSet.h"
00022 #include "SimCalorimetry/EcalSimAlgos/interface/EcalShapeBase.h"
00023 
00024 #include <vector>
00025 
00026 template<class C> class EcalUncalibRecHitRecWeightsAlgo 
00027 {
00028  public:
00029   // destructor
00030   virtual ~EcalUncalibRecHitRecWeightsAlgo<C>() { };
00031 
00033    virtual EcalUncalibratedRecHit makeRecHit(
00034                                               const C& dataFrame 
00035                                               , const double* pedestals
00036                                               , const double* pedestalsRMS
00037                                               , const double* gainRatios 
00038                                               , const EcalWeightSet::EcalWeightMatrix** weights
00039                                               , const EcalShapeBase & testbeamPulseShape
00040     ) {
00041     double amplitude_(-1.),  pedestal_(-1.), jitter_(-1.), chi2_(-1.);
00042     uint32_t flag = 0;
00043 
00044 
00045     // Get time samples
00046     ROOT::Math::SVector<double,C::MAXSAMPLES> frame;
00047     int gainId0 = 1;
00048     int iGainSwitch = 0;
00049     bool isSaturated = 0;
00050     for(int iSample = 0; iSample < C::MAXSAMPLES; iSample++) {
00051       int gainId = dataFrame.sample(iSample).gainId();
00052       //Handling saturation (treating saturated gainId as maximum gain)
00053       if ( gainId == 0 ) 
00054         { 
00055           gainId = 3;
00056           //isSaturated = 1;
00057           // in pileup run May2012 samples 7,8,9,10 have gainid ==0
00058           // fix it like this: it won't hurt for the future SA20120512
00059           if(iSample==4 || iSample ==5 || iSample==6) isSaturated = 1;
00060         }
00061 
00062       //      if (gainId != gainId0) iGainSwitch = 1;
00063       // same problem as above: mark saturation only when physically
00064       // expected to occur SA20120513
00065       if ( (gainId != gainId0) && (iSample==4 || iSample ==5 || iSample==6) ) iGainSwitch = 1;
00066       if (!iGainSwitch)
00067         frame(iSample) = double(dataFrame.sample(iSample).adc());
00068       else
00069         frame(iSample) = double(((double)(dataFrame.sample(iSample).adc()) - pedestals[gainId-1]) * gainRatios[gainId-1]);
00070     }
00071 
00072     // Compute parameters
00073     ROOT::Math::SVector <double,3> param = (*(weights[iGainSwitch])) * frame;
00074     amplitude_ = param(EcalUncalibRecHitRecAbsAlgo<C>::iAmplitude);
00075     pedestal_ = param(EcalUncalibRecHitRecAbsAlgo<C>::iPedestal);
00076     if (amplitude_) jitter_ = param(EcalUncalibRecHitRecAbsAlgo<C>::iTime);
00077 
00078 
00079     //When saturated gain flag i
00080     if (isSaturated)
00081       {
00082         flag = EcalUncalibratedRecHit::kSaturated;
00083         amplitude_ = double((4095. - pedestals[2]) * gainRatios[2]);
00084       }
00085     return EcalUncalibratedRecHit( dataFrame.id(), amplitude_, pedestal_, jitter_, chi2_, flag);
00086   }
00087 
00089 };
00090 #endif