Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:36

0001 #include "CalibTracker/SiStripAPVAnalysis/interface/MedianCommonModeCalculator.h"
0002 #include <cmath>
0003 
0004 using namespace std;
0005 MedianCommonModeCalculator::MedianCommonModeCalculator()
0006     :  //  theNoiseCalculator(noise_calc),
0007       //  theApvMask(mask_calc),
0008       alreadyUsedEvent(false) {
0009   if (false)
0010     cout << "Constructing MedianCommonMode Calculator ..." << endl;
0011   //  cutToAvoidSignal = sig_cut;
0012 }
0013 //
0014 //  Destructor
0015 //
0016 MedianCommonModeCalculator::~MedianCommonModeCalculator() {
0017   if (false)
0018     cout << "Destructing TT6CommonModeCalculator " << endl;
0019 }
0020 //
0021 // Action :
0022 //
0023 ApvAnalysis::PedestalType MedianCommonModeCalculator::doIt(const ApvAnalysis::PedestalType& _indat) {
0024   ApvAnalysis::PedestalType indat = _indat;
0025   ApvAnalysis::PedestalType out;
0026   calculateCommonMode(indat);
0027   int setNumber;
0028   if (!theCommonModeValues.empty()) {
0029     for (unsigned int i = 0; i < indat.size(); i++) {
0030       setNumber = theTkCommonMode->topology().setOfStrip(i);
0031       out.push_back(indat[i] - theCommonModeValues[setNumber]);
0032     }
0033   } else {
0034     out = indat;
0035   }
0036   return out;
0037 }
0038 //
0039 //  Calculation of Common Mode Values :
0040 //
0041 void MedianCommonModeCalculator::calculateCommonMode(ApvAnalysis::PedestalType& indat) {
0042   if (alreadyUsedEvent == false) {
0043     alreadyUsedEvent = true;
0044 
0045     theCommonModeValues.clear();
0046 
0047     double avVal = 0.0;
0048 
0049     sort(indat.begin(), indat.end());
0050 
0051     uint16_t index = indat.size() % 2 ? indat.size() / 2 : indat.size() / 2 - 1;
0052     if (!indat.empty()) {
0053       avVal = indat[index];
0054     }
0055 
0056     theCommonModeValues.push_back(static_cast<float>(avVal));
0057 
0058     MedianCommonModeCalculator::setCM(theCommonModeValues);
0059   }
0060 }
0061 
0062 //
0063 // Define New Event
0064 //
0065 void MedianCommonModeCalculator::newEvent() { alreadyUsedEvent = false; }