CMS 3D CMS Logo

L1TCaloSummary.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TCaloSummary
4 // Class: L1TCaloSummary
5 //
13 //
14 // Original Author: Sridhara Dasu
15 // Created: Sat, 14 Nov 2015 14:18:27 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
30 
33 
34 #include "L1Trigger/L1TCaloLayer1/src/UCTLayer1.hh"
35 #include "L1Trigger/L1TCaloLayer1/src/UCTCrate.hh"
36 #include "L1Trigger/L1TCaloLayer1/src/UCTCard.hh"
37 #include "L1Trigger/L1TCaloLayer1/src/UCTRegion.hh"
38 #include "L1Trigger/L1TCaloLayer1/src/UCTTower.hh"
39 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometry.hh"
40 
41 #include "L1Trigger/L1TCaloLayer1/src/UCTObject.hh"
42 #include "L1Trigger/L1TCaloLayer1/src/UCTSummaryCard.hh"
43 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometryExtended.hh"
44 
51 
54 
56 
57 #include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh"
58 #include <bitset>
59 
60 using namespace l1tcalo;
61 using namespace l1extra;
62 using namespace std;
63 
64 //
65 // class declaration
66 //
67 
69 public:
70  explicit L1TCaloSummary(const edm::ParameterSet&);
71  ~L1TCaloSummary() override;
72 
73  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
74 
75 private:
76  //void beginJob() override;
77  void produce(edm::Event&, const edm::EventSetup&) override;
78  //void endJob() override;
79 
80  void beginRun(edm::Run const&, edm::EventSetup const&) override;
81 
82  void print();
83 
84  // ----------member data ---------------------------
85 
86  uint32_t nPumBins;
87 
88  std::vector<std::vector<std::vector<uint32_t>>> pumLUT;
89 
91 
92  uint32_t jetSeed;
93  uint32_t tauSeed;
95  uint32_t eGammaSeed;
98 
99  bool verbose;
101 
103 
104  UCTLayer1* layer1;
105  UCTSummaryCard* summaryCard;
106 };
107 
108 //
109 // constants, enums and typedefs
110 //
111 
112 //
113 // static data member definitions
114 //
115 
116 //
117 // constructors and destructor
118 //
120  : nPumBins(iConfig.getParameter<unsigned int>("nPumBins")),
121  pumLUT(nPumBins, std::vector<std::vector<uint32_t>>(2, std::vector<uint32_t>(13))),
122  caloScaleFactor(iConfig.getParameter<double>("caloScaleFactor")),
123  jetSeed(iConfig.getParameter<unsigned int>("jetSeed")),
124  tauSeed(iConfig.getParameter<unsigned int>("tauSeed")),
125  tauIsolationFactor(iConfig.getParameter<double>("tauIsolationFactor")),
126  eGammaSeed(iConfig.getParameter<unsigned int>("eGammaSeed")),
127  eGammaIsolationFactor(iConfig.getParameter<double>("eGammaIsolationFactor")),
128  boostedJetPtFactor(iConfig.getParameter<double>("boostedJetPtFactor")),
129  verbose(iConfig.getParameter<bool>("verbose")),
130  fwVersion(iConfig.getParameter<int>("firmwareVersion")),
131  regionToken(consumes<L1CaloRegionCollection>(edm::InputTag("simCaloStage2Layer1Digis"))) {
132  std::vector<double> pumLUTData;
133  char pumLUTString[10];
134  for (uint32_t pumBin = 0; pumBin < nPumBins; pumBin++) {
135  for (uint32_t side = 0; side < 2; side++) {
136  if (side == 0)
137  sprintf(pumLUTString, "pumLUT%2.2dp", pumBin);
138  else
139  sprintf(pumLUTString, "pumLUT%2.2dn", pumBin);
140  pumLUTData = iConfig.getParameter<std::vector<double>>(pumLUTString);
141  for (uint32_t iEta = 0; iEta < std::max((uint32_t)pumLUTData.size(), MaxUCTRegionsEta); iEta++) {
142  pumLUT[pumBin][side][iEta] = (uint32_t)round(pumLUTData[iEta] / caloScaleFactor);
143  }
144  if (pumLUTData.size() != (MaxUCTRegionsEta))
145  edm::LogError("L1TCaloSummary") << "PUM LUT Data size integrity check failed; Expected size = "
146  << MaxUCTRegionsEta << "; Provided size = " << pumLUTData.size()
147  << "; Will use what is provided :(" << std::endl;
148  }
149  }
150  produces<L1JetParticleCollection>("Boosted");
152 }
153 
155  if (summaryCard != nullptr)
156  delete summaryCard;
157 }
158 
159 //
160 // member functions
161 //
162 
163 // ------------ method called to produce the data ------------
165  using namespace edm;
166 
167  std::unique_ptr<L1JetParticleCollection> bJetCands(new L1JetParticleCollection);
168 
169  UCTGeometry g;
170 
171  // Here we read region data from the region collection created by L1TCaloLayer1 instead of
172  // independently creating regions from TPGs for processing by the summary card. This results
173  // in a single region vector of size 252 whereas from independent creation we had 3*6 vectors
174  // of size 7*2. Indices are mapped in UCTSummaryCard accordingly.
175  summaryCard->clearRegions();
176  std::vector<UCTRegion*> inputRegions;
177  inputRegions.clear();
178  edm::Handle<std::vector<L1CaloRegion>> regionCollection;
179  if (!iEvent.getByToken(regionToken, regionCollection))
180  edm::LogError("L1TCaloSummary") << "UCT: Failed to get regions from region collection!";
181  iEvent.getByToken(regionToken, regionCollection);
182  for (const L1CaloRegion& i : *regionCollection) {
183  UCTRegionIndex r = g.getUCTRegionIndexFromL1CaloRegion(i.gctEta(), i.gctPhi());
184  UCTTowerIndex t = g.getUCTTowerIndexFromL1CaloRegion(r, i.raw());
185  uint32_t absCaloEta = std::abs(t.first);
186  uint32_t absCaloPhi = std::abs(t.second);
187  bool negativeEta = false;
188  if (t.first < 0)
189  negativeEta = true;
190  uint32_t crate = g.getCrate(t.first, t.second);
191  uint32_t card = g.getCard(t.first, t.second);
192  uint32_t region = g.getRegion(absCaloEta, absCaloPhi);
193  UCTRegion* test = new UCTRegion(crate, card, negativeEta, region, fwVersion);
194  test->setRegionSummary(i.raw());
195  inputRegions.push_back(test);
196  }
197  summaryCard->setRegionData(inputRegions);
198 
199  if (!summaryCard->process()) {
200  edm::LogError("L1TCaloSummary") << "UCT: Failed to process summary card" << std::endl;
201  exit(1);
202  }
203 
204  double pt = 0;
205  double eta = -999.;
206  double phi = -999.;
207  double mass = 0;
208 
209  std::list<UCTObject*> boostedJetObjs = summaryCard->getBoostedJetObjs();
210  for (std::list<UCTObject*>::const_iterator i = boostedJetObjs.begin(); i != boostedJetObjs.end(); i++) {
211  const UCTObject* object = *i;
212  pt = ((double)object->et()) * caloScaleFactor * boostedJetPtFactor;
213  eta = g.getUCTTowerEta(object->iEta());
214  phi = g.getUCTTowerPhi(object->iPhi());
215  bitset<3> activeRegionEtaPattern = 0;
216  for (uint32_t iEta = 0; iEta < 3; iEta++) {
217  bool activeStrip = false;
218  for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
219  if (object->boostedJetRegionET()[3 * iEta + iPhi] > 30 &&
220  object->boostedJetRegionET()[3 * iEta + iPhi] > object->et() * 0.0625)
221  activeStrip = true;
222  }
223  if (activeStrip)
224  activeRegionEtaPattern |= (0x1 << iEta);
225  }
226  bitset<3> activeRegionPhiPattern = 0;
227  for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
228  bool activeStrip = false;
229  for (uint32_t iEta = 0; iEta < 3; iEta++) {
230  if (object->boostedJetRegionET()[3 * iEta + iPhi] > 30 &&
231  object->boostedJetRegionET()[3 * iEta + iPhi] > object->et() * 0.0625)
232  activeStrip = true;
233  }
234  if (activeStrip)
235  activeRegionPhiPattern |= (0x1 << iPhi);
236  }
237  string regionEta = activeRegionEtaPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
238  string regionPhi = activeRegionPhiPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
239 
240  bool centralHighest = object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[0] &&
241  object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[1] &&
242  object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[2] &&
243  object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[3] &&
244  object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[5] &&
245  object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[6] &&
246  object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[7] &&
247  object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[8];
248 
249  if (abs(eta) < 2.5 && ((regionEta == "101" && (regionPhi == "110" || regionPhi == "101" || regionPhi == "010")) ||
250  ((regionEta == "110" || regionEta == "101" || regionEta == "010") && regionPhi == "101") ||
251  (regionEta == "111" && (regionPhi == "110" || regionPhi == "010")) ||
252  ((regionEta == "110" || regionEta == "010") && regionPhi == "111") ||
253  ((regionEta == "010" || regionPhi == "010" || regionEta == "110" || regionPhi == "110" ||
254  regionEta == "011" || regionPhi == "011") &&
255  centralHighest)))
256  bJetCands->push_back(L1JetParticle(math::PtEtaPhiMLorentzVector(pt, eta, phi, mass), L1JetParticle::kCentral));
257  }
258 
259  iEvent.put(std::move(bJetCands), "Boosted");
260 }
261 
263 
264 // ------------ method called once each job just before starting event loop ------------
265 //void L1TCaloSummary::beginJob() {}
266 
267 // ------------ method called once each job just after ending the event loop ------------
268 //void L1TCaloSummary::endJob() {}
269 
270 // ------------ method called when starting to processes a run ------------
271 
272 void L1TCaloSummary::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {}
273 
274 // ------------ method called when ending the processing of a run ------------
275 /*
276  void
277  L1TCaloSummary::endRun(edm::Run const&, edm::EventSetup const&)
278  {
279  }
280 */
281 
282 // ------------ method called when starting to processes a luminosity block ------------
283 /*
284  void
285  L1TCaloSummary::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
286  {
287  }
288 */
289 
290 // ------------ method called when ending the processing of a luminosity block ------------
291 /*
292  void
293  L1TCaloSummary::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
294  {
295  }
296 */
297 
298 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
300  //The following says we do not know what parameters are allowed so do no validation
301  // Please change this to state exactly what you do use, even if it is no parameters
303  desc.setUnknown();
304  descriptions.addDefault(desc);
305 }
306 
307 //define this as a plug-in
double caloScaleFactor
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void produce(edm::Event &, const edm::EventSetup &) override
bool verbose
L1TCaloSummary(const edm::ParameterSet &)
uint32_t eGammaSeed
Log< level::Error, false > LogError
UCTSummaryCard * summaryCard
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
double eGammaIsolationFactor
~L1TCaloSummary() override
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
float tauIsolationFactor
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< std::vector< std::vector< uint32_t > > > pumLUT
double boostedJetPtFactor
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginRun(edm::Run const &, edm::EventSetup const &) override
HLT enums.
UCTLayer1 * layer1
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:21
std::vector< L1CaloRegion > L1CaloRegionCollection
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
def exit(msg="")
edm::EDGetTokenT< L1CaloRegionCollection > regionToken