CMS 3D CMS Logo

MuIsoDepositProducer.cc
Go to the documentation of this file.
2 
3 // Framework
9 
11 
18 
21 
24 
26 #include <string>
27 
28 using namespace edm;
29 using namespace std;
30 using namespace reco;
31 using namespace muonisolation;
32 
35  : theDepositNames(std::vector<std::string>(1, std::string())) {
36  static const std::string metname = "RecoMuon|MuonIsolationProducers|MuIsoDepositProducer";
37  LogDebug(metname) << " MuIsoDepositProducer CTOR";
38 
39  edm::ParameterSet ioPSet = par.getParameter<edm::ParameterSet>("IOPSet");
40 
41  theInputType = ioPSet.getParameter<std::string>("InputType");
42  theExtractForCandidate = ioPSet.getParameter<bool>("ExtractForCandidate");
43  theMuonTrackRefType = ioPSet.getParameter<std::string>("MuonTrackRefType");
44 
45  bool readFromRecoTrack = theInputType == "TrackCollection";
46  bool readFromRecoMuon = theInputType == "MuonCollection";
47  bool readFromCandidateView = theInputType == "CandidateView";
48  if (readFromRecoTrack) {
49  theMuonCollectionTag = consumes<View<Track>>(ioPSet.getParameter<edm::InputTag>("inputMuonCollection"));
50  } else if (readFromRecoMuon) {
51  theMuonCollectionTag = consumes<View<RecoCandidate>>(ioPSet.getParameter<edm::InputTag>("inputMuonCollection"));
52  } else if (readFromCandidateView) {
53  theMuonCollectionTag = consumes<View<Candidate>>(ioPSet.getParameter<edm::InputTag>("inputMuonCollection"));
54  } else {
55  throw cms::Exception("Configuration") << "Inconsistent configuration or failure to read Candidate-muon view";
56  }
57 
58  theMultipleDepositsFlag = ioPSet.getParameter<bool>("MultipleDepositsFlag");
59 
61  theDepositNames = par.getParameter<edm::ParameterSet>("ExtractorPSet")
62  .getParameter<std::vector<std::string>>("DepositInstanceLabels");
63  }
64 
65  for (unsigned int i = 0; i < theDepositNames.size(); ++i) {
66  std::string alias = par.getParameter<std::string>("@module_label");
67  if (!theDepositNames[i].empty())
68  alias += "_" + theDepositNames[i];
69  produces<reco::IsoDepositMap>(theDepositNames[i]).setBranchAlias(alias);
70  }
71 
72  edm::ParameterSet extractorPSet = par.getParameter<edm::ParameterSet>("ExtractorPSet");
73  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
74  theExtractor = IsoDepositExtractorFactory::get()->create(extractorName, extractorPSet, consumesCollector());
75  LogDebug(metname) << " Load extractor..." << extractorName;
76 }
77 
80  LogDebug("RecoMuon/MuIsoDepositProducer") << " MuIsoDepositProducer DTOR";
81 }
82 
85  static const std::string metname = "RecoMuon|MuonIsolationProducers|MuIsoDepositProducer";
86 
87  LogDebug(metname) << " Muon Deposit producing..."
88  << " BEGINING OF EVENT "
89  << "================================";
90 
91  unsigned int nDeps = theMultipleDepositsFlag ? theDepositNames.size() : 1;
92 
93  // Take the muon container
94  LogTrace(metname) << " Taking the muons: "
95  << theMuonCollectionTag.index(); //a more friendly print would use "inputMuonCollection"
100 
101  unsigned int nMuons = 0;
102 
103  bool readFromRecoTrack = theInputType == "TrackCollection";
104  bool readFromRecoMuon = theInputType == "MuonCollection";
105  bool readFromCandidateView = theInputType == "CandidateView";
106 
107  if (readFromRecoMuon) {
108  event.getByToken(theMuonCollectionTag, muons);
109  nMuons = muons->size();
110  LogDebug(metname) << "Got Muons of size " << nMuons;
111  }
112  if (readFromRecoTrack) {
113  event.getByToken(theMuonCollectionTag, tracks);
114  nMuons = tracks->size();
115  LogDebug(metname) << "Got MuonTracks of size " << nMuons;
116  }
117  if (readFromCandidateView || theExtractForCandidate) {
118  event.getByToken(theMuonCollectionTag, cands);
119  unsigned int nCands = cands->size();
120  if (readFromRecoMuon && theExtractForCandidate) {
122  if (nMuons != nCands)
123  edm::LogError(metname) << "Inconsistent configuration or failure to read Candidate-muon view";
124  }
125  nMuons = nCands;
126  LogDebug(metname) << "Got candidate view with size " << nMuons;
127  }
128 
129  static const unsigned int MAX_DEPS = 10;
130  std::unique_ptr<reco::IsoDepositMap> depMaps[MAX_DEPS];
131 
132  if (nDeps > 10)
133  LogError(metname) << "Unable to handle more than 10 input deposits";
134  for (unsigned int i = 0; i < nDeps; ++i) {
135  depMaps[i] = std::make_unique<reco::IsoDepositMap>();
136  }
137 
141  if (nMuons > 0) {
142  std::vector<std::vector<IsoDeposit>> deps2D(nDeps, std::vector<IsoDeposit>(nMuons));
143 
144  for (unsigned int i = 0; i < nMuons; ++i) {
145  TrackBaseRef muRef;
146  if (readFromRecoMuon) {
147  if (theMuonTrackRefType == "track") {
148  muRef = TrackBaseRef((*muons)[i].track());
149  } else if (theMuonTrackRefType == "standAloneMuon") {
150  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
151  } else if (theMuonTrackRefType == "combinedMuon") {
152  muRef = TrackBaseRef((*muons)[i].combinedMuon());
153  } else if (theMuonTrackRefType == "bestGlbTrkSta") {
154  if (!(*muons)[i].combinedMuon().isNull()) {
155  muRef = TrackBaseRef((*muons)[i].combinedMuon());
156  } else if (!(*muons)[i].track().isNull()) {
157  muRef = TrackBaseRef((*muons)[i].track());
158  } else {
159  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
160  }
161  } else if (theMuonTrackRefType == "bestTrkSta") {
162  if (!(*muons)[i].track().isNull()) {
163  muRef = TrackBaseRef((*muons)[i].track());
164  } else {
165  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
166  }
167  } else {
168  edm::LogWarning(metname) << "Wrong track type is supplied: breaking";
169  break;
170  }
171  } else if (readFromRecoTrack) {
172  muRef = TrackBaseRef(tracks, i);
173  }
174 
176  if (readFromCandidateView || theExtractForCandidate)
177  deps2D[0][i] = theExtractor->deposit(event, eventSetup, (*cands)[i]);
178  else
179  deps2D[0][i] = theExtractor->deposit(event, eventSetup, muRef);
180 
181  } else {
182  std::vector<IsoDeposit> deps(nDeps);
183  if (readFromCandidateView || theExtractForCandidate)
184  deps = theExtractor->deposits(event, eventSetup, (*cands)[i]);
185  else
186  deps = theExtractor->deposits(event, eventSetup, muRef);
187  for (unsigned int iDep = 0; iDep < nDeps; ++iDep) {
188  deps2D[iDep][i] = deps[iDep];
189  }
190  }
191  }
192 
194  for (unsigned int iDep = 0; iDep < nDeps; ++iDep) {
196  for (unsigned int iMu = 0; iMu < nMuons; ++iMu) {
197  LogTrace(metname) << "Contents of " << theDepositNames[iDep] << " for a muon at index " << iMu;
198  LogTrace(metname) << deps2D[iDep][iMu].print();
199  }
200 
202  reco::IsoDepositMap::Filler filler(*depMaps[iDep]);
203 
205  if (readFromRecoMuon) {
206  filler.insert(muons, deps2D[iDep].begin(), deps2D[iDep].end());
207  } else if (readFromRecoTrack) {
208  filler.insert(tracks, deps2D[iDep].begin(), deps2D[iDep].end());
209  } else if (readFromCandidateView) {
210  filler.insert(cands, deps2D[iDep].begin(), deps2D[iDep].end());
211  } else {
212  edm::LogError(metname) << "Inconsistent configuration: unknown type requested";
213  }
214 
216  filler.fill();
217  }
218  }
219 
220  for (unsigned int iMap = 0; iMap < nDeps; ++iMap) {
221  LogTrace(metname) << "About to put a deposit named " << theDepositNames[iMap] << " of size "
222  << depMaps[iMap]->size() << " into edm::Event";
223  event.put(std::move(depMaps[iMap]), theDepositNames[iMap]);
224  }
225 
226  LogTrace(metname) << " END OF EVENT "
227  << "================================";
228 }
229 
#define LogDebug(id)
T getParameter(std::string const &) const
std::vector< std::string > theDepositNames
MuIsoDepositProducer(const edm::ParameterSet &)
constructor
const std::string metname
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > theExtractor
~MuIsoDepositProducer() override
destructor
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:35
edm::EDGetToken theMuonCollectionTag
#define end
Definition: vmac.h:39
#define LogTrace(id)
fixed size matrix
#define begin
Definition: vmac.h:32
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
data making method
unsigned int index() const
Definition: EDGetToken.h:45
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1