Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-23 15:57:18

0001 #include "CalibTracker/SiStripAPVAnalysis/interface/TT6ApvMask.h"
0002 #include <cmath>
0003 #include <numeric>
0004 #include <algorithm>
0005 using namespace std;
0006 //
0007 //  Constructors:
0008 //
0009 TT6ApvMask::TT6ApvMask(int ctype, float ncut, float dcut, float tcut) {
0010   theCalculationFlag_ = ctype;
0011   theNoiseCut_ = ncut;
0012   theDeadCut_ = dcut;
0013   theTruncationCut_ = tcut;
0014 }
0015 
0016 //
0017 //  Destructor :
0018 //
0019 TT6ApvMask::~TT6ApvMask() {
0020   if (false)
0021     cout << "Destructing TT6ApvMask " << endl;
0022 }
0023 //
0024 // Calculate the Mask
0025 //
0026 void TT6ApvMask::calculateMask(const ApvAnalysis::PedestalType& in) {
0027   theMask_.clear();
0028   ApvAnalysis::PedestalType temp_in(in);
0029   double sumVal, sqSumVal, avVal, sqAvVal, rmsVal;
0030   sort(temp_in.begin(), temp_in.end());
0031   int nSize = in.size();
0032   int cutLow = int(nSize * theTruncationCut_);
0033   int cutHigh = int(nSize * theTruncationCut_);
0034   int effSize = nSize - cutLow - cutHigh;
0035   sumVal = accumulate((temp_in.begin() + cutLow), (temp_in.end() - cutHigh), 0.0);
0036   sqSumVal = inner_product((temp_in.begin() + cutLow), (temp_in.end() - cutHigh), (temp_in.begin() + cutLow), 0.0);
0037 
0038   avVal = (effSize) ? sumVal / float(effSize) : 0.0;
0039   sqAvVal = (effSize) ? sqSumVal / float(effSize) : 0.0;
0040   rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(sqAvVal - avVal * avVal) : 0.0;
0041   if (false)
0042     cout << " TT6ApvMask::calculateMask  Mean " << avVal << " RMS " << rmsVal << " " << effSize << endl;
0043   for (unsigned int i = 0; i < in.size(); i++) {
0044     if (defineNoisy(static_cast<float>(avVal), static_cast<float>(rmsVal), in[i])) {
0045       theMask_.push_back(noisy);
0046     } else if (in[i] < theDeadCut_ * avVal) {
0047       theMask_.push_back(dead);
0048     } else {
0049       theMask_.push_back(ok);
0050     }
0051   }
0052 }
0053 //
0054 //  Identification of Noisy strips (three options available : using cut on
0055 //   rms of noice distribution, using a percentage cut wrt the average, using
0056 //   a fixed cut
0057 //
0058 bool TT6ApvMask::defineNoisy(float avrg, float rms, float noise) {
0059   bool temp;
0060   temp = false;
0061   if (theCalculationFlag_ == 1) {
0062     if ((noise - avrg) > theNoiseCut_ * rms) {
0063       temp = true;
0064       if (false)
0065         cout << " Mean " << avrg << " rms " << rms << " Noise " << noise << endl;
0066     }
0067   } else if (theCalculationFlag_ == 2) {
0068     if ((noise - avrg) > avrg * theNoiseCut_)
0069       temp = true;
0070   } else if (theCalculationFlag_ == 3) {
0071     if (noise > theNoiseCut_)
0072       temp = true;
0073   }
0074   return temp;
0075 }