CMS 3D CMS Logo

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