107 const std::vector<T> &
values,
111 if (tp.
isNonnull() && tp->parentVertex().
isNonnull() && !tp->parentVertex()->sourceTracks().empty()) {
112 return tp->parentVertex()->sourceTracks()[0];
134 decayRho_(iConfig.getParameter<double>(
"decayRho")),
135 decayAbsZ_(iConfig.getParameter<double>(
"decayAbsZ")),
146 else throw cms::Exception(
"Configuration") <<
"Track type '" << trackType <<
"' not supported.\n";
151 produces<edm::ValueMap<int> >();
152 produces<edm::ValueMap<int> >(
"ext");
153 produces<edm::ValueMap<int> >(
"flav");
154 produces<edm::ValueMap<int> >(
"hitsPdgId");
155 produces<edm::ValueMap<int> >(
"G4processType");
156 produces<edm::ValueMap<int> >(
"momPdgId");
157 produces<edm::ValueMap<int> >(
"momFlav");
158 produces<edm::ValueMap<int> >(
"momStatus");
159 produces<edm::ValueMap<int> >(
"gmomPdgId");
160 produces<edm::ValueMap<int> >(
"gmomFlav");
161 produces<edm::ValueMap<int> >(
"hmomFlav");
162 produces<edm::ValueMap<int> >(
"tpId");
163 produces<edm::ValueMap<int> >(
"tpEv");
164 produces<edm::ValueMap<int> >(
"tpBx");
165 produces<edm::ValueMap<float> >(
"signp");
166 produces<edm::ValueMap<float> >(
"pt");
167 produces<edm::ValueMap<float> >(
"eta");
168 produces<edm::ValueMap<float> >(
"phi");
169 produces<edm::ValueMap<float> >(
"prodRho");
170 produces<edm::ValueMap<float> >(
"prodZ");
171 produces<edm::ValueMap<float> >(
"momRho");
172 produces<edm::ValueMap<float> >(
"momZ");
173 produces<edm::ValueMap<float> >(
"tpAssoQuality");
175 produces<reco::GenParticleCollection>(
"secondaries");
176 produces<edm::Association<reco::GenParticleCollection> >(
"toPrimaries");
177 produces<edm::Association<reco::GenParticleCollection> >(
"toSecondaries");
205 edm::LogVerbatim(
"MuonMCClassifier") <<
"\n ***************************************************************** ";
207 edm::LogVerbatim(
"MuonMCClassifier") <<
" ***************************************************************** \n";
212 for (
size_t i = 0,
n = muons->size();
i <
n; ++
i) {
219 for (
size_t i = 0,
n = muons->size();
i <
n; ++
i) {
226 for (
size_t i = 0,
n = trackingParticles->size();
i <
n; ++
i) {
236 edm::LogVerbatim(
"MuonMCClassifier") <<
"\n ***************************************************************** ";
237 edm::LogVerbatim(
"MuonMCClassifier") <<
" STANDALONE (UpdAtVtx) MUON association ";
238 edm::LogVerbatim(
"MuonMCClassifier") <<
" ***************************************************************** \n";
243 typedef reco::MuonToSimCollection::const_iterator r2s_it;
244 typedef reco::SimToMuonCollection::const_iterator s2r_it;
246 size_t nmu = muons->size();
247 edm::LogVerbatim(
"MuonMCClassifier") <<
"\n There are "<<nmu<<
" reco::Muons.";
249 std::vector<int> classif(nmu, 0),
ext(nmu, 0);
250 std::vector<int> hitsPdgId(nmu, 0), G4processType(nmu, 0), momPdgId(nmu, 0), gmomPdgId(nmu, 0), momStatus(nmu, 0);
251 std::vector<int> flav(nmu, 0), momFlav(nmu, 0), gmomFlav(nmu, 0), hmomFlav(nmu, 0);
252 std::vector<int> tpId(nmu, -1), tpBx(nmu, 999), tpEv(nmu, 999);
253 std::vector<float> signp(nmu, 0.0),
pt(nmu, 0.0),
eta(nmu, -99.),
phi(nmu, -99.);
254 std::vector<float> prodRho(nmu, 0.0), prodZ(nmu, 0.0), momRho(nmu, 0.0), momZ(nmu, 0.0);
255 std::vector<float> tpAssoQuality(nmu, -1);
257 std::unique_ptr<reco::GenParticleCollection> secondaries;
258 std::map<TrackingParticleRef, int> tpToSecondaries;
259 std::vector<int> muToPrimary(nmu, -1), muToSecondary(nmu, -1);
263 for(
size_t i = 0;
i < nmu; ++
i) {
266 LogTrace(
"MuonMCClassifier") <<
"\n reco::Muon # "<<
i<<
"didn't pass the selection. classified as -99 and skipped";
267 classif[
i] = -99;
continue;
273 r2s_it
match = recSimColl.find(mu);
275 if (match != recSimColl.end()) {
277 tp = match->second.front().first;
279 tpAssoQuality[
i] = match->second.front().second;
280 s2r_it matchback = simRecColl.find(tp);
281 if (matchback != simRecColl.end()) {
282 muMatchBack = matchback->second.front().first;
284 edm::LogWarning(
"MuonMCClassifier") <<
"\n***WARNING: This I do NOT understand: why no match back? *** \n";
289 r2s_it matchSta = UpdSTA_recSimColl.find(mu);
290 if (matchSta != UpdSTA_recSimColl.end()) {
291 tp = matchSta->second.front().first;
293 tpAssoQuality[
i] = matchSta->second.front().second;
294 s2r_it matchback = UpdSTA_simRecColl.find(tp);
295 if (matchback != UpdSTA_simRecColl.end()) {
296 muMatchBack = matchback->second.front().first;
298 edm::LogWarning(
"MuonMCClassifier") <<
"\n***WARNING: This I do NOT understand: why no match back in UpdSTA? *** \n";
302 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t No matching TrackingParticle is found ";
306 bool isGhost = muMatchBack !=
mu;
307 if (isGhost)
edm::LogVerbatim(
"MuonMCClassifier") <<
"\t *** This seems a Duplicate muon ! classif[i] will be < 0 ***";
310 tpBx[
i] = tp->eventId().bunchCrossing();
311 tpEv[
i] = tp->eventId().event();
313 hitsPdgId[
i] = tp->pdgId();
314 prodRho[
i] = tp->vertex().Rho();
315 prodZ[
i] = tp->vertex().Z();
318 const std::vector<SimVertex> & G4Vs = tp->parentVertex()->g4Vertices();
319 G4processType[
i] = G4Vs[0].processType();
321 signp[
i] = tp->charge() * tp->p();
328 if (!tp->genParticles().empty()) {
334 if (genMom->pdgId() != tp->pdgId()) {
335 momPdgId[
i] = genMom->pdgId();
336 momStatus[
i] = genMom->status();
337 momRho[
i] = genMom->vertex().Rho();
338 momZ[
i] = genMom->vz();
343 while (mMom->pdgId() == tp->pdgId()) {
346 if (mMom->numberOfMothers() > 0) {
347 mMom = mMom->motherRef();
350 <<
"\t\t backtracking mother "<<jm<<
", pdgId = "<<mMom->pdgId()<<
", status= " <<mMom->status();
353 momPdgId[
i] = genMom->pdgId();
354 momStatus[
i] = genMom->status();
355 momRho[
i] = genMom->vertex().Rho();
356 momZ[
i] = genMom->vz();
359 <<
"\t Particle pdgId = "<<hitsPdgId[
i] <<
", (Event,Bx) = "<<
"(" <<tpEv[
i]<<
","<<tpBx[
i]<<
")" 360 <<
"\n\t q*p = "<<signp[
i]<<
", pT = "<<
pt[
i]<<
", eta = "<<
eta[
i]<<
", phi = "<<phi[
i]
361 <<
"\n\t produced at vertex rho = " << prodRho[
i] <<
", z = " << prodZ[
i]
362 <<
", (GEANT4 process = "<< G4processType[
i]<<
")" 363 <<
"\n\t has GEN mother pdgId = " << momPdgId[
i] <<
" (status = "<<momStatus[
i] <<
")";
368 gmomPdgId[
i] = genGMom->pdgId();
369 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t\t mother prod. vertex rho = " << momRho[
i] <<
", z = " << momZ[
i]
370 <<
", grand-mom pdgId = " << gmomPdgId[
i];
376 int flav =
flavour(nMom->pdgId());
377 if (hmomFlav[
i] < flav) hmomFlav[
i] = flav;
379 <<
"\t\t backtracking flavour: mom pdgId = "<<nMom->pdgId()
380 <<
", flavour = " << flav <<
", heaviest so far = " << hmomFlav[
i];
386 <<
"\t GenParticle with pdgId = "<<hitsPdgId[
i] <<
", (Event,Bx) = "<<
"(" <<tpEv[
i]<<
","<<tpBx[
i]<<
")" 387 <<
"\n\t q*p = "<<signp[
i]<<
", pT = "<<
pt[
i]<<
", eta = "<<
eta[
i]<<
", phi = "<<phi[
i]
388 <<
"\n\t produced at vertex rho = " << prodRho[
i] <<
", z = " << prodZ[
i]
389 <<
", (GEANT4 process = "<< G4processType[
i]<<
")" 390 <<
"\n\t has NO mother!";
396 momPdgId[
i] = simMom->pdgId();
397 momRho[
i] = simMom->vertex().Rho();
398 momZ[
i] = simMom->vertex().Z();
400 <<
"\t Particle pdgId = "<<hitsPdgId[
i] <<
", (Event,Bx) = "<<
"(" <<tpEv[
i]<<
","<<tpBx[
i]<<
")" 401 <<
"\n\t q*p = "<<signp[
i]<<
", pT = "<<
pt[
i]<<
", eta = "<<
eta[
i]<<
", phi = "<<phi[
i]
402 <<
"\n\t produced at vertex rho = " << prodRho[
i] <<
", z = " << prodZ[
i]
403 <<
", (GEANT4 process = "<< G4processType[
i]<<
")" 404 <<
"\n\t has SIM mother pdgId = " << momPdgId[
i]
405 <<
" produced at rho = " << simMom->vertex().Rho() <<
", z = " << simMom->vertex().Z();
407 if (!simMom->genParticles().empty()) {
408 momStatus[
i] = simMom->genParticles()[0]->status();
410 if (genGMom.
isNonnull()) gmomPdgId[
i] = genGMom->pdgId();
412 <<
"\t\t SIM mother is in GEN (status " << momStatus[
i] <<
"), grand-mom id = " << gmomPdgId[
i];
417 if (simGMom.
isNonnull()) gmomPdgId[
i] = simGMom->pdgId();
418 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t\t SIM mother is in SIM only, grand-mom id = " << gmomPdgId[
i];
422 <<
"\t Particle pdgId = "<<hitsPdgId[
i] <<
", (Event,Bx) = "<<
"(" <<tpEv[
i]<<
","<<tpBx[
i]<<
")" 423 <<
"\n\t q*p = "<<signp[
i]<<
", pT = "<<
pt[
i]<<
", eta = "<<
eta[
i]<<
", phi = "<<phi[
i]
424 <<
"\n\t produced at vertex rho = " << prodRho[
i] <<
", z = " << prodZ[
i]
425 <<
", (GEANT4 process = "<< G4processType[
i]<<
")" 426 <<
"\n\t has NO mother!";
430 gmomFlav[
i] =
flavour(gmomPdgId[i]);
433 if (
abs(tp->pdgId()) != 13) {
434 if (
abs(tp->pdgId()) == 11) {
435 classif[
i] = isGhost ? -11 : 11;
436 ext[
i] = isGhost ? -11 : 11;
437 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t This is electron/positron. classif[i] = " << classif[
i];
440 classif[
i] = isGhost ? -1 : 1;
441 ext[
i] = isGhost ? -1 : 1;
442 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t This is not a muon. Sorry. classif[i] = " << classif[
i];
449 if (!tp->genParticles().empty() && (momPdgId[
i] != 0)) {
450 if (
abs(momPdgId[i]) < 100 && (
abs(momPdgId[i]) != 15)) {
451 classif[
i] = isGhost ? -4 : 4;
454 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t This seems PRIMARY MUON ! classif[i] = " << classif[
i];
455 }
else if (momFlav[i] == 4 || momFlav[i] == 5 || momFlav[i] == 15) {
456 classif[
i] = isGhost ? -3 : 3;
457 flav[
i] = momFlav[
i];
458 if (momFlav[i] == 15) ext[
i] = 9;
459 else if (momFlav[i] == 5) ext[
i] = 8;
460 else if (hmomFlav[i] == 5) ext[
i] = 7;
462 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t This seems HEAVY FLAVOUR ! classif[i] = " << classif[
i];
464 classif[
i] = isGhost ? -2 : 2;
465 flav[
i] = momFlav[
i];
466 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t This seems LIGHT FLAVOUR ! classif[i] = " << classif[
i];
469 classif[
i] = isGhost ? -2 : 2;
470 flav[
i] = momFlav[
i];
471 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t This seems LIGHT FLAVOUR ! classif[i] = " << classif[
i];
474 if (momPdgId[i] == 0) ext[
i] = 2;
475 else if (
abs(momPdgId[i]) < 100) ext[
i] = (momFlav[
i] == 15 ? 9 : 10);
476 else if (momFlav[i] == 5) ext[
i] = 8;
477 else if (momFlav[i] == 4) ext[
i] = (hmomFlav[
i] == 5 ? 7 : 6);
478 else if (momStatus[i] != -1) {
480 if (
id != 211 &&
id != 321 &&
id != 130 ) ext[
i] = 5;
484 if (isGhost) ext[
i] = -ext[
i];
488 if (!tp->genParticles().empty() &&
std::abs(ext[i]) >= 5) {
489 if (genParticles.
id() != tp->genParticles().
id()) {
490 throw cms::Exception(
"Configuration") <<
"Product ID mismatch between the genParticle collection (" <<
genParticles_ <<
", id " << genParticles.
id() <<
") and the references in the TrackingParticles (id " << tp->genParticles().
id() <<
")\n";
492 muToPrimary[
i] = tp->genParticles()[0].
key();
495 int &indexPlus1 = tpToSecondaries[tp];
497 muToSecondary[
i] = indexPlus1 - 1;
500 edm::LogVerbatim(
"MuonMCClassifier") <<
"\t Extended classification code = " << ext[
i];
511 writeValueMap(iEvent, muons, G4processType,
"G4processType");
526 writeValueMap(iEvent, muons, tpAssoQuality,
"tpAssoQuality");
535 fillPri.insert(muons, muToPrimary.begin(), muToPrimary.end());
536 fillSec.
insert(muons, muToSecondary.begin(), muToSecondary.end());
537 fillPri.fill(); fillSec.
fill();
548 const std::vector<T> &
values,
553 unique_ptr<ValueMap<T> > valMap(
new ValueMap<T>());
565 if (flav <= 37 && flav != 21)
return flav;
567 int bflav = ((flav / 1000) % 10);
568 if (bflav != 0)
return bflav;
570 int mflav = ((flav / 100) % 10);
571 if (mflav != 0)
return mflav;
582 if (simMom.
isNonnull() && !simMom->genParticles().empty()) {
583 if (genParticles.
id() != simMom->genParticles().
id()) {
584 throw cms::Exception(
"Configuration") <<
"Product ID mismatch between the genParticle collection (" <<
genParticles_ <<
", id " << genParticles.
id() <<
") and the references in the TrackingParticles (id " << simMom->genParticles().
id() <<
")\n";
586 out.back().addMother(simMom->genParticles()[0]);
edm::InputTag genParticles_
bool linkToGenParticles_
Create a link to the generator level particles.
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
int pdgId() const
PDG ID.
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
void insert(const H &h, I begin, I end)
const_iterator end() const
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.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
int status() const
Status word.
ProductID id() const
Accessor for product ID.
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
reco::MuonTrackType trackType_
Track to use.
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
~MuonMCClassifier() override
float charge() const
Electric charge. Note this is taken from the first SimTrack only.
#define DEFINE_FWK_MODULE(type)
bool isGlobalMuon() const override
void associateMuons(MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &muons, MuonTrackType type, const edm::RefVector< TrackingParticleCollection > &tpColl) const
Abs< T >::type abs(const T &t)
TrackingParticleRef getTpMother(TrackingParticleRef tp)
MuonMCClassifier(const edm::ParameterSet &)
edm::InputTag associatorLabel_
The Associations.
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
T const * product() const
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.
edm::EDGetTokenT< reco::MuonToTrackingParticleAssociator > muAssocToken_
const_iterator begin() const
Point vertex() const
Parent vertex position.
double decayRho_
Cylinder to use to decide if a decay is early or late.
edm::EDGetTokenT< edm::View< reco::Muon > > muonsToken_
The RECO objects.
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.
int flavour(int pdgId) const
Returns the flavour given a pdg id code.
void produce(edm::Event &, const edm::EventSetup &) override
Analysis-level muon class.
edm::Ref< TrackingParticleCollection > TrackingParticleRef
edm::EDGetTokenT< TrackingParticleCollection > trackingParticlesToken_
The TrackingParticle objects.
StringCutObjectSelector< pat::Muon > muonCut_