00001
00002
00003
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00036
00037 #include "Riostream.h"
00038
00039 #include "TSystem.h"
00040 #include "TRandom.h"
00041 #include "TGeoTube.h"
00042
00043 #include "TFile.h"
00044 #include "TThread.h"
00045 #include <TView3D.h>
00046
00047 #include "TFndDB.h"
00048 #include "TFndGeometry.h"
00049
00050 TFndGeometry *gFndGeom;
00051
00052 ClassImp(TFndGeometry)
00053
00054
00055 TFndGeometry::TFndGeometry():
00056 fVerboseLevel(),fSetup(),
00057 fPromptNode(),fPromptVolume(),fCurDetNode(),fTgtNodes(),
00058 fMainCanvas()
00059 {
00060 gFndGeom = this;
00061
00062 }
00063
00064
00065 TFndGeometry::~TFndGeometry(){
00066
00067 delete fMainCanvas;
00068 gFndGeom = 0;
00069 }
00070
00071
00072 Double_t TFndGeometry::GetTofinoRotAngles(Int_t slab){
00073
00074 if(slab < 0 || slab > K_N_TOFINO_SLABS){
00075 gROOT->Error("TFndGeometry::GetTofinoRotAngles","Slab out of range (%d)",slab);
00076 return 0;
00077 }
00078
00079 Double_t res = (Double_t)(slab-1) * GetTofinoSlabAngle();
00080 res += GetTofinoSlabAngle() / 2;
00081 return res;
00082 }
00083
00084
00085 Double_t TFndGeometry::GetTofoneRotAngles(Int_t slab){
00086
00087 if(slab < 0 || slab > K_N_TOFONE_SLABS){
00088 gROOT->Error("TFndGeometry::GetTofoneRotAngles","Slab out of range (%d)",slab);
00089 return 0;
00090 }
00091
00092 Double_t res = (Double_t)(slab-1) * GetTofoneSlabAngle();
00093
00094 return res;
00095 }
00096
00097
00098 Int_t TFndGeometry::ConvertFromGeant3(TString root_geom_filename, TString geant3_geom_path,Bool_t CleanTmp){
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 TString TempFileName = root_geom_filename;
00112 Int_t dot_id = TempFileName.Index(".");
00113 if(dot_id == -1){
00114 gROOT->Warning("ConvertFromGeant3","no \".\" found into the geom_filename: not converting");
00115 return -1;
00116 }
00117 TempFileName.Resize(dot_id);
00118 TempFileName+=".C";
00119
00120 TString cmd_conv;
00121 cmd_conv.Form("%s %s %s","g2root",geant3_geom_path.Data(),TempFileName.Data());
00122
00123 Printf(" ---> sending command \"%s\"",cmd_conv.Data());
00124 gSystem->Exec(cmd_conv.Data());
00125 Printf("TFndGeometry::ConvertFromGeant3 ---> Root GEOMETRY macro created.");
00126
00127 TString cmd_x = ".x ";
00128 cmd_x += TempFileName;
00129 Printf("sending root-command \"%s\"",cmd_x.Data());
00130 gROOT->ProcessLine(cmd_x.Data());
00131
00132 TFile f(root_geom_filename,"RECREATE");
00133 gGeoManager->SetName("TheFinudaGeometry");
00134 gGeoManager->Write();
00135 f.Close();
00136
00137 if(CleanTmp){
00138 TString cmd_rm = "rm -i "; cmd_rm += TempFileName;
00139 gSystem->Exec(cmd_rm.Data());
00140 }
00141 return 0;
00142 }
00143
00144
00145 Int_t TFndGeometry::LoadGeometry(TString filename){
00146
00147
00148
00149
00150
00151 if(gSystem->AccessPathName(ExpandPathName(filename))){
00152 Warning("LoadGeometry","File \"%s\"not found",filename.Data());
00153 return -1;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 TFile f(filename,"OPEN");
00165 if(fVerboseLevel>1) f.ls();
00166 if(fVerboseLevel>0) Printf("Geometry manager new address: %x",f.Get("TheFinudaGeometry"));
00167
00168 if(gGeoManager) delete gGeoManager;
00169 gGeoManager = (TGeoManager *)(f.Get("TheFinudaGeometry"));
00170
00171 if(!gGeoManager){
00172 Warning("LoadGeometry","No geometry loaded");
00173 return -2;
00174 }
00175 f.Close();
00176
00177 Init();
00178
00179
00180 return 0;
00181 }
00182
00183
00184 void TFndGeometry::Init(){
00185
00186
00187
00188
00189 fPromptNode = gGeoManager->GetNode(0);
00190 fPromptVolume = fPromptNode->GetVolume();
00191
00192
00193 if(fPromptVolume->FindNode("TAR1_1")){
00194 fSetup = (Int_t) FGEO_2003;
00195 fTgtNodes[0] = fPromptVolume->FindNode("TAR1_1");
00196 fTgtNodes[1] = fPromptVolume->FindNode("LIM2_1");
00197 fTgtNodes[2] = fPromptVolume->FindNode("LIM3_1");
00198 fTgtNodes[3] = fPromptVolume->FindNode("LIM4_1");
00199 fTgtNodes[4] = fPromptVolume->FindNode("TAR5_1");
00200 fTgtNodes[5] = fPromptVolume->FindNode("TAR6_1");
00201 fTgtNodes[6] = fPromptVolume->FindNode("TAR7_1");
00202 fTgtNodes[7] = fPromptVolume->FindNode("TAR8_1");
00203 }
00204 else if(fPromptVolume->FindNode("LIM1_1")){
00205 fSetup = (Int_t) FGEO_2006;
00206 fTgtNodes[0] = fPromptVolume->FindNode("LIM1_1");
00207 fTgtNodes[1] = fPromptVolume->FindNode("TAR2_1");
00208 fTgtNodes[2] = fPromptVolume->FindNode("LIM3_1");
00209 fTgtNodes[3] = fPromptVolume->FindNode("LIM4_1");
00210 fTgtNodes[4] = fPromptVolume->FindNode("LIM5_1");
00211 fTgtNodes[5] = fPromptVolume->FindNode("LIM6_1");
00212 fTgtNodes[6] = fPromptVolume->FindNode("TAR7_1");
00213 fTgtNodes[7] = fPromptVolume->FindNode("LIM8_1");
00214 }
00215 else{
00216 Error("Init","Can not identify current setup!");
00217 gApplication->Terminate();
00218 }
00219 if(fVerboseLevel>0) Info("Init","Loaded setup is \"%s\" (id: %d)",GetCurrentSetup().Data(),fSetup);
00220
00221
00222 LoadGeoMatrices();
00223 if(fVerboseLevel>0) Info("Init","All matrices succesfully loaded");
00224 }
00225
00226
00227 void TFndGeometry::LoadGeoMatrices(){
00228
00229
00230 Int_t channel;
00231
00233 for(Int_t lay=1;lay<=2;lay++){
00234 for(Int_t sl=1;sl<=K_N_TOFONE_SLABS;sl++){
00235 if(lay ==1 && sl>K_N_TOFINO_SLABS){
00236 fGeoMatr_Top_Tof[lay-1][sl-1] = 0;
00237 continue;
00238 }
00239 channel = TFndDB::Tof_ChannelToDBNumbering(lay,sl);
00240 SelectDetectorNode(FIN_TOF,channel);
00241 if(fVerboseLevel>1) Printf("LoadGeoMatrices ===> node TOF: channel \"%d\": \"%s\"",channel,fCurDetNode->GetName());
00242
00243 fGeoMatr_Top_Tof[lay-1][sl-1] = new TGeoHMatrix();
00244 Double_t trasl_tof[3] = { 0. , 0. , 0. };
00245 TGeoTube *tgtub = (TGeoTube *) ( fCurDetNode->GetDaughter(0)->GetVolume()->GetShape() );
00246 trasl_tof[0] = tgtub->GetRmin();
00247 trasl_tof[0] += ( (tgtub->GetRmax() - tgtub->GetRmin()) / 2 );
00248
00249 fGeoMatr_Top_Tof[lay-1][sl-1]->SetTranslation(trasl_tof);
00250
00251 fGeoMatr_Top_Tof[lay-1][sl-1]->RotateZ( (lay==1) ? GetTofinoRotAngles(sl) : GetTofoneRotAngles(sl) );
00252 }
00253 }
00255
00256
00257 for(Int_t lay=1;lay<=2;lay++){
00258 for(Int_t mod=1;mod<=K_N_Sil_Modules;mod++){
00259 if(lay==1){
00260 if(mod>8) continue;
00261 SelectDetectorNode(FIN_ISM,mod);
00262 }
00263 else SelectDetectorNode(FIN_OSM,mod);
00264
00265 fGeoMatr_Top_Sil[lay-1][mod-1] = fCurDetNode->GetMatrix();
00266 }
00267 }
00268
00269
00271 for(Int_t lay=1;lay<=K_N_LMD_LAYERS;lay++){
00272 for(Int_t ch=1;ch<=K_N_LMD_CHAMS_PER_LAYER;ch++){
00273 for(Int_t wire=0;wire<=K_N_LMD_OUTER_WIRES;wire++){
00274 if(lay==1 && wire > K_N_LMD_INNER_WIRES) continue;
00275
00276 channel = TFndDB::Lmd_ChannelToDBNumbering(lay,ch,wire);
00277 SelectDetectorNode(FIN_LMD,channel);
00278
00279 if(wire==0){
00280 if(fVerboseLevel>1) Printf("LoadGeoMatrices ===> external node LMD: channel \"%d\": \"%s\"",channel,fCurDetNode->GetName());
00281 fGeoMatr_Top_Lmd[lay-1][ch-1] = fCurDetNode->GetMatrix();
00282 continue;
00283 }
00284
00285 if(fVerboseLevel>1) Printf("LoadGeoMatrices ---> LMD: channel \"%d\": \"%s\"",channel,fCurDetNode->GetName());
00286 if(lay ==1) fGeoMatr_InnerLmd_Wire [ch-1][wire-1] = fCurDetNode->GetMatrix();
00287 else if(lay ==2) fGeoMatr_OuterLmd_Wire [ch-1][wire-1] = fCurDetNode->GetMatrix();
00288 else{ Error("LoadGeoMatrices","layer out of range (%d)",lay); gApplication->Terminate(); }
00289 }
00290 }
00291 }
00292
00293 for(Int_t l_id=0;l_id<K_N_LMD_LAYERS;l_id++){
00294 for(Int_t ch_id=0;ch_id<K_N_LMD_CHAMS_PER_LAYER;ch_id++){
00295 for(Int_t wire_id=0;wire_id<K_N_LMD_OUTER_WIRES;wire_id++){
00296 if(l_id==0 && wire_id >= K_N_LMD_INNER_WIRES) continue;
00297 if(l_id ==0){
00298 fGeoMatr_Top_InnerLmdWire[ch_id][wire_id] = new TGeoHMatrix(*fGeoMatr_Top_Lmd[l_id][ch_id]);
00299 fGeoMatr_Top_InnerLmdWire[ch_id][wire_id]->Multiply(fGeoMatr_InnerLmd_Wire[ch_id][wire_id]);
00300 }
00301 else if(l_id==1){
00302 fGeoMatr_Top_OuterLmdWire[ch_id][wire_id] = new TGeoHMatrix(*fGeoMatr_Top_Lmd[l_id][ch_id]);
00303 fGeoMatr_Top_OuterLmdWire[ch_id][wire_id]->Multiply(fGeoMatr_OuterLmd_Wire[ch_id][wire_id]);
00304 }
00305 else{
00306 Error("LoadGeoMatrices","layer ID out of range (%d)",l_id); gApplication->Terminate();
00307 }
00308 }
00309 }
00310 }
00311
00313 for(Int_t crown=1;crown<=K_N_STB_CROWNS;crown++){
00314 for(Int_t tube=0;tube<=K_N_STB_TUBES;tube++){
00315 channel = TFndDB::Stb_ChannelToDBNumbering(crown,tube);
00316 SelectDetectorNode(FIN_STB,channel);
00317 if(tube == 0){
00318 if(fVerboseLevel>1) printf("LoadGeoMatrices ===> STB (outer volume): \"%d\": \"%s\"\n",channel,fCurDetNode->GetName());
00319 continue;
00320 }
00321 if(fVerboseLevel>1) printf("LoadGeoMatrices ---> STB: channel \"%d\": \"%s\"\n",channel,fCurDetNode->GetName());
00322 fGeoMatr_Top_StbWire[crown-1][tube-1] = fCurDetNode->GetMatrix();;
00323 }
00324 }
00325 }
00326
00327
00328 Double_t TFndGeometry::SilPositionStrip(const Int_t &side, const Double_t &barcha) {
00329
00330
00331
00332
00333
00334 const Double_t pitchp = 0.0025;
00335 const Double_t pitchn = 0.0050;
00336
00337
00338
00339 const Double_t pgeo[18]={0.0000,0.0740,6.3920,0.0740,
00340 0.0000,0.0740,6.3920,0.0740,
00341 0.0000,0.0740,6.3920,0.0740,
00342 0.0000,
00343 0.0000,0.0800,5.1000,0.0800,0.0000};
00344 const Double_t qgeo[18]={0.0000,0.0750,6.3900,0.0750,
00345 0.0000,0.0750,6.3900,0.0750,
00346 0.0000,0.0750,6.3900,0.0750,
00347 0.0000,
00348 0.0000,0.1462,4.9676,0.1462,0.0000};
00349
00350 const Double_t nstrp=2041.0;
00351 const Double_t maxchp=1021.0;
00352
00353 const Double_t nstrn=3837.0;
00354 const Double_t maxchn=1920.0;
00355
00356 Double_t idncha = floor(barcha);
00357 Double_t difcha = barcha - idncha;
00358 Double_t idnstr = 0.;
00359 Double_t pitch = 0.;
00360 Double_t helle = 0.;
00361 Double_t dely0 = 0.;
00362 Double_t numstr = 0.;
00363 Double_t nfrac = 0.;
00364 Double_t nikstr = 0.;
00365 Double_t strpos = 0.;
00366 if (side == 0) {
00367
00368
00369
00370 idnstr = 2*idncha-1;
00371 pitch = pitchp;
00372 helle = 0.5*(pgeo[14]+pgeo[15]+pgeo[16]);
00373 dely0 = pgeo[16];
00374 numstr = nstrp;
00375 strpos = pitch*(idnstr-1)-helle+dely0;
00376 } else {
00377
00378
00379
00380 if (idncha <= maxchn/3.) {
00381 nfrac = 1.;
00382 } else if (idncha <= maxchn/3.*2.) {
00383 nfrac = 2.;
00384 } else {
00385 nfrac = 3.;
00386 }
00387 idnstr = 2*idncha-nfrac;
00388 numstr = nstrn/3;
00389 pitch = pitchn;
00390 if (idnstr > numstr*2) {
00391
00392
00393
00394 nikstr = 2.;
00395 helle = 0.5*(qgeo[1]+qgeo[2]+qgeo[3]);
00396 dely0 = qgeo[3];
00397 strpos = pitch*(idnstr-nikstr*numstr-1.)+dely0+(0.5*qgeo[6]+qgeo[5]+qgeo[4]);
00398 } else if (idnstr <= numstr) {
00399
00400
00401
00402 nikstr = 0.;
00403 helle = 0.5*(qgeo[9]+qgeo[10]+qgeo[11]);
00404 dely0 = qgeo[11];
00405 strpos = pitch*(idnstr-nikstr*numstr-1)+dely0-(0.5*qgeo[6]+qgeo[7]+qgeo[8])-2.*helle;
00406 } else {
00407
00408
00409
00410 nikstr = 1.;
00411 helle = 0.5*(qgeo[5]+qgeo[6]+qgeo[7]);
00412 dely0 = qgeo[7];
00413 strpos = pitch*(idnstr-nikstr*numstr-1)-helle+dely0;
00414 }
00415 }
00416 strpos += difcha*2.0*pitch;
00417 return strpos;
00418 }
00419
00420
00421 void TFndGeometry::RefSys_TofSlabToMRS(const Int_t &channel,const Double_t* local, Double_t* master) {
00422
00423 Int_t lay = -1;
00424 Int_t sla = -1;
00425 TFndDB::Tof_ChNum_To_DetChan(channel,lay,sla);
00426
00427 if(
00428 (channel > K_N_TOFINO_SLABS && channel <= 100) ||
00429 (channel > 172 && channel <= 300) ||
00430 (channel > 312)
00431 ) {
00432 Error("RefSys_TofSlabToMRS","Wrong channel number (%d)",channel);
00433 for(Int_t i=0;i<3;i++) master[i] = 0.;
00434 return;
00435 }
00436
00437
00438 fGeoMatr_Top_Tof[lay-1][sla-1]->LocalToMaster(local,master);
00439
00440 }
00441
00442
00443 void TFndGeometry::RefSys_SilModToMRS(const Int_t &layer,const Int_t &module,const Double_t* local, Double_t* master){
00444
00445 fGeoMatr_Top_Sil[layer-1][module-1]->LocalToMaster(local,master);
00446 }
00447
00448
00449 void TFndGeometry::RefSys_LmdWireToMRS(const Int_t &channel,const Double_t* local, Double_t* master) {
00450
00451 Int_t lay = -1;
00452 Int_t dch = -1;
00453 Int_t wire = -1;
00454 Int_t wire_node = -1;
00455 TFndDB::Lmd_ChNum_To_DetChan(channel,lay,dch,wire,wire_node);
00456
00457 if(lay ==1) fGeoMatr_Top_InnerLmdWire[dch-1][wire-1]->LocalToMaster(local,master);
00458 else if(lay ==2) fGeoMatr_Top_OuterLmdWire[dch-1][wire-1]->LocalToMaster(local,master);
00459 else{
00460 Error("RefSys_LmdWireToMRS","layer value out of range (%d)",lay); gApplication->Terminate();
00461 }
00462 }
00463
00464
00465 void TFndGeometry::RefSys_StbWireToMRS(const Int_t &channel,const Double_t* local, Double_t* master) {
00466
00467 Int_t crown = -1;
00468 Int_t tube = -1;
00469 Int_t wire_node = -1;
00470 TFndDB::Stb_ChNum_To_DetChan(channel,crown,tube,wire_node);
00471 fGeoMatr_Top_StbWire[crown-1][tube-1]->LocalToMaster(local,master);
00472 }
00473
00474
00475 void TFndGeometry::PrintGeoMatrices(Int_t det,Int_t verbose_lev){
00476
00477
00478
00479 Int_t channel;
00480
00481 switch(det){
00482 case (Int_t) FIN_GTS:
00483
00484 break;
00485 case (Int_t) FIN_TOF:
00486 for(Int_t lay=1;lay<=2;lay++){
00487 for(Int_t sl=1;sl<=K_N_TOFONE_SLABS;sl++){
00488 if(lay ==1 && sl>K_N_TOFINO_SLABS) continue;
00489 channel = TFndDB::Tof_ChannelToDBNumbering(lay,sl);
00490 SelectDetectorNode(FIN_TOF,channel);
00491 Printf("PrintGeoMatrices ===> node TOF: channel \"%d\": \"%s\"",channel,fCurDetNode->GetName());
00492 fGeoMatr_Top_Tof[lay-1][sl-1]->Print();
00493 }
00494 }
00495 break;
00496 case (Int_t) FIN_ISM:
00497 for(Int_t mod=1;mod<=8;mod++){
00498 SelectDetectorNode(FIN_ISM,mod);
00499 Printf("PrintGeoMatrices ===> node ISIM: module \"%d\": \"%s\"",mod,fCurDetNode->GetName());
00500 fGeoMatr_Top_Sil[0][mod-1]->Print();
00501 }
00502 break;
00503 case (Int_t) FIN_OSM:
00504 for(Int_t mod=1;mod<=K_N_Sil_Modules;mod++){
00505 SelectDetectorNode(FIN_OSM,mod);
00506 Printf("PrintGeoMatrices ===> node OSIM: module \"%d\": \"%s\"",mod,fCurDetNode->GetName());
00507 fGeoMatr_Top_Sil[1][mod-1]->Print();
00508 }
00509 break;
00510 case (Int_t) FIN_LMD:
00511 for(Int_t lay=1;lay<=K_N_LMD_LAYERS;lay++){
00512 for(Int_t ch=1;ch<=K_N_LMD_CHAMS_PER_LAYER;ch++){
00513 for(Int_t wire=0;wire<=K_N_LMD_OUTER_WIRES;wire++){
00514 if(lay==1 && wire > K_N_LMD_INNER_WIRES) continue;
00515
00516 channel = TFndDB::Lmd_ChannelToDBNumbering(lay,ch,wire);
00517 SelectDetectorNode(det,channel);
00518 if(wire==0){
00519 Printf("PrintGeoMatrices ===> external node LMD: channel \"%d\": \"%s\"",channel,fCurDetNode->GetName());
00520 fGeoMatr_Top_Lmd[lay-1][ch-1]->Print();
00521 continue;
00522 }
00523 Printf("PrintGeoMatrices -> LMD: channel \"%d\": \"%s\"",channel,fCurDetNode->GetName());
00524 if(lay ==1) fGeoMatr_InnerLmd_Wire [ch-1][wire-1]->Print();
00525 else if(lay==2) fGeoMatr_OuterLmd_Wire [ch-1][wire-1]->Print();
00526 else{ Error("PrintGeoMatrices","layer out of range (%d)",lay); gApplication->Terminate(); }
00527 }
00528 }
00529 }
00530 break;
00531 case (Int_t) FIN_STB:
00532 for(Int_t crown=1;crown<=K_N_STB_CROWNS;crown++){
00533 for(Int_t tube=0;tube<=K_N_STB_TUBES;tube++){
00534 channel = TFndDB::Stb_ChannelToDBNumbering(crown,tube);
00535 SelectDetectorNode(FIN_STB,channel);
00536 if(tube == 0){
00537 Printf("PrintGeoMatrices ===> STB (outer volume): \"%d\": \"%s\"",channel,fCurDetNode->GetName());
00538 continue;
00539 }
00540 Printf("PrintGeoMatrices ---> STB: channel \"%d\": \"%s\"",channel,fCurDetNode->GetName());
00541 fGeoMatr_Top_StbWire[crown-1][tube-1]->Print();
00542 }
00543 }
00544 break;
00545 default:
00546 Warning("PrintGeoMatrices","detector id \"%d\" not available",det);
00547 return;
00548 }
00549
00550 }
00551
00552
00553 Int_t TFndGeometry::ShowGeometry(Option_t *option,Int_t vis_level){
00554
00555
00556
00557
00558 if(!fPromptNode){
00559 Warning("ShowGeometry","No geometry available");
00560 return -1;
00561 }
00562
00563 delete fMainCanvas;
00564 fMainCanvas = new TCanvas("FinGeomCanvas","FINUDA Geometry",100,100,400,400);
00565 fMainCanvas->SetFillColor(0);
00566 gGeoManager->SetVisLevel(vis_level);
00567 SetDefaultColors();
00568 SetDefaultVisibility();
00569
00570 gGeoManager->GetTopVolume()->Draw(option);
00572
00573 TView3D *view = new TView3D();
00574 Double_t k=150.;
00575 view->SetRange( -k, -k, -k, k, k, k);
00576 Int_t iret;
00577 view->SetView(5, 5, 0, iret);
00578 view->SetViewChanged();
00580 fMainCanvas->SetView(view);
00581 fMainCanvas->Modified();
00582 fMainCanvas->Update();
00583
00584 return 0;
00585 }
00586
00587
00588 Int_t TFndGeometry::PrintNode(TGeoNode *node,Int_t id_subnum,const Int_t level){
00589
00590
00591 if(!node){
00592 Warning("PrintNode","node not defined!");
00593 return 0;
00594 }
00595
00596 TString sp_str = "";
00597 sp_str.Resize(level * 5);
00598
00599 Printf("%s -> Sub-Node number %d: \"%s\" (level %d)",sp_str.Data(),id_subnum,node->GetName(),level);
00600 Int_t ndau = node->GetNdaughters();
00601 if(!ndau) return 0;
00602
00603 Printf("%s Number of daughters: %d",sp_str.Data(),ndau);
00604 return ndau;
00605
00606 }
00607
00608
00609 void TFndGeometry::PrintStructure(const Int_t levels){
00610
00611
00612
00613
00614
00615
00616 if(!gGeoManager){
00617 Warning("PrintStructure","No geometry loaded");
00618 return;
00619 }
00620
00621
00622 Int_t Nmany = gGeoManager->GetNmany();
00623 Int_t Nsegments = gGeoManager->GetNsegments();
00624 Int_t NAlignable = gGeoManager->GetNAlignable();
00625 Int_t Ntracks = gGeoManager->GetNtracks();
00626 Int_t NNodes = gGeoManager->GetNNodes();
00627
00628
00629 Printf("");
00630 Printf(" --------- the FINUDA SPECTROMETER geometry structure: ---------");
00631 Printf(" -> Top volume: \"%s\"",gGeoManager->GetTopVolume()->GetName());
00632 Printf(" Number of many =======> %d",Nmany);
00633 Printf(" Number of segments ===> %d",Nsegments);
00634 Printf(" Number of Alignable ==> %d",NAlignable);
00635 Printf(" Number of tracks =====> %d",Ntracks);
00636 Printf(" Number of nodes ======> %d",NNodes);
00637 Printf(" --- --- --- ---");
00638
00639
00640
00641 Printf(" --------- Inspecting the geometry structure: ---------");
00642
00643 Int_t NDaughters = fPromptNode->GetNdaughters();
00644
00645 Printf(" -> Prompt node: \"%s\"",fPromptNode->GetName());
00646 Printf(" Number of daughters ======> %d",NDaughters);
00647
00648
00649 TGeoNode *daughts[levels];
00650 Int_t ndau[levels];
00651 Int_t next_dau_num[levels];
00652 for(Int_t i=0;i<levels;i++){
00653 daughts[i] = 0;
00654 ndau[i] = 0;
00655 next_dau_num[i] = 0;
00656 }
00657
00658 for(ndau[0]=0;ndau[0]<NDaughters;ndau[0]++){
00659 daughts[0] = fPromptNode->GetDaughter(ndau[0]);
00660 next_dau_num[0] = PrintNode(daughts[0],ndau[0],0);
00661 if(levels <1) continue;
00662 for(ndau[1]=0;ndau[1]<next_dau_num[0];ndau[1]++){
00663 daughts[1] = daughts[0]->GetDaughter(ndau[1]);
00664 next_dau_num[1] = PrintNode(daughts[1],ndau[1],1);
00665 if(levels <2) continue;
00666 for(ndau[2]=0;ndau[2]<next_dau_num[1];ndau[2]++){
00667 daughts[2] = daughts[1]->GetDaughter(ndau[2]);
00668 next_dau_num[2] = PrintNode(daughts[2],ndau[2],2);
00669 if(levels <3) continue;
00670 for(ndau[3]=0;ndau[3]<next_dau_num[2];ndau[3]++){
00671 daughts[3] = daughts[2]->GetDaughter(ndau[3]);
00672 next_dau_num[3] = PrintNode(daughts[3],ndau[3],3);
00673 if(levels <4) continue;
00674 for(ndau[4]=0;ndau[4]<next_dau_num[3];ndau[4]++){
00675 daughts[4] = daughts[3]->GetDaughter(ndau[4]);
00676 next_dau_num[4] = PrintNode(daughts[4],ndau[4],4);
00677 if(levels <5) continue;
00678 for(ndau[5]=0;ndau[5]<next_dau_num[4];ndau[5]++){
00679 daughts[5] = daughts[4]->GetDaughter(ndau[5]);
00680 next_dau_num[5] = PrintNode(daughts[5],ndau[5],5);
00681 if(levels <6) continue;
00682 for(ndau[6]=0;ndau[6]<next_dau_num[5];ndau[6]++){
00683 daughts[6] = daughts[5]->GetDaughter(ndau[6]);
00684 next_dau_num[6] = PrintNode(daughts[6],ndau[6],6);
00685 if(levels <7) continue;
00686 for(ndau[7]=0;ndau[7]<next_dau_num[6];ndau[7]++){
00687 daughts[7] = daughts[6]->GetDaughter(ndau[7]);
00688 next_dau_num[7] = PrintNode(daughts[7],ndau[7],7);
00689 }
00690 }
00691 }
00692 }
00693 }
00694 }
00695 }
00696 }
00697
00698 }
00699
00700
00701 TGeoNode *TFndGeometry::SelectDetectorNode(const Int_t &det, const Int_t &ch){
00702
00703
00704
00705
00706
00707
00708
00709
00710 if(det == (Int_t) FIN_GTS){
00711 Warning("SelectDetectorNode","No geometry has been provided for GTS",det);
00712 return 0;
00713 }
00714
00715 fCurDetNode = 0;
00716
00717 Int_t lay = -1;
00718 Int_t dch_num = -1;
00719 Int_t wire_num = -1;
00720 Int_t wirenode = -1;
00721
00722 TString nnam;
00723
00724
00725 switch(det){
00726 case (Int_t) FIN_GTS:
00727
00728 break;
00729 case (Int_t) FIN_TOF:
00730 if(ch >= 1 && ch <= K_N_TOFINO_SLABS) fCurDetNode = fPromptVolume->FindNode("ITOF_1");
00731 else if(ch>=101 && ch<=100+K_N_TOFONE_SLABS) fCurDetNode = fPromptVolume->FindNode("ETOF_1");
00732 else{
00733 Error("SelectDetectorNode","Wrong cannel number for TOF (%d)",ch);
00734 return 0;
00735 }
00736 break;
00737 case (Int_t) FIN_ISM:
00738 nnam.Form("ISIM_%d",ch);
00739 fCurDetNode = fPromptVolume->FindNode(nnam);
00740 break;
00741 case (Int_t) FIN_OSM:
00742 nnam.Form("OSIM_%d",ch);
00743 fCurDetNode = fPromptVolume->FindNode(nnam);
00744 break;
00745 case (Int_t) FIN_LMD:
00746
00747
00748
00749
00750
00751
00752
00753 if(ch<=0 || ch > 2822){
00754 Error("SelectDetectorNode","Channel out of range (LMD): %d",ch);
00755 gApplication->Terminate();
00756 }
00757 TFndDB::Lmd_ChNum_To_DetChan(ch,lay,dch_num,wire_num,wirenode);
00758 if(wire_num == 0){
00759 fCurDetNode = fPromptVolume->FindNode("BAG2_1")->GetDaughter((lay-1)*8 + (dch_num-1));
00760 break;
00761 }
00762 if(fVerboseLevel>1) Printf("Selecting node for LMD: ch: %d ===> layer: %d; dch_num: %d; wire_num: %d; wirenode: %d.",ch,lay,dch_num,wire_num,wirenode);
00763
00764
00765
00766 fCurDetNode = fPromptVolume->FindNode("BAG2_1")
00767 ->GetDaughter((lay-1)*8 + (dch_num-1))->GetDaughter(0)->GetDaughter(0)
00768 ->GetDaughter(4)->GetDaughter(wirenode);
00769
00770
00771
00772 break;
00773 case (Int_t) FIN_STB:
00774
00775
00776
00777
00778
00779 TFndDB::Stb_ChNum_To_DetChan(ch,lay,wire_num,wirenode);
00780 if(lay<1 || lay > K_N_STB_CROWNS || wire_num<0 || wire_num >K_N_STB_TUBES){
00781 Error("SelectDetectorNode","Channel out of range (STB): %d",ch);
00782 gApplication->Terminate();
00783 }
00784 if(lay<=2){
00785 nnam = "SSTR_1";
00786 }
00787 else if(lay<=6){
00788 nnam = "TSTR_1";
00789 }
00790
00791
00792
00793
00794 else{
00795 Error("SelectDetectorNode","BUG! (stb)");
00796 gApplication->Terminate();
00797 }
00798 if(fVerboseLevel>1) Printf("Selecting node for STB: ch: %d ===> crown: %d; tube: %d; wirenode: %d.",ch,lay,wire_num,wirenode);
00799 if(wire_num==0) fCurDetNode = fPromptVolume->FindNode(nnam);
00800 else fCurDetNode = fPromptVolume->FindNode(nnam)->GetDaughter(wirenode);
00801 if(!fCurDetNode){
00802 Error("SelectDetectorNode","BUG!");
00803 gApplication->Terminate();
00804 }
00805 break;
00806 default:
00807 Warning("SelectDetectorNode","detector id \"%d\" not available",det);
00808 return 0;
00809 }
00810
00811 if(fVerboseLevel>0) Info("SelectDetectorNode","Current node set to \"%s\"",fCurDetNode->GetName());
00812 return fCurDetNode;
00813 }
00814
00816
00818
00819
00820 Int_t TFndGeometry::SetDefaultColors(){
00821
00822
00823
00824 fPromptVolume->FindNode("PIPE_1")->GetVolume()->SetLineColor(35);
00825 for(Int_t i=0;i<fPromptVolume->FindNode("PIPE_1")->GetNdaughters();i++){
00826 fPromptVolume->FindNode("PIPE_1")->GetDaughter(i)->GetVolume()->SetLineColor(95);
00827 }
00828
00829 SelectDetectorNode(FIN_TOF,1);
00830 fCurDetNode->GetDaughter(0)->GetVolume()->SetLineColor(7);
00831
00832 SelectDetectorNode(FIN_ISM,1);
00833 fCurDetNode->GetVolume()->SetLineColor(18);
00834
00835
00836 for(Int_t i=0;i<8;i++) fTgtNodes[i]->GetVolume()->SetLineColor(28);
00837
00838 SelectDetectorNode(FIN_OSM,1);
00839 fCurDetNode->GetVolume()->SetLineColor(19);
00840
00841
00842 fPromptVolume->FindNode("BAG2_1")->GetDaughter(0)->GetDaughter(0)->GetDaughter(0)->GetVolume()->SetLineColor(38);
00843 fPromptVolume->FindNode("BAG2_1")->GetDaughter(8)->GetDaughter(0)->GetDaughter(0)->GetVolume()->SetLineColor(9);
00844
00845
00846 fPromptVolume->FindNode("SSTR_1")->GetVolume()->SetLineColor(29);
00847 fPromptVolume->FindNode("TSTR_1")->GetVolume()->SetLineColor(30);
00848
00849 SelectDetectorNode(FIN_TOF,101);
00850 fCurDetNode->GetDaughter(0)->GetVolume()->SetLineColor(7);
00851
00852
00853
00854 fPromptVolume->FindNode("MCRA_1")->GetVolume()->SetLineColor(18);
00855 fPromptVolume->FindNode("MCRA_1")->GetVolume()->SetLineColor(18);
00856
00857 fPromptVolume->FindNode("FLCN_1")->GetVolume()->SetLineColor(18);
00858 fPromptVolume->FindNode("FLCN_2")->GetVolume()->SetLineColor(18);
00859
00860 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN1_1")->GetVolume()->SetLineColor(18);
00861 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN1_2")->GetVolume()->SetLineColor(18);
00862 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN2_1")->GetVolume()->SetLineColor(18);
00863 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN2_2")->GetVolume()->SetLineColor(18);
00864 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN3_1")->GetVolume()->SetLineColor(18);
00865 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN3_2")->GetVolume()->SetLineColor(18);
00866
00867 fPromptVolume->FindNode("RIN5_1")->GetVolume()->SetLineColor(18);
00868 fPromptVolume->FindNode("RIN5_2")->GetVolume()->SetLineColor(18);
00869
00870 TString mdcstr = "";
00871 TString beastr = "";
00872 for(Int_t l=1;l<=2;l++){
00873 for(Int_t c=1;c<=16;c++){
00874 mdcstr.Form("MDC%d_%d",l,c);
00875 beastr.Form("BEA%d_%d",l,c);
00876 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode(mdcstr.Data())->GetVolume()->SetLineColor(18);
00877 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode(beastr.Data())->GetVolume()->SetLineColor(18);
00878 }
00879 }
00880
00881 gGeoManager->ModifiedPad();
00882
00883 }
00884
00885
00886 Int_t TFndGeometry::SetDefaultVisibility(){
00887
00888
00889
00890
00891 SetLayerVisibility(FGEO_TOFINO, 1,1);
00892 SetLayerVisibility(FGEO_BEAM_PIPE, 1,0);
00893 SetLayerVisibility(FGEO_ISIM, 1,0);
00894 SetLayerVisibility(FGEO_TARGETS, 1,0);
00895 SetLayerVisibility(FGEO_OSIM, 1,0);
00896 SetLayerVisibility(FGEO_INNER_LMD, 1,0);
00897 SetLayerVisibility(FGEO_OUTER_LMD, 1,0);
00898 SetLayerVisibility(FGEO_STRAW_TUBES, 1,0);
00899 SetLayerVisibility(FGEO_TOFONE, 1,1);
00900 SetStructureVisibility(0,0);
00901 }
00902
00903
00904 void TFndGeometry::SetLayerVisibility(Int_t layer,Bool_t visible,Bool_t detailed){
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917 switch(layer){
00918 case (Int_t)FGEO_BEAM_PIPE:
00919 fPromptVolume->FindNode("PIPE_1")->GetVolume()->FindNode("BERI_1")->SetVisibility(visible);
00920 fPromptVolume->FindNode("PIPE_1")->GetVolume()->FindNode("PSTR_1")->SetVisibility(kFALSE);
00921 fPromptVolume->FindNode("PIPE_1")->GetVolume()->FindNode("PSTR_2")->SetVisibility(kFALSE);
00922 fPromptVolume->FindNode("PIPE_1")->GetVolume()->FindNode("PTAI_1")->SetVisibility(detailed);
00923 fPromptVolume->FindNode("PIPE_1")->GetVolume()->FindNode("PTAI_2")->SetVisibility(detailed);
00924
00925
00926
00927
00928
00929
00930
00931 return;
00932 case (Int_t)FGEO_TOFINO:
00933 fPromptVolume->FindNode("ITOF_1")->GetVolume()->SetVisibility(visible);
00934 fPromptVolume->FindNode("ITOF_1")->GetVolume()->VisibleDaughters(visible && detailed);
00935 return;
00936 case (Int_t)FGEO_ISIM:
00937 fPromptVolume->FindNode("ISIM_1")->GetVolume()->SetVisibility(visible);
00938 fPromptVolume->FindNode("IGLA_1")->GetVolume()->SetVisibility(detailed);
00939 fPromptVolume->FindNode("IUPL_4")->GetVolume()->SetVisibility(detailed);
00940 return;
00941 case (Int_t)FGEO_TARGETS:
00942 for(Int_t i=0;i<8;i++){
00943 fTgtNodes[i]->GetVolume()->SetVisibility(visible);
00944 fTgtNodes[i]->GetVolume()->VisibleDaughters(detailed);
00945 }
00946 if(fSetup==(Int_t)FGEO_2006) fPromptVolume->FindNode("DEG5_1")->SetVisibility(visible && detailed);
00947 return;
00948 case (Int_t)FGEO_OSIM:
00949 fPromptVolume->FindNode("OSIM_1")->GetVolume()->SetVisibility(visible);
00950 fPromptVolume->FindNode("OGLA_1")->GetVolume()->SetVisibility(detailed);
00951 fPromptVolume->FindNode("OUPL_6")->GetVolume()->SetVisibility(detailed);
00952 return;
00953 case (Int_t)FGEO_INNER_LMD:
00954 SetLmdLayVis(0,visible,detailed);
00955 return;
00956 case (Int_t)FGEO_OUTER_LMD:
00957 SetLmdLayVis(1,visible,detailed);
00958 return;
00959 case (Int_t)FGEO_STRAW_TUBES:
00960 for(Int_t i=0;i<6;i++) SetStbLayVis(i,visible,detailed);
00961 return;
00962 case (Int_t)FGEO_STRAW_TUBES_1:
00963 SetStbLayVis(0,visible,detailed);
00964 return;
00965 case (Int_t)FGEO_STRAW_TUBES_2:
00966 SetStbLayVis(1,visible,detailed);
00967 return;
00968 case (Int_t)FGEO_STRAW_TUBES_3:
00969 SetStbLayVis(2,visible,detailed);
00970 return;
00971 case (Int_t)FGEO_STRAW_TUBES_4:
00972 SetStbLayVis(3,visible,detailed);
00973 return;
00974 case (Int_t)FGEO_STRAW_TUBES_5:
00975 SetStbLayVis(4,visible,detailed);
00976 return;
00977 case (Int_t)FGEO_STRAW_TUBES_6:
00978 SetStbLayVis(5,visible,detailed);
00979 return;
00980
00981 case (Int_t)FGEO_TOFONE:
00982 fPromptVolume->FindNode("ETOF_1")->GetVolume()->SetVisibility(visible);
00983 fPromptVolume->FindNode("ETOF_1")->GetVolume()->VisibleDaughters(visible && detailed);
00984 return;
00985 default:
00986 Warning("SetLayerVisibility","The selected layer was not accepted (id = %d)",layer);
00987 return;
00988 }
00989
00990 }
00991
00992
00993 void TFndGeometry::SetStructureVisibility(Bool_t visible,Int_t detail_lev){
00994
00995
00996
00997 fPromptVolume->FindNode("MCRA_1")->GetVolume()->SetVisibility(visible);
00998 fPromptVolume->FindNode("MCRA_1")->GetVolume()->VisibleDaughters((Bool_t)detail_lev);
00999
01000
01001 Bool_t flcvis = (detail_lev >= 4) ? kTRUE: kFALSE;
01002 Bool_t rin5vis = (detail_lev >= 5) ? kTRUE: kFALSE;
01003 Bool_t flavis = (detail_lev >= 6) ? kTRUE: kFALSE;
01004 Bool_t magvis3 = (detail_lev >= 7) ? kTRUE: kFALSE;
01005 Bool_t magvis2 = (detail_lev >= 8) ? kTRUE: kFALSE;
01006 Bool_t magvis1 = (detail_lev >= 9) ? kTRUE: kFALSE;
01007
01008 fPromptVolume->FindNode("MAG1_1")->SetVisibility(magvis1);
01009 fPromptVolume->FindNode("MAG1_2")->SetVisibility(magvis1);
01010 fPromptVolume->FindNode("MAG2_1")->SetVisibility(magvis2);
01011 fPromptVolume->FindNode("MAG2_2")->SetVisibility(magvis2);
01012 fPromptVolume->FindNode("MAG3_1")->SetVisibility(magvis3);
01013
01014 fPromptVolume->FindNode("FLCN_1")->SetVisibility(flcvis);
01015 fPromptVolume->FindNode("FLCN_2")->SetVisibility(flcvis);
01016
01017 fPromptVolume->FindNode("COIL_1")->SetVisibility(kFALSE);
01018
01019 fPromptVolume->FindNode("CCOM_1")->SetVisibility(kFALSE);
01020 fPromptVolume->FindNode("CCOM_2")->SetVisibility(kFALSE);
01021 fPromptVolume->FindNode("PBEL_1")->SetVisibility(kFALSE);
01022 fPromptVolume->FindNode("PBEL_2")->SetVisibility(kFALSE);
01023
01024 fPromptVolume->FindNode("MCP1_1")->SetVisibility(kFALSE);
01025 fPromptVolume->FindNode("MCP1_2")->SetVisibility(kFALSE);
01026 fPromptVolume->FindNode("MCP2_1")->SetVisibility(kFALSE);
01027 fPromptVolume->FindNode("MCP2_2")->SetVisibility(kFALSE);
01028
01029 fPromptVolume->FindNode("FLA1_1")->SetVisibility(flavis);
01030 fPromptVolume->FindNode("FLA1_2")->SetVisibility(flavis);
01031 fPromptVolume->FindNode("FLA2_1")->SetVisibility(flavis);
01032 fPromptVolume->FindNode("FLA2_2")->SetVisibility(flavis);
01033
01034 fPromptVolume->FindNode("BAG1_1")->SetVisibility(kFALSE);
01035 fPromptVolume->FindNode("STST_1")->SetVisibility(kFALSE);
01036
01037 fPromptVolume->FindNode("RIN5_1")->SetVisibility(rin5vis);
01038 fPromptVolume->FindNode("RIN5_2")->SetVisibility(rin5vis);
01039
01040 Bool_t rinvis = (detail_lev >= 3) ? kTRUE: kFALSE;
01041 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN1_1")->SetVisibility(rinvis);
01042 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN1_2")->SetVisibility(rinvis);
01043 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN2_1")->SetVisibility(rinvis);
01044 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN2_2")->SetVisibility(rinvis);
01045 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN3_1")->SetVisibility(rinvis);
01046 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode("RIN3_2")->SetVisibility(rinvis);
01047
01048
01049 TString mdcstr = "";
01050 TString beastr = "";
01051 Bool_t mdcvis = (detail_lev >= 1) ? kTRUE: kFALSE;
01052 Bool_t beavis = (detail_lev >= 2) ? kTRUE: kFALSE;
01053
01054 for(Int_t l=1;l<=2;l++){
01055 for(Int_t c=1;c<=16;c++){
01056 mdcstr.Form("MDC%d_%d",l,c);
01057 beastr.Form("BEA%d_%d",l,c);
01058 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode(mdcstr.Data())->SetVisibility(mdcvis);
01059 fPromptVolume->FindNode("BAG2_1")->GetVolume()->FindNode(beastr.Data())->SetVisibility(beavis);
01060 }
01061 }
01062
01063 }
01064
01065
01066 void TFndGeometry::SetLmdLayVis(Int_t lay,Bool_t visible,Bool_t detailed){
01067
01068 Int_t offset = (Int_t)(lay * 8);
01069 TGeoNode *cnod = fPromptVolume->FindNode("BAG2_1")->GetDaughter(offset)->GetDaughter(0)->GetDaughter(0);
01070 gGeoManager->SetVisOption(0);
01071 cnod->GetVolume()->SetVisibility(visible);
01072 cnod->GetVolume()->VisibleDaughters(detailed && visible);
01073 cnod->GetDaughter(0)->GetVolume()->SetVisibility(visible && detailed);
01074 }
01075
01076
01077 void TFndGeometry::SetStbLayVis(Int_t lay,Bool_t visible,Bool_t detailed){
01078
01079 TString nnam;
01080 Int_t offset = 0;
01081
01082 if(lay<2){
01083 nnam = "SSTR_1";
01084 }
01085 else if(lay<4){
01086 nnam = "TSTR_1";
01087 }
01088 else if(lay<6){
01089 nnam = "TSTR_1";
01090 offset = 810;
01091 }
01092 else{
01093 Error("SetStbLayVis","BUG!");
01094 gApplication->Terminate();
01095 }
01096
01097 TGeoNode *cnod = fPromptVolume->FindNode(nnam);
01098 if(!cnod){
01099 Error("SetStbLayVis","BUG!");
01100 gApplication->Terminate();
01101 }
01102
01103 gGeoManager->SetVisOption(0);
01104
01105 cnod->GetVolume()->VisibleDaughters(visible && detailed);
01106 cnod->GetVolume()->SetVisibility(visible && !detailed);
01107 cnod->GetDaughter(offset+lay)->GetVolume()->SetVisibility(visible && detailed);
01108
01109 }
01110
01111
01112
01113
01114