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 
edm::EDGetToken::index
constexpr unsigned int index() const noexcept
Definition: EDGetToken.h:50
Range.h
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
Handle.h
MuIsoDepositProducer::~MuIsoDepositProducer
~MuIsoDepositProducer() override
destructor
Definition: MuIsoDepositProducer.cc:79
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
Muon.h
MessageLogger.h
EDProducer.h
ESHandle.h
MuIsoDepositProducer::theInputType
std::string theInputType
Definition: MuIsoDepositProducer.h:31
custom_jme_cff.nMuons
nMuons
Definition: custom_jme_cff.py:148
edm
HLT enums.
Definition: AlignableModifier.h:19
MuIsoDepositProducer::theMuonCollectionTag
edm::EDGetToken theMuonCollectionTag
Definition: MuIsoDepositProducer.h:36
reco::TrackBaseRef
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:35
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
IsoDepositDirection.h
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
MuIsoDepositProducer::theExtractForCandidate
bool theExtractForCandidate
Definition: MuIsoDepositProducer.h:33
MuIsoDepositProducer
Definition: MuIsoDepositProducer.h:17
MakerMacros.h
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuIsoDepositProducer::MuIsoDepositProducer
MuIsoDepositProducer(const edm::ParameterSet &)
constructor
Definition: MuIsoDepositProducer.cc:34
MuonFwd.h
mps_fire.end
end
Definition: mps_fire.py:242
IsoDeposit.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
IsoDepositExtractor.h
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15146
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
MuIsoDepositProducer::theMuonTrackRefType
std::string theMuonTrackRefType
Definition: MuIsoDepositProducer.h:35
ModuleDef.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
muonisolation
Definition: CandViewExtractor.h:16
ValueMap.h
MuIsoDepositProducer::theDepositNames
std::vector< std::string > theDepositNames
Definition: MuIsoDepositProducer.h:37
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
MuIsoDepositProducer.h
MuIsoDepositProducer::theMultipleDepositsFlag
bool theMultipleDepositsFlag
Definition: MuIsoDepositProducer.h:38
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:128
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Exception
Definition: hltDiff.cc:245
IsoDepositExtractorFactory.h
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase< reco::Track >
ConsumesCollector.h
IsoDepositFwd.h
edm::helper::Filler
Definition: ValueMap.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
symbols.deps
deps
Definition: symbols.py:55
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
MuIsoDepositProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
data making method
Definition: MuIsoDepositProducer.cc:84
susybsm::HSCParticleType::standAloneMuon
Definition: HSCParticle.h:20
edm::InputTag
Definition: InputTag.h:15
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:40
MuIsoDepositProducer::theExtractor
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > theExtractor
Definition: MuIsoDepositProducer.h:39