Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CalibTracker/SiStripAPVAnalysis/interface/TT6CommonModeCalculator.h"
0002 #include <cmath>
0003 
0004 using namespace std;
0005 TT6CommonModeCalculator::TT6CommonModeCalculator(TkNoiseCalculator* noise_calc, TkApvMask* mask_calc, float sig_cut)
0006     : theNoiseCalculator(noise_calc), theApvMask(mask_calc), alreadyUsedEvent(false) {
0007   if (false)
0008     cout << "Constructing TT6CommonMode Calculator ..." << endl;
0009   cutToAvoidSignal = sig_cut;
0010 }
0011 //
0012 //  Destructor
0013 //
0014 TT6CommonModeCalculator::~TT6CommonModeCalculator() {
0015   if (false)
0016     cout << "Destructing TT6CommonModeCalculator " << endl;
0017 }
0018 //
0019 // Action :
0020 //
0021 ApvAnalysis::PedestalType TT6CommonModeCalculator::doIt(const ApvAnalysis::PedestalType& _indat) {
0022   ApvAnalysis::PedestalType indat = _indat;
0023   ApvAnalysis::PedestalType out;
0024   calculateCommonMode(indat);
0025   int setNumber;
0026   if (!theCommonModeValues.empty()) {
0027     for (unsigned int i = 0; i < indat.size(); i++) {
0028       setNumber = theTkCommonMode->topology().setOfStrip(i);
0029       out.push_back(indat[i] - theCommonModeValues[setNumber]);
0030     }
0031   } else {
0032     out = indat;
0033   }
0034   return out;
0035 }
0036 //
0037 //  Calculation of Common Mode Values :
0038 //
0039 void TT6CommonModeCalculator::calculateCommonMode(ApvAnalysis::PedestalType& indat) {
0040   if (alreadyUsedEvent == false) {
0041     alreadyUsedEvent = true;
0042     //  cout<< "I am inside the calculateCommonMode"<<endl;
0043     TkApvMask::MaskType strip_mask = theApvMask->mask();
0044     ApvAnalysis::PedestalType strip_noise = theNoiseCalculator->noise();
0045     theCommonModeValues.clear();
0046 
0047     if (!strip_noise.empty()) {
0048       int nSet = theTkCommonMode->topology().numberOfSets();
0049       for (int i = 0; i < nSet; i++) {
0050         int initial = theTkCommonMode->topology().initialStrips()[i];
0051         int final = theTkCommonMode->topology().finalStrips()[i];
0052         double sumVal = 0.0;
0053         double sumWt = 0.0;
0054         for (int j = initial; j <= final; j++) {
0055           if (strip_mask[j] == TkApvMask::ok) {
0056             if (fabs(indat[j]) < cutToAvoidSignal * strip_noise[j]) {
0057               double nWeight = 1 / (strip_noise[j] * strip_noise[j]);
0058               sumVal += (indat[j] * nWeight);
0059               sumWt += nWeight;
0060             }
0061           }
0062         }
0063         double avVal = (sumWt) ? sumVal / sumWt : 0.0;
0064         theCommonModeValues.push_back(static_cast<float>(avVal));
0065         //cout <<"Setting CM values"<<endl;
0066       }
0067     }
0068   }
0069   TT6CommonModeCalculator::setCM(theCommonModeValues);
0070   calculateCMSlope(indat);
0071 }
0072 //
0073 // Define New Event
0074 //
0075 void TT6CommonModeCalculator::newEvent() { alreadyUsedEvent = false; }
0076 //
0077 // Calculate CMSlope
0078 //
0079 void TT6CommonModeCalculator::calculateCMSlope(ApvAnalysis::PedestalType& indat) {
0080   if (indat.size() != 128) {
0081     slope = -100.0;
0082     return;
0083   }
0084   ApvAnalysis::PedestalType diffVec;
0085   diffVec.clear();
0086   for (int s = 0; s < 64; s++)
0087     diffVec.push_back(indat[s + 64] - indat[s]);
0088   std::sort(diffVec.begin(), diffVec.end());
0089   slope = (diffVec[31] + diffVec[32]) / 2. / 64.;
0090 }