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
16 
17 #include "CLHEP/Random/RandFlat.h"
18 #include "CLHEP/Random/RandGauss.h"
19 
21 public:
22  explicit SiStripNoisesBuilder(const edm::ParameterSet& iConfig);
23 
24  ~SiStripNoisesBuilder() override = default;
25 
26  void analyze(const edm::Event&, const edm::EventSetup&) override;
27 
28 private:
30  const uint32_t printdebug_;
31 };
32 
34  : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
36  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)) {}
37 
38 void SiStripNoisesBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
39  unsigned int run = evt.id().run();
40 
41  edm::LogInfo("SiStripNoisesBuilder") << "... creating dummy SiStripNoises Data for Run " << run << "\n " << std::endl;
42 
44 
45  int count = -1;
46 
48  const auto& DetInfos = reader.getAllData();
49 
50  for (const auto& it : DetInfos) {
51  const auto& nAPVs = it.second.nApvs;
52 
53  count++;
54  //Generate Noise for det detid
55  SiStripNoises::InputVector theSiStripVector;
56  for (int strip = 0; strip < 128 * nAPVs; ++strip) {
57  float MeanNoise = 5;
58  float RmsNoise = 1;
59  float noise = CLHEP::RandGauss::shoot(MeanNoise, RmsNoise);
60 
61  //double badStripProb = .5;
62  //bool disable = (CLHEP::RandFlat::shoot(1.) < badStripProb ? true:false);
63 
64  obj.setData(noise, theSiStripVector);
65  if (count < static_cast<int>(printdebug_))
66  edm::LogInfo("SiStripNoisesBuilder")
67  << "detid " << it.first << " \t"
68  << " strip " << strip << " \t" << noise << " \t" << theSiStripVector.back() / 10 << " \t" << std::endl;
69  }
70  if (!obj.put(it.first, theSiStripVector))
71  edm::LogError("SiStripNoisesBuilder") << "[SiStripNoisesBuilder::analyze] detid already exists" << std::endl;
72  }
73 
74  //And now write sistripnoises data in DB
76 
77  if (mydbservice.isAvailable()) {
78  if (mydbservice->isNewTagRequest("SiStripNoisesRcd")) {
79  mydbservice->createOneIOV<SiStripNoises>(obj, mydbservice->beginOfTime(), "SiStripNoisesRcd");
80  } else {
81  mydbservice->appendOneIOV<SiStripNoises>(obj, mydbservice->currentTime(), "SiStripNoisesRcd");
82  }
83  } else {
84  edm::LogError("SiStripNoisesBuilder") << "Service is unavailable" << std::endl;
85  }
86 }
87 
90 
void analyze(const edm::Event &, const edm::EventSetup &) override
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)
#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
const std::string & fullPath() const
Definition: FileInPath.cc:144