CMS 3D CMS Logo

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:
19  explicit SiStripNoisesBuilder(const edm::ParameterSet& iConfig);
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",
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 
std::string fullPath() const
Definition: FileInPath.cc:161
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
reader
Definition: DQM.py:105
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)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EventID id() const
Definition: EventBase.h:63
SiStripDetInfo read(std::string filePath)
~SiStripNoisesBuilder() override=default
Log< level::Info, false > LogInfo
RunNumber_t run() const
Definition: EventID.h:38
HLT enums.
static constexpr char const *const kDefaultFile
bool isAvailable() const
Definition: Service.h:40