CMS 3D CMS Logo

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::unique_ptr<MuonCaloSumBxCollection> towerSums (std::make_unique<MuonCaloSumBxCollection>());
110  std::unique_ptr<MuonCaloSumBxCollection> tower2x2s (std::make_unique<MuonCaloSumBxCollection>());
111 
113 
114  if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
115  int detamax = 4;
116  int dphimax = 4;
117 
118  const int iFirstBx = caloTowers->getFirstBX();
119  const int iLastBx = caloTowers->getLastBX();
120 
121  // set BX range for sums
122  towerSums->setBXRange(iFirstBx, iLastBx);
123  tower2x2s->setBXRange(iFirstBx, iLastBx);
124 
125  for (int bx = iFirstBx; bx <= iLastBx; ++bx) {
126  std::map<int, MuonCaloSum> sums;
127  std::map<int, MuonCaloSum> regs;
128 
129  for (auto it = caloTowers->begin(bx); it != caloTowers->end(bx); ++it) {
130  const CaloTower& twr = *it;
131  int hwEta = twr.hwEta();
132  if (std::abs(hwEta) > 27) {
133  continue;
134  }
135  int hwPt = twr.hwPt();
136  if (hwPt < 1) {
137  continue;
138  }
139  int hwPhi = twr.hwPhi();
140 
141  // calculating tower2x2s
142  int ieta2x2 = (hwEta + 27) / 2;
143  int iphi2x2 = hwPhi / 2;
144  int muon_idx = iphi2x2 * 28 + ieta2x2;
145  if (regs.count(muon_idx) == 0) {
146  regs[muon_idx] = MuonCaloSum(hwPt, iphi2x2, ieta2x2, muon_idx);
147  } else {
148  regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + hwPt);
149  }
150 
151  // std::cout << "iphi; phi " << hwPhi << "; " << phi << " .. ieta; eta" << hwEta << "; " << twr.eta() << std::endl;
152 
153  // calculating towerSums
154  int ietamax = hwEta + detamax + 1;
155  for (int ieta = hwEta-detamax; ieta < ietamax; ++ieta) {
156  if (std::abs(ieta) > 27) {
157  continue;
158  }
159  int ietamu = (ieta + 27) / 2;
160  int iphimax = hwPhi + dphimax + 1;
161  for (int iphi = hwPhi-dphimax; iphi < iphimax; ++iphi) {
162  int iphiwrapped = iphi;
163  if (iphiwrapped < 0) {
164  iphiwrapped += 72;
165  } else if (iphiwrapped > 71) {
166  iphiwrapped -= 72;
167  }
168  int iphimu = iphiwrapped / 2;
169  int idxmu = iphimu * 28 + ietamu;
170  if (sums.count(idxmu) == 0) {
171  sums[idxmu] = MuonCaloSum(hwPt, iphimu, ietamu, idxmu);
172  } else {
173  sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + hwPt);
174  }
175  }
176  }
177  }
178 
179  // fill towerSums output collection for this BX
180  for (auto it = sums.begin(); it != sums.end(); ++it) {
181  if (it->second.etBits() > 0) {
182  MuonCaloSum sum = MuonCaloSum(it->second);
183  // convert Et to correct scale:
184  if (sum.etBits() > 31) {
185  sum.setEtBits(31);
186  }
187  towerSums->push_back(bx, sum);
188  }
189  }
190  // fill tower2x2s output collection for this BX
191  for (auto it = regs.begin(); it != regs.end(); ++it) {
192  if (it->second.etBits() > 0) {
193  tower2x2s->push_back(bx, it->second);
194  }
195  }
196  }
197  } else {
198  LogWarning("GlobalMuon") << "CaloTowers not found. Producing empty collections." << std::endl;
199  }
200 
201  iEvent.put(std::move(towerSums), "TriggerTowerSums");
202  iEvent.put(std::move(tower2x2s), "TriggerTower2x2s");
203 
204 }
205 
206 // ------------ method called once each job just before starting event loop ------------
207 void
209 {
210 }
211 
212 // ------------ method called once each job just after ending the event loop ------------
213 void
215 }
216 
217 // ------------ method called when starting to processes a run ------------
218 void
220 {
221 }
222 
223 // ------------ method called when ending the processing of a run ------------
224 void
226 {
227 }
228 
229 // ------------ method called when starting to processes a luminosity block ------------
230 void
232 {
233 }
234 
235 // ------------ method called when ending the processing of a luminosity block ------------
236 void
238 {
239 }
240 
241 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
242 void
244  //The following says we do not know what parameters are allowed so do no validation
245  // Please change this to state exactly what you do use, even if it is no parameters
247  desc.setUnknown();
248  descriptions.addDefault(desc);
249 }
250 
251 //define this as a plug-in
const_iterator end(int bx) const
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
virtual void endRun(const edm::Run &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< CaloTowerBxCollection > m_caloTowerToken
int hwPhi() const
Definition: L1Candidate.h:50
delete x;
Definition: CaloConfig.h:22
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)
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 getFirstBX() const
int hwPt() const
Definition: L1Candidate.h:48
virtual void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
virtual void beginJob() override
HLT enums.
int getLastBX() const
const_iterator begin(int bx) const
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:42
const int etBits() const
Definition: MuonCaloSum.h:22