Commit 3f6fdca5 authored by flavigny's avatar flavigny
Browse files

Strasse classes protoype to be updated

parent 65504a6a
add_custom_command(OUTPUT TStrassePhysicsDict.cxx COMMAND ../../scripts/build_dict.sh TStrassePhysics.h TStrassePhysicsDict.cxx TStrassePhysics.rootmap libNPStrasse.dylib DEPENDS TStrassePhysics.h)
add_custom_command(OUTPUT TStrasseDataDict.cxx COMMAND ../../scripts/build_dict.sh TStrasseData.h TStrasseDataDict.cxx TStrasseData.rootmap libNPStrasse.dylib DEPENDS TStrasseData.h)
add_library(NPStrasse SHARED TStrasseSpectra.cxx TStrasseData.cxx TStrassePhysics.cxx TStrasseDataDict.cxx TStrassePhysicsDict.cxx )
target_link_libraries(NPStrasse ${ROOT_LIBRARIES} NPCore)
install(FILES TStrasseData.h TStrassePhysics.h TStrasseSpectra.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: F. Flavigny contact : flavigny@lpccaen.in2p3.fr *
* *
* Creation Date : July 2020 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Strasse Raw data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
#include "TStrasseData.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
ClassImp(TStrasseData)
//////////////////////////////////////////////////////////////////////
TStrasseData::TStrasseData() {
}
//////////////////////////////////////////////////////////////////////
TStrasseData::~TStrasseData() {
}
//////////////////////////////////////////////////////////////////////
void TStrasseData::Clear() {
// Energy X
fInner_XE_DetectorNbr.clear();
fInner_XE_StripNbr.clear();
fInner_XE_Energy.clear();
// Energy Y
fInner_YE_DetectorNbr.clear();
fInner_YE_StripNbr.clear();
fInner_YE_Energy.clear();
// Energy X
fOutter_XE_DetectorNbr.clear();
fOutter_XE_StripNbr.clear();
fOutter_XE_Energy.clear();
// Energy Y
fOutter_YE_DetectorNbr.clear();
fOutter_YE_StripNbr.clear();
fOutter_YE_Energy.clear();
}
//////////////////////////////////////////////////////////////////////
void TStrasseData::Dump() const {
// This method is very useful for debuging and worth the dev.
cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TStrasseData::Dump()] XXXXXXXXXXXXXXXXX" << endl;
// Energy
size_t mysize = fInner_XE_DetectorNbr.size();
cout << "Inner Strasse_XE_Mult: " << mysize << endl;
for (size_t i = 0 ; i < mysize ; i++){
cout << "X-DetNbr: " << fInner_XE_DetectorNbr[i]
<< " X-Energy: " << fInner_XE_Energy[i];
}
}
#ifndef __StrasseDATA__
#define __StrasseDATA__
/*****************************************************************************
* 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: F. Flavigny contact : flavigny@lpccaen.in2p3.fr *
* *
* Creation Date : July 2020 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Strasse Raw data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
// STL
#include <vector>
using namespace std;
// ROOT
#include "TObject.h"
class TStrasseData : public TObject {
//////////////////////////////////////////////////////////////
// data members are hold into vectors in order
// to allow multiplicity treatment
private:
// First Stage Front Energy
vector<unsigned short> fInner_XE_DetectorNbr;
vector<unsigned short> fInner_XE_StripNbr;
vector<double> fInner_XE_Energy;
// First Stage Back Energy
vector<unsigned short> fInner_YE_DetectorNbr;
vector<unsigned short> fInner_YE_StripNbr;
vector<double> fInner_YE_Energy;
// Second Stage Front Energy
vector<unsigned short> fOutter_XE_DetectorNbr;
vector<unsigned short> fOutter_XE_StripNbr;
vector<double> fOutter_XE_Energy;
// Second Stage Back Energy
vector<unsigned short> fOutter_YE_DetectorNbr;
vector<unsigned short> fOutter_YE_StripNbr;
vector<double> fOutter_YE_Energy;
//////////////////////////////////////////////////////////////
// Constructor and destructor
public:
TStrasseData();
~TStrasseData();
//////////////////////////////////////////////////////////////
// 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 ////////////////////////
// First Stage Energy Front
inline void SetInnerXE(const UShort_t& DetNbr, const UShort_t& StripNbr, const Double_t& Energy){
fInner_XE_DetectorNbr.push_back(DetNbr);
fInner_XE_StripNbr.push_back(StripNbr);
fInner_XE_Energy.push_back(Energy);
};//!
// First Stage Energy Back
inline void SetInnerYE(const UShort_t& DetNbr, const UShort_t& StripNbr, const Double_t& Energy){
fInner_YE_DetectorNbr.push_back(DetNbr);
fInner_YE_StripNbr.push_back(StripNbr);
fInner_YE_Energy.push_back(Energy);
};//!
//////
// Second Stage Energy Front
inline void SetOutterXE(const UShort_t& DetNbr, const UShort_t& StripNbr, const Double_t& Energy){
fOutter_XE_DetectorNbr.push_back(DetNbr);
fOutter_XE_StripNbr.push_back(StripNbr);
fOutter_XE_Energy.push_back(Energy);
};//!
// Second Stage Energy Back
inline void SetOutterYE(const UShort_t& DetNbr, const UShort_t& StripNbr, const Double_t& Energy){
fOutter_YE_DetectorNbr.push_back(DetNbr);
fOutter_YE_StripNbr.push_back(StripNbr);
fOutter_YE_Energy.push_back(Energy);
};//!
////////////////////// GETTERS ////////////////////////
// First Stage Energy X
inline UShort_t GetInnerMultXEnergy() const
{return fInner_XE_DetectorNbr.size();}
inline UShort_t GetInner_XE_DetectorNbr(const unsigned int &i) const
{return fInner_XE_DetectorNbr[i];}//!
inline UShort_t GetInner_XE_StripNbr(const unsigned int &i) const
{return fInner_XE_StripNbr[i];}//!
inline Double_t GetInner_XE_Energy(const unsigned int &i) const
{return fInner_XE_Energy[i];}//!
// First Stage Energy Y
inline UShort_t GetInnerMultYEnergy() const
{return fInner_YE_DetectorNbr.size();}
inline UShort_t GetInner_YE_DetectorNbr(const unsigned int &i) const
{return fInner_YE_DetectorNbr[i];}//!
inline UShort_t GetInner_YE_StripNbr(const unsigned int &i) const
{return fInner_YE_StripNbr[i];}//!
inline Double_t GetInner_YE_Energy(const unsigned int &i) const
{return fInner_YE_Energy[i];}//!
//////
// Second Stage Energy X
inline UShort_t GetOutterMultXEnergy() const
{return fOutter_XE_DetectorNbr.size();}
inline UShort_t GetOutter_XE_DetectorNbr(const unsigned int &i) const
{return fOutter_XE_DetectorNbr[i];}//!
inline UShort_t GetOutter_XE_StripNbr(const unsigned int &i) const
{return fOutter_XE_StripNbr[i];}//!
inline Double_t GetOutter_XE_Energy(const unsigned int &i) const
{return fOutter_XE_Energy[i];}//!
// Second Stage Energy Y
inline UShort_t GetOutterMultYEnergy() const
{return fOutter_YE_DetectorNbr.size();}
inline UShort_t GetOutter_YE_DetectorNbr(const unsigned int &i) const
{return fOutter_YE_DetectorNbr[i];}//!
inline UShort_t GetOutter_YE_StripNbr(const unsigned int &i) const
{return fOutter_YE_StripNbr[i];}//!
inline Double_t GetOutter_YE_Energy(const unsigned int &i) const
{return fOutter_YE_Energy[i];}//!
//////////////////////////////////////////////////////////////
// Required for ROOT dictionnary
ClassDef(TStrasseData,1) // StrasseData 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: F. Flavigny contact : flavigny@lpccaen.in2p3.fr *
* *
* Creation Date : July 2020 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Strasse Treated data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
#include "TStrassePhysics.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(TStrassePhysics)
///////////////////////////////////////////////////////////////////////////
TStrassePhysics::TStrassePhysics(){
EventMultiplicity = 0;
m_EventData = new TStrasseData;
m_PreTreatedData = new TStrasseData;
m_EventPhysics = this;
m_Spectra = NULL;
m_E_RAW_Threshold = 0; // adc channels
m_E_Threshold = 0; // MeV
m_NumberOfDetectors = 0;
m_MaximumStripMultiplicityAllowed = 10;
m_StripEnergyMatching = 0.050;
}
///////////////////////////////////////////////////////////////////////////
/// A usefull method to bundle all operation to add a detector
void TStrassePhysics::AddDetector(TVector3){
// 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 TStrassePhysics::AddDetector(double R, double Theta, double Phi){
m_NumberOfDetectors++;
//double Height = 118; // mm
double Height = 61.8; // mm
//double Base = 95; // mm
double Base = 78.1; // mm
double NumberOfStrips = 128;
double StripPitchHeight = Height / NumberOfStrips; // mm
double StripPitchBase = Base / NumberOfStrips; // mm
// Vector U on detector face (parallel to Y strips) Y strips are along X axis
TVector3 U;
// Vector V on detector face (parallel to X strips)
TVector3 V;
// Vector W normal to detector face (pointing to the back)
TVector3 W;
// Vector C position of detector face center
TVector3 C;
C = TVector3(R*sin(Theta)*cos(Phi),
R*sin(Theta)*sin(Phi),
Height*0.5+R*cos(Theta));
TVector3 P = TVector3(cos(Theta)*cos(Phi),
cos(Theta)*sin(Phi),
-sin(Theta));
W = C.Unit();
U = W.Cross(P);
V = W.Cross(U);
U = U.Unit();
V = V.Unit();
vector<double> lineX;
vector<double> lineY;
vector<double> lineZ;
vector<vector<double>> OneDetectorStripPositionX;
vector<vector<double>> OneDetectorStripPositionY;
vector<vector<double>> OneDetectorStripPositionZ;
double X, Y, Z;
// Moving C to the 1.1 Corner;
TVector3 Strip_1_1;
Strip_1_1 = C - (0.5*Base*U + 0.5*Height*V) + U*(StripPitchBase / 2.) + V*(StripPitchHeight / 2.);
TVector3 StripPos;
for(int i=0; i<NumberOfStrips; i++){
lineX.clear();
lineY.clear();
lineZ.clear();
for(int j=0; j<NumberOfStrips; j++){
StripPos = Strip_1_1 + i*U*StripPitchBase + j*V*StripPitchHeight;
lineX.push_back(StripPos.X());
lineY.push_back(StripPos.Y());
lineZ.push_back(StripPos.Z());
}
OneDetectorStripPositionX.push_back(lineX);
OneDetectorStripPositionY.push_back(lineY);
OneDetectorStripPositionZ.push_back(lineZ);
}
m_StripPositionX.push_back(OneDetectorStripPositionX);
m_StripPositionY.push_back(OneDetectorStripPositionY);
m_StripPositionZ.push_back(OneDetectorStripPositionZ);
}
///////////////////////////////////////////////////////////////////////////
TVector3 TStrassePhysics::GetPositionOfInteraction(const int i){
TVector3 Position = TVector3(GetStripPositionX(DetectorNumber[i], StripX[i], StripY[i]),
GetStripPositionY(DetectorNumber[i], StripX[i], StripY[i]),
GetStripPositionZ(DetectorNumber[i], StripX[i], StripY[i]));
return Position;
}
///////////////////////////////////////////////////////////////////////////
TVector3 TStrassePhysics::GetDetectorNormal(const int i){
TVector3 U = TVector3(GetStripPositionX(DetectorNumber[i],128,1),
GetStripPositionY(DetectorNumber[i],128,1),
GetStripPositionZ(DetectorNumber[i],128,1))
-TVector3(GetStripPositionX(DetectorNumber[i],1,1),
GetStripPositionY(DetectorNumber[i],1,1),
GetStripPositionZ(DetectorNumber[i],1,1));
TVector3 V = TVector3(GetStripPositionX(DetectorNumber[i],128,128),
GetStripPositionY(DetectorNumber[i],128,128),
GetStripPositionZ(DetectorNumber[i],128,128))
-TVector3(GetStripPositionX(DetectorNumber[i],128,1),
GetStripPositionY(DetectorNumber[i],128,1),
GetStripPositionZ(DetectorNumber[i],128,1));
TVector3 Normal = U.Cross(V);
return (Normal.Unit());
}
///////////////////////////////////////////////////////////////////////////
void TStrassePhysics::BuildSimplePhysicalEvent() {
BuildPhysicalEvent();
}
///////////////////////////////////////////////////////////////////////////
void TStrassePhysics::BuildPhysicalEvent() {
// apply thresholds and calibration
PreTreat();
if(1 /*CheckEvent() == 1*/){
vector<TVector2> couple = Match_X_Y();
EventMultiplicity = couple.size();
for(unsigned int i=0; i<couple.size(); i++){
int N = m_PreTreatedData->GetInner_XE_DetectorNbr(couple[i].X());
int X = m_PreTreatedData->GetInner_XE_StripNbr(couple[i].X());
int Y = m_PreTreatedData->GetInner_YE_StripNbr(couple[i].Y());
double XE = m_PreTreatedData->GetInner_XE_Energy(couple[i].X());
double YE = m_PreTreatedData->GetInner_YE_Energy(couple[i].Y());
DetectorNumber.push_back(N);
StripX.push_back(X);
StripY.push_back(Y);
DE.push_back(XE);
PosX.push_back(GetPositionOfInteraction(i).x());
PosY.push_back(GetPositionOfInteraction(i).y());
PosZ.push_back(GetPositionOfInteraction(i).z());
int OutterMult = m_PreTreatedData->GetOutterMultXEnergy();
for(unsigned int j=0; j<OutterMult; j++){
if(m_PreTreatedData->GetOutter_XE_DetectorNbr(j)==N){
double XDE = m_PreTreatedData->GetOutter_XE_Energy(j);
double YDE = m_PreTreatedData->GetOutter_YE_Energy(j);
E.push_back(XDE);
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////
vector<TVector2> TStrassePhysics::Match_X_Y(){
vector<TVector2> ArrayOfGoodCouple;
static unsigned int m_XEMult, m_YEMult;
m_XEMult = m_PreTreatedData->GetInnerMultXEnergy();
m_YEMult = m_PreTreatedData->GetInnerMultYEnergy();
if(m_XEMult>m_MaximumStripMultiplicityAllowed || m_YEMult>m_MaximumStripMultiplicityAllowed){
return ArrayOfGoodCouple;
}
for(unsigned int i=0; i<m_XEMult; i++){
for(unsigned int j=0; j<m_YEMult; j++){
// Declaration of variable for clarity
int XDetNbr = m_PreTreatedData->GetInner_XE_DetectorNbr(i);
int YDetNbr = m_PreTreatedData->GetInner_YE_DetectorNbr(j);
// if same detector check energy
if(XDetNbr == YDetNbr){
// Declaration of variable for clarity
double XE = m_PreTreatedData->GetInner_XE_Energy(i);
double YE = m_PreTreatedData->GetInner_YE_Energy(i);
double XStripNbr = m_PreTreatedData->GetInner_XE_StripNbr(i);
double YStripNbr = m_PreTreatedData->GetInner_YE_StripNbr(i);
// look if energy matches
if(abs(XE-YE)/2.<m_StripEnergyMatching){
ArrayOfGoodCouple.push_back(TVector2(i,j));
}
}
}
}
return ArrayOfGoodCouple;
}
///////////////////////////////////////////////////////////////////////////
int TStrassePhysics::CheckEvent(){
// Check the size of the different elements
if(m_PreTreatedData->GetInnerMultXEnergy() == m_PreTreatedData->GetInnerMultYEnergy() )
return 1;
else
return -1;
}
///////////////////////////////////////////////////////////////////////////
void TStrassePhysics::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();
//////
// First Stage Energy
unsigned int sizeFront = m_EventData->GetInnerMultXEnergy();
for (UShort_t i = 0; i < sizeFront ; ++i) {
if (m_EventData->GetInner_XE_Energy(i) > m_E_RAW_Threshold) {
Double_t Energy = m_EventData->GetInner_XE_Energy(i);
//Double_t Energy = Cal->ApplyCalibration("Strasse/ENERGY"+NPL::itoa(m_EventData->GetInner_XE_DetectorNbr(i)),m_EventData->GetInner_XE_Energy(i));
if (Energy > m_E_Threshold) {
m_PreTreatedData->SetInnerXE(m_EventData->GetInner_XE_DetectorNbr(i), m_EventData->GetInner_XE_StripNbr(i), Energy);
}
}
}
unsigned int sizeBack = m_EventData->GetInnerMultXEnergy();
for (UShort_t i = 0; i < sizeBack ; ++i) {
if (m_EventData->GetInner_YE_Energy(i) > m_E_RAW_Threshold) {
Double_t Energy = m_EventData->GetInner_YE_Energy(i);
//Double_t Energy = Cal->ApplyCalibration("Strasse/ENERGY"+NPL::itoa(m_EventData->GetInner_YE_DetectorNbr(i)),m_EventData->GetInner_YE_Energy(i));
if (Energy > m_E_Threshold) {
m_PreTreatedData->SetInnerYE(m_EventData->GetInner_YE_DetectorNbr(i), m_EventData->GetInner_YE_StripNbr(i), Energy);
}
}
}
//////
// Second Stage Energy
sizeFront = m_EventData->GetOutterMultXEnergy();
for (UShort_t i = 0; i < sizeFront ; ++i) {
if (m_EventData->GetOutter_XE_Energy(i) > m_E_RAW_Threshold) {
Double_t Energy = m_EventData->GetOutter_XE_Energy(i);
//Double_t Energy = Cal->ApplyCalibration("Strasse/ENERGY"+NPL::itoa(m_EventData->GetOutter_XE_DetectorNbr(i)),m_EventData->GetOutter_XE_Energy(i));
if (Energy > m_E_Threshold) {
m_PreTreatedData->SetOutterXE(m_EventData->GetOutter_XE_DetectorNbr(i), m_EventData->GetOutter_XE_StripNbr(i), Energy);
}
}
}
sizeBack = m_EventData->GetOutterMultXEnergy();
for (UShort_t i = 0; i < sizeBack ; ++i) {
if (m_EventData->GetOutter_YE_Energy(i) > m_E_RAW_Threshold) {
Double_t Energy = m_EventData->GetOutter_YE_Energy(i);
//Double_t Energy = Cal->ApplyCalibration("Strasse/ENERGY"+NPL::itoa(m_EventData->GetOutter_YE_DetectorNbr(i)),m_EventData->GetOutter_YE_Energy(i));
if (Energy > m_E_Threshold) {
m_PreTreatedData->SetOutterYE(m_EventData->GetOutter_YE_DetectorNbr(i), m_EventData->GetOutter_YE_StripNbr(i), Energy);
}
}
}
}
///////////////////////////////////////////////////////////////////////////
void TStrassePhysics::ReadAnalysisConfig() {
bool ReadingStatus = false;
// path to file
string FileName = "./configs/ConfigStrasse.dat";
// open analysis config file
ifstream AnalysisConfigFile;
AnalysisConfigFile.open(FileName.c_str());
if (!AnalysisConfigFile.is_open()) {
cout << " No ConfigStrasse.dat found: Default parameter loaded for Analayis " << FileName << endl;
return;
}
cout << " Loading user parameter for Analysis from ConfigStrasse.dat " << endl;
// Save it in a TAsciiFile
TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
asciiConfig->AppendLine("%%% ConfigStrasse.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 = "ConfigStrasse";
if (LineBuffer.compare(0, name.length(), name) == 0)
ReadingStatus = true;
// loop on tokens and data