CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
CandIsoDepositProducer Class Reference

#include <CandIsoDepositProducer.h>

Inheritance diagram for CandIsoDepositProducer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 CandIsoDepositProducer (const edm::ParameterSet &)
 constructor with config More...
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 build deposits More...
 
virtual ~CandIsoDepositProducer ()
 destructor More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

enum  TrackType {
  FakeT, BestT, StandAloneMuonT, CombinedMuonT,
  TrackT, GsfT, CandidateT
}
 

Private Member Functions

const reco::TrackextractTrack (const reco::Candidate &cand, reco::Track *dummyStorage) const
 

Private Attributes

edm::EDGetTokenT< edm::View
< reco::Candidate > > 
theCandCollectionToken
 
edm::ParameterSet theConfig
 
std::vector< std::string > theDepositNames
 
reco::isodeposit::IsoDepositExtractortheExtractor
 
bool theMultipleDepositsFlag
 
TrackType theTrackType
 

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, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 20 of file CandIsoDepositProducer.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

CandIsoDepositProducer::CandIsoDepositProducer ( const edm::ParameterSet par)

constructor with config

Definition at line 33 of file CandIsoDepositProducer.cc.

References BestT, CandidateT, CombinedMuonT, edm::EDConsumerBase::consumesCollector(), edm::hlt::Exception, FakeT, reco::get(), edm::ParameterSet::getParameter(), GsfT, LogDebug, StandAloneMuonT, AlCaHLTBitMon_QueryRunRegistry::string, theConfig, theDepositNames, theExtractor, theMultipleDepositsFlag, theTrackType, and TrackT.

33  :
34  theConfig(par),
36  theDepositNames(std::vector<std::string>(1,"")),
37  theMultipleDepositsFlag(par.getParameter<bool>("MultipleDepositsFlag")),
38  theExtractor(0)
39  {
40  LogDebug("PhysicsTools|MuonIsolation")<<" CandIsoDepositProducer CTOR";
41 
42  edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
43  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
44  theExtractor = IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet, consumesCollector());
45 
46  if (! theMultipleDepositsFlag) produces<reco::IsoDepositMap>();
47  else {
48  theDepositNames = extractorPSet.getParameter<std::vector<std::string> >("DepositInstanceLabels");
49  if (theDepositNames.size() > 10) throw cms::Exception("Configuration Error") << "This module supports only up to 10 deposits";
50  for (unsigned int iDep=0; iDep<theDepositNames.size(); ++iDep){
51  produces<reco::IsoDepositMap>(theDepositNames[iDep]);
52  }
53  }
54 
55  std::string trackType = par.getParameter<std::string>("trackType");
56  if (trackType == "fake") theTrackType = FakeT;
57  else if (trackType == "best") theTrackType = BestT;
58  else if (trackType == "standAloneMuon") theTrackType = StandAloneMuonT;
59  else if (trackType == "combinedMuon") theTrackType = CombinedMuonT;
60  else if (trackType == "trackerMuon") theTrackType = TrackT;
61  else if (trackType == "track") theTrackType = TrackT;
62  else if (trackType == "gsf") theTrackType = GsfT;
63  else if (trackType == "candidate") theTrackType = CandidateT;
64  else throw cms::Exception("Error") << "Track type " << trackType << " not valid.";
65 }
#define LogDebug(id)
T getParameter(std::string const &) const
std::vector< std::string > theDepositNames
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
edm::EDGetTokenT< edm::View< reco::Candidate > > theCandCollectionToken
reco::isodeposit::IsoDepositExtractor * theExtractor
T get(const Candidate &c)
Definition: component.h:55
CandIsoDepositProducer::~CandIsoDepositProducer ( )
virtual

destructor

Definition at line 68 of file CandIsoDepositProducer.cc.

References LogDebug, and theExtractor.

