CMS 3D CMS Logo

GlobalMuonProducer.cc
Go to the documentation of this file.
1 
12 // Framework
19 
21 
22 // TrackFinder and specific GLB Trajectory Builder
27 
28 using namespace edm;
29 using namespace std;
30 
31 //
32 // constructor with config
33 //
35  LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "constructor called" << endl;
36 
37  // Parameter set for the Builder
38  ParameterSet trajectoryBuilderParameters = parameterSet.getParameter<ParameterSet>("GLBTrajBuilderParameters");
39  InputTag trackCollectionTag = parameterSet.getParameter<InputTag>("TrackerCollectionLabel");
40  trajectoryBuilderParameters.addParameter<InputTag>("TrackerCollectionLabel", trackCollectionTag);
41  InputTag vertexCollectionTag = parameterSet.getParameter<InputTag>("VertexCollectionLabel");
42  trajectoryBuilderParameters.addParameter<InputTag>("VertexCollectionLabel", vertexCollectionTag);
43  bool selectHighPurity_ = parameterSet.getParameter<bool>("selectHighPurity");
44  trajectoryBuilderParameters.addParameter<bool>("selectHighPurity", selectHighPurity_);
45 
46  // STA Muon Collection Label
47  theSTACollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
48  staMuonsToken = consumes<reco::TrackCollection>(parameterSet.getParameter<InputTag>("MuonCollectionLabel"));
49  staMuonsTrajToken =
50  consumes<std::vector<Trajectory> >(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
51  staAssoMapToken =
52  consumes<TrajTrackAssociationCollection>(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
53  updatedStaAssoMapToken =
54  consumes<reco::TrackToTrackMap>(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
55 
56  // service parameters
57  ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
58 
59  // TrackLoader parameters
60  ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
61 
62  // the services
63  theService = new MuonServiceProxy(serviceParameters, consumesCollector());
64 
65  // instantiate the concrete trajectory builder in the Track Finder
66  edm::ConsumesCollector iC = consumesCollector();
67  auto mtl = std::make_unique<MuonTrackLoader>(trackLoaderParameters, iC, theService);
68  auto gmtb = std::make_unique<GlobalMuonTrajectoryBuilder>(trajectoryBuilderParameters, theService, iC);
69 
70  theTrackFinder = std::make_unique<MuonTrackFinder>(std::move(gmtb), std::move(mtl), iC);
71 
72  setAlias(parameterSet.getParameter<std::string>("@module_label"));
73  produces<reco::TrackCollection>().setBranchAlias(theAlias + "Tracks");
74  produces<TrackingRecHitCollection>().setBranchAlias(theAlias + "RecHits");
75  produces<reco::TrackExtraCollection>().setBranchAlias(theAlias + "TrackExtras");
76  produces<vector<Trajectory> >().setBranchAlias(theAlias + "Trajectories");
77  produces<TrajTrackAssociationCollection>().setBranchAlias(theAlias + "TrajTrackMap");
78  produces<reco::MuonTrackLinksCollection>().setBranchAlias(theAlias + "s");
79 }
80 
81 //
82 // destructor
83 //
85  LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "destructor called" << endl;
86  if (theService)
87  delete theService;
88 }
89 
90 //
91 // reconstruct muons
92 //
94  const string metname = "Muon|RecoMuon|GlobalMuonProducer";
95  LogTrace(metname) << endl << endl << endl;
96  LogTrace(metname) << "Global Muon Reconstruction started" << endl;
97 
98  // Update the services
99  theService->update(eventSetup);
100 
101  // Take the STA muon container(s)
103  event.getByToken(staMuonsToken, staMuons);
104 
105  Handle<vector<Trajectory> > staMuonsTraj;
106 
107  LogTrace(metname) << "Taking " << staMuons->size() << " Stand Alone Muons " << endl;
108 
109  vector<MuonTrajectoryBuilder::TrackCand> staTrackCands;
110 
112 
113  edm::Handle<reco::TrackToTrackMap> updatedStaAssoMap;
114 
115  if (event.getByToken(staMuonsTrajToken, staMuonsTraj) && event.getByToken(staAssoMapToken, staAssoMap) &&
116  event.getByToken(updatedStaAssoMapToken, updatedStaAssoMap)) {
117  for (TrajTrackAssociationCollection::const_iterator it = staAssoMap->begin(); it != staAssoMap->end(); ++it) {
118  const Ref<vector<Trajectory> > traj = it->key;
119  const reco::TrackRef tkRegular = it->val;
120  reco::TrackRef tkUpdated;
123  if (theSTACollectionLabel.instance() == "UpdatedAtVtx") {
124  iEnd = updatedStaAssoMap->end();
125  iii = updatedStaAssoMap->find(it->val);
126  if (iii != iEnd)
127  tkUpdated = (*updatedStaAssoMap)[it->val];
128  }
129 
130  int etaFlip1 =
131  ((tkUpdated.isNonnull() && tkRegular.isNonnull()) && ((tkUpdated->eta() * tkRegular->eta()) < 0)) ? -1 : 1;
132 
133  const reco::TrackRef tk = (tkUpdated.isNonnull() && etaFlip1 == 1) ? tkUpdated : tkRegular;
134 
136  if (traj->isValid())
137  tkCand.first = &*traj;
138  staTrackCands.push_back(tkCand);
139  }
140  } else {
141  for (unsigned int position = 0; position != staMuons->size(); ++position) {
142  reco::TrackRef staTrackRef(staMuons, position);
144  staTrackCands.push_back(staCand);
145  }
146  }
147 
148  theTrackFinder->reconstruct(staTrackCands, event, eventSetup);
149 
150  LogTrace(metname) << "Event loaded"
151  << "================================" << endl
152  << endl;
153 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::pair< const Trajectory *, reco::TrackRef > TrackCand
const std::string metname
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
key_type key() const
Accessor for product key.
Definition: Ref.h:250
const_iterator find(const key_type &k) const
find element with specified reference key
#define LogTrace(id)
void produce(edm::Event &, const edm::EventSetup &) override
reconstruct muons
const_iterator end() const
last iterator over the map (read only)
trackCollectionTag
Definition: cosmics_id.py:5
char const * label
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
~GlobalMuonProducer() override
destructor
GlobalMuonProducer(const edm::ParameterSet &)
constructor with config
const_iterator begin() const
first iterator over the map (read only)
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1