CMS 3D CMS Logo

TevMuonProducer.cc
Go to the documentation of this file.
1 
10 // Framework
18 
20 
21 // TrackFinder and specific GLB Trajectory Builder
27 
28 using namespace edm;
29 using namespace std;
30 using namespace reco;
31 
32 //
33 // constructor with config
34 //
36  LogDebug("Muon|RecoMuon|TevMuonProducer") << "constructor called" << endl;
37 
38  // GLB Muon Collection Label
39  theGLBCollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
40  glbMuonsToken = consumes<reco::TrackCollection>(theGLBCollectionLabel);
41  glbMuonsTrajToken = consumes<std::vector<Trajectory> >(theGLBCollectionLabel.label());
42 
43  // service parameters
44  ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
45 
46  // the services
47  theService = new MuonServiceProxy(serviceParameters);
48  edm::ConsumesCollector iC = consumesCollector();
49 
50  // TrackRefitter parameters
51  ParameterSet refitterParameters = parameterSet.getParameter<ParameterSet>("RefitterParameters");
52  theRefitter = new GlobalMuonRefitter(refitterParameters, theService, iC);
53 
54  // TrackLoader parameters
55  ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
56  theTrackLoader = new MuonTrackLoader(trackLoaderParameters, iC, theService);
57 
58  theRefits = parameterSet.getParameter<std::vector<std::string> >("Refits");
59  theRefitIndex = parameterSet.getParameter<std::vector<int> >("RefitIndex");
60 
61  for (unsigned int ww = 0; ww < theRefits.size(); ww++) {
62  LogDebug("Muon|RecoMuon|TevMuonProducer") << "Refit " << theRefits[ww];
63  produces<reco::TrackCollection>(theRefits[ww]);
64  produces<TrackingRecHitCollection>(theRefits[ww]);
65  produces<reco::TrackExtraCollection>(theRefits[ww]);
66  produces<vector<Trajectory> >(theRefits[ww]);
67  produces<TrajTrackAssociationCollection>(theRefits[ww]);
68  produces<reco::TrackToTrackMap>(theRefits[ww]);
69  }
70  produces<DYTestimators>("dytInfo");
71 }
72 
73 //
74 // destructor
75 //
77  LogTrace("Muon|RecoMuon|TevMuonProducer") << "destructor called" << endl;
78  if (theService)
79  delete theService;
80  if (theRefitter)
81  delete theRefitter;
82  if (theTrackLoader)
83  delete theTrackLoader;
84 }
85 
86 //
87 // reconstruct muons
88 //
89 void TevMuonProducer::produce(Event& event, const EventSetup& eventSetup) {
90  const string metname = "Muon|RecoMuon|TevMuonProducer";
91  LogTrace(metname) << endl << endl;
92  LogTrace(metname) << "TeV Muon Reconstruction started" << endl;
93 
94  // Update the services
95  theService->update(eventSetup);
96 
97  theRefitter->setEvent(event);
98 
99  theRefitter->setServices(theService->eventSetup());
100 
101  //Retrieve tracker topology from geometry
103  eventSetup.get<TrackerTopologyRcd>().get(tTopoHand);
104  const TrackerTopology* tTopo = tTopoHand.product();
105 
106  // Take the GLB muon container(s)
108  event.getByToken(glbMuonsToken, glbMuons);
109 
110  auto dytInfo = std::make_unique<DYTestimators>();
111  DYTestimators::Filler filler(*dytInfo);
112  size_t GLBmuonSize = glbMuons->size();
113  vector<DYTInfo> dytTmp(GLBmuonSize);
114 
115  Handle<vector<Trajectory> > glbMuonsTraj;
116 
117  LogTrace(metname) << "Taking " << glbMuons->size() << " Global Muons " << theGLBCollectionLabel << endl;
118 
119  vector<MuonTrajectoryBuilder::TrackCand> glbTrackCands;
120 
121  event.getByToken(glbMuonsTrajToken, glbMuonsTraj);
122 
123  const reco::TrackCollection* glbTracks = glbMuons.product();
124 
125  for (unsigned int ww = 0; ww < theRefits.size(); ww++) {
126  LogDebug(metname) << "TeVRefit for Refit: " << theRefitIndex[ww];
127  std::vector<std::pair<Trajectory*, reco::TrackRef> > miniMap;
128  vector<Trajectory*> trajectories;
129  reco::TrackRef::key_type trackIndex = 0;
130  int glbCounter = 0;
131  for (reco::TrackCollection::const_iterator track = glbTracks->begin(); track != glbTracks->end();
132  track++, ++trackIndex) {
133  reco::TrackRef glbRef(glbMuons, trackIndex);
134 
135  vector<Trajectory> refitted = theRefitter->refit(*track, theRefitIndex[ww], tTopo);
136 
137  if (theRefits[ww] == "dyt")
138  dytTmp[glbCounter] = *theRefitter->getDYTInfo();
139  glbCounter++;
140 
141  if (!refitted.empty()) {
142  Trajectory* refit = new Trajectory(refitted.front());
143  LogDebug(metname) << "TeVTrackLoader for Refit: " << theRefits[ww];
144  trajectories.push_back(refit);
145  std::pair<Trajectory*, reco::TrackRef> thisPair(refit, glbRef);
146  miniMap.push_back(thisPair);
147  }
148  }
149  theTrackLoader->loadTracks(trajectories, event, miniMap, glbMuons, *tTopo, theRefits[ww]);
150  }
151 
152  filler.insert(glbMuons, dytTmp.begin(), dytTmp.end());
153  filler.fill();
154  event.put(std::move(dytInfo), "dytInfo");
155 
156  LogTrace(metname) << "Done." << endl;
157 }
#define LogDebug(id)
T getParameter(std::string const &) const
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
void produce(edm::Event &, const edm::EventSetup &) override
reconstruct muons
const std::string metname
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
TevMuonProducer(const edm::ParameterSet &)
constructor with config
#define LogTrace(id)
~TevMuonProducer() override
destructor
T const * product() const
Definition: Handle.h:69
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:73
T const * product() const
Definition: ESHandle.h:86
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1