diff --git a/Inputs/DetectorConfiguration/Microball.detector b/Inputs/DetectorConfiguration/Microball.detector new file mode 100644 index 0000000000000000000000000000000000000000..12eaeb828a7ef3546024a5f355c53020f1e1b89d --- /dev/null +++ b/Inputs/DetectorConfiguration/Microball.detector @@ -0,0 +1,31 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +GeneralTarget +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Target + THICKNESS= 10 + RADIUS= 20 + MATERIAL= CD2 + ANGLE= 0 + X= 0 + Y= 0 + Z= 0 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Microball + X= 0 + Y= 0 + Z= 350 + Shape= Square +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Microball + X= 350 + Y= 350 + Z= 350 + Shape= Square +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Microball + R= 350 + THETA= 90 + PHI= 63 + Shape= Cylindrical +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + diff --git a/Inputs/DetectorConfiguration/lassaSingle.detector b/Inputs/DetectorConfiguration/lassaSingle.detector deleted file mode 100644 index 9db148ee21b7af92a1286651078e35a2e80f038e..0000000000000000000000000000000000000000 --- a/Inputs/DetectorConfiguration/lassaSingle.detector +++ /dev/null @@ -1,27 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -GeneralTarget -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% Thickness in micrometer -% Radius in mm -% Temperature in K, Pressure in bar -Target - THICKNESS= 6.26 -ANGLE= 0 - RADIUS= 10 - MATERIAL= CD2 - X= 0 - Y= 0 - Z= 0 - -%%%%%%%%%%%%%%%%%%%%% -LASSAArray -%%%%%%%%%%%%%%%%%%%%% - -%%%%%%% Telescope 0 %%%%%%% -LassaTelescope -A= -3.5 -3.5 215 -B= 3.5 -3.5 215 -C= -3.5 3.5 215 -D= 3.5 3.5 215 - diff --git a/Inputs/EventGenerator/3He.source b/Inputs/EventGenerator/3He.source index 66efecc3e4be50185b581bdd2afda851991e014b..62826ae77c98e7500a20de339fda5272741616bc 100644 --- a/Inputs/EventGenerator/3He.source +++ b/Inputs/EventGenerator/3He.source @@ -5,9 +5,9 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Isotropic EnergyLow= 0 - EnergyHigh= 525 - HalfOpenAngleMin= 0 - HalfOpenAngleMax= 90 + EnergyHigh= 550 + HalfOpenAngleMin= 10 + HalfOpenAngleMax= 60 x0= 0 y0= 0 z0= 0 diff --git a/Inputs/EventGenerator/alpha.source b/Inputs/EventGenerator/alpha.source index 1c9997fde237f339d97cecb394ca6d5542eea6a5..f4b6cb9ac5897b5a80779922b6a8676f7d73ffb3 100644 --- a/Inputs/EventGenerator/alpha.source +++ b/Inputs/EventGenerator/alpha.source @@ -5,9 +5,9 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Isotropic EnergyLow= 0 - EnergyHigh= 590 - HalfOpenAngleMin= 0 - HalfOpenAngleMax= 90 + EnergyHigh= 650 + HalfOpenAngleMin= 10 + HalfOpenAngleMax= 60 x0= 0 y0= 0 z0= 0 diff --git a/Inputs/EventGenerator/deuton.source b/Inputs/EventGenerator/deuton.source index 4bd428cd0b4f89d52538700126a6914038b11e9a..0c6c3b6f1d99106ca0e3fee0f900ce4ad88d34ad 100644 --- a/Inputs/EventGenerator/deuton.source +++ b/Inputs/EventGenerator/deuton.source @@ -6,8 +6,8 @@ Isotropic EnergyLow= 0 EnergyHigh= 205 - HalfOpenAngleMin= 0 - HalfOpenAngleMax= 90 + HalfOpenAngleMin= 10 + HalfOpenAngleMax= 60 x0= 0 y0= 0 z0= 0 diff --git a/Inputs/EventGenerator/proton.pbuu b/Inputs/EventGenerator/proton.pbuu index 9b4a60c1ea9d5740dce83a2b0fb3fd3e3ea841e6..1e6be07b5dbc7e7f0802283affc3061da5b4bb88 100644 --- a/Inputs/EventGenerator/proton.pbuu +++ b/Inputs/EventGenerator/proton.pbuu @@ -6,7 +6,7 @@ % In the TH2F histogram, angle ix X-axis and energy is Y-axis % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pBUU - AngleEnergyHistPath= sn112e120_ELab_ThetaLab_p.root h + AngleEnergyHistPath= sn112e120_flat_p.root h x0= 0 y0= 0 z0= 0 diff --git a/Inputs/EventGenerator/proton.source b/Inputs/EventGenerator/proton.source index 75ce81c443c5a62b35a19132ac185721b8412dde..2ed351a016742d2f64412b5879e2525cb027c4db 100644 --- a/Inputs/EventGenerator/proton.source +++ b/Inputs/EventGenerator/proton.source @@ -7,7 +7,7 @@ Isotropic EnergyLow= 0 EnergyHigh= 250 HalfOpenAngleMin= 0 - HalfOpenAngleMax= 90 + HalfOpenAngleMax= 20 x0= 0 y0= 0 z0= 0 diff --git a/Inputs/EventGenerator/triton.source b/Inputs/EventGenerator/triton.source index 28ecc223289d59d56ff668874ffa5543fe304440..118077dcdab992076e1346b3af4c5998b91574d5 100644 --- a/Inputs/EventGenerator/triton.source +++ b/Inputs/EventGenerator/triton.source @@ -5,9 +5,9 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Isotropic EnergyLow= 0 - EnergyHigh= 235 - HalfOpenAngleMin= 0 - HalfOpenAngleMax= 90 + EnergyHigh= 255 + HalfOpenAngleMin= 10 + HalfOpenAngleMax= 60 x0= 0 y0= 0 z0= 0 diff --git a/NPLib/Detectors/Microball/CMakeLists.txt b/NPLib/Detectors/Microball/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..63ea5977a7d9d5885bbcd8c568e2343e8792711d --- /dev/null +++ b/NPLib/Detectors/Microball/CMakeLists.txt @@ -0,0 +1,6 @@ +add_custom_command(OUTPUT TMicroballPhysicsDict.cxx COMMAND ../../scripts/build_dict.sh TMicroballPhysics.h TMicroballPhysicsDict.cxx TMicroballPhysics.rootmap libNPMicroball.dylib DEPENDS TMicroballPhysics.h) +add_custom_command(OUTPUT TMicroballDataDict.cxx COMMAND ../../scripts/build_dict.sh TMicroballData.h TMicroballDataDict.cxx TMicroballData.rootmap libNPMicroball.dylib DEPENDS TMicroballData.h) +add_library(NPMicroball SHARED TMicroballSpectra.cxx TMicroballData.cxx TMicroballPhysics.cxx TMicroballDataDict.cxx TMicroballPhysicsDict.cxx ) +target_link_libraries(NPMicroball ${ROOT_LIBRARIES} NPCore) +install(FILES TMicroballData.h TMicroballPhysics.h TMicroballSpectra.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}) + diff --git a/NPLib/Detectors/Microball/TMicroballData.cxx b/NPLib/Detectors/Microball/TMicroballData.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c8008da1653862808749faddf3a370144b8eb523 --- /dev/null +++ b/NPLib/Detectors/Microball/TMicroballData.cxx @@ -0,0 +1,79 @@ +/***************************************************************************** + * Copyright (C) 2009-2016 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Pierre Morfouace contact address: morfouac@nscl.msu.edu * + * * + * Creation Date : June 2016 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold Microball Raw data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ +#include "TMicroballData.h" + +#include <iostream> +#include <fstream> +#include <sstream> +#include <string> +using namespace std; + +ClassImp(TMicroballData) + + +////////////////////////////////////////////////////////////////////// +TMicroballData::TMicroballData() { +} + + + +////////////////////////////////////////////////////////////////////// +TMicroballData::~TMicroballData() { +} + + + +////////////////////////////////////////////////////////////////////// +void TMicroballData::Clear() { + // Energy + fMicroball_E_DetectorNbr.clear(); + fMicroball_Energy.clear(); + // Time + fMicroball_T_DetectorNbr.clear(); + fMicroball_Time.clear(); +} + + + +////////////////////////////////////////////////////////////////////// +void TMicroballData::Dump() const { + // This method is very useful for debuging and worth the dev. + cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TMicroballData::Dump()] XXXXXXXXXXXXXXXXX" << endl; + + // Energy + size_t mysize = fMicroball_E_DetectorNbr.size(); + cout << "Microball_E_Mult: " << mysize << endl; + + for (size_t i = 0 ; i < mysize ; i++){ + cout << "DetNbr: " << fMicroball_E_DetectorNbr[i] + << " Energy: " << fMicroball_Energy[i]; + } + + // Time + mysize = fMicroball_T_DetectorNbr.size(); + cout << "Microball_T_Mult: " << mysize << endl; + + for (size_t i = 0 ; i < mysize ; i++){ + cout << "DetNbr: " << fMicroball_T_DetectorNbr[i] + << " Time: " << fMicroball_Time[i]; + } +} diff --git a/NPLib/Detectors/Microball/TMicroballData.h b/NPLib/Detectors/Microball/TMicroballData.h new file mode 100644 index 0000000000000000000000000000000000000000..122b505e98ce74884b5690434c2fc68abbade960 --- /dev/null +++ b/NPLib/Detectors/Microball/TMicroballData.h @@ -0,0 +1,114 @@ +#ifndef __MicroballDATA__ +#define __MicroballDATA__ +/***************************************************************************** + * Copyright (C) 2009-2016 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Pierre Morfouace contact address: morfouac@nscl.msu.edu * + * * + * Creation Date : June 2016 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold Microball Raw data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// STL +#include <vector> +using namespace std; + +// ROOT +#include "TObject.h" + +class TMicroballData : public TObject { + ////////////////////////////////////////////////////////////// + // data members are hold into vectors in order + // to allow multiplicity treatment + private: + // Energy + vector<UShort_t> fMicroball_E_DetectorNbr; + vector<Double_t> fMicroball_Energy; + + // Time + vector<UShort_t> fMicroball_T_DetectorNbr; + vector<Double_t> fMicroball_Time; + + + ////////////////////////////////////////////////////////////// + // Constructor and destructor + public: + TMicroballData(); + virtual ~TMicroballData(); + + + ////////////////////////////////////////////////////////////// + // Inherited from TObject and overriden to avoid warnings + public: + void Clear(); + void Clear(const Option_t*) {}; + void Dump() const; + + + ////////////////////////////////////////////////////////////// + // Getters and Setters + // Prefer inline declaration to avoid unnecessary called of + // frequently used methods + // add //! to avoid ROOT creating dictionnary for the methods + public: + ////////////////////// SETTERS //////////////////////// + // Energy + inline void SetE_DetectorNbr(const UShort_t& DetNbr) + {fMicroball_E_DetectorNbr.push_back(DetNbr);} //! + inline void Set_Energy(const Double_t& Energy) + {fMicroball_Energy.push_back(Energy);}//! + // Prefer global setter so that all vectors have the same size + inline void SetEnergy(const UShort_t& DetNbr,const Double_t& Energy) { + SetE_DetectorNbr(DetNbr); + Set_Energy(Energy); + };//! + + // Time + inline void SetT_DetectorNbr(const UShort_t& DetNbr) + {fMicroball_T_DetectorNbr.push_back(DetNbr);} //! + inline void Set_Time(const Double_t& Time) + {fMicroball_Time.push_back(Time);}//! + // Prefer global setter so that all vectors have the same size + inline void SetTime(const UShort_t& DetNbr,const Double_t& Time) { + SetT_DetectorNbr(DetNbr); + Set_Time(Time); + };//! + + + ////////////////////// GETTERS //////////////////////// + // Energy + inline UShort_t GetMultEnergy() const + {return fMicroball_E_DetectorNbr.size();} + inline UShort_t GetE_DetectorNbr(const unsigned int &i) const + {return fMicroball_E_DetectorNbr[i];}//! + inline Double_t Get_Energy(const unsigned int &i) const + {return fMicroball_Energy[i];}//! + + // Time + inline UShort_t GetMultTime() const + {return fMicroball_T_DetectorNbr.size();} + inline UShort_t GetT_DetectorNbr(const unsigned int &i) const + {return fMicroball_T_DetectorNbr[i];}//! + inline Double_t Get_Time(const unsigned int &i) const + {return fMicroball_Time[i];}//! + + + ////////////////////////////////////////////////////////////// + // Required for ROOT dictionnary + ClassDef(TMicroballData,1) // MicroballData structure +}; + +#endif diff --git a/NPLib/Detectors/Microball/TMicroballPhysics.cxx b/NPLib/Detectors/Microball/TMicroballPhysics.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5f8b258dfef09823cba459a489d0d4b7642b612c --- /dev/null +++ b/NPLib/Detectors/Microball/TMicroballPhysics.cxx @@ -0,0 +1,424 @@ +/***************************************************************************** + * Copyright (C) 2009-2016 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Pierre Morfouace contact address: morfouac@nscl.msu.edu * + * * + * Creation Date : June 2016 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold Microball Treated data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +#include "TMicroballPhysics.h" + +// STL +#include <sstream> +#include <iostream> +#include <cmath> +#include <stdlib.h> +#include <limits> +using namespace std; + +// NPL +#include "RootInput.h" +#include "RootOutput.h" +#include "NPDetectorFactory.h" + +// ROOT +#include "TChain.h" + +ClassImp(TMicroballPhysics) + + +/////////////////////////////////////////////////////////////////////////// +TMicroballPhysics::TMicroballPhysics() + : m_EventData(new TMicroballData), + m_PreTreatedData(new TMicroballData), + m_EventPhysics(this), + m_Spectra(0), + m_E_RAW_Threshold(0), // adc channels + m_E_Threshold(0), // MeV + m_NumberOfDetectors(0) { +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::BuildSimplePhysicalEvent() { + BuildPhysicalEvent(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::BuildPhysicalEvent() { + // apply thresholds and calibration + PreTreat(); + + // match energy and time together + for (UShort_t e = 0; e < m_PreTreatedData->GetMultEnergy(); e++) { + for (UShort_t t = 0; t < m_PreTreatedData->GetMultTime(); t++) { + if (m_PreTreatedData->GetE_DetectorNbr(e) == m_PreTreatedData->GetT_DetectorNbr(t)) { + DetectorNumber.push_back(m_PreTreatedData->GetE_DetectorNbr(e)); + Energy.push_back(m_PreTreatedData->Get_Energy(e)); + Time.push_back(m_PreTreatedData->Get_Time(t)); + } + } + } +} + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::PreTreat() { + // This method typically applies thresholds and calibrations + // Might test for disabled channels for more complex detector + + // clear pre-treated object + ClearPreTreatedData(); + + // instantiate CalibrationManager + static CalibrationManager* Cal = CalibrationManager::getInstance(); + + // Energy + for (UShort_t i = 0; i < m_EventData->GetMultEnergy(); ++i) { + if (m_EventData->Get_Energy(i) > m_E_RAW_Threshold) { + Double_t Energy = Cal->ApplyCalibration("Microball/ENERGY"+NPL::itoa(m_EventData->GetE_DetectorNbr(i)),m_EventData->Get_Energy(i)); + if (Energy > m_E_Threshold) { + m_PreTreatedData->SetEnergy(m_EventData->GetE_DetectorNbr(i), Energy); + } + } + } + + // Time + for (UShort_t i = 0; i < m_EventData->GetMultTime(); ++i) { + Double_t Time= Cal->ApplyCalibration("Microball/TIME"+NPL::itoa(m_EventData->GetT_DetectorNbr(i)),m_EventData->Get_Time(i)); + m_PreTreatedData->SetTime(m_EventData->GetT_DetectorNbr(i), Time); + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::ReadAnalysisConfig() { + bool ReadingStatus = false; + + // path to file + string FileName = "./configs/ConfigMicroball.dat"; + + // open analysis config file + ifstream AnalysisConfigFile; + AnalysisConfigFile.open(FileName.c_str()); + + if (!AnalysisConfigFile.is_open()) { + cout << " No ConfigMicroball.dat found: Default parameter loaded for Analayis " << FileName << endl; + return; + } + cout << " Loading user parameter for Analysis from ConfigMicroball.dat " << endl; + + // Save it in a TAsciiFile + TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig(); + asciiConfig->AppendLine("%%% ConfigMicroball.dat %%%"); + asciiConfig->Append(FileName.c_str()); + asciiConfig->AppendLine(""); + // read analysis config file + string LineBuffer,DataBuffer,whatToDo; + while (!AnalysisConfigFile.eof()) { + // Pick-up next line + getline(AnalysisConfigFile, LineBuffer); + + // search for "header" + string name = "ConfigMicroball"; + if (LineBuffer.compare(0, name.length(), name) == 0) + ReadingStatus = true; + + // loop on tokens and data + while (ReadingStatus ) { + whatToDo=""; + AnalysisConfigFile >> whatToDo; + + // Search for comment symbol (%) + if (whatToDo.compare(0, 1, "%") == 0) { + AnalysisConfigFile.ignore(numeric_limits<streamsize>::max(), '\n' ); + } + + else if (whatToDo=="E_RAW_THRESHOLD") { + AnalysisConfigFile >> DataBuffer; + m_E_RAW_Threshold = atof(DataBuffer.c_str()); + cout << whatToDo << " " << m_E_RAW_Threshold << endl; + } + + else if (whatToDo=="E_THRESHOLD") { + AnalysisConfigFile >> DataBuffer; + m_E_Threshold = atof(DataBuffer.c_str()); + cout << whatToDo << " " << m_E_Threshold << endl; + } + + else { + ReadingStatus = false; + } + } + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::Clear() { + DetectorNumber.clear(); + Energy.clear(); + Time.clear(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::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 Microball bloc, Reading toggle to true + string name="Microball"; + if (LineBuffer.compare(0, name.length(), name) == 0){ + cout << "///" << endl ; + cout << "Microball found: " << endl ; + ReadingStatus = true ; + } + + // 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 ; + } + } + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::InitSpectra() { + m_Spectra = new TMicroballSpectra(m_NumberOfDetectors); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::FillSpectra() { + m_Spectra -> FillRawSpectra(m_EventData); + m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData); + m_Spectra -> FillPhysicsSpectra(m_EventPhysics); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::CheckSpectra() { + m_Spectra->CheckSpectra(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::ClearSpectra() { + // To be done +} + + + +/////////////////////////////////////////////////////////////////////////// +map< string , TH1*> TMicroballPhysics::GetSpectra() { + if(m_Spectra) + return m_Spectra->GetMapHisto(); + else{ + map< string , TH1*> empty; + return empty; + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +vector<TCanvas*> TMicroballPhysics::GetCanvas() { + if(m_Spectra) + return m_Spectra->GetCanvas(); + else{ + vector<TCanvas*> empty; + return empty; + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::WriteSpectra() { + m_Spectra->WriteSpectra(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::AddParameterToCalibrationManager() { + CalibrationManager* Cal = CalibrationManager::getInstance(); + for (int i = 0; i < m_NumberOfDetectors; ++i) { + Cal->AddParameter("Microball", "D"+ NPL::itoa(i+1)+"_ENERGY","Microball_D"+ NPL::itoa(i+1)+"_ENERGY"); + Cal->AddParameter("Microball", "D"+ NPL::itoa(i+1)+"_TIME","Microball_D"+ NPL::itoa(i+1)+"_TIME"); + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::InitializeRootInputRaw() { + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchStatus("Microball", true ); + inputChain->SetBranchAddress("Microball", &m_EventData ); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::InitializeRootInputPhysics() { + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchAddress("Microball", &m_EventPhysics); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TMicroballPhysics::InitializeRootOutput() { + TTree* outputTree = RootOutput::getInstance()->GetTree(); + outputTree->Branch("Microball", "TMicroballPhysics", &m_EventPhysics); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// Construct Method to be pass to the DetectorFactory // +//////////////////////////////////////////////////////////////////////////////// +NPL::VDetector* TMicroballPhysics::Construct() { + return (NPL::VDetector*) new TMicroballPhysics(); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// Registering the construct method to the factory // +//////////////////////////////////////////////////////////////////////////////// +extern "C"{ +class proxy_Microball{ + public: + proxy_Microball(){ + NPL::DetectorFactory::getInstance()->AddToken("Microball","Microball"); + NPL::DetectorFactory::getInstance()->AddDetector("Microball",TMicroballPhysics::Construct); + } +}; + +proxy_Microball p_Microball; +} + diff --git a/NPLib/Detectors/Microball/TMicroballPhysics.h b/NPLib/Detectors/Microball/TMicroballPhysics.h new file mode 100644 index 0000000000000000000000000000000000000000..b16c9d8333b19cb8307716eb85294c3fe0a08d67 --- /dev/null +++ b/NPLib/Detectors/Microball/TMicroballPhysics.h @@ -0,0 +1,179 @@ +#ifndef TMicroballPHYSICS_H +#define TMicroballPHYSICS_H +/***************************************************************************** + * Copyright (C) 2009-2016 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Pierre Morfouace contact address: morfouac@nscl.msu.edu * + * * + * Creation Date : June 2016 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold Microball Treated data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// C++ headers +#include <vector> +#include <map> +#include <string> +using namespace std; + +// ROOT headers +#include "TObject.h" +#include "TH1.h" +#include "TCanvas.h" + +// NPTool headers +#include "TMicroballData.h" +#include "TMicroballSpectra.h" +#include "NPCalibrationManager.h" +#include "NPVDetector.h" + +// forward declaration +class TMicroballSpectra; + + + +class TMicroballPhysics : public TObject, public NPL::VDetector { + ////////////////////////////////////////////////////////////// + // constructor and destructor + public: + TMicroballPhysics(); + ~TMicroballPhysics() {}; + + + ////////////////////////////////////////////////////////////// + // Inherited from TObject and overriden to avoid warnings + public: + void Clear(); + void Clear(const Option_t*) {}; + + + ////////////////////////////////////////////////////////////// + // data obtained after BuildPhysicalEvent() and stored in + // output ROOT file + public: + vector<int> DetectorNumber; + vector<double> Energy; + vector<double> Time; + + + ////////////////////////////////////////////////////////////// + // methods inherited from the VDetector ABC class + public: + // read stream from ConfigFile to pick-up detector parameters + void ReadConfiguration(string); + + // add parameters to the CalibrationManger + void AddParameterToCalibrationManager(); + + // method called event by event, aiming at extracting the + // physical information from detector + void BuildPhysicalEvent(); + + // same as BuildPhysicalEvent() method but with a simpler + // treatment + void BuildSimplePhysicalEvent(); + + // same as above but for online analysis + void BuildOnlinePhysicalEvent() {BuildPhysicalEvent();}; + + // activate raw data object and branches from input TChain + // in this method mother branches (Detector) AND daughter leaves + // (fDetector_parameter) have to be activated + void InitializeRootInputRaw(); + + // activate physics data object and branches from input TChain + // in this method mother branches (Detector) AND daughter leaves + // (fDetector_parameter) have to be activated + void InitializeRootInputPhysics(); + + // create branches of output ROOT file + void InitializeRootOutput(); + + // clear the raw and physical data objects event by event + void ClearEventPhysics() {Clear();} + void ClearEventData() {m_EventData->Clear();} + + // methods related to the TMicroballSpectra class + // instantiate the TMicroballSpectra class and + // declare list of histograms + void InitSpectra(); + + // fill the spectra + void FillSpectra(); + + // used for Online mainly, sanity check for histograms and + // change their color if issues are found, for example + void CheckSpectra(); + + // used for Online only, clear all the spectra + void ClearSpectra(); + + // write spectra to ROOT output file + void WriteSpectra(); + + + ////////////////////////////////////////////////////////////// + // specific methods to Microball array + public: + // remove bad channels, calibrate the data and apply thresholds + void PreTreat(); + + // clear the pre-treated object + void ClearPreTreatedData() {m_PreTreatedData->Clear();} + + // read the user configuration file. If no file is found, load standard one + void ReadAnalysisConfig(); + + // give and external TMicroballData object to TMicroballPhysics. + // needed for online analysis for example + void SetRawDataPointer(TMicroballData* rawDataPointer) {m_EventData = rawDataPointer;} + + // objects are not written in the TTree + private: + TMicroballData* m_EventData; //! + TMicroballData* m_PreTreatedData; //! + TMicroballPhysics* m_EventPhysics; //! + + // getters for raw and pre-treated data object + public: + TMicroballData* GetRawData() const {return m_EventData;} + TMicroballData* GetPreTreatedData() const {return m_PreTreatedData;} + + // parameters used in the analysis + private: + // thresholds + double m_E_RAW_Threshold; //! + double m_E_Threshold; //! + + // number of detectors + private: + int m_NumberOfDetectors; //! + + // spectra class + private: + TMicroballSpectra* m_Spectra; // ! + + // spectra getter + public: + map<string, TH1*> GetSpectra(); + vector<TCanvas*> GetCanvas(); + + // Static constructor to be passed to the Detector Factory + public: + static NPL::VDetector* Construct(); + + ClassDef(TMicroballPhysics,1) // MicroballPhysics structure +}; +#endif diff --git a/NPLib/Detectors/Microball/TMicroballSpectra.cxx b/NPLib/Detectors/Microball/TMicroballSpectra.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b1bbe64982ffb6d2551bbd3913bd762a4fe593aa --- /dev/null +++ b/NPLib/Detectors/Microball/TMicroballSpectra.cxx @@ -0,0 +1,174 @@ +/***************************************************************************** + * Copyright (C) 2009-2016 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Pierre Morfouace contact address: morfouac@nscl.msu.edu * + * * + * Creation Date : June 2016 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold Microball Spectra * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// class header +#include "TMicroballSpectra.h" + +// STL +#include <iostream> +#include <string> +using namespace std; + +// NPTool header +#include "NPOptionManager.h" + + + +//////////////////////////////////////////////////////////////////////////////// +TMicroballSpectra::TMicroballSpectra() + : fNumberOfDetectors(0) { + SetName("Microball"); +} + + + +//////////////////////////////////////////////////////////////////////////////// +TMicroballSpectra::TMicroballSpectra(unsigned int NumberOfDetectors) { + if(NPOptionManager::getInstance()->GetVerboseLevel()>0) + cout << "************************************************" << endl + << "TMicroballSpectra : Initalizing control spectra for " + << NumberOfDetectors << " Detectors" << endl + << "************************************************" << endl ; + SetName("Microball"); + fNumberOfDetectors = NumberOfDetectors; + + InitRawSpectra(); + InitPreTreatedSpectra(); + InitPhysicsSpectra(); +} + + + +//////////////////////////////////////////////////////////////////////////////// +TMicroballSpectra::~TMicroballSpectra() { +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TMicroballSpectra::InitRawSpectra() { + static string name; + for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors + // Energy + name = "Microball"+NPL::itoa(i+1)+"_ENERGY_RAW"; + AddHisto1D(name, name, 4096, 0, 16384, "Microball/RAW"); + // Time + name = "Microball"+NPL::itoa(i+1)+"_TIME_RAW"; + AddHisto1D(name, name, 4096, 0, 16384, "Microball/RAW"); + } // end loop on number of detectors +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TMicroballSpectra::InitPreTreatedSpectra() { + static string name; + for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors + // Energy + name = "Microball"+NPL::itoa(i+1)+"_ENERGY_CAL"; + AddHisto1D(name, name, 500, 0, 25, "Microball/CAL"); + // Time + name = "Microball"+NPL::itoa(i+1)+"_TIME_CAL"; + AddHisto1D(name, name, 500, 0, 25, "Microball/CAL"); + + + } // end loop on number of detectors +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TMicroballSpectra::InitPhysicsSpectra() { + static string name; + // Kinematic Plot + name = "Microball_ENERGY_TIME"; + AddHisto2D(name, name, 500, 0, 500, 500, 0, 50, "Microball/PHY"); +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TMicroballSpectra::FillRawSpectra(TMicroballData* RawData) { + static string name; + static string family; + + // Energy + unsigned int sizeE = RawData->GetMultEnergy(); + for (unsigned int i = 0; i < sizeE; i++) { + name = "Microball"+NPL::itoa(RawData->GetE_DetectorNbr(i))+"_ENERGY_RAW"; + family = "Microball/RAW"; + + GetHisto(family,name) -> Fill(RawData->Get_Energy(i)); + } + + // Time + unsigned int sizeT = RawData->GetMultTime(); + for (unsigned int i = 0; i < sizeT; i++) { + name = "Microball"+NPL::itoa(RawData->GetT_DetectorNbr(i))+"_TIME_RAW"; + family = "Microball/RAW"; + + GetHisto(family,name) -> Fill(RawData->Get_Time(i)); + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TMicroballSpectra::FillPreTreatedSpectra(TMicroballData* PreTreatedData) { + static string name; + static string family; + + // Energy + unsigned int sizeE = PreTreatedData->GetMultEnergy(); + for (unsigned int i = 0; i < sizeE; i++) { + name = "Microball"+NPL::itoa(PreTreatedData->GetE_DetectorNbr(i))+"_ENERGY_CAL"; + family = "Microball/CAL"; + + GetHisto(family,name) -> Fill(PreTreatedData->Get_Energy(i)); + } + + // Time + unsigned int sizeT = PreTreatedData->GetMultTime(); + for (unsigned int i = 0; i < sizeT; i++) { + name = "Microball"+NPL::itoa(PreTreatedData->GetT_DetectorNbr(i))+"_TIME_CAL"; + family = "Microball/CAL"; + + GetHisto(family,name) -> Fill(PreTreatedData->Get_Time(i)); + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TMicroballSpectra::FillPhysicsSpectra(TMicroballPhysics* Physics) { + static string name; + static string family; + family= "Microball/PHY"; + + // Energy vs time + unsigned int sizeE = Physics->Energy.size(); + for(unsigned int i = 0 ; i < sizeE ; i++){ + name = "Microball_ENERGY_TIME"; + GetHisto(family,name) -> Fill(Physics->Energy[i],Physics->Time[i]); + } +} + diff --git a/NPLib/Detectors/Microball/TMicroballSpectra.h b/NPLib/Detectors/Microball/TMicroballSpectra.h new file mode 100644 index 0000000000000000000000000000000000000000..596addaf97aa0422b6665ddeebd84b24101929fc --- /dev/null +++ b/NPLib/Detectors/Microball/TMicroballSpectra.h @@ -0,0 +1,62 @@ +#ifndef TMicroballSPECTRA_H +#define TMicroballSPECTRA_H +/***************************************************************************** + * Copyright (C) 2009-2016 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Pierre Morfouace contact address: morfouac@nscl.msu.edu * + * * + * Creation Date : June 2016 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold Microball Spectra * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// NPLib headers +#include "NPVSpectra.h" +#include "TMicroballData.h" +#include "TMicroballPhysics.h" + +// Forward Declaration +class TMicroballPhysics; + + +class TMicroballSpectra : public VSpectra { + ////////////////////////////////////////////////////////////// + // constructor and destructor + public: + TMicroballSpectra(); + TMicroballSpectra(unsigned int NumberOfDetectors); + ~TMicroballSpectra(); + + ////////////////////////////////////////////////////////////// + // Initialization methods + private: + void InitRawSpectra(); + void InitPreTreatedSpectra(); + void InitPhysicsSpectra(); + + ////////////////////////////////////////////////////////////// + // Filling methods + public: + void FillRawSpectra(TMicroballData*); + void FillPreTreatedSpectra(TMicroballData*); + void FillPhysicsSpectra(TMicroballPhysics*); + + ////////////////////////////////////////////////////////////// + // Detector parameters + private: + unsigned int fNumberOfDetectors; +}; + +#endif diff --git a/NPSimulation/Detectors/Microball/CMakeLists.txt b/NPSimulation/Detectors/Microball/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e6671135ee25002a34a73d44b0e0b6acb1923bd0 --- /dev/null +++ b/NPSimulation/Detectors/Microball/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(NPSMicroball SHARED Microball.cc) +target_link_libraries(NPSMicroball NPSCore ${ROOT_LIBRARIES} ${Geant4_LIBRARIES} ${NPLib_LIBRARIES} -lNPMicroball) diff --git a/NPSimulation/Detectors/Microball/Microball.cc b/NPSimulation/Detectors/Microball/Microball.cc new file mode 100644 index 0000000000000000000000000000000000000000..1f1e771f72d2276399b85df9dfea8fbad72a6e53 --- /dev/null +++ b/NPSimulation/Detectors/Microball/Microball.cc @@ -0,0 +1,399 @@ +/***************************************************************************** + * Copyright (C) 2009-2016 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Pierre Morfouace contact address: morfouac@nscl.msu.edu * + * * + * Creation Date : June 2016 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class describe Microball simulation * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + *****************************************************************************/ + +// C++ headers +#include <sstream> +#include <cmath> +#include <limits> +//G4 Geometry object +#include "G4Tubs.hh" +#include "G4Box.hh" + +//G4 sensitive +#include "G4SDManager.hh" +#include "G4MultiFunctionalDetector.hh" + +//G4 various object +#include "G4Material.hh" +#include "G4Transform3D.hh" +#include "G4PVPlacement.hh" +#include "G4VisAttributes.hh" +#include "G4Colour.hh" + +// NPTool header +#include "Microball.hh" +#include "CalorimeterScorers.hh" +#include "RootOutput.h" +#include "MaterialManager.hh" +#include "NPSDetectorFactory.hh" +// CLHEP header +#include "CLHEP/Random/RandGauss.h" + +using namespace std; +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"; +} +//....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)); + +} + +Microball::~Microball(){ +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +void Microball::AddMicroball(double R, double Theta, double Phi, string Shape){ + m_R.push_back(R); + m_Theta.push_back(Theta); + m_Phi.push_back(Phi); + m_Shape.push_back(Shape); +} + +//....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; +} + +//....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; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +// Virtual Method of NPS::VDetector class + +// 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 ; + + 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 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, "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; + } + + /////////////////////////////////////////////////// + // 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); + } + + AddMicroball(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 ; + } + } + } +} +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +// Construct detector and inialise sensitive part. +// Called After DetecorConstruction::AddDetector Method +void Microball::ConstructDetector(G4LogicalVolume* world){ + 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] ) ; + 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()*Microball_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(), + "Microball",world,false,i+1); + } + + else if(m_Shape[i] == "Square"){ + new G4PVPlacement(G4Transform3D(*Rot,Det_pos), + BuildSquareDetector(), + "Microball",world,false,i+1); + } + } +} +//....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) ; +} + +//....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[2]; + m_Event->SetEnergy(DetectorNbr,Energy); + m_Event->SetTime(DetectorNbr,Time); + } + } + // 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_Calorimeter("Calorimeter",level, 0) ; + //and register it to the multifunctionnal detector + m_MicroballScorer->RegisterPrimitive(Calorimeter); + G4SDManager::GetSDMpointer()->AddNewDetector(m_MicroballScorer) ; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//////////////////////////////////////////////////////////////////////////////// +// Construct Method to be pass to the DetectorFactory // +//////////////////////////////////////////////////////////////////////////////// +NPS::VDetector* Microball::Construct(){ + return (NPS::VDetector*) new Microball(); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//////////////////////////////////////////////////////////////////////////////// +// Registering the construct method to the factory // +//////////////////////////////////////////////////////////////////////////////// +extern"C" { + 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; +} diff --git a/NPSimulation/Detectors/Microball/Microball.hh b/NPSimulation/Detectors/Microball/Microball.hh new file mode 100644 index 0000000000000000000000000000000000000000..3512cb5d78404694074ce3c6d8490781b2aa6fc4 --- /dev/null +++ b/NPSimulation/Detectors/Microball/Microball.hh @@ -0,0 +1,116 @@ +#ifndef Microball_h +#define Microball_h 1 +/***************************************************************************** + * Copyright (C) 2009-2016 this file is part of the NPTool Project * + * * + * For the licensing terms see $NPTOOL/Licence/NPTool_Licence * + * For the list of contributors see $NPTOOL/Licence/Contributors * + *****************************************************************************/ + +/***************************************************************************** + * Original Author: Pierre Morfouace contact address: morfouac@nscl.msu.edu * + * * + * Creation Date : June 2016 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class describe Microball simulation * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + *****************************************************************************/ + +// C++ header +#include <string> +#include <vector> +using namespace std; + +// G4 headers +#include "G4ThreeVector.hh" +#include "G4RotationMatrix.hh" +#include "G4LogicalVolume.hh" +#include "G4MultiFunctionalDetector.hh" + +// NPTool header +#include "NPSVDetector.hh" +#include "TMicroballData.h" + +class Microball : public NPS::VDetector{ + //////////////////////////////////////////////////// + /////// Default Constructor and Destructor ///////// + //////////////////////////////////////////////////// + public: + Microball() ; + virtual ~Microball() ; + + //////////////////////////////////////////////////// + /////// Specific Function of this Class /////////// + //////////////////////////////////////////////////// + public: + // Cylindric plastic + void AddMicroball(double R, + double Theta, + double Phi, + string Shape); + + G4LogicalVolume* BuildSquareDetector(); + G4LogicalVolume* BuildCylindricalDetector(); + + private: + G4LogicalVolume* m_SquareDetector; + G4LogicalVolume* m_CylindricalDetector; + + //////////////////////////////////////////////////// + ////// Inherite from NPS::VDetector class ///////// + //////////////////////////////////////////////////// + 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 + // Initialize all Scorer used by the MUST2Array + void InitializeScorers() ; + + // Associated Scorer + G4MultiFunctionalDetector* m_MicroballScorer ; + //////////////////////////////////////////////////// + ///////////Event class to store Data//////////////// + //////////////////////////////////////////////////// + private: + TMicroballData* m_Event ; + + //////////////////////////////////////////////////// + ///////////////Private intern Data////////////////// + //////////////////////////////////////////////////// + private: // Geometry + // Detector Coordinate + vector<double> m_R; + vector<double> m_Theta; + vector<double> m_Phi; + + // Shape type + vector<string> m_Shape ; + + // Visualisation Attribute + G4VisAttributes* m_VisSquare; + G4VisAttributes* m_VisCylinder; + + // Needed for dynamic loading of the library + public: + static NPS::VDetector* Construct(); +}; +#endif diff --git a/Projects/Lassa/Analysis.cxx b/Projects/Lassa/Analysis.cxx index 3e560153cc647bbaa08f67b73bb2711174b7f2bf..bf7b08e47f50a1ba756838a76bea29a1867c46c1 100644 --- a/Projects/Lassa/Analysis.cxx +++ b/Projects/Lassa/Analysis.cxx @@ -88,10 +88,12 @@ void Analysis::TreatEvent(){ if(Lassa->ThickSi_E.size()>0) InitialEnergy_Lassa = InitialEnergy; double phi_in = acos(InitialConditions->GetMomentumDirectionX(0)/sin(InitialConditions->GetThetaCM(0)*deg)); - ECM_initial = alpha->GetEnergyCM(InitialEnergy, InitialConditions->GetThetaCM(0)*deg, phi_in, BetaCM); + ECM_initial = helium3->GetEnergyCM(InitialEnergy, InitialConditions->GetThetaCM(0)*deg, phi_in, BetaCM); + ThetaCM = helium3->GetThetaCM(InitialEnergy, InitialConditions->GetThetaCM(0)*deg, phi_in, BetaCM)/deg; + ThetaLabInitial = InitialConditions->GetThetaLab_WorldFrame(0); if(Lassa->ThickSi_E.size()>0){ - ECM_initial_Lassa = alpha->GetEnergyCM(InitialEnergy_Lassa, InitialConditions->GetThetaCM(0)*deg, phi_in, BetaCM); + ECM_initial_Lassa = helium3->GetEnergyCM(InitialEnergy_Lassa, InitialConditions->GetThetaCM(0)*deg, phi_in, BetaCM); } else ECM_initial_Lassa = -100; ///////////////////////////LOOP on Lassa Hit////////////////////////////////// @@ -162,9 +164,11 @@ void Analysis::TreatEvent(){ if(fabs(InitialEnergy-ELab_nucl)>EDelta) ELab_nucl = -100; if(ELab>0){ - ECM = alpha->GetEnergyCM(ELab, ThetaLab, PhiLab, BetaCM); + ECM = helium3->GetEnergyCM(ELab, ThetaLab, PhiLab, BetaCM); + } + else{ + ECM = -100; } - else ECM = -100; ThetaLab = ThetaLab/deg; PhiLab = PhiLab/deg; @@ -192,8 +196,10 @@ void Analysis::InitOutputBranch() { RootOutput::getInstance()->GetTree()->Branch("ThicknessCsI",&ThicknessCsI,"ThicknessCsI/D"); RootOutput::getInstance()->GetTree()->Branch("ELab",&ELab,"ELab/D"); RootOutput::getInstance()->GetTree()->Branch("ECM",&ECM,"ECM/D"); + RootOutput::getInstance()->GetTree()->Branch("ThetaCM",&ThetaCM,"ThetaCM/D"); RootOutput::getInstance()->GetTree()->Branch("ELab_nucl",&ELab_nucl,"ELab_nucl/D"); RootOutput::getInstance()->GetTree()->Branch("ThetaLab",&ThetaLab,"ThetaLab/D"); + RootOutput::getInstance()->GetTree()->Branch("ThetaLabInitial",&ThetaLabInitial,"ThetaLabInitial/D"); RootOutput::getInstance()->GetTree()->Branch("PhiLab",&PhiLab,"PhiLab/D"); RootOutput::getInstance()->GetTree()->Branch("InitialEnergy",&InitialEnergy,"InitialEnergy/D"); RootOutput::getInstance()->GetTree()->Branch("InitialEnergy_Lassa",&InitialEnergy_Lassa,"InitialEnergy_Lassa/D"); @@ -219,8 +225,10 @@ void Analysis::ReInitValue(){ E_CsI =-100; ELab = -100; ECM = -100; + ThetaCM = -100; ELab_nucl = -100; ThetaLab = -100; + ThetaLabInitial = -100; PhiLab = -100; X = -100; Y = -100; diff --git a/Projects/Lassa/Analysis.h b/Projects/Lassa/Analysis.h index 14ccdd9f335b1c89db89468fca13a917794d255d..0f7e35d245136b6ef613a4678b0ca3eebd103d97 100644 --- a/Projects/Lassa/Analysis.h +++ b/Projects/Lassa/Analysis.h @@ -45,11 +45,13 @@ class Analysis: public NPL::VAnalysis{ private: double ELab; double ECM; + double ThetaCM; double ELab_nucl; double E_ThickSi; double E_CsI; double PhiLab; double ThetaLab; + double ThetaLabInitial; double X,Y,Z; double TelescopeNumber; double thresholdEnergy; diff --git a/Projects/Lassa/RunToTreat.txt b/Projects/Lassa/RunToTreat.txt index e13a324518cca0d05be9944222d179618b3206c2..3d9e6f20bc0cedce806456aa34c8f76eb5735907 100755 --- a/Projects/Lassa/RunToTreat.txt +++ b/Projects/Lassa/RunToTreat.txt @@ -1,7 +1,7 @@ TTreeName SimulatedTree RootFileName - ../../Outputs/Simulation/e09042_alphasource_nucl.root - %../../Outputs/Simulation/lassa_pid_d.root - %../../Outputs/Simulation/lassa_pid_t.root + %../../Outputs/Simulation/e09042_3Hesource_nucl.root + %../../Outputs/Simulation/one_lassa_proton_multi.root + ../../Outputs/Simulation/test.root diff --git a/Projects/macros/GeometricalEfficiency.C b/Projects/macros/GeometricalEfficiency.C index 67ee4183bd70ab6246e9da0a2e96c93b9af8b594..1c0e74e57c580bbcb2501fad84a193244dc587a6 100644 --- a/Projects/macros/GeometricalEfficiency.C +++ b/Projects/macros/GeometricalEfficiency.C @@ -48,7 +48,7 @@ using namespace std; -void GeometricalEfficiency(const char * fname = "hiraU_flat_p_nucl"){ +void GeometricalEfficiency(const char * fname = "e09042_alphasource_nucl"){ // Open output ROOT file from NPTool simulation run TString path = gSystem->Getenv("NPTOOL"); path += "/Outputs/Simulation/"; @@ -68,10 +68,10 @@ void GeometricalEfficiency(const char * fname = "hiraU_flat_p_nucl"){ tree->SetBranchStatus("InteractionCoordinates", true); // Prepare histograms - TH1F *hDetecTheta = new TH1F("hDetecTheta", "DetecTheta", 180, 0, 180); - TH1F *hDetecThetaCM = new TH1F("hDetecThetaCM", "hDetecThetaCM", 180, 0, 180); - TH1F *hEmittTheta = new TH1F("hEmittTheta", "EmittTheta", 180, 0, 180); - TH1F *hEmittThetaCM = new TH1F("hEmittThetaCM", "hEmittThetaCM", 180, 0, 180); + TH1F *hDetecTheta = new TH1F("hDetecTheta", "DetecTheta", 180, 0, 90); + TH1F *hDetecThetaCM = new TH1F("hDetecThetaCM", "hDetecThetaCM", 180, 0, 90); + TH1F *hEmittTheta = new TH1F("hEmittTheta", "EmittTheta", 180, 0, 90); + TH1F *hEmittThetaCM = new TH1F("hEmittThetaCM", "hEmittThetaCM", 180, 0, 90); // Read the TTree int nentries = tree->GetEntries(); @@ -100,10 +100,10 @@ void GeometricalEfficiency(const char * fname = "hiraU_flat_p_nucl"){ TCanvas *c = new TCanvas("c", "efficiency",800,800); c->SetTopMargin(0.01); c->SetRightMargin(0.03); - TH1F *hEfficiency = new TH1F("hEfficiency", "Efficiency", 180, 0, 180); - hEfficiency->Divide(hDetecTheta, hEmittTheta, 100, 1); + TH1F *hEfficiency = new TH1F("hEfficiency", "Efficiency", 180, 0, 90); + hEfficiency->Divide(hDetecTheta, hEmittTheta, 1, 1); hEfficiency->GetXaxis()->SetTitle("#Theta (deg)"); - hEfficiency->GetYaxis()->SetTitle("#epsilon (%)"); + hEfficiency->GetYaxis()->SetTitle("#epsilon"); hEfficiency->Draw(); TCanvas* c4 = new TCanvas("c4", "CM Frame",800,800); @@ -111,13 +111,13 @@ void GeometricalEfficiency(const char * fname = "hiraU_flat_p_nucl"){ c4->SetRightMargin(0.03); TH1F* SolidACM = new TH1F(*hDetecThetaCM); SolidACM->Sumw2(); - TF1* C = new TF1("C",Form("1. /(2*%f*sin(x*%f/180.)*1*%f/180)",M_PI,M_PI,M_PI),0,180); + TF1* C = new TF1("C",Form("1./(2*%f*sin(x*%f/180.)*1*%f/180)",M_PI,M_PI,M_PI),0,90); SolidACM->Divide(hEmittThetaCM); SolidACM->Divide(C,1); SolidACM->Draw(); SolidACM->GetXaxis()->SetTitle("#theta_{CM} (deg)"); SolidACM->GetYaxis()->SetTitle("d#Omega (sr) "); - TF1* f = new TF1("f",Form("2 * %f * sin(x*%f/180.) *1*%f/180.",M_PI,M_PI,M_PI),0,180); + TF1* f = new TF1("f",Form("2 * %f * sin(x*%f/180.) *1*%f/180.",M_PI,M_PI,M_PI),0,90); f->Draw("SAME"); c4->Update();