test
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  // Make sure that you can get genParticles
114  std::map<int, MuonCaloSum> sums;
115  std::map<int, MuonCaloSum> regs;
116 
117  if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
118  for (auto it = caloTowers->begin(0); it != caloTowers->end(0); ++it) {
119  const CaloTower& twr = *it;
120  if (std::abs(twr.hwEta()) > 27) {
121  continue;
122  }
123  int ieta2x2 = (twr.hwEta() + 27) / 2;
124  int iphi2x2 = twr.hwPhi() / 2;
125  int muon_idx = iphi2x2 * 28 + ieta2x2;
126  if (regs.count(muon_idx) == 0) {
127  regs[muon_idx] = MuonCaloSum(twr.hwPt(), iphi2x2, ieta2x2, muon_idx);
128  } else {
129  regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + twr.hwPt());
130  }
131 
132  // std::cout << "iphi; phi " << twr.hwPhi() << "; " << twr.phi() << " .. ieta; eta" << twr.hwEta() << "; " << twr.eta() << std::endl;
133 
134  for (int ieta = -27; ieta < 28; ++ieta) {
135  for (int iphi = 0; iphi < 72; ++iphi) {
136  int deta = std::abs(ieta - twr.hwEta());
137  int dphi = iphi - twr.hwPhi();
138  if (dphi > 36) {
139  dphi -= 72;
140  }
141  if (dphi < -36) {
142  dphi += 72;
143  }
144  dphi = std::abs(dphi);
145  if (deta <= 4 && dphi <= 4) {
146  int ietamu = (ieta + 27) / 2;
147  int iphimu = iphi / 2;
148  int idxmu = iphimu * 28 + ietamu;
149  if (sums.count(idxmu) == 0) {
150  sums[idxmu] = MuonCaloSum(twr.hwPt(), iphimu, ietamu, idxmu);
151  } else {
152  sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + twr.hwPt());
153  }
154  }
155 
156  }
157  }
158  }
159  } else {
160  LogError("GlobalMuon") << "CaloTowers not found." << std::endl;
161  }
162 
163  for (auto it = sums.begin(); it != sums.end(); ++it) {
164  if (it->second.etBits() > 0) {
165  MuonCaloSum sum = MuonCaloSum(it->second);
166  // convert Et to correct scale:
167  if (sum.etBits() > 31) {
168  sum.setEtBits(31);
169  }
170  towerSums->push_back(0, sum);
171  }
172  }
173  for (auto it = regs.begin(); it != regs.end(); ++it) {
174  if (it->second.etBits() > 0) {
175  tower2x2s->push_back(0, it->second);
176  }
177  }
178 
179  iEvent.put(towerSums, "TriggerTowerSums");
180  iEvent.put(tower2x2s, "TriggerTower2x2s");
181 
182 }
183 
184 // ------------ method called once each job just before starting event loop ------------
185 void
187 {
188 }
189 
190 // ------------ method called once each job just after ending the event loop ------------
191 void
193 }
194 
195 // ------------ method called when starting to processes a run ------------
196 void
198 {
199 }
200 
201 // ------------ method called when ending the processing of a run ------------
202 void
204 {
205 }
206 
207 // ------------ method called when starting to processes a luminosity block ------------
208 void
210 {
211 }
212 
213 // ------------ method called when ending the processing of a luminosity block ------------
214 void
216 {
217 }
218 
219 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
220 void
222  //The following says we do not know what parameters are allowed so do no validation
223  // Please change this to state exactly what you do use, even if it is no parameters
225  desc.setUnknown();
226  descriptions.addDefault(desc);
227 }
228 
229 //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