Commit 42785e9c authored by Morfouace's avatar Morfouace
Browse files

Updtating PISTA detectors

parent d18c6261
add_custom_command(OUTPUT TPISTAPhysicsDict.cxx COMMAND ../../scripts/build_dict.sh TPISTAPhysics.h TPISTAPhysicsDict.cxx TPISTAPhysics.rootmap libNPPISTA.dylib DEPENDS TPISTAPhysics.h)
add_custom_command(OUTPUT TPISTADataDict.cxx COMMAND ../../scripts/build_dict.sh TPISTAData.h TPISTADataDict.cxx TPISTAData.rootmap libNPPISTA.dylib DEPENDS TPISTAData.h)
add_library(NPPISTA SHARED TPISTASpectra.cxx TPISTAData.cxx TPISTAPhysics.cxx TPISTADataDict.cxx TPISTAPhysicsDict.cxx )
target_link_libraries(NPPISTA ${ROOT_LIBRARIES} NPCore)
install(FILES TPISTAData.h TPISTAPhysics.h TPISTASpectra.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
......
/*****************************************************************************
* Copyright (C) 2009-2020 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: Pierre Morfouace contact address: pierre.morfouace2@cea.fr *
* *
* Creation Date : November 2020 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Sofia Raw data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
#include "TSofiaData.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
ClassImp(TSofiaData)
//////////////////////////////////////////////////////////////////////
TSofiaData::TSofiaData() {
}
//////////////////////////////////////////////////////////////////////
TSofiaData::~TSofiaData() {
}
//////////////////////////////////////////////////////////////////////
void TSofiaData::Clear() {
// TOF
fTOF_DetectorNbr.clear();
fTOF_PlasticNbr.clear();
fTOF_Energy.clear();
fTOF_Time.clear();
// TWIN
fTWIN_SectorNbr.clear();
fTWIN_AnodeNbr.clear();
fTWIN_AnodeEnergy.clear();
fTWIN_AnodeTime.clear();
fTWIN_Esum1 = -10;
fTWIN_Esum2 = -10;
fTWIN_Esum3 = -10;
fTWIN_Esum4 = -10;
}
//////////////////////////////////////////////////////////////////////
void TSofiaData::Dump() const {
// This method is very useful for debuging and worth the dev.
cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TSofiaData::Dump()] XXXXXXXXXXXXXXXXX" << endl;
// Energy
size_t mysize = fTOF_DetectorNbr.size();
cout << "TWIN_Mult: " << GetTwinMult() << endl;
cout << "TOF_Mult: " << mysize << endl;
}
#ifndef __SofiaDATA__
#define __SofiaDATA__
/*****************************************************************************
* Copyright (C) 2009-2020 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: Pierre Morfouace contact address: pierre.morfouace2@cea.fr *
* *
* Creation Date : November 2020 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Sofia Raw data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
// STL
#include <vector>
using namespace std;
// ROOT
#include "TObject.h"
class TSofiaData : public TObject {
//////////////////////////////////////////////////////////////
// data members are hold into vectors in order
// to allow multiplicity treatment
private:
// TOF //
vector<int> fTOF_DetectorNbr;
vector<int> fTOF_PlasticNbr;
vector<double> fTOF_Energy;
vector<double> fTOF_Time;
// TWIN MUSIC //
vector<int> fTWIN_SectorNbr;
vector<int> fTWIN_AnodeNbr;
vector<double> fTWIN_AnodeEnergy;
vector<double> fTWIN_AnodeTime;
double fTWIN_Esum1;
double fTWIN_Esum2;
double fTWIN_Esum3;
double fTWIN_Esum4;
//////////////////////////////////////////////////////////////
// Constructor and destructor
public:
TSofiaData();
~TSofiaData();
//////////////////////////////////////////////////////////////
// Inherited from TObject and overriden to avoid warnings
public:
void Clear();
void Clear(const Option_t*) {};
void Dump() const;
//////////////////////////////////////////////////////////////
// Getters and Setters
// Prefer inline declaration to avoid unnecessary called of
// frequently used methods
// add //! to avoid ROOT creating dictionnary for the methods
public:
////////////////////// SETTERS ////////////////////////
// TOF
inline void SetDetectorNbr(int det){fTOF_DetectorNbr.push_back(det);};//!
inline void SetPlasticNbr(int plastic){fTOF_PlasticNbr.push_back(plastic);};//!
inline void SetEnergy(double Energy){fTOF_Energy.push_back(Energy);};//!
inline void SetTime(double Time){fTOF_Time.push_back(Time);};//!
// TWIN
inline void SetTwinSectorNbr(int Sector){fTWIN_SectorNbr.push_back(Sector);};//!
inline void SetTwinAnodeNbr(int Anode){fTWIN_AnodeNbr.push_back(Anode);};//!
inline void SetTwinAnodeEnergy(double Energy){fTWIN_AnodeEnergy.push_back(Energy);};//!
inline void SetTwinAnodeTime(double Time){fTWIN_AnodeTime.push_back(Time);};//!
inline void SetTwinEsum1(double E){fTWIN_Esum1=E;};//!
inline void SetTwinEsum2(double E){fTWIN_Esum2=E;};//!
inline void SetTwinEsum3(double E){fTWIN_Esum3=E;};//!
inline void SetTwinEsum4(double E){fTWIN_Esum4=E;};//!
////////////////////// GETTERS ////////////////////////
// TOF
inline int GetMultiplicity() const {return fTOF_PlasticNbr.size();}//!
inline int GetDetectorNbr(const unsigned int &i) const {return fTOF_DetectorNbr[i];}//!
inline int GetPlasticNbr(const unsigned int &i) const {return fTOF_PlasticNbr[i];}//!
inline double GetEnergy(const unsigned int &i) const {return fTOF_Energy[i];}//!
inline double GetTime(const unsigned int &i) const {return fTOF_Time[i];}//!
// TWIN
inline int GetTwinMult() const {return fTWIN_AnodeNbr.size();}//!
inline int GetTwinSectorNbr(const unsigned int &i) const {return fTWIN_SectorNbr[i];}//!
inline int GetTwinAnodeNbr(const unsigned int &i) const {return fTWIN_AnodeNbr[i];}//!
inline double GetTwinAnodeEnergy(const unsigned int &i) const {return fTWIN_AnodeEnergy[i];}//!
inline double GetTwinAnodeTime(const unsigned int &i) const {return fTWIN_AnodeTime[i];}//!
inline double GetTwinEsum1() const {return fTWIN_Esum1;}//!
inline double GetTwinEsum2() const {return fTWIN_Esum2;}//!
inline double GetTwinEsum3() const {return fTWIN_Esum3;}//!
inline double GetTwinEsum4() const {return fTWIN_Esum4;}//!
//////////////////////////////////////////////////////////////
// Required for ROOT dictionnary
ClassDef(TSofiaData,1) // SofiaData structure
};
#endif
/*****************************************************************************
* Copyright (C) 2009-2020 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: Pierre Morfouace contact address: pierre.morfouace2@cea.fr *
* *
* Creation Date : November 2020 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Sofia Treated data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
#include "TSofiaPhysics.h"
// STL
#include <sstream>
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <limits>
using namespace std;
// NPL
#include "RootInput.h"
#include "RootOutput.h"
#include "NPDetectorFactory.h"
#include "NPOptionManager.h"
// ROOT
#include "TChain.h"
ClassImp(TSofiaPhysics)
///////////////////////////////////////////////////////////////////////////
TSofiaPhysics::TSofiaPhysics()
: m_EventData(new TSofiaData),
m_PreTreatedData(new TSofiaData),
m_EventPhysics(this),
m_Spectra(0),
m_E_RAW_Threshold(0), // adc channels
m_E_Threshold(0), // MeV
m_NumberOfDetectors(0) {
}
///////////////////////////////////////////////////////////////////////////
/// A usefull method to bundle all operation to add a detector
void TSofiaPhysics::AddDetector(TVector3 , string ){
// In That simple case nothing is done
// Typically for more complex detector one would calculate the relevant
// positions (stripped silicon) or angles (gamma array)
m_NumberOfDetectors++;
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::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));
// Call the cartesian method
AddDetector(Pos,shape);
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::BuildSimplePhysicalEvent() {
BuildPhysicalEvent();
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::BuildPhysicalEvent() {
// apply thresholds and calibration
PreTreat();
// match energy and time together
unsigned int mysizeE = m_PreTreatedData->GetMultiplicity();
for (UShort_t e = 0; e < mysizeE ; e++) {
DetectorNumber.push_back(m_PreTreatedData->GetDetectorNbr(e));
PlasticNumber.push_back(m_PreTreatedData->GetPlasticNbr(e));
Energy.push_back(m_PreTreatedData->GetEnergy(e));
Time.push_back(m_PreTreatedData->GetTime(e));
}
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::PreTreat() {
// This method typically applies thresholds and calibrations
// Might test for disabled channels for more complex detector
// clear pre-treated object
ClearPreTreatedData();
// instantiate CalibrationManager
static CalibrationManager* Cal = CalibrationManager::getInstance();
// Energy
unsigned int mysize = m_EventData->GetMultiplicity();
for (UShort_t i = 0; i < mysize ; ++i) {
if (m_EventData->GetEnergy(i) > m_E_RAW_Threshold) {
Double_t Energy = Cal->ApplyCalibration("Sofia/ENERGY"+NPL::itoa(m_EventData->GetPlasticNbr(i)),m_EventData->GetEnergy(i));
if (Energy > m_E_Threshold) {
m_PreTreatedData->SetDetectorNbr(m_EventData->GetDetectorNbr(i));
m_PreTreatedData->SetPlasticNbr(m_EventData->GetPlasticNbr(i));
m_PreTreatedData->SetTime(m_EventData->GetTime(i));
m_PreTreatedData->SetEnergy(Energy);
}
}
}
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::ReadAnalysisConfig() {
bool ReadingStatus = false;
// path to file
string FileName = "./configs/ConfigSofia.dat";
// open analysis config file
ifstream AnalysisConfigFile;
AnalysisConfigFile.open(FileName.c_str());
if (!AnalysisConfigFile.is_open()) {
cout << " No ConfigSofia.dat found: Default parameter loaded for Analayis " << FileName << endl;
return;
}
cout << " Loading user parameter for Analysis from ConfigSofia.dat " << endl;
// Save it in a TAsciiFile
TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
asciiConfig->AppendLine("%%% ConfigSofia.dat %%%");
asciiConfig->Append(FileName.c_str());
asciiConfig->AppendLine("");
// read analysis config file
string LineBuffer,DataBuffer,whatToDo;
while (!AnalysisConfigFile.eof()) {
// Pick-up next line
getline(AnalysisConfigFile, LineBuffer);
// search for "header"
string name = "ConfigSofia";
if (LineBuffer.compare(0, name.length(), name) == 0)
ReadingStatus = true;
// loop on tokens and data
while (ReadingStatus ) {
whatToDo="";
AnalysisConfigFile >> whatToDo;
// Search for comment symbol (%)
if (whatToDo.compare(0, 1, "%") == 0) {
AnalysisConfigFile.ignore(numeric_limits<streamsize>::max(), '\n' );
}
else if (whatToDo=="E_RAW_THRESHOLD") {
AnalysisConfigFile >> DataBuffer;
m_E_RAW_Threshold = atof(DataBuffer.c_str());
cout << whatToDo << " " << m_E_RAW_Threshold << endl;
}
else if (whatToDo=="E_THRESHOLD") {
AnalysisConfigFile >> DataBuffer;
m_E_Threshold = atof(DataBuffer.c_str());
cout << whatToDo << " " << m_E_Threshold << endl;
}
else {
ReadingStatus = false;
}
}
}
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::Clear() {
DetectorNumber.clear();
PlasticNumber.clear();
Energy.clear();
Time.clear();
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::ReadConfiguration(NPL::InputParser parser) {
vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Sofia");
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 << "//// Sofia " << 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 << "//// Sofia " << 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{
cout << "ERROR: check your input file formatting " << endl;
exit(1);
}
}
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::InitSpectra() {
m_Spectra = new TSofiaSpectra(m_NumberOfDetectors);
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::FillSpectra() {
m_Spectra -> FillRawSpectra(m_EventData);
m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData);
m_Spectra -> FillPhysicsSpectra(m_EventPhysics);
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::CheckSpectra() {
m_Spectra->CheckSpectra();
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::ClearSpectra() {
// To be done
}
///////////////////////////////////////////////////////////////////////////
map< string , TH1*> TSofiaPhysics::GetSpectra() {
if(m_Spectra)
return m_Spectra->GetMapHisto();
else{
map< string , TH1*> empty;
return empty;
}
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::WriteSpectra() {
m_Spectra->WriteSpectra();
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::AddParameterToCalibrationManager() {
CalibrationManager* Cal = CalibrationManager::getInstance();
for (int i = 0; i < m_NumberOfDetectors; ++i) {
Cal->AddParameter("Sofia", "D"+ NPL::itoa(i+1)+"_ENERGY","Sofia_D"+ NPL::itoa(i+1)+"_ENERGY");
Cal->AddParameter("Sofia", "D"+ NPL::itoa(i+1)+"_TIME","Sofia_D"+ NPL::itoa(i+1)+"_TIME");
}
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::InitializeRootInputRaw() {
TChain* inputChain = RootInput::getInstance()->GetChain();
inputChain->SetBranchStatus("Sofia", true );
inputChain->SetBranchAddress("Sofia", &m_EventData );
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::InitializeRootInputPhysics() {
TChain* inputChain = RootInput::getInstance()->GetChain();
inputChain->SetBranchAddress("Sofia", &m_EventPhysics);
}
///////////////////////////////////////////////////////////////////////////
void TSofiaPhysics::InitializeRootOutput() {
TTree* outputTree = RootOutput::getInstance()->GetTree();
outputTree->Branch("Sofia", "TSofiaPhysics", &m_EventPhysics);
}
////////////////////////////////////////////////////////////////////////////////
// Construct Method to be pass to the DetectorFactory //
////////////////////////////////////////////////////////////////////////////////
NPL::VDetector* TSofiaPhysics::Construct() {
return (NPL::VDetector*) new TSofiaPhysics();
}
////////////////////////////////////////////////////////////////////////////////
// Registering the construct method to the factory //
////////////////////////////////////////////////////////////////////////////////
extern "C"{
class proxy_Sofia{
public:
proxy_Sofia(){
NPL::DetectorFactory::getInstance()->AddToken("Sofia","Sofia");
NPL::DetectorFactory::getInstance()->AddDetector("Sofia",TSofiaPhysics::Construct);
}
};
proxy_Sofia p_Sofia;
}
#ifndef TSofiaPHYSICS_H
#define TSofiaPHYSICS_H
/*****************************************************************************
* Copyright (C) 2009-2020 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: Pierre Morfouace contact address: pierre.morfouace2@cea.fr *
* *
* Creation Date : November 2020 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Sofia Treated data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
// C++ headers
#include <vector>
#include <map>
#include <string>
using namespace std;
// ROOT headers
#include "TObject.h"
#include "TH1.h"
#include "TVector3.h"
// NPTool headers
#include "TSofiaData.h"
#include "TSofiaSpectra.h"
#include "NPCalibrationManager.h"
#include "NPVDetector.h"
#include "NPInputParser.h"
// forward declaration
class TSofiaSpectra;
class TSofiaPhysics : public TObject, public NPL::VDetector {
//////////////////////////////////////////////////////////////
// constructor and destructor
public:
TSofiaPhysics();
~TSofiaPhysics() {};
//////////////////////////////////////////////////////////////
// Inherited from TObject and overriden to avoid warnings
public:
void Clear();
void Clear(const Option_t*) {};
//////////////////////////////////////////////////////////////
// data obtained after BuildPhysicalEvent() and stored in
// output ROOT file
public:
vector<int> DetectorNumber;
vector<int> PlasticNumber;
vector<double> Energy;
vector<double> Time;