CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripGainRandomCalculator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiStripChannelGain
3 // Class: SiStripGainRandomCalculator
4 // Original Author: G. Bruno
5 // Created: Mon May 20 10:04:31 CET 2007
6 
10 
14 
15 #include "CLHEP/Random/RandGauss.h"
16 
17 using namespace cms;
18 using namespace std;
19 
21  : ConditionDBWriter<SiStripApvGain>(iConfig) {
22  edm::LogInfo("SiStripGainRandomCalculator::SiStripGainRandomCalculator");
23 
24  // std::string Mode=iConfig.getParameter<std::string>("Mode");
25  // if (Mode==std::string("Gaussian")) GaussianMode_=true;
26  // else if (IOVMode==std::string("Constant")) ConstantMode_=true;
27  // else edm::LogError("SiStripGainRandomCalculator::SiStripGainRandomCalculator(): ERROR - unknown generation mode...will not store anything on the DB") << std::endl;
28 
29  detid_apvs_.clear();
30 
31  meanGain_ = iConfig.getParameter<double>("MeanGain");
32  sigmaGain_ = iConfig.getParameter<double>("SigmaGain");
33  minimumPosValue_ = iConfig.getParameter<double>("MinPositiveGain");
34  printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
35 
37 }
38 
40  edm::LogInfo("SiStripGainRandomCalculator::~SiStripGainRandomCalculator");
41 }
42 
44  if (tkDigiGeomRcdWatcher_.check(iSetup)) {
45  const auto& dd = iSetup.getData(tkGeomToken_);
46  edm::LogInfo("SiStripGainRandomCalculator::algoAnalyze - got new geometry ") << std::endl;
47 
48  detid_apvs_.clear();
49 
50  edm::LogInfo("SiStripGainCalculator") << " There are " << dd.detUnits().size() << " detectors" << std::endl;
51 
52  for (const auto& it : dd.detUnits()) {
53  if (dynamic_cast<const StripGeomDetUnit*>(it) != nullptr) {
54  uint32_t detid = (it->geographicalId()).rawId();
55  const StripTopology& p = dynamic_cast<const StripGeomDetUnit*>(it)->specificTopology();
56  unsigned short NAPVs = p.nstrips() / 128;
57  if (NAPVs < 1 || NAPVs > 6) {
58  edm::LogError("SiStripGainCalculator")
59  << " Problem with Number of strips in detector.. " << p.nstrips() << " Exiting program" << endl;
60  exit(1);
61  }
62  detid_apvs_.push_back(pair<uint32_t, unsigned short>(detid, NAPVs));
63  if (printdebug_)
64  edm::LogInfo("SiStripGainCalculator") << "detid " << detid << " apvs " << NAPVs;
65  }
66  }
67  }
68 }
69 
70 std::unique_ptr<SiStripApvGain> SiStripGainRandomCalculator::getNewObject() {
71  std::cout << "SiStripGainRandomCalculator::getNewObject called" << std::endl;
72 
73  auto obj = std::make_unique<SiStripApvGain>();
74 
75  for (std::vector<pair<uint32_t, unsigned short> >::const_iterator it = detid_apvs_.begin(); it != detid_apvs_.end();
76  it++) {
77  //Generate Gain for det detid
78  std::vector<float> theSiStripVector;
79  for (unsigned short j = 0; j < it->second; j++) {
80  float gain;
81 
82  // if(sigmaGain_/meanGain_ < 0.00001) gain = meanGain_;
83  // else{
84  gain = CLHEP::RandGauss::shoot(meanGain_, sigmaGain_);
85  if (gain <= minimumPosValue_)
86  gain = minimumPosValue_;
87  // }
88 
89  if (printdebug_)
90  edm::LogInfo("SiStripGainCalculator") << "detid " << it->first << " \t"
91  << " apv " << j << " \t" << gain << " \t" << std::endl;
92  theSiStripVector.push_back(gain);
93  }
94 
95  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
96  if (!obj->put(it->first, range))
97  edm::LogError("SiStripGainCalculator") << "[SiStripGainCalculator::beginJob] detid already exists" << std::endl;
98  }
99 
100  return obj;
101 }
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< SiStripApvGain > getNewObject() override
Log< level::Error, false > LogError
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
const uint16_t range(const Frame &aFrame)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
edm::ESWatcher< TrackerDigiGeometryRecord > tkDigiGeomRcdWatcher_
std::pair< ContainerIterator, ContainerIterator > Range
SiStripGainRandomCalculator(const edm::ParameterSet &)
Log< level::Info, false > LogInfo
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::vector< std::pair< uint32_t, unsigned short > > detid_apvs_
tuple cout
Definition: gather_cfg.py:144
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_