Commit 74bf5885 authored by Adrien Matta's avatar Adrien Matta
Browse files

* Updating detector skeleton to use new input parser

        - also made some change to get a more functionnal detector
parent 5012526f
......@@ -34,6 +34,7 @@ using namespace std;
#include "RootInput.h"
#include "RootOutput.h"
#include "NPDetectorFactory.h"
#include "NPOptionManager.h"
// ROOT
#include "TChain.h"
......@@ -52,8 +53,23 @@ TDETECTORNAMEPhysics::TDETECTORNAMEPhysics()
m_NumberOfDetectors(0) {
}
///////////////////////////////////////////////////////////////////////////
/// A usefull method to bundle all operation to add a detector
void TDETECTORNAMEPhysics::AddDetector(TVector3 , string ){
// In That simple case nothing is done
// Typically for more complex detector one would calculate the relevant
// positions (stripped silicon) or angles (gamma array)
m_NumberOfDetectors++;
}
///////////////////////////////////////////////////////////////////////////
void TDETECTORNAMEPhysics::AddDetector(double R, double Theta, double Phi, string shape){
// Compute the TVector3 corresponding
TVector3 Pos(R*sin(Theta)*cos(Phi),R*sin(Theta)*sin(Phi),R*cos(Theta));
// Call the cartesian method
AddDetector(Pos,shape);
}
///////////////////////////////////////////////////////////////////////////
void TDETECTORNAMEPhysics::BuildSimplePhysicalEvent() {
BuildPhysicalEvent();
......@@ -186,125 +202,39 @@ void TDETECTORNAMEPhysics::Clear() {
///////////////////////////////////////////////////////////////////////////
void TDETECTORNAMEPhysics::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_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 DETECTORNAME bloc, Reading toggle to true
string name="DETECTORNAME";
if (LineBuffer.compare(0, name.length(), name) == 0){
cout << "///" << endl ;
cout << "DETECTORNAME found: " << endl ;
ReadingStatus = true ;
void TDETECTORNAMEPhysics::ReadConfiguration(NPL::InputParser parser) {
vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("DETECTORNAME");
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << "//// " << blocks.size() << " detectors found " << endl;
vector<string> cart = {"POS","Shape"};
vector<string> sphe = {"R","Theta","Phi","Shape"};
for(unsigned int i = 0 ; i < blocks.size() ; i++){
if(blocks[i]->HasTokenList(cart)){
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << endl << "//// DETECTORNAME " << i+1 << endl;
TVector3 Pos = blocks[i]->GetTVector3("POS","mm");
string Shape = blocks[i]->GetString("Shape");
AddDetector(Pos,Shape);
}
// 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) {
cout << "\033[1;311mWARNING: Another detector is find before standard sequence of Token, Error may occured in detector definition\033[0m" << 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;
}
///////////////////////////////////////////////////
// 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_X && check_Y && check_Z) ) && check_Shape ){
m_NumberOfDetectors++;
// Reinitialisation of Check Boolean
check_Theta = false ;
check_Phi = false ;
check_R = false ;
check_Shape = false ;
check_X = false ;
check_Y = false ;
check_Z = false ;
ReadingStatus = false ;
cout << "///"<< endl ;
}
else if(blocks[i]->HasTokenList(sphe)){
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << endl << "//// DETECTORNAME " << i+1 << endl;
double R = blocks[i]->GetDouble("R","mm");
double Theta = blocks[i]->GetDouble("Theta","deg");
double Phi = blocks[i]->GetDouble("Phi","deg");
string Shape = blocks[i]->GetString("Shape");
AddDetector(R,Theta,Phi,Shape);
}
else{
cout << "ERROR: check your input file formatting " << endl;
exit(1);
}
}
}
///////////////////////////////////////////////////////////////////////////
void TDETECTORNAMEPhysics::InitSpectra() {
m_Spectra = new TDETECTORNAMESpectra(m_NumberOfDetectors);
......
......@@ -32,13 +32,13 @@ using namespace std;
#include "TObject.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TVector3.h"
// NPTool headers
#include "TDETECTORNAMEData.h"
#include "TDETECTORNAMESpectra.h"
#include "NPCalibrationManager.h"
#include "NPVDetector.h"
#include "NPInputParser.h"
// forward declaration
class TDETECTORNAMESpectra;
......@@ -67,12 +67,15 @@ class TDETECTORNAMEPhysics : public TObject, public NPL::VDetector {
vector<double> Energy;
vector<double> Time;
/// A usefull method to bundle all operation to add a detector
void AddDetector(TVector3 POS, string shape);
void AddDetector(double R, double Theta, double Phi, string shape);
//////////////////////////////////////////////////////////////
// methods inherited from the VDetector ABC class
public:
// read stream from ConfigFile to pick-up detector parameters
void ReadConfiguration(string);
void ReadConfiguration(NPL::InputParser);
// add parameters to the CalibrationManger
void AddParameterToCalibrationManager();
......
......@@ -44,6 +44,7 @@
#include "RootOutput.h"
#include "MaterialManager.hh"
#include "NPSDetectorFactory.hh"
#include "NPOptionManager.h"
// CLHEP header
#include "CLHEP/Random/RandGauss.h"
......@@ -81,9 +82,18 @@ DETECTORNAME::DETECTORNAME(){
DETECTORNAME::~DETECTORNAME(){
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DETECTORNAME::AddDetector(G4ThreeVector POS, string Shape){
// Convert the POS value to R theta Phi as Spherical coordinate is easier in G4
m_R.push_back(POS.mag());
m_Theta.push_back(POS.theta());
m_Phi.push_back(POS.phi());
m_Shape.push_back(Shape);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DETECTORNAME::AddDETECTORNAME(double R, double Theta, double Phi, string Shape){
void DETECTORNAME::AddDetector(double R, double Theta, double Phi, string Shape){
m_R.push_back(R);
m_Theta.push_back(Theta);
m_Phi.push_back(Phi);
......@@ -125,154 +135,40 @@ G4LogicalVolume* DETECTORNAME::BuildCylindricalDetector(){
// Read stream at Configfile to pick-up parameters of detector (Position,...)
// Called in DetecorConstruction::ReadDetextorConfiguration Method
void DETECTORNAME::ReadConfiguration(string Path){
ifstream ConfigFile ;
ConfigFile.open(Path.c_str()) ;
string LineBuffer ;
string DataBuffer ;
double Theta = 0 , Phi = 0 , R = 0 ;
double X = 0 , Y = 0 , Z = 0 ;
string Shape ;
bool check_Theta = false ;
bool check_Phi = false ;
bool check_R = 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 DETECTORNAME bloc, Reading toggle to true
string name = "DETECTORNAME";
if (LineBuffer.compare(0, name.length(), name) == 0) {
G4cout << "///" << G4endl ;
G4cout << "DETECTORNAME found: " << G4endl ;
ReadingStatus = true ;
void DETECTORNAME::ReadConfiguration(NPL::InputParser parser){
vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("DETECTORNAME");
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << "//// " << blocks.size() << " detectors found " << endl;
vector<string> cart = {"POS","Shape"};
vector<string> sphe = {"R","Theta","Phi","Shape"};
for(unsigned int i = 0 ; i < blocks.size() ; i++){
if(blocks[i]->HasTokenList(cart)){
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << endl << "//// DETECTORNAME " << i+1 << endl;
G4ThreeVector Pos = NPS::ConvertVector(blocks[i]->GetTVector3("POS","mm"));
string Shape = blocks[i]->GetString("Shape");
AddDetector(Pos,Shape);
}
// 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 == "THETA=") {
check_Theta = true;
ConfigFile >> DataBuffer ;
Theta = atof(DataBuffer.c_str()) ;
Theta = Theta * deg;
G4cout << "Theta: " << Theta / deg << G4endl;
}
else if (DataBuffer == "PHI=" ) {
check_Phi = true;
ConfigFile >> DataBuffer ;
Phi = atof(DataBuffer.c_str()) ;
Phi = Phi * deg;
G4cout << "Phi: " << Phi / deg << G4endl;
}
else if (DataBuffer == "R=") {
check_R = true;
ConfigFile >> DataBuffer ;
R = atof(DataBuffer.c_str()) ;
R = R * mm;
G4cout << "R: " << R/mm << G4endl;
}
//Position method
else if (DataBuffer == "X=") {
check_X = true;
ConfigFile >> DataBuffer ;
X = atof(DataBuffer.c_str()) ;
X = X * mm;
G4cout << "X: " << X / mm << G4endl;
}
else if (DataBuffer == "Y=") {
check_Y = true;
ConfigFile >> DataBuffer ;
Y = atof(DataBuffer.c_str()) ;
Y = Y * mm;
G4cout << "Y: " << Y / mm << G4endl;
}
else if (DataBuffer == "Z=") {
check_Z = true;
ConfigFile >> DataBuffer ;
Z = atof(DataBuffer.c_str()) ;
Z = Z * mm;
G4cout << "Z: " << Z / mm << G4endl;
}
//General
else if (DataBuffer == "Shape=") {
check_Shape = true;
ConfigFile >> DataBuffer ;
Shape = DataBuffer ;
G4cout << "Shape: " << Shape << 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_Shape)
||
( check_X && check_Y && check_Z && check_Shape)){
// Convert Cartesian to Spherical (detector always face the target)
if (check_X){
R = sqrt (X*X+Y*Y+Z*Z);
Theta = acos(Z / (R) );
Phi = atan2(Y,X);
}
AddDETECTORNAME(R,Theta,Phi,Shape);
// Reinitialisation of Check Boolean
check_Theta = false ;
check_Phi = false ;
check_R = false ;
check_Shape = false ;
check_X = false ;
check_Y = false ;
check_Z = false ;
ReadingStatus = false ;
G4cout << "///"<< G4endl ;
}
else if(blocks[i]->HasTokenList(sphe)){
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << endl << "//// DETECTORNAME " << i+1 << endl;
double R = blocks[i]->GetDouble("R","mm");
double Theta = blocks[i]->GetDouble("Theta","deg");
double Phi = blocks[i]->GetDouble("Phi","deg");
string Shape = blocks[i]->GetString("Shape");
AddDetector(R,Theta,Phi,Shape);
}
else{
cout << "ERROR: check your input file formatting " << endl;
exit(1);
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
// Construct detector and inialise sensitive part.
......
......@@ -35,6 +35,7 @@ using namespace std;
// NPTool header
#include "NPSVDetector.hh"
#include "TDETECTORNAMEData.h"
#include "NPInputParser.h"
class DETECTORNAME : public NPS::VDetector{
////////////////////////////////////////////////////
......@@ -48,11 +49,11 @@ class DETECTORNAME : public NPS::VDetector{
/////// Specific Function of this Class ///////////
////////////////////////////////////////////////////
public:
// Cylindric plastic
void AddDETECTORNAME(double R,
double Theta,
double Phi,
string Shape);
// Cartesian
void AddDetector(G4ThreeVector POS, string Shape);
// Spherical
void AddDetector(double R,double Theta,double Phi,string Shape);
G4LogicalVolume* BuildSquareDetector();
G4LogicalVolume* BuildCylindricalDetector();
......@@ -67,7 +68,7 @@ class DETECTORNAME : public NPS::VDetector{
public:
// Read stream at Configfile to pick-up parameters of detector (Position,...)
// Called in DetecorConstruction::ReadDetextorConfiguration Method
void ReadConfiguration(string Path) ;
void ReadConfiguration(NPL::InputParser) ;
// Construct detector and inialise sensitive part.
// Called After DetecorConstruction::AddDetector Method
......
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GeneralTarget
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Target
THICKNESS= 10
RADIUS= 20
MATERIAL= CD2
ANGLE= 0
X= 0
Y= 0
Z= 0
THICKNESS= 10 micrometer
RADIUS= 20 mm
MATERIAL= CD2
ANGLE= 0 deg
X= 0 mm
Y= 0 mm
Z= 0 mm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DETECTORNAME
X= 0
Y= 0
Z= 350
Shape= Square
pipo
POS= 0 0 350 mm
Shape= Square
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DETECTORNAME
X= 350
Y= 350
Z= 350
Shape= Square
pipo
POS = 35 35 35 cm
Shape= Square
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DETECTORNAME
R= 350
THETA= 90
PHI= 63
Shape= Cylindrical
pipo
R= 350 mm
THETA= 90 deg
PHI= 63 deg
Shape= Cylindrical
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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