68  {
69  LogDebug("PhysicsTools/CandIsoDepositProducer")<<" CandIsoDepositProducer DTOR";
70  delete theExtractor;
71 }
#define LogDebug(id)
reco::isodeposit::IsoDepositExtractor * theExtractor

Member Function Documentation

const reco::Track * CandIsoDepositProducer::extractTrack ( const reco::Candidate cand,
reco::Track dummyStorage 
) const
inlineprivate

Definition at line 73 of file CandIsoDepositProducer.cc.

References BestT, reco::RecoCandidate::bestTrack(), trackerHits::c, CandidateT, reco::Candidate::charge(), reco::RecoCandidate::combinedMuon(), CombinedMuonT, edm::hlt::Exception, FakeT, edm::Ref< C, T, F >::get(), GsfT, reco::RecoCandidate::gsfTrack(), reco::Candidate::momentum(), reco::RecoCandidate::standAloneMuon(), StandAloneMuonT, theTrackType, reco::RecoCandidate::track(), TrackT, and reco::Candidate::vertex().

Referenced by produce().

73  {
74  if (theTrackType == CandidateT) {
75  return 0;
76  } else if (theTrackType == FakeT) {
77  *dummy = Track(10,10,c.vertex(),c.momentum(),c.charge(), reco::Track::CovarianceMatrix());
78  return dummy;
79  } else {
80  const RecoCandidate *rc = dynamic_cast<const RecoCandidate *>(&c);
81  if (rc == 0) throw cms::Exception("Error") << " Candidate is not RecoCandidate: can't get a real track from it!";
82  switch (theTrackType) {
83  case FakeT: break; // to avoid warning
84  case CandidateT: break; // to avoid warning
85  case BestT: return rc->bestTrack(); break;
86  case StandAloneMuonT: return &*rc->standAloneMuon(); break;
87  case CombinedMuonT: return &*rc->combinedMuon(); break;
88  case TrackT: return &*rc->track(); break;
89  case GsfT: return static_cast<const Track*>(rc->gsfTrack().get()); break;
90  }
91  return 0;
92  }
93 }
virtual reco::GsfTrackRef gsfTrack() const
reference to a GsfTrack
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track
virtual reco::TrackRef track() const
reference to a Track
virtual const Track * bestTrack() const
best track pointer
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:70
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track
void CandIsoDepositProducer::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
virtual

build deposits

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

well, it is empty already by construction, but still

for(i<nMuons)

now fill in selectively

some debugging stuff

fill the maps here

for(iDep<nDeps)

if (nMuons>0)

Implements edm::stream::EDProducerBase.

Definition at line 96 of file CandIsoDepositProducer.cc.

References begin, trackerHits::c, CandidateT, reco::isodeposit::IsoDepositExtractor::deposit(), reco::isodeposit::IsoDepositExtractor::deposits(), end, extractTrack(), edm::helper::Filler< Map >::fill(), i, edm::helper::Filler< Map >::insert(), LogTrace, metname, edm::Event::put(), AlCaHLTBitMon_QueryRunRegistry::string, theCandCollectionToken, theDepositNames, theExtractor, theMultipleDepositsFlag, and theTrackType.

