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 
76  produces<MuonBxCollection>("imdMuonsLegacy");
77  muonSource_InputToken = consumes<L1MuGMTReadoutCollection>(muonSource_InputTag);
78 }
79 
80 
82 {
83 
84  // do anything here that needs to be done at desctruction time
85  // (e.g. close files, deallocate resources etc.)
86 
87 }
88 
89 
90 //
91 // member functions
92 //
93 
94 // ------------ method called to produce the data ------------
95 void
97  const edm::EventSetup& iSetup)
98 {
99  using namespace edm ;
100  using namespace l1extra ;
101  using namespace std ;
102 
103  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104  // ~~~~~~~~~~~~~~~~~~~~ Muons ~~~~~~~~~~~~~~~~~~~~
105  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106 
107  std::unique_ptr< MuonBxCollection > imdMuonsLegacy( new MuonBxCollection() );
108 
109  if( produceMuonParticles_ )
110  {
112  iSetup.get< L1MuTriggerScalesRcd >().get( muScales ) ;
113 
115  iSetup.get< L1MuTriggerPtScaleRcd >().get( muPtScale ) ;
116 
117  Handle< L1MuGMTReadoutCollection > hwMuCollection ;
118  iEvent.getByToken( muonSource_InputToken, hwMuCollection ) ;
119 
120  vector< L1MuGMTExtendedCand > hwMuCands ;
121 
122  if( !hwMuCollection.isValid() )
123  {
124  LogDebug("L1TMuonLegacyConverter")
125  << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
126  << "\nrequested in configuration, but not found in the event."
127  << std::endl;
128  }
129  else
130  {
131  if( centralBxOnly_ )
132  {
133  // Get GMT candidates from central bunch crossing only
134  hwMuCands = hwMuCollection->getRecord().getGMTCands() ;
135  }
136  else
137  {
138  // Get GMT candidates from all bunch crossings
139  vector< L1MuGMTReadoutRecord > records = hwMuCollection->getRecords();
140  vector< L1MuGMTReadoutRecord >::const_iterator rItr = records.begin();
141  vector< L1MuGMTReadoutRecord >::const_iterator rEnd = records.end();
142 
143  for( ; rItr != rEnd ; ++rItr )
144  {
145  vector< L1MuGMTExtendedCand > tmpCands = rItr->getGMTCands() ;
146 
147  hwMuCands.insert( hwMuCands.end(),
148  tmpCands.begin(),
149  tmpCands.end() ) ;
150  }
151  }
152 
153 // cout << "HW muons" << endl ;
154  vector< L1MuGMTExtendedCand >::const_iterator muItr = hwMuCands.begin() ;
155  vector< L1MuGMTExtendedCand >::const_iterator muEnd = hwMuCands.end() ;
156  for( int i = 0 ; muItr != muEnd ; ++muItr, ++i )
157  {
158 // cout << "#" << i
159 // << " name " << muItr->name()
160 // << " empty " << muItr->empty()
161 // << " pt " << muItr->ptIndex()
162 // << " eta " << muItr->etaIndex()
163 // << " phi " << muItr->phiIndex()
164 // << " iso " << muItr->isol()
165 // << " mip " << muItr->mip()
166 // << " bx " << muItr->bx()
167 // << endl ;
168 
169  if( !muItr->empty() ){
170  // keep x and y components non-zero and protect against roundoff.
171  double pt = muPtScale->getPtScale()->getLowEdge( muItr->ptIndex() ) + 1.e-6 ;
172  double eta = muScales->getGMTEtaScale()->getCenter( muItr->etaIndex() ) ;
173  double phi = muScales->getPhiScale()->getLowEdge( muItr->phiIndex() ) ;
174 
176  eta,
177  phi,
178  muonMassGeV_ ) ;
179 
180  // from L1TMuonProducer.cc - which is the stage2 muon producer:
181  // Muon outMu{vec, mu->hwPt(), mu->hwEta(), mu->hwGlobalPhi(), outMuQual, mu->hwSign(), mu->hwSignValid(), iso, mu->tfMuonIndex(), 0, true, mu->hwIsoSum(), mu->hwDPhi(), mu->hwDEta(), mu->hwRank()};
182 
183  Muon outMu{p4, (int)muItr->ptIndex(), (int)muItr->etaIndex(), (int)muItr->phiIndex(), (int)muItr->quality(), muItr->charge(), muItr->isol(), (int)muItr->etaRegionIndex(), 0, true, 0, 0, 0 , (int)muItr->rank() };
184  imdMuonsLegacy->push_back( muItr->bx(), outMu ) ;
185  }
186  }
187  }
188  }
189 
190  iEvent.put( std::move(imdMuonsLegacy), "imdMuonsLegacy" );
191 
192 } // closing produce
193 
194 //define this as a plug-in
196 
#define LogDebug(id)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
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:457
#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:10
L1TMuonLegacyConverter(const edm::ParameterSet &)
static const double muonMassGeV_
const T & get() const
Definition: EventSetup.h:56
HLT enums.
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
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