CMS 3D CMS Logo

PackedCandidateTrackChi2Producer.cc
Go to the documentation of this file.
11 
12 namespace pat {
13 
16 
17  public:
19  : candidateToken_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("candidates"))),
20  trackToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackCollection"))),
21  doLostTracks_(iConfig.getParameter<bool>("doLostTracks")) {
22  if (doLostTracks_) {
23  track2LostTrackToken_ = consumes<edm::Association<pat::PackedCandidateCollection>>(
24  iConfig.getParameter<edm::InputTag>("candidates"));
25  } else {
27  consumes<edm::Association<reco::PFCandidateCollection>>(iConfig.getParameter<edm::InputTag>("candidates"));
28  }
29 
30  produces<FloatMap>();
31  }
32 
33  void produce(edm::Event&, const edm::EventSetup&) override;
34 
36 
37  private:
42  const bool doLostTracks_;
43  static const uint8_t roundingPrecision = 8;
44  };
45 
46 } // namespace pat
47 
49  auto const candidates = iEvent.getHandle(candidateToken_);
50 
51  const edm::Association<reco::PFCandidateCollection>* candidate2PF = nullptr;
52  if (!doLostTracks_) {
53  candidate2PF = &iEvent.get(candidate2PFToken_);
54  }
55 
56  const edm::Association<pat::PackedCandidateCollection>* tracks2LT = nullptr;
58  if (doLostTracks_) {
59  tracks2LT = &iEvent.get(track2LostTrackToken_);
60  iEvent.getByToken(trackToken_, trks);
61  }
62 
63  const auto nCand = candidates->size();
64  std::vector<float> trkChi2Map(nCand, 0);
65 
66  if (doLostTracks_) { //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys...
67  for (size_t i = 0; i < trks->size(); i++) {
68  const auto& trk = reco::TrackRef(trks, i);
69  const auto& lostTrack = (*tracks2LT)[trk];
70  if (lostTrack.isNonnull()) {
71  const float nChi2 = trk->normalizedChi2();
72  trkChi2Map.at(lostTrack.key()) = MiniFloatConverter::reduceMantissaToNbitsRounding<roundingPrecision>(nChi2);
73  }
74  }
75  } else { //for the regular PackedPFCands we have direct references...
76  for (size_t i = 0; i < nCand; i++) {
77  const auto& cand = pat::PackedCandidateRef(candidates, i);
78 
79  // ignore neutral candidates or without track
80  if (cand->charge() == 0 || !cand->hasTrackDetails())
81  continue;
82 
83  const auto& candTrack = (*candidate2PF)[cand]->trackRef();
84 
85  if (candTrack.isNonnull()) {
86  const float nChi2 = candTrack->normalizedChi2();
87 
88  trkChi2Map.at(i) = MiniFloatConverter::reduceMantissaToNbitsRounding<roundingPrecision>(nChi2);
89  }
90  }
91  }
92 
93  // fill the value maps
94  std::unique_ptr<FloatMap> valueMap = std::make_unique<FloatMap>();
95  FloatMap::Filler filler(*valueMap);
96  filler.insert(candidates, trkChi2Map.begin(), trkChi2Map.end());
97  filler.fill();
98  iEvent.put(std::move(valueMap), "");
99 }
100 
101 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
104  desc.add<edm::InputTag>("candidates", edm::InputTag("packedPFCandidates"))
105  ->setComment("packed candidate input collection");
106  desc.add<edm::InputTag>("trackCollection", edm::InputTag("generalTracks"))->setComment("track input collection");
107  desc.add<bool>("doLostTracks", false);
108  descriptions.add("packedPFCandidateTrackChi2", desc);
109 }
110 
112 using namespace pat;
ConfigurationDescriptions.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
pat::PackedCandidateTrackChi2Producer::roundingPrecision
static const uint8_t roundingPrecision
Definition: PackedCandidateTrackChi2Producer.cc:43
edm::EDGetTokenT< pat::PackedCandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle< reco::TrackCollection >
pat::PackedCandidateTrackChi2Producer
Definition: PackedCandidateTrackChi2Producer.cc:14
pat::PackedCandidateTrackChi2Producer::track2LostTrackToken_
edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > track2LostTrackToken_
Definition: PackedCandidateTrackChi2Producer.cc:40
pat::PackedCandidateTrackChi2Producer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: PackedCandidateTrackChi2Producer.cc:102
MakerMacros.h
Track.h
libminifloat.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
pat::PackedCandidateTrackChi2Producer::candidateToken_
const edm::EDGetTokenT< pat::PackedCandidateCollection > candidateToken_
Definition: PackedCandidateTrackChi2Producer.cc:38
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
PackedCandidate.h
cand
Definition: decayParser.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::PackedCandidateTrackChi2Producer::FloatMap
edm::ValueMap< float > FloatMap
Definition: PackedCandidateTrackChi2Producer.cc:15
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
InputTag.h
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1131
ValueMap.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
pat::PackedCandidateTrackChi2Producer::doLostTracks_
const bool doLostTracks_
Definition: PackedCandidateTrackChi2Producer.cc:42
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:55017
edm::ValueMap< float >
pat::PackedCandidateTrackChi2Producer::trackToken_
const edm::EDGetTokenT< reco::TrackCollection > trackToken_
Definition: PackedCandidateTrackChi2Producer.cc:41
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
pat::PackedCandidateTrackChi2Producer::candidate2PFToken_
edm::EDGetTokenT< edm::Association< reco::PFCandidateCollection > > candidate2PFToken_
Definition: PackedCandidateTrackChi2Producer.cc:39
hltEgammaHLTExtra_cfi.trks
trks
Definition: hltEgammaHLTExtra_cfi.py:43
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
pat::PackedCandidateTrackChi2Producer::PackedCandidateTrackChi2Producer
PackedCandidateTrackChi2Producer(const edm::ParameterSet &iConfig)
Definition: PackedCandidateTrackChi2Producer.cc:18
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
pat::PackedCandidateTrackChi2Producer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PackedCandidateTrackChi2Producer.cc:48
pat::PackedCandidateRef
edm::Ref< pat::PackedCandidateCollection > PackedCandidateRef
Definition: PackedCandidate.h:1132