Commit de9745f2 authored by Valérian Alcindor's avatar Valérian Alcindor
Browse files

Several updates related to STRASSE and addition of a GAGG detector as well as...

Several updates related to STRASSE and addition of a GAGG detector as well as several small improvement
parent c0608a5a
Pipeline #101391 passed with stages
in 8 minutes and 34 seconds
......@@ -6,7 +6,7 @@
*****************************************************************************/
/*****************************************************************************
* Original Author: Valerian Alcindor contact address: *
* Original Author: Valerian Alcindor contact address: *
* *
* Creation Date : October 2020 *
* Last update : *
......@@ -16,66 +16,62 @@
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
* *
*****************************************************************************/
#include "TGAGGPhysics.h"
// STL
#include <sstream>
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <iostream>
#include <limits>
#include <sstream>
#include <stdlib.h>
using namespace std;
// NPL
#include "RootInput.h"
#include "RootOutput.h"
#include "NPDetectorFactory.h"
#include "NPOptionManager.h"
#include "RootInput.h"
#include "RootOutput.h"
// ROOT
#include "TChain.h"
ClassImp(TGAGGPhysics)
///////////////////////////////////////////////////////////////////////////
TGAGGPhysics::TGAGGPhysics()
: m_EventData(new TGAGGData),
m_PreTreatedData(new TGAGGData),
m_EventPhysics(this),
m_Spectra(0),
m_E_RAW_Threshold(0), // adc channels
m_E_Threshold(0), // MeV
m_NumberOfDetectors(0) {
///////////////////////////////////////////////////////////////////////////
TGAGGPhysics::TGAGGPhysics()
: m_EventData(new TGAGGData), m_PreTreatedData(new TGAGGData),
m_EventPhysics(this), m_Spectra(0), m_E_RAW_Threshold(0), // adc channels
m_E_Threshold(0), // MeV
m_NumberOfDetectors(0) {
m_Position.clear();
}
///////////////////////////////////////////////////////////////////////////
/// A usefull method to bundle all operation to add a detector
void TGAGGPhysics::AddDetector(TVector3 , string ){
void TGAGGPhysics::AddDetector(TVector3 Pos, string shape) {
// In That simple case nothing is done
// Typically for more complex detector one would calculate the relevant
// Typically for more complex detector one would calculate the relevant
// positions (stripped silicon) or angles (gamma array)
m_Position.push_back(Pos);
m_NumberOfDetectors++;
}
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::AddDetector(double R, double Theta, double Phi, string shape){
void TGAGGPhysics::AddDetector(double R, double Theta, double Phi,
string shape) {
// Compute the TVector3 corresponding
TVector3 Pos(R*sin(Theta)*cos(Phi),R*sin(Theta)*sin(Phi),R*cos(Theta));
TVector3 Pos(R * sin(Theta) * cos(Phi), R * sin(Theta) * sin(Phi),
R * cos(Theta));
// Call the cartesian method
AddDetector(Pos,shape);
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::BuildSimplePhysicalEvent() {
BuildPhysicalEvent();
AddDetector(Pos, shape);
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::BuildSimplePhysicalEvent() { BuildPhysicalEvent(); }
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::BuildPhysicalEvent() {
......@@ -85,9 +81,10 @@ void TGAGGPhysics::BuildPhysicalEvent() {
// match energy and time together
unsigned int mysizeE = m_PreTreatedData->GetMultEnergy();
unsigned int mysizeT = m_PreTreatedData->GetMultTime();
for (UShort_t e = 0; e < mysizeE ; e++) {
for (UShort_t t = 0; t < mysizeT ; t++) {
if (m_PreTreatedData->GetE_DetectorNbr(e) == m_PreTreatedData->GetT_DetectorNbr(t)) {
for (UShort_t e = 0; e < mysizeE; e++) {
for (UShort_t t = 0; t < mysizeT; t++) {
if (m_PreTreatedData->GetE_DetectorNbr(e)
== m_PreTreatedData->GetT_DetectorNbr(t)) {
DetectorNumber.push_back(m_PreTreatedData->GetE_DetectorNbr(e));
Energy.push_back(m_PreTreatedData->Get_Energy(e));
Time.push_back(m_PreTreatedData->Get_Time(t));
......@@ -96,6 +93,11 @@ void TGAGGPhysics::BuildPhysicalEvent() {
}
}
///////////////////////////////////////////////////////////////////////////
TVector3 TGAGGPhysics::GetPositionOfInteraction(int& i) {
return m_Position[DetectorNumber[i]];
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::PreTreat() {
// This method typically applies thresholds and calibrations
......@@ -109,25 +111,27 @@ void TGAGGPhysics::PreTreat() {
// Energy
unsigned int mysize = m_EventData->GetMultEnergy();
for (UShort_t i = 0; i < mysize ; ++i) {
for (UShort_t i = 0; i < mysize; ++i) {
if (m_EventData->Get_Energy(i) > m_E_RAW_Threshold) {
Double_t Energy = Cal->ApplyCalibration("GAGG/ENERGY"+NPL::itoa(m_EventData->GetE_DetectorNbr(i)),m_EventData->Get_Energy(i));
Double_t Energy = Cal->ApplyCalibration(
"GAGG/ENERGY" + NPL::itoa(m_EventData->GetE_DetectorNbr(i)),
m_EventData->Get_Energy(i));
if (Energy > m_E_Threshold) {
m_PreTreatedData->SetEnergy(m_EventData->GetE_DetectorNbr(i), Energy);
}
}
}
// Time
// Time
mysize = m_EventData->GetMultTime();
for (UShort_t i = 0; i < mysize; ++i) {
Double_t Time= Cal->ApplyCalibration("GAGG/TIME"+NPL::itoa(m_EventData->GetT_DetectorNbr(i)),m_EventData->Get_Time(i));
Double_t Time = Cal->ApplyCalibration(
"GAGG/TIME" + NPL::itoa(m_EventData->GetT_DetectorNbr(i)),
m_EventData->Get_Time(i));
m_PreTreatedData->SetTime(m_EventData->GetT_DetectorNbr(i), Time);
}
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::ReadAnalysisConfig() {
bool ReadingStatus = false;
......@@ -140,44 +144,46 @@ void TGAGGPhysics::ReadAnalysisConfig() {
AnalysisConfigFile.open(FileName.c_str());
if (!AnalysisConfigFile.is_open()) {
cout << " No ConfigGAGG.dat found: Default parameter loaded for Analayis " << FileName << endl;
cout << " No ConfigGAGG.dat found: Default parameter loaded for Analayis "
<< FileName << endl;
return;
}
cout << " Loading user parameter for Analysis from ConfigGAGG.dat " << endl;
// Save it in a TAsciiFile
TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
TAsciiFile* asciiConfig
= RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
asciiConfig->AppendLine("%%% ConfigGAGG.dat %%%");
asciiConfig->Append(FileName.c_str());
asciiConfig->AppendLine("");
// read analysis config file
string LineBuffer,DataBuffer,whatToDo;
string LineBuffer, DataBuffer, whatToDo;
while (!AnalysisConfigFile.eof()) {
// Pick-up next line
getline(AnalysisConfigFile, LineBuffer);
// search for "header"
string name = "ConfigGAGG";
if (LineBuffer.compare(0, name.length(), name) == 0)
if (LineBuffer.compare(0, name.length(), name) == 0)
ReadingStatus = true;
// loop on tokens and data
while (ReadingStatus ) {
whatToDo="";
while (ReadingStatus) {
whatToDo = "";
AnalysisConfigFile >> whatToDo;
// Search for comment symbol (%)
if (whatToDo.compare(0, 1, "%") == 0) {
AnalysisConfigFile.ignore(numeric_limits<streamsize>::max(), '\n' );
AnalysisConfigFile.ignore(numeric_limits<streamsize>::max(), '\n');
}
else if (whatToDo=="E_RAW_THRESHOLD") {
else if (whatToDo == "E_RAW_THRESHOLD") {
AnalysisConfigFile >> DataBuffer;
m_E_RAW_Threshold = atof(DataBuffer.c_str());
cout << whatToDo << " " << m_E_RAW_Threshold << endl;
}
else if (whatToDo=="E_THRESHOLD") {
else if (whatToDo == "E_THRESHOLD") {
AnalysisConfigFile >> DataBuffer;
m_E_Threshold = atof(DataBuffer.c_str());
cout << whatToDo << " " << m_E_Threshold << endl;
......@@ -190,8 +196,6 @@ void TGAGGPhysics::ReadAnalysisConfig() {
}
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::Clear() {
DetectorNumber.clear();
......@@ -199,36 +203,32 @@ void TGAGGPhysics::Clear() {
Time.clear();
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::ReadConfiguration(NPL::InputParser parser) {
vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("GAGG");
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << "//// " << blocks.size() << " detectors found " << endl;
vector<string> cart = {"POS","Shape"};
vector<string> sphe = {"R","Theta","Phi","Shape"};
for(unsigned int i = 0 ; i < blocks.size() ; i++){
if(blocks[i]->HasTokenList(cart)){
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << endl << "//// GAGG " << i+1 << endl;
TVector3 Pos = blocks[i]->GetTVector3("POS","mm");
if (NPOptionManager::getInstance()->GetVerboseLevel())
cout << "//// " << blocks.size() << " detectors found " << endl;
vector<string> cart = {"POS", "Shape"};
vector<string> sphe = {"R", "Theta", "Phi", "Shape"};
for (unsigned int i = 0; i < blocks.size(); i++) {
if (blocks[i]->HasTokenList(cart)) {
if (NPOptionManager::getInstance()->GetVerboseLevel())
cout << endl << "//// GAGG " << i + 1 << endl;
TVector3 Pos = blocks[i]->GetTVector3("POS", "mm");
string Shape = blocks[i]->GetString("Shape");
AddDetector(Pos, Shape);
} else if (blocks[i]->HasTokenList(sphe)) {
if (NPOptionManager::getInstance()->GetVerboseLevel())
cout << endl << "//// GAGG " << i + 1 << endl;
double R = blocks[i]->GetDouble("R", "mm");
double Theta = blocks[i]->GetDouble("Theta", "deg");
double Phi = blocks[i]->GetDouble("Phi", "deg");
string Shape = blocks[i]->GetString("Shape");
AddDetector(Pos,Shape);
}
else if(blocks[i]->HasTokenList(sphe)){
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << endl << "//// GAGG " << i+1 << endl;
double R = blocks[i]->GetDouble("R","mm");
double Theta = blocks[i]->GetDouble("Theta","deg");
double Phi = blocks[i]->GetDouble("Phi","deg");
string Shape = blocks[i]->GetString("Shape");
AddDetector(R,Theta,Phi,Shape);
}
else{
AddDetector(R, Theta, Phi, Shape);
} else {
cout << "ERROR: check your input file formatting " << endl;
exit(1);
}
......@@ -240,105 +240,83 @@ void TGAGGPhysics::InitSpectra() {
m_Spectra = new TGAGGSpectra(m_NumberOfDetectors);
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::FillSpectra() {
m_Spectra -> FillRawSpectra(m_EventData);
m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData);
m_Spectra -> FillPhysicsSpectra(m_EventPhysics);
m_Spectra->FillRawSpectra(m_EventData);
m_Spectra->FillPreTreatedSpectra(m_PreTreatedData);
m_Spectra->FillPhysicsSpectra(m_EventPhysics);
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::CheckSpectra() {
m_Spectra->CheckSpectra();
}
void TGAGGPhysics::CheckSpectra() { m_Spectra->CheckSpectra(); }
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::ClearSpectra() {
// To be done
}
///////////////////////////////////////////////////////////////////////////
map< string , TH1*> TGAGGPhysics::GetSpectra() {
if(m_Spectra)
map<string, TH1*> TGAGGPhysics::GetSpectra() {
if (m_Spectra)
return m_Spectra->GetMapHisto();
else{
map< string , TH1*> empty;
else {
map<string, TH1*> empty;
return empty;
}
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::WriteSpectra() {
m_Spectra->WriteSpectra();
}
void TGAGGPhysics::WriteSpectra() { m_Spectra->WriteSpectra(); }
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::AddParameterToCalibrationManager() {
CalibrationManager* Cal = CalibrationManager::getInstance();
for (int i = 0; i < m_NumberOfDetectors; ++i) {
Cal->AddParameter("GAGG", "D"+ NPL::itoa(i+1)+"_ENERGY","GAGG_D"+ NPL::itoa(i+1)+"_ENERGY");
Cal->AddParameter("GAGG", "D"+ NPL::itoa(i+1)+"_TIME","GAGG_D"+ NPL::itoa(i+1)+"_TIME");
Cal->AddParameter("GAGG", "D" + NPL::itoa(i + 1) + "_ENERGY",
"GAGG_D" + NPL::itoa(i + 1) + "_ENERGY");
Cal->AddParameter("GAGG", "D" + NPL::itoa(i + 1) + "_TIME",
"GAGG_D" + NPL::itoa(i + 1) + "_TIME");
}
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::InitializeRootInputRaw() {
TChain* inputChain = RootInput::getInstance()->GetChain();
inputChain->SetBranchStatus("GAGG", true );
inputChain->SetBranchAddress("GAGG", &m_EventData );
inputChain->SetBranchStatus("GAGG", true);
inputChain->SetBranchAddress("GAGG", &m_EventData);
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::InitializeRootInputPhysics() {
TChain* inputChain = RootInput::getInstance()->GetChain();
inputChain->SetBranchAddress("GAGG", &m_EventPhysics);
}
///////////////////////////////////////////////////////////////////////////
void TGAGGPhysics::InitializeRootOutput() {
TTree* outputTree = RootOutput::getInstance()->GetTree();
outputTree->Branch("GAGG", "TGAGGPhysics", &m_EventPhysics);
}
////////////////////////////////////////////////////////////////////////////////
// Construct Method to be pass to the DetectorFactory //
////////////////////////////////////////////////////////////////////////////////
NPL::VDetector* TGAGGPhysics::Construct() {
return (NPL::VDetector*) new TGAGGPhysics();
return (NPL::VDetector*)new TGAGGPhysics();
}
////////////////////////////////////////////////////////////////////////////////
// Registering the construct method to the factory //
////////////////////////////////////////////////////////////////////////////////
extern "C"{
class proxy_GAGG{
public:
proxy_GAGG(){
NPL::DetectorFactory::getInstance()->AddToken("GAGG","GAGG");
NPL::DetectorFactory::getInstance()->AddDetector("GAGG",TGAGGPhysics::Construct);
}
extern "C" {
class proxy_GAGG {
public:
proxy_GAGG() {
NPL::DetectorFactory::getInstance()->AddToken("GAGG", "GAGG");
NPL::DetectorFactory::getInstance()->AddDetector("GAGG",
TGAGGPhysics::Construct);
}
};
proxy_GAGG p_GAGG;
}
......@@ -8,7 +8,7 @@
*****************************************************************************/
/*****************************************************************************
* Original Author: Valerian Alcindor contact address: *
* Original Author: Valerian Alcindor contact address: *
* *
* Creation Date : October 2020 *
* Last update : *
......@@ -18,163 +18,163 @@
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
* *
*****************************************************************************/
// C++ headers
#include <vector>
// C++ headers
#include <map>
#include <string>
#include <vector>
using namespace std;
// ROOT headers
#include "TObject.h"
#include "TH1.h"
#include "TObject.h"
#include "TVector3.h"
// NPTool headers
#include "TGAGGData.h"
#include "TGAGGSpectra.h"
#include "NPCalibrationManager.h"
#include "NPVDetector.h"
#include "NPInputParser.h"
#include "NPVDetector.h"
#include "TGAGGData.h"
#include "TGAGGSpectra.h"
// forward declaration
class TGAGGSpectra;
class TGAGGPhysics : public TObject, public NPL::VDetector {
//////////////////////////////////////////////////////////////
// constructor and destructor
public:
TGAGGPhysics();
~TGAGGPhysics() {};
public:
TGAGGPhysics();
~TGAGGPhysics(){};
//////////////////////////////////////////////////////////////
// Inherited from TObject and overriden to avoid warnings
public:
void Clear();
void Clear(const Option_t*) {};
public:
void Clear();
void Clear(const Option_t*){};
//////////////////////////////////////////////////////////////
// data obtained after BuildPhysicalEvent() and stored in
// output ROOT file
public:
vector<int> DetectorNumber;
vector<double> Energy;
vector<double> Time;
public:
vector<int> DetectorNumber;
vector<double> Energy;
vector<double> Time;
vector<TVector3> m_Position;
/// A usefull method to bundle all operation to add a detector
void AddDetector(TVector3 POS, string shape);
void AddDetector(double R, double Theta, double Phi, string shape);
void AddDetector(TVector3 POS, string shape);
void AddDetector(double R, double Theta, double Phi, string shape);
//////////////////////////////////////////////////////////////
// methods inherited from the VDetector ABC class
public:
// read stream from ConfigFile to pick-up detector parameters
void ReadConfiguration(NPL::InputParser);
public:
// read stream from ConfigFile to pick-up detector parameters
void ReadConfiguration(NPL::InputParser);
// add parameters to the CalibrationManger
void AddParameterToCalibrationManager();
// add parameters to the CalibrationManger
void AddParameterToCalibrationManager();
// method called event by event, aiming at extracting the
// physical information from detector
void BuildPhysicalEvent();
// method called event by event, aiming at extracting the
// physical information from detector
void BuildPhysicalEvent();
// same as BuildPhysicalEvent() method but with a simpler
// treatment
void BuildSimplePhysicalEvent();
// same as BuildPhysicalEvent() method but with a simpler
// treatment
void BuildSimplePhysicalEvent();
// same as above but for online analysis
void BuildOnlinePhysicalEvent() {BuildPhysicalEvent();};
// same as above but for online analysis
void BuildOnlinePhysicalEvent() { BuildPhysicalEvent(); };
// activate raw data object and branches from input TChain
// in this method mother branches (Detector) AND daughter leaves
// (fDetector_parameter) have to be activated
void InitializeRootInputRaw();
// activate raw data object and branches from input TChain
// in this method mother branches (Detector) AND daughter leaves
// (fDetector_parameter) have to be activated
void InitializeRootInputRaw();
// activate physics data object and branches from input TChain
// in this method mother branches (Detector) AND daughter leaves
// (fDetector_parameter) have to be activated
void InitializeRootInputPhysics();
// activate physics data object and branches from input TChain
// in this method mother branches (Detector) AND daughter leaves
// (fDetector_parameter) have to be activated
void InitializeRootInputPhysics();
// create branches of output ROOT file
void InitializeRootOutput();
// create branches of output ROOT file
void InitializeRootOutput();
// clear the raw and physical data objects event by event
void ClearEventPhysics() {Clear();}
void ClearEventData() {m_EventData->Clear();}
// clear the raw and physical data objects event by event
void ClearEventPhysics() { Clear(); }
void ClearEventData() { m_EventData->Clear(); }
// methods related to the TGAGGSpectra class
// instantiate the TGAGGSpectra class and
// declare list of histograms
void InitSpectra();
// methods related to the TGAGGSpectra class
// instantiate the TGAGGSpectra class and
// declare list of histograms
void InitSpectra();
// fill the spectra
void FillSpectra();
// fill the spectra
void FillSpectra();
// used for Online mainly, sanity check for histograms and
// change their color if issues are found, for example
void CheckSpectra();
// used for Online mainly, sanity check for histograms and
// change their color if issues are found, for example
void CheckSpectra();
// used for Online only, clear all the spectra
void ClearSpectra();
// write spectra to ROOT output file
void WriteSpectra();
// used for Online only, clear all the spectra
void ClearSpectra();
// write spectra to ROOT output file
void WriteSpectra();
//////////////////////////////////////////////////////////////
// specific methods to GAGG array
public:
// remove bad channels, calibrate the data and apply thresholds
void PreTreat();
public:
// remove bad channels, calibrate the data and apply thresholds
void PreTreat();
// clear the pre-treated object
void ClearPreTreatedData() { m_PreTreatedData->Clear(); }
// clear the pre-treated object
void ClearPreTreatedData