00001
00002
00003
00004
00005
00006
00007
00008 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00009 #include "Alignment/CocoaModel/interface/OpticalObjectMgr.h"
00010 #include "Alignment/CocoaModel/interface/OptOLaser.h"
00011 #include "Alignment/CocoaModel/interface/OptOSource.h"
00012 #include "Alignment/CocoaModel/interface/OptOXLaser.h"
00013 #include "Alignment/CocoaModel/interface/OptOMirror.h"
00014 #include "Alignment/CocoaModel/interface/OptOPlateSplitter.h"
00015 #include "Alignment/CocoaModel/interface/OptOCubeSplitter.h"
00016 #include "Alignment/CocoaModel/interface/OptOModifiedRhomboidPrism.h"
00017 #include "Alignment/CocoaModel/interface/OptOOpticalSquare.h"
00018 #include "Alignment/CocoaModel/interface/OptOLens.h"
00019 #include "Alignment/CocoaModel/interface/OptORisleyPrism.h"
00020 #include "Alignment/CocoaModel/interface/OptOSensor2D.h"
00021 #include "Alignment/CocoaModel/interface/OptODistancemeter.h"
00022 #include "Alignment/CocoaModel/interface/OptODistancemeter3dim.h"
00023 #include "Alignment/CocoaModel/interface/OptOScreen.h"
00024 #include "Alignment/CocoaModel/interface/OptOTiltmeter.h"
00025 #include "Alignment/CocoaModel/interface/OptOPinhole.h"
00026 #include "Alignment/CocoaModel/interface/OptOCOPS.h"
00027 #include "Alignment/CocoaModel/interface/OptOUserDefined.h"
00028 #include "Alignment/CocoaModel/interface/ALIPlane.h"
00029
00030 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00031 #include "Alignment/CocoaModel/interface/Model.h"
00032 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
00033 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00034 #include "Alignment/CocoaModel/interface/EntryLengthAffCentre.h"
00035 #include "Alignment/CocoaModel/interface/EntryAngleAffAngles.h"
00036 #include "Alignment/CocoaModel/interface/EntryNoDim.h"
00037 #include "Alignment/CocoaModel/interface/EntryMgr.h"
00038
00039 #include "Alignment/CocoaDDLObjects/interface/CocoaMaterialElementary.h"
00040 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
00041
00042 #include "CondFormats/OptAlignObjects/interface/OpticalAlignInfo.h"
00043
00044 #include "CLHEP/Units/SystemOfUnits.h"
00045
00046 #include <stdlib.h>
00047 #include <iostream>
00048
00049
00050
00051
00052
00053 OpticalObject::OpticalObject( OpticalObject* parent, const ALIstring& type, const ALIstring& name, const ALIbool copy_data ) :theParent(parent), theType(type), theName(name), fcopyData( copy_data)
00054 {
00055 if ( ALIUtils::debug >= 4 ) {
00056 std::cout << std::endl << "@@@@ Creating OpticalObject: NAME= " << theName << " TYPE= " <<theType << " fcopyData " <<fcopyData <<std::endl;
00057 }
00058
00059 OpticalObjectMgr::getInstance()->registerMe( this );
00060 }
00061
00062
00063
00064
00065
00066 void OpticalObject::construct()
00067 {
00068
00069 ALIFileIn& filein = ALIFileIn::getInstance( Model::SDFName() );
00070
00071
00072
00073
00074
00075
00076 if( theParent != 0 ) {
00077
00078 if(!fcopyData) {
00079 if(ALIUtils::debug >=4) std::cout << "@@@@ Reading data of Optical Object " << name() << std::endl;
00080 readData( filein );
00081 } else {
00082 if(ALIUtils::debug >=4) std::cout << "Copy data of Optical Object " << name() << std::endl;
00083 copyData();
00084 }
00085
00086
00087 setGlobalCoordinates();
00088
00089
00090
00091
00092
00093
00094
00095
00096 setOriginalEntryValues();
00097 }
00098
00099
00100 createComponentOptOs( filein );
00101
00102
00103 constructMaterial();
00104
00105
00106 constructSolidShape();
00107
00108 }
00109
00110
00111
00112
00113
00114
00115 void OpticalObject::readData( ALIFileIn& filein )
00116 {
00117
00118 std::vector<ALIstring> wordlist;
00119 filein.getWordsInLine( wordlist );
00120 if (wordlist[0] == ALIstring( "ENTRY" ) ){
00121
00122 readExtraEntries( filein );
00123 filein.getWordsInLine( wordlist );
00124 }
00125
00126
00127 centreIsGlobal = 0;
00128 anglesIsGlobal = 0;
00129
00130
00131 if ( type() == ALIstring("source") || type() == ALIstring("pinhole") ) {
00132 readCoordinates( wordlist[0], "centre", filein );
00133 setAnglesNull();
00134 } else {
00135
00136 readCoordinates( wordlist[0], "centre", filein );
00137 filein.getWordsInLine( wordlist );
00138 readCoordinates( wordlist[0], "angles", filein );
00139 }
00140
00141 }
00142
00143
00144
00145
00146
00147 void OpticalObject::readExtraEntries( ALIFileIn& filein )
00148 {
00149
00150 std::vector<ALIstring> wordlist;
00151 for (;;) {
00152 filein.getWordsInLine( wordlist );
00153 if ( wordlist[0] != ALIstring("}") ) {
00154 fillExtraEntry( wordlist );
00155 } else {
00156 break;
00157 }
00158 }
00159 }
00160
00161
00162
00163
00164
00165 void OpticalObject::fillExtraEntry( std::vector<ALIstring>& wordlist )
00166 {
00167
00168
00169
00170
00171 Entry* xentry;
00172 if ( wordlist[0] == ALIstring("length") ) {
00173 xentry = new EntryLength( wordlist[0] );
00174 } else if ( wordlist[0] == ALIstring("angle") ) {
00175 xentry = new EntryAngle( wordlist[0] );
00176 } else if ( wordlist[0] == ALIstring("nodim") ) {
00177 xentry = new EntryNoDim( wordlist[0] );
00178 } else {
00179 std::cerr << "!!ERROR: Exiting... unknown type of Extra Entry " << wordlist[0] << std::endl;
00180 ALIUtils::dumpVS( wordlist, " Only 'length', 'angle' or 'nodim' are allowed ", std::cerr );
00181 exit(2);
00182 }
00183
00184 if( ALIUtils::debug>=99) {
00185 ALIUtils::dumpVS( wordlist, "fillExtraEntry: ", std::cout );
00186 }
00187
00188 wordlist.erase( wordlist.begin() );
00189
00190 if( ALIUtils::debug>=99) {
00191 ALIUtils::dumpVS( wordlist, "fillExtraEntry: ", std::cout );
00192 }
00193
00194
00195 xentry->setOptOCurrent( this );
00196
00197 xentry->fillName( wordlist[0] );
00198
00199 xentry->fill( wordlist );
00200
00201
00202 Model::addEntryToList( xentry );
00203 addExtraEntryToList( xentry );
00204
00205 if(ALIUtils::debug >=5) std::cout << "fillExtraEntry: xentry_value" << xentry->value()<<xentry->ValueDimensionFactor() << std::endl;
00206
00207
00208 addExtraEntryValueToList( xentry->value() );
00209
00210
00211 }
00212
00213
00214
00215
00216
00217
00218 void OpticalObject::readCoordinates( const ALIstring& coor_type_read, const ALIstring& coor_type_expected, ALIFileIn& filein )
00219 {
00220
00221 ALIstring coor_type_reads = coor_type_read.substr(0,6);
00222 if( coor_type_reads == "center" ) coor_type_reads = "centre";
00223
00224
00225
00226
00227 if( EntryMgr::getInstance()->findEntryByLongName( longName(), "" ) == 0 ) {
00228 if(coor_type_read.size() == 7) {
00229 if(coor_type_read[6] == 'G' ) {
00230 if(ALIUtils::debug >= 5) std::cout << " coordinate global " << coor_type_read << std::endl;
00231 if(coor_type_expected == "centre" ) {
00232 centreIsGlobal = 1;
00233 } else if(coor_type_expected == "angles" ) {
00234 anglesIsGlobal = 1;
00235 }
00236 }
00237 }
00238 }
00239
00240 std::vector<ALIstring> wordlist;
00241
00242 ALIstring coor_names[3];
00243
00244 for( int ii=0; ii<4; ii++ ) {
00245 if ( ii == 0 ) {
00246
00247 if ( coor_type_reads != coor_type_expected ) {
00248 filein.ErrorInLine();
00249 std::cerr << "readCoordinates: " << coor_type_expected << " should be read here, instead of " << coor_type_reads << std::endl;
00250 exit(1);
00251 }
00252 } else {
00253
00254 filein.getWordsInLine(wordlist);
00255 coor_names[ii-1] = wordlist[0];
00256 fillCoordinateEntry( coor_type_expected, wordlist );
00257 }
00258 }
00259
00260
00261 if( coor_names[0] == ALIstring("X") && coor_names[1] == ALIstring("Y") && coor_names[2] == ALIstring("Z")) {
00262
00263 }else if( coor_names[0] == ALIstring("R") && coor_names[1] == ALIstring("PHI") && coor_names[2] == ALIstring("Z")) {
00264 transformCylindrical2Cartesian();
00265 }else if( coor_names[0] == ALIstring("R") && coor_names[1] == ALIstring("THE") && coor_names[2] == ALIstring("PHI")) {
00266 transformSpherical2Cartesian();
00267 } else {
00268 std::cerr << "!!!EXITING: coordinates have to be cartesian (X ,Y ,Z), or cylindrical (R, PHI, Z) or spherical (R, THE, PHI) " << std::endl
00269 << " they are " << coor_names[0] << ", " << coor_names[1] << ", " << coor_names[2] << "." << std::endl;
00270 exit(1);
00271 }
00272 }
00273
00274
00275
00276 void OpticalObject::transformCylindrical2Cartesian()
00277 {
00278 ALIuint ii;
00279 ALIuint siz = theCoordinateEntryVector.size();
00280 ALIdouble newcoor[3];
00281 ALIdouble R = theCoordinateEntryVector[0]->value();
00282 ALIdouble phi = theCoordinateEntryVector[1]->value()/ALIUtils::LengthValueDimensionFactor()*ALIUtils::AngleValueDimensionFactor();
00283 newcoor[0] = R*cos(phi);
00284 newcoor[1] = R*sin(phi);
00285 newcoor[2] = theCoordinateEntryVector[2]->value();
00286
00287
00288
00289 for( ii = 0; ii < siz; ii++ ) {
00290 if(ALIUtils::debug >= 5 ) std::cout << " OpticalObject::transformCylindrical2Cartesian " << ii << " " << newcoor[ii] << std::endl;
00291 theCoordinateEntryVector[ii]->setValue( newcoor[ii] );
00292 }
00293
00294 ALIstring name = "centre_X";
00295 theCoordinateEntryVector[0]->fillName( name );
00296 name = "centre_Y";
00297 theCoordinateEntryVector[1]->fillName( name );
00298 name = "centre_Z";
00299 theCoordinateEntryVector[2]->fillName( name );
00300
00301 }
00302
00303
00304 void OpticalObject::transformSpherical2Cartesian()
00305 {
00306
00307 }
00308
00309
00310
00311
00312
00313 void OpticalObject::fillCoordinateEntry( const ALIstring& coor_type, const std::vector<ALIstring>& wordlist )
00314 {
00315
00316
00317 Entry* entry = 0;
00318 if ( coor_type == ALIstring("centre") ) {
00319 entry = new EntryLengthAffCentre( coor_type );
00320 }else if ( coor_type == ALIstring("angles") ) {
00321 entry = new EntryAngleAffAngles( coor_type );
00322 } else {
00323 std::cerr << " !!! FATAL ERROR at OpticalObject::fillCoordinateEntry : wrong coordinate type " << coor_type << std::endl;
00324 exit(1);
00325 }
00326
00327
00328 entry->setOptOCurrent( this );
00329
00330 ALIstring name = coor_type + "_" + wordlist[0];
00331 entry->fillName( name );
00332
00333 entry->fill( wordlist );
00334
00335
00336 Model::addEntryToList( entry );
00337 addCoordinateEntryToList( entry );
00338
00339 }
00340
00341
00342
00343
00344
00345 void OpticalObject::setAnglesNull()
00346 {
00347
00348 EntryAngleAffAngles* entry;
00349
00350 ALIstring coor("XYZ");
00351
00352
00353 for (int ii=0; ii<3; ii++) {
00354 entry = new EntryAngleAffAngles( "angles" );
00355
00356
00357 entry->setOptOCurrent( this );
00358
00359 ALIstring name = "angles_" + coor.substr(ii, 1);
00360 entry->fillName( name );
00361
00362 entry->fillNull( );
00363
00364
00365
00366
00367 Model::addEntryToList( entry );
00368 addCoordinateEntryToList( entry );
00369
00370 }
00371
00372 }
00373
00374
00375
00376
00377
00378 void OpticalObject::copyData()
00379 {
00380 centreIsGlobal = 0;
00381 anglesIsGlobal = 0;
00382 if(ALIUtils::debug >= 5) std::cout << "entering copyData()" << std::endl;
00383
00384
00385 OpticalObject* opto = Model::nextOptOToCopy();
00386
00387
00388 ALIint copy_name_last_slash = opto->name().rfind('/');
00389 ALIint copy_name_size = opto->name().length();
00390
00391 theName.append( opto->name(), copy_name_last_slash, copy_name_size);
00392 if(ALIUtils::debug >= 5) std::cout << "copying OptO: " << opto->name() << " to OptO " << theName << std::endl;
00393
00394
00395 std::vector<Entry*>::const_iterator vecite;
00396 for( vecite = opto->ExtraEntryList().begin(); vecite != opto->ExtraEntryList().end(); vecite++ ) {
00397 std::vector<ALIstring> wordlist;
00398 wordlist.push_back( (*vecite)->type() );
00399 buildWordList( (*vecite), wordlist );
00400 if( ALIUtils::debug>=9) {
00401 ALIUtils::dumpVS( wordlist, "copyData: ", std::cout );
00402 }
00403 fillExtraEntry( wordlist );
00404 }
00405
00406
00407 for( vecite = opto->CoordinateEntryList().begin(); vecite != opto->CoordinateEntryList().end(); vecite++ ) {
00408 std::vector<ALIstring> wordlist;
00409 buildWordList( (*vecite), wordlist );
00410
00411 ALIstring coor_name;
00412 if( vecite - opto->CoordinateEntryList().begin() < 3 ) {
00413 coor_name = "centre";
00414 } else {
00415 coor_name = "angles";
00416 }
00417 fillCoordinateEntry( coor_name, wordlist );
00418 }
00419
00420 }
00421
00422
00423
00424
00425
00426 void OpticalObject::buildWordList( const Entry* entry, std::vector<ALIstring>& wordlist )
00427 {
00428
00429 wordlist.push_back( entry->name() );
00430
00431
00432 char chartmp[20];
00433 gcvt(entry->value()/entry->ValueDimensionFactor(),10, chartmp);
00434 wordlist.push_back( chartmp );
00435
00436
00437 gcvt(entry->sigma()/entry->SigmaDimensionFactor(),10, chartmp);
00438 wordlist.push_back( chartmp );
00439
00440
00441 ALIstring strtmp;
00442 ALIint inttmp = entry->quality();
00443 switch ( inttmp ) {
00444 case 0:
00445 strtmp = "fix";
00446 break;
00447 case 1:
00448 strtmp = "cal";
00449 break;
00450 case 2:
00451 strtmp = "unk";
00452 break;
00453 default:
00454 std::cerr << "buildWordList: entry " << entry->OptOCurrent()->name() << entry->name() << " quality not found " << inttmp << std::endl;
00455 break;
00456 }
00457 wordlist.push_back( strtmp );
00458
00459 if( ALIUtils::debug>=9) {
00460 ALIUtils::dumpVS( wordlist, "buildWordList: ", std::cout );
00461 }
00462
00463 }
00464
00465
00466
00467
00468
00469 void OpticalObject::createComponentOptOs( ALIFileIn& filein )
00470 {
00471
00472 ALIbool fcopyComponents = 0;
00473
00474
00475 std::vector<ALIstring> vopto_types;
00476 int igetood = Model::getComponentOptOTypes( type(), vopto_types );
00477 if( !igetood ) {
00478 if(ALIUtils::debug >= 5) std::cout << " NO MORE COMPONENTS IN THIS OptO" << name() << std::endl ;
00479 return;
00480 }
00481
00482
00483
00484
00485
00486
00487
00488 std::vector<ALIstring>::iterator vsite;
00489 std::vector<ALIstring> wordlist;
00490 for( vsite=vopto_types.begin(); vsite!=vopto_types.end(); vsite++ ) {
00491
00492
00493 if( !fcopyData && !fcopyComponents ) filein.getWordsInLine(wordlist);
00494
00495
00496
00497
00498
00499 if( fcopyData || fcopyComponents ) {
00500 fcopyComponents = 1;
00501
00502 }else if( wordlist[0] == ALIstring("copy_components") ) {
00503 if(ALIUtils::debug>=3)std::cout << "createComponentOptOs: copy_components" << wordlist[0] << std::endl;
00504 Model::createCopyComponentList( type() );
00505 fcopyComponents = 1;
00506
00507 } else if ( wordlist[0] != (*vsite) ) {
00508 filein.ErrorInLine();
00509 std::cerr << "!!! Badly placed OpticalObject: " << wordlist[0] << " should be = " << (*vsite) << std::endl;
00510 exit(2);
00511 }
00512
00513
00514 ALIstring component_name = name();
00515
00516 if( !fcopyComponents ) {
00517 component_name += '/';
00518 component_name += wordlist[1];
00519 }
00520
00521
00522
00523 OpticalObject* OptOcomponent = createNewOptO( this, *vsite, component_name, fcopyComponents );
00524
00525
00526 if( wordlist.size() == 3 ) {
00527 OptOcomponent->setID( ALIUtils::getInt( wordlist[2] ) );
00528 } else {
00529 OptOcomponent->setID( OpticalObjectMgr::getInstance()->buildCmsSwID() );
00530 }
00531
00532
00533 OptOcomponent->construct();
00534
00535
00536 Model::OptOList().push_back( OptOcomponent );
00537 }
00538
00539 }
00540
00541
00542 OpticalObject* OpticalObject::createNewOptO( OpticalObject* parent, ALIstring optoType, ALIstring optoName, ALIbool fcopyComponents )
00543 {
00544 if ( ALIUtils::debug >= 3 ) std::cout << " OpticalObject::createNewOptO optoType " << optoType << " optoName " << optoName << " parent " << parent->name() << std::endl;
00545 OpticalObject* OptOcomponent;
00546 if( optoType == "laser" ) {
00547 OptOcomponent =
00548 new OptOLaser( this, optoType, optoName, fcopyComponents );
00549 } else if( optoType == "source" ) {
00550 OptOcomponent =
00551 new OptOSource( this, optoType, optoName, fcopyComponents );
00552 } else if( optoType == "Xlaser" ) {
00553 OptOcomponent =
00554 new OptOXLaser( this, optoType, optoName, fcopyComponents );
00555 } else if( optoType == "mirror" ){
00556 OptOcomponent =
00557 new OptOMirror( this, optoType, optoName, fcopyComponents );
00558 } else if( optoType == "plate_splitter" ) {
00559 OptOcomponent =
00560 new OptOPlateSplitter( this, optoType, optoName, fcopyComponents );
00561 } else if( optoType == "cube_splitter" ) {
00562 OptOcomponent =
00563 new OptOCubeSplitter( this, optoType, optoName, fcopyComponents );
00564 } else if( optoType == "modified_rhomboid_prism" ) {
00565 OptOcomponent =
00566 new OptOModifiedRhomboidPrism( this, optoType, optoName, fcopyComponents );
00567 } else if( optoType == "pseudo_pentaprism" || optoType == "optical_square" ) {
00568 OptOcomponent =
00569 new OptOOpticalSquare( this, optoType, optoName, fcopyComponents );
00570 } else if( optoType == "lens" ) {
00571 OptOcomponent =
00572 new OptOLens( this, optoType, optoName, fcopyComponents );
00573 } else if( optoType == "Risley_prism" ) {
00574 OptOcomponent =
00575 new OptORisleyPrism( this, optoType, optoName, fcopyComponents );
00576 } else if( optoType == "sensor2D" ) {
00577 OptOcomponent =
00578 new OptOSensor2D( this, optoType, optoName, fcopyComponents );
00579 } else if( optoType == "distancemeter" || optoType == "distancemeter1dim" ) {
00580 OptOcomponent =
00581 new OptODistancemeter( this, optoType, optoName, fcopyComponents );
00582 } else if( optoType == "distancemeter3dim" ) {
00583 OptOcomponent =
00584 new OptODistancemeter3dim( this, optoType, optoName, fcopyComponents );
00585 } else if( optoType == "distance_target" ) {
00586 OptOcomponent =
00587 new OptOScreen( this, optoType, optoName, fcopyComponents );
00588 } else if( optoType == "tiltmeter" ) {
00589 OptOcomponent =
00590 new OptOTiltmeter( this, optoType, optoName, fcopyComponents );
00591 } else if( optoType == "pinhole" ) {
00592 OptOcomponent =
00593 new OptOPinhole( this, optoType, optoName, fcopyComponents );
00594 } else if( optoType == "COPS" ) {
00595 OptOcomponent =
00596 new OptOCOPS( this, optoType, optoName, fcopyComponents );
00597 } else {
00598 OptOcomponent =
00599
00600 new OptOUserDefined( this, optoType, optoName, fcopyComponents );
00601 }
00602
00603 return OptOcomponent;
00604 }
00605
00606
00607
00608
00609
00610 void OpticalObject::setGlobalCoordinates()
00611 {
00612 setGlobalCentre();
00613 setGlobalRM();
00614 }
00615
00616
00617 void OpticalObject::setGlobalCentre()
00618 {
00619 SetCentreLocalFromEntryValues();
00620 if ( type() != ALIstring("system") && !centreIsGlobal ) {
00621 SetCentreGlobFromCentreLocal();
00622 }
00623 if( anglesIsGlobal ){
00624 std::cerr << "!!!FATAL ERROR: angles in global coordinates not supported momentarily " << std::endl;
00625 abort();
00626 }
00627 }
00628
00629
00630
00631 void OpticalObject::setGlobalRM()
00632 {
00633 SetRMLocalFromEntryValues();
00634 if( !anglesIsGlobal ) {
00635 SetRMGlobFromRMLocal();
00636 }
00637
00638
00639 calculateLocalRotationAxisInGlobal();
00640
00641 }
00642
00643
00644
00645
00646 void OpticalObject::setGlobalRMOriginalOriginal(const HepRotation& rmorioriLocal )
00647 {
00648 HepRotation rmorioriold = rmGlobOriginalOriginal();
00649 if ( ALIUtils::debug >= 5 ) {
00650 std::cout << " setGlobalRMOriginalOriginal OptO " << name() << std::endl;
00651 ALIUtils::dumprm(rmorioriLocal," setGlobalRMOriginalOriginal new local");
00652 ALIUtils::dumprm(rmGlobOriginalOriginal()," setGlobalRMOriginalOriginal old ");
00653 }
00654
00655 SetRMGlobFromRMLocalOriginalOriginal( rmorioriLocal );
00656
00657
00658
00659
00660
00661
00662 if ( ALIUtils::debug >= 5 ) {
00663 ALIUtils::dumprm( parent()->rmGlobOriginalOriginal()," parent rmoriori glob ");
00664 ALIUtils::dumprm(rmGlobOriginalOriginal()," setGlobalRMOriginalOriginal new ");
00665 }
00666
00667
00668 std::vector<OpticalObject*> vopto;
00669 ALIbool igetood = Model::getComponentOptOs(name(), vopto);
00670 if( !igetood ) {
00671
00672 return;
00673 }
00674 std::vector<OpticalObject*>::const_iterator vocite;
00675 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
00676 HepRotation rmorioriLocalChild = (*vocite)->buildRmFromEntryValuesOriginalOriginal();
00677 (*vocite)->setGlobalRMOriginalOriginal( rmorioriLocalChild );
00678
00679 }
00680
00681 }
00682
00683
00684
00685 void OpticalObject::propagateGlobalRMOriginalOriginalChangeToChildren( const HepRotation& rmorioriold, const HepRotation& rmoriorinew )
00686 {
00687 std::cout << " propagateGlobalRMOriginalOriginalChangeToChildren OptO " << name() << std::endl;
00688 ALIUtils::dumprm(rmGlobOriginalOriginal()," setGlobalRMOriginalOriginal old ");
00689 theRmGlobOriginalOriginal = rmoriorinew.inverse() * theRmGlobOriginalOriginal;
00690 theRmGlobOriginalOriginal = rmorioriold * theRmGlobOriginalOriginal;
00691 ALIUtils::dumprm(rmGlobOriginalOriginal()," setGlobalRMOriginalOriginal new ");
00692
00693
00694 std::vector<OpticalObject*> vopto;
00695 ALIbool igetood = Model::getComponentOptOs(name(), vopto);
00696 if( !igetood ) {
00697
00698 return;
00699 }
00700 std::vector<OpticalObject*>::const_iterator vocite;
00701 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
00702
00703 (*vocite)->propagateGlobalRMOriginalOriginalChangeToChildren( rmorioriold, rmoriorinew );
00704 }
00705
00706 }
00707
00708
00709 HepRotation OpticalObject::buildRmFromEntryValuesOriginalOriginal()
00710 {
00711 HepRotation rm;
00712 const OpticalObject* opto_par = this;
00713
00714 if(ALIUtils::debug >= 55) std::cout << "rotate with parent: before X " << opto_par->parent()->name() <<" " << parent()->getEntryRMangle(XCoor) <<std::endl;
00715 const std::vector< Entry* >& cel = CoordinateEntryList();
00716 rm.rotateX( cel[3]->valueOriginalOriginal() );
00717 if(ALIUtils::debug >= 55) std::cout << "rotate with parent: before Y " << opto_par->parent()->name() <<" " << parent()->getEntryRMangle(YCoor) <<std::endl;
00718 rm.rotateY( cel[4]->valueOriginalOriginal() );
00719 if(ALIUtils::debug >= 55) std::cout << "rotate with parent: before Z " << opto_par->parent()->name() <<" " << parent()->getEntryRMangle(ZCoor) <<std::endl;
00720 rm.rotateZ( cel[5]->valueOriginalOriginal() );
00721
00722 if(ALIUtils::debug >= 54) ALIUtils::dumprm( theRmGlob, ("SetRMGlobFromRMLocal: RM GLOB after " + opto_par->parent()->longName()).c_str() );
00723
00724 return rm;
00725 }
00726
00727
00728 void OpticalObject::SetCentreLocalFromEntryValues()
00729 {
00730
00731
00732
00733
00734
00735
00736
00737 theCentreGlob.setX( getEntryCentre(XCoor) );
00738 theCentreGlob.setY( getEntryCentre(YCoor) );
00739 theCentreGlob.setZ( getEntryCentre(ZCoor) );
00740 if(ALIUtils::debug >=4) ALIUtils::dump3v( centreGlob(), "SetCentreLocalFromEntryValues: CENTRE LOCAL ");
00741 }
00742
00743
00744
00745 void OpticalObject::SetRMLocalFromEntryValues()
00746 {
00747
00748
00749
00750 theRmGlob = CLHEP::HepRotation();
00751 theRmGlob.rotateX( getEntryRMangle(XCoor) );
00752 if(ALIUtils::debug >= 4) {
00753 std::cout << " getEntryRMangle(XCoor) )" << getEntryRMangle(XCoor) << std::endl;
00754 ALIUtils::dumprm( theRmGlob, "SetRMLocalFromEntryValues: RM after X");
00755 }
00756 theRmGlob.rotateY( getEntryRMangle(YCoor) );
00757 if(ALIUtils::debug >= 4) {
00758 std::cout << " getEntryRMangle(YCoor) )" << getEntryRMangle(YCoor) << std::endl;
00759 ALIUtils::dumprm( theRmGlob, "SetRMLocalFromEntryValues: RM after Y");
00760 }
00761 theRmGlob.rotateZ( getEntryRMangle(ZCoor) );
00762 if(ALIUtils::debug >= 4) {
00763 std::cout << " getEntryRMangle(ZCoor) )" << getEntryRMangle(ZCoor) << std::endl;
00764 ALIUtils::dumprm( theRmGlob, "SetRMLocalFromEntryValues: RM FINAL");
00765 }
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778 }
00779
00780
00781
00782 void OpticalObject::SetCentreGlobFromCentreLocal()
00783 {
00784
00785 CLHEP::Hep3Vector cLocal = theCentreGlob;
00786 theCentreGlob = parent()->rmGlob() * theCentreGlob;
00787
00788 if(ALIUtils::debug >= 5) ALIUtils::dump3v( theCentreGlob, "SetCentreGlobFromCentreLocal: CENTRE in parent local frame ");
00789 theCentreGlob += parent()->centreGlob();
00790
00791 if(ALIUtils::debug >= 5) ALIUtils::dump3v( theCentreGlob, "SetCentreGlobFromCentreLocal: CENTRE GLOBAL ");
00792 if(ALIUtils::debug >= 5) {
00793 ALIUtils::dump3v( parent()->centreGlob(), ( " parent centreGlob" + parent()->name() ).c_str() );
00794 ALIUtils::dumprm( parent()->rmGlob(), " parent rmGlob ");
00795 }
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806 }
00807
00808
00809
00810 void OpticalObject::SetRMGlobFromRMLocal()
00811 {
00812 const OpticalObject* opto_par = this;
00813 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00814 if(gomgr->GlobalOptions()["rotateAroundLocal"] == 0) {
00815 while ( opto_par->parent()->type() != ALIstring("system") ) {
00816
00817 if(ALIUtils::debug >= 5) std::cout << "rotate with parent: before X " << opto_par->parent()->name() <<" " << parent()->getEntryRMangle(XCoor) <<std::endl;
00818 theRmGlob.rotateX( parent()->getEntryRMangle(XCoor) );
00819 if(ALIUtils::debug >= 5) std::cout << "rotate with parent: before Y " << opto_par->parent()->name() <<" " << parent()->getEntryRMangle(YCoor) <<std::endl;
00820 theRmGlob.rotateY( parent()->getEntryRMangle(YCoor) );
00821 if(ALIUtils::debug >= 5) std::cout << "rotate with parent: before Z " << opto_par->parent()->name() <<" " << parent()->getEntryRMangle(ZCoor) <<std::endl;
00822 theRmGlob.rotateZ( parent()->getEntryRMangle(ZCoor) );
00823 if(ALIUtils::debug >= 4) ALIUtils::dumprm( theRmGlob, ("SetRMGlobFromRMLocal: RM GLOB after " + opto_par->parent()->longName()).c_str() );
00824 opto_par = opto_par->parent();
00825 }
00826 }else {
00827 if(ALIUtils::debug >= 4) {
00828 std::cout << " Composing rmGlob with parent " << parent()->name() << std::endl;
00829
00830 }
00831 theRmGlob = parent()->rmGlob() * theRmGlob;
00832 }
00833
00834
00835 if(ALIUtils::debug >= 4) {
00836 ALIUtils::dumprm( theRmGlob, "SetRMGlobFromRMLocal: final RM GLOB ");
00837 ALIUtils::dumprm( parent()->rmGlob(), "parent rm glob ");
00838 }
00839 }
00840
00841
00842 void OpticalObject::SetRMGlobFromRMLocalOriginalOriginal( HepRotation rmoriori )
00843 {
00844
00845 theRmGlobOriginalOriginal = rmoriori;
00846 theRmGlobOriginalOriginal = parent()->rmGlobOriginalOriginal() * theRmGlobOriginalOriginal;
00847 }
00848
00849
00850
00851
00852
00853 void OpticalObject::setOriginalEntryValues()
00854 {
00855
00856 theCentreGlobOriginal = centreGlob();
00857 theRmGlobOriginal = rmGlob();
00858
00859 theCentreGlobOriginalOriginal = centreGlob();
00860 theRmGlobOriginalOriginal = rmGlob();
00861
00862
00863
00864
00865
00866
00867
00868 std::vector<ALIdouble>::const_iterator vdcite;
00869 for (vdcite = ExtraEntryValueList().begin();
00870 vdcite != ExtraEntryValueList().end(); vdcite++) {
00871 addExtraEntryValueOriginalToList( *vdcite );
00872 addExtraEntryValueOriginalOriginalToList( *vdcite );
00873 }
00874
00875 if( ALIUtils::debug >= 6 ) std::cout << " setOriginalEntryValues " << std::endl;
00876 }
00877
00878
00879
00880
00881
00882 void OpticalObject::participateInMeasurement(LightRay& lightray, Measurement& meas, const ALIstring& behav )
00883 {
00884
00885 setMeas( &meas );
00886 if ( behav == " " ) {
00887 defaultBehaviour( lightray, meas );
00888 } else if ( behav == "D" || behav == "DD" ) {
00889 detailedDeviatesLightRay( lightray );
00890 } else if ( behav == "T" || behav == "DT" ) {
00891 detailedTraversesLightRay( lightray );
00892 } else if ( behav == "FD" ) {
00893 fastDeviatesLightRay( lightray );
00894 } else if ( behav == "FT" ) {
00895 fastTraversesLightRay( lightray );
00896 } else if ( behav == "M" ) {
00897 makeMeasurement( lightray, meas );
00898 } else {
00899 userDefinedBehaviour( lightray, meas, behav);
00900 }
00901 }
00902
00903
00904
00905
00906
00907 void OpticalObject::defaultBehaviour( LightRay& lightray, Measurement& meas )
00908 {
00909 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement a default behaviour" << std::endl;
00910 std::cerr << " You have to specify some behaviour, like :D or :T or ..." << std::endl;
00911 exit(1);
00912 }
00913
00914
00915
00916
00917
00918 void OpticalObject::fastDeviatesLightRay( LightRay& lightray )
00919 {
00920 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement deviation (:D)" << std::endl;
00921 std::cerr << " Please read documentation for this object type" << std::endl;
00922 exit(1);
00923 }
00924
00925
00926
00927
00928
00929 void OpticalObject::fastTraversesLightRay( LightRay& lightray )
00930 {
00931 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement the light traversing (:T)" << std::endl;
00932 std::cerr << " Please read documentation for this object type" << std::endl;
00933 exit(1);
00934 }
00935
00936
00937
00938
00939
00940 void OpticalObject::detailedDeviatesLightRay( LightRay& lightray )
00941 {
00942 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement detailed deviation (:DD / :D)" << std::endl;
00943 std::cerr << " Please read documentation for this object type" << std::endl;
00944 exit(1);
00945 }
00946
00947
00948
00949
00950
00951 void OpticalObject::detailedTraversesLightRay( LightRay& lightray )
00952 {
00953 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement detailed traversing of light ray (:DT / :T)" << std::endl;
00954 std::cerr << " Please read documentation for this object type" << std::endl;
00955 exit(1);
00956 }
00957
00958
00959
00960
00961
00962 void OpticalObject::makeMeasurement( LightRay& lightray, Measurement& meas )
00963 {
00964 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement making measurement (:M)" << std::endl;
00965 std::cerr << " Please read documentation for this object type" << std::endl;
00966 exit(1);
00967 }
00968
00969 void OpticalObject::userDefinedBehaviour( LightRay& lightray, Measurement& meas, const ALIstring& behav)
00970 {
00971 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement user defined behaviour = " << behav << std::endl;
00972 std::cerr << " Please read documentation for this object type" << std::endl;
00973 exit(1);
00974 }
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986 ALIPlane OpticalObject::getPlate(const ALIbool forwardPlate, const ALIbool applyWedge)
00987 {
00988 if (ALIUtils::debug >= 4) std::cout << "% LR: GET PLATE " << name() << " forward= " << forwardPlate << std::endl;
00989
00990 const ALIdouble width = (findExtraEntryValue("width"));
00991
00992
00993
00994 CLHEP::Hep3Vector ZAxis(0.,0.,1.);
00995 CLHEP::HepRotation rmt = rmGlob();
00996 CLHEP::Hep3Vector plate_normal = rmt*ZAxis;
00997
00998
00999 CLHEP::Hep3Vector plate_point = centreGlob();
01000
01001 ALIdouble normal_sign = -forwardPlate*2 + 1;
01002 plate_point += normal_sign * width/2. * plate_normal;
01003
01004 if (ALIUtils::debug >= 3) {
01005 ALIUtils::dump3v( plate_point, "plate_point");
01006 ALIUtils::dump3v( plate_normal, "plate_normal before wedge");
01007 ALIUtils::dumprm( rmt, "rmt before wedge" );
01008 }
01009
01010 if(applyWedge) {
01011 ALIdouble wedge;
01012 wedge = findExtraEntryValue("wedge");
01013 if( wedge != 0. ){
01014
01015 CLHEP::Hep3Vector XAxis(1.,0.,0.);
01016 XAxis = rmt*XAxis;
01017 plate_normal.rotate( normal_sign * wedge/2., XAxis );
01018 if (ALIUtils::debug >= 3) ALIUtils::dump3v( plate_normal, "plate_normal after wedgeX ");
01019 if (ALIUtils::debug >= 4) ALIUtils::dump3v( XAxis, "X Axis for applying wedge ");
01020 CLHEP::Hep3Vector YAxis(0.,1.,0.);
01021 YAxis = rmt*YAxis;
01022 plate_normal.rotate( normal_sign * wedge/2., YAxis );
01023 if (ALIUtils::debug >= 3) ALIUtils::dump3v( plate_normal, "plate_normal after wedgeY ");
01024 if (ALIUtils::debug >= 4) ALIUtils::dump3v( YAxis, "Y Axis for applying wedge ");
01025 }
01026 }
01027
01028
01029 return ALIPlane(plate_point, plate_normal);
01030
01031 }
01032
01033
01034
01035
01036
01037
01038 void OpticalObject::displaceCentreGlob( const XYZcoor coor, const ALIdouble disp)
01039 {
01040 if ( ALIUtils::debug >= 5 ) std::cout << name() << " displaceCentreGlob: coor " << coor << " disp = " << disp << std::endl;
01041
01042 theCentreGlob = centreGlobOriginal();
01043 CLHEP::Hep3Vector dispVec = getDispVec( coor, disp );
01044 theCentreGlob += dispVec;
01045
01046
01047 std::vector<OpticalObject*> vopto;
01048 ALIbool igetood = Model::getComponentOptOs(name(), vopto);
01049 if( !igetood ) {
01050
01051 return;
01052 }
01053 std::vector<OpticalObject*>::const_iterator vocite;
01054 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01055 (*vocite)->displaceCentreGlob( dispVec );
01056 }
01057
01058 }
01059
01060
01061
01062 CLHEP::Hep3Vector OpticalObject::getDisplacementInLocalCoordinates( const XYZcoor coor, const ALIdouble disp )
01063 {
01064 CLHEP::Hep3Vector dispVec;
01065 switch( coor ) {
01066 case 0:
01067 dispVec = CLHEP::Hep3Vector( disp, 0., 0. );
01068 break;
01069 case 1:
01070 dispVec = CLHEP::Hep3Vector( 0., disp, 0. );
01071 break;
01072 case 2:
01073 dispVec = CLHEP::Hep3Vector( 0., 0., disp );
01074 break;
01075 default:
01076 std::cerr << "!!! DISPLACECENTREGLOB coordinate should be 0-2, not " << coor << std::endl;
01077 exit(2);
01078 }
01079
01080 return dispVec;
01081 }
01082
01083
01084
01085
01086
01087 void OpticalObject::displaceCentreGlob( const CLHEP::Hep3Vector& dispVec)
01088 {
01089 if ( ALIUtils::debug >= 5 ) std::cout << name() << " displaceCentreGlob: dispVec = " << dispVec << std::endl;
01090
01091 theCentreGlob = centreGlobOriginal();
01092 theCentreGlob += dispVec;
01093
01094
01095 std::vector<OpticalObject*> vopto;
01096 ALIbool igetood = Model::getComponentOptOs(name(), vopto);
01097 if( !igetood ) {
01098 return;
01099 }
01100 std::vector<OpticalObject*>::const_iterator vocite;
01101 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01102 (*vocite)->displaceCentreGlob( dispVec );
01103 }
01104
01105 }
01106
01107
01108
01109
01110
01111 void OpticalObject::displaceExtraEntry(const ALIuint entryNo, const ALIdouble disp)
01112 {
01113
01114 ALIdouble Pentry_value = (*(theExtraEntryValueVector.begin() + entryNo));
01115
01116 ALIdouble Pentry_orig_value = *(theExtraEntryValueOriginalVector.begin() + entryNo);
01117 Pentry_value = (Pentry_orig_value) + disp;
01118
01119 theExtraEntryValueVector[entryNo] = Pentry_value;
01120 }
01121
01122
01123 void OpticalObject::setExtraEntryValue(const ALIuint entryNo, const ALIdouble val)
01124 {
01125 theExtraEntryValueVector[entryNo] = val;
01126 }
01127
01128
01129 void OpticalObject::displaceCentreGlobOriginal( const XYZcoor coor, const ALIdouble disp)
01130 {
01131 if ( ALIUtils::debug >= 4 ) std::cout << "@@ OpticalObject::displaceCentreGloboriginal " << name() << " " << coor << " " << disp << std::endl;
01132 if ( ALIUtils::debug >= 5 ) ALIUtils::dump3v(theCentreGlobOriginal, "the centre glob original 0");
01133 CLHEP::Hep3Vector dispVec = getDispVec( coor, disp );
01134 theCentreGlobOriginal += dispVec;
01135
01136 if ( ALIUtils::debug >= 5 ) ALIUtils::dump3v(theCentreGlobOriginal, "the centre glob original displaced");
01137
01138
01139 std::vector<OpticalObject*> vopto;
01140 Model::getComponentOptOs(name(), vopto);
01141 std::vector<OpticalObject*>::const_iterator vocite;
01142 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01143 (*vocite)->displaceCentreGlobOriginal( dispVec );
01144 }
01145
01146 }
01147
01148
01149
01150
01151
01152 void OpticalObject::displaceCentreGlobOriginal( const CLHEP::Hep3Vector& dispVec)
01153 {
01154 if ( ALIUtils::debug >= 4 ) std::cout << " OpticalObject::displaceCentreGloboriginal " << name() << " dispVec " << dispVec << std::endl;
01155
01156 theCentreGlobOriginal += dispVec;
01157
01158 if ( ALIUtils::debug >= 5 ) ALIUtils::dump3v(theCentreGlobOriginal, "the centre glob original");
01159
01160
01161 std::vector<OpticalObject*> vopto;
01162 Model::getComponentOptOs(name(), vopto);
01163 std::vector<OpticalObject*>::const_iterator vocite;
01164 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01165 (*vocite)->displaceCentreGlobOriginal( dispVec );
01166 }
01167
01168 }
01169
01170
01171
01172 void OpticalObject::displaceCentreGlobOriginalOriginal( const XYZcoor coor, const ALIdouble disp)
01173 {
01174 if ( ALIUtils::debug >= 4 ) std::cout << "@@ OpticalObject::displaceCentreGloboriginal " << name() << " " << coor << " " << disp << std::endl;
01175 if ( ALIUtils::debug >= 5 ) ALIUtils::dump3v(theCentreGlobOriginalOriginal, "the centre glob originalOriginal 0");
01176 CLHEP::Hep3Vector dispVec = getDispVec( coor, disp );
01177 theCentreGlobOriginalOriginal += dispVec;
01178
01179 if ( ALIUtils::debug >= 5 ) ALIUtils::dump3v(theCentreGlobOriginalOriginal, "the centre glob original displaced");
01180
01181
01182 std::vector<OpticalObject*> vopto;
01183 Model::getComponentOptOs(name(), vopto);
01184 std::vector<OpticalObject*>::const_iterator vocite;
01185 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01186 (*vocite)->displaceCentreGlobOriginalOriginal( dispVec );
01187 }
01188
01189 }
01190
01191
01192
01193
01194
01195 void OpticalObject::displaceCentreGlobOriginalOriginal( const CLHEP::Hep3Vector& dispVec)
01196 {
01197 if ( ALIUtils::debug >= 4 ) std::cout << " OpticalObject::displaceCentreGloboriginal " << name() << " dispVec " << dispVec << std::endl;
01198
01199 theCentreGlobOriginalOriginal += dispVec;
01200
01201 if ( ALIUtils::debug >= 5 ) ALIUtils::dump3v(theCentreGlobOriginalOriginal, "the centre glob original");
01202
01203
01204 std::vector<OpticalObject*> vopto;
01205 Model::getComponentOptOs(name(), vopto);
01206 std::vector<OpticalObject*>::const_iterator vocite;
01207 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01208 (*vocite)->displaceCentreGlobOriginalOriginal( dispVec );
01209 }
01210
01211 }
01212
01213
01214
01215
01216
01217
01218 void OpticalObject::displaceRmGlobAroundGlobal( OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp)
01219 {
01220 if(ALIUtils::debug>=5) std::cout << name() << "DISPLACERMGLOBAROUNDGLOBAL" << coor << "disp" << disp << std::endl;
01221
01222 theRmGlob = rmGlobOriginal();
01223 theCentreGlob = centreGlobOriginal();
01224 if(ALIUtils::debug >= 5 ) {
01225 std::cout << this->name() << std::endl;
01226 ALIUtils::dumprm( theRmGlob, "before disp rm " );
01227 }
01228 rotateItAroundGlobal( theRmGlob, coor, disp );
01229 if(ALIUtils::debug >= 5 ) {
01230 ALIUtils::dumprm( theRmGlob, "after disp rm " );
01231 }
01232
01233 if(ALIUtils::debug >= 5) ALIUtils::dump3v( centreGlob(), " centre_glob before rotation" );
01234 if(ALIUtils::debug >= 5 ) ALIUtils::dump3v( centreGlobOriginal(), " centreGlobOriginal before rotation" );
01235 if(opto1stRotated != this ) {
01236
01237 CLHEP::Hep3Vector radiusOriginal = centreGlobOriginal() - opto1stRotated->centreGlobOriginal();
01238 CLHEP::Hep3Vector radius_rotated = radiusOriginal;
01239 rotateItAroundGlobal( radius_rotated, coor, disp );
01240 theCentreGlob = centreGlobOriginal() + (radius_rotated - radiusOriginal);
01241 if(ALIUtils::debug >= 5) ALIUtils::dump3v( centreGlob(), " centre_glob after rotation" );
01242 if(ALIUtils::debug >= 5) ALIUtils::dump3v( centreGlobOriginal(), " centre_globOriginal() after rotation" );
01243 }
01244
01245
01246 std::vector<OpticalObject*> vopto;
01247 Model::getComponentOptOs(name(), vopto);
01248 std::vector<OpticalObject*>::const_iterator vocite;
01249 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01250 (*vocite)->displaceRmGlobAroundGlobal( opto1stRotated, coor, disp);
01251 }
01252
01253 }
01254
01255
01256
01257
01258
01259
01260 void OpticalObject::displaceRmGlobAroundLocal( OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp)
01261 {
01262 if( anglesIsGlobal ) {
01263 std::cerr << "!!!FATAL ERROR: angles in global coordinates not supported momentarily if 'rotateAroundGlobal' is set as a Global Option " << std::endl;
01264 abort();
01265 }
01266
01267 if(ALIUtils::debug>=5) std::cout << name() << " DISPLACE_RMGLOB_AROUND_LOCAL " << coor << " disp " << disp << std::endl;
01268
01269
01270 theRmGlob = CLHEP::HepRotation();
01271
01272
01273 if( coor == XCoor ) {
01274 theRmGlob.rotateX( getEntryRMangle(XCoor) + disp );
01275 if(ALIUtils::debug>=5) std::cout << " rmglob rotated around x " << getEntryRMangle(XCoor) + disp << std::endl;
01276 }else {
01277 theRmGlob.rotateX( getEntryRMangle(XCoor) );
01278 }
01279 if(ALIUtils::debug >= 4) {
01280 ALIUtils::dumprm( theRmGlob, "displaceRmGlobAroundLocal: rm local after X " );
01281 }
01282
01283
01284 if( coor == YCoor ) {
01285 theRmGlob.rotateY( getEntryRMangle(YCoor) + disp );
01286 if(ALIUtils::debug>=5) std::cout << " rmglob rotated around y " << getEntryRMangle(YCoor) + disp << std::endl;
01287 }else {
01288 theRmGlob.rotateY( getEntryRMangle(YCoor) );
01289 }
01290 if(ALIUtils::debug >= 4) {
01291 std::cout << " getEntryRMangle(YCoor) " << getEntryRMangle(YCoor) << std::endl;
01292 ALIUtils::dumprm( theRmGlob, "displaceRmGlobAroundLocal: rm local after Y " );
01293 }
01294
01295 if( coor == ZCoor ) {
01296 theRmGlob.rotateZ( getEntryRMangle(ZCoor) + disp );
01297 if(ALIUtils::debug>=5) std::cout << " rmglob rotated around z " << getEntryRMangle(ZCoor) + disp << std::endl;
01298 }else {
01299 theRmGlob.rotateZ( getEntryRMangle(ZCoor) );
01300 }
01301 if(ALIUtils::debug >= 4) {
01302 std::cout << " getEntryRMangle(ZCoor) " << getEntryRMangle(ZCoor) << std::endl;
01303 ALIUtils::dumprm( theRmGlob, "SetRMLocalFromEntryValues: RM ");
01304 }
01305
01306
01307 if(ALIUtils::debug >= 5 && disp != 0) {
01308 std::cout << this->name() << std::endl;
01309 ALIUtils::dumprm( theRmGlob, "displaceRmGlobAroundLocal: rm local " );
01310 }
01311
01312
01313 if( !anglesIsGlobal ) {
01314 SetRMGlobFromRMLocal();
01315 }
01316
01317
01318 calculateLocalRotationAxisInGlobal();
01319
01320
01321 if(ALIUtils::debug >= 5 && disp != 0) {
01322 std::cout << this->name() << std::endl;
01323 ALIUtils::dumprm( theRmGlob, "displaceRmGlobAroundLocal: rm global " );
01324 }
01325
01326 if(opto1stRotated != this ) {
01327 setGlobalCentre();
01328 if(ALIUtils::debug >= 5) {
01329 ALIUtils::dump3v( centreGlob(), " centre_glob after rotation" );
01330 ALIUtils::dump3v( centreGlobOriginal(), " centre_globOriginal() after rotation" );
01331 }
01332 }
01333
01334
01335 std::vector<OpticalObject*> vopto;
01336 Model::getComponentOptOs(name(), vopto);
01337 std::vector<OpticalObject*>::const_iterator vocite;
01338 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01339 (*vocite)->displaceRmGlobAroundLocal( opto1stRotated, coor, 0.);
01340
01341 }
01342
01343 }
01344
01345
01346
01347 void OpticalObject::setGlobalCoordinatesOfComponents()
01348 {
01349
01350
01351 std::vector<OpticalObject*> vopto;
01352 Model::getComponentOptOs(name(), vopto);
01353 std::vector<OpticalObject*>::const_iterator vocite;
01354 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01355 (*vocite)->setGlobalCoordinates();
01356 }
01357
01358 }
01359
01360
01361
01362 void OpticalObject::displaceRmGlobOriginal(const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp)
01363 {
01364 if(ALIUtils::debug>=9) std::cout << name() << " DISPLACEORIGRMGLOB " << coor << " disp " << disp << std::endl;
01365 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
01366 if(gomgr->GlobalOptions()["rotateAroundLocal"] == 0) {
01367
01368 if( ALIUtils::debug >= 5 ) ALIUtils::dumprm(theRmGlobOriginal, (name() + ALIstring(" theRmGlobOriginal before displaced ")).c_str() );
01369 switch( coor ) {
01370 case 0:
01371 theRmGlobOriginal.rotateX( disp );
01372 break;
01373 case 1:
01374 theRmGlobOriginal.rotateY( disp );
01375 break;
01376 case 2:
01377 theRmGlobOriginal.rotateZ( disp );
01378 break;
01379 default:
01380 std::cerr << "!!! DISPLACERMGLOB coordinate should be 0-2, not " << coor << std::endl;
01381 exit(2);
01382 }
01383
01384
01385
01386 if(ALIUtils::debug>=98)ALIUtils::dump3v( centreGlob(), "angles rotate centre_glob" );
01387 if(ALIUtils::debug>=98)ALIUtils::dump3v( centreGlobOriginal(), " centreGlobOriginal" );
01388 if(opto1stRotated != this ) {
01389
01390 CLHEP::Hep3Vector radiusOriginal = centreGlobOriginal() - opto1stRotated->centreGlobOriginal();
01391 CLHEP::Hep3Vector radius_rotated = radiusOriginal;
01392 switch (coor) {
01393 case 0:
01394 radius_rotated.rotateX(disp);
01395 break;
01396 case 1:
01397 radius_rotated.rotateY(disp);
01398 break;
01399 case 2:
01400 radius_rotated.rotateZ(disp);
01401 break;
01402 default:
01403 break;
01404 }
01405 theCentreGlobOriginal = centreGlobOriginal() + (radius_rotated - radiusOriginal);
01406 if(ALIUtils::debug>=98)ALIUtils::dump3v( centreGlob(), "angle rotate centre_glob" );
01407 if(ALIUtils::debug>=98)ALIUtils::dump3v( centreGlobOriginal(), " centre_globOriginal()" );
01408 }
01409
01410 if( ALIUtils::debug >= 5 ) ALIUtils::dumprm(theRmGlobOriginal, (name() + ALIstring(" theRmGlobOriginal displaced ")).c_str() );
01411
01412
01413 std::vector<OpticalObject*> vopto;
01414 Model::getComponentOptOs(name(), vopto);
01415 std::vector<OpticalObject*>::const_iterator vocite;
01416 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01417 (*vocite)->displaceRmGlobOriginal( opto1stRotated, coor, disp);
01418 }
01419
01420 } else {
01421 setGlobalCoordinates();
01422 theCentreGlobOriginal = theCentreGlob;
01423 theRmGlobOriginal = theRmGlob;
01424
01425 std::vector<OpticalObject*> vopto;
01426 Model::getComponentOptOs(name(), vopto);
01427 std::vector<OpticalObject*>::const_iterator vocite;
01428 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01429 (*vocite)->displaceRmGlobOriginal( opto1stRotated, coor, disp);
01430 }
01431 if( ALIUtils::debug >= 5 ) {
01432 ALIUtils::dump3v( theCentreGlob, " displaceRmGlobOriginal " );
01433 ALIUtils::dumprm( theRmGlob, " displaceRmGlobOriginal " );
01434 }
01435 }
01436
01437 }
01438
01439
01440 void OpticalObject::displaceRmGlobOriginalOriginal(const OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp)
01441 {
01442 if(ALIUtils::debug>=9) std::cout << name() << " DISPLACEORIGRMGLOB " << coor << " disp " << disp << std::endl;
01443 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
01444 if(gomgr->GlobalOptions()["rotateAroundLocal"] == 0) {
01445
01446 if( ALIUtils::debug >= 5 ) ALIUtils::dumprm(theRmGlobOriginalOriginal, (name() + ALIstring(" theRmGlobOriginalOriginal before displaced ")).c_str() );
01447 switch( coor ) {
01448 case 0:
01449 theRmGlobOriginalOriginal.rotateX( disp );
01450 break;
01451 case 1:
01452 theRmGlobOriginalOriginal.rotateY( disp );
01453 break;
01454 case 2:
01455 theRmGlobOriginalOriginal.rotateZ( disp );
01456 break;
01457 default:
01458 std::cerr << "!!! DISPLACERMGLOB coordinate should be 0-2, not " << coor << std::endl;
01459 exit(2);
01460 }
01461
01462
01463
01464 if(ALIUtils::debug>=98)ALIUtils::dump3v( centreGlob(), "angles rotate centre_glob" );
01465 if(ALIUtils::debug>=98)ALIUtils::dump3v( centreGlobOriginalOriginal(), " centreGlobOriginalOriginal" );
01466 if(opto1stRotated != this ) {
01467
01468 CLHEP::Hep3Vector radiusOriginalOriginal = centreGlobOriginalOriginal() - opto1stRotated->centreGlobOriginalOriginal();
01469 CLHEP::Hep3Vector radius_rotated = radiusOriginalOriginal;
01470 switch (coor) {
01471 case 0:
01472 radius_rotated.rotateX(disp);
01473 break;
01474 case 1:
01475 radius_rotated.rotateY(disp);
01476 break;
01477 case 2:
01478 radius_rotated.rotateZ(disp);
01479 break;
01480 default:
01481 break;
01482 }
01483 theCentreGlobOriginalOriginal = centreGlobOriginalOriginal() + (radius_rotated - radiusOriginalOriginal);
01484 if(ALIUtils::debug>=98)ALIUtils::dump3v( centreGlob(), "angle rotate centre_glob" );
01485 if(ALIUtils::debug>=98)ALIUtils::dump3v( centreGlobOriginalOriginal(), " centre_globOriginalOriginal()" );
01486 }
01487
01488 if( ALIUtils::debug >= 5 ) ALIUtils::dumprm(theRmGlobOriginalOriginal, (name() + ALIstring(" theRmGlobOriginalOriginal displaced ")).c_str() );
01489
01490
01491 std::vector<OpticalObject*> vopto;
01492 Model::getComponentOptOs(name(), vopto);
01493 std::vector<OpticalObject*>::const_iterator vocite;
01494 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01495 (*vocite)->displaceRmGlobOriginalOriginal( opto1stRotated, coor, disp);
01496 }
01497
01498 } else {
01499 setGlobalCoordinates();
01500 theCentreGlobOriginalOriginal = theCentreGlob;
01501 theRmGlobOriginalOriginal = theRmGlob;
01502
01503 std::vector<OpticalObject*> vopto;
01504 Model::getComponentOptOs(name(), vopto);
01505 std::vector<OpticalObject*>::const_iterator vocite;
01506 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01507 (*vocite)->displaceRmGlobOriginalOriginal( opto1stRotated, coor, disp);
01508 }
01509 if( ALIUtils::debug >= 5 ) {
01510 ALIUtils::dump3v( theCentreGlob, " displaceRmGlobOriginalOriginal " );
01511 ALIUtils::dumprm( theRmGlob, " displaceRmGlobOriginalOriginal " );
01512 }
01513 }
01514
01515 }
01516
01517
01518
01519 void OpticalObject::displaceExtraEntryOriginal( const ALIuint entryNo, const ALIdouble disp)
01520 {
01521 ALIdouble Pentry_orig_value = *(theExtraEntryValueOriginalVector.begin() + entryNo);
01522 Pentry_orig_value += disp;
01523
01524 theExtraEntryValueOriginalVector[entryNo] = Pentry_orig_value;
01525
01526 }
01527
01528
01529
01530 void OpticalObject::displaceExtraEntryOriginalOriginal( const ALIuint entryNo, const ALIdouble disp)
01531 {
01532 ALIdouble Pentry_orig_value = *(theExtraEntryValueOriginalOriginalVector.begin() + entryNo);
01533 Pentry_orig_value += disp;
01534
01535 theExtraEntryValueOriginalOriginalVector[entryNo] = Pentry_orig_value;
01536
01537 }
01538
01539
01540
01541 const ALIint OpticalObject::extraEntryNo( const ALIstring& entry_name ) const
01542 {
01543
01544
01545 std::vector<Entry*>::const_iterator vecite;
01546 for (vecite = ExtraEntryList().begin(); vecite != ExtraEntryList().end(); vecite++) {
01547
01548 if ((*vecite)->name() == entry_name ) {
01549 return (vecite - ExtraEntryList().begin());
01550 }
01551
01552 }
01553
01554
01555 return ALIint(-1);
01556 }
01557
01558
01559
01560
01561
01562 const ALIdouble OpticalObject::findExtraEntryValue( const ALIstring& eename ) const {
01563 ALIdouble retval;
01564 const ALIint entryNo = extraEntryNo( eename );
01565 if( entryNo >= 0 ) {
01566 const ALIdouble Pentry_value = *(theExtraEntryValueVector.begin() + entryNo);
01567 retval = (Pentry_value);
01568 } else {
01569
01570 ALIdouble check;
01571 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
01572 gomgr->getGlobalOptionValue("check_extra_entries", check );
01573 if( check == 1) {
01574
01575 std::cerr << "!!OpticalObject:ERROR: entry not found; " << eename << ", in object " << name() << std::endl;
01576 exit(1);
01577 } else {
01578
01579 retval = 0.;
01580 }
01581 }
01582
01583 if(ALIUtils::debug >= 5) std::cout << " OpticalObject::findExtraEntryValue: " << eename << " = " << retval << std::endl;
01584 return retval;
01585 }
01586
01587
01588
01589
01590
01591 const ALIdouble OpticalObject::findExtraEntryValueMustExist( const ALIstring& eename ) const
01592 {
01593 ALIdouble entry = findExtraEntryValue( eename );
01594 const ALIint entryNo = extraEntryNo( eename );
01595 if( entryNo < 0) {
01596 std::cerr << "!!OpticalObject::findExtraEntryValueMustExist: ERROR: entry not found; " << eename << ", in object " << name() << std::endl;
01597 exit(1);
01598 }
01599
01600 return entry;
01601 }
01602
01603
01604
01605
01606
01607 const ALIbool OpticalObject::findExtraEntryValueIfExists( const ALIstring& eename, ALIdouble& value ) const
01608 {
01609 value = findExtraEntryValue( eename );
01610 const ALIint entryNo = extraEntryNo( eename );
01611
01612 return( entryNo >= 0 );
01613 }
01614
01615
01616
01617
01618
01619 void OpticalObject::resetGlobalCoordinates()
01620 {
01621
01622
01623 theRmGlob = rmGlobOriginal();
01624 theCentreGlob = centreGlobOriginal();
01625
01626
01627
01628 std::vector<ALIdouble>::iterator vdite;
01629 std::vector<ALIdouble>::const_iterator vdcite_o = ExtraEntryValueOriginalList().begin() ;
01630 for (vdite = ExtraEntryValueList().begin();
01631 vdite != ExtraEntryValueList().end(); vdite++,vdcite_o++) {
01632 (*vdite) = (*vdcite_o);
01633 }
01634
01635
01636 std::vector<OpticalObject*> vopto;
01637 Model::getComponentOptOs(name(), vopto);
01638 std::vector<OpticalObject*>::const_iterator vocite;
01639 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01640 (*vocite)->resetGlobalCoordinates();
01641 }
01642
01643 calculateLocalRotationAxisInGlobal();
01644 }
01645
01646
01647
01648
01649
01650 void OpticalObject::resetOriginalOriginalCoordinates()
01651 {
01652
01653
01654
01655 theRmGlob = theRmGlobOriginalOriginal;
01656 theCentreGlob = theCentreGlobOriginalOriginal;
01657 theRmGlobOriginal = theRmGlobOriginalOriginal;
01658 theCentreGlobOriginal = theCentreGlobOriginalOriginal;
01659
01660
01661
01662 std::vector<ALIdouble>::iterator vdite;
01663 std::vector<ALIdouble>::iterator vdite_o = theExtraEntryValueOriginalVector.begin() ;
01664 std::vector<ALIdouble>::const_iterator vdcite_oo = theExtraEntryValueOriginalOriginalVector.begin() ;
01665 std::vector<Entry*>::const_iterator vdciteE = ExtraEntryList().begin() ;
01666 for (vdite = ExtraEntryValueList().begin();
01667 vdite != ExtraEntryValueList().end(); vdite++,vdite_o++,vdcite_oo++,vdciteE++) {
01668 (*vdite) = (*vdcite_oo);
01669 (*vdite_o) = (*vdcite_oo);
01670 (*vdciteE)->addFittedDisplacementToValue( - (*vdciteE)->valueDisplacementByFitting() );
01671
01672
01673
01674 }
01675
01676
01677
01678
01679
01680
01681
01682
01683 calculateLocalRotationAxisInGlobal();
01684
01685
01686 std::vector<OpticalObject*> vopto;
01687 Model::getComponentOptOs(name(), vopto);
01688 std::vector<OpticalObject*>::const_iterator vocite;
01689 for (vocite = vopto.begin(); vocite != vopto.end(); vocite++) {
01690 (*vocite)->resetOriginalOriginalCoordinates();
01691 }
01692
01693
01694 }
01695
01696
01697
01698
01699
01700
01701 OpticalObject::~OpticalObject()
01702 {
01703 }
01704
01705
01706
01707
01708
01709 const ALIstring OpticalObject::shortName() const
01710 {
01711 ALIint last_slash = name().rfind('/');
01712 ALIstring sname = name().substr(last_slash+1, name().size()-1);
01713 if( last_slash == -1 ) {
01714 sname = name();
01715 } else {
01716 sname = name().substr(last_slash+1, name().size()-1);
01717 }
01718 return sname;
01719 }
01720
01721
01722
01723 std::ostream& operator << (std::ostream& os, const OpticalObject& c) {
01724 os << "OPTICALOBJECT: " << c.theName << " of type: " << c.theType
01725 << " " << c.theCentreGlob
01726 << c.theRmGlob << std::endl;
01727
01728 return os;
01729
01730 }
01731
01732
01733
01734 const HepRotation OpticalObject::rmLocal() const
01735 {
01736 HepRotation rm;
01737 rm.rotateX( theCoordinateEntryVector[3]->value() );
01738 rm.rotateY( theCoordinateEntryVector[4]->value() );
01739 rm.rotateZ( theCoordinateEntryVector[5]->value() );
01740
01741 return rm;
01742 }
01743
01744
01745 std::vector<double> OpticalObject::getLocalRotationAngles( std::vector< Entry* > entries ) const
01746 {
01747 return getRotationAnglesInOptOFrame( theParent, entries );
01748 }
01749
01750
01751 std::vector<double> OpticalObject::getRotationAnglesInOptOFrame( const OpticalObject* optoAncestor, std::vector< Entry* > entries ) const
01752 {
01753 CLHEP::HepRotation rmParent = optoAncestor->rmGlob();
01754 CLHEP::HepRotation rmLocal = rmParent.inverse() * theRmGlob;
01755
01756
01757 if( theRmGlobOriginal != theRmGlob ){
01758 std::cerr << " !!!FATAL ERROR: OpticalObject::getRotationAnglesInOptOFrame theRmGlobOriginal != theRmGlob " << std::endl;
01759 ALIUtils::dumprm( theRmGlobOriginal, " theRmGlobOriginal ");
01760 ALIUtils::dumprm( theRmGlob, " theRmGlob ");
01761 exit(1);
01762 }
01763
01764 if( ALIUtils::debug >= 5 ) {
01765 std::cout << " OpticalObject::getRotationAnglesInOptOFrame " << name() << " optoAncestor " << optoAncestor->name() << std::endl;
01766 ALIUtils::dumprm( rmParent, " rm parent ");
01767 ALIUtils::dumprm( rmLocal, " rm local ");
01768 ALIUtils::dumprm( theRmGlobOriginal, " theRmGlobOriginal ");
01769 ALIUtils::dumprm( theRmGlob, " theRmGlob ");
01770 }
01771 return getRotationAnglesFromMatrix( rmLocal, entries );
01772
01773 }
01774
01775
01776
01777 std::vector<double> OpticalObject::getRotationAnglesFromMatrix( CLHEP::HepRotation& rmLocal, std::vector< Entry* > entries ) const
01778 {
01779 std::vector<double> newang(3);
01780 double angleX = entries[3]->value()+entries[3]->valueDisplacementByFitting();
01781 double angleY = entries[4]->value()+entries[4]->valueDisplacementByFitting();
01782 double angleZ = entries[5]->value()+entries[5]->valueDisplacementByFitting();
01783 if( ALIUtils::debug >= 4 ) {
01784 std::cout << " angles as value entries: X= " << angleX << " Y= " << angleY << " Z " << angleZ << std::endl;
01785 }
01786 return ALIUtils::getRotationAnglesFromMatrix( rmLocal, angleX, angleY, angleZ );
01787 }
01788
01789
01790 void OpticalObject::calculateLocalRotationAxisInGlobal()
01791 {
01792 axisXLocalInGlobal = CLHEP::Hep3Vector(1.,0.,0.);
01793 axisXLocalInGlobal *= theRmGlob;
01794 axisYLocalInGlobal = CLHEP::Hep3Vector(0.,1.,0.);
01795 axisYLocalInGlobal *= theRmGlob;
01796 axisZLocalInGlobal = CLHEP::Hep3Vector(0.,0.,1.);
01797 axisZLocalInGlobal *= theRmGlob;
01798 if( ALIUtils::debug >= 4 ){
01799 std::cout << name() << " axis X local in global " << axisXLocalInGlobal << std::endl;
01800 std::cout << name() << " axis Y local in global " << axisYLocalInGlobal << std::endl;
01801 std::cout << name() << " axis Z local in global " << axisZLocalInGlobal << std::endl;
01802 }
01803
01804 }
01805
01806
01807
01808 template<class T>
01809 void OpticalObject::rotateItAroundGlobal( T& object, const XYZcoor coor, const double disp )
01810 {
01811 switch (coor) {
01812 case 0:
01813 object.rotateX(disp);
01814 break;
01815 case 1:
01816 object.rotateY(disp);
01817 break;
01818 case 2:
01819 object.rotateZ(disp);
01820 break;
01821 }
01822
01823
01824 if( ALIUtils::debug >= 5 ) std::cout << " rotateItAroundGlobal coor " << coor << " disp " << disp << std::endl;
01825 }
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871 double OpticalObject::diff2pi( double ang1, double ang2 )
01872 {
01873 double diff = fabs( ang1 - ang2 );
01874 diff = diff - int(diff/2./M_PI) * 2 *M_PI;
01875 return diff;
01876 }
01877
01878
01879
01880 bool OpticalObject::eq2ang( double ang1, double ang2 )
01881 {
01882 bool beq = true;
01883
01884 double diff = diff2pi( ang1, ang2 );
01885 if( diff > 0.00001 ) {
01886 if( fabs( diff - 2*M_PI ) > 0.00001 ) {
01887
01888 beq = false;
01889 }
01890 }
01891
01892 return beq;
01893 }
01894
01895
01896
01897 double OpticalObject::approxTo0( double val )
01898 {
01899 double precision = 1.e-9;
01900 if( fabs(val) < precision ) val = 0;
01901 return val;
01902 }
01903
01904
01905
01906 double OpticalObject::addPii( double val )
01907 {
01908 if( val < M_PI ) {
01909 val += M_PI;
01910 } else {
01911 val -= M_PI;
01912 }
01913
01914 return val;
01915 }
01916
01917
01918 int OpticalObject::checkMatrixEquations( double angleX, double angleY, double angleZ, CLHEP::HepRotation* rot)
01919 {
01920
01921 if( rot == 0 ) {
01922 rot = new CLHEP::HepRotation();
01923 rot->rotateX( angleX );
01924 rot->rotateY( angleY );
01925 rot->rotateZ( angleZ );
01926 }
01927 double sx = sin(angleX);
01928 double cx = cos(angleX);
01929 double sy = sin(angleY);
01930 double cy = cos(angleY);
01931 double sz = sin(angleZ);
01932 double cz = cos(angleZ);
01933
01934 double rotxx = cy*cz;
01935 double rotxy = sx*sy*cz-cx*sz;
01936 double rotxz = cx*sy*cz+sx*sz;
01937 double rotyx = cy*sz;
01938 double rotyy = sx*sy*sz+cx*cz;
01939 double rotyz = cx*sy*sz-sx*cz;
01940 double rotzx = -sy;
01941 double rotzy = sx*cy;
01942 double rotzz = cx*cy;
01943
01944 int matrixElemBad = 0;
01945 if( !eq2ang( rot->xx(), rotxx ) ) {
01946 std::cerr << " EQUATION for xx() IS BAD " << rot->xx() << " <> " << rotxx << std::endl;
01947 matrixElemBad++;
01948 }
01949 if( !eq2ang( rot->xy(), rotxy ) ) {
01950 std::cerr << " EQUATION for xy() IS BAD " << rot->xy() << " <> " << rotxy << std::endl;
01951 matrixElemBad++;
01952 }
01953 if( !eq2ang( rot->xz(), rotxz ) ) {
01954 std::cerr << " EQUATION for xz() IS BAD " << rot->xz() << " <> " << rotxz << std::endl;
01955 matrixElemBad++;
01956 }
01957 if( !eq2ang( rot->yx(), rotyx ) ) {
01958 std::cerr << " EQUATION for yx() IS BAD " << rot->yx() << " <> " << rotyx << std::endl;
01959 matrixElemBad++;
01960 }
01961 if( !eq2ang( rot->yy(), rotyy ) ) {
01962 std::cerr << " EQUATION for yy() IS BAD " << rot->yy() << " <> " << rotyy << std::endl;
01963 matrixElemBad++;
01964 }
01965 if( !eq2ang( rot->yz(), rotyz ) ) {
01966 std::cerr << " EQUATION for yz() IS BAD " << rot->yz() << " <> " << rotyz << std::endl;
01967 matrixElemBad++;
01968 }
01969 if( !eq2ang( rot->zx(), rotzx ) ) {
01970 std::cerr << " EQUATION for zx() IS BAD " << rot->zx() << " <> " << rotzx << std::endl;
01971 matrixElemBad++;
01972 }
01973 if( !eq2ang( rot->zy(), rotzy ) ) {
01974 std::cerr << " EQUATION for zy() IS BAD " << rot->zy() << " <> " << rotzy << std::endl;
01975 matrixElemBad++;
01976 }
01977 if( !eq2ang( rot->zz(), rotzz ) ) {
01978 std::cerr << " EQUATION for zz() IS BAD " << rot->zz() << " <> " << rotzz << std::endl;
01979 matrixElemBad++;
01980 }
01981
01982
01983 return matrixElemBad;
01984 }
01985
01986
01987
01988 CLHEP::Hep3Vector OpticalObject::getDispVec( const XYZcoor coor, const ALIdouble disp)
01989 {
01990 CLHEP::Hep3Vector dispVec;
01991 switch (coor) {
01992 case 0:
01993 dispVec = CLHEP::Hep3Vector( disp, 0., 0. );
01994 break;
01995 case 1:
01996 dispVec = CLHEP::Hep3Vector( 0., disp, 0. );
01997 break;
01998 case 2:
01999 dispVec = CLHEP::Hep3Vector( 0., 0., disp );
02000 break;
02001 default:
02002 break;
02003 }
02004
02005 if ( ALIUtils::debug >= 5 ) {
02006 ALIUtils::dump3v( dispVec, " dispVec in local " );
02007 CLHEP::HepRotation rmt = parent()->rmGlob();
02008 ALIUtils::dumprm( rmt, "parent rmGlob ");
02009 }
02010 dispVec = parent()->rmGlob() * dispVec;
02011 if ( ALIUtils::debug >= 5 ) ALIUtils::dump3v( dispVec, " dispVec in global " );
02012
02013 return dispVec;
02014 }
02015
02016
02017
02018
02019 const CLHEP::Hep3Vector OpticalObject::centreLocal() const
02020 {
02021
02022 CLHEP::Hep3Vector cLocal = theCentreGlob - parent()->centreGlob();
02023 CLHEP::HepRotation rmParentInv = inverseOf( parent()->rmGlob() );
02024 cLocal = rmParentInv * cLocal;
02025
02026 return cLocal;
02027
02028
02029
02030
02031
02032
02033
02034
02035 }
02036
02037
02038 const double OpticalObject::getEntryCentre( const XYZcoor coor ) const
02039 {
02040 Entry* ce = theCoordinateEntryVector[coor];
02041
02042 return ce->value() + ce->valueDisplacementByFitting();
02043 }
02044
02045
02046
02047 const double OpticalObject::getEntryCentre( const ALIstring& coorstr ) const
02048 {
02049 XYZcoor coor = XCoor;
02050 if( coorstr == "X" ) {
02051 coor = XCoor;
02052 }else if( coorstr == "Y" ) {
02053 coor = YCoor;
02054 }else if( coorstr == "Z" ) {
02055 coor = ZCoor;
02056 }
02057 Entry* ce = theCoordinateEntryVector[coor];
02058
02059 return ce->value() + ce->valueDisplacementByFitting();
02060 }
02061
02062
02063 const double OpticalObject::getEntryRMangle( const XYZcoor coor ) const{
02064 Entry* ce = theCoordinateEntryVector[coor+3];
02065
02066
02067 return ce->value() + ce->valueDisplacementByFitting();
02068 }
02069
02070
02071 const double OpticalObject::getEntryRMangle( const ALIstring& coorstr ) const
02072 {
02073 XYZcoor coor = XCoor;
02074 if( coorstr == "X" ) {
02075 coor = XCoor;
02076 }else if( coorstr == "Y" ) {
02077 coor = YCoor;
02078 }else if( coorstr == "Z" ) {
02079 coor = ZCoor;
02080 }
02081 Entry* ce = theCoordinateEntryVector[coor+3];
02082
02083
02084 return ce->value() + ce->valueDisplacementByFitting();
02085 }
02086
02087
02088
02089 void OpticalObject::constructMaterial()
02090 {
02091
02092 theMaterial = new CocoaMaterialElementary( "Hydrogen", 70.8*mg/cm3, "H", 1.00794 , 1 );
02093
02094 }
02095
02096
02097 void OpticalObject::constructSolidShape()
02098 {
02099 ALIdouble go;
02100 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
02101 gomgr->getGlobalOptionValue("VisScale", go );
02102
02103 theSolidShape = new CocoaSolidShapeBox( "Box", go*5.*cm/m, go*5.*cm/m, go*5.*cm/m );
02104 }
02105
02106
02107
02108 void OpticalObject::constructFromOptAligInfo( const OpticalAlignInfo& oaInfo )
02109 {
02110 if( theParent != 0 ) {
02111
02112
02113 std::vector<OpticalAlignParam> exEnt = oaInfo.extraEntries_;
02114 std::vector<OpticalAlignParam>::iterator ite;
02115 std::vector<ALIstring> wordlist;
02116 for( ite = exEnt.begin(); ite != exEnt.end(); ite++ ){
02117 wordlist = getCoordinateFromOptAlignParam( *ite );
02118 wordlist.insert(wordlist.begin(), (*ite).dimType() );
02119 fillExtraEntry( wordlist );
02120 }
02121
02122
02123 centreIsGlobal = 0;
02124 anglesIsGlobal = 0;
02125
02126
02127 fillCoordinateEntry( "centre", getCoordinateFromOptAlignParam( oaInfo.x_ ) );
02128 fillCoordinateEntry( "centre", getCoordinateFromOptAlignParam( oaInfo.y_ ) );
02129 fillCoordinateEntry( "centre", getCoordinateFromOptAlignParam( oaInfo.z_ ) );
02130 fillCoordinateEntry( "angles", getCoordinateFromOptAlignParam( oaInfo.angx_ ) );
02131 fillCoordinateEntry( "angles", getCoordinateFromOptAlignParam( oaInfo.angy_ ) );
02132 fillCoordinateEntry( "angles", getCoordinateFromOptAlignParam( oaInfo.angz_ ) );
02133
02134
02135 setGlobalCoordinates();
02136
02137
02138 setOriginalEntryValues();
02139 }
02140
02141
02142 constructMaterial();
02143
02144
02145 constructSolidShape();
02146
02147 if ( ALIUtils::debug >= 5 ) {
02148 std::cout << "constructFromOptAligInfo constructed: " << *this << std::endl;
02149 }
02150
02151
02152 createComponentOptOsFromOptAlignInfo();
02153 }
02154
02155
02156
02157 std::vector<ALIstring> OpticalObject::getCoordinateFromOptAlignParam( const OpticalAlignParam& oaParam )
02158 {
02159 char chartmp[20];
02160 std::vector<ALIstring> wordlist;
02161 wordlist.push_back( oaParam.name() );
02162 gcvt( oaParam.value(), 10, chartmp );
02163 wordlist.push_back( chartmp );
02164 gcvt( oaParam.sigma(), 10, chartmp );
02165 wordlist.push_back( chartmp );
02166 if( oaParam.quality() == 0 ) {
02167 wordlist.push_back("fix");
02168 } else if( oaParam.quality() == 1 ) {
02169 wordlist.push_back("cal");
02170 } else if( oaParam.quality() == 2 ) {
02171 wordlist.push_back("unk");
02172 }
02173
02174 if ( ALIUtils::debug >= 5 ) {
02175 ALIUtils::dumpVS( wordlist, " getCoordinateFromOptAlignParam " + oaParam.name() );
02176 }
02177
02178 return wordlist;
02179
02180 }
02181
02182
02183
02184 void OpticalObject::createComponentOptOsFromOptAlignInfo()
02185 {
02186
02187 std::vector<OpticalAlignInfo> children;
02188
02189 std::vector<OpticalAlignInfo>::const_iterator ite;
02190 if ( ALIUtils::debug >= 5 ) {
02191 std::cout << " Model::getOpticalAlignments().size " << Model::getOpticalAlignments().size() << std::endl;
02192 }
02193
02194 int siz= Model::getOpticalAlignments().size();
02195 for(uint ii = 0; ii < siz; ii++ ){
02196
02197
02198
02199
02200 if( Model::getOpticalAlignments()[ii].parentName_ == theName ) {
02201
02202
02203
02204 std::vector<OpticalAlignParam> exent = Model::getOpticalAlignments()[ii].extraEntries_;
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215 OpticalAlignInfo oaInfochild = Model::getOpticalAlignments()[ii];
02216
02217
02218 children.push_back(oaInfochild);
02219 if ( ALIUtils::debug >= 5 ) {
02220 std::cout << theName << "createComponentOptOsFromOptAlignInfo: children added " << oaInfochild.name_ << std::endl;
02221 }
02222 }
02223
02224
02225 }
02226
02227
02228
02229 if ( ALIUtils::debug >= 5 ) {
02230 std::cout << "OpticalObject::createComponentsFromAlignInfo: N components = " << children.size() << std::endl;
02231 }
02232 for( ite = children.begin(); ite != children.end(); ite++ ){
02233
02234
02235 ALIstring optoType = (*ite).type_;
02236
02237
02238
02239 ALIstring optoName = (*ite).name_;
02240 ALIbool fcopyComponents = 0;
02241
02242
02243 OpticalObject* OptOcomponent = createNewOptO( this, optoType, optoName, fcopyComponents );
02244
02245
02246 OptOcomponent->constructFromOptAligInfo( *ite );
02247
02248
02249 Model::OptOList().push_back( OptOcomponent );
02250 }
02251
02252 }
02253