CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
MuIsoDepositProducer Class Reference

#include <MuIsoDepositProducer.h>

Inheritance diagram for MuIsoDepositProducer:
edm::stream::EDProducer<>

Public Member Functions

 MuIsoDepositProducer (const edm::ParameterSet &)
 constructor More...
 
void produce (edm::Event &, const edm::EventSetup &) override
 data making method More...
 
 ~MuIsoDepositProducer () override
 destructor More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Attributes

std::vector< std::string > theDepositNames
 
bool theExtractForCandidate
 
std::unique_ptr< reco::isodeposit::IsoDepositExtractortheExtractor
 
std::string theInputType
 
bool theMultipleDepositsFlag
 
edm::EDGetToken theMuonCollectionTag
 
std::string theMuonTrackRefType
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 13 of file MuIsoDepositProducer.h.

Constructor & Destructor Documentation

MuIsoDepositProducer::MuIsoDepositProducer ( const edm::ParameterSet par)

constructor

constructor with config

Definition at line 36 of file MuIsoDepositProducer.cc.

References egammaCTFFinalFitWithMaterial_cff::alias, relativeConstraints::empty, Exception, reco::get(), edm::ParameterSet::getParameter(), mps_fire::i, LogDebug, metname, AlCaHLTBitMon_QueryRunRegistry::string, theDepositNames, theExtractForCandidate, theExtractor, theInputType, theMultipleDepositsFlag, theMuonCollectionTag, and theMuonTrackRefType.

36  :
37  theDepositNames(std::vector<std::string>(1,std::string()))
38 {
39  static const std::string metname = "RecoMuon|MuonIsolationProducers|MuIsoDepositProducer";
40  LogDebug(metname)<<" 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 
48  bool readFromRecoTrack = theInputType == "TrackCollection";
49  bool readFromRecoMuon = theInputType == "MuonCollection";
50  bool readFromCandidateView = theInputType == "CandidateView";
51  if(readFromRecoTrack){
52  theMuonCollectionTag = consumes<View<Track>>(ioPSet.getParameter<edm::InputTag>("inputMuonCollection"));
53  } else if(readFromRecoMuon) {
54  theMuonCollectionTag = consumes<View<RecoCandidate>>(ioPSet.getParameter<edm::InputTag>("inputMuonCollection"));
55  } else if (readFromCandidateView) {
56  theMuonCollectionTag = consumes<View<Candidate>>(ioPSet.getParameter<edm::InputTag>("inputMuonCollection"));
57  } else {
58  throw cms::Exception("Configuration")<<"Inconsistent configuration or failure to read Candidate-muon view";
59  }
60 
61  theMultipleDepositsFlag = ioPSet.getParameter<bool>("MultipleDepositsFlag");
62 
63 
64 
66  theDepositNames = par.getParameter<edm::ParameterSet>("ExtractorPSet")
67  .getParameter<std::vector<std::string> >("DepositInstanceLabels");
68  }
69 
70  for (unsigned int i = 0; i < theDepositNames.size(); ++i){
71  std::string alias = par.getParameter<std::string>("@module_label");
72  if (!theDepositNames[i].empty()) alias += "_" + theDepositNames[i];
73  produces<reco::IsoDepositMap>(theDepositNames[i]).setBranchAlias(alias);
74  }
75 
76  edm::ParameterSet extractorPSet = par.getParameter<edm::ParameterSet>("ExtractorPSet");
77  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
78  theExtractor = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet, consumesCollector())};
79  LogDebug(metname)<<" Load extractor..."<<extractorName;
80 }
#define LogDebug(id)
T getParameter(std::string const &) const
std::vector< std::string > theDepositNames
const std::string metname
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > theExtractor
edm::EDGetToken theMuonCollectionTag
T get(const Candidate &c)
Definition: component.h:55
MuIsoDepositProducer::~MuIsoDepositProducer ( )
override

destructor

Definition at line 83 of file MuIsoDepositProducer.cc.

References LogDebug.

83  {
84  LogDebug("RecoMuon/MuIsoDepositProducer")<<" MuIsoDepositProducer DTOR";
85 }
#define LogDebug(id)

Member Function Documentation

void MuIsoDepositProducer::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
override

data making method

build deposits

