CMS 3D CMS Logo

SiStripGainESProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripGainESProducer
00004 // Class:      SiStripGainESProducer
00005 // 
00013 //
00014 // Original Author:  Giacomo Bruno
00015 //         Created:  Fri Apr 27 12:31:25 CEST 2007
00016 // $Id: SiStripGainESProducer.cc,v 1.4 2008/08/08 17:10:54 giordano Exp $
00017 //
00018 //
00019 
00020 
00021 
00022 // user include files
00023 
00024 #include "FWCore/Framework/interface/ESHandle.h"
00025 #include "CalibTracker/SiStripESProducers/plugins/real/SiStripGainESProducer.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 
00028 
00029 //
00030 // constructors and destructor
00031 //
00032 SiStripGainESProducer::SiStripGainESProducer(const edm::ParameterSet& iConfig){
00033 
00034   //the following line is needed to tell the framework what
00035   // data is being produced
00036   setWhatProduced(this);
00037   
00038   //now do what ever other initialization is needed
00039   automaticMode_ = iConfig.getParameter<bool>("AutomaticNormalization");
00040   norm_=iConfig.getParameter<double>("NormalizationFactor");
00041   printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
00042   apvgain_ = iConfig.getParameter<std::string>("APVGain");
00043 
00044   if(!automaticMode_ && norm_<=0){
00045     edm::LogError("SiStripGainESProducer::SiStripGainESProducer() - ERROR: negative or zero Normalization factor provided. Assuming 1 for such factor") << std::endl;
00046     norm_=1.;
00047   }
00048 
00049 }
00050 
00051 
00052 SiStripGainESProducer::~SiStripGainESProducer()
00053 {
00054  
00055    // do anything here that needs to be done at desctruction time
00056    // (e.g. close files, deallocate resources etc.)
00057 
00058 }
00059 
00060 
00061 //
00062 // member functions
00063 //
00064 
00065 // ------------ method called to produce the data  ------------
00066 std::auto_ptr<SiStripGain> SiStripGainESProducer::produce(const SiStripGainRcd & iRecord)
00067 {
00068    using namespace edm::es;
00069    edm::ESHandle<SiStripApvGain> pDD;
00070    iRecord.getRecord<SiStripApvGainRcd>().get(apvgain_,pDD );
00071    
00072    double NFactor;
00073 
00074    if(automaticMode_ || printdebug_ ){
00075 
00076      std::vector<uint32_t> DetIds;
00077      pDD->getDetIds(DetIds);
00078 
00079      double SumOfGains=0;
00080      int NGains=0;
00081 
00082      for(std::vector<uint32_t>::const_iterator detit=DetIds.begin(); detit!=DetIds.end(); detit++){
00083 
00084        SiStripApvGain::Range detRange = pDD->getRange(*detit);
00085 
00086        int iComp=0;
00087 
00088        for(std::vector<float>::const_iterator apvit=detRange.first; apvit!=detRange.second; apvit++){
00089 
00090          SumOfGains+=(*apvit);
00091          NGains++;
00092          if (printdebug_)
00093            edm::LogInfo("SiStripGainESProducer::produce()")<< "detid/component: " << *detit <<"/"<<iComp<< "   gain factor " <<*apvit ;
00094          iComp++;
00095 
00096 
00097        }
00098 
00099      }
00100 
00101      if(automaticMode_){
00102        if(SumOfGains>0 && NGains>0){
00103          NFactor=SumOfGains/NGains;
00104        }
00105        else{
00106          edm::LogError("SiStripGainESProducer::produce() - ERROR: empty set of gain values received. Cannot compute normalization factor. Assuming 1 for such factor") << std::endl;
00107          NFactor=1.;
00108        }
00109      }
00110 
00111 
00112    }
00113 
00114    if(!automaticMode_){
00115      NFactor=norm_;
00116    }
00117 
00118 
00119    if (printdebug_)  edm::LogInfo("SiStripGainESProducer::produce()")<< "putting A SiStrip Gain object in eventSetup with normalization factor " << NFactor ;
00120 
00121    SiStripGain * gain = new SiStripGain( *(pDD.product()), NFactor);
00122    return std::auto_ptr<SiStripGain>(gain );
00123 
00124 }
00125 

Generated on Tue Jun 9 17:25:51 2009 for CMSSW by  doxygen 1.5.4