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
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(0)
40 {
41  LogDebug("RecoMuon|MuonIsolation")<<" MuIsoDepositProducer CTOR";
42 
43  edm::ParameterSet ioPSet = par.getParameter<edm::ParameterSet>("IOPSet");
44 
45  theInputType = ioPSet.getParameter<std::string>("InputType");
46  theExtractForCandidate = ioPSet.getParameter<bool>("ExtractForCandidate");
47  theMuonTrackRefType = ioPSet.getParameter<std::string>("MuonTrackRefType");
48  theMuonCollectionTag = ioPSet.getParameter<edm::InputTag>("inputMuonCollection");
49  theMultipleDepositsFlag = ioPSet.getParameter<bool>("MultipleDepositsFlag");
50 
51 
52 
53  if (theMultipleDepositsFlag){
54  theDepositNames = par.getParameter<edm::ParameterSet>("ExtractorPSet")
55  .getParameter<std::vector<std::string> >("DepositInstanceLabels");
56  }
57 
58  for (unsigned int i = 0; i < theDepositNames.size(); ++i){
60  if (theDepositNames[i] != "") alias += "_" + theDepositNames[i];
61  produces<reco::IsoDepositMap>(theDepositNames[i]).setBranchAlias(alias);
62  }
63 }
64 
67  LogDebug("RecoMuon/MuIsoDepositProducer")<<" MuIsoDepositProducer DTOR";
68  delete theExtractor;
69 }
70 
73  std::string metname = "RecoMuon|MuonIsolationProducers|MuIsoDepositProducer";
74 
75  LogDebug(metname)<<" Muon Deposit producing..."
76  <<" BEGINING OF EVENT " <<"================================";
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  unsigned int nDeps = theMultipleDepositsFlag ? theDepositNames.size() : 1;
87 
88 
89 
90  // Take the muon container
91  LogTrace(metname)<<" Taking the muons: "<<theMuonCollectionTag;
95  Handle<View<Candidate> > cands;
96 
97  unsigned int nMuons = 0;
98 
99  bool readFromRecoTrack = theInputType == "TrackCollection";
100  bool readFromRecoMuon = theInputType == "MuonCollection";
101  bool readFromCandidateView = theInputType == "CandidateView";
102 
103  if (readFromRecoMuon){
104  event.getByLabel(theMuonCollectionTag,muons);
105  nMuons = muons->size();
106  LogDebug(metname) <<"Got Muons of size "<<nMuons;
107 
108  }
109  if (readFromRecoTrack){
110  event.getByLabel(theMuonCollectionTag,tracks);
111  nMuons = tracks->size();
112  LogDebug(metname) <<"Got MuonTracks of size "<<nMuons;
113  }
114  if (readFromCandidateView || theExtractForCandidate){
115  event.getByLabel(theMuonCollectionTag,cands);
116  unsigned int nCands = cands->size();
117  if (readFromRecoMuon && theExtractForCandidate){
119  if (nMuons != nCands) edm::LogError(metname)<<"Inconsistent configuration or failure to read Candidate-muon view";
120  }
121  nMuons = nCands;
122  LogDebug(metname)<< "Got candidate view with size "<<nMuons;
123  }
124 
125  static const unsigned int MAX_DEPS=10;
126  std::auto_ptr<reco::IsoDepositMap> depMaps[MAX_DEPS];
127 
128  if (nDeps >10 ) LogError(metname)<<"Unable to handle more than 10 input deposits";
129  for (unsigned int i =0;i<nDeps; ++i){
130  depMaps[i] = std::auto_ptr<reco::IsoDepositMap>(new reco::IsoDepositMap());
131  }
132 
136  if (nMuons > 0){
137 
138  std::vector<std::vector<IsoDeposit> > deps2D(nDeps, std::vector<IsoDeposit>(nMuons));
139 
140  for (unsigned int i=0; i< nMuons; ++i) {
141  TrackBaseRef muRef;
142  if (readFromRecoMuon){
143  if (theMuonTrackRefType == "track"){
144  muRef = TrackBaseRef((*muons)[i].track());
145  } else if (theMuonTrackRefType == "standAloneMuon"){
146  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
147  } else if (theMuonTrackRefType == "combinedMuon"){
148  muRef = TrackBaseRef((*muons)[i].combinedMuon());
149  } else if (theMuonTrackRefType == "bestGlbTrkSta"){
150  if (!(*muons)[i].combinedMuon().isNull()){
151  muRef = TrackBaseRef((*muons)[i].combinedMuon());
152  } else if (!(*muons)[i].track().isNull()){
153  muRef = TrackBaseRef((*muons)[i].track());
154  } else {
155  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
156  }
157  } else if (theMuonTrackRefType == "bestTrkSta"){
158  if (!(*muons)[i].track().isNull()){
159  muRef = TrackBaseRef((*muons)[i].track());
160  } else {
161  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
162  }
163  }else {
164  edm::LogWarning(metname)<<"Wrong track type is supplied: breaking";
165  break;
166  }
167  } else if (readFromRecoTrack){
168  muRef = TrackBaseRef(tracks, i);
169  }
170 
172  if (readFromCandidateView || theExtractForCandidate) deps2D[0][i] = theExtractor->deposit(event, eventSetup, (*cands)[i]);
173  else deps2D[0][i] = theExtractor->deposit(event, eventSetup, muRef);
174 
175  } else {
176  std::vector<IsoDeposit> deps(nDeps);
177  if (readFromCandidateView || theExtractForCandidate) deps = theExtractor->deposits(event, eventSetup, (*cands)[i]);
178  else deps = theExtractor->deposits(event, eventSetup, muRef);
179  for (unsigned int iDep =0; iDep<nDeps; ++iDep) {
180  deps2D[iDep][i] = deps[iDep];
181  }
182  }
183  }
184 
186  for (unsigned int iDep=0; iDep < nDeps; ++iDep){
188  for (unsigned int iMu = 0; iMu< nMuons; ++iMu){
189  LogTrace(metname)<<"Contents of "<<theDepositNames[iDep]
190  <<" for a muon at index "<<iMu;
191  LogTrace(metname)<<deps2D[iDep][iMu].print();
192  }
193 
195  reco::IsoDepositMap::Filler filler(*depMaps[iDep]);
196 
198  if (readFromRecoMuon){
199  filler.insert(muons, deps2D[iDep].begin(), deps2D[iDep].end());
200  } else if (readFromRecoTrack){
201  filler.insert(tracks, deps2D[iDep].begin(), deps2D[iDep].end());
202  } else if (readFromCandidateView){
203  filler.insert(cands, deps2D[iDep].begin(), deps2D[iDep].end());
204  } else {
205  edm::LogError(metname)<<"Inconsistent configuration: unknown type requested";
206  }
207 
209  filler.fill();
210  }
211  }
212 
213 
214  for (unsigned int iMap = 0; iMap < nDeps; ++iMap){
215  LogTrace(metname)<<"About to put a deposit named "<<theDepositNames[iMap]
216  <<" of size "<<depMaps[iMap]->size()
217  <<" into edm::Event";
218  event.put(depMaps[iMap], theDepositNames[iMap]);
219  }
220 
221  LogTrace(metname) <<" END OF EVENT " <<"================================";
222 }
223 
#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:52
virtual ~MuIsoDepositProducer()
destructor
edm::InputTag theMuonCollectionTag
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:31
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
#define end
Definition: vmac.h:37
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:30
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:55