CMS 3D CMS Logo

CandIsoDepositProducer.cc
Go to the documentation of this file.
2 
3 // Framework
9 
11 
15 
18 
21 
23 #include <string>
24 
25 using namespace edm;
26 using namespace reco;
27 
30  : theConfig(par),
31  theCandCollectionToken(consumes<edm::View<reco::Candidate> >(par.getParameter<edm::InputTag>("src"))),
32  theDepositNames(std::vector<std::string>(1, "")),
33  theMultipleDepositsFlag(par.getParameter<bool>("MultipleDepositsFlag")) {
34  LogDebug("PhysicsTools|MuonIsolation") << " CandIsoDepositProducer CTOR";
35 
36  edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
37  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
38  theExtractor = IsoDepositExtractorFactory::get()->create(extractorName, extractorPSet, consumesCollector());
39 
41  produces<reco::IsoDepositMap>();
42  else {
43  theDepositNames = extractorPSet.getParameter<std::vector<std::string> >("DepositInstanceLabels");
44  if (theDepositNames.size() > 10)
45  throw cms::Exception("Configuration Error") << "This module supports only up to 10 deposits";
46  for (unsigned int iDep = 0; iDep < theDepositNames.size(); ++iDep) {
47  produces<reco::IsoDepositMap>(theDepositNames[iDep]);
48  }
49  }
50 
51  std::string trackType = par.getParameter<std::string>("trackType");
52  if (trackType == "fake")
54  else if (trackType == "best")
56  else if (trackType == "standAloneMuon")
58  else if (trackType == "combinedMuon")
60  else if (trackType == "trackerMuon")
62  else if (trackType == "track")
64  else if (trackType == "gsf")
66  else if (trackType == "candidate")
68  else
69  throw cms::Exception("Error") << "Track type " << trackType << " not valid.";
70 }
71 
74  LogDebug("PhysicsTools/CandIsoDepositProducer") << " CandIsoDepositProducer DTOR";
75 }
76 
78  if (theTrackType == CandidateT) {
79  return nullptr;
80  } else if (theTrackType == FakeT) {
81  *dummy = Track(10, 10, c.vertex(), c.momentum(), c.charge(), reco::Track::CovarianceMatrix());
82  return dummy;
83  } else {
84  const RecoCandidate *rc = dynamic_cast<const RecoCandidate *>(&c);
85  if (rc == nullptr)
86  throw cms::Exception("Error") << " Candidate is not RecoCandidate: can't get a real track from it!";
87  switch (theTrackType) {
88  case FakeT:
89  break; // to avoid warning
90  case CandidateT:
91  break; // to avoid warning
92  case BestT:
93  return rc->bestTrack();
94  break;
95  case StandAloneMuonT:
96  return &*rc->standAloneMuon();
97  break;
98  case CombinedMuonT:
99  return &*rc->combinedMuon();
100  break;
101  case TrackT:
102  return &*rc->track();
103  break;
104  case GsfT:
105  return static_cast<const Track *>(rc->gsfTrack().get());
106  break;
107  }
108  return nullptr;
109  }
110 }
111 
114  static const std::string metname = "CandIsoDepositProducer";
115 
117  event.getByToken(theCandCollectionToken, hCands);
118 
119  unsigned int nDeps = theMultipleDepositsFlag ? theDepositNames.size() : 1;
120 
121  static const unsigned int MAX_DEPS = 10;
122 
123  if (nDeps > MAX_DEPS)
124  LogError(metname) << "Unable to handle more than 10 input deposits";
125 
129  size_t nMuons = hCands->size();
130  std::vector<std::vector<IsoDeposit> > deps2D(nDeps, std::vector<IsoDeposit>(nMuons));
131 
132  if (nMuons > 0) {
133  theExtractor->initEvent(event, eventSetup);
134 
135  Track dummy;
136  for (size_t i = 0; i < nMuons; ++i) {
137  const Candidate &c = (*hCands)[i];
138  const Track *track = extractTrack(c, &dummy);
139  if ((theTrackType != CandidateT) && (!track)) {
140  edm::LogWarning("CandIsoDepositProducer")
141  << "Candidate #" << i << " has no bestTrack(), it will produce no deposit";
142  reco::IsoDeposit emptyDep;
143  for (size_t iDep = 0; iDep < nDeps; ++iDep) {
144  deps2D[iDep][i] = emptyDep;
145  }
146  continue;
147  }
149  deps2D[0][i] = ((theTrackType == CandidateT) ? theExtractor->deposit(event, eventSetup, c)
150  : theExtractor->deposit(event, eventSetup, *track));
151  } else {
152  std::vector<IsoDeposit> deps =
154  : theExtractor->deposits(event, eventSetup, *track));
155  for (unsigned int iDep = 0; iDep < nDeps; ++iDep) {
156  deps2D[iDep][i] = deps[iDep];
157  }
158  }
159  }
160  } //if (nMuons>0)
161 
163  for (unsigned int iDep = 0; iDep < nDeps; ++iDep) {
165  for (unsigned int iMu = 0; iMu < nMuons; ++iMu) {
166  LogTrace(metname) << "Contents of " << theDepositNames[iDep] << " for a muon at index " << iMu;
167  LogTrace(metname) << deps2D[iDep][iMu].print();
168  }
169 
171  auto depMap = std::make_unique<reco::IsoDepositMap>();
173  filler.insert(hCands, deps2D[iDep].begin(), deps2D[iDep].end());
174  deps2D[iDep].clear();
175  filler.fill();
176  event.put(std::move(depMap), theDepositNames[iDep]);
177  }
178 }
179 
CandIsoDepositProducer
Definition: CandIsoDepositProducer.h:24
CandIsoDepositProducer::FakeT
Definition: CandIsoDepositProducer.h:34
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
Muon.h
MessageLogger.h
CandIsoDepositProducer::CombinedMuonT
Definition: CandIsoDepositProducer.h:34
EDProducer.h
ESHandle.h
reco::RecoCandidate::combinedMuon
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track
Definition: RecoCandidate.cc:23
CandIsoDepositProducer::theExtractor
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > theExtractor
Definition: CandIsoDepositProducer.h:40
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
reco::RecoCandidate::standAloneMuon
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track
Definition: RecoCandidate.cc:21
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
IsoDepositDirection.h
reco::RecoCandidate::gsfTrack
virtual reco::GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: RecoCandidate.cc:19
CandIsoDepositProducer::CandIsoDepositProducer
CandIsoDepositProducer(const edm::ParameterSet &)
constructor with config
Definition: CandIsoDepositProducer.cc:29
reco::RecoCandidate::track
virtual reco::TrackRef track() const
reference to a Track
Definition: RecoCandidate.cc:13
end
#define end
Definition: vmac.h:39
CandIsoDepositProducer::BestT
Definition: CandIsoDepositProducer.h:34
MakerMacros.h
CandIsoDepositProducer::TrackT
Definition: CandIsoDepositProducer.h:34
reco::RecoCandidate::bestTrack
const Track * bestTrack() const override
best track pointer
Definition: RecoCandidate.cc:29
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
jets_cff.nMuons
nMuons
Definition: jets_cff.py:209
reco::Track
Definition: Track.h:27
IsoDeposit.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
CandIsoDepositProducer::~CandIsoDepositProducer
~CandIsoDepositProducer() override
destructor
Definition: CandIsoDepositProducer.cc:73
IsoDepositExtractor.h
CandIsoDepositProducer.h
edm::View
Definition: CaloClusterFwd.h:14
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
CandIsoDepositProducer::StandAloneMuonT
Definition: CandIsoDepositProducer.h:34
GsfTrack.h
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
reco::RecoCandidate
Definition: RecoCandidate.h:20
CandIsoDepositProducer::theDepositNames
std::vector< std::string > theDepositNames
Definition: CandIsoDepositProducer.h:38
get
#define get
CandIsoDepositProducer::CandidateT
Definition: CandIsoDepositProducer.h:34
PbPb_ZMuSkimMuonDPG_cff.trackType
trackType
Definition: PbPb_ZMuSkimMuonDPG_cff.py:36
reco::Candidate
Definition: Candidate.h:27
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CandIsoDepositProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
build deposits
Definition: CandIsoDepositProducer.cc:113
CandIsoDepositProducer::theCandCollectionToken
edm::EDGetTokenT< edm::View< reco::Candidate > > theCandCollectionToken
Definition: CandIsoDepositProducer.h:36
Exception
Definition: hltDiff.cc:246
IsoDepositExtractorFactory.h
options_cfi.eventSetup
eventSetup
Definition: options_cfi.py:12
EventSetup.h
reco::IsoDeposit
Definition: IsoDeposit.h:49
CandIsoDepositProducer::theConfig
edm::ParameterSet theConfig
Definition: CandIsoDepositProducer.h:35
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
CandIsoDepositProducer::GsfT
Definition: CandIsoDepositProducer.h:34
cms::Exception
Definition: Exception.h:70
edm::helper::Filler
Definition: ValueMap.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
dummy
Definition: DummySelector.h:38
symbols.deps
deps
Definition: symbols.py:55
CandIsoDepositProducer::theTrackType
TrackType theTrackType
Definition: CandIsoDepositProducer.h:37
event
Definition: event.py:1
reco::TrackBase::CovarianceMatrix
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
edm::Event
Definition: Event.h:73
CandIsoDepositProducer::extractTrack
const reco::Track * extractTrack(const reco::Candidate &cand, reco::Track *dummyStorage) const
Definition: CandIsoDepositProducer.cc:77
CandIsoDepositProducer::theMultipleDepositsFlag
bool theMultipleDepositsFlag
Definition: CandIsoDepositProducer.h:39
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:43