read them as RecoCandidates: need to have track() standAloneMuon() etc in the interface

get rid of this at some point and use the cands

expect nMuons set already

OK, now we know how many deps for how many muons each we will create might linearize this at some point (lazy) do it in case some muons are there only

end for (nMuons)

now fill in selectively

some debugging stuff

fill the maps here

now figure out the source handle (see getByToken above)

now actually fill

end if (nMuons>0)

Definition at line 88 of file MuIsoDepositProducer.cc.

References begin, egammaForCoreTracking_cff::cands, DEFINE_FWK_MODULE, symbols::deps, end, edm::helper::Filler< Map >::fill(), objects.autophobj::filler, mps_fire::i, edm::EDGetToken::index(), edm::helper::Filler< Map >::insert(), LogDebug, LogTrace, metname, eostools::move(), extraflags_cff::muons, custom_jme_cff::nMuons, susybsm::HSCParticleType::standAloneMuon, AlCaHLTBitMon_QueryRunRegistry::string, theDepositNames, theExtractForCandidate, theExtractor, theInputType, theMultipleDepositsFlag, theMuonCollectionTag, theMuonTrackRefType, HiIsolationCommonParameters_cff::track, and l1t::tracks.

88  {
89  static const std::string metname = "RecoMuon|MuonIsolationProducers|MuIsoDepositProducer";
90 
91  LogDebug(metname)<<" Muon Deposit producing..."
92  <<" BEGINING OF EVENT " <<"================================";
93 
94  unsigned int nDeps = theMultipleDepositsFlag ? theDepositNames.size() : 1;
95 
96 
97 
98  // Take the muon container
99  LogTrace(metname)<<" Taking the muons: "<<theMuonCollectionTag.index();//a more friendly print would use "inputMuonCollection"
104 
105  unsigned int nMuons = 0;
106 
107  bool readFromRecoTrack = theInputType == "TrackCollection";
108  bool readFromRecoMuon = theInputType == "MuonCollection";
109  bool readFromCandidateView = theInputType == "CandidateView";
110 
111  if (readFromRecoMuon){
112  event.getByToken(theMuonCollectionTag,muons);
113  nMuons = muons->size();
114  LogDebug(metname) <<"Got Muons of size "<<nMuons;
115 
116  }
117  if (readFromRecoTrack){
118  event.getByToken(theMuonCollectionTag,tracks);
119  nMuons = tracks->size();
120  LogDebug(metname) <<"Got MuonTracks of size "<<nMuons;
121  }
122  if (readFromCandidateView || theExtractForCandidate){
123  event.getByToken(theMuonCollectionTag,cands);
124  unsigned int nCands = cands->size();
125  if (readFromRecoMuon && theExtractForCandidate){
127  if (nMuons != nCands) edm::LogError(metname)<<"Inconsistent configuration or failure to read Candidate-muon view";
128  }
129  nMuons = nCands;
130  LogDebug(metname)<< "Got candidate view with size "<<nMuons;
131  }
132 
133  static const unsigned int MAX_DEPS=10;
134  std::unique_ptr<reco::IsoDepositMap> depMaps[MAX_DEPS];
135 
136  if (nDeps >10 ) LogError(metname)<<"Unable to handle more than 10 input deposits";
137  for (unsigned int i =0;i<nDeps; ++i){
138  depMaps[i] = std::make_unique<reco::IsoDepositMap>();
139  }
140 
144  if (nMuons > 0){
145 
146  std::vector<std::vector<IsoDeposit> > deps2D(nDeps, std::vector<IsoDeposit>(nMuons));
147 
148  for (unsigned int i=0; i< nMuons; ++i) {
149  TrackBaseRef muRef;
150  if (readFromRecoMuon){
151  if (theMuonTrackRefType == "track"){
152  muRef = TrackBaseRef((*muons)[i].track());
153  } else if (theMuonTrackRefType == "standAloneMuon"){
154  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
155  } else if (theMuonTrackRefType == "combinedMuon"){
156  muRef = TrackBaseRef((*muons)[i].combinedMuon());
157  } else if (theMuonTrackRefType == "bestGlbTrkSta"){
158  if (!(*muons)[i].combinedMuon().isNull()){
159  muRef = TrackBaseRef((*muons)[i].combinedMuon());
160  } else if (!(*muons)[i].track().isNull()){
161  muRef = TrackBaseRef((*muons)[i].track());
162  } else {
163  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
164  }
165  } else if (theMuonTrackRefType == "bestTrkSta"){
166  if (!(*muons)[i].track().isNull()){
167  muRef = TrackBaseRef((*muons)[i].track());
168  } else {
169  muRef = TrackBaseRef((*muons)[i].standAloneMuon());
170  }
171  }else {
172  edm::LogWarning(metname)<<"Wrong track type is supplied: breaking";
173  break;
174  }
175  } else if (readFromRecoTrack){
176  muRef = TrackBaseRef(tracks, i);
177  }
178 
180  if (readFromCandidateView || theExtractForCandidate) deps2D[0][i] = theExtractor->deposit(event, eventSetup, (*cands)[i]);
181  else deps2D[0][i] = theExtractor->deposit(event, eventSetup, muRef);
182 
183  } else {
184  std::vector<IsoDeposit> deps(nDeps);
185  if (readFromCandidateView || theExtractForCandidate) deps = theExtractor->deposits(event, eventSetup, (*cands)[i]);
186  else 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]
198  <<" for a muon at index "<<iMu;
199  LogTrace(metname)<<deps2D[iDep][iMu].print();
200  }
201 
203  reco::IsoDepositMap::Filler filler(*depMaps[iDep]);
204 
206  if (readFromRecoMuon){
207  filler.insert(muons, deps2D[iDep].begin(), deps2D[iDep].end());
208  } else if (readFromRecoTrack){
209  filler.insert(tracks, deps2D[iDep].begin(), deps2D[iDep].end());
210  } else if (readFromCandidateView){
211  filler.insert(cands, deps2D[iDep].begin(), deps2D[iDep].end());
212  } else {
213  edm::LogError(metname)<<"Inconsistent configuration: unknown type requested";
214  }
215 
217  filler.fill();
218  }
219  }
220 
221 
222  for (unsigned int iMap = 0; iMap < nDeps; ++iMap){
223  LogTrace(metname)<<"About to put a deposit named "<<theDepositNames[iMap]
224  <<" of size "<<depMaps[iMap]->size()
225  <<" into edm::Event";
226  event.put(std::move(depMaps[iMap]), theDepositNames[iMap]);
227  }
228 
229  LogTrace(metname) <<" END OF EVENT " <<"================================";
230 }
#define LogDebug(id)
std::vector< std::string > theDepositNames
const std::string metname
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > theExtractor
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:36
edm::EDGetToken theMuonCollectionTag
#define end
Definition: vmac.h:39
#define LogTrace(id)
#define begin
Definition: vmac.h:32
unsigned int index() const
Definition: EDGetToken.h:45
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

