Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:38

0001 /** \class CaloTowersReCreator
0002   *  
0003   */
0004 
0005 #include "CaloTowersCreationAlgo.h"
0006 
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/ESGetToken.h"
0014 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0015 #include "Geometry/CaloTopology/interface/CaloTowerTopology.h"
0016 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0017 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0018 
0019 class CaloTowersReCreator : public edm::stream::EDProducer<> {
0020 public:
0021   explicit CaloTowersReCreator(const edm::ParameterSet& ps);
0022   ~CaloTowersReCreator() override {}
0023   void produce(edm::Event& e, const edm::EventSetup& c) override;
0024   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0025   double EBEScale, EEEScale, HBEScale, HESEScale;
0026   double HEDEScale, HOEScale, HF1EScale, HF2EScale;
0027 
0028 private:
0029   CaloTowersCreationAlgo algo_;
0030   edm::EDGetTokenT<CaloTowerCollection> tok_calo_;
0031   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0032   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_topo_;
0033   edm::ESGetToken<CaloTowerTopology, HcalRecNumberingRecord> tok_cttopo_;
0034   edm::ESGetToken<CaloTowerConstituentsMap, CaloGeometryRecord> tok_ctmap_;
0035   bool allowMissingInputs_;
0036 };
0037 
0038 #include "FWCore/Framework/interface/MakerMacros.h"
0039 DEFINE_FWK_MODULE(CaloTowersReCreator);
0040 
0041 CaloTowersReCreator::CaloTowersReCreator(const edm::ParameterSet& conf)
0042     : algo_(0.,
0043             0.,
0044             false,
0045             false,
0046             false,
0047             false,
0048             0.,
0049             0.,
0050             0.,
0051             0.,
0052             0.,
0053             0.,
0054             0.,
0055             0.,
0056             0.,
0057             0.,
0058             0.,
0059             0.,
0060             0.,
0061             0.,
0062             0.,  // thresholds cannot be reapplied
0063             conf.getParameter<std::vector<double> >("EBGrid"),
0064             conf.getParameter<std::vector<double> >("EBWeights"),
0065             conf.getParameter<std::vector<double> >("EEGrid"),
0066             conf.getParameter<std::vector<double> >("EEWeights"),
0067             conf.getParameter<std::vector<double> >("HBGrid"),
0068             conf.getParameter<std::vector<double> >("HBWeights"),
0069             conf.getParameter<std::vector<double> >("HESGrid"),
0070             conf.getParameter<std::vector<double> >("HESWeights"),
0071             conf.getParameter<std::vector<double> >("HEDGrid"),
0072             conf.getParameter<std::vector<double> >("HEDWeights"),
0073             conf.getParameter<std::vector<double> >("HOGrid"),
0074             conf.getParameter<std::vector<double> >("HOWeights"),
0075             conf.getParameter<std::vector<double> >("HF1Grid"),
0076             conf.getParameter<std::vector<double> >("HF1Weights"),
0077             conf.getParameter<std::vector<double> >("HF2Grid"),
0078             conf.getParameter<std::vector<double> >("HF2Weights"),
0079             conf.getParameter<double>("EBWeight"),
0080             conf.getParameter<double>("EEWeight"),
0081             conf.getParameter<double>("HBWeight"),
0082             conf.getParameter<double>("HESWeight"),
0083             conf.getParameter<double>("HEDWeight"),
0084             conf.getParameter<double>("HOWeight"),
0085             conf.getParameter<double>("HF1Weight"),
0086             conf.getParameter<double>("HF2Weight"),
0087             0.,
0088             0.,
0089             0.,
0090             conf.getParameter<bool>("UseHO"),
0091             // (these have no effect on recreation: here for compatibility)
0092             conf.getParameter<int>("MomConstrMethod"),
0093             conf.getParameter<double>("MomHBDepth"),
0094             conf.getParameter<double>("MomHEDepth"),
0095             conf.getParameter<double>("MomEBDepth"),
0096             conf.getParameter<double>("MomEEDepth"),
0097             conf.getParameter<int>("HcalPhase")),
0098       allowMissingInputs_(false) {
0099   tok_calo_ = consumes<CaloTowerCollection>(conf.getParameter<edm::InputTag>("caloLabel"));
0100   tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
0101   tok_topo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0102   tok_cttopo_ = esConsumes<CaloTowerTopology, HcalRecNumberingRecord>();
0103   tok_ctmap_ = esConsumes<CaloTowerConstituentsMap, CaloGeometryRecord>();
0104 
0105   EBEScale = conf.getParameter<double>("EBEScale");
0106   EEEScale = conf.getParameter<double>("EEEScale");
0107   HBEScale = conf.getParameter<double>("HBEScale");
0108   HESEScale = conf.getParameter<double>("HESEScale");
0109   HEDEScale = conf.getParameter<double>("HEDEScale");
0110   HOEScale = conf.getParameter<double>("HOEScale");
0111   HF1EScale = conf.getParameter<double>("HF1EScale");
0112   HF2EScale = conf.getParameter<double>("HF2EScale");
0113   //  two notes:
0114   //  1) all this could go in a pset
0115   //  2) not clear the instanceLabel thing
0116 
0117   produces<CaloTowerCollection>();
0118 }
0119 
0120 void CaloTowersReCreator::produce(edm::Event& e, const edm::EventSetup& c) {
0121   // get the necessary event setup objects...
0122   edm::ESHandle<CaloGeometry> pG = c.getHandle(tok_geom_);
0123   edm::ESHandle<HcalTopology> htopo = c.getHandle(tok_topo_);
0124   edm::ESHandle<CaloTowerTopology> cttopo = c.getHandle(tok_cttopo_);
0125   edm::ESHandle<CaloTowerConstituentsMap> ctmap = c.getHandle(tok_ctmap_);
0126 
0127   algo_.setEBEScale(EBEScale);
0128   algo_.setEEEScale(EEEScale);
0129   algo_.setHBEScale(HBEScale);
0130   algo_.setHESEScale(HESEScale);
0131   algo_.setHEDEScale(HEDEScale);
0132   algo_.setHOEScale(HOEScale);
0133   algo_.setHF1EScale(HF1EScale);
0134   algo_.setHF2EScale(HF2EScale);
0135   algo_.setGeometry(cttopo.product(), ctmap.product(), htopo.product(), pG.product());
0136 
0137   algo_.begin();  // clear the internal buffer
0138 
0139   // Step A/C: Get Inputs and process (repeatedly)
0140   edm::Handle<CaloTowerCollection> calt;
0141   e.getByToken(tok_calo_, calt);
0142 
0143   // modified to rescale the CaloTowers directly
0144   // without going through metatowers
0145   // required for the algorithms that make use of individual
0146   // crystal information
0147 
0148   if (!calt.isValid()) {
0149     // can't find it!
0150     if (!allowMissingInputs_) {
0151       *calt;  // will throw the proper exception
0152     }
0153   } else {
0154     // Step B: Create empty output
0155     auto prod = std::make_unique<CaloTowerCollection>();
0156 
0157     // step C: rescale (without going threough metataowers)
0158     algo_.rescaleTowers(*calt, *prod);
0159 
0160     // Step D: Put into the event
0161     e.put(std::move(prod));
0162   }
0163 }
0164 
0165 void CaloTowersReCreator::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0166   edm::ParameterSetDescription desc;
0167   desc.add<double>("EBWeight", 1.0);
0168   desc.add<double>("HBEScale", 50.0);
0169   desc.add<double>("HEDWeight", 1.0);
0170   desc.add<double>("EEWeight", 1.0);
0171   desc.add<double>("HF1Weight", 1.0);
0172   desc.add<double>("HOWeight", 1.0);
0173   desc.add<double>("HESWeight", 1.0);
0174   desc.add<double>("HF2Weight", 1.0);
0175   desc.add<double>("HESEScale", 50.0);
0176   desc.add<double>("HEDEScale", 50.0);
0177   desc.add<double>("EBEScale", 50.0);
0178   desc.add<double>("HBWeight", 1.0);
0179   desc.add<double>("EEEScale", 50.0);
0180   desc.add<double>("MomHBDepth", 0.2);
0181   desc.add<double>("MomHEDepth", 0.4);
0182   desc.add<double>("MomEBDepth", 0.3);
0183   desc.add<double>("MomEEDepth", 0.0);
0184   desc.add<std::vector<double> >("HBGrid", {0.0, 2.0, 4.0, 5.0, 9.0, 20.0, 30.0, 50.0, 100.0, 1000.0});
0185   desc.add<std::vector<double> >("EEWeights", {0.51, 1.39, 1.71, 2.37, 2.32, 2.2, 2.1, 1.98, 1.8});
0186   desc.add<std::vector<double> >("HF2Weights", {1.0, 1.0, 1.0, 1.0, 1.0});
0187   desc.add<std::vector<double> >("HOWeights", {1.0, 1.0, 1.0, 1.0, 1.0});
0188   desc.add<std::vector<double> >("EEGrid", {2.0, 4.0, 5.0, 9.0, 20.0, 30.0, 50.0, 100.0, 300.0});
0189   desc.add<std::vector<double> >("HBWeights", {2.0, 1.86, 1.69, 1.55, 1.37, 1.19, 1.13, 1.11, 1.09, 1.0});
0190   desc.add<std::vector<double> >("HF2Grid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
0191   desc.add<std::vector<double> >("HEDWeights", {1.7, 1.57, 1.54, 1.49, 1.41, 1.26, 1.19, 1.15, 1.12, 1.0});
0192   desc.add<std::vector<double> >("HF1Grid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
0193   desc.add<std::vector<double> >("EBWeights", {0.86, 1.47, 1.66, 2.01, 1.98, 1.86, 1.83, 1.74, 1.65});
0194   desc.add<std::vector<double> >("HF1Weights", {1.0, 1.0, 1.0, 1.0, 1.0});
0195   desc.add<std::vector<double> >("HESGrid", {0.0, 2.0, 4.0, 5.0, 9.0, 20.0, 30.0, 50.0, 100.0, 1000.0});
0196   desc.add<std::vector<double> >("HESWeights", {1.7, 1.57, 1.54, 1.49, 1.41, 1.26, 1.19, 1.15, 1.12, 1.0});
0197   desc.add<std::vector<double> >("HEDGrid", {0.0, 2.0, 4.0, 5.0, 9.0, 20.0, 30.0, 50.0, 100.0, 1000.0});
0198   desc.add<std::vector<double> >("HOGrid", {-1.0, 1.0, 10.0, 100.0, 1000.0});
0199   desc.add<std::vector<double> >("EBGrid", {2.0, 4.0, 5.0, 9.0, 20.0, 30.0, 50.0, 100.0, 300.0});
0200   desc.add<edm::InputTag>("caloLabel", edm::InputTag("calotowermaker"));
0201   desc.add<int>("MomConstrMethod", 1);
0202   desc.add<int>("HcalPhase", 0);
0203 
0204   descriptions.addDefault(desc);
0205 }