CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CalibTracker/SiStripAPVAnalysis/src/TT6CommonModeCalculator.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripAPVAnalysis/interface/TT6CommonModeCalculator.h"
00002 #include <cmath>
00003 
00004 using namespace std;
00005 TT6CommonModeCalculator::TT6CommonModeCalculator(TkNoiseCalculator* noise_calc, TkApvMask* mask_calc, float sig_cut) : 
00006   theNoiseCalculator(noise_calc),
00007   theApvMask(mask_calc),
00008   alreadyUsedEvent(false)
00009 {
00010   if (0) cout << "Constructing TT6CommonMode Calculator ..." << endl;
00011   cutToAvoidSignal = sig_cut;
00012 }
00013 //
00014 //  Destructor 
00015 //
00016 TT6CommonModeCalculator::~TT6CommonModeCalculator() {
00017   if (0) cout << "Destructing TT6CommonModeCalculator " << endl;
00018 }
00019 //
00020 // Action :
00021 //
00022 ApvAnalysis::PedestalType TT6CommonModeCalculator::doIt
00023                 (const ApvAnalysis::PedestalType& _indat) 
00024 {
00025   ApvAnalysis::PedestalType indat = _indat;
00026   ApvAnalysis::PedestalType out;
00027   calculateCommonMode(indat);
00028   int setNumber;
00029   if(theCommonModeValues.size() >0) {
00030     for (unsigned int i=0; i<indat.size(); i++){
00031       setNumber = theTkCommonMode->topology().setOfStrip(i);
00032       out.push_back(indat[i] - theCommonModeValues[setNumber]);
00033     }  
00034   }else{
00035     out = indat;
00036   }
00037   return out;
00038 }
00039 //
00040 //  Calculation of Common Mode Values :
00041 //
00042 void TT6CommonModeCalculator::calculateCommonMode(ApvAnalysis::PedestalType& indat) 
00043 { 
00044   if (alreadyUsedEvent == false) {
00045     alreadyUsedEvent = true;
00046     //  cout<< "I am inside the calculateCommonMode"<<endl;
00047     TkApvMask::MaskType strip_mask = theApvMask->mask();
00048     ApvAnalysis::PedestalType strip_noise = theNoiseCalculator->noise();
00049     theCommonModeValues.clear();
00050     
00051     if(strip_noise.size() > 0) {
00052       int nSet = theTkCommonMode->topology().numberOfSets();
00053       for (int i=0; i<nSet; i++){
00054         int initial   = theTkCommonMode->topology().initialStrips()[i];
00055         int final     = theTkCommonMode->topology().finalStrips()[i];
00056         double sumVal = 0.0;
00057         double sumWt =  0.0;
00058         for (int j = initial; j <= final; j++) {
00059           if (strip_mask[j] == TkApvMask::ok ) {
00060             if(fabs(indat[j]) < cutToAvoidSignal*strip_noise[j]) { 
00061               double nWeight = 1/(strip_noise[j]*strip_noise[j]);
00062               sumVal += (indat[j]*nWeight);
00063               sumWt += nWeight;
00064             }
00065           }
00066         }
00067         double avVal = (sumWt) ? sumVal/sumWt :0.0;
00068         theCommonModeValues.push_back(static_cast<float>(avVal));
00069         //cout <<"Setting CM values"<<endl;
00070       }
00071     }
00072   }
00073   TT6CommonModeCalculator::setCM(theCommonModeValues);
00074   calculateCMSlope(indat);     
00075 }
00076 //
00077 // Define New Event
00078 // 
00079 void TT6CommonModeCalculator::newEvent() {
00080   alreadyUsedEvent = false;
00081 }
00082 //
00083 // Calculate CMSlope 
00084 // 
00085 void TT6CommonModeCalculator::calculateCMSlope(ApvAnalysis::PedestalType& indat) {
00086   if (indat.size() != 128) {
00087     slope = -100.0;
00088     return;
00089   }
00090   ApvAnalysis::PedestalType diffVec;
00091   diffVec.clear();
00092   for(int s=0;s<64;s++) diffVec.push_back(indat[s+64]-indat[s]);
00093   std::sort(diffVec.begin(),diffVec.end());
00094   slope = (diffVec[31]+diffVec[32])/2./64.;
00095 }
00096