std::vector<std::string> MuIsoDepositProducer::theDepositNames
private

Definition at line 35 of file MuIsoDepositProducer.h.

Referenced by MuIsoDepositProducer(), and produce().

bool MuIsoDepositProducer::theExtractForCandidate
private

Definition at line 31 of file MuIsoDepositProducer.h.

Referenced by MuIsoDepositProducer(), and produce().

std::unique_ptr<reco::isodeposit::IsoDepositExtractor> MuIsoDepositProducer::theExtractor
private

Definition at line 37 of file MuIsoDepositProducer.h.

Referenced by MuIsoDepositProducer(), and produce().

std::string MuIsoDepositProducer::theInputType
private

input type. Choose from:

Definition at line 29 of file MuIsoDepositProducer.h.

Referenced by MuIsoDepositProducer(), and produce().

bool MuIsoDepositProducer::theMultipleDepositsFlag
private

Definition at line 36 of file MuIsoDepositProducer.h.

Referenced by MuIsoDepositProducer(), and produce().

edm::EDGetToken MuIsoDepositProducer::theMuonCollectionTag
private

Definition at line 34 of file MuIsoDepositProducer.h.

Referenced by MuIsoDepositProducer(), and produce().

std::string MuIsoDepositProducer::theMuonTrackRefType
private

Definition at line 33 of file MuIsoDepositProducer.h.

Referenced by MuIsoDepositProducer(), and produce().