File indexing completed on 2023-03-17 11:15:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include "FWCore/Framework/interface/global/EDProducer.h"
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/EventSetup.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/Utilities/interface/InputTag.h"
0034 #include "PhysicsTools/CandUtils/interface/EventShapeVariables.h"
0035 #include "PhysicsTools/CandUtils/interface/Thrust.h"
0036
0037 #include <memory>
0038 #include <vector>
0039
0040 class EventShapeVarsProducer : public edm::global::EDProducer<> {
0041 public:
0042 explicit EventShapeVarsProducer(const edm::ParameterSet&);
0043
0044 private:
0045 edm::EDGetTokenT<edm::View<reco::Candidate>> srcToken_;
0046 double r_;
0047 unsigned fwmax_;
0048
0049 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0050 };
0051
0052 EventShapeVarsProducer::EventShapeVarsProducer(const edm::ParameterSet& cfg) {
0053 srcToken_ = consumes<edm::View<reco::Candidate>>(cfg.getParameter<edm::InputTag>("src"));
0054 r_ = cfg.exists("r") ? cfg.getParameter<double>("r") : 2.;
0055 fwmax_ = cfg.exists("fwmax") ? cfg.getParameter<unsigned>("fwmax") : 0;
0056
0057 produces<double>("thrust");
0058
0059 produces<double>("isotropy");
0060 produces<double>("circularity");
0061 produces<double>("sphericity");
0062 produces<double>("aplanarity");
0063 produces<double>("C");
0064 produces<double>("D");
0065 if (fwmax_ > 0)
0066 produces<std::vector<double>>("FWmoments");
0067 }
0068
0069 void put(edm::Event& evt, double value, const char* instanceName) {
0070 evt.put(std::make_unique<double>(value), instanceName);
0071 }
0072
0073 void EventShapeVarsProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const {
0074 edm::Handle<edm::View<reco::Candidate>> objects;
0075 evt.getByToken(srcToken_, objects);
0076
0077 Thrust thrustAlgo(objects->begin(), objects->end());
0078 put(evt, thrustAlgo.thrust(), "thrust");
0079
0080
0081 EventShapeVariables eventShapeVarsAlgo(*objects);
0082 eventShapeVarsAlgo.set_r(r_);
0083 put(evt, eventShapeVarsAlgo.isotropy(), "isotropy");
0084 put(evt, eventShapeVarsAlgo.circularity(), "circularity");
0085 put(evt, eventShapeVarsAlgo.sphericity(), "sphericity");
0086 put(evt, eventShapeVarsAlgo.aplanarity(), "aplanarity");
0087 put(evt, eventShapeVarsAlgo.C(), "C");
0088 put(evt, eventShapeVarsAlgo.D(), "D");
0089 if (fwmax_ > 0) {
0090 eventShapeVarsAlgo.setFWmax(fwmax_);
0091 auto vfw = std::make_unique<std::vector<double>>(eventShapeVarsAlgo.getFWmoments());
0092 evt.put(std::move(vfw), "FWmoments");
0093 }
0094 }
0095
0096 #include "FWCore/Framework/interface/MakerMacros.h"
0097
0098 DEFINE_FWK_MODULE(EventShapeVarsProducer);