00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "L1Trigger/DTTraco/interface/DTTracoCard.h"
00024
00025
00026
00027
00028 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00029 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00030 #include "L1Trigger/DTTraco/interface/DTTracoChip.h"
00031 #include "L1Trigger/DTTraco/interface/DTTracoTrig.h"
00032 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
00033 #include "L1Trigger/DTBti/interface/DTBtiTrigData.h"
00034 #include "L1Trigger/DTTriggerServerTheta/interface/DTTSTheta.h"
00035
00036
00037
00038
00039 #include <iostream>
00040 #include <cmath>
00041 #include <utility>
00042 #include <iomanip>
00043 #include <math.h>
00044
00045
00046
00047
00048
00049 DTTracoCard::DTTracoCard(DTTrigGeom* geo, DTBtiCard* bticard,
00050 DTTSTheta* tstheta) : DTGeomSupplier(geo) ,
00051 _bticard(bticard), _tstheta(tstheta) {
00052
00053 }
00054
00055
00056
00057
00058
00059 DTTracoCard::~DTTracoCard(){
00060
00061 localClear();
00062
00063 }
00064
00065
00066
00067
00068
00069 void
00070 DTTracoCard::clearCache(){
00071
00072 TRACOCache::clearCache();
00073 localClear();
00074
00075 }
00076
00077 void
00078 DTTracoCard::setConfig(const DTConfigManager *conf){
00079
00080 DTChamberId sid = ChamberId();
00081 _conf_traco_map = conf->getDTConfigTracoMap(sid);
00082 _debug = conf->getDTTPGDebug();
00083
00084
00085 _flag_acc = conf->useAcceptParam();
00086
00087
00088 _lut_from_db = conf->lutFromDB();
00089
00090
00091
00092 if(_lut_from_db)
00093 _conf_luts = conf->getDTConfigLUTs(sid);
00094
00095 }
00096
00097 void
00098 DTTracoCard::localClear(){
00099
00100 for(TRACO_iter p=_tracomap.begin();p!=_tracomap.end();p++){
00101 delete (*p).second;
00102 }
00103 _tracomap.clear();
00104 }
00105
00106 void
00107 DTTracoCard::loadTRACO() {
00108
00109 localClear();
00110
00111 if(debug()){
00112 std::cout << "DTTracoCard::loadTRACO called for wheel=" << wheel() ;
00113 std::cout << ", station=" << station();
00114 std::cout << ", sector=" << sector() << std::endl;
00115 }
00116
00117 int maxtc = int(ceil( float(geom()->nCell(1)) / float(DTConfig::NBTITC) ));
00118
00119
00120 std::vector<DTBtiTrigData>::const_iterator p;
00121 std::vector<DTBtiTrigData>::const_iterator pend=_bticard->end();
00122 for(p=_bticard->begin();p!=pend;p++){
00123 if(debug()){
00124 std::cout << "Found bti trigger: ";
00125 (*p).print();
00126 }
00127
00128
00129 int nbti = (*p).btiNumber();
00130 int nsl = (*p).btiSL();
00131 int step = (*p).step();
00132 int K = (*p).K();
00133 DTBtiId id_bti = (*p).parentId();
00134
00135 DTConfigBti* conf_bti = _bticard->config_bti( id_bti );
00136 int LL = conf_bti->LL();
00137 int LH = conf_bti->LH();
00138 int CL = conf_bti->CL();
00139 int CH = conf_bti->CH();
00140 int RL = conf_bti->RL();
00141 int RH = conf_bti->RH();
00142
00143
00144
00145
00146
00147
00148
00149
00150 int ntc = static_cast<int>((nbti-1)/DTConfig::NBTITC)+1;
00151 if( ntc<1 || ntc>maxtc )
00152 continue;
00153
00154 if(debug())
00155 std::cout << "Bti trigger assigned to traco " << ntc << " (maxtc " << maxtc << ")" << std::endl;
00156
00157
00158 DTTracoId tracoid = DTTracoId(wheel(),station(),sector(),ntc);
00159
00160
00161 int pos = nbti-(ntc-1)*DTConfig::NBTITC;
00162
00163
00164
00165
00166
00167
00168
00169
00170 if( nsl==1 ) {
00171 if( !_flag_acc || (K>=CL && K<=CH) )
00172 activeGetTRACO(ntc)->add_btiT( step, pos, &(*p) );
00173 else
00174 if(debug())
00175 std::cout << "ATTENTION: in TRACO n. " << ntc
00176 << " bti pos " << pos << " trigger K= " << K
00177 << " outside acceptance " << CL << "<K<" << CH << std::endl;
00178 }
00179
00180
00181 if( nsl==3 ) {
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 if( (ntc-1)>0 && (ntc-1)<=maxtc ) {
00193 if( !_flag_acc || (K>=LL && K<=LH) ) {
00194 activeGetTRACO(ntc-1)->add_btiT( step, pos+8-4*(-1), &(*p) );
00195 } else {
00196 if(debug()) {
00197 std::cout << "ATTENTION: in TRACO n. " << ntc-1
00198 << " bti pos " << pos+8-4*(-1) << " trigger K= " << K
00199 << " outside acceptance " << LL << "<K<" << LH << std::endl;
00200 }
00201 }
00202 }
00203
00204
00205 if( (ntc)>0 && (ntc)<=maxtc ) {
00206 if( !_flag_acc || (K>=CL && K<=CH) ) {
00207 activeGetTRACO(ntc)->add_btiT( step, pos+8-4*(0), &(*p) );
00208 } else {
00209 if(debug())
00210 std::cout << "ATTENTION: in TRACO n. " << ntc
00211 << " bti pos " << pos+8-4*(0) << " trigger K= " << K
00212 << " outside acceptance " << CL << "<K<" << CH << std::endl;
00213 }
00214 }
00215
00216
00217 if( (ntc+1)>0 && (ntc+1)<=maxtc ) {
00218 if( !_flag_acc || (K>=RL && K<=RH) ) {
00219 activeGetTRACO(ntc+1)->add_btiT( step, pos+8-4*(+1), &(*p) );
00220 } else {
00221 if(debug())
00222 std::cout << "ATTENTION: in TRACO n. " << ntc+1
00223 << " bti pos " << pos+8-4*(+1) << " trigger K= " << K
00224 << " outside acceptance " << RL << "<K<" << RH << std::endl;
00225 }
00226 }
00227 }
00228
00229
00230
00231 }
00232 }
00233
00234 void
00235 DTTracoCard::runTRACO() {
00236
00237 if(debug()){
00238 std::cout << "DTTracoCard:runTRACO called for wheel=" << wheel() ;
00239 std::cout << ", station=" << station();
00240 std::cout << ", sector=" << sector();
00241 std::cout << ", " << _tracomap.size() << " TRACOs with signal" << std::endl;
00242 }
00243
00244
00245 if(_tracomap.size()>0){
00246
00247 if(debug()){
00248 std::cout << "====================================================" << std::endl;
00249 std::cout << " TRACO triggers " << std::endl;
00250 }
00251
00252
00253 TRACO_iter ptraco;
00254 for(ptraco=_tracomap.begin(); ptraco!=_tracomap.end(); ptraco++) {
00255 DTTracoChip* traco = (*ptraco).second;
00256 traco->run();
00257 for(int step=DTConfig::NSTEPF; step<=DTConfig::NSTEPL; step++){
00258 if( traco->nTrig(step)>0 ){
00259 _cache.push_back( traco->triggerData(step,1) );
00260
00261
00262
00263
00264
00265
00266
00267
00268 }
00269
00270 if( traco->nTrig(step)>1 && traco->useSecondTrack(step) ){
00271 _cache.push_back( traco->triggerData(step,2) );
00272
00273
00274
00275
00276
00277
00278
00279
00280 }
00281 }
00282 }
00283 if(debug())
00284 std::cout << "====================================================" << std::endl;
00285 }
00286 }
00287
00288 DTTracoChip*
00289 DTTracoCard::activeGetTRACO(int n) {
00290
00291
00292 DTChamberId sid = geom()->statId();
00293 DTTracoId _id = DTTracoId(sid,n);
00294
00295 DTTracoChip* traco = 0;
00296 TRACO_iter ptraco = _tracomap.find(n);
00297 if( ptraco!=_tracomap.end() ) {
00298 traco=(*ptraco).second;
00299 } else {
00300 traco = new DTTracoChip(this,n,config_traco(_id));
00301 _tracomap[n]=traco;
00302 }
00303 return traco;
00304 }
00305
00306 DTTracoChip*
00307 DTTracoCard::getTRACO(int n) const {
00308 TRACO_const_iter ptraco = _tracomap.find(n);
00309 if( ptraco==_tracomap.end() ) return 0;
00310 return (*ptraco).second;
00311 }
00312
00313 std::vector<DTTracoChip*>
00314 DTTracoCard::tracoList() {
00315
00316 std::vector<DTTracoChip*> blist;
00317
00318 if(size()<1)return blist;
00319
00320 for(TRACO_const_iter p=_tracomap.begin();p!=_tracomap.end();p++){
00321 blist.push_back((*p).second);
00322 }
00323 return blist;
00324
00325 }
00326
00327 DTTracoTrig*
00328 DTTracoCard::storeTrigger(DTTracoTrigData td) {
00329 DTTracoId tracoid = td.parentId();
00330 if(!(tracoid.wheel()==wheel() &&
00331 tracoid.sector()==sector() &&
00332 tracoid.station()==station()) ) return 0;
00333 std::cout << "DTTracoChip::trigger: trigger not belonging to this card! ";
00334 std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
00335 std::cout << "trig=(" << tracoid.wheel() << "," << tracoid.station() << ","
00336 << tracoid.sector() << ")";
00337
00338 DTTracoChip* traco = activeGetTRACO(tracoid.traco());
00339
00340 DTTracoTrig* trig = new DTTracoTrig(traco,td);
00341
00342 traco->addTrig(td.step(),trig);
00343
00344 return trig;
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 LocalPoint
00376 DTTracoCard::localPosition(const DTTrigData* tr) const {
00377
00378 DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00379 if(!trig) {
00380 std::cout << "DTTracoCard::localPosition called with wrong argument!" << std::endl;
00381 return LocalPoint(0,0,0);
00382 }
00383 float x = geom()->localPosition(trig->parentId()).x();
00384 float y = geom()->localPosition(trig->parentId()).y();
00385 float z = geom()->localPosition(trig->parentId()).z();
00386
00387 float trig_pos = geom()->cellPitch() * ( (float)trig->X() / (float)(config_traco(trig->parentId())->BTIC()));
00388
00389
00390
00391
00392
00393 x += trig_pos;
00394
00395
00396
00397 if(trig->posIn()==0 ) {
00398 z -= 0.5 * geom()->distSL();
00399 }
00400 else if(trig->posOut()==0) {
00401 z += 0.5 * geom()->distSL();
00402 }
00403 return LocalPoint(x,y,z);
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 LocalVector
00429 DTTracoCard::localDirection(const DTTrigData* tr) const {
00430
00431 DTTracoTrigData* trig = dynamic_cast<DTTracoTrigData*>(const_cast<DTTrigData*>(tr));
00432 if(!trig) {
00433 std::cout << "DTtracoCard::localDirection called with wrong argument!" << std::endl;
00434 return LocalVector(0,0,0);
00435 }
00436
00437
00438
00439
00440 float psi = atan((float)(trig->K())*geom()->cellPitch()
00441 /( geom()->distSL() * config_traco(trig->parentId())->BTIC()) );
00442
00443 if(config_traco(trig->parentId())->debug()==4)
00444 std::cout << "K " << trig->K() << " == psi " << psi << " in FE frame " << std::endl;
00445
00446
00447 float xd=-sin(psi);
00448 float yd=0;
00449 float zd=-cos(psi);
00450
00451
00452
00453
00454
00455
00456
00457 if(config_traco(trig->parentId())->debug()==4)
00458 std::cout << "Direction in chamber frame is (" << xd << "," << yd << "," << zd << ")" << std::endl;
00459
00460 return LocalVector(xd,yd,zd);
00461 }
00462
00463 DTConfigTraco*
00464 DTTracoCard::config_traco(const DTTracoId& tracoid) const
00465 {
00466
00467 ConfTracoMap::const_iterator titer = _conf_traco_map.find(tracoid);
00468 if (titer == _conf_traco_map.end()){
00469 std::cout << "DTTracoCard::config_traco : TRACO (" << tracoid.wheel()
00470 << "," << tracoid.sector()
00471 << "," << tracoid.station()
00472 << "," << tracoid.traco()
00473 << ") not found, return 0" << std::endl;
00474 return 0;
00475 }
00476
00477 return const_cast<DTConfigTraco*>(&(*titer).second);
00478 }
00479