diff --git a/Inputs/DetectorConfiguration/ForwardArray.detector b/Inputs/DetectorConfiguration/ForwardArray.detector new file mode 100644 index 0000000000000000000000000000000000000000..0b537297b0878ffd0aa7f8ebdc091cb0f9fd5279 --- /dev/null +++ b/Inputs/DetectorConfiguration/ForwardArray.detector @@ -0,0 +1,15 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Target + THICKNESS= 10 micrometer + RADIUS= 5 mm + MATERIAL= CD2 + ANGLE= 0 deg + X= 0 mm + Y= 0 mm + Z= 0 mm +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ForwardArray + POS= 0 0 120 mm + ROT= 230 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + diff --git a/NPLib/Detectors/ForwardArray/CMakeLists.txt b/NPLib/Detectors/ForwardArray/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e862d3b6485541e33b43ec4e89ca9aabfdf183a --- /dev/null +++ b/NPLib/Detectors/ForwardArray/CMakeLists.txt @@ -0,0 +1,6 @@ +add_custom_command(OUTPUT TForwardArrayPhysicsDict.cxx COMMAND ../../scripts/build_dict.sh TForwardArrayPhysics.h TForwardArrayPhysicsDict.cxx TForwardArrayPhysics.rootmap libNPForwardArray.dylib DEPENDS TForwardArrayPhysics.h) +add_custom_command(OUTPUT TForwardArrayDataDict.cxx COMMAND ../../scripts/build_dict.sh TForwardArrayData.h TForwardArrayDataDict.cxx TForwardArrayData.rootmap libNPForwardArray.dylib DEPENDS TForwardArrayData.h) +add_library(NPForwardArray SHARED TForwardArraySpectra.cxx TForwardArrayData.cxx TForwardArrayPhysics.cxx TForwardArrayDataDict.cxx TForwardArrayPhysicsDict.cxx ) +target_link_libraries(NPForwardArray ${ROOT_LIBRARIES} NPCore) +install(FILES TForwardArrayData.h TForwardArrayPhysics.h TForwardArraySpectra.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}) + diff --git a/NPLib/Detectors/ForwardArray/TForwardArrayData.cxx b/NPLib/Detectors/ForwardArray/TForwardArrayData.cxx new file mode 100644 index 0000000000000000000000000000000000000000..301ae19a17613baa576533bfb580944821b4ae09 --- /dev/null +++ b/NPLib/Detectors/ForwardArray/TForwardArrayData.cxx @@ -0,0 +1,79 @@ +/***************************************************************************** + * Copyright (C) 2009-2017 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 : May 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold ForwardArray Raw data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ +#include "TForwardArrayData.h" + +#include <iostream> +#include <fstream> +#include <sstream> +#include <string> +using namespace std; + +ClassImp(TForwardArrayData) + + +////////////////////////////////////////////////////////////////////// +TForwardArrayData::TForwardArrayData() { +} + + + +////////////////////////////////////////////////////////////////////// +TForwardArrayData::~TForwardArrayData() { +} + + + +////////////////////////////////////////////////////////////////////// +void TForwardArrayData::Clear() { + // Energy + fForwardArray_E_DetectorNbr.clear(); + fForwardArray_Energy.clear(); + // Time + fForwardArray_T_DetectorNbr.clear(); + fForwardArray_Time.clear(); +} + + + +////////////////////////////////////////////////////////////////////// +void TForwardArrayData::Dump() const { + // This method is very useful for debuging and worth the dev. + cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TForwardArrayData::Dump()] XXXXXXXXXXXXXXXXX" << endl; + + // Energy + size_t mysize = fForwardArray_E_DetectorNbr.size(); + cout << "ForwardArray_E_Mult: " << mysize << endl; + + for (size_t i = 0 ; i < mysize ; i++){ + cout << "DetNbr: " << fForwardArray_E_DetectorNbr[i] + << " Energy: " << fForwardArray_Energy[i]; + } + + // Time + mysize = fForwardArray_T_DetectorNbr.size(); + cout << "ForwardArray_T_Mult: " << mysize << endl; + + for (size_t i = 0 ; i < mysize ; i++){ + cout << "DetNbr: " << fForwardArray_T_DetectorNbr[i] + << " Time: " << fForwardArray_Time[i]; + } +} diff --git a/NPLib/Detectors/ForwardArray/TForwardArrayData.h b/NPLib/Detectors/ForwardArray/TForwardArrayData.h new file mode 100644 index 0000000000000000000000000000000000000000..96ec4fd502db46cefc429121c20590094a8f0d91 --- /dev/null +++ b/NPLib/Detectors/ForwardArray/TForwardArrayData.h @@ -0,0 +1,114 @@ +#ifndef __ForwardArrayDATA__ +#define __ForwardArrayDATA__ +/***************************************************************************** + * Copyright (C) 2009-2017 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 : May 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold ForwardArray Raw data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// STL +#include <vector> +using namespace std; + +// ROOT +#include "TObject.h" + +class TForwardArrayData : public TObject { + ////////////////////////////////////////////////////////////// + // data members are hold into vectors in order + // to allow multiplicity treatment + private: + // Energy + vector<UShort_t> fForwardArray_E_DetectorNbr; + vector<Double_t> fForwardArray_Energy; + + // Time + vector<UShort_t> fForwardArray_T_DetectorNbr; + vector<Double_t> fForwardArray_Time; + + + ////////////////////////////////////////////////////////////// + // Constructor and destructor + public: + TForwardArrayData(); + virtual ~TForwardArrayData(); + + + ////////////////////////////////////////////////////////////// + // 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) + {fForwardArray_E_DetectorNbr.push_back(DetNbr);} //! + inline void Set_Energy(const Double_t& Energy) + {fForwardArray_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) + {fForwardArray_T_DetectorNbr.push_back(DetNbr);} //! + inline void Set_Time(const Double_t& Time) + {fForwardArray_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 fForwardArray_E_DetectorNbr.size();} + inline UShort_t GetE_DetectorNbr(const unsigned int &i) const + {return fForwardArray_E_DetectorNbr[i];}//! + inline Double_t Get_Energy(const unsigned int &i) const + {return fForwardArray_Energy[i];}//! + + // Time + inline UShort_t GetMultTime() const + {return fForwardArray_T_DetectorNbr.size();} + inline UShort_t GetT_DetectorNbr(const unsigned int &i) const + {return fForwardArray_T_DetectorNbr[i];}//! + inline Double_t Get_Time(const unsigned int &i) const + {return fForwardArray_Time[i];}//! + + + ////////////////////////////////////////////////////////////// + // Required for ROOT dictionnary + ClassDef(TForwardArrayData,1) // ForwardArrayData structure +}; + +#endif diff --git a/NPLib/Detectors/ForwardArray/TForwardArrayPhysics.cxx b/NPLib/Detectors/ForwardArray/TForwardArrayPhysics.cxx new file mode 100644 index 0000000000000000000000000000000000000000..fd7aa748e3640343e7f76647435c2eb68c7f9d22 --- /dev/null +++ b/NPLib/Detectors/ForwardArray/TForwardArrayPhysics.cxx @@ -0,0 +1,358 @@ +/***************************************************************************** + * Copyright (C) 2009-2017 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 : May 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold ForwardArray Treated data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +#include "TForwardArrayPhysics.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" +#include "NPOptionManager.h" + +// ROOT +#include "TChain.h" + +ClassImp(TForwardArrayPhysics) + + +/////////////////////////////////////////////////////////////////////////// +TForwardArrayPhysics::TForwardArrayPhysics() + : m_EventData(new TForwardArrayData), + m_PreTreatedData(new TForwardArrayData), + m_EventPhysics(this), + m_Spectra(0), + m_E_RAW_Threshold(0), // adc channels + m_E_Threshold(0), // MeV + m_NumberOfDetectors(0) { +} + +/////////////////////////////////////////////////////////////////////////// +/// A usefull method to bundle all operation to add a detector +void TForwardArrayPhysics::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 TForwardArrayPhysics::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 TForwardArrayPhysics::BuildSimplePhysicalEvent() { + BuildPhysicalEvent(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::BuildPhysicalEvent() { + // apply thresholds and calibration + PreTreat(); + + // match energy and time together + unsigned int mysizeE = m_PreTreatedData->GetMultEnergy(); + unsigned int mysizeT = m_PreTreatedData->GetMultTime(); + for (UShort_t e = 0; e < mysizeE ; e++) { + for (UShort_t t = 0; t < mysizeT ; 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 TForwardArrayPhysics::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 + unsigned int mysize = m_EventData->GetMultEnergy(); + for (UShort_t i = 0; i < mysize ; ++i) { + if (m_EventData->Get_Energy(i) > m_E_RAW_Threshold) { + Double_t Energy = Cal->ApplyCalibration("ForwardArray/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 + mysize = m_EventData->GetMultTime(); + for (UShort_t i = 0; i < mysize; ++i) { + Double_t Time= Cal->ApplyCalibration("ForwardArray/TIME"+NPL::itoa(m_EventData->GetT_DetectorNbr(i)),m_EventData->Get_Time(i)); + m_PreTreatedData->SetTime(m_EventData->GetT_DetectorNbr(i), Time); + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::ReadAnalysisConfig() { + bool ReadingStatus = false; + + // path to file + string FileName = "./configs/ConfigForwardArray.dat"; + + // open analysis config file + ifstream AnalysisConfigFile; + AnalysisConfigFile.open(FileName.c_str()); + + if (!AnalysisConfigFile.is_open()) { + cout << " No ConfigForwardArray.dat found: Default parameter loaded for Analayis " << FileName << endl; + return; + } + cout << " Loading user parameter for Analysis from ConfigForwardArray.dat " << endl; + + // Save it in a TAsciiFile + TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig(); + asciiConfig->AppendLine("%%% ConfigForwardArray.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 = "ConfigForwardArray"; + 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 TForwardArrayPhysics::Clear() { + DetectorNumber.clear(); + Energy.clear(); + Time.clear(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::ReadConfiguration(NPL::InputParser parser) { + vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("ForwardArray"); + 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 << "//// ForwardArray " << i+1 << endl; + + TVector3 Pos = blocks[i]->GetTVector3("POS","mm"); + string Shape = blocks[i]->GetString("Shape"); + AddDetector(Pos,Shape); + } + else if(blocks[i]->HasTokenList(sphe)){ + if(NPOptionManager::getInstance()->GetVerboseLevel()) + cout << endl << "//// ForwardArray " << 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 TForwardArrayPhysics::InitSpectra() { + m_Spectra = new TForwardArraySpectra(m_NumberOfDetectors); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::FillSpectra() { + m_Spectra -> FillRawSpectra(m_EventData); + m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData); + m_Spectra -> FillPhysicsSpectra(m_EventPhysics); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::CheckSpectra() { + m_Spectra->CheckSpectra(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::ClearSpectra() { + // To be done +} + + + +/////////////////////////////////////////////////////////////////////////// +map< string , TH1*> TForwardArrayPhysics::GetSpectra() { + if(m_Spectra) + return m_Spectra->GetMapHisto(); + else{ + map< string , TH1*> empty; + return empty; + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +/*vector<TCanvas*> TForwardArrayPhysics::GetCanvas() { + if(m_Spectra) + return m_Spectra->GetCanvas(); + else{ + vector<TCanvas*> empty; + return empty; + } +}*/ + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::WriteSpectra() { + m_Spectra->WriteSpectra(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::AddParameterToCalibrationManager() { + CalibrationManager* Cal = CalibrationManager::getInstance(); + for (int i = 0; i < m_NumberOfDetectors; ++i) { + Cal->AddParameter("ForwardArray", "D"+ NPL::itoa(i+1)+"_ENERGY","ForwardArray_D"+ NPL::itoa(i+1)+"_ENERGY"); + Cal->AddParameter("ForwardArray", "D"+ NPL::itoa(i+1)+"_TIME","ForwardArray_D"+ NPL::itoa(i+1)+"_TIME"); + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::InitializeRootInputRaw() { + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchStatus("ForwardArray", true ); + inputChain->SetBranchAddress("ForwardArray", &m_EventData ); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::InitializeRootInputPhysics() { + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchAddress("ForwardArray", &m_EventPhysics); +} + + + +/////////////////////////////////////////////////////////////////////////// +void TForwardArrayPhysics::InitializeRootOutput() { + TTree* outputTree = RootOutput::getInstance()->GetTree(); + outputTree->Branch("ForwardArray", "TForwardArrayPhysics", &m_EventPhysics); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// Construct Method to be pass to the DetectorFactory // +//////////////////////////////////////////////////////////////////////////////// +NPL::VDetector* TForwardArrayPhysics::Construct() { + return (NPL::VDetector*) new TForwardArrayPhysics(); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// Registering the construct method to the factory // +//////////////////////////////////////////////////////////////////////////////// +extern "C"{ +class proxy_ForwardArray{ + public: + proxy_ForwardArray(){ + NPL::DetectorFactory::getInstance()->AddToken("ForwardArray","ForwardArray"); + NPL::DetectorFactory::getInstance()->AddDetector("ForwardArray",TForwardArrayPhysics::Construct); + } +}; + +proxy_ForwardArray p_ForwardArray; +} + diff --git a/NPLib/Detectors/ForwardArray/TForwardArrayPhysics.h b/NPLib/Detectors/ForwardArray/TForwardArrayPhysics.h new file mode 100644 index 0000000000000000000000000000000000000000..2cf7fb2d14153f7d5e46772156a0404074be3a32 --- /dev/null +++ b/NPLib/Detectors/ForwardArray/TForwardArrayPhysics.h @@ -0,0 +1,182 @@ +#ifndef TForwardArrayPHYSICS_H +#define TForwardArrayPHYSICS_H +/***************************************************************************** + * Copyright (C) 2009-2017 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 : May 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold ForwardArray 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" +#include "TVector3.h" +// NPTool headers +#include "TForwardArrayData.h" +#include "TForwardArraySpectra.h" +#include "NPCalibrationManager.h" +#include "NPVDetector.h" +#include "NPInputParser.h" +// forward declaration +class TForwardArraySpectra; + + + +class TForwardArrayPhysics : public TObject, public NPL::VDetector { + ////////////////////////////////////////////////////////////// + // constructor and destructor + public: + TForwardArrayPhysics(); + ~TForwardArrayPhysics() {}; + + + ////////////////////////////////////////////////////////////// + // 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; + + /// 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(NPL::InputParser); + + // 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 TForwardArraySpectra class + // instantiate the TForwardArraySpectra 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 ForwardArray 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 TForwardArrayData object to TForwardArrayPhysics. + // needed for online analysis for example + void SetRawDataPointer(TForwardArrayData* rawDataPointer) {m_EventData = rawDataPointer;} + + // objects are not written in the TTree + private: + TForwardArrayData* m_EventData; //! + TForwardArrayData* m_PreTreatedData; //! + TForwardArrayPhysics* m_EventPhysics; //! + + // getters for raw and pre-treated data object + public: + TForwardArrayData* GetRawData() const {return m_EventData;} + TForwardArrayData* 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: + TForwardArraySpectra* 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(TForwardArrayPhysics,1) // ForwardArrayPhysics structure +}; +#endif diff --git a/NPLib/Detectors/ForwardArray/TForwardArraySpectra.cxx b/NPLib/Detectors/ForwardArray/TForwardArraySpectra.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e3969fc1c7c3e736dd01edc11f5681370c934629 --- /dev/null +++ b/NPLib/Detectors/ForwardArray/TForwardArraySpectra.cxx @@ -0,0 +1,174 @@ +/***************************************************************************** + * Copyright (C) 2009-2017 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 : May 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold ForwardArray Spectra * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// class header +#include "TForwardArraySpectra.h" + +// STL +#include <iostream> +#include <string> +using namespace std; + +// NPTool header +#include "NPOptionManager.h" + + + +//////////////////////////////////////////////////////////////////////////////// +TForwardArraySpectra::TForwardArraySpectra() + : fNumberOfDetectors(0) { + SetName("ForwardArray"); +} + + + +//////////////////////////////////////////////////////////////////////////////// +TForwardArraySpectra::TForwardArraySpectra(unsigned int NumberOfDetectors) { + if(NPOptionManager::getInstance()->GetVerboseLevel()>0) + cout << "************************************************" << endl + << "TForwardArraySpectra : Initalizing control spectra for " + << NumberOfDetectors << " Detectors" << endl + << "************************************************" << endl ; + SetName("ForwardArray"); + fNumberOfDetectors = NumberOfDetectors; + + InitRawSpectra(); + InitPreTreatedSpectra(); + InitPhysicsSpectra(); +} + + + +//////////////////////////////////////////////////////////////////////////////// +TForwardArraySpectra::~TForwardArraySpectra() { +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TForwardArraySpectra::InitRawSpectra() { + static string name; + for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors + // Energy + name = "ForwardArray"+NPL::itoa(i+1)+"_ENERGY_RAW"; + AddHisto1D(name, name, 4096, 0, 16384, "ForwardArray/RAW"); + // Time + name = "ForwardArray"+NPL::itoa(i+1)+"_TIME_RAW"; + AddHisto1D(name, name, 4096, 0, 16384, "ForwardArray/RAW"); + } // end loop on number of detectors +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TForwardArraySpectra::InitPreTreatedSpectra() { + static string name; + for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors + // Energy + name = "ForwardArray"+NPL::itoa(i+1)+"_ENERGY_CAL"; + AddHisto1D(name, name, 500, 0, 25, "ForwardArray/CAL"); + // Time + name = "ForwardArray"+NPL::itoa(i+1)+"_TIME_CAL"; + AddHisto1D(name, name, 500, 0, 25, "ForwardArray/CAL"); + + + } // end loop on number of detectors +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TForwardArraySpectra::InitPhysicsSpectra() { + static string name; + // Kinematic Plot + name = "ForwardArray_ENERGY_TIME"; + AddHisto2D(name, name, 500, 0, 500, 500, 0, 50, "ForwardArray/PHY"); +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TForwardArraySpectra::FillRawSpectra(TForwardArrayData* RawData) { + static string name; + static string family; + + // Energy + unsigned int sizeE = RawData->GetMultEnergy(); + for (unsigned int i = 0; i < sizeE; i++) { + name = "ForwardArray"+NPL::itoa(RawData->GetE_DetectorNbr(i))+"_ENERGY_RAW"; + family = "ForwardArray/RAW"; + + //GetHisto(family,name) -> Fill(RawData->Get_Energy(i)); + } + + // Time + unsigned int sizeT = RawData->GetMultTime(); + for (unsigned int i = 0; i < sizeT; i++) { + name = "ForwardArray"+NPL::itoa(RawData->GetT_DetectorNbr(i))+"_TIME_RAW"; + family = "ForwardArray/RAW"; + + //GetHisto(family,name) -> Fill(RawData->Get_Time(i)); + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TForwardArraySpectra::FillPreTreatedSpectra(TForwardArrayData* PreTreatedData) { + static string name; + static string family; + + // Energy + unsigned int sizeE = PreTreatedData->GetMultEnergy(); + for (unsigned int i = 0; i < sizeE; i++) { + name = "ForwardArray"+NPL::itoa(PreTreatedData->GetE_DetectorNbr(i))+"_ENERGY_CAL"; + family = "ForwardArray/CAL"; + + //GetHisto(family,name) -> Fill(PreTreatedData->Get_Energy(i)); + } + + // Time + unsigned int sizeT = PreTreatedData->GetMultTime(); + for (unsigned int i = 0; i < sizeT; i++) { + name = "ForwardArray"+NPL::itoa(PreTreatedData->GetT_DetectorNbr(i))+"_TIME_CAL"; + family = "ForwardArray/CAL"; + + //GetHisto(family,name) -> Fill(PreTreatedData->Get_Time(i)); + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +void TForwardArraySpectra::FillPhysicsSpectra(TForwardArrayPhysics* Physics) { + static string name; + static string family; + family= "ForwardArray/PHY"; + + // Energy vs time + unsigned int sizeE = Physics->Energy.size(); + for(unsigned int i = 0 ; i < sizeE ; i++){ + name = "ForwardArray_ENERGY_TIME"; + //GetHisto(family,name) -> Fill(Physics->Energy[i],Physics->Time[i]); + } +} + diff --git a/NPLib/Detectors/ForwardArray/TForwardArraySpectra.h b/NPLib/Detectors/ForwardArray/TForwardArraySpectra.h new file mode 100644 index 0000000000000000000000000000000000000000..6c36add1fdd365d82ac86e5b2cc8856d9250e07c --- /dev/null +++ b/NPLib/Detectors/ForwardArray/TForwardArraySpectra.h @@ -0,0 +1,62 @@ +#ifndef TForwardArraySPECTRA_H +#define TForwardArraySPECTRA_H +/***************************************************************************** + * Copyright (C) 2009-2017 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 : May 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold ForwardArray Spectra * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// NPLib headers +#include "NPVSpectra.h" +#include "TForwardArrayData.h" +#include "TForwardArrayPhysics.h" + +// Forward Declaration +class TForwardArrayPhysics; + + +class TForwardArraySpectra : public VSpectra { + ////////////////////////////////////////////////////////////// + // constructor and destructor + public: + TForwardArraySpectra(); + TForwardArraySpectra(unsigned int NumberOfDetectors); + ~TForwardArraySpectra(); + + ////////////////////////////////////////////////////////////// + // Initialization methods + private: + void InitRawSpectra(); + void InitPreTreatedSpectra(); + void InitPhysicsSpectra(); + + ////////////////////////////////////////////////////////////// + // Filling methods + public: + void FillRawSpectra(TForwardArrayData*); + void FillPreTreatedSpectra(TForwardArrayData*); + void FillPhysicsSpectra(TForwardArrayPhysics*); + + ////////////////////////////////////////////////////////////// + // Detector parameters + private: + unsigned int fNumberOfDetectors; +}; + +#endif diff --git a/NPSimulation/Detectors/ForwardArray/CMakeLists.txt b/NPSimulation/Detectors/ForwardArray/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e4d2997ccf68a2704a2dfa3b7528eb3d290f7c69 --- /dev/null +++ b/NPSimulation/Detectors/ForwardArray/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(NPSForwardArray SHARED ForwardArray.cc) +target_link_libraries(NPSForwardArray NPSCore ${ROOT_LIBRARIES} ${Geant4_LIBRARIES} ${NPLib_LIBRARIES} -lNPForwardArray) diff --git a/NPSimulation/Detectors/ForwardArray/ForwardArray.cc b/NPSimulation/Detectors/ForwardArray/ForwardArray.cc new file mode 100644 index 0000000000000000000000000000000000000000..09d7bd37f62ced265cad8a2ab31bcaabe31526f0 --- /dev/null +++ b/NPSimulation/Detectors/ForwardArray/ForwardArray.cc @@ -0,0 +1,365 @@ +/***************************************************************************** + * Copyright (C) 2009-2017 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 : May 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class describe ForwardArray 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 "ForwardArray.hh" +#include "CalorimeterScorers.hh" +#include "RootOutput.h" +#include "MaterialManager.hh" +#include "NPSDetectorFactory.hh" +#include "NPOptionManager.h" +#include "NPSHitsMap.hh" +// CLHEP header +#include "CLHEP/Random/RandGauss.h" + +using namespace std; +using namespace CLHEP; + + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +namespace ForwardArray_NS{ + // Energy and time Resolution + const double EnergyThreshold = 0.1*MeV; + const double ResoTime = 4.5*ns ; + const double ResoEnergy = 1.0*MeV ; + //const double Width = 100*mm ; + + const string Material = "BC400"; + const double Rmin=12.70*mm; + const double Rmax=64.26*mm; + const double Rmax_new=50.8*mm; + const double Thickness=4.33*mm; + const double Phimin=0; + const double Phimax=18.0; + const double R_PM=8.25*mm; + const double PMLength=33*mm; +} +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +// ForwardArray Specific Method +ForwardArray::ForwardArray(){ + m_Event = new TForwardArrayData() ; + m_ForwardArrayScorer = 0; + m_PieDetector = 0; + m_PhotoTube = 0; + + + // RGB Color + Transparency + m_VisSquare = new G4VisAttributes(G4Colour(192, 192, 192, 0.8)); + m_VisPM = new G4VisAttributes(G4Colour(0, 0, 0, 1)); + +} + +ForwardArray::~ForwardArray(){ +} +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +void ForwardArray::AddDetector(G4ThreeVector POS, double Rot){ + // 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_Rot.push_back(Rot); +} + + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +void ForwardArray::AddDetector(double R, double Theta, double Phi, double Rot){ + m_R.push_back(R); + m_Theta.push_back(Theta); + m_Phi.push_back(Phi); + m_Rot.push_back(Rot); +} + + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +G4LogicalVolume* ForwardArray::BuildPieVolume(){ + G4Tubs* pie = new G4Tubs("ForwardArray_Cyl",ForwardArray_NS::Rmin,ForwardArray_NS::Rmax,ForwardArray_NS::Thickness*0.5,ForwardArray_NS::Phimin*deg,ForwardArray_NS::Phimax*deg); + + G4Material* DetectorMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(ForwardArray_NS::Material); + m_PieDetector = new G4LogicalVolume(pie,DetectorMaterial,"logic_ForwardArray_pie",0,0,0); + m_PieDetector->SetVisAttributes(m_VisSquare); + m_PieDetector->SetSensitiveDetector(m_ForwardArrayScorer); + + return m_PieDetector; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +G4LogicalVolume* ForwardArray::BuildPhotoTube(){ + G4Tubs* PM = new G4Tubs("ForwardArray_PM",0,ForwardArray_NS::R_PM,ForwardArray_NS::PMLength*0.5,0,360*deg); + + G4Material* DetectorMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(ForwardArray_NS::Material); + m_PhotoTube = new G4LogicalVolume(PM,DetectorMaterial,"logic_ForwardArray_PM",0,0,0); + m_PhotoTube->SetVisAttributes(m_VisPM); + //m_PhotoTube->SetSensitiveDetector(m_ForwardArrayScorer); + + return m_PhotoTube; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +G4LogicalVolume* ForwardArray::BuildSmallVolume(){ + G4Tubs* pie = new G4Tubs("ForwardArray_Cyl",ForwardArray_NS::Rmin,ForwardArray_NS::Rmax_new,ForwardArray_NS::Thickness*0.5,ForwardArray_NS::Phimin*deg,ForwardArray_NS::Phimax*2*deg); + + G4Material* DetectorMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(ForwardArray_NS::Material); + m_PieDetector = new G4LogicalVolume(pie,DetectorMaterial,"logic_ForwardArray_pie",0,0,0); + m_PieDetector->SetVisAttributes(m_VisSquare); + m_PieDetector->SetSensitiveDetector(m_ForwardArrayScorer); + + return m_PieDetector; +} + +//....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 ForwardArray::ReadConfiguration(NPL::InputParser parser){ + vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("ForwardArray"); + if(NPOptionManager::getInstance()->GetVerboseLevel()) + cout << "//// " << blocks.size() << " detectors found " << endl; + + vector<string> cart = {"POS","ROT"}; + vector<string> sphe = {"R","Theta","Phi","ROT"}; + + for(unsigned int i = 0 ; i < blocks.size() ; i++){ + if(blocks[i]->HasTokenList(cart)){ + if(NPOptionManager::getInstance()->GetVerboseLevel()) + cout << endl << "//// ForwardArray " << i+1 << endl; + + G4ThreeVector Pos = NPS::ConvertVector(blocks[i]->GetTVector3("POS","mm")); + double Rot = blocks[i]->GetDouble("ROT","deg"); + AddDetector(Pos,Rot); + } + else if(blocks[i]->HasTokenList(sphe)){ + if(NPOptionManager::getInstance()->GetVerboseLevel()) + cout << endl << "//// ForwardArray " << i+1 << endl; + double R = blocks[i]->GetDouble("R","mm"); + double Theta = blocks[i]->GetDouble("Theta","deg"); + double Phi = blocks[i]->GetDouble("Phi","deg"); + double Rot = blocks[i]->GetDouble("ROT","deg"); + AddDetector(R,Theta,Phi,Rot); + } + else{ + cout << "ERROR: check your input file formatting " << endl; + exit(1); + } + } +} + + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +// Construct detector and inialise sensitive part. +// Called After DetecorConstruction::AddDetector Method +void ForwardArray::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()*ForwardArray_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(); + + + const G4double dangle = 18.*deg; + G4RotationMatrix* RotPM = new G4RotationMatrix; + RotPM->rotateY(90*deg); + RotPM->rotateZ(m_Rot[i]+dangle/2); + for(int j=0; j<16; j++){ + G4RotationMatrix* Rotz = new G4RotationMatrix; + Rotz->rotateZ(j*dangle+m_Rot[i]); + new G4PVPlacement(G4Transform3D(*Rotz,Det_pos), + BuildPieVolume(), + "ForwardArray",world,false,j+1,false); + + + G4double wXpm = (ForwardArray_NS::Rmax + ForwardArray_NS::PMLength/2) * cos(j*dangle+m_Rot[i]+dangle/2); + G4double wYpm = (ForwardArray_NS::Rmax + ForwardArray_NS::PMLength/2) * sin(j*dangle+m_Rot[i]+dangle/2); + G4double wZpm = m_R[i]+ForwardArray_NS::Thickness*0.5; + G4ThreeVector Det_PM = G4ThreeVector(wXpm, wYpm, wZpm); + + if(j>0)RotPM->rotateZ(dangle); + new G4PVPlacement(G4Transform3D(*RotPM,Det_PM), + BuildPhotoTube(), + "PhotoTube",world,false,j+1,false); + + + + } + + G4RotationMatrix* Rotz = new G4RotationMatrix; + Rotz->rotateZ(16*dangle+m_Rot[i]); + new G4PVPlacement(G4Transform3D(*Rotz,Det_pos), + BuildSmallVolume(), + "ForwardArray",world,false,17,false); + + G4double wXpm = (ForwardArray_NS::Rmax_new + ForwardArray_NS::PMLength/2) * cos(16*dangle+m_Rot[i]+dangle); + G4double wYpm = (ForwardArray_NS::Rmax_new + ForwardArray_NS::PMLength/2) * sin(16*dangle+m_Rot[i]+dangle); + G4double wZpm = m_R[i]+ForwardArray_NS::Thickness*0.5; + G4ThreeVector Det_PM = G4ThreeVector(wXpm, wYpm, wZpm); + RotPM->rotateZ(dangle+dangle/2); + new G4PVPlacement(G4Transform3D(*RotPM,Det_PM), + BuildPhotoTube(), + "PhotoTube",world,false,17,false); + + + + Rotz = new G4RotationMatrix; + Rotz->rotateZ(18*dangle+m_Rot[i]); + new G4PVPlacement(G4Transform3D(*Rotz,Det_pos), + BuildSmallVolume(), + "ForwardArray",world,false,18,false); + + wXpm = (ForwardArray_NS::Rmax_new + ForwardArray_NS::PMLength/2) * cos(18*dangle+m_Rot[i]+dangle); + wYpm = (ForwardArray_NS::Rmax_new + ForwardArray_NS::PMLength/2) * sin(18*dangle+m_Rot[i]+dangle); + wZpm = m_R[i]+ForwardArray_NS::Thickness*0.5; + Det_PM = G4ThreeVector(wXpm, wYpm, wZpm); + RotPM->rotateZ(2*dangle); + new G4PVPlacement(G4Transform3D(*RotPM,Det_PM), + BuildPhotoTube(), + "PhotoTube",world,false,18,false); + + + } +} +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +// Add Detector branch to the EventTree. +// Called After DetecorConstruction::AddDetector Method +void ForwardArray::InitializeRootOutput(){ + RootOutput *pAnalysis = RootOutput::getInstance(); + TTree *pTree = pAnalysis->GetTree(); + if(!pTree->FindBranch("ForwardArray")){ + pTree->Branch("ForwardArray", "TForwardArrayData", &m_Event) ; + } + pTree->SetBranchAddress("ForwardArray", &m_Event) ; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +// Read sensitive part and fill the Root tree. +// Called at in the EventAction::EndOfEventAvtion +void ForwardArray::ReadSensitive(const G4Event* event){ + m_Event->Clear(); + + /////////// + // Calorimeter scorer + NPS::HitsMap<G4double*>* CaloHitMap; + std::map<G4int, G4double**>::iterator Calo_itr; + + G4int CaloCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("ForwardArrayScorer/Calorimeter"); + CaloHitMap = (NPS::HitsMap<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); + double Energy = RandGauss::shoot(Info[0],ForwardArray_NS::ResoEnergy); + if(Energy>ForwardArray_NS::EnergyThreshold){ + double Time = RandGauss::shoot(Info[1],ForwardArray_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(); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//////////////////////////////////////////////////////////////// +void ForwardArray::InitializeScorers() { + // This check is necessary in case the geometry is reloaded + bool already_exist = false; + m_ForwardArrayScorer = CheckScorer("ForwardArrayScorer",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_ForwardArrayScorer->RegisterPrimitive(Calorimeter); + G4SDManager::GetSDMpointer()->AddNewDetector(m_ForwardArrayScorer) ; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//////////////////////////////////////////////////////////////////////////////// +// Construct Method to be pass to the DetectorFactory // +//////////////////////////////////////////////////////////////////////////////// +NPS::VDetector* ForwardArray::Construct(){ + return (NPS::VDetector*) new ForwardArray(); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//////////////////////////////////////////////////////////////////////////////// +// Registering the construct method to the factory // +//////////////////////////////////////////////////////////////////////////////// +extern"C" { + class proxy_nps_ForwardArray{ + public: + proxy_nps_ForwardArray(){ + NPS::DetectorFactory::getInstance()->AddToken("ForwardArray","ForwardArray"); + NPS::DetectorFactory::getInstance()->AddDetector("ForwardArray",ForwardArray::Construct); + } + }; + + proxy_nps_ForwardArray p_nps_ForwardArray; +} diff --git a/NPSimulation/Detectors/ForwardArray/ForwardArray.hh b/NPSimulation/Detectors/ForwardArray/ForwardArray.hh new file mode 100644 index 0000000000000000000000000000000000000000..e5044c4d4ad0248f4e9204e6c8575b1fe527eb75 --- /dev/null +++ b/NPSimulation/Detectors/ForwardArray/ForwardArray.hh @@ -0,0 +1,118 @@ +#ifndef ForwardArray_h +#define ForwardArray_h 1 +/***************************************************************************** + * Copyright (C) 2009-2017 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 : May 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class describe ForwardArray 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 "TForwardArrayData.h" +#include "NPInputParser.h" + + + +class ForwardArray : public NPS::VDetector{ + //////////////////////////////////////////////////// + /////// Default Constructor and Destructor ///////// + //////////////////////////////////////////////////// + public: + ForwardArray() ; + virtual ~ForwardArray() ; + + //////////////////////////////////////////////////// + /////// Specific Function of this Class /////////// + //////////////////////////////////////////////////// + public: + // Cartesian + void AddDetector(G4ThreeVector POS, double Rot); + // Spherical + void AddDetector(double R,double Theta,double Phi, double Rot); + + G4LogicalVolume* BuildPieVolume(); + G4LogicalVolume* BuildSmallVolume(); + G4LogicalVolume* BuildPhotoTube(); + + private: + G4LogicalVolume* m_PieDetector; + G4LogicalVolume* m_PhotoTube; + + //////////////////////////////////////////////////// + ////// Inherite from NPS::VDetector class ///////// + //////////////////////////////////////////////////// + public: + // Read stream at Configfile to pick-up parameters of detector (Position,...) + // Called in DetecorConstruction::ReadDetextorConfiguration Method + void ReadConfiguration(NPL::InputParser) ; + + // 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_ForwardArrayScorer ; + //////////////////////////////////////////////////// + ///////////Event class to store Data//////////////// + //////////////////////////////////////////////////// + private: + TForwardArrayData* m_Event ; + + //////////////////////////////////////////////////// + ///////////////Private intern Data////////////////// + //////////////////////////////////////////////////// + private: // Geometry + // Detector Coordinate + vector<double> m_R; + vector<double> m_Theta; + vector<double> m_Phi; + vector<double> m_Rot; + + + // Visualisation Attribute + G4VisAttributes* m_VisSquare; + G4VisAttributes* m_VisPM; + + // Needed for dynamic loading of the library + public: + static NPS::VDetector* Construct(); +}; +#endif diff --git a/Projects/ForwardArray/Analysis.cxx b/Projects/ForwardArray/Analysis.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d13d2f67548d72f759864c5be268eb6085ae973a --- /dev/null +++ b/Projects/ForwardArray/Analysis.cxx @@ -0,0 +1,68 @@ +/***************************************************************************** + * 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: XAUTHORX contact address: XMAILX * + * * + * Creation Date : XMONTHX XYEARX * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class describe ForwardArray analysis project * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + *****************************************************************************/ + +#include<iostream> +using namespace std; +#include"Analysis.h" +#include"NPAnalysisFactory.h" +#include"NPDetectorManager.h" +//////////////////////////////////////////////////////////////////////////////// +Analysis::Analysis(){ +} +//////////////////////////////////////////////////////////////////////////////// +Analysis::~Analysis(){ +} + +//////////////////////////////////////////////////////////////////////////////// +void Analysis::Init(){ + ForwardArray= (TForwardArrayPhysicsPhysics*) m_DetectorManager->GetDetector("ForwardArray"); +} + +//////////////////////////////////////////////////////////////////////////////// +void Analysis::TreatEvent(){ +} + +//////////////////////////////////////////////////////////////////////////////// +void Analysis::End(){ +} + + +//////////////////////////////////////////////////////////////////////////////// +// Construct Method to be pass to the DetectorFactory // +//////////////////////////////////////////////////////////////////////////////// +NPL::VAnalysis* Analysis::Construct(){ + return (NPL::VAnalysis*) new Analysis(); +} + +//////////////////////////////////////////////////////////////////////////////// +// Registering the construct method to the factory // +//////////////////////////////////////////////////////////////////////////////// +extern "C"{ +class proxy{ + public: + proxy(){ + NPL::AnalysisFactory::getInstance()->SetConstructor(Analysis::Construct); + } +}; + +proxy p; +} + diff --git a/Projects/ForwardArray/Analysis.h b/Projects/ForwardArray/Analysis.h new file mode 100644 index 0000000000000000000000000000000000000000..3b11154d7721fa61d71797db405138dd25f8556e --- /dev/null +++ b/Projects/ForwardArray/Analysis.h @@ -0,0 +1,42 @@ +#ifndef Analysis_h +#define Analysis_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: XAUTHORX contact address: XMAILX * + * * + * Creation Date : XMONTHX XYEARX * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class describe ForwardArray analysis project * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + *****************************************************************************/ + +#include"NPVAnalysis.h" +#include"TForwardArrayPhysics.h" +class Analysis: public NPL::VAnalysis{ + public: + Analysis(); + ~Analysis(); + + public: + void Init(); + void TreatEvent(); + void End(); + + static NPL::VAnalysis* Construct(); + + private: + TForwardArrayPhysics* ForwardArray; + +}; +#endif diff --git a/Projects/ForwardArray/CMakeLists.txt b/Projects/ForwardArray/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..22c74affdfc45019bdda2594f8439c52d4ab97ec --- /dev/null +++ b/Projects/ForwardArray/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required (VERSION 2.8) +# Setting the policy to match Cmake version +cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) +# include the default NPAnalysis cmake file +include("../../NPLib/ressources/CMake/NPAnalysis.cmake") diff --git a/Projects/ForwardArray/ForwardArray.detector b/Projects/ForwardArray/ForwardArray.detector new file mode 100644 index 0000000000000000000000000000000000000000..0414d21a55050dff662ede2fbc97d3ead1fe6c6f --- /dev/null +++ b/Projects/ForwardArray/ForwardArray.detector @@ -0,0 +1,25 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Target + THICKNESS= 10 micrometer + RADIUS= 20 mm + MATERIAL= CD2 + ANGLE= 0 deg + X= 0 mm + Y= 0 mm + Z= 0 mm +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ForwardArray + POS= 0 0 350 mm + Shape= Square +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ForwardArray + POS = 35 35 35 cm + Shape= Square +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ForwardArray + R= 350 mm + THETA= 90 deg + PHI= 63 deg + Shape= Cylindrical +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +