diff --git a/NPLib/Core/CMakeLists.txt b/NPLib/Core/CMakeLists.txt index f2692be7e2b0185daa4128f067559224f0fc6bf2..e90904f6406d8a1e28f2d745f220d7cfa0d74074 100644 --- a/NPLib/Core/CMakeLists.txt +++ b/NPLib/Core/CMakeLists.txt @@ -4,6 +4,6 @@ add_custom_command(OUTPUT NPDeltaSpectraDict.cxx COMMAND ${CMAKE_BINARY_DIR}/sc add_custom_command(OUTPUT NPVDetectorDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh NPVDetector.h NPVDetectorDict.cxx NPVDetector.rootmap libNPCore.so NPCoreLinkdef.h) #add_custom_command(OUTPUT NPVTreeReaderDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh NPVTreeReader.h NPVTreeReaderDict.cxx NPVTreeReader.rootmap libNPCore.so NPCoreLinkdef.h) #add_library(NPCore SHARED NPCore.cxx NPRandom.cxx NPVAnalysis.cxx NPAnalysisFactory.cxx NPCalibrationManager.cxx NPOptionManager.cxx RootOutput.cxx RootInput.cxx TAsciiFile.cxx TAsciiFileDict.cxx NPDeltaSpectraDict.cxx NPDetectorManager.cxx NPVTreeReader.cxx NPVTreeReaderDict.cxx NPVDetector.cxx NPVDetectorDict.cxx NPVSpectra.cxx NPDetectorFactory.cxx NPSpectraServer.cxx NPInputParser.cxx NPImage.cxx NPElog.cxx NPDeltaSpectra.cxx NPXmlParser.cxx) -add_library(NPCore SHARED NPCore.cxx NPRandom.cxx NPVAnalysis.cxx NPAnalysisFactory.cxx NPCalibrationManager.cxx NPOptionManager.cxx RootOutput.cxx RootInput.cxx TAsciiFile.cxx TAsciiFileDict.cxx NPDeltaSpectraDict.cxx NPDetectorManager.cxx NPVDetector.cxx NPVDetectorDict.cxx NPVTreeReader.cxx NPVSpectra.cxx NPDetectorFactory.cxx NPSpectraServer.cxx NPInputParser.cxx NPImage.cxx NPElog.cxx NPDeltaSpectra.cxx NPXmlParser.cxx) +add_library(NPCore SHARED NPCore.cxx NPRandom.cxx NPVAnalysis.cxx NPAnalysisFactory.cxx NPCalibrationManager.cxx NPOptionManager.cxx RootHistogramsCalib.cxx RootOutput.cxx RootInput.cxx TAsciiFile.cxx TAsciiFileDict.cxx NPDeltaSpectraDict.cxx NPDetectorManager.cxx NPVDetector.cxx NPVDetectorDict.cxx NPVTreeReader.cxx NPVSpectra.cxx NPDetectorFactory.cxx NPSpectraServer.cxx NPInputParser.cxx NPImage.cxx NPElog.cxx NPDeltaSpectra.cxx NPXmlParser.cxx) target_link_libraries(NPCore ${ROOT_LIBRARIES} -lTreePlayer -lXMLIO) -install(FILES NPCore.h NPVAnalysis.h NPAnalysisFactory.h NPRandom.h NPCalibrationManager.h NPOptionManager.h RootInput.h RootOutput.h TAsciiFile.h NPDetectorManager.h NPVTreeReader.h NPVDetector.h NPGlobalSystemOfUnits.h NPPhysicalConstants.h NPSystemOfUnits.h NPVSpectra.h NPDetectorFactory.h NPSpectraServer.h NPInputParser.h NPImage.h NPElog.h NPDeltaSpectra.h NPXmlParser.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}) +install(FILES NPCore.h NPVAnalysis.h NPAnalysisFactory.h NPRandom.h NPCalibrationManager.h NPOptionManager.h RootInput.h RootOutput.h RootHistogramsCalib.h TAsciiFile.h NPDetectorManager.h NPVTreeReader.h NPVDetector.h NPGlobalSystemOfUnits.h NPPhysicalConstants.h NPSystemOfUnits.h NPVSpectra.h NPDetectorFactory.h NPSpectraServer.h NPInputParser.h NPImage.h NPElog.h NPDeltaSpectra.h NPXmlParser.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}) diff --git a/NPLib/Core/NPDetectorManager.cxx b/NPLib/Core/NPDetectorManager.cxx index a666e1f237e84d22c3616c3dc1686ce9fed007ff..0a379cb8bfb21906e4e61bbe24498ae14e38b76e 100644 --- a/NPLib/Core/NPDetectorManager.cxx +++ b/NPLib/Core/NPDetectorManager.cxx @@ -22,93 +22,100 @@ #include "NPDetectorManager.h" // STL -#include <cstdlib> -#include <fstream> #include <iostream> +#include <sstream> +#include <fstream> +#include <cstdlib> #include <limits> #include <set> -#include <sstream> -#if __cplusplus > 199711L +#if __cplusplus > 199711L #include <chrono> #endif // NPL -#include "NPCalibrationManager.h" #include "NPDetectorFactory.h" -#include "NPInputParser.h" +#include "RootInput.h" #include "NPOptionManager.h" +#include "NPCalibrationManager.h" +#include "NPInputParser.h" #include "NPSystemOfUnits.h" -#include "RootInput.h" using namespace NPUNITS; -// Root -#include "TCanvas.h" +//Root +#include"TCanvas.h" #include "TROOT.h" /////////////////////////////////////////////////////////////////////////////// -// double NPL::DetectorManager::GetTargetThickness () {return m_TargetThickness;} +//double NPL::DetectorManager::GetTargetThickness () {return m_TargetThickness;} // Default Constructor -NPL::DetectorManager::DetectorManager() { +NPL::DetectorManager::DetectorManager(){ ROOT::EnableThreadSafety(); + //m_BuildPhysicalPtr = &NPL::VDetector::BuildPhysicalEvent; + //m_ClearEventPhysicsPtr = &NPL::VDetector::ClearEventPhysics; + //m_ClearEventDataPtr = &NPL::VDetector::ClearEventData ; m_BuildPhysicalPtr = &NPL::VDetector::BuildPhysicalEvent; - m_ClearEventPhysicsPtr = &NPL::VDetector::ClearEventPhysics; - m_ClearEventDataPtr = &NPL::VDetector::ClearEventData; + m_ClearEventPhysicsPtr = &NPL::VDetector::ClearEventPhysics; + m_ClearEventDataPtr = &NPL::VDetector::ClearEventData ; m_SetTreeReaderPtr = &NPL::VDetector::SetTreeReader; m_InitializeRootInputPhysicsPtr = &NPL::VDetector::InitializeRootInputPhysics; m_InitializeRootInputRawPtr = &NPL::VDetector::InitializeRootInputRaw; m_InitializeRootOutputPtr = &NPL::VDetector::InitializeRootOutput; - m_FillSpectra = NULL; - m_CheckSpectra = NULL; + m_InitializeRootHistogramsCalibPtr = &NPL::VDetector::InitializeRootHistogramsCalib; + m_FillHistogramsCalibPtr = &NPL::VDetector::FillHistogramsCalib; + m_WriteHistogramsCalibPtr = &NPL::VDetector::WriteHistogramsCalib; + m_FillSpectra = NULL; + m_CheckSpectra = NULL; m_SpectraServer = NULL; - if (NPOptionManager::getInstance()->GetGenerateHistoOption()) { - m_FillSpectra = &NPL::VDetector::FillSpectra; - if (NPOptionManager::getInstance()->GetCheckHistoOption()) - m_CheckSpectra = &NPL::VDetector::CheckSpectra; + if(NPOptionManager::getInstance()->GetGenerateHistoOption()){ + m_FillSpectra = &NPL::VDetector::FillSpectra ; + if(NPOptionManager::getInstance()->GetCheckHistoOption()) + m_CheckSpectra = &NPL::VDetector::CheckSpectra ; } - m_CryoTarget = false; - m_TargetThickness = 0; - m_TargetAngle = 0; - m_TargetRadius = 0; - m_TargetDensity = 0; - m_TargetDensity = 0; - m_FrontDeformation = 0; - m_FrontThickness = 0; - m_FrontRadius = 0; - m_FrontMaterial = ""; - m_BackDeformation = 0; - m_BackRadius = 0; - m_BackThickness = 0; - m_BackMaterial = ""; - m_FrameRadius = 0; + m_CryoTarget=false; + m_TargetThickness = 0 ; + m_TargetAngle = 0 ; + m_TargetRadius = 0 ; + m_TargetDensity = 0 ; + m_TargetDensity = 0 ; + m_FrontDeformation = 0 ; + m_FrontThickness = 0 ; + m_FrontRadius = 0 ; + m_FrontMaterial = "" ; + m_BackDeformation = 0 ; + m_BackRadius = 0 ; + m_BackThickness = 0 ; + m_BackMaterial = "" ; + m_FrameRadius = 0 ; m_FrameThickness = 0; - m_FrontCone = 0; - m_BackCone = 0; - m_FrameMaterial = ""; - m_ShieldInnerRadius = 0; - m_ShieldOuterRadius = 0; - m_ShieldBottomLength = 0; - m_ShieldTopLength = 0; - m_ShieldFrontRadius = 0; - m_ShieldBackRadius = 0; - m_ShieldMaterial = ""; - m_RootOutput = RootOutput::getInstance(); + m_FrontCone = 0 ; + m_BackCone = 0 ; + m_FrameMaterial = "" ; + m_ShieldInnerRadius = 0 ; + m_ShieldOuterRadius = 0 ; + m_ShieldBottomLength = 0 ; + m_ShieldTopLength = 0 ; + m_ShieldFrontRadius = 0 ; + m_ShieldBackRadius = 0 ; + m_ShieldMaterial = "" ; + m_RootOutput=RootOutput::getInstance(); } + /////////////////////////////////////////////////////////////////////////////// // Default Desstructor -NPL::DetectorManager::~DetectorManager() { +NPL::DetectorManager::~DetectorManager(){ #if __cplusplus > 199711L && NPMULTITHREADING StopThread(); #endif - if (m_SpectraServer) + if(m_SpectraServer) m_SpectraServer->Destroy(); } /////////////////////////////////////////////////////////////////////////////// // Read stream at ConfigFile and pick-up Token declaration of Detector -void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { - std::cout << "\033[1;36m"; +void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { + std::cout << "\033[1;36m" ; // Instantiate the Calibration Manager // All The detector will then add to it their parameter (see AddDetector) @@ -126,89 +133,83 @@ void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { //////////////////////////////////////////// //////////// Search for Target ///////////// //////////////////////////////////////////// - std::vector<NPL::InputBlock*> starget = parser.GetAllBlocksWithToken("Target"); - std::vector<NPL::InputBlock*> ctarget = parser.GetAllBlocksWithToken("CryogenicTarget"); + std::vector<NPL::InputBlock*> starget = parser.GetAllBlocksWithToken("Target"); + std::vector<NPL::InputBlock*> ctarget = parser.GetAllBlocksWithToken("CryogenicTarget"); - if (starget.size() == 1) { - if (NPOptionManager::getInstance()->GetVerboseLevel()) { + if(starget.size()==1){ + if(NPOptionManager::getInstance()->GetVerboseLevel()){ std::cout << "//// TARGET ////" << std::endl; std::cout << "//// Solid Target found " << std::endl; } - std::vector<std::string> token = {"Thickness", "Radius", "Material", "Angle", "X", "Y", "Z"}; - if (starget[0]->HasTokenList(token)) { - m_TargetThickness = starget[0]->GetDouble("Thickness", "micrometer"); - m_TargetAngle = starget[0]->GetDouble("Angle", "deg"); + std::vector<std::string> token = {"Thickness","Radius","Material","Angle","X","Y","Z"}; + if(starget[0]->HasTokenList(token)){ + m_TargetThickness = starget[0]->GetDouble("Thickness","micrometer"); + m_TargetAngle = starget[0]->GetDouble("Angle","deg"); m_TargetMaterial = starget[0]->GetString("Material"); - m_TargetX = starget[0]->GetDouble("X", "mm"); - m_TargetY = starget[0]->GetDouble("Y", "mm"); - m_TargetZ = starget[0]->GetDouble("Z", "mm"); + m_TargetX = starget[0]->GetDouble("X","mm"); + m_TargetY = starget[0]->GetDouble("Y","mm"); + m_TargetZ = starget[0]->GetDouble("Z","mm"); } - else { + else{ std::cout << "ERROR: Target token list incomplete, check your input file" << std::endl; exit(1); } } - else if (ctarget.size() == 1) { - if (NPOptionManager::getInstance()->GetVerboseLevel()) - std::cout << "//// Cryogenic Target found " << std::endl; + else if(ctarget.size()==1){ + if(NPOptionManager::getInstance()->GetVerboseLevel()) + std::cout<< "//// Cryogenic Target found " << std::endl; m_CryoTarget = true; - std::vector<std::string> CoreToken = {"NominalThickness", "Material", "Density", "Radius", "Angle", "X", "Y", "Z"}; - std::vector<std::string> FrontToken = {"FrontDeformation", "FrontThickness", "FrontRadius", "FrontMaterial"}; - std::vector<std::string> BackToken = {"BackDeformation", "BackThickness", "BackRadius", "BackMaterial"}; - std::vector<std::string> FrameToken = {"FrameRadius", "FrameThickness", "FrontCone", "BackCone", "FrameMaterial"}; - std::vector<std::string> ShieldToken = {"ShieldInnerRadius", - "ShieldOuterRadius" - "ShieldBottomLength", - "ShieldTopLength", - "ShieldFrontRadius", - "ShieldBackRadius", - "ShieldMaterial"}; - - if (ctarget[0]->HasTokenList(CoreToken)) { - // Target - m_TargetThickness = ctarget[0]->GetDouble("NominalThickness", "micrometer"); - m_TargetAngle = ctarget[0]->GetDouble("Angle", "deg"); + std::vector<std::string> CoreToken = {"NominalThickness","Material","Density","Radius","Angle","X","Y","Z"}; + std::vector<std::string> FrontToken = {"FrontDeformation","FrontThickness","FrontRadius","FrontMaterial"}; + std::vector<std::string> BackToken = {"BackDeformation","BackThickness","BackRadius","BackMaterial"}; + std::vector<std::string> FrameToken = {"FrameRadius","FrameThickness","FrontCone","BackCone","FrameMaterial"}; + std::vector<std::string> ShieldToken = {"ShieldInnerRadius","ShieldOuterRadius""ShieldBottomLength","ShieldTopLength","ShieldFrontRadius","ShieldBackRadius","ShieldMaterial"}; + + if(ctarget[0]->HasTokenList(CoreToken)){ + // Target + m_TargetThickness = ctarget[0]->GetDouble("NominalThickness","micrometer"); + m_TargetAngle = ctarget[0]->GetDouble("Angle","deg"); m_TargetMaterial = ctarget[0]->GetString("Material"); - m_TargetDensity = ctarget[0]->GetDouble("Density", "g/cm3"); - m_TargetRadius = ctarget[0]->GetDouble("Radius", "mm"); - m_TargetX = ctarget[0]->GetDouble("X", "mm"); - m_TargetY = ctarget[0]->GetDouble("Y", "mm"); - m_TargetZ = ctarget[0]->GetDouble("Z", "mm"); - m_TargetDensity = ctarget[0]->GetDouble("Density", "g/cm3"); - m_TargetRadius = ctarget[0]->GetDouble("Radius", "mm"); + m_TargetDensity = ctarget[0]->GetDouble("Density","g/cm3"); + m_TargetRadius = ctarget[0]->GetDouble("Radius","mm"); + m_TargetX = ctarget[0]->GetDouble("X","mm"); + m_TargetY = ctarget[0]->GetDouble("Y","mm"); + m_TargetZ = ctarget[0]->GetDouble("Z","mm"); + m_TargetDensity = ctarget[0]->GetDouble("Density","g/cm3"); + m_TargetRadius = ctarget[0]->GetDouble("Radius","mm"); // Front Window - m_FrontDeformation = ctarget[0]->GetDouble("FrontDeformation", "mm"); - m_FrontThickness = ctarget[0]->GetDouble("FrontThickness", "micrometer"); - m_FrontRadius = ctarget[0]->GetDouble("FrontRadius", "mm"); + m_FrontDeformation = ctarget[0]->GetDouble("FrontDeformation","mm"); + m_FrontThickness = ctarget[0]->GetDouble("FrontThickness","micrometer"); + m_FrontRadius = ctarget[0]->GetDouble("FrontRadius","mm"); m_FrontMaterial = ctarget[0]->GetString("FrontMaterial"); // Back Window - m_BackDeformation = ctarget[0]->GetDouble("BackDeformation", "mm"); - m_BackRadius = ctarget[0]->GetDouble("BackRadius", "mm"); - m_BackThickness = ctarget[0]->GetDouble("BackThickness", "micrometer"); + m_BackDeformation = ctarget[0]->GetDouble("BackDeformation","mm"); + m_BackRadius = ctarget[0]->GetDouble("BackRadius","mm"); + m_BackThickness = ctarget[0]->GetDouble("BackThickness","micrometer"); m_BackMaterial = ctarget[0]->GetString("BackMaterial"); // Cell Frame - m_FrameRadius = ctarget[0]->GetDouble("FrameRadius", "mm"); - m_FrameThickness = ctarget[0]->GetDouble("FrameThickness", "mm"); - m_FrontCone = ctarget[0]->GetDouble("FrontCone", "deg"); - m_BackCone = ctarget[0]->GetDouble("BackCone", "deg"); + m_FrameRadius = ctarget[0]->GetDouble("FrameRadius","mm"); + m_FrameThickness = ctarget[0]->GetDouble("FrameThickness","mm"); + m_FrontCone = ctarget[0]->GetDouble("FrontCone","deg"); + m_BackCone = ctarget[0]->GetDouble("BackCone","deg"); m_FrameMaterial = ctarget[0]->GetString("FrameMaterial"); // Heat Shield - m_ShieldInnerRadius = ctarget[0]->GetDouble("ShieldInnerRadius", "mm"); - m_ShieldOuterRadius = ctarget[0]->GetDouble("ShieldOuterRadius", "mm"); - m_ShieldBottomLength = ctarget[0]->GetDouble("ShieldBottomLength", "mm"); - m_ShieldTopLength = ctarget[0]->GetDouble("ShieldTopLength", "mm"); - m_ShieldFrontRadius = ctarget[0]->GetDouble("ShieldFrontRadius", "mm"); - m_ShieldBackRadius = ctarget[0]->GetDouble("ShieldBackRadius", "mm"); + m_ShieldInnerRadius = ctarget[0]->GetDouble("ShieldInnerRadius","mm"); + m_ShieldOuterRadius = ctarget[0]->GetDouble("ShieldOuterRadius","mm"); + m_ShieldBottomLength = ctarget[0]->GetDouble("ShieldBottomLength","mm"); + m_ShieldTopLength = ctarget[0]->GetDouble("ShieldTopLength","mm"); + m_ShieldFrontRadius = ctarget[0]->GetDouble("ShieldFrontRadius","mm"); + m_ShieldBackRadius = ctarget[0]->GetDouble("ShieldBackRadius","mm"); m_ShieldMaterial = ctarget[0]->GetString("ShieldMaterial"); } - else { - std::cout << "ERROR: CryogenicTarget token list incomplete, check your input file" << std::endl; + else{ + std::cout<< "ERROR: CryogenicTarget token list incomplete, check your input file" << std::endl; } } - else { + else{ std::cout << "ERROR: One and only one target shall be declared in your detector file" << std::endl; } @@ -216,18 +217,23 @@ void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { /////////// Search for Detectors /////////// //////////////////////////////////////////// // Get the list of main token + std::cout<< "test detec mana 1" << std::endl; std::vector<std::string> token = parser.GetAllBlocksToken(); + std::cout<< "test detec mana 2 " << token.size() << std::endl; // Look for detectors among them - for (unsigned int i = 0; i < token.size(); i++) { + for(unsigned int i = 0 ; i < token.size() ; i++){ VDetector* detector = theFactory->Construct(token[i]); VTreeReader* Reader = theFactory->ConstructReader(token[i]); - if (detector != NULL && check.find(token[i]) == check.end()) { - if (NPOptionManager::getInstance()->GetVerboseLevel()) { + std::cout << "test detec mana 3 " << detector << std::endl; + if(detector!=NULL && check.find(token[i])==check.end()){ + if(NPOptionManager::getInstance()->GetVerboseLevel()){ std::cout << "/////////////////////////////////////////" << std::endl; - std::cout << "//// Adding Detector " << token[i] << std::endl; + std::cout << "//// Adding Detector " << token[i] << std::endl; } + std::cout << "TEST COUCOU" << std::endl; detector->ReadConfiguration(parser); - if (NPOptionManager::getInstance()->GetVerboseLevel()) + std::cout << "TEST COUCOU 2" << std::endl; + if(NPOptionManager::getInstance()->GetVerboseLevel()) std::cout << "/////////////////////////////////////////" << std::endl; // Add array to the VDetector Vector @@ -235,17 +241,31 @@ void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { AddDetectorReader(token[i], Reader); check.insert(token[i]); } - else if (detector != NULL) { + else if(detector!=NULL){ delete detector; delete Reader; } + //std::cout << "Reader adress : " << Reader << std::endl; + //if(Reader!=NULL && check.find(token[i])==check.end()){ + // if(NPOptionManager::getInstance()->GetVerboseLevel()){ + // std::cout << "/////////////////////////////////////////" << std::endl; + // std::cout << "//// Adding Reader " << token[i] << std::endl; + // std::cout << "/////////////////////////////////////////" << std::endl; + // } + // // Add array to the VDetector Vector + // AddDetectorReader(token[i], Reader); + // //check.insert(token[i]); + //} + //else if(Reader!=NULL) + // delete Reader; } + std::cout << "Readersize : " << m_DetectorReader.size() << std::endl; // Now That the detector lib are loaded, we can instantiate the root input std::string runToReadfileName = NPOptionManager::getInstance()->GetRunToReadFile(); RootInput::getInstance(runToReadfileName); // If Requiered, they can also instiantiate their control histogramm - if (NPOptionManager::getInstance()->GetGenerateHistoOption()) + if(NPOptionManager::getInstance()->GetGenerateHistoOption()) InitSpectra(); // The calibration Manager got all the parameter added, so it can load them from the calibration file @@ -253,154 +273,207 @@ void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { // Start the thread if multithreading supported #if __cplusplus > 199711L && NPMULTITHREADING + std::cout << "Test init POOL ////////////////////////////////////////////////////////////" << std::endl; InitThreadPool(); #endif return; } -void NPL::DetectorManager::SetTreeReader(TTreeReader* TreeReader) { - static std::map<std::string, VDetector*>::iterator it; - static std::map<std::string, VDetector*>::iterator begin = m_Detector.begin(); - static std::map<std::string, VDetector*>::iterator end = m_Detector.end(); - - for (it = begin; it != end; ++it) { +void NPL::DetectorManager::SetTreeReader(TTreeReader* TreeReader){ + static std::map<std::string,VDetector*>::iterator it; + static std::map<std::string,VDetector*>::iterator begin=m_Detector.begin(); + static std::map<std::string,VDetector*>::iterator end= m_Detector.end(); + + for (it =begin; it != end; ++it) { (it->second->*m_SetTreeReaderPtr)(TreeReader); } + } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::BuildPhysicalEvent() { +void NPL::DetectorManager::BuildPhysicalEvent(){ + //std::cout << "Test Build ////////////////////////////////////////////////////////////" << std::endl; #if __cplusplus > 199711L && NPMULTITHREADING - // add new job - m_mtx.lock(); - m_Ready.flip(); - m_mtx.unlock(); - std::this_thread::yield(); + // add new job + m_mtx.lock(); + m_Ready.flip(); + m_mtx.unlock(); + std::this_thread::yield(); - while (!IsDone()) { + while(!IsDone()){ std::this_thread::yield(); - } + } -#else - static std::map<std::string, VDetector*>::iterator it; - static std::map<std::string, VDetector*>::iterator begin = m_Detector.begin(); - static std::map<std::string, VDetector*>::iterator end = m_Detector.end(); +#else + static std::map<std::string,VDetector*>::iterator it; + static std::map<std::string,VDetector*>::iterator begin=m_Detector.begin(); + static std::map<std::string,VDetector*>::iterator end= m_Detector.end(); - for (it = begin; it != end; ++it) { + //static std::map<std::string,VTreeReader*>::iterator it; + //static std::map<std::string,VTreeReader*>::iterator begin=m_DetectorReader.begin(); + //static std::map<std::string,VTreeReader*>::iterator end= m_DetectorReader.end(); + + for (it =begin; it != end; ++it) { (it->second->*m_ClearEventPhysicsPtr)(); (it->second->*m_BuildPhysicalPtr)(); - (it->second->*m_FillSpectra)(); - if (m_CheckSpectra) { - (it->second->*m_CheckSpectra)(); - } + // (it->second->*m_FillSpectra)(); + // if(m_CheckSpectra) { + // (it->second->*m_CheckSpectra)(); + //} } #endif return; } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::InitializeRootInput() { +void NPL::DetectorManager::InitializeRootInput(){ - if (NPOptionManager::getInstance()->GetDisableAllBranchOption()) - RootInput::getInstance()->GetChain()->SetBranchStatus("*", false); + if( NPOptionManager::getInstance()->GetDisableAllBranchOption() ) + RootInput::getInstance()->GetChain()->SetBranchStatus ( "*" , false ) ; - std::map<std::string, VDetector*>::iterator it; + std::map<std::string,VDetector*>::iterator it; - if (NPOptionManager::getInstance()->GetInputPhysicalTreeOption()) - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { + //std::cout << "m_DetectorReader size : " << m_DetectorReader.size() << std::endl; + if(NPOptionManager::getInstance()->GetInputPhysicalTreeOption()) + //m_DetectorReader.begin()->second->InitializeRootInputPhysics(); + for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ + std::cout << "Test input" << std::endl; (it->second->*m_InitializeRootInputPhysicsPtr)(); } else // Default Case - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { + //m_DetectorReader.begin()->second->InitializeRootInputRaw(); + for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ + std::cout << "Test input" << std::endl; (it->second->*m_InitializeRootInputRawPtr)(); } } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::InitializeRootOutput() { - std::map<std::string, VDetector*>::iterator it; +void NPL::DetectorManager::InitializeRootOutput(){ + std::map<std::string,VDetector*>::iterator it; - if (!NPOptionManager::getInstance()->GetInputPhysicalTreeOption()) - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { + if(!NPOptionManager::getInstance()->GetInputPhysicalTreeOption()) + for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ + std::cout << "Test output" << std::endl; (it->second->*m_InitializeRootOutputPtr)(); } } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::AddDetector(std::string DetectorName, VDetector* newDetector) { +void NPL::DetectorManager::InitializeRootHistogramsCalib(){ + std::map<std::string,VDetector*>::iterator it; + + if(NPOptionManager::getInstance()->IsCalibration()) + for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ + std::cout << "Test calib output" << std::endl; + (it->second->*m_InitializeRootHistogramsCalibPtr)(); + } + else{ + std::cout << "Warning : IsCalibration not recognized, output file not initialized" << std::endl; + } +} + +/////////////////////////////////////////////////////////////////////////////// +void NPL::DetectorManager::FillHistogramsCalib(){ + std::map<std::string,VDetector*>::iterator it; + + if(NPOptionManager::getInstance()->IsCalibration()) + for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ + (it->second->*m_FillHistogramsCalibPtr)(); + } + else{ + std::cout << "Warning : IsCalibration not recognized, Fill not working" << std::endl; + } +} + +void NPL::DetectorManager::WriteHistogramsCalib(){ + std::map<std::string,VDetector*>::iterator it; + + if(NPOptionManager::getInstance()->IsCalibration()) + for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ + std::cout << "Test Write Histograms" << std::endl; + (it->second->*m_WriteHistogramsCalibPtr)(); + } + else{ + std::cout << "Warning : IsCalibration not recognized, Write not working" << std::endl; + } +} + +/////////////////////////////////////////////////////////////////////////////// +void NPL::DetectorManager::AddDetector(std::string DetectorName , VDetector* newDetector){ m_Detector[DetectorName] = newDetector; newDetector->AddParameterToCalibrationManager(); } -void NPL::DetectorManager::AddDetectorReader(std::string DetectorName, VTreeReader* newDetector) { +void NPL::DetectorManager::AddDetectorReader(std::string DetectorName , VTreeReader* newDetector){ m_DetectorReader[DetectorName] = newDetector; } /////////////////////////////////////////////////////////////////////////////// -NPL::VDetector* NPL::DetectorManager::GetDetector(std::string name) { - std::map<std::string, VDetector*>::iterator it; +NPL::VDetector* NPL::DetectorManager::GetDetector(std::string name){ + std::map<std::string,VDetector*>::iterator it; it = m_Detector.find(name); - if (it != m_Detector.end()) - return it->second; - else { + if ( it!=m_Detector.end() ) return it->second; + else{ std::cout << std::endl; std::cout << "********************************** Error **********************************" << std::endl; std::cout << " No Detector " << name << " found in the Detector Manager" << std::endl; std::cout << " Available Detectors: " << std::endl; - for (std::map<std::string, VDetector*>::iterator i = m_Detector.begin(); i != m_Detector.end(); ++i) { + for(std::map<std::string,VDetector*>::iterator i = m_Detector.begin(); i != m_Detector.end(); ++i) { std::cout << "\t" << i->first << std::endl; } std::cout << "***************************************************************************************" << std::endl; std::cout << std::endl; exit(1); } + } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::ClearEventPhysics() { - std::map<std::string, VDetector*>::iterator it; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) +void NPL::DetectorManager::ClearEventPhysics(){ + std::map<std::string,VDetector*>::iterator it; + for (it = m_Detector.begin(); it != m_Detector.end(); ++it) (it->second->*m_ClearEventPhysicsPtr)(); } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::ClearEventData() { - std::map<std::string, VDetector*>::iterator it; +void NPL::DetectorManager::ClearEventData(){ + std::map<std::string,VDetector*>::iterator it; for (it = m_Detector.begin(); it != m_Detector.end(); ++it) (it->second->*m_ClearEventDataPtr)(); } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::InitSpectra() { +void NPL::DetectorManager::InitSpectra(){ bool batch = false; - if (gROOT) { + if(gROOT){ batch = gROOT->IsBatch(); gROOT->ProcessLine("gROOT->SetBatch()"); } - std::map<std::string, VDetector*>::iterator it; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) + std::map<std::string,VDetector*>::iterator it; + for (it = m_Detector.begin(); it != m_Detector.end(); ++it) it->second->InitSpectra(); - if (gROOT && !batch) + if(gROOT&&!batch) gROOT->ProcessLine("gROOT->SetBatch(kFALSE)"); } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::WriteSpectra() { - std::cout << std::endl << "\r \033[1;36m *** Writing Spectra: this may take a while ***\033[0m" << std::flush; - std::map<std::string, VDetector*>::iterator it; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) +void NPL::DetectorManager::WriteSpectra(){ + std::cout << std::endl << "\r \033[1;36m *** Writing Spectra: this may take a while ***\033[0m"<<std::flush; + std::map<std::string,VDetector*>::iterator it; + for (it = m_Detector.begin(); it != m_Detector.end(); ++it) it->second->WriteSpectra(); - std::cout << "\r " << std::flush; + std::cout << "\r " << std::flush; } /////////////////////////////////////////////////////////////////////////////// -std::vector<std::map<std::string, TH1*>> NPL::DetectorManager::GetSpectra() { - std::vector<std::map<std::string, TH1*>> myVector; - std::map<std::string, VDetector*>::iterator it; +std::vector< std::map< std::string, TH1* > > NPL::DetectorManager::GetSpectra(){ + std::vector< std::map< std::string, TH1* > > myVector; + std::map<std::string,VDetector*>::iterator it; // loop on detectors for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { myVector.push_back(it->second->GetSpectra()); @@ -410,10 +483,10 @@ std::vector<std::map<std::string, TH1*>> NPL::DetectorManager::GetSpectra() { } /////////////////////////////////////////////////////////////////////////////// -std::vector<std::string> NPL::DetectorManager::GetDetectorList() { - std::map<std::string, VDetector*>::iterator it; +std::vector<std::string> NPL::DetectorManager::GetDetectorList(){ + std::map<std::string,VDetector*>::iterator it; std::vector<std::string> DetectorList; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { + for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { DetectorList.push_back(it->first); } @@ -422,147 +495,154 @@ std::vector<std::string> NPL::DetectorManager::GetDetectorList() { #if __cplusplus > 199711L && NPMULTITHREADING //////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::InitThreadPool() { +void NPL::DetectorManager::InitThreadPool(){ StopThread(); m_ThreadPool.clear(); m_Ready.clear(); - std::map<std::string, VDetector*>::iterator it; - m_Ready.resize(m_Detector.size(), false); + std::map<std::string,VDetector*>::iterator it; + std::cout << "Test Detector size : " << m_Detector.size() << std::endl; + m_Ready.resize(m_Detector.size(),false); unsigned int i = 0; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { - m_ThreadPool.push_back(std::thread(&NPL::DetectorManager::StartThread, this, it->second, i++)); + for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { + m_ThreadPool.push_back( std::thread( &NPL::DetectorManager::StartThread,this,it->second,i++) ); } m_stop = false; - for (auto& th : m_ThreadPool) { + for(auto& th: m_ThreadPool){ th.detach(); } - std::cout << "\033[1;33m**** Detector Manager : Started " << i << " Threads ****\033[0m" << std::endl; + std::cout << "\033[1;33m**** Detector Manager : Started " << i << " Threads ****\033[0m" << std::endl ; } //////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::StartThread(NPL::VDetector* det, unsigned int id) { - // Let the main thread start +void NPL::DetectorManager::StartThread(NPL::VDetector* det,unsigned int id){ + // Let the main thread start std::this_thread::sleep_for(std::chrono::milliseconds(250)); - while (true) { + while(true){ // Do the job if possible - if (m_Ready[id]) { + if(m_Ready[id]){ + //std::cout << "Test Build 2 ////////////////////////////////////////////////////////////" << std::endl; // Do the job (det->*m_ClearEventPhysicsPtr)(); (det->*m_BuildPhysicalPtr)(); - if (m_FillSpectra) { - (det->*m_FillSpectra)(); - if (m_CheckSpectra) - (det->*m_CheckSpectra)(); - } - m_mtx.lock(); - m_Ready[id].flip(); - m_mtx.unlock(); - std::this_thread::yield(); - } - else { - // std::this_thread::sleep_for(std::chrono::milliseconds(100)); - std::this_thread::yield(); - } + //if(m_FillSpectra){ + // (reader->*m_FillSpectra)(); + // if(m_CheckSpectra) + // (reader->*m_CheckSpectra)(); + //} + m_mtx.lock(); + m_Ready[id].flip(); + m_mtx.unlock(); + std::this_thread::yield(); + } + else{ +// std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::yield(); + } // Return if stopped - if (m_stop) { + if(m_stop){ return; - } - } + } + } } //////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::StopThread() { +void NPL::DetectorManager::StopThread(){ // make sure the last thread are schedule before stopping; std::this_thread::yield(); - m_stop = true; + m_stop=true; std::this_thread::yield(); } //////////////////////////////////////////////////////////////////////////////// -bool NPL::DetectorManager::IsDone() { +bool NPL::DetectorManager::IsDone(){ static std::vector<bool>::iterator it; - static std::vector<bool>::iterator begin = m_Ready.begin(); + static std::vector<bool>::iterator begin = m_Ready.begin(); static std::vector<bool>::iterator end = m_Ready.end(); - unsigned int i = 0; - for (it = begin; it != end; it++) { - if ((*it)) + unsigned int i = 0 ; + for( it = begin ; it!=end ; it++){ + //std::cout << i++ << " " << *it << std::endl; + if((*it)) return false; } return true; } #endif //////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::SetSpectraServer() { +void NPL::DetectorManager::SetSpectraServer(){ m_SpectraServer = NPL::SpectraServer::getInstance(); - std::map<std::string, VDetector*>::iterator it; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { + std::map<std::string,VDetector*>::iterator it; + for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ std::vector<TCanvas*> canvas = it->second->GetCanvas(); size_t mysize = canvas.size(); - for (size_t i = 0; i < mysize; i++) { - } - // m_SpectraServer->AddCanvas(canvas[i]); + for (size_t i = 0 ; i < mysize ; i++){} + //m_SpectraServer->AddCanvas(canvas[i]); } // Avoid warning on gcc // int r; - // r=system("nponline localhost 9092 & "); - m_SpectraServer->CheckRequest(); + //r=system("nponline localhost 9092 & "); + m_SpectraServer->CheckRequest(); } //////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::StopSpectraServer() { - if (m_SpectraServer) +void NPL::DetectorManager::StopSpectraServer(){ + if(m_SpectraServer) m_SpectraServer->Destroy(); else - std::cout << "WARNING: requesting to stop spectra server, which is not started" << std::endl; + std::cout <<"WARNING: requesting to stop spectra server, which is not started" << std::endl; + } //////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::CheckSpectraServer() { - if (m_SpectraServer) +void NPL::DetectorManager::CheckSpectraServer(){ + if(m_SpectraServer) m_SpectraServer->CheckRequest(); else - std::cout << "WARNING: requesting to check spectra server, which is not started" << std::endl; + std::cout <<"WARNING: requesting to check spectra server, which is not started" << std::endl; + } //////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::FillOutputTree() { +void NPL::DetectorManager::FillOutputTree(){ + //std::cout << "Root Output " << m_RootOutput << std::endl; m_RootOutput->Fill(); } //////////////////////////////////////////////////////////////////////////////// -bool NPL::DetectorManager::IsCryogenic() const { return m_CryoTarget; }; -double NPL::DetectorManager::GetTargetThickness() const { return m_TargetThickness; }; -double NPL::DetectorManager::GetNominalTargetThickness() const { return m_TargetThickness; }; -double NPL::DetectorManager::GetTargetDensity() const { return m_TargetDensity; }; -double NPL::DetectorManager::GetFrontDeformation() const { return m_FrontDeformation; }; -double NPL::DetectorManager::GetFrontThickness() const { return m_FrontThickness; }; -double NPL::DetectorManager::GetFrontRadius() const { return m_FrontRadius; }; -std::string NPL::DetectorManager::GetFrontMaterial() const { return m_FrontMaterial; }; -double NPL::DetectorManager::GetBackDeformation() const { return m_BackDeformation; }; -double NPL::DetectorManager::GetBackRadius() const { return m_BackRadius; }; -double NPL::DetectorManager::GetBackThickness() const { return m_BackThickness; }; -std::string NPL::DetectorManager::GetBackMaterial() const { return m_BackMaterial; }; -double NPL::DetectorManager::GetFrameRadius() const { return m_FrameRadius; }; -double NPL::DetectorManager::GetFrameThickness() const { return m_FrameThickness; }; -double NPL::DetectorManager::GetFrontCone() const { return m_FrontCone; }; -double NPL::DetectorManager::GetBackCone() const { return m_BackCone; }; -std::string NPL::DetectorManager::GetFrameMaterial() const { return m_FrameMaterial; }; -double NPL::DetectorManager::GetShieldInnerRadius() const { return m_ShieldInnerRadius; }; -double NPL::DetectorManager::GetShieldOuterRadius() const { return m_ShieldOuterRadius; }; -double NPL::DetectorManager::GetShieldBottomLength() const { return m_ShieldBottomLength; }; -double NPL::DetectorManager::GetShieldTopLength() const { return m_ShieldTopLength; }; -double NPL::DetectorManager::GetShieldFrontRadius() const { return m_ShieldFrontRadius; }; -double NPL::DetectorManager::GetShieldBackRadius() const { return m_ShieldBackRadius; }; -std::string NPL::DetectorManager::GetShieldMaterial() const { return m_ShieldMaterial; }; -std::string NPL::DetectorManager::GetTargetMaterial() const { return m_TargetMaterial; }; -double NPL::DetectorManager::GetWindowsThickness() const { return m_WindowsThickness; }; -std::string NPL::DetectorManager::GetWindowsMaterial() const { return m_WindowsMaterial; }; -double NPL::DetectorManager::GetTargetRadius() const { return m_TargetRadius; }; -double NPL::DetectorManager::GetTargetAngle() const { return m_TargetAngle; }; -double NPL::DetectorManager::GetTargetX() const { return m_TargetX; }; -double NPL::DetectorManager::GetTargetY() const { return m_TargetY; }; -double NPL::DetectorManager::GetTargetZ() const { return m_TargetZ; }; +bool NPL::DetectorManager::IsCryogenic() const {return m_CryoTarget;}; +double NPL::DetectorManager::GetTargetThickness() const {return m_TargetThickness;}; +double NPL::DetectorManager::GetNominalTargetThickness() const {return m_TargetThickness;}; +double NPL::DetectorManager::GetTargetDensity() const {return m_TargetDensity;}; +double NPL::DetectorManager::GetFrontDeformation() const {return m_FrontDeformation;}; +double NPL::DetectorManager::GetFrontThickness() const {return m_FrontThickness;}; +double NPL::DetectorManager::GetFrontRadius() const {return m_FrontRadius;}; +std::string NPL::DetectorManager::GetFrontMaterial() const {return m_FrontMaterial;}; +double NPL::DetectorManager::GetBackDeformation() const {return m_BackDeformation;}; +double NPL::DetectorManager::GetBackRadius() const {return m_BackRadius;}; +double NPL::DetectorManager::GetBackThickness() const {return m_BackThickness;}; +std::string NPL::DetectorManager::GetBackMaterial() const {return m_BackMaterial;}; +double NPL::DetectorManager::GetFrameRadius() const {return m_FrameRadius;}; +double NPL::DetectorManager::GetFrameThickness() const {return m_FrameThickness;}; +double NPL::DetectorManager::GetFrontCone() const {return m_FrontCone;}; +double NPL::DetectorManager::GetBackCone() const {return m_BackCone;}; +std::string NPL::DetectorManager::GetFrameMaterial() const {return m_FrameMaterial;}; +double NPL::DetectorManager::GetShieldInnerRadius() const {return m_ShieldInnerRadius;}; +double NPL::DetectorManager::GetShieldOuterRadius() const {return m_ShieldOuterRadius;}; +double NPL::DetectorManager::GetShieldBottomLength() const {return m_ShieldBottomLength;}; +double NPL::DetectorManager::GetShieldTopLength() const {return m_ShieldTopLength;}; +double NPL::DetectorManager::GetShieldFrontRadius() const {return m_ShieldFrontRadius;}; +double NPL::DetectorManager::GetShieldBackRadius() const {return m_ShieldBackRadius;}; +std::string NPL::DetectorManager::GetShieldMaterial() const {return m_ShieldMaterial;}; +std::string NPL::DetectorManager::GetTargetMaterial() const {return m_TargetMaterial;}; +double NPL::DetectorManager::GetWindowsThickness() const {return m_WindowsThickness;}; +std::string NPL::DetectorManager::GetWindowsMaterial() const {return m_WindowsMaterial;}; +double NPL::DetectorManager::GetTargetRadius() const {return m_TargetRadius;}; +double NPL::DetectorManager::GetTargetAngle() const {return m_TargetAngle;}; +double NPL::DetectorManager::GetTargetX() const {return m_TargetX;}; +double NPL::DetectorManager::GetTargetY() const {return m_TargetY;}; +double NPL::DetectorManager::GetTargetZ() const {return m_TargetZ;}; + + diff --git a/NPLib/Core/NPDetectorManager.h b/NPLib/Core/NPDetectorManager.h index a7a4d78d8aac1c547ef41f950dc30c7ccdb7e98b..8a4e65bb5d6146d75ea46a707dfafe9ef43c9f52 100644 --- a/NPLib/Core/NPDetectorManager.h +++ b/NPLib/Core/NPDetectorManager.h @@ -44,6 +44,7 @@ typedef void(NPL::VDetector::*VDetector_FuncPtr)(void); typedef void(NPL::VTreeReader::*VTreeReader_FuncPtr)(void); typedef void(NPL::VDetector::*VDetector_SetReader)(TTreeReader*); typedef bool(NPL::VDetector::*VDetector_Unallocate)(void); +//typedef void(NPL::VTreeReader::*VTreeReader_SetReader)(TTreeReader*); // This class manage a std::map of virtual detector namespace NPL{ class DetectorManager{ @@ -56,6 +57,9 @@ namespace NPL{ void BuildPhysicalEvent(); void InitializeRootInput(); void InitializeRootOutput(); + void InitializeRootHistogramsCalib(); + void FillHistogramsCalib(); + void WriteHistogramsCalib(); void SetTreeReader(TTreeReader* TreeReader); void AddDetector(std::string,VDetector*); void AddDetectorReader(std::string,VTreeReader*); @@ -97,6 +101,9 @@ namespace NPL{ VDetector_FuncPtr m_InitializeRootInputPhysicsPtr; VDetector_FuncPtr m_InitializeRootInputRawPtr; VDetector_FuncPtr m_InitializeRootOutputPtr; + VDetector_FuncPtr m_InitializeRootHistogramsCalibPtr; + VDetector_FuncPtr m_FillHistogramsCalibPtr; + VDetector_FuncPtr m_WriteHistogramsCalibPtr; VDetector_SetReader m_SetTreeReaderPtr; VDetector_FuncPtr m_FillSpectra; VDetector_FuncPtr m_CheckSpectra; @@ -111,6 +118,7 @@ namespace NPL{ public: // Init the Thread Pool void StopThread(); void StartThread(NPL::VDetector*,unsigned int); + //void StartThread(NPL::VTreeReader*,unsigned int); void InitThreadPool(); bool IsDone(); diff --git a/NPLib/Core/NPOptionManager.cxx b/NPLib/Core/NPOptionManager.cxx index 77d9b17aefc510088b6fbbe29e1d8ba2893f0941..64eb1da35e55e1962a26217be25a0ee7ff2eeca9 100644 --- a/NPLib/Core/NPOptionManager.cxx +++ b/NPLib/Core/NPOptionManager.cxx @@ -1,9 +1,9 @@ -; /***************************************************************************** - * 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 * - *****************************************************************************/ +;/***************************************************************************** + * 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: A. MATTA contact address: matta@lpccaen.in2p3.fr * @@ -21,110 +21,113 @@ *****************************************************************************/ #include "NPOptionManager.h" -#include "NPCore.h" -#include "NPInputParser.h" #include "NPLibVersion.h" -#include <cstdlib> +#include "NPInputParser.h" #include <fstream> #include <sstream> -#include <sys/types.h> -#include <unistd.h> +#include <cstdlib> #include <vector> -NPOptionManager* NPOptionManager::instance = 0; + +NPOptionManager* NPOptionManager::instance = 0 ; //////////////////////////////////////////////////////////////////////////////// -NPOptionManager* NPOptionManager::getInstance(int argc, char** argv) { - if (instance == 0) - instance = new NPOptionManager(argc, argv); +NPOptionManager* NPOptionManager::getInstance(int argc, char** argv){ + if (instance == 0) instance = new NPOptionManager(argc, argv); - return instance; + return instance ; } //////////////////////////////////////////////////////////////////////////////// -NPOptionManager* NPOptionManager::getInstance(std::string arg) { +NPOptionManager* NPOptionManager::getInstance(std::string arg){ + + if (instance == 0) instance = new NPOptionManager(arg); - if (instance == 0) - instance = new NPOptionManager(arg); + return instance ; - return instance; } //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::ReadProjectConfigFile() { - // check if the file exist - std::ifstream ProjectFile; - ProjectFile.open("./project.config"); +void NPOptionManager::ReadProjectConfigFile(){ + // check if the file exist + std::ifstream ProjectFile; + ProjectFile.open("./project.config"); - if (ProjectFile.is_open()) { + if(ProjectFile.is_open()){ std::cout << "///// Loading Project Configuration: " << std::endl; ProjectFile.close(); NPL::InputParser parser("./project.config"); std::vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Project"); unsigned int size = blocks.size(); - for (unsigned int i = 0; i < size; i++) { - - if (blocks[i]->HasToken("AnalysisOutput")) - m_AnalysisOutputPath = blocks[i]->GetString("AnalysisOutput"); - - if (blocks[i]->HasToken("SimulationOutput")) - m_SimulationOutputPath = blocks[i]->GetString("SimulationOutput"); - - if (blocks[i]->HasToken("EnergyLoss")) - m_EnergyLossPath = blocks[i]->GetString("EnergyLoss"); + for(unsigned int i = 0 ; i < size ; i++){ + + if(blocks[i]->HasToken("AnalysisOutput")) + m_AnalysisOutputPath = blocks[i]->GetString("AnalysisOutput"); + + if(blocks[i]->HasToken("SimulationOutput")) + m_SimulationOutputPath = blocks[i]->GetString("SimulationOutput"); + + if(blocks[i]->HasToken("CalibrationOutput")) + m_CalibrationOutputPath = blocks[i]->GetString("CalibrationOutput"); + + if(blocks[i]->HasToken("EnergyLoss")) + m_EnergyLossPath = blocks[i]->GetString("EnergyLoss"); } - } - - // else use the standard config - else { - - std::cout << "///// No Project Configuration: " << std::endl; - std::string Path = getenv("NPTOOL"); - m_AnalysisOutputPath = Path + "/Outputs/Analysis/"; - m_SimulationOutputPath = Path + "/Outputs/Simulation/"; - m_EnergyLossPath = Path + "/Inputs/EnergyLoss/"; - std::cout << "AnalysisOutput= " << m_AnalysisOutputPath << std::endl; - std::cout << "SimulationOutput= " << m_SimulationOutputPath << std::endl; - std::cout << "EnergyLoss= " << m_EnergyLossPath << std::endl; - } + } + + + // else use the standard config + else{ + + std::cout << "///// No Project Configuration: " << std::endl; + std::string Path = getenv("NPTOOL"); + m_AnalysisOutputPath=Path+"/Outputs/Analysis/"; + m_SimulationOutputPath=Path+"/Outputs/Simulation/"; + m_CalibrationOutputPath=Path+"/Outputs/Calibration/"; + m_EnergyLossPath=Path+"/Inputs/EnergyLoss/"; + std::cout << "AnalysisOutput= " << m_AnalysisOutputPath << std::endl; + std::cout << "SimulationOutput= " << m_SimulationOutputPath << std::endl; + std::cout << "CalibrationOutput= " << m_CalibrationOutputPath << std::endl; + std::cout << "EnergyLoss= " << m_EnergyLossPath << std::endl; + } } //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::ReadTheInputArgument(int argc, char** argv) { - if (argc == 1) +void NPOptionManager::ReadTheInputArgument(int argc, char** argv){ + if(argc==1) DisplayHelp(); // Default Setting - fDefaultReactionFileName = "defaultReaction.reaction"; - fDefaultDetectorFileName = "defaultDetector.detector"; - fDefaultOutputFileName = "SimulatedTree.root"; - fDefaultOutputTreeName = "NPTool_Tree"; - fDefaultRunToReadFileName = "defaultRunToTreat.txt"; + fDefaultReactionFileName = "defaultReaction.reaction"; + fDefaultDetectorFileName = "defaultDetector.detector"; + fDefaultOutputFileName = "SimulatedTree.root"; + fDefaultOutputTreeName = "NPTool_Tree"; + fDefaultRunToReadFileName = "defaultRunToTreat.txt"; fDefaultCalibrationFileName = "defaultCalibration.txt"; - fDefaultG4MacroPath = "defaultG4MacroPath.txt"; + fDefaultG4MacroPath = "defaultG4MacroPath.txt"; // Assigned values - fReactionFileName = fDefaultReactionFileName; - fDetectorFileName = fDefaultDetectorFileName; - fOutputFileName = fDefaultOutputFileName; - fOutputTreeName = fDefaultOutputTreeName; - fRunToReadFileName = fDefaultRunToReadFileName; - fCalibrationFileName = fDefaultCalibrationFileName; - fG4MacroPath = fDefaultG4MacroPath; + fReactionFileName = fDefaultReactionFileName; + fDetectorFileName = fDefaultDetectorFileName; + fOutputFileName = fDefaultOutputFileName; + fOutputTreeName = fDefaultOutputTreeName; + fRunToReadFileName = fDefaultRunToReadFileName; + fCalibrationFileName = fDefaultCalibrationFileName; + fG4MacroPath = fDefaultG4MacroPath; fIsSplit = false; - fLastSimFile = false; + fLastSimFile = false; fLastPhyFile = false; fLastResFile = false; fLastAnyFile = false; - fIsAnalysis = false; - fIsSimulation = false; - fVerboseLevel = 1; - fNumberOfEntryToAnalyse = -1; - fFirstEntryToAnalyse = 0; - fSpectraServerPort = 9092; - fRandomSeed = -1; - fRecordTrack = 0; + fIsAnalysis = false; + fIsSimulation= false; + fVerboseLevel = 1; + fNumberOfEntryToAnalyse = -1; + fFirstEntryToAnalyse = 0; + fSpectraServerPort = 9092; + fRandomSeed = -1; + fRecordTrack = 0; fDisableAllBranchOption = false; fInputPhysicalTreeOption = false; - fGenerateHistoOption = false; + fGenerateHistoOption = false ; fCircularTree = false; fOnline = false; fG4BatchMode = false; @@ -140,206 +143,160 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv) { fSharedLibExtension = ".dylib"; #endif + + + for (int i = 1; i < argc; i++) { std::string argument = argv[i]; - if (argument == "-H" || argument == "-h" || argument == "--help") - DisplayHelp(); + if (argument == "-H" || argument == "-h" || argument == "--help") DisplayHelp(); - else if (argument == "--event-generator" && argc >= i + 1) - fReactionFileName = argv[++i]; + else if (argument == "--event-generator" && argc >= i + 1) fReactionFileName = argv[++i] ; - else if (argument == "-E" && argc >= i + 1) - fReactionFileName = argv[++i]; + else if (argument == "-E" && argc >= i + 1) fReactionFileName = argv[++i] ; - else if (argument == "--detector" && argc >= i + 1) - fDetectorFileName = argv[++i]; + else if (argument == "--detector" && argc >= i + 1) fDetectorFileName = argv[++i] ; - else if (argument == "-D" && argc >= i + 1) - fDetectorFileName = argv[++i]; + else if (argument == "-D" && argc >= i + 1) fDetectorFileName = argv[++i] ; - else if (argument == "--output" && argc >= i + 1) - fOutputFileName = argv[++i]; + else if (argument == "--output" && argc >= i + 1) fOutputFileName = argv[++i] ; - else if (argument == "-O" && argc >= i + 1) - fOutputFileName = argv[++i]; + else if (argument == "-O" && argc >= i + 1) fOutputFileName = argv[++i] ; - else if (argument == "--tree-name" && argc >= i + 1) - fOutputTreeName = argv[++i]; + else if (argument == "--tree-name" && argc >= i + 1) fOutputTreeName = argv[++i] ; - else if (argument == "--run" && argc >= i + 1) - fRunToReadFileName = argv[++i]; + else if (argument == "--run" && argc >= i + 1) fRunToReadFileName = argv[++i] ; - else if (argument == "-R" && argc >= i + 1) - fRunToReadFileName = argv[++i]; + else if (argument == "-R" && argc >= i + 1) fRunToReadFileName = argv[++i] ; - else if (argument == "-T" && argc >= i + 2) { - std::string file = argv[++i]; - std::string tree = argv[++i]; - CreateRunToTreatFile(file, tree); - } + else if (argument == "-T" && argc >= i + 2) { std::string file = argv[++i] ; std::string tree = argv[++i]; CreateRunToTreatFile(file,tree);} - else if (argument == "--cal" && argc >= i + 1) - fCalibrationFileName = argv[++i]; + else if (argument == "--cal" && argc >= i + 1) fCalibrationFileName = argv[++i] ; + + else if (argument == "-S" && argc >= i + 1) fIsSplit=true; - else if (argument == "-S" && argc >= i + 1) - fIsSplit = true; + else if (argument == "-C" && argc >= i + 1) fCalibrationFileName = argv[++i] ; - else if (argument == "-C" && argc >= i + 1) - fCalibrationFileName = argv[++i]; + else if (argument == "-M" && argc >= i + 1) fG4MacroPath = argv[++i] ; - else if (argument == "-M" && argc >= i + 1) - fG4MacroPath = argv[++i]; + else if (argument == "-B" && argc >= i + 1) {fG4MacroPath = argv[++i] ;fG4BatchMode=true;} - else if (argument == "-B" && argc >= i + 1) { - fG4MacroPath = argv[++i]; - fG4BatchMode = true; - } + else if (argument == "-V" && argc >= i + 1) fVerboseLevel = atoi(argv[++i]) ; - else if (argument == "-V" && argc >= i + 1) - fVerboseLevel = atoi(argv[++i]); + else if (argument == "--verbose" && argc >= i + 1) fVerboseLevel = atoi(argv[++i]) ; - else if (argument == "--verbose" && argc >= i + 1) - fVerboseLevel = atoi(argv[++i]); + else if (argument == "-P" && argc >= i + 1) fSpectraServerPort = atoi(argv[++i]) ; - else if (argument == "-P" && argc >= i + 1) - fSpectraServerPort = atoi(argv[++i]); + else if (argument == "--disable-branch") fDisableAllBranchOption = true ; - else if (argument == "--disable-branch") - fDisableAllBranchOption = true; + else if (argument == "--input-physical") fInputPhysicalTreeOption = true ; - else if (argument == "--input-physical") - fInputPhysicalTreeOption = true; + else if (argument == "-IP") fInputPhysicalTreeOption = true ; - else if (argument == "-IP") - fInputPhysicalTreeOption = true; + else if (argument == "-GH") fGenerateHistoOption = true ; - else if (argument == "-GH") - fGenerateHistoOption = true; + else if (argument == "-CH") fCheckHistoOption = true ; - else if (argument == "-CH") - fCheckHistoOption = true; + else if (argument == "-check-histo") fCheckHistoOption = true ; - else if (argument == "-check-histo") - fCheckHistoOption = true; + else if (argument == "--generate-histo") fGenerateHistoOption = true ; - else if (argument == "--generate-histo") - fGenerateHistoOption = true; + else if (argument == "-L") fNumberOfEntryToAnalyse = atoi(argv[++i]) ; - else if (argument == "-L") - fNumberOfEntryToAnalyse = atoi(argv[++i]); + else if (argument == "--random-seed") fRandomSeed = atoi(argv[++i]) ; - else if (argument == "--random-seed") - fRandomSeed = atoi(argv[++i]); + else if (argument == "--record-track") fRecordTrack = true ; - else if (argument == "--record-track") - fRecordTrack = true; + else if (argument == "-F") fFirstEntryToAnalyse = atoi(argv[++i]); - else if (argument == "-F") - fFirstEntryToAnalyse = atoi(argv[++i]); + else if (argument == "--last-sim") fLastSimFile = true ; - else if (argument == "--last-sim") - fLastSimFile = true; + else if (argument == "--last-phy") fLastPhyFile = true ; - else if (argument == "--last-phy") - fLastPhyFile = true; + else if (argument == "--last-res") fLastResFile = true ; - else if (argument == "--last-res") - fLastResFile = true; + else if (argument == "--last-any") fLastAnyFile = true ; - else if (argument == "--last-any") - fLastAnyFile = true; + else if (argument == "--online") {fOnline = true ;fGenerateHistoOption=true;} - else if (argument == "--online") { - fOnline = true; - fGenerateHistoOption = true; - } + else if (argument == "--circular") {fCircularTree = true;} - else if (argument == "--circular") { - fCircularTree = true; - } - - else if (argument == "--definition" && argc >= i + 1) { - std::string def = argv[++i]; - fDefinition.insert(def); - } + else if (argument == "--definition" && argc >= i + 1) {std::string def= argv[++i];fDefinition.insert(def);} - else { - SendErrorAndExit(argument.c_str()); + else{ + SendErrorAndExit(argument.c_str()); } } CheckArguments(); - if (argc != 0) + if(argc!=0) DisplayVersion(); } //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::CreateRunToTreatFile(std::string file, std::string tree) { - - char buffer[1024]; - sprintf(buffer, "/tmp/RunToTreat_%d.txt", getpid()); - std::ofstream run(buffer); - if (!run.is_open()) +void NPOptionManager::CreateRunToTreatFile(std::string file, std::string tree){ + + std::ofstream run(".RunToTreat.txt"); + if(!run.is_open()) exit(1); run << "Tree " << tree << std::endl; run << " " << file << std::endl << std::endl; run.close(); - fRunToReadFileName = buffer; -} + fRunToReadFileName=".RunToTreat.txt"; + } + //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::DisplayVersion() { - if (fVerboseLevel > 0) { +void NPOptionManager::DisplayVersion(){ + if(fVerboseLevel>0){ std::string line; - line.resize(80, '*'); + line.resize(80,'*'); std::cout << line << std::endl; - std::cout << "*********************************** NPTool ***********************************" << std::endl; + std::cout << "*********************************** NPTool ***********************************"<< std::endl; std::cout << line << std::endl; - std::cout << " NPLib version: nplib-" << NPL::version_major << "-" << NPL::version_minor << "-" << NPL::version_deta - << std::endl; - std::cout << " Copyright: NPTool Collaboration " << std::endl; - std::cout << " Gitlab: https://gitlab.in2p3.fr/np/nptool" << std::endl; - ; + std::cout << " NPLib version: nplib-"<< NPL::version_major <<"-" << NPL::version_minor << "-" << NPL::version_deta <<std::endl; + std::cout << " Copyright: NPTool Collaboration "<<std::endl; + std::cout << " Gitlab: https://gitlab.in2p3.fr/np/nptool"<<std::endl; ; std::cout << line << std::endl; + } } //////////////////////////////////////////////////////////////////////////////// -NPOptionManager::NPOptionManager(int argc, char** argv) { +NPOptionManager::NPOptionManager(int argc, char** argv){ // Start by reading the project configuration ReadProjectConfigFile(); - ReadTheInputArgument(argc, argv); + ReadTheInputArgument(argc,argv); } //////////////////////////////////////////////////////////////////////////////// -NPOptionManager::NPOptionManager(std::string arg) { +NPOptionManager::NPOptionManager(std::string arg){ // add dummy string in front of arg string arg.insert(0, "ignore "); - std::vector<char*> args; + std::vector<char *> args; std::stringstream iss(arg); std::string token; - while (iss >> token) { - char* arg = new char[token.size() + 1]; + while(iss >> token) { + char *arg = new char[token.size() + 1]; copy(token.begin(), token.end(), arg); arg[token.size()] = '\0'; args.push_back(arg); } args.push_back(0); - ReadTheInputArgument(args.size() - 1, &args[0]); + ReadTheInputArgument(args.size()-1, &args[0]); /* for(size_t i = 0; i < args.size(); i++) delete[] args[i]; */ } //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::CheckArguments() { +void NPOptionManager::CheckArguments(){ CheckEventGenerator(); CheckDetectorConfiguration(); CheckG4Macro(); } //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::CheckEventGenerator() { +void NPOptionManager::CheckEventGenerator(){ bool checkFile = true; // NPTool path @@ -353,14 +310,14 @@ void NPOptionManager::CheckEventGenerator() { ConfigFile.open(fReactionFileName.c_str()); if (!ConfigFile.is_open()) { ConfigFile.open(StandardPath.c_str()); - if (!ConfigFile.is_open()) { // if not, assign standard path + if (!ConfigFile.is_open()) { // if not, assign standard path checkFile = false; } else { fReactionFileName = StandardPath; } } - if (!checkFile && fReactionFileName != fDefaultReactionFileName) { // if file does not exist + if (!checkFile && fReactionFileName != fDefaultReactionFileName) { // if file does not exist SendErrorAndExit("EventGenerator"); } @@ -369,7 +326,7 @@ void NPOptionManager::CheckEventGenerator() { } //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::CheckDetectorConfiguration() { +void NPOptionManager::CheckDetectorConfiguration(){ bool checkFile = true; // NPTool path @@ -383,69 +340,66 @@ void NPOptionManager::CheckDetectorConfiguration() { ConfigFile.open(fDetectorFileName.c_str()); if (!ConfigFile.is_open()) { ConfigFile.open(StandardPath.c_str()); - if (!ConfigFile.is_open()) { // if not, assign standard path + if (!ConfigFile.is_open()) { // if not, assign standard path checkFile = false; } else { fDetectorFileName = StandardPath; } } - if (!checkFile && fDetectorFileName != fDefaultDetectorFileName) { // if file does not exist + if (!checkFile && fDetectorFileName != fDefaultDetectorFileName) { // if file does not exist SendErrorAndExit("DetectorConfiguration"); } // close ConfigFile ConfigFile.close(); + } //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::CheckG4Macro() { - if (IsDefault("G4MacroPath")) - return; +void NPOptionManager::CheckG4Macro(){ + if(IsDefault("G4MacroPath")) + return ; // ifstream to configfile - std::ifstream MacroFile(fG4MacroPath); + std::ifstream MacroFile( fG4MacroPath ); if (!MacroFile.is_open()) { SendErrorAndExit("G4MacroPath"); } + } + + //////////////////////////////////////////////////////////////////////////////// // This method tests if the input files are the default ones -bool NPOptionManager::IsDefault(const char* type) const { +bool NPOptionManager::IsDefault(const char* type) const{ bool result = false; std::string stype = type; if (stype == "EventGenerator") { - if (fReactionFileName == fDefaultReactionFileName) - result = true; + if (fReactionFileName == fDefaultReactionFileName) result = true; } else if (stype == "DetectorConfiguration") { - if (fDetectorFileName == fDefaultDetectorFileName) - result = true; + if (fDetectorFileName == fDefaultDetectorFileName) result = true; } else if (stype == "Calibration") { - if (fCalibrationFileName == fDefaultCalibrationFileName) - result = true; + if (fCalibrationFileName == fDefaultCalibrationFileName) result = true; } else if (stype == "RunToTreat") { - if (fRunToReadFileName == fDefaultRunToReadFileName) - result = true; + if (fRunToReadFileName == fDefaultRunToReadFileName) result = true; } else if (stype == "OutputFileName") { - if (fOutputFileName == fDefaultOutputFileName) - result = true; + if (fOutputFileName == fDefaultOutputFileName) result = true; } else if (stype == "TreeName") { - if (fOutputTreeName == fDefaultOutputTreeName) - result = true; + if (fOutputTreeName == fDefaultOutputTreeName) result = true; } else if (stype == "G4MacroPath") { - if (fG4MacroPath == fDefaultG4MacroPath) - result = true; + if (fG4MacroPath== fDefaultG4MacroPath) result = true; } - + else { std::cout << "NPOptionManager::IsDefault() unkwown keyword" << std::endl; } @@ -453,9 +407,10 @@ bool NPOptionManager::IsDefault(const char* type) const { return result; } + //////////////////////////////////////////////////////////////////////////////// // This method tests if the input files are the default ones -void NPOptionManager::SendErrorAndExit(const char* type) const { +void NPOptionManager::SendErrorAndExit(const char* type) const{ std::string stype = type; if (stype == "EventGenerator") { std::cout << std::endl; @@ -467,12 +422,9 @@ void NPOptionManager::SendErrorAndExit(const char* type) const { } else if (stype == "DetectorConfiguration") { std::cout << std::endl; - std::cout << "*********************************** Error ***********************************" - << std::endl; - std::cout << "* No detector geometry file found in $NPTool/Inputs/DetectorConfiguration or local directories *" - << std::endl; - std::cout << "*****************************************************************************************" - << std::endl; + std::cout << "*********************************** Error ***********************************" << std::endl; + std::cout << "* No detector geometry file found in $NPTool/Inputs/DetectorConfiguration or local directories *" << std::endl; + std::cout << "*****************************************************************************************" << std::endl; std::cout << std::endl; exit(1); } @@ -482,12 +434,9 @@ void NPOptionManager::SendErrorAndExit(const char* type) const { } else if (stype == "G4MacroPath") { std::cout << std::endl; - std::cout << "*********************************** Error ***********************************" - << std::endl; - std::cout << "* No Geant4 macro file found in the provided path *" - << std::endl; - std::cout << "*****************************************************************************************" - << std::endl; + std::cout << "*********************************** Error ***********************************" << std::endl; + std::cout << "* No Geant4 macro file found in the provided path *" << std::endl; + std::cout << "*****************************************************************************************" << std::endl; std::cout << std::endl; exit(1); } @@ -498,75 +447,73 @@ void NPOptionManager::SendErrorAndExit(const char* type) const { } } + //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::DisplayHelp() { +void NPOptionManager::DisplayHelp(){ DisplayVersion(); - std::cout << std::endl << "----NPOptionManager Help----" << std::endl << std::endl; - std::cout << "List of Option " << std::endl; - std::cout << "\t--help -H -h\t\t\tDisplay this help message" << std::endl; - std::cout << "\t--detector -D <arg>\t\tSet arg as the detector configuration file" << std::endl; - std::cout << "\t--event-generator -E <arg>\tSet arg as the event generator file" << std::endl; - std::cout << "\t--output -O <arg>\t\tSet arg as the Output File Name (output tree)" << std::endl; - std::cout << "\t--tree-name <arg>\t\tSet arg as the Output Tree Name " << std::endl; - std::cout << "\t--definition <definition> \tAdd <definition> to the list of definition" << std::endl; - std::cout << "\t-S \t\t\t\tOne tree output per detector" << std::endl; - std::cout << "\t--verbose -V <arg>\t\tSet the verbose level, 0 for nothing, 1 for normal printout." << std::endl; - std::cout << "\t\t\t\t\tError and warning are not affected" << std::endl; - std::cout << std::endl << "NPAnalysis only:" << std::endl; - std::cout << "\t--run -R <arg>\t\t\tSet arg as the run to read file list" << std::endl; - std::cout << "\t-T <name> <file>\t\tTree <name> from root file <file>" << std::endl; - std::cout << "\t--cal -C <arg>\t\t\tSet arg as the calibration file list" << std::endl; - std::cout << "\t--disable-branch\t\tDisable of branch of Input tree except the one of the detector (faster)" - << std::endl; - std::cout << "\t--generate-histo -GH\t\tInstantiate the T*Spectra class of each detector" << std::endl; - std::cout << "\t--check-histo -CH\t\tCheck if the Histogram looks ok and change there color if not" << std::endl; - std::cout << "\t--input-physical -IP\t\tConsider the Input file is containing Physics Class." << std::endl; - std::cout << "\t-L <arg>\t\t\tLimit the number of events to be analysed to arg" << std::endl; - std::cout << "\t-F <arg>\t\t\tSet the first event to analyse to arg (analysis goes from F -> L+F)" << std::endl; - std::cout << "\t-P <arg>\t\t\tSet the Spectra Server Port for online analyis" << std::endl; - std::cout << "\t--last-sim\t\t\tIgnore the list of Run to treat if any and analysed the last simulated file" - << std::endl; - std::cout << "\t--last-phy\t\t\tIgnore the list of Run to treat if any and analysed the last Physics file" - << std::endl; - std::cout << "\t--last-res\t\t\tIgnore the list of Run to treat if any and analysed the last Result file" - << std::endl; - std::cout << "\t--last-any\t\t\tIgnore the list of Run to treat if any and analysed the last generated root file" - << std::endl; - std::cout << "\t--online \t\t\tStart the spectra server" << std::endl; - std::cout << "\t--circular \t\t\tSet the output tree a circular one" << std::endl; - std::cout << std::endl << "NPSimulation only:" << std::endl; - std::cout << "\t-M <arg>\t\t\tExecute Geant4 macro <arg> at startup" << std::endl; - std::cout << "\t-B <arg>\t\t\tExecute in batch mode (no ui) with Geant4 macro <arg> at startup" << std::endl; - std::cout << "\t--random-seed <arg>\t\tSet the random generator seed to <arg> (unsigned int)" << std::endl; - std::cout << "\t--record-track\t\t\tRecord the track of every simulated particle to the ouput tree" << std::endl; - std::cout << std::endl << std::endl; + std::cout << std::endl << "----NPOptionManager Help----" << std::endl << std::endl ; + std::cout << "List of Option " << std::endl ; + std::cout << "\t--help -H -h\t\t\tDisplay this help message" << std::endl ; + std::cout << "\t--detector -D <arg>\t\tSet arg as the detector configuration file" << std::endl ; + std::cout << "\t--event-generator -E <arg>\tSet arg as the event generator file" << std::endl ; + std::cout << "\t--output -O <arg>\t\tSet arg as the Output File Name (output tree)" << std::endl ; + std::cout << "\t--tree-name <arg>\t\tSet arg as the Output Tree Name " << std::endl ; + std::cout << "\t--definition <definition> \tAdd <definition> to the list of definition" << std::endl ; + std::cout << "\t-S \t\t\t\tOne tree output per detector" << std::endl ; + std::cout << "\t--verbose -V <arg>\t\tSet the verbose level, 0 for nothing, 1 for normal printout."<<std::endl; + std::cout << "\t\t\t\t\tError and warning are not affected" << std::endl ; + std::cout << std::endl << "NPAnalysis only:"<<std::endl; + std::cout << "\t--run -R <arg>\t\t\tSet arg as the run to read file list" << std::endl ; + std::cout << "\t-T <name> <file>\t\tTree <name> from root file <file>" << std::endl ; + std::cout << "\t--cal -C <arg>\t\t\tSet arg as the calibration file list" << std::endl ; + std::cout << "\t--disable-branch\t\tDisable of branch of Input tree except the one of the detector (faster)" << std::endl ; + std::cout << "\t--generate-histo -GH\t\tInstantiate the T*Spectra class of each detector" << std::endl ; + std::cout << "\t--check-histo -CH\t\tCheck if the Histogram looks ok and change there color if not" << std::endl ; + std::cout << "\t--input-physical -IP\t\tConsider the Input file is containing Physics Class." << std::endl ; + std::cout << "\t-L <arg>\t\t\tLimit the number of events to be analysed to arg" << std::endl ; + std::cout << "\t-F <arg>\t\t\tSet the first event to analyse to arg (analysis goes from F -> L+F)" << std::endl ; + std::cout << "\t-P <arg>\t\t\tSet the Spectra Server Port for online analyis" << std::endl ; + std::cout << "\t--last-sim\t\t\tIgnore the list of Run to treat if any and analysed the last simulated file" << std::endl ; + std::cout << "\t--last-phy\t\t\tIgnore the list of Run to treat if any and analysed the last Physics file" << std::endl ; + std::cout << "\t--last-res\t\t\tIgnore the list of Run to treat if any and analysed the last Result file" << std::endl ; + std::cout << "\t--last-any\t\t\tIgnore the list of Run to treat if any and analysed the last generated root file" << std::endl ; + std::cout << "\t--online \t\t\tStart the spectra server" << std::endl ; + std::cout << "\t--circular \t\t\tSet the output tree a circular one" << std::endl ; + std::cout << std::endl << "NPSimulation only:"<<std::endl; + std::cout << "\t-M <arg>\t\t\tExecute Geant4 macro <arg> at startup" << std::endl ; + std::cout << "\t-B <arg>\t\t\tExecute in batch mode (no ui) with Geant4 macro <arg> at startup" << std::endl ; + std::cout << "\t--random-seed <arg>\t\tSet the random generator seed to <arg> (unsigned int)" << std::endl ; + std::cout << "\t--record-track\t\t\tRecord the track of every simulated particle to the ouput tree" << std::endl ; + std::cout << std::endl << std::endl ; // exit current program exit(0); } + //////////////////////////////////////////////////////////////////////////////// -void NPOptionManager::Destroy() { +void NPOptionManager::Destroy(){ if (instance != 0) { delete instance; instance = 0; } } //////////////////////////////////////////////////////////////////////////////// -std::string NPOptionManager::GetLastFile() { +std::string NPOptionManager::GetLastFile(){ std::string path = getenv("NPTOOL"); - if (fLastSimFile) - return (path + "/.last_sim_file"); + if(fLastSimFile) + return (path+"/.last_sim_file"); - else if (fLastPhyFile) - return (path + "/.last_phy_file"); + else if(fLastPhyFile) + return (path+"/.last_phy_file"); - else if (fLastResFile) - return (path + "/.last_res_file"); + else if(fLastResFile) + return (path+"/.last_res_file"); - else if (fLastAnyFile) - return (path + "/.last_any_file"); + else if(fLastAnyFile) + return (path+"/.last_any_file"); else return "VOID"; + } diff --git a/NPLib/Core/NPOptionManager.h b/NPLib/Core/NPOptionManager.h index f7e3417846a9466d3522bcaf2ad3685cc6b9191d..4caa6cdaa6874b9cfe7411343a35519932d8ca8f 100644 --- a/NPLib/Core/NPOptionManager.h +++ b/NPLib/Core/NPOptionManager.h @@ -107,6 +107,7 @@ class NPOptionManager{ bool GetCircularTree() {return fCircularTree;} bool IsAnalysis() {return fIsAnalysis;}; bool IsSimulation() {return fIsSimulation;} + bool IsCalibration() {return fIsCalibration;} bool IsReader() {return fReader;} bool IsSplit() {return fIsSplit;} @@ -120,6 +121,7 @@ class NPOptionManager{ std::string GetLastFile(); std::string GetAnalysisOutputPath(){return m_AnalysisOutputPath;}; std::string GetSimulationOutputPath(){return m_SimulationOutputPath;}; + std::string GetCalibrationOutputPath(){return m_CalibrationOutputPath;}; std::string GetEnergyLossPath(){return m_EnergyLossPath;}; // Setters void SetReactionFile(const std::string& name) {fReactionFileName = name;CheckEventGenerator();} @@ -128,6 +130,7 @@ class NPOptionManager{ void SetVerboseLevel(int VerboseLevel) {fVerboseLevel = VerboseLevel;} void SetIsAnalysis(bool val=true){fIsAnalysis=val;}; void SetIsSimulation(bool val=true){fIsSimulation=val;} + void SetIsCalibration(bool val=true){fIsCalibration=val;} void SetReader(bool reader=false){fReader=reader;} public: // user definition @@ -163,6 +166,7 @@ class NPOptionManager{ bool fCircularTree; bool fIsAnalysis; bool fIsSimulation; + bool fIsCalibration; bool fReader; int fVerboseLevel; // 0 for not talk, 1 for talking int fNumberOfEntryToAnalyse; // use to limit the number of analysed in NPA @@ -176,6 +180,7 @@ class NPOptionManager{ std::set<std::string> fDefinition; // a set of user defined definition std::string m_AnalysisOutputPath;// output path of analysed tree std::string m_SimulationOutputPath;// output path of simulated tree + std::string m_CalibrationOutputPath;// output path of calibration histograms std::string m_EnergyLossPath;// input/output path of energy loss table }; diff --git a/NPLib/Core/NPVDetector.h b/NPLib/Core/NPVDetector.h index 072d7288f55bf7a61486742f438f062fc26a2271..1e587764d542148f49ce605d22e032daa51de3f6 100644 --- a/NPLib/Core/NPVDetector.h +++ b/NPLib/Core/NPVDetector.h @@ -64,6 +64,15 @@ namespace NPL { // Create associated branches and associated private member DetectorPhysics address virtual void InitializeRootOutput(){}; + + // Create folders and histograms for calibration + virtual void InitializeRootHistogramsCalib(){}; + + // Fill histograms for calibration + virtual void FillHistogramsCalib(){}; + + // Write histograms for calibration + virtual void WriteHistogramsCalib(){}; // This method is called at each event read from the Input Tree. Aime is to build treat Raw dat in order to extract // physical parameter. diff --git a/NPLib/Core/RootHistogramsCalib.cxx b/NPLib/Core/RootHistogramsCalib.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ff6ed9a3134473cb8f994a72104108ecb782285b --- /dev/null +++ b/NPLib/Core/RootHistogramsCalib.cxx @@ -0,0 +1,166 @@ +/***************************************************************************** + * Copyright (C) 2009-2021 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: N. de Sereville contact address: deserevi@ipno.in2p3.fr * + * * + * Creation Date : 21/07/09 * + * Last update : 10/05/21 * + *---------------------------------------------------------------------------* + * Decription: This class is a singleton class which deals with the ROOT * + * output file and tree both for NPSimulation and NPAnalysis. * + *---------------------------------------------------------------------------* + * Comment: * + * + 03/02/11: Add support for TAsciiFile objects (N. de Sereville) * + * + 10/05/21: Add support for split tree output (A. Matta) * + * * + * * + *****************************************************************************/ + +#include <iostream> +#include <fstream> +#include <cstdlib> + +#include "RootHistogramsCalib.h" +#include "NPOptionManager.h" + +using namespace std; + +RootHistogramsCalib* RootHistogramsCalib::instance = 0; +//////////////////////////////////////////////////////////////////////////////// +RootHistogramsCalib* RootHistogramsCalib::getInstance(std::string fileNameBase){ + // A new instance of RootHistogramsCalib is created if it does not exist: + if (instance == 0) { + instance = new RootHistogramsCalib(fileNameBase.c_str()); + } + + // The instance of RootHistogramsCalib is returned: + return instance; +} + +//////////////////////////////////////////////////////////////////////////////// +void RootHistogramsCalib::Destroy(){ + if (instance != 0) { + delete instance; + instance = 0; + } +} + +//////////////////////////////////////////////////////////////////////////////// +RootHistogramsCalib::RootHistogramsCalib(std::string fileNameBase){ + + cout << endl << "/////////// ROOT Output files ///////////" << endl; + cout << "Initializing ouput files " << endl; + pCurrentDirectory= gDirectory; + bool calibration=false; + + if(NPOptionManager::getInstance()->IsCalibration()){ + calibration= true; + } + + // Setup the base name + if(calibration) + pBaseName = NPOptionManager::getInstance()->GetCalibrationOutputPath(); + else + pBaseName="./"; + + pBaseName += "/"+fileNameBase; + + if (fileNameBase.find("root")==std::string::npos) + pBaseName += ".root"; + + CreateFile("global"); +} + +//////////////////////////////////////////////////////////////////////////////// +void RootHistogramsCalib::CreateFile(std::string name){ + // Create the tree only if does not exist already + string file_name=pBaseName; + + cout << " - Creating output file " << file_name.c_str() << endl; + pRootFile = new TFile(file_name.c_str(), "RECREATE"); + pRootFile->SetCompressionLevel(1); + + gDirectory->cd(pCurrentDirectory->GetPath()); + // + /* + for(auto it = m_DetectorMap.begin() ; it!=m_DetectorMap.end() ;++it){ + string insertion = "_"+it->first; + master << filebase << insertion << ".root" << std::endl; + string filename=path+"/"+filebase+"/"+filebase+insertion+".root"; + auto file = new TFile(filename.c_str(),"RECREATE"); + string treename = "RawTree_"+it->first; + auto tree = new TTree("RawTree",treename.c_str()); + m_TreeMap[it->first]=tree; + m_FileMap[it->first]=file; + tree->SetDirectory(file); + std::cout << "Splitting tree: " << filename << std::endl; + it->second->InitBranch(tree); + } + master.close(); + +*/ +} +//////////////////////////////////////////////////////////////////////////////// +void RootHistogramsCalib::Fill(){ +// for(auto it = pRootTrees.begin();it!=pRootTrees.end();it++){ +// it->second->Fill(); +// } +} + +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +RootHistogramsCalib::~RootHistogramsCalib(){ + // The data is written to the file and the tree is closed: + /*if (pRootFiles.size()>0) { + cout << endl << endl << "Root Output summary" << endl; + TDirectory* pCurrentDirectory= gDirectory; + for(auto it = pRootFiles.begin(); it!=pRootFiles.end();it++){ + cout << " - " <<it->first << " tree and file " << endl; + gDirectory->cd(it->second->GetPath()); + // write TAsciiFile if used + // EventGenerator + if (!pEventGenerator->IsEmpty()) pEventGenerator->Write(0,TAsciiFile::kOverwrite); + // DetectorConfiguration + if (!pDetectorConfiguration->IsEmpty()) pDetectorConfiguration->Write(0,TAsciiFile::kOverwrite); + // CalibrationFile + if (!pCalibrationFile->IsEmpty()) pCalibrationFile->Write(0,TAsciiFile::kOverwrite); + // RunToTreatFile + if (!pRunToTreatFile->IsEmpty()) pRunToTreatFile->Write(0,TAsciiFile::kOverwrite); + // Analysis ConfigFile + if (!pAnalysisConfigFile->IsEmpty()) pAnalysisConfigFile->Write(0,TAsciiFile::kOverwrite); + + cout << " -> Number of entries in the " << it->first << " Tree: " << pRootTrees[it->first]->GetEntries() << endl; + cout << " -> Number of bites written to file: " << pRootTrees[it->first]->Write(0, TObject::kOverwrite) << endl; + it->second->Flush(); + it->second->Purge(1); + + gDirectory->cd(pCurrentDirectory->GetPath()); + it->second->Close(); + } + } + + else { + cout << "\033[1;31mNo histograms and Tree !\033[0m" << endl; + } +*/ +} + +//////////////////////////////////////////////////////////////////////////////// +TFile* RootHistogramsCalib::GetFile(std::string name) { + + if(pRootFile!=nullptr) + return pRootFile; + else{ + std::cout << "Error: Requested file for detector " << name << " does not exist" << std::endl; + exit(1); + } + return 0; +} + + diff --git a/NPLib/Core/RootHistogramsCalib.h b/NPLib/Core/RootHistogramsCalib.h new file mode 100644 index 0000000000000000000000000000000000000000..db79d9b85a2e156599b455961c6d9aee14fff004 --- /dev/null +++ b/NPLib/Core/RootHistogramsCalib.h @@ -0,0 +1,87 @@ +#ifndef ROOTHISTOCALIB_HH +#define ROOTHISTOCALIB_HH +/***************************************************************************** + * Copyright (C) 2009-2021 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: N. de Sereville contact address: deserevi@ipno.in2p3.fr * + * * + * Creation Date : 21/07/09 * + * Last update : 10/05/21 * + *---------------------------------------------------------------------------* + * Decription: This class is a singleton class which deals with the ROOT * + * output file and tree both for NPSimulation and NPAnalysis. * + *---------------------------------------------------------------------------* + * Comment: * + * + 03/02/11: Add support for TAsciiFile objects (N. de Sereville) * + * + 10/05/21: Add support for split tree output (A. Matta) * + * * + * * + *****************************************************************************/ + +// STL +#include <map> + +// NPL headers +#include "TAsciiFile.h" + +// ROOT headers +#include "TH1F.h" +#include "TH2F.h" +#include "TFile.h" +#include "TTree.h" +#include "TList.h" +#include <string> + +class RootHistogramsCalib{ +public: + // The analysis class is designed to be a singleton (i.e. only one instance + // can exist). A member function called Instance is defined, which allows + // the user to get a pointer to the existing instance or to create it if + // it does not yet exist: + // (see the constructor for an explanation of the arguments) + static RootHistogramsCalib* getInstance(std::string fileNameBase = "Calibration"); + + // The analysis class instance can be deleted by calling the Destroy + // method (NOTE: The class destructor is protected, and can thus not be + // called directly): + static void Destroy(); + +protected: + // Constructor (protected) + RootHistogramsCalib(std::string fileNameBase); + + // Destructor (protected) + virtual ~RootHistogramsCalib(); + + // Prevent copying + RootHistogramsCalib(const RootHistogramsCalib& only); + const RootHistogramsCalib& operator=(const RootHistogramsCalib& only); + +private: + // The static instance of the RootHistogramsCalib class: + static RootHistogramsCalib* instance; + +private: + void InitAsciiFiles(); + void CreateFile(std::string name); +public: + TFile* GetFile(std::string name="global") ; + std::map<TString,std::map<TString,TH1F*>>* GetTH1Map(){return TH1Map;}; + std::map<TString,std::map<TString,TH2F*>>* GetTH2Map(){return TH2Map;}; + void Fill(); + +private: + std::string pBaseName; + std::string pMasterFile; + TDirectory* pCurrentDirectory; + TFile* pRootFile = nullptr; + std::map<TString,std::map<TString,TH1F*>>* TH1Map = new std::map<TString,std::map<TString,TH1F*>>; + std::map<TString,std::map<TString,TH2F*>>* TH2Map = new std::map<TString,std::map<TString,TH2F*>>; +}; + +#endif // ROOTHISTOCALIB_HH diff --git a/NPLib/Detectors/Exogam/TExogamData.cxx b/NPLib/Detectors/Exogam/TExogamData.cxx index 5db6fe8d21e3aafcbee03a6e36b7224073882f9a..448d049ce88ad70235f60a432e82bb4dd7db1e22 100644 --- a/NPLib/Detectors/Exogam/TExogamData.cxx +++ b/NPLib/Detectors/Exogam/TExogamData.cxx @@ -43,31 +43,21 @@ TExogamData::~TExogamData() void TExogamData::Clear() { - fEXO_Clover.clear(); - fEXO_Cristal.clear(); - fEXO_Energy.clear(); - fEXO_Time.clear(); - // ECC / E - fEXO_ECC_E_Clover.clear(); - fEXO_ECC_E_Cristal.clear(); - fEXO_ECC_E_Energy.clear(); - // ECC / T - fEXO_ECC_T_Clover.clear(); - fEXO_ECC_T_Cristal.clear(); - fEXO_ECC_T_Time.clear(); - // GOCCE / E - fEXO_GOCCE_E_Clover.clear(); - fEXO_GOCCE_E_Cristal.clear(); - fEXO_GOCCE_E_Segment.clear(); - fEXO_GOCCE_E_Energy.clear(); - // GOCCE / T - fEXO_GOCCE_T_Clover.clear(); - fEXO_GOCCE_T_Cristal.clear(); - fEXO_GOCCE_T_Segment.clear(); - fEXO_GOCCE_T_Time.clear(); - - //GeFill - fEXO_Fill = -1; + fEXO_E.clear(); + fEXO_E_CrystalNbr.clear(); + fEXO_E_TS.clear(); + fEXO_HG.clear(); + fEXO_HG_CrystalNbr.clear(); + fEXO_HG_TS.clear(); + fEXO_TDC.clear(); + fEXO_TDC_CrystalNbr.clear(); + fEXO_TDC_TS.clear(); + fEXO_Outer.clear(); + fEXO_Outer_SubCrystalNbr.clear(); + fEXO_BGO.clear(); + fEXO_BGO_CrystalNbr.clear(); + fEXO_CSI.clear(); + fEXO_CSI_CrystalNbr.clear(); } @@ -75,38 +65,29 @@ void TExogamData::Clear() void TExogamData::Dump() const { cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event XXXXXXXXXXXXXXXXX" << endl; - - // RealValues (for simulation purposes) - cout << "EXO_Mult = " << fEXO_Clover.size() << endl; - for (UShort_t i = 0; i < fEXO_Clover.size(); i++) { - cout << "CloverE: " << fEXO_Clover[i] << " CristalE: " << fEXO_Cristal[i]; - cout << " Energy: " << fEXO_Energy[i]; - cout << " Time: " << fEXO_Energy[i] << endl; + + cout << "Inner6MV Mult = " << fEXO_E.size() << endl; + for (UShort_t i = 0; i < fEXO_E.size(); i++) { + cout << "Energy: " << fEXO_E[i] << " Cristal Numb: " << fEXO_E_CrystalNbr[i] << " TimeStamp: " << fEXO_E_TS[i] << endl; } - - // ECC - // Energy - cout << "EXO_ECC_MultE = " << fEXO_ECC_E_Clover.size() << endl; - for (UShort_t i = 0; i < fEXO_ECC_E_Clover.size(); i++) { - cout << "CloverE: " << fEXO_ECC_E_Clover[i] << " CristalE: " << fEXO_ECC_E_Cristal[i] << " Energy: " << fEXO_ECC_E_Energy[i] << endl; + cout << "Inner20MV Mult = " << fEXO_HG.size() << endl; + for (UShort_t i = 0; i < fEXO_HG.size(); i++) { + cout << "Energy: " << fEXO_HG[i] << " Cristal Numb: " << fEXO_HG_CrystalNbr[i] << " TimeStamp: " << fEXO_HG_TS[i] << endl; } - // Time - cout << "EXO_ECC_MultT = " << fEXO_ECC_T_Clover.size() << endl; - for (UShort_t i = 0; i < fEXO_ECC_T_Clover.size(); i++) { - cout << "CloverT: " << fEXO_ECC_T_Clover[i] << " CristalT: " << fEXO_ECC_T_Cristal[i] << " Time: " << fEXO_ECC_T_Time[i] << endl; + cout << "OutersV Mult = " << fEXO_Outer.size() << endl; + for (UShort_t i = 0; i < fEXO_Outer.size(); i++) { + cout << "Energy: " << fEXO_Outer[i] << " Cristal Numb: " << fEXO_Outer_SubCrystalNbr[i] << endl; } - // GOCCE - // Energy - cout << "EXO_GOCCE_MultE = " << fEXO_GOCCE_E_Clover.size() << endl; - for (UShort_t i = 0; i < fEXO_GOCCE_E_Clover.size(); i++) { - cout << "CloverE: " << fEXO_GOCCE_E_Clover[i] << " CristalE: " << fEXO_GOCCE_E_Cristal[i] << " SegmentE: " << fEXO_GOCCE_E_Segment[i] << " Energy: " << fEXO_GOCCE_E_Energy[i] << endl; + cout << "DeltaTV Mult = " << fEXO_TDC.size() << endl; + for (UShort_t i = 0; i < fEXO_TDC.size(); i++) { + cout << "Energy: " << fEXO_TDC[i] << " Cristal Numb: " << fEXO_TDC_CrystalNbr[i] << " TimeStamp: " << fEXO_TDC_TS[i] << endl; } - // Time - cout << "EXO_GOCCE_MultT = " << fEXO_GOCCE_T_Clover.size() << endl; - for (UShort_t i = 0; i < fEXO_GOCCE_T_Clover.size(); i++) { - cout << "CloverT: " << fEXO_GOCCE_T_Clover[i] << " CristalT: " << fEXO_GOCCE_T_Cristal[i] << " SegmentT: " << fEXO_GOCCE_T_Segment[i] << " Time: " << fEXO_GOCCE_T_Time[i] << endl; + cout << "BGOV Mult = " << fEXO_BGO.size() << endl; + for (UShort_t i = 0; i < fEXO_BGO.size(); i++) { + cout << "Energy: " << fEXO_BGO[i] << " Cristal Numb: " << fEXO_BGO_CrystalNbr[i] << endl; + } + cout << "CSIV Mult = " << fEXO_CSI.size() << endl; + for (UShort_t i = 0; i < fEXO_CSI.size(); i++) { + cout << "Energy: " << fEXO_CSI[i] << " Cristal Numb: " << fEXO_CSI_CrystalNbr[i] << endl; } - - //GeFill - cout << "EXO_GeFill =" << fEXO_Fill << endl; } diff --git a/NPLib/Detectors/Exogam/TExogamData.h b/NPLib/Detectors/Exogam/TExogamData.h index 5163d0b67f12ac6ed7329f9f7ecdad21ce252821..eb2e8c1be05f1ac01c54bb4f98e06149c06f6b1d 100644 --- a/NPLib/Detectors/Exogam/TExogamData.h +++ b/NPLib/Detectors/Exogam/TExogamData.h @@ -17,113 +17,92 @@ * This class hold Exogam Raw data * * * *---------------------------------------------------------------------------* - * Comment: Added vectors for real energy/time values (double) (T.Goigoux CEA) * + * Comment: Added vectors for real energy/time values (double) (T.Goigoux CEA) * * * * * *****************************************************************************/ - // STL -#include <vector> -using namespace std; #include "TObject.h" - - +#include <vector> class TExogamData : public TObject { private: - // real energy value (for npsimulation) - vector<UShort_t> fEXO_Clover; - vector<UShort_t> fEXO_Cristal; - vector<double> fEXO_Energy; - vector<double> fEXO_Time; - // ECC / Energy - vector<UShort_t> fEXO_ECC_E_Clover; - vector<UShort_t> fEXO_ECC_E_Cristal; - vector<UShort_t> fEXO_ECC_E_Energy; - // ECC / Time - vector<UShort_t> fEXO_ECC_T_Clover; - vector<UShort_t> fEXO_ECC_T_Cristal; - vector<UShort_t> fEXO_ECC_T_Time; - // GOCCE / Energy - vector<UShort_t> fEXO_GOCCE_E_Clover; - vector<UShort_t> fEXO_GOCCE_E_Cristal; - vector<UShort_t> fEXO_GOCCE_E_Segment; - vector<UShort_t> fEXO_GOCCE_E_Energy; - // GOCCE / Time - vector<UShort_t> fEXO_GOCCE_T_Clover; - vector<UShort_t> fEXO_GOCCE_T_Cristal; - vector<UShort_t> fEXO_GOCCE_T_Segment; - vector<UShort_t> fEXO_GOCCE_T_Time; - // GeFill - UShort_t fEXO_Fill; + std::vector<UShort_t> fEXO_E; + std::vector<UShort_t> fEXO_E_CrystalNbr; + std::vector<UShort_t> fEXO_E_TS; + + std::vector<UShort_t> fEXO_HG; // Same as Energy but with High Gain (for Low Energy events) + std::vector<UShort_t> fEXO_HG_CrystalNbr; + std::vector<UShort_t> fEXO_HG_TS; + + std::vector<UShort_t> fEXO_TDC; // Internal TDC of EXOGAM + std::vector<UShort_t> fEXO_TDC_CrystalNbr; + std::vector<UShort_t> fEXO_TDC_TS; + + std::vector<UShort_t> fEXO_Outer; + std::vector<UShort_t> fEXO_Outer_SubCrystalNbr; + + std::vector<UShort_t> fEXO_BGO; + std::vector<UShort_t> fEXO_BGO_CrystalNbr; + + std::vector<UShort_t> fEXO_CSI; + std::vector<UShort_t> fEXO_CSI_CrystalNbr; + public: TExogamData(); virtual ~TExogamData(); void Clear(); - void Clear(const Option_t*) {}; + void Clear(const Option_t*){}; void Dump() const; - ///////////////////// SETTERS //////////////////////// - void SetClover(UShort_t clo) { fEXO_Clover.push_back(clo);} - void SetCristal(UShort_t cris) { fEXO_Cristal.push_back(cris);} - void SetEnergy(double ener) { fEXO_Energy.push_back(ener);} - void SetTime(double time) { fEXO_Time.push_back(time);} - // ECC / Energy - void SetECCEClover(UShort_t clov) { fEXO_ECC_E_Clover.push_back(clov);} - void SetECCECristal(UShort_t cris) { fEXO_ECC_E_Cristal.push_back(cris);} - void SetECCEEnergy(UShort_t ener) { fEXO_ECC_E_Energy.push_back(ener);} - // ECC / Time - void SetECCTClover(UShort_t clov) { fEXO_ECC_T_Clover.push_back(clov);} - void SetECCTCristal(UShort_t cris) { fEXO_ECC_T_Cristal.push_back(cris);} - void SetECCTTime(UShort_t time) { fEXO_ECC_T_Time.push_back(time);} - // GOCCE / Energy - void SetGOCCEEClover(UShort_t clov) { fEXO_GOCCE_E_Clover.push_back(clov);} - void SetGOCCEECristal(UShort_t cris) { fEXO_GOCCE_E_Cristal.push_back(cris);} - void SetGOCCEESegment(UShort_t seg) { fEXO_GOCCE_E_Segment.push_back(seg);} - void SetGOCCEEEnergy(UShort_t ener) { fEXO_GOCCE_E_Energy.push_back(ener);} - // GOCCE / Time - void SetGOCCETClover(UShort_t clov) { fEXO_GOCCE_T_Clover.push_back(clov);} - void SetGOCCETCristal(UShort_t cris) { fEXO_GOCCE_T_Cristal.push_back(cris);} - void SetGOCCETSegment(UShort_t seg) { fEXO_GOCCE_T_Segment.push_back(seg);} - void SetGOCCETTime(UShort_t time) { fEXO_GOCCE_T_Time.push_back(time);} - //GeFill - void SetGeFill(UShort_t Fill) {fEXO_Fill = Fill;} - - ///////////////////// GETTERS //////////////////////// - UShort_t GetClover(Int_t i) {return fEXO_Clover[i];} - UShort_t GetCristal(Int_t i) {return fEXO_Cristal[i];} - UShort_t GetEnergy(Int_t i) {return fEXO_Energy[i];} - UShort_t GetTime(Int_t i) {return fEXO_Time[i];} - // ECC / Energy - // UShort_t GetCloverMult() {return fEXO_ECC_E_Clover.size();} - UShort_t GetECCEMult() {return fEXO_ECC_E_Clover.size();} - UShort_t GetECCEClover(Int_t i) {return fEXO_ECC_E_Clover[i];} - UShort_t GetECCECristal(Int_t i) {return fEXO_ECC_E_Cristal[i];} - UShort_t GetECCEEnergy(Int_t i) {return fEXO_ECC_E_Energy[i];} - // ECC / Time - UShort_t GetECCTMult() {return fEXO_ECC_T_Clover.size();} - UShort_t GetECCTClover(Int_t i) {return fEXO_ECC_T_Clover[i];} - UShort_t GetECCTCristal(Int_t i) {return fEXO_ECC_T_Cristal[i];} - UShort_t GetECCTTime(Int_t i) {return fEXO_ECC_T_Time[i];} - // GOCCE / Energy - UShort_t GetGOCCEEMult() {return fEXO_GOCCE_E_Clover.size();} // multiplicity of segments hit in one clover - UShort_t GetGOCCEEClover(Int_t i) {return fEXO_GOCCE_E_Clover[i];} - UShort_t GetGOCCEECristal(Int_t i) {return fEXO_GOCCE_E_Cristal[i];} - UShort_t GetGOCCEESegment(Int_t i) {return fEXO_GOCCE_E_Segment[i];} - UShort_t GetGOCCEEEnergy(Int_t i) {return fEXO_GOCCE_E_Energy[i];} - // GOCCE / Time - UShort_t GetGOCCETMult() {return fEXO_GOCCE_T_Clover.size();} - UShort_t GetGOCCETClover(Int_t i) {return fEXO_GOCCE_T_Clover[i];} - UShort_t GetGOCCETCristal(Int_t i) {return fEXO_GOCCE_T_Cristal[i];} - UShort_t GetGOCCETSegment(Int_t i) {return fEXO_GOCCE_T_Segment[i];} - UShort_t GetGOCCETTime(Int_t i) {return fEXO_GOCCE_T_Time[i];} - //GeFill - UShort_t GetGeFill() {return fEXO_Fill;} + inline void SetInner6MV(UShort_t& Energy, UShort_t& DetNumb, UShort_t& TimeStamp) { + fEXO_E.push_back(Energy); + fEXO_E_CrystalNbr.push_back(DetNumb); + fEXO_E_TS.push_back(TimeStamp); + } + inline void SetInner20MV(UShort_t& Energy, UShort_t& DetNumb, UShort_t& TimeStamp) { + fEXO_HG.push_back(Energy); + fEXO_HG_CrystalNbr.push_back(DetNumb); + fEXO_HG_TS.push_back(TimeStamp); + } + inline void SetDeltaTV(UShort_t& Time, UShort_t& DetNumb, UShort_t& TimeStamp) { + fEXO_TDC.push_back(Time); + fEXO_TDC_CrystalNbr.push_back(DetNumb); + fEXO_TDC_TS.push_back(TimeStamp); + } + inline void SetOutersV(UShort_t& Energy, UShort_t& OutersNumb) { + fEXO_Outer.push_back(Energy); + fEXO_Outer_SubCrystalNbr.push_back(OutersNumb); + } + inline void SetBGOV(UShort_t& Energy, UShort_t& BGONumb) { + fEXO_BGO.push_back(Energy); + fEXO_BGO_CrystalNbr.push_back(BGONumb); + } + inline void SetCSIV(UShort_t& Energy, UShort_t& CSINumb) { + fEXO_CSI.push_back(Energy); + fEXO_CSI_CrystalNbr.push_back(CSINumb); + } + ///////////////////// GETTERS //////////////////////// + inline UShort_t GetEXO_E(UShort_t& i) { return fEXO_E[i]; } + inline UShort_t GetEXO_E_CrystalNbr(UShort_t& i) { return fEXO_E_CrystalNbr[i]; } + inline UShort_t GetEXO_E_TS(UShort_t& i) { return fEXO_E_TS[i]; } + inline UShort_t GetEXO_HG(UShort_t& i) { return fEXO_HG[i]; } + inline UShort_t GetEXO_HG_CrystalNbr(UShort_t& i) { return fEXO_HG_CrystalNbr[i]; } + inline UShort_t GetEXO_HG_TS(UShort_t& i) { return fEXO_HG_TS[i]; } + inline UShort_t GetEXO_TDC(UShort_t& i) { return fEXO_TDC[i]; } + inline UShort_t GetEXO_TDC_CrystalNbr(UShort_t& i) { return fEXO_TDC_CrystalNbr[i]; } + inline UShort_t GetEXO_TDC_TS(UShort_t& i) { return fEXO_TDC_TS[i]; } + inline UShort_t GetEXO_Outer(UShort_t& i) { return fEXO_Outer[i]; } + inline UShort_t GetEXO_Outer_SubCrystalNbr(UShort_t& i) { return fEXO_Outer_SubCrystalNbr[i]; } + inline UShort_t GetEXO_BGO(UShort_t& i) { return fEXO_BGO[i]; } + inline UShort_t GetEXO_BGO_CrystalNbr(UShort_t& i) { return fEXO_BGO_CrystalNbr[i]; } + inline UShort_t GetEXO_CSI(UShort_t& i) { return fEXO_CSI[i]; } + inline UShort_t GetEXO_CSI_CrystalNbr(UShort_t& i) { return fEXO_CSI_CrystalNbr[i]; } - ClassDef(TExogamData,1) // ExogamData structure - }; + ClassDef(TExogamData, 1) // ExogamData structure +}; #endif diff --git a/NPLib/Detectors/Exogam/TExogamPhysics.cxx b/NPLib/Detectors/Exogam/TExogamPhysics.cxx index 9216efef3317ed9827b9a8cf269fb5e4092dae1b..58ea53a90b9a04c7c64b08164514dbe759c27777 100644 --- a/NPLib/Detectors/Exogam/TExogamPhysics.cxx +++ b/NPLib/Detectors/Exogam/TExogamPhysics.cxx @@ -67,7 +67,7 @@ void TExogamPhysics::BuildSimplePhysicalEvent() /////////////////////////////////////////////////////////////////////////// void TExogamPhysics::PreTreat() { - ClearPreTreatedData(); + /*ClearPreTreatedData(); //E @@ -159,13 +159,13 @@ void TExogamPhysics::PreTreat() //cout << "EXOGAM pretreat ok!" << endl; return; - + */ } /////////////////////////////////////////////////////////////////////////// void TExogamPhysics::BuildPhysicalEvent() { - PreTreat(); + /*PreTreat(); if(PreTreatedData -> GetECCEMult() != PreTreatedData -> GetECCTMult()) cout << PreTreatedData -> GetECCEMult() << " " << PreTreatedData -> GetECCTMult() << endl; @@ -391,6 +391,7 @@ void TExogamPhysics::BuildPhysicalEvent() CloverMult = GetClover_Mult(); //cout << "Exogam fine" << endl; + */ } diff --git a/NPLib/Detectors/Exogam/TExogamSpectra.cxx b/NPLib/Detectors/Exogam/TExogamSpectra.cxx index b7d9b9ff6dd4443f307183bf01e19b8bdaf4b29e..bb2b500238ce3033be43340878c53cb8645b4d48 100644 --- a/NPLib/Detectors/Exogam/TExogamSpectra.cxx +++ b/NPLib/Detectors/Exogam/TExogamSpectra.cxx @@ -133,7 +133,7 @@ void TExogamSpectra::FillRawSpectra(TExogamData* RawData){ string family; // Energy - for (unsigned int i = 0; i < RawData->GetECCEMult(); i++){ + /*for (unsigned int i = 0; i < RawData->GetECCEMult(); i++){ name = Form("ExogamEnergyRaw_Clover%d_ECC%d", RawData->GetECCEClover(i)+1,RawData->GetECCECristal(i)+1); family = "Exogam/ERAW/ECC"; FillSpectra(family,name @@ -156,11 +156,12 @@ void TExogamSpectra::FillRawSpectra(TExogamData* RawData){ FillSpectra(family,name ,RawData->GetECCTTime(i)); } +*/ } //////////////////////////////////////////////////////////////////////////////// void TExogamSpectra::FillPreTreatedSpectra(TExogamData* PreTreatedData){ - string name ; +/* string name ; string family; // Energy for (unsigned int i = 0; i < PreTreatedData->GetECCEMult(); i++) { @@ -187,7 +188,7 @@ void TExogamSpectra::FillPreTreatedSpectra(TExogamData* PreTreatedData){ ,PreTreatedData->GetECCTTime(i)); } - +*/ } //////////////////////////////////////////////////////////////////////////////// diff --git a/NPLib/Detectors/ZDD/TZDDData.cxx b/NPLib/Detectors/ZDD/TZDDData.cxx index e1885d22c0e6ecdb26f2032e40a704571eb129de..b41cd81ce9a624bd4fe2df910fa5ea31b64babfb 100644 --- a/NPLib/Detectors/ZDD/TZDDData.cxx +++ b/NPLib/Detectors/ZDD/TZDDData.cxx @@ -44,29 +44,17 @@ TZDDData::~TZDDData() { ////////////////////////////////////////////////////////////////////// void TZDDData::Clear() { - // Drift_Chambers - fZDD_Drift_DetectorNbr.clear(); - fZDD_DriftTime.clear(); - // Energy - fZDD_E_DetectorNbr.clear(); - fZDD_Energy.clear(); - // Time - fZDD_T_DetectorNbr.clear(); - fZDD_Time.clear(); - - // IC Energy - fZDD_E_IC_Nbr.clear(); - fZDD_IC_Energy.clear(); - // IC Time - fZDD_T_IC_Nbr.clear(); - fZDD_IC_Time.clear(); - - // Plastic Energy - fZDD_E_Plastic_Nbr.clear(); - fZDD_Plastic_Energy.clear(); - // Plastic Time - fZDD_T_Plastic_Nbr.clear(); - fZDD_Plastic_Time.clear(); + fZDD_IC_E.clear(); + fZDD_IC_N.clear(); + fZDD_IC_TS.clear(); + fZDD_PM_E.clear(); + fZDD_PM_N.clear(); + fZDD_PM_TS.clear(); + fZDD_DC_N.clear(); + fZDD_DC_TS.clear(); + fZDD_EXO_E.clear(); + fZDD_EXO_N.clear(); + fZDD_EXO_TS.clear(); } @@ -76,21 +64,20 @@ void TZDDData::Dump() const { // This method is very useful for debuging and worth the dev. cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TZDDData::Dump()] XXXXXXXXXXXXXXXXX" << endl; - // Energy - size_t mysize = fZDD_E_DetectorNbr.size(); - cout << "ZDD_E_Mult: " << mysize << endl; - - for (size_t i = 0 ; i < mysize ; i++){ - cout << "DetNbr: " << fZDD_E_DetectorNbr[i] - << " Energy: " << fZDD_Energy[i]; + cout << "ZDD_ICE Mult: " << fZDD_IC_E.size() << endl; + for (size_t i = 0 ; i < fZDD_IC_E.size(); i++){ + cout << "DetNbr: " << fZDD_IC_N[i] << " Energy: " << fZDD_IC_E[i] << " TimeStamp: " << fZDD_IC_TS[i] << endl; + } + cout << "ZDD_PME Mult: " << fZDD_PM_E.size() << endl; + for (size_t i = 0 ; i < fZDD_PM_E.size(); i++){ + cout << "DetNbr: " << fZDD_PM_N[i] << " Energy: " << fZDD_PM_E[i] << " TimeStamp: " << fZDD_PM_TS[i] << endl; } - - // Time - mysize = fZDD_T_DetectorNbr.size(); - cout << "ZDD_T_Mult: " << mysize << endl; - - for (size_t i = 0 ; i < mysize ; i++){ - cout << "DetNbr: " << fZDD_T_DetectorNbr[i] - << " Time: " << fZDD_Time[i]; + cout << "ZDD_DCE Mult: " << fZDD_DC_E.size() << endl; + for (size_t i = 0 ; i < fZDD_DC_E.size(); i++){ + cout << "DetNbr: " << fZDD_DC_N[i] << " Energy: " << fZDD_DC_E[i] << " TimeStamp: " << fZDD_DC_TS[i] << endl; } + cout << "ZDD_EXOE Mult: " << fZDD_EXO_E.size() << endl; + for (size_t i = 0 ; i < fZDD_EXO_E.size(); i++){ + cout << "DetNbr: " << fZDD_EXO_N[i] << " Energy: " << fZDD_EXO_E[i] << " TimeStamp: " << fZDD_EXO_TS[i] << endl; + } } diff --git a/NPLib/Detectors/ZDD/TZDDData.h b/NPLib/Detectors/ZDD/TZDDData.h index 6ac5e4bfa6cc23ebcd775b49aa12c132ea483083..b03959fe43c09c97f3d4d60d053619af609ba1c8 100644 --- a/NPLib/Detectors/ZDD/TZDDData.h +++ b/NPLib/Detectors/ZDD/TZDDData.h @@ -36,34 +36,26 @@ class TZDDData : public TObject { // data members are hold into vectors in order // to allow multiplicity treatment private: - double counter = 0; - // Energy IC - vector<UShort_t> fZDD_E_IC_Nbr; - vector<Double_t> fZDD_IC_Energy; - - // Time IC - vector<UShort_t> fZDD_T_IC_Nbr; - vector<Double_t> fZDD_IC_Time; + // IC + vector<UShort_t> fZDD_IC_E; + vector<UShort_t> fZDD_IC_N; + vector<UShort_t> fZDD_IC_TS; + + // Plastic + vector<UShort_t> fZDD_PM_E; + vector<UShort_t> fZDD_PM_N; + vector<UShort_t> fZDD_PM_TS; - // Energy Plastic - vector<UShort_t> fZDD_E_Plastic_Nbr; - vector<Double_t> fZDD_Plastic_Energy; + // DC + vector<UShort_t> fZDD_DC_E; + vector<UShort_t> fZDD_DC_N; + vector<UShort_t> fZDD_DC_TS; - // Time Plastic - vector<UShort_t> fZDD_T_Plastic_Nbr; - vector<Double_t> fZDD_Plastic_Time; - - // Energy - vector<UShort_t> fZDD_E_DetectorNbr; - vector<Double_t> fZDD_Energy; + // EXOZDD + vector<UShort_t> fZDD_EXO_E; + vector<UShort_t> fZDD_EXO_N; + vector<UShort_t> fZDD_EXO_TS; - // Time - vector<UShort_t> fZDD_T_DetectorNbr; - vector<Double_t> fZDD_Time; - - // DriftTime in DC - vector<UShort_t> fZDD_Drift_DetectorNbr; - vector<Double_t> fZDD_DriftTime; ////////////////////////////////////////////////////////////// // Constructor and destructor @@ -88,128 +80,40 @@ class TZDDData : public TObject { public: ////////////////////// SETTERS //////////////////////// // Energy - inline void SetEnergy(const UShort_t& DetNbr,const Double_t& Energy){ - fZDD_E_DetectorNbr.push_back(DetNbr); - fZDD_Energy.push_back(Energy); + inline void SetZDDIC(const UShort_t& DetNumb,const UShort_t& Energy, const UShort_t& TimeStamp){ + fZDD_IC_E.push_back(Energy); + fZDD_IC_N.push_back(DetNumb); + fZDD_IC_TS.push_back(TimeStamp); };//! - - // Time - inline void SetTime(const UShort_t& DetNbr,const Double_t& Time) { - fZDD_T_DetectorNbr.push_back(DetNbr); - fZDD_Time.push_back(Time); + inline void SetZDDPM(const UShort_t& DetNumb,const UShort_t& Energy, const UShort_t& TimeStamp){ + fZDD_PM_E.push_back(Energy); + fZDD_PM_N.push_back(DetNumb); + fZDD_PM_TS.push_back(TimeStamp); };//! - - // IC Energy - inline void Set_IC_Energy(const UShort_t& IC_Nbr,const Double_t& IC_Energy){ - fZDD_E_IC_Nbr.push_back(IC_Nbr); - fZDD_IC_Energy.push_back(IC_Energy); - };//! - - // IC Time - inline void Set_IC_Time(const UShort_t& IC_Nbr,const Double_t& IC_Time) { - fZDD_T_IC_Nbr.push_back(IC_Nbr); - fZDD_IC_Time.push_back(IC_Time); + inline void SetZDDDC(const UShort_t& DetNumb,const UShort_t& Energy, const UShort_t& TimeStamp){ + fZDD_DC_E.push_back(Energy); + fZDD_DC_N.push_back(DetNumb); + fZDD_DC_TS.push_back(TimeStamp); };//! - - // Plastic Energy - inline void Set_Plastic_Energy(const UShort_t& Plastic_Nbr,const Double_t& Plastic_Energy){ - fZDD_E_Plastic_Nbr.push_back(Plastic_Nbr); - fZDD_Plastic_Energy.push_back(Plastic_Energy); + inline void SetZDDEXO(const UShort_t& DetNumb,const UShort_t& Energy, const UShort_t& TimeStamp){ + fZDD_EXO_E.push_back(Energy); + fZDD_EXO_N.push_back(DetNumb); + fZDD_EXO_TS.push_back(TimeStamp); };//! - // Plastic Time - inline void Set_Plastic_Time(const UShort_t& Plastic_Nbr,const Double_t& Plastic_Time) { - fZDD_T_Plastic_Nbr.push_back(Plastic_Nbr); - fZDD_Plastic_Time.push_back(Plastic_Time); - };//! - - // Position DriftTime and X in DC - inline void Set_DC_Time(const UShort_t& DetNbr, const Double_t& DriftTime) { - fZDD_Drift_DetectorNbr.push_back(DetNbr); - fZDD_DriftTime.push_back(DriftTime); - }; //! - ////////////////////// GETTERS //////////////////////// - // Energy - inline UShort_t GetMultEnergy(std::string Detector) const - {if(Detector == "IC") - return fZDD_E_IC_Nbr.size(); - else if(Detector == "Plastic") - return fZDD_E_Plastic_Nbr.size(); - else{ - std::cout << "Detector should be either IC or Plastic" << std::endl; - return -1; - } - } - - inline UShort_t GetE_DetectorNbr(std::string Detector, const unsigned int &i) const - {if(Detector == "IC") - return fZDD_E_IC_Nbr[i]; - else if(Detector == "Plastic") - return fZDD_E_Plastic_Nbr[i]; - else{ - std::cout << "Detector should be either IC or Plastic" << std::endl; - return -1; - } - } - inline Double_t Get_Energy(std::string Detector, const unsigned int &i) const - {if(Detector == "IC") - return fZDD_IC_Energy[i]; - else if(Detector == "Plastic") - return fZDD_Plastic_Energy[i]; - else{ - std::cout << "Detector should be either IC or Plastic" << std::endl; - return -1; - } - } - - // Time - inline UShort_t GetMultTime(std::string Detector) const - {if(Detector == "IC") - return fZDD_T_IC_Nbr.size(); - else if(Detector == "Plastic") - return fZDD_T_Plastic_Nbr.size(); - else if(Detector == "DC") - return fZDD_Drift_DetectorNbr.size(); - else{ - std::cout << "Detector should be either IC, DC or Plastic" << std::endl; - return -1; - } - } - - inline UShort_t GetT_DetectorNbr(std::string Detector, const unsigned int &i) const - {if(Detector == "IC") - return fZDD_T_IC_Nbr[i]; - else if(Detector == "Plastic") - return fZDD_T_Plastic_Nbr[i]; - else if(Detector == "DC") - return fZDD_Drift_DetectorNbr[i]; - else{ - std::cout << "Detector should be either IC, DC or Plastic" << std::endl; - return -1; - } - } - inline Double_t Get_Time(std::string Detector, const unsigned int &i) const - {if(Detector == "IC") - return fZDD_IC_Time[i]; - else if(Detector == "Plastic") - return fZDD_Plastic_Time[i]; - else if(Detector == "DC") - return fZDD_DriftTime[i]; - else{ - std::cout << "Detector should be either IC, DC or Plastic" << std::endl; - return -1; - } - } - // Position - inline UShort_t GetMultDrift() const { return fZDD_Drift_DetectorNbr.size(); } - inline UShort_t GetDrift_DetectorNbr(const unsigned int& i) const { - return fZDD_Drift_DetectorNbr[i]; - } //! - inline Double_t Get_DriftTime(const unsigned int& i) const { - return fZDD_DriftTime[i]; - } //! - + inline UShort_t GetZDD_ICE(UShort_t& i) { return fZDD_IC_E[i]; } + inline UShort_t GetZDD_ICN(UShort_t& i) { return fZDD_IC_N[i]; } + inline UShort_t GetZDD_ICTS(UShort_t& i) { return fZDD_IC_TS[i]; } + inline UShort_t GetZDD_PME(UShort_t& i) { return fZDD_PM_E[i]; } + inline UShort_t GetZDD_PMN(UShort_t& i) { return fZDD_PM_N[i]; } + inline UShort_t GetZDD_PMTS(UShort_t& i) { return fZDD_PM_TS[i]; } + inline UShort_t GetZDD_DCE(UShort_t& i) { return fZDD_DC_E[i]; } + inline UShort_t GetZDD_DCN(UShort_t& i) { return fZDD_DC_N[i]; } + inline UShort_t GetZDD_DCTS(UShort_t& i) { return fZDD_DC_TS[i]; } + inline UShort_t GetZDD_EXOE(UShort_t& i) { return fZDD_EXO_E[i]; } + inline UShort_t GetZDD_EXON(UShort_t& i) { return fZDD_EXO_N[i]; } + inline UShort_t GetZDD_EXOTS(UShort_t& i) { return fZDD_EXO_TS[i]; } ////////////////////////////////////////////////////////////// // Required for ROOT dictionnary diff --git a/NPLib/Detectors/ZDD/TZDDPhysics.cxx b/NPLib/Detectors/ZDD/TZDDPhysics.cxx index ab4d6319ec1be05c79c52d9cc2c7e2faba5df00a..8d8387a3108a66b3eb210451bb32bf5a030e397e 100644 --- a/NPLib/Detectors/ZDD/TZDDPhysics.cxx +++ b/NPLib/Detectors/ZDD/TZDDPhysics.cxx @@ -96,16 +96,16 @@ void TZDDPhysics::BuildPhysicalEvent() { /////////////////////////////////////////////////////////////////////////// void TZDDPhysics::Treat_DC(){ - // Dont have anything to modify for the moment + /* // Dont have anything to modify for the moment unsigned int mysizeDC = m_PreTreatedData->GetMultDrift(); for(int i = 0; i < mysizeDC; i++){ DC_DetectorNumber.push_back(m_PreTreatedData->GetDrift_DetectorNbr(i)); DC_DriftTime.push_back(m_PreTreatedData->Get_DriftTime(i)); - } + }*/ } /////////////////////////////////////////////////////////////////////////// void TZDDPhysics::Match_E_T(std::string Detector){ - unsigned int mysizeE = m_PreTreatedData->GetMultEnergy(Detector); + /*unsigned int mysizeE = m_PreTreatedData->GetMultEnergy(Detector); unsigned int mysizeT = m_PreTreatedData->GetMultTime(Detector); for (UShort_t e = 0; e < mysizeE ; e++) { for (UShort_t t = 0; t < mysizeT ; t++) { @@ -127,6 +127,7 @@ void TZDDPhysics::Match_E_T(std::string Detector){ } } } +*/ } @@ -155,7 +156,7 @@ void TZDDPhysics::PreTreat() { /////////////////////////////////////////////////////////////////////////// void TZDDPhysics::PreTreatEnergy(std::string Detector, CalibrationManager* Cal){ - unsigned int mysize = m_EventData->GetMultEnergy(Detector); + /*unsigned int mysize = m_EventData->GetMultEnergy(Detector); for (UShort_t i = 0; i < mysize ; ++i) { if (m_EventData->Get_Energy(Detector, i) > m_E_RAW_Threshold) { Double_t Energy = Cal->ApplyCalibration("ZDD/ENERGY"+NPL::itoa(m_EventData->GetE_DetectorNbr(Detector, i)),m_EventData->Get_Energy(Detector, i)); @@ -168,11 +169,12 @@ void TZDDPhysics::PreTreatEnergy(std::string Detector, CalibrationManager* Cal){ } } } +*/ } /////////////////////////////////////////////////////////////////////////// void TZDDPhysics::PreTreatTime(std::string Detector, CalibrationManager* Cal){ - unsigned int mysize = m_EventData->GetMultTime(Detector); +/* unsigned int mysize = m_EventData->GetMultTime(Detector); for (UShort_t i = 0; i < mysize; ++i) { Double_t Time= Cal->ApplyCalibration("ZDD/TIME"+NPL::itoa(m_EventData->GetT_DetectorNbr(Detector, i)),m_EventData->Get_Time(Detector,i)); if(Detector == "IC") @@ -182,6 +184,7 @@ void TZDDPhysics::PreTreatTime(std::string Detector, CalibrationManager* Cal){ else if(Detector == "DC") m_PreTreatedData->Set_DC_Time(m_EventData->GetT_DetectorNbr(Detector, i), Time); } +*/ } diff --git a/NPLib/Detectors/ZDD/TZDDSpectra.cxx b/NPLib/Detectors/ZDD/TZDDSpectra.cxx index 37e9f081a9440eaf119b0eccd25cd6bcf7219fcb..f81ca27962f502d3def2a295cfe7fa3609d9801a 100644 --- a/NPLib/Detectors/ZDD/TZDDSpectra.cxx +++ b/NPLib/Detectors/ZDD/TZDDSpectra.cxx @@ -111,6 +111,7 @@ void TZDDSpectra::FillRawSpectra(TZDDData* RawData) { static string name; static string family; +/* // Energy unsigned int sizeE = RawData->GetMultEnergy("Plastic"); for (unsigned int i = 0; i < sizeE; i++) { @@ -128,6 +129,7 @@ void TZDDSpectra::FillRawSpectra(TZDDData* RawData) { FillSpectra(family,name,RawData->Get_Time("Plastic", i)); } +*/ } @@ -137,7 +139,7 @@ void TZDDSpectra::FillPreTreatedSpectra(TZDDData* PreTreatedData) { static string name; static string family; - // Energy + /*// Energy unsigned int sizeE = PreTreatedData->GetMultEnergy("Plastic"); for (unsigned int i = 0; i < sizeE; i++) { name = "ZDD"+NPL::itoa(PreTreatedData->GetE_DetectorNbr("Plastic", i))+"_ENERGY_CAL"; @@ -154,6 +156,7 @@ void TZDDSpectra::FillPreTreatedSpectra(TZDDData* PreTreatedData) { FillSpectra(family,name,PreTreatedData->Get_Time("Plastic", i)); } +*/ } diff --git a/NPLib/Utility/CMakeLists.txt b/NPLib/Utility/CMakeLists.txt index 73568d9f786cc939dd6e5f88aca45f349bd69370..1c57054b063ea73dc6b1319d75a3999cf1e5fd13 100644 --- a/NPLib/Utility/CMakeLists.txt +++ b/NPLib/Utility/CMakeLists.txt @@ -6,8 +6,10 @@ add_executable(npreader npreader.cxx) target_link_libraries(npreader ${ROOT_LIBRARIES} -lThread -lGraf -lTreePlayer -lHist -lMatrix NPCore) add_executable(nponline nponline.cxx) target_link_libraries(nponline ${ROOT_LIBRARIES} NPCore NPOnline) +add_executable(npcalibration npcalibration.cxx) +target_link_libraries(npcalibration ${ROOT_LIBRARIES} -lThread -lGraf -lTreePlayer -lHist -lMatrix NPCore) add_executable(npspectra_test npspectra_test.cxx) target_link_libraries(npspectra_test ${ROOT_LIBRARIES} NPCore NPOnline) -install(PROGRAMS nptool-installer npanalysis nponline npreader DESTINATION ${CMAKE_BINARY_OUTPUT_DIRECTORY}) +install(PROGRAMS nptool-installer npanalysis nponline npreader npcalibration DESTINATION ${CMAKE_BINARY_OUTPUT_DIRECTORY}) install(SCRIPT ${CMAKE_BINARY_DIR}/scripts/post_install.cmake ${DETLIST}) diff --git a/NPLib/Utility/npcalibration b/NPLib/Utility/npcalibration new file mode 100755 index 0000000000000000000000000000000000000000..5480250b7ac633e92ab894a9b5c17dd7ede49d33 Binary files /dev/null and b/NPLib/Utility/npcalibration differ diff --git a/NPLib/Utility/npcalibration.cxx b/NPLib/Utility/npcalibration.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5f5f76a9635568098ed0db78d40e9347123f6544 --- /dev/null +++ b/NPLib/Utility/npcalibration.cxx @@ -0,0 +1,243 @@ +// NPL +#include"NPDetectorManager.h" +#include"NPOptionManager.h" +#include"NPVAnalysis.h" +#include"NPAnalysisFactory.h" +#include"RootInput.h" +#include"RootHistogramsCalib.h" + +// STL +#include<iostream> +#include<stdio.h> +#include<dlfcn.h> +#include<stdlib.h> +#include<unistd.h> +#include<sys/time.h> + +// Root +#include"TTreeReader.h" +#include"TKey.h" +#include"TEnv.h" +#include"TROOT.h" +void ProgressDisplay(clock_t&,clock_t&,unsigned long&, unsigned long&, unsigned long&, double&, unsigned long&, int&, int&); +void ProgressDisplay(struct timeval& begin, struct timeval& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree); +//////////////////////////////////////////////////////////////////////////////// +int main(int argc , char** argv){ + // command line parsing + NPOptionManager* myOptionManager = NPOptionManager::getInstance(argc,argv); + myOptionManager->SetIsCalibration(); + myOptionManager->SetReader(true); + std::string inputfilename = myOptionManager->GetRunToReadFile(); + // if input files are not given, use those from TAsciiFile + if (myOptionManager->IsDefault("DetectorConfiguration")) { + std::string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("DetectorConfiguration"); + if(name!="fail"){ + myOptionManager->SetDetectorFile(name); + std::cout << "\033[1;33mInfo: No Detector file given, using Input tree one \033[0m" << std::endl;; + } + } + + if (myOptionManager->IsDefault("EventGenerator")) { + std::string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("EventGenerator"); + if(name!="fail"){ + myOptionManager->SetReactionFile(name); + std::cout << "\033[1;33mInfo: No Event file given, using Input tree one \033[0m" << std::endl;; + } + } + + // get input files from NPOptionManager + std::string detectorfileName = myOptionManager->GetDetectorFile(); + std::string OutputfileName = myOptionManager->GetOutputFile(); + + // Instantiate RootOutput + //std::string TreeName="NPTool_Tree"; + + //// User decided of the name + //if(!myOptionManager->IsDefault("TreeName")){ + // TreeName=myOptionManager->GetOutputTreeName(); + //} + + // Case of a Physics tree produced + //else if(!myOptionManager->GetInputPhysicalTreeOption()){ + // TreeName="PhysicsTree"; + // if(myOptionManager->IsDefault("OutputFileName")) + // OutputfileName="PhysicsTree"; + //} + + //// Case of Result tree produced + //else{ + // TreeName="ResultTree"; + // if(myOptionManager->IsDefault("OutputFileName")) + // OutputfileName="ResultTree"; + //} + + RootHistogramsCalib::getInstance(OutputfileName); + + // Instantiate the detector using a file + NPL::DetectorManager* myDetector = new NPL::DetectorManager(); + myDetector->ReadConfigurationFile(detectorfileName); + myDetector->InitializeRootInput(); + // Attempt to load an analysis + // NPL::VAnalysis* UserAnalysis = NULL; + //std::string libName = "./libNPAnalysis" + myOptionManager->GetSharedLibExtension(); + // dlopen(libName.c_str(),RTLD_NOW | RTLD_GLOBAL); + // char* error = dlerror(); + TTreeReader* inputTreeReader = RootInput::getInstance()->GetTreeReader(); + std::cout << "Checking TreeReader adress: " << inputTreeReader << std::endl; + myDetector->SetTreeReader(inputTreeReader); + //if(error==NULL){ + // UserAnalysis = NPL::AnalysisFactory::getInstance()->Construct(); + // UserAnalysis->SetDetectorManager(myDetector); + // UserAnalysis->Init(); + // //UserAnalysis->InitTreeReader(inputTreeReader); + //} + //else{ + // std::string str_error=error; + // if(str_error.find("image not found")!=std::string::npos ||str_error.find("No such file or directory")!=std::string::npos ) + // std::cout << "\033[1;33m**** INFO: No User analysis found, building Physical tree ****\033[0m" << std::endl; + // else{ + // std::cout << "\033[1;31m**** ERROR: Failure to load libNPAnalysis ****" << std::endl << error << "\033[0m" <<std::endl; + // exit(1); + // } + //} + + + std::cout << std::endl << "///////// Starting Analysis ///////// "<< std::endl; + TChain* Chain = RootInput:: getInstance()->GetChain(); + myOptionManager->GetNumberOfEntryToAnalyse(); + + unsigned long first_entry = myOptionManager->GetFirstEntryToAnalyse(); // defaults to zero + unsigned long nentries = Chain->GetEntries(); + if(nentries> myOptionManager->GetNumberOfEntryToAnalyse() && myOptionManager->GetNumberOfEntryToAnalyse()>0) + nentries = myOptionManager->GetNumberOfEntryToAnalyse() ; + if(nentries + first_entry > Chain->GetEntries()) {nentries = first_entry+Chain->GetEntries();} + + + TString ChainName = Chain->GetName(); + std::cout << " Number of Event to be treated : " << nentries << " on chain " << ChainName << std::endl; + + unsigned long inter = 0; + unsigned long treated = 0; + double mean_rate =0; + unsigned long displayed=0; + clock_t end; + clock_t begin = clock(); + struct timeval tv_end; + struct timeval tv_begin; gettimeofday(&tv_begin,NULL); + unsigned long new_nentries = 0 ; + int current_tree = 0 ; + int total_tree = Chain->GetNtrees(); + + bool IsCalibration = myOptionManager->IsCalibration(); + std::cout << IsCalibration << "\n"; + + if(IsCalibration){ + myDetector->InitializeRootHistogramsCalib(); + while(inputTreeReader->Next()){ + myDetector->FillHistogramsCalib(); + current_tree = Chain->GetTreeNumber()+1; + ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + } + myDetector->WriteHistogramsCalib(); + } + else{ + std::cout << "Error, IsCalibration Option not well configured !\n"; + } + std::cout << "test core dumped 1\n"; + +#if __cplusplus > 199711L && NPMULTITHREADING + myDetector->StopThread(); +#endif + + current_tree = Chain->GetTreeNumber()+1; + //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + + std::cout << "test core dumped 2\n"; + ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + + std::cout << "test core dumped 3\n"; + RootInput::Destroy(); + RootHistogramsCalib::Destroy(); + std::cout << "test core dumped 4\n"; + return 0; +} +//////////////////////////////////////////////////////////////////////////////// +void ProgressDisplay(struct timeval& begin, struct timeval& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree){ + gettimeofday(&end,NULL); + long double elapsed= end.tv_sec-begin.tv_sec+(end.tv_usec-begin.tv_usec)*1e-6; + if(elapsed>1||treated>=total ){ + displayed++; + double event_rate = inter/elapsed; + mean_rate += (event_rate-mean_rate)/(displayed); + double percent = 100*treated/total; + double remain = (total-treated)/mean_rate; + + char* timer; + double check; + int minutes = remain/60.; + int seconds = remain -60*minutes; + if(remain>60) + check=asprintf(&timer,"%dmin%ds",minutes,seconds); + else + check=asprintf(&timer,"%ds",(int)(remain)); + + static char star[10]; + if(displayed%2==0 || treated==total) + sprintf(star,"*******"); + else + sprintf(star,"-------"); + + if(treated!=total) + printf("\r \033[1;31m %s Progress: \033[1;36m%.1f%% \033[1;31m| Rate: %.1fk evt/s | Remain: %s | Tree: %d/%d %s \033[0m ", star,percent,mean_rate/1000.,timer, current_tree,total_tree,star); + + else{ + printf("\r \033[1;32m %s Progress: %.1f%% | Rate: %.1fk evt/s | Remain: %s | Tree: %d/%d %s \033[0m ", star,percent,mean_rate/1000.,timer, current_tree, total_tree,star); + } + fflush(stdout); + inter=0; + gettimeofday(&begin,NULL); + } + + treated++; + inter++; +} +//////////////////////////////////////////////////////////////////////////////// +void ProgressDisplay(clock_t& begin, clock_t& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree){ + end = clock(); + if((end-begin)>CLOCKS_PER_SEC||treated>=total ){ + displayed++; + long double elapsed =(long double) (end-begin)/CLOCKS_PER_SEC; + double event_rate = inter/elapsed; + mean_rate += (event_rate-mean_rate)/(displayed); + double percent = 100*treated/total; + double remain = (total-treated)/mean_rate; + + char* timer; + double check; + int minutes = remain/60.; + int seconds = remain -60*minutes; + if(remain>60) + check=asprintf(&timer,"%dmin%ds",minutes,seconds); + else + check=asprintf(&timer,"%ds",(int)(remain)); + + static char star[10]; + if(displayed%2==0 || treated==total) + sprintf(star,"*******"); + else + sprintf(star,"-------"); + + if(treated!=total) + printf("\r \033[1;31m %s Progress: \033[1;36m%.1f%% \033[1;31m| Rate: %.1fk evt/s | Remain: %s | Tree: %d/%d %s \033[0m ", star,percent,mean_rate/1000.,timer, current_tree,total_tree,star); + + else{ + printf("\r \033[1;32m %s Progress: %.1f%% | Rate: %.1fk evt/s | Remain: %s | Tree: %d/%d %s \033[0m ", star,percent,mean_rate/1000.,timer, current_tree, total_tree,star); + } + fflush(stdout); + inter=0; + begin = clock() ; + } + + treated++; + inter++; +}