CMS 3D CMS Logo

MuonAssociatorEDProducer.cc
Go to the documentation of this file.
5 #include <memory>
6 
8  : tracksTag(parset.getParameter<edm::InputTag>("tracksTag")),
9  tpTag(parset.getParameter<edm::InputTag>("tpTag")),
10  ignoreMissingTrackCollection(parset.getUntrackedParameter<bool>("ignoreMissingTrackCollection", false)),
11  parset_(parset) {
12  edm::LogVerbatim("MuonAssociatorEDProducer") << "constructing MuonAssociatorEDProducer";
13  produces<reco::RecoToSimCollection>();
14  produces<reco::SimToRecoCollection>();
15  tpToken_ = consumes<TrackingParticleCollection>(tpTag);
16  tracksToken_ = consumes<edm::View<reco::Track>>(tracksTag);
17 
19  LogTrace("MuonAssociatorEDProducer") << "constructing MuonAssociatorByHits" << parset_.dump();
20  edm::LogVerbatim("MuonAssociatorEDProducer") << "\n MuonAssociatorByHits will associate reco::Tracks with "
21  << tracksTag << "\n\t\t and TrackingParticles with " << tpTag;
22  const std::string recoTracksLabel = tracksTag.label();
23  const std::string recoTracksInstance = tracksTag.instance();
24 
25  // check and fix inconsistent input settings
26  // tracks with hits only on muon detectors
27  if (recoTracksLabel == "standAloneMuons" || recoTracksLabel == "standAloneSETMuons" ||
28  recoTracksLabel == "cosmicMuons" || recoTracksLabel == "hltL2Muons") {
29  if (parset_.getParameter<bool>("UseTracker")) {
30  edm::LogWarning("MuonAssociatorEDProducer")
31  << "\n*** WARNING : inconsistent input tracksTag = " << tracksTag << "\n with UseTracker = true"
32  << "\n ---> setting UseTracker = false ";
33  parset_.addParameter<bool>("UseTracker", false);
34  }
35  if (!parset_.getParameter<bool>("UseMuon")) {
36  edm::LogWarning("MuonAssociatorEDProducer")
37  << "\n*** WARNING : inconsistent input tracksTag = " << tracksTag << "\n with UseMuon = false"
38  << "\n ---> setting UseMuon = true ";
39  parset_.addParameter<bool>("UseMuon", true);
40  }
41  }
42  // tracks with hits only on tracker
43  if (recoTracksLabel == "generalTracks" || recoTracksLabel == "ctfWithMaterialTracksP5LHCNavigation" ||
44  recoTracksLabel == "hltL3TkTracksFromL2" ||
45  (recoTracksLabel == "hltL3Muons" && recoTracksInstance == "L2Seeded")) {
46  if (parset_.getParameter<bool>("UseMuon")) {
47  edm::LogWarning("MuonAssociatorEDProducer")
48  << "\n*** WARNING : inconsistent input tracksTag = " << tracksTag << "\n with UseMuon = true"
49  << "\n ---> setting UseMuon = false ";
50  parset_.addParameter<bool>("UseMuon", false);
51  }
52  if (!parset_.getParameter<bool>("UseTracker")) {
53  edm::LogWarning("MuonAssociatorEDProducer")
54  << "\n*** WARNING : inconsistent input tracksTag = " << tracksTag << "\n with UseTracker = false"
55  << "\n ---> setting UseTracker = true ";
56  parset_.addParameter<bool>("UseTracker", true);
57  }
58  }
59 
60  LogTrace("MuonAssociatorEDProducer") << "MuonAssociatorEDProducer::beginJob "
61  ": constructing MuonAssociatorByHits";
62  associatorByHits = new MuonAssociatorByHits(parset_, consumesCollector());
63 }
64 
66 
68 
70 
72  using namespace edm;
73 
75  LogTrace("MuonAssociatorEDProducer") << "getting TrackingParticle collection - " << tpTag;
76  event.getByToken(tpToken_, TPCollection);
77  LogTrace("MuonAssociatorEDProducer") << "\t... size = " << TPCollection->size();
78 
80  LogTrace("MuonAssociatorEDProducer") << "getting reco::Track collection - " << tracksTag;
81  bool trackAvailable = event.getByToken(tracksToken_, trackCollection);
82  if (trackAvailable)
83  LogTrace("MuonAssociatorEDProducer") << "\t... size = " << trackCollection->size();
84  else
85  LogTrace("MuonAssociatorEDProducer") << "\t... NOT FOUND.";
86 
87  std::unique_ptr<reco::RecoToSimCollection> rts;
88  std::unique_ptr<reco::SimToRecoCollection> str;
89 
90  if (ignoreMissingTrackCollection && !trackAvailable) {
91  // the track collection is not in the event and we're being told to ignore
92  // this. do not output anything to the event, other wise this would be
93  // considered as inefficiency.
94  LogTrace("MuonAssociatorEDProducer") << "\n ignoring missing track collection."
95  << "\n";
96  } else {
97  edm::LogVerbatim("MuonAssociatorEDProducer")
98  << "\n >>> RecoToSim association <<< \n"
99  << " Track collection : " << tracksTag.label() << ":" << tracksTag.instance()
100  << " (size = " << trackCollection->size() << ") \n"
101  << " TrackingParticle collection : " << tpTag.label() << ":" << tpTag.instance()
102  << " (size = " << TPCollection->size() << ")";
103 
104  reco::RecoToSimCollection recSimColl =
106 
107  edm::LogVerbatim("MuonAssociatorEDProducer")
108  << "\n >>> SimToReco association <<< \n"
109  << " TrackingParticle collection : " << tpTag.label() << ":" << tpTag.instance()
110  << " (size = " << TPCollection->size() << ") \n"
111  << " Track collection : " << tracksTag.label() << ":" << tracksTag.instance()
112  << " (size = " << trackCollection->size() << ")";
113 
114  reco::SimToRecoCollection simRecColl =
116 
117  rts.reset(new reco::RecoToSimCollection(recSimColl));
118  str.reset(new reco::SimToRecoCollection(simRecColl));
119 
120  event.put(std::move(rts));
121  event.put(std::move(str));
122  }
123 }
gather_cfg.tracksTag
tracksTag
Definition: gather_cfg.py:244
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
MuonAssociatorEDProducer::tpToken_
edm::EDGetTokenT< TrackingParticleCollection > tpToken_
Definition: MuonAssociatorEDProducer.h:25
edm::InputTag::instance
std::string const & instance() const
Definition: InputTag.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
MuonAssociatorEDProducer.h
TrackAssociation.h
MuonAssociatorEDProducer::tpTag
edm::InputTag tpTag
Definition: MuonAssociatorEDProducer.h:24
edm::Handle< TrackingParticleCollection >
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
MuonAssociatorEDProducer::tracksToken_
edm::EDGetTokenT< edm::View< reco::Track > > tracksToken_
Definition: MuonAssociatorEDProducer.h:26
MuonAssociatorByHits_cfi.tpTag
tpTag
Definition: MuonAssociatorByHits_cfi.py:152
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
edm::ParameterSet::dump
std::string dump(unsigned int indent=0) const
Definition: ParameterSet.cc:825
MuonAssociatorByHits_cfi.ignoreMissingTrackCollection
ignoreMissingTrackCollection
Definition: MuonAssociatorByHits_cfi.py:153
str
#define str(s)
Definition: TestProcessor.cc:48
MuonAssociatorByHits::associateRecoToSim
reco::RecoToSimCollection associateRecoToSim(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
Definition: MuonAssociatorByHits.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
MuonAssociatorEDProducer::parset_
edm::ParameterSet parset_
Definition: MuonAssociatorEDProducer.h:29
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
MuonAssociatorByHits
Definition: MuonAssociatorByHits.h:25
duplicaterechits_cfi.trackCollection
trackCollection
Definition: duplicaterechits_cfi.py:4
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
MuonAssociatorEDProducer::tracksTag
edm::InputTag tracksTag
Definition: MuonAssociatorEDProducer.h:23
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:124
MuonAssociatorEDProducer::ignoreMissingTrackCollection
bool ignoreMissingTrackCollection
Definition: MuonAssociatorEDProducer.h:28
edm::LogVerbatim
Definition: MessageLogger.h:297
MuonAssociatorByHits::associateSimToReco
virtual reco::SimToRecoCollection associateSimToReco(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
Definition: MuonAssociatorByHits.h:47
edm::EventSetup
Definition: EventSetup.h:57
MuonAssociatorEDProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonAssociatorEDProducer.cc:71
MuonAssociatorEDProducer::~MuonAssociatorEDProducer
~MuonAssociatorEDProducer() override
Definition: MuonAssociatorEDProducer.cc:65
MuonAssociatorEDProducer::endJob
virtual void endJob()
Definition: MuonAssociatorEDProducer.cc:69
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
MuonAssociatorEDProducer::associatorByHits
MuonAssociatorByHits * associatorByHits
Definition: MuonAssociatorEDProducer.h:30
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
event
Definition: event.py:1
MuonAssociatorEDProducer::beginJob
virtual void beginJob()
Definition: MuonAssociatorEDProducer.cc:67
edm::Event
Definition: Event.h:73
MuonAssociatorEDProducer::MuonAssociatorEDProducer
MuonAssociatorEDProducer(const edm::ParameterSet &)
Definition: MuonAssociatorEDProducer.cc:7