CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 // system include files
21 #include <memory>
22 #include <fstream>
23 
24 // user include files
27 
30 
34 
38 
39 #include "TMath.h"
40 #include "TRandom3.h"
41 
42 //
43 // class declaration
44 //
45 using namespace l1t;
46 
48 public:
50  ~L1TMuonCaloSumProducer() override;
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  void produce(edm::Event&, const edm::EventSetup&) override;
56 
57  void beginRun(const edm::Run&, edm::EventSetup const&) override;
58  void endRun(const edm::Run&, edm::EventSetup const&) override;
59  void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
60  void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
61 
64 };
65 
66 //
67 // constants, enums and typedefs
68 //
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
78  //register your inputs:
79  m_caloLabel = iConfig.getParameter<edm::InputTag>("caloStage2Layer2Label");
80  m_caloTowerToken = consumes<CaloTowerBxCollection>(m_caloLabel);
81  //register your products
82  produces<MuonCaloSumBxCollection>("TriggerTowerSums");
83  produces<MuonCaloSumBxCollection>("TriggerTower2x2s");
84 }
85 
87  // do anything here that needs to be done at desctruction time
88  // (e.g. close files, deallocate resources etc.)
89 }
90 
91 //
92 // member functions
93 //
94 
95 // ------------ method called to produce the data ------------
97  using namespace edm;
98  std::unique_ptr<MuonCaloSumBxCollection> towerSums(std::make_unique<MuonCaloSumBxCollection>());
99  std::unique_ptr<MuonCaloSumBxCollection> tower2x2s(std::make_unique<MuonCaloSumBxCollection>());
100 
102 
103  if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
104  int detamax = 4;
105  int dphimax = 4;
106 
107  const int iFirstBx = caloTowers->getFirstBX();
108  const int iLastBx = caloTowers->getLastBX();
109 
110  // set BX range for sums
111  towerSums->setBXRange(iFirstBx, iLastBx);
112  tower2x2s->setBXRange(iFirstBx, iLastBx);
113 
114  for (int bx = iFirstBx; bx <= iLastBx; ++bx) {
115  std::map<int, MuonCaloSum> sums;
116  std::map<int, MuonCaloSum> regs;
117 
118  for (auto it = caloTowers->begin(bx); it != caloTowers->end(bx); ++it) {
119  const CaloTower& twr = *it;
120  int hwEta = twr.hwEta();
121  if (std::abs(hwEta) > 27) {
122  continue;
123  }
124  int hwPt = twr.hwPt();
125  if (hwPt < 1) {
126  continue;
127  }
128  int hwPhi = twr.hwPhi();
129 
130  // calculating tower2x2s
131  int ieta2x2 = (hwEta + 27) / 2;
132  int iphi2x2 = hwPhi / 2;
133  int muon_idx = iphi2x2 * 28 + ieta2x2;
134  if (regs.count(muon_idx) == 0) {
135  regs[muon_idx] = MuonCaloSum(hwPt, iphi2x2, ieta2x2, muon_idx);
136  } else {
137  regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + hwPt);
138  }
139 
140  // std::cout << "iphi; phi " << hwPhi << "; " << phi << " .. ieta; eta" << hwEta << "; " << twr.eta() << std::endl;
141 
142  // calculating towerSums
143  int ietamax = hwEta + detamax + 1;
144  for (int ieta = hwEta - detamax; ieta < ietamax; ++ieta) {
145  if (std::abs(ieta) > 27) {
146  continue;
147  }
148  int ietamu = (ieta + 27) / 2;
149  int iphimax = hwPhi + dphimax + 1;
150  for (int iphi = hwPhi - dphimax; iphi < iphimax; ++iphi) {
151  int iphiwrapped = iphi;
152  if (iphiwrapped < 0) {
153  iphiwrapped += 72;
154  } else if (iphiwrapped > 71) {
155  iphiwrapped -= 72;
156  }
157  int iphimu = iphiwrapped / 2;
158  int idxmu = iphimu * 28 + ietamu;
159  if (sums.count(idxmu) == 0) {
160  sums[idxmu] = MuonCaloSum(hwPt, iphimu, ietamu, idxmu);
161  } else {
162  sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + hwPt);
163  }
164  }
165  }
166  }
167 
168  // fill towerSums output collection for this BX
169  for (auto it = sums.begin(); it != sums.end(); ++it) {
170  if (it->second.etBits() > 0) {
171  MuonCaloSum sum = MuonCaloSum(it->second);
172  // convert Et to correct scale:
173  if (sum.etBits() > 31) {
174  sum.setEtBits(31);
175  }
176  towerSums->push_back(bx, sum);
177  }
178  }
179  // fill tower2x2s output collection for this BX
180  for (auto it = regs.begin(); it != regs.end(); ++it) {
181  if (it->second.etBits() > 0) {
182  tower2x2s->push_back(bx, it->second);
183  }
184  }
185  }
186  } else {
187  LogWarning("GlobalMuon") << "CaloTowers not found. Producing empty collections." << std::endl;
188  }
189 
190  iEvent.put(std::move(towerSums), "TriggerTowerSums");
191  iEvent.put(std::move(tower2x2s), "TriggerTower2x2s");
192 }
193 
194 // ------------ method called when starting to processes a run ------------
196 
197 // ------------ method called when ending the processing of a run ------------
199 
200 // ------------ method called when starting to processes a luminosity block ------------
202 
203 // ------------ method called when ending the processing of a luminosity block ------------
205 
206 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
208  //The following says we do not know what parameters are allowed so do no validation
209  // Please change this to state exactly what you do use, even if it is no parameters
211  desc.setUnknown();
212  descriptions.addDefault(desc);
213 }
214 
215 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void endRun(const edm::Run &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< CaloTowerBxCollection > m_caloTowerToken
int hwPhi() const
Definition: L1Candidate.h:37
L1TMuonCaloSumProducer(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int hwEta() const
Definition: L1Candidate.h:36
void beginLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
void produce(edm::Event &, const edm::EventSetup &) override
void setEtBits(int bits)
Definition: MuonCaloSum.h:15
void beginRun(const edm::Run &, edm::EventSetup const &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int hwPt() const
Definition: L1Candidate.h:35
void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Log< level::Warning, false > LogWarning
Definition: Run.h:45
const int etBits() const
Definition: MuonCaloSum.h:20