Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 86827
b: "refs/heads/CMSSW_7_0_X"
c: 59c4a1a
h: "refs/heads/CMSSW_7_0_X"
i:
  86825: 24f3ace
  86823: 099af58
v: v3
  • Loading branch information
Marco De Mattia committed Apr 15, 2010
1 parent 263c6e0 commit 3319475
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 84 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
refs/heads/gh-pages: 90c10214674639ca7a94515baf184b0cc75e1b69
"refs/heads/CMSSW_7_0_X": 2ad3d8738eb7a9dd1d33f24ff1b9ef597a13ac04
"refs/heads/CMSSW_7_0_X": 59c4a1a1bbf137c56cf721f52db71d3f4d5965a6
39 changes: 21 additions & 18 deletions trunk/CalibFormats/SiStripObjects/interface/SiStripGain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected]) on 11/11/2009:
* It now holds a std::vector of pointers to ApvGain and a std::vector of corresponding
Expand All @@ -39,14 +39,16 @@

#include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
#include <vector>
#include <memory>

class SiStripGain
{
public:
SiStripGain() {};
virtual ~SiStripGain() {};

inline SiStripGain(const SiStripApvGain& apvgain, const double & factor)
inline SiStripGain(const SiStripApvGain& apvgain, const double & factor) :
apvgain_(0)
{
multiply(apvgain, factor);
}
Expand All @@ -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<SiStripApvGain::Range> 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<SiStripApvGain::Range>& 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<SiStripApvGain::Range>& rangeVector) const;
/// ATTENTION: we assume the detIds are the same as those from the first gain
void getDetIds(std::vector<uint32_t>& DetIds_) const;

Expand All @@ -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<const SiStripApvGain *> apvgain_;
std::vector<double> norm_;
std::vector<const SiStripApvGain *> apvgainVector_;
std::vector<double> normVector_;
const SiStripApvGain * apvgain_;
std::auto_ptr<SiStripApvGain> apvgainAutoPtr_;
};

#endif
160 changes: 95 additions & 65 deletions trunk/CalibFormats/SiStripObjects/src/SiStripGain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,98 +6,133 @@
// <Notes on implementation>
// 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 <sstream>

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<SiStripApvGain::Range>& 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<SiStripApvGain::Range>::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<uint32_t, SiStripDetInfoFileReader::DetInfo> DetInfos = reader.getAllData();

// Loop on the apvgain in input and fill the newApvGain with the values/factor.
std::vector<uint32_t> detIds;
apvgain->getDetIds(detIds);
std::vector<uint32_t>::const_iterator it = detIds.begin();
for( ; it != detIds.end(); ++it ) {

std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator detInfoIt = DetInfos.find(*it);
if( detInfoIt != DetInfos.end() ) {

std::vector<float> 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<SiStripApvGain::Range>& 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<SiStripApvGain::Range>::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_["<<i<<"] = " << apvgain_[i]->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<uint32_t>& 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<SiStripApvGain::Range> SiStripGain::getAllRanges(const uint32_t& DetId) const
const SiStripApvGain::Range SiStripGain::getRange(const uint32_t& DetId, const int index) const
{
std::vector<SiStripApvGain::Range> allRanges;
std::vector<const SiStripApvGain*>::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
Expand All @@ -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<SiStripApvGain::Range> 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;
}
}
}
Expand All @@ -130,11 +162,9 @@ void SiStripGain::printSummary(std::stringstream& ss) const
getDetIds(detIds);
std::vector<uint32_t>::const_iterator detid = detIds.begin();
for( ; detid != detIds.end(); ++detid ) {
std::vector<SiStripApvGain::Range> 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;
Expand Down

0 comments on commit 3319475

Please sign in to comment.