CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TMicroGMTCaloInputProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TMicroGMTCaloInputProducer
4 // Class: L1TMicroGMTCaloInputProducer
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 
38 
39 #include "TMath.h"
40 #include "TRandom3.h"
41 
42 //
43 // class declaration
44 //
45 using namespace l1t;
46 
48  public:
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54  private:
55  virtual void beginJob() ;
56  virtual void produce(edm::Event&, const edm::EventSetup&);
57  virtual void endJob() ;
58 
59  virtual void beginRun(edm::Run&, edm::EventSetup const&);
60  virtual void endRun(edm::Run&, edm::EventSetup const&);
61  virtual void beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
62  virtual void endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
63 
66 
67 };
68 
69 //
70 // constants, enums and typedefs
71 //
72 
73 
74 //
75 // static data member definitions
76 //
77 
78 //
79 // constructors and destructor
80 //
82  //register your inputs:
83  m_caloLabel = iConfig.getParameter<edm::InputTag> ("caloStage2Layer2Label");
84  m_caloTowerToken = consumes <CaloTowerBxCollection> (m_caloLabel);
85  //register your products
86  produces<GMTInputCaloSumBxCollection>("TriggerTowerSums");
87  produces<GMTInputCaloSumBxCollection>("TriggerTower2x2s");
88 }
89 
90 
92 {
93  // do anything here that needs to be done at desctruction time
94  // (e.g. close files, deallocate resources etc.)
95 }
96 
97 
98 //
99 // member functions
100 //
101 
102 
103 // ------------ method called to produce the data ------------
104 void
106 {
107  using namespace edm;
108  std::auto_ptr<GMTInputCaloSumBxCollection> towerSums (new GMTInputCaloSumBxCollection());
109  std::auto_ptr<GMTInputCaloSumBxCollection> tower2x2s (new GMTInputCaloSumBxCollection());
110 
112  // Make sure that you can get genParticles
113  std::map<int, GMTInputCaloSum> sums;
114  std::map<int, GMTInputCaloSum> regs;
115 
116  if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
117  for (auto it = caloTowers->begin(0); it != caloTowers->end(0); ++it) {
118  const CaloTower& twr = *it;
119  if (std::abs(twr.hwEta()) > 27) {
120  continue;
121  }
122  int ieta2x2 = (twr.hwEta() + 27) / 2;
123  int iphi2x2 = twr.hwPhi() / 2;
124  int muon_idx = iphi2x2 * 28 + ieta2x2;
125  if (regs.count(muon_idx) == 0) {
126  regs[muon_idx] = GMTInputCaloSum(twr.hwPt(), iphi2x2, ieta2x2, muon_idx);
127  } else {
128  regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + twr.hwPt());
129  }
130 
131  // std::cout << "iphi; phi " << twr.hwPhi() << "; " << twr.phi() << " .. ieta; eta" << twr.hwEta() << "; " << twr.eta() << std::endl;
132 
133  for (int ieta = -27; ieta < 28; ++ieta) {
134  for (int iphi = 0; iphi < 72; ++iphi) {
135  int deta = std::abs(ieta - twr.hwEta());
136  int dphi = iphi - twr.hwPhi();
137  if (dphi > 36) {
138  dphi -= 72;
139  }
140  if (dphi < -36) {
141  dphi += 72;
142  }
143  dphi = std::abs(dphi);
144  if (deta <= 4 && dphi <= 4) {
145  int ietamu = (ieta + 27) / 2;
146  int iphimu = iphi / 2;
147  int idxmu = iphimu * 28 + ietamu;
148  if (sums.count(idxmu) == 0) {
149  sums[idxmu] = GMTInputCaloSum(twr.hwPt(), iphimu, ietamu, idxmu);
150  } else {
151  sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + twr.hwPt());
152  }
153  }
154 
155  }
156  }
157  }
158  } else {
159  LogError("GlobalMuon") << "CaloTowers not found." << std::endl;
160  }
161 
162  for (auto it = sums.begin(); it != sums.end(); ++it) {
163  if (it->second.etBits() > 0) {
164  GMTInputCaloSum sum = GMTInputCaloSum(it->second);
165  // convert Et to correct scale:
166  if (sum.etBits() > 31) {
167  sum.setEtBits(31);
168  }
169  towerSums->push_back(0, sum);
170  }
171  }
172  for (auto it = regs.begin(); it != regs.end(); ++it) {
173  if (it->second.etBits() > 0) {
174  tower2x2s->push_back(0, it->second);
175  }
176  }
177 
178  iEvent.put(towerSums, "TriggerTowerSums");
179  iEvent.put(tower2x2s, "TriggerTower2x2s");
180 
181 }
182 
183 // ------------ method called once each job just before starting event loop ------------
184 void
186 {
187 }
188 
189 // ------------ method called once each job just after ending the event loop ------------
190 void
192 }
193 
194 // ------------ method called when starting to processes a run ------------
195 void
197 {
198 }
199 
200 // ------------ method called when ending the processing of a run ------------
201 void
203 {
204 }
205 
206 // ------------ method called when starting to processes a luminosity block ------------
207 void
209 {
210 }
211 
212 // ------------ method called when ending the processing of a luminosity block ------------
213 void
215 {
216 }
217 
218 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
219 void
221  //The following says we do not know what parameters are allowed so do no validation
222  // Please change this to state exactly what you do use, even if it is no parameters
224  desc.setUnknown();
225  descriptions.addDefault(desc);
226 }
227 
228 //define this as a plug-in
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
virtual void endRun(edm::Run &, edm::EventSetup const &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int hwPhi() const
Definition: L1Candidate.cc:79
void setEtBits(int bits)
void beginJob()
Definition: Breakpoints.cc:15
virtual void endLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
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:120
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int hwEta() const
Definition: L1Candidate.cc:74
virtual void produce(edm::Event &, const edm::EventSetup &)
BXVector< GMTInputCaloSum > GMTInputCaloSumBxCollection
virtual void beginRun(edm::Run &, edm::EventSetup const &)
int hwPt() const
Definition: L1Candidate.cc:69
const int etBits() const
edm::EDGetTokenT< CaloTowerBxCollection > m_caloTowerToken
L1TMicroGMTCaloInputProducer(const edm::ParameterSet &)
Definition: Run.h:43