File indexing completed on 2024-04-06 12:21:42
0001 #include "RctInputTextToDigi.h"
0002
0003
0004
0005
0006
0007 RctInputTextToDigi::RctInputTextToDigi(const edm::ParameterSet &iConfig)
0008 : inputFile_(iConfig.getParameter<edm::FileInPath>("inputFile")),
0009 inputStream_(inputFile_.fullPath().c_str()),
0010 lookupTables_(new L1RCTLookupTables),
0011 paramsToken_(esConsumes()),
0012 nEvent_(0),
0013 oldVersion_(false) {
0014
0015
0016
0017
0018
0019
0020
0021
0022 produces<EcalTrigPrimDigiCollection>();
0023 produces<HcalTrigPrimDigiCollection>();
0024
0025
0026
0027 if ((!inputStream_.is_open()) || (!inputStream_)) {
0028
0029 std::cerr << "Input file didn't open!!" << std::endl;
0030 }
0031
0032 }
0033
0034 RctInputTextToDigi::~RctInputTextToDigi() {
0035
0036
0037
0038 inputStream_.close();
0039 }
0040
0041
0042
0043
0044
0045
0046 void RctInputTextToDigi::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0047 using namespace edm;
0048
0049
0050
0051
0052
0053
0054
0055
0056 const L1RCTParameters *r = &iSetup.getData(paramsToken_);
0057 lookupTables_->setRCTParameters(r);
0058
0059 std::unique_ptr<EcalTrigPrimDigiCollection> ecalTPs(new EcalTrigPrimDigiCollection());
0060 std::unique_ptr<HcalTrigPrimDigiCollection> hcalTPs(new HcalTrigPrimDigiCollection());
0061 ecalTPs->reserve(56 * 72);
0062 hcalTPs->reserve(56 * 72 + 18 * 8);
0063 const int nEcalSamples = 1;
0064 const int nHcalSamples = 1;
0065
0066 int fileEventNumber;
0067
0068
0069
0070
0071 std::string junk;
0072
0073 if (nEvent_ == 0) {
0074
0075 unsigned short junk_counter = 0;
0076
0077 do {
0078 if (inputStream_ >> junk) {
0079 }
0080
0081
0082
0083
0084
0085
0086
0087 if ((junk_counter == 11) && (junk == "1-32")) {
0088 oldVersion_ = true;
0089 }
0090 junk_counter++;
0091 } while (junk != "LUTOut");
0092 std::cout << "Skipped file header" << std::endl;
0093 if (oldVersion_) {
0094 std::cout << "oldVersion_ TRUE (tower 1-32)" << std::endl;
0095 } else {
0096 std::cout << "oldVersion_ FALSE (tower 0-31)" << std::endl;
0097 }
0098 }
0099
0100
0101
0102 for (int i = 0; i < 72; i++) {
0103
0104 for (int j = 0; j < 56; j++) {
0105
0106
0107
0108
0109 unsigned short crate;
0110 unsigned short card;
0111 unsigned short tower;
0112 unsigned eAddr;
0113 unsigned hAddr;
0114
0115 inputStream_ >> std::hex >> fileEventNumber >> crate >> card >> tower >> eAddr >> hAddr >> junk >> std::dec;
0116
0117 if (oldVersion_) {
0118 tower = tower - 1;
0119 }
0120 int encodedEtEcal = (int)(eAddr >> 1);
0121 bool fineGrainEcal = (bool)(eAddr & 1);
0122 int encodedEtHcal = (int)(hAddr >> 1);
0123 bool fineGrainHcal = (bool)(hAddr & 1);
0124
0125
0126
0127
0128
0129
0130 int iEta = lookupTables_->rctParameters()->calcIEta(crate, card, tower);
0131 int iPhi = lookupTables_->rctParameters()->calcIPhi(crate, card, tower);
0132
0133 iPhi = ((72 + 18 - iPhi) % 72);
0134 if (iPhi == 0) {
0135 iPhi = 72;
0136 }
0137 unsigned absIeta = abs(iEta);
0138 int zSide = (iEta / absIeta);
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 EcalTriggerPrimitiveDigi ecalDigi(EcalTrigTowerDetId(zSide, EcalTriggerTower, absIeta, iPhi));
0149 ecalDigi.setSize(nEcalSamples);
0150
0151
0152
0153 ecalDigi.setSample(0, EcalTriggerPrimitiveSample(encodedEtEcal, fineGrainEcal, 0));
0154
0155 ecalTPs->push_back(ecalDigi);
0156
0157 HcalTriggerPrimitiveDigi hcalDigi(HcalTrigTowerDetId(iEta, iPhi));
0158
0159 hcalDigi.setSize(nHcalSamples);
0160
0161
0162 hcalDigi.setSample(0, HcalTriggerPrimitiveSample(encodedEtHcal, fineGrainHcal, 0, 0));
0163
0164 hcalTPs->push_back(hcalDigi);
0165 }
0166
0167
0168
0169 for (int i = 0; i < 18; i++) {
0170 for (int j = 0; j < 8; j++) {
0171
0172 int hfIEta = (j % 4) + 29;
0173 if (i < 9) {
0174 hfIEta = hfIEta * (-1);
0175 }
0176
0177
0178 int hfIPhi = (i % 9) * 8 + (j / 4) * 4 + 1;
0179
0180 HcalTriggerPrimitiveDigi hfDigi(HcalTrigTowerDetId(hfIEta, hfIPhi));
0181 hfDigi.setSize(1);
0182 hfDigi.setSample(0, HcalTriggerPrimitiveSample(0, false, 0, 0));
0183 hcalTPs->push_back(hfDigi);
0184 }
0185 }
0186 }
0187 iEvent.put(std::move(ecalTPs));
0188 iEvent.put(std::move(hcalTPs));
0189
0190 nEvent_++;
0191
0192 }
0193
0194
0195
0196 void RctInputTextToDigi::beginJob() {
0197
0198
0199
0200 }
0201
0202
0203
0204 void RctInputTextToDigi::endJob() {
0205
0206
0207 }
0208
0209
0210 DEFINE_FWK_MODULE(RctInputTextToDigi);