CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/CalibTracker/SiStripChannelGain/plugins/SiStripGainRandomCalculator.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Package:    SiStripChannelGain
00003 // Class:      SiStripGainRandomCalculator
00004 // Original Author:  G. Bruno
00005 //         Created:  Mon May 20 10:04:31 CET 2007
00006 // $Id: SiStripGainRandomCalculator.cc,v 1.7 2010/04/12 23:23:46 elmer Exp $
00007 
00008 #include "CalibTracker/SiStripChannelGain/plugins/SiStripGainRandomCalculator.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 
00013 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" 
00014 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00015 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00016 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00017 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00018 
00019 #include "CLHEP/Random/RandGauss.h"
00020 
00021 
00022 using namespace cms;
00023 using namespace std;
00024 
00025 
00026 SiStripGainRandomCalculator::SiStripGainRandomCalculator(const edm::ParameterSet& iConfig) : ConditionDBWriter<SiStripApvGain>(iConfig), m_cacheID_(0){
00027 
00028   
00029   edm::LogInfo("SiStripGainRandomCalculator::SiStripGainRandomCalculator");
00030 
00031 //   std::string Mode=iConfig.getParameter<std::string>("Mode");
00032 //   if (Mode==std::string("Gaussian")) GaussianMode_=true;
00033 //   else if (IOVMode==std::string("Constant")) ConstantMode_=true;
00034 //   else  edm::LogError("SiStripGainRandomCalculator::SiStripGainRandomCalculator(): ERROR - unknown generation mode...will not store anything on the DB") << std::endl;
00035 
00036   detid_apvs_.clear();
00037 
00038   meanGain_=iConfig.getParameter<double>("MeanGain");
00039   sigmaGain_=iConfig.getParameter<double>("SigmaGain");
00040   minimumPosValue_=iConfig.getParameter<double>("MinPositiveGain");
00041   printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
00042 
00043 
00044 }
00045 
00046 
00047 SiStripGainRandomCalculator::~SiStripGainRandomCalculator(){
00048 
00049    edm::LogInfo("SiStripGainRandomCalculator::~SiStripGainRandomCalculator");
00050 }
00051 
00052 
00053 
00054 void SiStripGainRandomCalculator::algoAnalyze(const edm::Event & event, const edm::EventSetup& iSetup){
00055 
00056 
00057   unsigned long long cacheID = iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
00058   
00059   if (m_cacheID_ != cacheID) {
00060     
00061     m_cacheID_ = cacheID; 
00062 
00063     edm::ESHandle<TrackerGeometry> pDD;
00064 
00065     iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00066     edm::LogInfo("SiStripGainRandomCalculator::algoAnalyze - got new geometry  ")<<std::endl;
00067 
00068     detid_apvs_.clear();
00069     
00070     edm::LogInfo("SiStripGainCalculator") <<" There are "<<pDD->detUnits().size() <<" detectors"<<std::endl;
00071     
00072     for(TrackerGeometry::DetUnitContainer::const_iterator it = pDD->detUnits().begin(); it != pDD->detUnits().end(); it++){
00073   
00074       if( dynamic_cast<StripGeomDetUnit*>((*it))!=0){
00075         uint32_t detid=((*it)->geographicalId()).rawId();            
00076         const StripTopology& p = dynamic_cast<StripGeomDetUnit*>((*it))->specificTopology();
00077         unsigned short NAPVs = p.nstrips()/128;
00078         if(NAPVs<1 || NAPVs>6 ) {
00079           edm::LogError("SiStripGainCalculator")<<" Problem with Number of strips in detector.. "<< p.nstrips() <<" Exiting program"<<endl;
00080           exit(1);
00081         }
00082         detid_apvs_.push_back( pair<uint32_t,unsigned short>(detid,NAPVs) );
00083         if (printdebug_)
00084           edm::LogInfo("SiStripGainCalculator")<< "detid " << detid << " apvs " << NAPVs;
00085       }
00086     }
00087   }
00088 
00089 
00090 }
00091 
00092 
00093 SiStripApvGain * SiStripGainRandomCalculator::getNewObject() {
00094 
00095   std::cout<<"SiStripGainRandomCalculator::getNewObject called"<<std::endl;
00096 
00097   SiStripApvGain * obj = new SiStripApvGain();
00098 
00099   for(std::vector< pair<uint32_t,unsigned short> >::const_iterator it = detid_apvs_.begin(); it != detid_apvs_.end(); it++){
00100     //Generate Gain for det detid
00101     std::vector<float> theSiStripVector;
00102     for(unsigned short j=0; j<it->second; j++){
00103       float gain;
00104 
00105       //      if(sigmaGain_/meanGain_ < 0.00001) gain = meanGain_;
00106       //      else{
00107       gain = CLHEP::RandGauss::shoot(meanGain_, sigmaGain_);
00108       if(gain<=minimumPosValue_) gain=minimumPosValue_;
00109       //      }
00110 
00111       if (printdebug_)
00112         edm::LogInfo("SiStripGainCalculator") << "detid " << it->first << " \t"
00113                                               << " apv " << j << " \t"
00114                                               << gain    << " \t" 
00115                                               << std::endl;         
00116       theSiStripVector.push_back(gain);
00117     }
00118     
00119     
00120     SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
00121     if ( ! obj->put(it->first,range) )
00122       edm::LogError("SiStripGainCalculator")<<"[SiStripGainCalculator::beginJob] detid already exists"<<std::endl;
00123 
00124   }
00125   
00126   return obj;
00127 
00128 }
00129 
00130