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 =
105  associatorByHits->associateRecoToSim(trackCollection, TPCollection, &event, &setup);
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 =
115  associatorByHits->associateSimToReco(trackCollection, TPCollection, &event, &setup);
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 }
T getParameter(std::string const &) const
edm::EDGetTokenT< TrackingParticleCollection > tpToken_
MuonAssociatorEDProducer(const edm::ParameterSet &)
std::string dump(unsigned int indent=0) const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
void produce(edm::Event &, const edm::EventSetup &) override
MuonAssociatorByHits * associatorByHits
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:125
#define LogTrace(id)
reco::RecoToSimCollection associateRecoToSim(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
std::string const & label() const
Definition: InputTag.h:36
edm::EDGetTokenT< edm::View< reco::Track > > tracksToken_
HLT enums.
virtual reco::SimToRecoCollection associateSimToReco(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
#define str(s)
std::string const & instance() const
Definition: InputTag.h:37
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1