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 (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 TT6CommonModeCalculator::calculateCommonMode(ApvAnalysis::PedestalType& indat) 00042 { 00043 if (alreadyUsedEvent == false) { 00044 alreadyUsedEvent = true; 00045 // cout<< "I am inside the calculateCommonMode"<<endl; 00046 TkApvMask::MaskType strip_mask = theApvMask->mask(); 00047 ApvAnalysis::PedestalType strip_noise = theNoiseCalculator->noise(); 00048 theCommonModeValues.clear(); 00049 00050 if(strip_noise.size() > 0) { 00051 int nSet = theTkCommonMode->topology().numberOfSets(); 00052 for (int i=0; i<nSet; i++){ 00053 int initial = theTkCommonMode->topology().initialStrips()[i]; 00054 int final = theTkCommonMode->topology().finalStrips()[i]; 00055 double sumVal = 0.0; 00056 double sumWt = 0.0; 00057 for (int j = initial; j <= final; j++) { 00058 if (strip_mask[j] == TkApvMask::ok ) { 00059 if(fabs(indat[j]) < cutToAvoidSignal*strip_noise[j]) { 00060 double nWeight = 1/(strip_noise[j]*strip_noise[j]); 00061 sumVal += (indat[j]*nWeight); 00062 sumWt += nWeight; 00063 } 00064 } 00065 } 00066 double avVal = (sumWt) ? sumVal/sumWt :0.0; 00067 theCommonModeValues.push_back(static_cast<float>(avVal)); 00068 //cout <<"Setting CM values"<<endl; 00069 } 00070 } 00071 } 00072 TT6CommonModeCalculator::setCM(theCommonModeValues); 00073 calculateCMSlope(indat); 00074 } 00075 // 00076 // Define New Event 00077 // 00078 void TT6CommonModeCalculator::newEvent() { 00079 alreadyUsedEvent = false; 00080 } 00081 // 00082 // Calculate CMSlope 00083 // 00084 void TT6CommonModeCalculator::calculateCMSlope(ApvAnalysis::PedestalType& indat) { 00085 if (indat.size() != 128) { 00086 slope = -100.0; 00087 return; 00088 } 00089 ApvAnalysis::PedestalType diffVec; 00090 diffVec.clear(); 00091 for(int s=0;s<64;s++) diffVec.push_back(indat[s+64]-indat[s]); 00092 std::sort(diffVec.begin(),diffVec.end()); 00093 slope = (diffVec[31]+diffVec[32])/2./64.; 00094 } 00095