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 }
gather_cfg.tracksTag
tracksTag
Definition: gather_cfg.py:244
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
edm::Handle::product
T const * product() const
Definition: Handle.h:70
MuonAssociatorEDProducer::tpToken_
edm::EDGetTokenT< TrackingParticleCollection > tpToken_
Definition: MuonAssociatorEDProducer.h:25
edm::InputTag::instance
std::string const & instance() const
Definition: InputTag.h:37
MuonAssociatorEDProducer::tpRefVectorToken_
edm::EDGetTokenT< TrackingParticleRefVector > tpRefVectorToken_
Definition: MuonAssociatorEDProducer.h:26
edm
HLT enums.
Definition: AlignableModifier.h:19
MuonAssociatorEDProducer.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
TrackAssociation.h
edm::RefVector< TrackingParticleCollection >
MuonAssociatorEDProducer::tpTag
edm::InputTag tpTag
Definition: MuonAssociatorEDProducer.h:24
edm::Handle< TrackingParticleCollection >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
MuonAssociatorByHits_cfi.tpRefVector
tpRefVector
Definition: MuonAssociatorByHits_cfi.py:139
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
MuonAssociatorEDProducer::tracksToken_
edm::EDGetTokenT< edm::View< reco::Track > > tracksToken_
Definition: MuonAssociatorEDProducer.h:27
MuonAssociatorByHits_cfi.tpTag
tpTag
Definition: MuonAssociatorByHits_cfi.py:138
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
edm::RefToBaseVector::push_back
void push_back(const RefToBase< T > &)
Definition: RefToBaseVector.h:217
edm::ParameterSet::dump
std::string dump(unsigned int indent=0) const
Definition: ParameterSet.cc:832
MuonAssociatorByHits_cfi.ignoreMissingTrackCollection
ignoreMissingTrackCollection
Definition: MuonAssociatorByHits_cfi.py:136
str
#define str(s)
Definition: TestProcessor.cc:53
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
MuonAssociatorEDProducer::parset_
edm::ParameterSet parset_
Definition: MuonAssociatorEDProducer.h:31
edm::ParameterSet
Definition: ParameterSet.h:47
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:135
MuonAssociatorEDProducer::ignoreMissingTrackCollection
bool ignoreMissingTrackCollection
Definition: MuonAssociatorEDProducer.h:30
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:58
MuonAssociatorEDProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonAssociatorEDProducer.cc:78
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
MuonAssociatorEDProducer::~MuonAssociatorEDProducer
~MuonAssociatorEDProducer() override
Definition: MuonAssociatorEDProducer.cc:72
edm::RefToBaseVector< reco::Track >
MuonAssociatorEDProducer::endJob
virtual void endJob()
Definition: MuonAssociatorEDProducer.cc:76
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
MuonAssociatorEDProducer::associatorByHits
MuonAssociatorByHits * associatorByHits
Definition: MuonAssociatorEDProducer.h:32
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
TrackingParticleRef
edm::Ref< TrackingParticleCollection > TrackingParticleRef
Definition: TrackingParticleFwd.h:12
event
Definition: event.py:1
MuonAssociatorEDProducer::beginJob
virtual void beginJob()
Definition: MuonAssociatorEDProducer.cc:74
edm::Event
Definition: Event.h:73
edm::RefVector::size
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
MuonAssociatorEDProducer::MuonAssociatorEDProducer
MuonAssociatorEDProducer(const edm::ParameterSet &)
Definition: MuonAssociatorEDProducer.cc:7
MuonAssociatorEDProducer::tpRefVector
bool tpRefVector
Definition: MuonAssociatorEDProducer.h:29