test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TMicroGMTProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TMicroGMTProducer
4 // Class: L1TMicroGMTProducer
5 //
13 //
14 // Original Author: Joschka Philip Lingemann,40 3-B01,+41227671598,
15 // Created: Thu Oct 3 16:31:34 CEST 2013
16 // $Id$
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <fstream>
24 #include <sstream>
25 
26 
27 // user include files
30 
33 
35 
40 
45 
46 #include "TMath.h"
47 //
48 // class declaration
49 //
50 using namespace l1t;
51 
53  public:
54  explicit L1TMicroGMTProducer(const edm::ParameterSet&);
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59  private:
60  virtual void beginJob() ;
61  virtual void produce(edm::Event&, const edm::EventSetup&);
62  virtual void endJob() ;
63 
64  virtual void beginRun(edm::Run&, edm::EventSetup const&);
65  virtual void endRun(edm::Run&, edm::EventSetup const&);
66  virtual void beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
67  virtual void endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
68 
69  static bool compareMuons(const std::shared_ptr<MicroGMTConfiguration::InterMuon>& mu1,
70  const std::shared_ptr<MicroGMTConfiguration::InterMuon>& mu2);
71 
72  void sortMuons(MicroGMTConfiguration::InterMuonList&, unsigned) const;
73 
74  void calculateRank(MicroGMTConfiguration::InterMuonList& muons) const;
75 
76  void splitAndConvertMuons(edm::Handle<MicroGMTConfiguration::InputCollection> const& in,
79  GMTInternalWedges& wedges_pos,
80  GMTInternalWedges& wedges_neg,
81  int bx) const;
82 
83  void convertMuons(edm::Handle<MicroGMTConfiguration::InputCollection> const& in,
85  GMTInternalWedges& wedges,
86  int bx) const;
87 
88  void addMuonsToCollections(MicroGMTConfiguration::InterMuonList& coll,
90  std::auto_ptr<MuonBxCollection>& out,
91  int bx) const;
92 
93  // ----------member data ---------------------------
101  std::ofstream m_debugOut;
102 
107 
108  };
109 
110 //
111 // constants, enums and typedefs
112 //
113 
114 
115 //
116 // static data member definitions
117 //
118 
119 //
120 // constructors and destructor
121 //
122 L1TMicroGMTProducer::L1TMicroGMTProducer(const edm::ParameterSet& iConfig) : m_rankPtQualityLUT(iConfig), m_isolationUnit(iConfig), m_cancelOutUnit(iConfig), m_debugOut("test/debug/iso_debug.dat")
123 {
124  // edm::InputTag barrelTfInputTag = iConfig.getParameter<edm::InputTag>("barrelTFInput");
125  // edm::InputTag overlapTfInputTag = iConfig.getParameter<edm::InputTag>("overlapTFInput");
126  // edm::InputTag forwardTfInputTag = iConfig.getParameter<edm::InputTag>("forwardTFInput");
127 
128  m_barrelTfInputTag = iConfig.getParameter<edm::InputTag>("barrelTFInput");
129  m_overlapTfInputTag = iConfig.getParameter<edm::InputTag>("overlapTFInput");
130  m_endcapTfInputTag = iConfig.getParameter<edm::InputTag>("forwardTFInput");
131  m_trigTowerTag = iConfig.getParameter<edm::InputTag>("triggerTowerInput");
132 
133  m_barrelTfInputToken = consumes<MicroGMTConfiguration::InputCollection>(m_barrelTfInputTag);
134  m_overlapTfInputToken = consumes<MicroGMTConfiguration::InputCollection>(m_overlapTfInputTag);
135  m_endcapTfInputToken = consumes<MicroGMTConfiguration::InputCollection>(m_endcapTfInputTag);
136  m_caloTowerInputToken = consumes<MicroGMTConfiguration::CaloInputCollection>(m_trigTowerTag);
137 
138  //register your products
139  produces<MuonBxCollection>();
140  produces<MuonBxCollection>("imdMuonsBMTF");
141  produces<MuonBxCollection>("imdMuonsEMTFPos");
142  produces<MuonBxCollection>("imdMuonsEMTFNeg");
143  produces<MuonBxCollection>("imdMuonsOMTFPos");
144  produces<MuonBxCollection>("imdMuonsOMTFNeg");
145 
146 
147 
148 }
149 
151 {
152  m_debugOut.close();
153 }
154 
155 
156 //
157 // member functions
158 //
159 
160 
161 
162 // ------------ method called to produce the data ------------
163 void
165 {
166  using namespace edm;
167  std::auto_ptr<MuonBxCollection> outMuons (new MuonBxCollection());
168  std::auto_ptr<MuonBxCollection> imdMuonsBMTF (new MuonBxCollection());
169  std::auto_ptr<MuonBxCollection> imdMuonsEMTFPos (new MuonBxCollection());
170  std::auto_ptr<MuonBxCollection> imdMuonsEMTFNeg (new MuonBxCollection());
171  std::auto_ptr<MuonBxCollection> imdMuonsOMTFPos (new MuonBxCollection());
172  std::auto_ptr<MuonBxCollection> imdMuonsOMTFNeg (new MuonBxCollection());
173 
174 
179 
180  // iEvent.getByToken(m_barrelTfInputToken, bmtfMuons);
181  iEvent.getByToken(m_barrelTfInputToken, bmtfMuons);
182  iEvent.getByToken(m_endcapTfInputToken, emtfMuons);
183  iEvent.getByToken(m_overlapTfInputToken, omtfMuons);
184  iEvent.getByToken(m_caloTowerInputToken, trigTowers);
185 
186  int bx = 0;
187 
188  m_isolationUnit.setTowerSums(*trigTowers, bx);
189  MicroGMTConfiguration::InterMuonList internMuonsBmtf;
190  MicroGMTConfiguration::InterMuonList internMuonsEmtfPos;
191  MicroGMTConfiguration::InterMuonList internMuonsEmtfNeg;
192  MicroGMTConfiguration::InterMuonList internMuonsOmtfPos;
193  MicroGMTConfiguration::InterMuonList internMuonsOmtfNeg;
194 
195  // These wedges contain shared pointers to the ones in the InterMuonList
196  GMTInternalWedges omtfNegWedges;
197  GMTInternalWedges bmtfWedges;
198  GMTInternalWedges emtfPosWedges;
199  GMTInternalWedges emtfNegWedges;
200  GMTInternalWedges omtfPosWedges;
201 
202  // this converts the InputMuon type to the InternalMuon type and splits them into
203  // positive / negative eta collections necessary as LUTs may differ for pos / neg.
204  convertMuons(bmtfMuons, internMuonsBmtf, bmtfWedges, bx);
205  splitAndConvertMuons(emtfMuons, internMuonsEmtfPos, internMuonsEmtfNeg, emtfPosWedges, emtfNegWedges, bx);
206  splitAndConvertMuons(omtfMuons, internMuonsOmtfPos, internMuonsOmtfNeg, omtfPosWedges, omtfNegWedges, bx);
207 
208  // cancel out within the track finders:
212  // cancel-out for endcap will be done in the sorter
215 
216  // cancel out between track finder acceptance overlaps:
221 
222  m_isolationUnit.extrapolateMuons(internMuonsBmtf);
223  m_isolationUnit.extrapolateMuons(internMuonsEmtfNeg);
224  m_isolationUnit.extrapolateMuons(internMuonsEmtfPos);
225  m_isolationUnit.extrapolateMuons(internMuonsOmtfNeg);
226  m_isolationUnit.extrapolateMuons(internMuonsOmtfPos);
227 
228  // the rank calculated here is used in the sort below
229  calculateRank(internMuonsBmtf);
230  calculateRank(internMuonsEmtfNeg);
231  calculateRank(internMuonsEmtfPos);
232  calculateRank(internMuonsOmtfNeg);
233  calculateRank(internMuonsOmtfPos);
234 
235  // The sort function both sorts and removes all but best "nSurvivors"
236  sortMuons(internMuonsBmtf, 8);
237  sortMuons(internMuonsOmtfPos, 4);
238  sortMuons(internMuonsOmtfNeg, 4);
239  sortMuons(internMuonsEmtfPos, 4);
240  sortMuons(internMuonsEmtfNeg, 4);
241 
242  // This combines the 5 streams into one InternalMuon collection for
243  // the final global sort.
245  addMuonsToCollections(internMuonsEmtfPos, internalMuons, imdMuonsEMTFPos, bx);
246  addMuonsToCollections(internMuonsOmtfPos, internalMuons, imdMuonsOMTFPos, bx);
247  addMuonsToCollections(internMuonsBmtf, internalMuons, imdMuonsBMTF, bx);
248  addMuonsToCollections(internMuonsOmtfNeg, internalMuons, imdMuonsOMTFNeg, bx);
249  addMuonsToCollections(internMuonsEmtfNeg, internalMuons, imdMuonsEMTFNeg, bx);
250 
251  // sort internal muons and delete all but best 8
252  sortMuons(internalMuons, 8);
253 
254  m_isolationUnit.isolatePreSummed(internalMuons);
255  // copy muons to output collection...
256  for (const auto& mu : internalMuons) {
257  if (mu->hwPt() > 0) {
258  math::PtEtaPhiMLorentzVector vec{mu->hwPt()*0.5, mu->hwEta()*0.010875, mu->hwGlobalPhi()*0.010908, 0.0};
259  int iso = mu->hwAbsIso() + (mu->hwRelIso() << 1);
260  Muon outMu{vec, mu->hwPt(), mu->hwEta(), mu->hwGlobalPhi(), mu->hwQual(), mu->hwSign(), mu->hwSignValid(), iso, 0, true, mu->hwIsoSum(), mu->hwDPhi(), mu->hwDEta(), mu->hwRank()};
261  m_debugOut << mu->hwCaloPhi() << " " << mu->hwCaloEta() << std::endl;
262  outMuons->push_back(bx, outMu);
263  }
264  }
265 
266 
267  iEvent.put(outMuons);
268  iEvent.put(imdMuonsBMTF, "imdMuonsBMTF");
269  iEvent.put(imdMuonsEMTFPos, "imdMuonsEMTFPos");
270  iEvent.put(imdMuonsEMTFNeg, "imdMuonsEMTFNeg");
271  iEvent.put(imdMuonsOMTFPos, "imdMuonsOMTFPos");
272  iEvent.put(imdMuonsOMTFNeg, "imdMuonsOMTFNeg");
273 }
274 
275 
276 bool
277 L1TMicroGMTProducer::compareMuons(const std::shared_ptr<MicroGMTConfiguration::InterMuon>& mu1,
278  const std::shared_ptr<MicroGMTConfiguration::InterMuon>& mu2) {
279  return (mu1->hwWins() > mu2->hwWins());
280 }
281 
282 void
284  MicroGMTConfiguration::InterMuonList::iterator mu1;
285  // reset from previous sort stage
286  for (mu1 = muons.begin(); mu1 != muons.end(); ++mu1) {
287  (*mu1)->setHwWins(0);
288  }
289 
290  for (mu1 = muons.begin(); mu1 != muons.end(); ++mu1) {
291  auto mu2 = mu1;
292  mu2++;
293  for ( ; mu2 != muons.end(); ++mu2) {
294  if ((*mu1)->hwRank() >= (*mu2)->hwRank() && (*mu1)->hwCancelBit() != 1) {
295  (*mu1)->increaseWins();
296  } else if ((*mu2)->hwCancelBit() != 1) {
297  (*mu2)->increaseWins();
298  }
299  }
300  }
301 
302  size_t nMuonsBefore = muons.size();
303  mu1 = muons.begin();
304  int minWins = nMuonsBefore-nSurvivors;
305 
306  // remove all muons that were cancelled or that do not have sufficient rank
307  // (reduces the container size to nSurvivors)
308  while (mu1 != muons.end()) {
309  if ((*mu1)->hwWins() < minWins || (*mu1)->hwCancelBit() == 1) {
310  muons.erase(mu1);
311  }
312  ++mu1;
313  }
315 }
316 
317 
318 
319 void
321 {
322  for (auto& mu1 : muons) {
323  int rank = m_rankPtQualityLUT.lookup(mu1->hwPt(), mu1->hwQual());
324  mu1->setHwRank(rank);
325  }
326 }
327 
328 
329 void
332  std::auto_ptr<MuonBxCollection>& out, int bx) const
333 {
334  for (auto& mu : coll) {
335  interout.push_back(mu);
336  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > vec{};
337  // FIXME: once we debugged the change global -> local: Change hwLocalPhi -> hwGlobalPhi to test offsets
338  Muon outMu{vec, mu->hwPt(), mu->hwEta(), mu->hwGlobalPhi(), mu->hwQual(), mu->hwSign(), mu->hwSignValid(), -1, 0, true, -1, mu->hwDPhi(), mu->hwDEta(), mu->hwRank()};
339 
340  out->push_back(bx, outMu);
341  }
342 }
343 
344 void
348  GMTInternalWedges& wedges_pos,
349  GMTInternalWedges& wedges_neg,
350  int bx) const
351 {
352  // initialize the wedge collections:
353  for (int i = 0; i < 6; ++i) {
354  wedges_pos[i] = std::vector<std::shared_ptr<GMTInternalMuon>>();
355  wedges_pos[i].reserve(3);
356  wedges_neg[i] = std::vector<std::shared_ptr<GMTInternalMuon>>();
357  wedges_neg[i].reserve(3);
358  }
359  for (size_t i = 0; i < in->size(bx); ++i) {
360  int gPhi = MicroGMTConfiguration::calcGlobalPhi(in->at(bx, i).hwPhi(), in->at(bx, i).trackFinderType(), in->at(bx, i).processor());
361  std::shared_ptr<GMTInternalMuon> out = std::make_shared<GMTInternalMuon>(in->at(bx, i), gPhi);
362  if(in->at(bx, i).hwEta() > 0) {
363  out_pos.push_back(out);
364  wedges_pos[in->at(bx, i).processor()].push_back(out);
365  } else {
366  out_neg.emplace_back(out);
367  wedges_neg[in->at(bx, i).processor()].push_back(out);
368  }
369  }
370  for (int i = 0; i < 6; ++i) {
371  if(wedges_pos[i].size() > 3) edm::LogWarning("Input Mismatch") << " too many inputs per processor for emtf+ / omtf+" << std::endl;
372  if(wedges_neg[i].size() > 3) edm::LogWarning("Input Mismatch") << " too many inputs per processor for emtf- / omtf-" << std::endl;
373  }
374 }
375 
376 void
379  GMTInternalWedges& wedges, int bx) const
380 {
381  // initialize the wedge collection:
382  for (int i = 0; i < 12; ++i) {
383  wedges[i] = std::vector<std::shared_ptr<GMTInternalMuon>>();
384  wedges[i].reserve(3);
385  }
386  for (size_t i = 0; i < in->size(bx); ++i) {
387  int gPhi = MicroGMTConfiguration::calcGlobalPhi(in->at(bx, i).hwPhi(), in->at(bx, i).trackFinderType(), in->at(bx, i).processor());
388  std::shared_ptr<GMTInternalMuon> outMu = std::make_shared<GMTInternalMuon>(in->at(bx, i), gPhi);
389  out.emplace_back(outMu);
390  wedges[in->at(bx, i).processor()].push_back(outMu);
391  }
392  for (int i = 0; i < 12; ++i) {
393  if(wedges[i].size() > 3) edm::LogWarning("Input Mismatch") << " too many inputs per processor for barrel" << std::endl;
394  }
395 }
396 
397 // ------------ method called once each job just before starting event loop ------------
398 void
400 {
401 }
402 
403 // ------------ method called once each job just after ending the event loop ------------
404 void
406 }
407 
408 // ------------ method called when starting to processes a run ------------
409 void
411 {
412 }
413 
414 // ------------ method called when ending the processing of a run ------------
415 void
417 {
418 }
419 
420 // ------------ method called when starting to processes a luminosity block ------------
421 void
423 {
424 }
425 
426 // ------------ method called when ending the processing of a luminosity block ------------
427 void
429 {
430 }
431 
432 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
433 void
435  //The following says we do not know what parameters are allowed so do no validation
436  // Please change this to state exactly what you do use, even if it is no parameters
438  desc.setUnknown();
439  descriptions.addDefault(desc);
440 }
441 
442 //define this as a plug-in
virtual void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
MicroGMTIsolationUnit m_isolationUnit
void extrapolateMuons(MicroGMTConfiguration::InterMuonList &) const
void setCancelOutBitsOverlapEndcap(GMTInternalWedges &, GMTInternalWedges &, cancelmode)
Cancel-out between overlap and endcap track finders.
void setCancelOutBitsOverlapBarrel(GMTInternalWedges &, GMTInternalWedges &, cancelmode)
Cancel-out between overlap and barrel track finders.
edm::InputTag m_trigTowerTag
void sortMuons(MicroGMTConfiguration::InterMuonList &, unsigned) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
void setTowerSums(const MicroGMTConfiguration::CaloInputCollection &inputs, int bx)
edm::InputTag m_endcapTfInputTag
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MicroGMTRankPtQualLUT m_rankPtQualityLUT
edm::EDGetTokenT< MicroGMTConfiguration::InputCollection > m_endcapTfInputToken
edm::EDGetTokenT< MicroGMTConfiguration::InputCollection > m_overlapTfInputToken
void beginJob()
Definition: Breakpoints.cc:15
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static bool compareMuons(const std::shared_ptr< MicroGMTConfiguration::InterMuon > &mu1, const std::shared_ptr< MicroGMTConfiguration::InterMuon > &mu2)
MicroGMTCancelOutUnit m_cancelOutUnit
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int iEvent
Definition: GenABIO.cc:230
int lookup(int pt, int qual) const
void addDefault(ParameterSetDescription const &psetDescription)
void splitAndConvertMuons(edm::Handle< MicroGMTConfiguration::InputCollection > const &in, MicroGMTConfiguration::InterMuonList &out_pos, MicroGMTConfiguration::InterMuonList &out_neg, GMTInternalWedges &wedges_pos, GMTInternalWedges &wedges_neg, int bx) const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
virtual void endLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
virtual void endRun(edm::Run &, edm::EventSetup const &)
void calculateRank(MicroGMTConfiguration::InterMuonList &muons) const
const int mu
Definition: Constants.h:22
GMTInternalMuonList InterMuonList
void addMuonsToCollections(MicroGMTConfiguration::InterMuonList &coll, MicroGMTConfiguration::InterMuonList &interout, std::auto_ptr< MuonBxCollection > &out, int bx) const
Definition: Muon.h:12
tuple out
Definition: dbtoconf.py:99
BXVector< Muon > MuonBxCollection
Definition: Muon.h:9
void setCancelOutBits(GMTInternalWedges &, tftype, cancelmode)
Cancel out between sectors/wedges in one track finder.
JetCorrectorParametersCollection coll
Definition: classes.h:10
edm::InputTag m_overlapTfInputTag
virtual void produce(edm::Event &, const edm::EventSetup &)
virtual void beginRun(edm::Run &, edm::EventSetup const &)
edm::EDGetTokenT< MicroGMTConfiguration::CaloInputCollection > m_caloTowerInputToken
void convertMuons(edm::Handle< MicroGMTConfiguration::InputCollection > const &in, MicroGMTConfiguration::InterMuonList &out, GMTInternalWedges &wedges, int bx) const
tuple muons
Definition: patZpeak.py:38
std::map< int, std::vector< std::shared_ptr< GMTInternalMuon > > > GMTInternalWedges
edm::EDGetTokenT< MicroGMTConfiguration::InputCollection > m_barrelTfInputToken
void isolatePreSummed(MicroGMTConfiguration::InterMuonList &muons) const
L1TMicroGMTProducer(const edm::ParameterSet &)
tuple size
Write out results.
Definition: Run.h:43
edm::InputTag m_barrelTfInputTag