Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:39

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 = 0.0;
0036   sqSumVal = 0.0;
0037   sumVal = accumulate((temp_in.begin() + cutLow), (temp_in.end() - cutHigh), 0.0);
0038   sqSumVal = inner_product((temp_in.begin() + cutLow), (temp_in.end() - cutHigh), (temp_in.begin() + cutLow), 0.0);
0039 
0040   avVal = (effSize) ? sumVal / float(effSize) : 0.0;
0041   sqAvVal = (effSize) ? sqSumVal / float(effSize) : 0.0;
0042   rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(sqAvVal - avVal * avVal) : 0.0;
0043   if (false)
0044     cout << " TT6ApvMask::calculateMask  Mean " << avVal << " RMS " << rmsVal << " " << effSize << endl;
0045   for (unsigned int i = 0; i < in.size(); i++) {
0046     if (defineNoisy(static_cast<float>(avVal), static_cast<float>(rmsVal), in[i])) {
0047       theMask_.push_back(noisy);
0048     } else if (in[i] < theDeadCut_ * avVal) {
0049       theMask_.push_back(dead);
0050     } else {
0051       theMask_.push_back(ok);
0052     }
0053   }
0054 }
0055 //
0056 //  Identification of Noisy strips (three options available : using cut on
0057 //   rms of noice distribution, using a percentage cut wrt the average, using
0058 //   a fixed cut
0059 //
0060 bool TT6ApvMask::defineNoisy(float avrg, float rms, float noise) {
0061   bool temp;
0062   temp = false;
0063   if (theCalculationFlag_ == 1) {
0064     if ((noise - avrg) > theNoiseCut_ * rms) {
0065       temp = true;
0066       if (false)
0067         cout << " Mean " << avrg << " rms " << rms << " Noise " << noise << endl;
0068     }
0069   } else if (theCalculationFlag_ == 2) {
0070     if ((noise - avrg) > avrg * theNoiseCut_)
0071       temp = true;
0072   } else if (theCalculationFlag_ == 3) {
0073     if (noise > theNoiseCut_)
0074       temp = true;
0075   }
0076   return temp;
0077 }