Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0002 #include "CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h"
0003 #include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/FileInPath.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 
0010 #include "CLHEP/Random/RandFlat.h"
0011 #include "CLHEP/Random/RandGauss.h"
0012 
0013 #include <iostream>
0014 #include <fstream>
0015 
0016 class SiStripThresholdBuilder : public edm::one::EDAnalyzer<> {
0017 public:
0018   explicit SiStripThresholdBuilder(const edm::ParameterSet& iConfig);
0019 
0020   ~SiStripThresholdBuilder() override = default;
0021 
0022   void analyze(const edm::Event&, const edm::EventSetup&) override;
0023 
0024 private:
0025   edm::FileInPath fp_;
0026   uint32_t printdebug_;
0027 };
0028 
0029 SiStripThresholdBuilder::SiStripThresholdBuilder(const edm::ParameterSet& iConfig)
0030     : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
0031                                                          edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))),
0032       printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 3)) {}
0033 
0034 void SiStripThresholdBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0035   unsigned int run = evt.id().run();
0036 
0037   edm::LogInfo("SiStripThresholdBuilder")
0038       << "... creating dummy SiStripThreshold Data for Run " << run << "\n " << std::endl;
0039 
0040   SiStripThreshold obj;
0041 
0042   const auto& reader = SiStripDetInfoFileReader::read(fp_.fullPath());
0043   const auto& DetInfos = reader.getAllData();
0044 
0045   int count = -1;
0046   for (const auto& it : DetInfos) {
0047     count++;
0048     //Generate Pedestal for det detid
0049     SiStripThreshold::Container theSiStripVector;
0050     uint16_t strip = 0;
0051     while (strip < 128 * it.second.nApvs) {
0052       float lTh = (CLHEP::RandFlat::shoot(1.) * 64) / 5;
0053       float hTh = (CLHEP::RandFlat::shoot(1.) * 64) / 5;
0054       if (hTh < lTh) {
0055         float tmp = hTh;
0056         hTh = lTh;
0057         lTh = tmp;
0058       }
0059       float cTh = (CLHEP::RandFlat::shoot(1.) * 30.);
0060 
0061       obj.setData(strip, lTh, hTh, cTh, theSiStripVector);
0062       if (count < (int)printdebug_) {
0063         std::stringstream ss;
0064         theSiStripVector.back().print(ss);
0065         edm::LogInfo("SiStripThresholdBuilder")
0066             << "detid: " << it.first << " \n"
0067             << "firstStrip: " << strip << " \t"
0068             << "lTh: " << lTh << " \t"
0069             << "hTh: " << hTh << " \t"
0070             << "cTh: " << cTh << " \t"
0071             << "FirstStrip_and_Hth: " << theSiStripVector.back().FirstStrip_and_Hth << " \n"
0072             << ss.str() << std::endl;
0073       }
0074       obj.setData(strip + 1, lTh, hTh, theSiStripVector);
0075       strip = (uint16_t)(CLHEP::RandFlat::shoot(strip + 2, 128 * it.second.nApvs));
0076     }
0077     if (!obj.put(it.first, theSiStripVector))
0078       edm::LogError("SiStripThresholdBuilder")
0079           << "[SiStripThresholdBuilder::analyze] detid already exists" << std::endl;
0080   }
0081 
0082   //End now write sistrippedestals data in DB
0083   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0084 
0085   if (mydbservice.isAvailable()) {
0086     if (mydbservice->isNewTagRequest("SiStripThresholdRcd")) {
0087       mydbservice->createOneIOV<SiStripThreshold>(obj, mydbservice->beginOfTime(), "SiStripThresholdRcd");
0088     } else {
0089       mydbservice->appendOneIOV<SiStripThreshold>(obj, mydbservice->currentTime(), "SiStripThresholdRcd");
0090     }
0091   } else {
0092     edm::LogError("SiStripThresholdBuilder") << "Service is unavailable" << std::endl;
0093   }
0094 }
0095 
0096 #include "FWCore/PluginManager/interface/ModuleDef.h"
0097 #include "FWCore/Framework/interface/MakerMacros.h"
0098 
0099 DEFINE_FWK_MODULE(SiStripThresholdBuilder);