Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-11 03:56:56

0001 // system includes
0002 #include <iostream>
0003 #include <fstream>
0004 
0005 // user includes
0006 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0007 #include "CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h"
0008 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/ParameterSet/interface/FileInPath.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 
0014 #include "CLHEP/Random/RandFlat.h"
0015 #include "CLHEP/Random/RandGauss.h"
0016 
0017 class SiStripNoisesBuilder : public edm::one::EDAnalyzer<> {
0018 public:
0019   explicit SiStripNoisesBuilder(const edm::ParameterSet& iConfig);
0020 
0021   ~SiStripNoisesBuilder() override = default;
0022 
0023   void analyze(const edm::Event&, const edm::EventSetup&) override;
0024 
0025 private:
0026   const edm::FileInPath fp_;
0027   const uint32_t printdebug_;
0028 };
0029 
0030 SiStripNoisesBuilder::SiStripNoisesBuilder(const edm::ParameterSet& iConfig)
0031     : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
0032                                                          edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))),
0033       printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)) {}
0034 
0035 void SiStripNoisesBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0036   unsigned int run = evt.id().run();
0037 
0038   edm::LogInfo("SiStripNoisesBuilder") << "... creating dummy SiStripNoises Data for Run " << run << "\n " << std::endl;
0039 
0040   SiStripNoises obj;
0041 
0042   int count = -1;
0043 
0044   const auto& reader = SiStripDetInfoFileReader::read(fp_.fullPath());
0045   const auto& DetInfos = reader.getAllData();
0046 
0047   for (const auto& it : DetInfos) {
0048     const auto& nAPVs = it.second.nApvs;
0049 
0050     count++;
0051     //Generate Noise for det detid
0052     SiStripNoises::InputVector theSiStripVector;
0053     for (int strip = 0; strip < 128 * nAPVs; ++strip) {
0054       float MeanNoise = 5;
0055       float RmsNoise = 1;
0056       float noise = CLHEP::RandGauss::shoot(MeanNoise, RmsNoise);
0057 
0058       //double badStripProb = .5;
0059       //bool disable = (CLHEP::RandFlat::shoot(1.) < badStripProb ? true:false);
0060 
0061       obj.setData(noise, theSiStripVector);
0062       if (count < static_cast<int>(printdebug_))
0063         edm::LogInfo("SiStripNoisesBuilder")
0064             << "detid " << it.first << " \t"
0065             << " strip " << strip << " \t" << noise << " \t" << theSiStripVector.back() / 10 << " \t" << std::endl;
0066     }
0067     if (!obj.put(it.first, theSiStripVector))
0068       edm::LogError("SiStripNoisesBuilder") << "[SiStripNoisesBuilder::analyze] detid already exists" << std::endl;
0069   }
0070 
0071   //And now write sistripnoises data in DB
0072   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0073 
0074   if (mydbservice.isAvailable()) {
0075     if (mydbservice->isNewTagRequest("SiStripNoisesRcd")) {
0076       mydbservice->createOneIOV<SiStripNoises>(obj, mydbservice->beginOfTime(), "SiStripNoisesRcd");
0077     } else {
0078       mydbservice->appendOneIOV<SiStripNoises>(obj, mydbservice->currentTime(), "SiStripNoisesRcd");
0079     }
0080   } else {
0081     edm::LogError("SiStripNoisesBuilder") << "Service is unavailable" << std::endl;
0082   }
0083 }
0084 
0085 #include "FWCore/PluginManager/interface/ModuleDef.h"
0086 #include "FWCore/Framework/interface/MakerMacros.h"
0087 
0088 DEFINE_FWK_MODULE(SiStripNoisesBuilder);