CMS 3D CMS Logo

CandIsoDepositProducer.cc
Go to the documentation of this file.
19 
20 #include <string>
21 
23 public:
25 
26  ~CandIsoDepositProducer() override;
27 
28  void produce(edm::Event &, const edm::EventSetup &) override;
29 
30 private:
31  inline const reco::Track *extractTrack(const reco::Candidate &cand, reco::Track *dummyStorage) const;
36  std::vector<std::string> theDepositNames;
38  std::unique_ptr<reco::isodeposit::IsoDepositExtractor> theExtractor;
39 };
40 
41 using namespace edm;
42 using namespace reco;
43 
46  : theConfig(par),
47  theCandCollectionToken(consumes<edm::View<reco::Candidate> >(par.getParameter<edm::InputTag>("src"))),
48  theDepositNames(std::vector<std::string>(1, "")),
49  theMultipleDepositsFlag(par.getParameter<bool>("MultipleDepositsFlag")) {
50  LogDebug("PhysicsTools|MuonIsolation") << " CandIsoDepositProducer CTOR";
51 
52  edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
53  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
54  theExtractor = IsoDepositExtractorFactory::get()->create(extractorName, extractorPSet, consumesCollector());
55 
57  produces<reco::IsoDepositMap>();
58  else {
59  theDepositNames = extractorPSet.getParameter<std::vector<std::string> >("DepositInstanceLabels");
60  if (theDepositNames.size() > 10)
61  throw cms::Exception("Configuration Error") << "This module supports only up to 10 deposits";
62  for (unsigned int iDep = 0; iDep < theDepositNames.size(); ++iDep) {
63  produces<reco::IsoDepositMap>(theDepositNames[iDep]);
64  }
65  }
66 
67  std::string trackType = par.getParameter<std::string>("trackType");
68  if (trackType == "fake")
70  else if (trackType == "best")
72  else if (trackType == "standAloneMuon")
74  else if (trackType == "combinedMuon")
76  else if (trackType == "trackerMuon")
78  else if (trackType == "track")
80  else if (trackType == "gsf")
82  else if (trackType == "candidate")
84  else
85  throw cms::Exception("Error") << "Track type " << trackType << " not valid.";
86 }
87 
90  LogDebug("PhysicsTools/CandIsoDepositProducer") << " CandIsoDepositProducer DTOR";
91 }
92 
94  if (theTrackType == CandidateT) {
95  return nullptr;
96  } else if (theTrackType == FakeT) {
97  *dummy = Track(10, 10, c.vertex(), c.momentum(), c.charge(), reco::Track::CovarianceMatrix());
98  return dummy;
99  } else {
100  const RecoCandidate *rc = dynamic_cast<const RecoCandidate *>(&c);
101  if (rc == nullptr)
102  throw cms::Exception("Error") << " Candidate is not RecoCandidate: can't get a real track from it!";
103  switch (theTrackType) {
104  case FakeT:
105  break; // to avoid warning
106  case CandidateT:
107  break; // to avoid warning
108  case BestT:
109  return rc->bestTrack();
110  break;
111  case StandAloneMuonT:
112  return &*rc->standAloneMuon();
113  break;
114  case CombinedMuonT:
115  return &*rc->combinedMuon();
116  break;
117  case TrackT:
118  return &*rc->track();
119  break;
120  case GsfT:
121  return static_cast<const Track *>(rc->gsfTrack().get());
122  break;
123  }
124  return nullptr;
125  }
126 }
127 
130  static const std::string metname = "CandIsoDepositProducer";
131 
133  event.getByToken(theCandCollectionToken, hCands);
134 
135  unsigned int nDeps = theMultipleDepositsFlag ? theDepositNames.size() : 1;
136 
137  static const unsigned int MAX_DEPS = 10;
138 
139  if (nDeps > MAX_DEPS)
140  LogError(metname) << "Unable to handle more than 10 input deposits";
141 
145  size_t nMuons = hCands->size();
146  std::vector<std::vector<IsoDeposit> > deps2D(nDeps, std::vector<IsoDeposit>(nMuons));
147 
148  if (nMuons > 0) {
149  theExtractor->initEvent(event, eventSetup);
150 
151  Track dummy;
152  for (size_t i = 0; i < nMuons; ++i) {
153  const Candidate &c = (*hCands)[i];
154  const Track *track = extractTrack(c, &dummy);
155  if ((theTrackType != CandidateT) && (!track)) {
156  edm::LogWarning("CandIsoDepositProducer")
157  << "Candidate #" << i << " has no bestTrack(), it will produce no deposit";
158  reco::IsoDeposit emptyDep;
159  for (size_t iDep = 0; iDep < nDeps; ++iDep) {
160  deps2D[iDep][i] = emptyDep;
161  }
162  continue;
163  }
165  deps2D[0][i] = ((theTrackType == CandidateT) ? theExtractor->deposit(event, eventSetup, c)
166  : theExtractor->deposit(event, eventSetup, *track));
167  } else {
168  std::vector<IsoDeposit> deps =
170  : theExtractor->deposits(event, eventSetup, *track));
171  for (unsigned int iDep = 0; iDep < nDeps; ++iDep) {
172  deps2D[iDep][i] = deps[iDep];
173  }
174  }
175  }
176  } //if (nMuons>0)
177 
179  for (unsigned int iDep = 0; iDep < nDeps; ++iDep) {
181  for (unsigned int iMu = 0; iMu < nMuons; ++iMu) {
182  LogTrace(metname) << "Contents of " << theDepositNames[iDep] << " for a muon at index " << iMu;
183  LogTrace(metname) << deps2D[iDep][iMu].print();
184  }
185 
187  auto depMap = std::make_unique<reco::IsoDepositMap>();
189  filler.insert(hCands, deps2D[iDep].begin(), deps2D[iDep].end());
190  deps2D[iDep].clear();
191  filler.fill();
192  event.put(std::move(depMap), theDepositNames[iDep]);
193  }
194 }
195 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual reco::GsfTrackRef gsfTrack() const
reference to a GsfTrack
const std::string metname
edm::EDGetTokenT< edm::View< reco::Candidate > > theCandCollectionToken
std::vector< std::string > theDepositNames
Log< level::Error, false > LogError
void produce(edm::Event &, const edm::EventSetup &) override
build deposits
#define LogTrace(id)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const reco::Track * extractTrack(const reco::Candidate &cand, reco::Track *dummyStorage) const
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > theExtractor
const Track * bestTrack() const override
best track pointer
CandIsoDepositProducer(const edm::ParameterSet &)
constructor with config
fixed size matrix
HLT enums.
virtual reco::TrackRef track() const
reference to a Track
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track
~CandIsoDepositProducer() override
destructor
#define get
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
#define LogDebug(id)
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track