File indexing completed on 2024-10-08 05:11:45
0001 #ifndef L1_DUMMY_PRODUCER_H
0002 #define L1_DUMMY_PRODUCER_H
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <memory>
0013 #include <string>
0014 #include <iostream>
0015 #include <fstream>
0016 #include <iomanip>
0017 #include <vector>
0018 #include <algorithm>
0019 #include "TMath.h"
0020 #include <bitset>
0021 #include <atomic>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/global/EDProducer.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0030
0031
0032 #include "DataFormats/HcalDigi/interface/HcalTriggerPrimitiveDigi.h"
0033 #include "DataFormats/L1CSCTrackFinder/interface/L1Track.h"
0034 #include "L1Trigger/HardwareValidation/interface/DEtrait.h"
0035
0036
0037 #include "CLHEP/Random/RandomEngine.h"
0038 #include "CLHEP/Random/RandGaussQ.h"
0039
0040 class L1DummyProducer : public edm::global::EDProducer<> {
0041 public:
0042 explicit L1DummyProducer(const edm::ParameterSet&);
0043 ~L1DummyProducer() override;
0044
0045 private:
0046
0047 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0048
0049 public:
0050 template <class T>
0051 void SimpleDigi(int nevt, CLHEP::HepRandomEngine*, std::unique_ptr<T>& data, int type = 0) const;
0052
0053 private:
0054 int verbose_;
0055 int verbose() const { return verbose_; }
0056 mutable std::atomic<int> nevt_;
0057
0058 bool m_doSys[dedefs::DEnsys];
0059 std::string instName[dedefs::DEnsys][5];
0060
0061 double EBase_;
0062 double ESigm_;
0063 };
0064
0065 template <class T>
0066 void L1DummyProducer::SimpleDigi(int, CLHEP::HepRandomEngine*, std::unique_ptr<T>& data, int type) const {
0067
0068 }
0069
0070 template <>
0071 inline void L1DummyProducer::SimpleDigi(int,
0072 CLHEP::HepRandomEngine* engine,
0073 std::unique_ptr<EcalTrigPrimDigiCollection>& data,
0074 int type) const {
0075 if (verbose())
0076 std::cout << "L1DummyProducer::SimpleDigi<EcalTrigPrimDigiCollection>....\n" << std::flush;
0077 int side = (engine->flat() > 0.5) ? -1 : 1;
0078 int ieta = (int)(1 + 17 * engine->flat());
0079 int iphi = (int)(1 + 72 * engine->flat());
0080 const EcalTrigTowerDetId e_id(side, EcalBarrel, ieta, iphi, 0);
0081 EcalTriggerPrimitiveDigi e_digi(e_id);
0082 int energy = (int)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0083 bool fg = (engine->flat() > 0.5);
0084 int ttf = (int)(8 * engine->flat());
0085 EcalTriggerPrimitiveSample e_sample(energy, fg, ttf);
0086 e_digi.setSize(1);
0087 e_digi.setSample(0, e_sample);
0088 data->push_back(e_digi);
0089
0090
0091 if (verbose())
0092 std::cout << "L1DummyProducer::SimpleDigi<EcalTrigPrimDigiCollection> end.\n" << std::flush;
0093 }
0094
0095 template <>
0096 inline void L1DummyProducer::SimpleDigi(int,
0097 CLHEP::HepRandomEngine* engine,
0098 std::unique_ptr<HcalTrigPrimDigiCollection>& data,
0099 int type) const {
0100 if (verbose())
0101 std::cout << "L1DummyProducer::SimpleDigi<HcalTrigPrimDigiCollection>....\n" << std::flush;
0102 int side = (engine->flat() > 0.5) ? -1 : 1;
0103 int ieta = (int)(1 + 17 * engine->flat());
0104 int iphi = (int)(1 + 72 * engine->flat());
0105 const HcalTrigTowerDetId h_id(side * ieta, iphi);
0106 HcalTriggerPrimitiveDigi h_digi(h_id);
0107 int energy = (int)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0108 HcalTriggerPrimitiveSample h_sample(energy, false, 0, 0);
0109 h_digi.setSize(1);
0110 h_digi.setSample(0, h_sample);
0111 data->push_back(h_digi);
0112
0113
0114 if (verbose())
0115 std::cout << "L1DummyProducer::SimpleDigi<HcalTrigPrimDigiCollection> end.\n" << std::flush;
0116 }
0117
0118 template <>
0119 inline void L1DummyProducer::SimpleDigi(int nevt,
0120 CLHEP::HepRandomEngine* engine,
0121 std::unique_ptr<L1CaloEmCollection>& data,
0122 int type) const {
0123 if (verbose())
0124 std::cout << "L1DummyProducer::SimpleDigi<L1CaloEmCollection>....\n" << std::flush;
0125 int energy = (int)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0126 unsigned rank = energy & 0x3f;
0127 unsigned region = (engine->flat() > 0.5 ? 0 : 1);
0128 unsigned card = (unsigned)(7 * engine->flat());
0129 unsigned crate = (unsigned)(18 * engine->flat());
0130 bool iso = (engine->flat() > 0.4);
0131 uint16_t index = (unsigned)(4 * engine->flat());
0132 int16_t bx = nevt;
0133 L1CaloEmCand cand(rank, region, card, crate, iso, index, bx);
0134 data->push_back(cand);
0135
0136 if (verbose())
0137 std::cout << "L1DummyProducer::SimpleDigi<L1CaloEmCollection> end.\n" << std::flush;
0138 }
0139
0140 template <>
0141 inline void L1DummyProducer::SimpleDigi(int,
0142 CLHEP::HepRandomEngine* engine,
0143 std::unique_ptr<L1CaloRegionCollection>& data,
0144 int type) const {
0145 if (verbose())
0146 std::cout << "L1DummyProducer::SimpleDigi<L1CaloRegionCollection>....\n" << std::flush;
0147 int energy = (int)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0148 unsigned et = energy & 0x3ff;
0149 bool overFlow = false;
0150 bool tauVeto = false;
0151 bool mip = false;
0152 bool quiet = false;
0153 unsigned crate = (unsigned)(18 * engine->flat());
0154 unsigned card = (unsigned)(7 * engine->flat());
0155 unsigned rgn = crate % 2;
0156 L1CaloRegion cand(et, overFlow, tauVeto, mip, quiet, crate, card, rgn);
0157 data->push_back(cand);
0158
0159 if (verbose())
0160 std::cout << "L1DummyProducer::SimpleDigi<L1CaloRegionCollection> end.\n" << std::flush;
0161 }
0162
0163 template <>
0164 inline void L1DummyProducer::SimpleDigi(int,
0165 CLHEP::HepRandomEngine* engine,
0166 std::unique_ptr<L1GctEmCandCollection>& data,
0167 int type) const {
0168 if (verbose())
0169 std::cout << "L1DummyProducer::SimpleDigi<L1GctEmCandCollection>....\n" << std::flush;
0170 bool iso;
0171 switch (type) {
0172 case 0:
0173 iso = true;
0174 break;
0175 case 1:
0176 iso = false;
0177 break;
0178 default:
0179 throw cms::Exception("L1DummyProducerInvalidType")
0180 << "L1DummyProducer::SimpleDigi production of L1GctEmCandCollection "
0181 << " invalid type: " << type << std::endl;
0182 }
0183 int energy = (int)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0184 unsigned rank = energy & 0x3f;
0185 unsigned phi = (unsigned)(18 * engine->flat());
0186 unsigned eta = (unsigned)(7 * engine->flat());
0187 if (engine->flat() > 0.5)
0188 eta = (eta & 0x7) + (0x1 << 3);
0189 L1GctEmCand cand(rank, phi, eta, iso);
0190 data->push_back(cand);
0191
0192
0193 if (verbose())
0194 std::cout << "L1DummyProducer::SimpleDigi<L1GctEmCandCollection> end.\n" << std::flush;
0195 }
0196
0197 template <>
0198 inline void L1DummyProducer::SimpleDigi(int,
0199 CLHEP::HepRandomEngine* engine,
0200 std::unique_ptr<L1GctJetCandCollection>& data,
0201 int type) const {
0202 if (verbose())
0203 std::cout << "L1DummyProducer::SimpleDigi<L1GctJetCandCollection>....\n" << std::flush;
0204 bool isFor, isTau;
0205 switch (type) {
0206 case 0:
0207 isFor = false;
0208 isTau = false;
0209 break;
0210 case 1:
0211 isFor = true;
0212 isTau = false;
0213 break;
0214 case 2:
0215 isFor = false;
0216 isTau = true;
0217 break;
0218 default:
0219 throw cms::Exception("L1DummyProducerInvalidType")
0220 << "L1DummyProducer::SimpleDigi production of L1GctJetCandCollection "
0221 << " invalid type: " << type << std::endl;
0222 }
0223
0224 int energy = (int)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0225 unsigned rank = energy & 0x3f;
0226 unsigned phi = (unsigned)(18 * engine->flat());
0227 unsigned eta = (unsigned)(7 * engine->flat());
0228 if (engine->flat() > 0.5)
0229 eta = (eta & 0x7) + (0x1 << 3);
0230 L1GctJetCand cand(rank, phi, eta, isTau, isFor);
0231 data->push_back(cand);
0232
0233 if (verbose())
0234 std::cout << "L1DummyProducer::SimpleDigi<L1GctJetCandCollection> end.\n" << std::flush;
0235 }
0236
0237 template <>
0238 inline void L1DummyProducer::SimpleDigi(int,
0239 CLHEP::HepRandomEngine* engine,
0240 std::unique_ptr<L1MuRegionalCandCollection>& data,
0241 int type) const {
0242 if (verbose())
0243 std::cout << "L1DummyProducer::SimpleDigi<L1MuRegionalCandCollection>....\n" << std::flush;
0244
0245 assert(type >= 0 && type < 4);
0246 unsigned type_idx = type;
0247 int bx = 0;
0248 unsigned phi, eta, pt, charge, ch_valid, finehalo, quality;
0249 float phiv(0.), etav(0.), ptv(0.);
0250 for (int i = 0; i < 4; i++) {
0251 phi = (int)(144 * engine->flat());
0252 eta = (int)(63 * engine->flat());
0253 phiv = phi * 2 * TMath::Pi() / 144.;
0254 etav = 2.5 * (-1 + 2 * eta / 63.);
0255 pt = ((int)(32 * engine->flat())) & 0x1f;
0256 ptv = 100 * (pt / 31.);
0257 charge = (engine->flat() > 0.5 ? 0 : 1);
0258 ;
0259 ch_valid = 0;
0260 finehalo = 0;
0261 quality = (int)(8 * engine->flat());
0262 L1MuRegionalCand cand(type_idx, phi, eta, pt, charge, ch_valid, finehalo, quality, bx);
0263 cand.setPhiValue(phiv);
0264 cand.setEtaValue(etav);
0265 cand.setPtValue(ptv);
0266 data->push_back(cand);
0267 }
0268
0269
0270 if (verbose())
0271 std::cout << "L1DummyProducer::SimpleDigi<L1MuRegionalCandCollection> end.\n" << std::flush;
0272 }
0273
0274 template <>
0275 inline void L1DummyProducer::SimpleDigi(int nevt,
0276 CLHEP::HepRandomEngine* engine,
0277 std::unique_ptr<L1MuDTTrackContainer>& data,
0278 int type) const {
0279 assert(type == 0);
0280 int type_idx = type;
0281 if (verbose())
0282 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTTrackContainer>....\n" << std::flush;
0283 std::unique_ptr<L1MuRegionalCandCollection> tracks(new L1MuRegionalCandCollection());
0284 SimpleDigi(nevt, engine, tracks, type_idx);
0285 typedef std::vector<L1MuDTTrackCand> L1MuDTTrackCandCollection;
0286 std::unique_ptr<L1MuDTTrackCandCollection> tracksd(new L1MuDTTrackCandCollection());
0287 for (L1MuRegionalCandCollection::const_iterator it = tracks->begin(); it != tracks->end(); it++) {
0288 L1MuDTTrackCand* cnd = new L1MuDTTrackCand();
0289 cnd->setDataWord(it->getDataWord());
0290 cnd->setBx(it->bx());
0291 tracksd->push_back(L1MuDTTrackCand());
0292 tracksd->push_back(*cnd);
0293 }
0294 data->setContainer(*tracksd);
0295 if (verbose())
0296 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTTrackContainer> end.\n" << std::flush;
0297
0298
0299 }
0300
0301 template <>
0302 inline void L1DummyProducer::SimpleDigi(int,
0303 CLHEP::HepRandomEngine* engine,
0304 std::unique_ptr<L1MuDTChambPhContainer>& data,
0305 int type) const {
0306 if (verbose())
0307 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambPhContainer>....\n" << std::flush;
0308 typedef std::vector<L1MuDTChambPhDigi> Phi_Container;
0309 int ntrk = 4;
0310 Phi_Container tracks(ntrk);
0311 int ubx, uwh, usc, ust, uphr, uphb, uqua, utag, ucnt;
0312 for (int i = 0; i < ntrk; i++) {
0313 ubx = 0;
0314 uwh = (int)(-2 + 5 * engine->flat());
0315 usc = (int)(12 * engine->flat());
0316 ust = (int)(1. + 4 * engine->flat());
0317 uphr = 0;
0318 uphb = 0;
0319 uqua = (int)(8 * engine->flat());
0320 utag = 0;
0321 ucnt = 0;
0322
0323 L1MuDTChambPhDigi cand(ubx, uwh, usc, ust, uphr, uphb, uqua, utag, ucnt);
0324 tracks.push_back(cand);
0325 }
0326 data->setContainer(tracks);
0327
0328
0329 if (verbose())
0330 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambPhContainer> end.\n" << std::flush;
0331 }
0332
0333 template <>
0334 inline void L1DummyProducer::SimpleDigi(int,
0335 CLHEP::HepRandomEngine* engine,
0336 std::unique_ptr<L1MuDTChambThContainer>& data,
0337 int type) const {
0338 if (verbose())
0339 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambThContainer>....\n" << std::flush;
0340 typedef std::vector<L1MuDTChambThDigi> The_Container;
0341 int ntrk = 4;
0342 The_Container tracks(ntrk);
0343 int ubx, uwh, usc, ust, uos[7], uqa[7];
0344 for (int i = 0; i < ntrk; i++) {
0345 ubx = 0;
0346 uwh = (int)(-2 + 5 * engine->flat());
0347 usc = (int)(12 * engine->flat());
0348 ust = (int)(1. + 4 * engine->flat());
0349 for (int j = 0; j < 7; j++) {
0350 uos[j] = (engine->flat() > 0.5 ? 0 : 1);
0351 uqa[j] = (engine->flat() > 0.5 ? 0 : 1);
0352 }
0353 L1MuDTChambThDigi cand(ubx, uwh, usc, ust, uos, uqa);
0354 tracks.push_back(cand);
0355 }
0356 data->setContainer(tracks);
0357
0358
0359
0360 if (verbose())
0361 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambThContainer> end.\n" << std::flush;
0362 }
0363
0364 template <>
0365 inline void L1DummyProducer::SimpleDigi(int nevt,
0366 CLHEP::HepRandomEngine* engine,
0367 std::unique_ptr<L1MuGMTCandCollection>& data,
0368 int type) const {
0369 if (verbose())
0370 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTCandCollection>....\n" << std::flush;
0371
0372 L1MuGMTCand cand(0, nevt);
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382 double eng = EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine);
0383 double phi = 2 * TMath::Pi() * engine->flat();
0384 double eta = 2.5 * (-1 + 2 * engine->flat());
0385 cand.setPtValue(eng);
0386 cand.setPhiValue(phi);
0387 cand.setEtaValue(eta);
0388 unsigned engp = (unsigned)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0389 unsigned phip = (unsigned)(255 * engine->flat());
0390 unsigned etap = (unsigned)(63 * engine->flat());
0391 cand.setPtPacked(engp & 0x1f);
0392 cand.setPhiPacked(phip & 0x7f);
0393 cand.setEtaPacked(etap & 0x3f);
0394 double r = engine->flat();
0395 cand.setIsolation(r > 0.2);
0396 cand.setMIP(r > 0.7);
0397 cand.setChargePacked(r > 0.5 ? 0 : 1);
0398 cand.setBx(0);
0399 data->push_back(cand);
0400 if (verbose())
0401 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTCandCollection> end.\n" << std::flush;
0402 }
0403
0404 template <>
0405 inline void L1DummyProducer::SimpleDigi(int nevt,
0406 CLHEP::HepRandomEngine* engine,
0407 std::unique_ptr<L1MuGMTReadoutCollection>& data,
0408 int type) const {
0409 if (verbose())
0410 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTReadoutCollection>....\n" << std::flush;
0411 L1MuGMTReadoutRecord rec(0);
0412 int bxn = nevt;
0413 rec.setBxNr(bxn);
0414 rec.setEvNr(bxn);
0415 rec.setBxInEvent(0);
0416 std::unique_ptr<L1MuRegionalCandCollection> trks_dttf(new L1MuRegionalCandCollection);
0417 std::unique_ptr<L1MuRegionalCandCollection> trks_rpcb(new L1MuRegionalCandCollection);
0418 std::unique_ptr<L1MuRegionalCandCollection> trks_csc(new L1MuRegionalCandCollection);
0419 std::unique_ptr<L1MuRegionalCandCollection> trks_rpcf(new L1MuRegionalCandCollection);
0420 SimpleDigi(nevt, engine, trks_dttf, 0);
0421 SimpleDigi(nevt, engine, trks_rpcb, 1);
0422 SimpleDigi(nevt, engine, trks_csc, 2);
0423 SimpleDigi(nevt, engine, trks_rpcf, 3);
0424 for (int i = 0; i < 4; i++) {
0425 rec.setInputCand(i, trks_dttf->at(i));
0426 rec.setInputCand(i + 4, trks_rpcb->at(i));
0427 rec.setInputCand(i + 8, trks_csc->at(i));
0428 rec.setInputCand(i + 12, trks_rpcf->at(i));
0429 }
0430 for (int nr = 0; nr < 4; nr++) {
0431 int eng = (int)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0432 rec.setGMTBrlCand(nr, eng & 0x11, eng & 0x11);
0433 rec.setGMTFwdCand(nr, eng & 0x11, eng & 0x11);
0434 rec.setGMTCand(nr, eng & 0x11);
0435 int eta = (int)(14 * engine->flat());
0436 int phi = (int)(18 * engine->flat());
0437 rec.setMIPbit(eta, phi);
0438 rec.setQuietbit(eta, phi);
0439 }
0440 data->addRecord(rec);
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450 if (verbose())
0451 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTReadoutCollection> end.\n" << std::flush;
0452 }
0453
0454 template <>
0455 inline void L1DummyProducer::SimpleDigi(int,
0456 CLHEP::HepRandomEngine*,
0457 std::unique_ptr<LTCDigiCollection>& data,
0458 int type) const {
0459 if (verbose())
0460 std::cout << "L1DummyProducer::SimpleDigi<LTCDigiCollection>....\n" << std::flush;
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487 if (verbose())
0488 std::cout << "L1DummyProducer::SimpleDigi<LTCDigiCollection> end.\n" << std::flush;
0489 }
0490
0491 template <>
0492 inline void L1DummyProducer::SimpleDigi(int,
0493 CLHEP::HepRandomEngine* engine,
0494 std::unique_ptr<CSCCorrelatedLCTDigiCollection>& data,
0495 int type) const {
0496 if (verbose())
0497 std::cout << "L1DummyProducer::SimpleDigi<CSCCorrelatedLCTDigiCollection>....\n" << std::flush;
0498
0499
0500 CSCCorrelatedLCTDigi dg = CSCCorrelatedLCTDigi();
0501
0502 dg.clear();
0503
0504 static constexpr int MIN_ENDCAP = 1, MIN_STATION = 1, MIN_RING = 1, MIN_CHAMBER = 1, MIN_LAYER = 1;
0505 static constexpr int MAX_ENDCAP = 2, MAX_STATION = 4, MAX_RING = 4, MAX_CHAMBER = 36, MAX_LAYER = 6;
0506
0507 float rnd = engine->flat();
0508 int ec = (int)(MIN_ENDCAP + (MAX_ENDCAP - MIN_ENDCAP) * rnd + 1);
0509 int st = (int)(MIN_STATION + (MAX_STATION - MIN_STATION) * rnd + 1);
0510 int rg = (int)(MIN_RING + (MAX_RING - MIN_RING) * rnd + 1);
0511 int ch = (int)(MIN_CHAMBER + (MAX_CHAMBER - MIN_CHAMBER) * rnd + 1);
0512 int lr = (int)(MIN_LAYER + (MAX_LAYER - MIN_LAYER) * rnd + 1);
0513 CSCDetId did = CSCDetId(ec, st, rg, ch, lr);
0514
0515
0516 data->insertDigi(did, dg);
0517 if (verbose())
0518 std::cout << "L1DummyProducer::SimpleDigi<CSCCorrelatedLCTDigiCollection> end.\n" << std::flush;
0519 }
0520
0521 template <>
0522 inline void L1DummyProducer::SimpleDigi(int nevt,
0523 CLHEP::HepRandomEngine* engine,
0524 std::unique_ptr<L1CSCTrackCollection>& data,
0525 int type) const {
0526 if (verbose())
0527 std::cout << "L1DummyProducer::SimpleDigi<L1CSCTrackCollection>...\n" << std::flush;
0528 std::unique_ptr<CSCCorrelatedLCTDigiCollection> dgcoll(new CSCCorrelatedLCTDigiCollection);
0529 SimpleDigi(nevt, engine, dgcoll, 0);
0530 csc::L1Track l1trk = csc::L1Track();
0531 std::unique_ptr<L1MuRegionalCandCollection> regcoll(new L1MuRegionalCandCollection);
0532 SimpleDigi(nevt, engine, regcoll, 2);
0533 L1MuRegionalCand regcand = *(regcoll->begin());
0534 l1trk.setDataWord(regcand.getDataWord());
0535 l1trk.setBx(regcand.bx());
0536 l1trk.setPhiValue(regcand.phiValue());
0537 l1trk.setEtaValue(regcand.etaValue());
0538 l1trk.setPtValue(regcand.ptValue());
0539 L1CSCTrack l1csctrk = std::make_pair(l1trk, *dgcoll);
0540 data->push_back(l1csctrk);
0541
0542
0543
0544
0545 if (verbose())
0546 std::cout << "L1DummyProducer::SimpleDigi<L1CSCTrackCollection> end.\n" << std::flush;
0547 }
0548
0549 #endif