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