CMS 3D CMS Logo

L1TMuonLegacyConverter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TMuonLegacyConverter
4 // Class: L1TMuonLegacyConverter
5 //
8 //
9 // Original Author: Bortignon Pierluigi
10 // Created: Sun March 6 EDT 2016
11 //
12 //
13 
14 // system include files
15 #include <memory>
16 
17 // user include files
19 
22 
26 
29 
37 
42 
44 
45 // #include "FWCore/Utilities/interface/EDMException.h"
46 
47 //
48 // class decleration
49 //
50 
51 //
52 // constants, enums and typedefs
53 //
54 using namespace l1t;
55 
56 //
57 // static data member definitions
58 //
59 
60 double const L1TMuonLegacyConverter::muonMassGeV_ = 0.105658369; // PDG06
61 
62 //
63 // constructors and destructor
64 //
66  using namespace l1extra;
67 
68  // moving inputTag here
69  muonSource_InputTag = iConfig.getParameter<edm::InputTag>("muonSource");
70  produceMuonParticles_ = iConfig.getUntrackedParameter<bool>("produceMuonParticles");
71  centralBxOnly_ = iConfig.getUntrackedParameter<bool>("centralBxOnly");
72 
73  produces<MuonBxCollection>("imdMuonsLegacy");
74  muonSource_InputToken = consumes<L1MuGMTReadoutCollection>(muonSource_InputTag);
75 
76  if (produceMuonParticles_) {
77  muScalesToken_ = esConsumes();
78  muPtScaleToken_ = esConsumes();
79  }
80 }
81 
83  // do anything here that needs to be done at desctruction time
84  // (e.g. close files, deallocate resources etc.)
85 }
86 
87 //
88 // member functions
89 //
90 
91 // ------------ method called to produce the data ------------
93  using namespace edm;
94  using namespace l1extra;
95  using namespace std;
96 
97  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98  // ~~~~~~~~~~~~~~~~~~~~ Muons ~~~~~~~~~~~~~~~~~~~~
99  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100 
101  std::unique_ptr<MuonBxCollection> imdMuonsLegacy(new MuonBxCollection());
102 
103  LogDebug("L1TMuonLegacyConverter") << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
104  << "\nrequested in configuration, but not found in the event." << std::endl;
105 
106  if (produceMuonParticles_) {
107  ESHandle<L1MuTriggerScales> muScales = iSetup.getHandle(muScalesToken_);
108 
109  ESHandle<L1MuTriggerPtScale> muPtScale = iSetup.getHandle(muPtScaleToken_);
110 
111  Handle<L1MuGMTReadoutCollection> simMuCollection;
112  iEvent.getByToken(muonSource_InputToken, simMuCollection);
113 
114  vector<L1MuGMTExtendedCand> simMuCands;
115 
116  if (!simMuCollection.isValid()) {
117  LogDebug("L1TMuonLegacyConverter") << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
118  << "\nrequested in configuration, but not found in the event." << std::endl;
119  } else {
120  if (centralBxOnly_) {
121  // Get GMT candidates from central bunch crossing only
122  simMuCands = simMuCollection->getRecord().getGMTCands();
123  } else {
124  // Get GMT candidates from all bunch crossings
125  vector<L1MuGMTReadoutRecord> records = simMuCollection->getRecords();
126  vector<L1MuGMTReadoutRecord>::const_iterator rItr = records.begin();
127  vector<L1MuGMTReadoutRecord>::const_iterator rEnd = records.end();
128 
129  for (; rItr != rEnd; ++rItr) {
130  vector<L1MuGMTExtendedCand> tmpCands = rItr->getGMTCands();
131 
132  simMuCands.insert(simMuCands.end(), tmpCands.begin(), tmpCands.end());
133  }
134  }
135 
136  vector<L1MuGMTExtendedCand>::const_iterator muItr = simMuCands.begin();
137  vector<L1MuGMTExtendedCand>::const_iterator muEnd = simMuCands.end();
138  for (int i = 0; muItr != muEnd; ++muItr, ++i) {
139  if (!muItr->empty()) {
140  // keep x and y components non-zero and protect against roundoff.
141  double pt = muPtScale->getPtScale()->getLowEdge(muItr->ptIndex()) + 1.e-6;
142  std::cout << "pt from muPtScale = " << pt << std::endl;
143  double eta = muScales->getGMTEtaScale()->getCenter(muItr->etaIndex());
144  double phi = muScales->getPhiScale()->getLowEdge(muItr->phiIndex());
145 
146  math::PtEtaPhiMLorentzVector p4(pt, eta, phi, muonMassGeV_);
147 
148  Muon outMu{p4,
149  (int)0,
150  (int)0,
151  (int)0,
152  (int)muItr->quality(),
153  (int)muItr->charge(),
154  (int)muItr->charge_valid(),
155  (int)muItr->isol(),
156  (int)0,
157  (int)0,
158  true,
159  (int)0,
160  (int)0,
161  (int)0,
162  (int)muItr->rank()};
163  imdMuonsLegacy->push_back(muItr->bx(), outMu);
164  }
165  }
166  }
167  }
168 
169  iEvent.put(std::move(imdMuonsLegacy), "imdMuonsLegacy");
170 
171 } // closing produce
172 
173 //define this as a plug-in
const L1MuScale * getGMTEtaScale() const
get the GMT eta scale
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
delete x;
Definition: CaloConfig.h:22
const L1MuScale * getPhiScale() const
get the phi scale
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
const L1MuScale * getPtScale() const
get the Pt scale
T getUntrackedParameter(std::string const &, T const &) const
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int iEvent
Definition: GenABIO.cc:224
Definition: Muon.py:1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
BXVector< Muon > MuonBxCollection
Definition: Muon.h:11
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
L1TMuonLegacyConverter(const edm::ParameterSet &)
static const double muonMassGeV_
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
L1MuGMTReadoutRecord const & getRecord(int bx=0) const
std::vector< L1MuGMTExtendedCand > getGMTCands() const
get GMT candidates vector
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)