Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-31 08:39:23

0001 // -*- C++ -*-
0002 //
0003 // Package:    Test/WriteL1TriggerObjectsTxt
0004 // Class:      WriteL1TriggerObjectsTxt
0005 //
0006 /**\class WriteL1TriggerObjectsTxt WriteL1TriggerObjectsTxt.cc Test/WriteL1TriggerObjectsTxt/plugins/WriteL1TriggerObjectsTxt.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Aleko Khukhunaishvili
0015 //         Created:  Fri, 21 Jul 2017 08:25:18 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <fstream>
0022 
0023 // user include files
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   template <typename T>
0049   void fillL1TrgObjsCollection(std::unique_ptr<HcalL1TriggerObjects>& l1TrgObjsCol,
0050                                const HcalDbService* conditions,
0051                                const HcalTopology* topo,
0052                                T cell);
0053 
0054   std::string tagName_;
0055   edm::ESGetToken<HcalDbService, HcalDbRecord> tok_dbservice_;
0056 };
0057 
0058 WriteL1TriggerObjectsTxt::WriteL1TriggerObjectsTxt(const edm::ParameterSet& iConfig)
0059     : tagName_(iConfig.getParameter<std::string>("TagName")),
0060       tok_dbservice_(esConsumes<HcalDbService, HcalDbRecord>()) {}
0061 
0062 WriteL1TriggerObjectsTxt::~WriteL1TriggerObjectsTxt() {}
0063 
0064 template <typename T>
0065 void WriteL1TriggerObjectsTxt::fillL1TrgObjsCollection(std::unique_ptr<HcalL1TriggerObjects>& l1TrgObjsCol,
0066                                                        const HcalDbService* conditions,
0067                                                        const HcalTopology* topo,
0068                                                        T cell) {
0069   const HcalCalibrations calibrations = conditions->getHcalCalibrations(cell);
0070 
0071   float gain = 0.0;
0072   float ped = 0.0;
0073 
0074   for (auto i : {0, 1, 2, 3}) {
0075     gain += calibrations.LUTrespcorrgain(i);
0076     ped += calibrations.effpedestal(i);
0077   }
0078 
0079   gain /= 4.;
0080   ped /= 4.;
0081 
0082   const HcalChannelStatus* channelStatus = conditions->getHcalChannelStatus(cell);
0083   uint32_t status = channelStatus->getValue();
0084   HcalL1TriggerObject l1object(cell, ped, gain, status);
0085   l1TrgObjsCol->setTopo(topo);
0086   l1TrgObjsCol->addValues(l1object);
0087 }
0088 
0089 void WriteL1TriggerObjectsTxt::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0090   using namespace edm;
0091 
0092   const HcalDbService* conditions = &iSetup.getData(tok_dbservice_);
0093 
0094   const HcalLutMetadata* metadata = conditions->getHcalLutMetadata();
0095   const HcalTopology* topo = metadata->topo();
0096 
0097   std::unique_ptr<HcalL1TriggerObjects> HcalL1TrigObjCol(new HcalL1TriggerObjects);
0098 
0099   for (const auto& id : metadata->getAllChannels()) {
0100     if (id.det() == DetId::Hcal and topo->valid(id)) {
0101       HcalDetId cell(id);
0102       HcalSubdetector subdet = cell.subdet();
0103       if (subdet != HcalBarrel and subdet != HcalEndcap and subdet != HcalForward)
0104         continue;
0105 
0106       fillL1TrgObjsCollection(HcalL1TrigObjCol, conditions, topo, cell);
0107 
0108     } else if (id.det() == DetId::Calo && id.subdetId() == HcalZDCDetId::SubdetectorId) {
0109       HcalZDCDetId cell(id.rawId());
0110 
0111       if (cell.section() != HcalZDCDetId::EM && cell.section() != HcalZDCDetId::HAD &&
0112           cell.section() != HcalZDCDetId::LUM)
0113         continue;
0114 
0115       fillL1TrgObjsCollection(HcalL1TrigObjCol, conditions, topo, cell);
0116     }
0117   }
0118 
0119   HcalL1TrigObjCol->setTagString(tagName_);
0120   HcalL1TrigObjCol->setAlgoString("TP algo determined by HcalTPChannelParameter auxi params");
0121   std::string outfilename = "Gen_L1TriggerObjects_";
0122   outfilename += tagName_;
0123   outfilename += ".txt";
0124   std::ofstream of(outfilename.c_str());
0125   HcalDbASCIIIO::dumpObject(of, *HcalL1TrigObjCol);
0126 }
0127 
0128 void WriteL1TriggerObjectsTxt::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0129   edm::ParameterSetDescription desc;
0130   desc.setUnknown();
0131   descriptions.addDefault(desc);
0132 }
0133 
0134 DEFINE_FWK_MODULE(WriteL1TriggerObjectsTxt);