00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 using namespace std;
00015
00016 #include <string>
00017 #include <fstream>
00018 #include <iostream>
00019 #include <sstream>
00020 #include <vector>
00021 #include <iomanip>
00022
00023 #include <TGeoManager.h>
00024 #include <TGeoArb8.h>
00025 #include <TMath.h>
00026
00027 #include "BesVisLib/EmcROOTGeo.h"
00028 #include "Identifier/EmcID.h"
00029 #include "BesVisLib/BesEvent.h"
00030 #include "BesVisLib/BesView.h"
00031 #include "RawEvent/RawDataUtil.h"
00032
00033
00034 EmcROOTGeo::EmcROOTGeo()
00035 : SubDetectorROOTGeo()
00036 {
00037
00038 m_kPhiEc = 96;
00039 m_kThetaEc = 6;
00040 m_kSectorEc = 16;
00041 m_kNbEc = 35;
00042 m_kRealNbEc = 30;
00043
00044 for (int part = 0; part < m_kPart; part++) {
00045 for (int phi = 0; phi < m_kPhiBr; phi++) {
00046 m_NodePhi[part][phi] = 0;
00047 for (int theta = 0; theta < m_kThetaBr; theta++) {
00048 m_NodeTheta[part][phi][theta] = 0;
00049 m_NodeTheta2[part][phi][theta] = 0;
00050 m_PhysicalCrystal[part][phi][theta] = 0;
00051 m_PhysicalCrystal2[part][phi][theta] = 0;
00052 m_Emc2DCrystal[part][phi][theta] = 0;
00053 }
00054 }
00055 }
00056 m_PhyNodeOrgArray = new TObjArray();
00057
00058 m_EmcColor = 4;
00059 m_partColor = 4;
00060 m_phiColor = 4;
00061 m_thetaColor = 4;
00062 m_brCrystalColor = 4;
00063 m_ecCrystalColor = 7;
00064 }
00065
00066 EmcROOTGeo::~EmcROOTGeo()
00067 { }
00068
00069 void
00070 EmcROOTGeo::InitFromGDML( const char *gdmlFile, const char *setupName )
00071 {
00072 m_ROOTGeoInit = 2;
00073
00074 ReadGdml(gdmlFile, setupName);
00075 SetNode();
00076 }
00077
00078 void
00079 EmcROOTGeo::InitFromROOT( TGeoVolume *vol )
00080 {
00081 m_ROOTGeoInit = 1;
00082
00083 SetVolumeEmc(vol);
00084 SetNode();
00085 }
00086
00087 void
00088 EmcROOTGeo::Init2DGeometry()
00089 {
00090 if (m_ROOTGeoInit != 1 && m_ROOTGeoInit != 2) {
00091 cout << "EmcROOTGeo::Init2DGeometry, ROOT Geometry not Initialized yet!" << endl;
00092 return;
00093 }
00094 m_2DGeoInit = 1;
00095
00096 Double_t local[3] = {0.0, 0.0, 0.0};
00097 Double_t master[3] = {0.0, 0.0, 0.0};
00098
00099
00100
00101 TString name;
00102 TString title;
00103
00104
00105 for (int part = 0; part < GetPartNb(); part++) {
00106 for (int theta = 0; theta < GetThetaNb(part); theta++) {
00107 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
00108 TGeoPhysicalNode *phyNode = 0;
00109 phyNode = GetPhysicalCrystal(part, phi, theta);
00110 if (part == 1) name = TString("Barrel");
00111 else {
00112 if (part == 0) name = TString("EastEc");
00113 else if (part == 2) name = TString("WestEc");
00114 }
00115 name = TString("Emc Part");
00116 name += part;
00117 name += " Theta";
00118 if (part == 1) name += m_kThetaBr - 1 - theta;
00119 else name += theta;
00120 name += " Phi";
00121 name += phi;
00122
00123 char data[100];
00124 sprintf(data, "Emc part %i, #theta %i, #phi %i", part, theta, phi);
00125 title = TString( data );
00126
00127 TGeoArb8 *crystalShape = (TGeoArb8*)phyNode->GetShape();
00128 Double_t *localArb8Point, masterArb8Point[24*2];
00129 localArb8Point = crystalShape->GetVertices();
00130 for (Int_t i = 0; i < 8; i++) {
00131 local[0] = localArb8Point[2*i];
00132 local[1] = localArb8Point[2*i+1];
00133 if (i < 4) local[2] = crystalShape->GetDz() * (-1.0);
00134 else local[2] = crystalShape->GetDz();
00135
00136 phyNode->GetMatrix(-1*phyNode->GetLevel())->LocalToMaster(local, &master[0]);
00137
00138 for (Int_t j = 0; j < 3; j++) {
00139 masterArb8Point[3*i+j] = master[j];
00140 }
00141 }
00142
00143 TGeoPhysicalNode *phyNode2 = 0;
00144 phyNode2 = GetPhysicalCrystal2(part, phi, theta);
00145 if (phyNode2 != 0) {
00146 crystalShape = (TGeoArb8*)phyNode2->GetShape();
00147 localArb8Point = crystalShape->GetVertices();
00148 for (Int_t i = 0; i < 8; i++) {
00149 local[0] = localArb8Point[2*i];
00150 local[1] = localArb8Point[2*i+1];
00151 if (i < 4) local[2] = crystalShape->GetDz() * (-1.0);
00152 else local[2] = crystalShape->GetDz();
00153 phyNode2->GetMatrix(-1*phyNode->GetLevel())
00154 ->LocalToMaster(local, &master[0]);
00155 for (Int_t j = 0; j < 3; j++) {
00156 masterArb8Point[24+3*i+j] = master[j];
00157 }
00158 }
00159 }
00160
00161 if (phyNode2 == 0)
00162 m_Emc2DCrystal[part][phi][theta] =
00163 new Emc2DCrystal(name, title, 8, &masterArb8Point[0], part, theta);
00164 else
00165 m_Emc2DCrystal[part][phi][theta] =
00166 new Emc2DCrystal(name, title, 16, &masterArb8Point[0], part, theta);
00167 }
00168 }
00169 }
00170 }
00171
00172 void
00173 EmcROOTGeo::SetNode()
00174 {
00175
00176 if (m_ROOTGeoInit == 2) {
00177
00178 m_Emc = GetTopVolume();
00179 if (!m_Emc) std::cout << "m_Emc = 0" << std::endl;
00180
00181 }
00182 else if (m_ROOTGeoInit == 1) {
00183
00184 for (int part = 0; part < m_kPart; part++) {
00185 int ipart = 0;
00186 if (part == 1) ipart = 2;
00187 if (part == 0) ipart = 1;
00188
00189 m_NodePart[part] = m_Emc->GetNode(ipart);
00190
00191 if (part == 1) {
00192 for (int phi = 0; phi < m_kPhiBr; phi++) {
00193 int iphi = 0;
00194 iphi = 308 - phi;
00195
00196 m_NodePhi[part][phi] = GetPart(part)->GetVolume()->GetNode(iphi);
00197 }
00198 }
00199 else {
00200 int endphilist[16]= {15,7,14,6,13,12,11,10,9,8,5,4,3,2,1,0};
00201 int endphipos[16] = {15,14,13,12,11,10,3,1,9,8,7,6,5,4,2,0};
00202
00203 for (int sector = 0; sector < m_kSectorEc; sector++) {
00204 m_NodePhi[part][sector] =
00205 GetPart(part)->GetVolume()->GetNode(endphipos[sector]);
00206 }
00207 }
00208 }
00209 }
00210
00211
00212 for (int phi = 0; phi < m_kPhiBr; phi++) {
00213 int theta=0;
00214 for (int idaughter = 0; idaughter< GetPhi(1, phi)->GetNdaughters(); idaughter++) {
00215 TString name = GetPhi(1, phi)->GetDaughter(idaughter)->GetName();
00216 if (name.Contains("logicalBSCCasing")){
00217
00218 m_NodeTheta[1][phi][theta] = GetPhi(1, phi)->GetDaughter(idaughter);
00219 theta++;
00220 }
00221 }
00222 }
00223
00224 for (int part = 0; part < m_kPart; part++) {
00225 if (part == 1) continue;
00226 for (int sector = 0; sector < m_kSectorEc; sector++) {
00227 for (int nb = 0; nb < m_kNbEc; nb++) {
00228 int theta, phi;
00229 if (nb < m_kRealNbEc) {
00230 ComputeThetaPhi(part, sector, nb, theta, phi);
00231 m_NodeTheta[part][phi][theta] = GetPhi(part, sector)->GetDaughter(nb);
00232
00233
00234
00235 }
00236 else {
00237 ComputeThetaPhi(part, sector, ComputeEndCopyNb(nb), theta, phi);
00238 m_NodeTheta2[part][phi][theta] = GetPhi(part, sector)->GetDaughter(nb);
00239
00240
00241
00242 }
00243 }
00244 }
00245 }
00246
00247
00248 }
00249
00250 void
00251 EmcROOTGeo::SetVolumeAppendInVis()
00252 {
00253
00254
00255
00256
00257 TGeoVolume *logicRear,*logicOrgGlass,*logicRearCasing,*logicAlPlate,*logicPD,*logicPreAmpBox,*logicAirInPABox,*logicHangingPlate,*logicWaterPipe;
00258 TGeoVolume *logicCable,*logicOCGirder,*logicSupportBar,*logicSupportBar1,*logicEndRing,*logicGear,*logicTaperRing1,*logicTaperRing2,*logicTaperRing3;
00259
00260
00261 logicRear = GetLogicalVolume("logicalRearBox");
00262 logicOrgGlass = GetLogicalVolume("logicalOrganicGlass");
00263 logicRearCasing = GetLogicalVolume("logicalRearCasing");
00264 logicAlPlate = GetLogicalVolume("logicalAlPlate");
00265 logicPD = GetLogicalVolume("logicalPD");
00266 logicPreAmpBox = GetLogicalVolume("logicalPreAmpBox");
00267 logicAirInPABox = GetLogicalVolume("logicalAirInPABox");
00268 logicHangingPlate = GetLogicalVolume("logicalHangingPlate");
00269 logicWaterPipe = GetLogicalVolume("logicalWaterPipe");
00270
00271 for (int i = 0; i < 44; i++){
00272
00273 std::ostringstream osnameBSCCable1;
00274 osnameBSCCable1 << "logicalBSCCable_1_"<<i;
00275 logicCable = GetLogicalVolume( osnameBSCCable1.str() );
00276 if (logicCable)
00277 logicCable->SetVisibility(0);
00278
00279 std::ostringstream osnameBSCCable2;
00280 osnameBSCCable2 << "logicalBSCCable_2_"<<i;
00281 logicCable = GetLogicalVolume( osnameBSCCable2.str() );
00282 if (logicCable)
00283 logicCable->SetVisibility(0);
00284
00285 std::ostringstream osnameOCGirder1;
00286 osnameOCGirder1 <<"logicalOpenningCutGirder_1_"<<i;
00287 logicOCGirder = GetLogicalVolume( osnameOCGirder1.str() );
00288 if (logicOCGirder)
00289 logicOCGirder->SetVisibility(0);
00290
00291 std::ostringstream osnameOCGirder2;
00292 osnameOCGirder2 <<"logicalOpenningCutGirder_2_"<<i;
00293 logicOCGirder = GetLogicalVolume( osnameOCGirder2.str() );
00294 if (logicOCGirder)
00295 logicOCGirder->SetVisibility(0);
00296
00297 std::ostringstream osnameOCGirder3;
00298 osnameOCGirder3 <<"logicalOpenningCutGirder_3_"<<i;
00299 logicOCGirder = GetLogicalVolume( osnameOCGirder3.str() );
00300 if (logicOCGirder)
00301 logicOCGirder->SetVisibility(0);
00302
00303 std::ostringstream osnameOCGirder4;
00304 osnameOCGirder4 <<"logicalOpenningCutGirder_4_"<<i;
00305 logicOCGirder = GetLogicalVolume( osnameOCGirder4.str() );
00306 if (logicOCGirder)
00307 logicOCGirder->SetVisibility(0);
00308 }
00309
00310
00311
00312 logicSupportBar = GetLogicalVolume("logicalSupportBar0");
00313 logicSupportBar1 = GetLogicalVolume("logicalSupportBar1");
00314 logicEndRing = GetLogicalVolume("logicalEndRing");
00315 logicGear = GetLogicalVolume("logicalGear");
00316 logicTaperRing1 = GetLogicalVolume("logicalTaperRing1");
00317 logicTaperRing2 = GetLogicalVolume("logicalTaperRing2");
00318 logicTaperRing3 = GetLogicalVolume("logicalTaperRing3");
00319
00320 if (logicRear)
00321 logicRear->SetVisibility(0);
00322 if (logicOrgGlass)
00323 logicOrgGlass->SetVisibility(0);
00324 if (logicRearCasing)
00325 logicRearCasing->SetVisibility(0);
00326 if (logicAlPlate)
00327 logicAlPlate->SetVisibility(0);
00328 if (logicPD)
00329 logicPD->SetVisibility(0);
00330 if (logicPreAmpBox)
00331 logicPreAmpBox->SetVisibility(0);
00332 if (logicAirInPABox)
00333 logicAirInPABox->SetVisibility(0);
00334 if (logicHangingPlate)
00335 logicHangingPlate->SetVisibility(0);
00336 if (logicWaterPipe)
00337 logicWaterPipe->SetVisibility(0);
00338 if (logicGear)
00339 logicGear->SetVisibility(0);
00340 if (logicTaperRing1)
00341 logicTaperRing1->SetVisibility(0);
00342 if (logicTaperRing2)
00343 logicTaperRing2->SetVisibility(0);
00344 if (logicTaperRing3)
00345 logicTaperRing3->SetVisibility(0);
00346 if (logicSupportBar)
00347 logicSupportBar->SetVisibility(0);
00348 if (logicSupportBar1)
00349 logicSupportBar1->SetVisibility(0);
00350 if (logicEndRing)
00351 logicEndRing->SetVisibility(0);
00352 }
00353
00354 void
00355 EmcROOTGeo::SetVolumeDefaultVis()
00356 {
00357
00358 SetVolumeAppendInVis();
00359
00360
00361
00362 m_Emc->SetLineColor(m_EmcColor);
00363 m_Emc->SetVisibility(0);
00364
00365 for (int part = 0; part < m_kPart-1; part++) {
00366 GetVolumePart(part)->SetLineColor(m_partColor);
00367 int nPhi = (part == 1 ? m_kPhiBr : m_kSectorEc);
00368 for (int phi = 0; phi < nPhi; phi++) {
00369 GetVolumePhi(part, phi)->SetLineColor(m_phiColor);
00370 GetVolumePhi(part, phi)->SetVisibility(0);
00371 }
00372 if (part == 1) {
00373 for (int theta = 0; theta < m_kThetaBr; theta++) {
00374 GetVolumeTheta(part, 0, theta)->SetLineColor(m_thetaColor);
00375 GetVolumeTheta(part, 0, theta)->SetVisibility(0);
00376 GetVolumeCrystal(part, 0, theta)->SetLineColor(m_brCrystalColor);
00377 GetVolumeCrystal(part, 0, theta)->SetVisibility(0);
00378 }
00379 }
00380 else if (part == 0) {
00381 int iPhi[3] = {0,1,2};
00382 for (int i = 0; i < 3; i++) {
00383 int phi = iPhi[i];
00384 int nTheta = (part == 1 ? m_kThetaBr : m_kNbEc);
00385 for (int theta = 0; theta < nTheta; theta++) {
00386 GetVolumeTheta(part, phi, theta)->SetLineColor(m_thetaColor);
00387 GetVolumeTheta(part, phi, theta)->SetVisibility(0);
00388 GetVolumeCrystal(part, phi, theta)->SetLineColor(m_ecCrystalColor);
00389 GetVolumeCrystal(part, phi, theta)->SetVisibility(0);
00390 }
00391 }
00392 }
00393 }
00394
00395
00396 for (int part = 0; part < m_kPart; part++) {
00397 GetPart(part)->SetVisibility(0);
00398 int nPhi = (part == 1 ? m_kPhiBr : m_kSectorEc);
00399 for (int phi = 0; phi < nPhi; phi++) {
00400 GetPhi(part, phi)->SetVisibility(0);
00401 }
00402 }
00403
00404
00405 for (int part = 0; part < m_kPart; part++) {
00406 for (int theta = 0; theta < GetThetaNb(part); theta++) {
00407 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
00408
00409 TGeoNode *nodeTheta = GetTheta(part, phi, theta);
00410 if (nodeTheta) nodeTheta->SetVisibility(0);
00411 TGeoNode *nodeCrystal = GetCrystal(part, phi, theta);
00412 if (nodeCrystal) nodeCrystal->SetVisibility(0);
00413
00414 TGeoNode *nodeTheta2 = GetTheta2(part, phi, theta);
00415 if (nodeTheta2) nodeTheta2->SetVisibility(0);
00416 TGeoNode *nodeCrystal2 = GetCrystal2(part, phi, theta);
00417 if (nodeCrystal2) nodeCrystal2->SetVisibility(0);
00418 }
00419 }
00420 }
00421
00422
00423 }
00424
00425 void
00426 EmcROOTGeo::SetAllVisible()
00427 {
00428
00429 SetVolumeAppendInVis();
00430
00431
00432
00433 m_Emc->SetLineColor(m_EmcColor);
00434 m_Emc->SetVisibility(0);
00435
00436 for (int part = 0; part < m_kPart-1; part++) {
00437 GetVolumePart(part)->SetLineColor(m_partColor);
00438 int nPhi = (part == 1 ? m_kPhiBr : m_kSectorEc);
00439 for (int phi = 0; phi < nPhi; phi++) {
00440 GetVolumePhi(part, phi)->SetLineColor(m_phiColor);
00441 GetVolumePhi(part, phi)->SetVisibility(1);
00442 }
00443 if (part == 1) {
00444 for (int theta = 0; theta < m_kThetaBr; theta++) {
00445 GetVolumeTheta(part, 0, theta)->SetLineColor(m_thetaColor);
00446 GetVolumeTheta(part, 0, theta)->SetVisibility(1);
00447 GetVolumeCrystal(part, 0, theta)->SetLineColor(m_brCrystalColor);
00448 GetVolumeCrystal(part, 0, theta)->SetVisibility(1);
00449 }
00450 }
00451 else if (part == 0) {
00452 int iPhi[3] = {0,1,2};
00453 for (int i = 0; i < 3; i++) {
00454 int phi = iPhi[i];
00455 int nTheta = (part == 1 ? m_kThetaBr : m_kNbEc);
00456 for (int theta = 0; theta < nTheta; theta++) {
00457 GetVolumeTheta(part, phi, theta)->SetLineColor(m_thetaColor);
00458 GetVolumeTheta(part, phi, theta)->SetVisibility(1);
00459 GetVolumeCrystal(part, phi, theta)->SetLineColor(m_ecCrystalColor);
00460 GetVolumeCrystal(part, phi, theta)->SetVisibility(1);
00461 }
00462 }
00463 }
00464 }
00465
00466
00467 for (int part = 0; part < m_kPart; part++) {
00468 GetPart(part)->SetVisibility(1);
00469 int nPhi = (part == 1 ? m_kPhiBr : m_kSectorEc);
00470 for (int phi = 0; phi < nPhi; phi++) {
00471 GetPhi(part, phi)->SetVisibility(1);
00472 }
00473 }
00474
00475
00476 for (int part = 0; part < m_kPart; part++) {
00477 for (int theta = 0; theta < GetThetaNb(part); theta++) {
00478 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
00479
00480 TGeoNode *nodeTheta = GetTheta(part, phi, theta);
00481 if (nodeTheta) nodeTheta->SetVisibility(1);
00482 TGeoNode *nodeCrystal = GetCrystal(part, phi, theta);
00483 if (nodeCrystal) nodeCrystal->SetVisibility(1);
00484
00485 TGeoNode *nodeTheta2 = GetTheta2(part, phi, theta);
00486 if (nodeTheta2) nodeTheta2->SetVisibility(1);
00487 TGeoNode *nodeCrystal2 = GetCrystal2(part, phi, theta);
00488 if (nodeCrystal2) nodeCrystal2->SetVisibility(1);
00489 }
00490 }
00491 }
00492
00493
00494 }
00495
00496 void
00497 EmcROOTGeo::SetQuarterVisible()
00498 {
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541 }
00542
00543 void
00544 EmcROOTGeo::SetHalfVisible()
00545 {
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 }
00581
00582 void
00583 EmcROOTGeo::SetNoEndVisible()
00584 {
00585
00586
00587
00588
00589
00590
00591
00592 }
00593
00594 void
00595 EmcROOTGeo::SetPhysicalNode()
00596 {
00597 if (gGeoManager == 0) std::cout << "Create gGeoManager first" << std::endl;
00598 TGeoNode *bes = gGeoManager->GetTopNode();
00599 std::cout << "Emc m_childNo " << m_childNo << std::endl;
00600 TGeoNode *emc = bes->GetDaughter(2);
00601
00602
00603 int part = 1;
00604 TGeoNode *nodePart = GetPart(part);
00605 for (int phi = 0; phi < GetPhiNb(part, 0); phi++) {
00606 TGeoNode *nodePhi = GetPhi(part, phi);
00607 for (int theta = 0; theta < GetThetaNb(part); theta++) {
00608 TGeoNode *nodeTheta = GetTheta(part, phi, theta);
00609 TGeoNode *nodeCrystal = GetCrystal(part, phi, theta);
00610 m_PhysicalCrystal[part][phi][theta] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
00611 TString("/") + emc->GetName() +
00612 TString("/") + nodePart->GetName() +
00613 TString("/") + nodePhi->GetName() +
00614 TString("/") + nodeTheta->GetName() +
00615 TString("/") + nodeCrystal->GetName() );
00616 m_PhysicalCrystal[part][phi][theta]->SetVisibility(0);
00617 m_PhysicalCrystal[part][phi][theta]->SetIsVolAtt(kFALSE);
00618 m_PhysicalCrystal[part][phi][theta]->SetLineColor(m_brCrystalColor);
00619
00620 }
00621 }
00622
00623
00624 for (part = 0; part < m_kPart; part++) {
00625 if (part == 1) continue;
00626 nodePart = GetPart(part);
00627 for (int sector = 0; sector < m_kSectorEc; sector++) {
00628 TGeoNode *nodeSector = GetPhi(part, sector);
00629 for (int nb = 0; nb < m_kNbEc; nb++) {
00630 TGeoNode *nodeNb = nodeSector->GetDaughter(nb);
00631 TGeoNode *nodeCrystal = nodeNb->GetDaughter(0);
00632
00633 int theta, phi;
00634 if (nb < m_kRealNbEc) {
00635 ComputeThetaPhi(part, sector, nb, theta, phi);
00636 m_PhysicalCrystal[part][phi][theta] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
00637 TString("/") + emc->GetName() +
00638 TString("/") + nodePart->GetName() +
00639 TString("/") + nodeSector->GetName() +
00640 TString("/") + nodeNb->GetName() +
00641 TString("/") + nodeCrystal->GetName() );
00642 m_PhysicalCrystal[part][phi][theta]->SetVisibility(0);
00643 m_PhysicalCrystal[part][phi][theta]->SetIsVolAtt(kFALSE);
00644 m_PhysicalCrystal[part][phi][theta]->SetLineColor(m_ecCrystalColor);
00645
00646 }
00647 else {
00648 ComputeThetaPhi(part, sector, ComputeEndCopyNb(nb), theta, phi);
00649 m_PhysicalCrystal2[part][phi][theta] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
00650 TString("/") + emc->GetName() +
00651 TString("/") + nodePart->GetName() +
00652 TString("/") + nodeSector->GetName() +
00653 TString("/") + nodeNb->GetName() +
00654 TString("/") + nodeCrystal->GetName() );
00655 m_PhysicalCrystal2[part][phi][theta]->SetVisibility(0);
00656 m_PhysicalCrystal2[part][phi][theta]->SetIsVolAtt(kFALSE);
00657 m_PhysicalCrystal2[part][phi][theta]->SetLineColor(m_ecCrystalColor);
00658
00659 }
00660 }
00661 }
00662 }
00663
00664 SetDetector();
00665 }
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699 void
00700 EmcROOTGeo::SetDetector()
00701 {
00702 BesView *view = 0;
00703 if (gPad) view = (BesView*)gPad->GetView();
00704
00705
00706 m_DetectorsArray->Clear();
00707
00708
00709 int part = 1;
00710 for (int theta = 0; theta < GetThetaNb(part); theta++) {
00711 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
00712 TGeoPhysicalNode *phyNode = GetPhysicalCrystal(part, phi, theta);
00713 if (phyNode) {
00714 phyNode->SetVisibility(0);
00715 if ( phi >= 0 && phi < m_kPhiBr*4/4
00716
00717 ) {
00718 m_DetectorsArray->Add( phyNode );
00719 }
00720 else if (view && view->GetVisFull3DEmc()) {
00721 m_DetectorsArray->Add( phyNode );
00722 }
00723 }
00724 }
00725 }
00726
00727
00728 for (int part = 0; part < m_kPart; part++) {
00729 if (part == 1) continue;
00730 for (int theta = 0; theta < GetThetaNb(part); theta++) {
00731 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
00732 TGeoPhysicalNode *phyNode = GetPhysicalCrystal(part, phi, theta);
00733 if (phyNode) {
00734 phyNode->SetVisibility(0);
00735 if (part == 2 && phi <= GetPhiNb(part, theta)||
00736 part == 0 && phi <= GetPhiNb(part, theta) ) {
00737 m_DetectorsArray->Add( phyNode );
00738 }
00739 else if (view && view->GetVisFull3DEmc()) {
00740 m_DetectorsArray->Add( phyNode );
00741 }
00742 }
00743
00744 phyNode = 0;
00745 phyNode = GetPhysicalCrystal2(part, phi, theta);
00746 if (phyNode) {
00747 phyNode->SetVisibility(0);
00748 if (part == 2 && phi <= GetPhiNb(part, theta)||
00749 part == 0 && phi <= GetPhiNb(part, theta) ) {
00750 m_DetectorsArray->Add( phyNode );
00751 }
00752 else if (view && view->GetVisFull3DEmc()) {
00753 m_DetectorsArray->Add( phyNode );
00754 }
00755 }
00756 }
00757 }
00758 }
00759
00760
00761 }
00762
00763 void
00764 EmcROOTGeo::SetHits()
00765 {
00766
00767
00768
00769
00770 for (int i = 0; i < m_HitsArray->GetEntries(); i++) {
00771 TGeoPhysicalNode *phyNode = (TGeoPhysicalNode*)m_HitsArray->At(i);
00772
00773 int color = m_brCrystalColor;
00774 int part = GetPart(phyNode);
00775 if (part == 0 || part == 2)
00776 color = m_ecCrystalColor;
00777
00778 phyNode->SetLineColor(color);
00779 phyNode->SetVisibility(0);
00780
00781 RestorePhyNode(phyNode, (TGeoNode*)m_PhyNodeOrgArray->At(i));
00782 }
00783 m_PhyNodeOrgArray->Clear("C");
00784 m_HitsArray->Clear("C");
00785
00786
00787 for (int i = 0; i < m_2DHitsArray->GetEntries(); i++) {
00788 Emc2DCrystal *aCrystal = (Emc2DCrystal*)m_2DHitsArray->At(i);
00789 aCrystal->ClearInfo();
00790 aCrystal->AddInfo(aCrystal->GetTitle());
00791 aCrystal->CloseInfo();
00792 }
00793 m_2DHitsArray->Clear("C");
00794
00795
00796 if (gEvent) m_EmcDigiCol = gEvent->GetEmcDigiCol();
00797
00798 for (int i = 0; i < m_EmcDigiCol->GetEntries(); i++) {
00799 TEmcDigi *aEmcDigi = (TEmcDigi*)m_EmcDigiCol->At(i);
00800 Identifier aEmcID( aEmcDigi->getIntId() );
00801 int part = EmcID::barrel_ec( aEmcID );
00802 int theta = EmcID::theta_module( aEmcID );
00803 int phi = EmcID::phi_module( aEmcID );
00804
00805 Double_t charge = RawDataUtil::EmcCharge(aEmcDigi->getMeasure(),
00806 aEmcDigi->getChargeChannel());
00807 Double_t time = RawDataUtil::EmcTime(aEmcDigi->getTimeChannel());
00808
00809 TGeoPhysicalNode *phyNode = 0;
00810 phyNode = GetPhysicalCrystal( part, phi, theta );
00811 if (phyNode) {
00812 m_PhyNodeOrgArray->Add ( phyNode->GetNode() );
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00828 }
00829
00830 phyNode = GetPhysicalCrystal2( part, phi, theta );
00831 if (phyNode) {
00832 m_PhyNodeOrgArray->Add ( phyNode->GetNode() );
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00848 }
00849
00850 Emc2DCrystal *aCrystal = 0;
00851 aCrystal = m_Emc2DCrystal[part][phi][theta];
00852 if (aCrystal) {
00853 aCrystal->ClearInfo();
00854 aCrystal->AddInfo(aCrystal->GetTitle());
00855
00856 char data[100];
00857 sprintf(data, "time = %-.3f ns, charge = %-.3f MeV", time, charge);
00858 aCrystal->AddInfo( TString(data) );
00859 sprintf(data, "Fired");
00860 aCrystal->AddInfo( TString(data) );
00861
00862 aCrystal->CloseInfo();
00863
00864 m_2DHitsArray->Add(aCrystal);
00865 }
00866 }
00867 }
00868
00869 void
00870 EmcROOTGeo::SetVisEmcDetector()
00871 {
00872 BesView *view = 0;
00873 if (gPad) view = (BesView*)gPad->GetView();
00874
00875 for (int i = 0; i < m_DetectorsArray->GetEntries(); i++) {
00876 TGeoPhysicalNode *phyNode = (TGeoPhysicalNode*)m_DetectorsArray->At(i);
00877 phyNode->SetVisibility(0);
00878 if (view && view->GetVisEmcGlobal()) {
00879 int part = GetPart(phyNode);
00880 if (part == 0 && view->GetVisEmcEast() ||
00881 part == 1 && view->GetVisEmcBarrel() ||
00882 part == 2 && view->GetVisEmcWest() )
00883 phyNode->SetVisibility(1);
00884 }
00885 }
00886 }
00887
00888 void
00889 EmcROOTGeo::SetVisEmcHits()
00890 {
00891 BesView *view = 0;
00892 if (gPad) view = (BesView*)gPad->GetView();
00893
00894 for (int i = 0; i < m_HitsArray->GetEntries(); i++) {
00895 TGeoPhysicalNode *phyNode = (TGeoPhysicalNode*)m_HitsArray->At(i);
00896 if (view && view->GetVisEmcHitsGlobal()) {
00897 int part = GetPart(phyNode);
00898 if (part == 0 && view->GetVisEmcHitsEast() ||
00899 part == 1 && view->GetVisEmcHitsBarrel() ||
00900 part == 2 && view->GetVisEmcHitsWest() ) {
00901 phyNode->SetVisibility(1);
00902 phyNode->SetLineColor(kMagenta);
00903 continue;
00904 }
00905 }
00906 phyNode->SetVisibility(0);
00907 }
00908 }
00909
00910 int
00911 EmcROOTGeo::GetPartNb()
00912 {
00913 int part = m_kPart;
00914
00915 return part;
00916 }
00917
00918 int
00919 EmcROOTGeo::GetThetaNb(int part)
00920 {
00921 int thetaNb = m_kThetaBr;
00922 if (part != 1) thetaNb = m_kThetaEc;
00923
00924 return thetaNb;;
00925 }
00926
00927 int
00928 EmcROOTGeo::GetPhiNb(int part, int theta)
00929 {
00930 int phiNb = m_kPhiBr;
00931 if (part != 1) {
00932 if (theta < 2) phiNb = 4*m_kSectorEc;
00933 else if (theta >= 2 && theta < 4) phiNb = 5*m_kSectorEc;
00934 else if (theta >= 4 && theta < m_kThetaEc) phiNb = 6*m_kSectorEc;
00935 }
00936
00937 return phiNb;
00938 }
00939
00940 TGeoVolume*
00941 EmcROOTGeo::GetVolumePart( int part )
00942 {
00943
00944 std::stringstream osname;
00945 if (part != 1) osname <<"logicalEndWorld";
00946 else osname <<"logicalBSCWorld";
00947
00948
00949 if (part == 0 || part == 1) {
00950 return GetLogicalVolume( osname.str() );
00951 }
00952 else {
00953 std::cout << "No volume " << osname.str() << std::endl;
00954 return 0;
00955 }
00956 }
00957
00958 TGeoVolume*
00959 EmcROOTGeo::GetVolumePhi( int part, int phi )
00960 {
00961
00962 std::stringstream osname;
00963
00964 if (part == 1) osname << "logicalBSCPhi" ;
00965 else{
00966 if (phi == 15 || phi == 7) osname << "logicalEndPhi2" ;
00967 else if (phi == 14 || phi == 6) osname << "logicalEndPhi1" ;
00968 else osname << "logicalEndPhi0" ;
00969 }
00970
00971
00972 if ( (part == 0 && phi >= 0 && phi < 16) ||
00973 (part == 1 && phi >= 0 && phi < 120) ) {
00974 return GetLogicalVolume( osname.str() );
00975 }
00976 else {
00977 std::cout << "No volume " << osname.str() << std::endl;
00978 return 0;
00979 }
00980 }
00981
00982 TGeoVolume*
00983 EmcROOTGeo::GetVolumeTheta( int part, int phi, int theta )
00984 {
00985
00986
00987 std::stringstream osname;
00988 if (part == 1 && theta >= 0 && theta < 44) {
00989
00990 osname << "logicalBSCCasing" << theta;
00991 return GetLogicalVolume( osname.str() );
00992 }
00993 else if ( part != 1 && theta >= 0 && theta < 35 &&
00994 (phi < 3) ) {
00995
00996 osname << "logicalEndCasing_" << phi << "_" << theta;
00997 return GetLogicalVolume( osname.str() );
00998 }
00999 else {
01000 std::cout << "No volume " << osname.str() << std::endl;
01001 return 0;
01002 }
01003 }
01004
01005 TGeoVolume*
01006 EmcROOTGeo::GetVolumeCrystal( int part, int phi, int theta )
01007 {
01008
01009
01010 std::stringstream osname;
01011 if (part == 1 && theta >= 0 && theta < 44) {
01012
01013 osname << "logicalCrystal";
01014 return GetLogicalVolume( osname.str() );
01015 }
01016 else if ( part == 0 && theta >= 0 && theta < 35 &&
01017 (phi < 3) ) {
01018
01019 osname << "logicalEndCrystal_" << phi << "_" << theta;
01020 return GetLogicalVolume( osname.str() );
01021 }
01022 else {
01023 std::cout << "No volume " << osname.str() << std::endl;
01024 return 0;
01025 }
01026 }
01027
01028 TGeoNode*
01029 EmcROOTGeo::GetPart( int part )
01030 {
01031 if (m_ROOTGeoInit == 2) {
01032 std::stringstream osname;
01033
01034 if (part == 1) osname <<"pv_logicalBSCWorld_2";
01035 if (part == 0) osname <<"pv_logicalEndWorld_1";
01036 if (part == 2) osname <<"pv_logicalEndWorld_0";
01037
01038 return GetNode( osname.str() );
01039 }
01040 else if (m_ROOTGeoInit == 1) {
01041 if (m_NodePart[part] != 0) {
01042 return m_NodePart[part];
01043 }
01044 else {
01045 std::cout << "Node: " << "Part" << part << " not found" << std::endl;
01046 return 0;
01047 }
01048 }
01049
01050 return 0;
01051 }
01052
01053 TGeoNode*
01054 EmcROOTGeo::GetPhi( int part, int phi )
01055 {
01056 if (m_ROOTGeoInit == 2) {
01057 int endphilist[16]= {15,7,14,6,13,12,11,10,9,8,5,4,3,2,1,0};
01058 int endphipos[16] = {15,14,13,12,11,10,3,1,9,8,7,6,5,4,2,0};
01059
01060 int realphi=0;
01061 if (phi==15||phi==7) realphi = 2;
01062 if (phi==14||phi==6) realphi = 1;
01063
01064 std::stringstream osname;
01065
01066 if (part == 1) osname << "pv_logicalBSCPhi" << "_" << 308-phi;
01067 else osname <<"pv_logicalEndPhi"<<realphi<<"_" <<endphipos[phi];
01068 return GetNode( osname.str() );
01069 }
01070 else if (m_ROOTGeoInit == 1) {
01071 if (m_NodePhi[part][phi] != 0) {
01072 return m_NodePhi[part][phi];
01073 }
01074 else {
01075 std::cout << "Node: " << "Part" << part << "Phi" << phi << " not found" << std::endl;
01076 return 0;
01077 }
01078 }
01079
01080 return 0;
01081 }
01082
01083 TGeoNode*
01084 EmcROOTGeo::GetTheta( int part, int phi, int theta )
01085 {
01086 if (m_NodeTheta[part][phi][theta] != 0) {
01087 return m_NodeTheta[part][phi][theta];
01088 }
01089 else {
01090 std::cout << "Node: " << "Part" << part << "Phi" << phi << "Theta" << theta << " not found" << std::endl;
01091 return 0;
01092 }
01093 }
01094
01095 TGeoNode*
01096 EmcROOTGeo::GetTheta2( int part, int phi, int theta )
01097 {
01098 if (m_NodeTheta2[part][phi][theta] != 0) {
01099 return m_NodeTheta2[part][phi][theta];
01100 }
01101 else {
01102 return 0;
01103 }
01104 }
01105
01106 TGeoNode*
01107 EmcROOTGeo::GetCrystal( int part, int phi, int theta )
01108 {
01109
01110 return GetTheta(part, phi, theta)->GetDaughter(0);
01111 }
01112
01113 TGeoNode*
01114 EmcROOTGeo::GetCrystal2( int part, int phi, int theta )
01115 {
01116
01117 if (GetTheta2(part, phi, theta) == 0) return 0;
01118 else return GetTheta2(part, phi, theta)->GetDaughter(0);
01119 }
01120
01121 TGeoPhysicalNode*
01122 EmcROOTGeo::GetPhysicalCrystal( int part, int phi, int theta )
01123 {
01124 if (m_PhysicalCrystal[part][phi][theta] != 0) {
01125 return m_PhysicalCrystal[part][phi][theta];
01126 }
01127 else {
01128 std::cout << "PhysicalNode: " << "Part" << part << "Phi" << phi << "Theta" << theta << " not found" << std::endl;
01129 return 0;
01130 }
01131 }
01132
01133 TGeoPhysicalNode*
01134 EmcROOTGeo::GetPhysicalCrystal2( int part, int phi, int theta )
01135 {
01136 return m_PhysicalCrystal2[part][phi][theta];
01137 }
01138
01139 bool
01140 EmcROOTGeo::HasTwoNodes( int part, int phi, int theta )
01141 {
01142 if (part == 1) return false;
01143 else return true;
01144 }
01145
01146
01147 void
01148 EmcROOTGeo::ComputeThetaPhi( int id, int sector, int nb, int &CryNumberTheta, int &CryNumberPhi)
01149 {
01150 if ((sector>=0)&&(sector<3))
01151 sector+=16;
01152 if ((sector!=7)&&(sector!=15))
01153 {
01154 if ((nb>=0)&&(nb<4))
01155 {
01156 CryNumberTheta = 0;
01157 CryNumberPhi = (sector-3)*4+nb;
01158 }
01159 else if ((nb>=4)&&(nb<8))
01160 {
01161 CryNumberTheta = 1;
01162 CryNumberPhi = (sector-3)*4+nb-4;
01163 }
01164 else if ((nb>=8)&&(nb<13))
01165 {
01166 CryNumberTheta = 2;
01167 CryNumberPhi = (sector-3)*5+nb-8;
01168 }
01169 else if ((nb>=13)&&(nb<18))
01170 {
01171 CryNumberTheta = 3;
01172 CryNumberPhi = (sector-3)*5+nb-13;
01173 }
01174 else if ((nb>=18)&&(nb<24))
01175 {
01176 CryNumberTheta = 4;
01177 CryNumberPhi = (sector-3)*6+nb-18;
01178 }
01179 else if ((nb>=24)&&(nb<30))
01180 {
01181 CryNumberTheta = 5;
01182 CryNumberPhi = (sector-3)*6+nb-24;
01183 }
01184 }
01185 else
01186 {
01187 if ((nb>=0)&&(nb<4))
01188 {
01189 CryNumberTheta = 0;
01190 CryNumberPhi = (sector-3)*4+3-nb;
01191 }
01192 else if ((nb>=4)&&(nb<8))
01193 {
01194 CryNumberTheta = 1;
01195 CryNumberPhi = (sector-3)*4+7-nb;
01196 }
01197 else if ((nb>=8)&&(nb<13))
01198 {
01199 CryNumberTheta = 2;
01200 CryNumberPhi = (sector-3)*5+12-nb;
01201 }
01202 else if ((nb>=13)&&(nb<18))
01203 {
01204 CryNumberTheta = 3;
01205 CryNumberPhi = (sector-3)*5+17-nb;
01206 }
01207 else if ((nb>=18)&&(nb<24))
01208 {
01209 CryNumberTheta = 4;
01210 CryNumberPhi = (sector-3)*6+23-nb;
01211 }
01212 else if ((nb>=24)&&(nb<30))
01213 {
01214 CryNumberTheta = 5;
01215 CryNumberPhi = (sector-3)*6+29-nb;
01216 }
01217 }
01218
01219 if (id==2)
01220 {
01221 switch (CryNumberTheta)
01222 {
01223 case 0:
01224 if (CryNumberPhi<32)
01225 CryNumberPhi = 31-CryNumberPhi;
01226 else
01227 CryNumberPhi = 95-CryNumberPhi;
01228 break;
01229 case 1:
01230 if (CryNumberPhi<32)
01231 CryNumberPhi = 31-CryNumberPhi;
01232 else
01233 CryNumberPhi = 95-CryNumberPhi;
01234 break;
01235 case 2:
01236 if (CryNumberPhi<40)
01237 CryNumberPhi = 39-CryNumberPhi;
01238 else
01239 CryNumberPhi = 119-CryNumberPhi;
01240 break;
01241 case 3:
01242 if (CryNumberPhi<40)
01243 CryNumberPhi = 39-CryNumberPhi;
01244 else
01245 CryNumberPhi = 119-CryNumberPhi;
01246 break;
01247 case 4:
01248 if (CryNumberPhi<48)
01249 CryNumberPhi = 47-CryNumberPhi;
01250 else
01251 CryNumberPhi = 143-CryNumberPhi;
01252 break;
01253 case 5:
01254 if (CryNumberPhi<48)
01255 CryNumberPhi = 47-CryNumberPhi;
01256 else
01257 CryNumberPhi = 143-CryNumberPhi;
01258 default:
01259 ;
01260 }
01261 }
01262 }
01263
01264 int
01265 EmcROOTGeo::ComputeEndCopyNb(int num)
01266 {
01267 int copyNb;
01268 switch (num){
01269 case 30:
01270 copyNb = 5;
01271 break;
01272 case 31:
01273 copyNb = 6;
01274 break;
01275 case 32:
01276 copyNb = 14;
01277 break;
01278 case 33:
01279 copyNb = 15;
01280 break;
01281 case 34:
01282 copyNb = 16;
01283 break;
01284 default:
01285 copyNb = num;
01286 break;
01287 }
01288 return copyNb;
01289 }
01290
01291 Emc2DCrystal*
01292 EmcROOTGeo::Get2DCrystal( Int_t part, Int_t phi, Int_t theta )
01293 {
01294 if (m_Emc2DCrystal[part][phi][theta]) return m_Emc2DCrystal[part][phi][theta];
01295 else return 0;
01296 }
01297
01298 int
01299 EmcROOTGeo::GetPart(TGeoPhysicalNode* phyNode)
01300 {
01301 for (int part = 0; part < GetPartNb(); part++) {
01302 for (int theta = 0; theta < GetThetaNb(part); theta++) {
01303 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
01304 if (phyNode == GetPhysicalCrystal(part, phi, theta)) {
01305
01306 return part;
01307 }
01308 if (phyNode == GetPhysicalCrystal2(part, phi, theta)) {
01309
01310 return part;
01311 }
01312 }
01313 }
01314 }
01315
01316 cout << "EmcROOTGeo::GetPart, this crystal physical node does not exist!" << endl;
01317 return -1;
01318 }
01319
01320 void
01321 EmcROOTGeo::Draw(Option_t *option)
01322 {
01323 TString opt = option;
01324 opt.ToUpper();
01325
01326 if (!m_2DGeoInit) cout << "EmcROOTGeo::Draw2D(), 2D Geometry not initialized!" << endl;
01327 BesView *view = (BesView*)gPad->GetView();
01328 if (!view) cout << "EmcROOTGeo::Draw(), BesView not found" << endl;
01329
01330 if (view->GetVisEmcGlobal()) {
01331 TString crystalOpt;
01332
01333
01334
01335 for (Int_t part = GetPartNb()-1; part >= 0; part--) {
01336 for (int theta = 0; theta < GetThetaNb(part); theta++) {
01337 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
01338
01339 if (m_Emc2DCrystal[part][phi][theta]) {
01340
01341 m_Emc2DCrystal[part][phi][theta]->SetFired(false);
01342 if ( (part == 0 && view->GetVisEmcEast()) ||
01343 (part == 1 && view->GetVisEmcBarrel()) ||
01344 (part == 2 && view->GetVisEmcWest()) )
01345 m_Emc2DCrystal[part][phi][theta]->Draw(crystalOpt);
01346 }
01347 }
01348 }
01349 }
01350 }
01351 }
01352
01353 void
01354 EmcROOTGeo::DrawHits(Option_t *option)
01355 {
01356
01357 BesView *view = (BesView*)gPad->GetView();
01358 if (!view) cout << "EmcROOTGeo::DrawHits(), BesView not found" << endl;
01359
01360
01361
01362
01363
01364
01365 if (view->GetVisEmcHitsGlobal()) {
01366
01367
01368 for (Int_t part = GetPartNb()-1; part >= 0; part--) {
01369 for (int theta = 0; theta < GetThetaNb(part); theta++) {
01370 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
01371 if (m_Emc2DCrystal[part][phi][theta]) {
01372 m_Emc2DCrystal[part][phi][theta]->ResetTimeCharge();
01373
01374 }
01375 }
01376 }
01377 }
01378
01379 if (m_EmcDigiCol) {
01380 for (int i = 0; i < m_EmcDigiCol->GetEntries(); i++) {
01381 TEmcDigi *aEmcDigi = (TEmcDigi*)m_EmcDigiCol->At(i);
01382
01383
01384 Identifier aEmcID( aEmcDigi->getIntId() );
01385 int part = EmcID::barrel_ec( aEmcID );
01386 int theta = EmcID::theta_module( aEmcID );
01387 int phi = EmcID::phi_module( aEmcID );
01388
01389 Emc2DCrystal *aCrystal = 0;
01390 aCrystal = m_Emc2DCrystal[part][phi][theta];
01391
01392
01393 Double_t charge = RawDataUtil::EmcCharge(aEmcDigi->getMeasure(),
01394 aEmcDigi->getChargeChannel());
01395 aCrystal->SetCharge(charge);
01396
01397
01398 if (aCrystal&&charge > 5) {
01399 if ( (part == 0 && view->GetVisEmcHitsEast()) ||
01400 (part == 1 && view->GetVisEmcHitsBarrel()) ||
01401 (part == 2 && view->GetVisEmcHitsWest()) ) {
01402 aCrystal->SetFired(true);
01403 aCrystal->Draw();
01404 }
01405 }
01406 }
01407 }
01408 }
01409 }
01410
01411 void EmcROOTGeo::Align(TGeoPhysicalNode *phyNode, TGeoMatrix *newmat, TGeoShape *newshape, Bool_t check)
01412 {
01413
01414
01415 if (!newmat && !newshape) return;
01416 TGeoNode *node = phyNode->GetNode();
01417
01418 Int_t fLevel=phyNode->GetLevel();
01419 TGeoNode *nnode = 0;
01420 TGeoVolume *vm = phyNode->GetVolume(fLevel-2);
01421
01422 TGeoVolume *vd = 0;
01423
01424 TGeoNode *nodeArray[30];
01425 TString orgName = phyNode->GetName();
01426 Int_t i,id;
01427 if (!phyNode->IsAligned()) {
01428 for (i=0; i<=fLevel-2; i++) {
01429 nodeArray[i] = phyNode->GetNode(i);
01430 }
01431
01432
01433
01434
01435 for (i=fLevel-2; i<fLevel; i++) {
01436
01437 node = phyNode->GetNode(i+1);
01438 id = vm->GetIndex(node);
01439
01440 if (id < 0) {
01441
01442 return;
01443 }
01444
01445 vd = node->GetVolume()->CloneVolume();
01446 nnode = node->MakeCopyNode();
01447
01448 nnode->SetName(node->GetName());
01449 nnode->SetVolume(vd);
01450 nnode->SetMotherVolume(vm);
01451
01452 vm->GetNodes()->RemoveAt(id);
01453 vm->GetNodes()->AddAt(nnode,id);
01454 nodeArray[i+1] = nnode;
01455 vm = vd;
01456 }
01457 } else {
01458 nnode = phyNode->GetNode();
01459 }
01460
01461 TString name;
01462 for (Int_t j = 0; j < phyNode->GetLevel()+1; j++) {
01463 name += "/";
01464 name += nodeArray[j]->GetName();
01465 }
01466
01467 phyNode->SetName(name);
01468 phyNode->Refresh();
01469
01470
01471 TGeoNodeMatrix *aligned = (TGeoNodeMatrix*)nnode;
01472 vm = nnode->GetMotherVolume();
01473 vd = nnode->GetVolume();
01474 if (newmat) {
01475
01476 if (!newmat->IsRegistered()) newmat->RegisterYourself();
01477 aligned->SetMatrix(newmat);
01478
01479 TGeoHMatrix *global = phyNode->GetMatrix();
01480 TGeoHMatrix *up = phyNode->GetMatrix(fLevel-1);
01481 *global = up;
01482 global->Multiply(newmat);
01483 }
01484
01485 if (newshape) vd->SetShape(newshape);
01486
01487 vm->SetVoxelFinder(0);
01488 vm->Voxelize("ALL");
01489 vm->FindOverlaps();
01490
01491 if (check) vm->CheckOverlaps();
01492
01493 }
01494
01495 void EmcROOTGeo::RestorePhyNode(TGeoPhysicalNode *phyNode, TGeoNode *node)
01496 {
01497 Align(phyNode, node->GetMatrix(), node->GetVolume()->GetShape());
01498 }