diff --git a/Inputs/DetectorConfiguration/Microball.detector b/Inputs/DetectorConfiguration/Microball.detector index 899818c09149c6261acb082274ed90bbae674ac5..512f2cc8b43b9382107f8e261d85937ed456d61c 100644 --- a/Inputs/DetectorConfiguration/Microball.detector +++ b/Inputs/DetectorConfiguration/Microball.detector @@ -11,32 +11,32 @@ Target Z= 0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Microball - RING1= 0 - RING2= 0 - RING3= 0 - RING4= 0 + RING1= 1 + RING2= 1 + RING3= 1 + RING4= 1 RING5= 1 RING6= 1 - RING7= 0 - RING8= 0 - RING9= 0 - DISABLE_CRYSTAL 1 - DISABLE_CRYSTAL 2 - DISABLE_CRYSTAL 7 - DISABLE_CRYSTAL 8 - DISABLE_CRYSTAL 17 - DISABLE_CRYSTAL 18 - DISABLE_CRYSTAL 29 - DISABLE_CRYSTAL 30 - DISABLE_CRYSTAL 41 - DISABLE_CRYSTAL 42 - DISABLE_CRYSTAL 55 - DISABLE_CRYSTAL 56 - DISABLE_CRYSTAL 69 - DISABLE_CRYSTAL 70 - DISABLE_CRYSTAL 81 - DISABLE_CRYSTAL 82 - DISABLE_CRYSTAL 91 - DISABLE_CRYSTAL 92 + RING7= 1 + RING8= 1 + RING9= 1 + %DISABLE_CRYSTAL 1 + %DISABLE_CRYSTAL 2 + %DISABLE_CRYSTAL 7 + %DISABLE_CRYSTAL 8 + %DISABLE_CRYSTAL 17 + %DISABLE_CRYSTAL 18 + %DISABLE_CRYSTAL 29 + %DISABLE_CRYSTAL 30 + %DISABLE_CRYSTAL 41 + %DISABLE_CRYSTAL 42 + %DISABLE_CRYSTAL 55 + %DISABLE_CRYSTAL 56 + %DISABLE_CRYSTAL 69 + %DISABLE_CRYSTAL 70 + %DISABLE_CRYSTAL 81 + %DISABLE_CRYSTAL 82 + %DISABLE_CRYSTAL 91 + %DISABLE_CRYSTAL 92 CRYSTALS_DONE diff --git a/Inputs/DetectorConfiguration/csi.detector b/Inputs/DetectorConfiguration/csi.detector index 02f021dfae83ce1b2f642d023e18af49373f8473..bd499a276c04e17084f4806485279ae6eaf58423 100644 --- a/Inputs/DetectorConfiguration/csi.detector +++ b/Inputs/DetectorConfiguration/csi.detector @@ -1,86 +1,69 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GeneralTarget %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Thickness in micrometer % Radius in mm % Temperature in K, Pressure in bar Target - THICKNESS= 0.001 - ANGLE= 0 - RADIUS= 2 - MATERIAL= CH2 - X= 0 - Y= 0 - Z= 0 + THICKNESS= 0.1 + ANGLE= 0 + RADIUS= 10 + MATERIAL= CD2 + X= 0 + Y= 0 + Z= 0 + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ScintillatorCsI +%ScintillatorCsI %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -CsI +%CsI THETA= 0 PHI= 0 R= 0 - X= 0 - Y= 0 - Z= 58 - Thickness= 100 + X= 0 + Y= 0 + Z= 15 + Thickness= 0.0001 Shape= Trapezoidal - FaceFront= 34 - FaceBack= 44 + FaceFront= 1000 + FaceBack= 1000 Radius= 0 - Scintillator= CsI_Scintillator + Scintillator= CsI LeadThickness= 0 - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ScintillatorPlastic %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%Plastic -% THETA= 0 -% PHI= 0 -% R= 0 -% X= 0 -% Y= 0 -% Z= 389.25 -% Thickness= 1.5 -% Shape= Square -% Height= 22 -% Width= 22 -% Radius= 0 -% Scintillator= Si -% LeadThickness= 0 -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%Plastic -% THETA= 0 -% PHI= 0 -% R= 0 -% X= 0 -% Y= 0 -% -% Z= 505 -% Thickness= 10 -% Shape= Square -% Height= 27 -% Width= 27 -% Radius= 0 -% Scintillator= Epoxy -% LeadThickness= 0 +Plastic + THETA= 0 + PHI= 0 + R= 0 + X= 0 + Y= 0 + Z= 1 + Thickness= 1.0 + Shape= Square + Height= 10 + Width= 10 + Radius= 0 + Scintillator= Pb + LeadThickness= 0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%Plastic -% THETA= 0 -% PHI= 0 -% R= 0 -% X= 0 -% Y= 0 -% Z= 510.15 -% Thickness= 0.3 -% Shape= Square -% Height= 27 -% Width= 27 -% Radius= 0 -% Scintillator= Si -% LeadThickness= 0 -% -% +Plastic + THETA= 0 + PHI= 0 + R= 0 + X= 0 + Y= 0 + Z= 250 + Thickness= 200 + Shape= Square + Height= 300 + Width= 300 + Radius= 0 + Scintillator= CsI + LeadThickness= 0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Avaible material: % BC400 diff --git a/Inputs/DetectorConfiguration/plastic.detector b/Inputs/DetectorConfiguration/plastic.detector index 0111b33aa4157a9f8735552a544654c633c9caca..5558ccc3fbf2e9ac34702332a0f67fbd17e159fe 100644 --- a/Inputs/DetectorConfiguration/plastic.detector +++ b/Inputs/DetectorConfiguration/plastic.detector @@ -15,24 +15,24 @@ Target %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ScintillatorPlastic %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Plastic - THETA= 0 - PHI= 0 - R= 150 - Thickness= 20 - Radius= 50 - Scintillator= Kapton - LeadThickness= 0 - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ScintillatorPlastic %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plastic THETA= 0 PHI= 0 - R= 175 - Thickness= 20 - Radius= 50 - Scintillator= BC452_5 + R= 0 + X= 0 + Y= 0 + Z= 10 + Thickness= 1.0 + Shape= Square + Height= 22 + Width= 22 + Radius= 0 + Scintillator= BC400 LeadThickness= 0 + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Avaible material: diff --git a/Inputs/EventGenerator/proton.source b/Inputs/EventGenerator/proton.source index 3d8202747388187085a4433a48876d31059b679c..e267c593ecef5d20a3fe74fd76caacab255b7f6e 100644 --- a/Inputs/EventGenerator/proton.source +++ b/Inputs/EventGenerator/proton.source @@ -4,10 +4,10 @@ % Energy are given in MeV , Position in mm % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Isotropic - EnergyLow= 0 - EnergyHigh= 250 - HalfOpenAngleMin= 0 - HalfOpenAngleMax= 180 + EnergyLow= 60 + EnergyHigh= 60 + HalfOpenAngleMin= 0 + HalfOpenAngleMax= 0 x0= 0 y0= 0 z0= 0 diff --git a/NPLib/Detectors/CsI/TCsIPhysics.cxx b/NPLib/Detectors/CsI/TCsIPhysics.cxx index 46e67f8a95a4ff10f68cc1492874b608f3881d9b..cb9410b88262fb2197ca5ff0a9b6043737f32097 100644 --- a/NPLib/Detectors/CsI/TCsIPhysics.cxx +++ b/NPLib/Detectors/CsI/TCsIPhysics.cxx @@ -41,262 +41,328 @@ using namespace std; // tranform an integer to a string string itoa(int value) { - char buffer [33]; - sprintf(buffer,"%d",value); - return buffer; + char buffer [33]; + sprintf(buffer,"%d",value); + return buffer; } ClassImp(TCsIPhysics) /////////////////////////////////////////////////////////////////////////// TCsIPhysics::TCsIPhysics() - { - NumberOfDetector = 0 ; - EventData = new TCsIData ; - EventPhysics = this ; - } - +{ + NumberOfDetector = 0 ; + EventData = new TCsIData ; + EventPhysics = this ; +} + /////////////////////////////////////////////////////////////////////////// TCsIPhysics::~TCsIPhysics() - {} - +{} + /////////////////////////////////////////////////////////////////////////// void TCsIPhysics::Clear() - { - DetectorNumber.clear() ; - Energy.clear() ; - Time.clear() ; - } - -/////////////////////////////////////////////////////////////////////////// -void TCsIPhysics::ReadConfiguration(string Path) - { - ifstream ConfigFile ; - ConfigFile.open(Path.c_str()) ; - string LineBuffer ; - string DataBuffer ; - - bool check_Theta = false ; - bool check_Phi = false ; - bool check_R = false ; - bool check_Thickness = false ; - bool check_Radius = false ; - bool check_LeadThickness = false ; - bool check_Scintillator = false ; - bool check_Height = false ; - bool check_Width = false ; - bool check_Shape = false ; - bool check_X = false ; - bool check_Y = false ; - bool check_Z = false ; - bool ReadingStatus = false ; - - while (!ConfigFile.eof()) - { - - getline(ConfigFile, LineBuffer); +{ + DetectorNumber.clear() ; + Energy.clear() ; + Time.clear() ; +} - // If line is a Start Up CsI bloc, Reading toggle to true - if (LineBuffer.compare(0, 3, "CsI") == 0) - { - cout << "///" << endl ; - cout << "Platic found: " << endl ; - ReadingStatus = true ; +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::ReadConfiguration(string Path) +{ + ifstream ConfigFile ; + ConfigFile.open(Path.c_str()) ; + string LineBuffer ; + string DataBuffer ; + + double Theta = 0 , Phi = 0 , R = 0 , Thickness = 0 , Radius = 0 ; + double LeadThickness = 0, X = 0 , Y = 0 , Z = 0 , FaceFront = 0 , FaceBack = 0 ; + string Scintillator, Shape ; + + bool check_Theta = false ; + bool check_Phi = false ; + bool check_R = false ; + bool check_Thickness = false ; + bool check_Radius = false ; + bool check_LeadThickness = false ; + bool check_Scintillator = false ; + bool check_FaceFront = false ; + bool check_FaceBack = false ; + bool check_Shape = false ; + bool check_X = false ; + bool check_Y = false ; + bool check_Z = false ; + bool ReadingStatus = false ; + + + while (!ConfigFile.eof()) { + getline(ConfigFile, LineBuffer); + + // If line is a Start Up CsI bloc, Reading toggle to true + if (LineBuffer.compare(0, 3, "CsI") == 0) { + cout << "///" << endl ; + cout << "CsI found: " << endl ; + ReadingStatus = true ; + + } + + // Else don't toggle to Reading Block Status + else ReadingStatus = false ; + + // Reading Block + while(ReadingStatus){ + // Pickup Next Word + ConfigFile >> DataBuffer ; + + // Comment Line + if (DataBuffer.compare(0, 1, "%") == 0) { + ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' ); } - // Else don't toggle to Reading Block Status - else ReadingStatus = false ; - - // Reading Block - while(ReadingStatus) - { - // Pickup Next Word - ConfigFile >> DataBuffer ; - - // Comment Line - if (DataBuffer.compare(0, 1, "%") == 0) { ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );} - - // Finding another telescope (safety), toggle out - else if (DataBuffer.compare(0, 6, "CsI") == 0) { - cout << "WARNING: Another Detector is find before standard sequence of Token, Error may occured in Telecope definition" << endl ; - ReadingStatus = false ; - } - - //Angle method - else if (DataBuffer=="THETA=") { - check_Theta = true; - ConfigFile >> DataBuffer ; - cout << "Theta: " << atof(DataBuffer.c_str()) << "deg" << endl; - } - - else if (DataBuffer=="PHI=") { - check_Phi = true; - ConfigFile >> DataBuffer ; - cout << "Phi: " << atof( DataBuffer.c_str() ) << "deg" << endl; - } - - else if (DataBuffer=="R=") { - check_R = true; - ConfigFile >> DataBuffer ; - cout << "R: " << atof( DataBuffer.c_str() ) << "mm" << endl; - } - - //Position method - else if (DataBuffer=="X=") { - check_X = true; - ConfigFile >> DataBuffer ; - cout << "X: " << atof( DataBuffer.c_str() ) << "mm" << endl; - } - - else if (DataBuffer=="Y=") { - check_Y = true; - ConfigFile >> DataBuffer ; - cout << "Y: " << atof( DataBuffer.c_str() ) << "mm"<< endl; - } - - else if (DataBuffer=="Z=") { - check_Z = true; - ConfigFile >> DataBuffer ; - cout << "Z: " << atof( DataBuffer.c_str() ) << "mm" << endl; - } - - - //General - else if (DataBuffer=="Shape=") { - check_Shape = true; - ConfigFile >> DataBuffer ; - cout << "Shape: " << DataBuffer << endl; - } - - // Cylindrical shape - else if (DataBuffer== "Radius=") { - check_Radius = true; - ConfigFile >> DataBuffer ; - cout << "CsI Radius: " << atof( DataBuffer.c_str() ) << "mm" << endl; - } - - // Squared shape - else if (DataBuffer=="Width=") { - check_Width = true; - ConfigFile >> DataBuffer ; - cout << "CsI Width: " <<atof( DataBuffer.c_str() ) << "mm" << endl; - } - - else if (DataBuffer== "Height=") { - check_Height = true; - ConfigFile >> DataBuffer ; - cout << "CsI Height: " << atof( DataBuffer.c_str() ) << "mm" << endl; - } - - // Common - else if (DataBuffer=="Thickness=") { - check_Thickness = true; - ConfigFile >> DataBuffer ; - cout << "CsI Thickness: " << atof( DataBuffer.c_str() ) << "mm" << endl; - } - - else if (DataBuffer== "Scintillator=") { - check_Scintillator = true ; - ConfigFile >> DataBuffer ; - cout << "CsI Scintillator type: " << DataBuffer << endl; - } - - else if (DataBuffer=="LeadThickness=") { - check_LeadThickness = true; - ConfigFile >> DataBuffer ; - cout << "Lead Thickness : " << atof( DataBuffer.c_str() ) << "mm" << endl; - } - - /////////////////////////////////////////////////// - // If no Detector Token and no comment, toggle out - else - {ReadingStatus = false; cout << "Wrong Token Sequence: Getting out " << DataBuffer << endl ;} - - ///////////////////////////////////////////////// - // If All necessary information there, toggle out - - if ( check_Theta && check_Phi && check_R && check_Thickness && check_Radius && check_LeadThickness && check_Scintillator && check_Height && check_Width && check_Shape && check_X && check_Y && check_Z ) - { - NumberOfDetector++; - - // Reinitialisation of Check Boolean - check_Theta = false ; - check_Phi = false ; - check_R = false ; - check_Thickness = false ; - check_Radius = false ; - check_LeadThickness = false ; - check_Scintillator = false ; - check_Height = false ; - check_Width = false ; - check_Shape = false ; - check_X = false ; - check_Y = false ; - check_Z = false ; - ReadingStatus = false ; - cout << "///"<< endl ; - } + // Finding another telescope (safety), toggle out + else if (DataBuffer.compare(0, 3, "CsI") == 0) { + cout << "WARNING: Another Telescope is find before standard sequence of Token, Error may occured in Telecope definition" << endl ; + ReadingStatus = false ; + } + + //Angle method + else if (DataBuffer.compare(0, 6, "THETA=") == 0) { + check_Theta = true; + ConfigFile >> DataBuffer ; + Theta = atof(DataBuffer.c_str()) ; + Theta = Theta ; + cout << "Theta: " << Theta << " deg" << endl; + } + + else if (DataBuffer.compare(0, 4, "PHI=") == 0) { + check_Phi = true; + ConfigFile >> DataBuffer ; + Phi = atof(DataBuffer.c_str()) ; + Phi = Phi ; + cout << "Phi: " << Phi << " deg" << endl; + } + + else if (DataBuffer.compare(0, 2, "R=") == 0) { + check_R = true; + ConfigFile >> DataBuffer ; + R = atof(DataBuffer.c_str()) ; + R = R ; + cout << "R: " << R << " mm" << endl; + } + + //Position method + else if (DataBuffer.compare(0, 2, "X=") == 0) { + check_X = true; + ConfigFile >> DataBuffer ; + X = atof(DataBuffer.c_str()) ; + X = X ; + cout << "X: " << X << " mm" << endl; + } + + else if (DataBuffer.compare(0, 2, "Y=") == 0) { + check_Y = true; + ConfigFile >> DataBuffer ; + Y = atof(DataBuffer.c_str()) ; + Y = Y ; + cout << "Y: " << Y << " mm" << endl; + } + + else if (DataBuffer.compare(0, 2, "Z=") == 0) { + check_Z = true; + ConfigFile >> DataBuffer ; + Z = atof(DataBuffer.c_str()) ; + Z = Z ; + cout << "Z: " << Z << " mm" << endl; + } + + + //General + else if (DataBuffer.compare(0, 6, "Shape=") == 0) { + check_Shape = true; + ConfigFile >> DataBuffer ; + Shape = DataBuffer ; + cout << "Shape: " << Shape << endl; + } + + // Cylindrical shape + else if (DataBuffer.compare(0, 7, "Radius=") == 0) { + check_Radius = true; + ConfigFile >> DataBuffer ; + Radius = atof(DataBuffer.c_str()) ; + Radius = Radius ; + cout << "CsI Radius: " << Radius << " mm" << endl; + } + + // Trapezoidal shape + else if (DataBuffer.compare(0, 10, "FaceFront=") == 0) { + check_FaceFront = true; + ConfigFile >> DataBuffer ; + FaceFront = atof(DataBuffer.c_str()) ; + FaceFront = FaceFront; + cout << "CsI FaceFront: " << FaceFront << " mm" << endl; + } + + else if (DataBuffer.compare(0, 9, "FaceBack=") == 0) { + check_FaceBack = true; + ConfigFile >> DataBuffer ; + FaceBack = atof(DataBuffer.c_str()) ; + FaceBack = FaceBack ; + cout << "CsI FaceBack: " << FaceBack << " mm" << endl; + } + + // Common + else if (DataBuffer.compare(0, 10, "Thickness=") == 0) { + check_Thickness = true; + ConfigFile >> DataBuffer ; + Thickness = atof(DataBuffer.c_str()) ; + Thickness = Thickness; + cout << "CsI Thickness: " << Thickness << " mm" << endl; } - } - } + + else if (DataBuffer.compare(0, 13, "Scintillator=") == 0) { + check_Scintillator = true ; + ConfigFile >> DataBuffer ; + Scintillator = DataBuffer ; + cout << "CsI Scintillator type: " << Scintillator << endl; + } + + else if (DataBuffer.compare(0, 14, "LeadThickness=") == 0) { + check_LeadThickness = true; + ConfigFile >> DataBuffer ; + LeadThickness = atof(DataBuffer.c_str()) ; + LeadThickness = LeadThickness ; + cout << "Lead Thickness : " << LeadThickness << " mm" << endl; + } + + /////////////////////////////////////////////////// + // If no Detector Token and no comment, toggle out + else{ + ReadingStatus = false; + cout << "Wrong Token Sequence: Getting out " << DataBuffer << endl ; + } + + ///////////////////////////////////////////////// + // If All necessary information there, toggle out + + if (( check_Theta && check_Phi && check_R && check_Thickness + && check_Radius && check_LeadThickness && check_Scintillator + && check_Shape) // Cylindrical case + || + ( check_X && check_Y && check_Z && check_Thickness && check_Radius + && check_LeadThickness && check_Scintillator ) + || + ( check_Theta && check_Phi && check_R && check_Thickness + && check_FaceBack && check_FaceFront && check_LeadThickness + && check_Scintillator && check_Shape ) // Trapezoidal case + || + ( check_X && check_Y && check_Z && check_Thickness && check_FaceBack + && check_FaceFront && check_LeadThickness && check_Scintillator )) { + + if (check_X && check_Y && check_Z){ + R = sqrt (X*X+Y*Y+Z*Z); + Theta = acos(Z / (R) ); + Phi = atan2(Y,X); + } + + /*if (Shape == "Cylinder") + AddCsI( R , + Theta , + Phi , + Thickness , + Radius , + Scintillator , + LeadThickness ); + + else if (Shape == "Trapezoidal") + AddCsI( R , + Theta , + Phi , + FaceFront , + FaceBack , + Thickness , + Scintillator , + LeadThickness );*/ + + // Reinitialisation of Check Boolean + + check_Theta = false ; + check_Phi = false ; + check_R = false ; + check_Thickness = false ; + check_Radius = false ; + check_LeadThickness = false ; + check_Scintillator = false ; + check_FaceFront = false ; + check_FaceBack = false ; + check_Shape = false ; + check_X = false ; + check_Y = false ; + check_Z = false ; + ReadingStatus = false ; + cout << "///"<< endl ; + } + } + } +} /////////////////////////////////////////////////////////////////////////// void TCsIPhysics::AddParameterToCalibrationManager() - { - CalibrationManager* Cal = CalibrationManager::getInstance(); - - for(int i = 0 ; i < NumberOfDetector ; i++) - { - for( int j = 0 ; j < 16 ; j++) - { - Cal->AddParameter("CsI", "Detector"+itoa(i+1)+"_E","CsI_Detector"+itoa(i+1)+"_E") ; - Cal->AddParameter("CsI", "Detector"+itoa(i+1)+"_T","CsI_Detector"+itoa(i+1)+"_T") ; - } - - } - } - +{ + CalibrationManager* Cal = CalibrationManager::getInstance(); + + for(int i = 0 ; i < NumberOfDetector ; i++) + { + for( int j = 0 ; j < 16 ; j++) + { + Cal->AddParameter("CsI", "Detector"+itoa(i+1)+"_E","CsI_Detector"+itoa(i+1)+"_E") ; + Cal->AddParameter("CsI", "Detector"+itoa(i+1)+"_T","CsI_Detector"+itoa(i+1)+"_T") ; + } + + } +} + /////////////////////////////////////////////////////////////////////////// -void TCsIPhysics::InitializeRootInputRaw() - { - TChain* inputChain = RootInput::getInstance()->GetChain() ; - inputChain->SetBranchStatus ( "CsI" , true ) ; - inputChain->SetBranchStatus ( "fCsI_*" , true ) ; - inputChain->SetBranchAddress( "CsI" , &EventData ) ; - } +void TCsIPhysics::InitializeRootInputRaw() +{ + TChain* inputChain = RootInput::getInstance()->GetChain() ; + inputChain->SetBranchStatus ( "CsI" , true ) ; + inputChain->SetBranchStatus ( "fCsI_*" , true ) ; + inputChain->SetBranchAddress( "CsI" , &EventData ) ; +} /////////////////////////////////////////////////////////////////////////// void TCsIPhysics::InitializeRootInputPhysics() - { - TChain* inputChain = RootInput::getInstance()->GetChain(); - inputChain->SetBranchStatus ( "CsI", true ); - inputChain->SetBranchStatus ( "DetectorNumber", true ); - inputChain->SetBranchStatus ( "Energy", true ); - inputChain->SetBranchStatus ( "Time", true ); - inputChain->SetBranchAddress( "CsI", &EventPhysics ); - } +{ + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchStatus ( "CsI", true ); + inputChain->SetBranchStatus ( "DetectorNumber", true ); + inputChain->SetBranchStatus ( "Energy", true ); + inputChain->SetBranchStatus ( "Time", true ); + inputChain->SetBranchAddress( "CsI", &EventPhysics ); +} /////////////////////////////////////////////////////////////////////////// void TCsIPhysics::InitializeRootOutput() - { - TTree* outputTree = RootOutput::getInstance()->GetTree() ; - outputTree->Branch( "CsI" , "TCsIPhysics" , &EventPhysics ) ; - } +{ + TTree* outputTree = RootOutput::getInstance()->GetTree() ; + outputTree->Branch( "CsI" , "TCsIPhysics" , &EventPhysics ) ; +} /////////////////////////////////////////////////////////////////////////// void TCsIPhysics::BuildPhysicalEvent() - { - BuildSimplePhysicalEvent() ; - } +{ + BuildSimplePhysicalEvent() ; +} /////////////////////////////////////////////////////////////////////////// void TCsIPhysics::BuildSimplePhysicalEvent() - { - for(unsigned int i = 0 ; i < EventData->GetEnergyMult() ; i++) - { - DetectorNumber.push_back( EventData->GetENumber(i) ) ; - Energy.push_back( CalibrationManager::getInstance()->ApplyCalibration("CsI/Detector" + itoa( EventData->GetENumber(i) ) +"_E",EventData->GetEEnergy(i) ) ); - Time.push_back( CalibrationManager::getInstance()->ApplyCalibration( "CsI/Detector" + itoa( EventData->GetENumber(i) ) +"_T",EventData->GetTTime(i) ) ); - } - - } +{ + for(unsigned int i = 0 ; i < EventData->GetEnergyMult() ; i++) + { + DetectorNumber.push_back( EventData->GetENumber(i) ) ; + Energy.push_back( CalibrationManager::getInstance()->ApplyCalibration("CsI/Detector" + itoa( EventData->GetENumber(i) ) +"_E",EventData->GetEEnergy(i) ) ); + Time.push_back( CalibrationManager::getInstance()->ApplyCalibration( "CsI/Detector" + itoa( EventData->GetENumber(i) ) +"_T",EventData->GetTTime(i) ) ); + } + +} //////////////////////////////////////////////////////////////////////////////// // Construct Method to be pass to the DetectorFactory // diff --git a/NPSimulation/Core/CMakeLists.txt b/NPSimulation/Core/CMakeLists.txt index ade632670b93c175f115c1b1675c8d51cff067d1..0e1c8623ae2e5ad91659940b0ce83357bfd26a6e 100644 --- a/NPSimulation/Core/CMakeLists.txt +++ b/NPSimulation/Core/CMakeLists.txt @@ -1,2 +1,2 @@ -add_library(NPSCore SHARED CalorimeterScorers.cc EventAction.cc EventGeneratorParticleDecay.cc ObsoleteGeneralScorers.cc PrimaryGeneratorAction.cc Target.cc Chamber.cc EventGeneratorBeam.cc EventGeneratorTwoBodyReaction.cc EventGeneratorpBUU.cc Particle.cc PrimaryGeneratorActionMessenger.cc NPSVDetector.cc DetectorConstruction.cc EventGeneratorGammaDecay.cc MaterialManager.cc ParticleStack.cc SiliconScorers.cc PhotoDiodeScorers.cc VEventGenerator.cc DetectorMessenger.cc EventGeneratorIsotropic.cc MyMagneticField.cc PhysicsList.cc SteppingVerbose.cc NPSDetectorFactory.cc RunAction.cc) +add_library(NPSCore SHARED CalorimeterScorers.cc EventAction.cc EventGeneratorParticleDecay.cc ObsoleteGeneralScorers.cc PrimaryGeneratorAction.cc Target.cc Chamber.cc EventGeneratorBeam.cc EventGeneratorTwoBodyReaction.cc EventGeneratorpBUU.cc Particle.cc PrimaryGeneratorActionMessenger.cc NPSVDetector.cc DetectorConstruction.cc EventGeneratorGammaDecay.cc MaterialManager.cc ParticleStack.cc SiliconScorers.cc PhotoDiodeScorers.cc VEventGenerator.cc DetectorMessenger.cc EventGeneratorIsotropic.cc MyMagneticField.cc PhysicsList.cc SteppingVerbose.cc NPSDetectorFactory.cc RunAction.cc LocalIonIonInelasticPhysic.cc) target_link_libraries(NPSCore ${ROOT_LIBRARIES} ${Geant4_LIBRARIES} ${NPLib_LIBRARIES} -lNPInitialConditions -lNPInteractionCoordinates) diff --git a/NPSimulation/Core/CalorimeterScorers.cc b/NPSimulation/Core/CalorimeterScorers.cc index 17f997c9fbe75454281cc6e5b87e6ef0421b9c84..28295b95c721772198e0d8ad39c26027adad9289 100644 --- a/NPSimulation/Core/CalorimeterScorers.cc +++ b/NPSimulation/Core/CalorimeterScorers.cc @@ -1,4 +1,4 @@ - /***************************************************************************** +/***************************************************************************** * Copyright (C) 2009-2013 this file is part of the NPTool Project * * * * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * @@ -26,7 +26,7 @@ using namespace CALORIMETERSCORERS ; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... PS_Calorimeter::PS_Calorimeter(G4String name, vector<G4int> NestingLevel,G4int depth) :G4VPrimitiveScorer(name, depth),HCID(-1){ - m_NestingLevel = NestingLevel; + m_NestingLevel = NestingLevel; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -35,42 +35,42 @@ PS_Calorimeter::~PS_Calorimeter(){ //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4bool PS_Calorimeter::ProcessHits(G4Step* aStep, G4TouchableHistory*){ - // Contain Energy, Time + as many copy number as nested volume - unsigned int mysize = m_NestingLevel.size(); - G4double* Infos = new G4double[2+mysize]; - Infos[0] = aStep->GetTotalEnergyDeposit(); - Infos[1] = aStep->GetPreStepPoint()->GetGlobalTime(); - - for(unsigned int i = 0 ; i < mysize ; i++){ - Infos[i+2] = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_NestingLevel[i]); - } - - m_Index = 0 ; - G4int multiplier = 1; - for(unsigned int i = 0 ; i < mysize ; i++){ - m_Index+= aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_NestingLevel[i])*multiplier; - multiplier*=10; - } - - // Check if the particle has interact before, if yes, add up the energies. + // Contain Energy, Time + as many copy number as nested volume + unsigned int mysize = m_NestingLevel.size(); + G4double* Infos = new G4double[2+mysize]; + Infos[0] = aStep->GetTotalEnergyDeposit(); + Infos[1] = aStep->GetPreStepPoint()->GetGlobalTime(); + + for(unsigned int i = 0 ; i < mysize ; i++){ + Infos[i+2] = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_NestingLevel[i]); + } + + m_Index = 0 ; + G4int multiplier = 1; + for(unsigned int i = 0 ; i < mysize ; i++){ + m_Index+= aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_NestingLevel[i])*multiplier; + multiplier*=10; + } + + // Check if the particle has interact before, if yes, add up the energies. map<G4int, G4double**>::iterator it; it= EvtMap->GetMap()->find(m_Index); if(it!=EvtMap->GetMap()->end()){ - G4double* dummy = *(it->second); - Infos[0]+=dummy[0]; + G4double* dummy = *(it->second); + Infos[0]+=dummy[0]; } - - EvtMap->set(m_Index, Infos); - return TRUE; + + EvtMap->set(m_Index, Infos); + return TRUE; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PS_Calorimeter::Initialize(G4HCofThisEvent* HCE){ - EvtMap = new G4THitsMap<G4double*>(GetMultiFunctionalDetector()->GetName(), GetName()); - if (HCID < 0) { - HCID = GetCollectionID(0); - } - HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); + EvtMap = new G4THitsMap<G4double*>(GetMultiFunctionalDetector()->GetName(), GetName()); + if (HCID < 0) { + HCID = GetCollectionID(0); + } + HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -79,30 +79,30 @@ void PS_Calorimeter::EndOfEvent(G4HCofThisEvent*){ //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PS_Calorimeter::clear(){ - std::map<G4int, G4double**>::iterator MapIterator; - for (MapIterator = EvtMap->GetMap()->begin() ; MapIterator != EvtMap->GetMap()->end() ; MapIterator++){ - delete *(MapIterator->second); - } - - EvtMap->clear(); + std::map<G4int, G4double**>::iterator MapIterator; + for (MapIterator = EvtMap->GetMap()->begin() ; MapIterator != EvtMap->GetMap()->end() ; MapIterator++){ + delete *(MapIterator->second); + } + + EvtMap->clear(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PS_Calorimeter::DrawAll(){ - + } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PS_Calorimeter::PrintAll(){ - G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl ; - G4cout << " PrimitiveScorer " << GetName() << G4endl ; - G4cout << " Number of entries " << EvtMap->entries() << G4endl ; + G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl ; + G4cout << " PrimitiveScorer " << GetName() << G4endl ; + G4cout << " Number of entries " << EvtMap->entries() << G4endl ; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... PS_CalorimeterWithInteraction::PS_CalorimeterWithInteraction(G4String name, vector<G4int> NestingLevel,G4int depth) :G4VPrimitiveScorer(name, depth),HCID(-1){ - m_NestingLevel = NestingLevel; + m_NestingLevel = NestingLevel; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -111,51 +111,52 @@ PS_CalorimeterWithInteraction::~PS_CalorimeterWithInteraction(){ //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4bool PS_CalorimeterWithInteraction::ProcessHits(G4Step* aStep, G4TouchableHistory*){ - // Contain Energy, Time + as many copy number as nested volume - unsigned int mysize = m_NestingLevel.size(); - G4double* Infos = new G4double[7+mysize]; - Infos[0] = aStep->GetTotalEnergyDeposit(); - Infos[1] = aStep->GetPreStepPoint()->GetGlobalTime(); - // Interaction coordinates (used to fill the InteractionCoordinates branch) - G4ThreeVector m_Position = aStep->GetPreStepPoint()->GetPosition(); - - Infos[2] = m_Position.x(); - Infos[3] = m_Position.y(); - Infos[4] = m_Position.z(); - Infos[5] = m_Position.theta(); - Infos[6] = m_Position.phi(); - - - for(unsigned int i = 0 ; i < mysize ; i++){ - Infos[i+7] = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_NestingLevel[i]); - } - - m_Index = 0 ; - G4int multiplier = 1; - for(unsigned int i = 0 ; i < mysize ; i++){ - m_Index+= aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_NestingLevel[i])*multiplier; - multiplier*=10; - } - - // Check if the particle has interact before, if yes, add up the energies. + // Contain Energy, Time + as many copy number as nested volume + unsigned int mysize = m_NestingLevel.size(); + G4double* Infos = new G4double[7+mysize]; + Infos[0] = aStep->GetTotalEnergyDeposit(); + Infos[1] = aStep->GetPreStepPoint()->GetGlobalTime(); + + // Interaction coordinates (used to fill the InteractionCoordinates branch) + G4ThreeVector m_Position = aStep->GetPreStepPoint()->GetPosition(); + + Infos[2] = m_Position.x(); + Infos[3] = m_Position.y(); + Infos[4] = m_Position.z(); + Infos[5] = m_Position.theta(); + Infos[6] = m_Position.phi(); + + + for(unsigned int i = 0 ; i < mysize ; i++){ + Infos[i+7] = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_NestingLevel[i]); + } + + m_Index = 0 ; + G4int multiplier = 1; + for(unsigned int i = 0 ; i < mysize ; i++){ + m_Index+= aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(m_NestingLevel[i])*multiplier; + multiplier*=10; + } + + // Check if the particle has interact before, if yes, add up the energies. map<G4int, G4double**>::iterator it; it= EvtMap->GetMap()->find(m_Index); if(it!=EvtMap->GetMap()->end()){ - G4double* dummy = *(it->second); - Infos[0]+=dummy[0]; + G4double* dummy = *(it->second); + Infos[0]+=dummy[0]; } - - EvtMap->set(m_Index, Infos); - return TRUE; + + EvtMap->set(m_Index, Infos); + return TRUE; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PS_CalorimeterWithInteraction::Initialize(G4HCofThisEvent* HCE){ - EvtMap = new G4THitsMap<G4double*>(GetMultiFunctionalDetector()->GetName(), GetName()); - if (HCID < 0) { - HCID = GetCollectionID(0); - } - HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); + EvtMap = new G4THitsMap<G4double*>(GetMultiFunctionalDetector()->GetName(), GetName()); + if (HCID < 0) { + HCID = GetCollectionID(0); + } + HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -164,23 +165,23 @@ void PS_CalorimeterWithInteraction::EndOfEvent(G4HCofThisEvent*){ //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PS_CalorimeterWithInteraction::clear(){ - std::map<G4int, G4double**>::iterator MapIterator; - for (MapIterator = EvtMap->GetMap()->begin() ; MapIterator != EvtMap->GetMap()->end() ; MapIterator++){ - delete *(MapIterator->second); - } - - EvtMap->clear(); + std::map<G4int, G4double**>::iterator MapIterator; + for (MapIterator = EvtMap->GetMap()->begin() ; MapIterator != EvtMap->GetMap()->end() ; MapIterator++){ + delete *(MapIterator->second); + } + + EvtMap->clear(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PS_CalorimeterWithInteraction::DrawAll(){ - + } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void PS_CalorimeterWithInteraction::PrintAll(){ - G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl ; - G4cout << " PrimitiveScorer " << GetName() << G4endl ; - G4cout << " Number of entries " << EvtMap->entries() << G4endl ; + G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl ; + G4cout << " PrimitiveScorer " << GetName() << G4endl ; + G4cout << " Number of entries " << EvtMap->entries() << G4endl ; } diff --git a/NPSimulation/Core/MaterialManager.cc b/NPSimulation/Core/MaterialManager.cc index 4bf9980941a9a7f53397181681c3bf2f03362ecc..71a2fe9f3d2259df36732c8a8ee972292439a973 100644 --- a/NPSimulation/Core/MaterialManager.cc +++ b/NPSimulation/Core/MaterialManager.cc @@ -382,6 +382,15 @@ G4Material* MaterialManager::GetMaterialFromLibrary(string Name,double density){ return material; } + else if(Name == "NaturalTin"){ + if(!density) + density = 7.31*g/cm3; + G4Material* material = new G4Material("NPS_"+Name,density,1); + material->AddElement(GetElementFromLibrary("Sn"),1); + m_Material[Name]=material; + return material; + } + else if(Name == "CsI_Scintillator"){ if(!density) density = 4.51*g/cm3; diff --git a/NPSimulation/Core/PhysicsList.cc b/NPSimulation/Core/PhysicsList.cc index 0f31852f2b6dcb9409d13d2c50d15e4cb7d34026..a3f5851e1c90222d835ab28fe7a76f72d5af7f77 100644 --- a/NPSimulation/Core/PhysicsList.cc +++ b/NPSimulation/Core/PhysicsList.cc @@ -24,6 +24,10 @@ //NPS #include "PhysicsList.hh" +// Local physic directly implemented from the Hadronthrapy example +// Physic dedicated to the ion-ion inelastic processes +#include "LocalIonIonInelasticPhysic.hh" + // G4 #include "G4SystemOfUnits.hh" #include "G4RunManager.hh" @@ -35,64 +39,76 @@ ///////////////////////////////////////////////////////////////////////////// PhysicsList::PhysicsList() : G4VModularPhysicsList(){ - m_EmList = "Option4"; - defaultCutValue = 1*mm; - opticalPhysicsList = NULL; - - ReadConfiguration("PhysicsListOption.txt"); - G4LossTableManager::Instance(); - SetVerboseLevel(0); - - // ****** Definition of defaults for the physics processes ***** - // ****** in case no physics is called by the macro file ***** - // - // The default physics corresponds to the actual QGSP_BIC_HP list - // but with the following differences: - // --> G4EmStandardPhysics_option4 for the electromagnetic processes - // is used n place of the less accurate G4EmStandardPhysics - // --> The G4RadioactiveDecayPhysics is add - // --> G4HadronPhysicsQGSP_BIC is used in place of G4HadronPhysicsQGSP_BIC_HP - // --> G4HadronElasticPhysics is used in place of G4HadronElasticPhysics_HP - - // Elecromagnetic physics - // Using the more accurate option4 - - emPhysicsList=NULL; - if(m_EmList == "Option4") - emPhysicsList = new G4EmStandardPhysics_option4(); - - else if(m_EmList== "Livermore") - emPhysicsList = new G4EmLivermorePhysics(); - - else if( m_EmList == "Penelope") - emPhysicsList = new G4EmPenelopePhysics(); - - else{ - std::cout << "\r\033[1;31mERROR: User given physics list " << m_EmList << " is not supported, option are Option4 Livermore Penelope\033[0m" <<std::endl; - exit(1); - } - - // Hadronic physics - if(m_IonBinaryCascadePhysics){ - m_PhysList["IonBinaryCascadePhysics"] = new G4IonBinaryCascadePhysics(); - } + m_EmList = "Option4"; + defaultCutValue = 0.2*mm; + opticalPhysicsList = NULL; + + ReadConfiguration("PhysicsListOption.txt"); + G4LossTableManager::Instance(); + SetVerboseLevel(0); + + // ****** Definition of defaults for the physics processes ***** + // ****** in case no physics is called by the macro file ***** + // + // The default physics corresponds to the actual QGSP_BIC_HP list + // but with the following differences: + // --> G4EmStandardPhysics_option4 for the electromagnetic processes + // is used n place of the less accurate G4EmStandardPhysics + // --> The G4RadioactiveDecayPhysics is add + // --> G4HadronPhysicsQGSP_BIC is used in place of G4HadronPhysicsQGSP_BIC_HP + // --> G4HadronElasticPhysics is used in place of G4HadronElasticPhysics_HP + + // Elecromagnetic physics + // Using the more accurate option4 + + emPhysicsList=NULL; + if(m_EmList == "Option4") + emPhysicsList = new G4EmStandardPhysics_option4(); + + else if(m_EmList== "Livermore") + emPhysicsList = new G4EmLivermorePhysics(); + + else if( m_EmList == "Penelope") + emPhysicsList = new G4EmPenelopePhysics(); + + else{ + std::cout << "\r\033[1;31mERROR: User given physics list " << m_EmList << " is not supported, option are Option4 Livermore Penelope\033[0m" <<std::endl; + exit(1); + } + + // Hadronic physics + if(m_IonBinaryCascadePhysics){ + m_PhysList["IonBinaryCascadePhysics"] = new G4IonBinaryCascadePhysics(); + //m_PhysList["G4HadronInelasticQBBC"] = new G4HadronInelasticQBBC(); + } if(m_EmExtraPhysics) - m_PhysList["EmExtraPhysics"]=new G4EmExtraPhysics(); - - if(m_HadronElasticPhysics) - m_PhysList["G4HadronElasticPhysics"]=new G4HadronElasticPhysics(); - - if(m_StoppingPhysics) - m_PhysList["StoppingPhysics"]=new G4StoppingPhysics(); - - if(m_HadronPhysicsQGSP_BIC_HP){ - #if NPS_GEANT4_VERSION_MAJOR > 9 - m_PhysList["HadronPhysicsQGSP_BIC_HP"] = new G4HadronPhysicsQGSP_BIC_HP(); - #else - std::cout << "\r\032[1;31m Warning: physics list HadronPhysicsQGSP_BIC_HP require Geant4 10, process not activated \033[0m" <<std::endl; - #endif - } - // Optical Photon for scintillator simulation + m_PhysList["EmExtraPhysics"]=new G4EmExtraPhysics(); + + if(m_HadronElasticPhysics){ + //m_PhysList["G4HadronElasticPhysicsHP"]=new G4HadronElasticPhysicsHP(); + m_PhysList["G4HadronElasticPhysics"]=new G4HadronElasticPhysics(); + } + + if(m_LocalIonInelasticPhysics) + m_PhysList["LocalIonInelasticPhysics"]=new LocalIonIonInelasticPhysic(); + + if(m_StoppingPhysics) + m_PhysList["StoppingPhysics"]=new G4StoppingPhysics(); + + if(m_HadronPhysicsINCLXX){ + m_PhysList["HadronPhysicsINCLXX"] = new G4HadronPhysicsINCLXX(); + m_PhysList["IonPhysicsINCLXX"] = new G4IonINCLXXPhysics(); + } + + if(m_HadronPhysicsQGSP_BIC_HP){ +#if NPS_GEANT4_VERSION_MAJOR > 9 + m_PhysList["HadronPhysicsQGSP_BIC_HP"] = new G4HadronPhysicsQGSP_BIC_HP(); + +#else + std::cout << "\r\032[1;31m Warning: physics list HadronPhysicsQGSP_BIC_HP require Geant4 10, process not activated \033[0m" <<std::endl; +#endif + } + // Optical Photon for scintillator simulation if(m_OpticalPhysics){ opticalPhysicsList = new G4OpticalPhysics(0); opticalPhysicsList->SetMaxNumPhotonsPerStep(100); @@ -100,77 +116,83 @@ PhysicsList::PhysicsList() : G4VModularPhysicsList(){ opticalPhysicsList->SetTrackSecondariesFirst(kScintillation,true); opticalPhysicsList->SetTrackSecondariesFirst(kCerenkov,true); } - - - // Decay physics - // Add Radioactive decay - // Gamma decay of known states - if(m_Decay){ - decay_List = new G4DecayPhysics(); - radioactiveDecay_List = new G4RadioactiveDecayPhysics() ; - m_PhysList["decay_list"]= decay_List; - m_PhysList["radioactiveDecay"]=radioactiveDecay_List; - } - - else{ - decay_List = 0; - radioactiveDecay_List = 0; - } - + + + // Decay physics + // Add Radioactive decay + // Gamma decay of known states + if(m_Decay){ + decay_List = new G4DecayPhysics(); + radioactiveDecay_List = new G4RadioactiveDecayPhysics() ; + m_PhysList["decay_list"]= decay_List; + m_PhysList["radioactiveDecay"]=radioactiveDecay_List; + } + + else{ + decay_List = 0; + radioactiveDecay_List = 0; + } + } //////////////////////////////////////////////////////////////////////////////// void PhysicsList::ReadConfiguration(std::string filename){ - m_IonBinaryCascadePhysics = 0; - m_EmExtraPhysics = 0; - m_HadronElasticPhysics = 0; - m_StoppingPhysics = 0; - m_OpticalPhysics = 0; - m_HadronPhysicsQGSP_BIC_HP = 0; - m_Decay = 0; - - std::ifstream file(filename.c_str()); - if(!file.is_open()){ - std::cout << "WARNING: Could not find Physics List option file " << filename << " | Using default Physics List" << std::endl; - return; - } - - std::cout << "Reading Physics list option file " << filename << std::endl; - - std::string name; - std::string str_value; - double value; - while(file >> name >> str_value){ - value = std::atof(str_value.c_str()); - if(name == "EmPhysicsList") - m_EmList = str_value; - else if(name == "DefaultCutOff") - defaultCutValue = value; - else if(name == "IonBinaryCascadePhysics") - m_IonBinaryCascadePhysics = value; - else if (name == "EmExtraPhysics") - m_EmExtraPhysics= value; - else if (name == "HadronElasticPhysics") - m_HadronElasticPhysics= value; - else if (name == "StoppingPhysics") - m_StoppingPhysics= value; - else if (name == "OpticalPhysics") - m_OpticalPhysics= value; - else if (name == "HadronPhysicsQGSP_BIC_HP") - m_HadronPhysicsQGSP_BIC_HP= value; - else if (name == "Decay") - m_Decay = value; - else - std::cout <<"WARNING: Physics List Token '" << name << "' unknown. Token is ignored." << std::endl; - } - - // Most special process need decay to be activated - if( (m_IonBinaryCascadePhysics || m_EmExtraPhysics || m_HadronElasticPhysics - || m_StoppingPhysics || m_HadronPhysicsQGSP_BIC_HP) && !m_Decay){ + m_IonBinaryCascadePhysics = 0; + m_EmExtraPhysics = 0; + m_HadronElasticPhysics = 0; + m_LocalIonInelasticPhysics = 0; + m_StoppingPhysics = 0; + m_OpticalPhysics = 0; + m_HadronPhysicsQGSP_BIC_HP = 0; + m_HadronPhysicsINCLXX = 0; + m_Decay = 0; + + std::ifstream file(filename.c_str()); + if(!file.is_open()){ + std::cout << "WARNING: Could not find Physics List option file " << filename << " | Using default Physics List" << std::endl; + return; + } + + std::cout << "Reading Physics list option file " << filename << std::endl; + + std::string name; + std::string str_value; + double value; + while(file >> name >> str_value){ + value = std::atof(str_value.c_str()); + if(name == "EmPhysicsList") + m_EmList = str_value; + else if(name == "DefaultCutOff") + defaultCutValue = value; + else if(name == "IonBinaryCascadePhysics") + m_IonBinaryCascadePhysics = value; + else if(name == "LocalIonInelasticPhysics") + m_LocalIonInelasticPhysics = value; + else if (name == "EmExtraPhysics") + m_EmExtraPhysics= value; + else if (name == "HadronElasticPhysics") + m_HadronElasticPhysics= value; + else if (name == "StoppingPhysics") + m_StoppingPhysics= value; + else if (name == "OpticalPhysics") + m_OpticalPhysics= value; + else if (name == "HadronPhysicsQGSP_BIC_HP") + m_HadronPhysicsQGSP_BIC_HP= value; + else if (name == "HadronPhysicsINCLXX") + m_HadronPhysicsINCLXX= value; + else if (name == "Decay") + m_Decay = value; + else + std::cout <<"WARNING: Physics List Token '" << name << "' unknown. Token is ignored." << std::endl; + } + + // Most special process need decay to be activated + if( (m_IonBinaryCascadePhysics || m_EmExtraPhysics || m_HadronElasticPhysics || m_LocalIonInelasticPhysics + || m_StoppingPhysics || m_HadronPhysicsQGSP_BIC_HP || m_HadronPhysicsINCLXX) && !m_Decay){ m_Decay = true; std::cout << "Information: Selected process require Decay to be activated." << std::endl; - } - + } + } ///////////////////////////////////////////////////////////////////////////// PhysicsList::~PhysicsList(){ @@ -178,75 +200,75 @@ PhysicsList::~PhysicsList(){ ///////////////////////////////////////////////////////////////////////////// void PhysicsList::ConstructParticle(){ - if(m_OpticalPhysics){ - //G4OpticalPhoton::OpticalPhotonDefinition(); - ((G4VPhysicsConstructor*) opticalPhysicsList)->ConstructParticle(); - - } - - if(decay_List){ - decay_List -> ConstructParticle(); - radioactiveDecay_List->ConstructParticle(); - } - - else{ - // If decay is not activated we have to declare the particle ourself - G4He3::He3Definition(); - G4Deuteron::DeuteronDefinition(); - G4Triton::TritonDefinition(); - G4Alpha::AlphaDefinition(); - G4Proton::ProtonDefinition(); - G4AntiProton::AntiProtonDefinition(); - G4Neutron::NeutronDefinition(); - G4Electron::ElectronDefinition(); - G4Positron::PositronDefinition(); - G4NeutrinoE::NeutrinoEDefinition(); - G4AntiNeutrinoE::AntiNeutrinoEDefinition(); - G4Geantino::GeantinoDefinition(); - G4ChargedGeantino::ChargedGeantinoDefinition(); - G4Gamma::GammaDefinition(); - // mesons - G4PionPlus ::PionPlusDefinition(); - G4PionMinus ::PionMinusDefinition(); - G4PionZero ::PionZeroDefinition(); - G4Eta ::EtaDefinition(); - G4EtaPrime ::EtaPrimeDefinition(); - // G4RhoZero ::RhoZeroDefinition(); - G4KaonPlus ::KaonPlusDefinition(); - G4KaonMinus ::KaonMinusDefinition(); - G4KaonZero ::KaonZeroDefinition(); - G4AntiKaonZero ::AntiKaonZeroDefinition(); - G4KaonZeroLong ::KaonZeroLongDefinition(); - G4KaonZeroShort::KaonZeroShortDefinition(); - // Ion - G4IonConstructor ionConstructor ; - ionConstructor.ConstructParticle() ; - } + if(m_OpticalPhysics){ + //G4OpticalPhoton::OpticalPhotonDefinition(); + ((G4VPhysicsConstructor*) opticalPhysicsList)->ConstructParticle(); + + } + + if(decay_List){ + decay_List -> ConstructParticle(); + radioactiveDecay_List->ConstructParticle(); + } + + else{ + // If decay is not activated we have to declare the particle ourself + G4He3::He3Definition(); + G4Deuteron::DeuteronDefinition(); + G4Triton::TritonDefinition(); + G4Alpha::AlphaDefinition(); + G4Proton::ProtonDefinition(); + G4AntiProton::AntiProtonDefinition(); + G4Neutron::NeutronDefinition(); + G4Electron::ElectronDefinition(); + G4Positron::PositronDefinition(); + G4NeutrinoE::NeutrinoEDefinition(); + G4AntiNeutrinoE::AntiNeutrinoEDefinition(); + G4Geantino::GeantinoDefinition(); + G4ChargedGeantino::ChargedGeantinoDefinition(); + G4Gamma::GammaDefinition(); + // mesons + G4PionPlus ::PionPlusDefinition(); + G4PionMinus ::PionMinusDefinition(); + G4PionZero ::PionZeroDefinition(); + G4Eta ::EtaDefinition(); + G4EtaPrime ::EtaPrimeDefinition(); + // G4RhoZero ::RhoZeroDefinition(); + G4KaonPlus ::KaonPlusDefinition(); + G4KaonMinus ::KaonMinusDefinition(); + G4KaonZero ::KaonZeroDefinition(); + G4AntiKaonZero ::AntiKaonZeroDefinition(); + G4KaonZeroLong ::KaonZeroLongDefinition(); + G4KaonZeroShort::KaonZeroShortDefinition(); + // Ion + G4IonConstructor ionConstructor ; + ionConstructor.ConstructParticle() ; + } } ///////////////////////////////////////////////////////////////////////////// void PhysicsList::ConstructProcess(){ // Transportation AddTransportation(); - + // Electromagnetic physics emPhysicsList -> ConstructProcess(); if(opticalPhysicsList){ - ((G4VPhysicsConstructor*) opticalPhysicsList)->ConstructProcess(); + ((G4VPhysicsConstructor*) opticalPhysicsList)->ConstructProcess(); } // Hadronic physics std::map<std::string,G4VPhysicsConstructor*>::iterator it; for(it = m_PhysList.begin(); it!= m_PhysList.end(); it++){ it->second -> ConstructProcess(); } - BiasCrossSectionByFactor(m_IonBinaryCascadePhysics); + BiasCrossSectionByFactor(m_IonBinaryCascadePhysics); em_option.SetBuildCSDARange(true); em_option.SetDEDXBinningForCSDARange(10*10); em_option.SetFluo(true); em_option.SetAuger(true); - - + + return; } @@ -256,21 +278,21 @@ void PhysicsList::AddStepMax(){ ///////////////////////////////////////////////////////////////////////////// void PhysicsList::SetCuts(){ - - if (verboseLevel >0){ - G4cout << "PhysicsList::SetCuts:"; - G4cout << "CutLength : " << G4BestUnit(defaultCutValue,"Length") << G4endl; - } - - // Special Cut for optical photon to be emmitted - SetCutsWithDefault(); + + if (verboseLevel >0){ + G4cout << "PhysicsList::SetCuts:"; + G4cout << "CutLength : " << G4BestUnit(defaultCutValue,"Length") << G4endl; + } + + // Special Cut for optical photon to be emmitted + SetCutsWithDefault(); } //////////////////////////////////////////////////////////////////////////////// /////// Friend Method for CS biasing //////////////////////////////////////////////////////////////////////////////// void PhysicsList::BiasCrossSectionByFactor(double factor){ - factor++; + factor++; } diff --git a/NPSimulation/Core/PhysicsList.hh b/NPSimulation/Core/PhysicsList.hh index 8e0cd5f81df29e27452eeda07c32ecd73621a560..08c898a376d6af581ee2c4338367ebf91f6cf54e 100644 --- a/NPSimulation/Core/PhysicsList.hh +++ b/NPSimulation/Core/PhysicsList.hh @@ -55,7 +55,11 @@ //Hadronique #include "G4HadronElasticPhysics.hh" #include "G4HadronElasticPhysicsHP.hh" +#include "G4HadronDElasticPhysics.hh" +#include "G4HadronInelasticQBBC.hh" #include "G4IonBinaryCascadePhysics.hh" +#include "G4HadronPhysicsINCLXX.hh" +#include "G4IonINCLXXPhysics.hh" #if NPS_GEANT4_VERSION_MAJOR > 9 #include "G4HadronPhysicsQGSP_BIC_HP.hh" #endif @@ -89,11 +93,14 @@ class PhysicsList: public G4VModularPhysicsList{ private: // Physics option std::string m_EmList; double m_IonBinaryCascadePhysics; + double m_LocalIonInelasticPhysics; double m_EmExtraPhysics; double m_HadronElasticPhysics; + double m_HadronInelasticPhysics; double m_StoppingPhysics; double m_OpticalPhysics; - double m_HadronPhysicsQGSP_BIC_HP; + double m_HadronPhysicsQGSP_BIC_HP; + double m_HadronPhysicsINCLXX; double m_Decay; }; diff --git a/NPSimulation/Core/SteppingVerbose.cc b/NPSimulation/Core/SteppingVerbose.cc index e2d8a1a4b2fd17cc3fd2c8a129f34c79954efcde..8e65937e65011fdb2b3cbd68074e0c15d0d5e820 100644 --- a/NPSimulation/Core/SteppingVerbose.cc +++ b/NPSimulation/Core/SteppingVerbose.cc @@ -49,6 +49,7 @@ void SteppingVerbose::StepInfo() << std::setw(6) << "X" << " " << std::setw(6) << "Y" << " " << std::setw(6) << "Z" << " " + << std::setw(10) << "Theta" << " " << std::setw(9) << "KineE" << " " << std::setw(9) << "dEStep" << " " << std::setw(10) << "StepLeng" @@ -61,6 +62,7 @@ void SteppingVerbose::StepInfo() << std::setw(6) << G4BestUnit(fTrack->GetPosition().x(), "Length") << std::setw(6) << G4BestUnit(fTrack->GetPosition().y(), "Length") << std::setw(6) << G4BestUnit(fTrack->GetPosition().z(), "Length") + << std::setw(6) << G4BestUnit(fTrack->GetPosition().theta(), "Angle") << std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(), "Energy") << std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(), "Energy") << std::setw(6) << G4BestUnit(fStep->GetStepLength(), "Length") @@ -139,6 +141,7 @@ void SteppingVerbose::TrackingStarted() << std::setw(6) << "X" << " " << std::setw(6) << "Y" << " " << std::setw(6) << "Z" << " " + << std::setw(9) << "Angle" << " " << std::setw(9) << "KineE" << " " << std::setw(9) << "dEStep" << " " << std::setw(10) << "StepLeng" @@ -150,6 +153,7 @@ void SteppingVerbose::TrackingStarted() << std::setw(6) << G4BestUnit(fTrack->GetPosition().x(), "Length") << std::setw(6) << G4BestUnit(fTrack->GetPosition().y(), "Length") << std::setw(6) << G4BestUnit(fTrack->GetPosition().z(), "Length") + << std::setw(6) << G4BestUnit(fTrack->GetPosition().theta(), "Angle") << std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(), "Energy") << std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(), "Energy") << std::setw(6) << G4BestUnit(fStep->GetStepLength(), "Length") diff --git a/NPSimulation/Detectors/CsI/CsI.cc b/NPSimulation/Detectors/CsI/CsI.cc index 6e43964b06833c049eaf97128783271d5df75ab0..0d767453b44dbb95aff4756a4d586de9a7555d36 100644 --- a/NPSimulation/Detectors/CsI/CsI.cc +++ b/NPSimulation/Detectors/CsI/CsI.cc @@ -555,7 +555,7 @@ void CsI::VolumeMaker(G4ThreeVector Det_pos, int DetNumber, G4LogicalVolume* wor //new G4LogicalSkinSurface("OpticalCrysralSurface",logicCsI,OpticalCrysralSurface); // Photodiode - G4String NamePD = Name+"PhotoDiode"; + /*G4String NamePD = Name+"PhotoDiode"; G4Material* PDMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary("Si"); @@ -573,7 +573,7 @@ void CsI::VolumeMaker(G4ThreeVector Det_pos, int DetNumber, G4LogicalVolume* wor NamePD , world , false , - 0 ); + 0 );*/ } @@ -624,7 +624,13 @@ void CsI::ReadSensitive(const G4Event* event){ //cout << "Energy CsI " << endl; //cout << E_CsI << endl; m_Event->SetCsIEEnergy(E_CsI); - m_Event->SetENumber(Info[2]); + m_Event->SetENumber(Info[7]); + + ms_InterCoord->SetDetectedPositionX(Info[2]) ; + ms_InterCoord->SetDetectedPositionY(Info[3]) ; + ms_InterCoord->SetDetectedPositionZ(Info[4]) ; + ms_InterCoord->SetDetectedAngleTheta(Info[5]/deg) ; + ms_InterCoord->SetDetectedAnglePhi(Info[6]/deg) ; } // Clear Map for next event CsIHitMap->clear(); @@ -669,7 +675,7 @@ void CsI::InitializeScorers() { if(already_exist) return ; - G4VPrimitiveScorer* CsIScorer= new CALORIMETERSCORERS::PS_Calorimeter("CsI",NestingLevel); + G4VPrimitiveScorer* CsIScorer= new CALORIMETERSCORERS::PS_CalorimeterWithInteraction("CsI",NestingLevel); m_CsIScorer->RegisterPrimitive(CsIScorer); G4VPrimitiveScorer* PDScorer = new PHOTODIODESCORERS::PS_PhotoDiode_Rectangle("PhotoDiode",0, diff --git a/NPSimulation/Detectors/Hira/Hira.cc b/NPSimulation/Detectors/Hira/Hira.cc index c49fde8854be64d313ac843e118156563df2a5ea..fffa3c5d5bdc127084d5284a36517dd6a0a5e11b 100644 --- a/NPSimulation/Detectors/Hira/Hira.cc +++ b/NPSimulation/Detectors/Hira/Hira.cc @@ -69,8 +69,8 @@ Hira::Hira(){ m_EventHira = new THiraData(); // Silicon - m_SiliconVisAtt = new G4VisAttributes(G4Colour(0.839216, 0.839216, 0.839216)) ; - m_SiliconVisAtt2 = new G4VisAttributes(G4Colour(0.839216, 0.839216, 0.839216)) ; + m_SiliconVisAtt = new G4VisAttributes(G4Colour(0.839216, 0.839216, 0.839216, 0.8)) ; + m_SiliconVisAtt2 = new G4VisAttributes(G4Colour(0.2, 0.0, 0.6)) ; // CsI Color m_CsIVisAtt = new G4VisAttributes(G4Colour(0.529412, 0.807843, 0.980392, 0.9)) ; //m_CsIVisAtt->SetForceWireframe(true); diff --git a/NPSimulation/Detectors/Microball/Microball.cc b/NPSimulation/Detectors/Microball/Microball.cc index fe75e0cf56eb40e6d8f9f11e1876111c17bf16b1..5d86bee981d4128d96dbb4df5c1195afd6c32ca9 100644 --- a/NPSimulation/Detectors/Microball/Microball.cc +++ b/NPSimulation/Detectors/Microball/Microball.cc @@ -64,78 +64,78 @@ using namespace CLHEP; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... namespace Microball_NS{ - // Energy and time Resolution - const double EnergyThreshold = 0.1*MeV; - const double ResoTime = 4.5*ns ; - const double ResoEnergy = 5.0*MeV ; - const double Radius = 50*mm ; - const double Width = 100*mm ; - const double Thickness = 300*mm ; - const string Scintillator = "BC400"; + // Energy and time Resolution + const double EnergyThreshold = 0.1*MeV; + const double ResoTime = 4.5*ns ; + const double ResoEnergy = 5.0*MeV ; + const double Radius = 50*mm ; + const double Width = 100*mm ; + const double Thickness = 300*mm ; + const string Scintillator = "BC400"; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... // Microball Specific Method Microball::Microball(){ - m_Event = new TMicroballData() ; - m_MicroballScorer = 0; - m_SquareDetector = 0; - m_CylindricalDetector = 0; - - - // RGB Color + Transparency - m_VisSquare = new G4VisAttributes(G4Colour(0, 1, 0, 0.5)); - m_VisCylinder = new G4VisAttributes(G4Colour(0, 0, 1, 0.5)); - + m_Event = new TMicroballData() ; + m_MicroballScorer = 0; + m_SquareDetector = 0; + m_CylindricalDetector = 0; + + + // RGB Color + Transparency + m_VisSquare = new G4VisAttributes(G4Colour(0, 1, 0, 0.5)); + m_VisCylinder = new G4VisAttributes(G4Colour(0, 0, 1, 0.5)); + } Microball::~Microball(){ } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... -void Microball::AddMicroball(bool bR1, bool bR2, bool bR3, - bool bR4, bool bR5, bool bR6, - bool bR7, bool bR8, bool bR9, - vector<int> copyNumArray){ - m_Ring1 = bR1; - m_Ring2 = bR2; - m_Ring3 = bR3; - m_Ring4 = bR4; - m_Ring5 = bR5; - m_Ring6 = bR6; - m_Ring7 = bR7; - m_Ring8 = bR8; - m_Ring9 = bR9; - m_Array = copyNumArray; +void Microball::AddMicroball(bool bR1, bool bR2, bool bR3, + bool bR4, bool bR5, bool bR6, + bool bR7, bool bR8, bool bR9, + vector<int> copyNumArray){ + m_Ring1 = bR1; + m_Ring2 = bR2; + m_Ring3 = bR3; + m_Ring4 = bR4; + m_Ring5 = bR5; + m_Ring6 = bR6; + m_Ring7 = bR7; + m_Ring8 = bR8; + m_Ring9 = bR9; + m_Array = copyNumArray; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4LogicalVolume* Microball::BuildSquareDetector(){ - if(!m_SquareDetector){ - G4Box* box = new G4Box("Microball_Box",Microball_NS::Width*0.5, - Microball_NS::Width*0.5,Microball_NS::Thickness*0.5); - - G4Material* ScintMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(Microball_NS::Scintillator); - m_SquareDetector = new G4LogicalVolume(box,ScintMaterial,"logic_Microball_Box",0,0,0); - m_SquareDetector->SetVisAttributes(m_VisSquare); - m_SquareDetector->SetSensitiveDetector(m_MicroballScorer); - } - return m_SquareDetector; + if(!m_SquareDetector){ + G4Box* box = new G4Box("Microball_Box",Microball_NS::Width*0.5, + Microball_NS::Width*0.5,Microball_NS::Thickness*0.5); + + G4Material* ScintMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(Microball_NS::Scintillator); + m_SquareDetector = new G4LogicalVolume(box,ScintMaterial,"logic_Microball_Box",0,0,0); + m_SquareDetector->SetVisAttributes(m_VisSquare); + m_SquareDetector->SetSensitiveDetector(m_MicroballScorer); + } + return m_SquareDetector; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4LogicalVolume* Microball::BuildCylindricalDetector(){ - if(!m_CylindricalDetector){ - G4Tubs* tub = new G4Tubs("Microball_Cyl",0,Microball_NS::Radius,Microball_NS::Thickness*0.5,0,360*deg); - - G4Material* ScintMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(Microball_NS::Scintillator); - m_CylindricalDetector = new G4LogicalVolume(tub,ScintMaterial,"logic_Microball_tub",0,0,0); - m_CylindricalDetector->SetVisAttributes(m_VisSquare); - m_CylindricalDetector->SetSensitiveDetector(m_MicroballScorer); - - } - return m_CylindricalDetector; + if(!m_CylindricalDetector){ + G4Tubs* tub = new G4Tubs("Microball_Cyl",0,Microball_NS::Radius,Microball_NS::Thickness*0.5,0,360*deg); + + G4Material* ScintMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(Microball_NS::Scintillator); + m_CylindricalDetector = new G4LogicalVolume(tub,ScintMaterial,"logic_Microball_tub",0,0,0); + m_CylindricalDetector->SetVisAttributes(m_VisSquare); + m_CylindricalDetector->SetSensitiveDetector(m_MicroballScorer); + + } + return m_CylindricalDetector; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -146,2642 +146,2642 @@ G4LogicalVolume* Microball::BuildCylindricalDetector(){ // Read stream at Configfile to pick-up parameters of detector (Position,...) // Called in DetecorConstruction::ReadDetextorConfiguration Method void Microball::ReadConfiguration(string Path){ - ifstream ConfigFile ; - ConfigFile.open(Path.c_str()) ; - string LineBuffer ; - string DataBuffer ; - - -bool bR1 = false; -bool bR2 = false; -bool bR3 = false; -bool bR4 = false; -bool bR5 = false; -bool bR6 = false; -bool bR7 = false; -bool bR8 = false; -bool bR9 = false; -vector<int> copyNumArray; - - bool ReadingStatus = false ; - -bool check_Ring1 = false; -bool check_Ring2 = false; -bool check_Ring3 = false; -bool check_Ring4 = false; -bool check_Ring5 = false; -bool check_Ring6 = false; -bool check_Ring7 = false; -bool check_Ring8 = false; -bool check_Ring9 = false; -bool check_Array = false; - - - while (!ConfigFile.eof()) { - getline(ConfigFile, LineBuffer); - - // If line is a Start Up Microball bloc, Reading toggle to true - string name = "Microball"; - - if (LineBuffer.compare(0, name.length(), name) == 0) { - G4cout << "///" << G4endl ; - G4cout << "Microball found: " << G4endl ; - ReadingStatus = true ; - } - - // Else don't toggle to Reading Block Status - else ReadingStatus = false ; - - // Reading Block - while(ReadingStatus){ - // Pickup Next Word - ConfigFile >> DataBuffer ; - - // Comment Line - if (DataBuffer.compare(0, 1, "%") == 0) { - ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' ); - } - - // Finding another telescope (safety), toggle out - else if (DataBuffer.compare(0, name.length(),name) == 0) { - G4cout << "WARNING: Another Detector is find before standard sequence of Token, Error may occured in Telecope definition" << G4endl ; - ReadingStatus = false ; - } - - //Angle method - else if (DataBuffer.compare(0, 6, "RING1=") == 0) { - check_Ring1 = true; - ConfigFile >> DataBuffer ; - bR1 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring1: " << bR1 << G4endl; - } - - else if (DataBuffer.compare(0, 6, "RING2=") == 0) { - check_Ring2 = true; - ConfigFile >> DataBuffer ; - bR2 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring2: " << bR2 << G4endl; - } - - else if (DataBuffer.compare(0, 6, "RING3=") == 0) { - check_Ring3 = true; - ConfigFile >> DataBuffer ; - bR3 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring3: " << bR3 << G4endl; - } - - else if (DataBuffer.compare(0, 6, "RING4=") == 0) { - check_Ring4 = true; - ConfigFile >> DataBuffer ; - bR4 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring4: " << bR4 << G4endl; - } - - else if (DataBuffer.compare(0, 6, "RING5=") == 0) { - check_Ring5 = true; - ConfigFile >> DataBuffer ; - bR5 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring5: " << bR5 << G4endl; - } - - else if (DataBuffer.compare(0, 6, "RING6=") == 0) { - check_Ring6 = true; - ConfigFile >> DataBuffer ; - bR6 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring6: " << bR6 << G4endl; - } - - else if (DataBuffer.compare(0, 6, "RING7=") == 0) { - check_Ring7 = true; - ConfigFile >> DataBuffer ; - bR7 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring7: " << bR7 << G4endl; - } - - else if (DataBuffer.compare(0, 6, "RING8=") == 0) { - check_Ring8 = true; - ConfigFile >> DataBuffer ; - bR8 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring8: " << bR8 << G4endl; - } - - - else if (DataBuffer.compare(0, 6, "RING9=") == 0) { - check_Ring9 = true; - ConfigFile >> DataBuffer ; - bR9 = atoi(DataBuffer.c_str()) ; - G4cout << "Ring9: " << bR9 << G4endl; - } - - else if (DataBuffer.compare(0, 15, "DISABLE_CRYSTAL") == 0) { - ConfigFile >> DataBuffer ; - int item = atoi(DataBuffer.c_str()); - copyNumArray.push_back(item) ; - G4cout << "Disabled crystal: " << item << G4endl; - } - - else if (DataBuffer.compare(0, 13, "CRYSTALS_DONE") == 0) { - check_Array = true; - } - - - //General - - /////////////////////////////////////////////////// - // If no Detector Token and no comment, toggle out - else{ - ReadingStatus = false; - G4cout << "Wrong Token Sequence: Getting out " << DataBuffer << G4endl ; - } - if(check_Ring1 && check_Ring2 && check_Ring3 && - check_Ring4 && check_Ring5 && check_Ring6 && - check_Ring7 && check_Ring8 && check_Ring9 && - check_Array){ - AddMicroball(bR1, bR2, bR3, - bR4, bR5, bR6, - bR7, bR8, bR9, - copyNumArray); - - // Reinitialisation of Check Boolean - check_Ring1 = false ; - check_Ring2 = false ; - check_Ring3 = false ; - check_Ring4 = false ; - check_Ring5 = false ; - check_Ring6 = false ; - check_Ring7 = false ; - check_Ring8 = false ; - check_Ring9 = false ; - check_Array = false ; - - ReadingStatus = false ; - G4cout << "///"<< G4endl ; - } - } - } -} -//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... - -// Construct detector and inialise sensitive part. -// Called After DetecorConstruction::AddDetector Method -void Microball::ConstructDetector(G4LogicalVolume* world){ - //the below for-loop is commented out, and to be replaced with our detector geometry. - - G4bool checkOverlaps = true; - G4double delrinBool = 1; - G4double crystalBool = 1; - G4double lgBool = 1; - -/*G4double ring1Bool = 1; -G4double ring2Bool = 1; -G4double ring3Bool = 1; -G4double ring4Bool = 1; -G4double ring5Bool = 1; -G4double ring6Bool = 1; -G4double ring7Bool = 1; -G4double ring8Bool = 1; -G4double ring9Bool = 1;*/ - - G4NistManager* nist = G4NistManager::Instance(); - -G4Material* CsI = nist->FindOrBuildMaterial("G4_CESIUM_IODIDE"); -G4VisAttributes* crystalVisAtt = new G4VisAttributes(G4Colour(0.,1.,0., .5)); -G4Material* glass = nist->FindOrBuildMaterial("G4_Pyrex_Glass"); -G4VisAttributes* lightGuideVisAtt = new G4VisAttributes(G4Colour(0.,0.,1.)); -G4Material* delrin = nist->FindOrBuildMaterial("G4_POLYOXYMETHYLENE"); - G4VisAttributes* delrinVisAtt = new G4VisAttributes(G4Colour(1.,0.,0.)); - -if(m_Ring1){ - // Ring 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lg pseudofixed - G4int detNum1 = 6; - G4double distanceFromTargetBack1 = 110.*mm; - G4double theta1 = 9.0*deg; - G4double halfTheta1 = 5.0*deg; - G4double lgThickness1 = 8.0*mm; - G4double detThickness1 = 9.2*mm; - G4double distanceFromTarget1 = distanceFromTargetBack1 - detThickness1; - - //G4double distance1 = distanceFromTarget1*sin(theta1); //this gives the distance from the beam axis. - - // - // Delrin Ring - // - G4double delrinA1 = 5*mm; - G4double delrinB1 = 10*mm; - G4double fdelrinHalfAngle1 = atan(delrinB1/2/(distanceFromTarget1+detThickness1+lgThickness1)); - G4double firs1 = pow(pow(distanceFromTarget1+detThickness1+lgThickness1,2)+pow(delrinB1/2,2),0.5)*sin(theta1-fdelrinHalfAngle1); - G4double firb1 = pow(pow(distanceFromTarget1+detThickness1+lgThickness1,2)+pow(delrinB1/2,2),0.5)*sin(theta1+fdelrinHalfAngle1); - G4double bdelrinHalfAngle1 = atan(delrinB1/2/(distanceFromTarget1+detThickness1+lgThickness1+delrinA1)); - G4double birs1 = pow(pow(distanceFromTarget1+detThickness1+lgThickness1+delrinA1,2)+pow(delrinB1/2,2),0.5)*sin(theta1-bdelrinHalfAngle1); - G4double birb1 = pow(pow(distanceFromTarget1+detThickness1+lgThickness1+delrinA1,2)+pow(delrinB1/2,2),0.5)*sin(theta1+bdelrinHalfAngle1); - - G4double delrin_dz1 = delrinB1/2; - G4double delrin_theta1 = 0; - G4double delrin_phi1 = 0; - G4double delrin_dyab1 = delrinA1/2; - G4double delrin_dxa1 = firs1*tan(180*deg/detNum1); - G4double delrin_dxb1 = birs1*tan(180*deg/detNum1); - G4double delrin_dycd1 = delrinA1/2; - G4double delrin_dxc1 = firb1*tan(180*deg/detNum1); - G4double delrin_dxd1 = birb1*tan(180*deg/detNum1); - G4double delrin_alpab1 = 0; - G4double delrin_alpcd1 = delrin_alpab1; - - - G4ThreeVector delrin_pos1 = G4ThreeVector(0,0,-distanceFromTarget1*cos(theta1)); - - G4Trap* solidDelrin1 = - new G4Trap("Delrin1", //its name - delrin_dz1, - delrin_theta1, delrin_phi1, - delrin_dyab1, - delrin_dxa1, delrin_dxb1, - delrin_alpab1, - delrin_dycd1, - delrin_dxc1, delrin_dxd1, - delrin_alpcd1); //its size - - G4LogicalVolume* logicDelrin1 = - new G4LogicalVolume(solidDelrin1, //its solid - delrin, //its material - "Delrin1"); //its name - logicDelrin1->SetVisAttributes(delrinVisAtt); - - // - // CsI Detector - // - G4double coneheight1 = 2*distanceFromTarget1; - G4double coneangle1 = theta1; - G4double crystal_rmina1 = 0.*mm; - G4double crystal_rmaxa1 = 0.0001*mm; - G4double crystal_rminb1 = coneheight1*tan(coneangle1-halfTheta1); - G4double crystal_rmaxb1 = coneheight1*tan(coneangle1+halfTheta1); - G4double crystal_hz1 = 0.5*coneheight1; - G4double crystal_phimin1 = 0.*deg, crystal_phimax1 = 360.*deg/detNum1; - G4RotationMatrix tip_rotm1 = G4RotationMatrix(); - G4ThreeVector tip_pos1 = G4ThreeVector(0,0,crystal_hz1+.0001*mm); - G4Transform3D tip_trans1 = G4Transform3D(tip_rotm1, tip_pos1); - G4ThreeVector z1 = G4ThreeVector(0,0,1); - G4ThreeVector d01 = G4ThreeVector(distanceFromTarget1*sin(coneangle1)*cos(0.5*360*deg/detNum1), - distanceFromTarget1*sin(coneangle1)*sin(0.5*360*deg/detNum1), - distanceFromTarget1*cos(coneangle1)); - G4ThreeVector unitAxis1 = z1.cross(d01); - unitAxis1 = unitAxis1/unitAxis1.mag(); - G4double ux1 = unitAxis1.x(); - G4double uy1 = unitAxis1.y(); - G4double uz1 = unitAxis1.z(); - G4ThreeVector top1 = G4ThreeVector(cos(coneangle1)+pow(ux1,2)*(1-cos(coneangle1)), ux1*uy1*(1-cos(coneangle1))-uz1*sin(coneangle1), ux1*uz1*(1-cos(coneangle1))+uy1*sin(coneangle1)); - G4ThreeVector mid1 = G4ThreeVector(uy1*ux1*(1-cos(coneangle1))+uz1*sin(coneangle1), cos(coneangle1)+pow(uy1,2)*(1-cos(coneangle1)), uy1*uz1*(1-cos(coneangle1))-ux1*sin(coneangle1)); - G4ThreeVector bot1 = G4ThreeVector(uz1*ux1*(1-cos(coneangle1))-uy1*sin(coneangle1), uz1*uy1*(1-cos(coneangle1))+ux1*sin(coneangle1), cos(coneangle1)+pow(uz1,2)*(1-cos(coneangle1))); - G4RotationMatrix firstBox_rotm1 = G4RotationMatrix(); - firstBox_rotm1.setRows(top1,mid1,bot1); - G4ThreeVector firstBox_pos1 = G4ThreeVector(0,0,0); - G4Transform3D firstBox_trans1 = G4Transform3D(firstBox_rotm1, firstBox_pos1); - G4RotationMatrix secondBox_rotm1 = G4RotationMatrix(); - secondBox_rotm1.setRows(top1,mid1,bot1); - G4ThreeVector secondBox_pos1 = (2*distanceFromTarget1+detThickness1)/distanceFromTarget1*d01; - G4Transform3D secondBox_trans1 = G4Transform3D(secondBox_rotm1, secondBox_pos1); - - G4Orb* solidTip1 = - new G4Orb("tip1", - .0001*mm); - G4Box* solidSubtractionBox1 = - new G4Box("SubtractionBox1", //its name - distanceFromTarget1, - distanceFromTarget1, - distanceFromTarget1); //its size - G4Cons* solidCone1 = - new G4Cons("Cone1", //its name - crystal_rmina1, crystal_rmaxa1, - crystal_rminb1, crystal_rmaxb1, - crystal_hz1, - crystal_phimin1, crystal_phimax1); //its size - G4UnionSolid* solidTippedCone1 = - new G4UnionSolid("TippedCone1", - solidTip1, - solidCone1, - tip_trans1); - G4SubtractionSolid* solidIntermediate1 = - new G4SubtractionSolid("Intermediate1", - solidTippedCone1, - solidSubtractionBox1, - firstBox_trans1); - G4SubtractionSolid* solidCrystal1 = - new G4SubtractionSolid("Crystal1", - solidIntermediate1, - solidSubtractionBox1, - secondBox_trans1); - - G4LogicalVolume* logicCrystal1 = - new G4LogicalVolume(solidCrystal1, //its solid - CsI, //its material - "CsI Detector1"); //its name - logicCrystal1->SetVisAttributes(crystalVisAtt); - logicCrystal1->SetSensitiveDetector(m_MicroballScorer); - //fScoringVolume = logicCrystal1; - - // - // Light Guide - // - G4double lightGuide_px1 = 10*mm; - G4double lightGuide_py1 = 10*mm; - G4double lightGuide_pz1 = lgThickness1; - G4Box* solidLightGuide1 = - new G4Box("LightGuide1", //its name - 0.5*lightGuide_px1, - 0.5*lightGuide_py1, - 0.5*lightGuide_pz1); //its size - - G4LogicalVolume* logicLightGuide1 = - new G4LogicalVolume(solidLightGuide1, //its solid - glass, //its material - "LightGuide1"); //its name - logicLightGuide1->SetVisAttributes(lightGuideVisAtt); - - for(int i = 1; i <= detNum1; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - G4ThreeVector d0 = G4ThreeVector(distanceFromTarget1*sin(coneangle1)*cos(0.5*360*deg/detNum1), - distanceFromTarget1*sin(coneangle1)*sin(0.5*360*deg/detNum1), - distanceFromTarget1*cos(coneangle1)); - G4ThreeVector df = G4ThreeVector(distanceFromTarget1*sin(theta1)*sin(i*360*deg/detNum1+.001*deg/*+0.5*360*deg/detNum1*/), - distanceFromTarget1*sin(theta1)*cos(i*360*deg/detNum1+.001*deg/*+0.5*360*deg/detNum1*/), - -distanceFromTarget1*cos(theta1)); - G4ThreeVector axis = d0.cross(df); - G4double ax = axis.x(); - G4double ay = axis.y(); - G4double az = axis.z(); - G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); - G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); - G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); - G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); - G4RotationMatrix abc = G4RotationMatrix(); - abc.setRows(a,b,c); - G4ThreeVector unitdf = df/df.mag(); - G4double udfx = unitdf.x(); - G4double udfy = unitdf.y(); - G4double udfz = unitdf.z(); - G4double k = 180.*deg; - G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); - G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); - G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); - G4RotationMatrix def = G4RotationMatrix(); - def.setRows(d,e,f); - crystal_rotm=def*abc; - G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - G4ThreeVector lg_Axis = df.cross(z1); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4ThreeVector p = G4ThreeVector(cos(theta1)+pow(ulgx,2)*(1-cos(theta1)), ulgx*ulgy*(1-cos(theta1))-ulgz*sin(theta1), ulgx*ulgz*(1-cos(theta1))+ulgy*sin(theta1)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta1))+ulgz*sin(theta1), cos(theta1)+pow(ulgy,2)*(1-cos(theta1)), ulgy*ulgz*(1-cos(theta1))-ulgx*sin(theta1)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta1))-ulgy*sin(theta1), ulgz*ulgy*(1-cos(theta1))+ulgx*sin(theta1), cos(theta1)+pow(ulgz,2)*(1-cos(theta1))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum1); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget1+detThickness1+0.5*lgThickness1)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta1+90*deg)*sin(i*360*deg/detNum1+.001*deg), sin(theta1+90*deg)*cos(i*360*deg/detNum1+.001*deg), -cos(theta1+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z1); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg-theta1; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((-i)*360*deg/detNum1+.001*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget1+detThickness1+lgThickness1+delrinA1/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - bool placeCrystal = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (m_Array[i2] == 0+i){ - placeCrystal = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal1, //its logical volume - "CsI Detector1", //its name - world, //its mother volume - false, //no boolean operation - 0+i, //copy number - checkOverlaps); //overlaps checking - } - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide1, //its logical volume - "LightGuide1", //its name - world, //its mother volume - false, //no boolean operation - 0+i, //copy number - checkOverlaps); //overlaps checking - } - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin1, //its logical volume - "Delrin1", //its name - world, //its mother volume - false, //no boolean operation - 0+i, //copy number - checkOverlaps); //overlaps checking - } - } - }} - if(m_Ring2){ - // Ring 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lg pseudofixed - G4int detNum2 = 10; - G4double distanceFromTargetBack2 = 80.*mm; - G4double theta2 = 21.0*deg; - G4double halfTheta2 = 7.0*deg; //+0.1*deg; //0.1 is a fudge factor to make it cover solid angle 4pi - G4double lgThickness2 = 7.5*mm; - G4double detThickness2 = 7.2*mm; - G4double distanceFromTarget2 = distanceFromTargetBack2 - detThickness2; - - //G4double distance2 = distanceFromTarget2*sin(theta2); //this gives the distance from the beam axis. - - // - // Delrin Ring - // - G4double delrinA2 = 5*mm; - G4double delrinB2 = 10*mm; - G4double fdelrinHalfAngle2 = atan(delrinB2/2/(distanceFromTarget2+detThickness2+lgThickness2)); - G4double firs2 = pow(pow(distanceFromTarget2+detThickness2+lgThickness2,2)+pow(delrinB2/2,2),0.5)*sin(theta2-fdelrinHalfAngle2); - G4double firb2 = pow(pow(distanceFromTarget2+detThickness2+lgThickness2,2)+pow(delrinB2/2,2),0.5)*sin(theta2+fdelrinHalfAngle2); - G4double bdelrinHalfAngle2 = atan(delrinB2/2/(distanceFromTarget2+detThickness2+lgThickness2+delrinA2)); - G4double birs2 = pow(pow(distanceFromTarget2+detThickness2+lgThickness2+delrinA2,2)+pow(delrinB2/2,2),0.5)*sin(theta2-bdelrinHalfAngle2); - G4double birb2 = pow(pow(distanceFromTarget2+detThickness2+lgThickness2+delrinA2,2)+pow(delrinB2/2,2),0.5)*sin(theta2+bdelrinHalfAngle2); - - G4double delrin_dz2 = delrinB2/2; - G4double delrin_theta2 = 0; - G4double delrin_phi2 = 0; - G4double delrin_dyab2 = delrinA2/2; - G4double delrin_dxa2 = firs2*tan(180*deg/detNum2); - G4double delrin_dxb2 = birs2*tan(180*deg/detNum2); - G4double delrin_dycd2 = delrinA2/2; - G4double delrin_dxc2 = firb2*tan(180*deg/detNum2); - G4double delrin_dxd2 = birb2*tan(180*deg/detNum2); - G4double delrin_alpab2 = 0; - G4double delrin_alpcd2 = delrin_alpab2; - + ifstream ConfigFile ; + ConfigFile.open(Path.c_str()) ; + string LineBuffer ; + string DataBuffer ; + + + bool bR1 = false; + bool bR2 = false; + bool bR3 = false; + bool bR4 = false; + bool bR5 = false; + bool bR6 = false; + bool bR7 = false; + bool bR8 = false; + bool bR9 = false; + vector<int> copyNumArray; + + bool ReadingStatus = false ; + + bool check_Ring1 = false; + bool check_Ring2 = false; + bool check_Ring3 = false; + bool check_Ring4 = false; + bool check_Ring5 = false; + bool check_Ring6 = false; + bool check_Ring7 = false; + bool check_Ring8 = false; + bool check_Ring9 = false; + bool check_Array = false; + + + while (!ConfigFile.eof()) { + getline(ConfigFile, LineBuffer); + + // If line is a Start Up Microball bloc, Reading toggle to true + string name = "Microball"; + + if (LineBuffer.compare(0, name.length(), name) == 0) { + G4cout << "///" << G4endl ; + G4cout << "Microball found: " << G4endl ; + ReadingStatus = true ; + } + + // Else don't toggle to Reading Block Status + else ReadingStatus = false ; + + // Reading Block + while(ReadingStatus){ + // Pickup Next Word + ConfigFile >> DataBuffer ; - G4ThreeVector delrin_pos2 = G4ThreeVector(0,0,-distanceFromTarget2*cos(theta2)); - - G4Trap* solidDelrin2 = - new G4Trap("Delrin2", //its name - delrin_dz2, - delrin_theta2, delrin_phi2, - delrin_dyab2, - delrin_dxa2, delrin_dxb2, - delrin_alpab2, - delrin_dycd2, - delrin_dxc2, delrin_dxd2, - delrin_alpcd2); //its size - - G4LogicalVolume* logicDelrin2 = - new G4LogicalVolume(solidDelrin2, //its solid - delrin, //its material - "Delrin2"); //its name - logicDelrin2->SetVisAttributes(delrinVisAtt); - - - // - // CsI Detector - // - G4double coneheight2 = 2*distanceFromTarget2; - G4double coneangle2 = theta2; - G4double crystal_rmina2 = 0.*mm; - G4double crystal_rmaxa2 = 0.0001*mm; - G4double crystal_rminb2 = coneheight2*tan(coneangle2-halfTheta2); - G4double crystal_rmaxb2 = coneheight2*tan(coneangle2+halfTheta2); - G4double crystal_hz2 = 0.5*coneheight2; - G4double crystal_phimin2 = 0.*deg, crystal_phimax2 = 360.*deg/detNum2; - G4RotationMatrix tip_rotm2 = G4RotationMatrix(); - G4ThreeVector tip_pos2 = G4ThreeVector(0,0,crystal_hz2+.0001*mm); - G4Transform3D tip_trans2 = G4Transform3D(tip_rotm2, tip_pos2); - G4ThreeVector z2 = G4ThreeVector(0,0,1); - G4ThreeVector d02 = G4ThreeVector(distanceFromTarget2*sin(coneangle2)*cos(0.5*360*deg/detNum2), - distanceFromTarget2*sin(coneangle2)*sin(0.5*360*deg/detNum2), - distanceFromTarget2*cos(coneangle2)); - G4ThreeVector unitAxis2 = z2.cross(d02); - unitAxis2 = unitAxis2/unitAxis2.mag(); - G4double ux2 = unitAxis2.x(); - G4double uy2 = unitAxis2.y(); - G4double uz2 = unitAxis2.z(); - G4ThreeVector top2 = G4ThreeVector(cos(coneangle2)+pow(ux2,2)*(1-cos(coneangle2)), ux2*uy2*(1-cos(coneangle2))-uz2*sin(coneangle2), ux2*uz2*(1-cos(coneangle2))+uy2*sin(coneangle2)); - G4ThreeVector mid2 = G4ThreeVector(uy2*ux2*(1-cos(coneangle2))+uz2*sin(coneangle2), cos(coneangle2)+pow(uy2,2)*(1-cos(coneangle2)), uy2*uz2*(1-cos(coneangle2))-ux2*sin(coneangle2)); - G4ThreeVector bot2 = G4ThreeVector(uz2*ux2*(1-cos(coneangle2))-uy2*sin(coneangle2), uz2*uy2*(1-cos(coneangle2))+ux2*sin(coneangle2), cos(coneangle2)+pow(uz2,2)*(1-cos(coneangle2))); - G4RotationMatrix firstBox_rotm2 = G4RotationMatrix(); - firstBox_rotm2.setRows(top2,mid2,bot2); - G4ThreeVector firstBox_pos2 = G4ThreeVector(0,0,0); - G4Transform3D firstBox_trans2 = G4Transform3D(firstBox_rotm2, firstBox_pos2); - G4RotationMatrix secondBox_rotm2 = G4RotationMatrix(); - secondBox_rotm2.setRows(top2,mid2,bot2); - G4ThreeVector secondBox_pos2 = (2*distanceFromTarget2+detThickness2)/distanceFromTarget2*d02; - G4Transform3D secondBox_trans2 = G4Transform3D(secondBox_rotm2, secondBox_pos2); - - G4Orb* solidTip2 = - new G4Orb("tip2", - .0001*mm); - G4Box* solidSubtractionBox2 = - new G4Box("SubtractionBox2", //its name - distanceFromTarget2, - distanceFromTarget2, - distanceFromTarget2); //its size - G4Cons* solidCone2 = - new G4Cons("Cone2", //its name - crystal_rmina2, crystal_rmaxa2, - crystal_rminb2, crystal_rmaxb2, - crystal_hz2, - crystal_phimin2, crystal_phimax2); //its size - G4UnionSolid* solidTippedCone2 = - new G4UnionSolid("TippedCone2", - solidTip2, - solidCone2, - tip_trans2); - G4SubtractionSolid* solidIntermediate2 = - new G4SubtractionSolid("Intermediate2", - solidTippedCone2, - solidSubtractionBox2, - firstBox_trans2); - G4SubtractionSolid* solidCrystal2 = - new G4SubtractionSolid("Crystal2", - solidIntermediate2, - solidSubtractionBox2, - secondBox_trans2); - - G4LogicalVolume* logicCrystal2 = - new G4LogicalVolume(solidCrystal2, //its solid - CsI, //its material - "CsI Detector2"); //its name - logicCrystal2->SetVisAttributes(crystalVisAtt); - logicCrystal2->SetSensitiveDetector(m_MicroballScorer); - // - // Light Guide - // - G4double lightGuide_px2 = 10*mm; - G4double lightGuide_py2 = 10*mm; - G4double lightGuide_pz2 = lgThickness2; - G4Box* solidLightGuide2 = - new G4Box("LightGuide2", //its name - 0.5*lightGuide_px2, - 0.5*lightGuide_py2, - 0.5*lightGuide_pz2); //its size - - G4LogicalVolume* logicLightGuide2 = - new G4LogicalVolume(solidLightGuide2, //its solid - glass, //its material - "LightGuide2"); //its name - logicLightGuide2->SetVisAttributes(lightGuideVisAtt); - - for(int i = 1; i <= detNum2; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - G4ThreeVector d0 = G4ThreeVector(distanceFromTarget2*sin(coneangle2)*cos(0.5*360*deg/detNum2), - distanceFromTarget2*sin(coneangle2)*sin(0.5*360*deg/detNum2), - distanceFromTarget2*cos(coneangle2)); - G4ThreeVector df = G4ThreeVector(distanceFromTarget2*sin(theta2)*sin(i*360*deg/detNum2+.001*deg/*+0.5*360*deg/detNum2*/), - distanceFromTarget2*sin(theta2)*cos(i*360*deg/detNum2+.001*deg/*+0.5*360*deg/detNum2*/), - -distanceFromTarget2*cos(theta2)); - G4ThreeVector axis = d0.cross(df); - G4double ax = axis.x(); - G4double ay = axis.y(); - G4double az = axis.z(); - G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); - G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); - G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); - G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); - G4RotationMatrix abc = G4RotationMatrix(); - abc.setRows(a,b,c); - G4ThreeVector unitdf = df/df.mag(); - G4double udfx = unitdf.x(); - G4double udfy = unitdf.y(); - G4double udfz = unitdf.z(); - G4double k = 180.*deg; - G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); - G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); - G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); - G4RotationMatrix def = G4RotationMatrix(); - def.setRows(d,e,f); - crystal_rotm=def*abc; - G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - G4ThreeVector lg_Axis = df.cross(z2); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4ThreeVector p = G4ThreeVector(cos(theta2)+pow(ulgx,2)*(1-cos(theta2)), ulgx*ulgy*(1-cos(theta2))-ulgz*sin(theta2), ulgx*ulgz*(1-cos(theta2))+ulgy*sin(theta2)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta2))+ulgz*sin(theta2), cos(theta2)+pow(ulgy,2)*(1-cos(theta2)), ulgy*ulgz*(1-cos(theta2))-ulgx*sin(theta2)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta2))-ulgy*sin(theta2), ulgz*ulgy*(1-cos(theta2))+ulgx*sin(theta2), cos(theta2)+pow(ulgz,2)*(1-cos(theta2))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum2); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget2+detThickness2+0.5*lgThickness2)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4Transform3D d0_trans = G4Transform3D(G4RotationMatrix(), d0); - G4Transform3D df_trans = G4Transform3D(G4RotationMatrix(), df); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta2+90*deg)*sin(i*360*deg/detNum2+.001*deg), sin(theta2+90*deg)*cos(i*360*deg/detNum2+.001*deg), -cos(theta2+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z2); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg-theta2; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((-i)*360*deg/detNum2+.001*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget2+detThickness2+lgThickness2+delrinA2/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - bool placeCrystal = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (m_Array[i2] == 6+i){ - placeCrystal = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal2, //its logical volume - "CsI Detector2", //its name - world, //its mother volume - false, //no boolean operation - 6+i, //copy number - checkOverlaps); //overlaps checking - } - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide2, //its logical volume - "LightGuide2", //its name - world, //its mother volume - false, //no boolean operation - 6+i, //copy number - checkOverlaps); //overlaps checking - } - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin2, //its logical volume - "Delrin2", //its name - world, //its mother volume - false, //no boolean operation - 6+i, //copy number - checkOverlaps); //overlaps checking - } - } - }} - - if(m_Ring3){ - // Ring 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lg pseudofixed - G4int detNum3 = 12; - G4double distanceFromTargetBack3 = 60.*mm; - G4double theta3 = 36.0*deg; - G4double halfTheta3 = 8.0*deg; - G4double lgThickness3 = 6.0*mm; - G4double detThickness3 = 6.4*mm; - G4double distanceFromTarget3 = distanceFromTargetBack3 - detThickness3; - - //G4double distance3 = distanceFromTarget3*sin(theta3); //this gives the distance from the beam axis. - - // - // Delrin Ring - // - G4double delrinA3 = 5*mm; - G4double delrinB3 = 10*mm; - G4double fdelrinHalfAngle3 = atan(delrinB3/2/(distanceFromTarget3+detThickness3+lgThickness3)); - G4double firs3 = pow(pow(distanceFromTarget3+detThickness3+lgThickness3,2)+pow(delrinB3/2,2),0.5)*sin(theta3-fdelrinHalfAngle3); - G4double firb3 = pow(pow(distanceFromTarget3+detThickness3+lgThickness3,2)+pow(delrinB3/2,2),0.5)*sin(theta3+fdelrinHalfAngle3); - G4double bdelrinHalfAngle3 = atan(delrinB3/2/(distanceFromTarget3+detThickness3+lgThickness3+delrinA3)); - G4double birs3 = pow(pow(distanceFromTarget3+detThickness3+lgThickness3+delrinA3,2)+pow(delrinB3/2,2),0.5)*sin(theta3-bdelrinHalfAngle3); - G4double birb3 = pow(pow(distanceFromTarget3+detThickness3+lgThickness3+delrinA3,2)+pow(delrinB3/2,2),0.5)*sin(theta3+bdelrinHalfAngle3); - - G4double delrin_dz3 = delrinB3/2; - G4double delrin_theta3 = 0; - G4double delrin_phi3 = 0; - G4double delrin_dyab3 = delrinA3/2; - G4double delrin_dxa3 = firs3*tan(180*deg/detNum3); - G4double delrin_dxb3 = birs3*tan(180*deg/detNum3); - G4double delrin_dycd3 = delrinA3/2; - G4double delrin_dxc3 = firb3*tan(180*deg/detNum3); - G4double delrin_dxd3 = birb3*tan(180*deg/detNum3); - G4double delrin_alpab3 = 0; - G4double delrin_alpcd3 = delrin_alpab3; - + // Comment Line + if (DataBuffer.compare(0, 1, "%") == 0) { + ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' ); + } - G4ThreeVector delrin_pos3 = G4ThreeVector(0,0,-distanceFromTarget3*cos(theta3)); - - G4Trap* solidDelrin3 = - new G4Trap("Delrin3", //its name - delrin_dz3, - delrin_theta3, delrin_phi3, - delrin_dyab3, - delrin_dxa3, delrin_dxb3, - delrin_alpab3, - delrin_dycd3, - delrin_dxc3, delrin_dxd3, - delrin_alpcd3); //its size - - G4LogicalVolume* logicDelrin3 = - new G4LogicalVolume(solidDelrin3, //its solid - delrin, //its material - "Delrin3"); //its name - logicDelrin3->SetVisAttributes(delrinVisAtt); - - // - // CsI Detector - // - G4double coneheight3 = distanceFromTarget3; - G4double coneangle3 = theta3; - G4double crystal_rmina3 = 0.*mm; - G4double crystal_rmaxa3 = 0.0001*mm; - G4double crystal_rminb3 = coneheight3*tan(coneangle3-halfTheta3); - G4double crystal_rmaxb3 = coneheight3*tan(coneangle3+halfTheta3); - G4double crystal_hz3 = 0.5*coneheight3; - G4double crystal_phimin3 = 0.*deg, crystal_phimax3 = 360.*deg/detNum3; - G4RotationMatrix tip_rotm3 = G4RotationMatrix(); - G4ThreeVector tip_pos3 = G4ThreeVector(0,0,crystal_hz3+.0001*mm); - G4Transform3D tip_trans3 = G4Transform3D(tip_rotm3, tip_pos3); - G4ThreeVector z3 = G4ThreeVector(0,0,1); - G4ThreeVector d03 = G4ThreeVector(distanceFromTarget3*sin(coneangle3)*cos(0.5*360*deg/detNum3), - distanceFromTarget3*sin(coneangle3)*sin(0.5*360*deg/detNum3), - distanceFromTarget3*cos(coneangle3)); - G4ThreeVector unitAxis3 = z3.cross(d03); - unitAxis3 = unitAxis3/unitAxis3.mag(); - G4double ux3 = unitAxis3.x(); - G4double uy3 = unitAxis3.y(); - G4double uz3 = unitAxis3.z(); - G4ThreeVector top3 = G4ThreeVector(cos(coneangle3)+pow(ux3,2)*(1-cos(coneangle3)), ux3*uy3*(1-cos(coneangle3))-uz3*sin(coneangle3), ux3*uz3*(1-cos(coneangle3))+uy3*sin(coneangle3)); - G4ThreeVector mid3 = G4ThreeVector(uy3*ux3*(1-cos(coneangle3))+uz3*sin(coneangle3), cos(coneangle3)+pow(uy3,2)*(1-cos(coneangle3)), uy3*uz3*(1-cos(coneangle3))-ux3*sin(coneangle3)); - G4ThreeVector bot3 = G4ThreeVector(uz3*ux3*(1-cos(coneangle3))-uy3*sin(coneangle3), uz3*uy3*(1-cos(coneangle3))+ux3*sin(coneangle3), cos(coneangle3)+pow(uz3,2)*(1-cos(coneangle3))); - G4RotationMatrix firstBox_rotm3 = G4RotationMatrix(); - firstBox_rotm3.setRows(top3,mid3,bot3); - G4ThreeVector firstBox_pos3 = G4ThreeVector(0,0,0); - G4Transform3D firstBox_trans3 = G4Transform3D(firstBox_rotm3, firstBox_pos3); - G4RotationMatrix secondBox_rotm3 = G4RotationMatrix(); - secondBox_rotm3.setRows(top3,mid3,bot3); - G4ThreeVector secondBox_pos3 = (2*distanceFromTarget3+detThickness3)/distanceFromTarget3*d03; - G4Transform3D secondBox_trans3 = G4Transform3D(secondBox_rotm3, secondBox_pos3); - - G4Orb* solidTip3 = - new G4Orb("tip3", - .0001*mm); - G4Box* solidSubtractionBox3 = - new G4Box("SubtractionBox3", //its name - distanceFromTarget3, - distanceFromTarget3, - distanceFromTarget3); //its size - G4Cons* solidCone3 = - new G4Cons("Cone3", //its name - crystal_rmina3, crystal_rmaxa3, - crystal_rminb3, crystal_rmaxb3, - crystal_hz3, - crystal_phimin3, crystal_phimax3); //its size - G4UnionSolid* solidTippedCone3 = - new G4UnionSolid("TippedCone3", - solidTip3, - solidCone3, - tip_trans3); - G4SubtractionSolid* solidIntermediate3 = - new G4SubtractionSolid("Intermediate3", - solidTippedCone3, - solidSubtractionBox3, - firstBox_trans3); - G4SubtractionSolid* solidCrystal3 = - new G4SubtractionSolid("Crystal3", - solidIntermediate3, - solidSubtractionBox3, - secondBox_trans3); - - G4LogicalVolume* logicCrystal3 = - new G4LogicalVolume(solidCrystal3, //its solid - CsI, //its material - "CsI Detector3"); //its name - logicCrystal3->SetVisAttributes(crystalVisAtt); - logicCrystal3->SetSensitiveDetector(m_MicroballScorer); - - - // - // Light Guide - // - G4double lightGuide_px3 = 10*mm; - G4double lightGuide_py3 = 10*mm; - G4double lightGuide_pz3 = lgThickness3; - G4Box* solidLightGuide3 = - new G4Box("LightGuide3", //its name - 0.5*lightGuide_px3, - 0.5*lightGuide_py3, - 0.5*lightGuide_pz3); //its size - - G4LogicalVolume* logicLightGuide3 = - new G4LogicalVolume(solidLightGuide3, //its solid - glass, //its material - "LightGuide3"); //its name - logicLightGuide3->SetVisAttributes(lightGuideVisAtt); - - - for(int i = 1; i <= detNum3; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - G4ThreeVector d0 = G4ThreeVector(distanceFromTarget3*sin(coneangle3)*cos(0.5*360*deg/detNum3), - distanceFromTarget3*sin(coneangle3)*sin(0.5*360*deg/detNum3), - distanceFromTarget3*cos(coneangle3)); - G4ThreeVector df = G4ThreeVector(distanceFromTarget3*sin(theta3)*sin(i*360*deg/detNum3+.001*deg/*+0.5*360*deg/detNum3*/), - distanceFromTarget3*sin(theta3)*cos(i*360*deg/detNum3+.001*deg/*+0.5*360*deg/detNum3*/), - -distanceFromTarget3*cos(theta3)); - G4ThreeVector axis = d0.cross(df); - G4double ax = axis.x(); - G4double ay = axis.y(); - G4double az = axis.z(); - G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); - G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); - G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); - G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); - G4RotationMatrix abc = G4RotationMatrix(); - abc.setRows(a,b,c); - G4ThreeVector unitdf = df/df.mag(); - G4double udfx = unitdf.x(); - G4double udfy = unitdf.y(); - G4double udfz = unitdf.z(); - G4double k = 180.*deg; - G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); - G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); - G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); - G4RotationMatrix def = G4RotationMatrix(); - def.setRows(d,e,f); - crystal_rotm=def*abc; - G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - G4ThreeVector lg_Axis = df.cross(z3); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4ThreeVector p = G4ThreeVector(cos(theta3)+pow(ulgx,2)*(1-cos(theta3)), ulgx*ulgy*(1-cos(theta3))-ulgz*sin(theta3), ulgx*ulgz*(1-cos(theta3))+ulgy*sin(theta3)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta3))+ulgz*sin(theta3), cos(theta3)+pow(ulgy,2)*(1-cos(theta3)), ulgy*ulgz*(1-cos(theta3))-ulgx*sin(theta3)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta3))-ulgy*sin(theta3), ulgz*ulgy*(1-cos(theta3))+ulgx*sin(theta3), cos(theta3)+pow(ulgz,2)*(1-cos(theta3))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum3); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget3+detThickness3+0.5*lgThickness3)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta3+90*deg)*sin(i*360*deg/detNum3+.001*deg), sin(theta3+90*deg)*cos(i*360*deg/detNum3+.001*deg), -cos(theta3+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z3); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg-theta3; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((-i)*360*deg/detNum3+.001*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget3+detThickness3+lgThickness3+delrinA3/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - //if(i != 1){ - bool placeCrystal = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (m_Array[i2] == 16+i){ - placeCrystal = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal3, //its logical volume - "CsI Detector3", //its name - world, //its mother volume - false, //no boolean operation - 16+i, //copy number - checkOverlaps); //overlaps checking - } - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide3, //its logical volume - "LightGuide3", //its name - world, //its mother volume - false, //no boolean operation - 16+i, //copy number - checkOverlaps); //overlaps checking - } - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin3, //its logical volume - "Delrin3", //its name - world, //its mother volume - false, //no boolean operation - 16+i, //copy number - checkOverlaps); //overlaps checking - } - } - //} - }} - - if(m_Ring4){ - // Ring 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - G4int detNum4 = 12; - G4double distanceFromTargetBack4 = 50.*mm; - G4double theta4 = 52.0*deg; - G4double halfTheta4 = 8.0*deg; // fudge factor - G4double lgThickness4 = 6.0*mm; - G4double detThickness4 = 6.0*mm; - G4double distanceFromTarget4 = distanceFromTargetBack4 - detThickness4; - - //G4double distance4 = distanceFromTarget4*sin(theta4); //this gives the distance from the beam axis. - - // - // Delrin Ring - // - G4double delrinA4 = 5*mm; - G4double delrinB4 = 10*mm; - G4double fdelrinHalfAngle4 = atan(delrinB4/2/(distanceFromTarget4+detThickness4+lgThickness4)); - G4double firs4 = pow(pow(distanceFromTarget4+detThickness4+lgThickness4,2)+pow(delrinB4/2,2),0.5)*sin(theta4-fdelrinHalfAngle4); - G4double firb4 = pow(pow(distanceFromTarget4+detThickness4+lgThickness4,2)+pow(delrinB4/2,2),0.5)*sin(theta4+fdelrinHalfAngle4); - G4double bdelrinHalfAngle4 = atan(delrinB4/2/(distanceFromTarget4+detThickness4+lgThickness4+delrinA4)); - G4double birs4 = pow(pow(distanceFromTarget4+detThickness4+lgThickness4+delrinA4,2)+pow(delrinB4/2,2),0.5)*sin(theta4-bdelrinHalfAngle4); - G4double birb4 = pow(pow(distanceFromTarget4+detThickness4+lgThickness4+delrinA4,2)+pow(delrinB4/2,2),0.5)*sin(theta4+bdelrinHalfAngle4); - - G4double delrin_dz4 = delrinB4/2; - G4double delrin_theta4 = 0; - G4double delrin_phi4 = 0; - G4double delrin_dyab4 = delrinA4/2; - G4double delrin_dxa4 = firs4*tan(180*deg/detNum4); - G4double delrin_dxb4 = birs4*tan(180*deg/detNum4); - G4double delrin_dycd4 = delrinA4/2; - G4double delrin_dxc4 = firb4*tan(180*deg/detNum4); - G4double delrin_dxd4 = birb4*tan(180*deg/detNum4); - G4double delrin_alpab4 = 0; - G4double delrin_alpcd4 = delrin_alpab4; - + // Finding another telescope (safety), toggle out + else if (DataBuffer.compare(0, name.length(),name) == 0) { + G4cout << "WARNING: Another Detector is find before standard sequence of Token, Error may occured in Telecope definition" << G4endl ; + ReadingStatus = false ; + } - G4ThreeVector delrin_pos4 = G4ThreeVector(0,0,-distanceFromTarget4*cos(theta4)); - - G4Trap* solidDelrin4 = - new G4Trap("Delrin4", //its name - delrin_dz4, - delrin_theta4, delrin_phi4, - delrin_dyab4, - delrin_dxa4, delrin_dxb4, - delrin_alpab4, - delrin_dycd4, - delrin_dxc4, delrin_dxd4, - delrin_alpcd4); //its size - - G4LogicalVolume* logicDelrin4 = - new G4LogicalVolume(solidDelrin4, //its solid - delrin, //its material - "Delrin4"); //its name - logicDelrin4->SetVisAttributes(delrinVisAtt); - - - // - // CsI Detector - // - G4double coneheight4 = distanceFromTarget4; - G4double coneangle4 = theta4; - G4double crystal_rmina4 = 0.*mm; - G4double crystal_rmaxa4 = 0.0001*mm; - G4double crystal_rminb4 = coneheight4*tan(coneangle4-halfTheta4); - G4double crystal_rmaxb4 = coneheight4*tan(coneangle4+halfTheta4); - G4double crystal_hz4 = 0.5*coneheight4; - G4double crystal_phimin4 = 0.*deg, crystal_phimax4 = 360.*deg/detNum4; - G4RotationMatrix tip_rotm4 = G4RotationMatrix(); - G4ThreeVector tip_pos4 = G4ThreeVector(0,0,crystal_hz4+.0001*mm); - G4Transform3D tip_trans4 = G4Transform3D(tip_rotm4, tip_pos4); - G4ThreeVector z4 = G4ThreeVector(0,0,1); - G4ThreeVector d04 = G4ThreeVector(distanceFromTarget4*sin(coneangle4)*cos(0.5*360*deg/detNum4), - distanceFromTarget4*sin(coneangle4)*sin(0.5*360*deg/detNum4), - distanceFromTarget4*cos(coneangle4)); - G4ThreeVector unitAxis4 = z4.cross(d04); - unitAxis4 = unitAxis4/unitAxis4.mag(); - G4double ux4 = unitAxis4.x(); - G4double uy4 = unitAxis4.y(); - G4double uz4 = unitAxis4.z(); - G4ThreeVector top4 = G4ThreeVector(cos(coneangle4)+pow(ux4,2)*(1-cos(coneangle4)), ux4*uy4*(1-cos(coneangle4))-uz4*sin(coneangle4), ux4*uz4*(1-cos(coneangle4))+uy4*sin(coneangle4)); - G4ThreeVector mid4 = G4ThreeVector(uy4*ux4*(1-cos(coneangle4))+uz4*sin(coneangle4), cos(coneangle4)+pow(uy4,2)*(1-cos(coneangle4)), uy4*uz4*(1-cos(coneangle4))-ux4*sin(coneangle4)); - G4ThreeVector bot4 = G4ThreeVector(uz4*ux4*(1-cos(coneangle4))-uy4*sin(coneangle4), uz4*uy4*(1-cos(coneangle4))+ux4*sin(coneangle4), cos(coneangle4)+pow(uz4,2)*(1-cos(coneangle4))); - G4RotationMatrix firstBox_rotm4 = G4RotationMatrix(); - firstBox_rotm4.setRows(top4,mid4,bot4); - G4ThreeVector firstBox_pos4 = G4ThreeVector(0,0,0); - G4Transform3D firstBox_trans4 = G4Transform3D(firstBox_rotm4, firstBox_pos4); - G4RotationMatrix secondBox_rotm4 = G4RotationMatrix(); - secondBox_rotm4.setRows(top4,mid4,bot4); - G4ThreeVector secondBox_pos4 = (2*distanceFromTarget4+detThickness4)/distanceFromTarget4*d04; - G4Transform3D secondBox_trans4 = G4Transform3D(secondBox_rotm4, secondBox_pos4); - - G4Orb* solidTip4 = - new G4Orb("tip4", - .0001*mm); - G4Box* solidSubtractionBox4 = - new G4Box("SubtractionBox4", //its name - distanceFromTarget4, - distanceFromTarget4, - distanceFromTarget4); //its size - G4Cons* solidCone4 = - new G4Cons("Cone4", //its name - crystal_rmina4, crystal_rmaxa4, - crystal_rminb4, crystal_rmaxb4, - crystal_hz4, - crystal_phimin4, crystal_phimax4); //its size - G4UnionSolid* solidTippedCone4 = - new G4UnionSolid("TippedCone4", - solidTip4, - solidCone4, - tip_trans4); - G4SubtractionSolid* solidIntermediate4 = - new G4SubtractionSolid("Intermediate4", - solidTippedCone4, - solidSubtractionBox4, - firstBox_trans4); - G4SubtractionSolid* solidCrystal4 = - new G4SubtractionSolid("Crystal4", - solidIntermediate4, - solidSubtractionBox4, - secondBox_trans4); - - G4LogicalVolume* logicCrystal4 = - new G4LogicalVolume(solidCrystal4, //its solid - CsI, //its material - "CsI Detector4"); //its name - logicCrystal4->SetVisAttributes(crystalVisAtt); - logicCrystal4->SetSensitiveDetector(m_MicroballScorer); - - // - // Light Guide - // - G4double lightGuide_px4 = 10*mm; - G4double lightGuide_py4 = 10*mm; - G4double lightGuide_pz4 = lgThickness4; - G4Box* solidLightGuide4 = - new G4Box("LightGuide4", //its name - 0.5*lightGuide_px4, - 0.5*lightGuide_py4, - 0.5*lightGuide_pz4); //its size - - G4LogicalVolume* logicLightGuide4 = - new G4LogicalVolume(solidLightGuide4, //its solid - glass, //its material - "LightGuide4"); //its name - logicLightGuide4->SetVisAttributes(lightGuideVisAtt); - - - for(int i = 1; i <= detNum4; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - G4ThreeVector d0 = G4ThreeVector(distanceFromTarget4*sin(coneangle4)*cos(0.5*360*deg/detNum4), - distanceFromTarget4*sin(coneangle4)*sin(0.5*360*deg/detNum4), - distanceFromTarget4*cos(coneangle4)); - G4ThreeVector df = G4ThreeVector(distanceFromTarget4*sin(theta4)*sin(i*360*deg/detNum4+.001*deg/*+0.5*360*deg/detNum4*/), - distanceFromTarget4*sin(theta4)*cos(i*360*deg/detNum4+.001*deg/*+0.5*360*deg/detNum4*/), - -distanceFromTarget4*cos(theta4)); - G4ThreeVector axis = d0.cross(df); - G4double ax = axis.x(); - G4double ay = axis.y(); - G4double az = axis.z(); - G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); - G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); - G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); - G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); - G4RotationMatrix abc = G4RotationMatrix(); - abc.setRows(a,b,c); - G4ThreeVector unitdf = df/df.mag(); - G4double udfx = unitdf.x(); - G4double udfy = unitdf.y(); - G4double udfz = unitdf.z(); - G4double k = 180.*deg; - G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); - G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); - G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); - G4RotationMatrix def = G4RotationMatrix(); - def.setRows(d,e,f); - crystal_rotm=def*abc; - G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - G4ThreeVector lg_Axis = df.cross(z4); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4ThreeVector p = G4ThreeVector(cos(theta4)+pow(ulgx,2)*(1-cos(theta4)), ulgx*ulgy*(1-cos(theta4))-ulgz*sin(theta4), ulgx*ulgz*(1-cos(theta4))+ulgy*sin(theta4)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta4))+ulgz*sin(theta4), cos(theta4)+pow(ulgy,2)*(1-cos(theta4)), ulgy*ulgz*(1-cos(theta4))-ulgx*sin(theta4)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta4))-ulgy*sin(theta4), ulgz*ulgy*(1-cos(theta4))+ulgx*sin(theta4), cos(theta4)+pow(ulgz,2)*(1-cos(theta4))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum4); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget4+detThickness4+0.5*lgThickness4)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta4+90*deg)*sin(i*360*deg/detNum4+.001*deg), sin(theta4+90*deg)*cos(i*360*deg/detNum4+.001*deg), -cos(theta4+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z4); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg-theta4; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((-i)*360*deg/detNum4+.001*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget4+detThickness4+lgThickness4+delrinA4/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - //if(i != 1){ - bool placeCrystal = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (m_Array[i2] == 28+i){ - placeCrystal = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal4, //its logical volume - "CsI Detector4", //its name - world, //its mother volume - false, //no boolean operation - 28+i, //copy number - checkOverlaps); //overlaps checking - } - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide4, //its logical volume - "LightGuide4", //its name - world, //its mother volume - false, //no boolean operation - 28+i, //copy number - checkOverlaps); //overlaps checking - } - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin4, //its logical volume - "Delrin4", //its name - world, //its mother volume - false, //no boolean operation - 28+i, //copy number - checkOverlaps); //overlaps checking - } - } - //} - }} - - if(m_Ring5){ - // Ring 5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - G4int detNum5 = 14; - G4double distanceFromTargetBack5 = 50.*mm; - G4double theta5 = 70.0*deg; - G4double halfTheta5 = 10.0*deg; //fudge factor - G4double lgThickness5 = 6.0*mm; - G4double detThickness5 = 5.6*mm; - G4double distanceFromTarget5 = distanceFromTargetBack5 - detThickness5; - - //G4double distance5 = distanceFromTarget5*sin(theta5); //this gives the distance from the beam axis. - - // - // Delrin Ring - // - G4double delrinA5 = 5*mm; - G4double delrinB5 = 10*mm; - G4double fdelrinHalfAngle5 = atan(delrinB5/2/(distanceFromTarget5+detThickness5+lgThickness5)); - G4double firs5 = pow(pow(distanceFromTarget5+detThickness5+lgThickness5,2)+pow(delrinB5/2,2),0.5)*sin(theta5-fdelrinHalfAngle5); - G4double firb5 = pow(pow(distanceFromTarget5+detThickness5+lgThickness5,2)+pow(delrinB5/2,2),0.5)*sin(theta5+fdelrinHalfAngle5); - G4double bdelrinHalfAngle5 = atan(delrinB5/2/(distanceFromTarget5+detThickness5+lgThickness5+delrinA5)); - G4double birs5 = pow(pow(distanceFromTarget5+detThickness5+lgThickness5+delrinA5,2)+pow(delrinB5/2,2),0.5)*sin(theta5-bdelrinHalfAngle5); - G4double birb5 = pow(pow(distanceFromTarget5+detThickness5+lgThickness5+delrinA5,2)+pow(delrinB5/2,2),0.5)*sin(theta5+bdelrinHalfAngle5); - - G4double delrin_dz5 = delrinB5/2; - G4double delrin_theta5 = 0; - G4double delrin_phi5 = 0; - G4double delrin_dyab5 = delrinA5/2; - G4double delrin_dxa5 = firs5*tan(180*deg/detNum5); - G4double delrin_dxb5 = birs5*tan(180*deg/detNum5); - G4double delrin_dycd5 = delrinA5/2; - G4double delrin_dxc5 = firb5*tan(180*deg/detNum5); - G4double delrin_dxd5 = birb5*tan(180*deg/detNum5); - G4double delrin_alpab5 = 0; - G4double delrin_alpcd5 = delrin_alpab5; - + //Angle method + else if (DataBuffer.compare(0, 6, "RING1=") == 0) { + check_Ring1 = true; + ConfigFile >> DataBuffer ; + bR1 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring1: " << bR1 << G4endl; + } - G4ThreeVector delrin_pos5 = G4ThreeVector(0,0,-distanceFromTarget5*cos(theta5)); - - G4Trap* solidDelrin5 = - new G4Trap("Delrin5", //its name - delrin_dz5, - delrin_theta5, delrin_phi5, - delrin_dyab5, - delrin_dxa5, delrin_dxb5, - delrin_alpab5, - delrin_dycd5, - delrin_dxc5, delrin_dxd5, - delrin_alpcd5); //its size - - G4LogicalVolume* logicDelrin5 = - new G4LogicalVolume(solidDelrin5, //its solid - delrin, //its material - "Delrin5"); //its name - logicDelrin5->SetVisAttributes(delrinVisAtt); - - - // - // CsI Detector - // - G4double coneheight5 = 0.6*distanceFromTarget5; - G4double coneangle5 = theta5; - G4double crystal_rmina5 = 0.*mm; - G4double crystal_rmaxa5 = 0.0001*mm; - G4double crystal_rminb5 = coneheight5*tan(coneangle5-halfTheta5); - G4double crystal_rmaxb5 = coneheight5*tan(coneangle5+halfTheta5); - G4double crystal_hz5 = 0.5*coneheight5; - G4double crystal_phimin5 = 0.*deg, crystal_phimax5 = 360.*deg/detNum5; - G4RotationMatrix tip_rotm5 = G4RotationMatrix(); - G4ThreeVector tip_pos5 = G4ThreeVector(0,0,crystal_hz5+.0001*mm); - G4Transform3D tip_trans5 = G4Transform3D(tip_rotm5, tip_pos5); - G4ThreeVector z5 = G4ThreeVector(0,0,1); - G4ThreeVector d05 = G4ThreeVector(distanceFromTarget5*sin(coneangle5)*cos(0.5*360*deg/detNum5), - distanceFromTarget5*sin(coneangle5)*sin(0.5*360*deg/detNum5), - distanceFromTarget5*cos(coneangle5)); - G4ThreeVector unitAxis5 = z5.cross(d05); - unitAxis5 = unitAxis5/unitAxis5.mag(); - G4double ux5 = unitAxis5.x(); - G4double uy5 = unitAxis5.y(); - G4double uz5 = unitAxis5.z(); - G4ThreeVector top5 = G4ThreeVector(cos(coneangle5)+pow(ux5,2)*(1-cos(coneangle5)), ux5*uy5*(1-cos(coneangle5))-uz5*sin(coneangle5), ux5*uz5*(1-cos(coneangle5))+uy5*sin(coneangle5)); - G4ThreeVector mid5 = G4ThreeVector(uy5*ux5*(1-cos(coneangle5))+uz5*sin(coneangle5), cos(coneangle5)+pow(uy5,2)*(1-cos(coneangle5)), uy5*uz5*(1-cos(coneangle5))-ux5*sin(coneangle5)); - G4ThreeVector bot5 = G4ThreeVector(uz5*ux5*(1-cos(coneangle5))-uy5*sin(coneangle5), uz5*uy5*(1-cos(coneangle5))+ux5*sin(coneangle5), cos(coneangle5)+pow(uz5,2)*(1-cos(coneangle5))); - G4RotationMatrix firstBox_rotm5 = G4RotationMatrix(); - firstBox_rotm5.setRows(top5,mid5,bot5); - G4ThreeVector firstBox_pos5 = G4ThreeVector(0,0,0); - G4Transform3D firstBox_trans5 = G4Transform3D(firstBox_rotm5, firstBox_pos5); - G4RotationMatrix secondBox_rotm5 = G4RotationMatrix(); - secondBox_rotm5.setRows(top5,mid5,bot5); - G4ThreeVector secondBox_pos5 = (3*distanceFromTarget5+detThickness5)/distanceFromTarget5*d05; - G4Transform3D secondBox_trans5 = G4Transform3D(secondBox_rotm5, secondBox_pos5); - - G4Orb* solidTip5 = - new G4Orb("tip5", - .0001*mm); - G4Box* solidSubtractionBox5 = - new G4Box("SubtractionBox5", //its name - distanceFromTarget5, - distanceFromTarget5, - distanceFromTarget5); //its size - G4Box* solidSecondSubtractionBox5 = - new G4Box("SecondSubtractionBox5", //its name - 2*distanceFromTarget5, - 2*distanceFromTarget5, - 2*distanceFromTarget5); //its size - G4Cons* solidCone5 = - new G4Cons("Cone5", //its name - crystal_rmina5, crystal_rmaxa5, - crystal_rminb5, crystal_rmaxb5, - crystal_hz5, - crystal_phimin5, crystal_phimax5); //its size - G4UnionSolid* solidTippedCone5 = - new G4UnionSolid("TippedCone5", - solidTip5, - solidCone5, - tip_trans5); - G4SubtractionSolid* solidIntermediate5 = - new G4SubtractionSolid("Intermediate5", - solidTippedCone5, - solidSubtractionBox5, - firstBox_trans5); - G4SubtractionSolid* solidCrystal5 = - new G4SubtractionSolid("Crystal5", - solidIntermediate5, - solidSecondSubtractionBox5, - secondBox_trans5); - - G4LogicalVolume* logicCrystal5 = - new G4LogicalVolume(solidCrystal5, //its solid - CsI, //its material - "CsI Detector5"); //its name - logicCrystal5->SetVisAttributes(crystalVisAtt); - logicCrystal5->SetSensitiveDetector(m_MicroballScorer); - - - // - // Light Guide - // - G4double lightGuide_px5 = 10*mm; - G4double lightGuide_py5 = 10*mm; - G4double lightGuide_pz5 = lgThickness5; - G4Box* solidLightGuide5 = - new G4Box("LightGuide5", //its name - 0.5*lightGuide_px5, - 0.5*lightGuide_py5, - 0.5*lightGuide_pz5); //its size - - G4LogicalVolume* logicLightGuide5 = - new G4LogicalVolume(solidLightGuide5, //its solid - glass, //its material - "LightGuide5"); //its name - logicLightGuide5->SetVisAttributes(lightGuideVisAtt); - - - for(int i = 1; i <= detNum5; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - G4ThreeVector d0 = G4ThreeVector(distanceFromTarget5*sin(coneangle5)*cos(0.5*360*deg/detNum5), - distanceFromTarget5*sin(coneangle5)*sin(0.5*360*deg/detNum5), - distanceFromTarget5*cos(coneangle5)); - G4ThreeVector df = G4ThreeVector(distanceFromTarget5*sin(theta5)*sin(i*360*deg/detNum5+.001*deg/*+0.5*360*deg/detNum5*/), - distanceFromTarget5*sin(theta5)*cos(i*360*deg/detNum5+.001*deg/*+0.5*360*deg/detNum5*/), - -distanceFromTarget5*cos(theta5)); - G4ThreeVector axis = d0.cross(df); - G4double ax = axis.x(); - G4double ay = axis.y(); - G4double az = axis.z(); - G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); - G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); - G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); - G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); - G4RotationMatrix abc = G4RotationMatrix(); - abc.setRows(a,b,c); - G4ThreeVector unitdf = df/df.mag(); - G4double udfx = unitdf.x(); - G4double udfy = unitdf.y(); - G4double udfz = unitdf.z(); - G4double k = 180.*deg; - G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); - G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); - G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); - G4RotationMatrix def = G4RotationMatrix(); - def.setRows(d,e,f); - crystal_rotm=def*abc; - G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - G4ThreeVector lg_Axis = df.cross(z5); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4ThreeVector p = G4ThreeVector(cos(theta5)+pow(ulgx,2)*(1-cos(theta5)), ulgx*ulgy*(1-cos(theta5))-ulgz*sin(theta5), ulgx*ulgz*(1-cos(theta5))+ulgy*sin(theta5)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta5))+ulgz*sin(theta5), cos(theta5)+pow(ulgy,2)*(1-cos(theta5)), ulgy*ulgz*(1-cos(theta5))-ulgx*sin(theta5)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta5))-ulgy*sin(theta5), ulgz*ulgy*(1-cos(theta5))+ulgx*sin(theta5), cos(theta5)+pow(ulgz,2)*(1-cos(theta5))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum5); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget5+detThickness5+0.5*lgThickness5)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta5+90*deg)*sin(i*360*deg/detNum5+.001*deg), sin(theta5+90*deg)*cos(i*360*deg/detNum5+.001*deg), -cos(theta5+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z5); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg-theta5; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((-i)*360*deg/detNum5+.001*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget5+detThickness5+lgThickness5+delrinA5/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - //if(i != 1){ - bool placeCrystal = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (m_Array[i2] == 40+i){ - placeCrystal = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal5, //its logical volume - "CsI Detector5", //its name - world, //its mother volume - false, //no boolean operation - 40+i, //copy number - checkOverlaps); //overlaps checking - } - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide5, //its logical volume - "LightGuide5", //its name - world, //its mother volume - false, //no boolean operation - 40+i, //copy number - checkOverlaps); //overlaps checking - } - //} - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin5, //its logical volume - "Delrin5", //its name - world, //its mother volume - false, //no boolean operation - 40+i, //copy number - checkOverlaps); //overlaps checking - } - } - }} - - if(m_Ring6){ - // Ring 6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ this ring is weird. - G4int detNum6 = 14; - G4double distanceFromTargetBack6 = 50.*mm; - G4double theta6 = 90.0*deg; - G4double halfTheta6 = 10.0*deg; - G4double lgThickness6 = 7.0*mm; - G4double detThickness6 = 5.2*mm; - G4double distanceFromTarget6 = distanceFromTargetBack6 - detThickness6; - - //G4double distance6 = distanceFromTarget6*sin(theta6); //this gives the distance from the beam axis. - - // - // Delrin Ring - // - G4double delrinA6 = 5*mm; - G4double delrinB6 = 10*mm; - G4double fdelrinHalfAngle6 = atan(delrinB6/2/(distanceFromTarget6+detThickness6+lgThickness6)); - G4double firs6 = pow(pow(distanceFromTarget6+detThickness6+lgThickness6,2)+pow(delrinB6/2,2),0.5)*sin(theta6-fdelrinHalfAngle6); - G4double firb6 = pow(pow(distanceFromTarget6+detThickness6+lgThickness6,2)+pow(delrinB6/2,2),0.5)*sin(theta6+fdelrinHalfAngle6); - G4double bdelrinHalfAngle6 = atan(delrinB6/2/(distanceFromTarget6+detThickness6+lgThickness6+delrinA6)); - G4double birs6 = pow(pow(distanceFromTarget6+detThickness6+lgThickness6+delrinA6,2)+pow(delrinB6/2,2),0.5)*sin(theta6-bdelrinHalfAngle6); - G4double birb6 = pow(pow(distanceFromTarget6+detThickness6+lgThickness6+delrinA6,2)+pow(delrinB6/2,2),0.5)*sin(theta6+bdelrinHalfAngle6); - - G4double delrin_dz6 = delrinB6/2; - G4double delrin_theta6 = 0; - G4double delrin_phi6 = 0; - G4double delrin_dyab6 = delrinA6/2; - G4double delrin_dxa6 = firs6*tan(180*deg/detNum6); - G4double delrin_dxb6 = birs6*tan(180*deg/detNum6); - G4double delrin_dycd6 = delrinA6/2; - G4double delrin_dxc6 = firb6*tan(180*deg/detNum6); - G4double delrin_dxd6 = birb6*tan(180*deg/detNum6); - G4double delrin_alpab6 = 0; - G4double delrin_alpcd6 = delrin_alpab6; - + else if (DataBuffer.compare(0, 6, "RING2=") == 0) { + check_Ring2 = true; + ConfigFile >> DataBuffer ; + bR2 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring2: " << bR2 << G4endl; + } - G4ThreeVector delrin_pos6 = G4ThreeVector(0,0,-distanceFromTarget6*cos(theta6)); - - G4Trap* solidDelrin6 = - new G4Trap("Delrin6", //its name - delrin_dz6, - delrin_theta6, delrin_phi6, - delrin_dyab6, - delrin_dxa6, delrin_dxb6, - delrin_alpab6, - delrin_dycd6, - delrin_dxc6, delrin_dxd6, - delrin_alpcd6); //its size - - G4LogicalVolume* logicDelrin6 = - new G4LogicalVolume(solidDelrin6, //its solid - delrin, //its material - "Delrin6"); //its name - logicDelrin6->SetVisAttributes(delrinVisAtt); - - - /* - // - // CsI Detector for deletion - // - G4double crystal_rmina6 = distance6/cos(halfTheta6); - G4double crystal_rmaxa6 = distance6/cos(halfTheta6)+2*distance6*tan(halfTheta6); - G4double crystal_rminb6 = (distance6+detThickness6)/cos(halfTheta6); - G4double crystal_rmaxb6 = (distance6+detThickness6)/cos(halfTheta6)+2*(distance6+detThickness6)*tan(halfTheta6); - G4double crystal_hz6 = 0.5*pow(pow(detThickness6,2)+pow((crystal_rminb6+crystal_rmaxb6-crystal_rmina6-crystal_rmaxa6)/2,2),0.5); - //G4double crystal_hz6 = 0.5*detThickness6; - G4double crystal_phimin6 = 0.*deg, crystal_phimax6 = 360.*deg/detNum6; - - - G4Cons* solidCrystal6 = - new G4Cons("Crystal6", //its name - crystal_rmina6, crystal_rmaxa6, - crystal_rminb6, crystal_rmaxb6, - crystal_hz6, - crystal_phimin6, crystal_phimax6); //its size - - G4LogicalVolume* logicCrystal6 = - new G4LogicalVolume(solidCrystal6, //its solid - CsI, //its material - "CsI Detector6"); //its name - logicCrystal6->SetVisAttributes(crystalVisAtt); - */ - - G4double crystal_dxa6 = distanceFromTarget6*tan(halfTheta6); - G4double crystal_dxb6 = (distanceFromTarget6+detThickness6)*tan(halfTheta6); - G4double crystal_dya6 = distanceFromTarget6*tan(0.5*360*deg/detNum6); - G4double crystal_dyb6 = (distanceFromTarget6+detThickness6)*tan(0.5*360*deg/detNum6); - G4double crystal_dz = 0.5*detThickness6; - - G4Trd* solidCrystal6 = - new G4Trd("Crystal6", //its name - crystal_dxa6, crystal_dxb6, - crystal_dya6, crystal_dyb6, - crystal_dz); //its size - G4LogicalVolume* logicCrystal6 = - new G4LogicalVolume(solidCrystal6, //its solid - CsI, //its material - "CsI Detector6"); //its name - logicCrystal6->SetVisAttributes(crystalVisAtt); - logicCrystal6->SetSensitiveDetector(m_MicroballScorer); - // - // Light Guide - // - G4double lightGuide_px6 = 10*mm; - G4double lightGuide_py6 = 10*mm; - G4double lightGuide_pz6 = lgThickness6; - G4Box* solidLightGuide6 = - new G4Box("LightGuide6", //its name - 0.5*lightGuide_px6, - 0.5*lightGuide_py6, - 0.5*lightGuide_pz6); //its size + else if (DataBuffer.compare(0, 6, "RING3=") == 0) { + check_Ring3 = true; + ConfigFile >> DataBuffer ; + bR3 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring3: " << bR3 << G4endl; + } + + else if (DataBuffer.compare(0, 6, "RING4=") == 0) { + check_Ring4 = true; + ConfigFile >> DataBuffer ; + bR4 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring4: " << bR4 << G4endl; + } + + else if (DataBuffer.compare(0, 6, "RING5=") == 0) { + check_Ring5 = true; + ConfigFile >> DataBuffer ; + bR5 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring5: " << bR5 << G4endl; + } + + else if (DataBuffer.compare(0, 6, "RING6=") == 0) { + check_Ring6 = true; + ConfigFile >> DataBuffer ; + bR6 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring6: " << bR6 << G4endl; + } + + else if (DataBuffer.compare(0, 6, "RING7=") == 0) { + check_Ring7 = true; + ConfigFile >> DataBuffer ; + bR7 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring7: " << bR7 << G4endl; + } + + else if (DataBuffer.compare(0, 6, "RING8=") == 0) { + check_Ring8 = true; + ConfigFile >> DataBuffer ; + bR8 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring8: " << bR8 << G4endl; + } + + + else if (DataBuffer.compare(0, 6, "RING9=") == 0) { + check_Ring9 = true; + ConfigFile >> DataBuffer ; + bR9 = atoi(DataBuffer.c_str()) ; + G4cout << "Ring9: " << bR9 << G4endl; + } + + else if (DataBuffer.compare(0, 15, "DISABLE_CRYSTAL") == 0) { + ConfigFile >> DataBuffer ; + int item = atoi(DataBuffer.c_str()); + copyNumArray.push_back(item) ; + G4cout << "Disabled crystal: " << item << G4endl; + } + + else if (DataBuffer.compare(0, 13, "CRYSTALS_DONE") == 0) { + check_Array = true; + } + + + //General + + /////////////////////////////////////////////////// + // If no Detector Token and no comment, toggle out + else{ + ReadingStatus = false; + G4cout << "Wrong Token Sequence: Getting out " << DataBuffer << G4endl ; + } + if(check_Ring1 && check_Ring2 && check_Ring3 && + check_Ring4 && check_Ring5 && check_Ring6 && + check_Ring7 && check_Ring8 && check_Ring9 && + check_Array){ + AddMicroball(bR1, bR2, bR3, + bR4, bR5, bR6, + bR7, bR8, bR9, + copyNumArray); - G4LogicalVolume* logicLightGuide6 = - new G4LogicalVolume(solidLightGuide6, //its solid - glass, //its material - "LightGuide6"); //its name - logicLightGuide6->SetVisAttributes(lightGuideVisAtt); - - - for(int i = 1; i <= detNum6; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - /* - G4RotationMatrix abc6 = G4RotationMatrix(); - G4RotationMatrix def6 = G4RotationMatrix(); - G4ThreeVector a6 = G4ThreeVector(pow(sin(i*360*deg/detNum6),2), -sin(i*360*deg/detNum6)*cos(i*360*deg/detNum6), cos(i*360*deg/detNum6)); - G4ThreeVector b6 = G4ThreeVector(-sin(i*360*deg/detNum6)*cos(i*360*deg/detNum6), pow(cos(i*360*deg/detNum6),2), sin(i*360*deg/detNum6)); - G4ThreeVector c6 = G4ThreeVector(-cos(i*360*deg/detNum6), -sin(i*360*deg/detNum6), 0); - abc6.setRows(a6,b6,c6); - G4double k= (i-1)*360*deg/detNum6+0.5*360*deg/detNum6; - G4ThreeVector d6 = G4ThreeVector(cos(k)+pow(cos(i*360*deg/detNum6),2)*(1-cos(k)), - cos(i*360*deg/detNum6)*sin(i*360*deg/detNum6)*(1-cos(k)), - sin(i*360*deg/detNum6)*sin(k)); - G4ThreeVector e6 = G4ThreeVector(cos(i*360*deg/detNum6)*sin(i*360*deg/detNum6)*(1-cos(k)), - cos(k)+pow(sin(i*360*deg/detNum6),2)*(1-cos(k)), - -cos(i*360*deg/detNum6)*sin(k)); - G4ThreeVector f6 = G4ThreeVector(-sin(i*360*deg/detNum6)*sin(k), - cos(i*360*deg/detNum6)*sin(k), - cos(k)); - def6.setRows(d6,e6,f6); - crystal_rotm = def6*abc6; - */ - G4ThreeVector z6 = G4ThreeVector(0,0,1); - G4ThreeVector df6 = G4ThreeVector(cos(i*360*deg/detNum6+0.5*360*deg/detNum6), - sin(i*360*deg/detNum6+0.5*360*deg/detNum6), - 0); - G4ThreeVector unitAxis6 = z6.cross(df6); - unitAxis6 = unitAxis6/unitAxis6.mag(); - G4double ux6 = unitAxis6.x(); - G4double uy6 = unitAxis6.y(); - G4double uz6 = unitAxis6.z(); - G4double angle6 = acos(z6.dot(df6)/(z6.mag()*df6.mag())); - G4ThreeVector a6 = G4ThreeVector(cos(angle6)+pow(ux6,2)*(1-cos(angle6)), ux6*uy6*(1-cos(angle6))-uz6*sin(angle6), ux6*uz6*(1-cos(angle6))+uy6*sin(angle6)); - G4ThreeVector b6 = G4ThreeVector(uy6*ux6*(1-cos(angle6))+uz6*sin(angle6), cos(angle6)+pow(uy6,2)*(1-cos(angle6)), uy6*uz6*(1-cos(angle6))-ux6*sin(angle6)); - G4ThreeVector c6 = G4ThreeVector(uz6*ux6*(1-cos(angle6))-uy6*sin(angle6), uz6*uy6*(1-cos(angle6))+ux6*sin(angle6), cos(angle6)+pow(uz6,2)*(1-cos(angle6))); - G4RotationMatrix abc6 = G4RotationMatrix(); - abc6.setRows(a6,b6,c6); - crystal_rotm.rotateZ(i*360*deg/detNum6+0.5*360*deg/detNum6); - crystal_rotm=abc6*crystal_rotm; - G4ThreeVector crystal_pos = G4ThreeVector((distanceFromTarget6+0.5*detThickness6)*cos(i*360*deg/detNum6+0.5*360*deg/detNum6), - (distanceFromTarget6+0.5*detThickness6)*sin(i*360*deg/detNum6+0.5*360*deg/detNum6), - 0)+delrin_pos6; - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - G4ThreeVector df = G4ThreeVector(distanceFromTarget6*sin(theta6)*sin(i*360*deg/detNum6/*+0.5*360*deg/detNum6*/), - distanceFromTarget6*sin(theta6)*cos(i*360*deg/detNum6/*+0.5*360*deg/detNum6*/), - -distanceFromTarget6*cos(theta6)); - G4ThreeVector lg_Axis = df.cross(z6); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4ThreeVector p = G4ThreeVector(cos(theta6)+pow(ulgx,2)*(1-cos(theta6)), ulgx*ulgy*(1-cos(theta6))-ulgz*sin(theta6), ulgx*ulgz*(1-cos(theta6))+ulgy*sin(theta6)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta6))+ulgz*sin(theta6), cos(theta6)+pow(ulgy,2)*(1-cos(theta6)), ulgy*ulgz*(1-cos(theta6))-ulgx*sin(theta6)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta6))-ulgy*sin(theta6), ulgz*ulgy*(1-cos(theta6))+ulgx*sin(theta6), cos(theta6)+pow(ulgz,2)*(1-cos(theta6))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum6); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget6+detThickness6+0.5*lgThickness6)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta6+90*deg)*sin(i*360*deg/detNum6+.001*deg), sin(theta6+90*deg)*cos(i*360*deg/detNum6+.001*deg), -cos(theta6+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z6); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg-theta6; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((-i)*360*deg/detNum6+.001*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget6+detThickness6+lgThickness6+delrinA6/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - bool placeCrystal = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (m_Array[i2] == 54+i){ - placeCrystal = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal6, //its logical volume - "CsI Detector6", //its name - world, //its mother volume - false, //no boolean operation - 54+i, //copy number - checkOverlaps); //overlaps checking - } - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide6, //its logical volume - "LightGuide6", //its name - world, //its mother volume - false, //no boolean operation - 54+i, //copy number - checkOverlaps); //overlaps checking - } - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin6, //its logical volume - "Delrin6", //its name - world, //its mother volume - false, //no boolean operation - 54+i, //copy number - checkOverlaps); //overlaps checking - } - } - }} - - if(m_Ring7){ - // Ring 7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lg pseudofixed - G4int detNum7 = 12; - G4double distanceFromTargetBack7 = 45.*mm; - G4double theta7 = 111.5*deg; - G4double halfTheta7 = 11.5*deg; //fudge factor - G4double lgThickness7 = 7.0*mm; - G4double detThickness7 = 4.1*mm; - G4double distanceFromTarget7 = distanceFromTargetBack7 - detThickness7; - - //G4double distance7 = distanceFromTarget7*sin(theta7); //this gives the distance from the beam axis. - - /* - // - // Delrin Ring (for deletion) - // - G4double delrin_rmina7 = distance7+detThickness7+lgThickness7, delrin_rmaxa7 = delrin_rmina7+5*mm; - G4double delrin_hz7 = 5*mm; //distance7*tan(halfTheta7); - G4double delrin_phimin7 = 0.*deg, delrin_phimax7 = 360.*deg; - G4ThreeVector delrin_pos7 = G4ThreeVector(0,0,-distanceFromTarget7*cos(theta7)); //G4ThreeVector(0,0,distance7+lgThickness7+detThickness7*sin(theta7)); - - G4Tubs* solidDelrin7 = - new G4Tubs("Delrin7", //its name - delrin_rmina7, delrin_rmaxa7, - delrin_hz7, - delrin_phimin7, delrin_phimax7); //its size - - G4LogicalVolume* logicDelrin7 = - new G4LogicalVolume(solidDelrin7, //its solid - delrin, //its material - "Delrin7"); //its name - logicDelrin7->SetVisAttributes(delrinVisAtt); - - if(delrinBool) {new G4PVPlacement(0, //no rotation - delrin_pos7, //its position - logicDelrin7, //its logical volume - "Delrin7", //its name - world, //its mother volume - false, //no boolean operation - 0, //copy number - checkOverlaps); //overlaps checking - } - */ - // - // Delrin Ring - // - G4double delrinA7 = 5*mm; - G4double delrinB7 = 10*mm; - G4double fdelrinHalfAngle7 = atan(delrinB7/2/(distanceFromTarget7+detThickness7+lgThickness7)); - G4double firs7 = pow(pow(distanceFromTarget7+detThickness7+lgThickness7,2)+pow(delrinB7/2,2),0.5)*sin(theta7-fdelrinHalfAngle7); - G4double firb7 = pow(pow(distanceFromTarget7+detThickness7+lgThickness7,2)+pow(delrinB7/2,2),0.5)*sin(theta7+fdelrinHalfAngle7); - G4double bdelrinHalfAngle7 = atan(delrinB7/2/(distanceFromTarget7+detThickness7+lgThickness7+delrinA7)); - G4double birs7 = pow(pow(distanceFromTarget7+detThickness7+lgThickness7+delrinA7,2)+pow(delrinB7/2,2),0.5)*sin(theta7-bdelrinHalfAngle7); - G4double birb7 = pow(pow(distanceFromTarget7+detThickness7+lgThickness7+delrinA7,2)+pow(delrinB7/2,2),0.5)*sin(theta7+bdelrinHalfAngle7); - - G4double delrin_dz7 = delrinB7/2; - G4double delrin_theta7 = 0; - G4double delrin_phi7 = 0; - G4double delrin_dyab7 = delrinA7/2; - G4double delrin_dxa7 = firs7*tan(180*deg/detNum7); - G4double delrin_dxb7 = birs7*tan(180*deg/detNum7); - G4double delrin_dycd7 = delrinA7/2; - G4double delrin_dxc7 = firb7*tan(180*deg/detNum7); - G4double delrin_dxd7 = birb7*tan(180*deg/detNum7); - G4double delrin_alpab7 = 0; - G4double delrin_alpcd7 = delrin_alpab7; - - G4ThreeVector delrin_pos7 = G4ThreeVector(0,0,-distanceFromTarget7*cos(theta7)); - - G4Trap* solidDelrin7 = - new G4Trap("Delrin7", //its name - delrin_dz7, - delrin_theta7, delrin_phi7, - delrin_dyab7, - delrin_dxa7, delrin_dxb7, - delrin_alpab7, - delrin_dycd7, - delrin_dxc7, delrin_dxd7, - delrin_alpcd7); //its size - - G4LogicalVolume* logicDelrin7 = - new G4LogicalVolume(solidDelrin7, //its solid - delrin, //its material - "Delrin7"); //its name - logicDelrin7->SetVisAttributes(delrinVisAtt); - - // - // CsI Detector - // - G4double coneheight7 = 0.6*distanceFromTarget7; - G4double coneangle7 = theta7; - G4double crystal_rmina7 = 0.*mm; - G4double crystal_rmaxa7 = 0.0001*mm; - G4double crystal_rminb7 = -coneheight7*tan(coneangle7+halfTheta7); - G4double crystal_rmaxb7 = -coneheight7*tan(coneangle7-halfTheta7); - G4double crystal_hz7 = 0.5*coneheight7; - G4double crystal_phimin7 = 0.*deg, crystal_phimax7 = 360.*deg/detNum7; - G4RotationMatrix tip_rotm7 = G4RotationMatrix(); - G4ThreeVector tip_pos7 = G4ThreeVector(0,0,crystal_hz7+.0001*mm); - G4Transform3D tip_trans7 = G4Transform3D(tip_rotm7, tip_pos7); - G4ThreeVector z7 = G4ThreeVector(0,0,1); - G4ThreeVector d07 = G4ThreeVector(distanceFromTarget7*sin(coneangle7)*cos(0.5*360*deg/detNum7), - distanceFromTarget7*sin(coneangle7)*sin(0.5*360*deg/detNum7), - -distanceFromTarget7*cos(coneangle7)); - G4ThreeVector unitAxis7 = z7.cross(d07); - unitAxis7 = unitAxis7/unitAxis7.mag(); - G4double ux7 = unitAxis7.x(); - G4double uy7 = unitAxis7.y(); - G4double uz7 = unitAxis7.z(); - G4ThreeVector top7 = G4ThreeVector(cos(-coneangle7)+pow(ux7,2)*(1-cos(-coneangle7)), ux7*uy7*(1-cos(-coneangle7))-uz7*sin(-coneangle7), ux7*uz7*(1-cos(-coneangle7))+uy7*sin(-coneangle7)); - G4ThreeVector mid7 = G4ThreeVector(uy7*ux7*(1-cos(-coneangle7))+uz7*sin(-coneangle7), cos(-coneangle7)+pow(uy7,2)*(1-cos(-coneangle7)), uy7*uz7*(1-cos(-coneangle7))-ux7*sin(-coneangle7)); - G4ThreeVector bot7 = G4ThreeVector(uz7*ux7*(1-cos(-coneangle7))-uy7*sin(-coneangle7), uz7*uy7*(1-cos(-coneangle7))+ux7*sin(-coneangle7), cos(-coneangle7)+pow(uz7,2)*(1-cos(-coneangle7))); - G4RotationMatrix firstBox_rotm7 = G4RotationMatrix(); - firstBox_rotm7.setRows(top7,mid7,bot7); - G4ThreeVector firstBox_pos7 = G4ThreeVector(0,0,0); - G4Transform3D firstBox_trans7 = G4Transform3D(firstBox_rotm7, firstBox_pos7); - G4RotationMatrix secondBox_rotm7 = G4RotationMatrix(); - secondBox_rotm7.setRows(top7,mid7,bot7); - G4ThreeVector secondBox_pos7 = (3*distanceFromTarget7+detThickness7)/distanceFromTarget7*d07; - G4Transform3D secondBox_trans7 = G4Transform3D(secondBox_rotm7, secondBox_pos7); - - G4Orb* solidTip7 = - new G4Orb("tip7", - .0001*mm); - G4Box* solidSubtractionBox7 = - new G4Box("SubtractionBox7", //its name - distanceFromTarget7, - distanceFromTarget7, - distanceFromTarget7); //its size - G4Box* solidSecondSubtractionBox7 = - new G4Box("SecondSubtractionBox7", //its name - 2*distanceFromTarget7, - 2*distanceFromTarget7, - 2*distanceFromTarget7); //its size - G4Cons* solidCone7 = - new G4Cons("Cone7", //its name - crystal_rmina7, crystal_rmaxa7, - crystal_rminb7, crystal_rmaxb7, - crystal_hz7, - crystal_phimin7, crystal_phimax7); //its size - G4UnionSolid* solidTippedCone7 = - new G4UnionSolid("TippedCone7", - solidTip7, - solidCone7, - tip_trans7); - G4SubtractionSolid* solidIntermediate7 = - new G4SubtractionSolid("Intermediate7", - solidTippedCone7, - solidSubtractionBox7, - firstBox_trans7); - G4SubtractionSolid* solidCrystal7 = - new G4SubtractionSolid("Crystal7", - solidIntermediate7, - solidSecondSubtractionBox7, - secondBox_trans7); - - G4LogicalVolume* logicCrystal7 = - new G4LogicalVolume(solidCrystal7, //its solid - CsI, //its material - "CsI Detector7"); //its name - logicCrystal7->SetVisAttributes(crystalVisAtt); - logicCrystal7->SetSensitiveDetector(m_MicroballScorer); - // - // Light Guide - // - G4double lightGuide_px7 = 10*mm; - G4double lightGuide_py7 = 10*mm; - G4double lightGuide_pz7 = lgThickness7; - G4Box* solidLightGuide7 = - new G4Box("LightGuide7", //its name - 0.5*lightGuide_px7, - 0.5*lightGuide_py7, - 0.5*lightGuide_pz7); //its size + // Reinitialisation of Check Boolean + check_Ring1 = false ; + check_Ring2 = false ; + check_Ring3 = false ; + check_Ring4 = false ; + check_Ring5 = false ; + check_Ring6 = false ; + check_Ring7 = false ; + check_Ring8 = false ; + check_Ring9 = false ; + check_Array = false ; - G4LogicalVolume* logicLightGuide7 = - new G4LogicalVolume(solidLightGuide7, //its solid - glass, //its material - "LightGuide7"); //its name - logicLightGuide7->SetVisAttributes(lightGuideVisAtt); - - - for(int i = 1; i <= detNum7; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - G4ThreeVector d0 = G4ThreeVector(distanceFromTarget7*sin(coneangle7)*cos(0.5*360*deg/detNum7), - distanceFromTarget7*sin(coneangle7)*sin(0.5*360*deg/detNum7), - distanceFromTarget7*cos(coneangle7)); - G4ThreeVector df = G4ThreeVector(distanceFromTarget7*sin(theta7)*sin(i*360*deg/detNum7+.001*deg/*+0.5*360*deg/detNum7*/), - distanceFromTarget7*sin(theta7)*cos(i*360*deg/detNum7+.001*deg/*+0.5*360*deg/detNum7*/), - -distanceFromTarget7*cos(theta7)); - G4ThreeVector axis = d0.cross(df); - G4double ax = axis.x(); - G4double ay = axis.y(); - G4double az = axis.z(); - G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); - G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); - G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); - G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); - G4RotationMatrix abc = G4RotationMatrix(); - abc.setRows(a,b,c); - G4ThreeVector unitdf = df/df.mag(); - G4double udfx = unitdf.x(); - G4double udfy = unitdf.y(); - G4double udfz = unitdf.z(); - G4double k = 180.*deg; - G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); - G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); - G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); - G4RotationMatrix def = G4RotationMatrix(); - def.setRows(d,e,f); - crystal_rotm=def*abc; - crystal_rotm.rotateY(180*deg); - G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - G4ThreeVector lg_Axis = df.cross(z7); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4double lg_ang = theta7; - G4ThreeVector p = G4ThreeVector(cos(lg_ang)+pow(ulgx,2)*(1-cos(lg_ang)), ulgx*ulgy*(1-cos(lg_ang))-ulgz*sin(lg_ang), ulgx*ulgz*(1-cos(lg_ang))+ulgy*sin(lg_ang)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(lg_ang))+ulgz*sin(lg_ang), cos(lg_ang)+pow(ulgy,2)*(1-cos(lg_ang)), ulgy*ulgz*(1-cos(lg_ang))-ulgx*sin(lg_ang)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(lg_ang))-ulgy*sin(lg_ang), ulgz*ulgy*(1-cos(lg_ang))+ulgx*sin(lg_ang), cos(lg_ang)+pow(ulgz,2)*(1-cos(lg_ang))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum7); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget7+detThickness7+0.5*lgThickness7+.0003*mm)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta7+90*deg)*sin(i*360*deg/detNum7+.001*deg), sin(theta7+90*deg)*cos(i*360*deg/detNum7+.001*deg), -cos(theta7+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z7); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg+theta7; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((i)*360*deg/detNum7+.001*deg); - delrin_rotm.rotateX(180*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget7+detThickness7+lgThickness7+delrinA7/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - bool placeCrystal = true; - bool placeDel = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (148-m_Array[i2] == 68+i){ - placeCrystal = false; - } - if (m_Array[i2] == 68+i){ - placeDel = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal7, //its logical volume - "CsI Detector7", //its name - world, //its mother volume - false, //no boolean operation - 68+i, //copy number - checkOverlaps); //overlaps checking - } - } - if(placeDel){ - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide7, //its logical volume - "LightGuide7", //its name - world, //its mother volume - false, //no boolean operation - 68+i, //copy number - checkOverlaps); //overlaps checking - } - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin7, //its logical volume - "Delrin7", //its name - world, //its mother volume - false, //no boolean operation - 68+i, //copy number - checkOverlaps); //overlaps checking - } - } - }} - - - if(m_Ring8) { - // Ring 8 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - G4int detNum8 = 10; - G4double distanceFromTargetBack8 = 47*mm; //Its really 47 mm from the target, but at 45.9 we avoid intersection the detectors in ring 9 - G4double theta8 = 135.0*deg; - G4double halfTheta8 = 12.0*deg; //+0.1*deg; //fudge factor - G4double lgThickness8 = 7.5*mm; - G4double detThickness8 = 3.6*mm; - G4double distanceFromTarget8 = distanceFromTargetBack8 - detThickness8; - - //G4double distance8 = distanceFromTarget8*sin(theta8); //this gives the distance from the beam axis. - /* - // - // Delrin Ring (for deletion) - // - G4double delrin_rmina8 = distance8+detThickness8+lgThickness8, delrin_rmaxa8 = delrin_rmina8+5*mm; - G4double delrin_hz8 = 5*mm; //distance8*tan(halfTheta8); - G4double delrin_phimin8 = 0.*deg, delrin_phimax8 = 360.*deg; - G4ThreeVector delrin_pos8 = G4ThreeVector(0,0,-distanceFromTarget8*cos(theta8)); //G4ThreeVector(0,0,distance8+lgThickness8+detThickness8*sin(theta8)); - - G4Tubs* solidDelrin8 = - new G4Tubs("Delrin8", //its name - delrin_rmina8, delrin_rmaxa8, - delrin_hz8, - delrin_phimin8, delrin_phimax8); //its size - - G4LogicalVolume* logicDelrin8 = - new G4LogicalVolume(solidDelrin8, //its solid - delrin, //its material - "Delrin8"); //its name - logicDelrin8->SetVisAttributes(delrinVisAtt); - - if(delrinBool) {new G4PVPlacement(0, //no rotation - delrin_pos8, //its position - logicDelrin8, //its logical volume - "Delrin8", //its name - world, //its mother volume - false, //no boolean operation - 0, //copy number - checkOverlaps); //overlaps checking - } - */ - // - // Delrin Ring - // - G4double delrinA8 = 5*mm; - G4double delrinB8 = 10*mm; - G4double fdelrinHalfAngle8 = atan(delrinB8/2/(distanceFromTarget8+detThickness8+lgThickness8)); - G4double firs8 = pow(pow(distanceFromTarget8+detThickness8+lgThickness8,2)+pow(delrinB8/2,2),0.5)*sin(theta8-fdelrinHalfAngle8); - G4double firb8 = pow(pow(distanceFromTarget8+detThickness8+lgThickness8,2)+pow(delrinB8/2,2),0.5)*sin(theta8+fdelrinHalfAngle8); - G4double bdelrinHalfAngle8 = atan(delrinB8/2/(distanceFromTarget8+detThickness8+lgThickness8+delrinA8)); - G4double birs8 = pow(pow(distanceFromTarget8+detThickness8+lgThickness8+delrinA8,2)+pow(delrinB8/2,2),0.5)*sin(theta8-bdelrinHalfAngle8); - G4double birb8 = pow(pow(distanceFromTarget8+detThickness8+lgThickness8+delrinA8,2)+pow(delrinB8/2,2),0.5)*sin(theta8+bdelrinHalfAngle8); - - G4double delrin_dz8 = delrinB8/2; - G4double delrin_theta8 = 0; - G4double delrin_phi8 = 0; - G4double delrin_dyab8 = delrinA8/2; - G4double delrin_dxa8 = firs8*tan(180*deg/detNum8); - G4double delrin_dxb8 = birs8*tan(180*deg/detNum8); - G4double delrin_dycd8 = delrinA8/2; - G4double delrin_dxc8 = firb8*tan(180*deg/detNum8); - G4double delrin_dxd8 = birb8*tan(180*deg/detNum8); - G4double delrin_alpab8 = 0; - G4double delrin_alpcd8 = delrin_alpab8; - - G4ThreeVector delrin_pos8 = G4ThreeVector(0,0,-distanceFromTarget8*cos(theta8)); + ReadingStatus = false ; + G4cout << "///"<< G4endl ; + } + } + } +} +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... - G4Trap* solidDelrin8 = - new G4Trap("Delrin8", //its name - delrin_dz8, - delrin_theta8, delrin_phi8, - delrin_dyab8, - delrin_dxa8, delrin_dxb8, - delrin_alpab8, - delrin_dycd8, - delrin_dxc8, delrin_dxd8, - delrin_alpcd8); //its size - - G4LogicalVolume* logicDelrin8 = - new G4LogicalVolume(solidDelrin8, //its solid - delrin, //its material - "Delrin8"); //its name - logicDelrin8->SetVisAttributes(delrinVisAtt); +// Construct detector and inialise sensitive part. +// Called After DetecorConstruction::AddDetector Method +void Microball::ConstructDetector(G4LogicalVolume* world){ + //the below for-loop is commented out, and to be replaced with our detector geometry. - // - // CsI Detector - // - G4double coneheight8 = distanceFromTarget8; - G4double coneangle8 = theta8; - G4double crystal_rmina8 = 0.*mm; - G4double crystal_rmaxa8 = 0.0001*mm; - G4double crystal_rminb8 = -coneheight8*tan(coneangle8+halfTheta8); - G4double crystal_rmaxb8 = -coneheight8*tan(coneangle8-halfTheta8); - G4double crystal_hz8 = 0.5*coneheight8; - G4double crystal_phimin8 = 0.*deg, crystal_phimax8 = 360.*deg/detNum8; - G4RotationMatrix tip_rotm8 = G4RotationMatrix(); - G4ThreeVector tip_pos8 = G4ThreeVector(0,0,crystal_hz8+.0001*mm); - G4Transform3D tip_trans8 = G4Transform3D(tip_rotm8, tip_pos8); - G4ThreeVector z8 = G4ThreeVector(0,0,1); - G4ThreeVector d08 = G4ThreeVector(distanceFromTarget8*sin(coneangle8)*cos(0.5*360*deg/detNum8), - distanceFromTarget8*sin(coneangle8)*sin(0.5*360*deg/detNum8), - -distanceFromTarget8*cos(coneangle8)); - G4ThreeVector unitAxis8 = z8.cross(d08); - unitAxis8 = unitAxis8/unitAxis8.mag(); - G4double ux8 = unitAxis8.x(); - G4double uy8 = unitAxis8.y(); - G4double uz8 = unitAxis8.z(); - G4ThreeVector top8 = G4ThreeVector(cos(-coneangle8)+pow(ux8,2)*(1-cos(-coneangle8)), ux8*uy8*(1-cos(-coneangle8))-uz8*sin(-coneangle8), ux8*uz8*(1-cos(-coneangle8))+uy8*sin(-coneangle8)); - G4ThreeVector mid8 = G4ThreeVector(uy8*ux8*(1-cos(-coneangle8))+uz8*sin(-coneangle8), cos(-coneangle8)+pow(uy8,2)*(1-cos(-coneangle8)), uy8*uz8*(1-cos(-coneangle8))-ux8*sin(-coneangle8)); - G4ThreeVector bot8 = G4ThreeVector(uz8*ux8*(1-cos(-coneangle8))-uy8*sin(-coneangle8), uz8*uy8*(1-cos(-coneangle8))+ux8*sin(-coneangle8), cos(-coneangle8)+pow(uz8,2)*(1-cos(-coneangle8))); - G4RotationMatrix firstBox_rotm8 = G4RotationMatrix(); - firstBox_rotm8.setRows(top8,mid8,bot8); - G4ThreeVector firstBox_pos8 = G4ThreeVector(0,0,0); - G4Transform3D firstBox_trans8 = G4Transform3D(firstBox_rotm8, firstBox_pos8); - G4RotationMatrix secondBox_rotm8 = G4RotationMatrix(); - secondBox_rotm8.setRows(top8,mid8,bot8); - G4ThreeVector secondBox_pos8 = (2*distanceFromTarget8+detThickness8)/d08.mag()*d08; - G4Transform3D secondBox_trans8 = G4Transform3D(secondBox_rotm8, secondBox_pos8); - - G4Orb* solidTip8 = - new G4Orb("tip8", - .0001*mm); - G4Box* solidSubtractionBox8 = - new G4Box("SubtractionBox8", //its name - distanceFromTarget8, - distanceFromTarget8, - distanceFromTarget8); //its size - G4Cons* solidCone8 = - new G4Cons("Cone8", //its name - crystal_rmina8, crystal_rmaxa8, - crystal_rminb8, crystal_rmaxb8, - crystal_hz8, - crystal_phimin8, crystal_phimax8); //its size - G4UnionSolid* solidTippedCone8 = - new G4UnionSolid("TippedCone8", - solidTip8, - solidCone8, - tip_trans8); - G4SubtractionSolid* solidIntermediate8 = - new G4SubtractionSolid("Intermediate8", - solidTippedCone8, - solidSubtractionBox8, - firstBox_trans8); - G4SubtractionSolid* solidCrystal8 = - new G4SubtractionSolid("Crystal8", - solidIntermediate8, - solidSubtractionBox8, - secondBox_trans8); - - G4LogicalVolume* logicCrystal8 = - new G4LogicalVolume(solidCrystal8, //its solid - CsI, //its material - "CsI Detector8"); //its name - logicCrystal8->SetVisAttributes(crystalVisAtt); - logicCrystal8->SetSensitiveDetector(m_MicroballScorer); - // - // Light Guide - // - G4double lightGuide_px8 = 10*mm; - G4double lightGuide_py8 = 10*mm; - G4double lightGuide_pz8 = lgThickness8; - G4Box* solidLightGuide8 = - new G4Box("LightGuide8", //its name - 0.5*lightGuide_px8, - 0.5*lightGuide_py8, - 0.5*lightGuide_pz8); //its size - - G4LogicalVolume* logicLightGuide8 = - new G4LogicalVolume(solidLightGuide8, //its solid - glass, //its material - "LightGuide8"); //its name - logicLightGuide8->SetVisAttributes(lightGuideVisAtt); - - - for(int i = 1; i <= detNum8; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - G4ThreeVector d0 = G4ThreeVector(distanceFromTarget8*sin(coneangle8)*cos(0.5*360*deg/detNum8), - distanceFromTarget8*sin(coneangle8)*sin(0.5*360*deg/detNum8), - distanceFromTarget8*cos(coneangle8)); - G4ThreeVector df = G4ThreeVector(distanceFromTarget8*sin(theta8)*sin(i*360*deg/detNum8+.001*deg/*+0.5*360*deg/detNum8*/), - distanceFromTarget8*sin(theta8)*cos(i*360*deg/detNum8+.001*deg/*+0.5*360*deg/detNum8*/), - -distanceFromTarget8*cos(theta8)); - G4ThreeVector axis = d0.cross(df); - G4double ax = axis.x(); - G4double ay = axis.y(); - G4double az = axis.z(); - G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); - G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); - G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); - G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); - G4RotationMatrix abc = G4RotationMatrix(); - abc.setRows(a,b,c); - G4ThreeVector unitdf = df/df.mag(); - G4double udfx = unitdf.x(); - G4double udfy = unitdf.y(); - G4double udfz = unitdf.z(); - G4double k = 180.*deg; - G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); - G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); - G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); - G4RotationMatrix def = G4RotationMatrix(); - def.setRows(d,e,f); - crystal_rotm=def*abc; - crystal_rotm.rotateY(180*deg); - G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - G4ThreeVector lg_Axis = df.cross(z8); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4ThreeVector p = G4ThreeVector(cos(theta8)+pow(ulgx,2)*(1-cos(theta8)), ulgx*ulgy*(1-cos(theta8))-ulgz*sin(theta8), ulgx*ulgz*(1-cos(theta8))+ulgy*sin(theta8)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta8))+ulgz*sin(theta8), cos(theta8)+pow(ulgy,2)*(1-cos(theta8)), ulgy*ulgz*(1-cos(theta8))-ulgx*sin(theta8)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta8))-ulgy*sin(theta8), ulgz*ulgy*(1-cos(theta8))+ulgx*sin(theta8), cos(theta8)+pow(ulgz,2)*(1-cos(theta8))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum8); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget8+detThickness8+0.5*lgThickness8+.0003*mm)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta8+90*deg)*sin(i*360*deg/detNum8+.001*deg), sin(theta8+90*deg)*cos(i*360*deg/detNum8+.001*deg), -cos(theta8+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z8); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg+theta8; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((i)*360*deg/detNum8+.001*deg); - delrin_rotm.rotateX(180*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget8+detThickness8+lgThickness8+delrinA8/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - bool placeCrystal = true; - bool placeDel = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (170-m_Array[i2] == 80+i){ - placeCrystal = false; - } - if (m_Array[i2] == 80+i){ - placeDel = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal8, //its logical volume - "CsI Detector8", //its name - world, //its mother volume - false, //no boolean operation - 80+i, //copy number - checkOverlaps); //overlaps checking - } - } - if (placeDel){ - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide8, //its logical volume - "LightGuide8", //its name - world, //its mother volume - false, //no boolean operation - 80+i, //copy number - checkOverlaps); //overlaps checking - } - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin8, //its logical volume - "Delrin8", //its name - world, //its mother volume - false, //no boolean operation - 80+i, //copy number - checkOverlaps); //overlaps checking - } - } - }} - - - if(m_Ring9){ - // Ring 9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - G4int detNum9 = 6; - G4double distanceFromTargetBack9 = 50.*mm; - G4double theta9 = 159.0*deg; - G4double halfTheta9 = 12.0*deg; //+0.1*deg; //0.1 is a fudge factor to make it cover a solid angle of 4 pi - G4double lgThickness9 = 8.0*mm; - G4double detThickness9 = 3.5*mm; - G4double distanceFromTarget9 = distanceFromTargetBack9 - detThickness9; - - //G4double distance9 = distanceFromTarget9*sin(theta9); //this gives the distance from the beam axis. - - /* - // - // Delrin Ring (for deletion) - // - G4double delrin_rmina9 = distance9+detThickness9+lgThickness9, delrin_rmaxa9 = delrin_rmina9+5*mm; - G4double delrin_hz9 = 5*mm; //distance9*tan(halfTheta9); - G4double delrin_phimin9 = 0.*deg, delrin_phimax9 = 360.*deg; - G4ThreeVector delrin_pos9 = G4ThreeVector(0,0,-distanceFromTarget9*cos(theta9)); //G4ThreeVector(0,0,distance9+lgThickness9+detThickness9*sin(theta9)); - - G4Tubs* solidDelrin9 = - new G4Tubs("Delrin9", //its name - delrin_rmina9, delrin_rmaxa9, - delrin_hz9, - delrin_phimin9, delrin_phimax9); //its size - - G4LogicalVolume* logicDelrin9 = - new G4LogicalVolume(solidDelrin9, //its solid - delrin, //its material - "Delrin9"); //its name - logicDelrin9->SetVisAttributes(delrinVisAtt); - - if(delrinBool) {new G4PVPlacement(0, //no rotation - delrin_pos9, //its position - logicDelrin9, //its logical volume - "Delrin9", //its name - world, //its mother volume - false, //no boolean operation - 0, //copy number - checkOverlaps); //overlaps checking - } -*/ - - // - // Delrin Ring - // - G4double delrinA9 = 5*mm; - G4double delrinB9 = 10*mm; - G4double fdelrinHalfAngle9 = atan(delrinB9/2/(distanceFromTarget9+detThickness9+lgThickness9)); - G4double firs9 = pow(pow(distanceFromTarget9+detThickness9+lgThickness9,2)+pow(delrinB9/2,2),0.5)*sin(theta9-fdelrinHalfAngle9); - G4double firb9 = pow(pow(distanceFromTarget9+detThickness9+lgThickness9,2)+pow(delrinB9/2,2),0.5)*sin(theta9+fdelrinHalfAngle9); - G4double bdelrinHalfAngle9 = atan(delrinB9/2/(distanceFromTarget9+detThickness9+lgThickness9+delrinA9)); - G4double birs9 = pow(pow(distanceFromTarget9+detThickness9+lgThickness9+delrinA9,2)+pow(delrinB9/2,2),0.5)*sin(theta9-bdelrinHalfAngle9); - G4double birb9 = pow(pow(distanceFromTarget9+detThickness9+lgThickness9+delrinA9,2)+pow(delrinB9/2,2),0.5)*sin(theta9+bdelrinHalfAngle9); - - G4double delrin_dz9 = delrinB9/2; - G4double delrin_theta9 = 0; - G4double delrin_phi9 = 0; - G4double delrin_dyab9 = delrinA9/2; - G4double delrin_dxa9 = firs9*tan(180*deg/detNum9); - G4double delrin_dxb9 = birs9*tan(180*deg/detNum9); - G4double delrin_dycd9 = delrinA9/2; - G4double delrin_dxc9 = firb9*tan(180*deg/detNum9); - G4double delrin_dxd9 = birb9*tan(180*deg/detNum9); - G4double delrin_alpab9 = 0; - G4double delrin_alpcd9 = delrin_alpab9; - - G4ThreeVector delrin_pos9 = G4ThreeVector(0,0,-distanceFromTarget9*cos(theta9)); - - G4Trap* solidDelrin9 = - new G4Trap("Delrin9", //its name - delrin_dz9, - delrin_theta9, delrin_phi9, - delrin_dyab9, - delrin_dxa9, delrin_dxb9, - delrin_alpab9, - delrin_dycd9, - delrin_dxc9, delrin_dxd9, - delrin_alpcd9); //its size - - G4LogicalVolume* logicDelrin9 = - new G4LogicalVolume(solidDelrin9, //its solid - delrin, //its material - "Delrin9"); //its name - logicDelrin9->SetVisAttributes(delrinVisAtt); - - // - // CsI Detector - // - G4double coneheight9 = distanceFromTarget9; - G4double coneangle9 = theta9; - G4double crystal_rmina9 = 0.*mm; - G4double crystal_rmaxa9 = 0.0001*mm; - G4double crystal_rminb9 = -coneheight9*tan(coneangle9+halfTheta9); - G4double crystal_rmaxb9 = -coneheight9*tan(coneangle9-halfTheta9); - G4double crystal_hz9 = 0.5*coneheight9; - G4double crystal_phimin9 = 0.*deg, crystal_phimax9 = 360.*deg/detNum9; - G4RotationMatrix tip_rotm9 = G4RotationMatrix(); - G4ThreeVector tip_pos9 = G4ThreeVector(0,0,crystal_hz9+.0001*mm); - G4Transform3D tip_trans9 = G4Transform3D(tip_rotm9, tip_pos9); - G4ThreeVector z9 = G4ThreeVector(0,0,1); - G4ThreeVector d09 = G4ThreeVector(distanceFromTarget9*sin(coneangle9)*cos(0.5*360*deg/detNum9), - distanceFromTarget9*sin(coneangle9)*sin(0.5*360*deg/detNum9), - -distanceFromTarget9*cos(coneangle9)); - G4ThreeVector unitAxis9 = z9.cross(d09); - unitAxis9 = unitAxis9/unitAxis9.mag(); - G4double ux9 = unitAxis9.x(); - G4double uy9 = unitAxis9.y(); - G4double uz9 = unitAxis9.z(); - G4ThreeVector top9 = G4ThreeVector(cos(-coneangle9)+pow(ux9,2)*(1-cos(-coneangle9)), ux9*uy9*(1-cos(-coneangle9))-uz9*sin(-coneangle9), ux9*uz9*(1-cos(-coneangle9))+uy9*sin(-coneangle9)); - G4ThreeVector mid9 = G4ThreeVector(uy9*ux9*(1-cos(-coneangle9))+uz9*sin(-coneangle9), cos(-coneangle9)+pow(uy9,2)*(1-cos(-coneangle9)), uy9*uz9*(1-cos(-coneangle9))-ux9*sin(-coneangle9)); - G4ThreeVector bot9 = G4ThreeVector(uz9*ux9*(1-cos(-coneangle9))-uy9*sin(-coneangle9), uz9*uy9*(1-cos(-coneangle9))+ux9*sin(-coneangle9), cos(-coneangle9)+pow(uz9,2)*(1-cos(-coneangle9))); - G4RotationMatrix firstBox_rotm9 = G4RotationMatrix(); - firstBox_rotm9.setRows(top9,mid9,bot9); - G4ThreeVector firstBox_pos9 = G4ThreeVector(0,0,0); - G4Transform3D firstBox_trans9 = G4Transform3D(firstBox_rotm9, firstBox_pos9); - G4RotationMatrix secondBox_rotm9 = G4RotationMatrix(); - secondBox_rotm9.setRows(top9,mid9,bot9); - G4ThreeVector secondBox_pos9 = (2*distanceFromTarget9+detThickness9)/d09.mag()*d09; - G4Transform3D secondBox_trans9 = G4Transform3D(secondBox_rotm9, secondBox_pos9); - - G4Orb* solidTip9 = - new G4Orb("tip9", - .0001*mm); - G4Box* solidSubtractionBox9 = - new G4Box("SubtractionBox9", //its name - distanceFromTarget9, - distanceFromTarget9, - distanceFromTarget9); //its size - G4Cons* solidCone9 = - new G4Cons("Cone9", //its name - crystal_rmina9, crystal_rmaxa9, - crystal_rminb9, crystal_rmaxb9, - crystal_hz9, - crystal_phimin9, crystal_phimax9); //its size - G4UnionSolid* solidTippedCone9 = - new G4UnionSolid("TippedCone9", - solidTip9, - solidCone9, - tip_trans9); - G4SubtractionSolid* solidIntermediate9 = - new G4SubtractionSolid("Intermediate9", - solidTippedCone9, - solidSubtractionBox9, - firstBox_trans9); - G4SubtractionSolid* solidCrystal9 = - new G4SubtractionSolid("Crystal9", - solidIntermediate9, - solidSubtractionBox9, - secondBox_trans9); - - G4LogicalVolume* logicCrystal9 = - new G4LogicalVolume(solidCrystal9, //its solid - CsI, //its material - "CsI Detector9"); //its name - logicCrystal9->SetVisAttributes(crystalVisAtt); - logicCrystal9->SetSensitiveDetector(m_MicroballScorer); - - // - // Light Guide - // - G4double lightGuide_px9 = 10*mm; - G4double lightGuide_py9 = 10*mm; - G4double lightGuide_pz9 = lgThickness9; - G4Box* solidLightGuide9 = - new G4Box("LightGuide9", //its name - 0.5*lightGuide_px9, - 0.5*lightGuide_py9, - 0.5*lightGuide_pz9); //its size - - G4LogicalVolume* logicLightGuide9 = - new G4LogicalVolume(solidLightGuide9, //its solid - glass, //its material - "LightGuide9"); //its name - logicLightGuide9->SetVisAttributes(lightGuideVisAtt); - - - for(int i = 1; i <= detNum9; i++) - { - G4RotationMatrix crystal_rotm = G4RotationMatrix(); - G4ThreeVector d0 = G4ThreeVector(distanceFromTarget9*sin(coneangle9)*cos(0.5*360*deg/detNum9), - distanceFromTarget9*sin(coneangle9)*sin(0.5*360*deg/detNum9), - distanceFromTarget9*cos(coneangle9)); - G4ThreeVector df = G4ThreeVector(distanceFromTarget9*sin(theta9)*sin(i*360*deg/detNum9+.001*deg/*+0.5*360*deg/detNum9*/), - distanceFromTarget9*sin(theta9)*cos(i*360*deg/detNum9+.001*deg/*+0.5*360*deg/detNum9*/), - -distanceFromTarget9*cos(theta9)); - G4ThreeVector axis = d0.cross(df); - G4double ax = axis.x(); - G4double ay = axis.y(); - G4double az = axis.z(); - G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); - G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); - G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); - G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); - G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); - G4RotationMatrix abc = G4RotationMatrix(); - abc.setRows(a,b,c); - G4ThreeVector unitdf = df/df.mag(); - G4double udfx = unitdf.x(); - G4double udfy = unitdf.y(); - G4double udfz = unitdf.z(); - G4double k = 180.*deg; - G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); - G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); - G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); - G4RotationMatrix def = G4RotationMatrix(); - def.setRows(d,e,f); - crystal_rotm=def*abc; - crystal_rotm.rotateY(180*deg); - G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); - G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); - G4RotationMatrix lg_rotm = G4RotationMatrix(); - /* - lg_rotm.rotateZ(i*360*deg/detNum9); - G4ThreeVector lg_pos = G4ThreeVector((distance9+detThickness9+0.5*lgThickness9)*cos(i*360*deg/detNum9), - (distance9+detThickness9+0.5*lgThickness9)*sin(i*360*deg/detNum9), - 0)+delrin_pos9; - */ - G4ThreeVector lg_Axis = df.cross(z9); - lg_Axis = lg_Axis/lg_Axis.mag(); - G4double ulgx = lg_Axis.x(); - G4double ulgy = lg_Axis.y(); - G4double ulgz = lg_Axis.z(); - G4ThreeVector p = G4ThreeVector(cos(theta9)+pow(ulgx,2)*(1-cos(theta9)), ulgx*ulgy*(1-cos(theta9))-ulgz*sin(theta9), ulgx*ulgz*(1-cos(theta9))+ulgy*sin(theta9)); - G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta9))+ulgz*sin(theta9), cos(theta9)+pow(ulgy,2)*(1-cos(theta9)), ulgy*ulgz*(1-cos(theta9))-ulgx*sin(theta9)); - G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta9))-ulgy*sin(theta9), ulgz*ulgy*(1-cos(theta9))+ulgx*sin(theta9), cos(theta9)+pow(ulgz,2)*(1-cos(theta9))); - G4RotationMatrix pqr = G4RotationMatrix(); - pqr.setRows(p,q,r); - lg_rotm.rotateZ(i*360*deg/detNum9); - lg_rotm.rotateX(180*deg); - lg_rotm=pqr*lg_rotm; - G4ThreeVector lg_pos = (distanceFromTarget9+detThickness9+0.5*lgThickness9+.0003*mm)/df.mag()*df; - G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); - G4RotationMatrix delrin_rotm = G4RotationMatrix(); - G4ThreeVector w = G4ThreeVector(sin(theta9+90*deg)*sin(i*360*deg/detNum9+.001*deg), sin(theta9+90*deg)*cos(i*360*deg/detNum9+.001*deg), -cos(theta9+90*deg)); - G4ThreeVector delrin_Axis = w.cross(-z9); - delrin_Axis = delrin_Axis/delrin_Axis.mag(); - G4double udx = delrin_Axis.x(); - G4double udy = delrin_Axis.y(); - G4double udz = delrin_Axis.z(); - G4double delAng = 90*deg+theta9; - G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); - G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); - G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); - G4RotationMatrix pqrdel = G4RotationMatrix(); - pqrdel.setRows(pdel,qdel,rdel); - delrin_rotm.rotateZ((i)*360*deg/detNum9+.001*deg); - delrin_rotm.rotateX(180*deg); - delrin_rotm=pqrdel*delrin_rotm; - G4ThreeVector delrin_pos = (distanceFromTarget9+detThickness9+lgThickness9+delrinA9/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping - G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); - bool placeCrystal = true; - bool placeDel = true; - for (unsigned int i2=0; i2 < m_Array.size(); i2++){ - if (186-m_Array[i2] == 90+i){ - placeCrystal = false; - } - if (m_Array[i2] == 90+i){ - placeDel = false; - } - } - if (placeCrystal){ - if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position - logicCrystal9, //its logical volume - "CsI Detector9", //its name - world, //its mother volume - false, //no boolean operation - 90+i, //copy number - checkOverlaps); //overlaps checking - } - } - if (placeDel){ - if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position - logicLightGuide9, //its logical volume - "LightGuide9", //its name - world, //its mother volume - false, //no boolean operation - 90+i, //copy number - checkOverlaps); //overlaps checking - } - if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position - logicDelrin9, //its logical volume - "Delrin9", //its name - world, //its mother volume - false, //no boolean operation - 90+i, //copy number - checkOverlaps); //overlaps checking - } - } - }} + G4bool checkOverlaps = true; + G4double delrinBool = 1; + G4double crystalBool = 1; + G4double lgBool = 1; + + /*G4double ring1Bool = 1; + G4double ring2Bool = 1; + G4double ring3Bool = 1; + G4double ring4Bool = 1; + G4double ring5Bool = 1; + G4double ring6Bool = 1; + G4double ring7Bool = 1; + G4double ring8Bool = 1; + G4double ring9Bool = 1;*/ + + G4NistManager* nist = G4NistManager::Instance(); + + G4Material* CsI = nist->FindOrBuildMaterial("G4_CESIUM_IODIDE"); + G4VisAttributes* crystalVisAtt = new G4VisAttributes(G4Colour(0.,1.,0., .5)); + G4Material* glass = nist->FindOrBuildMaterial("G4_Pyrex_Glass"); + G4VisAttributes* lightGuideVisAtt = new G4VisAttributes(G4Colour(0.,0.,1.)); + G4Material* delrin = nist->FindOrBuildMaterial("G4_POLYOXYMETHYLENE"); + G4VisAttributes* delrinVisAtt = new G4VisAttributes(G4Colour(1.,0.,0.)); + + if(m_Ring1){ + // Ring 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lg pseudofixed + G4int detNum1 = 6; + G4double distanceFromTargetBack1 = 110.*mm; + G4double theta1 = 9.0*deg; + G4double halfTheta1 = 5.0*deg; + G4double lgThickness1 = 8.0*mm; + G4double detThickness1 = 9.2*mm; + G4double distanceFromTarget1 = distanceFromTargetBack1 - detThickness1; + + //G4double distance1 = distanceFromTarget1*sin(theta1); //this gives the distance from the beam axis. + + // + // Delrin Ring + // + G4double delrinA1 = 5*mm; + G4double delrinB1 = 10*mm; + G4double fdelrinHalfAngle1 = atan(delrinB1/2/(distanceFromTarget1+detThickness1+lgThickness1)); + G4double firs1 = pow(pow(distanceFromTarget1+detThickness1+lgThickness1,2)+pow(delrinB1/2,2),0.5)*sin(theta1-fdelrinHalfAngle1); + G4double firb1 = pow(pow(distanceFromTarget1+detThickness1+lgThickness1,2)+pow(delrinB1/2,2),0.5)*sin(theta1+fdelrinHalfAngle1); + G4double bdelrinHalfAngle1 = atan(delrinB1/2/(distanceFromTarget1+detThickness1+lgThickness1+delrinA1)); + G4double birs1 = pow(pow(distanceFromTarget1+detThickness1+lgThickness1+delrinA1,2)+pow(delrinB1/2,2),0.5)*sin(theta1-bdelrinHalfAngle1); + G4double birb1 = pow(pow(distanceFromTarget1+detThickness1+lgThickness1+delrinA1,2)+pow(delrinB1/2,2),0.5)*sin(theta1+bdelrinHalfAngle1); + + G4double delrin_dz1 = delrinB1/2; + G4double delrin_theta1 = 0; + G4double delrin_phi1 = 0; + G4double delrin_dyab1 = delrinA1/2; + G4double delrin_dxa1 = firs1*tan(180*deg/detNum1); + G4double delrin_dxb1 = birs1*tan(180*deg/detNum1); + G4double delrin_dycd1 = delrinA1/2; + G4double delrin_dxc1 = firb1*tan(180*deg/detNum1); + G4double delrin_dxd1 = birb1*tan(180*deg/detNum1); + G4double delrin_alpab1 = 0; + G4double delrin_alpcd1 = delrin_alpab1; + + + G4ThreeVector delrin_pos1 = G4ThreeVector(0,0,-distanceFromTarget1*cos(theta1)); + + G4Trap* solidDelrin1 = + new G4Trap("Delrin1", //its name + delrin_dz1, + delrin_theta1, delrin_phi1, + delrin_dyab1, + delrin_dxa1, delrin_dxb1, + delrin_alpab1, + delrin_dycd1, + delrin_dxc1, delrin_dxd1, + delrin_alpcd1); //its size + + G4LogicalVolume* logicDelrin1 = + new G4LogicalVolume(solidDelrin1, //its solid + delrin, //its material + "Delrin1"); //its name + logicDelrin1->SetVisAttributes(delrinVisAtt); + + // + // CsI Detector + // + G4double coneheight1 = 2*distanceFromTarget1; + G4double coneangle1 = theta1; + G4double crystal_rmina1 = 0.*mm; + G4double crystal_rmaxa1 = 0.0001*mm; + G4double crystal_rminb1 = coneheight1*tan(coneangle1-halfTheta1); + G4double crystal_rmaxb1 = coneheight1*tan(coneangle1+halfTheta1); + G4double crystal_hz1 = 0.5*coneheight1; + G4double crystal_phimin1 = 0.*deg, crystal_phimax1 = 360.*deg/detNum1; + G4RotationMatrix tip_rotm1 = G4RotationMatrix(); + G4ThreeVector tip_pos1 = G4ThreeVector(0,0,crystal_hz1+.0001*mm); + G4Transform3D tip_trans1 = G4Transform3D(tip_rotm1, tip_pos1); + G4ThreeVector z1 = G4ThreeVector(0,0,1); + G4ThreeVector d01 = G4ThreeVector(distanceFromTarget1*sin(coneangle1)*cos(0.5*360*deg/detNum1), + distanceFromTarget1*sin(coneangle1)*sin(0.5*360*deg/detNum1), + distanceFromTarget1*cos(coneangle1)); + G4ThreeVector unitAxis1 = z1.cross(d01); + unitAxis1 = unitAxis1/unitAxis1.mag(); + G4double ux1 = unitAxis1.x(); + G4double uy1 = unitAxis1.y(); + G4double uz1 = unitAxis1.z(); + G4ThreeVector top1 = G4ThreeVector(cos(coneangle1)+pow(ux1,2)*(1-cos(coneangle1)), ux1*uy1*(1-cos(coneangle1))-uz1*sin(coneangle1), ux1*uz1*(1-cos(coneangle1))+uy1*sin(coneangle1)); + G4ThreeVector mid1 = G4ThreeVector(uy1*ux1*(1-cos(coneangle1))+uz1*sin(coneangle1), cos(coneangle1)+pow(uy1,2)*(1-cos(coneangle1)), uy1*uz1*(1-cos(coneangle1))-ux1*sin(coneangle1)); + G4ThreeVector bot1 = G4ThreeVector(uz1*ux1*(1-cos(coneangle1))-uy1*sin(coneangle1), uz1*uy1*(1-cos(coneangle1))+ux1*sin(coneangle1), cos(coneangle1)+pow(uz1,2)*(1-cos(coneangle1))); + G4RotationMatrix firstBox_rotm1 = G4RotationMatrix(); + firstBox_rotm1.setRows(top1,mid1,bot1); + G4ThreeVector firstBox_pos1 = G4ThreeVector(0,0,0); + G4Transform3D firstBox_trans1 = G4Transform3D(firstBox_rotm1, firstBox_pos1); + G4RotationMatrix secondBox_rotm1 = G4RotationMatrix(); + secondBox_rotm1.setRows(top1,mid1,bot1); + G4ThreeVector secondBox_pos1 = (2*distanceFromTarget1+detThickness1)/distanceFromTarget1*d01; + G4Transform3D secondBox_trans1 = G4Transform3D(secondBox_rotm1, secondBox_pos1); + + G4Orb* solidTip1 = + new G4Orb("tip1", + .0001*mm); + G4Box* solidSubtractionBox1 = + new G4Box("SubtractionBox1", //its name + distanceFromTarget1, + distanceFromTarget1, + distanceFromTarget1); //its size + G4Cons* solidCone1 = + new G4Cons("Cone1", //its name + crystal_rmina1, crystal_rmaxa1, + crystal_rminb1, crystal_rmaxb1, + crystal_hz1, + crystal_phimin1, crystal_phimax1); //its size + G4UnionSolid* solidTippedCone1 = + new G4UnionSolid("TippedCone1", + solidTip1, + solidCone1, + tip_trans1); + G4SubtractionSolid* solidIntermediate1 = + new G4SubtractionSolid("Intermediate1", + solidTippedCone1, + solidSubtractionBox1, + firstBox_trans1); + G4SubtractionSolid* solidCrystal1 = + new G4SubtractionSolid("Crystal1", + solidIntermediate1, + solidSubtractionBox1, + secondBox_trans1); + + G4LogicalVolume* logicCrystal1 = + new G4LogicalVolume(solidCrystal1, //its solid + CsI, //its material + "CsI Detector1"); //its name + logicCrystal1->SetVisAttributes(crystalVisAtt); + logicCrystal1->SetSensitiveDetector(m_MicroballScorer); + //fScoringVolume = logicCrystal1; + + // + // Light Guide + // + G4double lightGuide_px1 = 10*mm; + G4double lightGuide_py1 = 10*mm; + G4double lightGuide_pz1 = lgThickness1; + G4Box* solidLightGuide1 = + new G4Box("LightGuide1", //its name + 0.5*lightGuide_px1, + 0.5*lightGuide_py1, + 0.5*lightGuide_pz1); //its size + + G4LogicalVolume* logicLightGuide1 = + new G4LogicalVolume(solidLightGuide1, //its solid + glass, //its material + "LightGuide1"); //its name + logicLightGuide1->SetVisAttributes(lightGuideVisAtt); + + for(int i = 1; i <= detNum1; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + G4ThreeVector d0 = G4ThreeVector(distanceFromTarget1*sin(coneangle1)*cos(0.5*360*deg/detNum1), + distanceFromTarget1*sin(coneangle1)*sin(0.5*360*deg/detNum1), + distanceFromTarget1*cos(coneangle1)); + G4ThreeVector df = G4ThreeVector(distanceFromTarget1*sin(theta1)*sin(i*360*deg/detNum1+.001*deg/*+0.5*360*deg/detNum1*/), + distanceFromTarget1*sin(theta1)*cos(i*360*deg/detNum1+.001*deg/*+0.5*360*deg/detNum1*/), + -distanceFromTarget1*cos(theta1)); + G4ThreeVector axis = d0.cross(df); + G4double ax = axis.x(); + G4double ay = axis.y(); + G4double az = axis.z(); + G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); + G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); + G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); + G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); + G4RotationMatrix abc = G4RotationMatrix(); + abc.setRows(a,b,c); + G4ThreeVector unitdf = df/df.mag(); + G4double udfx = unitdf.x(); + G4double udfy = unitdf.y(); + G4double udfz = unitdf.z(); + G4double k = 180.*deg; + G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); + G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); + G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); + G4RotationMatrix def = G4RotationMatrix(); + def.setRows(d,e,f); + crystal_rotm=def*abc; + G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + G4ThreeVector lg_Axis = df.cross(z1); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4ThreeVector p = G4ThreeVector(cos(theta1)+pow(ulgx,2)*(1-cos(theta1)), ulgx*ulgy*(1-cos(theta1))-ulgz*sin(theta1), ulgx*ulgz*(1-cos(theta1))+ulgy*sin(theta1)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta1))+ulgz*sin(theta1), cos(theta1)+pow(ulgy,2)*(1-cos(theta1)), ulgy*ulgz*(1-cos(theta1))-ulgx*sin(theta1)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta1))-ulgy*sin(theta1), ulgz*ulgy*(1-cos(theta1))+ulgx*sin(theta1), cos(theta1)+pow(ulgz,2)*(1-cos(theta1))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum1); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget1+detThickness1+0.5*lgThickness1)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta1+90*deg)*sin(i*360*deg/detNum1+.001*deg), sin(theta1+90*deg)*cos(i*360*deg/detNum1+.001*deg), -cos(theta1+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z1); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg-theta1; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((-i)*360*deg/detNum1+.001*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget1+detThickness1+lgThickness1+delrinA1/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + bool placeCrystal = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (m_Array[i2] == 0+i){ + placeCrystal = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal1, //its logical volume + "CsI Detector1", //its name + world, //its mother volume + false, //no boolean operation + 0+i, //copy number + checkOverlaps); //overlaps checking + } + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide1, //its logical volume + "LightGuide1", //its name + world, //its mother volume + false, //no boolean operation + 0+i, //copy number + checkOverlaps); //overlaps checking + } + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin1, //its logical volume + "Delrin1", //its name + world, //its mother volume + false, //no boolean operation + 0+i, //copy number + checkOverlaps); //overlaps checking + } + } + }} + if(m_Ring2){ + // Ring 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lg pseudofixed + G4int detNum2 = 10; + G4double distanceFromTargetBack2 = 80.*mm; + G4double theta2 = 21.0*deg; + G4double halfTheta2 = 7.0*deg; //+0.1*deg; //0.1 is a fudge factor to make it cover solid angle 4pi + G4double lgThickness2 = 7.5*mm; + G4double detThickness2 = 7.2*mm; + G4double distanceFromTarget2 = distanceFromTargetBack2 - detThickness2; + + //G4double distance2 = distanceFromTarget2*sin(theta2); //this gives the distance from the beam axis. + + // + // Delrin Ring + // + G4double delrinA2 = 5*mm; + G4double delrinB2 = 10*mm; + G4double fdelrinHalfAngle2 = atan(delrinB2/2/(distanceFromTarget2+detThickness2+lgThickness2)); + G4double firs2 = pow(pow(distanceFromTarget2+detThickness2+lgThickness2,2)+pow(delrinB2/2,2),0.5)*sin(theta2-fdelrinHalfAngle2); + G4double firb2 = pow(pow(distanceFromTarget2+detThickness2+lgThickness2,2)+pow(delrinB2/2,2),0.5)*sin(theta2+fdelrinHalfAngle2); + G4double bdelrinHalfAngle2 = atan(delrinB2/2/(distanceFromTarget2+detThickness2+lgThickness2+delrinA2)); + G4double birs2 = pow(pow(distanceFromTarget2+detThickness2+lgThickness2+delrinA2,2)+pow(delrinB2/2,2),0.5)*sin(theta2-bdelrinHalfAngle2); + G4double birb2 = pow(pow(distanceFromTarget2+detThickness2+lgThickness2+delrinA2,2)+pow(delrinB2/2,2),0.5)*sin(theta2+bdelrinHalfAngle2); + + G4double delrin_dz2 = delrinB2/2; + G4double delrin_theta2 = 0; + G4double delrin_phi2 = 0; + G4double delrin_dyab2 = delrinA2/2; + G4double delrin_dxa2 = firs2*tan(180*deg/detNum2); + G4double delrin_dxb2 = birs2*tan(180*deg/detNum2); + G4double delrin_dycd2 = delrinA2/2; + G4double delrin_dxc2 = firb2*tan(180*deg/detNum2); + G4double delrin_dxd2 = birb2*tan(180*deg/detNum2); + G4double delrin_alpab2 = 0; + G4double delrin_alpcd2 = delrin_alpab2; + + + G4ThreeVector delrin_pos2 = G4ThreeVector(0,0,-distanceFromTarget2*cos(theta2)); + + G4Trap* solidDelrin2 = + new G4Trap("Delrin2", //its name + delrin_dz2, + delrin_theta2, delrin_phi2, + delrin_dyab2, + delrin_dxa2, delrin_dxb2, + delrin_alpab2, + delrin_dycd2, + delrin_dxc2, delrin_dxd2, + delrin_alpcd2); //its size + + G4LogicalVolume* logicDelrin2 = + new G4LogicalVolume(solidDelrin2, //its solid + delrin, //its material + "Delrin2"); //its name + logicDelrin2->SetVisAttributes(delrinVisAtt); + + + // + // CsI Detector + // + G4double coneheight2 = 2*distanceFromTarget2; + G4double coneangle2 = theta2; + G4double crystal_rmina2 = 0.*mm; + G4double crystal_rmaxa2 = 0.0001*mm; + G4double crystal_rminb2 = coneheight2*tan(coneangle2-halfTheta2); + G4double crystal_rmaxb2 = coneheight2*tan(coneangle2+halfTheta2); + G4double crystal_hz2 = 0.5*coneheight2; + G4double crystal_phimin2 = 0.*deg, crystal_phimax2 = 360.*deg/detNum2; + G4RotationMatrix tip_rotm2 = G4RotationMatrix(); + G4ThreeVector tip_pos2 = G4ThreeVector(0,0,crystal_hz2+.0001*mm); + G4Transform3D tip_trans2 = G4Transform3D(tip_rotm2, tip_pos2); + G4ThreeVector z2 = G4ThreeVector(0,0,1); + G4ThreeVector d02 = G4ThreeVector(distanceFromTarget2*sin(coneangle2)*cos(0.5*360*deg/detNum2), + distanceFromTarget2*sin(coneangle2)*sin(0.5*360*deg/detNum2), + distanceFromTarget2*cos(coneangle2)); + G4ThreeVector unitAxis2 = z2.cross(d02); + unitAxis2 = unitAxis2/unitAxis2.mag(); + G4double ux2 = unitAxis2.x(); + G4double uy2 = unitAxis2.y(); + G4double uz2 = unitAxis2.z(); + G4ThreeVector top2 = G4ThreeVector(cos(coneangle2)+pow(ux2,2)*(1-cos(coneangle2)), ux2*uy2*(1-cos(coneangle2))-uz2*sin(coneangle2), ux2*uz2*(1-cos(coneangle2))+uy2*sin(coneangle2)); + G4ThreeVector mid2 = G4ThreeVector(uy2*ux2*(1-cos(coneangle2))+uz2*sin(coneangle2), cos(coneangle2)+pow(uy2,2)*(1-cos(coneangle2)), uy2*uz2*(1-cos(coneangle2))-ux2*sin(coneangle2)); + G4ThreeVector bot2 = G4ThreeVector(uz2*ux2*(1-cos(coneangle2))-uy2*sin(coneangle2), uz2*uy2*(1-cos(coneangle2))+ux2*sin(coneangle2), cos(coneangle2)+pow(uz2,2)*(1-cos(coneangle2))); + G4RotationMatrix firstBox_rotm2 = G4RotationMatrix(); + firstBox_rotm2.setRows(top2,mid2,bot2); + G4ThreeVector firstBox_pos2 = G4ThreeVector(0,0,0); + G4Transform3D firstBox_trans2 = G4Transform3D(firstBox_rotm2, firstBox_pos2); + G4RotationMatrix secondBox_rotm2 = G4RotationMatrix(); + secondBox_rotm2.setRows(top2,mid2,bot2); + G4ThreeVector secondBox_pos2 = (2*distanceFromTarget2+detThickness2)/distanceFromTarget2*d02; + G4Transform3D secondBox_trans2 = G4Transform3D(secondBox_rotm2, secondBox_pos2); + + G4Orb* solidTip2 = + new G4Orb("tip2", + .0001*mm); + G4Box* solidSubtractionBox2 = + new G4Box("SubtractionBox2", //its name + distanceFromTarget2, + distanceFromTarget2, + distanceFromTarget2); //its size + G4Cons* solidCone2 = + new G4Cons("Cone2", //its name + crystal_rmina2, crystal_rmaxa2, + crystal_rminb2, crystal_rmaxb2, + crystal_hz2, + crystal_phimin2, crystal_phimax2); //its size + G4UnionSolid* solidTippedCone2 = + new G4UnionSolid("TippedCone2", + solidTip2, + solidCone2, + tip_trans2); + G4SubtractionSolid* solidIntermediate2 = + new G4SubtractionSolid("Intermediate2", + solidTippedCone2, + solidSubtractionBox2, + firstBox_trans2); + G4SubtractionSolid* solidCrystal2 = + new G4SubtractionSolid("Crystal2", + solidIntermediate2, + solidSubtractionBox2, + secondBox_trans2); + + G4LogicalVolume* logicCrystal2 = + new G4LogicalVolume(solidCrystal2, //its solid + CsI, //its material + "CsI Detector2"); //its name + logicCrystal2->SetVisAttributes(crystalVisAtt); + logicCrystal2->SetSensitiveDetector(m_MicroballScorer); + // + // Light Guide + // + G4double lightGuide_px2 = 10*mm; + G4double lightGuide_py2 = 10*mm; + G4double lightGuide_pz2 = lgThickness2; + G4Box* solidLightGuide2 = + new G4Box("LightGuide2", //its name + 0.5*lightGuide_px2, + 0.5*lightGuide_py2, + 0.5*lightGuide_pz2); //its size + + G4LogicalVolume* logicLightGuide2 = + new G4LogicalVolume(solidLightGuide2, //its solid + glass, //its material + "LightGuide2"); //its name + logicLightGuide2->SetVisAttributes(lightGuideVisAtt); + + for(int i = 1; i <= detNum2; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + G4ThreeVector d0 = G4ThreeVector(distanceFromTarget2*sin(coneangle2)*cos(0.5*360*deg/detNum2), + distanceFromTarget2*sin(coneangle2)*sin(0.5*360*deg/detNum2), + distanceFromTarget2*cos(coneangle2)); + G4ThreeVector df = G4ThreeVector(distanceFromTarget2*sin(theta2)*sin(i*360*deg/detNum2+.001*deg/*+0.5*360*deg/detNum2*/), + distanceFromTarget2*sin(theta2)*cos(i*360*deg/detNum2+.001*deg/*+0.5*360*deg/detNum2*/), + -distanceFromTarget2*cos(theta2)); + G4ThreeVector axis = d0.cross(df); + G4double ax = axis.x(); + G4double ay = axis.y(); + G4double az = axis.z(); + G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); + G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); + G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); + G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); + G4RotationMatrix abc = G4RotationMatrix(); + abc.setRows(a,b,c); + G4ThreeVector unitdf = df/df.mag(); + G4double udfx = unitdf.x(); + G4double udfy = unitdf.y(); + G4double udfz = unitdf.z(); + G4double k = 180.*deg; + G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); + G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); + G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); + G4RotationMatrix def = G4RotationMatrix(); + def.setRows(d,e,f); + crystal_rotm=def*abc; + G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + G4ThreeVector lg_Axis = df.cross(z2); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4ThreeVector p = G4ThreeVector(cos(theta2)+pow(ulgx,2)*(1-cos(theta2)), ulgx*ulgy*(1-cos(theta2))-ulgz*sin(theta2), ulgx*ulgz*(1-cos(theta2))+ulgy*sin(theta2)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta2))+ulgz*sin(theta2), cos(theta2)+pow(ulgy,2)*(1-cos(theta2)), ulgy*ulgz*(1-cos(theta2))-ulgx*sin(theta2)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta2))-ulgy*sin(theta2), ulgz*ulgy*(1-cos(theta2))+ulgx*sin(theta2), cos(theta2)+pow(ulgz,2)*(1-cos(theta2))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum2); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget2+detThickness2+0.5*lgThickness2)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4Transform3D d0_trans = G4Transform3D(G4RotationMatrix(), d0); + G4Transform3D df_trans = G4Transform3D(G4RotationMatrix(), df); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta2+90*deg)*sin(i*360*deg/detNum2+.001*deg), sin(theta2+90*deg)*cos(i*360*deg/detNum2+.001*deg), -cos(theta2+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z2); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg-theta2; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((-i)*360*deg/detNum2+.001*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget2+detThickness2+lgThickness2+delrinA2/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + bool placeCrystal = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (m_Array[i2] == 6+i){ + placeCrystal = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal2, //its logical volume + "CsI Detector2", //its name + world, //its mother volume + false, //no boolean operation + 6+i, //copy number + checkOverlaps); //overlaps checking + } + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide2, //its logical volume + "LightGuide2", //its name + world, //its mother volume + false, //no boolean operation + 6+i, //copy number + checkOverlaps); //overlaps checking + } + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin2, //its logical volume + "Delrin2", //its name + world, //its mother volume + false, //no boolean operation + 6+i, //copy number + checkOverlaps); //overlaps checking + } + } + }} + + if(m_Ring3){ + // Ring 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lg pseudofixed + G4int detNum3 = 12; + G4double distanceFromTargetBack3 = 60.*mm; + G4double theta3 = 36.0*deg; + G4double halfTheta3 = 8.0*deg; + G4double lgThickness3 = 6.0*mm; + G4double detThickness3 = 6.4*mm; + G4double distanceFromTarget3 = distanceFromTargetBack3 - detThickness3; + + //G4double distance3 = distanceFromTarget3*sin(theta3); //this gives the distance from the beam axis. + + // + // Delrin Ring + // + G4double delrinA3 = 5*mm; + G4double delrinB3 = 10*mm; + G4double fdelrinHalfAngle3 = atan(delrinB3/2/(distanceFromTarget3+detThickness3+lgThickness3)); + G4double firs3 = pow(pow(distanceFromTarget3+detThickness3+lgThickness3,2)+pow(delrinB3/2,2),0.5)*sin(theta3-fdelrinHalfAngle3); + G4double firb3 = pow(pow(distanceFromTarget3+detThickness3+lgThickness3,2)+pow(delrinB3/2,2),0.5)*sin(theta3+fdelrinHalfAngle3); + G4double bdelrinHalfAngle3 = atan(delrinB3/2/(distanceFromTarget3+detThickness3+lgThickness3+delrinA3)); + G4double birs3 = pow(pow(distanceFromTarget3+detThickness3+lgThickness3+delrinA3,2)+pow(delrinB3/2,2),0.5)*sin(theta3-bdelrinHalfAngle3); + G4double birb3 = pow(pow(distanceFromTarget3+detThickness3+lgThickness3+delrinA3,2)+pow(delrinB3/2,2),0.5)*sin(theta3+bdelrinHalfAngle3); + + G4double delrin_dz3 = delrinB3/2; + G4double delrin_theta3 = 0; + G4double delrin_phi3 = 0; + G4double delrin_dyab3 = delrinA3/2; + G4double delrin_dxa3 = firs3*tan(180*deg/detNum3); + G4double delrin_dxb3 = birs3*tan(180*deg/detNum3); + G4double delrin_dycd3 = delrinA3/2; + G4double delrin_dxc3 = firb3*tan(180*deg/detNum3); + G4double delrin_dxd3 = birb3*tan(180*deg/detNum3); + G4double delrin_alpab3 = 0; + G4double delrin_alpcd3 = delrin_alpab3; + + + G4ThreeVector delrin_pos3 = G4ThreeVector(0,0,-distanceFromTarget3*cos(theta3)); + + G4Trap* solidDelrin3 = + new G4Trap("Delrin3", //its name + delrin_dz3, + delrin_theta3, delrin_phi3, + delrin_dyab3, + delrin_dxa3, delrin_dxb3, + delrin_alpab3, + delrin_dycd3, + delrin_dxc3, delrin_dxd3, + delrin_alpcd3); //its size + + G4LogicalVolume* logicDelrin3 = + new G4LogicalVolume(solidDelrin3, //its solid + delrin, //its material + "Delrin3"); //its name + logicDelrin3->SetVisAttributes(delrinVisAtt); + + // + // CsI Detector + // + G4double coneheight3 = distanceFromTarget3; + G4double coneangle3 = theta3; + G4double crystal_rmina3 = 0.*mm; + G4double crystal_rmaxa3 = 0.0001*mm; + G4double crystal_rminb3 = coneheight3*tan(coneangle3-halfTheta3); + G4double crystal_rmaxb3 = coneheight3*tan(coneangle3+halfTheta3); + G4double crystal_hz3 = 0.5*coneheight3; + G4double crystal_phimin3 = 0.*deg, crystal_phimax3 = 360.*deg/detNum3; + G4RotationMatrix tip_rotm3 = G4RotationMatrix(); + G4ThreeVector tip_pos3 = G4ThreeVector(0,0,crystal_hz3+.0001*mm); + G4Transform3D tip_trans3 = G4Transform3D(tip_rotm3, tip_pos3); + G4ThreeVector z3 = G4ThreeVector(0,0,1); + G4ThreeVector d03 = G4ThreeVector(distanceFromTarget3*sin(coneangle3)*cos(0.5*360*deg/detNum3), + distanceFromTarget3*sin(coneangle3)*sin(0.5*360*deg/detNum3), + distanceFromTarget3*cos(coneangle3)); + G4ThreeVector unitAxis3 = z3.cross(d03); + unitAxis3 = unitAxis3/unitAxis3.mag(); + G4double ux3 = unitAxis3.x(); + G4double uy3 = unitAxis3.y(); + G4double uz3 = unitAxis3.z(); + G4ThreeVector top3 = G4ThreeVector(cos(coneangle3)+pow(ux3,2)*(1-cos(coneangle3)), ux3*uy3*(1-cos(coneangle3))-uz3*sin(coneangle3), ux3*uz3*(1-cos(coneangle3))+uy3*sin(coneangle3)); + G4ThreeVector mid3 = G4ThreeVector(uy3*ux3*(1-cos(coneangle3))+uz3*sin(coneangle3), cos(coneangle3)+pow(uy3,2)*(1-cos(coneangle3)), uy3*uz3*(1-cos(coneangle3))-ux3*sin(coneangle3)); + G4ThreeVector bot3 = G4ThreeVector(uz3*ux3*(1-cos(coneangle3))-uy3*sin(coneangle3), uz3*uy3*(1-cos(coneangle3))+ux3*sin(coneangle3), cos(coneangle3)+pow(uz3,2)*(1-cos(coneangle3))); + G4RotationMatrix firstBox_rotm3 = G4RotationMatrix(); + firstBox_rotm3.setRows(top3,mid3,bot3); + G4ThreeVector firstBox_pos3 = G4ThreeVector(0,0,0); + G4Transform3D firstBox_trans3 = G4Transform3D(firstBox_rotm3, firstBox_pos3); + G4RotationMatrix secondBox_rotm3 = G4RotationMatrix(); + secondBox_rotm3.setRows(top3,mid3,bot3); + G4ThreeVector secondBox_pos3 = (2*distanceFromTarget3+detThickness3)/distanceFromTarget3*d03; + G4Transform3D secondBox_trans3 = G4Transform3D(secondBox_rotm3, secondBox_pos3); + + G4Orb* solidTip3 = + new G4Orb("tip3", + .0001*mm); + G4Box* solidSubtractionBox3 = + new G4Box("SubtractionBox3", //its name + distanceFromTarget3, + distanceFromTarget3, + distanceFromTarget3); //its size + G4Cons* solidCone3 = + new G4Cons("Cone3", //its name + crystal_rmina3, crystal_rmaxa3, + crystal_rminb3, crystal_rmaxb3, + crystal_hz3, + crystal_phimin3, crystal_phimax3); //its size + G4UnionSolid* solidTippedCone3 = + new G4UnionSolid("TippedCone3", + solidTip3, + solidCone3, + tip_trans3); + G4SubtractionSolid* solidIntermediate3 = + new G4SubtractionSolid("Intermediate3", + solidTippedCone3, + solidSubtractionBox3, + firstBox_trans3); + G4SubtractionSolid* solidCrystal3 = + new G4SubtractionSolid("Crystal3", + solidIntermediate3, + solidSubtractionBox3, + secondBox_trans3); + + G4LogicalVolume* logicCrystal3 = + new G4LogicalVolume(solidCrystal3, //its solid + CsI, //its material + "CsI Detector3"); //its name + logicCrystal3->SetVisAttributes(crystalVisAtt); + logicCrystal3->SetSensitiveDetector(m_MicroballScorer); + + + // + // Light Guide + // + G4double lightGuide_px3 = 10*mm; + G4double lightGuide_py3 = 10*mm; + G4double lightGuide_pz3 = lgThickness3; + G4Box* solidLightGuide3 = + new G4Box("LightGuide3", //its name + 0.5*lightGuide_px3, + 0.5*lightGuide_py3, + 0.5*lightGuide_pz3); //its size + + G4LogicalVolume* logicLightGuide3 = + new G4LogicalVolume(solidLightGuide3, //its solid + glass, //its material + "LightGuide3"); //its name + logicLightGuide3->SetVisAttributes(lightGuideVisAtt); + + + for(int i = 1; i <= detNum3; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + G4ThreeVector d0 = G4ThreeVector(distanceFromTarget3*sin(coneangle3)*cos(0.5*360*deg/detNum3), + distanceFromTarget3*sin(coneangle3)*sin(0.5*360*deg/detNum3), + distanceFromTarget3*cos(coneangle3)); + G4ThreeVector df = G4ThreeVector(distanceFromTarget3*sin(theta3)*sin(i*360*deg/detNum3+.001*deg/*+0.5*360*deg/detNum3*/), + distanceFromTarget3*sin(theta3)*cos(i*360*deg/detNum3+.001*deg/*+0.5*360*deg/detNum3*/), + -distanceFromTarget3*cos(theta3)); + G4ThreeVector axis = d0.cross(df); + G4double ax = axis.x(); + G4double ay = axis.y(); + G4double az = axis.z(); + G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); + G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); + G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); + G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); + G4RotationMatrix abc = G4RotationMatrix(); + abc.setRows(a,b,c); + G4ThreeVector unitdf = df/df.mag(); + G4double udfx = unitdf.x(); + G4double udfy = unitdf.y(); + G4double udfz = unitdf.z(); + G4double k = 180.*deg; + G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); + G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); + G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); + G4RotationMatrix def = G4RotationMatrix(); + def.setRows(d,e,f); + crystal_rotm=def*abc; + G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + G4ThreeVector lg_Axis = df.cross(z3); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4ThreeVector p = G4ThreeVector(cos(theta3)+pow(ulgx,2)*(1-cos(theta3)), ulgx*ulgy*(1-cos(theta3))-ulgz*sin(theta3), ulgx*ulgz*(1-cos(theta3))+ulgy*sin(theta3)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta3))+ulgz*sin(theta3), cos(theta3)+pow(ulgy,2)*(1-cos(theta3)), ulgy*ulgz*(1-cos(theta3))-ulgx*sin(theta3)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta3))-ulgy*sin(theta3), ulgz*ulgy*(1-cos(theta3))+ulgx*sin(theta3), cos(theta3)+pow(ulgz,2)*(1-cos(theta3))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum3); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget3+detThickness3+0.5*lgThickness3)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta3+90*deg)*sin(i*360*deg/detNum3+.001*deg), sin(theta3+90*deg)*cos(i*360*deg/detNum3+.001*deg), -cos(theta3+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z3); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg-theta3; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((-i)*360*deg/detNum3+.001*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget3+detThickness3+lgThickness3+delrinA3/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + //if(i != 1){ + bool placeCrystal = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (m_Array[i2] == 16+i){ + placeCrystal = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal3, //its logical volume + "CsI Detector3", //its name + world, //its mother volume + false, //no boolean operation + 16+i, //copy number + checkOverlaps); //overlaps checking + } + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide3, //its logical volume + "LightGuide3", //its name + world, //its mother volume + false, //no boolean operation + 16+i, //copy number + checkOverlaps); //overlaps checking + } + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin3, //its logical volume + "Delrin3", //its name + world, //its mother volume + false, //no boolean operation + 16+i, //copy number + checkOverlaps); //overlaps checking + } + } + //} + }} + + if(m_Ring4){ + // Ring 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + G4int detNum4 = 12; + G4double distanceFromTargetBack4 = 50.*mm; + G4double theta4 = 52.0*deg; + G4double halfTheta4 = 8.0*deg; // fudge factor + G4double lgThickness4 = 6.0*mm; + G4double detThickness4 = 6.0*mm; + G4double distanceFromTarget4 = distanceFromTargetBack4 - detThickness4; + + //G4double distance4 = distanceFromTarget4*sin(theta4); //this gives the distance from the beam axis. + + // + // Delrin Ring + // + G4double delrinA4 = 5*mm; + G4double delrinB4 = 10*mm; + G4double fdelrinHalfAngle4 = atan(delrinB4/2/(distanceFromTarget4+detThickness4+lgThickness4)); + G4double firs4 = pow(pow(distanceFromTarget4+detThickness4+lgThickness4,2)+pow(delrinB4/2,2),0.5)*sin(theta4-fdelrinHalfAngle4); + G4double firb4 = pow(pow(distanceFromTarget4+detThickness4+lgThickness4,2)+pow(delrinB4/2,2),0.5)*sin(theta4+fdelrinHalfAngle4); + G4double bdelrinHalfAngle4 = atan(delrinB4/2/(distanceFromTarget4+detThickness4+lgThickness4+delrinA4)); + G4double birs4 = pow(pow(distanceFromTarget4+detThickness4+lgThickness4+delrinA4,2)+pow(delrinB4/2,2),0.5)*sin(theta4-bdelrinHalfAngle4); + G4double birb4 = pow(pow(distanceFromTarget4+detThickness4+lgThickness4+delrinA4,2)+pow(delrinB4/2,2),0.5)*sin(theta4+bdelrinHalfAngle4); + + G4double delrin_dz4 = delrinB4/2; + G4double delrin_theta4 = 0; + G4double delrin_phi4 = 0; + G4double delrin_dyab4 = delrinA4/2; + G4double delrin_dxa4 = firs4*tan(180*deg/detNum4); + G4double delrin_dxb4 = birs4*tan(180*deg/detNum4); + G4double delrin_dycd4 = delrinA4/2; + G4double delrin_dxc4 = firb4*tan(180*deg/detNum4); + G4double delrin_dxd4 = birb4*tan(180*deg/detNum4); + G4double delrin_alpab4 = 0; + G4double delrin_alpcd4 = delrin_alpab4; + + + G4ThreeVector delrin_pos4 = G4ThreeVector(0,0,-distanceFromTarget4*cos(theta4)); + + G4Trap* solidDelrin4 = + new G4Trap("Delrin4", //its name + delrin_dz4, + delrin_theta4, delrin_phi4, + delrin_dyab4, + delrin_dxa4, delrin_dxb4, + delrin_alpab4, + delrin_dycd4, + delrin_dxc4, delrin_dxd4, + delrin_alpcd4); //its size + + G4LogicalVolume* logicDelrin4 = + new G4LogicalVolume(solidDelrin4, //its solid + delrin, //its material + "Delrin4"); //its name + logicDelrin4->SetVisAttributes(delrinVisAtt); + + + // + // CsI Detector + // + G4double coneheight4 = distanceFromTarget4; + G4double coneangle4 = theta4; + G4double crystal_rmina4 = 0.*mm; + G4double crystal_rmaxa4 = 0.0001*mm; + G4double crystal_rminb4 = coneheight4*tan(coneangle4-halfTheta4); + G4double crystal_rmaxb4 = coneheight4*tan(coneangle4+halfTheta4); + G4double crystal_hz4 = 0.5*coneheight4; + G4double crystal_phimin4 = 0.*deg, crystal_phimax4 = 360.*deg/detNum4; + G4RotationMatrix tip_rotm4 = G4RotationMatrix(); + G4ThreeVector tip_pos4 = G4ThreeVector(0,0,crystal_hz4+.0001*mm); + G4Transform3D tip_trans4 = G4Transform3D(tip_rotm4, tip_pos4); + G4ThreeVector z4 = G4ThreeVector(0,0,1); + G4ThreeVector d04 = G4ThreeVector(distanceFromTarget4*sin(coneangle4)*cos(0.5*360*deg/detNum4), + distanceFromTarget4*sin(coneangle4)*sin(0.5*360*deg/detNum4), + distanceFromTarget4*cos(coneangle4)); + G4ThreeVector unitAxis4 = z4.cross(d04); + unitAxis4 = unitAxis4/unitAxis4.mag(); + G4double ux4 = unitAxis4.x(); + G4double uy4 = unitAxis4.y(); + G4double uz4 = unitAxis4.z(); + G4ThreeVector top4 = G4ThreeVector(cos(coneangle4)+pow(ux4,2)*(1-cos(coneangle4)), ux4*uy4*(1-cos(coneangle4))-uz4*sin(coneangle4), ux4*uz4*(1-cos(coneangle4))+uy4*sin(coneangle4)); + G4ThreeVector mid4 = G4ThreeVector(uy4*ux4*(1-cos(coneangle4))+uz4*sin(coneangle4), cos(coneangle4)+pow(uy4,2)*(1-cos(coneangle4)), uy4*uz4*(1-cos(coneangle4))-ux4*sin(coneangle4)); + G4ThreeVector bot4 = G4ThreeVector(uz4*ux4*(1-cos(coneangle4))-uy4*sin(coneangle4), uz4*uy4*(1-cos(coneangle4))+ux4*sin(coneangle4), cos(coneangle4)+pow(uz4,2)*(1-cos(coneangle4))); + G4RotationMatrix firstBox_rotm4 = G4RotationMatrix(); + firstBox_rotm4.setRows(top4,mid4,bot4); + G4ThreeVector firstBox_pos4 = G4ThreeVector(0,0,0); + G4Transform3D firstBox_trans4 = G4Transform3D(firstBox_rotm4, firstBox_pos4); + G4RotationMatrix secondBox_rotm4 = G4RotationMatrix(); + secondBox_rotm4.setRows(top4,mid4,bot4); + G4ThreeVector secondBox_pos4 = (2*distanceFromTarget4+detThickness4)/distanceFromTarget4*d04; + G4Transform3D secondBox_trans4 = G4Transform3D(secondBox_rotm4, secondBox_pos4); + + G4Orb* solidTip4 = + new G4Orb("tip4", + .0001*mm); + G4Box* solidSubtractionBox4 = + new G4Box("SubtractionBox4", //its name + distanceFromTarget4, + distanceFromTarget4, + distanceFromTarget4); //its size + G4Cons* solidCone4 = + new G4Cons("Cone4", //its name + crystal_rmina4, crystal_rmaxa4, + crystal_rminb4, crystal_rmaxb4, + crystal_hz4, + crystal_phimin4, crystal_phimax4); //its size + G4UnionSolid* solidTippedCone4 = + new G4UnionSolid("TippedCone4", + solidTip4, + solidCone4, + tip_trans4); + G4SubtractionSolid* solidIntermediate4 = + new G4SubtractionSolid("Intermediate4", + solidTippedCone4, + solidSubtractionBox4, + firstBox_trans4); + G4SubtractionSolid* solidCrystal4 = + new G4SubtractionSolid("Crystal4", + solidIntermediate4, + solidSubtractionBox4, + secondBox_trans4); + + G4LogicalVolume* logicCrystal4 = + new G4LogicalVolume(solidCrystal4, //its solid + CsI, //its material + "CsI Detector4"); //its name + logicCrystal4->SetVisAttributes(crystalVisAtt); + logicCrystal4->SetSensitiveDetector(m_MicroballScorer); + + // + // Light Guide + // + G4double lightGuide_px4 = 10*mm; + G4double lightGuide_py4 = 10*mm; + G4double lightGuide_pz4 = lgThickness4; + G4Box* solidLightGuide4 = + new G4Box("LightGuide4", //its name + 0.5*lightGuide_px4, + 0.5*lightGuide_py4, + 0.5*lightGuide_pz4); //its size + + G4LogicalVolume* logicLightGuide4 = + new G4LogicalVolume(solidLightGuide4, //its solid + glass, //its material + "LightGuide4"); //its name + logicLightGuide4->SetVisAttributes(lightGuideVisAtt); + + + for(int i = 1; i <= detNum4; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + G4ThreeVector d0 = G4ThreeVector(distanceFromTarget4*sin(coneangle4)*cos(0.5*360*deg/detNum4), + distanceFromTarget4*sin(coneangle4)*sin(0.5*360*deg/detNum4), + distanceFromTarget4*cos(coneangle4)); + G4ThreeVector df = G4ThreeVector(distanceFromTarget4*sin(theta4)*sin(i*360*deg/detNum4+.001*deg/*+0.5*360*deg/detNum4*/), + distanceFromTarget4*sin(theta4)*cos(i*360*deg/detNum4+.001*deg/*+0.5*360*deg/detNum4*/), + -distanceFromTarget4*cos(theta4)); + G4ThreeVector axis = d0.cross(df); + G4double ax = axis.x(); + G4double ay = axis.y(); + G4double az = axis.z(); + G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); + G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); + G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); + G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); + G4RotationMatrix abc = G4RotationMatrix(); + abc.setRows(a,b,c); + G4ThreeVector unitdf = df/df.mag(); + G4double udfx = unitdf.x(); + G4double udfy = unitdf.y(); + G4double udfz = unitdf.z(); + G4double k = 180.*deg; + G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); + G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); + G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); + G4RotationMatrix def = G4RotationMatrix(); + def.setRows(d,e,f); + crystal_rotm=def*abc; + G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + G4ThreeVector lg_Axis = df.cross(z4); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4ThreeVector p = G4ThreeVector(cos(theta4)+pow(ulgx,2)*(1-cos(theta4)), ulgx*ulgy*(1-cos(theta4))-ulgz*sin(theta4), ulgx*ulgz*(1-cos(theta4))+ulgy*sin(theta4)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta4))+ulgz*sin(theta4), cos(theta4)+pow(ulgy,2)*(1-cos(theta4)), ulgy*ulgz*(1-cos(theta4))-ulgx*sin(theta4)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta4))-ulgy*sin(theta4), ulgz*ulgy*(1-cos(theta4))+ulgx*sin(theta4), cos(theta4)+pow(ulgz,2)*(1-cos(theta4))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum4); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget4+detThickness4+0.5*lgThickness4)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta4+90*deg)*sin(i*360*deg/detNum4+.001*deg), sin(theta4+90*deg)*cos(i*360*deg/detNum4+.001*deg), -cos(theta4+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z4); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg-theta4; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((-i)*360*deg/detNum4+.001*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget4+detThickness4+lgThickness4+delrinA4/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + //if(i != 1){ + bool placeCrystal = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (m_Array[i2] == 28+i){ + placeCrystal = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal4, //its logical volume + "CsI Detector4", //its name + world, //its mother volume + false, //no boolean operation + 28+i, //copy number + checkOverlaps); //overlaps checking + } + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide4, //its logical volume + "LightGuide4", //its name + world, //its mother volume + false, //no boolean operation + 28+i, //copy number + checkOverlaps); //overlaps checking + } + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin4, //its logical volume + "Delrin4", //its name + world, //its mother volume + false, //no boolean operation + 28+i, //copy number + checkOverlaps); //overlaps checking + } + } + //} + }} + + if(m_Ring5){ + // Ring 5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + G4int detNum5 = 14; + G4double distanceFromTargetBack5 = 50.*mm; + G4double theta5 = 70.0*deg; + G4double halfTheta5 = 10.0*deg; //fudge factor + G4double lgThickness5 = 6.0*mm; + G4double detThickness5 = 5.6*mm; + G4double distanceFromTarget5 = distanceFromTargetBack5 - detThickness5; + + //G4double distance5 = distanceFromTarget5*sin(theta5); //this gives the distance from the beam axis. + + // + // Delrin Ring + // + G4double delrinA5 = 5*mm; + G4double delrinB5 = 10*mm; + G4double fdelrinHalfAngle5 = atan(delrinB5/2/(distanceFromTarget5+detThickness5+lgThickness5)); + G4double firs5 = pow(pow(distanceFromTarget5+detThickness5+lgThickness5,2)+pow(delrinB5/2,2),0.5)*sin(theta5-fdelrinHalfAngle5); + G4double firb5 = pow(pow(distanceFromTarget5+detThickness5+lgThickness5,2)+pow(delrinB5/2,2),0.5)*sin(theta5+fdelrinHalfAngle5); + G4double bdelrinHalfAngle5 = atan(delrinB5/2/(distanceFromTarget5+detThickness5+lgThickness5+delrinA5)); + G4double birs5 = pow(pow(distanceFromTarget5+detThickness5+lgThickness5+delrinA5,2)+pow(delrinB5/2,2),0.5)*sin(theta5-bdelrinHalfAngle5); + G4double birb5 = pow(pow(distanceFromTarget5+detThickness5+lgThickness5+delrinA5,2)+pow(delrinB5/2,2),0.5)*sin(theta5+bdelrinHalfAngle5); + + G4double delrin_dz5 = delrinB5/2; + G4double delrin_theta5 = 0; + G4double delrin_phi5 = 0; + G4double delrin_dyab5 = delrinA5/2; + G4double delrin_dxa5 = firs5*tan(180*deg/detNum5); + G4double delrin_dxb5 = birs5*tan(180*deg/detNum5); + G4double delrin_dycd5 = delrinA5/2; + G4double delrin_dxc5 = firb5*tan(180*deg/detNum5); + G4double delrin_dxd5 = birb5*tan(180*deg/detNum5); + G4double delrin_alpab5 = 0; + G4double delrin_alpcd5 = delrin_alpab5; + + + G4ThreeVector delrin_pos5 = G4ThreeVector(0,0,-distanceFromTarget5*cos(theta5)); + + G4Trap* solidDelrin5 = + new G4Trap("Delrin5", //its name + delrin_dz5, + delrin_theta5, delrin_phi5, + delrin_dyab5, + delrin_dxa5, delrin_dxb5, + delrin_alpab5, + delrin_dycd5, + delrin_dxc5, delrin_dxd5, + delrin_alpcd5); //its size + + G4LogicalVolume* logicDelrin5 = + new G4LogicalVolume(solidDelrin5, //its solid + delrin, //its material + "Delrin5"); //its name + logicDelrin5->SetVisAttributes(delrinVisAtt); + + + // + // CsI Detector + // + G4double coneheight5 = 0.6*distanceFromTarget5; + G4double coneangle5 = theta5; + G4double crystal_rmina5 = 0.*mm; + G4double crystal_rmaxa5 = 0.0001*mm; + G4double crystal_rminb5 = coneheight5*tan(coneangle5-halfTheta5); + G4double crystal_rmaxb5 = coneheight5*tan(coneangle5+halfTheta5); + G4double crystal_hz5 = 0.5*coneheight5; + G4double crystal_phimin5 = 0.*deg, crystal_phimax5 = 360.*deg/detNum5; + G4RotationMatrix tip_rotm5 = G4RotationMatrix(); + G4ThreeVector tip_pos5 = G4ThreeVector(0,0,crystal_hz5+.0001*mm); + G4Transform3D tip_trans5 = G4Transform3D(tip_rotm5, tip_pos5); + G4ThreeVector z5 = G4ThreeVector(0,0,1); + G4ThreeVector d05 = G4ThreeVector(distanceFromTarget5*sin(coneangle5)*cos(0.5*360*deg/detNum5), + distanceFromTarget5*sin(coneangle5)*sin(0.5*360*deg/detNum5), + distanceFromTarget5*cos(coneangle5)); + G4ThreeVector unitAxis5 = z5.cross(d05); + unitAxis5 = unitAxis5/unitAxis5.mag(); + G4double ux5 = unitAxis5.x(); + G4double uy5 = unitAxis5.y(); + G4double uz5 = unitAxis5.z(); + G4ThreeVector top5 = G4ThreeVector(cos(coneangle5)+pow(ux5,2)*(1-cos(coneangle5)), ux5*uy5*(1-cos(coneangle5))-uz5*sin(coneangle5), ux5*uz5*(1-cos(coneangle5))+uy5*sin(coneangle5)); + G4ThreeVector mid5 = G4ThreeVector(uy5*ux5*(1-cos(coneangle5))+uz5*sin(coneangle5), cos(coneangle5)+pow(uy5,2)*(1-cos(coneangle5)), uy5*uz5*(1-cos(coneangle5))-ux5*sin(coneangle5)); + G4ThreeVector bot5 = G4ThreeVector(uz5*ux5*(1-cos(coneangle5))-uy5*sin(coneangle5), uz5*uy5*(1-cos(coneangle5))+ux5*sin(coneangle5), cos(coneangle5)+pow(uz5,2)*(1-cos(coneangle5))); + G4RotationMatrix firstBox_rotm5 = G4RotationMatrix(); + firstBox_rotm5.setRows(top5,mid5,bot5); + G4ThreeVector firstBox_pos5 = G4ThreeVector(0,0,0); + G4Transform3D firstBox_trans5 = G4Transform3D(firstBox_rotm5, firstBox_pos5); + G4RotationMatrix secondBox_rotm5 = G4RotationMatrix(); + secondBox_rotm5.setRows(top5,mid5,bot5); + G4ThreeVector secondBox_pos5 = (3*distanceFromTarget5+detThickness5)/distanceFromTarget5*d05; + G4Transform3D secondBox_trans5 = G4Transform3D(secondBox_rotm5, secondBox_pos5); + + G4Orb* solidTip5 = + new G4Orb("tip5", + .0001*mm); + G4Box* solidSubtractionBox5 = + new G4Box("SubtractionBox5", //its name + distanceFromTarget5, + distanceFromTarget5, + distanceFromTarget5); //its size + G4Box* solidSecondSubtractionBox5 = + new G4Box("SecondSubtractionBox5", //its name + 2*distanceFromTarget5, + 2*distanceFromTarget5, + 2*distanceFromTarget5); //its size + G4Cons* solidCone5 = + new G4Cons("Cone5", //its name + crystal_rmina5, crystal_rmaxa5, + crystal_rminb5, crystal_rmaxb5, + crystal_hz5, + crystal_phimin5, crystal_phimax5); //its size + G4UnionSolid* solidTippedCone5 = + new G4UnionSolid("TippedCone5", + solidTip5, + solidCone5, + tip_trans5); + G4SubtractionSolid* solidIntermediate5 = + new G4SubtractionSolid("Intermediate5", + solidTippedCone5, + solidSubtractionBox5, + firstBox_trans5); + G4SubtractionSolid* solidCrystal5 = + new G4SubtractionSolid("Crystal5", + solidIntermediate5, + solidSecondSubtractionBox5, + secondBox_trans5); + + G4LogicalVolume* logicCrystal5 = + new G4LogicalVolume(solidCrystal5, //its solid + CsI, //its material + "CsI Detector5"); //its name + logicCrystal5->SetVisAttributes(crystalVisAtt); + logicCrystal5->SetSensitiveDetector(m_MicroballScorer); + + + // + // Light Guide + // + G4double lightGuide_px5 = 10*mm; + G4double lightGuide_py5 = 10*mm; + G4double lightGuide_pz5 = lgThickness5; + G4Box* solidLightGuide5 = + new G4Box("LightGuide5", //its name + 0.5*lightGuide_px5, + 0.5*lightGuide_py5, + 0.5*lightGuide_pz5); //its size + + G4LogicalVolume* logicLightGuide5 = + new G4LogicalVolume(solidLightGuide5, //its solid + glass, //its material + "LightGuide5"); //its name + logicLightGuide5->SetVisAttributes(lightGuideVisAtt); + + + for(int i = 1; i <= detNum5; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + G4ThreeVector d0 = G4ThreeVector(distanceFromTarget5*sin(coneangle5)*cos(0.5*360*deg/detNum5), + distanceFromTarget5*sin(coneangle5)*sin(0.5*360*deg/detNum5), + distanceFromTarget5*cos(coneangle5)); + G4ThreeVector df = G4ThreeVector(distanceFromTarget5*sin(theta5)*sin(i*360*deg/detNum5+.001*deg/*+0.5*360*deg/detNum5*/), + distanceFromTarget5*sin(theta5)*cos(i*360*deg/detNum5+.001*deg/*+0.5*360*deg/detNum5*/), + -distanceFromTarget5*cos(theta5)); + G4ThreeVector axis = d0.cross(df); + G4double ax = axis.x(); + G4double ay = axis.y(); + G4double az = axis.z(); + G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); + G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); + G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); + G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); + G4RotationMatrix abc = G4RotationMatrix(); + abc.setRows(a,b,c); + G4ThreeVector unitdf = df/df.mag(); + G4double udfx = unitdf.x(); + G4double udfy = unitdf.y(); + G4double udfz = unitdf.z(); + G4double k = 180.*deg; + G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); + G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); + G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); + G4RotationMatrix def = G4RotationMatrix(); + def.setRows(d,e,f); + crystal_rotm=def*abc; + G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + G4ThreeVector lg_Axis = df.cross(z5); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4ThreeVector p = G4ThreeVector(cos(theta5)+pow(ulgx,2)*(1-cos(theta5)), ulgx*ulgy*(1-cos(theta5))-ulgz*sin(theta5), ulgx*ulgz*(1-cos(theta5))+ulgy*sin(theta5)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta5))+ulgz*sin(theta5), cos(theta5)+pow(ulgy,2)*(1-cos(theta5)), ulgy*ulgz*(1-cos(theta5))-ulgx*sin(theta5)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta5))-ulgy*sin(theta5), ulgz*ulgy*(1-cos(theta5))+ulgx*sin(theta5), cos(theta5)+pow(ulgz,2)*(1-cos(theta5))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum5); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget5+detThickness5+0.5*lgThickness5)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta5+90*deg)*sin(i*360*deg/detNum5+.001*deg), sin(theta5+90*deg)*cos(i*360*deg/detNum5+.001*deg), -cos(theta5+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z5); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg-theta5; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((-i)*360*deg/detNum5+.001*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget5+detThickness5+lgThickness5+delrinA5/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + //if(i != 1){ + bool placeCrystal = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (m_Array[i2] == 40+i){ + placeCrystal = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal5, //its logical volume + "CsI Detector5", //its name + world, //its mother volume + false, //no boolean operation + 40+i, //copy number + checkOverlaps); //overlaps checking + } + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide5, //its logical volume + "LightGuide5", //its name + world, //its mother volume + false, //no boolean operation + 40+i, //copy number + checkOverlaps); //overlaps checking + } + //} + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin5, //its logical volume + "Delrin5", //its name + world, //its mother volume + false, //no boolean operation + 40+i, //copy number + checkOverlaps); //overlaps checking + } + } + }} + + if(m_Ring6){ + // Ring 6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ this ring is weird. + G4int detNum6 = 14; + G4double distanceFromTargetBack6 = 50.*mm; + G4double theta6 = 90.0*deg; + G4double halfTheta6 = 10.0*deg; + G4double lgThickness6 = 7.0*mm; + G4double detThickness6 = 5.2*mm; + G4double distanceFromTarget6 = distanceFromTargetBack6 - detThickness6; + + //G4double distance6 = distanceFromTarget6*sin(theta6); //this gives the distance from the beam axis. + + // + // Delrin Ring + // + G4double delrinA6 = 5*mm; + G4double delrinB6 = 10*mm; + G4double fdelrinHalfAngle6 = atan(delrinB6/2/(distanceFromTarget6+detThickness6+lgThickness6)); + G4double firs6 = pow(pow(distanceFromTarget6+detThickness6+lgThickness6,2)+pow(delrinB6/2,2),0.5)*sin(theta6-fdelrinHalfAngle6); + G4double firb6 = pow(pow(distanceFromTarget6+detThickness6+lgThickness6,2)+pow(delrinB6/2,2),0.5)*sin(theta6+fdelrinHalfAngle6); + G4double bdelrinHalfAngle6 = atan(delrinB6/2/(distanceFromTarget6+detThickness6+lgThickness6+delrinA6)); + G4double birs6 = pow(pow(distanceFromTarget6+detThickness6+lgThickness6+delrinA6,2)+pow(delrinB6/2,2),0.5)*sin(theta6-bdelrinHalfAngle6); + G4double birb6 = pow(pow(distanceFromTarget6+detThickness6+lgThickness6+delrinA6,2)+pow(delrinB6/2,2),0.5)*sin(theta6+bdelrinHalfAngle6); + + G4double delrin_dz6 = delrinB6/2; + G4double delrin_theta6 = 0; + G4double delrin_phi6 = 0; + G4double delrin_dyab6 = delrinA6/2; + G4double delrin_dxa6 = firs6*tan(180*deg/detNum6); + G4double delrin_dxb6 = birs6*tan(180*deg/detNum6); + G4double delrin_dycd6 = delrinA6/2; + G4double delrin_dxc6 = firb6*tan(180*deg/detNum6); + G4double delrin_dxd6 = birb6*tan(180*deg/detNum6); + G4double delrin_alpab6 = 0; + G4double delrin_alpcd6 = delrin_alpab6; + + + G4ThreeVector delrin_pos6 = G4ThreeVector(0,0,-distanceFromTarget6*cos(theta6)); + + G4Trap* solidDelrin6 = + new G4Trap("Delrin6", //its name + delrin_dz6, + delrin_theta6, delrin_phi6, + delrin_dyab6, + delrin_dxa6, delrin_dxb6, + delrin_alpab6, + delrin_dycd6, + delrin_dxc6, delrin_dxd6, + delrin_alpcd6); //its size + + G4LogicalVolume* logicDelrin6 = + new G4LogicalVolume(solidDelrin6, //its solid + delrin, //its material + "Delrin6"); //its name + logicDelrin6->SetVisAttributes(delrinVisAtt); + + + /* + // + // CsI Detector for deletion + // + G4double crystal_rmina6 = distance6/cos(halfTheta6); + G4double crystal_rmaxa6 = distance6/cos(halfTheta6)+2*distance6*tan(halfTheta6); + G4double crystal_rminb6 = (distance6+detThickness6)/cos(halfTheta6); + G4double crystal_rmaxb6 = (distance6+detThickness6)/cos(halfTheta6)+2*(distance6+detThickness6)*tan(halfTheta6); + G4double crystal_hz6 = 0.5*pow(pow(detThickness6,2)+pow((crystal_rminb6+crystal_rmaxb6-crystal_rmina6-crystal_rmaxa6)/2,2),0.5); + //G4double crystal_hz6 = 0.5*detThickness6; + G4double crystal_phimin6 = 0.*deg, crystal_phimax6 = 360.*deg/detNum6; + + + G4Cons* solidCrystal6 = + new G4Cons("Crystal6", //its name + crystal_rmina6, crystal_rmaxa6, + crystal_rminb6, crystal_rmaxb6, + crystal_hz6, + crystal_phimin6, crystal_phimax6); //its size + + G4LogicalVolume* logicCrystal6 = + new G4LogicalVolume(solidCrystal6, //its solid + CsI, //its material + "CsI Detector6"); //its name + logicCrystal6->SetVisAttributes(crystalVisAtt); + */ + + G4double crystal_dxa6 = distanceFromTarget6*tan(halfTheta6); + G4double crystal_dxb6 = (distanceFromTarget6+detThickness6)*tan(halfTheta6); + G4double crystal_dya6 = distanceFromTarget6*tan(0.5*360*deg/detNum6); + G4double crystal_dyb6 = (distanceFromTarget6+detThickness6)*tan(0.5*360*deg/detNum6); + G4double crystal_dz = 0.5*detThickness6; + + G4Trd* solidCrystal6 = + new G4Trd("Crystal6", //its name + crystal_dxa6, crystal_dxb6, + crystal_dya6, crystal_dyb6, + crystal_dz); //its size + G4LogicalVolume* logicCrystal6 = + new G4LogicalVolume(solidCrystal6, //its solid + CsI, //its material + "CsI Detector6"); //its name + logicCrystal6->SetVisAttributes(crystalVisAtt); + logicCrystal6->SetSensitiveDetector(m_MicroballScorer); + // + // Light Guide + // + G4double lightGuide_px6 = 10*mm; + G4double lightGuide_py6 = 10*mm; + G4double lightGuide_pz6 = lgThickness6; + G4Box* solidLightGuide6 = + new G4Box("LightGuide6", //its name + 0.5*lightGuide_px6, + 0.5*lightGuide_py6, + 0.5*lightGuide_pz6); //its size + + G4LogicalVolume* logicLightGuide6 = + new G4LogicalVolume(solidLightGuide6, //its solid + glass, //its material + "LightGuide6"); //its name + logicLightGuide6->SetVisAttributes(lightGuideVisAtt); + + + for(int i = 1; i <= detNum6; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + /* + G4RotationMatrix abc6 = G4RotationMatrix(); + G4RotationMatrix def6 = G4RotationMatrix(); + G4ThreeVector a6 = G4ThreeVector(pow(sin(i*360*deg/detNum6),2), -sin(i*360*deg/detNum6)*cos(i*360*deg/detNum6), cos(i*360*deg/detNum6)); + G4ThreeVector b6 = G4ThreeVector(-sin(i*360*deg/detNum6)*cos(i*360*deg/detNum6), pow(cos(i*360*deg/detNum6),2), sin(i*360*deg/detNum6)); + G4ThreeVector c6 = G4ThreeVector(-cos(i*360*deg/detNum6), -sin(i*360*deg/detNum6), 0); + abc6.setRows(a6,b6,c6); + G4double k= (i-1)*360*deg/detNum6+0.5*360*deg/detNum6; + G4ThreeVector d6 = G4ThreeVector(cos(k)+pow(cos(i*360*deg/detNum6),2)*(1-cos(k)), + cos(i*360*deg/detNum6)*sin(i*360*deg/detNum6)*(1-cos(k)), + sin(i*360*deg/detNum6)*sin(k)); + G4ThreeVector e6 = G4ThreeVector(cos(i*360*deg/detNum6)*sin(i*360*deg/detNum6)*(1-cos(k)), + cos(k)+pow(sin(i*360*deg/detNum6),2)*(1-cos(k)), + -cos(i*360*deg/detNum6)*sin(k)); + G4ThreeVector f6 = G4ThreeVector(-sin(i*360*deg/detNum6)*sin(k), + cos(i*360*deg/detNum6)*sin(k), + cos(k)); + def6.setRows(d6,e6,f6); + crystal_rotm = def6*abc6; + */ + G4ThreeVector z6 = G4ThreeVector(0,0,1); + G4ThreeVector df6 = G4ThreeVector(cos(i*360*deg/detNum6+0.5*360*deg/detNum6), + sin(i*360*deg/detNum6+0.5*360*deg/detNum6), + 0); + G4ThreeVector unitAxis6 = z6.cross(df6); + unitAxis6 = unitAxis6/unitAxis6.mag(); + G4double ux6 = unitAxis6.x(); + G4double uy6 = unitAxis6.y(); + G4double uz6 = unitAxis6.z(); + G4double angle6 = acos(z6.dot(df6)/(z6.mag()*df6.mag())); + G4ThreeVector a6 = G4ThreeVector(cos(angle6)+pow(ux6,2)*(1-cos(angle6)), ux6*uy6*(1-cos(angle6))-uz6*sin(angle6), ux6*uz6*(1-cos(angle6))+uy6*sin(angle6)); + G4ThreeVector b6 = G4ThreeVector(uy6*ux6*(1-cos(angle6))+uz6*sin(angle6), cos(angle6)+pow(uy6,2)*(1-cos(angle6)), uy6*uz6*(1-cos(angle6))-ux6*sin(angle6)); + G4ThreeVector c6 = G4ThreeVector(uz6*ux6*(1-cos(angle6))-uy6*sin(angle6), uz6*uy6*(1-cos(angle6))+ux6*sin(angle6), cos(angle6)+pow(uz6,2)*(1-cos(angle6))); + G4RotationMatrix abc6 = G4RotationMatrix(); + abc6.setRows(a6,b6,c6); + crystal_rotm.rotateZ(i*360*deg/detNum6+0.5*360*deg/detNum6); + crystal_rotm=abc6*crystal_rotm; + G4ThreeVector crystal_pos = G4ThreeVector((distanceFromTarget6+0.5*detThickness6)*cos(i*360*deg/detNum6+0.5*360*deg/detNum6), + (distanceFromTarget6+0.5*detThickness6)*sin(i*360*deg/detNum6+0.5*360*deg/detNum6), + 0)+delrin_pos6; + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + G4ThreeVector df = G4ThreeVector(distanceFromTarget6*sin(theta6)*sin(i*360*deg/detNum6/*+0.5*360*deg/detNum6*/), + distanceFromTarget6*sin(theta6)*cos(i*360*deg/detNum6/*+0.5*360*deg/detNum6*/), + -distanceFromTarget6*cos(theta6)); + G4ThreeVector lg_Axis = df.cross(z6); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4ThreeVector p = G4ThreeVector(cos(theta6)+pow(ulgx,2)*(1-cos(theta6)), ulgx*ulgy*(1-cos(theta6))-ulgz*sin(theta6), ulgx*ulgz*(1-cos(theta6))+ulgy*sin(theta6)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta6))+ulgz*sin(theta6), cos(theta6)+pow(ulgy,2)*(1-cos(theta6)), ulgy*ulgz*(1-cos(theta6))-ulgx*sin(theta6)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta6))-ulgy*sin(theta6), ulgz*ulgy*(1-cos(theta6))+ulgx*sin(theta6), cos(theta6)+pow(ulgz,2)*(1-cos(theta6))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum6); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget6+detThickness6+0.5*lgThickness6)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta6+90*deg)*sin(i*360*deg/detNum6+.001*deg), sin(theta6+90*deg)*cos(i*360*deg/detNum6+.001*deg), -cos(theta6+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z6); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg-theta6; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((-i)*360*deg/detNum6+.001*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget6+detThickness6+lgThickness6+delrinA6/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + bool placeCrystal = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (m_Array[i2] == 54+i){ + placeCrystal = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal6, //its logical volume + "CsI Detector6", //its name + world, //its mother volume + false, //no boolean operation + 54+i, //copy number + checkOverlaps); //overlaps checking + } + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide6, //its logical volume + "LightGuide6", //its name + world, //its mother volume + false, //no boolean operation + 54+i, //copy number + checkOverlaps); //overlaps checking + } + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin6, //its logical volume + "Delrin6", //its name + world, //its mother volume + false, //no boolean operation + 54+i, //copy number + checkOverlaps); //overlaps checking + } + } + }} + + if(m_Ring7){ + // Ring 7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lg pseudofixed + G4int detNum7 = 12; + G4double distanceFromTargetBack7 = 45.*mm; + G4double theta7 = 111.5*deg; + G4double halfTheta7 = 11.5*deg; //fudge factor + G4double lgThickness7 = 7.0*mm; + G4double detThickness7 = 4.1*mm; + G4double distanceFromTarget7 = distanceFromTargetBack7 - detThickness7; + + //G4double distance7 = distanceFromTarget7*sin(theta7); //this gives the distance from the beam axis. + + /* + // + // Delrin Ring (for deletion) + // + G4double delrin_rmina7 = distance7+detThickness7+lgThickness7, delrin_rmaxa7 = delrin_rmina7+5*mm; + G4double delrin_hz7 = 5*mm; //distance7*tan(halfTheta7); + G4double delrin_phimin7 = 0.*deg, delrin_phimax7 = 360.*deg; + G4ThreeVector delrin_pos7 = G4ThreeVector(0,0,-distanceFromTarget7*cos(theta7)); //G4ThreeVector(0,0,distance7+lgThickness7+detThickness7*sin(theta7)); + + G4Tubs* solidDelrin7 = + new G4Tubs("Delrin7", //its name + delrin_rmina7, delrin_rmaxa7, + delrin_hz7, + delrin_phimin7, delrin_phimax7); //its size + + G4LogicalVolume* logicDelrin7 = + new G4LogicalVolume(solidDelrin7, //its solid + delrin, //its material + "Delrin7"); //its name + logicDelrin7->SetVisAttributes(delrinVisAtt); + + if(delrinBool) {new G4PVPlacement(0, //no rotation + delrin_pos7, //its position + logicDelrin7, //its logical volume + "Delrin7", //its name + world, //its mother volume + false, //no boolean operation + 0, //copy number + checkOverlaps); //overlaps checking + } + */ + // + // Delrin Ring + // + G4double delrinA7 = 5*mm; + G4double delrinB7 = 10*mm; + G4double fdelrinHalfAngle7 = atan(delrinB7/2/(distanceFromTarget7+detThickness7+lgThickness7)); + G4double firs7 = pow(pow(distanceFromTarget7+detThickness7+lgThickness7,2)+pow(delrinB7/2,2),0.5)*sin(theta7-fdelrinHalfAngle7); + G4double firb7 = pow(pow(distanceFromTarget7+detThickness7+lgThickness7,2)+pow(delrinB7/2,2),0.5)*sin(theta7+fdelrinHalfAngle7); + G4double bdelrinHalfAngle7 = atan(delrinB7/2/(distanceFromTarget7+detThickness7+lgThickness7+delrinA7)); + G4double birs7 = pow(pow(distanceFromTarget7+detThickness7+lgThickness7+delrinA7,2)+pow(delrinB7/2,2),0.5)*sin(theta7-bdelrinHalfAngle7); + G4double birb7 = pow(pow(distanceFromTarget7+detThickness7+lgThickness7+delrinA7,2)+pow(delrinB7/2,2),0.5)*sin(theta7+bdelrinHalfAngle7); + + G4double delrin_dz7 = delrinB7/2; + G4double delrin_theta7 = 0; + G4double delrin_phi7 = 0; + G4double delrin_dyab7 = delrinA7/2; + G4double delrin_dxa7 = firs7*tan(180*deg/detNum7); + G4double delrin_dxb7 = birs7*tan(180*deg/detNum7); + G4double delrin_dycd7 = delrinA7/2; + G4double delrin_dxc7 = firb7*tan(180*deg/detNum7); + G4double delrin_dxd7 = birb7*tan(180*deg/detNum7); + G4double delrin_alpab7 = 0; + G4double delrin_alpcd7 = delrin_alpab7; + + G4ThreeVector delrin_pos7 = G4ThreeVector(0,0,-distanceFromTarget7*cos(theta7)); + + G4Trap* solidDelrin7 = + new G4Trap("Delrin7", //its name + delrin_dz7, + delrin_theta7, delrin_phi7, + delrin_dyab7, + delrin_dxa7, delrin_dxb7, + delrin_alpab7, + delrin_dycd7, + delrin_dxc7, delrin_dxd7, + delrin_alpcd7); //its size + + G4LogicalVolume* logicDelrin7 = + new G4LogicalVolume(solidDelrin7, //its solid + delrin, //its material + "Delrin7"); //its name + logicDelrin7->SetVisAttributes(delrinVisAtt); + + // + // CsI Detector + // + G4double coneheight7 = 0.6*distanceFromTarget7; + G4double coneangle7 = theta7; + G4double crystal_rmina7 = 0.*mm; + G4double crystal_rmaxa7 = 0.0001*mm; + G4double crystal_rminb7 = -coneheight7*tan(coneangle7+halfTheta7); + G4double crystal_rmaxb7 = -coneheight7*tan(coneangle7-halfTheta7); + G4double crystal_hz7 = 0.5*coneheight7; + G4double crystal_phimin7 = 0.*deg, crystal_phimax7 = 360.*deg/detNum7; + G4RotationMatrix tip_rotm7 = G4RotationMatrix(); + G4ThreeVector tip_pos7 = G4ThreeVector(0,0,crystal_hz7+.0001*mm); + G4Transform3D tip_trans7 = G4Transform3D(tip_rotm7, tip_pos7); + G4ThreeVector z7 = G4ThreeVector(0,0,1); + G4ThreeVector d07 = G4ThreeVector(distanceFromTarget7*sin(coneangle7)*cos(0.5*360*deg/detNum7), + distanceFromTarget7*sin(coneangle7)*sin(0.5*360*deg/detNum7), + -distanceFromTarget7*cos(coneangle7)); + G4ThreeVector unitAxis7 = z7.cross(d07); + unitAxis7 = unitAxis7/unitAxis7.mag(); + G4double ux7 = unitAxis7.x(); + G4double uy7 = unitAxis7.y(); + G4double uz7 = unitAxis7.z(); + G4ThreeVector top7 = G4ThreeVector(cos(-coneangle7)+pow(ux7,2)*(1-cos(-coneangle7)), ux7*uy7*(1-cos(-coneangle7))-uz7*sin(-coneangle7), ux7*uz7*(1-cos(-coneangle7))+uy7*sin(-coneangle7)); + G4ThreeVector mid7 = G4ThreeVector(uy7*ux7*(1-cos(-coneangle7))+uz7*sin(-coneangle7), cos(-coneangle7)+pow(uy7,2)*(1-cos(-coneangle7)), uy7*uz7*(1-cos(-coneangle7))-ux7*sin(-coneangle7)); + G4ThreeVector bot7 = G4ThreeVector(uz7*ux7*(1-cos(-coneangle7))-uy7*sin(-coneangle7), uz7*uy7*(1-cos(-coneangle7))+ux7*sin(-coneangle7), cos(-coneangle7)+pow(uz7,2)*(1-cos(-coneangle7))); + G4RotationMatrix firstBox_rotm7 = G4RotationMatrix(); + firstBox_rotm7.setRows(top7,mid7,bot7); + G4ThreeVector firstBox_pos7 = G4ThreeVector(0,0,0); + G4Transform3D firstBox_trans7 = G4Transform3D(firstBox_rotm7, firstBox_pos7); + G4RotationMatrix secondBox_rotm7 = G4RotationMatrix(); + secondBox_rotm7.setRows(top7,mid7,bot7); + G4ThreeVector secondBox_pos7 = (3*distanceFromTarget7+detThickness7)/distanceFromTarget7*d07; + G4Transform3D secondBox_trans7 = G4Transform3D(secondBox_rotm7, secondBox_pos7); + + G4Orb* solidTip7 = + new G4Orb("tip7", + .0001*mm); + G4Box* solidSubtractionBox7 = + new G4Box("SubtractionBox7", //its name + distanceFromTarget7, + distanceFromTarget7, + distanceFromTarget7); //its size + G4Box* solidSecondSubtractionBox7 = + new G4Box("SecondSubtractionBox7", //its name + 2*distanceFromTarget7, + 2*distanceFromTarget7, + 2*distanceFromTarget7); //its size + G4Cons* solidCone7 = + new G4Cons("Cone7", //its name + crystal_rmina7, crystal_rmaxa7, + crystal_rminb7, crystal_rmaxb7, + crystal_hz7, + crystal_phimin7, crystal_phimax7); //its size + G4UnionSolid* solidTippedCone7 = + new G4UnionSolid("TippedCone7", + solidTip7, + solidCone7, + tip_trans7); + G4SubtractionSolid* solidIntermediate7 = + new G4SubtractionSolid("Intermediate7", + solidTippedCone7, + solidSubtractionBox7, + firstBox_trans7); + G4SubtractionSolid* solidCrystal7 = + new G4SubtractionSolid("Crystal7", + solidIntermediate7, + solidSecondSubtractionBox7, + secondBox_trans7); + + G4LogicalVolume* logicCrystal7 = + new G4LogicalVolume(solidCrystal7, //its solid + CsI, //its material + "CsI Detector7"); //its name + logicCrystal7->SetVisAttributes(crystalVisAtt); + logicCrystal7->SetSensitiveDetector(m_MicroballScorer); + // + // Light Guide + // + G4double lightGuide_px7 = 10*mm; + G4double lightGuide_py7 = 10*mm; + G4double lightGuide_pz7 = lgThickness7; + G4Box* solidLightGuide7 = + new G4Box("LightGuide7", //its name + 0.5*lightGuide_px7, + 0.5*lightGuide_py7, + 0.5*lightGuide_pz7); //its size + + G4LogicalVolume* logicLightGuide7 = + new G4LogicalVolume(solidLightGuide7, //its solid + glass, //its material + "LightGuide7"); //its name + logicLightGuide7->SetVisAttributes(lightGuideVisAtt); + + + for(int i = 1; i <= detNum7; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + G4ThreeVector d0 = G4ThreeVector(distanceFromTarget7*sin(coneangle7)*cos(0.5*360*deg/detNum7), + distanceFromTarget7*sin(coneangle7)*sin(0.5*360*deg/detNum7), + distanceFromTarget7*cos(coneangle7)); + G4ThreeVector df = G4ThreeVector(distanceFromTarget7*sin(theta7)*sin(i*360*deg/detNum7+.001*deg/*+0.5*360*deg/detNum7*/), + distanceFromTarget7*sin(theta7)*cos(i*360*deg/detNum7+.001*deg/*+0.5*360*deg/detNum7*/), + -distanceFromTarget7*cos(theta7)); + G4ThreeVector axis = d0.cross(df); + G4double ax = axis.x(); + G4double ay = axis.y(); + G4double az = axis.z(); + G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); + G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); + G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); + G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); + G4RotationMatrix abc = G4RotationMatrix(); + abc.setRows(a,b,c); + G4ThreeVector unitdf = df/df.mag(); + G4double udfx = unitdf.x(); + G4double udfy = unitdf.y(); + G4double udfz = unitdf.z(); + G4double k = 180.*deg; + G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); + G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); + G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); + G4RotationMatrix def = G4RotationMatrix(); + def.setRows(d,e,f); + crystal_rotm=def*abc; + crystal_rotm.rotateY(180*deg); + G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + G4ThreeVector lg_Axis = df.cross(z7); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4double lg_ang = theta7; + G4ThreeVector p = G4ThreeVector(cos(lg_ang)+pow(ulgx,2)*(1-cos(lg_ang)), ulgx*ulgy*(1-cos(lg_ang))-ulgz*sin(lg_ang), ulgx*ulgz*(1-cos(lg_ang))+ulgy*sin(lg_ang)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(lg_ang))+ulgz*sin(lg_ang), cos(lg_ang)+pow(ulgy,2)*(1-cos(lg_ang)), ulgy*ulgz*(1-cos(lg_ang))-ulgx*sin(lg_ang)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(lg_ang))-ulgy*sin(lg_ang), ulgz*ulgy*(1-cos(lg_ang))+ulgx*sin(lg_ang), cos(lg_ang)+pow(ulgz,2)*(1-cos(lg_ang))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum7); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget7+detThickness7+0.5*lgThickness7+.0003*mm)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta7+90*deg)*sin(i*360*deg/detNum7+.001*deg), sin(theta7+90*deg)*cos(i*360*deg/detNum7+.001*deg), -cos(theta7+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z7); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg+theta7; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((i)*360*deg/detNum7+.001*deg); + delrin_rotm.rotateX(180*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget7+detThickness7+lgThickness7+delrinA7/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + bool placeCrystal = true; + bool placeDel = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (148-m_Array[i2] == 68+i){ + placeCrystal = false; + } + if (m_Array[i2] == 68+i){ + placeDel = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal7, //its logical volume + "CsI Detector7", //its name + world, //its mother volume + false, //no boolean operation + 68+i, //copy number + checkOverlaps); //overlaps checking + } + } + if(placeDel){ + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide7, //its logical volume + "LightGuide7", //its name + world, //its mother volume + false, //no boolean operation + 68+i, //copy number + checkOverlaps); //overlaps checking + } + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin7, //its logical volume + "Delrin7", //its name + world, //its mother volume + false, //no boolean operation + 68+i, //copy number + checkOverlaps); //overlaps checking + } + } + }} + + + if(m_Ring8) { + // Ring 8 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + G4int detNum8 = 10; + G4double distanceFromTargetBack8 = 47*mm; //Its really 47 mm from the target, but at 45.9 we avoid intersection the detectors in ring 9 + G4double theta8 = 135.0*deg; + G4double halfTheta8 = 12.0*deg; //+0.1*deg; //fudge factor + G4double lgThickness8 = 7.5*mm; + G4double detThickness8 = 3.6*mm; + G4double distanceFromTarget8 = distanceFromTargetBack8 - detThickness8; + + //G4double distance8 = distanceFromTarget8*sin(theta8); //this gives the distance from the beam axis. + /* + // + // Delrin Ring (for deletion) + // + G4double delrin_rmina8 = distance8+detThickness8+lgThickness8, delrin_rmaxa8 = delrin_rmina8+5*mm; + G4double delrin_hz8 = 5*mm; //distance8*tan(halfTheta8); + G4double delrin_phimin8 = 0.*deg, delrin_phimax8 = 360.*deg; + G4ThreeVector delrin_pos8 = G4ThreeVector(0,0,-distanceFromTarget8*cos(theta8)); //G4ThreeVector(0,0,distance8+lgThickness8+detThickness8*sin(theta8)); + + G4Tubs* solidDelrin8 = + new G4Tubs("Delrin8", //its name + delrin_rmina8, delrin_rmaxa8, + delrin_hz8, + delrin_phimin8, delrin_phimax8); //its size + + G4LogicalVolume* logicDelrin8 = + new G4LogicalVolume(solidDelrin8, //its solid + delrin, //its material + "Delrin8"); //its name + logicDelrin8->SetVisAttributes(delrinVisAtt); + + if(delrinBool) {new G4PVPlacement(0, //no rotation + delrin_pos8, //its position + logicDelrin8, //its logical volume + "Delrin8", //its name + world, //its mother volume + false, //no boolean operation + 0, //copy number + checkOverlaps); //overlaps checking + } + */ + // + // Delrin Ring + // + G4double delrinA8 = 5*mm; + G4double delrinB8 = 10*mm; + G4double fdelrinHalfAngle8 = atan(delrinB8/2/(distanceFromTarget8+detThickness8+lgThickness8)); + G4double firs8 = pow(pow(distanceFromTarget8+detThickness8+lgThickness8,2)+pow(delrinB8/2,2),0.5)*sin(theta8-fdelrinHalfAngle8); + G4double firb8 = pow(pow(distanceFromTarget8+detThickness8+lgThickness8,2)+pow(delrinB8/2,2),0.5)*sin(theta8+fdelrinHalfAngle8); + G4double bdelrinHalfAngle8 = atan(delrinB8/2/(distanceFromTarget8+detThickness8+lgThickness8+delrinA8)); + G4double birs8 = pow(pow(distanceFromTarget8+detThickness8+lgThickness8+delrinA8,2)+pow(delrinB8/2,2),0.5)*sin(theta8-bdelrinHalfAngle8); + G4double birb8 = pow(pow(distanceFromTarget8+detThickness8+lgThickness8+delrinA8,2)+pow(delrinB8/2,2),0.5)*sin(theta8+bdelrinHalfAngle8); + + G4double delrin_dz8 = delrinB8/2; + G4double delrin_theta8 = 0; + G4double delrin_phi8 = 0; + G4double delrin_dyab8 = delrinA8/2; + G4double delrin_dxa8 = firs8*tan(180*deg/detNum8); + G4double delrin_dxb8 = birs8*tan(180*deg/detNum8); + G4double delrin_dycd8 = delrinA8/2; + G4double delrin_dxc8 = firb8*tan(180*deg/detNum8); + G4double delrin_dxd8 = birb8*tan(180*deg/detNum8); + G4double delrin_alpab8 = 0; + G4double delrin_alpcd8 = delrin_alpab8; + + G4ThreeVector delrin_pos8 = G4ThreeVector(0,0,-distanceFromTarget8*cos(theta8)); + + G4Trap* solidDelrin8 = + new G4Trap("Delrin8", //its name + delrin_dz8, + delrin_theta8, delrin_phi8, + delrin_dyab8, + delrin_dxa8, delrin_dxb8, + delrin_alpab8, + delrin_dycd8, + delrin_dxc8, delrin_dxd8, + delrin_alpcd8); //its size + + G4LogicalVolume* logicDelrin8 = + new G4LogicalVolume(solidDelrin8, //its solid + delrin, //its material + "Delrin8"); //its name + logicDelrin8->SetVisAttributes(delrinVisAtt); + + // + // CsI Detector + // + G4double coneheight8 = distanceFromTarget8; + G4double coneangle8 = theta8; + G4double crystal_rmina8 = 0.*mm; + G4double crystal_rmaxa8 = 0.0001*mm; + G4double crystal_rminb8 = -coneheight8*tan(coneangle8+halfTheta8); + G4double crystal_rmaxb8 = -coneheight8*tan(coneangle8-halfTheta8); + G4double crystal_hz8 = 0.5*coneheight8; + G4double crystal_phimin8 = 0.*deg, crystal_phimax8 = 360.*deg/detNum8; + G4RotationMatrix tip_rotm8 = G4RotationMatrix(); + G4ThreeVector tip_pos8 = G4ThreeVector(0,0,crystal_hz8+.0001*mm); + G4Transform3D tip_trans8 = G4Transform3D(tip_rotm8, tip_pos8); + G4ThreeVector z8 = G4ThreeVector(0,0,1); + G4ThreeVector d08 = G4ThreeVector(distanceFromTarget8*sin(coneangle8)*cos(0.5*360*deg/detNum8), + distanceFromTarget8*sin(coneangle8)*sin(0.5*360*deg/detNum8), + -distanceFromTarget8*cos(coneangle8)); + G4ThreeVector unitAxis8 = z8.cross(d08); + unitAxis8 = unitAxis8/unitAxis8.mag(); + G4double ux8 = unitAxis8.x(); + G4double uy8 = unitAxis8.y(); + G4double uz8 = unitAxis8.z(); + G4ThreeVector top8 = G4ThreeVector(cos(-coneangle8)+pow(ux8,2)*(1-cos(-coneangle8)), ux8*uy8*(1-cos(-coneangle8))-uz8*sin(-coneangle8), ux8*uz8*(1-cos(-coneangle8))+uy8*sin(-coneangle8)); + G4ThreeVector mid8 = G4ThreeVector(uy8*ux8*(1-cos(-coneangle8))+uz8*sin(-coneangle8), cos(-coneangle8)+pow(uy8,2)*(1-cos(-coneangle8)), uy8*uz8*(1-cos(-coneangle8))-ux8*sin(-coneangle8)); + G4ThreeVector bot8 = G4ThreeVector(uz8*ux8*(1-cos(-coneangle8))-uy8*sin(-coneangle8), uz8*uy8*(1-cos(-coneangle8))+ux8*sin(-coneangle8), cos(-coneangle8)+pow(uz8,2)*(1-cos(-coneangle8))); + G4RotationMatrix firstBox_rotm8 = G4RotationMatrix(); + firstBox_rotm8.setRows(top8,mid8,bot8); + G4ThreeVector firstBox_pos8 = G4ThreeVector(0,0,0); + G4Transform3D firstBox_trans8 = G4Transform3D(firstBox_rotm8, firstBox_pos8); + G4RotationMatrix secondBox_rotm8 = G4RotationMatrix(); + secondBox_rotm8.setRows(top8,mid8,bot8); + G4ThreeVector secondBox_pos8 = (2*distanceFromTarget8+detThickness8)/d08.mag()*d08; + G4Transform3D secondBox_trans8 = G4Transform3D(secondBox_rotm8, secondBox_pos8); + + G4Orb* solidTip8 = + new G4Orb("tip8", + .0001*mm); + G4Box* solidSubtractionBox8 = + new G4Box("SubtractionBox8", //its name + distanceFromTarget8, + distanceFromTarget8, + distanceFromTarget8); //its size + G4Cons* solidCone8 = + new G4Cons("Cone8", //its name + crystal_rmina8, crystal_rmaxa8, + crystal_rminb8, crystal_rmaxb8, + crystal_hz8, + crystal_phimin8, crystal_phimax8); //its size + G4UnionSolid* solidTippedCone8 = + new G4UnionSolid("TippedCone8", + solidTip8, + solidCone8, + tip_trans8); + G4SubtractionSolid* solidIntermediate8 = + new G4SubtractionSolid("Intermediate8", + solidTippedCone8, + solidSubtractionBox8, + firstBox_trans8); + G4SubtractionSolid* solidCrystal8 = + new G4SubtractionSolid("Crystal8", + solidIntermediate8, + solidSubtractionBox8, + secondBox_trans8); + + G4LogicalVolume* logicCrystal8 = + new G4LogicalVolume(solidCrystal8, //its solid + CsI, //its material + "CsI Detector8"); //its name + logicCrystal8->SetVisAttributes(crystalVisAtt); + logicCrystal8->SetSensitiveDetector(m_MicroballScorer); + // + // Light Guide + // + G4double lightGuide_px8 = 10*mm; + G4double lightGuide_py8 = 10*mm; + G4double lightGuide_pz8 = lgThickness8; + G4Box* solidLightGuide8 = + new G4Box("LightGuide8", //its name + 0.5*lightGuide_px8, + 0.5*lightGuide_py8, + 0.5*lightGuide_pz8); //its size + + G4LogicalVolume* logicLightGuide8 = + new G4LogicalVolume(solidLightGuide8, //its solid + glass, //its material + "LightGuide8"); //its name + logicLightGuide8->SetVisAttributes(lightGuideVisAtt); + + + for(int i = 1; i <= detNum8; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + G4ThreeVector d0 = G4ThreeVector(distanceFromTarget8*sin(coneangle8)*cos(0.5*360*deg/detNum8), + distanceFromTarget8*sin(coneangle8)*sin(0.5*360*deg/detNum8), + distanceFromTarget8*cos(coneangle8)); + G4ThreeVector df = G4ThreeVector(distanceFromTarget8*sin(theta8)*sin(i*360*deg/detNum8+.001*deg/*+0.5*360*deg/detNum8*/), + distanceFromTarget8*sin(theta8)*cos(i*360*deg/detNum8+.001*deg/*+0.5*360*deg/detNum8*/), + -distanceFromTarget8*cos(theta8)); + G4ThreeVector axis = d0.cross(df); + G4double ax = axis.x(); + G4double ay = axis.y(); + G4double az = axis.z(); + G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); + G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); + G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); + G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); + G4RotationMatrix abc = G4RotationMatrix(); + abc.setRows(a,b,c); + G4ThreeVector unitdf = df/df.mag(); + G4double udfx = unitdf.x(); + G4double udfy = unitdf.y(); + G4double udfz = unitdf.z(); + G4double k = 180.*deg; + G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); + G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); + G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); + G4RotationMatrix def = G4RotationMatrix(); + def.setRows(d,e,f); + crystal_rotm=def*abc; + crystal_rotm.rotateY(180*deg); + G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + G4ThreeVector lg_Axis = df.cross(z8); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4ThreeVector p = G4ThreeVector(cos(theta8)+pow(ulgx,2)*(1-cos(theta8)), ulgx*ulgy*(1-cos(theta8))-ulgz*sin(theta8), ulgx*ulgz*(1-cos(theta8))+ulgy*sin(theta8)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta8))+ulgz*sin(theta8), cos(theta8)+pow(ulgy,2)*(1-cos(theta8)), ulgy*ulgz*(1-cos(theta8))-ulgx*sin(theta8)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta8))-ulgy*sin(theta8), ulgz*ulgy*(1-cos(theta8))+ulgx*sin(theta8), cos(theta8)+pow(ulgz,2)*(1-cos(theta8))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum8); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget8+detThickness8+0.5*lgThickness8+.0003*mm)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta8+90*deg)*sin(i*360*deg/detNum8+.001*deg), sin(theta8+90*deg)*cos(i*360*deg/detNum8+.001*deg), -cos(theta8+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z8); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg+theta8; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((i)*360*deg/detNum8+.001*deg); + delrin_rotm.rotateX(180*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget8+detThickness8+lgThickness8+delrinA8/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + bool placeCrystal = true; + bool placeDel = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (170-m_Array[i2] == 80+i){ + placeCrystal = false; + } + if (m_Array[i2] == 80+i){ + placeDel = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal8, //its logical volume + "CsI Detector8", //its name + world, //its mother volume + false, //no boolean operation + 80+i, //copy number + checkOverlaps); //overlaps checking + } + } + if (placeDel){ + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide8, //its logical volume + "LightGuide8", //its name + world, //its mother volume + false, //no boolean operation + 80+i, //copy number + checkOverlaps); //overlaps checking + } + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin8, //its logical volume + "Delrin8", //its name + world, //its mother volume + false, //no boolean operation + 80+i, //copy number + checkOverlaps); //overlaps checking + } + } + }} + + + if(m_Ring9){ + // Ring 9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + G4int detNum9 = 6; + G4double distanceFromTargetBack9 = 50.*mm; + G4double theta9 = 159.0*deg; + G4double halfTheta9 = 12.0*deg; //+0.1*deg; //0.1 is a fudge factor to make it cover a solid angle of 4 pi + G4double lgThickness9 = 8.0*mm; + G4double detThickness9 = 3.5*mm; + G4double distanceFromTarget9 = distanceFromTargetBack9 - detThickness9; + + //G4double distance9 = distanceFromTarget9*sin(theta9); //this gives the distance from the beam axis. + + /* + // + // Delrin Ring (for deletion) + // + G4double delrin_rmina9 = distance9+detThickness9+lgThickness9, delrin_rmaxa9 = delrin_rmina9+5*mm; + G4double delrin_hz9 = 5*mm; //distance9*tan(halfTheta9); + G4double delrin_phimin9 = 0.*deg, delrin_phimax9 = 360.*deg; + G4ThreeVector delrin_pos9 = G4ThreeVector(0,0,-distanceFromTarget9*cos(theta9)); //G4ThreeVector(0,0,distance9+lgThickness9+detThickness9*sin(theta9)); + + G4Tubs* solidDelrin9 = + new G4Tubs("Delrin9", //its name + delrin_rmina9, delrin_rmaxa9, + delrin_hz9, + delrin_phimin9, delrin_phimax9); //its size + + G4LogicalVolume* logicDelrin9 = + new G4LogicalVolume(solidDelrin9, //its solid + delrin, //its material + "Delrin9"); //its name + logicDelrin9->SetVisAttributes(delrinVisAtt); + + if(delrinBool) {new G4PVPlacement(0, //no rotation + delrin_pos9, //its position + logicDelrin9, //its logical volume + "Delrin9", //its name + world, //its mother volume + false, //no boolean operation + 0, //copy number + checkOverlaps); //overlaps checking + } + */ + + // + // Delrin Ring + // + G4double delrinA9 = 5*mm; + G4double delrinB9 = 10*mm; + G4double fdelrinHalfAngle9 = atan(delrinB9/2/(distanceFromTarget9+detThickness9+lgThickness9)); + G4double firs9 = pow(pow(distanceFromTarget9+detThickness9+lgThickness9,2)+pow(delrinB9/2,2),0.5)*sin(theta9-fdelrinHalfAngle9); + G4double firb9 = pow(pow(distanceFromTarget9+detThickness9+lgThickness9,2)+pow(delrinB9/2,2),0.5)*sin(theta9+fdelrinHalfAngle9); + G4double bdelrinHalfAngle9 = atan(delrinB9/2/(distanceFromTarget9+detThickness9+lgThickness9+delrinA9)); + G4double birs9 = pow(pow(distanceFromTarget9+detThickness9+lgThickness9+delrinA9,2)+pow(delrinB9/2,2),0.5)*sin(theta9-bdelrinHalfAngle9); + G4double birb9 = pow(pow(distanceFromTarget9+detThickness9+lgThickness9+delrinA9,2)+pow(delrinB9/2,2),0.5)*sin(theta9+bdelrinHalfAngle9); + + G4double delrin_dz9 = delrinB9/2; + G4double delrin_theta9 = 0; + G4double delrin_phi9 = 0; + G4double delrin_dyab9 = delrinA9/2; + G4double delrin_dxa9 = firs9*tan(180*deg/detNum9); + G4double delrin_dxb9 = birs9*tan(180*deg/detNum9); + G4double delrin_dycd9 = delrinA9/2; + G4double delrin_dxc9 = firb9*tan(180*deg/detNum9); + G4double delrin_dxd9 = birb9*tan(180*deg/detNum9); + G4double delrin_alpab9 = 0; + G4double delrin_alpcd9 = delrin_alpab9; + + G4ThreeVector delrin_pos9 = G4ThreeVector(0,0,-distanceFromTarget9*cos(theta9)); + + G4Trap* solidDelrin9 = + new G4Trap("Delrin9", //its name + delrin_dz9, + delrin_theta9, delrin_phi9, + delrin_dyab9, + delrin_dxa9, delrin_dxb9, + delrin_alpab9, + delrin_dycd9, + delrin_dxc9, delrin_dxd9, + delrin_alpcd9); //its size + + G4LogicalVolume* logicDelrin9 = + new G4LogicalVolume(solidDelrin9, //its solid + delrin, //its material + "Delrin9"); //its name + logicDelrin9->SetVisAttributes(delrinVisAtt); + + // + // CsI Detector + // + G4double coneheight9 = distanceFromTarget9; + G4double coneangle9 = theta9; + G4double crystal_rmina9 = 0.*mm; + G4double crystal_rmaxa9 = 0.0001*mm; + G4double crystal_rminb9 = -coneheight9*tan(coneangle9+halfTheta9); + G4double crystal_rmaxb9 = -coneheight9*tan(coneangle9-halfTheta9); + G4double crystal_hz9 = 0.5*coneheight9; + G4double crystal_phimin9 = 0.*deg, crystal_phimax9 = 360.*deg/detNum9; + G4RotationMatrix tip_rotm9 = G4RotationMatrix(); + G4ThreeVector tip_pos9 = G4ThreeVector(0,0,crystal_hz9+.0001*mm); + G4Transform3D tip_trans9 = G4Transform3D(tip_rotm9, tip_pos9); + G4ThreeVector z9 = G4ThreeVector(0,0,1); + G4ThreeVector d09 = G4ThreeVector(distanceFromTarget9*sin(coneangle9)*cos(0.5*360*deg/detNum9), + distanceFromTarget9*sin(coneangle9)*sin(0.5*360*deg/detNum9), + -distanceFromTarget9*cos(coneangle9)); + G4ThreeVector unitAxis9 = z9.cross(d09); + unitAxis9 = unitAxis9/unitAxis9.mag(); + G4double ux9 = unitAxis9.x(); + G4double uy9 = unitAxis9.y(); + G4double uz9 = unitAxis9.z(); + G4ThreeVector top9 = G4ThreeVector(cos(-coneangle9)+pow(ux9,2)*(1-cos(-coneangle9)), ux9*uy9*(1-cos(-coneangle9))-uz9*sin(-coneangle9), ux9*uz9*(1-cos(-coneangle9))+uy9*sin(-coneangle9)); + G4ThreeVector mid9 = G4ThreeVector(uy9*ux9*(1-cos(-coneangle9))+uz9*sin(-coneangle9), cos(-coneangle9)+pow(uy9,2)*(1-cos(-coneangle9)), uy9*uz9*(1-cos(-coneangle9))-ux9*sin(-coneangle9)); + G4ThreeVector bot9 = G4ThreeVector(uz9*ux9*(1-cos(-coneangle9))-uy9*sin(-coneangle9), uz9*uy9*(1-cos(-coneangle9))+ux9*sin(-coneangle9), cos(-coneangle9)+pow(uz9,2)*(1-cos(-coneangle9))); + G4RotationMatrix firstBox_rotm9 = G4RotationMatrix(); + firstBox_rotm9.setRows(top9,mid9,bot9); + G4ThreeVector firstBox_pos9 = G4ThreeVector(0,0,0); + G4Transform3D firstBox_trans9 = G4Transform3D(firstBox_rotm9, firstBox_pos9); + G4RotationMatrix secondBox_rotm9 = G4RotationMatrix(); + secondBox_rotm9.setRows(top9,mid9,bot9); + G4ThreeVector secondBox_pos9 = (2*distanceFromTarget9+detThickness9)/d09.mag()*d09; + G4Transform3D secondBox_trans9 = G4Transform3D(secondBox_rotm9, secondBox_pos9); + + G4Orb* solidTip9 = + new G4Orb("tip9", + .0001*mm); + G4Box* solidSubtractionBox9 = + new G4Box("SubtractionBox9", //its name + distanceFromTarget9, + distanceFromTarget9, + distanceFromTarget9); //its size + G4Cons* solidCone9 = + new G4Cons("Cone9", //its name + crystal_rmina9, crystal_rmaxa9, + crystal_rminb9, crystal_rmaxb9, + crystal_hz9, + crystal_phimin9, crystal_phimax9); //its size + G4UnionSolid* solidTippedCone9 = + new G4UnionSolid("TippedCone9", + solidTip9, + solidCone9, + tip_trans9); + G4SubtractionSolid* solidIntermediate9 = + new G4SubtractionSolid("Intermediate9", + solidTippedCone9, + solidSubtractionBox9, + firstBox_trans9); + G4SubtractionSolid* solidCrystal9 = + new G4SubtractionSolid("Crystal9", + solidIntermediate9, + solidSubtractionBox9, + secondBox_trans9); + + G4LogicalVolume* logicCrystal9 = + new G4LogicalVolume(solidCrystal9, //its solid + CsI, //its material + "CsI Detector9"); //its name + logicCrystal9->SetVisAttributes(crystalVisAtt); + logicCrystal9->SetSensitiveDetector(m_MicroballScorer); + + // + // Light Guide + // + G4double lightGuide_px9 = 10*mm; + G4double lightGuide_py9 = 10*mm; + G4double lightGuide_pz9 = lgThickness9; + G4Box* solidLightGuide9 = + new G4Box("LightGuide9", //its name + 0.5*lightGuide_px9, + 0.5*lightGuide_py9, + 0.5*lightGuide_pz9); //its size + + G4LogicalVolume* logicLightGuide9 = + new G4LogicalVolume(solidLightGuide9, //its solid + glass, //its material + "LightGuide9"); //its name + logicLightGuide9->SetVisAttributes(lightGuideVisAtt); + + + for(int i = 1; i <= detNum9; i++) + { + G4RotationMatrix crystal_rotm = G4RotationMatrix(); + G4ThreeVector d0 = G4ThreeVector(distanceFromTarget9*sin(coneangle9)*cos(0.5*360*deg/detNum9), + distanceFromTarget9*sin(coneangle9)*sin(0.5*360*deg/detNum9), + distanceFromTarget9*cos(coneangle9)); + G4ThreeVector df = G4ThreeVector(distanceFromTarget9*sin(theta9)*sin(i*360*deg/detNum9+.001*deg/*+0.5*360*deg/detNum9*/), + distanceFromTarget9*sin(theta9)*cos(i*360*deg/detNum9+.001*deg/*+0.5*360*deg/detNum9*/), + -distanceFromTarget9*cos(theta9)); + G4ThreeVector axis = d0.cross(df); + G4double ax = axis.x(); + G4double ay = axis.y(); + G4double az = axis.z(); + G4double ux = ax/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uy = ay/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double uz = az/pow((pow(ax,2)+pow(ay,2)+pow(az,2)),0.5); + G4double j = acos(d0.dot(df)/(d0.mag()*df.mag())); + G4ThreeVector a = G4ThreeVector(cos(j)+pow(ux,2)*(1-cos(j)), ux*uy*(1-cos(j))-uz*sin(j), ux*uz*(1-cos(j))+uy*sin(j)); + G4ThreeVector b = G4ThreeVector(uy*ux*(1-cos(j))+uz*sin(j), cos(j)+pow(uy,2)*(1-cos(j)), uy*uz*(1-cos(j))-ux*sin(j)); + G4ThreeVector c = G4ThreeVector(uz*ux*(1-cos(j))-uy*sin(j), uz*uy*(1-cos(j))+ux*sin(j), cos(j)+pow(uz,2)*(1-cos(j))); + G4RotationMatrix abc = G4RotationMatrix(); + abc.setRows(a,b,c); + G4ThreeVector unitdf = df/df.mag(); + G4double udfx = unitdf.x(); + G4double udfy = unitdf.y(); + G4double udfz = unitdf.z(); + G4double k = 180.*deg; + G4ThreeVector d = G4ThreeVector(cos(k)+pow(udfx,2)*(1-cos(k)), udfx*udfy*(1-cos(k))-udfz*sin(k), udfx*udfz*(1-cos(k))+udfy*sin(k)); + G4ThreeVector e = G4ThreeVector(udfy*udfx*(1-cos(k))+udfz*sin(k), cos(k)+pow(udfy,2)*(1-cos(k)), udfy*udfz*(1-cos(k))-udfx*sin(k)); + G4ThreeVector f = G4ThreeVector(udfz*udfx*(1-cos(k))-udfy*sin(k), udfz*udfy*(1-cos(k))+udfx*sin(k), cos(k)+pow(udfz,2)*(1-cos(k))); + G4RotationMatrix def = G4RotationMatrix(); + def.setRows(d,e,f); + crystal_rotm=def*abc; + crystal_rotm.rotateY(180*deg); + G4ThreeVector crystal_pos = G4ThreeVector(0,0,0); + G4Transform3D crystal_trans = G4Transform3D(crystal_rotm, crystal_pos); + G4RotationMatrix lg_rotm = G4RotationMatrix(); + /* + lg_rotm.rotateZ(i*360*deg/detNum9); + G4ThreeVector lg_pos = G4ThreeVector((distance9+detThickness9+0.5*lgThickness9)*cos(i*360*deg/detNum9), + (distance9+detThickness9+0.5*lgThickness9)*sin(i*360*deg/detNum9), + 0)+delrin_pos9; + */ + G4ThreeVector lg_Axis = df.cross(z9); + lg_Axis = lg_Axis/lg_Axis.mag(); + G4double ulgx = lg_Axis.x(); + G4double ulgy = lg_Axis.y(); + G4double ulgz = lg_Axis.z(); + G4ThreeVector p = G4ThreeVector(cos(theta9)+pow(ulgx,2)*(1-cos(theta9)), ulgx*ulgy*(1-cos(theta9))-ulgz*sin(theta9), ulgx*ulgz*(1-cos(theta9))+ulgy*sin(theta9)); + G4ThreeVector q = G4ThreeVector(ulgy*ulgx*(1-cos(theta9))+ulgz*sin(theta9), cos(theta9)+pow(ulgy,2)*(1-cos(theta9)), ulgy*ulgz*(1-cos(theta9))-ulgx*sin(theta9)); + G4ThreeVector r = G4ThreeVector(ulgz*ulgx*(1-cos(theta9))-ulgy*sin(theta9), ulgz*ulgy*(1-cos(theta9))+ulgx*sin(theta9), cos(theta9)+pow(ulgz,2)*(1-cos(theta9))); + G4RotationMatrix pqr = G4RotationMatrix(); + pqr.setRows(p,q,r); + lg_rotm.rotateZ(i*360*deg/detNum9); + lg_rotm.rotateX(180*deg); + lg_rotm=pqr*lg_rotm; + G4ThreeVector lg_pos = (distanceFromTarget9+detThickness9+0.5*lgThickness9+.0003*mm)/df.mag()*df; + G4Transform3D lg_trans = G4Transform3D(lg_rotm, lg_pos); + G4RotationMatrix delrin_rotm = G4RotationMatrix(); + G4ThreeVector w = G4ThreeVector(sin(theta9+90*deg)*sin(i*360*deg/detNum9+.001*deg), sin(theta9+90*deg)*cos(i*360*deg/detNum9+.001*deg), -cos(theta9+90*deg)); + G4ThreeVector delrin_Axis = w.cross(-z9); + delrin_Axis = delrin_Axis/delrin_Axis.mag(); + G4double udx = delrin_Axis.x(); + G4double udy = delrin_Axis.y(); + G4double udz = delrin_Axis.z(); + G4double delAng = 90*deg+theta9; + G4ThreeVector pdel = G4ThreeVector(cos(delAng)+pow(udx,2)*(1-cos(delAng)), udx*udy*(1-cos(delAng))-udz*sin(delAng), udx*udz*(1-cos(delAng))+udy*sin(delAng)); + G4ThreeVector qdel = G4ThreeVector(udy*udx*(1-cos(delAng))+udz*sin(delAng), cos(delAng)+pow(udy,2)*(1-cos(delAng)), udy*udz*(1-cos(delAng))-udx*sin(delAng)); + G4ThreeVector rdel = G4ThreeVector(udz*udx*(1-cos(delAng))-udy*sin(delAng), udz*udy*(1-cos(delAng))+udx*sin(delAng), cos(delAng)+pow(udz,2)*(1-cos(delAng))); + G4RotationMatrix pqrdel = G4RotationMatrix(); + pqrdel.setRows(pdel,qdel,rdel); + delrin_rotm.rotateZ((i)*360*deg/detNum9+.001*deg); + delrin_rotm.rotateX(180*deg); + delrin_rotm=pqrdel*delrin_rotm; + G4ThreeVector delrin_pos = (distanceFromTarget9+detThickness9+lgThickness9+delrinA9/2+.0003*mm)/df.mag()*df; //the .0003 mm is a fudge factor to prevent overlapping + G4Transform3D delrin_trans = G4Transform3D(delrin_rotm, delrin_pos); + bool placeCrystal = true; + bool placeDel = true; + for (unsigned int i2=0; i2 < m_Array.size(); i2++){ + if (186-m_Array[i2] == 90+i){ + placeCrystal = false; + } + if (m_Array[i2] == 90+i){ + placeDel = false; + } + } + if (placeCrystal){ + if(crystalBool) {new G4PVPlacement(crystal_trans, //rotation, position + logicCrystal9, //its logical volume + "CsI Detector9", //its name + world, //its mother volume + false, //no boolean operation + 90+i, //copy number + checkOverlaps); //overlaps checking + } + } + if (placeDel){ + if(lgBool) {new G4PVPlacement(lg_trans, //rotation, position + logicLightGuide9, //its logical volume + "LightGuide9", //its name + world, //its mother volume + false, //no boolean operation + 90+i, //copy number + checkOverlaps); //overlaps checking + } + if(delrinBool) {new G4PVPlacement(delrin_trans, //rotation, position + logicDelrin9, //its logical volume + "Delrin9", //its name + world, //its mother volume + false, //no boolean operation + 90+i, //copy number + checkOverlaps); //overlaps checking + } + } + }} } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... // Add Detector branch to the EventTree. // Called After DetecorConstruction::AddDetector Method void Microball::InitializeRootOutput(){ - RootOutput *pAnalysis = RootOutput::getInstance(); - TTree *pTree = pAnalysis->GetTree(); - pTree->Branch("Microball", "TMicroballData", &m_Event) ; - pTree->SetBranchAddress("Microball", &m_Event) ; + RootOutput *pAnalysis = RootOutput::getInstance(); + TTree *pTree = pAnalysis->GetTree(); + pTree->Branch("Microball", "TMicroballData", &m_Event) ; + pTree->SetBranchAddress("Microball", &m_Event) ; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... // Read sensitive part and fill the Root tree. // Called at in the EventAction::EndOfEventAvtion void Microball::ReadSensitive(const G4Event* event){ - m_Event->Clear(); - - /////////// - // Calorimeter scorer - G4THitsMap<G4double*>* CaloHitMap; - std::map<G4int, G4double**>::iterator Calo_itr; - - G4int CaloCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("MicroballScorer/Calorimeter"); - CaloHitMap = (G4THitsMap<G4double*>*)(event->GetHCofThisEvent()->GetHC(CaloCollectionID)); - - // Loop on the Calo map - for (Calo_itr = CaloHitMap->GetMap()->begin() ; Calo_itr != CaloHitMap->GetMap()->end() ; Calo_itr++){ - - G4double* Info = *(Calo_itr->second); - //(Info[0]/2.35)*((Info[0]*1.02)*pow((Info[0]*1.8),.5)) - // double Energy = RandGauss::shoot(Info[0],((Info[0]*1000*1.02/2.35)*pow((Info[0]*1000*1.8),.5)) ); - double Energy = RandGauss::shoot(Info[0],Microball_NS::ResoEnergy); - if(Energy>Microball_NS::EnergyThreshold){ - double Time = RandGauss::shoot(Info[1],Microball_NS::ResoTime); - int DetectorNbr = (int) Info[7]; - m_Event->SetEnergy(DetectorNbr,Energy); - m_Event->SetTime(DetectorNbr,Time); - - ms_InterCoord->SetDetectedPositionX(Info[2]) ; - ms_InterCoord->SetDetectedPositionY(Info[3]) ; - ms_InterCoord->SetDetectedPositionZ(Info[4]) ; - ms_InterCoord->SetDetectedAngleTheta(Info[5]/deg) ; - ms_InterCoord->SetDetectedAnglePhi(Info[6]/deg) ; + m_Event->Clear(); + + /////////// + // Calorimeter scorer + G4THitsMap<G4double*>* CaloHitMap; + std::map<G4int, G4double**>::iterator Calo_itr; + + G4int CaloCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("MicroballScorer/Calorimeter"); + CaloHitMap = (G4THitsMap<G4double*>*)(event->GetHCofThisEvent()->GetHC(CaloCollectionID)); + + // Loop on the Calo map + for (Calo_itr = CaloHitMap->GetMap()->begin() ; Calo_itr != CaloHitMap->GetMap()->end() ; Calo_itr++){ + + G4double* Info = *(Calo_itr->second); + //(Info[0]/2.35)*((Info[0]*1.02)*pow((Info[0]*1.8),.5)) + // double Energy = RandGauss::shoot(Info[0],((Info[0]*1000*1.02/2.35)*pow((Info[0]*1000*1.8),.5)) ); + double Energy = RandGauss::shoot(Info[0],Microball_NS::ResoEnergy); + if(Energy>Microball_NS::EnergyThreshold){ + double Time = RandGauss::shoot(Info[1],Microball_NS::ResoTime); + int DetectorNbr = (int) Info[7]; + m_Event->SetEnergy(DetectorNbr,Energy); + m_Event->SetTime(DetectorNbr,Time); + + ms_InterCoord->SetDetectedPositionX(Info[2]) ; + ms_InterCoord->SetDetectedPositionY(Info[3]) ; + ms_InterCoord->SetDetectedPositionZ(Info[4]) ; + ms_InterCoord->SetDetectedAngleTheta(Info[5]/deg) ; + ms_InterCoord->SetDetectedAnglePhi(Info[6]/deg) ; + } } - } - // clear map for next event - CaloHitMap->clear(); + // clear map for next event + CaloHitMap->clear(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //////////////////////////////////////////////////////////////// void Microball::InitializeScorers() { - // This check is necessary in case the geometry is reloaded - bool already_exist = false; - m_MicroballScorer = CheckScorer("MicroballScorer",already_exist) ; - - if(already_exist) - return ; - - // Otherwise the scorer is initialised - vector<int> level; level.push_back(0); - G4VPrimitiveScorer* Calorimeter= new CALORIMETERSCORERS::PS_CalorimeterWithInteraction("Calorimeter",level, 0) ; - //and register it to the multifunctionnal detector - m_MicroballScorer->RegisterPrimitive(Calorimeter); - G4SDManager::GetSDMpointer()->AddNewDetector(m_MicroballScorer) ; + // This check is necessary in case the geometry is reloaded + bool already_exist = false; + m_MicroballScorer = CheckScorer("MicroballScorer",already_exist) ; + + if(already_exist) + return ; + + // Otherwise the scorer is initialised + vector<int> level; level.push_back(0); + G4VPrimitiveScorer* Calorimeter= new CALORIMETERSCORERS::PS_CalorimeterWithInteraction("Calorimeter",level, 0) ; + //and register it to the multifunctionnal detector + m_MicroballScorer->RegisterPrimitive(Calorimeter); + G4SDManager::GetSDMpointer()->AddNewDetector(m_MicroballScorer) ; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -2791,7 +2791,7 @@ void Microball::InitializeScorers() { // Construct Method to be pass to the DetectorFactory // //////////////////////////////////////////////////////////////////////////////// NPS::VDetector* Microball::Construct(){ - return (NPS::VDetector*) new Microball(); + return (NPS::VDetector*) new Microball(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -2799,13 +2799,13 @@ NPS::VDetector* Microball::Construct(){ // Registering the construct method to the factory // //////////////////////////////////////////////////////////////////////////////// extern"C" { - class proxy_nps_plastic{ + class proxy_nps_plastic{ public: - proxy_nps_plastic(){ - NPS::DetectorFactory::getInstance()->AddToken("Microball","Microball"); - NPS::DetectorFactory::getInstance()->AddDetector("Microball",Microball::Construct); - } - }; - - proxy_nps_plastic p_nps_plastic; + proxy_nps_plastic(){ + NPS::DetectorFactory::getInstance()->AddToken("Microball","Microball"); + NPS::DetectorFactory::getInstance()->AddDetector("Microball",Microball::Construct); + } + }; + + proxy_nps_plastic p_nps_plastic; } diff --git a/NPSimulation/Detectors/Microball/Microball.hh b/NPSimulation/Detectors/Microball/Microball.hh index 5587d0780f07ee2efe84d47018f1c19dc7546183..5d6378e980cec37bc7c0e597b35683b6fb02c4e9 100644 --- a/NPSimulation/Detectors/Microball/Microball.hh +++ b/NPSimulation/Detectors/Microball/Microball.hh @@ -37,90 +37,90 @@ using namespace std; #include "TMicroballData.h" class Microball : public NPS::VDetector{ - //////////////////////////////////////////////////// - /////// Default Constructor and Destructor ///////// - //////////////////////////////////////////////////// - public: + //////////////////////////////////////////////////// + /////// Default Constructor and Destructor ///////// + //////////////////////////////////////////////////// +public: Microball() ; virtual ~Microball() ; - + //////////////////////////////////////////////////// /////// Specific Function of this Class /////////// //////////////////////////////////////////////////// - public: +public: // Cylindric plastic - void AddMicroball(bool bR1, bool bR2, bool bR3, - bool bR4, bool bR5, bool bR6, - bool bR7, bool bR8, bool bR9, - vector<int>); - + void AddMicroball(bool bR1, bool bR2, bool bR3, + bool bR4, bool bR5, bool bR6, + bool bR7, bool bR8, bool bR9, + vector<int>); + G4LogicalVolume* BuildSquareDetector(); G4LogicalVolume* BuildCylindricalDetector(); - - private: + +private: G4LogicalVolume* m_SquareDetector; G4LogicalVolume* m_CylindricalDetector; //////////////////////////////////////////////////// ////// Inherite from NPS::VDetector class ///////// //////////////////////////////////////////////////// - public: +public: // Read stream at Configfile to pick-up parameters of detector (Position,...) // Called in DetecorConstruction::ReadDetextorConfiguration Method void ReadConfiguration(string Path) ; - + // Construct detector and inialise sensitive part. // Called After DetecorConstruction::AddDetector Method void ConstructDetector(G4LogicalVolume* world) ; - + // Add Detector branch to the EventTree. // Called After DetecorConstruction::AddDetector Method void InitializeRootOutput() ; - + // Read sensitive part and fill the Root tree. // Called at in the EventAction::EndOfEventAvtion void ReadSensitive(const G4Event* event) ; - - public: // Scorer + +public: // Scorer // Initialize all Scorer used by the MUST2Array void InitializeScorers() ; - + // Associated Scorer G4MultiFunctionalDetector* m_MicroballScorer ; //////////////////////////////////////////////////// ///////////Event class to store Data//////////////// //////////////////////////////////////////////////// - private: +private: TMicroballData* m_Event ; - + //////////////////////////////////////////////////// ///////////////Private intern Data////////////////// //////////////////////////////////////////////////// - private: // Geometry - // Detector Coordinate - vector<double> m_R; +private: // Geometry + // Detector Coordinate + vector<double> m_R; vector<double> m_Theta; - vector<double> m_Phi; + vector<double> m_Phi; // Shape type vector<string> m_Shape ; - bool m_Ring1; - bool m_Ring2; - bool m_Ring3; - bool m_Ring4; - bool m_Ring5; - bool m_Ring6; - bool m_Ring7; - bool m_Ring8; - bool m_Ring9; - vector<int> m_Array; - + bool m_Ring1; + bool m_Ring2; + bool m_Ring3; + bool m_Ring4; + bool m_Ring5; + bool m_Ring6; + bool m_Ring7; + bool m_Ring8; + bool m_Ring9; + vector<int> m_Array; + // Visualisation Attribute G4VisAttributes* m_VisSquare; G4VisAttributes* m_VisCylinder; - - // Needed for dynamic loading of the library - public: + + // Needed for dynamic loading of the library +public: static NPS::VDetector* Construct(); }; #endif diff --git a/NPSimulation/Detectors/Plastic/Plastic.cc b/NPSimulation/Detectors/Plastic/Plastic.cc index 5f6d97caac6038e24661906c5cc676daf20d7678..678c40a80c7b4874dad10ff33fe2b988a34533ab 100644 --- a/NPSimulation/Detectors/Plastic/Plastic.cc +++ b/NPSimulation/Detectors/Plastic/Plastic.cc @@ -13,7 +13,7 @@ *---------------------------------------------------------------------------* * Decription: * * This class describe a Modular cylindrical Plastic Scintillator * - * Few Material are instantiate and user can choose position and dimension * + * Few Material are instantiate and user can choose position and dimension * * but also the adding of a lead plate on the rear side of the detector * * * *---------------------------------------------------------------------------* @@ -56,9 +56,9 @@ using namespace CLHEP; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... namespace PLASTIC{ - // Energy and time Resolution - const G4double ResoTime = 4.2 ;// = 10ns of Resolution // Unit is MeV/2.35 - const G4double ResoEnergy = 5.0 ;// Resolution in % + // Energy and time Resolution + const G4double ResoTime = 4.2 ;// = 10ns of Resolution // Unit is MeV/2.35 + const G4double ResoEnergy = 5.0 ;// Resolution in % } using namespace PLASTIC ; @@ -67,8 +67,8 @@ using namespace PLASTIC ; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... // Plastic Specific Method Plastic::Plastic(){ - m_Event = new TPlasticData() ; - m_PlasticScorer = 0; + m_Event = new TPlasticData() ; + m_PlasticScorer = 0; } Plastic::~Plastic(){ @@ -76,45 +76,45 @@ Plastic::~Plastic(){ //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void Plastic::AddPlastic( G4double R , - G4double Theta , - G4double Phi , - G4double PlasticThickness , - G4double PlasticRadius , - G4String Scintillator , - G4double LeadThickness ) + G4double Theta , + G4double Phi , + G4double PlasticThickness , + G4double PlasticRadius , + G4String Scintillator , + G4double LeadThickness ) { - - m_R.push_back(R) ; - m_Theta.push_back(Theta) ; - m_Phi.push_back(Phi) ; - m_PlasticThickness.push_back(PlasticThickness) ; - m_LeadThickness.push_back(LeadThickness) ; - m_Scintillator.push_back(Scintillator) ; - m_PlasticRadius.push_back(PlasticRadius) ; // cylindrical shape - m_PlasticHeight.push_back(-1) ; // squared shape - m_PlasticWidth.push_back(-1) ; // squared shape + + m_R.push_back(R) ; + m_Theta.push_back(Theta) ; + m_Phi.push_back(Phi) ; + m_PlasticThickness.push_back(PlasticThickness) ; + m_LeadThickness.push_back(LeadThickness) ; + m_Scintillator.push_back(Scintillator) ; + m_PlasticRadius.push_back(PlasticRadius) ; // cylindrical shape + m_PlasticHeight.push_back(-1) ; // squared shape + m_PlasticWidth.push_back(-1) ; // squared shape } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void Plastic::AddPlastic( G4double R , - G4double Theta , - G4double Phi , - G4double Height , - G4double Width , - G4double PlasticThickness , - G4String Scintillator , - G4double LeadThickness ) + G4double Theta , + G4double Phi , + G4double Height , + G4double Width , + G4double PlasticThickness , + G4String Scintillator , + G4double LeadThickness ) { - m_R.push_back(R) ; - m_Theta.push_back(Theta) ; - m_Phi.push_back(Phi) ; - m_PlasticThickness.push_back(PlasticThickness) ; - m_LeadThickness.push_back(LeadThickness) ; - m_Scintillator.push_back(Scintillator) ; - m_PlasticRadius.push_back(-1) ; // cylindrical shape - m_PlasticHeight.push_back(Height) ; // squared shape - m_PlasticWidth.push_back(Width) ; // squared shape - + m_R.push_back(R) ; + m_Theta.push_back(Theta) ; + m_Phi.push_back(Phi) ; + m_PlasticThickness.push_back(PlasticThickness) ; + m_LeadThickness.push_back(LeadThickness) ; + m_Scintillator.push_back(Scintillator) ; + m_PlasticRadius.push_back(-1) ; // cylindrical shape + m_PlasticHeight.push_back(Height) ; // squared shape + m_PlasticWidth.push_back(Width) ; // squared shape + } @@ -127,512 +127,576 @@ void Plastic::AddPlastic( G4double R , // Read stream at Configfile to pick-up parameters of detector (Position,...) // Called in DetecorConstruction::ReadDetextorConfiguration Method void Plastic::ReadConfiguration(string Path){ - ifstream ConfigFile ; - ConfigFile.open(Path.c_str()) ; - string LineBuffer ; - string DataBuffer ; - - G4double Theta = 0 , Phi = 0 , R = 0 , Thickness = 0 , Radius = 0 ; - G4double LeadThickness = 0, X = 0 , Y = 0 , Z = 0 , Width = 0 , Height = 0 ; - G4String Scintillator, Shape ; - - bool check_Theta = false ; - bool check_Phi = false ; - bool check_R = false ; - bool check_Thickness = false ; - bool check_Radius = false ; - bool check_LeadThickness = false ; - bool check_Scintillator = false ; - bool check_Height = false ; - bool check_Width = false ; - bool check_Shape = false ; - bool check_X = false ; - bool check_Y = false ; - bool check_Z = false ; - bool ReadingStatus = false ; - - - while (!ConfigFile.eof()) { - getline(ConfigFile, LineBuffer); - - // If line is a Start Up Plastic bloc, Reading toggle to true - if (LineBuffer.compare(0, 7, "Plastic") == 0) { - G4cout << "///" << G4endl ; - G4cout << "Platic found: " << G4endl ; - ReadingStatus = true ; - - } - - // Else don't toggle to Reading Block Status - else ReadingStatus = false ; - - // Reading Block - while(ReadingStatus){ - // Pickup Next Word - ConfigFile >> DataBuffer ; - - // Comment Line - if (DataBuffer.compare(0, 1, "%") == 0) { - ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' ); - } - - // Finding another telescope (safety), toggle out - else if (DataBuffer.compare(0, 6, "Plastic") == 0) { - G4cout << "WARNING: Another Telescope is find before standard sequence of Token, Error may occured in Telecope definition" << G4endl ; - ReadingStatus = false ; - } - - //Angle method - else if (DataBuffer.compare(0, 6, "THETA=") == 0) { - check_Theta = true; - ConfigFile >> DataBuffer ; - Theta = atof(DataBuffer.c_str()) ; - Theta = Theta * deg; - G4cout << "Theta: " << Theta / deg << G4endl; - } - - else if (DataBuffer.compare(0, 4, "PHI=") == 0) { - check_Phi = true; - ConfigFile >> DataBuffer ; - Phi = atof(DataBuffer.c_str()) ; - Phi = Phi * deg; - G4cout << "Phi: " << Phi / deg << G4endl; - } - - else if (DataBuffer.compare(0, 2, "R=") == 0) { - check_R = true; - ConfigFile >> DataBuffer ; - R = atof(DataBuffer.c_str()) ; - R = R * mm; - G4cout << "R: " << R/mm << G4endl; - } - - //Position method - else if (DataBuffer.compare(0, 2, "X=") == 0) { - check_X = true; - ConfigFile >> DataBuffer ; - X = atof(DataBuffer.c_str()) ; - X = X * mm; - G4cout << "X: " << X / mm << G4endl; - } - - else if (DataBuffer.compare(0, 2, "Y=") == 0) { - check_Y = true; - ConfigFile >> DataBuffer ; - Y = atof(DataBuffer.c_str()) ; - Y = Y * mm; - G4cout << "Y: " << Y / mm << G4endl; - } - - else if (DataBuffer.compare(0, 2, "Z=") == 0) { - check_Z = true; - ConfigFile >> DataBuffer ; - Z = atof(DataBuffer.c_str()) ; - Z = Z * mm; - G4cout << "Z: " << Z / mm << G4endl; - } - - - //General - else if (DataBuffer.compare(0, 6, "Shape=") == 0) { - check_Shape = true; - ConfigFile >> DataBuffer ; - Shape = DataBuffer ; - G4cout << "Shape: " << Shape << G4endl; - } - - // Cylindrical shape - else if (DataBuffer.compare(0, 7, "Radius=") == 0) { - check_Radius = true; - ConfigFile >> DataBuffer ; - Radius = atof(DataBuffer.c_str()) ; - Radius = Radius * mm; - G4cout << "Plastic Radius: " << Radius/mm << G4endl; - } - - // Squared shape - else if (DataBuffer.compare(0, 7, "Width=") == 0) { - check_Width = true; - ConfigFile >> DataBuffer ; - Width = atof(DataBuffer.c_str()) ; - Width = Width * mm; - G4cout << "Plastic Width: " << Width/mm << G4endl; - } - - else if (DataBuffer.compare(0, 7, "Height=") == 0) { - check_Height = true; - ConfigFile >> DataBuffer ; - Height = atof(DataBuffer.c_str()) ; - Height = Height * mm; - G4cout << "Plastic Height: " << Height/mm << G4endl; - } - - // Common - else if (DataBuffer.compare(0, 10, "Thickness=") == 0) { - check_Thickness = true; - ConfigFile >> DataBuffer ; - Thickness = atof(DataBuffer.c_str()) ; - Thickness = Thickness * mm; - G4cout << "Plastic Thickness: " << Thickness/mm << G4endl; - } - - else if (DataBuffer.compare(0, 13, "Scintillator=") == 0) { - check_Scintillator = true ; - ConfigFile >> DataBuffer ; - Scintillator = DataBuffer ; - G4cout << "Plastic Scintillator type: " << Scintillator << G4endl; - } - - else if (DataBuffer.compare(0, 14, "LeadThickness=") == 0) { - check_LeadThickness = true; - ConfigFile >> DataBuffer ; - LeadThickness = atof(DataBuffer.c_str()) ; - LeadThickness = LeadThickness * mm; - G4cout << "Lead Thickness : " << LeadThickness/mm << G4endl; - } - - /////////////////////////////////////////////////// - // If no Detector Token and no comment, toggle out - else{ - ReadingStatus = false; - G4cout << "Wrong Token Sequence: Getting out " << DataBuffer << G4endl ; - } - - ///////////////////////////////////////////////// - // If All necessary information there, toggle out - - if (( check_Theta && check_Phi && check_R && check_Thickness - && check_Radius && check_LeadThickness && check_Scintillator - && check_Shape) // Cylindrical case - || - ( check_X && check_Y && check_Z && check_Thickness && check_Radius - && check_LeadThickness && check_Scintillator ) - || - ( check_Theta && check_Phi && check_R && check_Thickness - && check_Width && check_Height && check_LeadThickness - && check_Scintillator && check_Shape ) // Squared case - || - ( check_X && check_Y && check_Z && check_Thickness && check_Width - && check_Height && check_LeadThickness && check_Scintillator )) { - - if (check_X && check_Y && check_Z){ - R = sqrt (X*X+Y*Y+Z*Z); - Theta = acos(Z / (R) ); - Phi = atan2(Y,X); + ifstream ConfigFile ; + ConfigFile.open(Path.c_str()) ; + string LineBuffer ; + string DataBuffer ; + + G4double Theta = 0 , Phi = 0 , R = 0 , Thickness = 0 , Radius = 0 ; + G4double LeadThickness = 0, X = 0 , Y = 0 , Z = 0 , Width = 0 , Height = 0 ; + G4String Scintillator, Shape ; + + bool check_Theta = false ; + bool check_Phi = false ; + bool check_R = false ; + bool check_Thickness = false ; + bool check_Radius = false ; + bool check_LeadThickness = false ; + bool check_Scintillator = false ; + bool check_Height = false ; + bool check_Width = false ; + bool check_Shape = false ; + bool check_X = false ; + bool check_Y = false ; + bool check_Z = false ; + bool ReadingStatus = false ; + + + while (!ConfigFile.eof()) { + getline(ConfigFile, LineBuffer); + + // If line is a Start Up Plastic bloc, Reading toggle to true + if (LineBuffer.compare(0, 7, "Plastic") == 0) { + G4cout << "///" << G4endl ; + G4cout << "Platic found: " << G4endl ; + ReadingStatus = true ; + + } + + // Else don't toggle to Reading Block Status + else ReadingStatus = false ; + + // Reading Block + while(ReadingStatus){ + // Pickup Next Word + ConfigFile >> DataBuffer ; + + // Comment Line + if (DataBuffer.compare(0, 1, "%") == 0) { + ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' ); + } + + // Finding another telescope (safety), toggle out + else if (DataBuffer.compare(0, 6, "Plastic") == 0) { + G4cout << "WARNING: Another Telescope is find before standard sequence of Token, Error may occured in Telecope definition" << G4endl ; + ReadingStatus = false ; + } + + //Angle method + else if (DataBuffer.compare(0, 6, "THETA=") == 0) { + check_Theta = true; + ConfigFile >> DataBuffer ; + Theta = atof(DataBuffer.c_str()) ; + Theta = Theta * deg; + G4cout << "Theta: " << Theta / deg << G4endl; + } + + else if (DataBuffer.compare(0, 4, "PHI=") == 0) { + check_Phi = true; + ConfigFile >> DataBuffer ; + Phi = atof(DataBuffer.c_str()) ; + Phi = Phi * deg; + G4cout << "Phi: " << Phi / deg << G4endl; + } + + else if (DataBuffer.compare(0, 2, "R=") == 0) { + check_R = true; + ConfigFile >> DataBuffer ; + R = atof(DataBuffer.c_str()) ; + R = R * mm; + G4cout << "R: " << R/mm << G4endl; + } + + //Position method + else if (DataBuffer.compare(0, 2, "X=") == 0) { + check_X = true; + ConfigFile >> DataBuffer ; + X = atof(DataBuffer.c_str()) ; + X = X * mm; + G4cout << "X: " << X / mm << G4endl; + } + + else if (DataBuffer.compare(0, 2, "Y=") == 0) { + check_Y = true; + ConfigFile >> DataBuffer ; + Y = atof(DataBuffer.c_str()) ; + Y = Y * mm; + G4cout << "Y: " << Y / mm << G4endl; + } + + else if (DataBuffer.compare(0, 2, "Z=") == 0) { + check_Z = true; + ConfigFile >> DataBuffer ; + Z = atof(DataBuffer.c_str()) ; + Z = Z * mm; + G4cout << "Z: " << Z / mm << G4endl; + } + + + //General + else if (DataBuffer.compare(0, 6, "Shape=") == 0) { + check_Shape = true; + ConfigFile >> DataBuffer ; + Shape = DataBuffer ; + G4cout << "Shape: " << Shape << G4endl; + } + + // Cylindrical shape + else if (DataBuffer.compare(0, 7, "Radius=") == 0) { + check_Radius = true; + ConfigFile >> DataBuffer ; + Radius = atof(DataBuffer.c_str()) ; + Radius = Radius * mm; + G4cout << "Plastic Radius: " << Radius/mm << G4endl; + } + + // Squared shape + else if (DataBuffer.compare(0, 7, "Width=") == 0) { + check_Width = true; + ConfigFile >> DataBuffer ; + Width = atof(DataBuffer.c_str()) ; + Width = Width * mm; + G4cout << "Plastic Width: " << Width/mm << G4endl; + } + + else if (DataBuffer.compare(0, 7, "Height=") == 0) { + check_Height = true; + ConfigFile >> DataBuffer ; + Height = atof(DataBuffer.c_str()) ; + Height = Height * mm; + G4cout << "Plastic Height: " << Height/mm << G4endl; + } + + // Common + else if (DataBuffer.compare(0, 10, "Thickness=") == 0) { + check_Thickness = true; + ConfigFile >> DataBuffer ; + Thickness = atof(DataBuffer.c_str()) ; + Thickness = Thickness * mm; + G4cout << "Plastic Thickness: " << Thickness/mm << G4endl; + } + + else if (DataBuffer.compare(0, 13, "Scintillator=") == 0) { + check_Scintillator = true ; + ConfigFile >> DataBuffer ; + Scintillator = DataBuffer ; + G4cout << "Plastic Scintillator type: " << Scintillator << G4endl; + } + + else if (DataBuffer.compare(0, 14, "LeadThickness=") == 0) { + check_LeadThickness = true; + ConfigFile >> DataBuffer ; + LeadThickness = atof(DataBuffer.c_str()) ; + LeadThickness = LeadThickness * mm; + G4cout << "Lead Thickness : " << LeadThickness/mm << G4endl; + } + + /////////////////////////////////////////////////// + // If no Detector Token and no comment, toggle out + else{ + ReadingStatus = false; + G4cout << "Wrong Token Sequence: Getting out " << DataBuffer << G4endl ; + } + + ///////////////////////////////////////////////// + // If All necessary information there, toggle out + + if (( check_Theta && check_Phi && check_R && check_Thickness + && check_Radius && check_LeadThickness && check_Scintillator + && check_Shape) // Cylindrical case + || + ( check_X && check_Y && check_Z && check_Thickness && check_Radius + && check_LeadThickness && check_Scintillator ) + || + ( check_Theta && check_Phi && check_R && check_Thickness + && check_Width && check_Height && check_LeadThickness + && check_Scintillator && check_Shape ) // Squared case + || + ( check_X && check_Y && check_Z && check_Thickness && check_Width + && check_Height && check_LeadThickness && check_Scintillator )) { + + if (check_X && check_Y && check_Z){ + R = sqrt (X*X+Y*Y+Z*Z); + Theta = acos(Z / (R) ); + Phi = atan2(Y,X); + } + + if (Shape == "Cylinder") + AddPlastic( R , + Theta , + Phi , + Thickness , + Radius , + Scintillator , + LeadThickness ); + + else if (Shape == "Square") + AddPlastic( R , + Theta , + Phi , + Height , + Width , + Thickness , + Scintillator , + LeadThickness ); + + // Reinitialisation of Check Boolean + + check_Theta = false ; + check_Phi = false ; + check_R = false ; + check_Thickness = false ; + check_Radius = false ; + check_LeadThickness = false ; + check_Scintillator = false ; + check_Height = false ; + check_Width = false ; + check_Shape = false ; + check_X = false ; + check_Y = false ; + check_Z = false ; + ReadingStatus = false ; + G4cout << "///"<< G4endl ; + } } - - if (Shape == "Cylinder") - AddPlastic( R , - Theta , - Phi , - Thickness , - Radius , - Scintillator , - LeadThickness ); - - else if (Shape == "Square") - AddPlastic( R , - Theta , - Phi , - Height , - Width , - Thickness , - Scintillator , - LeadThickness ); - - // Reinitialisation of Check Boolean - - check_Theta = false ; - check_Phi = false ; - check_R = false ; - check_Thickness = false ; - check_Radius = false ; - check_LeadThickness = false ; - check_Scintillator = false ; - check_Height = false ; - check_Width = false ; - check_Shape = false ; - check_X = false ; - check_Y = false ; - check_Z = false ; - ReadingStatus = false ; - G4cout << "///"<< G4endl ; - } } - } } // Construct detector and inialise sensitive part. // Called After DetecorConstruction::AddDetector Method void Plastic::ConstructDetector(G4LogicalVolume* world){ - G4ThreeVector Det_pos = G4ThreeVector(0, 0, 0) ; - - for (unsigned short i = 0 ; i < m_R.size() ; i++) { - G4double wX = m_R[i] * sin(m_Theta[i] ) * cos(m_Phi[i] ) ; - G4double wY = m_R[i] * sin(m_Theta[i] ) * sin(m_Phi[i] ) ; - G4double wZ = m_R[i] * cos(m_Theta[i] ) ; - Det_pos = G4ThreeVector(wX, wY, wZ) ; - VolumeMaker(Det_pos , i+1, world) ; - } - + G4ThreeVector Det_pos = G4ThreeVector(0, 0, 0) ; + + for (unsigned short i = 0 ; i < m_R.size() ; i++) { + G4double wX = m_R[i] * sin(m_Theta[i] ) * cos(m_Phi[i] ) ; + G4double wY = m_R[i] * sin(m_Theta[i] ) * sin(m_Phi[i] ) ; + G4double wZ = m_R[i] * cos(m_Theta[i] ) ; + Det_pos = G4ThreeVector(wX, wY, wZ) ; + VolumeMaker(Det_pos , i+1, world) ; + } + } void Plastic::VolumeMaker(G4ThreeVector Det_pos, int DetNumber, G4LogicalVolume* world){ - //////////////////////////////////////////////////////////////// - ////////////// Starting Volume Definition ////////////////////// - //////////////////////////////////////////////////////////////// - // Name of the module - std::ostringstream DetectorNumber ; - DetectorNumber << DetNumber ; - G4String Name = "Plastic" + DetectorNumber.str() ; - - int i = DetNumber-1; - - G4Material* PlasticMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(m_Scintillator[i]) ; - - // Definition of the volume containing the sensitive detector - - // Cylindrical Case - if(m_PlasticRadius[i]!=-1){ - if(m_PlasticThickness[i]>0 && m_PlasticRadius[i]>0){ - G4Tubs* solidPlastic = new G4Tubs( Name , - 0 , - m_PlasticRadius[i] , - m_PlasticThickness[i]/2 , - 0*deg , - 360*deg); - - G4LogicalVolume* logicPlastic = new G4LogicalVolume(solidPlastic, PlasticMaterial, Name+ "_Scintillator", 0, 0, 0); - logicPlastic->SetSensitiveDetector(m_PlasticScorer); - - G4VisAttributes* PlastVisAtt = new G4VisAttributes(G4Colour(0.0, 0.0, 0.9)) ; - logicPlastic->SetVisAttributes(PlastVisAtt) ; - - - - new G4PVPlacement(0 , - Det_pos , - logicPlastic , - Name + "_Scintillator" , - world , - false , - 0 ); + //////////////////////////////////////////////////////////////// + ////////////// Starting Volume Definition ////////////////////// + //////////////////////////////////////////////////////////////// + // Name of the module + std::ostringstream DetectorNumber ; + DetectorNumber << DetNumber ; + G4String Name = "Plastic" + DetectorNumber.str() ; + + int i = DetNumber-1; + + G4Material* PlasticMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(m_Scintillator[i]) ; + + // Definition of the volume containing the sensitive detector + + // Cylindrical Case + if(m_PlasticRadius[i]!=-1){ + if(m_PlasticThickness[i]>0 && m_PlasticRadius[i]>0){ + G4Tubs* solidPlastic = new G4Tubs( Name , + 0 , + m_PlasticRadius[i] , + m_PlasticThickness[i]/2 , + 0*deg , + 360*deg); + + G4LogicalVolume* logicPlastic = new G4LogicalVolume(solidPlastic, PlasticMaterial, Name+ "_Scintillator", 0, 0, 0); + logicPlastic->SetSensitiveDetector(m_PlasticScorer); + + G4VisAttributes* PlastVisAtt = new G4VisAttributes(G4Colour(0.0, 0.0, 0.9)) ; + logicPlastic->SetVisAttributes(PlastVisAtt) ; + + + + new G4PVPlacement(0 , + Det_pos , + logicPlastic , + Name + "_Scintillator" , + world , + false , + 0 ); + } + + + if(m_LeadThickness[i]>0&& m_PlasticRadius[i]>0){ + G4Tubs* solidLead = new G4Tubs(Name+"_Lead", + 0, + m_PlasticRadius[i], + m_LeadThickness[i]/2, + 0*deg, + 360*deg); + + G4Material* MaterialLead = MaterialManager::getInstance()->GetMaterialFromLibrary("Al"); + G4LogicalVolume* logicLead = new G4LogicalVolume(solidLead, MaterialLead, Name+"_Al", 0, 0, 0);//AC changed lead to Al + G4VisAttributes* LeadVisAtt = new G4VisAttributes(G4Colour(0.1, 0.1, 0.1)) ; + logicLead->SetVisAttributes(LeadVisAtt) ; + + G4PVPlacement( 0, + Det_pos+(m_PlasticThickness[i]/2+m_LeadThickness[i]/2)*Det_pos.unit(), + logicLead, + Name+"_Al", + world, + false, + 0); + } } - - - if(m_LeadThickness[i]>0&& m_PlasticRadius[i]>0){ - G4Tubs* solidLead = new G4Tubs(Name+"_Lead", - 0, - m_PlasticRadius[i], - m_LeadThickness[i]/2, - 0*deg, - 360*deg); - - G4Material* MaterialLead = MaterialManager::getInstance()->GetMaterialFromLibrary("Al"); - G4LogicalVolume* logicLead = new G4LogicalVolume(solidLead, MaterialLead, Name+"_Al", 0, 0, 0);//AC changed lead to Al - G4VisAttributes* LeadVisAtt = new G4VisAttributes(G4Colour(0.1, 0.1, 0.1)) ; - logicLead->SetVisAttributes(LeadVisAtt) ; - - G4PVPlacement( 0, - Det_pos+(m_PlasticThickness[i]/2+m_LeadThickness[i]/2)*Det_pos.unit(), - logicLead, - Name+"_Al", - world, - false, - 0); - } - } - - // Squared case - if(m_PlasticHeight[i]!=-1){ - if(m_PlasticThickness[i]>0 && m_PlasticHeight[i]>0 && m_PlasticWidth[i]>0){ - G4Box* solidPlastic = new G4Box(Name, 0.5*m_PlasticWidth[i], 0.5*m_PlasticHeight[i], 0.5*m_PlasticThickness[i]); - G4LogicalVolume* logicPlastic = new G4LogicalVolume(solidPlastic, PlasticMaterial, Name+ "_Scintillator", 0, 0, 0); - logicPlastic->SetSensitiveDetector(m_PlasticScorer); - - G4VisAttributes* PlastVisAtt = new G4VisAttributes(G4Colour(0, 0, 1)) ; - logicPlastic->SetVisAttributes(PlastVisAtt) ; - - G4RotationMatrix Rot3D; - Rot3D.set(0, 0, 0); - new G4PVPlacement( G4Transform3D(Rot3D,Det_pos), - logicPlastic, - Name + "_Scintillator" , - world, - false, - 0); + + // Squared case + if(m_PlasticHeight[i]!=-1){ + if(m_PlasticThickness[i]>0 && m_PlasticHeight[i]>0 && m_PlasticWidth[i]>0){ + G4Box* solidPlastic = new G4Box(Name, 0.5*m_PlasticWidth[i], 0.5*m_PlasticHeight[i], 0.5*m_PlasticThickness[i]); + G4LogicalVolume* logicPlastic = new G4LogicalVolume(solidPlastic, PlasticMaterial, Name+ "_Scintillator", 0, 0, 0); + logicPlastic->SetSensitiveDetector(m_PlasticScorer); + + G4VisAttributes* PlastVisAtt = new G4VisAttributes(G4Colour(0, 0, 1, 0.5)) ; + logicPlastic->SetVisAttributes(PlastVisAtt) ; + + G4RotationMatrix Rot3D; + Rot3D.set(0, 0, 0); + new G4PVPlacement( G4Transform3D(Rot3D,Det_pos), + logicPlastic, + Name + "_Scintillator" , + world, + false, + 0); + } + + if(m_LeadThickness[i]>0&& m_PlasticHeight[i]>0 && m_PlasticWidth[i]>0){ + G4Box* solidLead = new G4Box(Name+"_Al", 1*m_PlasticWidth[i], 1*m_PlasticHeight[i], 0.5*m_LeadThickness[i]); + + G4Material* MaterialLead = MaterialManager::getInstance()->GetMaterialFromLibrary("Al"); + G4LogicalVolume* logicLead = new G4LogicalVolume(solidLead, MaterialLead, Name+"_Al", 0, 0, 0); + G4VisAttributes* LeadVisAtt = new G4VisAttributes(G4Colour(0.5, 0.5, 0.5)) ; + logicLead->SetVisAttributes(LeadVisAtt) ; + + new G4PVPlacement(0, + Det_pos-(m_PlasticThickness[i]/2+m_LeadThickness[i]/2)*Det_pos.unit() -G4ThreeVector(0,0,1*cm) , + logicLead, + Name+"_Al", + world, + false, + 0); + } } - - if(m_LeadThickness[i]>0&& m_PlasticHeight[i]>0 && m_PlasticWidth[i]>0){ - G4Box* solidLead = new G4Box(Name+"_Al", 1*m_PlasticWidth[i], 1*m_PlasticHeight[i], 0.5*m_LeadThickness[i]); - - G4Material* MaterialLead = MaterialManager::getInstance()->GetMaterialFromLibrary("Al"); - G4LogicalVolume* logicLead = new G4LogicalVolume(solidLead, MaterialLead, Name+"_Al", 0, 0, 0); - G4VisAttributes* LeadVisAtt = new G4VisAttributes(G4Colour(0.5, 0.5, 0.5)) ; - logicLead->SetVisAttributes(LeadVisAtt) ; - - new G4PVPlacement(0, - Det_pos-(m_PlasticThickness[i]/2+m_LeadThickness[i]/2)*Det_pos.unit() -G4ThreeVector(0,0,1*cm) , - logicLead, - Name+"_Al", - world, - false, - 0); - } - } } // Add Detector branch to the EventTree. // Called After DetecorConstruction::AddDetector Method void Plastic::InitializeRootOutput(){ - RootOutput *pAnalysis = RootOutput::getInstance(); - TTree *pTree = pAnalysis->GetTree(); - pTree->Branch("Plastic", "TPlasticData", &m_Event) ; - pTree->SetBranchAddress("Plastic", &m_Event) ; + RootOutput *pAnalysis = RootOutput::getInstance(); + TTree *pTree = pAnalysis->GetTree(); + pTree->Branch("Plastic", "TPlasticData", &m_Event) ; + pTree->SetBranchAddress("Plastic", &m_Event) ; } // Read sensitive part and fill the Root tree. // Called at in the EventAction::EndOfEventAvtion void Plastic::ReadSensitive(const G4Event* event){ - G4String DetectorNumber; - m_Event->Clear(); - - ////////////////////////////////////////////////////////////////////////////////////// - //////////////////////// Used to Read Event Map of detector ////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// - - std::map<G4int, G4int*>::iterator DetectorNumber_itr; - std::map<G4int, G4double*>::iterator Energy_itr; - std::map<G4int, G4double*>::iterator Time_itr; - std::map<G4int, G4double*>::iterator Pos_Z_itr; - - G4THitsMap<G4int>* DetectorNumberHitMap; - G4THitsMap<G4double>* EnergyHitMap; - G4THitsMap<G4double>* TimeHitMap; - G4THitsMap<G4double>* PosZHitMap; - - ////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// - - // Read the Scorer associate to the Silicon Strip - - //Detector Number - G4int StripDetCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/PlasticNumber") ; - DetectorNumberHitMap = (G4THitsMap<G4int>*)(event->GetHCofThisEvent()->GetHC(StripDetCollectionID)) ; - DetectorNumber_itr = DetectorNumberHitMap->GetMap()->begin() ; - - //Energy - G4int StripEnergyCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/Energy") ; - EnergyHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(StripEnergyCollectionID)) ; - Energy_itr = EnergyHitMap->GetMap()->begin() ; - - //Time of Flight - G4int StripTimeCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/Time") ; - TimeHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(StripTimeCollectionID)) ; - Time_itr = TimeHitMap->GetMap()->begin() ; - - //Interaction Coordinate Z - G4int InterCoordZCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/InterCoordZ"); - PosZHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(InterCoordZCollectionID)); - Pos_Z_itr = PosZHitMap->GetMap()->begin(); - - G4int sizeN = DetectorNumberHitMap->entries() ; - G4int sizeE = EnergyHitMap->entries() ; - G4int sizeT = TimeHitMap->entries() ; - - // Loop on Plastic Number - for (G4int l = 0 ; l < sizeN ; l++) { - G4int N = *(DetectorNumber_itr->second) ; - G4int NTrackID = DetectorNumber_itr->first - N ; - - - if (N > 0) { - m_Event->SetPlasticNumber(N) ; - // Energy - Energy_itr = EnergyHitMap->GetMap()->begin(); - for (G4int h = 0 ; h < sizeE ; h++) { - G4int ETrackID = Energy_itr->first - N ; - G4double E = *(Energy_itr->second) ; - if (ETrackID == NTrackID) { - m_Event->SetEnergy(RandGauss::shoot(E, E*ResoEnergy/100./2.35)) ; - } - Energy_itr++; - } - - - // Time - Time_itr = TimeHitMap->GetMap()->begin(); - for (G4int h = 0 ; h < sizeT ; h++) { - G4int TTrackID = Time_itr->first - N ; - G4double T = *(Time_itr->second) ; - if (TTrackID == NTrackID) { - m_Event->SetTime(RandGauss::shoot(T, ResoTime)) ; - } - Time_itr++; - } - - // Pos Z - Pos_Z_itr = PosZHitMap->GetMap()->begin(); - for (G4int h = 0 ; h < PosZHitMap->entries() ; h++) { - G4int PosZTrackID = Pos_Z_itr->first - N ; - G4double PosZ = *(Pos_Z_itr->second) ; - if (PosZTrackID == NTrackID) { - ms_InterCoord->SetDetectedPositionZ(PosZ) ; + G4String DetectorNumber; + m_Event->Clear(); + + ////////////////////////////////////////////////////////////////////////////////////// + //////////////////////// Used to Read Event Map of detector ////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////// + + std::map<G4int, G4int*>::iterator DetectorNumber_itr; + std::map<G4int, G4double*>::iterator Energy_itr; + std::map<G4int, G4double*>::iterator Time_itr; + std::map<G4int, G4double*>::iterator Pos_X_itr; + std::map<G4int, G4double*>::iterator Pos_Y_itr; + std::map<G4int, G4double*>::iterator Pos_Z_itr; + std::map<G4int, G4double*>::iterator Angle_Theta_itr; + + G4THitsMap<G4int>* DetectorNumberHitMap; + G4THitsMap<G4double>* EnergyHitMap; + G4THitsMap<G4double>* TimeHitMap; + G4THitsMap<G4double>* PosXHitMap; + G4THitsMap<G4double>* PosYHitMap; + G4THitsMap<G4double>* PosZHitMap; + G4THitsMap<G4double>* AngleThetaHitMap; + + ////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////// + + // Read the Scorer associate to the Silicon Strip + + //Detector Number + G4int StripDetCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/PlasticNumber") ; + DetectorNumberHitMap = (G4THitsMap<G4int>*)(event->GetHCofThisEvent()->GetHC(StripDetCollectionID)) ; + DetectorNumber_itr = DetectorNumberHitMap->GetMap()->begin() ; + + //Energy + G4int StripEnergyCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/Energy") ; + EnergyHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(StripEnergyCollectionID)) ; + Energy_itr = EnergyHitMap->GetMap()->begin() ; + + //Time of Flight + G4int StripTimeCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/Time") ; + TimeHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(StripTimeCollectionID)) ; + Time_itr = TimeHitMap->GetMap()->begin() ; + + //Interaction Coordinate X + G4int InterCoordXCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/InterCoordX"); + PosXHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(InterCoordXCollectionID)); + Pos_X_itr = PosXHitMap->GetMap()->begin(); + + //Interaction Coordinate Y + G4int InterCoordYCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/InterCoordY"); + PosYHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(InterCoordYCollectionID)); + Pos_Y_itr = PosYHitMap->GetMap()->begin(); + + //Interaction Coordinate Z + G4int InterCoordZCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/InterCoordZ"); + PosZHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(InterCoordZCollectionID)); + Pos_Z_itr = PosZHitMap->GetMap()->begin(); + + //Interaction Coordinate Theta + G4int InterCoordThetaCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("PlasticScorer/InterCoordTheta"); + AngleThetaHitMap = (G4THitsMap<G4double>*)(event->GetHCofThisEvent()->GetHC(InterCoordThetaCollectionID)); + Angle_Theta_itr = AngleThetaHitMap->GetMap()->begin(); + + G4int sizeN = DetectorNumberHitMap->entries() ; + G4int sizeE = EnergyHitMap->entries() ; + G4int sizeT = TimeHitMap->entries() ; + + // Loop on Plastic Number + for (G4int l = 0 ; l < sizeN ; l++) { + G4int N = *(DetectorNumber_itr->second) ; + G4int NTrackID = DetectorNumber_itr->first - N ; + + + if (N > 0) { + m_Event->SetPlasticNumber(N) ; + // Energy + Energy_itr = EnergyHitMap->GetMap()->begin(); + for (G4int h = 0 ; h < sizeE ; h++) { + G4int ETrackID = Energy_itr->first - N ; + G4double E = *(Energy_itr->second) ; + if (ETrackID == NTrackID) { + m_Event->SetEnergy(RandGauss::shoot(E, E*ResoEnergy/100./2.35)) ; + } + Energy_itr++; + } + + + // Time + Time_itr = TimeHitMap->GetMap()->begin(); + for (G4int h = 0 ; h < sizeT ; h++) { + G4int TTrackID = Time_itr->first - N ; + G4double T = *(Time_itr->second) ; + if (TTrackID == NTrackID) { + m_Event->SetTime(RandGauss::shoot(T, ResoTime)) ; + } + Time_itr++; + } + + // Pos X + Pos_X_itr = PosXHitMap->GetMap()->begin(); + for (G4int h = 0 ; h < PosXHitMap->entries() ; h++) { + G4int PosXTrackID = Pos_X_itr->first - N ; + G4double PosX = *(Pos_X_itr->second) ; + if (PosXTrackID == NTrackID) { + ms_InterCoord->SetDetectedPositionX(PosX) ; + } + Pos_X_itr++; + } + + // Pos Y + Pos_Y_itr = PosYHitMap->GetMap()->begin(); + for (G4int h = 0 ; h < PosYHitMap->entries() ; h++) { + G4int PosYTrackID = Pos_Y_itr->first - N ; + G4double PosY = *(Pos_Y_itr->second) ; + if (PosYTrackID == NTrackID) { + ms_InterCoord->SetDetectedPositionY(PosY) ; + } + Pos_Y_itr++; + } + + // Pos Z + Pos_Z_itr = PosZHitMap->GetMap()->begin(); + for (G4int h = 0 ; h < PosZHitMap->entries() ; h++) { + G4int PosZTrackID = Pos_Z_itr->first - N ; + G4double PosZ = *(Pos_Z_itr->second) ; + if (PosZTrackID == NTrackID) { + ms_InterCoord->SetDetectedPositionZ(PosZ) ; + } + Pos_Z_itr++; + } + + // Angle Theta + Angle_Theta_itr = AngleThetaHitMap->GetMap()->begin(); + for (G4int h = 0 ; h < AngleThetaHitMap->entries() ; h++) { + G4int AngleThetaTrackID = Angle_Theta_itr->first - N ; + G4double Theta = *(Angle_Theta_itr->second) ; + if (AngleThetaTrackID == NTrackID) { + ms_InterCoord->SetDetectedAngleTheta(Theta) ; + } + Angle_Theta_itr++; + } + } - Pos_Z_itr++; - } + + DetectorNumber_itr++; } - - DetectorNumber_itr++; - } - - // clear map for next event - TimeHitMap ->clear() ; - DetectorNumberHitMap ->clear() ; - EnergyHitMap ->clear() ; - PosZHitMap ->clear() ; - + + // clear map for next event + TimeHitMap->clear() ; + DetectorNumberHitMap->clear() ; + EnergyHitMap->clear() ; + PosXHitMap->clear() ; + PosYHitMap->clear() ; + PosZHitMap->clear() ; + AngleThetaHitMap->clear(); + } //////////////////////////////////////////////////////////////// void Plastic::InitializeScorers() { - bool already_exist = false; - m_PlasticScorer = CheckScorer("PlasticScorer",already_exist) ; - - if(already_exist) return ; - - G4VPrimitiveScorer* DetNbr = new PSDetectorNumber("PlasticNumber","Plastic", 0) ; - G4VPrimitiveScorer* Energy = new PSEnergy("Energy","Plastic", 0) ; - G4VPrimitiveScorer* Time = new PSTOF("Time","Plastic", 0) ; - G4VPrimitiveScorer* InteractionCoordinatesZ = new OBSOLETEGENERALSCORERS::PSInteractionCoordinatesZ("InterCoordZ","Plastic", 0); - //and register it to the multifunctionnal detector - m_PlasticScorer->RegisterPrimitive(DetNbr) ; - m_PlasticScorer->RegisterPrimitive(Energy) ; - m_PlasticScorer->RegisterPrimitive(Time) ; - m_PlasticScorer->RegisterPrimitive(InteractionCoordinatesZ); - G4SDManager::GetSDMpointer()->AddNewDetector(m_PlasticScorer) ; - + bool already_exist = false; + m_PlasticScorer = CheckScorer("PlasticScorer",already_exist) ; + + if(already_exist) return ; + + G4VPrimitiveScorer* DetNbr = new PSDetectorNumber("PlasticNumber","Plastic", 0) ; + G4VPrimitiveScorer* Energy = new PSEnergy("Energy","Plastic", 0) ; + G4VPrimitiveScorer* Time = new PSTOF("Time","Plastic", 0) ; + G4VPrimitiveScorer* InteractionCoordinatesX = new OBSOLETEGENERALSCORERS::PSInteractionCoordinatesX("InterCoordX","Plastic", 0); + G4VPrimitiveScorer* InteractionCoordinatesY = new OBSOLETEGENERALSCORERS::PSInteractionCoordinatesY("InterCoordY","Plastic", 0); + G4VPrimitiveScorer* InteractionCoordinatesZ = new OBSOLETEGENERALSCORERS::PSInteractionCoordinatesZ("InterCoordZ","Plastic", 0); + G4VPrimitiveScorer* InteractionCoordinatesTheta = new OBSOLETEGENERALSCORERS::PSInteractionCoordinatesAngleTheta("InterCoordTheta","Plastic", 0); + //and register it to the multifunctionnal detector + m_PlasticScorer->RegisterPrimitive(DetNbr) ; + m_PlasticScorer->RegisterPrimitive(Energy) ; + m_PlasticScorer->RegisterPrimitive(Time) ; + m_PlasticScorer->RegisterPrimitive(InteractionCoordinatesX); + m_PlasticScorer->RegisterPrimitive(InteractionCoordinatesY); + m_PlasticScorer->RegisterPrimitive(InteractionCoordinatesZ); + m_PlasticScorer->RegisterPrimitive(InteractionCoordinatesTheta); + G4SDManager::GetSDMpointer()->AddNewDetector(m_PlasticScorer) ; + } //////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// - // Construct Method to be pass to the DetectorFactory // - //////////////////////////////////////////////////////////////////////////////// - NPS::VDetector* Plastic::Construct(){ - return (NPS::VDetector*) new Plastic(); - } - - //////////////////////////////////////////////////////////////////////////////// - // Registering the construct method to the factory // - //////////////////////////////////////////////////////////////////////////////// - extern"C" { - class proxy_nps_plastic{ - public: - proxy_nps_plastic(){ - NPS::DetectorFactory::getInstance()->AddToken("Plastic","Plastic"); - NPS::DetectorFactory::getInstance()->AddDetector("Plastic",Plastic::Construct); - } -}; +//////////////////////////////////////////////////////////////////////////////// +// Construct Method to be pass to the DetectorFactory // +//////////////////////////////////////////////////////////////////////////////// +NPS::VDetector* Plastic::Construct(){ + return (NPS::VDetector*) new Plastic(); +} - proxy_nps_plastic p_nps_plastic; - } +//////////////////////////////////////////////////////////////////////////////// +// Registering the construct method to the factory // +//////////////////////////////////////////////////////////////////////////////// +extern"C" { + class proxy_nps_plastic{ + public: + proxy_nps_plastic(){ + NPS::DetectorFactory::getInstance()->AddToken("Plastic","Plastic"); + NPS::DetectorFactory::getInstance()->AddDetector("Plastic",Plastic::Construct); + } + }; + + proxy_nps_plastic p_nps_plastic; +} diff --git a/NPSimulation/PhysicsListOption.txt b/NPSimulation/PhysicsListOption.txt index 6e6fc7c040fc7fe15a6a81a2c6400d52d2ec1711..c46048762e6d5ec62e8256a618bb58b75807f4d3 100644 --- a/NPSimulation/PhysicsListOption.txt +++ b/NPSimulation/PhysicsListOption.txt @@ -1,10 +1,11 @@ EmPhysicsList Option4 DefaultCutOff 1 -IonBinaryCascadePhysics 0 -EmExtraPhysics 0 -HadronElasticPhysics 0 +IonBinaryCascadePhysics 1 +LocalIonInelasticPhysics 0 +EmExtraPhysics 0 +HadronElasticPhysics 1 StoppingPhysics 0 OpticalPhysics 0 -HadronPhysicsQGSP_BIC_HP 0 -Decay 0 - +HadronPhysicsINCLXX 0 +HadronPhysicsQGSP_BIC_HP 1 +Decay 1 diff --git a/NPSimulation/Simulation.cc b/NPSimulation/Simulation.cc index 73be2c1f2f9f489627ffce8181f7c892fac17a3a..b38ca713cf9bb182ccdebb74e1d790a842e625e2 100644 --- a/NPSimulation/Simulation.cc +++ b/NPSimulation/Simulation.cc @@ -34,129 +34,129 @@ #include "RootOutput.h" int main(int argc, char** argv){ - // Initialize NPOptionManager object - NPOptionManager* OptionManager = NPOptionManager::getInstance(argc, argv); - if(OptionManager->GetVerboseLevel() > 0){ - string line; - line.resize(80,'*'); - cout << endl << line << endl; - cout << "******************************** NPSimulation ********************************"<< endl; - cout << line << endl; - cout << "NPSimulation version: npsimulation-"<< NPS::version_major <<"-" << NPS::version_minor << "-" << NPS::version_dets <<endl; - cout << " Copyright: NPTool Collaboration "<<endl; - cout << " GitHub: http://github.com/adrien-matta/nptool"<<endl; ; - cout << line << endl; - } - - // Test if input files are found. If not, exit - if (OptionManager->IsDefault("EventGenerator")) - OptionManager->SendErrorAndExit("EventGenerator"); - if (OptionManager->IsDefault("DetectorConfiguration")) - OptionManager->SendErrorAndExit("DetectorConfiguration"); - // case when input files are here - G4String EventGeneratorFileName = OptionManager->GetReactionFile(); - G4String DetectorFileName = OptionManager->GetDetectorFile(); - // my Verbose output class - G4VSteppingVerbose::SetInstance(new SteppingVerbose); - - /////////////////////////////////////////////////////////////// - ///////////////// Initializing the Root Output //////////////// - /////////////////////////////////////////////////////////////// - RootOutput::getInstance("Simulation/" + OptionManager->GetOutputFile()); - - // Construct the default run manager - G4RunManager* runManager = new G4RunManager; - - // set mandatory initialization classes - DetectorConstruction* detector = new DetectorConstruction(); - runManager->SetUserInitialization(detector); - - PhysicsList* physicsList = new PhysicsList(); - runManager->SetUserInitialization(physicsList); - PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(detector); - - // Initialize Geant4 kernel - runManager->Initialize(); - - /////////////////////////////////////////////////////////////// - /////////// Define UI terminal for interactive mode /////////// - /////////////////////////////////////////////////////////////// - // interactive mode : define UI session - // Get the pointer to the User Interface manager - G4cout << "//////////// Starting UI ////////////"<< endl; - G4UImanager* UImanager = G4UImanager::GetUIpointer(); + // Initialize NPOptionManager object + NPOptionManager* OptionManager = NPOptionManager::getInstance(argc, argv); + if(OptionManager->GetVerboseLevel() > 0){ + string line; + line.resize(80,'*'); + cout << endl << line << endl; + cout << "******************************** NPSimulation ********************************"<< endl; + cout << line << endl; + cout << "NPSimulation version: npsimulation-"<< NPS::version_major <<"-" << NPS::version_minor << "-" << NPS::version_dets <<endl; + cout << " Copyright: NPTool Collaboration "<<endl; + cout << " GitHub: http://github.com/adrien-matta/nptool"<<endl; ; + cout << line << endl; + } + + // Test if input files are found. If not, exit + if (OptionManager->IsDefault("EventGenerator")) + OptionManager->SendErrorAndExit("EventGenerator"); + if (OptionManager->IsDefault("DetectorConfiguration")) + OptionManager->SendErrorAndExit("DetectorConfiguration"); + // case when input files are here + G4String EventGeneratorFileName = OptionManager->GetReactionFile(); + G4String DetectorFileName = OptionManager->GetDetectorFile(); + // my Verbose output class + G4VSteppingVerbose::SetInstance(new SteppingVerbose); + + /////////////////////////////////////////////////////////////// + ///////////////// Initializing the Root Output //////////////// + /////////////////////////////////////////////////////////////// + RootOutput::getInstance("Simulation/" + OptionManager->GetOutputFile()); + + // Construct the default run manager + G4RunManager* runManager = new G4RunManager; + + // set mandatory initialization classes + DetectorConstruction* detector = new DetectorConstruction(); + runManager->SetUserInitialization(detector); + + PhysicsList* physicsList = new PhysicsList(); + runManager->SetUserInitialization(physicsList); + PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(detector); + + // Initialize Geant4 kernel + runManager->Initialize(); + + /////////////////////////////////////////////////////////////// + /////////// Define UI terminal for interactive mode /////////// + /////////////////////////////////////////////////////////////// + // interactive mode : define UI session + // Get the pointer to the User Interface manager + G4cout << "//////////// Starting UI ////////////"<< endl; + G4UImanager* UImanager = G4UImanager::GetUIpointer(); #ifdef G4UI_USE - G4UIExecutive* ui = new G4UIExecutive(argc, argv); -#endif - - - /////////////////////////////////////////////////////////////// - ////////////////////// Reading Reaction /////////////////////// - /////////////////////////////////////////////////////////////// - primary->ReadEventGeneratorFile(EventGeneratorFileName); - runManager->SetUserAction(primary); - - /////////////////////////////////////////////////////////////// - ////////////////// Starting the Event Action ////////////////// - /////////////////////////////////////////////////////////////// - EventAction* event_action = new EventAction() ; - event_action->SetDetector(detector) ; - runManager->SetUserAction(event_action) ; - - /////////////////////////////////////////////////////////////// - /////////////////// Starting the Run Action /////////////////// - /////////////////////////////////////////////////////////////// - RunAction* run_action = new RunAction() ; - runManager->SetUserAction(run_action); - - G4VisManager* visManager=NULL; - if(!OptionManager->GetG4BatchMode()){ + G4UIExecutive* ui = new G4UIExecutive(argc, argv); +#endif + + + /////////////////////////////////////////////////////////////// + ////////////////////// Reading Reaction /////////////////////// + /////////////////////////////////////////////////////////////// + primary->ReadEventGeneratorFile(EventGeneratorFileName); + runManager->SetUserAction(primary); + + /////////////////////////////////////////////////////////////// + ////////////////// Starting the Event Action ////////////////// + /////////////////////////////////////////////////////////////// + EventAction* event_action = new EventAction() ; + event_action->SetDetector(detector) ; + runManager->SetUserAction(event_action) ; + + /////////////////////////////////////////////////////////////// + /////////////////// Starting the Run Action /////////////////// + /////////////////////////////////////////////////////////////// + RunAction* run_action = new RunAction() ; + runManager->SetUserAction(run_action); + + G4VisManager* visManager=NULL; + if(!OptionManager->GetG4BatchMode()){ #ifdef G4UI_USE #ifdef G4VIS_USE - string Path_Macro = getenv("NPTOOL"); - Path_Macro+="/NPSimulation/ressources/macro/"; - - UImanager->ApplyCommand("/control/execute " +Path_Macro+"aliases.mac"); - visManager = new G4VisExecutive("Quiet"); - visManager->Initialize(); - UImanager->ApplyCommand("/control/execute " +Path_Macro+"vis.mac"); + string Path_Macro = getenv("NPTOOL"); + Path_Macro+="/NPSimulation/ressources/macro/"; + + UImanager->ApplyCommand("/control/execute " +Path_Macro+"aliases.mac"); + visManager = new G4VisExecutive("Quiet"); + visManager->Initialize(); + UImanager->ApplyCommand("/control/execute " +Path_Macro+"vis.mac"); #endif - if (ui->IsGUI()){ - UImanager->ApplyCommand("/control/execute " +Path_Macro+"gui.mac"); - } + if (ui->IsGUI()){ + UImanager->ApplyCommand("/control/execute " +Path_Macro+"gui.mac"); + } #ifdef __APPLE__ - string command= "osascript "; - command+= getenv("NPTOOL"); - command+="/NPSimulation/ressources/scripts/bringtofront.osa & "; - int res =system(command.c_str()); - res =0; - + string command= "osascript "; + command+= getenv("NPTOOL"); + command+="/NPSimulation/ressources/scripts/bringtofront.osa & "; + int res =system(command.c_str()); + res =0; + #endif - } - // Execute user macro - if(!OptionManager->IsDefault("G4MacroPath")){ - UImanager->ApplyCommand("/control/execute "+ OptionManager->GetG4MacroPath()); - } - - // Start the session - if(!OptionManager->GetG4BatchMode()) - ui->SessionStart(); - - - delete ui; + } + // Execute user macro + if(!OptionManager->IsDefault("G4MacroPath")){ + UImanager->ApplyCommand("/control/execute "+ OptionManager->GetG4MacroPath()); + } + + // Start the session + if(!OptionManager->GetG4BatchMode()) + ui->SessionStart(); + + + delete ui; #endif - + #ifdef G4VIS_USE - if(visManager) - delete visManager; + if(visManager) + delete visManager; #endif - - /////////////////////////////////////////////////////////////// - ////////////////////// Job termination //////////////////////// - /////////////////////////////////////////////////////////////// - // delete primary; delete detector; - - delete runManager; - RootOutput::getInstance()->Destroy(); - return 0; -} + + /////////////////////////////////////////////////////////////// + ////////////////////// Job termination //////////////////////// + /////////////////////////////////////////////////////////////// + // delete primary; delete detector; + + delete runManager; + RootOutput::getInstance()->Destroy(); + return 0; +} \ No newline at end of file diff --git a/Projects/Lassa/RunToTreat.txt b/Projects/Lassa/RunToTreat.txt index e545ef4ec8d9268641db50481b41aeec7661d575..c4b7fade4518970db303e581ea74c25badfd331f 100755 --- a/Projects/Lassa/RunToTreat.txt +++ b/Projects/Lassa/RunToTreat.txt @@ -2,6 +2,6 @@ TTreeName SimulatedTree RootFileName %../../Outputs/Simulation/e09042_3Hesource_nucl.root - ../../Outputs/Simulation/one_lassa_proton_nucl.root + ../../Outputs/Simulation/e09042_protonsource_HadElas.root %../../Outputs/Simulation/test.root