File indexing completed on 2024-10-04 22:54:24
0001 #include "CalibTracker/SiStripAPVAnalysis/interface/ApvAnalysisFactory.h"
0002
0003
0004 #include "CalibTracker/SiStripAPVAnalysis/interface/TT6NTPedestalCalculator.h"
0005
0006 using namespace std;
0007 ApvAnalysisFactory::ApvAnalysisFactory(string theAlgorithmType,
0008 int theNumCMstripsInGroup,
0009 int theMaskCalcFlag,
0010 float theMaskNoiseCut,
0011 float theMaskDeadCut,
0012 float theMaskTruncCut,
0013 float theCutToAvoidSignal,
0014 int theEventInitNumber,
0015 int theEventIterNumber) {
0016 theAlgorithmType_ = theAlgorithmType;
0017 theNumCMstripsInGroup_ = theNumCMstripsInGroup;
0018 theMaskCalcFlag_ = theMaskCalcFlag;
0019 theMaskNoiseCut_ = theMaskNoiseCut;
0020 theMaskDeadCut_ = theMaskDeadCut;
0021 theMaskTruncCut_ = theMaskTruncCut;
0022 theCutToAvoidSignal_ = theCutToAvoidSignal;
0023 theEventInitNumber_ = theEventInitNumber;
0024 theEventIterNumber_ = theEventIterNumber;
0025 }
0026
0027 ApvAnalysisFactory::ApvAnalysisFactory(const edm::ParameterSet& pset) {
0028 theCMType_ = pset.getParameter<string>("CMType");
0029 useDB_ = pset.getParameter<bool>("useDB");
0030
0031 theAlgorithmType_ = pset.getParameter<string>("CalculatorAlgorithm");
0032 theNumCMstripsInGroup_ = pset.getParameter<int>("NumCMstripsInGroup");
0033 theMaskCalcFlag_ = pset.getParameter<int>("MaskCalculationFlag");
0034
0035 theMaskNoiseCut_ = pset.getParameter<double>("MaskNoiseCut");
0036 theMaskDeadCut_ = pset.getParameter<double>("MaskDeadCut");
0037 theMaskTruncCut_ = pset.getParameter<double>("MaskTruncationCut");
0038 theCutToAvoidSignal_ = pset.getParameter<double>("CutToAvoidSignal");
0039
0040 theEventInitNumber_ = pset.getParameter<int>("NumberOfEventsForInit");
0041 theEventIterNumber_ = pset.getParameter<int>("NumberOfEventsForIteration");
0042 apvMap_.clear();
0043 }
0044
0045 ApvAnalysisFactory::~ApvAnalysisFactory() {
0046 ApvAnalysisFactory::ApvAnalysisMap::iterator it = apvMap_.begin();
0047 for (; it != apvMap_.end(); it++) {
0048 vector<ApvAnalysis*>::iterator myApv = (*it).second.begin();
0049 for (; myApv != (*it).second.end(); myApv++)
0050 deleteApv(*myApv);
0051 }
0052 apvMap_.clear();
0053 }
0054
0055
0056
0057 bool ApvAnalysisFactory::instantiateApvs(uint32_t detId, int numberOfApvs) {
0058 ApvAnalysisFactory::ApvAnalysisMap::iterator CPos = apvMap_.find(detId);
0059 if (CPos != apvMap_.end()) {
0060 cout << " APVs for Detector Id " << detId << " already created !!!" << endl;
0061 ;
0062 return false;
0063 }
0064 vector<ApvAnalysis*> temp;
0065 for (int i = 0; i < numberOfApvs; i++) {
0066 ApvAnalysis* apvTmp = new ApvAnalysis(theEventIterNumber_);
0067
0068 constructAuxiliaryApvClasses(apvTmp, detId, i);
0069 temp.push_back(apvTmp);
0070 }
0071 apvMap_.insert(pair<uint32_t, vector<ApvAnalysis*> >(detId, temp));
0072 return true;
0073 }
0074
0075 std::vector<ApvAnalysis*> ApvAnalysisFactory::getApvAnalysis(const uint32_t nDET_ID) {
0076 ApvAnalysisMap::const_iterator _apvAnalysisIter = apvMap_.find(nDET_ID);
0077
0078 return apvMap_.end() != _apvAnalysisIter ? _apvAnalysisIter->second : std::vector<ApvAnalysis*>();
0079 }
0080
0081 void ApvAnalysisFactory::constructAuxiliaryApvClasses(ApvAnalysis* theAPV, uint32_t detId, int thisApv) {
0082
0083
0084
0085
0086
0087
0088
0089 TkPedestalCalculator* thePedestal = nullptr;
0090 TkNoiseCalculator* theNoise = nullptr;
0091 TkApvMask* theMask = nullptr;
0092 TkCommonModeCalculator* theCM = nullptr;
0093
0094 TkCommonMode* theCommonMode = new TkCommonMode();
0095 TkCommonModeTopology* theTopology = new TkCommonModeTopology(128, theNumCMstripsInGroup_);
0096 theCommonMode->setTopology(theTopology);
0097
0098
0099 if (theAlgorithmType_ == "TT6") {
0100 theMask = new TT6ApvMask(theMaskCalcFlag_, theMaskNoiseCut_, theMaskDeadCut_, theMaskTruncCut_);
0101 theNoise = new TT6NoiseCalculator(theEventInitNumber_, theEventIterNumber_, theCutToAvoidSignal_);
0102 thePedestal = new TT6PedestalCalculator(theEventInitNumber_, theEventIterNumber_, theCutToAvoidSignal_);
0103 theCM = new TT6CommonModeCalculator(theNoise, theMask, theCutToAvoidSignal_);
0104 } else if ("TT6NT" == theAlgorithmType_) {
0105 theMask = new TT6ApvMask(theMaskCalcFlag_, theMaskNoiseCut_, theMaskDeadCut_, theMaskTruncCut_);
0106 theNoise = new TT6NoiseCalculator(theEventInitNumber_, theEventIterNumber_, theCutToAvoidSignal_);
0107 thePedestal = new TT6NTPedestalCalculator;
0108 theCM = new TT6CommonModeCalculator(theNoise, theMask, theCutToAvoidSignal_);
0109 } else if (theAlgorithmType_ == "MIX") {
0110
0111 theMask = new TT6ApvMask(theMaskCalcFlag_, theMaskNoiseCut_, theMaskDeadCut_, theMaskTruncCut_);
0112
0113 thePedestal = new SimplePedestalCalculator(theEventInitNumber_);
0114
0115 theNoise = new SimpleNoiseCalculator(theEventInitNumber_, useDB_);
0116
0117 if (theCMType_ == "Median") {
0118 theCM = new MedianCommonModeCalculator();
0119 } else {
0120 cout << "Sorry Only Median is available for now, Mean and FastLinear are coming soon" << endl;
0121 delete theCommonMode;
0122 delete theMask;
0123 delete thePedestal;
0124 delete theNoise;
0125 return;
0126 }
0127 } else {
0128 cout << "ApvAnalysisFactory: algorithm " << theAlgorithmType_ << " not supported" << endl;
0129 delete theCommonMode;
0130 return;
0131 }
0132
0133 if (theCommonMode)
0134 theCM->setCM(theCommonMode);
0135 if (thePedestal)
0136 theAPV->setPedestalCalculator(*thePedestal);
0137 if (theNoise)
0138 theAPV->setNoiseCalculator(*theNoise);
0139 if (theMask)
0140 theAPV->setMask(*theMask);
0141 if (theCM)
0142 theAPV->setCommonModeCalculator(*theCM);
0143 }
0144
0145 void ApvAnalysisFactory::updatePair(uint32_t detId, size_t pairNumber, const edm::DetSet<SiStripRawDigi>& in) {
0146 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0147 if (apvAnalysisIt != apvMap_.end()) {
0148 size_t iter = 0;
0149
0150 for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
0151 apvIt != (apvAnalysisIt->second).end();
0152 apvIt++) {
0153 if (iter == pairNumber * 2 || iter == (2 * pairNumber + 1)) {
0154
0155
0156
0157 edm::DetSet<SiStripRawDigi> tmpRawDigi;
0158 tmpRawDigi.data.reserve(128);
0159
0160 size_t startStrip = 128 * (iter % 2);
0161 size_t stopStrip = startStrip + 128;
0162
0163 for (size_t istrip = startStrip; istrip < stopStrip; istrip++) {
0164 if (in.data.size() <= istrip)
0165 tmpRawDigi.data.push_back(SiStripRawDigi(0));
0166 else
0167 tmpRawDigi.data.push_back(in.data[istrip]);
0168 }
0169
0170 (*apvIt)->newEvent();
0171 (*apvIt)->updateCalibration(tmpRawDigi);
0172 }
0173
0174 iter++;
0175 }
0176 }
0177
0178 }
0179
0180 void ApvAnalysisFactory::update(uint32_t detId, const edm::DetSet<SiStripRawDigi>& in) {
0181 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0182 if (apvAnalysisIt != apvMap_.end()) {
0183 size_t i = 0;
0184 for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
0185 apvIt != (apvAnalysisIt->second).end();
0186 apvIt++) {
0187 edm::DetSet<SiStripRawDigi> tmpRawDigi;
0188
0189 tmpRawDigi.data.reserve(128);
0190 size_t startStrip = 128 * i;
0191 size_t stopStrip = startStrip + 128;
0192
0193 for (size_t istrip = startStrip; istrip < stopStrip; istrip++) {
0194 if (in.data.size() <= istrip)
0195 tmpRawDigi.data.push_back(SiStripRawDigi(0));
0196 else
0197 tmpRawDigi.data.push_back(in.data[istrip]);
0198 }
0199
0200 (*apvIt)->newEvent();
0201 (*apvIt)->updateCalibration(tmpRawDigi);
0202 i++;
0203 }
0204 }
0205 }
0206
0207 void ApvAnalysisFactory::getPedestal(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& peds) {
0208
0209 peds.clear();
0210 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0211 if (apvAnalysisIt != apvMap_.end()) {
0212 vector<ApvAnalysis*> myApvs = apvAnalysisIt->second;
0213 peds = myApvs[apvNumber]->pedestalCalculator().pedestal();
0214 }
0215 }
0216
0217 void ApvAnalysisFactory::getPedestal(uint32_t detId, ApvAnalysis::PedestalType& peds) {
0218
0219 peds.clear();
0220 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0221 if (apvAnalysisIt != apvMap_.end()) {
0222 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0223 for (vector<ApvAnalysis*>::const_iterator it = theApvs.begin(); it != theApvs.end(); it++) {
0224 ApvAnalysis::PedestalType tmp = (*it)->pedestalCalculator().pedestal();
0225 for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
0226 peds.push_back(*pit);
0227 }
0228 }
0229 }
0230 float ApvAnalysisFactory::getStripPedestal(uint32_t detId, int stripNumber) {
0231
0232 ApvAnalysis::PedestalType temp;
0233 int apvNumb = int(stripNumber / 128.);
0234 int stripN = (stripNumber - apvNumb * 128);
0235
0236 getPedestal(detId, apvNumb, temp);
0237 return temp[stripN];
0238 }
0239 void ApvAnalysisFactory::getNoise(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& noise) {
0240
0241 noise.clear();
0242 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0243 if (apvAnalysisIt != apvMap_.end()) {
0244 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0245
0246 noise = theApvs[apvNumber]->noiseCalculator().noise();
0247 }
0248 }
0249
0250 float ApvAnalysisFactory::getStripNoise(uint32_t detId, int stripNumber) {
0251
0252 ApvAnalysis::PedestalType temp;
0253 int apvNumb = int(stripNumber / 128.);
0254 int stripN = (stripNumber - apvNumb * 128);
0255
0256 getNoise(detId, apvNumb, temp);
0257 return temp[stripN];
0258 }
0259
0260 void ApvAnalysisFactory::getNoise(uint32_t detId, ApvAnalysis::PedestalType& peds) {
0261
0262 peds.clear();
0263 map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
0264 if (theApvs_map != apvMap_.end()) {
0265 vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
0266 for (; theApvs != (theApvs_map->second).end(); theApvs++) {
0267 ApvAnalysis::PedestalType tmp = (*theApvs)->noiseCalculator().noise();
0268 for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
0269 peds.push_back(*pit);
0270 }
0271 }
0272 }
0273
0274 void ApvAnalysisFactory::getRawNoise(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& noise) {
0275
0276 noise.clear();
0277 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0278 if (apvAnalysisIt != apvMap_.end()) {
0279 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0280
0281 noise = theApvs[apvNumber]->pedestalCalculator().rawNoise();
0282 }
0283 }
0284
0285 float ApvAnalysisFactory::getStripRawNoise(uint32_t detId, int stripNumber) {
0286
0287 ApvAnalysis::PedestalType temp;
0288 int apvNumb = int(stripNumber / 128.);
0289 int stripN = (stripNumber - apvNumb * 128);
0290
0291 getRawNoise(detId, apvNumb, temp);
0292 return temp[stripN];
0293 }
0294
0295 void ApvAnalysisFactory::getRawNoise(uint32_t detId, ApvAnalysis::PedestalType& peds) {
0296
0297 peds.clear();
0298 map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
0299 if (theApvs_map != apvMap_.end()) {
0300 vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
0301 for (; theApvs != (theApvs_map->second).end(); theApvs++) {
0302 ApvAnalysis::PedestalType tmp = (*theApvs)->pedestalCalculator().rawNoise();
0303 for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
0304 peds.push_back(*pit);
0305 }
0306 }
0307 }
0308
0309 vector<float> ApvAnalysisFactory::getCommonMode(uint32_t detId, int apvNumber) {
0310 vector<float> tmp;
0311 tmp.clear();
0312 map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
0313 if (theApvs_map != apvMap_.end()) {
0314 vector<ApvAnalysis*> theApvs = theApvs_map->second;
0315
0316 tmp = theApvs[apvNumber]->commonModeCalculator().commonMode()->returnAsVector();
0317 }
0318 return tmp;
0319 }
0320 void ApvAnalysisFactory::getCommonMode(uint32_t detId, ApvAnalysis::PedestalType& tmp) {
0321 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0322 if (apvAnalysisIt != apvMap_.end()) {
0323 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0324 for (unsigned int i = 0; i < theApvs.size(); i++) {
0325
0326 vector<float> tmp_cm = theApvs[i]->commonModeCalculator().commonMode()->returnAsVector();
0327 for (unsigned int it = 0; it < tmp_cm.size(); it++)
0328 tmp.push_back(tmp_cm[it]);
0329 }
0330 }
0331 }
0332
0333 void ApvAnalysisFactory::getMask(uint32_t det_id, TkApvMask::MaskType& tmp) {
0334 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(det_id);
0335 if (apvAnalysisIt != apvMap_.end()) {
0336 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0337 for (unsigned int i = 0; i < theApvs.size(); i++) {
0338 TkApvMask::MaskType theMaskType = (theApvs[i]->mask()).mask();
0339
0340
0341 for (unsigned int ii = 0; ii < theMaskType.size(); ii++) {
0342 tmp.push_back(theMaskType[ii]);
0343
0344 }
0345 }
0346 }
0347 }
0348 bool ApvAnalysisFactory::isUpdating(uint32_t detId) {
0349 bool updating = true;
0350 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0351 if (apvAnalysisIt != apvMap_.end()) {
0352 for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
0353 apvIt != (apvAnalysisIt->second).end();
0354 apvIt++) {
0355 if (!((*apvIt)->pedestalCalculator().status()->isUpdating()))
0356 updating = false;
0357 }
0358 }
0359 return updating;
0360 }
0361
0362 void ApvAnalysisFactory::deleteApv(ApvAnalysis* apv) {
0363 delete &(apv->pedestalCalculator());
0364 delete &(apv->noiseCalculator());
0365 delete &(apv->mask());
0366 delete &(apv->commonModeCalculator().commonMode()->topology());
0367 delete (apv->commonModeCalculator().commonMode());
0368 delete &(apv->commonModeCalculator());
0369 delete apv;
0370 }
0371
0372
0373
0374 float ApvAnalysisFactory::getCommonModeSlope(uint32_t detId, int apvNumber) {
0375 map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
0376 float tmp = -100.0;
0377 if (theApvs_map != apvMap_.end()) {
0378 vector<ApvAnalysis*> theApvs = theApvs_map->second;
0379 tmp = theApvs[apvNumber]->commonModeCalculator().getCMSlope();
0380 return tmp;
0381 }
0382 return tmp;
0383 }
0384 void ApvAnalysisFactory::getCommonModeSlope(uint32_t detId, ApvAnalysis::PedestalType& tmp) {
0385 tmp.clear();
0386 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0387 if (apvAnalysisIt != apvMap_.end()) {
0388 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0389 for (unsigned int i = 0; i < theApvs.size(); i++) {
0390 tmp.push_back(theApvs[i]->commonModeCalculator().getCMSlope());
0391 }
0392 }
0393 }