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);
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
StringObjectFunction< T, true >
configurableAnalysis::Candidate
char Candidate[]
Definition: modules.cc:20
EDProducer.h
OtherObjectVariableComputer::doSort_
bool doSort_
Definition: OtherObjectVariableComputer.cc:40
sistrip::View
View
Definition: ConstantsForView.h:26
OtherObjectVariableComputer::objVar_
StringObjectFunction< T, true > objVar_
Definition: OtherObjectVariableComputer.cc:37
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
OtherObjectVariableComputer::objSort_
StringObjectFunction< T, true > objSort_
Definition: OtherObjectVariableComputer.cc:41
objects
Definition: __init__.py:1
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
OtherCandVariableComputer
OtherObjectVariableComputer< reco::Candidate > OtherCandVariableComputer
Definition: OtherObjectVariableComputer.cc:95
OtherObjectVariableComputer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: OtherObjectVariableComputer.cc:62
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
CandidateFwd.h
MakerMacros.h
Track.h
OtherObjectVariableComputer
Matcher of number of reconstructed objects in the event to probe.
Definition: OtherObjectVariableComputer.cc:27
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
OtherObjectVariableComputer::~OtherObjectVariableComputer
~OtherObjectVariableComputer() override
Definition: OtherObjectVariableComputer.cc:59
OtherObjectVariableComputer::default_
double default_
Definition: OtherObjectVariableComputer.cc:38
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
deltaR.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
iEvent
int iEvent
Definition: GenABIO.cc:224
OtherObjectVariableComputer::objectsToken_
edm::EDGetTokenT< edm::View< T > > objectsToken_
Definition: OtherObjectVariableComputer.cc:36
edm::EventSetup
Definition: EventSetup.h:57
hgcalPerformanceValidation.objects
objects
Definition: hgcalPerformanceValidation.py:695
InputTag.h
ValueMap.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
StringCutObjectSelector.h
OtherObjectVariableComputer::probesToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > probesToken_
Definition: OtherObjectVariableComputer.cc:35
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ValueMap
Definition: ValueMap.h:107
StringCutObjectSelector< T, true >
edm::EDProducer
Definition: EDProducer.h:35
OtherObjectVariableComputer::objCut_
StringCutObjectSelector< T, true > objCut_
Definition: OtherObjectVariableComputer.cc:39
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
OtherObjectVariableComputer::OtherObjectVariableComputer
OtherObjectVariableComputer(const edm::ParameterSet &iConfig)
Definition: OtherObjectVariableComputer.cc:45
Candidate.h
View.h
ParameterSet.h
edm::Event
Definition: Event.h:73
StringObjectFunction.h