CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
78  // do anything here that needs to be done at desctruction time
79  // (e.g. close files, deallocate resources etc.)
80 }
81 
82 //
83 // member functions
84 //
85 
86 // ------------ method called to produce the data ------------
88  using namespace edm;
89  using namespace l1extra;
90  using namespace std;
91 
92  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93  // ~~~~~~~~~~~~~~~~~~~~ Muons ~~~~~~~~~~~~~~~~~~~~
94  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95 
96  std::unique_ptr<MuonBxCollection> imdMuonsLegacy(new MuonBxCollection());
97 
98  LogDebug("L1TMuonLegacyConverter") << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
99  << "\nrequested in configuration, but not found in the event." << std::endl;
100 
101  if (produceMuonParticles_) {
103  iSetup.get<L1MuTriggerScalesRcd>().get(muScales);
104 
106  iSetup.get<L1MuTriggerPtScaleRcd>().get(muPtScale);
107 
108  Handle<L1MuGMTReadoutCollection> simMuCollection;
109  iEvent.getByToken(muonSource_InputToken, simMuCollection);
110 
111  vector<L1MuGMTExtendedCand> simMuCands;
112 
113  if (!simMuCollection.isValid()) {
114  LogDebug("L1TMuonLegacyConverter") << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
115  << "\nrequested in configuration, but not found in the event." << std::endl;
116  } else {
117  if (centralBxOnly_) {
118  // Get GMT candidates from central bunch crossing only
119  simMuCands = simMuCollection->getRecord().getGMTCands();
120  } else {
121  // Get GMT candidates from all bunch crossings
122  vector<L1MuGMTReadoutRecord> records = simMuCollection->getRecords();
123  vector<L1MuGMTReadoutRecord>::const_iterator rItr = records.begin();
124  vector<L1MuGMTReadoutRecord>::const_iterator rEnd = records.end();
125 
126  for (; rItr != rEnd; ++rItr) {
127  vector<L1MuGMTExtendedCand> tmpCands = rItr->getGMTCands();
128 
129  simMuCands.insert(simMuCands.end(), tmpCands.begin(), tmpCands.end());
130  }
131  }
132 
133  vector<L1MuGMTExtendedCand>::const_iterator muItr = simMuCands.begin();
134  vector<L1MuGMTExtendedCand>::const_iterator muEnd = simMuCands.end();
135  for (int i = 0; muItr != muEnd; ++muItr, ++i) {
136  if (!muItr->empty()) {
137  // keep x and y components non-zero and protect against roundoff.
138  double pt = muPtScale->getPtScale()->getLowEdge(muItr->ptIndex()) + 1.e-6;
139  std::cout << "pt from muPtScale = " << pt << std::endl;
140  double eta = muScales->getGMTEtaScale()->getCenter(muItr->etaIndex());
141  double phi = muScales->getPhiScale()->getLowEdge(muItr->phiIndex());
142 
143  math::PtEtaPhiMLorentzVector p4(pt, eta, phi, muonMassGeV_);
144 
145  Muon outMu{p4,
146  (int)0,
147  (int)0,
148  (int)0,
149  (int)muItr->quality(),
150  (int)muItr->charge(),
151  (int)muItr->charge_valid(),
152  (int)muItr->isol(),
153  (int)0,
154  (int)0,
155  true,
156  (int)0,
157  (int)0,
158  (int)0,
159  (int)muItr->rank()};
160  imdMuonsLegacy->push_back(muItr->bx(), outMu);
161  }
162  }
163  }
164  }
165 
166  iEvent.put(std::move(imdMuonsLegacy), "imdMuonsLegacy");
167 
168 } // closing produce
169 
170 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
bool isValid() const
Definition: HandleBase.h:70
Definition: Muon.h:21
BXVector< Muon > MuonBxCollection
Definition: Muon.h:11
L1TMuonLegacyConverter(const edm::ParameterSet &)
static const double muonMassGeV_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void produce(edm::Event &, const edm::EventSetup &) override
T get() const
Definition: EventSetup.h:88
tuple cout
Definition: gather_cfg.py:144
int charge() const final
electric charge
#define LogDebug(id)