File indexing completed on 2023-03-17 10:44:10
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 }
0122 }
0123
0124 if (theCommonMode)
0125 theCM->setCM(theCommonMode);
0126 if (thePedestal)
0127 theAPV->setPedestalCalculator(*thePedestal);
0128 if (theNoise)
0129 theAPV->setNoiseCalculator(*theNoise);
0130 if (theMask)
0131 theAPV->setMask(*theMask);
0132 if (theCM)
0133 theAPV->setCommonModeCalculator(*theCM);
0134 }
0135
0136 void ApvAnalysisFactory::updatePair(uint32_t detId, size_t pairNumber, const edm::DetSet<SiStripRawDigi>& in) {
0137 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0138 if (apvAnalysisIt != apvMap_.end()) {
0139 size_t iter = 0;
0140
0141 for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
0142 apvIt != (apvAnalysisIt->second).end();
0143 apvIt++) {
0144 if (iter == pairNumber * 2 || iter == (2 * pairNumber + 1)) {
0145
0146
0147
0148 edm::DetSet<SiStripRawDigi> tmpRawDigi;
0149 tmpRawDigi.data.reserve(128);
0150
0151 size_t startStrip = 128 * (iter % 2);
0152 size_t stopStrip = startStrip + 128;
0153
0154 for (size_t istrip = startStrip; istrip < stopStrip; istrip++) {
0155 if (in.data.size() <= istrip)
0156 tmpRawDigi.data.push_back(SiStripRawDigi(0));
0157 else
0158 tmpRawDigi.data.push_back(in.data[istrip]);
0159 }
0160
0161 (*apvIt)->newEvent();
0162 (*apvIt)->updateCalibration(tmpRawDigi);
0163 }
0164
0165 iter++;
0166 }
0167 }
0168
0169 }
0170
0171 void ApvAnalysisFactory::update(uint32_t detId, const edm::DetSet<SiStripRawDigi>& in) {
0172 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0173 if (apvAnalysisIt != apvMap_.end()) {
0174 size_t i = 0;
0175 for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
0176 apvIt != (apvAnalysisIt->second).end();
0177 apvIt++) {
0178 edm::DetSet<SiStripRawDigi> tmpRawDigi;
0179
0180 tmpRawDigi.data.reserve(128);
0181 size_t startStrip = 128 * i;
0182 size_t stopStrip = startStrip + 128;
0183
0184 for (size_t istrip = startStrip; istrip < stopStrip; istrip++) {
0185 if (in.data.size() <= istrip)
0186 tmpRawDigi.data.push_back(SiStripRawDigi(0));
0187 else
0188 tmpRawDigi.data.push_back(in.data[istrip]);
0189 }
0190
0191 (*apvIt)->newEvent();
0192 (*apvIt)->updateCalibration(tmpRawDigi);
0193 i++;
0194 }
0195 }
0196 }
0197
0198 void ApvAnalysisFactory::getPedestal(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& peds) {
0199
0200 peds.clear();
0201 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0202 if (apvAnalysisIt != apvMap_.end()) {
0203 vector<ApvAnalysis*> myApvs = apvAnalysisIt->second;
0204 peds = myApvs[apvNumber]->pedestalCalculator().pedestal();
0205 }
0206 }
0207
0208 void ApvAnalysisFactory::getPedestal(uint32_t detId, ApvAnalysis::PedestalType& peds) {
0209
0210 peds.clear();
0211 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0212 if (apvAnalysisIt != apvMap_.end()) {
0213 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0214 for (vector<ApvAnalysis*>::const_iterator it = theApvs.begin(); it != theApvs.end(); it++) {
0215 ApvAnalysis::PedestalType tmp = (*it)->pedestalCalculator().pedestal();
0216 for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
0217 peds.push_back(*pit);
0218 }
0219 }
0220 }
0221 float ApvAnalysisFactory::getStripPedestal(uint32_t detId, int stripNumber) {
0222
0223 ApvAnalysis::PedestalType temp;
0224 int apvNumb = int(stripNumber / 128.);
0225 int stripN = (stripNumber - apvNumb * 128);
0226
0227 getPedestal(detId, apvNumb, temp);
0228 return temp[stripN];
0229 }
0230 void ApvAnalysisFactory::getNoise(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& noise) {
0231
0232 noise.clear();
0233 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0234 if (apvAnalysisIt != apvMap_.end()) {
0235 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0236
0237 noise = theApvs[apvNumber]->noiseCalculator().noise();
0238 }
0239 }
0240
0241 float ApvAnalysisFactory::getStripNoise(uint32_t detId, int stripNumber) {
0242
0243 ApvAnalysis::PedestalType temp;
0244 int apvNumb = int(stripNumber / 128.);
0245 int stripN = (stripNumber - apvNumb * 128);
0246
0247 getNoise(detId, apvNumb, temp);
0248 return temp[stripN];
0249 }
0250
0251 void ApvAnalysisFactory::getNoise(uint32_t detId, ApvAnalysis::PedestalType& peds) {
0252
0253 peds.clear();
0254 map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
0255 if (theApvs_map != apvMap_.end()) {
0256 vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
0257 for (; theApvs != (theApvs_map->second).end(); theApvs++) {
0258 ApvAnalysis::PedestalType tmp = (*theApvs)->noiseCalculator().noise();
0259 for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
0260 peds.push_back(*pit);
0261 }
0262 }
0263 }
0264
0265 void ApvAnalysisFactory::getRawNoise(uint32_t detId, int apvNumber, ApvAnalysis::PedestalType& noise) {
0266
0267 noise.clear();
0268 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0269 if (apvAnalysisIt != apvMap_.end()) {
0270 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0271
0272 noise = theApvs[apvNumber]->pedestalCalculator().rawNoise();
0273 }
0274 }
0275
0276 float ApvAnalysisFactory::getStripRawNoise(uint32_t detId, int stripNumber) {
0277
0278 ApvAnalysis::PedestalType temp;
0279 int apvNumb = int(stripNumber / 128.);
0280 int stripN = (stripNumber - apvNumb * 128);
0281
0282 getRawNoise(detId, apvNumb, temp);
0283 return temp[stripN];
0284 }
0285
0286 void ApvAnalysisFactory::getRawNoise(uint32_t detId, ApvAnalysis::PedestalType& peds) {
0287
0288 peds.clear();
0289 map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
0290 if (theApvs_map != apvMap_.end()) {
0291 vector<ApvAnalysis*>::const_iterator theApvs = (theApvs_map->second).begin();
0292 for (; theApvs != (theApvs_map->second).end(); theApvs++) {
0293 ApvAnalysis::PedestalType tmp = (*theApvs)->pedestalCalculator().rawNoise();
0294 for (ApvAnalysis::PedestalType::const_iterator pit = tmp.begin(); pit != tmp.end(); pit++)
0295 peds.push_back(*pit);
0296 }
0297 }
0298 }
0299
0300 vector<float> ApvAnalysisFactory::getCommonMode(uint32_t detId, int apvNumber) {
0301 vector<float> tmp;
0302 tmp.clear();
0303 map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
0304 if (theApvs_map != apvMap_.end()) {
0305 vector<ApvAnalysis*> theApvs = theApvs_map->second;
0306
0307 tmp = theApvs[apvNumber]->commonModeCalculator().commonMode()->returnAsVector();
0308 }
0309 return tmp;
0310 }
0311 void ApvAnalysisFactory::getCommonMode(uint32_t detId, ApvAnalysis::PedestalType& tmp) {
0312 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0313 if (apvAnalysisIt != apvMap_.end()) {
0314 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0315 for (unsigned int i = 0; i < theApvs.size(); i++) {
0316
0317 vector<float> tmp_cm = theApvs[i]->commonModeCalculator().commonMode()->returnAsVector();
0318 for (unsigned int it = 0; it < tmp_cm.size(); it++)
0319 tmp.push_back(tmp_cm[it]);
0320 }
0321 }
0322 }
0323
0324 void ApvAnalysisFactory::getMask(uint32_t det_id, TkApvMask::MaskType& tmp) {
0325 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(det_id);
0326 if (apvAnalysisIt != apvMap_.end()) {
0327 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0328 for (unsigned int i = 0; i < theApvs.size(); i++) {
0329 TkApvMask::MaskType theMaskType = (theApvs[i]->mask()).mask();
0330
0331
0332 for (unsigned int ii = 0; ii < theMaskType.size(); ii++) {
0333 tmp.push_back(theMaskType[ii]);
0334
0335 }
0336 }
0337 }
0338 }
0339 bool ApvAnalysisFactory::isUpdating(uint32_t detId) {
0340 bool updating = true;
0341 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0342 if (apvAnalysisIt != apvMap_.end()) {
0343 for (vector<ApvAnalysis*>::const_iterator apvIt = (apvAnalysisIt->second).begin();
0344 apvIt != (apvAnalysisIt->second).end();
0345 apvIt++) {
0346 if (!((*apvIt)->pedestalCalculator().status()->isUpdating()))
0347 updating = false;
0348 }
0349 }
0350 return updating;
0351 }
0352
0353 void ApvAnalysisFactory::deleteApv(ApvAnalysis* apv) {
0354 delete &(apv->pedestalCalculator());
0355 delete &(apv->noiseCalculator());
0356 delete &(apv->mask());
0357 delete &(apv->commonModeCalculator().commonMode()->topology());
0358 delete (apv->commonModeCalculator().commonMode());
0359 delete &(apv->commonModeCalculator());
0360 delete apv;
0361 }
0362
0363
0364
0365 float ApvAnalysisFactory::getCommonModeSlope(uint32_t detId, int apvNumber) {
0366 map<uint32_t, vector<ApvAnalysis*> >::const_iterator theApvs_map = apvMap_.find(detId);
0367 float tmp = -100.0;
0368 if (theApvs_map != apvMap_.end()) {
0369 vector<ApvAnalysis*> theApvs = theApvs_map->second;
0370 tmp = theApvs[apvNumber]->commonModeCalculator().getCMSlope();
0371 return tmp;
0372 }
0373 return tmp;
0374 }
0375 void ApvAnalysisFactory::getCommonModeSlope(uint32_t detId, ApvAnalysis::PedestalType& tmp) {
0376 tmp.clear();
0377 map<uint32_t, vector<ApvAnalysis*> >::const_iterator apvAnalysisIt = apvMap_.find(detId);
0378 if (apvAnalysisIt != apvMap_.end()) {
0379 vector<ApvAnalysis*> theApvs = apvAnalysisIt->second;
0380 for (unsigned int i = 0; i < theApvs.size(); i++) {
0381 tmp.push_back(theApvs[i]->commonModeCalculator().getCMSlope());
0382 }
0383 }
0384 }