Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:29

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