CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TMuonCaloSumProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TMuonCaloSumProducer
4 // Class: L1TMuonCaloSumProducer
5 //
13 //
14 // Original Author: Joschka Philip Lingemann,40 3-B01,+41227671598,
15 // Created: Thu Oct 3 10:12:30 CEST 2013
16 // $Id$
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <fstream>
24 
25 // user include files
28 
31 
35 
39 
40 #include "TMath.h"
41 #include "TRandom3.h"
42 
43 //
44 // class declaration
45 //
46 using namespace l1t;
47 
49  public:
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55  private:
56  virtual void beginJob() override ;
57  virtual void produce(edm::Event&, const edm::EventSetup&) override ;
58  virtual void endJob() override ;
59 
60  virtual void beginRun(const edm::Run&, edm::EventSetup const&) override ;
61  virtual void endRun(const edm::Run&, edm::EventSetup const&) override ;
62  virtual void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
63  virtual void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
64 
67 
68 };
69 
70 //
71 // constants, enums and typedefs
72 //
73 
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83  //register your inputs:
84  m_caloLabel = iConfig.getParameter<edm::InputTag> ("caloStage2Layer2Label");
85  m_caloTowerToken = consumes <CaloTowerBxCollection> (m_caloLabel);
86  //register your products
87  produces<MuonCaloSumBxCollection>("TriggerTowerSums");
88  produces<MuonCaloSumBxCollection>("TriggerTower2x2s");
89 }
90 
91 
93 {
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 }
97 
98 
99 //
100 // member functions
101 //
102 
103 
104 // ------------ method called to produce the data ------------
105 void
107 {
108  using namespace edm;
109  std::auto_ptr<MuonCaloSumBxCollection> towerSums (new MuonCaloSumBxCollection());
110  std::auto_ptr<MuonCaloSumBxCollection> tower2x2s (new MuonCaloSumBxCollection());
111 
113 
114  if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
115  int detamax = 4;
116  int dphimax = 4;
117 
118  for (int bx = caloTowers->getFirstBX(); bx <= caloTowers->getLastBX(); ++bx) {
119  std::map<int, MuonCaloSum> sums;
120  std::map<int, MuonCaloSum> regs;
121 
122  for (auto it = caloTowers->begin(bx); it != caloTowers->end(bx); ++it) {
123  const CaloTower& twr = *it;
124  int hwEta = twr.hwEta();
125  if (std::abs(hwEta) > 27) {
126  continue;
127  }
128  int hwPt = twr.hwPt();
129  if (hwPt < 1) {
130  continue;
131  }
132  int hwPhi = twr.hwPhi();
133 
134  // calculating tower2x2s
135  int ieta2x2 = (hwEta + 27) / 2;
136  int iphi2x2 = hwPhi / 2;
137  int muon_idx = iphi2x2 * 28 + ieta2x2;
138  if (regs.count(muon_idx) == 0) {
139  regs[muon_idx] = MuonCaloSum(hwPt, iphi2x2, ieta2x2, muon_idx);
140  } else {
141  regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + hwPt);
142  }
143 
144  // std::cout << "iphi; phi " << hwPhi << "; " << phi << " .. ieta; eta" << hwEta << "; " << twr.eta() << std::endl;
145 
146  // calculating towerSums
147  int ietamax = hwEta + detamax + 1;
148  for (int ieta = hwEta-detamax; ieta < ietamax; ++ieta) {
149  if (std::abs(ieta) > 27) {
150  continue;
151  }
152  int ietamu = (ieta + 27) / 2;
153  int iphimax = hwPhi + dphimax + 1;
154  for (int iphi = hwPhi-dphimax; iphi < iphimax; ++iphi) {
155  int iphiwrapped = iphi;
156  if (iphiwrapped < 0) {
157  iphiwrapped += 72;
158  } else if (iphiwrapped > 71) {
159  iphiwrapped -= 72;
160  }
161  int iphimu = iphiwrapped / 2;
162  int idxmu = iphimu * 28 + ietamu;
163  if (sums.count(idxmu) == 0) {
164  sums[idxmu] = MuonCaloSum(hwPt, iphimu, ietamu, idxmu);
165  } else {
166  sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + hwPt);
167  }
168  }
169  }
170  }
171 
172  // fill towerSums output collection for this BX
173  for (auto it = sums.begin(); it != sums.end(); ++it) {
174  if (it->second.etBits() > 0) {
175  MuonCaloSum sum = MuonCaloSum(it->second);
176  // convert Et to correct scale:
177  if (sum.etBits() > 31) {
178  sum.setEtBits(31);
179  }
180  towerSums->push_back(bx, sum);
181  }
182  }
183  // fill tower2x2s output collection for this BX
184  for (auto it = regs.begin(); it != regs.end(); ++it) {
185  if (it->second.etBits() > 0) {
186  tower2x2s->push_back(bx, it->second);
187  }
188  }
189  }
190  } else {
191  LogWarning("GlobalMuon") << "CaloTowers not found. Producing empty collections." << std::endl;
192  }
193 
194  iEvent.put(towerSums, "TriggerTowerSums");
195  iEvent.put(tower2x2s, "TriggerTower2x2s");
196 
197 }
198 
199 // ------------ method called once each job just before starting event loop ------------
200 void
202 {
203 }
204 
205 // ------------ method called once each job just after ending the event loop ------------
206 void
208 }
209 
210 // ------------ method called when starting to processes a run ------------
211 void
213 {
214 }
215 
216 // ------------ method called when ending the processing of a run ------------
217 void
219 {
220 }
221 
222 // ------------ method called when starting to processes a luminosity block ------------
223 void
225 {
226 }
227 
228 // ------------ method called when ending the processing of a luminosity block ------------
229 void
231 {
232 }
233 
234 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
235 void
237  //The following says we do not know what parameters are allowed so do no validation
238  // Please change this to state exactly what you do use, even if it is no parameters
240  desc.setUnknown();
241  descriptions.addDefault(desc);
242 }
243 
244 //define this as a plug-in
T getParameter(std::string const &) const
virtual void endRun(const edm::Run &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
BXVector< MuonCaloSum > MuonCaloSumBxCollection
Definition: MuonCaloSumFwd.h:7
edm::EDGetTokenT< CaloTowerBxCollection > m_caloTowerToken
int hwPhi() const
Definition: L1Candidate.h:50
void beginJob()
Definition: Breakpoints.cc:15
L1TMuonCaloSumProducer(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void endJob() override
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int hwEta() const
Definition: L1Candidate.h:49
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
virtual void produce(edm::Event &, const edm::EventSetup &) override
void setEtBits(int bits)
Definition: MuonCaloSum.h:17
virtual void beginRun(const edm::Run &, edm::EventSetup const &) override
int hwPt() const
Definition: L1Candidate.h:48
virtual void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
virtual void beginJob() override
Definition: Run.h:43
const int etBits() const
Definition: MuonCaloSum.h:22