96  {
97  static const std::string metname = "CandIsoDepositProducer";
98 
100  event.getByToken(theCandCollectionToken, hCands);
101 
102  unsigned int nDeps = theMultipleDepositsFlag ? theDepositNames.size() : 1;
103 
104  static const unsigned int MAX_DEPS=10;
105  std::auto_ptr<reco::IsoDepositMap> depMaps[MAX_DEPS];
106 
107  if (nDeps >10 ) LogError(metname)<<"Unable to handle more than 10 input deposits";
108  for (unsigned int i =0;i<nDeps; ++i){ // check if nDeps > 10??
109  depMaps[i] = std::auto_ptr<reco::IsoDepositMap>(new reco::IsoDepositMap());
110  }
111 
115  size_t nMuons = hCands->size();
116  if (nMuons > 0){
117  std::vector<std::vector<IsoDeposit> > deps2D(nDeps, std::vector<IsoDeposit>(nMuons));
118 
119 
120  Track dummy;
121  for (size_t i=0; i< nMuons; ++i) {
122  const Candidate &c = (*hCands)[i];
123  const Track *track = extractTrack(c, &dummy);
124  if ((theTrackType != CandidateT) && (!track)) {
125  edm::LogWarning("CandIsoDepositProducer") << "Candidate #"<<i<<" has no bestTrack(), it will produce no deposit";
126  reco::IsoDeposit emptyDep;
127  for (size_t iDep=0;iDep<nDeps;++iDep) {
128  deps2D[iDep][i] = emptyDep;
129  }
130  continue;
131  }
133  IsoDeposit dep = ( ( theTrackType == CandidateT )
134  ? theExtractor->deposit(event, eventSetup, c)
135  : theExtractor->deposit(event, eventSetup, *track) );
136  deps2D[0][i] = dep;
137  } else {
138  std::vector<IsoDeposit> deps = ( ( theTrackType == CandidateT )
139  ? theExtractor->deposits(event, eventSetup, c)
140  : theExtractor->deposits(event, eventSetup, *track) );
141  for (unsigned int iDep=0; iDep < nDeps; ++iDep){ deps2D[iDep][i] = deps[iDep]; }
142  }
143  }
144 
145 
147  for (unsigned int iDep=0; iDep < nDeps; ++iDep){
149  for (unsigned int iMu = 0; iMu< nMuons; ++iMu){
150  LogTrace(metname)<<"Contents of "<<theDepositNames[iDep]
151  <<" for a muon at index "<<iMu;
152  LogTrace(metname)<<deps2D[iDep][iMu].print();
153  }
154 
156  reco::IsoDepositMap::Filler filler(*depMaps[iDep]);
157  filler.insert(hCands, deps2D[iDep].begin(), deps2D[iDep].end());
158  filler.fill();
159  }
160  }
161 
162  for (unsigned int iMap = 0; iMap < nDeps; ++iMap) event.put(depMaps[iMap], theDepositNames[iMap]);
163 }
int i
Definition: DBlmapReader.cc:9
const std::string metname
std::vector< std::string > theDepositNames
const reco::Track * extractTrack(const reco::Candidate &cand, reco::Track *dummyStorage) const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
#define end
Definition: vmac.h:37
edm::ValueMap< reco::IsoDeposit > IsoDepositMap
keep it only as a part of ValueMap
Definition: IsoDepositFwd.h:9
#define LogTrace(id)
virtual std::vector< reco::IsoDeposit > deposits(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const
edm::EDGetTokenT< edm::View< reco::Candidate > > theCandCollectionToken
#define begin
Definition: vmac.h:30
reco::isodeposit::IsoDepositExtractor * theExtractor
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const =0

Member Data Documentation

edm::EDGetTokenT< edm::View<reco::Candidate> > CandIsoDepositProducer::theCandCollectionToken
private

Definition at line 33 of file CandIsoDepositProducer.h.

Referenced by produce().

edm::ParameterSet CandIsoDepositProducer::theConfig
private

Definition at line 32 of file CandIsoDepositProducer.h.

Referenced by CandIsoDepositProducer().

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

Definition at line 35 of file CandIsoDepositProducer.h.

Referenced by CandIsoDepositProducer(), and produce().

reco::isodeposit::IsoDepositExtractor* CandIsoDepositProducer::theExtractor
private
bool CandIsoDepositProducer::theMultipleDepositsFlag
private

Definition at line 36 of file CandIsoDepositProducer.h.

Referenced by CandIsoDepositProducer(), and produce().

TrackType CandIsoDepositProducer::theTrackType
private

Definition at line 34 of file CandIsoDepositProducer.h.

Referenced by CandIsoDepositProducer(), extractTrack(), and produce().