Commit ef853002 authored by flavigny's avatar flavigny
Browse files

* Adding BigRIPS Ionization Chamber treatment and cleanup

parent d0ad73a4
......@@ -6,8 +6,12 @@ add_custom_command(OUTPUT TBigRIPSPlasticDataDict.cxx COMMAND ${CMAKE_BINARY_DIR
add_custom_command(OUTPUT TBigRIPSPlasticPhysicsDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TBigRIPSPlasticPhysics.h TBigRIPSPlasticPhysicsDict.cxx TBigRIPSPlasticPhysics.rootmap libNPBigRIPS.dylib DEPENDS TBigRIPSPlasticPhysics.h)
add_library(NPBigRIPS SHARED TBigRIPSPPACData.cxx TBigRIPSPPACDataDict.cxx TBigRIPSPPACPhysics.cxx TBigRIPSPPACPhysicsDict.cxx TBigRIPSPlasticData.cxx TBigRIPSPlasticDataDict.cxx TBigRIPSPlasticPhysics.cxx TBigRIPSPlasticPhysicsDict.cxx )
add_custom_command(OUTPUT TBigRIPSICDataDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TBigRIPSICData.h TBigRIPSICDataDict.cxx TBigRIPSICData.rootmap libNPBigRIPS.dylib DEPENDS TBigRIPSICData.h)
add_custom_command(OUTPUT TBigRIPSICPhysicsDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TBigRIPSICPhysics.h TBigRIPSICPhysicsDict.cxx TBigRIPSICPhysics.rootmap libNPBigRIPS.dylib DEPENDS TBigRIPSICPhysics.h)
add_library(NPBigRIPS SHARED TBigRIPSPPACData.cxx TBigRIPSPPACDataDict.cxx TBigRIPSPPACPhysics.cxx TBigRIPSPPACPhysicsDict.cxx TBigRIPSPlasticData.cxx TBigRIPSPlasticDataDict.cxx TBigRIPSPlasticPhysics.cxx TBigRIPSPlasticPhysicsDict.cxx TBigRIPSICData.cxx TBigRIPSICDataDict.cxx TBigRIPSICPhysics.cxx TBigRIPSICPhysicsDict.cxx)
target_link_libraries(NPBigRIPS ${ROOT_LIBRARIES} NPCore NPTrackReconstruction)
install(FILES TBigRIPSPPACData.h TBigRIPSPPACPhysics.h TBigRIPSPlasticData.h TBigRIPSPPACPhysics.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
install(FILES TBigRIPSPPACData.h TBigRIPSPPACPhysics.h TBigRIPSPlasticData.h TBigRIPSPlasticPhysics.h TBigRIPSICData.h TBigRIPSICPhysics.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
#include "TBigRIPSICData.h"
#include <iostream>
TBigRIPSICData::TBigRIPSICData(){};
TBigRIPSICData::~TBigRIPSICData(){};
////////////////////////////////////////////////////////////////////////////////
void TBigRIPSICData::Clear(){
fIC_E.clear();
fIC_E_ID.clear();
fIC_E_Layer.clear();
fIC_T.clear();
fIC_T_ID.clear();
fIC_T_Layer.clear();
}
////////////////////////////////////////////////////////////////////////////////
void TBigRIPSICData::Print(){
using namespace std;
cout << " -- Event:" << endl;
//cout << " - Multiplicity: " << Mult() << endl;
}
ClassImp(TBigRIPSICData);
#ifndef TBigRIPSICData_H
#define TBigRIPSICData_H
#include "TObject.h"
#include <vector>
class TBigRIPSICData: public TObject{
public:
TBigRIPSICData();
~TBigRIPSICData();
private:
std::vector<int> fIC_E;
std::vector<int> fIC_E_ID;
std::vector<int> fIC_E_Layer;
std::vector<int> fIC_T;
std::vector<int> fIC_T_ID;
std::vector<int> fIC_T_Layer;
public:
void Clear();
void Print();
void Clear(const Option_t*) {};
void Dump() const{};
public:
void SetE(const int& E, const int& ID, const int& Layer){fIC_E.push_back(E);fIC_E_ID.push_back(ID);fIC_E_Layer.push_back(Layer);}
void SetT(const int& T, const int& ID, const int& Layer){fIC_T.push_back(T);fIC_T_ID.push_back(ID);fIC_T_Layer.push_back(Layer);}
int GetEMult() const {return fIC_E_ID.size();}
int const GetE(const unsigned int& i){return fIC_E[i];};
int const GetEID(const unsigned int& i){return fIC_E_ID[i];};
int const GetELayer(const unsigned int& i){return fIC_E_Layer[i];};
int GetTMult() const {return fIC_T_ID.size();}
int const GetT(const unsigned int& i){return fIC_T[i];};
int const GetTID(const unsigned int& i){return fIC_T_ID[i];};
int const GetTLayer(const unsigned int& i){return fIC_T_Layer[i];};
ClassDef(TBigRIPSICData,1);
};
#endif
/*****************************************************************************
* 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: F, Flavigny contact address: flavigny@lpccaen.in2p3.fr *
* *
* Creation Date : April 2021 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold RIBF IC treated data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
*****************************************************************************/
#include "TBigRIPSICPhysics.h"
// STL
#include <sstream>
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <limits>
// NPL
#include "RootInput.h"
#include "RootOutput.h"
#include "TAsciiFile.h"
#include "NPOptionManager.h"
#include "NPDetectorFactory.h"
#include "NPSystemOfUnits.h"
// ROOT
using namespace NPUNITS;
///////////////////////////////////////////////////////////////////////////
ClassImp(TBigRIPSICPhysics)
///////////////////////////////////////////////////////////////////////////
TBigRIPSICPhysics::TBigRIPSICPhysics(){
m_EventData = new TBigRIPSICData ;
m_PreTreatedData = new TBigRIPSICData ;
m_EventPhysics = this ;
//m_Spectra = NULL;
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::BuildSimplePhysicalEvent(){
BuildPhysicalEvent();
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::BuildPhysicalEvent(){
PreTreat();
return;
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::PreTreat(){
ClearPreTreatedData();
//Intermediate map associating a IC ID with its variables stored in an object
static map<int, BigRIPSICVariables > Fdata ;
static map<int, BigRIPSICVariables >::iterator found;
Fdata.clear() ;
int id,layer,ERaw;
//E
unsigned int sizeE = m_EventData->GetEMult();
for(unsigned int i = 0 ; i < sizeE ; i++){
id = m_EventData->GetEID(i);
layer = m_EventData->GetELayer(i);
ERaw = m_EventData->GetE(i);
Fdata[id].FE.push_back(ERaw);
Fdata[id].FE_Layer.push_back(layer);
}
int Nmulti;
BigRIPSICVariables tmp;
for(auto it = Fdata.begin();it!=Fdata.end();++it){
id = it->first;
ID.push_back(id);
FP.push_back(IDtoFP[id]);
tmp.Clear();
tmp = it->second;
//tmp.Print();
//Calculate E
double adc, Ecal;
double AvSum=0;
double SqSum=1;
int NLFired=0;
for (unsigned int j = 0; j < tmp.FE.size(); j++) {
adc = tmp.FE[j] - pedestal[id][tmp.FE_Layer[j]];
/*
std::cout << ">> FE : " << tmp.FE[j] << std::endl;
std::cout << ">> FE_Layer : " << tmp.FE_Layer[j] << std::endl;
std::cout << ">> ped : " << pedestal[id][tmp.FE_Layer[j]] << std::endl;
std::cout << ">> adc : " << adc << std::endl;
*/
if(adc>0){
AvSum = AvSum + adc;
SqSum = SqSum * adc;
NLFired++;
Ecal = ch2mev_0[id] + adc * ch2mev_1[id];
E.push_back(Ecal);
E_Layer.push_back(tmp.FE_Layer[j]);
//std::cout << ">> FE_Layer 22222222 : " << tmp.FE_Layer[j] << std::endl;
E_ID.push_back(id);
}
}
if(NLFired>0){
AvSum = AvSum/NLFired;
SqSum = std::pow(SqSum,1/NLFired);
RawAvSum.push_back(AvSum);
RawSqSum.push_back(SqSum);
CalAvSum.push_back(ch2mev_0[id] + AvSum * ch2mev_1[id]);
CalSqSum.push_back(ch2mev_0[id] + SqSum * ch2mev_1[id]);
NLayerFired.push_back(NLFired);
}else{
RawAvSum.push_back(-9999);
RawSqSum.push_back(-9999);
CalAvSum.push_back(-9999);
CalSqSum.push_back(-9999);
}
}//end of loop on FData (loop on all plastics)
//Print();
Fdata.clear();
return;
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::Clear(){
ID.clear();
FP.clear();
RawAvSum.clear();
RawSqSum.clear();
CalAvSum.clear();
CalSqSum.clear();
E.clear();
E_Layer.clear();
E_ID.clear();
NLayerFired.clear();
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::Print(){
/*
cout << "XXXXXXXXXXXXXXXXXXXXXXXX IC Physics Event XXXXXXXXXXXXXXXXX" << endl;
cout << "TL_Mult = " << TL.size();
for (UShort_t i = 0; i < TL.size(); i++){cout << "\tTL: " << TL[i] << endl;}
cout << "TR_Mult = " << TR.size();
for (UShort_t i = 0; i < TR.size(); i++){cout << "\tTR: " << TR[i] << endl;}
cout << "QL_Mult = " << QL.size();
for (UShort_t i = 0; i < QL.size(); i++){cout << "\tQL: " << QL[i] << endl;}
cout << "QR_Mult = " << QR.size();
for (UShort_t i = 0; i < QR.size(); i++){cout << "\tQR: " << QR[i] << endl;}
*/
}
///////////////////////////////////////////////////////////////////////////
//// Innherited from VDetector Class ////
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::ReadConfiguration(NPL::InputParser parser){
vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("BigRIPSIC");
if(NPOptionManager::getInstance()->GetVerboseLevel())
cout << "//// " << blocks.size() << " IC detector file found " << endl;
vector<string> token= {"XML"};
for(unsigned int i = 0 ; i < blocks.size() ; i++){
cout << endl << "//// BigRIPSIC file (" << i+1 << ")" << endl;
string xmlpath = blocks[i]->GetString("XML");
NPL::XmlParser xml;
xml.LoadFile(xmlpath);
AddICs("BigRIPSIC",xml);
}
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::AddICs(string name, NPL::XmlParser& xml){
std::vector<NPL::XML::block*> b = xml.GetAllBlocksWithName(name);
if(name=="BigRIPSIC"){
unsigned int size = b.size();
for(unsigned int i = 0 ; i < size ; i++){
unsigned int ID = b[i]->AsInt("ID");
IDtoFP[ID] = b[i]->AsInt("FPL");
ch2mev_0[ID] = b[i]->AsDouble("ch2mev_0");
ch2mev_1[ID] = b[i]->AsDouble("ch2mev_1");
for(unsigned int j = 0 ; j < 10 ; j++){
std::string str_ped = "pedestal" + std::to_string(j) ;
pedestal[ID][j] = b[i]->AsInt(str_ped);
}
}
}
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::InitSpectra(){
//m_Spectra = new TBigRIPSICSpectra(m_NumberOfDetector);
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::FillSpectra(){
// m_Spectra -> FillRawSpectra(m_EventData);
// m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData);
// m_Spectra -> FillPhysicsSpectra(m_EventPhysics);
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::CheckSpectra(){
// m_Spectra->CheckSpectra();
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::ClearSpectra(){
// To be done
}
///////////////////////////////////////////////////////////////////////////
map< string , TH1*> TBigRIPSICPhysics::GetSpectra() {
/* if(m_Spectra)
return m_Spectra->GetMapHisto();
else{
map< string , TH1*> empty;
return empty;
}*/
map< string , TH1*> empty;
return empty;
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::WriteSpectra(){
// m_Spectra->WriteSpectra();
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::AddParameterToCalibrationManager(){
//CalibrationManager* Cal = CalibrationManager::getInstance();
// each layer
//for( int l = 0 ; l < 14 ; ++l){
// Cal->AddParameter("SamuraiFDC2", "L"+ NPL::itoa(l),"FDC2_L"+ NPL::itoa(l));
//}
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::InitializeRootInputRaw(){
TChain* inputChain = RootInput::getInstance()->GetChain() ;
inputChain->SetBranchStatus( "BigRIPSIC" , true );
// The following line is necessary only for system were the tree is splitted
// (older root version). The found argument silenced the Branches not found
// warning for non splitted tree.
if(inputChain->FindBranch("fIC_*"))
inputChain->SetBranchStatus( "fIC_*",true);
inputChain->SetBranchAddress( "BigRIPSIC" , &m_EventData );
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::InitializeRootInputPhysics(){
}
///////////////////////////////////////////////////////////////////////////
void TBigRIPSICPhysics::InitializeRootOutput(){
TTree* outputTree = RootOutput::getInstance()->GetTree();
outputTree->Branch( "IC" , "TBigRIPSICPhysics" , &m_EventPhysics );
}
////////////////////////////////////////////////////////////////////////////////
// Construct Method to be pass to the DetectorFactory //
////////////////////////////////////////////////////////////////////////////////
NPL::VDetector* TBigRIPSICPhysics::Construct(){
return (NPL::VDetector*) new TBigRIPSICPhysics();
}
////////////////////////////////////////////////////////////////////////////////
// Registering the construct method to the factory //
////////////////////////////////////////////////////////////////////////////////
extern "C"{
class proxy_bigripsIC{
public:
proxy_bigripsIC(){
NPL::DetectorFactory::getInstance()->AddToken("BigRIPSIC","BigRIPS");
NPL::DetectorFactory::getInstance()->AddDetector("BigRIPSIC",TBigRIPSICPhysics::Construct);
}
};
proxy_bigripsIC p_bigripsIC;
}
#ifndef TBIGRIPSICPHYSICS_H
#define TBIGRIPSICPHYSICS_H
/*****************************************************************************
* 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: F. Flavigny contact address: flavigny@lpccaen.in2p3.fr *
* *
* Creation Date : April 2020 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold RIBF IC treated data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
* *
*****************************************************************************/
// STL
#include <vector>
#include <map>
#include <iostream>
// NPL
#include "TBigRIPSICData.h"
//#include "BigRIPSICVariables.h"
//#include "TBigRIPSICSpectra.h"
#include "NPCalibrationManager.h"
#include "NPVDetector.h"
#include "NPInputParser.h"
#include "NPXmlParser.h"
#include "NPDCReconstruction.h"
// ROOT
#include "TVector3.h"
// Forward declaration
//class TBigRIPSICSpectra;
using namespace std ;
class TBigRIPSICPhysics : public TObject, public NPL::VDetector{
public:
TBigRIPSICPhysics();
~TBigRIPSICPhysics() {};
public:
void Clear();
void Clear(const Option_t*) {};
void Print();
public:
//vectors with a size equals to the number of IC in dataset
std::vector<int> ID;
std::vector<int> FP;
std::vector<double> RawAvSum;
std::vector<double> RawSqSum;
std::vector<double> CalAvSum;
std::vector<double> CalSqSum;
std::vector<int> NLayerFired;
//vectors size = number of IC in dataset * number of layers
std::vector<double> E;
std::vector<int> E_Layer;
std::vector<int> E_ID;
public:
// Projected position at given Z plan
TVector3 ProjectedPosition(double Z);
private: // Xml file read to add ICs and their parameters
void AddICs(string name, NPL::XmlParser&);//! take the XML file and fill in parameters of each IC
map<int,int> IDtoFP;//! Focal plane where the IC is located
map<int,double> ch2mev_0;
map<int,double> ch2mev_1;
map<int,map<int,int>> pedestal;
public: // Innherited from VDetector Class
// Read stream at ConfigFile to pick-up parameters of detector (Position,...) using Token
void ReadConfiguration(NPL::InputParser) ;
// 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();};
// Those two method all to clear the Event Physics or Data
void ClearEventPhysics() {Clear();}
void ClearEventData() {m_EventData->Clear();}
// Method related to the TSpectra classes, aimed at providing a framework for online applications
// Instantiate the Spectra class and the histogramm throught it
void InitSpectra();
// Fill the spectra hold by the spectra class
void FillSpectra();
// Used for Online mainly, perform check on the histo and for example change their color if issues are found
void CheckSpectra();
// Used for Online only, clear all the spectra hold by the Spectra class
void ClearSpectra();
// Write Spectra to file
void WriteSpectra();
public:
// Clear The PreTeated object
void ClearPreTreatedData() {m_PreTreatedData->Clear();}
// Remove bad channel, calibrate the data and apply threshold
void PreTreat();
// Retrieve raw and pre-treated data
TBigRIPSICData* GetRawData() const {return m_EventData;}
TBigRIPSICData* GetPreTreatedData() const {return m_PreTreatedData;}
private: // Root Input and Output tree classes
TBigRIPSICData* m_EventData;//!
TBigRIPSICData* m_PreTreatedData;//!
TBigRIPSICPhysics* m_EventPhysics;//!
private: // Spectra Class
// TBigRIPSICSpectra* m_Spectra; // !
public: // Spectra Getter
map< string , TH1*> GetSpectra();
public: // Static constructor to be passed to the Detector Factory
static NPL::VDetector* Construct();
ClassDef(TBigRIPSICPhysics,1) // BigRIPSICPhysics structure
};
/*****************************************************************************
* Comment: *
* *
* Intermediate class useful to hold all variables per detector per event *
* Different from TICData whose variable (vectors) are independent *
* *
*****************************************************************************/
class BigRIPSICVariables{
public:
BigRIPSICVariables(){Clear();};
~BigRIPSICVariables(){};
public:
std::vector<double> FT;
std::vector<double> FE;
std::vector<double> FE_Layer;
int FmultiHit[2];
void Clear(){
FE.clear();
FT.clear();
for(int i=0; i<2; i++) FmultiHit[i]=0;
};
void Print(){
//cout << "XXXXXXXXXXXXXXXXXXXXXXXX IC Event XXXXXXXXXXXXXXXXX" << endl;
cout << "FE_Mult = " << FE.size();
for (UShort_t i = 0; i < FE.size(); i++){cout << "\tFE: " << FE[i] << endl;}
cout << "FT_Mult = " << FT.size();
for (UShort_t i = 0; i < FT.size(); i++){cout << "\tFT: " << FT[i] << endl;}
cout << "MultHit = " <<endl;
for (UShort_t i = 0; i <2; i++){cout << FmultiHit[i] << endl;}
}
bool HasEverything(){
if(FE.size()==1 && FT.size()==1){
return true;
}else{return false;}
}
};
#endif
#ifndef TDCDATA_H
#define TDCDATA_H
#ifndef TBigRIPSPPACData_H
#define TBigRIPSPPACData_H
#include "TObject.h"
#include <vector>
class TBigRIPSPPACData: public TObject{
......