CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripNoisesBuilder.cc
Go to the documentation of this file.
1 // system includes
2 #include <iostream>
3 #include <fstream>
4 
5 // user includes
13 
14 #include "CLHEP/Random/RandFlat.h"
15 #include "CLHEP/Random/RandGauss.h"
16 
18 public:
20 
21  ~SiStripNoisesBuilder() override = default;
22 
23  void analyze(const edm::Event&, const edm::EventSetup&) override;
24 
25 private:
27  const uint32_t printdebug_;
28 };
29 
31  : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
32  edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))),
33  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)) {}
34 
35 void SiStripNoisesBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
36  unsigned int run = evt.id().run();
37 
38  edm::LogInfo("SiStripNoisesBuilder") << "... creating dummy SiStripNoises Data for Run " << run << "\n " << std::endl;
39 
41 
42  int count = -1;
43 
45  const auto& DetInfos = reader.getAllData();
46 
47  for (const auto& it : DetInfos) {
48  const auto& nAPVs = it.second.nApvs;
49 
50  count++;
51  //Generate Noise for det detid
52  SiStripNoises::InputVector theSiStripVector;
53  for (int strip = 0; strip < 128 * nAPVs; ++strip) {
54  float MeanNoise = 5;
55  float RmsNoise = 1;
56  float noise = CLHEP::RandGauss::shoot(MeanNoise, RmsNoise);
57 
58  //double badStripProb = .5;
59  //bool disable = (CLHEP::RandFlat::shoot(1.) < badStripProb ? true:false);
60 
61  obj.setData(noise, theSiStripVector);
62  if (count < static_cast<int>(printdebug_))
63  edm::LogInfo("SiStripNoisesBuilder")
64  << "detid " << it.first << " \t"
65  << " strip " << strip << " \t" << noise << " \t" << theSiStripVector.back() / 10 << " \t" << std::endl;
66  }
67  if (!obj.put(it.first, theSiStripVector))
68  edm::LogError("SiStripNoisesBuilder") << "[SiStripNoisesBuilder::analyze] detid already exists" << std::endl;
69  }
70 
71  //And now write sistripnoises data in DB
73 
74  if (mydbservice.isAvailable()) {
75  if (mydbservice->isNewTagRequest("SiStripNoisesRcd")) {
76  mydbservice->createOneIOV<SiStripNoises>(obj, mydbservice->beginOfTime(), "SiStripNoisesRcd");
77  } else {
78  mydbservice->appendOneIOV<SiStripNoises>(obj, mydbservice->currentTime(), "SiStripNoisesRcd");
79  }
80  } else {
81  edm::LogError("SiStripNoisesBuilder") << "Service is unavailable" << std::endl;
82  }
83 }
84 
87 
RunNumber_t run() const
Definition: EventID.h:38
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
Log< level::Error, false > LogError
SiStripNoisesBuilder(const edm::ParameterSet &iConfig)
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
const edm::FileInPath fp_
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:40
tuple reader
Definition: DQM.py:105
SiStripDetInfo read(std::string filePath)
~SiStripNoisesBuilder() override=default
bool put(const uint32_t &detID, const InputVector &input)
__shared__ int noise
Log< level::Info, false > LogInfo
edm::EventID id() const
Definition: EventBase.h:59
std::string fullPath() const
Definition: FileInPath.cc:161
static constexpr char const *const kDefaultFile
void setData(float noise_, InputVector &vped)