New writer class for the skin detector

This commit is contained in:
Paolo Andreetto
2023-02-17 14:35:31 +01:00
parent fce2a39393
commit 043a44150c
5 changed files with 87 additions and 3 deletions

View File

@@ -4,18 +4,21 @@ set(HEADERS RootMathDense.h
muCastorMCTrack.h
muCastorHit.h
muCastorInfo.h
muCastorSkinHit.h)
muCastorSkinHit.h
SkinDetectorWriter.h)
set(SOURCES ${HEADERS} RootMuonScatter.cpp
muCastorMCTrack.cpp
muCastorHit.cpp
muCastorInfo.cpp
muCastorSkinHit.cpp)
muCastorSkinHit.cpp
SkinDetectorWriter.cpp)
set(DICTIONARY_HEADERS muCastorMCTrack.h
muCastorHit.h
muCastorInfo.h
muCastorSkinHit.h)
muCastorSkinHit.h
SkinDetectorWriter.h)
set(LIBRARIES ${ROOT_LIBRARIES}
${PACKAGE_LIBPREFIX}Math)

View File

@@ -81,6 +81,8 @@ using namespace ROOT::Mutom;
#pragma link C++ class muCastorInfo+;
#pragma link C++ class muCastorSkinHit+;
#pragma link C++ class SkinDetectorWriter+;
#endif // __CINT__
#endif // LINKDEF_H

View File

@@ -0,0 +1,43 @@
#include "SkinDetectorWriter.h"
#include "muCastorSkinHit.h"
#include "TVector3.h"
SkinDetectorWriter::SkinDetectorWriter(string filename) :
t_file(nullptr),
t_tree(nullptr),
t_buffer(nullptr)
{
t_file = new TFile(filename.c_str(), "RECREATE");
t_tree = new TTree("muCastorMC", "muCastorMC");
t_buffer = new TClonesArray("muCastorSkinHit");
t_tree->Branch("CastorSkinHits", "TClonesArray", t_buffer, 32000, 99);
}
SkinDetectorWriter::~SkinDetectorWriter()
{}
void SkinDetectorWriter::add(int detID, float p_x, float p_y, float p_z,
float m_x, float m_y, float m_z)
{
TClonesArray& ref = *t_buffer;
int size = ref.GetEntriesFast();
muCastorSkinHit* new_hit = new(ref[size]) muCastorSkinHit();
new_hit->SetDetID(detID);
new_hit->SetPdgCode(13);
new_hit->SetMotherID(-1);
new_hit->SetPos (TVector3(p_x, p_y, p_z));
new_hit->SetMom (TVector3(m_x, m_y, m_z));
}
void SkinDetectorWriter::write()
{
t_tree->Fill();
t_buffer->Delete(); // or t_buffer->Clear() ??
}
void SkinDetectorWriter::close()
{
t_tree->Write();
t_file->Close();
}

View File

@@ -0,0 +1,30 @@
#ifndef SkinDetectorWriter_h
#define SkinDetectorWriter_h
#include <string>
#include "TFile.h"
#include "TTree.h"
#include "TClonesArray.h"
using std::string;
class SkinDetectorWriter
{
public:
SkinDetectorWriter(string filename);
virtual ~SkinDetectorWriter();
void add(int detID, float p_x, float p_y, float p_z, float m_x, float m_y, float m_z);
void write();
void close();
private:
TFile* t_file;
TTree* t_tree;
TClonesArray* t_buffer;
};
#endif //SkinDetectorWriter_h

View File

@@ -26,6 +26,12 @@ public:
void SetMotherID(Int_t mid) { fMotherID = mid; };
void SetMom(TVector3 xyz) { fMomX = xyz.X(); fMomY = xyz.Y(); fMomZ = xyz.Z(); };
void SetPos(TVector3 xyz) { fPosX = xyz.X(); fPosY = xyz.Y(); fPosZ = xyz.Z(); };
Int_t GetDetID() { return fDetID; }
Int_t GetPdgCode() { return fPdgCode; }
Int_t GetMotherID() { return fMotherID; }
TVector3 GetMom() { return TVector3(fMomX, fMomY, fMomZ); }
TVector3 GetPos() { return TVector3(fPosX, fPosY, fPosZ); }
private:
Int_t fDetID; // Detector module ID