File indexing completed on 2024-04-06 12:19:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "L1Trigger/DTTraco/interface/DTTracoCard.h"
0024
0025
0026
0027
0028 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0029 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0030 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
0031 #include "L1Trigger/DTBti/interface/DTBtiTrigData.h"
0032 #include "L1Trigger/DTTraco/interface/DTTracoChip.h"
0033 #include "L1Trigger/DTTraco/interface/DTTracoTrig.h"
0034 #include "L1Trigger/DTTriggerServerTheta/interface/DTTSTheta.h"
0035
0036
0037
0038
0039 #include <cmath>
0040 #include <iomanip>
0041 #include <iostream>
0042 #include <utility>
0043
0044
0045
0046
0047
0048 DTTracoCard::DTTracoCard(DTTrigGeom *geo, DTBtiCard *bticard, DTTSTheta *tstheta)
0049 : DTGeomSupplier(geo), _bticard(bticard), _tstheta(tstheta) {}
0050
0051
0052
0053
0054
0055 DTTracoCard::~DTTracoCard() { localClear(); }
0056
0057
0058
0059
0060
0061 void DTTracoCard::clearCache() {
0062 TRACOCache::clearCache();
0063 localClear();
0064 }
0065
0066 void DTTracoCard::setConfig(const DTConfigManager *conf) {
0067
0068 DTChamberId sid = ChamberId();
0069 _conf_traco_map = conf->getDTConfigTracoMap(sid);
0070 _debug = conf->getDTTPGDebug();
0071
0072
0073 _flag_acc = conf->useAcceptParam();
0074
0075
0076 _lut_from_db = conf->lutFromDB();
0077
0078
0079
0080 if (_lut_from_db)
0081 _conf_luts = conf->getDTConfigLUTs(sid);
0082 }
0083
0084 void DTTracoCard::localClear() {
0085
0086 for (TRACO_iter p = _tracomap.begin(); p != _tracomap.end(); p++) {
0087 delete (*p).second;
0088 }
0089 _tracomap.clear();
0090 }
0091
0092 void DTTracoCard::loadTRACO() {
0093 localClear();
0094
0095 if (debug()) {
0096 std::cout << "DTTracoCard::loadTRACO called for wheel=" << wheel();
0097 std::cout << ", station=" << station();
0098 std::cout << ", sector=" << sector() << std::endl;
0099 }
0100
0101 int maxtc = int(ceil(float(geom()->nCell(1)) / float(DTConfig::NBTITC)));
0102
0103
0104 std::vector<DTBtiTrigData>::const_iterator p;
0105 std::vector<DTBtiTrigData>::const_iterator pend = _bticard->end();
0106 for (p = _bticard->begin(); p != pend; p++) {
0107 if (debug()) {
0108 std::cout << "Found bti trigger: ";
0109 (*p).print();
0110 }
0111
0112
0113 int nbti = (*p).btiNumber();
0114 int nsl = (*p).btiSL();
0115 int step = (*p).step();
0116 int K = (*p).K();
0117 DTBtiId id_bti = (*p).parentId();
0118
0119 DTConfigBti *conf_bti = _bticard->config_bti(id_bti);
0120 int LL = conf_bti->LL();
0121 int LH = conf_bti->LH();
0122 int CL = conf_bti->CL();
0123 int CH = conf_bti->CH();
0124 int RL = conf_bti->RL();
0125 int RH = conf_bti->RH();
0126
0127
0128
0129
0130
0131
0132
0133
0134 int ntc = static_cast<int>((nbti - 1) / DTConfig::NBTITC) + 1;
0135 if (ntc < 1 || ntc > maxtc)
0136 continue;
0137
0138 if (debug())
0139 std::cout << "Bti trigger assigned to traco " << ntc << " (maxtc " << maxtc << ")" << std::endl;
0140
0141
0142 DTTracoId tracoid = DTTracoId(wheel(), station(), sector(), ntc);
0143
0144
0145 int pos = nbti - (ntc - 1) * DTConfig::NBTITC;
0146
0147
0148
0149
0150
0151
0152
0153
0154 if (nsl == 1) {
0155 if (!_flag_acc || (K >= CL && K <= CH))
0156 activeGetTRACO(ntc)->add_btiT(step, pos, &(*p));
0157 else if (debug())
0158 std::cout << "ATTENTION: in TRACO n. " << ntc << " bti pos " << pos << " trigger K= " << K
0159 << " outside acceptance " << CL << "<K<" << CH << std::endl;
0160 }
0161
0162
0163 if (nsl == 3) {
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 if ((ntc - 1) > 0 && (ntc - 1) <= maxtc) {
0176 if (!_flag_acc || (K >= LL && K <= LH)) {
0177 activeGetTRACO(ntc - 1)->add_btiT(step, pos + 8 - 4 * (-1), &(*p));
0178 } else {
0179 if (debug()) {
0180 std::cout << "ATTENTION: in TRACO n. " << ntc - 1 << " bti pos " << pos + 8 - 4 * (-1)
0181 << " trigger K= " << K << " outside acceptance " << LL << "<K<" << LH << std::endl;
0182 }
0183 }
0184 }
0185
0186
0187 if ((ntc) > 0 && (ntc) <= maxtc) {
0188 if (!_flag_acc || (K >= CL && K <= CH)) {
0189 activeGetTRACO(ntc)->add_btiT(step, pos + 8 - 4 * (0), &(*p));
0190 } else {
0191 if (debug())
0192 std::cout << "ATTENTION: in TRACO n. " << ntc << " bti pos " << pos + 8 - 4 * (0) << " trigger K= " << K
0193 << " outside acceptance " << CL << "<K<" << CH << std::endl;
0194 }
0195 }
0196
0197
0198 if ((ntc + 1) > 0 && (ntc + 1) <= maxtc) {
0199 if (!_flag_acc || (K >= RL && K <= RH)) {
0200 activeGetTRACO(ntc + 1)->add_btiT(step, pos + 8 - 4 * (+1), &(*p));
0201 } else {
0202 if (debug())
0203 std::cout << "ATTENTION: in TRACO n. " << ntc + 1 << " bti pos " << pos + 8 - 4 * (+1)
0204 << " trigger K= " << K << " outside acceptance " << RL << "<K<" << RH << std::endl;
0205 }
0206 }
0207 }
0208
0209
0210
0211 }
0212 }
0213
0214 void DTTracoCard::runTRACO() {
0215 if (debug()) {
0216 std::cout << "DTTracoCard:runTRACO called for wheel=" << wheel();
0217 std::cout << ", station=" << station();
0218 std::cout << ", sector=" << sector();
0219 std::cout << ", " << _tracomap.size() << " TRACOs with signal" << std::endl;
0220 }
0221
0222
0223 if (!_tracomap.empty()) {
0224 if (debug()) {
0225 std::cout << "====================================================" << std::endl;
0226 std::cout << " TRACO triggers " << std::endl;
0227 }
0228
0229 TRACO_iter ptraco;
0230 for (ptraco = _tracomap.begin(); ptraco != _tracomap.end(); ptraco++) {
0231 DTTracoChip *traco = (*ptraco).second;
0232 traco->run();
0233 for (int step = DTConfig::NSTEPF; step <= DTConfig::NSTEPL; step++) {
0234 if (traco->nTrig(step) > 0) {
0235 _cache.push_back(traco->triggerData(step, 1));
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247 }
0248
0249 if (traco->nTrig(step) > 1 && traco->useSecondTrack(step)) {
0250 _cache.push_back(traco->triggerData(step, 2));
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262 }
0263 }
0264 }
0265 if (debug())
0266 std::cout << "====================================================" << std::endl;
0267 }
0268 }
0269
0270 DTTracoChip *DTTracoCard::activeGetTRACO(int n) {
0271
0272 DTChamberId sid = geom()->statId();
0273 DTTracoId _id = DTTracoId(sid, n);
0274
0275 DTTracoChip *traco = nullptr;
0276 TRACO_iter ptraco = _tracomap.find(n);
0277 if (ptraco != _tracomap.end()) {
0278 traco = (*ptraco).second;
0279 } else {
0280 traco = new DTTracoChip(this, n, config_traco(_id));
0281 _tracomap[n] = traco;
0282 }
0283 return traco;
0284 }
0285
0286 DTTracoChip *DTTracoCard::getTRACO(int n) const {
0287 TRACO_const_iter ptraco = _tracomap.find(n);
0288 if (ptraco == _tracomap.end())
0289 return nullptr;
0290 return (*ptraco).second;
0291 }
0292
0293 std::vector<DTTracoChip *> DTTracoCard::tracoList() {
0294 std::vector<DTTracoChip *> blist;
0295
0296 if (size() < 1)
0297 return blist;
0298
0299 for (TRACO_const_iter p = _tracomap.begin(); p != _tracomap.end(); p++) {
0300 blist.push_back((*p).second);
0301 }
0302 return blist;
0303 }
0304
0305 DTTracoTrig *DTTracoCard::storeTrigger(DTTracoTrigData td) {
0306 DTTracoId tracoid = td.parentId();
0307 if (!(tracoid.wheel() == wheel() && tracoid.sector() == sector() && tracoid.station() == station()))
0308 return nullptr;
0309 std::cout << "DTTracoChip::trigger: trigger not belonging to this card! ";
0310 std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
0311 std::cout << "trig=(" << tracoid.wheel() << "," << tracoid.station() << "," << tracoid.sector() << ")";
0312
0313 DTTracoChip *traco = activeGetTRACO(tracoid.traco());
0314
0315 DTTracoTrig *trig = new DTTracoTrig(traco, td);
0316
0317 traco->addTrig(td.step(), trig);
0318
0319 return trig;
0320 }
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351 LocalPoint DTTracoCard::localPosition(const DTTrigData *tr) const {
0352
0353 DTTracoTrigData *trig = dynamic_cast<DTTracoTrigData *>(const_cast<DTTrigData *>(tr));
0354 if (!trig) {
0355 std::cout << "DTTracoCard::localPosition called with wrong argument!" << std::endl;
0356 return LocalPoint(0, 0, 0);
0357 }
0358 float x = geom()->localPosition(trig->parentId()).x();
0359 float y = geom()->localPosition(trig->parentId()).y();
0360 float z = geom()->localPosition(trig->parentId()).z();
0361
0362 float trig_pos = geom()->cellPitch() * ((float)trig->X() / (float)(config_traco(trig->parentId())->BTIC()));
0363
0364
0365
0366
0367
0368 x += trig_pos;
0369
0370
0371
0372 if (trig->posIn() == 0) {
0373 z -= 0.5 * geom()->distSL();
0374 } else if (trig->posOut() == 0) {
0375 z += 0.5 * geom()->distSL();
0376 }
0377 return LocalPoint(x, y, z);
0378 }
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403 LocalVector DTTracoCard::localDirection(const DTTrigData *tr) const {
0404
0405 DTTracoTrigData *trig = dynamic_cast<DTTracoTrigData *>(const_cast<DTTrigData *>(tr));
0406 if (!trig) {
0407 std::cout << "DTtracoCard::localDirection called with wrong argument!" << std::endl;
0408 return LocalVector(0, 0, 0);
0409 }
0410
0411
0412
0413
0414 float psi =
0415 atan((float)(trig->K()) * geom()->cellPitch() / (geom()->distSL() * config_traco(trig->parentId())->BTIC()));
0416
0417 if (config_traco(trig->parentId())->debug() == 4)
0418 std::cout << "K " << trig->K() << " == psi " << psi << " in FE frame " << std::endl;
0419
0420
0421 float xd = -sin(psi);
0422 float yd = 0;
0423 float zd = -cos(psi);
0424
0425
0426
0427
0428
0429
0430 if (config_traco(trig->parentId())->debug() == 4)
0431 std::cout << "Direction in chamber frame is (" << xd << "," << yd << "," << zd << ")" << std::endl;
0432
0433 return LocalVector(xd, yd, zd);
0434 }
0435
0436 DTConfigTraco *DTTracoCard::config_traco(const DTTracoId &tracoid) const {
0437
0438 ConfTracoMap::const_iterator titer = _conf_traco_map.find(tracoid);
0439 if (titer == _conf_traco_map.end()) {
0440 std::cout << "DTTracoCard::config_traco : TRACO (" << tracoid.wheel() << "," << tracoid.sector() << ","
0441 << tracoid.station() << "," << tracoid.traco() << ") not found, return 0" << std::endl;
0442 return nullptr;
0443 }
0444
0445 return const_cast<DTConfigTraco *>(&(*titer).second);
0446 }