CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/CalibTracker/SiStripESProducers/src/SiStripApvGainGenerator.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripESProducers/interface/SiStripApvGainGenerator.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <boost/cstdint.hpp>
00004 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00005 #include "FWCore/ParameterSet/interface/FileInPath.h"
00006 
00007 #include "CLHEP/Random/RandFlat.h"
00008 #include "CLHEP/Random/RandGauss.h"
00009 
00010 SiStripApvGainGenerator::SiStripApvGainGenerator(const edm::ParameterSet& iConfig,const edm::ActivityRegistry& aReg):
00011   SiStripCondObjBuilderBase<SiStripApvGain>::SiStripCondObjBuilderBase(iConfig)
00012 {
00013   edm::LogInfo("SiStripApvGainGenerator") <<  "[SiStripApvGainGenerator::SiStripApvGainGenerator]";
00014 }
00015 
00016 SiStripApvGainGenerator::~SiStripApvGainGenerator() { 
00017   edm::LogInfo("SiStripApvGainGenerator") <<  "[SiStripApvGainGenerator::~SiStripApvGainGenerator]";
00018 }
00019 
00020 void SiStripApvGainGenerator::createObject(){
00021     
00022   obj_ = new SiStripApvGain();
00023 
00024   std::string genMode = _pset.getParameter<std::string>("genMode");
00025 
00026   double meanGain_=_pset.getParameter<double>("MeanGain");
00027   double sigmaGain_=_pset.getParameter<double>("SigmaGain");
00028   double minimumPosValue_=_pset.getParameter<double>("MinPositiveGain");
00029 
00030   edm::FileInPath fp_ = _pset.getParameter<edm::FileInPath>("file");
00031   uint32_t  printdebug_ = _pset.getUntrackedParameter<uint32_t>("printDebug", 5);
00032   uint32_t count=0;
00033 
00034   SiStripDetInfoFileReader reader(fp_.fullPath());
00035 
00036   const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos  = reader.getAllData();
00037   float gainValue;
00038   for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){    
00039   
00040     std::vector<float> theSiStripVector;
00041     for(unsigned short j=0; j<it->second.nApvs; j++){
00042   
00043       if(genMode=="default")
00044         gainValue=meanGain_;
00045       else if (genMode=="gaussian") {
00046         gainValue = CLHEP::RandGauss::shoot(meanGain_, sigmaGain_);
00047         if(gainValue<=minimumPosValue_) gainValue=minimumPosValue_;
00048       }
00049       else {
00050         LogDebug("SiStripApvGain") << "ERROR: wrong genMode specifier : " << genMode << ", please select one of \"default\" or \"gaussian\"" << std::endl;
00051         exit(1);
00052       }
00053         
00054       if (count<printdebug_) {
00055         edm::LogInfo("SiStripApvGainGenerator") << "detid: " << it->first  << " Apv: " << j <<  " gain: " << gainValue  << std::endl;       
00056       }
00057       theSiStripVector.push_back(gainValue);
00058     }
00059     count++;
00060     SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
00061     if ( ! obj_->put(it->first,range) )
00062       edm::LogError("SiStripApvGainGenerator")<<" detid already exists"<<std::endl;
00063   }
00064 }