CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuIsoDepositProducer.cc
Go to the documentation of this file.
2 
3 // Framework
8 
10 
17 
18 
21 
24 
26 #include <string>
27 
28 using namespace edm;
29 using namespace std;
30 using namespace reco;
31 using namespace muonisolation;
32 
33 
36  theConfig(par),
37  theDepositNames(std::vector<std::string>(1,std::string())),
38  theExtractor(0)
39 {
40  LogDebug("RecoMuon|MuonIsolation")<<" MuIsoDepositProducer CTOR";
41 
42  edm::ParameterSet ioPSet = par.getParameter<edm::ParameterSet>("IOPSet");
43 
44  theInputType = ioPSet.getParameter<std::string>("InputType");
45  theExtractForCandidate = ioPSet.getParameter<bool>("ExtractForCandidate");
46  theMuonTrackRefType = ioPSet.getParameter<std::string>("MuonTrackRefType");
47  theMuonCollectionTag = ioPSet.getParameter<edm::InputTag>("inputMuonCollection");
48  theMultipleDepositsFlag = ioPSet.getParameter<bool>("MultipleDepositsFlag");
49 
50 
51 
52  if (theMultipleDepositsFlag){
53  theDepositNames = par.getParameter<edm::ParameterSet>("ExtractorPSet")
54  .getParameter<std::vector<std::string> >("DepositInstanceLabels");
55  }
56 
57  for (unsigned int i = 0; i < theDepositNames.size(); ++i){
58  std::string alias = theConfig.getParameter<std::string>("@module_label");
59  if (theDepositNames[i] != "") alias += "_" + theDepositNames[i];
60  produces<reco::IsoDepositMap>(theDepositNames[i]).setBranchAlias(alias);
61  }
62 }
63 
66  LogDebug("RecoMuon/MuIsoDepositProducer")<<" MuIsoDepositProducer DTOR";
67  delete theExtractor;
68 }
69 
72  std::string metname = "RecoMuon|MuonIsolationProducers|MuIsoDepositProducer";
73 
74  LogDebug(metname)<<" Muon Deposit producing..."
75  <<" BEGINING OF EVENT " <<"================================";
76 
77  if (!theExtractor) {
78  edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
79  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
80  theExtractor = IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet);
81  LogDebug(metname)<<" Load extractor..."<<extractorName;
82  }
83 
84 
85  unsigned int nDeps = theMultipleDepositsFlag ? theDepositNames.size() : 1;
86 
87 
88 
89  // Take the muon container
90  LogTrace(metname)<<" Taking the muons: "<<theMuonCollectionTag;
94  Handle<View<Candidate> > cands;
95 
96  unsigned int nMuons = 0;
97 
98  bool readFromRecoTrack = theInputType == "TrackCollection";
99  bool readFromRecoMuon = theInputType == "MuonCollection";
100  bool readFromCandidateView = theInputType == "CandidateView";
101 
102  if (readFromRecoMuon){
103  event.getByLabel(theMuonCollectionTag,muons);
104  nMuons = muons->size();
105  LogDebug(metname) <<"Got Muons of size "<<nMuons;
106 
107  }
108  if (readFromRecoTrack){
109  event.getByLabel(theMuonCollectionTag,tracks);
110  nMuons = tracks->size();
111  LogDebug(metname) <<"Got MuonTracks of size "<<nMuons;
112  }
113  if (readFromCandidateView || theExtractForCandidate){
114  event.getByLabel(theMuonCollectionTag,cands);
115  unsigned int nCands = cands->size();
116  if (readFromRecoMuon && theExtractForCandidate){
118  if (nMuons != nCands) edm::LogError(metname)<<"Inconsistent configuration or failure to read Candidate-muon view";
119  }
120  nMuons = nCands;
121  LogDebug(metname)<< "Got candidate view with size "<<nMuons;
122  }
123 
124  static const unsigned int MAX_DEPS=10;
125  std::auto_ptr<reco::IsoDepositMap> depMaps[MAX_DEPS];
126 
127  if (nDeps >10 ) LogError(metname)<<"Unable to handle more than 10 input deposits";
128  for (unsigned int i =0;i<nDeps; ++i){
129  depMaps[i] = std::auto_ptr<reco::IsoDepositMap>(new reco::IsoDepositMap());
130  }
131 
135  if (nMuons > 0){
136 
137  std::vector<std::vector<IsoDeposit> > deps2D(nDeps, std::vector<IsoDeposit>(nMuons));
138 
139  for (unsigned int i=0; i< nMuons; ++i) {
140  TrackBaseRef muRef;
141  if (readFromRecoMuon){
142  if (theMuonTrackRefType == "track"){
143  muRef = TrackBaseRef((*muons)[i].track());
144  } else if (theMuonTrackRefType == "standAloneMuon"){
145  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
146  } else if (theMuonTrackRefType == "combinedMuon"){
147  muRef = TrackBaseRef((*muons)[i].combinedMuon());
148  } else if (theMuonTrackRefType == "bestGlbTrkSta"){
149  if (!(*muons)[i].combinedMuon().isNull()){
150  muRef = TrackBaseRef((*muons)[i].combinedMuon());
151  } else if (!(*muons)[i].track().isNull()){
152  muRef = TrackBaseRef((*muons)[i].track());
153  } else {
154  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
155  }
156  } else if (theMuonTrackRefType == "bestTrkSta"){
157  if (!(*muons)[i].track().isNull()){
158  muRef = TrackBaseRef((*muons)[i].track());
159  } else {
160  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
161  }
162  }else {
163  edm::LogWarning(metname)<<"Wrong track type is supplied: breaking";
164  break;
165  }
166  } else if (readFromRecoTrack){
167  muRef = TrackBaseRef(tracks, i);
168  }
169 
171  if (readFromCandidateView || theExtractForCandidate) deps2D[0][i] = theExtractor->deposit(event, eventSetup, (*cands)[i]);
172  else deps2D[0][i] = theExtractor->deposit(event, eventSetup, muRef);
173 
174  } else {
175  std::vector<IsoDeposit> deps(nDeps);
176  if (readFromCandidateView || theExtractForCandidate) deps = theExtractor->deposits(event, eventSetup, (*cands)[i]);
177  else deps = theExtractor->deposits(event, eventSetup, muRef);
178  for (unsigned int iDep =0; iDep<nDeps; ++iDep) {
179  deps2D[iDep][i] = deps[iDep];
180  }
181  }
182  }
183 
185  for (unsigned int iDep=0; iDep < nDeps; ++iDep){
187  for (unsigned int iMu = 0; iMu< nMuons; ++iMu){
188  LogTrace(metname)<<"Contents of "<<theDepositNames[iDep]
189  <<" for a muon at index "<<iMu;
190  LogTrace(metname)<<deps2D[iDep][iMu].print();
191  }
192 
194  reco::IsoDepositMap::Filler filler(*depMaps[iDep]);
195 
197  if (readFromRecoMuon){
198  filler.insert(muons, deps2D[iDep].begin(), deps2D[iDep].end());
199  } else if (readFromRecoTrack){
200  filler.insert(tracks, deps2D[iDep].begin(), deps2D[iDep].end());
201  } else if (readFromCandidateView){
202  filler.insert(cands, deps2D[iDep].begin(), deps2D[iDep].end());
203  } else {
204  edm::LogError(metname)<<"Inconsistent configuration: unknown type requested";
205  }
206 
208  filler.fill();
209  }
210  }
211 
212 
213  for (unsigned int iMap = 0; iMap < nDeps; ++iMap){
214  LogTrace(metname)<<"About to put a deposit named "<<theDepositNames[iMap]
215  <<" of size "<<depMaps[iMap]->size()
216  <<" into edm::Event";
217  event.put(depMaps[iMap], theDepositNames[iMap]);
218  }
219 
220  LogTrace(metname) <<" END OF EVENT " <<"================================";
221 }
222 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
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
virtual ~MuIsoDepositProducer()
destructor
edm::InputTag theMuonCollectionTag
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:22
#define end
Definition: vmac.h:38
edm::ValueMap< reco::IsoDeposit > IsoDepositMap
keep it only as a part of ValueMap
Definition: IsoDepositFwd.h:9
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
#define LogTrace(id)
tuple tracks
Definition: testEve_cfg.py:39
virtual std::vector< reco::IsoDeposit > deposits(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const
virtual void produce(edm::Event &, const edm::EventSetup &)
data making method
#define begin
Definition: vmac.h:31
tuple muons
Definition: patZpeak.py:38
reco::isodeposit::IsoDepositExtractor * theExtractor
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const =0
edm::ParameterSet theConfig
module configuration
T get(const Candidate &c)
Definition: component.h:56