102 template <
typename T>
105 const std::vector<T> &
values,
109 if (tp.
isNonnull() && tp->parentVertex().
isNonnull() && !tp->parentVertex()->sourceTracks().empty()) {
110 return tp->parentVertex()->sourceTracks()[0];
130 consumes<
reco::MuonToTrackingParticleAssociator>(iConfig.getParameter<
edm::InputTag>(
"associatorLabel"))),
131 decayRho_(iConfig.getParameter<double>(
"decayRho")),
132 decayAbsZ_(iConfig.getParameter<double>(
"decayAbsZ")),
138 if (trackType ==
"inner")
140 else if (trackType ==
"outer")
142 else if (trackType ==
"global")
144 else if (trackType ==
"segments")
146 else if (trackType ==
"glb_or_trk")
149 throw cms::Exception(
"Configuration") <<
"Track type '" << trackType <<
"' not supported.\n";
154 produces<edm::ValueMap<reco::MuonSimInfo>>();
156 produces<reco::GenParticleCollection>(
"secondaries");
157 produces<edm::Association<reco::GenParticleCollection>>(
"toPrimaries");
158 produces<edm::Association<reco::GenParticleCollection>>(
"toSecondaries");
166 LogTrace(
"MuonSimClassifier") <<
"\t Particle pdgId = " << simInfo.
pdgId <<
", (Event,Bx) = " 167 <<
"(" << simInfo.
tpEvent <<
"," << simInfo.
tpBX <<
")" 168 <<
"\n\t q*p = " << simInfo.
charge * simInfo.
p4.P() <<
", pT = " << simInfo.
p4.pt()
169 <<
", eta = " << simInfo.
p4.eta() <<
", phi = " << simInfo.
p4.phi()
170 <<
"\n\t produced at vertex rho = " << simInfo.
vertex.Rho()
193 LogTrace(
"MuonSimClassifier") <<
"\n " 194 "***************************************************************** ";
196 LogTrace(
"MuonSimClassifier") <<
" ******************************************" 197 "*********************** \n";
200 for (
size_t i = 0,
n = muons->size();
i <
n; ++
i) {
205 for (
size_t i = 0, n = trackingParticles->size();
i <
n; ++
i) {
216 LogTrace(
"MuonSimClassifier") <<
"\n " 217 "***************************************************************** ";
218 LogTrace(
"MuonSimClassifier") <<
" STANDALONE (UpdAtVtx) MUON association ";
219 LogTrace(
"MuonSimClassifier") <<
" ****************************************" 220 "************************* \n";
224 typedef reco::MuonToSimCollection::const_iterator r2s_it;
225 typedef reco::SimToMuonCollection::const_iterator s2r_it;
227 size_t nmu = muons->size();
228 LogTrace(
"MuonSimClassifier") <<
"\n There are " << nmu <<
" reco::Muons.";
230 std::vector<reco::MuonSimInfo> simInfo;
232 std::unique_ptr<reco::GenParticleCollection> secondaries;
233 std::map<TrackingParticleRef, int> tpToSecondaries;
234 std::vector<int> muToPrimary(nmu, -1), muToSecondary(nmu,
240 for (
size_t i = 0;
i < nmu; ++
i) {
242 LogTrace(
"MuonSimClassifier") <<
"\n reco::Muon # " <<
i;
246 r2s_it
match = recSimColl.find(allMuons.
at(
i));
248 if (match != recSimColl.end()) {
251 tp = match->second.front().first;
253 simInfo[
i].tpAssoQuality = match->second.front().second;
254 s2r_it matchback = simRecColl.find(tp);
255 if (matchback != simRecColl.end()) {
256 muMatchBack = matchback->second.front().first;
258 LogTrace(
"MuonSimClassifier") <<
"\n***WARNING: This I do NOT understand: why no match back? " 264 r2s_it matchSta = updSTA_recSimColl.find(allMuons.
at(
i));
265 if (matchSta != updSTA_recSimColl.end()) {
266 tp = matchSta->second.front().first;
269 simInfo[
i].tpAssoQuality = matchSta->second.front().second;
270 s2r_it matchback = updSTA_simRecColl.find(tp);
271 if (matchback != updSTA_simRecColl.end()) {
272 muMatchBack = matchback->second.front().first;
274 LogTrace(
"MuonSimClassifier") <<
"\n***WARNING: This I do NOT understand: why no match back " 279 LogTrace(
"MuonSimClassifier") <<
"\t No matching TrackingParticle is found ";
284 bool isGhost = muMatchBack != allMuons.
at(
i);
286 LogTrace(
"MuonSimClassifier") <<
"\t *** This seems a Duplicate muon ! " 287 "classif[i] will be < 0 ***";
290 simInfo[
i].tpBX = tp->eventId().bunchCrossing();
291 simInfo[
i].tpEvent = tp->eventId().event();
293 simInfo[
i].pdgId = tp->pdgId();
294 simInfo[
i].vertex = tp->vertex();
297 const std::vector<SimVertex> &g4Vs = tp->parentVertex()->g4Vertices();
298 simInfo[
i].g4processType = g4Vs[0].processType();
300 simInfo[
i].charge = tp->charge();
301 simInfo[
i].p4 = tp->p4();
305 if (!tp->genParticles().empty()) {
311 if (genMom->pdgId() != tp->pdgId()) {
312 simInfo[
i].motherPdgId = genMom->pdgId();
313 simInfo[
i].motherStatus = genMom->status();
314 simInfo[
i].motherVertex = genMom->vertex();
319 while (mMom->pdgId() == tp->pdgId()) {
321 if (mMom->numberOfMothers() > 0) {
322 mMom = mMom->motherRef();
324 LogTrace(
"MuonSimClassifier") <<
"\t\t backtracking mother " << jm <<
", pdgId = " << mMom->pdgId()
325 <<
", status= " << mMom->status();
328 simInfo[
i].motherPdgId = genMom->pdgId();
329 simInfo[
i].motherStatus = genMom->status();
330 simInfo[
i].motherVertex = genMom->vertex();
333 LogTrace(
"MuonSimClassifier") <<
"\t has GEN mother pdgId = " << simInfo[
i].motherPdgId
334 <<
" (status = " << simInfo[
i].motherStatus <<
")";
339 simInfo[
i].grandMotherPdgId = genGMom->pdgId();
341 <<
"\t\t mother prod. vertex rho = " << simInfo[
i].motherVertex.Rho()
342 <<
", z = " << simInfo[
i].motherVertex.Z() <<
", grand-mom pdgId = " << simInfo[
i].grandMotherPdgId;
349 int flav =
flavour(nMom->pdgId());
350 if (simInfo[i].heaviestMotherFlavour < flav)
351 simInfo[
i].heaviestMotherFlavour = flav;
353 <<
"\t\t backtracking flavour: mom pdgId = " << nMom->pdgId() <<
", flavour = " << flav
354 <<
", heaviest so far = " << simInfo[
i].heaviestMotherFlavour;
358 LogTrace(
"MuonSimClassifier") <<
"\t has NO mother!";
363 simInfo[
i].motherPdgId = simMom->pdgId();
364 simInfo[
i].motherVertex = simMom->vertex();
366 LogTrace(
"MuonSimClassifier") <<
"\t has SIM mother pdgId = " << simInfo[
i].motherPdgId
367 <<
" produced at rho = " << simMom->vertex().Rho()
368 <<
", z = " << simMom->vertex().Z();
370 if (!simMom->genParticles().empty()) {
371 simInfo[
i].motherStatus = simMom->genParticles()[0]->status();
373 (simMom->genParticles()[0]->numberOfMothers() > 0 ? simMom->genParticles()[0]->motherRef()
376 simInfo[i].grandMotherPdgId = genGMom->pdgId();
377 LogTrace(
"MuonSimClassifier") <<
"\t\t SIM mother is in GEN (status " << simInfo[
i].motherStatus
378 <<
"), grand-mom id = " << simInfo[
i].grandMotherPdgId;
380 simInfo[
i].motherStatus = -1;
383 simInfo[i].grandMotherPdgId = simGMom->pdgId();
385 <<
"\t\t SIM mother is in SIM only, grand-mom id = " << simInfo[
i].grandMotherPdgId;
389 LogTrace(
"MuonSimClassifier") <<
"\t has NO mother!";
392 simInfo[
i].motherFlavour =
flavour(simInfo[
i].motherPdgId);
393 simInfo[
i].grandMotherFlavour =
flavour(simInfo[
i].grandMotherPdgId);
399 simInfo[
i].extendedClass =
401 LogTrace(
"MuonSimClassifier") <<
"\t This is electron/positron. classif[i] = " << simInfo[
i].primaryClass;
403 simInfo[
i].primaryClass =
407 LogTrace(
"MuonSimClassifier") <<
"\t This is not a muon. Sorry. classif[i] = " << simInfo[
i].primaryClass;
413 if (!tp->genParticles().empty() && (simInfo[
i].motherPdgId != 0)) {
414 if (
std::abs(simInfo[
i].motherPdgId) < 100 && (
std::abs(simInfo[
i].motherPdgId) != 15)) {
415 simInfo[
i].primaryClass =
417 simInfo[
i].flavour = 13;
420 LogTrace(
"MuonSimClassifier") <<
"\t This seems PRIMARY MUON ! classif[i] = " << simInfo[
i].primaryClass;
421 }
else if (simInfo[
i].motherFlavour == 4 || simInfo[
i].motherFlavour == 5 || simInfo[
i].motherFlavour == 15) {
422 simInfo[
i].primaryClass =
424 simInfo[
i].flavour = simInfo[
i].motherFlavour;
425 if (simInfo[
i].motherFlavour == 15)
426 simInfo[
i].extendedClass =
428 else if (simInfo[
i].motherFlavour == 5)
429 simInfo[
i].extendedClass =
431 else if (simInfo[
i].heaviestMotherFlavour == 5)
432 simInfo[
i].extendedClass =
435 simInfo[
i].extendedClass =
437 LogTrace(
"MuonSimClassifier") <<
"\t This seems HEAVY FLAVOUR ! classif[i] = " << simInfo[
i].primaryClass;
439 simInfo[
i].primaryClass =
441 simInfo[
i].flavour = simInfo[
i].motherFlavour;
442 LogTrace(
"MuonSimClassifier") <<
"\t This seems LIGHT FLAVOUR ! classif[i] = " << simInfo[
i].primaryClass;
445 simInfo[
i].primaryClass =
447 simInfo[
i].flavour = simInfo[
i].motherFlavour;
448 LogTrace(
"MuonSimClassifier") <<
"\t This seems LIGHT FLAVOUR ! classif[i] = " << simInfo[
i].primaryClass;
453 if (simInfo[
i].motherPdgId == 0)
457 else if (
std::abs(simInfo[
i].motherPdgId) < 100) {
458 if (simInfo[
i].motherFlavour == 15)
459 simInfo[
i].extendedClass =
464 }
else if (simInfo[
i].motherFlavour == 5)
465 simInfo[
i].extendedClass =
467 else if (simInfo[
i].motherFlavour == 4) {
468 if (simInfo[
i].heaviestMotherFlavour == 5)
469 simInfo[
i].extendedClass =
472 simInfo[
i].extendedClass =
474 }
else if (simInfo[
i].motherStatus != -1) {
475 int id =
std::abs(simInfo[
i].motherPdgId);
476 if (
id != 211 &&
id != 321 &&
id != 130 )
496 if (!tp->genParticles().empty() &&
std::abs(simInfo[
i].extendedClass) >= 5) {
497 if (genParticles.
id() != tp->genParticles().
id()) {
499 <<
"Product ID mismatch between the genParticle collection (" <<
genParticles_ <<
", id " 500 << genParticles.
id() <<
") and the references in the TrackingParticles (id " << tp->genParticles().
id()
503 muToPrimary[
i] = tp->genParticles()[0].
key();
506 int &indexPlus1 = tpToSecondaries[tp];
510 muToSecondary[
i] = indexPlus1 - 1;
513 LogTrace(
"MuonSimClassifier") <<
"\t Extended classification code = " << simInfo[
i].extendedClass;
526 std::unique_ptr<edm::Association<reco::GenParticleCollection>> outPri(
528 std::unique_ptr<edm::Association<reco::GenParticleCollection>> outSec(
531 fillPri.insert(muons, muToPrimary.begin(), muToPrimary.end());
532 fillSec.
insert(muons, muToSecondary.begin(), muToSecondary.end());
540 template <
typename T>
543 const std::vector<T> &
values,
558 if (flav <= 37 && flav != 21)
561 int bflav = ((flav / 1000) % 10);
565 int mflav = ((flav / 100) % 10);
578 if (simMom.
isNonnull() && !simMom->genParticles().empty()) {
579 if (genParticles.
id() != simMom->genParticles().
id()) {
581 <<
"Product ID mismatch between the genParticle collection (" <<
genParticles_ <<
", id " << genParticles.
id()
582 <<
") and the references in the TrackingParticles (id " << simMom->genParticles().
id() <<
")\n";
584 out.back().addMother(simMom->genParticles()[0]);
586 return out.size() - 1;
const LorentzVector & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool isNonnull() const
Checks for non-null.
std::vector< TrackingParticle > TrackingParticleCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
TrackingParticleRef getTpMother(TrackingParticleRef tp)
edm::EDGetTokenT< edm::View< reco::Muon > > muonsToken_
The RECO objects.
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::Muon >> &handle, const std::vector< T > &values, const std::string &label) const
Write a ValueMap<int> in the event.
void produce(edm::Event &, const edm::EventSetup &) override
int pdgId() const
PDG ID.
reco::MuonTrackType trackType_
Track to use.
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
void insert(const H &h, I begin, I end)
int flavour(int pdgId) const
Returns the flavour given a pdg id code.
int convertAndPush(const TrackingParticle &tp, reco::GenParticleCollection &out, const TrackingParticleRef &momRef, const edm::Handle< reco::GenParticleCollection > &genParticles) const
key_type key() const
Accessor for product key.
value_type at(size_type idx) const
int status() const
Status word.
ProductID id() const
Accessor for product ID.
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
float charge() const
Electric charge. Note this is taken from the first SimTrack only.
edm::InputTag genParticles_
#define DEFINE_FWK_MODULE(type)
void associateMuons(MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &muons, MuonTrackType type, const edm::RefVector< TrackingParticleCollection > &tpColl) const
MuonSimClassifier(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
edm::EDGetTokenT< reco::MuonToTrackingParticleAssociator > muAssocToken_
T const * product() const
edm::EDGetTokenT< TrackingParticleCollection > trackingParticlesToken_
The TrackingParticle objects.
void dumpFormatedInfo(const reco::MuonSimInfo &simInfo)
edm::InputTag associatorLabel_
The Associations.
Point vertex() const
Parent vertex position.
double decayRho_
Cylinder to use to decide if a decay is early or late.
void push_back(const RefToBase< T > &)
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Monte Carlo truth information used for tracking validation.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
bool linkToGenParticles_
Create a link to the generator level particles.
edm::Ref< TrackingParticleCollection > TrackingParticleRef
~MuonSimClassifier() override