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 // 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
Ecal2004TBTDCRanges_v1_cff.endRun
endRun
Definition: Ecal2004TBTDCRanges_v1_cff.py:4
L1TMuonCaloSumProducer::~L1TMuonCaloSumProducer
~L1TMuonCaloSumProducer() override
Definition: L1TMuonCaloSumProducer.cc:86
l1t::MuonCaloSum::etBits
const int etBits() const
Definition: MuonCaloSum.h:20
l1t::L1Candidate::hwPhi
int hwPhi() const
Definition: L1Candidate.h:37
MessageLogger.h
L1TMuonCaloSumProducer::L1TMuonCaloSumProducer
L1TMuonCaloSumProducer(const edm::ParameterSet &)
Definition: L1TMuonCaloSumProducer.cc:77
MuonCaloSumFwd.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< CaloTowerBxCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
L1TMuonCaloSumProducer::m_caloLabel
edm::InputTag m_caloLabel
Definition: L1TMuonCaloSumProducer.cc:63
L1TMuonCaloSumProducer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
Definition: L1TMuonCaloSumProducer.cc:201
edm::Handle
Definition: AssociativeIterator.h:50
l1t::CaloTower
Definition: CaloTower.h:12
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
L1TMuonCaloSumProducer::endLuminosityBlock
void endLuminosityBlock(const edm::LuminosityBlock &, edm::EventSetup const &) override
Definition: L1TMuonCaloSumProducer.cc:204
MakerMacros.h
L1TMuonCaloSumProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TMuonCaloSumProducer.cc:96
L1TMuonCaloSumProducer::endRun
void endRun(const edm::Run &, edm::EventSetup const &) override
Definition: L1TMuonCaloSumProducer.cc:198
l1t::L1Candidate::hwEta
int hwEta() const
Definition: L1Candidate.h:36
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CaloTower.h
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
l1t::MuonCaloSum::setEtBits
void setEtBits(int bits)
Definition: MuonCaloSum.h:15
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
edm::ParameterSet
Definition: ParameterSet.h:47
L1TMuonCaloSumProducer::m_caloTowerToken
edm::EDGetTokenT< CaloTowerBxCollection > m_caloTowerToken
Definition: L1TMuonCaloSumProducer.cc:62
Event.h
eleHcalExtractorBlocks_cff.caloTowers
caloTowers
Definition: eleHcalExtractorBlocks_cff.py:15
l1t
delete x;
Definition: CaloConfig.h:22
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
L1TMuonCaloSumProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TMuonCaloSumProducer.cc:207
edm::EventSetup
Definition: EventSetup.h:58
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
L1TMuonCaloSumProducer
Definition: L1TMuonCaloSumProducer.cc:47
MuonCaloSum.h
l1t::MuonCaloSum
Definition: MuonCaloSum.h:7
Frameworkfwd.h
l1t::L1Candidate::hwPt
int hwPt() const
Definition: L1Candidate.h:35
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
L1TMuonCaloSumProducer::beginRun
void beginRun(const edm::Run &, edm::EventSetup const &) override
Definition: L1TMuonCaloSumProducer.cc:195
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
edm::InputTag
Definition: InputTag.h:15