File indexing completed on 2024-04-06 12:00:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <fstream>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029
0030 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
0031 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0032 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0033 #include "CondFormats/HcalObjects/interface/HcalL1TriggerObjects.h"
0034 #include "CondFormats/HcalObjects/interface/HcalL1TriggerObject.h"
0035 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
0036 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0037
0038 class WriteL1TriggerObjectsTxt : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0039 public:
0040 explicit WriteL1TriggerObjectsTxt(const edm::ParameterSet&);
0041 ~WriteL1TriggerObjectsTxt() override;
0042
0043 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0044
0045 private:
0046 void analyze(const edm::Event&, const edm::EventSetup&) override;
0047
0048 std::string tagName_;
0049 edm::ESGetToken<HcalDbService, HcalDbRecord> tok_dbservice_;
0050 };
0051
0052 WriteL1TriggerObjectsTxt::WriteL1TriggerObjectsTxt(const edm::ParameterSet& iConfig)
0053 : tagName_(iConfig.getParameter<std::string>("TagName")),
0054 tok_dbservice_(esConsumes<HcalDbService, HcalDbRecord>()) {}
0055
0056 WriteL1TriggerObjectsTxt::~WriteL1TriggerObjectsTxt() {}
0057
0058 void WriteL1TriggerObjectsTxt::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0059 using namespace edm;
0060
0061 const HcalDbService* conditions = &iSetup.getData(tok_dbservice_);
0062
0063 const HcalLutMetadata* metadata = conditions->getHcalLutMetadata();
0064 const HcalTopology* topo = metadata->topo();
0065
0066 std::unique_ptr<HcalL1TriggerObjects> HcalL1TrigObjCol(new HcalL1TriggerObjects);
0067
0068 for (const auto& id : metadata->getAllChannels()) {
0069 if (not(id.det() == DetId::Hcal and topo->valid(id)))
0070 continue;
0071
0072 HcalDetId cell(id);
0073 HcalSubdetector subdet = cell.subdet();
0074 if (subdet != HcalBarrel and subdet != HcalEndcap and subdet != HcalForward)
0075 continue;
0076
0077 HcalCalibrations calibrations = conditions->getHcalCalibrations(cell);
0078
0079 float gain = 0.0;
0080 float ped = 0.0;
0081
0082 for (auto i : {0, 1, 2, 3}) {
0083 gain += calibrations.LUTrespcorrgain(i);
0084 ped += calibrations.effpedestal(i);
0085 }
0086
0087 gain /= 4.;
0088 ped /= 4.;
0089
0090 const HcalChannelStatus* channelStatus = conditions->getHcalChannelStatus(cell);
0091 uint32_t status = channelStatus->getValue();
0092 HcalL1TriggerObject l1object(cell, ped, gain, status);
0093 HcalL1TrigObjCol->setTopo(topo);
0094 HcalL1TrigObjCol->addValues(l1object);
0095 }
0096
0097 HcalL1TrigObjCol->setTagString(tagName_);
0098 HcalL1TrigObjCol->setAlgoString("A 2-TS Peak Finder");
0099 std::string outfilename = "Gen_L1TriggerObjects_";
0100 outfilename += tagName_;
0101 outfilename += ".txt";
0102 std::ofstream of(outfilename.c_str());
0103 HcalDbASCIIIO::dumpObject(of, *HcalL1TrigObjCol);
0104 }
0105
0106 void WriteL1TriggerObjectsTxt::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0107 edm::ParameterSetDescription desc;
0108 desc.setUnknown();
0109 descriptions.addDefault(desc);
0110 }
0111
0112 DEFINE_FWK_MODULE(WriteL1TriggerObjectsTxt);