From e08abb109885eac967afc57211f559c4babeed43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Alcindor?= <valerian@MacBook-Pro-de-Valerian.local> Date: Tue, 16 Oct 2018 15:16:33 +0200 Subject: [PATCH] Adding a beam dump detector --- NPLib/Detectors/beam_dump/CMakeLists.txt | 6 + NPLib/Detectors/beam_dump/Tbeam_dumpData.cxx | 79 +++++ NPLib/Detectors/beam_dump/Tbeam_dumpData.h | 104 ++++++ .../Detectors/beam_dump/Tbeam_dumpPhysics.cxx | 328 ++++++++++++++++++ NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.h | 179 ++++++++++ .../Detectors/beam_dump/Tbeam_dumpSpectra.cxx | 174 ++++++++++ NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.h | 62 ++++ 7 files changed, 932 insertions(+) create mode 100755 NPLib/Detectors/beam_dump/CMakeLists.txt create mode 100755 NPLib/Detectors/beam_dump/Tbeam_dumpData.cxx create mode 100755 NPLib/Detectors/beam_dump/Tbeam_dumpData.h create mode 100755 NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.cxx create mode 100755 NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.h create mode 100755 NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.cxx create mode 100755 NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.h diff --git a/NPLib/Detectors/beam_dump/CMakeLists.txt b/NPLib/Detectors/beam_dump/CMakeLists.txt new file mode 100755 index 000000000..fa831276c --- /dev/null +++ b/NPLib/Detectors/beam_dump/CMakeLists.txt @@ -0,0 +1,6 @@ +add_custom_command(OUTPUT Tbeam_dumpPhysicsDict.cxx COMMAND ../../scripts/build_dict.sh Tbeam_dumpPhysics.h Tbeam_dumpPhysicsDict.cxx Tbeam_dumpPhysics.rootmap libNPbeam_dump.dylib DEPENDS Tbeam_dumpPhysics.h) +add_custom_command(OUTPUT Tbeam_dumpDataDict.cxx COMMAND ../../scripts/build_dict.sh Tbeam_dumpData.h Tbeam_dumpDataDict.cxx Tbeam_dumpData.rootmap libNPbeam_dump.dylib DEPENDS Tbeam_dumpData.h) +add_library(NPbeam_dump SHARED Tbeam_dumpSpectra.cxx Tbeam_dumpData.cxx Tbeam_dumpPhysics.cxx Tbeam_dumpDataDict.cxx Tbeam_dumpPhysicsDict.cxx ) +target_link_libraries(NPbeam_dump ${ROOT_LIBRARIES} NPCore) +install(FILES Tbeam_dumpData.h Tbeam_dumpPhysics.h Tbeam_dumpSpectra.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}) + diff --git a/NPLib/Detectors/beam_dump/Tbeam_dumpData.cxx b/NPLib/Detectors/beam_dump/Tbeam_dumpData.cxx new file mode 100755 index 000000000..494469974 --- /dev/null +++ b/NPLib/Detectors/beam_dump/Tbeam_dumpData.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: valerian contact address: girardalcindor@ganil.fr * + * * + * Creation Date : November 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold beam_dump Raw data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ +#include "Tbeam_dumpData.h" + +#include <iostream> +#include <fstream> +#include <sstream> +#include <string> +using namespace std; + +ClassImp(Tbeam_dumpData) + + +////////////////////////////////////////////////////////////////////// +Tbeam_dumpData::Tbeam_dumpData() { +} + + + +////////////////////////////////////////////////////////////////////// +Tbeam_dumpData::~Tbeam_dumpData() { +} + + + +////////////////////////////////////////////////////////////////////// +void Tbeam_dumpData::Clear() { + // Energy + fbeam_dump_E_DetectorNbr.clear(); + fbeam_dump_Energy.clear(); + // Time + fbeam_dump_T_DetectorNbr.clear(); + fbeam_dump_Time.clear(); +} + + + +////////////////////////////////////////////////////////////////////// +void Tbeam_dumpData::Dump() const { + // This method is very useful for debuging and worth the dev. + cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [Tbeam_dumpData::Dump()] XXXXXXXXXXXXXXXXX" << endl; + + // Energy + size_t mysize = fbeam_dump_E_DetectorNbr.size(); + cout << "beam_dump_E_Mult: " << mysize << endl; + + for (size_t i = 0 ; i < mysize ; i++){ + cout << "DetNbr: " << fbeam_dump_E_DetectorNbr[i] + << " Energy: " << fbeam_dump_Energy[i]; + } + + // Time + mysize = fbeam_dump_T_DetectorNbr.size(); + cout << "beam_dump_T_Mult: " << mysize << endl; + + for (size_t i = 0 ; i < mysize ; i++){ + cout << "DetNbr: " << fbeam_dump_T_DetectorNbr[i] + << " Time: " << fbeam_dump_Time[i]; + } +} diff --git a/NPLib/Detectors/beam_dump/Tbeam_dumpData.h b/NPLib/Detectors/beam_dump/Tbeam_dumpData.h new file mode 100755 index 000000000..6b7a71b6d --- /dev/null +++ b/NPLib/Detectors/beam_dump/Tbeam_dumpData.h @@ -0,0 +1,104 @@ +#ifndef __beam_dumpDATA__ +#define __beam_dumpDATA__ +/***************************************************************************** + * 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: valerian contact address: girardalcindor@ganil.fr * + * * + * Creation Date : November 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold beam_dump Raw data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// STL +#include <vector> +using namespace std; + +// ROOT +#include "TObject.h" + +class Tbeam_dumpData : public TObject { + ////////////////////////////////////////////////////////////// + // data members are hold into vectors in order + // to allow multiplicity treatment + private: + // Energy + vector<UShort_t> fbeam_dump_E_DetectorNbr; + vector<Double_t> fbeam_dump_Energy; + + // Time + vector<UShort_t> fbeam_dump_T_DetectorNbr; + vector<Double_t> fbeam_dump_Time; + + + ////////////////////////////////////////////////////////////// + // Constructor and destructor + public: + Tbeam_dumpData(); + ~Tbeam_dumpData(); + + + ////////////////////////////////////////////////////////////// + // 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 SetEnergy(const UShort_t& DetNbr,const Double_t& Energy){ + fbeam_dump_E_DetectorNbr.push_back(DetNbr); + fbeam_dump_Energy.push_back(Energy); + };//! + + // Time + inline void SetTime(const UShort_t& DetNbr,const Double_t& Time) { + fbeam_dump_T_DetectorNbr.push_back(DetNbr); + fbeam_dump_Time.push_back(Time); + };//! + + + ////////////////////// GETTERS //////////////////////// + // Energy + inline UShort_t GetMultEnergy() const + {return fbeam_dump_E_DetectorNbr.size();} + inline UShort_t GetE_DetectorNbr(const unsigned int &i) const + {return fbeam_dump_E_DetectorNbr[i];}//! + inline Double_t Get_Energy(const unsigned int &i) const + {return fbeam_dump_Energy[i];}//! + + // Time + inline UShort_t GetMultTime() const + {return fbeam_dump_T_DetectorNbr.size();} + inline UShort_t GetT_DetectorNbr(const unsigned int &i) const + {return fbeam_dump_T_DetectorNbr[i];}//! + inline Double_t Get_Time(const unsigned int &i) const + {return fbeam_dump_Time[i];}//! + + + ////////////////////////////////////////////////////////////// + // Required for ROOT dictionnary + ClassDef(Tbeam_dumpData,1) // beam_dumpData structure +}; + +#endif diff --git a/NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.cxx b/NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.cxx new file mode 100755 index 000000000..8f67aa3bf --- /dev/null +++ b/NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.cxx @@ -0,0 +1,328 @@ +/***************************************************************************** + * 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: valerian contact address: girardalcindor@ganil.fr * + * * + * Creation Date : November 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold beam_dump Treated data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +#include "Tbeam_dumpPhysics.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(Tbeam_dumpPhysics) + + + /////////////////////////////////////////////////////////////////////////// +Tbeam_dumpPhysics::Tbeam_dumpPhysics() + : m_EventData(new Tbeam_dumpData), + m_PreTreatedData(new Tbeam_dumpData), + 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 Tbeam_dumpPhysics::AddDetector(double R, double Theta, double Phi, double thickness){ + // Compute the TVector3 corresponding + TVector3 Pos(R*sin(Theta)*cos(Phi),R*sin(Theta)*sin(Phi),R*cos(Theta)); + // Call the cartesian method + m_NumberOfDetectors++; +} + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::BuildSimplePhysicalEvent() { + BuildPhysicalEvent(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::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 Tbeam_dumpPhysics::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("beam_dump/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("beam_dump/TIME"+NPL::itoa(m_EventData->GetT_DetectorNbr(i)),m_EventData->Get_Time(i)); + m_PreTreatedData->SetTime(m_EventData->GetT_DetectorNbr(i), Time); + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::ReadAnalysisConfig() { + bool ReadingStatus = false; + + // path to file + string FileName = "./configs/Configbeam_dump.dat"; + + // open analysis config file + ifstream AnalysisConfigFile; + AnalysisConfigFile.open(FileName.c_str()); + + if (!AnalysisConfigFile.is_open()) { + cout << " No Configbeam_dump.dat found: Default parameter loaded for Analayis " << FileName << endl; + return; + } + cout << " Loading user parameter for Analysis from Configbeam_dump.dat " << endl; + + // Save it in a TAsciiFile + TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig(); + asciiConfig->AppendLine("%%% Configbeam_dump.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 = "Configbeam_dump"; + 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 Tbeam_dumpPhysics::Clear() { + DetectorNumber.clear(); + Energy.clear(); + Time.clear(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::ReadConfiguration(NPL::InputParser parser) { + vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("beam_dump"); + if(NPOptionManager::getInstance()->GetVerboseLevel()) + cout << "//// " << blocks.size() << " detectors found " << endl; + + vector<string> sphe = {"R","Theta","Phi","Thickness"}; + + for(unsigned int i = 0 ; i < blocks.size() ; i++){ + if(blocks[i]->HasTokenList(sphe)){ + if(NPOptionManager::getInstance()->GetVerboseLevel()) + cout << endl << "//// beam_dump " << 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 Thickness = blocks[i]->GetDouble("Thickness", "micrometer"); + AddDetector(R,Theta,Phi,Thickness); + } + else{ + cout << "ERROR: check your input file formatting " << endl; + exit(1); + } + } +} + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::InitSpectra() { + m_Spectra = new Tbeam_dumpSpectra(m_NumberOfDetectors); +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::FillSpectra() { + m_Spectra -> FillRawSpectra(m_EventData); + m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData); + m_Spectra -> FillPhysicsSpectra(m_EventPhysics); +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::CheckSpectra() { + m_Spectra->CheckSpectra(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::ClearSpectra() { + // To be done +} + + + +/////////////////////////////////////////////////////////////////////////// +map< string , TH1*> Tbeam_dumpPhysics::GetSpectra() { + if(m_Spectra) + return m_Spectra->GetMapHisto(); + else{ + map< string , TH1*> empty; + return empty; + } +} + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::WriteSpectra() { + m_Spectra->WriteSpectra(); +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::AddParameterToCalibrationManager() { + CalibrationManager* Cal = CalibrationManager::getInstance(); + for (int i = 0; i < m_NumberOfDetectors; ++i) { + Cal->AddParameter("beam_dump", "D"+ NPL::itoa(i+1)+"_ENERGY","beam_dump_D"+ NPL::itoa(i+1)+"_ENERGY"); + Cal->AddParameter("beam_dump", "D"+ NPL::itoa(i+1)+"_TIME","beam_dump_D"+ NPL::itoa(i+1)+"_TIME"); + } +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::InitializeRootInputRaw() { + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchStatus("beam_dump", true ); + inputChain->SetBranchAddress("beam_dump", &m_EventData ); +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::InitializeRootInputPhysics() { + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchAddress("beam_dump", &m_EventPhysics); +} + + + +/////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpPhysics::InitializeRootOutput() { + TTree* outputTree = RootOutput::getInstance()->GetTree(); + outputTree->Branch("beam_dump", "Tbeam_dumpPhysics", &m_EventPhysics); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// Construct Method to be pass to the DetectorFactory // +//////////////////////////////////////////////////////////////////////////////// +NPL::VDetector* Tbeam_dumpPhysics::Construct() { + return (NPL::VDetector*) new Tbeam_dumpPhysics(); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// Registering the construct method to the factory // +//////////////////////////////////////////////////////////////////////////////// +extern "C"{ +class proxy_beam_dump{ + public: + proxy_beam_dump(){ + NPL::DetectorFactory::getInstance()->AddToken("beam_dump","beam_dump"); + NPL::DetectorFactory::getInstance()->AddDetector("beam_dump",Tbeam_dumpPhysics::Construct); + } +}; + +proxy_beam_dump p_beam_dump; +} + diff --git a/NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.h b/NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.h new file mode 100755 index 000000000..692504507 --- /dev/null +++ b/NPLib/Detectors/beam_dump/Tbeam_dumpPhysics.h @@ -0,0 +1,179 @@ +#ifndef Tbeam_dumpPHYSICS_H +#define Tbeam_dumpPHYSICS_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: valerian contact address: girardalcindor@ganil.fr * + * * + * Creation Date : November 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold beam_dump Treated data * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// C++ headers +#include <vector> +#include <map> +#include <string> +using namespace std; + +// ROOT headers +#include "TObject.h" +#include "TH1.h" +#include "TVector3.h" +// NPTool headers +#include "Tbeam_dumpData.h" +#include "Tbeam_dumpSpectra.h" +#include "NPCalibrationManager.h" +#include "NPVDetector.h" +#include "NPInputParser.h" +// forward declaration +class Tbeam_dumpSpectra; + + + +class Tbeam_dumpPhysics : public TObject, public NPL::VDetector { + ////////////////////////////////////////////////////////////// + // constructor and destructor + public: + Tbeam_dumpPhysics(); + ~Tbeam_dumpPhysics() {}; + + + ////////////////////////////////////////////////////////////// + // 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(double R, double Theta, double Phi, double Thickness); + + ////////////////////////////////////////////////////////////// + // 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 Tbeam_dumpSpectra class + // instantiate the Tbeam_dumpSpectra 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 beam_dump 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 Tbeam_dumpData object to Tbeam_dumpPhysics. + // needed for online analysis for example + void SetRawDataPointer(Tbeam_dumpData* rawDataPointer) {m_EventData = rawDataPointer;} + + // objects are not written in the TTree + private: + Tbeam_dumpData* m_EventData; //! + Tbeam_dumpData* m_PreTreatedData; //! + Tbeam_dumpPhysics* m_EventPhysics; //! + + // getters for raw and pre-treated data object + public: + Tbeam_dumpData* GetRawData() const {return m_EventData;} + Tbeam_dumpData* 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: + Tbeam_dumpSpectra* m_Spectra; // ! + + // spectra getter + public: + map<string, TH1*> GetSpectra(); + + // Static constructor to be passed to the Detector Factory + public: + static NPL::VDetector* Construct(); + + ClassDef(Tbeam_dumpPhysics,1) // beam_dumpPhysics structure +}; +#endif diff --git a/NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.cxx b/NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.cxx new file mode 100755 index 000000000..23b26b145 --- /dev/null +++ b/NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.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: valerian contact address: girardalcindor@ganil.fr * + * * + * Creation Date : November 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold beam_dump Spectra * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// class header +#include "Tbeam_dumpSpectra.h" + +// STL +#include <iostream> +#include <string> +using namespace std; + +// NPTool header +#include "NPOptionManager.h" + + + +//////////////////////////////////////////////////////////////////////////////// +Tbeam_dumpSpectra::Tbeam_dumpSpectra() + : fNumberOfDetectors(0) { + SetName("beam_dump"); +} + + + +//////////////////////////////////////////////////////////////////////////////// +Tbeam_dumpSpectra::Tbeam_dumpSpectra(unsigned int NumberOfDetectors) { + if(NPOptionManager::getInstance()->GetVerboseLevel()>0) + cout << "************************************************" << endl + << "Tbeam_dumpSpectra : Initalizing control spectra for " + << NumberOfDetectors << " Detectors" << endl + << "************************************************" << endl ; + SetName("beam_dump"); + fNumberOfDetectors = NumberOfDetectors; + + InitRawSpectra(); + InitPreTreatedSpectra(); + InitPhysicsSpectra(); +} + + + +//////////////////////////////////////////////////////////////////////////////// +Tbeam_dumpSpectra::~Tbeam_dumpSpectra() { +} + + + +//////////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpSpectra::InitRawSpectra() { + static string name; + for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors + // Energy + name = "beam_dump"+NPL::itoa(i+1)+"_ENERGY_RAW"; + AddHisto1D(name, name, 4096, 0, 16384, "beam_dump/RAW"); + // Time + name = "beam_dump"+NPL::itoa(i+1)+"_TIME_RAW"; + AddHisto1D(name, name, 4096, 0, 16384, "beam_dump/RAW"); + } // end loop on number of detectors +} + + + +//////////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpSpectra::InitPreTreatedSpectra() { + static string name; + for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors + // Energy + name = "beam_dump"+NPL::itoa(i+1)+"_ENERGY_CAL"; + AddHisto1D(name, name, 500, 0, 25, "beam_dump/CAL"); + // Time + name = "beam_dump"+NPL::itoa(i+1)+"_TIME_CAL"; + AddHisto1D(name, name, 500, 0, 25, "beam_dump/CAL"); + + + } // end loop on number of detectors +} + + + +//////////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpSpectra::InitPhysicsSpectra() { + static string name; + // Kinematic Plot + name = "beam_dump_ENERGY_TIME"; + AddHisto2D(name, name, 500, 0, 500, 500, 0, 50, "beam_dump/PHY"); +} + + + +//////////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpSpectra::FillRawSpectra(Tbeam_dumpData* RawData) { + static string name; + static string family; + + // Energy + unsigned int sizeE = RawData->GetMultEnergy(); + for (unsigned int i = 0; i < sizeE; i++) { + name = "beam_dump"+NPL::itoa(RawData->GetE_DetectorNbr(i))+"_ENERGY_RAW"; + family = "beam_dump/RAW"; + + FillSpectra(family,name,RawData->Get_Energy(i)); + } + + // Time + unsigned int sizeT = RawData->GetMultTime(); + for (unsigned int i = 0; i < sizeT; i++) { + name = "beam_dump"+NPL::itoa(RawData->GetT_DetectorNbr(i))+"_TIME_RAW"; + family = "beam_dump/RAW"; + + FillSpectra(family,name,RawData->Get_Time(i)); + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpSpectra::FillPreTreatedSpectra(Tbeam_dumpData* PreTreatedData) { + static string name; + static string family; + + // Energy + unsigned int sizeE = PreTreatedData->GetMultEnergy(); + for (unsigned int i = 0; i < sizeE; i++) { + name = "beam_dump"+NPL::itoa(PreTreatedData->GetE_DetectorNbr(i))+"_ENERGY_CAL"; + family = "beam_dump/CAL"; + + FillSpectra(family,name,PreTreatedData->Get_Energy(i)); + } + + // Time + unsigned int sizeT = PreTreatedData->GetMultTime(); + for (unsigned int i = 0; i < sizeT; i++) { + name = "beam_dump"+NPL::itoa(PreTreatedData->GetT_DetectorNbr(i))+"_TIME_CAL"; + family = "beam_dump/CAL"; + + FillSpectra(family,name,PreTreatedData->Get_Time(i)); + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +void Tbeam_dumpSpectra::FillPhysicsSpectra(Tbeam_dumpPhysics* Physics) { + static string name; + static string family; + family= "beam_dump/PHY"; + + // Energy vs time + unsigned int sizeE = Physics->Energy.size(); + for(unsigned int i = 0 ; i < sizeE ; i++){ + name = "beam_dump_ENERGY_TIME"; + FillSpectra(family,name,Physics->Energy[i],Physics->Time[i]); + } +} + diff --git a/NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.h b/NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.h new file mode 100755 index 000000000..32fd0f4a0 --- /dev/null +++ b/NPLib/Detectors/beam_dump/Tbeam_dumpSpectra.h @@ -0,0 +1,62 @@ +#ifndef Tbeam_dumpSPECTRA_H +#define Tbeam_dumpSPECTRA_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: valerian contact address: girardalcindor@ganil.fr * + * * + * Creation Date : November 2017 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold beam_dump Spectra * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// NPLib headers +#include "NPVSpectra.h" +#include "Tbeam_dumpData.h" +#include "Tbeam_dumpPhysics.h" + +// Forward Declaration +class Tbeam_dumpPhysics; + + +class Tbeam_dumpSpectra : public VSpectra { + ////////////////////////////////////////////////////////////// + // constructor and destructor + public: + Tbeam_dumpSpectra(); + Tbeam_dumpSpectra(unsigned int NumberOfDetectors); + ~Tbeam_dumpSpectra(); + + ////////////////////////////////////////////////////////////// + // Initialization methods + private: + void InitRawSpectra(); + void InitPreTreatedSpectra(); + void InitPhysicsSpectra(); + + ////////////////////////////////////////////////////////////// + // Filling methods + public: + void FillRawSpectra(Tbeam_dumpData*); + void FillPreTreatedSpectra(Tbeam_dumpData*); + void FillPhysicsSpectra(Tbeam_dumpPhysics*); + + ////////////////////////////////////////////////////////////// + // Detector parameters + private: + unsigned int fNumberOfDetectors; +}; + +#endif -- GitLab