CMS 3D CMS Logo

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