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 
29 using namespace edm;
30 using namespace std;
31 
32 //
33 // constructor with config
34 //
36 
37  LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "constructor called" << endl;
38 
39  // Parameter set for the Builder
40  ParameterSet trajectoryBuilderParameters = parameterSet.getParameter<ParameterSet>("GLBTrajBuilderParameters");
41  InputTag trackCollectionTag = parameterSet.getParameter<InputTag>("TrackerCollectionLabel");
42  trajectoryBuilderParameters.addParameter<InputTag>("TrackerCollectionLabel",trackCollectionTag);
43 
44  // STA Muon Collection Label
45  theSTACollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
46  staMuonsToken=consumes<reco::TrackCollection>(parameterSet.getParameter<InputTag>("MuonCollectionLabel"));
47  staMuonsTrajToken=consumes<std::vector<Trajectory> >(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
48  staAssoMapToken=consumes<TrajTrackAssociationCollection>(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
49  updatedStaAssoMapToken=consumes<reco::TrackToTrackMap>(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
50 
51 
52 
53  // service parameters
54  ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
55 
56  // TrackLoader parameters
57  ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
58 
59  // the services
60  theService = new MuonServiceProxy(serviceParameters);
61 
62  // instantiate the concrete trajectory builder in the Track Finder
63  edm::ConsumesCollector iC = consumesCollector();
64  MuonTrackLoader* mtl = new MuonTrackLoader(trackLoaderParameters,iC,theService);
65  GlobalMuonTrajectoryBuilder* gmtb = new GlobalMuonTrajectoryBuilder(trajectoryBuilderParameters, theService,iC);
66 
67  theTrackFinder = new MuonTrackFinder(gmtb, mtl);
68 
69  setAlias(parameterSet.getParameter<std::string>("@module_label"));
70  produces<reco::TrackCollection>().setBranchAlias(theAlias + "Tracks");
71  produces<TrackingRecHitCollection>().setBranchAlias(theAlias + "RecHits");
72  produces<reco::TrackExtraCollection>().setBranchAlias(theAlias + "TrackExtras");
73  produces<vector<Trajectory> >().setBranchAlias(theAlias + "Trajectories") ;
74  produces<TrajTrackAssociationCollection>().setBranchAlias(theAlias + "TrajTrackMap");
75  produces<reco::MuonTrackLinksCollection>().setBranchAlias(theAlias + "s");
76 }
77 
78 
79 //
80 // destructor
81 //
83 
84  LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "destructor called" << endl;
85  if (theService) delete theService;
86  if (theTrackFinder) delete theTrackFinder;
87 
88 }
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) && event.getByToken(updatedStaAssoMapToken,updatedStaAssoMap) ) {
117 
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 ) tkUpdated = (*updatedStaAssoMap)[it->val] ;
128  }
129 
130  int etaFlip1 = ((tkUpdated.isNonnull() && tkRegular.isNonnull()) && ( (tkUpdated->eta() * tkRegular->eta() ) < 0)) ? -1 : 1;
131 
132  const reco::TrackRef tk = ( tkUpdated.isNonnull() && etaFlip1==1 ) ? tkUpdated : tkRegular ;
133 
135  if( traj->isValid() ) 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 
149  LogTrace(metname)<<"Event loaded"
150  <<"================================"
151  <<endl<<endl;
152 
153 }
T getParameter(std::string const &) const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
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:508
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:265
void produce(edm::Event &, const edm::EventSetup &) override
reconstruct muons
trackCollectionTag
Definition: cosmics_id.py:6
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
~GlobalMuonProducer() override
destructor
#define LogTrace(id)
GlobalMuonProducer(const edm::ParameterSet &)
constructor with config
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:509
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