00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "L1Trigger/DTUtilities/interface/DTTrigGeom.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <iostream>
00028 #include <iomanip>
00029 #include <fstream>
00030 #include <sstream>
00031 #include <cstring>
00032
00033
00034
00035
00036 #include "Geometry/DTGeometry/interface/DTTopology.h"
00037 #include "Geometry/DTGeometry/interface/DTLayer.h"
00038 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
00039 #include "Geometry/DTGeometry/interface/DTChamber.h"
00040 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00041 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00042 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00043 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00044
00045 using namespace std;
00046
00047
00048
00049
00050
00051 DTTrigGeom::DTTrigGeom(DTChamber* stat, bool debug) : _stat(stat) , _debug(debug) {
00052
00053 getGeom();
00054
00055 }
00056
00057
00058
00059
00060
00061
00062 DTTrigGeom::~DTTrigGeom() {}
00063
00064
00065
00066
00067
00068
00069 float
00070 DTTrigGeom::phiSLOffset(){
00071
00072 float x1 = tubePosInCh(1,1,1).x();
00073 float x3 = tubePosInCh(3,1,1).x();
00074 float offset = x1-x3;
00075
00076
00077
00078 return offset;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 int
00143 DTTrigGeom::mapTubeInFEch(int nsl, int nlay, int ntube) const {
00144 int nch = 0;
00145 if(station()==4 && nsl==2){
00146 std::cout << "No theta superlayer in station 4!" << std::endl;
00147 }
00148 else{
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 nch =ntube;
00160
00161
00162
00163 }
00164 return nch;
00165 }
00166
00167 LocalPoint
00168 DTTrigGeom::tubePosInCh(int nsl, int nlay, int ntube) const {
00169 if ( nlay==4 && ntube==1) {
00170 std::cout << "ATTENTION: no wire nuber 1 for 4th layer!!!" << std::endl;
00171 LocalPoint dummyLP(0,0,0);
00172 return dummyLP;
00173 }
00174 const DTSuperLayer* sl = _stat->superLayer(DTSuperLayerId(statId(),nsl));
00175 const DTLayer* lay = sl->layer(DTLayerId(statId(),nsl,nlay));
00176
00177 float localX = lay->specificTopology().wirePosition(ntube);
00178 LocalPoint posInLayer(localX,0,0);
00179 LocalPoint posInChamber = _stat->surface().toLocal(lay->toGlobal(posInLayer));
00180
00181
00182
00183
00184
00185
00186 return posInChamber;
00187 }
00188
00189 int
00190 DTTrigGeom::posFE(int sl) const {
00191 if( station()!=4 || sl!=2 ) {
00192
00193 return 1;
00194 }
00195 else{
00196 std::cout << "No theta superlayer in station 4!" << std::endl;
00197 return 0;
00198 }
00199 }
00200
00201 void
00202 DTTrigGeom::setGeom(const DTChamber* stat) {
00203
00204 _stat=stat;
00205 getGeom();
00206
00207 }
00208
00209 void
00210 DTTrigGeom::getGeom() {
00211
00212
00213
00214 _PITCH = 4.2;
00215
00216 _H = 1.3;
00217
00218 _PHICH = _stat->surface().toGlobal(LocalVector(0,0,-1)).phi();
00219
00220
00221 DTSuperLayer* sl[3];
00222 DTLayer* l1[3];
00223 DTLayer* l3[3];
00224 int i = 0;
00225 for(i=0; i<3; i++) {
00226 if(station()==4&&i==1) {
00227 _ZSL[i] = -999;
00228 _NCELL[i] = 0;
00229 } else {
00230 sl[i] = (DTSuperLayer*) _stat->superLayer(DTSuperLayerId(statId(),i+1));
00231 l1[i] = (DTLayer*) sl[i]->layer(DTLayerId(statId(),i+1,1));
00232 l3[i] = (DTLayer*) sl[i]->layer(DTLayerId(statId(),i+1,3));
00233 _ZSL[i] = _stat->surface().toLocal(sl[i]->position()).z();
00234
00235 const DTTopology& tp=l1[i]->specificTopology();
00236 float posX=tp.wirePosition(tp.firstChannel());
00237 LocalPoint posInLayer(posX,0,0);
00238 LocalPoint posInChamber=_stat->surface().toLocal(l1[i]->surface().toGlobal(posInLayer));
00239 _NCELL[i] = l1[i]->specificTopology().channels();
00240 }
00241 }
00242
00243
00244 if(_debug){
00245 std::cout << setiosflags(std::ios::showpoint | std::ios::fixed) << std::setw(4) <<
00246 std::setprecision(1);
00247 std::cout << "Identification: wheel=" << wheel();
00248 std::cout << ", station=" << station();
00249 std::cout << ", sector=" << sector() << std::endl;
00250 GlobalPoint pp = _stat->toGlobal(LocalPoint(0,0,0));
00251 std::cout << "Position: Mag=" << pp.mag() << "cm, Phi=" << pp.phi()*180/3.14159;
00252 std::cout << " deg, Z=" << pp.z() << " cm" << std::endl;
00253 std::cout << "Rotation: ANGLE=" << phiCh()*180/3.14159 << std::endl;
00254
00255 std::cout << "Z of superlayers: phi=" << ZSL(1) << ", ";
00256 std::cout << ZSL(3) << " theta=" << ZSL(2);
00257 std::cout << " (DeltaY = " << distSL() << ")" << std::endl;
00258 std::cout << " ncell: sl 1 " << nCell(1) << " sl 2 " << nCell(2) <<
00259 " sl 3 " << nCell(3) << std::endl;
00260
00261 }
00262
00263
00264 }
00265
00266 float
00267 DTTrigGeom::ZSL(int sl) const {
00268 if(sl<1||sl>3){
00269 std::cout << "DTTrigGeom::ZSL: wrong SL number: " << sl;
00270 std::cout << -999 << " returned" << std::endl;
00271 return -999;
00272 }
00273 return _ZSL[sl-1];
00274 }
00275
00276
00277 void
00278 DTTrigGeom::dumpGeom() const {
00279 std::cout << "Identification: wheel=" << wheel();
00280 std::cout << ", station=" << station();
00281 std::cout << ", sector=" << sector() << std::endl;
00282 GlobalPoint pp = _stat->toGlobal(LocalPoint(0,0,0));
00283 std::cout << "Position: Mag=" << pp.mag() << "cm, Phi=" << pp.phi()*180/3.14159;
00284 std::cout << " deg, Z=" << pp.z() << " cm" << std::endl;
00285 std::cout << "Rotation: ANGLE=" << phiCh()*180/3.14159 << std::endl;
00286 std::cout << "Z of superlayers: phi=" << ZSL(1) << ", ";
00287 std::cout << ZSL(3) << " theta=" << ZSL(2) << std::endl;
00288 std::cout << "Number of cells: SL1=" << nCell(1) << " SL2=" << nCell(2) <<
00289 " SL3=" << nCell(3) << std::endl;
00290 std::cout << "First wire positions:" << std::endl;
00291 int ii=0;
00292 int jj=0;
00293 for( ii = 1; ii<=3; ii++ ) {
00294 if(station()!=4||ii!=2){
00295 for ( jj =1; jj<=4; jj++ ) {
00296 std::cout << " SL=" << ii << ", lay=" << jj << ", wire 1 position=";
00297 if ( jj ==4)
00298 std::cout << tubePosInCh( ii, jj, 2) << std::endl;
00299 else
00300 std::cout << tubePosInCh( ii, jj, 1) << std::endl;
00301 }
00302 }
00303 }
00304
00305 GlobalPoint gp1 = CMSPosition(DTBtiId(statId(),1,1));
00306
00307
00308 std::cout << "First BTI position:";
00309 std::cout << " SL1:" << localPosition(DTBtiId(statId(),1,1)) << std::endl;
00310 std::cout << " Position: R=" << gp1.perp() << "cm, Phi=" << gp1.phi()*180/3.14159 << " deg, Z=" << gp1.z() << " cm" << std::endl;
00311
00312 if(station()!=4)
00313 {
00314 GlobalPoint gp2 = CMSPosition(DTBtiId(statId(),2,1));
00315 std::cout << " SL2:" << localPosition(DTBtiId(statId(),2,1))<< std::endl;
00316 std::cout << " Position: R=" << gp2.perp() << "cm, Phi=" << gp2.phi()*180/3.14159 << " deg, Z=" << gp2.z() << " cm" << std::endl;
00317 }
00318
00319 GlobalPoint gp3 = CMSPosition(DTBtiId(statId(),3,1));
00320 std::cout << " SL3:" << localPosition(DTBtiId(statId(),3,1)) << std::endl;
00321 std::cout << " Position: R=" << gp3.perp() << "cm, Phi=" << gp3.phi()*180/3.14159 << " deg, Z=" << gp3.z() << " cm" << std::endl;
00322
00323 std::cout << "First TRACO position:";
00324 std::cout << localPosition(DTTracoId(statId(),1)) << std::endl;
00325 std::cout << "******************************************************" << std::endl;
00326 }
00327
00328 void
00329 DTTrigGeom::dumpLUT(short int btic) {
00330
00331
00332 int wh = wheel();
00333 int st = station();
00334 int se = sector();
00335
00336
00337 string name = "Lut_from_CMSSW_geom";
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 name += ".txt";
00354
00355 ofstream fout;
00356 fout.open(name.c_str(),ofstream::app);
00357
00358
00359
00360
00361
00362 fout << wh;
00363 fout << "\t" << st;
00364 fout << "\t" << se;
00365
00366
00367 float xBTI1_3 = localPosition( DTBtiId(DTSuperLayerId(wheel(),station(),sector(),3),1) ).x();
00368 float xBTI1_1 = localPosition( DTBtiId(DTSuperLayerId(wheel(),station(),sector(),1),1) ).x();
00369 float SL_shift = xBTI1_3 - xBTI1_1;
00370
00371
00372
00373 LocalPoint traco1 = localPosition(DTTracoId(statId(),1));
00374 LocalPoint traco2 = localPosition(DTTracoId(statId(),2));
00375 GlobalPoint traco_1 = toGlobal(traco1);
00376 GlobalPoint traco_2 = toGlobal(traco2);
00377
00378
00379 float d;
00380 float xcn;
00381 int xcn_sign;
00382 GlobalPoint pp = _stat->toGlobal(LocalPoint(0,0,ZcenterSL()));
00383
00384
00385 if(sector()==1 || sector() ==7){
00386 d = fabs(traco_1.x());
00387 xcn = fabs(traco_1.y());
00388
00389 if (SL_shift > 0)
00390 xcn = xcn+SL_shift;
00391 xcn_sign = static_cast<int>(pp.y()/fabs(pp.y()))*static_cast<int>(traco_1.y()/fabs(traco_1.y()));
00392 if(station() == 2 || (station() == 4 && sector() == 1))
00393 xcn_sign = - xcn_sign;
00394 xcn = xcn*xcn_sign;
00395 }
00396 else {
00397 float m1 = (traco_2.y()-traco_1.y())/(traco_2.x()-traco_1.x());
00398 float q1 = traco_1.y()-m1*traco_1.x();
00399 float m = tan(phiCh());
00400 float xn = q1/(m-m1);
00401 float yn = m*xn;
00402
00403 d = sqrt(xn*xn+yn*yn);
00404 xcn = sqrt( (xn-traco_1.x())*(xn-traco_1.x()) + (yn-traco_1.y())*(yn-traco_1.y()) );
00405
00406 if (SL_shift > 0)
00407 xcn = xcn+SL_shift;
00408
00409 float diff = (pp.x()-traco_1.x())*traco_1.y();
00410 xcn_sign = static_cast<int>(diff/fabs(diff));
00411 xcn = xcn*xcn_sign;
00412 }
00413
00414
00415
00416
00417
00418 fout << "\tA8";
00419
00420
00421 short int Low_byte = (btic & 0x00FF);
00422 short int High_byte =( btic>>8 & 0x00FF);
00423 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00424
00425
00426 short int DSPmantissa = 0;
00427 short int DSPexp = 0;
00428
00429
00430 IEEE32toDSP(d, DSPmantissa, DSPexp);
00431 Low_byte = (DSPmantissa & 0x00FF);
00432 High_byte =( DSPmantissa>>8 & 0x00FF);
00433 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00434 Low_byte = (DSPexp & 0x00FF);
00435 High_byte =( DSPexp>>8 & 0x00FF);
00436 fout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte;
00437
00438
00439 DSPmantissa = 0;
00440 DSPexp = 0;
00441 IEEE32toDSP(xcn, DSPmantissa, DSPexp);
00442 Low_byte = (DSPmantissa & 0x00FF);
00443 High_byte =( DSPmantissa>>8 & 0x00FF);
00444 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte;
00445 Low_byte = (DSPexp & 0x00FF);
00446 High_byte =( DSPexp>>8 & 0x00FF);
00447 fout << setw(2) << setfill('0') << High_byte << setw(2) << setfill('0') << Low_byte;
00448
00449
00450 Low_byte = (xcn_sign & 0x00FF);
00451 High_byte =( xcn_sign>>8 & 0x00FF);
00452 fout << setw(2) << setfill('0') << hex << High_byte << setw(2) << setfill('0') << Low_byte << dec << "\n";
00453
00454 fout.close();
00455
00456 return;
00457
00458 }
00459
00460 void
00461 DTTrigGeom::IEEE32toDSP(float f, short int & DSPmantissa, short int & DSPexp)
00462 {
00463 long int *pl=0, lm;
00464 bool sign=false;
00465
00466 DSPmantissa = 0;
00467 DSPexp = 0;
00468
00469 if( f!=0.0 )
00470 {
00471 memcpy(pl,&f,sizeof(float));
00472 if((*pl & 0x80000000)!=0)
00473 sign=true;
00474 lm = ( 0x800000 | (*pl & 0x7FFFFF));
00475 lm >>= 9;
00476 lm &= 0x7FFF;
00477 DSPexp = ((*pl>>23)&0xFF)-126;
00478 DSPmantissa = (short)lm;
00479 if(sign)
00480 DSPmantissa = - DSPmantissa;
00481
00482 }
00483 return;
00484 }
00485
00486
00487 LocalPoint
00488 DTTrigGeom::localPosition(const DTBtiId id) const {
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529 int nsl = id.superlayer();
00530 const DTSuperLayer* sl = _stat->superLayer(DTSuperLayerId(statId(),nsl));
00531 const DTLayer* lay = sl->layer(DTLayerId(statId(),nsl,1));
00532 int tube = id.bti();
00533 float localX = lay->specificTopology().wirePosition(tube);
00534 float xt = -cellPitch()/2.;
00535 float zt = -cellH() * 3./2.;
00536
00537 LocalPoint posInLayer1(localX+xt,0,zt);
00538 LocalPoint posInChamber = _stat->surface().toLocal(lay->toGlobal(posInLayer1));
00539
00540
00541
00542
00543
00544
00545 return posInChamber;
00546 }
00547
00548 LocalPoint
00549 DTTrigGeom::localPosition(const DTTracoId id) const {
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560 float x = localPosition( DTBtiId(DTSuperLayerId(wheel(),station(),sector(),3),1) ).x();
00561
00562
00563
00564
00565 x += (id.traco()-2)*DTConfig::NBTITC * cellPitch();
00566
00567 float y = 0;
00568 float z = ZcenterSL();
00569
00570 return LocalPoint(x,y,z);
00571 }