00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 using namespace std;
00012
00013 #include <string>
00014 #include <fstream>
00015 #include <iostream>
00016 #include <sstream>
00017 #include <vector>
00018 #include <iomanip>
00019
00020 #include <TGeoManager.h>
00021
00022 #include "ROOTGeo/TofROOTGeo.h"
00023
00024 TofROOTGeo::TofROOTGeo()
00025 {
00026
00027 for (int part = 0; part < m_kPart; part++) {
00028 for (int scin = 0; scin < m_kAssemblyBr; scin++) {
00029 m_NodeScin[part][scin] = 0;
00030 m_PhysicalScin[part][scin] = 0;
00031 }
00032 }
00033 }
00034
00035 TofROOTGeo::~TofROOTGeo()
00036 { }
00037
00038 void
00039 TofROOTGeo::InitFromGdml( const char *gdmlFile, const char *setupName )
00040 {
00041 ReadGdml(gdmlFile, setupName);
00042 SetNode();
00043 SetDefaultVis();
00044
00045 m_ROOTGeoInit = 1;
00046 }
00047
00048 void
00049 TofROOTGeo::SetNode()
00050 {
00051 m_Tof = GetTopVolume();
00052 if(!m_Tof) std::cout << "m_Tof = 0" << std::endl;
00053
00054 for (int part = 0; part < m_kPart; part++) {
00055 int nScin = 0;
00056 if (part == 1) nScin = m_kAssemblyBr;
00057 else nScin = m_kAssemblyEc;
00058 for (int scin = 0; scin < nScin; scin++) {
00059 std::stringstream osname;
00060 if (part == 0) {
00061 osname << "pv_" << "logical" << "Tof" << "ScinEc" << "_" << m_kAssemblyBr + m_kAssemblyEc + scin << "_0";
00062 }
00063 else if (part == 1) {
00064 osname << "pv_" << "logical" << "Tof" << "ScinBr" << "_" << scin << "_0";
00065 }
00066 else if (part == 2) {
00067 osname << "pv_" << "logical" << "Tof" << "ScinEc" << "_" << m_kAssemblyBr + scin << "_0";
00068 }
00069
00070 m_NodeScin[part][scin] = GetNode( osname.str() );
00071 }
00072 }
00073 }
00074
00075 void
00076 TofROOTGeo::SetDefaultVis()
00077 {
00078
00079 int tofColor = 2;
00080 int scinColor = 6;
00081 int bucketColor = 4;
00082
00083 m_Tof->SetLineColor(tofColor);
00084 m_Tof->SetVisibility(0);
00085
00086 for (int part = 0; part < m_kPart; part++) {
00087 GetVolumeScin(part)->SetLineColor(scinColor);
00088 GetVolumeScin(part)->SetVisibility(1);
00089 GetVolumeBucket(part)->SetLineColor(bucketColor);
00090 GetVolumeBucket(part)->SetVisibility(0);
00091
00092 int nScin = 0;
00093 if (part == 1) nScin = m_kAssemblyBr;
00094 else nScin = m_kAssemblyEc;
00095 for (int scin = 0; scin < nScin; scin++) {
00096 GetScin(part, scin)->SetVisibility(0);
00097
00098 int nBucket = 0;
00099 if (part == 1) nBucket = m_kBucketBr;
00100 else nBucket = m_kBucketEc;
00101 for (int bucket = 0; bucket < nBucket; bucket++) {
00102 GetBucket(part, scin, bucket)->SetVisibility(0);
00103 }
00104 }
00105 }
00106
00107 }
00108
00109 void
00110 TofROOTGeo::SetAllVisible()
00111 {
00112 for (int part = 0; part < m_kPart; part++) {
00113 GetVolumeScin(part)->SetVisibility(1);
00114 GetVolumeBucket(part)->SetVisibility(1);
00115
00116 int nScin = 0;
00117 if (part == 1) nScin = m_kAssemblyBr;
00118 else nScin = m_kAssemblyEc;
00119 for (int scin = 0; scin < nScin; scin++) {
00120 GetScin(part, scin)->SetVisibility(1);
00121
00122 int nBucket = 0;
00123 if (part == 1) nBucket = m_kBucketBr;
00124 else nBucket = m_kBucketEc;
00125 for (int bucket = 0; bucket < nBucket; bucket++) {
00126 GetBucket(part, scin, bucket)->SetVisibility(1);
00127 }
00128 }
00129 }
00130 }
00131
00132 void
00133 TofROOTGeo::SetQuarterVisible()
00134 {
00135 for (int part = 0; part < m_kPart; part++) {
00136 GetVolumeScin(part)->SetVisibility(1);
00137 GetVolumeBucket(part)->SetVisibility(1);
00138
00139 int nScin = 0;
00140 if (part == 1) nScin = m_kAssemblyBr;
00141 else nScin = m_kAssemblyEc;
00142 for (int scin = 0; scin < nScin; scin++) {
00143 if (scin < nScin/4) GetScin(part, scin)->SetVisibility(0);
00144 else GetScin(part, scin)->SetVisibility(1);
00145
00146 int nBucket = 0;
00147 if (part == 1) nBucket = m_kBucketBr;
00148 else nBucket = m_kBucketEc;
00149 for (int bucket = 0; bucket < nBucket; bucket++) {
00150 if (scin < nScin/4) GetBucket(part, scin, bucket)->SetVisibility(0);
00151 else GetBucket(part, scin, bucket)->SetVisibility(1);
00152 }
00153 }
00154 }
00155 }
00156
00157 void
00158 TofROOTGeo::SetPhysicalNode()
00159 {
00160 int scinColor = 6;
00161
00162 if (gGeoManager == 0) std::cout << "Create gGeoManager first" << std::endl;
00163 TGeoNode *bes = gGeoManager->GetTopNode();
00164
00165 TGeoNode *tof = bes->GetDaughter(m_childNo);
00166
00167 for (int part = 0; part < m_kPart; part++) {
00168 int nScin = 0;
00169 if (part == 1) nScin = m_kAssemblyBr;
00170 else nScin = m_kAssemblyEc;
00171 for (int scin = 0; scin < nScin; scin++) {
00172 TGeoNode *nodeScin = GetScin(part, scin);
00173 m_PhysicalScin[part][scin] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
00174 TString("/") + tof->GetName() +
00175 TString("/") + nodeScin->GetName() );
00176 m_PhysicalScin[part][scin]->SetVisibility(0);
00177 m_PhysicalScin[part][scin]->SetIsVolAtt(kFALSE);
00178 m_PhysicalScin[part][scin]->SetLineColor(scinColor);
00179 }
00180 }
00181 }
00182
00183 int
00184 TofROOTGeo::GetPartNb()
00185 {
00186 int nPart = m_kPart;
00187 return nPart;
00188 }
00189
00190 int
00191 TofROOTGeo::GetScinNb(int part)
00192 {
00193 int nScin = m_kAssemblyBr;
00194 if (part != 1) nScin = m_kAssemblyEc;
00195 return nScin;
00196 }
00197
00198 TGeoVolumeAssembly*
00199 TofROOTGeo::GetVolumeAssembly( int part )
00200 {
00201 std::stringstream osname;
00202 if (part == 0 || part == 2) {
00203 osname << "logical" << "Tof" << "AssemblyEc";
00204 }
00205 else {
00206 if (part == 1) {
00207 osname << "logical" << "Tof" << "AssemblyBr";
00208 }
00209 }
00210
00211 return GetAssemblyVolume( osname.str() );
00212 }
00213
00214 TGeoVolume*
00215 TofROOTGeo::GetVolumeScin( int part )
00216 {
00217 std::stringstream osname;
00218 if (part == 0 || part == 2) {
00219 osname << "logical" << "Tof" << "ScinEc";
00220 }
00221 else {
00222 if (part == 1) {
00223 osname << "logical" << "Tof" << "ScinBr";
00224 }
00225 }
00226
00227 return GetLogicalVolume( osname.str() );
00228 }
00229
00230 TGeoVolume*
00231 TofROOTGeo::GetVolumeBucket( int part )
00232 {
00233 std::stringstream osname;
00234 if (part == 0 || part == 2) {
00235 osname << "logical" << "Tof" << "BucketEc";
00236 }
00237 else {
00238 if (part == 1) {
00239 osname << "logical" << "Tof" << "BucketBr";
00240 }
00241 }
00242
00243 return GetLogicalVolume( osname.str() );
00244 }
00245
00246 TGeoNode*
00247 TofROOTGeo::GetScin( int part, int scin )
00248 {
00249 if (m_NodeScin[part][scin] != 0) {
00250 return m_NodeScin[part][scin];
00251 }
00252 else {
00253 std::cout << "Node: " << "Part" << part << "Scin" << scin << " not found" << std::endl;
00254 return 0;
00255 }
00256
00257 return m_NodeScin[part][scin];
00258 }
00259
00260 TGeoNode *
00261 TofROOTGeo::GetBucket( int part, int scin, int bucket )
00262 {
00263 std::stringstream osname;
00264 if (part == 0) {
00265 osname << "pv_" << "logical" << "Tof" << "BucketEc" << "_" << m_kAssemblyBr + m_kAssemblyEc + scin << "_1";
00266 }
00267 else if (part == 1) {
00268 osname << "pv_" << "logical" << "Tof" << "BucketBr" << "_" << scin << "_" << bucket+1;
00269 }
00270 else if (part == 2) {
00271 osname << "pv_" << "logical" << "Tof" << "BucketEc" << "_" << m_kAssemblyBr + scin << "_1";
00272 }
00273
00274 return GetNode( osname.str() );
00275 }
00276
00277 TGeoPhysicalNode*
00278 TofROOTGeo::GetPhysicalScin( int part, int scin )
00279 {
00280 if (m_PhysicalScin[part][scin] != 0) {
00281 return m_PhysicalScin[part][scin];
00282 }
00283 else {
00284 std::cout << "PhysicalNode: " << "Part" << part << "Scin" << scin << " not found" << std::endl;
00285 return 0;
00286 }
00287 }
00288