CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/CalibTracker/SiStripAPVAnalysis/src/TT6ApvMask.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripAPVAnalysis/interface/TT6ApvMask.h"
00002 #include <cmath>
00003 #include <numeric>
00004 #include <algorithm>
00005 using namespace std;
00006 // 
00007 //  Constructors:
00008 //
00009 TT6ApvMask::TT6ApvMask(int ctype, float ncut, float dcut, float tcut) {
00010   theCalculationFlag_ = ctype;
00011   theNoiseCut_        = ncut;
00012   theDeadCut_         = dcut;
00013   theTruncationCut_   = tcut;
00014 }
00015 
00016 // 
00017 //  Destructor :
00018 //
00019 TT6ApvMask::~TT6ApvMask(){
00020   if (0) cout << "Destructing TT6ApvMask " << endl;
00021 }
00022 //
00023 // Calculate the Mask 
00024 //
00025 void TT6ApvMask::calculateMask(ApvAnalysis::PedestalType in){
00026 
00027   theMask_.clear();
00028   ApvAnalysis::PedestalType temp_in(in);
00029   double sumVal,sqSumVal,avVal,sqAvVal,rmsVal; 
00030   sort(temp_in.begin(), temp_in.end());
00031   int nSize    = in.size();
00032   int cutLow   = int(nSize * theTruncationCut_);
00033   int cutHigh  = int(nSize * theTruncationCut_);
00034   int effSize  = nSize - cutLow - cutHigh;
00035   sumVal = 0.0;
00036   sqSumVal = 0.0;
00037   sumVal   = accumulate((temp_in.begin()+cutLow), (temp_in.end()-cutHigh), 0.0);
00038   sqSumVal = inner_product((temp_in.begin()+cutLow), (temp_in.end()-cutHigh), 
00039                            (temp_in.begin()+cutLow), 0.0);
00040   
00041   avVal    = (effSize) ? sumVal/float(effSize):0.0;
00042   sqAvVal  = (effSize) ? sqSumVal/float(effSize):0.0;
00043   rmsVal   = (sqAvVal - avVal*avVal > 0.0) ? sqrt(sqAvVal - avVal*avVal):0.0; 
00044   if (0) cout << " TT6ApvMask::calculateMask  Mean " << avVal <<
00045            " RMS " << rmsVal << " " <<  effSize << endl;       
00046   for (unsigned int i=0; i<in.size(); i++){
00047     if (defineNoisy( static_cast<float>(avVal),
00048                      static_cast<float>(rmsVal),in[i])) {
00049       theMask_.push_back(noisy);
00050     } else if (in[i] < theDeadCut_*avVal) {
00051            theMask_.push_back(dead);
00052     } else {
00053       theMask_.push_back(ok);
00054     }     
00055   }
00056 }
00057 //
00058 //  Identification of Noisy strips (three options available : using cut on 
00059 //   rms of noice distribution, using a percentage cut wrt the average, using
00060 //   a fixed cut 
00061 //
00062 bool TT6ApvMask::defineNoisy(float avrg,float rms,float noise){
00063   bool temp;
00064   temp=false;
00065   if (theCalculationFlag_ == 1){
00066    if ((noise-avrg) > theNoiseCut_*rms) {
00067      temp=true;
00068      if (0) cout << " Mean " << avrg << " rms " << rms << " Noise " << noise << endl;
00069    }
00070   } else if (theCalculationFlag_ == 2){
00071     if ((noise-avrg) > avrg*theNoiseCut_) temp=true;
00072   } else if (theCalculationFlag_ == 3){
00073     if (noise > theNoiseCut_) temp=true;
00074   } 
00075   return temp;
00076 }