From 3319475fbb9a4f653d66af5206d664b6f0e75b3d Mon Sep 17 00:00:00 2001 From: Marco De Mattia Date: Thu, 15 Apr 2010 12:47:38 +0000 Subject: [PATCH] --- yaml --- r: 86827 b: "refs/heads/CMSSW_7_0_X" c: 59c4a1a1bbf137c56cf721f52db71d3f4d5965a6 h: "refs/heads/CMSSW_7_0_X" i: 86825: 24f3ace2b8e661a17d9c69a20d9d2191523fb841 86823: 099af58b89448caca713de0749b19806c1554dcc v: v3 --- [refs] | 2 +- .../SiStripObjects/interface/SiStripGain.h | 39 +++-- .../SiStripObjects/src/SiStripGain.cc | 160 +++++++++++------- 3 files changed, 117 insertions(+), 84 deletions(-) diff --git a/[refs] b/[refs] index 818b96c0e86d6..b958f92cb0331 100644 --- a/[refs] +++ b/[refs] @@ -1,3 +1,3 @@ --- refs/heads/gh-pages: 90c10214674639ca7a94515baf184b0cc75e1b69 -"refs/heads/CMSSW_7_0_X": 2ad3d8738eb7a9dd1d33f24ff1b9ef597a13ac04 +"refs/heads/CMSSW_7_0_X": 59c4a1a1bbf137c56cf721f52db71d3f4d5965a6 diff --git a/trunk/CalibFormats/SiStripObjects/interface/SiStripGain.h b/trunk/CalibFormats/SiStripObjects/interface/SiStripGain.h index 3977fd6969a12..d0387cbd4bccd 100644 --- a/trunk/CalibFormats/SiStripObjects/interface/SiStripGain.h +++ b/trunk/CalibFormats/SiStripObjects/interface/SiStripGain.h @@ -14,7 +14,7 @@ * * Original Author: gbruno * Created: Wed Mar 22 12:24:20 CET 2006 - * $Id: SiStripGain.h,v 1.5 2009/11/16 10:06:20 demattia Exp $ + * $Id: SiStripGain.h,v 1.6 2010/03/29 12:32:37 demattia Exp $ * * Modifications by M. De Mattia (demattia@pd.infn.it) on 11/11/2009: * It now holds a std::vector of pointers to ApvGain and a std::vector of corresponding @@ -39,6 +39,7 @@ #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h" #include +#include class SiStripGain { @@ -46,7 +47,8 @@ class SiStripGain SiStripGain() {}; virtual ~SiStripGain() {}; - inline SiStripGain(const SiStripApvGain& apvgain, const double & factor) + inline SiStripGain(const SiStripApvGain& apvgain, const double & factor) : + apvgain_(0) { multiply(apvgain, factor); } @@ -55,27 +57,24 @@ class SiStripGain void multiply(const SiStripApvGain & apvgain, const double & factor); // getters + // For the product of all apvGains + // ------------------------------- + const SiStripApvGain::Range getRange(const uint32_t& detID) const; + float getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range) const; + float getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range) const; + + // For a specific apvGain + // ---------------------- /** - * This method is kept for compatibility, but it can also be used to get one particular - * set of gain values. By default it will return the first gain, so if there is only - * one it will work like the old version and the old code using it will work. * The second parameter allows to specify which gain to retrieve, considering that * they are in input order. * NOTE that no protection is inside the method (because we want to keep it very light) * therefore it is the caller duty to check that the index is in the correct range. */ - const SiStripApvGain::Range getRange(const uint32_t& detID, const int index = 0) const; - /// Returns a std::vector of ranges for all the gains in the format expected by getStripGain and getApvGain. - const std::vector getAllRanges(const uint32_t& DetId) const; + const SiStripApvGain::Range getRange(const uint32_t& detID, const int index) const; + float getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range, const int index) const; + float getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range, const int index) const; - /// Used to get the gain of a specific gain set - float getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range, const int index = 0) const; - /// Used to get the full gain (product of all the gains) - float getStripGain(const uint16_t& strip, const std::vector& range) const; - /// Used to get the gain of a specific gain set - float getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range, const int index = 0) const; - /// Used to get the full gain (product of all the gains) - float getApvGain(const uint16_t& apv, const std::vector& rangeVector) const; /// ATTENTION: we assume the detIds are the same as those from the first gain void getDetIds(std::vector& DetIds_) const; @@ -84,13 +83,17 @@ class SiStripGain private: + void fillNewGain(const SiStripApvGain * apvgain, const double & factor, + const SiStripApvGain * apvgain2 = 0, const double & factor2 = 1.); SiStripGain(const SiStripGain&); // stop default const SiStripGain& operator=(const SiStripGain&); // stop default // ---------- member data -------------------------------- - std::vector apvgain_; - std::vector norm_; + std::vector apvgainVector_; + std::vector normVector_; + const SiStripApvGain * apvgain_; + std::auto_ptr apvgainAutoPtr_; }; #endif diff --git a/trunk/CalibFormats/SiStripObjects/src/SiStripGain.cc b/trunk/CalibFormats/SiStripObjects/src/SiStripGain.cc index 5bbf0e7f20c67..0fcfb98847ed4 100644 --- a/trunk/CalibFormats/SiStripObjects/src/SiStripGain.cc +++ b/trunk/CalibFormats/SiStripObjects/src/SiStripGain.cc @@ -6,98 +6,133 @@ // // Original Author: gbruno // Created: Wed Mar 22 12:24:33 CET 2006 -// $Id: SiStripGain.cc,v 1.9 2010/02/20 20:55:06 wmtan Exp $ +// $Id: SiStripGain.cc,v 1.10 2010/03/29 12:32:37 demattia Exp $ #include "FWCore/Utilities/interface/typelookup.h" #include "CalibFormats/SiStripObjects/interface/SiStripGain.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h" +#include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h" #include void SiStripGain::multiply(const SiStripApvGain & apvgain, const double & factor) { - apvgain_.push_back(&apvgain); - norm_.push_back(factor); -} - -float SiStripGain::getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range, const int index) const -{ - if( !(apvgain_.empty()) ) { - return (apvgain_[index]->getStripGain(strip, range))/(norm_[0]); + // When inserting the first ApvGain + if( apvgain_ == 0 ) { + if( (factor != 1) && (factor != 0) ) { + fillNewGain( &apvgain, factor ); + } + else { + // If the normalization factor is one, no need to create a new SiStripApvGain + apvgain_ = &apvgain; + } } else { - edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl; - return 1.; + // There is already an ApvGain inside the SiStripGain. Multiply it by the new one and save the new pointer. + std::cout << "multiplication" << std::endl; + fillNewGain( apvgain_, 1., &apvgain, factor ); } + apvgainVector_.push_back(&apvgain); + normVector_.push_back(factor); } -float SiStripGain::getStripGain(const uint16_t& strip, const std::vector& rangeVector) const +void SiStripGain::fillNewGain(const SiStripApvGain * apvgain, const double & factor, + const SiStripApvGain * apvgain2, const double & factor2) { - if( !(apvgain_.empty()) ) { - double gain = 1.; - std::vector::const_iterator range = rangeVector.begin(); - int i = 0; - for( ; range != rangeVector.end(); ++range, ++i ) { - gain*=(apvgain_[i]->getStripGain(strip, *range))/(norm_[i]); + SiStripApvGain * newApvGain = new SiStripApvGain; + edm::FileInPath fp("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"); + SiStripDetInfoFileReader reader(fp.fullPath()); + const std::map DetInfos = reader.getAllData(); + + // Loop on the apvgain in input and fill the newApvGain with the values/factor. + std::vector detIds; + apvgain->getDetIds(detIds); + std::vector::const_iterator it = detIds.begin(); + for( ; it != detIds.end(); ++it ) { + + std::map::const_iterator detInfoIt = DetInfos.find(*it); + if( detInfoIt != DetInfos.end() ) { + + std::vector theSiStripVector; + + // Loop on all the apvs and then on the strips + SiStripApvGain::Range range = apvgain->getRange(*it); + + SiStripApvGain::Range range2; + if( apvgain2 != 0 ) { + range2 = apvgain2->getRange(*it); + } + + for( int apv = 0; apv < detInfoIt->second.nApvs; ++apv ) { + float apvGainValue = apvgain->getApvGain( apv, range )/factor; + + if( (apvgain2 != 0) && (factor2 != 0.) ) { + apvGainValue *= apvgain2->getApvGain( apv, range2 )/factor2; + } + + theSiStripVector.push_back(apvGainValue); + } + SiStripApvGain::Range inputRange(theSiStripVector.begin(), theSiStripVector.end()); + if( ! newApvGain->put(*it, inputRange) ) { + edm::LogError("SiStripGain") << "detid already exists" << std::endl; + } } - return gain; } - else { + apvgain_ = newApvGain; + // Deletes the managed object and replaces it with the new one + apvgainAutoPtr_.reset(newApvGain); +} + +float SiStripGain::getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range) const +{ + if( apvgain_ == 0 ) { edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl; return 1.; } + return( apvgain_->getStripGain(strip, range) ); } -float SiStripGain::getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range, const int index) const +float SiStripGain::getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range, const int index) const { - if( !(apvgain_.empty()) ) { - return (apvgain_[index]->getApvGain(apv, range))/(norm_[0]); + if( !(apvgainVector_.empty()) ) { + return( apvgainVector_[index]->getStripGain(strip, range) ); } - else { + edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl; + return 1.; +} + +float SiStripGain::getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range) const +{ + if( apvgain_ == 0 ) { edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl; return 1.; } + return( apvgain_->getApvGain(apv, range) ); } -float SiStripGain::getApvGain(const uint16_t& apv, const std::vector& rangeVector) const +float SiStripGain::getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range, const int index) const { - if( !(apvgain_.empty()) ) { - // std::cout << "apvgain_.size() = " << apvgain_.size() << std::endl; - // std::cout << "apvgain_[0] = " << apvgain_[0]->getApvGain(apv, range) << std::endl; - double gain = 1.; - std::vector::const_iterator range = rangeVector.begin(); - int i = 0; - for( ; range != rangeVector.end(); ++range, ++i ) { - gain *= apvgain_[i]->getApvGain(apv, *range)/norm_[i]; - // std::cout << "apvgain_["<getApvGain(apv, *range) << std::endl; - } - return gain; - } - else { - edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl; - return 1.; + if( !(apvgainVector_.empty()) ) { + return (apvgainVector_[index]->getApvGain(apv, range))/(normVector_[index]); } + edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl; + return 1.; } void SiStripGain::getDetIds(std::vector& DetIds_) const { // ATTENTION: we assume the detIds are the same as those from the first gain - return apvgain_[0]->getDetIds(DetIds_); + return apvgain_->getDetIds(DetIds_); } -const SiStripApvGain::Range SiStripGain::getRange(const uint32_t& DetId, const int index) const +const SiStripApvGain::Range SiStripGain::getRange(const uint32_t& DetId) const { - return apvgain_[index]->getRange(DetId); + return apvgain_->getRange(DetId); } -const std::vector SiStripGain::getAllRanges(const uint32_t& DetId) const +const SiStripApvGain::Range SiStripGain::getRange(const uint32_t& DetId, const int index) const { - std::vector allRanges; - std::vector::const_iterator apvGainIt = apvgain_.begin(); - for( ; apvGainIt != apvgain_.end(); ++apvGainIt ) { - allRanges.push_back((*apvGainIt)->getRange(DetId)); - } - return allRanges; + return apvgainVector_[index]->getRange(DetId); } void SiStripGain::printDebug(std::stringstream & ss) const @@ -108,16 +143,13 @@ void SiStripGain::printDebug(std::stringstream & ss) const ss << "Number of detids " << detIds.size() << std::endl; for( ; detid != detIds.end(); ++detid ) { - std::vector rangeVector = getAllRanges(*detid); - if( !rangeVector.empty() ) { - // SiStripApvGain::Range range = getRange(*detid); - int apv=0; - for( int it=0; it < rangeVector[0].second - rangeVector[0].first; ++it ) { - ss << "detid " << *detid << " \t" - << " apv " << apv++ << " \t" - << getApvGain(it,rangeVector) << " \t" - << std::endl; - } + SiStripApvGain::Range range = getRange(*detid); + int apv=0; + for( int it=0; it < range.second - range.first; ++it ) { + ss << "detid " << *detid << " \t" + << " apv " << apv++ << " \t" + << getApvGain(it,range) << " \t" + << std::endl; } } } @@ -130,11 +162,9 @@ void SiStripGain::printSummary(std::stringstream& ss) const getDetIds(detIds); std::vector::const_iterator detid = detIds.begin(); for( ; detid != detIds.end(); ++detid ) { - std::vector rangeVector = getAllRanges(*detid); - if( !rangeVector.empty() ) { - for( int it=0; it < rangeVector[0].second - rangeVector[0].first; ++it ) { - summaryGain.add(*detid, getApvGain(it, rangeVector)); - } + SiStripApvGain::Range range = getRange(*detid); + for( int it=0; it < range.second - range.first; ++it ) { + summaryGain.add(*detid, getApvGain(it, range)); } } ss << "Summary of gain values:" << std::endl;