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 
42  // STA Muon Collection Label
43  theSTACollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
44  staMuonsToken = consumes<reco::TrackCollection>(parameterSet.getParameter<InputTag>("MuonCollectionLabel"));
45  staMuonsTrajToken =
46  consumes<std::vector<Trajectory> >(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
47  staAssoMapToken =
48  consumes<TrajTrackAssociationCollection>(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
49  updatedStaAssoMapToken =
50  consumes<reco::TrackToTrackMap>(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
51 
52  // service parameters
53  ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
54 
55  // TrackLoader parameters
56  ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
57 
58  // the services
59  theService = new MuonServiceProxy(serviceParameters);
60 
61  // instantiate the concrete trajectory builder in the Track Finder
62  edm::ConsumesCollector iC = consumesCollector();
63  MuonTrackLoader* mtl = new MuonTrackLoader(trackLoaderParameters, iC, theService);
64  GlobalMuonTrajectoryBuilder* gmtb = new GlobalMuonTrajectoryBuilder(trajectoryBuilderParameters, theService, iC);
65 
66  theTrackFinder = new MuonTrackFinder(gmtb, mtl);
67 
68  setAlias(parameterSet.getParameter<std::string>("@module_label"));
69  produces<reco::TrackCollection>().setBranchAlias(theAlias + "Tracks");
70  produces<TrackingRecHitCollection>().setBranchAlias(theAlias + "RecHits");
71  produces<reco::TrackExtraCollection>().setBranchAlias(theAlias + "TrackExtras");
72  produces<vector<Trajectory> >().setBranchAlias(theAlias + "Trajectories");
73  produces<TrajTrackAssociationCollection>().setBranchAlias(theAlias + "TrajTrackMap");
74  produces<reco::MuonTrackLinksCollection>().setBranchAlias(theAlias + "s");
75 }
76 
77 //
78 // destructor
79 //
81  LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "destructor called" << endl;
82  if (theService)
83  delete theService;
84  if (theTrackFinder)
85  delete theTrackFinder;
86 }
87 
88 //
89 // reconstruct muons
90 //
92  const string metname = "Muon|RecoMuon|GlobalMuonProducer";
93  LogTrace(metname) << endl << endl << endl;
94  LogTrace(metname) << "Global Muon Reconstruction started" << endl;
95 
96  // Update the services
97  theService->update(eventSetup);
98 
99  // Take the STA muon container(s)
101  event.getByToken(staMuonsToken, staMuons);
102 
103  Handle<vector<Trajectory> > staMuonsTraj;
104 
105  LogTrace(metname) << "Taking " << staMuons->size() << " Stand Alone Muons " << endl;
106 
107  vector<MuonTrajectoryBuilder::TrackCand> staTrackCands;
108 
110 
111  edm::Handle<reco::TrackToTrackMap> updatedStaAssoMap;
112 
113  if (event.getByToken(staMuonsTrajToken, staMuonsTraj) && event.getByToken(staAssoMapToken, staAssoMap) &&
114  event.getByToken(updatedStaAssoMapToken, updatedStaAssoMap)) {
115  for (TrajTrackAssociationCollection::const_iterator it = staAssoMap->begin(); it != staAssoMap->end(); ++it) {
116  const Ref<vector<Trajectory> > traj = it->key;
117  const reco::TrackRef tkRegular = it->val;
118  reco::TrackRef tkUpdated;
121  if (theSTACollectionLabel.instance() == "UpdatedAtVtx") {
122  iEnd = updatedStaAssoMap->end();
123  iii = updatedStaAssoMap->find(it->val);
124  if (iii != iEnd)
125  tkUpdated = (*updatedStaAssoMap)[it->val];
126  }
127 
128  int etaFlip1 =
129  ((tkUpdated.isNonnull() && tkRegular.isNonnull()) && ((tkUpdated->eta() * tkRegular->eta()) < 0)) ? -1 : 1;
130 
131  const reco::TrackRef tk = (tkUpdated.isNonnull() && etaFlip1 == 1) ? tkUpdated : tkRegular;
132 
134  if (traj->isValid())
135  tkCand.first = &*traj;
136  staTrackCands.push_back(tkCand);
137  }
138  } else {
139  for (unsigned int position = 0; position != staMuons->size(); ++position) {
140  reco::TrackRef staTrackRef(staMuons, position);
142  staTrackCands.push_back(staCand);
143  }
144  }
145 
146  theTrackFinder->reconstruct(staTrackCands, event, eventSetup);
147 
148  LogTrace(metname) << "Event loaded"
149  << "================================" << endl
150  << endl;
151 }
T getParameter(std::string const &) const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
std::pair< const Trajectory *, reco::TrackRef > TrackCand
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
const std::string metname
const_iterator find(const key_type &k) const
find element with specified reference key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
void produce(edm::Event &, const edm::EventSetup &) override
reconstruct muons
trackCollectionTag
Definition: cosmics_id.py:6
char const * label
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:124
~GlobalMuonProducer() override
destructor
#define LogTrace(id)
GlobalMuonProducer(const edm::ParameterSet &)
constructor with config
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
const_iterator begin() const
first iterator over the map (read only)
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
Definition: event.py:1