Commit 3574b6be authored by adrien-matta's avatar adrien-matta
Browse files

* Working nptool-wizard

parent ced06fa4
......@@ -7,7 +7,7 @@ Isotropic
EnergyLow= 5.2
EnergyHigh= 5.2
HalfOpenAngleMin= 0
HalfOpenAngleMax= 20
HalfOpenAngleMax= 180
x0= 0
y0= -8
z0= 0
......
......@@ -7,13 +7,13 @@
// NPTool header
#include "NPVDetector.h"
int main(int argc , char** argv)
{
int main(int argc , char** argv){
// Find the different paths
std::string path = getenv("NPTOOL");
std::string pathNPL = path + "/NPLib/Detectors/";
std::string pathNPS = path + "/NPSimulation/";
std::string pathNPS = path + "/NPSimulation/Detectors/";
std::string pathInputs = path + "/Inputs/DetectorConfiguration/";
std::string pwd = getenv("PWD");
int return_value = -1 ;
......@@ -29,28 +29,52 @@ int main(int argc , char** argv)
switch(now->tm_mon + 1){
case 1:
month = "January";
break;
case 2:
month = "February";
break;
case 3:
month = "March";
break;
case 4:
month = "April";
break;
case 5:
month = "May";
break;
case 6:
month = "June";
break;
case 7:
month = "July";
break;
case 8:
month = "August";
break;
case 9:
month = "September";
break;
case 10:
month = "October";
break;
case 11:
month = "November";
break;
case 12:
month = "December";
break;
}
std::string year = NPL::itoa(now->tm_year+1900);
......@@ -99,24 +123,24 @@ int main(int argc , char** argv)
return_value = system(command.c_str());
// Edit npl file
command = "sed -i '' -e \"s/DETECTORNAME/"+ answer +"/g\" "
+ pathNPL + answer +"/* > /dev/null 2> /dev/null";
command = "sed -i '' -e \"s/DETECTORNAME/"+ answer +"/g\" "
+ pathNPL + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/XAUTHORX/"+ author+"/g\" "
+ pathNPL + answer +"/* > /dev/null 2> /dev/null";
+ pathNPL + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/XMAILX/"+ email+"/g\" "
+ pathNPL + answer +"/* > /dev/null 2> /dev/null";
+ pathNPL + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/XYEARX/"+ year +" /g\" "
+ pathNPL + answer +"/* > /dev/null 2> /dev/null";
+ pathNPL + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/XMONTHX/"+ month +"/g\" "
+ pathNPL + answer +"/* > /dev/null 2> /dev/null";
+ pathNPL + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
// change files name
......@@ -143,12 +167,55 @@ int main(int argc , char** argv)
// Create nps folder
command = "mkdir " + pathNPS + "/Detectors/" + answer + " > /dev/null 2> /dev/null";
command = "mkdir " + pathNPS + answer + " > /dev/null 2> /dev/null";
return_value = system(command.c_str());
// Add nps file
command = "cp " + pathNPL + "../ressources/DetectorSkeleton/NPSimulation/*.* "
+ pathNPS + answer +"/ > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/DETECTORNAME/"+ answer +"/g\" "
+ pathNPS + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/XAUTHORX/"+ author+"/g\" "
+ pathNPS + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/XMAILX/"+ email+"/g\" "
+ pathNPS + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/XYEARX/"+ year +" /g\" "
+ pathNPS + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/XMONTHX/"+ month +"/g\" "
+ pathNPS + answer +"/*.* > /dev/null 2> /dev/null";
return_value = system(command.c_str());
// change files name
command = "mv " + pathNPS + answer +"/DETECTORNAME.hh "
+ pathNPS + answer + "/" + SimFile_h ;
return_value = system(command.c_str());
command = "mv " + pathNPS + answer +"/DETECTORNAME.cc "
+ pathNPS + answer + "/" + SimFile_cxx ;
return_value = system(command.c_str());
// Add input file
command = "cp " + pathNPL + "../ressources/DetectorSkeleton/Inputs/*.* "
+ pathInputs +" > /dev/null 2> /dev/null";
return_value = system(command.c_str());
command = "sed -i '' -e \"s/DETECTORNAME/"+ answer +"/g\" "
+ pathInputs + "DETECTORNAME.detector > /dev/null 2> /dev/null";
return_value = system(command.c_str());
// change files name
command = "mv " + pathInputs +"DETECTORNAME.detector "
+ pathInputs + answer + ".detector" ;
return_value = system(command.c_str());
// Provide a list of created file
std::cout << "\t List of created files to\033[1;35m edit \033[0m:" << std::endl;
......
......@@ -14,10 +14,18 @@ DETECTORNAME
X= 0
Y= 0
Z= 350
Thickness= 30
Shape= Square
Height= 70
Width= 40
Scintillator= BC400
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DETECTORNAME
X= 350
Y= 350
Z= 350
Shape= Square
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DETECTORNAME
R= 350
THETA= 90
PHI= 63
Shape= Cylindrical
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -52,13 +52,14 @@ using namespace CLHEP;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
namespace DETECTORNAME{
namespace DETECTORNAME_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 = 5*mm ;
const double Width = 10*mm ;
const double Thickness = 30*mm ;
const double Radius = 50*mm ;
const double Width = 100*mm ;
const double Thickness = 300*mm ;
const string Scintillator = "BC400";
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -72,9 +73,9 @@ DETECTORNAME::DETECTORNAME(){
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));
// RGB Color + Transparency
m_VisSquare = new G4VisAttributes(G4Colour(0, 1, 0, 0.5));
m_VisCylinder = new G4VisAttributes(G4Colour(0, 0, 1, 0.5));
}
......@@ -92,13 +93,31 @@ void DETECTORNAME::AddDETECTORNAME(double R, double Theta, double Phi, string
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4LogicalVolume* DETECTORNAME::BuildSquareDetector(){
if(!m_SquareDetector){
G4Box* box = new G4Box("DETECTORNAME_Box",DETECTORNAME::Width*0.5,
DETECTORNAME::Width*0.5,DETECTORNAME::Thickness*0.5)
m_SquareDetector = new G4LogicalVolume(box,m_Scintillator,"logic_DETECTORNAME_Box",0,0,0);
logicPADDetector->SetVisAttributes(m_VisSquare);
G4Box* box = new G4Box("DETECTORNAME_Box",DETECTORNAME_NS::Width*0.5,
DETECTORNAME_NS::Width*0.5,DETECTORNAME_NS::Thickness*0.5);
G4Material* ScintMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(DETECTORNAME_NS::Scintillator);
m_SquareDetector = new G4LogicalVolume(box,ScintMaterial,"logic_DETECTORNAME_Box",0,0,0);
m_SquareDetector->SetVisAttributes(m_VisSquare);
m_SquareDetector->SetSensitiveDetector(m_DETECTORNAMEScorer);
}
return m_SquareDetector;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4LogicalVolume* DETECTORNAME::BuildCylindricalDetector(){
if(!m_CylindricalDetector){
G4Tubs* tub = new G4Tubs("DETECTORNAME_Cyl",0,DETECTORNAME_NS::Radius,DETECTORNAME_NS::Thickness*0.5,0,360*deg);
G4Material* ScintMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(DETECTORNAME_NS::Scintillator);
m_CylindricalDetector = new G4LogicalVolume(tub,ScintMaterial,"logic_DETECTORNAME_tub",0,0,0);
m_CylindricalDetector->SetVisAttributes(m_VisSquare);
m_CylindricalDetector->SetSensitiveDetector(m_DETECTORNAMEScorer);
}
return m_CylindricalDetector;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -114,7 +133,7 @@ void DETECTORNAME::ReadConfiguration(string Path){
double Theta = 0 , Phi = 0 , R = 0 ;
double X = 0 , Y = 0 , Z = 0 ;
string , Shape ;
string Shape ;
bool check_Theta = false ;
bool check_Phi = false ;
......@@ -238,7 +257,7 @@ void DETECTORNAME::ReadConfiguration(string Path){
Phi = atan2(Y,X);
}
AddDETECTORNAME(R,Theta,Phi,Shape);
AddDETECTORNAME(R,Theta,Phi,Shape);
// Reinitialisation of Check Boolean
check_Theta = false ;
......@@ -259,21 +278,37 @@ void DETECTORNAME::ReadConfiguration(string Path){
// Construct detector and inialise sensitive part.
// Called After DetecorConstruction::AddDetector Method
void DETECTORNAME::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) ;
if(m_Shape == "Cylndrical"){
new G4PVPlacement(new G4RotationMatrix(),Det_pos,BuildCylindricalDetector(),
"DETECTORNAME_"+NPL::itoa(i+1),world,false,i+1);
G4ThreeVector Det_pos = G4ThreeVector(wX, wY, wZ) ;
// So the face of the detector is at R instead of the middle
Det_pos+=Det_pos.unit()*DETECTORNAME_NS::Thickness*0.5;
// Building Detector reference frame
G4double ii = cos(m_Theta[i]) * cos(m_Phi[i]);
G4double jj = cos(m_Theta[i]) * sin(m_Phi[i]);
G4double kk = -sin(m_Theta[i]);
G4ThreeVector Y(ii,jj,kk);
G4ThreeVector w = Det_pos.unit();
G4ThreeVector u = w.cross(Y);
G4ThreeVector v = w.cross(u);
v = v.unit();
u = u.unit();
G4RotationMatrix* Rot = new G4RotationMatrix(u,v,w);
if(m_Shape[i] == "Cylindrical"){
new G4PVPlacement(G4Transform3D(*Rot,Det_pos),
BuildCylindricalDetector(),
"DETECTORNAME",world,false,i+1);
}
else if(m_Shape == "Square"){
new G4PVPlacement(new G4RotationMatrix(),Det_pos,BuildSquareDetector(),
"DETECTORNAME_"+NPL::itoa(i+1),world,false,i+1);
else if(m_Shape[i] == "Square"){
new G4PVPlacement(G4Transform3D(*Rot,Det_pos),
BuildSquareDetector(),
"DETECTORNAME",world,false,i+1);
}
}
}
......@@ -292,6 +327,31 @@ void DETECTORNAME::InitializeRootOutput(){
// Called at in the EventAction::EndOfEventAvtion
void DETECTORNAME::ReadSensitive(const G4Event* event){
m_Event->Clear();
///////////
// Calorimeter scorer
G4THitsMap<G4double*>* CaloHitMap;
std::map<G4int, G4double**>::iterator Calo_itr;
G4int CaloCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("DETECTORNAMEScorer/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],DETECTORNAME_NS::ResoEnergy);
if(Energy>DETECTORNAME_NS::EnergyThreshold){
double Time = RandGauss::shoot(Info[1],DETECTORNAME_NS::ResoTime);
int DetectorNbr = (int) Info[2];
m_Event->SetEnergy(DetectorNbr,Energy);
m_Event->SetTime(DetectorNbr,Time);
}
}
// clear map for next event
CaloHitMap->clear();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
......@@ -306,7 +366,7 @@ void DETECTORNAME::InitializeScorers() {
// Otherwise the scorer is initialised
vector<int> level; level.push_back(0);
G4VPrimitiveScorer* Calorimeter= new PSCalorimeter("Calorimeter",level, 0) ;
G4VPrimitiveScorer* Calorimeter= new CALORIMETERSCORERS::PS_Calorimeter("Calorimeter",level, 0) ;
//and register it to the multifunctionnal detector
m_DETECTORNAMEScorer->RegisterPrimitive(Calorimeter);
G4SDManager::GetSDMpointer()->AddNewDetector(m_DETECTORNAMEScorer) ;
......
......@@ -36,8 +36,7 @@ using namespace std;
#include "NPSVDetector.hh"
#include "TDETECTORNAMEData.h"
class DETECTORNAME : public NPS::VDetector
{
class DETECTORNAME : public NPS::VDetector{
////////////////////////////////////////////////////
/////// Default Constructor and Destructor /////////
////////////////////////////////////////////////////
......@@ -57,9 +56,10 @@ class DETECTORNAME : public NPS::VDetector
G4LogicalVolume* BuildSquareDetector();
G4LogicalVolume* BuildCylindricalDetector();
private:
G4LogicalVolume* m_SquareDetector();
G4LogicalVolume* m_CylindricalDetector();
G4LogicalVolume* m_SquareDetector;
G4LogicalVolume* m_CylindricalDetector;
////////////////////////////////////////////////////
////// Inherite from NPS::VDetector class /////////
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment