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:
51  ~L1TMuonCaloSumProducer() override;
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55  private:
56  void produce(edm::Event&, const edm::EventSetup&) override ;
57 
58  void beginRun(const edm::Run&, edm::EventSetup const&) override ;
59  void endRun(const edm::Run&, edm::EventSetup const&) override ;
60  void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
61  void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override ;
62 
65 
66 };
67 
68 //
69 // constants, enums and typedefs
70 //
71 
72 
73 //
74 // static data member definitions
75 //
76 
77 //
78 // constructors and destructor
79 //
81  //register your inputs:
82  m_caloLabel = iConfig.getParameter<edm::InputTag> ("caloStage2Layer2Label");
83  m_caloTowerToken = consumes <CaloTowerBxCollection> (m_caloLabel);
84  //register your products
85  produces<MuonCaloSumBxCollection>("TriggerTowerSums");
86  produces<MuonCaloSumBxCollection>("TriggerTower2x2s");
87 }
88 
89 
91 {
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 }
95 
96 
97 //
98 // member functions
99 //
100 
101 
102 // ------------ method called to produce the data ------------
103 void
105 {
106  using namespace edm;
107  std::unique_ptr<MuonCaloSumBxCollection> towerSums (std::make_unique<MuonCaloSumBxCollection>());
108  std::unique_ptr<MuonCaloSumBxCollection> tower2x2s (std::make_unique<MuonCaloSumBxCollection>());
109 
111 
112  if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
113  int detamax = 4;
114  int dphimax = 4;
115 
116  const int iFirstBx = caloTowers->getFirstBX();
117  const int iLastBx = caloTowers->getLastBX();
118 
119  // set BX range for sums
120  towerSums->setBXRange(iFirstBx, iLastBx);
121  tower2x2s->setBXRange(iFirstBx, iLastBx);
122 
123  for (int bx = iFirstBx; bx <= iLastBx; ++bx) {
124  std::map<int, MuonCaloSum> sums;
125  std::map<int, MuonCaloSum> regs;
126 
127  for (auto it = caloTowers->begin(bx); it != caloTowers->end(bx); ++it) {
128  const CaloTower& twr = *it;
129  int hwEta = twr.hwEta();
130  if (std::abs(hwEta) > 27) {
131  continue;
132  }
133  int hwPt = twr.hwPt();
134  if (hwPt < 1) {
135  continue;
136  }
137  int hwPhi = twr.hwPhi();
138 
139  // calculating tower2x2s
140  int ieta2x2 = (hwEta + 27) / 2;
141  int iphi2x2 = hwPhi / 2;
142  int muon_idx = iphi2x2 * 28 + ieta2x2;
143  if (regs.count(muon_idx) == 0) {
144  regs[muon_idx] = MuonCaloSum(hwPt, iphi2x2, ieta2x2, muon_idx);
145  } else {
146  regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + hwPt);
147  }
148 
149  // std::cout << "iphi; phi " << hwPhi << "; " << phi << " .. ieta; eta" << hwEta << "; " << twr.eta() << std::endl;
150 
151  // calculating towerSums
152  int ietamax = hwEta + detamax + 1;
153  for (int ieta = hwEta-detamax; ieta < ietamax; ++ieta) {
154  if (std::abs(ieta) > 27) {
155  continue;
156  }
157  int ietamu = (ieta + 27) / 2;
158  int iphimax = hwPhi + dphimax + 1;
159  for (int iphi = hwPhi-dphimax; iphi < iphimax; ++iphi) {
160  int iphiwrapped = iphi;
161  if (iphiwrapped < 0) {
162  iphiwrapped += 72;
163  } else if (iphiwrapped > 71) {
164  iphiwrapped -= 72;
165  }
166  int iphimu = iphiwrapped / 2;
167  int idxmu = iphimu * 28 + ietamu;
168  if (sums.count(idxmu) == 0) {
169  sums[idxmu] = MuonCaloSum(hwPt, iphimu, ietamu, idxmu);
170  } else {
171  sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + hwPt);
172  }
173  }
174  }
175  }
176 
177  // fill towerSums output collection for this BX
178  for (auto it = sums.begin(); it != sums.end(); ++it) {
179  if (it->second.etBits() > 0) {
180  MuonCaloSum sum = MuonCaloSum(it->second);
181  // convert Et to correct scale:
182  if (sum.etBits() > 31) {
183  sum.setEtBits(31);
184  }
185  towerSums->push_back(bx, sum);
186  }
187  }
188  // fill tower2x2s output collection for this BX
189  for (auto it = regs.begin(); it != regs.end(); ++it) {
190  if (it->second.etBits() > 0) {
191  tower2x2s->push_back(bx, it->second);
192  }
193  }
194  }
195  } else {
196  LogWarning("GlobalMuon") << "CaloTowers not found. Producing empty collections." << std::endl;
197  }
198 
199  iEvent.put(std::move(towerSums), "TriggerTowerSums");
200  iEvent.put(std::move(tower2x2s), "TriggerTower2x2s");
201 
202 }
203 
204 // ------------ method called when starting to processes a run ------------
205 void
207 {
208 }
209 
210 // ------------ method called when ending the processing of a run ------------
211 void
213 {
214 }
215 
216 // ------------ method called when starting to processes a luminosity block ------------
217 void
219 {
220 }
221 
222 // ------------ method called when ending the processing of a luminosity block ------------
223 void
225 {
226 }
227 
228 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
229 void
231  //The following says we do not know what parameters are allowed so do no validation
232  // Please change this to state exactly what you do use, even if it is no parameters
234  desc.setUnknown();
235  descriptions.addDefault(desc);
236 }
237 
238 //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:137
void endRun(const edm::Run &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#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
L1TMuonCaloSumProducer(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
void beginLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
void produce(edm::Event &, const edm::EventSetup &) override
void setEtBits(int bits)
Definition: MuonCaloSum.h:17
void beginRun(const edm::Run &, edm::EventSetup const &) override
int getFirstBX() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int hwPt() const
Definition: L1Candidate.h:48
void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
HLT enums.
int getLastBX() const
const_iterator begin(int bx) const
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:44
const int etBits() const
Definition: MuonCaloSum.h:22