Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-17 23:36:02

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ParameterSet/interface/FileInPath.h"
0006 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0007 #include "CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h"
0008 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
0009 
0010 #include "CLHEP/Random/RandFlat.h"
0011 #include "CLHEP/Random/RandGauss.h"
0012 
0013 #include <iostream>
0014 #include <fstream>
0015 
0016 class SiStripPedestalsBuilder : public edm::one::EDAnalyzer<> {
0017 public:
0018   explicit SiStripPedestalsBuilder(const edm::ParameterSet& iConfig);
0019 
0020   ~SiStripPedestalsBuilder() 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 SiStripPedestalsBuilder::SiStripPedestalsBuilder(const edm::ParameterSet& iConfig)
0030     : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
0031                                                          edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))),
0032       printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)) {}
0033 
0034 void SiStripPedestalsBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0035   unsigned int run = evt.id().run();
0036 
0037   edm::LogInfo("SiStripPedestalsBuilder")
0038       << "... creating dummy SiStripPedestals Data for Run " << run << "\n " << std::endl;
0039 
0040   SiStripPedestals 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 Pedestal for det detid
0052     SiStripPedestals::InputVector theSiStripVector;
0053     for (int strip = 0; strip < 128 * nAPVs; ++strip) {
0054       float MeanPed = 100;
0055       float RmsPed = 5;
0056 
0057       float ped = CLHEP::RandGauss::shoot(MeanPed, RmsPed);
0058 
0059       if (count < static_cast<int>(printdebug_))
0060         edm::LogInfo("SiStripPedestalsBuilder") << "detid " << it.first << " \t"
0061                                                 << " strip " << strip << " \t" << ped << " \t" << std::endl;
0062       obj.setData(ped, theSiStripVector);
0063     }
0064 
0065     //SiStripPedestals::Range range(theSiStripVector.begin(),theSiStripVector.end());
0066     if (!obj.put(it.first, theSiStripVector))
0067       edm::LogError("SiStripPedestalsBuilder")
0068           << "[SiStripPedestalsBuilder::analyze] detid already exists" << std::endl;
0069   }
0070 
0071   //End now write sistrippedestals data in DB
0072   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0073 
0074   if (mydbservice.isAvailable()) {
0075     if (mydbservice->isNewTagRequest("SiStripPedestalsRcd")) {
0076       mydbservice->createOneIOV<SiStripPedestals>(obj, mydbservice->beginOfTime(), "SiStripPedestalsRcd");
0077     } else {
0078       mydbservice->appendOneIOV<SiStripPedestals>(obj, mydbservice->currentTime(), "SiStripPedestalsRcd");
0079     }
0080   } else {
0081     edm::LogError("SiStripPedestalsBuilder") << "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(SiStripPedestalsBuilder);