CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CalibFormats/SiStripObjects/src/SiStripGain.cc

Go to the documentation of this file.
00001  // -*- C++ -*-
00002 //
00003 // Package:     SiStripObjects
00004 // Class  :     SiStripGain
00005 // Implementation:
00006 //     <Notes on implementation>
00007 // Original Author:  gbruno
00008 //         Created:  Wed Mar 22 12:24:33 CET 2006
00009 // $Id: SiStripGain.cc,v 1.13 2010/04/27 08:06:06 demattia Exp $
00010 
00011 #include "FWCore/Utilities/interface/typelookup.h"
00012 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
00015 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00016 #include <sstream>
00017 
00018 void SiStripGain::multiply(const SiStripApvGain & apvgain, const double & factor,
00019                            const std::pair<std::string, std::string> & recordLabelPair)
00020 {
00021   // When inserting the first ApvGain
00022   if( apvgain_ == 0 ) {
00023     if( (factor != 1) && (factor != 0) ) {
00024       fillNewGain( &apvgain, factor );
00025     }
00026     else {
00027       // If the normalization factor is one, no need to create a new SiStripApvGain
00028       apvgain_ = &apvgain;
00029     }
00030   }
00031   else {
00032     // There is already an ApvGain inside the SiStripGain. Multiply it by the new one and save the new pointer.
00033     fillNewGain( apvgain_, 1., &apvgain, factor ); 
00034   }
00035   recordLabelPair_.push_back(recordLabelPair);
00036   apvgainVector_.push_back(&apvgain);
00037   normVector_.push_back(factor);
00038 }
00039 
00040 void SiStripGain::fillNewGain(const SiStripApvGain * apvgain, const double & factor,
00041                  const SiStripApvGain * apvgain2, const double & factor2)
00042 {
00043   SiStripApvGain * newApvGain = new SiStripApvGain;
00044   edm::FileInPath fp("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
00045   SiStripDetInfoFileReader reader(fp.fullPath());
00046   const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo> DetInfos = reader.getAllData();
00047 
00048   // Loop on the apvgain in input and fill the newApvGain with the values/factor.
00049   std::vector<uint32_t> detIds;
00050   apvgain->getDetIds(detIds);
00051   std::vector<uint32_t>::const_iterator it = detIds.begin();
00052   for( ; it != detIds.end(); ++it ) {
00053 
00054     std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator detInfoIt = DetInfos.find(*it);
00055     if( detInfoIt != DetInfos.end() ) {
00056 
00057       std::vector<float> theSiStripVector;
00058 
00059       // Loop on all the apvs and then on the strips
00060       SiStripApvGain::Range range = apvgain->getRange(*it);
00061 
00062       SiStripApvGain::Range range2;
00063       if( apvgain2 != 0 ) {
00064         range2 = apvgain2->getRange(*it);
00065       }
00066 
00067       for( int apv = 0; apv < detInfoIt->second.nApvs; ++apv ) {
00068         float apvGainValue = apvgain->getApvGain( apv, range )/factor;
00069 
00070         if( (apvgain2 != 0) && (factor2 != 0.) ) {
00071           apvGainValue *= apvgain2->getApvGain( apv, range2 )/factor2;
00072         }
00073 
00074         theSiStripVector.push_back(apvGainValue);
00075       }
00076       SiStripApvGain::Range inputRange(theSiStripVector.begin(), theSiStripVector.end());
00077       if( ! newApvGain->put(*it, inputRange) ) {
00078         edm::LogError("SiStripGain") << "detid already exists" << std::endl;
00079       }
00080     }
00081   }
00082   apvgain_ = newApvGain;
00083   // Deletes the managed object and replaces it with the new one
00084   apvgainAutoPtr_.reset(newApvGain);
00085 }
00086 
00087 float SiStripGain::getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range) const
00088 {
00089   if( apvgain_ == 0 ) {
00090     edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
00091     return 1.;
00092   }
00093   return( apvgain_->getStripGain(strip, range) );
00094 }
00095 
00096 float SiStripGain::getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range, const uint32_t index) const
00097 {
00098   if( !(apvgainVector_.empty()) ) {
00099     return( apvgainVector_[index]->getStripGain(strip, range) );
00100   }
00101   edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
00102   return 1.;
00103 }
00104 
00105 float SiStripGain::getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range) const
00106 {
00107   if( apvgain_ == 0 ) {
00108     edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
00109     return 1.;
00110   }
00111   return( apvgain_->getApvGain(apv, range) );
00112 }
00113 
00114 float SiStripGain::getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range, const uint32_t index) const
00115 {
00116   if( !(apvgainVector_.empty()) ) {
00117     return (apvgainVector_[index]->getApvGain(apv, range))/(normVector_[index]);
00118   }
00119   edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
00120   return 1.;
00121 }
00122 
00123 void SiStripGain::getDetIds(std::vector<uint32_t>& DetIds_) const
00124 {
00125   // ATTENTION: we assume the detIds are the same as those from the first gain
00126   return apvgain_->getDetIds(DetIds_);
00127 }
00128 
00129 const SiStripApvGain::Range SiStripGain::getRange(const uint32_t& DetId) const
00130 {
00131   return apvgain_->getRange(DetId);
00132 }
00133 
00134 const SiStripApvGain::Range SiStripGain::getRange(const uint32_t& DetId, const uint32_t index) const
00135 {
00136   return apvgainVector_[index]->getRange(DetId);
00137 }
00138 
00139 void SiStripGain::printDebug(std::stringstream & ss) const
00140 {
00141   std::vector<unsigned int> detIds;
00142   getDetIds(detIds);
00143   std::vector<unsigned int>::const_iterator detid = detIds.begin();
00144   ss << "Number of detids " << detIds.size() << std::endl;
00145 
00146   for( ; detid != detIds.end(); ++detid ) {
00147     SiStripApvGain::Range range = getRange(*detid);
00148     int apv=0;
00149     for( int it=0; it < range.second - range.first; ++it ) {
00150       ss << "detid " << *detid << " \t"
00151          << " apv " << apv++ << " \t"
00152          << getApvGain(it,range) << " \t"
00153          << std::endl;
00154     }
00155   }
00156 }
00157 
00158 void SiStripGain::printSummary(std::stringstream& ss) const
00159 {
00160   SiStripDetSummary summaryGain;
00161 
00162   std::vector<unsigned int> detIds;
00163   getDetIds(detIds);
00164   std::vector<uint32_t>::const_iterator detid = detIds.begin();
00165   for( ; detid != detIds.end(); ++detid ) {
00166     SiStripApvGain::Range range = getRange(*detid);
00167     for( int it=0; it < range.second - range.first; ++it ) {
00168       summaryGain.add(*detid, getApvGain(it, range));
00169     }
00170   }
00171   ss << "Summary of gain values:" << std::endl;
00172   summaryGain.print(ss, true);
00173 }