Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:05

0001 #ifndef RecoTrackerDeDx_GenericTruncatedAverageDeDxEstimator_h
0002 #define RecoTrackerDeDx_GenericTruncatedAverageDeDxEstimator_h
0003 
0004 #include "RecoTracker/DeDx/interface/BaseDeDxEstimator.h"
0005 #include "RecoTracker/DeDx/interface/DeDxTools.h"
0006 #include "DataFormats/TrackReco/interface/DeDxHit.h"
0007 #include <numeric>
0008 
0009 class GenericTruncatedAverageDeDxEstimator : public BaseDeDxEstimator {
0010 public:
0011   GenericTruncatedAverageDeDxEstimator(const edm::ParameterSet& iConfig) {
0012     fraction_ = iConfig.getParameter<double>("fraction");
0013     expo_ = iConfig.getParameter<double>("exponent");
0014     truncate_ = iConfig.getParameter<bool>("truncate");
0015   }
0016 
0017   std::pair<float, float> dedx(const reco::DeDxHitCollection& Hits) override {
0018     int first = 0, last = Hits.size();
0019     if (truncate_) {
0020       if (fraction_ > 0) {  // truncate high charge ones
0021         last -= int(Hits.size() * fraction_);
0022       } else if (fraction_ < 0) {
0023         first += int(Hits.size() * (-fraction_));
0024       }
0025     }
0026     double sumdedx = 0;
0027     for (int i = first; i < last; i++) {
0028       sumdedx += pow(Hits[i].charge(), expo_);
0029     }
0030     double avrdedx = (last - first) ? pow(sumdedx / (last - first), 1.0 / expo_) : 0.0;
0031     return std::make_pair(avrdedx, -1);
0032   }
0033 
0034 private:
0035   float fraction_, expo_;
0036   bool truncate_;
0037 };
0038 
0039 #endif