1 #ifndef CalibTracker_SiStripESProducers_SiStripGainESProducerTemplate_h
2 #define CalibTracker_SiStripESProducers_SiStripGainESProducerTemplate_h
6 #include "boost/shared_ptr.hpp"
25 template<
typename TDependentRecord,
typename TInputRecord>
31 std::auto_ptr<SiStripGain>
produce(
const TDependentRecord&);
39 std::vector<std::pair<std::string, std::string> >
apvgain_;
44 std::vector<edm::ESHandle<SiStripApvGain> >
pDD;
49 template<
typename TDependentRecord,
typename TInputRecord>
52 setWhatProduced(
this);
54 automaticMode_ = iConfig.
getParameter<
bool>(
"AutomaticNormalization");
56 apvGainLabels_ = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"APVGain");
59 std::vector<edm::ParameterSet>::const_iterator gainPSetIt = apvGainLabels_.begin();
60 for( ; gainPSetIt != apvGainLabels_.end(); ++gainPSetIt ) {
61 apvgain_.push_back( std::make_pair(gainPSetIt->getParameter<std::string>(
"Record"), gainPSetIt->getUntrackedParameter<std::string>(
"Label",
"")) );
62 norm_.push_back(gainPSetIt->getUntrackedParameter<
double>(
"NormalizationFactor", 1.));
65 std::vector<double>::const_iterator it = norm_.begin();
66 for( ; it != norm_.end(); ++it ) {
67 if( *it <= 0 ) badNorm =
true;
70 if(!automaticMode_ && badNorm ){
71 edm::LogError(
"SiStripGainESProducer") <<
"[SiStripGainESProducer] - ERROR: negative or zero Normalization factor provided. Assuming 1 for such factor" << std::endl;
72 norm_ = std::vector<double>(norm_.size(), 1.);
76 template<
typename TDependentRecord,
typename TInputRecord>
79 std::auto_ptr<SiStripGain> ptr(SiStripGainNormalizationFunction(iRecord));
83 template<
typename TDependentRecord,
typename TInputRecord>
88 std::string
recordName( recordLabelPair.first );
89 std::string labelName( recordLabelPair.second );
93 else edm::LogError(
"SiStripGainESProducer::SiStripGainNormalizationFunction") <<
"ERROR: unrecognized record name " << recordName << std::endl
94 <<
"please specify one of: SiStripApvGainRcd, SiStripApvGain2Rcd, SiStripApvGain3Rcd" << std::endl;
97 template<
typename TDependentRecord,
typename TInputRecord>
107 fillApvGain( a, apvgain_[0], pDD );
111 if( apvgain_.size() > 1 ) {
112 for(
unsigned int i=1;
i<apvgain_.size(); ++
i ) {
113 fillApvGain( a, apvgain_[
i], pDD );
115 gain->
multiply(*(pDD[i].product()), getNFactor(i), apvgain_[i]);
128 if( apvgain_.size() > 1 ) {
129 for(
unsigned int i=1;
i<apvgain_.size(); ++
i ) {
132 gain->
multiply(*(pDD[i].product()), getNFactor(i), apvgain_[i]);
138 edm::LogError(
"SiStripGainESProducer") <<
"[SiStripGainNormalizationFunction] - ERROR: asking for a pair of records different from <SiStripGainRcd,SiStripApvGainRcd> and <SiStripGainSimRcd,SiStripApvGainSimRcd>" << std::endl;
142 template<
typename TDependentRecord,
typename TInputRecord>
146 if(automaticMode_ || printdebug_ ){
148 std::vector<uint32_t> DetIds;
149 pDD[apvGainIndex]->getDetIds(DetIds);
151 double SumOfGains=0.;
154 for(std::vector<uint32_t>::const_iterator detit=DetIds.begin(); detit!=DetIds.end(); detit++){
160 for(std::vector<float>::const_iterator apvit=detRange.first; apvit!=detRange.second; apvit++){
162 SumOfGains+=(*apvit);
165 edm::LogInfo(
"SiStripGainESProducer::produce()")<<
"detid/component: " << *detit <<
"/"<<iComp<<
" gain factor " <<*apvit ;
171 if(SumOfGains>0 && NGains>0){
172 NFactor=SumOfGains/NGains;
175 edm::LogError(
"SiStripGainESProducer::produce() - ERROR: empty set of gain values received. Cannot compute normalization factor. Assuming 1 for such factor") << std::endl;
182 NFactor=norm_[apvGainIndex];
185 if (printdebug_)
edm::LogInfo(
"SiStripGainESProducer")<<
" putting A SiStrip Gain object in eventSetup with normalization factor " << NFactor ;
void multiply(const SiStripApvGain &apvgain, const double &factor, const std::pair< std::string, std::string > &recordLabelPair)
Used to input additional gain values that will be multiplied to the first one.
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< edm::ESHandle< SiStripApvGain > > pDD
std::auto_ptr< SiStripGain > produce(const TDependentRecord &)
std::vector< double > norm_
void fillApvGain(const SiStripGainRcd &a, const std::pair< std::string, std::string > &recordLabelPair, std::vector< edm::ESHandle< SiStripApvGain > > &pDD)
U second(std::pair< T, U > const &p)
const DepRecordT & getRecord() const
std::vector< edm::ParameterSet > apvGainLabels_
double getNFactor(const int apvGainIndex)
std::pair< ContainerIterator, ContainerIterator > Range
SiStripGainESProducerTemplate(const edm::ParameterSet &)
std::vector< std::pair< std::string, std::string > > apvgain_
~SiStripGainESProducerTemplate()
SiStripGain * SiStripGainNormalizationFunction(const TDependentRecord &iRecord)