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  tpRefVector(parset.getParameter<bool>("tpRefVector")),
11  ignoreMissingTrackCollection(parset.getUntrackedParameter<bool>("ignoreMissingTrackCollection", false)),
12  parset_(parset) {
13  edm::LogVerbatim("MuonAssociatorEDProducer") << "constructing MuonAssociatorEDProducer";
14  produces<reco::RecoToSimCollection>();
15  produces<reco::SimToRecoCollection>();
16  if (tpRefVector)
17  tpRefVectorToken_ = consumes<TrackingParticleRefVector>(tpTag);
18  else
19  tpToken_ = consumes<TrackingParticleCollection>(tpTag);
20  tracksToken_ = consumes<edm::View<reco::Track>>(tracksTag);
21 
23  LogTrace("MuonAssociatorEDProducer") << "constructing MuonAssociatorByHits" << parset_.dump();
24  edm::LogVerbatim("MuonAssociatorEDProducer") << "\n MuonAssociatorByHits will associate reco::Tracks with "
25  << tracksTag << "\n\t\t and TrackingParticles with " << tpTag;
26  const std::string recoTracksLabel = tracksTag.label();
27 
28  // check and fix inconsistent input settings
29  // tracks with hits only on muon detectors
30  if (recoTracksLabel == "seedsOfSTAmuons" || recoTracksLabel == "standAloneMuons" ||
31  recoTracksLabel == "refittedStandAloneMuons" || recoTracksLabel == "seedsOfDisplacedSTAmuons" ||
32  recoTracksLabel == "displacedStandAloneMuons" || recoTracksLabel == "cosmicMuons" ||
33  recoTracksLabel == "cosmicMuons1Leg" || recoTracksLabel == "hltL2Muons") {
34  if (parset_.getParameter<bool>("UseTracker")) {
35  edm::LogWarning("MuonAssociatorEDProducer")
36  << "\n*** WARNING : inconsistent input tracksTag = " << tracksTag << "\n with UseTracker = true"
37  << "\n ---> setting UseTracker = false ";
38  parset_.addParameter<bool>("UseTracker", false);
39  }
40  if (!parset_.getParameter<bool>("UseMuon")) {
41  edm::LogWarning("MuonAssociatorEDProducer")
42  << "\n*** WARNING : inconsistent input tracksTag = " << tracksTag << "\n with UseMuon = false"
43  << "\n ---> setting UseMuon = true ";
44  parset_.addParameter<bool>("UseMuon", true);
45  }
46  }
47  // tracks with hits only on tracker
48  if (recoTracksLabel == "generalTracks" || recoTracksLabel == "probeTracks" || recoTracksLabel == "displacedTracks" ||
49  recoTracksLabel == "extractGemMuons" || recoTracksLabel == "extractMe0Muons" ||
50  recoTracksLabel == "ctfWithMaterialTracksP5LHCNavigation" || recoTracksLabel == "ctfWithMaterialTracksP5" ||
51  recoTracksLabel == "hltIterL3OIMuonTrackSelectionHighPurity" || recoTracksLabel == "hltIterL3MuonMerged" ||
52  recoTracksLabel == "hltIterL3MuonAndMuonFromL1Merged") {
53  if (parset_.getParameter<bool>("UseMuon")) {
54  edm::LogWarning("MuonAssociatorEDProducer")
55  << "\n*** WARNING : inconsistent input tracksTag = " << tracksTag << "\n with UseMuon = true"
56  << "\n ---> setting UseMuon = false ";
57  parset_.addParameter<bool>("UseMuon", false);
58  }
59  if (!parset_.getParameter<bool>("UseTracker")) {
60  edm::LogWarning("MuonAssociatorEDProducer")
61  << "\n*** WARNING : inconsistent input tracksTag = " << tracksTag << "\n with UseTracker = false"
62  << "\n ---> setting UseTracker = true ";
63  parset_.addParameter<bool>("UseTracker", true);
64  }
65  }
66 
67  LogTrace("MuonAssociatorEDProducer") << "MuonAssociatorEDProducer::beginJob "
68  ": constructing MuonAssociatorByHits";
69  associatorByHits = new MuonAssociatorByHits(parset_, consumesCollector());
70 }
71 
73 
75 
77 
79  using namespace edm;
80 
82  const TrackingParticleRefVector *tmpTPptr = nullptr;
84  Handle<TrackingParticleRefVector> TPCollectionRefVector;
85 
86  if (tpRefVector) {
87  event.getByToken(tpRefVectorToken_, TPCollectionRefVector);
88  tmpTPptr = TPCollectionRefVector.product();
89  //
90  tmpTP = *tmpTPptr;
91  } else {
92  event.getByToken(tpToken_, TPCollection);
93  size_t nTP = TPCollection->size();
94  for (size_t i = 0; i < nTP; ++i) {
95  tmpTP.push_back(TrackingParticleRef(TPCollection, i));
96  }
97  tmpTPptr = &tmpTP;
98  }
99 
100  LogTrace("MuonAssociatorEDProducer") << "getting TrackingParticle collection - " << tpTag;
101  LogTrace("MuonAssociatorEDProducer") << "\t... size = " << tmpTPptr->size();
102 
104  LogTrace("MuonAssociatorEDProducer") << "getting reco::Track collection - " << tracksTag;
105  bool trackAvailable = event.getByToken(tracksToken_, trackCollection);
106  if (trackAvailable)
107  LogTrace("MuonAssociatorEDProducer") << "\t... size = " << trackCollection->size();
108  else
109  LogTrace("MuonAssociatorEDProducer") << "\t... NOT FOUND.";
110 
111  std::unique_ptr<reco::RecoToSimCollection> rts;
112  std::unique_ptr<reco::SimToRecoCollection> str;
113 
114  if (ignoreMissingTrackCollection && !trackAvailable) {
115  // the track collection is not in the event and we're being told to ignore
116  // this. do not output anything to the event, other wise this would be
117  // considered as inefficiency.
118  LogTrace("MuonAssociatorEDProducer") << "\n ignoring missing track collection."
119  << "\n";
120  } else {
122  for (size_t i = 0; i < trackCollection->size(); ++i)
123  tmpT.push_back(trackCollection->refAt(i));
124 
125  edm::LogVerbatim("MuonAssociatorEDProducer")
126  << "\n >>> RecoToSim association <<< \n"
127  << " Track collection : " << tracksTag.label() << ":" << tracksTag.instance()
128  << " (size = " << trackCollection->size() << ") \n"
129  << " TrackingParticle collection : " << tpTag.label() << ":" << tpTag.instance()
130  << " (size = " << tmpTPptr->size() << ")";
131 
133 
134  edm::LogVerbatim("MuonAssociatorEDProducer")
135  << "\n >>> SimToReco association <<< \n"
136  << " TrackingParticle collection : " << tpTag.label() << ":" << tpTag.instance()
137  << " (size = " << tmpTPptr->size() << ") \n"
138  << " Track collection : " << tracksTag.label() << ":" << tracksTag.instance()
139  << " (size = " << trackCollection->size() << ")";
140 
142 
143  rts = std::make_unique<reco::RecoToSimCollection>(recSimColl);
144  str = std::make_unique<reco::SimToRecoCollection>(simRecColl);
145 
146  event.put(std::move(rts));
147  event.put(std::move(str));
148  }
149 }
Log< level::Info, true > LogVerbatim
edm::EDGetTokenT< TrackingParticleCollection > tpToken_
reco::RecoToSimCollection associateRecoToSim(edm::Handle< edm::View< reco::Track >> &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
MuonAssociatorEDProducer(const edm::ParameterSet &)
edm::EDGetTokenT< TrackingParticleRefVector > tpRefVectorToken_
std::string const & instance() const
Definition: InputTag.h:37
T const * product() const
Definition: Handle.h:70
std::string const & label() const
Definition: InputTag.h:36
void produce(edm::Event &, const edm::EventSetup &) override
MuonAssociatorByHits * associatorByHits
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 LogTrace(id)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
trackCollection
Definition: JetHT_cfg.py:50
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
edm::EDGetTokenT< edm::View< reco::Track > > tracksToken_
HLT enums.
void push_back(const RefToBase< T > &)
std::string dump(unsigned int indent=0) const
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
Log< level::Warning, false > LogWarning
#define str(s)
edm::Ref< TrackingParticleCollection > TrackingParticleRef
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1