test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CandIsoDepositProducer.cc
Go to the documentation of this file.
2 
3 // Framework
9 
11 
15 
16 
20 
23 
25 #include <string>
26 
27 using namespace edm;
28 using namespace reco;
29 using namespace muonisolation;
30 
31 
34  theConfig(par),
35  theCandCollectionToken(consumes< edm::View<reco::Candidate> >(par.getParameter<edm::InputTag>("src"))),
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 }
66 
69  LogDebug("PhysicsTools/CandIsoDepositProducer")<<" CandIsoDepositProducer DTOR";
70  delete theExtractor;
71 }
72 
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 }
94 
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 
106  if (nDeps >MAX_DEPS ) LogError(metname)<<"Unable to handle more than 10 input deposits";
107 
111  size_t nMuons = hCands->size();
112  std::vector<std::vector<IsoDeposit> > deps2D(nDeps, std::vector<IsoDeposit>(nMuons));
113 
114  if (nMuons > 0){
115  theExtractor->initEvent(event, eventSetup);
116 
117  Track dummy;
118  for (size_t i=0; i< nMuons; ++i) {
119  const Candidate &c = (*hCands)[i];
120  const Track *track = extractTrack(c, &dummy);
121  if ((theTrackType != CandidateT) && (!track)) {
122  edm::LogWarning("CandIsoDepositProducer") << "Candidate #"<<i<<" has no bestTrack(), it will produce no deposit";
123  reco::IsoDeposit emptyDep;
124  for (size_t iDep=0;iDep<nDeps;++iDep) {
125  deps2D[iDep][i] = emptyDep;
126  }
127  continue;
128  }
130  deps2D[0][i] = ( ( theTrackType == CandidateT )
131  ? theExtractor->deposit(event, eventSetup, c)
132  : theExtractor->deposit(event, eventSetup, *track) );
133  } else {
134  std::vector<IsoDeposit> deps = ( ( theTrackType == CandidateT )
135  ? theExtractor->deposits(event, eventSetup, c)
136  : theExtractor->deposits(event, eventSetup, *track) );
137  for (unsigned int iDep=0; iDep < nDeps; ++iDep){ deps2D[iDep][i] = deps[iDep]; }
138  }
139  }
140  }//if (nMuons>0)
141 
143  for (unsigned int iDep=0; iDep < nDeps; ++iDep){
145  for (unsigned int iMu = 0; iMu< nMuons; ++iMu){
146  LogTrace(metname)<<"Contents of "<<theDepositNames[iDep]
147  <<" for a muon at index "<<iMu;
148  LogTrace(metname)<<deps2D[iDep][iMu].print();
149  }
150 
152  std::unique_ptr<reco::IsoDepositMap> depMap(new reco::IsoDepositMap());
153  reco::IsoDepositMap::Filler filler(*depMap);
154  filler.insert(hCands, deps2D[iDep].begin(), deps2D[iDep].end());
155  deps2D[iDep].clear();
156  filler.fill();
157  event.put(std::move(depMap), theDepositNames[iDep]);
158  }
159 
160 }
161 
#define LogDebug(id)
virtual reco::GsfTrackRef gsfTrack() const
reference to a GsfTrack
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &, const edm::EventSetup &)
build deposits
virtual ~CandIsoDepositProducer()
destructor
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
std::vector< std::string > theDepositNames
const reco::Track * extractTrack(const reco::Candidate &cand, reco::Track *dummyStorage) const
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track
virtual void initEvent(const edm::Event &, const edm::EventSetup &)
perform some constly initialization
virtual reco::TrackRef track() const
reference to a Track
virtual Vector momentum() const =0
spatial momentum vector
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
def move
Definition: eostools.py:510
virtual const Point & vertex() const =0
vertex position
virtual int charge() const =0
electric charge
#define end
Definition: vmac.h:37
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:244
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)
CandIsoDepositProducer(const edm::ParameterSet &)
constructor with config
tuple deps
Definition: symbols.py:54
virtual std::vector< reco::IsoDeposit > deposits(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const
virtual const Track * bestTrack() const
best track pointer
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
T get(const Candidate &c)
Definition: component.h:55
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track