Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:38

0001 // -*- C++ -*-
0002 // Package:    SiStripChannelGain
0003 // Class:      SiStripGainRandomCalculator
0004 // Original Author:  G. Bruno
0005 //         Created:  Mon May 20 10:04:31 CET 2007
0006 
0007 #include "CalibTracker/SiStripChannelGain/plugins/SiStripGainRandomCalculator.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 
0011 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0012 #include "Geometry/CommonTopologies/interface/StripTopology.h"
0013 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0014 
0015 #include "CLHEP/Random/RandGauss.h"
0016 
0017 using namespace cms;
0018 using namespace std;
0019 
0020 SiStripGainRandomCalculator::SiStripGainRandomCalculator(const edm::ParameterSet& iConfig)
0021     : ConditionDBWriter<SiStripApvGain>(iConfig) {
0022   edm::LogInfo("SiStripGainRandomCalculator::SiStripGainRandomCalculator");
0023 
0024   //   std::string Mode=iConfig.getParameter<std::string>("Mode");
0025   //   if (Mode==std::string("Gaussian")) GaussianMode_=true;
0026   //   else if (IOVMode==std::string("Constant")) ConstantMode_=true;
0027   //   else  edm::LogError("SiStripGainRandomCalculator::SiStripGainRandomCalculator(): ERROR - unknown generation mode...will not store anything on the DB") << std::endl;
0028 
0029   detid_apvs_.clear();
0030 
0031   meanGain_ = iConfig.getParameter<double>("MeanGain");
0032   sigmaGain_ = iConfig.getParameter<double>("SigmaGain");
0033   minimumPosValue_ = iConfig.getParameter<double>("MinPositiveGain");
0034   printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
0035 
0036   tkGeomToken_ = esConsumes();
0037 }
0038 
0039 SiStripGainRandomCalculator::~SiStripGainRandomCalculator() {
0040   edm::LogInfo("SiStripGainRandomCalculator::~SiStripGainRandomCalculator");
0041 }
0042 
0043 void SiStripGainRandomCalculator::algoAnalyze(const edm::Event& event, const edm::EventSetup& iSetup) {
0044   if (tkDigiGeomRcdWatcher_.check(iSetup)) {
0045     const auto& dd = iSetup.getData(tkGeomToken_);
0046     edm::LogInfo("SiStripGainRandomCalculator::algoAnalyze - got new geometry  ") << std::endl;
0047 
0048     detid_apvs_.clear();
0049 
0050     edm::LogInfo("SiStripGainCalculator") << " There are " << dd.detUnits().size() << " detectors" << std::endl;
0051 
0052     for (const auto& it : dd.detUnits()) {
0053       if (dynamic_cast<const StripGeomDetUnit*>(it) != nullptr) {
0054         uint32_t detid = (it->geographicalId()).rawId();
0055         const StripTopology& p = dynamic_cast<const StripGeomDetUnit*>(it)->specificTopology();
0056         unsigned short NAPVs = p.nstrips() / 128;
0057         if (NAPVs < 1 || NAPVs > 6) {
0058           edm::LogError("SiStripGainCalculator")
0059               << " Problem with Number of strips in detector.. " << p.nstrips() << " Exiting program" << endl;
0060           exit(1);
0061         }
0062         detid_apvs_.push_back(pair<uint32_t, unsigned short>(detid, NAPVs));
0063         if (printdebug_)
0064           edm::LogInfo("SiStripGainCalculator") << "detid " << detid << " apvs " << NAPVs;
0065       }
0066     }
0067   }
0068 }
0069 
0070 std::unique_ptr<SiStripApvGain> SiStripGainRandomCalculator::getNewObject() {
0071   std::cout << "SiStripGainRandomCalculator::getNewObject called" << std::endl;
0072 
0073   auto obj = std::make_unique<SiStripApvGain>();
0074 
0075   for (std::vector<pair<uint32_t, unsigned short> >::const_iterator it = detid_apvs_.begin(); it != detid_apvs_.end();
0076        it++) {
0077     //Generate Gain for det detid
0078     std::vector<float> theSiStripVector;
0079     for (unsigned short j = 0; j < it->second; j++) {
0080       float gain;
0081 
0082       //      if(sigmaGain_/meanGain_ < 0.00001) gain = meanGain_;
0083       //      else{
0084       gain = CLHEP::RandGauss::shoot(meanGain_, sigmaGain_);
0085       if (gain <= minimumPosValue_)
0086         gain = minimumPosValue_;
0087       //      }
0088 
0089       if (printdebug_)
0090         edm::LogInfo("SiStripGainCalculator") << "detid " << it->first << " \t"
0091                                               << " apv " << j << " \t" << gain << " \t" << std::endl;
0092       theSiStripVector.push_back(gain);
0093     }
0094 
0095     SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
0096     if (!obj->put(it->first, range))
0097       edm::LogError("SiStripGainCalculator") << "[SiStripGainCalculator::beginJob] detid already exists" << std::endl;
0098   }
0099 
0100   return obj;
0101 }