From 043a44150c86491a4f9f5a326376d6b4bd630883 Mon Sep 17 00:00:00 2001 From: Paolo Andreetto Date: Fri, 17 Feb 2023 14:35:31 +0100 Subject: [PATCH] New writer class for the skin detector --- src/Root/CMakeLists.txt | 9 ++++--- src/Root/Linkdef.h | 2 ++ src/Root/SkinDetectorWriter.cpp | 43 +++++++++++++++++++++++++++++++++ src/Root/SkinDetectorWriter.h | 30 +++++++++++++++++++++++ src/Root/muCastorSkinHit.h | 6 +++++ 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 src/Root/SkinDetectorWriter.cpp create mode 100644 src/Root/SkinDetectorWriter.h diff --git a/src/Root/CMakeLists.txt b/src/Root/CMakeLists.txt index 90073b1..df5ccb3 100644 --- a/src/Root/CMakeLists.txt +++ b/src/Root/CMakeLists.txt @@ -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) diff --git a/src/Root/Linkdef.h b/src/Root/Linkdef.h index efe4969..c63ea61 100644 --- a/src/Root/Linkdef.h +++ b/src/Root/Linkdef.h @@ -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 diff --git a/src/Root/SkinDetectorWriter.cpp b/src/Root/SkinDetectorWriter.cpp new file mode 100644 index 0000000..726b762 --- /dev/null +++ b/src/Root/SkinDetectorWriter.cpp @@ -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(); +} \ No newline at end of file diff --git a/src/Root/SkinDetectorWriter.h b/src/Root/SkinDetectorWriter.h new file mode 100644 index 0000000..8025c63 --- /dev/null +++ b/src/Root/SkinDetectorWriter.h @@ -0,0 +1,30 @@ +#ifndef SkinDetectorWriter_h +#define SkinDetectorWriter_h + +#include + +#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 \ No newline at end of file diff --git a/src/Root/muCastorSkinHit.h b/src/Root/muCastorSkinHit.h index a81e4a4..9c91929 100644 --- a/src/Root/muCastorSkinHit.h +++ b/src/Root/muCastorSkinHit.h @@ -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