CMS 3D CMS Logo

OtherObjectVariableComputer.cc
Go to the documentation of this file.
1 //
2 
14 
18 
25 
26 template <typename T>
28 public:
29  explicit OtherObjectVariableComputer(const edm::ParameterSet& iConfig);
31 
32  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
33 
34 private:
38  double default_;
39  StringCutObjectSelector<T, true> objCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
40  bool doSort_;
42 };
43 
44 template <typename T>
46  : probesToken_(consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("probes"))),
47  objectsToken_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("objects"))),
48  objVar_(iConfig.getParameter<std::string>("expression")),
49  default_(iConfig.getParameter<double>("default")),
50  objCut_(
51  iConfig.existsAs<std::string>("objectSelection") ? iConfig.getParameter<std::string>("objectSelection") : "",
52  true),
53  doSort_(iConfig.existsAs<std::string>("objectSortDescendingBy")),
54  objSort_(doSort_ ? iConfig.getParameter<std::string>("objectSortDescendingBy") : "1", true) {
55  produces<edm::ValueMap<float>>();
56 }
57 
58 template <typename T>
60 
61 template <typename T>
63  using namespace edm;
64 
65  // read input
68  iEvent.getByToken(probesToken_, probes);
69  iEvent.getByToken(objectsToken_, objects);
70 
71  // fill
72  std::vector<std::pair<double, double>> selected;
73  typename View<T>::const_iterator object, endobjects = objects->end();
74  for (object = objects->begin(); object != endobjects; ++object) {
75  if (objCut_(*object)) {
76  selected.push_back(std::pair<double, double>(objSort_(*object), objVar_(*object)));
77  if (!doSort_)
78  break; // if we take just the first one, there's no need of computing the others
79  }
80  }
81  if (doSort_ && selected.size() > 1)
82  std::sort(selected.begin(), selected.end()); // sorts (ascending)
83 
84  // prepare vector for output
85  std::vector<float> values(probes->size(), (selected.empty() ? default_ : selected.back().second));
86 
87  // convert into ValueMap and store
88  auto valMap = std::make_unique<ValueMap<float>>();
90  filler.insert(probes, values.begin(), values.end());
91  filler.fill();
92  iEvent.put(std::move(valMap));
93 }
94 
96 //typedef OtherObjectVariableComputer<reco::Track> OtherTrackVariableComputer;
97 //typedef OtherObjectVariableComputer<reco::Vertex> OtherVertexVariableComputer;
98 
101 //DEFINE_FWK_MODULE(OtherTrackVariableComputer);
102 //DEFINE_FWK_MODULE(OtherVertexVariableComputer);
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
OtherObjectVariableComputer(const edm::ParameterSet &iConfig)
Matcher of number of reconstructed objects in the event to probe.
edm::EDGetTokenT< edm::View< reco::Candidate > > probesToken_
OtherObjectVariableComputer< reco::Candidate > OtherCandVariableComputer
edm::EDGetTokenT< edm::View< T > > objectsToken_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
StringCutObjectSelector< T, true > objCut_
StringObjectFunction< T, true > objVar_
fixed size matrix
HLT enums.
StringObjectFunction< T, true > objSort_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
long double T
def move(src, dest)
Definition: eostools.py:511