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 
15 // system include files
16 #include <memory>
17 
18 // user include files
20 
23 
27 
30 
38 
43 
45 
46 
47 // #include "FWCore/Utilities/interface/EDMException.h"
48 
49 //
50 // class decleration
51 //
52 
53 
54 //
55 // constants, enums and typedefs
56 //
57 using namespace l1t;
58 
59 
60 //
61 // static data member definitions
62 //
63 
64 double const L1TMuonLegacyConverter::muonMassGeV_ = 0.105658369 ; // PDG06
65 
66 //
67 // constructors and destructor
68 //
70 {
71  using namespace l1extra ;
72 
73  // moving inputTag here
74  muonSource_InputTag = iConfig.getParameter<edm::InputTag>("muonSource");
75  produceMuonParticles_ = iConfig.getUntrackedParameter<bool>("produceMuonParticles");
76  centralBxOnly_ = iConfig.getUntrackedParameter<bool>("centralBxOnly");
77 
78  produces<MuonBxCollection>("imdMuonsLegacy");
79  muonSource_InputToken = consumes<L1MuGMTReadoutCollection>(muonSource_InputTag);
80 }
81 
82 
84 {
85 
86  // do anything here that needs to be done at desctruction time
87  // (e.g. close files, deallocate resources etc.)
88 
89 }
90 
91 
92 //
93 // member functions
94 //
95 
96 // ------------ method called to produce the data ------------
97 void
99  const edm::EventSetup& iSetup)
100 {
101  using namespace edm ;
102  using namespace l1extra ;
103  using namespace std ;
104 
105  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106  // ~~~~~~~~~~~~~~~~~~~~ Muons ~~~~~~~~~~~~~~~~~~~~
107  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108 
109  std::unique_ptr< MuonBxCollection > imdMuonsLegacy( new MuonBxCollection() );
110 
111  LogDebug("L1TMuonLegacyConverter")
112  << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
113  << "\nrequested in configuration, but not found in the event."
114  << std::endl;
115 
116  if( produceMuonParticles_ )
117  {
119  iSetup.get< L1MuTriggerScalesRcd >().get( muScales ) ;
120 
122  iSetup.get< L1MuTriggerPtScaleRcd >().get( muPtScale ) ;
123 
124  Handle< L1MuGMTReadoutCollection > simMuCollection ;
125  iEvent.getByToken( muonSource_InputToken, simMuCollection ) ;
126 
127  vector< L1MuGMTExtendedCand > simMuCands ;
128 
129 
130  if( !simMuCollection.isValid() )
131  {
132 
133  LogDebug("L1TMuonLegacyConverter")
134  << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
135  << "\nrequested in configuration, but not found in the event."
136  << std::endl;
137  }
138  else
139  {
140  if( centralBxOnly_ )
141  {
142  // Get GMT candidates from central bunch crossing only
143  simMuCands = simMuCollection->getRecord().getGMTCands() ;
144  }
145  else
146  {
147  // Get GMT candidates from all bunch crossings
148  vector< L1MuGMTReadoutRecord > records = simMuCollection->getRecords();
149  vector< L1MuGMTReadoutRecord >::const_iterator rItr = records.begin();
150  vector< L1MuGMTReadoutRecord >::const_iterator rEnd = records.end();
151 
152  for( ; rItr != rEnd ; ++rItr )
153  {
154  vector< L1MuGMTExtendedCand > tmpCands = rItr->getGMTCands() ;
155 
156  simMuCands.insert( simMuCands.end(),
157  tmpCands.begin(),
158  tmpCands.end() ) ;
159  }
160  }
161 
162  vector< L1MuGMTExtendedCand >::const_iterator muItr = simMuCands.begin() ;
163  vector< L1MuGMTExtendedCand >::const_iterator muEnd = simMuCands.end() ;
164  for( int i = 0 ; muItr != muEnd ; ++muItr, ++i )
165  {
166 
167  if( !muItr->empty() ){
168  // keep x and y components non-zero and protect against roundoff.
169  double pt = muPtScale->getPtScale()->getLowEdge( muItr->ptIndex() ) + 1.e-6 ;
170  std::cout << "pt from muPtScale = " << pt << std::endl;
171  double eta = muScales->getGMTEtaScale()->getCenter( muItr->etaIndex() ) ;
172  double phi = muScales->getPhiScale()->getLowEdge( muItr->phiIndex() ) ;
173 
175  eta,
176  phi,
177  muonMassGeV_ ) ;
178 
179  Muon outMu{p4, (int)0, (int)0, (int)0, (int)muItr->quality(), (int)muItr->charge(), (int)muItr->charge_valid() , (int)muItr->isol(), (int)0 , (int)0, true, (int)0, (int)0, (int)0 , (int)muItr->rank() };
180  imdMuonsLegacy->push_back( muItr->bx(), outMu ) ;
181  }
182  }
183  }
184  }
185 
186  iEvent.put( std::move(imdMuonsLegacy), "imdMuonsLegacy" );
187 
188 } // closing produce
189 
190 //define this as a plug-in
192 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
std::vector< L1MuGMTExtendedCand > getGMTCands() const
get GMT candidates vector
const L1MuScale * getPtScale() const
get the Pt scale
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
delete x;
Definition: CaloConfig.h:22
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int iEvent
Definition: GenABIO.cc:230
Definition: Muon.py:1
double p4[4]
Definition: TauolaWrapper.h:92
const L1MuScale * getPhiScale() const
get the phi scale
bool isValid() const
Definition: HandleBase.h:74
BXVector< Muon > MuonBxCollection
Definition: Muon.h:11
L1TMuonLegacyConverter(const edm::ParameterSet &)
static const double muonMassGeV_
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
T get() const
Definition: EventSetup.h:63
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
const L1MuScale * getGMTEtaScale() const
get the GMT eta scale
L1MuGMTReadoutRecord const & getRecord(int bx=0) const
def move(src, dest)
Definition: eostools.py:510