File indexing completed on 2024-05-10 02:20:14
0001
0002
0003
0004
0005
0006
0007
0008 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0009 #include "Alignment/CocoaModel/interface/OpticalObjectMgr.h"
0010 #include "Alignment/CocoaModel/interface/OptOLaser.h"
0011 #include "Alignment/CocoaModel/interface/OptOSource.h"
0012 #include "Alignment/CocoaModel/interface/OptOXLaser.h"
0013 #include "Alignment/CocoaModel/interface/OptOMirror.h"
0014 #include "Alignment/CocoaModel/interface/OptOPlateSplitter.h"
0015 #include "Alignment/CocoaModel/interface/OptOCubeSplitter.h"
0016 #include "Alignment/CocoaModel/interface/OptOModifiedRhomboidPrism.h"
0017 #include "Alignment/CocoaModel/interface/OptOOpticalSquare.h"
0018 #include "Alignment/CocoaModel/interface/OptOLens.h"
0019 #include "Alignment/CocoaModel/interface/OptORisleyPrism.h"
0020 #include "Alignment/CocoaModel/interface/OptOSensor2D.h"
0021 #include "Alignment/CocoaModel/interface/OptODistancemeter.h"
0022 #include "Alignment/CocoaModel/interface/OptODistancemeter3dim.h"
0023 #include "Alignment/CocoaModel/interface/OptOScreen.h"
0024 #include "Alignment/CocoaModel/interface/OptOTiltmeter.h"
0025 #include "Alignment/CocoaModel/interface/OptOPinhole.h"
0026 #include "Alignment/CocoaModel/interface/OptOCOPS.h"
0027 #include "Alignment/CocoaModel/interface/OptOUserDefined.h"
0028 #include "Alignment/CocoaModel/interface/ALIPlane.h"
0029
0030 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
0031 #include "Alignment/CocoaModel/interface/Model.h"
0032 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
0033 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0034 #include "Alignment/CocoaModel/interface/EntryLengthAffCentre.h"
0035 #include "Alignment/CocoaModel/interface/EntryAngleAffAngles.h"
0036 #include "Alignment/CocoaModel/interface/EntryNoDim.h"
0037 #include "Alignment/CocoaModel/interface/EntryMgr.h"
0038
0039 #include "Alignment/CocoaDDLObjects/interface/CocoaMaterialElementary.h"
0040 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
0041
0042 #include "CondFormats/OptAlignObjects/interface/OpticalAlignInfo.h"
0043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0044
0045 #include <CLHEP/Units/SystemOfUnits.h>
0046
0047 #include <cstdlib>
0048 #include <iostream>
0049
0050
0051
0052
0053 OpticalObject::OpticalObject(OpticalObject* parent,
0054 const ALIstring& type,
0055 const ALIstring& name,
0056 const ALIbool copy_data)
0057 : theParent(parent), theType(type), theName(name), fcopyData(copy_data) {
0058 if (ALIUtils::debug >= 4) {
0059 std::cout << std::endl
0060 << "@@@@ Creating OpticalObject: NAME= " << theName << " TYPE= " << theType << " fcopyData " << fcopyData
0061 << std::endl;
0062 }
0063
0064 OpticalObjectMgr::getInstance()->registerMe(this);
0065 }
0066
0067
0068
0069
0070 void OpticalObject::construct() {
0071
0072 ALIFileIn& filein = ALIFileIn::getInstance(Model::SDFName());
0073
0074
0075
0076
0077
0078
0079 if (theParent != nullptr) {
0080
0081 if (!fcopyData) {
0082 if (ALIUtils::debug >= 4)
0083 std::cout << "@@@@ Reading data of Optical Object " << name() << std::endl;
0084 readData(filein);
0085 } else {
0086 if (ALIUtils::debug >= 4)
0087 std::cout << "Copy data of Optical Object " << name() << std::endl;
0088 copyData();
0089 }
0090
0091
0092 setGlobalCoordinates();
0093
0094
0095
0096
0097
0098
0099
0100
0101 setOriginalEntryValues();
0102 }
0103
0104
0105 createComponentOptOs(filein);
0106
0107
0108 constructMaterial();
0109
0110
0111 constructSolidShape();
0112 }
0113
0114
0115
0116
0117
0118 void OpticalObject::readData(ALIFileIn& filein) {
0119
0120 std::vector<ALIstring> wordlist;
0121 filein.getWordsInLine(wordlist);
0122 if (wordlist[0] == ALIstring("ENTRY")) {
0123
0124 readExtraEntries(filein);
0125 filein.getWordsInLine(wordlist);
0126 }
0127
0128
0129 centreIsGlobal = false;
0130 anglesIsGlobal = false;
0131
0132
0133 if (type() == ALIstring("source") || type() == ALIstring("pinhole")) {
0134 readCoordinates(wordlist[0], "centre", filein);
0135 setAnglesNull();
0136 } else {
0137
0138 readCoordinates(wordlist[0], "centre", filein);
0139 filein.getWordsInLine(wordlist);
0140 readCoordinates(wordlist[0], "angles", filein);
0141 }
0142 }
0143
0144
0145
0146
0147 void OpticalObject::readExtraEntries(ALIFileIn& filein) {
0148
0149 std::vector<ALIstring> wordlist;
0150 for (;;) {
0151 filein.getWordsInLine(wordlist);
0152 if (wordlist[0] != ALIstring("}")) {
0153 fillExtraEntry(wordlist);
0154 } else {
0155 break;
0156 }
0157 }
0158 }
0159
0160
0161
0162
0163 void OpticalObject::fillExtraEntry(std::vector<ALIstring>& wordlist) {
0164
0165
0166
0167 Entry* xentry;
0168 if (wordlist[0] == ALIstring("length")) {
0169 xentry = new EntryLength(wordlist[0]);
0170 } else if (wordlist[0] == ALIstring("angle")) {
0171 xentry = new EntryAngle(wordlist[0]);
0172 } else if (wordlist[0] == ALIstring("nodim")) {
0173 xentry = new EntryNoDim(wordlist[0]);
0174 } else {
0175 std::cerr << "!!ERROR: Exiting... unknown type of Extra Entry " << wordlist[0] << std::endl;
0176 ALIUtils::dumpVS(wordlist, " Only 'length', 'angle' or 'nodim' are allowed ", std::cerr);
0177 exit(2);
0178 }
0179
0180 if (ALIUtils::debug >= 99) {
0181 ALIUtils::dumpVS(wordlist, "fillExtraEntry: ", std::cout);
0182 }
0183
0184 wordlist.erase(wordlist.begin());
0185
0186 if (ALIUtils::debug >= 99) {
0187 ALIUtils::dumpVS(wordlist, "fillExtraEntry: ", std::cout);
0188 }
0189
0190
0191 xentry->setOptOCurrent(this);
0192
0193 xentry->fillName(wordlist[0]);
0194
0195 xentry->fill(wordlist);
0196
0197
0198 Model::addEntryToList(xentry);
0199 addExtraEntryToList(xentry);
0200
0201 if (ALIUtils::debug >= 5)
0202 std::cout << "fillExtraEntry: xentry_value" << xentry->value() << xentry->ValueDimensionFactor() << std::endl;
0203
0204
0205 addExtraEntryValueToList(xentry->value());
0206 }
0207
0208
0209
0210
0211
0212 void OpticalObject::readCoordinates(const ALIstring& coor_type_read,
0213 const ALIstring& coor_type_expected,
0214 ALIFileIn& filein) {
0215 ALIstring coor_type_reads = coor_type_read.substr(0, 6);
0216 if (coor_type_reads == "center")
0217 coor_type_reads = "centre";
0218
0219
0220
0221
0222 if (EntryMgr::getInstance()->findEntryByLongName(longName(), "") == nullptr) {
0223 if (coor_type_read.size() == 7) {
0224 if (coor_type_read[6] == 'G') {
0225 if (ALIUtils::debug >= 5)
0226 std::cout << " coordinate global " << coor_type_read << std::endl;
0227 if (coor_type_expected == "centre") {
0228 centreIsGlobal = true;
0229 } else if (coor_type_expected == "angles") {
0230 anglesIsGlobal = true;
0231 }
0232 }
0233 }
0234 }
0235
0236 std::vector<ALIstring> wordlist;
0237
0238 ALIstring coor_names[3];
0239
0240 for (int ii = 0; ii < 4; ii++) {
0241 if (ii == 0) {
0242
0243 if (coor_type_reads != coor_type_expected) {
0244 filein.ErrorInLine();
0245 std::cerr << "readCoordinates: " << coor_type_expected << " should be read here, instead of " << coor_type_reads
0246 << std::endl;
0247 exit(1);
0248 }
0249 } else {
0250
0251 filein.getWordsInLine(wordlist);
0252 coor_names[ii - 1] = wordlist[0];
0253 fillCoordinateEntry(coor_type_expected, wordlist);
0254 }
0255 }
0256
0257
0258 if (coor_names[0] == ALIstring("X") && coor_names[1] == ALIstring("Y") && coor_names[2] == ALIstring("Z")) {
0259
0260 } else if (coor_names[0] == ALIstring("R") && coor_names[1] == ALIstring("PHI") && coor_names[2] == ALIstring("Z")) {
0261 transformCylindrical2Cartesian();
0262 } else if (coor_names[0] == ALIstring("R") && coor_names[1] == ALIstring("THE") &&
0263 coor_names[2] == ALIstring("PHI")) {
0264 transformSpherical2Cartesian();
0265 } else {
0266 std::cerr << "!!!EXITING: coordinates have to be cartesian (X ,Y ,Z), or cylindrical (R, PHI, Z) or spherical (R, "
0267 "THE, PHI) "
0268 << std::endl
0269 << " they are " << coor_names[0] << ", " << coor_names[1] << ", " << coor_names[2] << "." << std::endl;
0270 exit(1);
0271 }
0272 }
0273
0274
0275 void OpticalObject::transformCylindrical2Cartesian() {
0276 ALIuint ii;
0277 ALIuint siz = theCoordinateEntryVector.size();
0278 ALIdouble R = theCoordinateEntryVector[0]->value();
0279 ALIdouble phi = theCoordinateEntryVector[1]->value() / ALIUtils::LengthValueDimensionFactor() *
0280 ALIUtils::AngleValueDimensionFactor();
0281 if (siz != 3) {
0282 throw cms::Exception("LogicError") << "@SUB=OpticalObject::transformCylindrical2Cartesian\n"
0283 << "Transformation from cylindrical to cartesian coordinates requires the"
0284 << " coordinate entry vector to have a size of three.";
0285 }
0286 ALIdouble newcoor[3] = {
0287 R * cos(phi),
0288 R * sin(phi),
0289 theCoordinateEntryVector[2]->value()
0290 };
0291
0292
0293
0294 for (ii = 0; ii < siz; ii++) {
0295 if (ALIUtils::debug >= 5)
0296 std::cout << " OpticalObject::transformCylindrical2Cartesian " << ii << " " << newcoor[ii] << std::endl;
0297 theCoordinateEntryVector[ii]->setValue(newcoor[ii]);
0298 }
0299
0300 ALIstring name = "centre_X";
0301 theCoordinateEntryVector[0]->fillName(name);
0302 name = "centre_Y";
0303 theCoordinateEntryVector[1]->fillName(name);
0304 name = "centre_Z";
0305 theCoordinateEntryVector[2]->fillName(name);
0306 }
0307
0308
0309 void OpticalObject::transformSpherical2Cartesian() {}
0310
0311
0312
0313
0314 void OpticalObject::fillCoordinateEntry(const ALIstring& coor_type, const std::vector<ALIstring>& wordlist) {
0315
0316 Entry* entry = nullptr;
0317 if (coor_type == ALIstring("centre")) {
0318 entry = new EntryLengthAffCentre(coor_type);
0319 } else if (coor_type == ALIstring("angles")) {
0320 entry = new EntryAngleAffAngles(coor_type);
0321 } else {
0322 std::cerr << " !!! FATAL ERROR at OpticalObject::fillCoordinateEntry : wrong coordinate type " << coor_type
0323 << std::endl;
0324 exit(1);
0325 }
0326
0327
0328 entry->setOptOCurrent(this);
0329
0330 ALIstring name = coor_type + "_" + wordlist[0];
0331 entry->fillName(name);
0332
0333 entry->fill(wordlist);
0334
0335
0336 Model::addEntryToList(entry);
0337 addCoordinateEntryToList(entry);
0338 }
0339
0340
0341
0342
0343 void OpticalObject::setAnglesNull() {
0344 EntryAngleAffAngles* entry;
0345
0346 ALIstring coor("XYZ");
0347
0348
0349 for (int ii = 0; ii < 3; ii++) {
0350 entry = new EntryAngleAffAngles("angles");
0351
0352
0353 entry->setOptOCurrent(this);
0354
0355 ALIstring name = "angles_" + coor.substr(ii, 1);
0356 entry->fillName(name);
0357
0358 entry->fillNull();
0359
0360
0361
0362
0363 Model::addEntryToList(entry);
0364 addCoordinateEntryToList(entry);
0365 }
0366 }
0367
0368
0369
0370
0371 void OpticalObject::copyData() {
0372 centreIsGlobal = false;
0373 anglesIsGlobal = false;
0374 if (ALIUtils::debug >= 5)
0375 std::cout << "entering copyData()" << std::endl;
0376
0377
0378 OpticalObject* opto = Model::nextOptOToCopy();
0379
0380
0381 ALIint copy_name_last_slash = opto->name().rfind('/');
0382 ALIint copy_name_size = opto->name().length();
0383
0384 theName.append(opto->name(), copy_name_last_slash, copy_name_size);
0385 if (ALIUtils::debug >= 5)
0386 std::cout << "copying OptO: " << opto->name() << " to OptO " << theName << std::endl;
0387
0388
0389 std::vector<Entry*>::const_iterator vecite;
0390 for (vecite = opto->ExtraEntryList().begin(); vecite != opto->ExtraEntryList().end(); ++vecite) {
0391 std::vector<ALIstring> wordlist;
0392 wordlist.push_back((*vecite)->type());
0393 buildWordList((*vecite), wordlist);
0394 if (ALIUtils::debug >= 9) {
0395 ALIUtils::dumpVS(wordlist, "copyData: ", std::cout);
0396 }
0397 fillExtraEntry(wordlist);
0398 }
0399
0400
0401 for (vecite = opto->CoordinateEntryList().begin(); vecite != opto->CoordinateEntryList().end(); ++vecite) {
0402 std::vector<ALIstring> wordlist;
0403 buildWordList((*vecite), wordlist);
0404
0405 ALIstring coor_name;
0406 if (vecite - opto->CoordinateEntryList().begin() < 3) {
0407 coor_name = "centre";
0408 } else {
0409 coor_name = "angles";
0410 }
0411 fillCoordinateEntry(coor_name, wordlist);
0412 }
0413 }
0414
0415
0416
0417
0418 void OpticalObject::buildWordList(const Entry* entry, std::vector<ALIstring>& wordlist) {
0419
0420 wordlist.push_back(entry->name());
0421
0422
0423 char chartmp[20];
0424 gcvt(entry->value() / entry->ValueDimensionFactor(), 10, chartmp);
0425 wordlist.push_back(chartmp);
0426
0427
0428 gcvt(entry->sigma() / entry->SigmaDimensionFactor(), 10, chartmp);
0429 wordlist.push_back(chartmp);
0430
0431
0432 ALIstring strtmp;
0433 ALIint inttmp = entry->quality();
0434 switch (inttmp) {
0435 case 0:
0436 strtmp = "fix";
0437 break;
0438 case 1:
0439 strtmp = "cal";
0440 break;
0441 case 2:
0442 strtmp = "unk";
0443 break;
0444 default:
0445 std::cerr << "buildWordList: entry " << entry->OptOCurrent()->name() << entry->name() << " quality not found "
0446 << inttmp << std::endl;
0447 break;
0448 }
0449 wordlist.push_back(strtmp);
0450
0451 if (ALIUtils::debug >= 9) {
0452 ALIUtils::dumpVS(wordlist, "buildWordList: ", std::cout);
0453 }
0454 }
0455
0456
0457
0458
0459 void OpticalObject::createComponentOptOs(ALIFileIn& filein) {
0460
0461 ALIbool fcopyComponents = false;
0462
0463
0464 std::vector<ALIstring> vopto_types;
0465 int igetood = Model::getComponentOptOTypes(type(), vopto_types);
0466 if (!igetood) {
0467 if (ALIUtils::debug >= 5)
0468 std::cout << " NO MORE COMPONENTS IN THIS OptO" << name() << std::endl;
0469 return;
0470 }
0471
0472
0473
0474
0475
0476
0477
0478 std::vector<ALIstring>::iterator vsite;
0479 std::vector<ALIstring> wordlist;
0480 for (vsite = vopto_types.begin(); vsite != vopto_types.end(); ++vsite) {
0481
0482
0483 if (!fcopyData && !fcopyComponents)
0484 filein.getWordsInLine(wordlist);
0485
0486
0487
0488
0489
0490 if (fcopyData || fcopyComponents) {
0491 fcopyComponents = true;
0492
0493 } else if (wordlist[0] == ALIstring("copy_components")) {
0494 if (ALIUtils::debug >= 3)
0495 std::cout << "createComponentOptOs: copy_components" << wordlist[0] << std::endl;
0496 Model::createCopyComponentList(type());
0497 fcopyComponents = true;
0498
0499 } else if (wordlist[0] != (*vsite)) {
0500 filein.ErrorInLine();
0501 std::cerr << "!!! Badly placed OpticalObject: " << wordlist[0] << " should be = " << (*vsite) << std::endl;
0502 exit(2);
0503 }
0504
0505
0506 ALIstring component_name = name();
0507
0508 if (!fcopyComponents) {
0509 component_name += '/';
0510 component_name += wordlist[1];
0511 }
0512
0513
0514
0515 OpticalObject* OptOcomponent = createNewOptO(this, *vsite, component_name, fcopyComponents);
0516
0517
0518 if (wordlist.size() == 3) {
0519 OptOcomponent->setID(ALIUtils::getInt(wordlist[2]));
0520 } else {
0521 OptOcomponent->setID(OpticalObjectMgr::getInstance()->buildCmsSwID());
0522 }
0523
0524
0525 OptOcomponent->construct();
0526
0527
0528 Model::OptOList().push_back(OptOcomponent);
0529 }
0530 }
0531
0532
0533 OpticalObject* OpticalObject::createNewOptO(OpticalObject* parent,
0534 ALIstring optoType,
0535 ALIstring optoName,
0536 ALIbool fcopyComponents) {
0537 if (ALIUtils::debug >= 3)
0538 std::cout << " OpticalObject::createNewOptO optoType " << optoType << " optoName " << optoName << " parent "
0539 << parent->name() << std::endl;
0540 OpticalObject* OptOcomponent;
0541 if (optoType == "laser") {
0542 OptOcomponent = new OptOLaser(this, optoType, optoName, fcopyComponents);
0543 } else if (optoType == "source") {
0544 OptOcomponent = new OptOSource(this, optoType, optoName, fcopyComponents);
0545 } else if (optoType == "Xlaser") {
0546 OptOcomponent = new OptOXLaser(this, optoType, optoName, fcopyComponents);
0547 } else if (optoType == "mirror") {
0548 OptOcomponent = new OptOMirror(this, optoType, optoName, fcopyComponents);
0549 } else if (optoType == "plate_splitter") {
0550 OptOcomponent = new OptOPlateSplitter(this, optoType, optoName, fcopyComponents);
0551 } else if (optoType == "cube_splitter") {
0552 OptOcomponent = new OptOCubeSplitter(this, optoType, optoName, fcopyComponents);
0553 } else if (optoType == "modified_rhomboid_prism") {
0554 OptOcomponent = new OptOModifiedRhomboidPrism(this, optoType, optoName, fcopyComponents);
0555 } else if (optoType == "pseudo_pentaprism" || optoType == "optical_square") {
0556 OptOcomponent = new OptOOpticalSquare(this, optoType, optoName, fcopyComponents);
0557 } else if (optoType == "lens") {
0558 OptOcomponent = new OptOLens(this, optoType, optoName, fcopyComponents);
0559 } else if (optoType == "Risley_prism") {
0560 OptOcomponent = new OptORisleyPrism(this, optoType, optoName, fcopyComponents);
0561 } else if (optoType == "sensor2D") {
0562 OptOcomponent = new OptOSensor2D(this, optoType, optoName, fcopyComponents);
0563 } else if (optoType == "distancemeter" || optoType == "distancemeter1dim") {
0564 OptOcomponent = new OptODistancemeter(this, optoType, optoName, fcopyComponents);
0565 } else if (optoType == "distancemeter3dim") {
0566 OptOcomponent = new OptODistancemeter3dim(this, optoType, optoName, fcopyComponents);
0567 } else if (optoType == "distance_target") {
0568 OptOcomponent = new OptOScreen(this, optoType, optoName, fcopyComponents);
0569 } else if (optoType == "tiltmeter") {
0570 OptOcomponent = new OptOTiltmeter(this, optoType, optoName, fcopyComponents);
0571 } else if (optoType == "pinhole") {
0572 OptOcomponent = new OptOPinhole(this, optoType, optoName, fcopyComponents);
0573 } else if (optoType == "COPS") {
0574 OptOcomponent = new OptOCOPS(this, optoType, optoName, fcopyComponents);
0575 } else {
0576 OptOcomponent =
0577
0578 new OptOUserDefined(this, optoType, optoName, fcopyComponents);
0579 }
0580
0581 return OptOcomponent;
0582 }
0583
0584
0585
0586
0587 void OpticalObject::setGlobalCoordinates() {
0588 setGlobalCentre();
0589 setGlobalRM();
0590 }
0591
0592
0593 void OpticalObject::setGlobalCentre() {
0594 SetCentreLocalFromEntryValues();
0595 if (type() != ALIstring("system") && !centreIsGlobal) {
0596 SetCentreGlobFromCentreLocal();
0597 }
0598 if (anglesIsGlobal) {
0599 std::cerr << "!!!FATAL ERROR: angles in global coordinates not supported momentarily " << std::endl;
0600 abort();
0601 }
0602 }
0603
0604
0605 void OpticalObject::setGlobalRM() {
0606 SetRMLocalFromEntryValues();
0607 if (!anglesIsGlobal) {
0608 SetRMGlobFromRMLocal();
0609 }
0610
0611
0612 calculateLocalRotationAxisInGlobal();
0613 }
0614
0615
0616 void OpticalObject::setGlobalRMOriginalOriginal(const CLHEP::HepRotation& rmorioriLocal) {
0617 CLHEP::HepRotation rmorioriold = rmGlobOriginalOriginal();
0618 if (ALIUtils::debug >= 5) {
0619 std::cout << " setGlobalRMOriginalOriginal OptO " << name() << std::endl;
0620 ALIUtils::dumprm(rmorioriLocal, " setGlobalRMOriginalOriginal new local");
0621 ALIUtils::dumprm(rmGlobOriginalOriginal(), " setGlobalRMOriginalOriginal old ");
0622 }
0623
0624 SetRMGlobFromRMLocalOriginalOriginal(rmorioriLocal);
0625
0626
0627
0628
0629
0630
0631 if (ALIUtils::debug >= 5) {
0632 ALIUtils::dumprm(parent()->rmGlobOriginalOriginal(), " parent rmoriori glob ");
0633 ALIUtils::dumprm(rmGlobOriginalOriginal(), " setGlobalRMOriginalOriginal new ");
0634 }
0635
0636
0637 std::vector<OpticalObject*> vopto;
0638 ALIbool igetood = Model::getComponentOptOs(name(), vopto);
0639 if (!igetood) {
0640
0641 return;
0642 }
0643 std::vector<OpticalObject*>::const_iterator vocite;
0644 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
0645 CLHEP::HepRotation rmorioriLocalChild = (*vocite)->buildRmFromEntryValuesOriginalOriginal();
0646 (*vocite)->setGlobalRMOriginalOriginal(rmorioriLocalChild);
0647
0648 }
0649 }
0650
0651
0652 void OpticalObject::propagateGlobalRMOriginalOriginalChangeToChildren(const CLHEP::HepRotation& rmorioriold,
0653 const CLHEP::HepRotation& rmoriorinew) {
0654 std::cout << " propagateGlobalRMOriginalOriginalChangeToChildren OptO " << name() << std::endl;
0655 ALIUtils::dumprm(rmGlobOriginalOriginal(), " setGlobalRMOriginalOriginal old ");
0656 theRmGlobOriginalOriginal = rmoriorinew.inverse() * theRmGlobOriginalOriginal;
0657 theRmGlobOriginalOriginal = rmorioriold * theRmGlobOriginalOriginal;
0658 ALIUtils::dumprm(rmGlobOriginalOriginal(), " setGlobalRMOriginalOriginal new ");
0659
0660
0661 std::vector<OpticalObject*> vopto;
0662 ALIbool igetood = Model::getComponentOptOs(name(), vopto);
0663 if (!igetood) {
0664
0665 return;
0666 }
0667 std::vector<OpticalObject*>::const_iterator vocite;
0668 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
0669
0670 (*vocite)->propagateGlobalRMOriginalOriginalChangeToChildren(rmorioriold, rmoriorinew);
0671 }
0672 }
0673
0674
0675 CLHEP::HepRotation OpticalObject::buildRmFromEntryValuesOriginalOriginal() {
0676 CLHEP::HepRotation rm;
0677 const OpticalObject* opto_par = this;
0678
0679 if (ALIUtils::debug >= 55)
0680 std::cout << "rotate with parent: before X " << opto_par->parent()->name() << " "
0681 << parent()->getEntryRMangle(XCoor) << std::endl;
0682 const std::vector<Entry*>& cel = CoordinateEntryList();
0683 rm.rotateX(cel[3]->valueOriginalOriginal());
0684 if (ALIUtils::debug >= 55)
0685 std::cout << "rotate with parent: before Y " << opto_par->parent()->name() << " "
0686 << parent()->getEntryRMangle(YCoor) << std::endl;
0687 rm.rotateY(cel[4]->valueOriginalOriginal());
0688 if (ALIUtils::debug >= 55)
0689 std::cout << "rotate with parent: before Z " << opto_par->parent()->name() << " "
0690 << parent()->getEntryRMangle(ZCoor) << std::endl;
0691 rm.rotateZ(cel[5]->valueOriginalOriginal());
0692
0693 if (ALIUtils::debug >= 54)
0694 ALIUtils::dumprm(theRmGlob, "SetRMGlobFromRMLocal: RM GLOB after " + opto_par->parent()->longName());
0695
0696 return rm;
0697 }
0698
0699
0700 void OpticalObject::SetCentreLocalFromEntryValues() {
0701
0702
0703
0704
0705
0706
0707 theCentreGlob.setX(getEntryCentre(XCoor));
0708 theCentreGlob.setY(getEntryCentre(YCoor));
0709 theCentreGlob.setZ(getEntryCentre(ZCoor));
0710 if (ALIUtils::debug >= 4)
0711 ALIUtils::dump3v(centreGlob(), "SetCentreLocalFromEntryValues: CENTRE LOCAL ");
0712 }
0713
0714
0715 void OpticalObject::SetRMLocalFromEntryValues() {
0716
0717
0718 theRmGlob = CLHEP::HepRotation();
0719 theRmGlob.rotateX(getEntryRMangle(XCoor));
0720 if (ALIUtils::debug >= 4) {
0721 std::cout << " getEntryRMangle(XCoor) )" << getEntryRMangle(XCoor) << std::endl;
0722 ALIUtils::dumprm(theRmGlob, "SetRMLocalFromEntryValues: RM after X");
0723 }
0724 theRmGlob.rotateY(getEntryRMangle(YCoor));
0725 if (ALIUtils::debug >= 4) {
0726 std::cout << " getEntryRMangle(YCoor) )" << getEntryRMangle(YCoor) << std::endl;
0727 ALIUtils::dumprm(theRmGlob, "SetRMLocalFromEntryValues: RM after Y");
0728 }
0729 theRmGlob.rotateZ(getEntryRMangle(ZCoor));
0730 if (ALIUtils::debug >= 4) {
0731 std::cout << " getEntryRMangle(ZCoor) )" << getEntryRMangle(ZCoor) << std::endl;
0732 ALIUtils::dumprm(theRmGlob, "SetRMLocalFromEntryValues: RM FINAL");
0733 }
0734
0735
0736
0737
0738
0739
0740
0741
0742
0743
0744
0745
0746 }
0747
0748
0749 void OpticalObject::SetCentreGlobFromCentreLocal() {
0750
0751 CLHEP::Hep3Vector cLocal = theCentreGlob;
0752 theCentreGlob = parent()->rmGlob() * theCentreGlob;
0753
0754 if (ALIUtils::debug >= 5)
0755 ALIUtils::dump3v(theCentreGlob, "SetCentreGlobFromCentreLocal: CENTRE in parent local frame ");
0756 theCentreGlob += parent()->centreGlob();
0757
0758 if (ALIUtils::debug >= 5)
0759 ALIUtils::dump3v(theCentreGlob, "SetCentreGlobFromCentreLocal: CENTRE GLOBAL ");
0760 if (ALIUtils::debug >= 5) {
0761 ALIUtils::dump3v(parent()->centreGlob(), " parent centreGlob" + parent()->name());
0762 ALIUtils::dumprm(parent()->rmGlob(), " parent rmGlob ");
0763 }
0764
0765
0766
0767
0768
0769
0770
0771
0772
0773
0774 }
0775
0776
0777 void OpticalObject::SetRMGlobFromRMLocal() {
0778 const OpticalObject* opto_par = this;
0779 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0780 if (gomgr->GlobalOptions()["rotateAroundLocal"] == 0) {
0781 while (opto_par->parent()->type() != ALIstring("system")) {
0782
0783 if (ALIUtils::debug >= 5)
0784 std::cout << "rotate with parent: before X " << opto_par->parent()->name() << " "
0785 << parent()->getEntryRMangle(XCoor) << std::endl;
0786 theRmGlob.rotateX(parent()->getEntryRMangle(XCoor));
0787 if (ALIUtils::debug >= 5)
0788 std::cout << "rotate with parent: before Y " << opto_par->parent()->name() << " "
0789 << parent()->getEntryRMangle(YCoor) << std::endl;
0790 theRmGlob.rotateY(parent()->getEntryRMangle(YCoor));
0791 if (ALIUtils::debug >= 5)
0792 std::cout << "rotate with parent: before Z " << opto_par->parent()->name() << " "
0793 << parent()->getEntryRMangle(ZCoor) << std::endl;
0794 theRmGlob.rotateZ(parent()->getEntryRMangle(ZCoor));
0795 if (ALIUtils::debug >= 4)
0796 ALIUtils::dumprm(theRmGlob, "SetRMGlobFromRMLocal: RM GLOB after " + opto_par->parent()->longName());
0797 opto_par = opto_par->parent();
0798 }
0799 } else {
0800 if (ALIUtils::debug >= 4) {
0801 std::cout << " Composing rmGlob with parent " << parent()->name() << std::endl;
0802
0803 }
0804 theRmGlob = parent()->rmGlob() * theRmGlob;
0805 }
0806
0807
0808 if (ALIUtils::debug >= 4) {
0809 ALIUtils::dumprm(theRmGlob, "SetRMGlobFromRMLocal: final RM GLOB ");
0810 ALIUtils::dumprm(parent()->rmGlob(), "parent rm glob ");
0811 }
0812 }
0813
0814
0815 void OpticalObject::SetRMGlobFromRMLocalOriginalOriginal(const CLHEP::HepRotation& rmoriori) {
0816 theRmGlobOriginalOriginal = rmoriori;
0817 theRmGlobOriginalOriginal = parent()->rmGlobOriginalOriginal() * theRmGlobOriginalOriginal;
0818 }
0819
0820
0821
0822
0823 void OpticalObject::setOriginalEntryValues() {
0824
0825 theCentreGlobOriginal = centreGlob();
0826 theRmGlobOriginal = rmGlob();
0827
0828 theCentreGlobOriginalOriginal = centreGlob();
0829 theRmGlobOriginalOriginal = rmGlob();
0830
0831
0832
0833
0834
0835
0836
0837 std::vector<ALIdouble>::const_iterator vdcite;
0838 for (vdcite = ExtraEntryValueList().begin(); vdcite != ExtraEntryValueList().end(); ++vdcite) {
0839 addExtraEntryValueOriginalToList(*vdcite);
0840 addExtraEntryValueOriginalOriginalToList(*vdcite);
0841 }
0842
0843 if (ALIUtils::debug >= 6)
0844 std::cout << " setOriginalEntryValues " << std::endl;
0845 }
0846
0847
0848
0849
0850 void OpticalObject::participateInMeasurement(LightRay& lightray, Measurement& meas, const ALIstring& behav) {
0851
0852 setMeas(&meas);
0853 if (behav == " ") {
0854 defaultBehaviour(lightray, meas);
0855 } else if (behav == "D" || behav == "DD") {
0856 detailedDeviatesLightRay(lightray);
0857 } else if (behav == "T" || behav == "DT") {
0858 detailedTraversesLightRay(lightray);
0859 } else if (behav == "FD") {
0860 fastDeviatesLightRay(lightray);
0861 } else if (behav == "FT") {
0862 fastTraversesLightRay(lightray);
0863 } else if (behav == "M") {
0864 makeMeasurement(lightray, meas);
0865 } else {
0866 userDefinedBehaviour(lightray, meas, behav);
0867 }
0868 }
0869
0870
0871
0872
0873 void OpticalObject::defaultBehaviour(LightRay& lightray, Measurement& meas) {
0874 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement a default behaviour"
0875 << std::endl;
0876 std::cerr << " You have to specify some behaviour, like :D or :T or ..." << std::endl;
0877 exit(1);
0878 }
0879
0880
0881
0882
0883 void OpticalObject::fastDeviatesLightRay(LightRay& lightray) {
0884 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement deviation (:D)"
0885 << std::endl;
0886 std::cerr << " Please read documentation for this object type" << std::endl;
0887 exit(1);
0888 }
0889
0890
0891
0892
0893 void OpticalObject::fastTraversesLightRay(LightRay& lightray) {
0894 std::cerr << "!!! Optical Object " << name() << " of type " << type()
0895 << " does not implement the light traversing (:T)" << std::endl;
0896 std::cerr << " Please read documentation for this object type" << std::endl;
0897 exit(1);
0898 }
0899
0900
0901
0902
0903 void OpticalObject::detailedDeviatesLightRay(LightRay& lightray) {
0904 std::cerr << "!!! Optical Object " << name() << " of type " << type()
0905 << " does not implement detailed deviation (:DD / :D)" << std::endl;
0906 std::cerr << " Please read documentation for this object type" << std::endl;
0907 exit(1);
0908 }
0909
0910
0911
0912
0913 void OpticalObject::detailedTraversesLightRay(LightRay& lightray) {
0914 std::cerr << "!!! Optical Object " << name() << " of type " << type()
0915 << " does not implement detailed traversing of light ray (:DT / :T)" << std::endl;
0916 std::cerr << " Please read documentation for this object type" << std::endl;
0917 exit(1);
0918 }
0919
0920
0921
0922
0923 void OpticalObject::makeMeasurement(LightRay& lightray, Measurement& meas) {
0924 std::cerr << "!!! Optical Object " << name() << " of type " << type() << " does not implement making measurement (:M)"
0925 << std::endl;
0926 std::cerr << " Please read documentation for this object type" << std::endl;
0927 exit(1);
0928 }
0929
0930 void OpticalObject::userDefinedBehaviour(LightRay& lightray, Measurement& meas, const ALIstring& behav) {
0931 std::cerr << "!!! Optical Object " << name() << " of type " << type()
0932 << " does not implement user defined behaviour = " << behav << std::endl;
0933 std::cerr << " Please read documentation for this object type" << std::endl;
0934 exit(1);
0935 }
0936
0937
0938
0939
0940
0941
0942
0943
0944
0945
0946 ALIPlane OpticalObject::getPlate(const ALIbool forwardPlate, const ALIbool applyWedge) {
0947 if (ALIUtils::debug >= 4)
0948 std::cout << "% LR: GET PLATE " << name() << " forward= " << forwardPlate << std::endl;
0949
0950 const ALIdouble width = (findExtraEntryValue("width"));
0951
0952
0953
0954 CLHEP::Hep3Vector ZAxis(0., 0., 1.);
0955 CLHEP::HepRotation rmt = rmGlob();
0956 CLHEP::Hep3Vector plate_normal = rmt * ZAxis;
0957
0958
0959 CLHEP::Hep3Vector plate_point = centreGlob();
0960
0961 ALIdouble normal_sign = -forwardPlate * 2 + 1;
0962 plate_point += normal_sign * width / 2. * plate_normal;
0963
0964 if (ALIUtils::debug >= 3) {
0965 ALIUtils::dump3v(plate_point, "plate_point");
0966 ALIUtils::dump3v(plate_normal, "plate_normal before wedge");
0967 ALIUtils::dumprm(rmt, "rmt before wedge");
0968 }
0969
0970 if (applyWedge) {
0971 ALIdouble wedge;
0972 wedge = findExtraEntryValue("wedge");
0973 if (wedge != 0.) {
0974
0975 CLHEP::Hep3Vector XAxis(1., 0., 0.);
0976 XAxis = rmt * XAxis;
0977 plate_normal.rotate(normal_sign * wedge / 2., XAxis);
0978 if (ALIUtils::debug >= 3)
0979 ALIUtils::dump3v(plate_normal, "plate_normal after wedgeX ");
0980 if (ALIUtils::debug >= 4)
0981 ALIUtils::dump3v(XAxis, "X Axis for applying wedge ");
0982 CLHEP::Hep3Vector YAxis(0., 1., 0.);
0983 YAxis = rmt * YAxis;
0984 plate_normal.rotate(normal_sign * wedge / 2., YAxis);
0985 if (ALIUtils::debug >= 3)
0986 ALIUtils::dump3v(plate_normal, "plate_normal after wedgeY ");
0987 if (ALIUtils::debug >= 4)
0988 ALIUtils::dump3v(YAxis, "Y Axis for applying wedge ");
0989 }
0990 }
0991
0992
0993 return ALIPlane(plate_point, plate_normal);
0994 }
0995
0996
0997
0998
0999
1000 void OpticalObject::displaceCentreGlob(const XYZcoor coor, const ALIdouble disp) {
1001 if (ALIUtils::debug >= 5)
1002 std::cout << name() << " displaceCentreGlob: coor " << coor << " disp = " << disp << std::endl;
1003
1004 theCentreGlob = centreGlobOriginal();
1005 CLHEP::Hep3Vector dispVec = getDispVec(coor, disp);
1006 theCentreGlob += dispVec;
1007
1008
1009 std::vector<OpticalObject*> vopto;
1010 ALIbool igetood = Model::getComponentOptOs(name(), vopto);
1011 if (!igetood) {
1012
1013 return;
1014 }
1015 std::vector<OpticalObject*>::const_iterator vocite;
1016 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1017 (*vocite)->displaceCentreGlob(dispVec);
1018 }
1019 }
1020
1021
1022 CLHEP::Hep3Vector OpticalObject::getDisplacementInLocalCoordinates(const XYZcoor coor, const ALIdouble disp) {
1023 CLHEP::Hep3Vector dispVec;
1024 switch (coor) {
1025 case 0:
1026 dispVec = CLHEP::Hep3Vector(disp, 0., 0.);
1027 break;
1028 case 1:
1029 dispVec = CLHEP::Hep3Vector(0., disp, 0.);
1030 break;
1031 case 2:
1032 dispVec = CLHEP::Hep3Vector(0., 0., disp);
1033 break;
1034 default:
1035 std::cerr << "!!! DISPLACECENTREGLOB coordinate should be 0-2, not " << coor << std::endl;
1036 exit(2);
1037 }
1038
1039 return dispVec;
1040 }
1041
1042
1043
1044
1045
1046 void OpticalObject::displaceCentreGlob(const CLHEP::Hep3Vector& dispVec) {
1047 if (ALIUtils::debug >= 5)
1048 std::cout << name() << " displaceCentreGlob: dispVec = " << dispVec << std::endl;
1049
1050 theCentreGlob = centreGlobOriginal();
1051 theCentreGlob += dispVec;
1052
1053
1054 std::vector<OpticalObject*> vopto;
1055 ALIbool igetood = Model::getComponentOptOs(name(), vopto);
1056 if (!igetood) {
1057 return;
1058 }
1059 std::vector<OpticalObject*>::const_iterator vocite;
1060 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1061 (*vocite)->displaceCentreGlob(dispVec);
1062 }
1063 }
1064
1065
1066
1067
1068 void OpticalObject::displaceExtraEntry(const ALIuint entryNo, const ALIdouble disp) {
1069 ALIdouble Pentry_orig_value = *(theExtraEntryValueOriginalVector.begin() + entryNo);
1070 ALIdouble Pentry_value = (Pentry_orig_value) + disp;
1071 LogDebug("OpticalObject::displaceExtraEntry")
1072 << " displaceExtraEntry " << Pentry_value << " <> " << Pentry_orig_value << std::endl;
1073 theExtraEntryValueVector[entryNo] = Pentry_value;
1074 }
1075
1076
1077 void OpticalObject::setExtraEntryValue(const ALIuint entryNo, const ALIdouble val) {
1078 theExtraEntryValueVector[entryNo] = val;
1079 }
1080
1081
1082 void OpticalObject::displaceCentreGlobOriginal(const XYZcoor coor, const ALIdouble disp) {
1083 if (ALIUtils::debug >= 4)
1084 std::cout << "@@ OpticalObject::displaceCentreGloboriginal " << name() << " " << coor << " " << disp << std::endl;
1085 if (ALIUtils::debug >= 5)
1086 ALIUtils::dump3v(theCentreGlobOriginal, "the centre glob original 0");
1087 CLHEP::Hep3Vector dispVec = getDispVec(coor, disp);
1088 theCentreGlobOriginal += dispVec;
1089
1090 if (ALIUtils::debug >= 5)
1091 ALIUtils::dump3v(theCentreGlobOriginal, "the centre glob original displaced");
1092
1093
1094 std::vector<OpticalObject*> vopto;
1095 Model::getComponentOptOs(name(), vopto);
1096 std::vector<OpticalObject*>::const_iterator vocite;
1097 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1098 (*vocite)->displaceCentreGlobOriginal(dispVec);
1099 }
1100 }
1101
1102
1103
1104
1105 void OpticalObject::displaceCentreGlobOriginal(const CLHEP::Hep3Vector& dispVec) {
1106 if (ALIUtils::debug >= 4)
1107 std::cout << " OpticalObject::displaceCentreGloboriginal " << name() << " dispVec " << dispVec << std::endl;
1108
1109 theCentreGlobOriginal += dispVec;
1110
1111 if (ALIUtils::debug >= 5)
1112 ALIUtils::dump3v(theCentreGlobOriginal, "the centre glob original");
1113
1114
1115 std::vector<OpticalObject*> vopto;
1116 Model::getComponentOptOs(name(), vopto);
1117 std::vector<OpticalObject*>::const_iterator vocite;
1118 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1119 (*vocite)->displaceCentreGlobOriginal(dispVec);
1120 }
1121 }
1122
1123
1124 void OpticalObject::displaceCentreGlobOriginalOriginal(const XYZcoor coor, const ALIdouble disp) {
1125 if (ALIUtils::debug >= 4)
1126 std::cout << "@@ OpticalObject::displaceCentreGloboriginal " << name() << " " << coor << " " << disp << std::endl;
1127 if (ALIUtils::debug >= 5)
1128 ALIUtils::dump3v(theCentreGlobOriginalOriginal, "the centre glob originalOriginal 0");
1129 CLHEP::Hep3Vector dispVec = getDispVec(coor, disp);
1130 theCentreGlobOriginalOriginal += dispVec;
1131
1132 if (ALIUtils::debug >= 5)
1133 ALIUtils::dump3v(theCentreGlobOriginalOriginal, "the centre glob original displaced");
1134
1135
1136 std::vector<OpticalObject*> vopto;
1137 Model::getComponentOptOs(name(), vopto);
1138 std::vector<OpticalObject*>::const_iterator vocite;
1139 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1140 (*vocite)->displaceCentreGlobOriginalOriginal(dispVec);
1141 }
1142 }
1143
1144
1145
1146
1147 void OpticalObject::displaceCentreGlobOriginalOriginal(const CLHEP::Hep3Vector& dispVec) {
1148 if (ALIUtils::debug >= 4)
1149 std::cout << " OpticalObject::displaceCentreGloboriginal " << name() << " dispVec " << dispVec << std::endl;
1150
1151 theCentreGlobOriginalOriginal += dispVec;
1152
1153 if (ALIUtils::debug >= 5)
1154 ALIUtils::dump3v(theCentreGlobOriginalOriginal, "the centre glob original");
1155
1156
1157 std::vector<OpticalObject*> vopto;
1158 Model::getComponentOptOs(name(), vopto);
1159 std::vector<OpticalObject*>::const_iterator vocite;
1160 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1161 (*vocite)->displaceCentreGlobOriginalOriginal(dispVec);
1162 }
1163 }
1164
1165
1166
1167
1168
1169 void OpticalObject::displaceRmGlobAroundGlobal(OpticalObject* opto1stRotated,
1170 const XYZcoor coor,
1171 const ALIdouble disp) {
1172 if (ALIUtils::debug >= 5)
1173 std::cout << name() << "DISPLACERMGLOBAROUNDGLOBAL" << coor << "disp" << disp << std::endl;
1174
1175 theRmGlob = rmGlobOriginal();
1176 theCentreGlob = centreGlobOriginal();
1177 if (ALIUtils::debug >= 5) {
1178 std::cout << this->name() << std::endl;
1179 ALIUtils::dumprm(theRmGlob, "before disp rm ");
1180 }
1181 rotateItAroundGlobal(theRmGlob, coor, disp);
1182 if (ALIUtils::debug >= 5) {
1183 ALIUtils::dumprm(theRmGlob, "after disp rm ");
1184 }
1185
1186 if (ALIUtils::debug >= 5)
1187 ALIUtils::dump3v(centreGlob(), " centre_glob before rotation");
1188 if (ALIUtils::debug >= 5)
1189 ALIUtils::dump3v(centreGlobOriginal(), " centreGlobOriginal before rotation");
1190 if (opto1stRotated != this) {
1191
1192 CLHEP::Hep3Vector radiusOriginal = centreGlobOriginal() - opto1stRotated->centreGlobOriginal();
1193 CLHEP::Hep3Vector radius_rotated = radiusOriginal;
1194 rotateItAroundGlobal(radius_rotated, coor, disp);
1195 theCentreGlob = centreGlobOriginal() + (radius_rotated - radiusOriginal);
1196 if (ALIUtils::debug >= 5)
1197 ALIUtils::dump3v(centreGlob(), " centre_glob after rotation");
1198 if (ALIUtils::debug >= 5)
1199 ALIUtils::dump3v(centreGlobOriginal(), " centre_globOriginal() after rotation");
1200 }
1201
1202
1203 std::vector<OpticalObject*> vopto;
1204 Model::getComponentOptOs(name(), vopto);
1205 std::vector<OpticalObject*>::const_iterator vocite;
1206 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1207 (*vocite)->displaceRmGlobAroundGlobal(opto1stRotated, coor, disp);
1208 }
1209 }
1210
1211
1212
1213
1214
1215 void OpticalObject::displaceRmGlobAroundLocal(OpticalObject* opto1stRotated, const XYZcoor coor, const ALIdouble disp) {
1216 if (anglesIsGlobal) {
1217 std::cerr << "!!!FATAL ERROR: angles in global coordinates not supported momentarily if 'rotateAroundGlobal' is "
1218 "set as a Global Option "
1219 << std::endl;
1220 abort();
1221 }
1222
1223 if (ALIUtils::debug >= 5)
1224 std::cout << name() << " DISPLACE_RMGLOB_AROUND_LOCAL " << coor << " disp " << disp << std::endl;
1225
1226
1227 theRmGlob = CLHEP::HepRotation();
1228
1229
1230 if (coor == XCoor) {
1231 theRmGlob.rotateX(getEntryRMangle(XCoor) + disp);
1232 if (ALIUtils::debug >= 5)
1233 std::cout << " rmglob rotated around x " << getEntryRMangle(XCoor) + disp << std::endl;
1234 } else {
1235 theRmGlob.rotateX(getEntryRMangle(XCoor));
1236 }
1237 if (ALIUtils::debug >= 4) {
1238 ALIUtils::dumprm(theRmGlob, "displaceRmGlobAroundLocal: rm local after X ");
1239 }
1240
1241
1242 if (coor == YCoor) {
1243 theRmGlob.rotateY(getEntryRMangle(YCoor) + disp);
1244 if (ALIUtils::debug >= 5)
1245 std::cout << " rmglob rotated around y " << getEntryRMangle(YCoor) + disp << std::endl;
1246 } else {
1247 theRmGlob.rotateY(getEntryRMangle(YCoor));
1248 }
1249 if (ALIUtils::debug >= 4) {
1250 std::cout << " getEntryRMangle(YCoor) " << getEntryRMangle(YCoor) << std::endl;
1251 ALIUtils::dumprm(theRmGlob, "displaceRmGlobAroundLocal: rm local after Y ");
1252 }
1253
1254 if (coor == ZCoor) {
1255 theRmGlob.rotateZ(getEntryRMangle(ZCoor) + disp);
1256 if (ALIUtils::debug >= 5)
1257 std::cout << " rmglob rotated around z " << getEntryRMangle(ZCoor) + disp << std::endl;
1258 } else {
1259 theRmGlob.rotateZ(getEntryRMangle(ZCoor));
1260 }
1261 if (ALIUtils::debug >= 4) {
1262 std::cout << " getEntryRMangle(ZCoor) " << getEntryRMangle(ZCoor) << std::endl;
1263 ALIUtils::dumprm(theRmGlob, "SetRMLocalFromEntryValues: RM ");
1264 }
1265
1266
1267 if (ALIUtils::debug >= 5 && disp != 0) {
1268 std::cout << this->name() << std::endl;
1269 ALIUtils::dumprm(theRmGlob, "displaceRmGlobAroundLocal: rm local ");
1270 }
1271
1272 if (!anglesIsGlobal) {
1273 SetRMGlobFromRMLocal();
1274 }
1275
1276
1277 calculateLocalRotationAxisInGlobal();
1278
1279
1280 if (ALIUtils::debug >= 5 && disp != 0) {
1281 std::cout << this->name() << std::endl;
1282 ALIUtils::dumprm(theRmGlob, "displaceRmGlobAroundLocal: rm global ");
1283 }
1284
1285 if (opto1stRotated != this) {
1286 setGlobalCentre();
1287 if (ALIUtils::debug >= 5) {
1288 ALIUtils::dump3v(centreGlob(), " centre_glob after rotation");
1289 ALIUtils::dump3v(centreGlobOriginal(), " centre_globOriginal() after rotation");
1290 }
1291 }
1292
1293
1294 std::vector<OpticalObject*> vopto;
1295 Model::getComponentOptOs(name(), vopto);
1296 std::vector<OpticalObject*>::const_iterator vocite;
1297 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1298 (*vocite)->displaceRmGlobAroundLocal(opto1stRotated, coor, 0.);
1299
1300 }
1301 }
1302
1303
1304 void OpticalObject::setGlobalCoordinatesOfComponents() {
1305
1306 std::vector<OpticalObject*> vopto;
1307 Model::getComponentOptOs(name(), vopto);
1308 std::vector<OpticalObject*>::const_iterator vocite;
1309 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1310 (*vocite)->setGlobalCoordinates();
1311 }
1312 }
1313
1314
1315 void OpticalObject::displaceRmGlobOriginal(const OpticalObject* opto1stRotated,
1316 const XYZcoor coor,
1317 const ALIdouble disp) {
1318 if (ALIUtils::debug >= 9)
1319 std::cout << name() << " DISPLACEORIGRMGLOB " << coor << " disp " << disp << std::endl;
1320 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
1321 if (gomgr->GlobalOptions()["rotateAroundLocal"] == 0) {
1322
1323 if (ALIUtils::debug >= 5)
1324 ALIUtils::dumprm(theRmGlobOriginal, name() + ALIstring(" theRmGlobOriginal before displaced "));
1325 switch (coor) {
1326 case 0:
1327 theRmGlobOriginal.rotateX(disp);
1328 break;
1329 case 1:
1330 theRmGlobOriginal.rotateY(disp);
1331 break;
1332 case 2:
1333 theRmGlobOriginal.rotateZ(disp);
1334 break;
1335 default:
1336 std::cerr << "!!! DISPLACERMGLOB coordinate should be 0-2, not " << coor << std::endl;
1337 exit(2);
1338 }
1339
1340
1341 if (ALIUtils::debug >= 98)
1342 ALIUtils::dump3v(centreGlob(), "angles rotate centre_glob");
1343 if (ALIUtils::debug >= 98)
1344 ALIUtils::dump3v(centreGlobOriginal(), " centreGlobOriginal");
1345 if (opto1stRotated != this) {
1346
1347 CLHEP::Hep3Vector radiusOriginal = centreGlobOriginal() - opto1stRotated->centreGlobOriginal();
1348 CLHEP::Hep3Vector radius_rotated = radiusOriginal;
1349 switch (coor) {
1350 case 0:
1351 radius_rotated.rotateX(disp);
1352 break;
1353 case 1:
1354 radius_rotated.rotateY(disp);
1355 break;
1356 case 2:
1357 radius_rotated.rotateZ(disp);
1358 break;
1359 default:
1360 break;
1361 }
1362 theCentreGlobOriginal = centreGlobOriginal() + (radius_rotated - radiusOriginal);
1363 if (ALIUtils::debug >= 98)
1364 ALIUtils::dump3v(centreGlob(), "angle rotate centre_glob");
1365 if (ALIUtils::debug >= 98)
1366 ALIUtils::dump3v(centreGlobOriginal(), " centre_globOriginal()");
1367 }
1368
1369 if (ALIUtils::debug >= 5)
1370 ALIUtils::dumprm(theRmGlobOriginal, name() + ALIstring(" theRmGlobOriginal displaced "));
1371
1372
1373 std::vector<OpticalObject*> vopto;
1374 Model::getComponentOptOs(name(), vopto);
1375 std::vector<OpticalObject*>::const_iterator vocite;
1376 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1377 (*vocite)->displaceRmGlobOriginal(opto1stRotated, coor, disp);
1378 }
1379
1380 } else {
1381 setGlobalCoordinates();
1382 theCentreGlobOriginal = theCentreGlob;
1383 theRmGlobOriginal = theRmGlob;
1384
1385 std::vector<OpticalObject*> vopto;
1386 Model::getComponentOptOs(name(), vopto);
1387 std::vector<OpticalObject*>::const_iterator vocite;
1388 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1389 (*vocite)->displaceRmGlobOriginal(opto1stRotated, coor, disp);
1390 }
1391 if (ALIUtils::debug >= 5) {
1392 ALIUtils::dump3v(theCentreGlob, " displaceRmGlobOriginal ");
1393 ALIUtils::dumprm(theRmGlob, " displaceRmGlobOriginal ");
1394 }
1395 }
1396 }
1397
1398
1399 void OpticalObject::displaceRmGlobOriginalOriginal(const OpticalObject* opto1stRotated,
1400 const XYZcoor coor,
1401 const ALIdouble disp) {
1402 if (ALIUtils::debug >= 9)
1403 std::cout << name() << " DISPLACEORIGRMGLOB " << coor << " disp " << disp << std::endl;
1404 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
1405 if (gomgr->GlobalOptions()["rotateAroundLocal"] == 0) {
1406
1407 if (ALIUtils::debug >= 5)
1408 ALIUtils::dumprm(theRmGlobOriginalOriginal, name() + ALIstring(" theRmGlobOriginalOriginal before displaced"));
1409 switch (coor) {
1410 case 0:
1411 theRmGlobOriginalOriginal.rotateX(disp);
1412 break;
1413 case 1:
1414 theRmGlobOriginalOriginal.rotateY(disp);
1415 break;
1416 case 2:
1417 theRmGlobOriginalOriginal.rotateZ(disp);
1418 break;
1419 default:
1420 std::cerr << "!!! DISPLACERMGLOB coordinate should be 0-2, not " << coor << std::endl;
1421 exit(2);
1422 }
1423
1424
1425 if (ALIUtils::debug >= 98)
1426 ALIUtils::dump3v(centreGlob(), "angles rotate centre_glob");
1427 if (ALIUtils::debug >= 98)
1428 ALIUtils::dump3v(centreGlobOriginalOriginal(), " centreGlobOriginalOriginal");
1429 if (opto1stRotated != this) {
1430
1431 CLHEP::Hep3Vector radiusOriginalOriginal =
1432 centreGlobOriginalOriginal() - opto1stRotated->centreGlobOriginalOriginal();
1433 CLHEP::Hep3Vector radius_rotated = radiusOriginalOriginal;
1434 switch (coor) {
1435 case 0:
1436 radius_rotated.rotateX(disp);
1437 break;
1438 case 1:
1439 radius_rotated.rotateY(disp);
1440 break;
1441 case 2:
1442 radius_rotated.rotateZ(disp);
1443 break;
1444 default:
1445 break;
1446 }
1447 theCentreGlobOriginalOriginal = centreGlobOriginalOriginal() + (radius_rotated - radiusOriginalOriginal);
1448 if (ALIUtils::debug >= 98)
1449 ALIUtils::dump3v(centreGlob(), "angle rotate centre_glob");
1450 if (ALIUtils::debug >= 98)
1451 ALIUtils::dump3v(centreGlobOriginalOriginal(), " centre_globOriginalOriginal()");
1452 }
1453
1454 if (ALIUtils::debug >= 5)
1455 ALIUtils::dumprm(theRmGlobOriginalOriginal, name() + ALIstring(" theRmGlobOriginalOriginal displaced "));
1456
1457
1458 std::vector<OpticalObject*> vopto;
1459 Model::getComponentOptOs(name(), vopto);
1460 std::vector<OpticalObject*>::const_iterator vocite;
1461 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1462 (*vocite)->displaceRmGlobOriginalOriginal(opto1stRotated, coor, disp);
1463 }
1464
1465 } else {
1466 setGlobalCoordinates();
1467 theCentreGlobOriginalOriginal = theCentreGlob;
1468 theRmGlobOriginalOriginal = theRmGlob;
1469
1470 std::vector<OpticalObject*> vopto;
1471 Model::getComponentOptOs(name(), vopto);
1472 std::vector<OpticalObject*>::const_iterator vocite;
1473 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1474 (*vocite)->displaceRmGlobOriginalOriginal(opto1stRotated, coor, disp);
1475 }
1476 if (ALIUtils::debug >= 5) {
1477 ALIUtils::dump3v(theCentreGlob, " displaceRmGlobOriginalOriginal ");
1478 ALIUtils::dumprm(theRmGlob, " displaceRmGlobOriginalOriginal ");
1479 }
1480 }
1481 }
1482
1483
1484 void OpticalObject::displaceExtraEntryOriginal(const ALIuint entryNo, const ALIdouble disp) {
1485 ALIdouble Pentry_orig_value = *(theExtraEntryValueOriginalVector.begin() + entryNo);
1486 Pentry_orig_value += disp;
1487
1488 theExtraEntryValueOriginalVector[entryNo] = Pentry_orig_value;
1489 }
1490
1491
1492 void OpticalObject::displaceExtraEntryOriginalOriginal(const ALIuint entryNo, const ALIdouble disp) {
1493 ALIdouble Pentry_orig_value = *(theExtraEntryValueOriginalOriginalVector.begin() + entryNo);
1494 Pentry_orig_value += disp;
1495
1496 theExtraEntryValueOriginalOriginalVector[entryNo] = Pentry_orig_value;
1497 }
1498
1499
1500 const ALIint OpticalObject::extraEntryNo(const ALIstring& entry_name) const {
1501
1502
1503 std::vector<Entry*>::const_iterator vecite;
1504 for (vecite = ExtraEntryList().begin(); vecite != ExtraEntryList().end(); ++vecite) {
1505
1506 if ((*vecite)->name() == entry_name) {
1507 return (vecite - ExtraEntryList().begin());
1508 }
1509
1510 }
1511
1512
1513 return ALIint(-1);
1514 }
1515
1516
1517
1518
1519 const ALIdouble OpticalObject::findExtraEntryValue(const ALIstring& eename) const {
1520 ALIdouble retval;
1521 const ALIint entryNo = extraEntryNo(eename);
1522 if (entryNo >= 0) {
1523 const ALIdouble Pentry_value = *(theExtraEntryValueVector.begin() + entryNo);
1524 retval = (Pentry_value);
1525 } else {
1526
1527 ALIdouble check;
1528 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
1529 gomgr->getGlobalOptionValue("check_extra_entries", check);
1530 if (check == 1) {
1531
1532 std::cerr << "!!OpticalObject:ERROR: entry not found; " << eename << ", in object " << name() << std::endl;
1533 exit(1);
1534 } else {
1535
1536 retval = 0.;
1537 }
1538 }
1539
1540 if (ALIUtils::debug >= 5)
1541 std::cout << " OpticalObject::findExtraEntryValue: " << eename << " = " << retval << std::endl;
1542 return retval;
1543 }
1544
1545
1546
1547
1548 const ALIdouble OpticalObject::findExtraEntryValueMustExist(const ALIstring& eename) const {
1549 ALIdouble entry = findExtraEntryValue(eename);
1550 const ALIint entryNo = extraEntryNo(eename);
1551 if (entryNo < 0) {
1552 std::cerr << "!!OpticalObject::findExtraEntryValueMustExist: ERROR: entry not found; " << eename << ", in object "
1553 << name() << std::endl;
1554 exit(1);
1555 }
1556
1557 return entry;
1558 }
1559
1560
1561
1562
1563 const ALIbool OpticalObject::findExtraEntryValueIfExists(const ALIstring& eename, ALIdouble& value) const {
1564 value = findExtraEntryValue(eename);
1565 const ALIint entryNo = extraEntryNo(eename);
1566
1567 return (entryNo >= 0);
1568 }
1569
1570
1571
1572
1573 void OpticalObject::resetGlobalCoordinates() {
1574
1575 theRmGlob = rmGlobOriginal();
1576 theCentreGlob = centreGlobOriginal();
1577
1578
1579
1580 std::vector<ALIdouble>::iterator vdite;
1581 std::vector<ALIdouble>::const_iterator vdcite_o = ExtraEntryValueOriginalList().begin();
1582 for (vdite = ExtraEntryValueList().begin(); vdite != ExtraEntryValueList().end(); ++vdite, ++vdcite_o) {
1583 (*vdite) = (*vdcite_o);
1584 }
1585
1586
1587 std::vector<OpticalObject*> vopto;
1588 Model::getComponentOptOs(name(), vopto);
1589 std::vector<OpticalObject*>::const_iterator vocite;
1590 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1591 (*vocite)->resetGlobalCoordinates();
1592 }
1593
1594 calculateLocalRotationAxisInGlobal();
1595 }
1596
1597
1598
1599
1600 void OpticalObject::resetOriginalOriginalCoordinates() {
1601
1602
1603
1604 theRmGlob = theRmGlobOriginalOriginal;
1605 theCentreGlob = theCentreGlobOriginalOriginal;
1606 theRmGlobOriginal = theRmGlobOriginalOriginal;
1607 theCentreGlobOriginal = theCentreGlobOriginalOriginal;
1608
1609
1610 std::vector<ALIdouble>::iterator vdite;
1611 std::vector<ALIdouble>::iterator vdite_o = theExtraEntryValueOriginalVector.begin();
1612 std::vector<ALIdouble>::const_iterator vdcite_oo = theExtraEntryValueOriginalOriginalVector.begin();
1613 std::vector<Entry*>::const_iterator vdciteE = ExtraEntryList().begin();
1614 for (vdite = ExtraEntryValueList().begin(); vdite != ExtraEntryValueList().end();
1615 ++vdite, ++vdite_o, ++vdcite_oo, ++vdciteE) {
1616 (*vdite) = (*vdcite_oo);
1617 (*vdite_o) = (*vdcite_oo);
1618 (*vdciteE)->addFittedDisplacementToValue(-(*vdciteE)->valueDisplacementByFitting());
1619
1620
1621
1622 }
1623
1624
1625
1626
1627
1628
1629
1630 calculateLocalRotationAxisInGlobal();
1631
1632
1633 std::vector<OpticalObject*> vopto;
1634 Model::getComponentOptOs(name(), vopto);
1635 std::vector<OpticalObject*>::const_iterator vocite;
1636 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1637 (*vocite)->resetOriginalOriginalCoordinates();
1638 }
1639 }
1640
1641
1642
1643
1644 OpticalObject::~OpticalObject() {}
1645
1646
1647
1648
1649 const ALIstring OpticalObject::shortName() const {
1650 ALIint last_slash = name().rfind('/');
1651 ALIstring sname = name().substr(last_slash + 1, name().size() - 1);
1652 if (last_slash == -1) {
1653 sname = name();
1654 } else {
1655 sname = name().substr(last_slash + 1, name().size() - 1);
1656 }
1657 return sname;
1658 }
1659
1660
1661 std::ostream& operator<<(std::ostream& os, const OpticalObject& c) {
1662 os << "OPTICALOBJECT: " << c.theName << " of type: " << c.theType << " " << c.theCentreGlob << c.theRmGlob
1663 << std::endl;
1664
1665 return os;
1666 }
1667
1668
1669 const CLHEP::HepRotation OpticalObject::rmLocal() const {
1670 CLHEP::HepRotation rm;
1671 rm.rotateX(theCoordinateEntryVector[3]->value());
1672 rm.rotateY(theCoordinateEntryVector[4]->value());
1673 rm.rotateZ(theCoordinateEntryVector[5]->value());
1674
1675 return rm;
1676 }
1677
1678
1679 std::vector<double> OpticalObject::getLocalRotationAngles(const std::vector<Entry*>& entries) const {
1680 return getRotationAnglesInOptOFrame(theParent, entries);
1681 }
1682
1683
1684 std::vector<double> OpticalObject::getRotationAnglesInOptOFrame(const OpticalObject* optoAncestor,
1685 const std::vector<Entry*>& entries) const {
1686 const CLHEP::HepRotation& rmParent = optoAncestor->rmGlob();
1687 CLHEP::HepRotation rmLocal = rmParent.inverse() * theRmGlob;
1688
1689
1690 if (theRmGlobOriginal != theRmGlob) {
1691 std::cerr << " !!!FATAL ERROR: OpticalObject::getRotationAnglesInOptOFrame theRmGlobOriginal != theRmGlob "
1692 << std::endl;
1693 ALIUtils::dumprm(theRmGlobOriginal, " theRmGlobOriginal ");
1694 ALIUtils::dumprm(theRmGlob, " theRmGlob ");
1695 exit(1);
1696 }
1697
1698 if (ALIUtils::debug >= 5) {
1699 std::cout << " OpticalObject::getRotationAnglesInOptOFrame " << name() << " optoAncestor " << optoAncestor->name()
1700 << std::endl;
1701 ALIUtils::dumprm(rmParent, " rm parent ");
1702 ALIUtils::dumprm(rmLocal, " rm local ");
1703 ALIUtils::dumprm(theRmGlobOriginal, " theRmGlobOriginal ");
1704 ALIUtils::dumprm(theRmGlob, " theRmGlob ");
1705 }
1706 return getRotationAnglesFromMatrix(rmLocal, entries);
1707 }
1708
1709
1710 std::vector<double> OpticalObject::getRotationAnglesFromMatrix(CLHEP::HepRotation& rmLocal,
1711 const std::vector<Entry*>& entries) const {
1712 std::vector<double> newang(3);
1713 double angleX = entries[3]->value() + entries[3]->valueDisplacementByFitting();
1714 double angleY = entries[4]->value() + entries[4]->valueDisplacementByFitting();
1715 double angleZ = entries[5]->value() + entries[5]->valueDisplacementByFitting();
1716 if (ALIUtils::debug >= 5) {
1717 std::cout << " angles as value entries: X= " << angleX << " Y= " << angleY << " Z " << angleZ << std::endl;
1718 }
1719 return ALIUtils::getRotationAnglesFromMatrix(rmLocal, angleX, angleY, angleZ);
1720 }
1721
1722
1723 void OpticalObject::calculateLocalRotationAxisInGlobal() {
1724 axisXLocalInGlobal = CLHEP::Hep3Vector(1., 0., 0.);
1725 axisXLocalInGlobal *= theRmGlob;
1726 axisYLocalInGlobal = CLHEP::Hep3Vector(0., 1., 0.);
1727 axisYLocalInGlobal *= theRmGlob;
1728 axisZLocalInGlobal = CLHEP::Hep3Vector(0., 0., 1.);
1729 axisZLocalInGlobal *= theRmGlob;
1730 if (ALIUtils::debug >= 4) {
1731 std::cout << name() << " axis X local in global " << axisXLocalInGlobal << std::endl;
1732 std::cout << name() << " axis Y local in global " << axisYLocalInGlobal << std::endl;
1733 std::cout << name() << " axis Z local in global " << axisZLocalInGlobal << std::endl;
1734 }
1735 }
1736
1737
1738 template <class T>
1739 void OpticalObject::rotateItAroundGlobal(T& object, const XYZcoor coor, const double disp) {
1740 switch (coor) {
1741 case 0:
1742 object.rotateX(disp);
1743 break;
1744 case 1:
1745 object.rotateY(disp);
1746 break;
1747 case 2:
1748 object.rotateZ(disp);
1749 break;
1750 }
1751
1752
1753 if (ALIUtils::debug >= 5)
1754 std::cout << " rotateItAroundGlobal coor " << coor << " disp " << disp << std::endl;
1755 }
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800 double OpticalObject::diff2pi(double ang1, double ang2) {
1801 double diff = fabs(ang1 - ang2);
1802 diff = diff - int(diff / 2. / M_PI) * 2 * M_PI;
1803 return diff;
1804 }
1805
1806
1807 bool OpticalObject::eq2ang(double ang1, double ang2) {
1808 bool beq = true;
1809
1810 double diff = diff2pi(ang1, ang2);
1811 if (diff > 0.00001) {
1812 if (fabs(diff - 2 * M_PI) > 0.00001) {
1813
1814 beq = false;
1815 }
1816 }
1817
1818 return beq;
1819 }
1820
1821
1822 double OpticalObject::approxTo0(double val) {
1823 double precision = 1.e-9;
1824 if (fabs(val) < precision)
1825 val = 0;
1826 return val;
1827 }
1828
1829
1830 double OpticalObject::addPii(double val) {
1831 if (val < M_PI) {
1832 val += M_PI;
1833 } else {
1834 val -= M_PI;
1835 }
1836
1837 return val;
1838 }
1839
1840
1841 int OpticalObject::checkMatrixEquations(double angleX, double angleY, double angleZ, CLHEP::HepRotation* rot) {
1842
1843 if (rot == nullptr) {
1844 rot = new CLHEP::HepRotation();
1845 rot->rotateX(angleX);
1846 rot->rotateY(angleY);
1847 rot->rotateZ(angleZ);
1848 }
1849 double sx = sin(angleX);
1850 double cx = cos(angleX);
1851 double sy = sin(angleY);
1852 double cy = cos(angleY);
1853 double sz = sin(angleZ);
1854 double cz = cos(angleZ);
1855
1856 double rotxx = cy * cz;
1857 double rotxy = sx * sy * cz - cx * sz;
1858 double rotxz = cx * sy * cz + sx * sz;
1859 double rotyx = cy * sz;
1860 double rotyy = sx * sy * sz + cx * cz;
1861 double rotyz = cx * sy * sz - sx * cz;
1862 double rotzx = -sy;
1863 double rotzy = sx * cy;
1864 double rotzz = cx * cy;
1865
1866 int matrixElemBad = 0;
1867 if (!eq2ang(rot->xx(), rotxx)) {
1868 std::cerr << " EQUATION for xx() IS BAD " << rot->xx() << " <> " << rotxx << std::endl;
1869 matrixElemBad++;
1870 }
1871 if (!eq2ang(rot->xy(), rotxy)) {
1872 std::cerr << " EQUATION for xy() IS BAD " << rot->xy() << " <> " << rotxy << std::endl;
1873 matrixElemBad++;
1874 }
1875 if (!eq2ang(rot->xz(), rotxz)) {
1876 std::cerr << " EQUATION for xz() IS BAD " << rot->xz() << " <> " << rotxz << std::endl;
1877 matrixElemBad++;
1878 }
1879 if (!eq2ang(rot->yx(), rotyx)) {
1880 std::cerr << " EQUATION for yx() IS BAD " << rot->yx() << " <> " << rotyx << std::endl;
1881 matrixElemBad++;
1882 }
1883 if (!eq2ang(rot->yy(), rotyy)) {
1884 std::cerr << " EQUATION for yy() IS BAD " << rot->yy() << " <> " << rotyy << std::endl;
1885 matrixElemBad++;
1886 }
1887 if (!eq2ang(rot->yz(), rotyz)) {
1888 std::cerr << " EQUATION for yz() IS BAD " << rot->yz() << " <> " << rotyz << std::endl;
1889 matrixElemBad++;
1890 }
1891 if (!eq2ang(rot->zx(), rotzx)) {
1892 std::cerr << " EQUATION for zx() IS BAD " << rot->zx() << " <> " << rotzx << std::endl;
1893 matrixElemBad++;
1894 }
1895 if (!eq2ang(rot->zy(), rotzy)) {
1896 std::cerr << " EQUATION for zy() IS BAD " << rot->zy() << " <> " << rotzy << std::endl;
1897 matrixElemBad++;
1898 }
1899 if (!eq2ang(rot->zz(), rotzz)) {
1900 std::cerr << " EQUATION for zz() IS BAD " << rot->zz() << " <> " << rotzz << std::endl;
1901 matrixElemBad++;
1902 }
1903
1904
1905 return matrixElemBad;
1906 }
1907
1908
1909 CLHEP::Hep3Vector OpticalObject::getDispVec(const XYZcoor coor, const ALIdouble disp) {
1910 CLHEP::Hep3Vector dispVec;
1911 switch (coor) {
1912 case 0:
1913 dispVec = CLHEP::Hep3Vector(disp, 0., 0.);
1914 break;
1915 case 1:
1916 dispVec = CLHEP::Hep3Vector(0., disp, 0.);
1917 break;
1918 case 2:
1919 dispVec = CLHEP::Hep3Vector(0., 0., disp);
1920 break;
1921 default:
1922 break;
1923 }
1924
1925 if (ALIUtils::debug >= 5) {
1926 ALIUtils::dump3v(dispVec, " dispVec in local ");
1927 CLHEP::HepRotation rmt = parent()->rmGlob();
1928 ALIUtils::dumprm(rmt, "parent rmGlob ");
1929 }
1930 dispVec = parent()->rmGlob() * dispVec;
1931 if (ALIUtils::debug >= 5)
1932 ALIUtils::dump3v(dispVec, " dispVec in global ");
1933
1934 return dispVec;
1935 }
1936
1937
1938 const CLHEP::Hep3Vector OpticalObject::centreLocal() const {
1939 CLHEP::Hep3Vector cLocal = theCentreGlob - parent()->centreGlob();
1940 CLHEP::HepRotation rmParentInv = inverseOf(parent()->rmGlob());
1941 cLocal = rmParentInv * cLocal;
1942
1943 return cLocal;
1944
1945
1946
1947
1948
1949
1950
1951
1952 }
1953
1954
1955 const double OpticalObject::getEntryCentre(const XYZcoor coor) const {
1956 Entry* ce = theCoordinateEntryVector[coor];
1957
1958 return ce->value() + ce->valueDisplacementByFitting();
1959 }
1960
1961
1962 const double OpticalObject::getEntryCentre(const ALIstring& coorstr) const {
1963 XYZcoor coor = XCoor;
1964 if (coorstr == "X") {
1965 coor = XCoor;
1966 } else if (coorstr == "Y") {
1967 coor = YCoor;
1968 } else if (coorstr == "Z") {
1969 coor = ZCoor;
1970 }
1971 Entry* ce = theCoordinateEntryVector[coor];
1972
1973 return ce->value() + ce->valueDisplacementByFitting();
1974 }
1975
1976
1977 const double OpticalObject::getEntryRMangle(const XYZcoor coor) const {
1978 Entry* ce = theCoordinateEntryVector[coor + 3];
1979
1980
1981 return ce->value() + ce->valueDisplacementByFitting();
1982 }
1983
1984
1985 const double OpticalObject::getEntryRMangle(const ALIstring& coorstr) const {
1986 XYZcoor coor = XCoor;
1987 if (coorstr == "X") {
1988 coor = XCoor;
1989 } else if (coorstr == "Y") {
1990 coor = YCoor;
1991 } else if (coorstr == "Z") {
1992 coor = ZCoor;
1993 }
1994 Entry* ce = theCoordinateEntryVector[coor + 3];
1995
1996
1997 return ce->value() + ce->valueDisplacementByFitting();
1998 }
1999
2000
2001 void OpticalObject::constructMaterial() {
2002 theMaterial = new CocoaMaterialElementary("Hydrogen", 70.8 * CLHEP::mg / CLHEP::cm3, "H", 1.00794f, 1);
2003 }
2004
2005
2006 void OpticalObject::constructSolidShape() {
2007 ALIdouble go;
2008 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
2009 gomgr->getGlobalOptionValue("VisScale", go);
2010
2011 theSolidShape = new CocoaSolidShapeBox("Box",
2012 go * 5. * CLHEP::cm / CLHEP::m,
2013 go * 5. * CLHEP::cm / CLHEP::m,
2014 go * 5. * CLHEP::cm / CLHEP::m);
2015 }
2016
2017
2018 void OpticalObject::constructFromOptAligInfo(const OpticalAlignInfo& oaInfo) {
2019 if (theParent != nullptr) {
2020
2021
2022 std::vector<OpticalAlignParam> exEnt = oaInfo.extraEntries_;
2023 std::vector<OpticalAlignParam>::iterator ite;
2024 std::vector<ALIstring> wordlist;
2025 for (ite = exEnt.begin(); ite != exEnt.end(); ++ite) {
2026 wordlist = getCoordinateFromOptAlignParam(*ite);
2027 wordlist.insert(wordlist.begin(), (*ite).dimType());
2028 fillExtraEntry(wordlist);
2029 }
2030
2031
2032 centreIsGlobal = false;
2033 anglesIsGlobal = false;
2034
2035 setCmsswID(oaInfo.ID_);
2036
2037 fillCoordinateEntry("centre", getCoordinateFromOptAlignParam(oaInfo.x_));
2038 fillCoordinateEntry("centre", getCoordinateFromOptAlignParam(oaInfo.y_));
2039 fillCoordinateEntry("centre", getCoordinateFromOptAlignParam(oaInfo.z_));
2040 fillCoordinateEntry("angles", getCoordinateFromOptAlignParam(oaInfo.angx_));
2041 fillCoordinateEntry("angles", getCoordinateFromOptAlignParam(oaInfo.angy_));
2042 fillCoordinateEntry("angles", getCoordinateFromOptAlignParam(oaInfo.angz_));
2043
2044
2045 setGlobalCoordinates();
2046
2047
2048 setOriginalEntryValues();
2049 }
2050
2051
2052 constructMaterial();
2053
2054
2055 constructSolidShape();
2056
2057 if (ALIUtils::debug >= 5) {
2058 std::cout << "constructFromOptAligInfo constructed: " << *this << std::endl;
2059 }
2060
2061
2062 createComponentOptOsFromOptAlignInfo();
2063 }
2064
2065
2066 std::vector<ALIstring> OpticalObject::getCoordinateFromOptAlignParam(const OpticalAlignParam& oaParam) {
2067 char chartmp[20];
2068 std::vector<ALIstring> wordlist;
2069 wordlist.push_back(oaParam.name());
2070 gcvt(oaParam.value(), 10, chartmp);
2071 wordlist.push_back(chartmp);
2072 gcvt(oaParam.sigma(), 10, chartmp);
2073 wordlist.push_back(chartmp);
2074 if (oaParam.quality() == 0) {
2075 wordlist.push_back("fix");
2076 } else if (oaParam.quality() == 1) {
2077 wordlist.push_back("cal");
2078 } else if (oaParam.quality() == 2) {
2079 wordlist.push_back("unk");
2080 }
2081
2082 if (ALIUtils::debug >= 5) {
2083 ALIUtils::dumpVS(wordlist, " getCoordinateFromOptAlignParam " + oaParam.name());
2084 }
2085
2086 return wordlist;
2087 }
2088
2089
2090 void OpticalObject::createComponentOptOsFromOptAlignInfo() {
2091
2092 std::vector<OpticalAlignInfo> children;
2093
2094 std::vector<OpticalAlignInfo>::const_iterator ite;
2095 if (ALIUtils::debug >= 5) {
2096 std::cout << " Model::getOpticalAlignments().size " << Model::getOpticalAlignments().size() << std::endl;
2097 }
2098
2099 int siz = Model::getOpticalAlignments().size();
2100 for (int ii = 0; ii < siz; ii++) {
2101
2102
2103
2104
2105 if (Model::getOpticalAlignments()[ii].parentName_ == theName) {
2106
2107
2108
2109 std::vector<OpticalAlignParam> exent = Model::getOpticalAlignments()[ii].extraEntries_;
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120 OpticalAlignInfo oaInfochild = Model::getOpticalAlignments()[ii];
2121
2122
2123 children.push_back(oaInfochild);
2124 if (ALIUtils::debug >= 5) {
2125 std::cout << theName << "createComponentOptOsFromOptAlignInfo: children added " << oaInfochild.name_
2126 << std::endl;
2127 }
2128 }
2129
2130 }
2131
2132
2133 if (ALIUtils::debug >= 5) {
2134 std::cout << "OpticalObject::createComponentsFromAlignInfo: N components = " << children.size() << std::endl;
2135 }
2136 for (ite = children.begin(); ite != children.end(); ++ite) {
2137
2138 ALIstring optoType = (*ite).type_;
2139
2140
2141
2142 ALIstring optoName = (*ite).name_;
2143 ALIbool fcopyComponents = false;
2144
2145
2146 OpticalObject* OptOcomponent = createNewOptO(this, optoType, optoName, fcopyComponents);
2147
2148
2149 OptOcomponent->constructFromOptAligInfo(*ite);
2150
2151
2152 Model::OptOList().push_back(OptOcomponent);
2153 }
2154 }