CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/CalibTracker/SiStripAPVAnalysis/src/MedianCommonModeCalculator.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripAPVAnalysis/interface/MedianCommonModeCalculator.h"
00002 #include <cmath>
00003 
00004 using namespace std;
00005 MedianCommonModeCalculator::MedianCommonModeCalculator() : 
00006   //  theNoiseCalculator(noise_calc),
00007     //  theApvMask(mask_calc),
00008   alreadyUsedEvent(false)
00009 {
00010   if (0) cout << "Constructing MedianCommonMode Calculator ..." << endl;
00011   //  cutToAvoidSignal = sig_cut;
00012 }
00013 //
00014 //  Destructor 
00015 //
00016 MedianCommonModeCalculator::~MedianCommonModeCalculator() {
00017   if (0) cout << "Destructing TT6CommonModeCalculator " << endl;
00018 }
00019 //
00020 // Action :
00021 //
00022 ApvAnalysis::PedestalType MedianCommonModeCalculator::doIt
00023                 (ApvAnalysis::PedestalType indat) 
00024 {
00025   ApvAnalysis::PedestalType out;
00026   calculateCommonMode(indat);
00027   int setNumber;
00028   if(theCommonModeValues.size() >0) {
00029     for (unsigned int i=0; i<indat.size(); i++){
00030       setNumber = theTkCommonMode->topology().setOfStrip(i);
00031       out.push_back(indat[i] - theCommonModeValues[setNumber]);
00032     }  
00033   }else{
00034     out = indat;
00035   }
00036   return out;
00037 }
00038 //
00039 //  Calculation of Common Mode Values :
00040 //
00041 void MedianCommonModeCalculator::calculateCommonMode(ApvAnalysis::PedestalType& indat) 
00042 { 
00043   if (alreadyUsedEvent == false) {
00044     alreadyUsedEvent = true;
00045     
00046     theCommonModeValues.clear();
00047     
00048     
00049     double avVal = 0.0;
00050     
00051     sort(indat.begin(),indat.end());
00052         
00053     uint16_t index = indat.size()%2 ? indat.size()/2 : indat.size()/2-1;
00054     if ( !indat.empty() ) { avVal = indat[index]; }
00055     
00056     theCommonModeValues.push_back(static_cast<float>(avVal));
00057        
00058     MedianCommonModeCalculator::setCM(theCommonModeValues);
00059 
00060   }
00061   
00062 }
00063 
00064 //
00065 // Define New Event
00066 // 
00067 void MedianCommonModeCalculator::newEvent() {
00068   alreadyUsedEvent = false;
00069 }