CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 = std::make_unique<MuonServiceProxy>(serviceParameters, consumesCollector());
48  edm::ConsumesCollector iC = consumesCollector();
49 
50  // TrackRefitter parameters
51  ParameterSet refitterParameters = parameterSet.getParameter<ParameterSet>("RefitterParameters");
52  theRefitter = std::make_unique<GlobalMuonRefitter>(refitterParameters, theService.get(), iC);
53 
54  // TrackLoader parameters
55  ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
56  theTrackLoader = std::make_unique<MuonTrackLoader>(trackLoaderParameters, iC, theService.get());
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 //
76 TevMuonProducer::~TevMuonProducer() { LogTrace("Muon|RecoMuon|TevMuonProducer") << "destructor called" << endl; }
77 
78 //
79 // reconstruct muons
80 //
81 void TevMuonProducer::produce(Event& event, const EventSetup& eventSetup) {
82  const string metname = "Muon|RecoMuon|TevMuonProducer";
83  LogTrace(metname) << endl << endl;
84  LogTrace(metname) << "TeV Muon Reconstruction started" << endl;
85 
86  // Update the services
87  theService->update(eventSetup);
88 
89  theRefitter->setEvent(event);
90 
91  theRefitter->setServices(theService->eventSetup());
92 
93  //Retrieve tracker topology from geometry
94  const TrackerTopology* tTopo = &eventSetup.getData(tTopoToken);
95 
96  // Take the GLB muon container(s)
98  event.getByToken(glbMuonsToken, glbMuons);
99 
100  auto dytInfo = std::make_unique<DYTestimators>();
101  DYTestimators::Filler filler(*dytInfo);
102  size_t GLBmuonSize = glbMuons->size();
103  vector<DYTInfo> dytTmp(GLBmuonSize);
104 
105  Handle<vector<Trajectory> > glbMuonsTraj;
106 
107  LogTrace(metname) << "Taking " << glbMuons->size() << " Global Muons " << theGLBCollectionLabel << endl;
108 
109  vector<MuonTrajectoryBuilder::TrackCand> glbTrackCands;
110 
111  event.getByToken(glbMuonsTrajToken, glbMuonsTraj);
112 
113  const reco::TrackCollection* glbTracks = glbMuons.product();
114 
115  for (unsigned int ww = 0; ww < theRefits.size(); ww++) {
116  LogDebug(metname) << "TeVRefit for Refit: " << theRefitIndex[ww];
117  std::vector<std::pair<Trajectory*, reco::TrackRef> > miniMap;
119  reco::TrackRef::key_type trackIndex = 0;
120  int glbCounter = 0;
121  for (reco::TrackCollection::const_iterator track = glbTracks->begin(); track != glbTracks->end();
122  track++, ++trackIndex) {
123  reco::TrackRef glbRef(glbMuons, trackIndex);
124 
125  vector<Trajectory> refitted = theRefitter->refit(*track, theRefitIndex[ww], tTopo);
126 
127  if (theRefits[ww] == "dyt")
128  dytTmp[glbCounter] = *theRefitter->getDYTInfo();
129  glbCounter++;
130 
131  if (!refitted.empty()) {
132  auto refit = std::make_unique<Trajectory>(refitted.front());
133  LogDebug(metname) << "TeVTrackLoader for Refit: " << theRefits[ww];
134  std::pair<Trajectory*, reco::TrackRef> thisPair(refit.get(), glbRef);
135  miniMap.push_back(thisPair);
136  trajectories.push_back(std::move(refit));
137  }
138  }
139  theTrackLoader->loadTracks(trajectories, event, miniMap, glbMuons, *tTopo, theRefits[ww]);
140  }
141 
142  filler.insert(glbMuons, dytTmp.begin(), dytTmp.end());
143  filler.fill();
144  event.put(std::move(dytInfo), "dytInfo");
145 
146  LogTrace(metname) << "Done." << endl;
147 }
std::unique_ptr< MuonServiceProxy > theService
the event setup proxy, it takes care the services update
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< int > theRefitIndex
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::EDGetTokenT< std::vector< Trajectory > > glbMuonsTrajToken
#define LogTrace(id)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken
TevMuonProducer(const edm::ParameterSet &)
constructor with config
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
def move
Definition: eostools.py:511
edm::InputTag theGLBCollectionLabel
STA Label.
MuonCandidate::TrajectoryContainer TrajectoryContainer
~TevMuonProducer() override
destructor
std::vector< std::string > theRefits
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::unique_ptr< MuonTrackLoader > theTrackLoader
std::unique_ptr< GlobalMuonRefitter > theRefitter
std::string const & label() const
Definition: InputTag.h:36
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::EDGetTokenT< reco::TrackCollection > glbMuonsToken
#define LogDebug(id)