From 4addac8a74407880fe91948a97c8358edf6583a1 Mon Sep 17 00:00:00 2001 From: Pierre Morfouace <pierre.morfouace@gmail.com> Date: Tue, 21 Apr 2015 18:01:39 -0400 Subject: [PATCH] *Debugging TCsIPhysics --- NPLib/CsI/TCsIPhysics.cxx | 6 +- NPLib/CsI/TCsIPhysics.cxx~ | 299 +++++++++++++++++++++++++++++++++++++ NPLib/CsI/TCsIPhysics.h | 7 +- NPLib/CsI/TCsIPhysics.h~ | 98 ++++++++++++ 4 files changed, 405 insertions(+), 5 deletions(-) create mode 100644 NPLib/CsI/TCsIPhysics.cxx~ create mode 100644 NPLib/CsI/TCsIPhysics.h~ diff --git a/NPLib/CsI/TCsIPhysics.cxx b/NPLib/CsI/TCsIPhysics.cxx index 0efb1649a..7b096267b 100644 --- a/NPLib/CsI/TCsIPhysics.cxx +++ b/NPLib/CsI/TCsIPhysics.cxx @@ -22,8 +22,10 @@ // NPL #include "TCsIPhysics.h" -#include "../include/RootOutput.h" -#include "../include/RootInput.h" +#include "RootInput.h" +#include "RootOutput.h" +#include "NPDetectorFactory.h" +#include "NPCalibrationManager.h" // STL #include <iostream> diff --git a/NPLib/CsI/TCsIPhysics.cxx~ b/NPLib/CsI/TCsIPhysics.cxx~ new file mode 100644 index 000000000..e61794478 --- /dev/null +++ b/NPLib/CsI/TCsIPhysics.cxx~ @@ -0,0 +1,299 @@ +/***************************************************************************** + * Copyright (C) 2009-2013 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: Adrien MATTA contact address: matta@ipno.in2p3.fr * + * * + * Creation Date : november 2009 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold CsI Physics * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// NPL +#include "TCsIPhysics.h" +#include "RootInput.h" +#include "RootOutput.h" +#include "NPDetectorFactory.h" + +// STL +#include <iostream> +#include <sstream> +#include <fstream> +#include <limits> +#include <stdlib.h> +using namespace std; + +// ROOT +#include "TChain.h" + +// tranform an integer to a string +string itoa(int value) +{ + char buffer [33]; + sprintf(buffer,"%d",value); + return buffer; +} + +ClassImp(TCsIPhysics) +/////////////////////////////////////////////////////////////////////////// +TCsIPhysics::TCsIPhysics() + { + NumberOfDetector = 0 ; + EventData = new TCsIData ; + EventPhysics = this ; + } + +/////////////////////////////////////////////////////////////////////////// +TCsIPhysics::~TCsIPhysics() + {} + +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::Clear() + { + DetectorNumber.clear() ; + Energy.clear() ; + Time.clear() ; + } + +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::ReadConfiguration(string Path) + { + ifstream ConfigFile ; + ConfigFile.open(Path.c_str()) ; + string LineBuffer ; + string DataBuffer ; + + bool check_Theta = false ; + bool check_Phi = false ; + bool check_R = false ; + bool check_Thickness = false ; + bool check_Radius = false ; + bool check_LeadThickness = false ; + bool check_Scintillator = false ; + bool check_Height = false ; + bool check_Width = false ; + bool check_Shape = false ; + bool check_X = false ; + bool check_Y = false ; + bool check_Z = false ; + bool ReadingStatus = false ; + + while (!ConfigFile.eof()) + { + + getline(ConfigFile, LineBuffer); + + // If line is a Start Up CsI bloc, Reading toggle to true + if (LineBuffer.compare(0, 3, "CsI") == 0) + { + cout << "///" << endl ; + cout << "Platic found: " << endl ; + ReadingStatus = true ; + } + + // Else don't toggle to Reading Block Status + else ReadingStatus = false ; + + // Reading Block + while(ReadingStatus) + { + // Pickup Next Word + ConfigFile >> DataBuffer ; + + // Comment Line + if (DataBuffer.compare(0, 1, "%") == 0) { ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );} + + // Finding another telescope (safety), toggle out + else if (DataBuffer.compare(0, 6, "CsI") == 0) { + cout << "WARNING: Another Detector is find before standard sequence of Token, Error may occured in Telecope definition" << endl ; + ReadingStatus = false ; + } + + //Angle method + else if (DataBuffer=="THETA=") { + check_Theta = true; + ConfigFile >> DataBuffer ; + cout << "Theta: " << atof(DataBuffer.c_str()) << "deg" << endl; + } + + else if (DataBuffer=="PHI=") { + check_Phi = true; + ConfigFile >> DataBuffer ; + cout << "Phi: " << atof( DataBuffer.c_str() ) << "deg" << endl; + } + + else if (DataBuffer=="R=") { + check_R = true; + ConfigFile >> DataBuffer ; + cout << "R: " << atof( DataBuffer.c_str() ) << "mm" << endl; + } + + //Position method + else if (DataBuffer=="X=") { + check_X = true; + ConfigFile >> DataBuffer ; + cout << "X: " << atof( DataBuffer.c_str() ) << "mm" << endl; + } + + else if (DataBuffer=="Y=") { + check_Y = true; + ConfigFile >> DataBuffer ; + cout << "Y: " << atof( DataBuffer.c_str() ) << "mm"<< endl; + } + + else if (DataBuffer=="Z=") { + check_Z = true; + ConfigFile >> DataBuffer ; + cout << "Z: " << atof( DataBuffer.c_str() ) << "mm" << endl; + } + + + //General + else if (DataBuffer=="Shape=") { + check_Shape = true; + ConfigFile >> DataBuffer ; + cout << "Shape: " << DataBuffer << endl; + } + + // Cylindrical shape + else if (DataBuffer== "Radius=") { + check_Radius = true; + ConfigFile >> DataBuffer ; + cout << "CsI Radius: " << atof( DataBuffer.c_str() ) << "mm" << endl; + } + + // Squared shape + else if (DataBuffer=="Width=") { + check_Width = true; + ConfigFile >> DataBuffer ; + cout << "CsI Width: " <<atof( DataBuffer.c_str() ) << "mm" << endl; + } + + else if (DataBuffer== "Height=") { + check_Height = true; + ConfigFile >> DataBuffer ; + cout << "CsI Height: " << atof( DataBuffer.c_str() ) << "mm" << endl; + } + + // Common + else if (DataBuffer=="Thickness=") { + check_Thickness = true; + ConfigFile >> DataBuffer ; + cout << "CsI Thickness: " << atof( DataBuffer.c_str() ) << "mm" << endl; + } + + else if (DataBuffer== "Scintillator=") { + check_Scintillator = true ; + ConfigFile >> DataBuffer ; + cout << "CsI Scintillator type: " << DataBuffer << endl; + } + + else if (DataBuffer=="LeadThickness=") { + check_LeadThickness = true; + ConfigFile >> DataBuffer ; + cout << "Lead Thickness : " << atof( DataBuffer.c_str() ) << "mm" << endl; + } + + /////////////////////////////////////////////////// + // If no Detector Token and no comment, toggle out + else + {ReadingStatus = false; cout << "Wrong Token Sequence: Getting out " << DataBuffer << endl ;} + + ///////////////////////////////////////////////// + // If All necessary information there, toggle out + + if ( check_Theta && check_Phi && check_R && check_Thickness && check_Radius && check_LeadThickness && check_Scintillator && check_Height && check_Width && check_Shape && check_X && check_Y && check_Z ) + { + NumberOfDetector++; + + // Reinitialisation of Check Boolean + check_Theta = false ; + check_Phi = false ; + check_R = false ; + check_Thickness = false ; + check_Radius = false ; + check_LeadThickness = false ; + check_Scintillator = false ; + check_Height = false ; + check_Width = false ; + check_Shape = false ; + check_X = false ; + check_Y = false ; + check_Z = false ; + ReadingStatus = false ; + cout << "///"<< endl ; + } + } + } + } + +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::AddParameterToCalibrationManager() + { + CalibrationManager* Cal = CalibrationManager::getInstance(); + + for(int i = 0 ; i < NumberOfDetector ; i++) + { + for( int j = 0 ; j < 16 ; j++) + { + Cal->AddParameter("CsI", "Detector"+itoa(i+1)+"_E","CsI_Detector"+itoa(i+1)+"_E") ; + Cal->AddParameter("CsI", "Detector"+itoa(i+1)+"_T","CsI_Detector"+itoa(i+1)+"_T") ; + } + + } + } + +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::InitializeRootInputRaw() + { + TChain* inputChain = RootInput::getInstance()->GetChain() ; + inputChain->SetBranchStatus ( "CsI" , true ) ; + inputChain->SetBranchStatus ( "fCsI_*" , true ) ; + inputChain->SetBranchAddress( "CsI" , &EventData ) ; + } +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::InitializeRootInputPhysics() + { + TChain* inputChain = RootInput::getInstance()->GetChain(); + inputChain->SetBranchStatus ( "CsI", true ); + inputChain->SetBranchStatus ( "DetectorNumber", true ); + inputChain->SetBranchStatus ( "Energy", true ); + inputChain->SetBranchStatus ( "Time", true ); + inputChain->SetBranchAddress( "CsI", &EventPhysics ); + } +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::InitializeRootOutput() + { + TTree* outputTree = RootOutput::getInstance()->GetTree() ; + outputTree->Branch( "CsI" , "TCsIPhysics" , &EventPhysics ) ; + } + +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::BuildPhysicalEvent() + { + BuildSimplePhysicalEvent() ; + } + +/////////////////////////////////////////////////////////////////////////// +void TCsIPhysics::BuildSimplePhysicalEvent() + { + for(unsigned int i = 0 ; i < EventData->GetEnergyMult() ; i++) + { + DetectorNumber.push_back( EventData->GetENumber(i) ) ; + Energy.push_back( CalibrationManager::getInstance()->ApplyCalibration("CsI/Detector" + itoa( EventData->GetENumber(i) ) +"_E",EventData->GetEEnergy(i) ) ); + Time.push_back( CalibrationManager::getInstance()->ApplyCalibration( "CsI/Detector" + itoa( EventData->GetENumber(i) ) +"_T",EventData->GetTTime(i) ) ); + } + + } + diff --git a/NPLib/CsI/TCsIPhysics.h b/NPLib/CsI/TCsIPhysics.h index c0d16c3eb..af4651b64 100644 --- a/NPLib/CsI/TCsIPhysics.h +++ b/NPLib/CsI/TCsIPhysics.h @@ -31,10 +31,11 @@ using namespace std ; // NPL #include "TCsIData.h" -#include "../include/VDetector.h" -#include "../include/CalibrationManager.h" +#include "NPVDetector.h" -class TCsIPhysics : public TObject, public NPA::VDetector +//#include "../include/CalibrationManager.h" + +class TCsIPhysics : public TObject, public NPL::VDetector { public: // Constructor and Destructor TCsIPhysics(); diff --git a/NPLib/CsI/TCsIPhysics.h~ b/NPLib/CsI/TCsIPhysics.h~ new file mode 100644 index 000000000..1e9244bff --- /dev/null +++ b/NPLib/CsI/TCsIPhysics.h~ @@ -0,0 +1,98 @@ +#ifndef __CsIPhysics__ +#define __CsIPhysics__ +/***************************************************************************** + * Copyright (C) 2009-2014 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: Adrien MATTA contact address: a.matta@surrey.ac.uk * + * * + * Creation Date : November 2009 * + * Last update : * + *---------------------------------------------------------------------------* + * Decription: * + * This class hold theCsI Detector Physics * + * * + *---------------------------------------------------------------------------* + * Comment: * + * * + * * + *****************************************************************************/ + +// STL +#include <vector> +using namespace std ; + +// ROOT +#include "TObject.h" + +// NPL +#include "TCsIData.h" +#include "NPVDetector.h" + +//#include "../include/CalibrationManager.h" + +class TCsIPhysics : public TObject, public NPA::VDetector +{ + public: // Constructor and Destructor + TCsIPhysics(); + ~TCsIPhysics(); + + public: + void Clear(); + void Clear(const Option_t*) {}; + + public: // Calibrated Data + vector<UShort_t> DetectorNumber ; + vector<Double_t> Energy; + vector<Double_t> Time; + + public: // inherrited from VDetector + // Read stream at ConfigFile to pick-up parameters of detector (Position,...) using Token + void ReadConfiguration(string); + + + // Add Parameter to the CalibrationManger + void AddParameterToCalibrationManager(); + + // Activated associated Branches and link it to the private member DetectorData address + // In this method mother Branches (Detector) AND daughter leaf (fDetector_parameter) have to be activated + void InitializeRootInputRaw() ; + + // Activated associated Branches and link it to the private member DetectorPhysics address + // In this method mother Branches (Detector) AND daughter leaf (parameter) have to be activated + void InitializeRootInputPhysics() ; + + // Create associated branches and associated private member DetectorPhysics address + void InitializeRootOutput(); + + // 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. + void BuildPhysicalEvent(); + + // Same as above, but only the simplest event and/or simple method are used (low multiplicity, faster algorythm but less efficient ...). + // This method aimed to be used for analysis performed during experiment, when speed is requiered. + // NB: This method can eventually be the same as BuildPhysicalEvent. + void BuildSimplePhysicalEvent(); + + // Same as above but for online analysis + void BuildOnlinePhysicalEvent() {BuildPhysicalEvent();}; + + // Give and external TCsIData object to TCsIPhysics. Needed for online analysis for example. + void SetRawDataPointer(TCsIData* rawDataPointer) {EventData = rawDataPointer;} + + // Those two method all to clear the Event Physics or Data + void ClearEventPhysics() {Clear();} + void ClearEventData() {EventData->Clear();} + + private: // Data not writted in the tree + int NumberOfDetector ;//! + TCsIData* EventData ;//! + TCsIPhysics* EventPhysics ;//! + + ClassDef(TCsIPhysics,1) // CsIPhysics structure +}; + +#endif -- GitLab