File indexing completed on 2024-04-06 12:20:05
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 = 0;
0315 usc = 0;
0316 ust = 0;
0317 uphr = 0;
0318 uphb = 0;
0319 uqua = 0;
0320 utag = 0;
0321 ucnt = 0;
0322 uwh = (int)(-2 + 5 * engine->flat());
0323 usc = (int)(12 * engine->flat());
0324 ust = (int)(1. + 4 * engine->flat());
0325 uqua = (int)(8 * engine->flat());
0326 L1MuDTChambPhDigi cand(ubx, uwh, usc, ust, uphr, uphb, uqua, utag, ucnt);
0327 tracks.push_back(cand);
0328 }
0329 data->setContainer(tracks);
0330
0331
0332 if (verbose())
0333 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambPhContainer> end.\n" << std::flush;
0334 }
0335
0336 template <>
0337 inline void L1DummyProducer::SimpleDigi(int,
0338 CLHEP::HepRandomEngine* engine,
0339 std::unique_ptr<L1MuDTChambThContainer>& data,
0340 int type) const {
0341 if (verbose())
0342 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambThContainer>....\n" << std::flush;
0343 typedef std::vector<L1MuDTChambThDigi> The_Container;
0344 int ntrk = 4;
0345 The_Container tracks(ntrk);
0346 int ubx, uwh, usc, ust, uos[7], uqa[7];
0347 for (int i = 0; i < ntrk; i++) {
0348 ubx = 0;
0349 uwh = (int)(-2 + 5 * engine->flat());
0350 usc = (int)(12 * engine->flat());
0351 ust = (int)(1. + 4 * engine->flat());
0352 for (int j = 0; j < 7; j++) {
0353 uos[j] = (engine->flat() > 0.5 ? 0 : 1);
0354 uqa[j] = (engine->flat() > 0.5 ? 0 : 1);
0355 }
0356 L1MuDTChambThDigi cand(ubx, uwh, usc, ust, uos, uqa);
0357 tracks.push_back(cand);
0358 }
0359 data->setContainer(tracks);
0360
0361
0362
0363 if (verbose())
0364 std::cout << "L1DummyProducer::SimpleDigi<L1MuDTChambThContainer> end.\n" << std::flush;
0365 }
0366
0367 template <>
0368 inline void L1DummyProducer::SimpleDigi(int nevt,
0369 CLHEP::HepRandomEngine* engine,
0370 std::unique_ptr<L1MuGMTCandCollection>& data,
0371 int type) const {
0372 if (verbose())
0373 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTCandCollection>....\n" << std::flush;
0374
0375 L1MuGMTCand cand(0, nevt);
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385 double eng = EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine);
0386 double phi = 2 * TMath::Pi() * engine->flat();
0387 double eta = 2.5 * (-1 + 2 * engine->flat());
0388 cand.setPtValue(eng);
0389 cand.setPhiValue(phi);
0390 cand.setEtaValue(eta);
0391 unsigned engp = (unsigned)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0392 unsigned phip = (unsigned)(255 * engine->flat());
0393 unsigned etap = (unsigned)(63 * engine->flat());
0394 cand.setPtPacked(engp & 0x1f);
0395 cand.setPhiPacked(phip & 0x7f);
0396 cand.setEtaPacked(etap & 0x3f);
0397 double r = engine->flat();
0398 cand.setIsolation(r > 0.2);
0399 cand.setMIP(r > 0.7);
0400 cand.setChargePacked(r > 0.5 ? 0 : 1);
0401 cand.setBx(0);
0402 data->push_back(cand);
0403 if (verbose())
0404 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTCandCollection> end.\n" << std::flush;
0405 }
0406
0407 template <>
0408 inline void L1DummyProducer::SimpleDigi(int nevt,
0409 CLHEP::HepRandomEngine* engine,
0410 std::unique_ptr<L1MuGMTReadoutCollection>& data,
0411 int type) const {
0412 if (verbose())
0413 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTReadoutCollection>....\n" << std::flush;
0414 L1MuGMTReadoutRecord rec(0);
0415 int bxn = nevt;
0416 rec.setBxNr(bxn);
0417 rec.setEvNr(bxn);
0418 rec.setBxInEvent(0);
0419 std::unique_ptr<L1MuRegionalCandCollection> trks_dttf(new L1MuRegionalCandCollection);
0420 std::unique_ptr<L1MuRegionalCandCollection> trks_rpcb(new L1MuRegionalCandCollection);
0421 std::unique_ptr<L1MuRegionalCandCollection> trks_csc(new L1MuRegionalCandCollection);
0422 std::unique_ptr<L1MuRegionalCandCollection> trks_rpcf(new L1MuRegionalCandCollection);
0423 SimpleDigi(nevt, engine, trks_dttf, 0);
0424 SimpleDigi(nevt, engine, trks_rpcb, 1);
0425 SimpleDigi(nevt, engine, trks_csc, 2);
0426 SimpleDigi(nevt, engine, trks_rpcf, 3);
0427 for (int i = 0; i < 4; i++) {
0428 rec.setInputCand(i, trks_dttf->at(i));
0429 rec.setInputCand(i + 4, trks_rpcb->at(i));
0430 rec.setInputCand(i + 8, trks_csc->at(i));
0431 rec.setInputCand(i + 12, trks_rpcf->at(i));
0432 }
0433 for (int nr = 0; nr < 4; nr++) {
0434 int eng = (int)(EBase_ + ESigm_ * CLHEP::RandGaussQ::shoot(engine));
0435 rec.setGMTBrlCand(nr, eng & 0x11, eng & 0x11);
0436 rec.setGMTFwdCand(nr, eng & 0x11, eng & 0x11);
0437 rec.setGMTCand(nr, eng & 0x11);
0438 int eta = (int)(14 * engine->flat());
0439 int phi = (int)(18 * engine->flat());
0440 rec.setMIPbit(eta, phi);
0441 rec.setQuietbit(eta, phi);
0442 }
0443 data->addRecord(rec);
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453 if (verbose())
0454 std::cout << "L1DummyProducer::SimpleDigi<L1MuGMTReadoutCollection> end.\n" << std::flush;
0455 }
0456
0457 template <>
0458 inline void L1DummyProducer::SimpleDigi(int,
0459 CLHEP::HepRandomEngine*,
0460 std::unique_ptr<LTCDigiCollection>& data,
0461 int type) const {
0462 if (verbose())
0463 std::cout << "L1DummyProducer::SimpleDigi<LTCDigiCollection>....\n" << std::flush;
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490 if (verbose())
0491 std::cout << "L1DummyProducer::SimpleDigi<LTCDigiCollection> end.\n" << std::flush;
0492 }
0493
0494 template <>
0495 inline void L1DummyProducer::SimpleDigi(int,
0496 CLHEP::HepRandomEngine* engine,
0497 std::unique_ptr<CSCCorrelatedLCTDigiCollection>& data,
0498 int type) const {
0499 if (verbose())
0500 std::cout << "L1DummyProducer::SimpleDigi<CSCCorrelatedLCTDigiCollection>....\n" << std::flush;
0501
0502
0503 CSCCorrelatedLCTDigi dg = CSCCorrelatedLCTDigi();
0504
0505 dg.clear();
0506
0507 static constexpr int MIN_ENDCAP = 1, MIN_STATION = 1, MIN_RING = 1, MIN_CHAMBER = 1, MIN_LAYER = 1;
0508 static constexpr int MAX_ENDCAP = 2, MAX_STATION = 4, MAX_RING = 4, MAX_CHAMBER = 36, MAX_LAYER = 6;
0509
0510 float rnd = engine->flat();
0511 int ec = (int)(MIN_ENDCAP + (MAX_ENDCAP - MIN_ENDCAP) * rnd + 1);
0512 int st = (int)(MIN_STATION + (MAX_STATION - MIN_STATION) * rnd + 1);
0513 int rg = (int)(MIN_RING + (MAX_RING - MIN_RING) * rnd + 1);
0514 int ch = (int)(MIN_CHAMBER + (MAX_CHAMBER - MIN_CHAMBER) * rnd + 1);
0515 int lr = (int)(MIN_LAYER + (MAX_LAYER - MIN_LAYER) * rnd + 1);
0516 CSCDetId did = CSCDetId(ec, st, rg, ch, lr);
0517
0518
0519 data->insertDigi(did, dg);
0520 if (verbose())
0521 std::cout << "L1DummyProducer::SimpleDigi<CSCCorrelatedLCTDigiCollection> end.\n" << std::flush;
0522 }
0523
0524 template <>
0525 inline void L1DummyProducer::SimpleDigi(int nevt,
0526 CLHEP::HepRandomEngine* engine,
0527 std::unique_ptr<L1CSCTrackCollection>& data,
0528 int type) const {
0529 if (verbose())
0530 std::cout << "L1DummyProducer::SimpleDigi<L1CSCTrackCollection>...\n" << std::flush;
0531 std::unique_ptr<CSCCorrelatedLCTDigiCollection> dgcoll(new CSCCorrelatedLCTDigiCollection);
0532 SimpleDigi(nevt, engine, dgcoll, 0);
0533 csc::L1Track l1trk = csc::L1Track();
0534 std::unique_ptr<L1MuRegionalCandCollection> regcoll(new L1MuRegionalCandCollection);
0535 SimpleDigi(nevt, engine, regcoll, 2);
0536 L1MuRegionalCand regcand = *(regcoll->begin());
0537 l1trk.setDataWord(regcand.getDataWord());
0538 l1trk.setBx(regcand.bx());
0539 l1trk.setPhiValue(regcand.phiValue());
0540 l1trk.setEtaValue(regcand.etaValue());
0541 l1trk.setPtValue(regcand.ptValue());
0542 L1CSCTrack l1csctrk = std::make_pair(l1trk, *dgcoll);
0543 data->push_back(l1csctrk);
0544
0545
0546
0547
0548 if (verbose())
0549 std::cout << "L1DummyProducer::SimpleDigi<L1CSCTrackCollection> end.\n" << std::flush;
0550 }
0551
0552 #endif