From e9a7c751391208efa6f996bf04dc433873718431 Mon Sep 17 00:00:00 2001 From: matta <matta@npt> Date: Wed, 10 Feb 2010 07:35:34 +0000 Subject: [PATCH] * Reviewing Calibration manager logic - Adding missing call of VDetector::AddParameterToCalibManager in the DetectorManager class - Modifing the algorithm that read the calibration file so it should work (hopefully) - Modifiyng analysis project so it's instantiate things in the correct order --- NPAnalysis/10He_Riken/src/Analysis.cc | 23 +++++++----- NPAnalysis/e530/src/Analysis.cc | 34 +++++++++--------- .../CalibrationManager/CalibrationManager.cxx | 36 ++++++++++++------- NPLib/CalibrationManager/CalibrationManager.h | 5 --- NPLib/MUST2/TMust2Physics.cxx | 8 ++--- NPLib/VDetector/DetectorManager.cxx | 1 + 6 files changed, 62 insertions(+), 45 deletions(-) diff --git a/NPAnalysis/10He_Riken/src/Analysis.cc b/NPAnalysis/10He_Riken/src/Analysis.cc index 1c4954590..8243ec186 100644 --- a/NPAnalysis/10He_Riken/src/Analysis.cc +++ b/NPAnalysis/10He_Riken/src/Analysis.cc @@ -17,6 +17,7 @@ int main(int argc,char** argv) string calibrationfileName = argv[2] ; string runToReadfileName = argv[3] ; + ///////////////////////////////////////////////////////////////////////////////////////////////////// // First of All instantiate RootInput and Output // Detector will be attached later RootInput:: getInstance(runToReadfileName) ; @@ -29,13 +30,19 @@ int main(int argc,char** argv) NPL::Reaction* Li10Reaction = new Reaction ; Li10Reaction -> ReadConfigurationFile("9Li-dp-10Li.reaction") ; + // Instantiate the Calibration Manger using a file (WARNING:prior to the detector instantiation) + CalibrationManager* myCalibration = CalibrationManager::getInstance(calibrationfileName) ; + // Instantiate the detector using a file NPA::DetectorManager* myDetector = new DetectorManager ; myDetector -> ReadConfigurationFile(detectorfileName) ; - - // Instantiate the Calibration Manger using a file - CalibrationManager* myCalibration = new CalibrationManager(calibrationfileName) ; + // Ask the detector manager to load the parameter added by the detector in the calibrationfileName + myCalibration->LoadParameterFromFile() ; + ///////////////////////////////////////////////////////////////////////////////////////////////////// + + + // Attach more branch to the output double ELab[2], ExcitationEnergy[2] ; @@ -46,11 +53,11 @@ int main(int argc,char** argv) RootOutput::getInstance()->GetTree()->Branch("ExcitationEnergy",ExcitationEnergy,"ExcitationEnergy[2]/D") ; //E lab et Theta lab - RootOutput::getInstance()->GetTree()->Branch("ThetaCM",ThetaCM,"ThetaCM[2]/D") ; - RootOutput::getInstance()->GetTree()->Branch("ELab",ELab,"ELab[2]/D") ; - RootOutput::getInstance()->GetTree()->Branch("ThetaLab",ThetaLab,"ThetaLab[2]/D") ; - RootOutput::getInstance()->GetTree()->Branch("X",X,"X/D[2]") ; - RootOutput::getInstance()->GetTree()->Branch("Y",Y,"Y/D[2]") ; + RootOutput::getInstance()->GetTree()->Branch("ThetaCM",ThetaCM,"ThetaCM[2]/D") ; + RootOutput::getInstance()->GetTree()->Branch("ELab",ELab,"ELab[2]/D") ; + RootOutput::getInstance()->GetTree()->Branch("ThetaLab",ThetaLab,"ThetaLab[2]/D") ; + RootOutput::getInstance()->GetTree()->Branch("X",X,"X/D[2]") ; + RootOutput::getInstance()->GetTree()->Branch("Y",Y,"Y/D[2]") ; // Get the formed Chained Tree and Treat it diff --git a/NPAnalysis/e530/src/Analysis.cc b/NPAnalysis/e530/src/Analysis.cc index 733750fb1..8ecfe8998 100644 --- a/NPAnalysis/e530/src/Analysis.cc +++ b/NPAnalysis/e530/src/Analysis.cc @@ -17,26 +17,28 @@ int main(int argc,char** argv) string reactionfileName = argv[1] ; string detectorfileName = argv[2] ; string calibrationfileName = argv[3] ; - string runToReadfileName = argv[4] ; + string runToTreatFileName = argv[4] ; - // First of All instantiate RootInput and Output - // Detector will be attached later - RootInput:: getInstance(runToReadfileName) ; - //RootOutput::getInstance("Analysis/10HeRiken_AnalyzedData", "AnalyzedTree") ; - RootOutput::getInstance("Analysis/Fe60", "Analysed_Data") ; + ///////////////////////////////////////////////////////////////////////////////////////////////////// + // First of All instantiate RootInput and Output + // Detector will be attached later + RootInput:: getInstance(runToTreatFileName) ; + RootOutput::getInstance("Analysis/60Fe_AnalyzedData", "AnalyzedTree") ; - // Instantiate some Reaction + // Instantiate some Reaction + NPL::Reaction* e530Reaction = new Reaction ; + e530Reaction -> ReadConfigurationFile(reactionfileName) ; - NPL::Reaction* Fe60Reaction = new Reaction; - Fe60Reaction -> ReadConfigurationFile(reactionfileName); + // Instantiate the Calibration Manger using a file (WARNING:prior to the detector instantiation) + CalibrationManager* myCalibration = CalibrationManager::getInstance(calibrationfileName) ; - // Instantiate the detector using a file - NPA::DetectorManager* myDetector = new DetectorManager ; - myDetector -> ReadConfigurationFile(detectorfileName) ; - - // Instantiate the Calibration Manger using a file - // CalibrationManager* myCalibration = new CalibrationManager(calibrationfileName) ; - CalibrationManager* myCalibration = CalibrationManager::getInstance(calibrationfileName); + // Instantiate the detector using a file + NPA::DetectorManager* myDetector = new DetectorManager ; + myDetector -> ReadConfigurationFile(detectorfileName) ; + + // Ask the detector manager to load the parameter added by the detector in the calibrationfileName + myCalibration->LoadParameterFromFile() ; + ///////////////////////////////////////////////////////////////////////////////////////////////////// // Attach more branch to the output diff --git a/NPLib/CalibrationManager/CalibrationManager.cxx b/NPLib/CalibrationManager/CalibrationManager.cxx index 5287937c3..15c4b3cef 100644 --- a/NPLib/CalibrationManager/CalibrationManager.cxx +++ b/NPLib/CalibrationManager/CalibrationManager.cxx @@ -25,6 +25,7 @@ #include <cstdlib> #include <limits> #include <cmath> +#include <sstream> ////////////////////////////////////////////////////////////////// CalibrationManager* CalibrationManager::instance = 0; @@ -99,35 +100,43 @@ void CalibrationManager::LoadParameterFromFile() { ifstream CalibFile ; string DataBuffer ; + string LineBuffer ; for(unsigned int i = 0 ; i < fFileList.size() ; i++) { CalibFile.open( fFileList[i].c_str() ); - vector<double> Coeff ; map<string,string>::iterator it ; if(!CalibFile) { cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << endl ; - cout << " WARNING: FILE " << fFileList[i] << " IS MISSING " << endl ; + cout << " WARNING: FILE " << fFileList[i] << " IS MISSING " << endl ; cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << endl ; } else while( !CalibFile.eof() ) { - CalibFile >> DataBuffer ; + // Read the file Line by line + getline(CalibFile, LineBuffer); + // Create a istringstream to manipulate the line easely + istringstream theLine (LineBuffer,istringstream::in); + theLine >> DataBuffer ; + + // Comment support, comment symbole is % + if(DataBuffer.compare(0, 1, "%") == 0) { + CalibFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );} + // Search word in the token list it=fToken.find(DataBuffer); // if the word is find, values are read if( it!=fToken.end() ) { - - Coeff.clear(); - while(DataBuffer!="\n") + vector<double> Coeff ; + while( !theLine.eof() ) { - CalibFile >> DataBuffer ; Coeff.push_back( atof(DataBuffer.c_str()) ) ; + theLine >> DataBuffer ; Coeff.push_back( atof(DataBuffer.c_str()) ) ; } // Check this parameter is not already define @@ -142,19 +151,18 @@ void CalibrationManager::LoadParameterFromFile() CalibFile.close() ; } } -////////////////////////////////////////////////////////////////// -bool FillCalibrationTable(string ParameterPattern, vector< vector <vector <double> > > &table) - { - - } ////////////////////////////////////////////////////////////////// double CalibrationManager::ApplyCalibration(string ParameterPath , double RawValue) { double CalibratedValue = 0 ; map< string , vector<double> >::iterator it ; + + // Find the good parameter in the Map + // Using Find method of stl is the fastest way it = fCalibrationCoeff.find(ParameterPath) ; + // If the find methods return the end iterator it's mean the parameter was not found if(it == fCalibrationCoeff.end() ) { /* cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << endl ; @@ -164,8 +172,12 @@ double CalibrationManager::ApplyCalibration(string ParameterPath , double RawVal return RawValue ; } + // Else we take the second part of the element (first is index, ie: parameter path) + // Second is the vector of Coeff vector<double> Coeff = it->second ; + // The vector size give the degree of calibration + // We just apply the coeff and returned the calibrated value for(unsigned int i = 0 ; i < Coeff.size() ; i++) { CalibratedValue += Coeff[i]*pow(RawValue, (double)i); diff --git a/NPLib/CalibrationManager/CalibrationManager.h b/NPLib/CalibrationManager/CalibrationManager.h index 48e28ca19..a5fc1950b 100644 --- a/NPLib/CalibrationManager/CalibrationManager.h +++ b/NPLib/CalibrationManager/CalibrationManager.h @@ -52,15 +52,10 @@ class CalibrationManager public: // Calibration Parameter Related - /*FIXME to be deleted later */ // call like : myCalibrationManager->AddParameter( "MUST2" ,"Telescope5_Si_X38_E", "T5_Si_X38_E" ) // return false if the token is not found in the file list bool AddParameter(string DetectorName , string ParameterName , string Token) ; - // Fill the Detector associated table with the asked parameter - bool FillCalibrationTable(string ParameterPattern , vector< vector <double> > &table) ; - - /*FIXME to be deleted later */ // call like : myCalibrationManager->ApplyCalibration( "MUST2/Telescope5_Si_X38_E" , RawEnergy ) // return the Calibrated value double ApplyCalibration(string ParameterPath , double RawValue); diff --git a/NPLib/MUST2/TMust2Physics.cxx b/NPLib/MUST2/TMust2Physics.cxx index d56961c2f..fbc27b9c7 100644 --- a/NPLib/MUST2/TMust2Physics.cxx +++ b/NPLib/MUST2/TMust2Physics.cxx @@ -41,16 +41,16 @@ ClassImp(TMust2Physics) /////////////////////////////////////////////////////////////////////////// TMust2Physics::TMust2Physics() { - EventMultiplicity = 0 ; - EventData = new TMust2Data ; - EventPhysics = this ; + EventMultiplicity = 0 ; + EventData = new TMust2Data ; + EventPhysics = this ; + NumberOfTelescope = 0 ; } /////////////////////////////////////////////////////////////////////////// void TMust2Physics::BuildSimplePhysicalEvent() { BuildPhysicalEvent(); - } /////////////////////////////////////////////////////////////////////////// diff --git a/NPLib/VDetector/DetectorManager.cxx b/NPLib/VDetector/DetectorManager.cxx index 398198c95..92991cdee 100644 --- a/NPLib/VDetector/DetectorManager.cxx +++ b/NPLib/VDetector/DetectorManager.cxx @@ -302,6 +302,7 @@ void DetectorManager::InitializeRootOutput() void DetectorManager::AddDetector(string DetectorName , VDetector* newDetector) { m_Detector[DetectorName] = newDetector; + newDetector->AddParameterToCalibrationManager(); } -- GitLab