From 46eb87e65b5b044e0a3ba864290abfca020ee114 Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Fri, 27 Aug 2021 16:41:27 -0400 Subject: [PATCH] Added base class DetectorEfficiency for all detector systems --- include/AnasenEfficiency.h | 23 ++++++------- include/DetectorEfficiency.h | 52 ++++++++++++++++++++++++++++++ include/SabreEfficiency.h | 21 ++++++------ src/Detectors/AnasenEfficiency.cpp | 42 +++++++++--------------- src/Detectors/SabreEfficiency.cpp | 37 +++++++-------------- 5 files changed, 97 insertions(+), 78 deletions(-) create mode 100644 include/DetectorEfficiency.h diff --git a/include/AnasenEfficiency.h b/include/AnasenEfficiency.h index 054a99c..de2f276 100644 --- a/include/AnasenEfficiency.h +++ b/include/AnasenEfficiency.h @@ -4,32 +4,28 @@ #include #include +#include "DetectorEfficiency.h" #include "StripDetector.h" #include "QQQDetector.h" -class AnasenEfficiency { +class AnasenEfficiency : public DetectorEfficiency { public: AnasenEfficiency(); ~AnasenEfficiency(); - void CalculateEfficiency(const std::string& filename); - inline void SetReactionType(int type) { m_rxn_type = type; }; - void DrawDetectorSystem(const std::string& filename); - double RunConsistencyCheck(); + void CalculateEfficiency(const std::string& filename) override; + void DrawDetectorSystem(const std::string& filename) override; + double RunConsistencyCheck() override; private: - void MyFill(THashTable* table, const std::string& name, const std::string& title, int bins, float min, float max, double val); - void MyFill(THashTable* table, const std::string& name, const std::string& title, int binsx, float minx, float maxx, double valx, int binsy, float miny, float maxy, double valy); - void RunDecay(const std::string& filename); - void RunTwoStep(const std::string& filename); - void RunThreeStep(const std::string& filename); + void RunDecay(const std::string& filename) override; + void Run2Step(const std::string& filename) override; + void Run3Step(const std::string& filename) override; + void Run1Step(const std::string& filename) override; bool IsRing1(double theta, double phi); bool IsRing2(double theta, double phi); bool IsQQQ(double theta, double phi); - inline bool IsDoubleEqual(double x, double y) { return std::fabs(x-y) < epsilon ? true : false; }; - - int m_rxn_type; std::vector m_Ring1, m_Ring2; std::vector m_forwardQQQs; std::vector m_backwardQQQs; @@ -53,7 +49,6 @@ private: /*************************/ static constexpr double threshold = 0.2; //MeV - static constexpr double epsilon = 1.0e-6; static constexpr double deg2rad = M_PI/180.0; }; diff --git a/include/DetectorEfficiency.h b/include/DetectorEfficiency.h new file mode 100644 index 0000000..7c24e0c --- /dev/null +++ b/include/DetectorEfficiency.h @@ -0,0 +1,52 @@ +#ifndef DETECTOREFFICIENCY_H +#define DETECTOREFFICIENCY_H + +#include +#include +#include +#include + +class DetectorEfficiency { +public: + DetectorEfficiency() { m_rxn_type = -1; }; + virtual ~DetectorEfficiency() {}; + + inline void SetReactionType(int rxntype) { m_rxn_type = rxntype; }; + virtual void CalculateEfficiency(const std::string& filename) = 0; + virtual void DrawDetectorSystem(const std::string& filename) = 0; + virtual double RunConsistencyCheck() = 0; + +protected: + void MyFill(THashTable* table, const std::string& name, const std::string& title, int bins, float min, float max, double val) { + TH1F* h = (TH1F*) table->FindObject(name.c_str()); + if(h) { + h->Fill(val); + } else { + h = new TH1F(name.c_str(), title.c_str(), bins, min, max); + h->Fill(val); + table->Add(h); + } + } + void MyFill(THashTable* table, const std::string& name, const std::string& title, int binsx, float minx, float maxx, double valx, int binsy, float miny, float maxy, double valy) { + TH2F* h = (TH2F*) table->FindObject(name.c_str()); + if(h) { + h->Fill(valx, valy); + } else { + h = new TH2F(name.c_str(), title.c_str(), binsx, minx, maxx, binsy, miny, maxy); + h->Fill(valx, valy); + table->Add(h); + } + } + inline bool IsDoubleEqual(double x, double y) { return std::fabs(x-y) < epsilon ? true : false; }; + + + virtual void Run2Step(const std::string& filename) = 0; + virtual void Run3Step(const std::string& filename) = 0; + virtual void RunDecay(const std::string& filename) = 0; + virtual void Run1Step(const std::string& filename) = 0; + + static constexpr double epsilon = 1.0e-6; + int m_rxn_type; +}; + +#endif \ No newline at end of file diff --git a/include/SabreEfficiency.h b/include/SabreEfficiency.h index a57dd6c..6bee112 100644 --- a/include/SabreEfficiency.h +++ b/include/SabreEfficiency.h @@ -1,38 +1,35 @@ #ifndef SABREEFFICIENCY_H #define SABREEFFICIENCY_H +#include "DetectorEfficiency.h" #include "SabreDetector.h" #include "Target.h" #include "DeadChannelMap.h" #include "Kinematics.h" #include -class SabreEfficiency { +class SabreEfficiency : public DetectorEfficiency { public: SabreEfficiency(); ~SabreEfficiency(); - inline void SetReactionType(int t) { m_rxn_type = t; }; void SetDeadChannelMap(std::string& filename) { dmap.LoadMapfile(filename); }; - void CalculateEfficiency(const std::string& file); - void DrawDetectorSystem(const std::string& filename); - double RunConsistencyCheck(); + void CalculateEfficiency(const std::string& file) override; + void DrawDetectorSystem(const std::string& filename) override; + double RunConsistencyCheck() override; private: - void MyFill(THashTable* table, const std::string& name, const std::string& title, int bins, float min, float max, double val); - void MyFill(THashTable* table, const std::string& name, const std::string& title, int binsx, float minx, float maxx, double valx, int binsy, float miny, float maxy, double valy); std::pair IsSabre(Mask::NucData* nucleus); - void Run2Step(const std::string& filename); - void Run3Step(const std::string& filename); - void RunDecay(const std::string& filename); + void Run2Step(const std::string& filename) override; + void Run3Step(const std::string& filename) override; + void RunDecay(const std::string& filename) override; + void Run1Step(const std::string& filename) override; - int m_rxn_type; std::vector detectors; Target deadlayer; Target sabre_eloss; DeadChannelMap dmap; - //Sabre constants const double INNER_R = 0.0326; const double OUTER_R = 0.1351; diff --git a/src/Detectors/AnasenEfficiency.cpp b/src/Detectors/AnasenEfficiency.cpp index 7367cc7..2c43f19 100644 --- a/src/Detectors/AnasenEfficiency.cpp +++ b/src/Detectors/AnasenEfficiency.cpp @@ -7,7 +7,9 @@ #include #include -AnasenEfficiency::AnasenEfficiency() { +AnasenEfficiency::AnasenEfficiency() : + DetectorEfficiency() +{ for(int i=0; iFindObject(name.c_str()); - if(h) { - h->Fill(val); - } else { - h = new TH1F(name.c_str(), title.c_str(), bins, min, max); - h->Fill(val); - table->Add(h); - } -} - -void AnasenEfficiency::MyFill(THashTable* table, const std::string& name, const std::string& title, int binsx, float minx, float maxx, double valx, int binsy, float miny, float maxy, double valy) { - TH2F* h = (TH2F*) table->FindObject(name.c_str()); - if(h) { - h->Fill(valx, valy); - } else { - h = new TH2F(name.c_str(), title.c_str(), binsx, minx, maxx, binsy, miny, maxy); - h->Fill(valx, valy); - table->Add(h); - } -} void AnasenEfficiency::DrawDetectorSystem(const std::string& filename) { TFile* file = TFile::Open(filename.c_str(), "RECREATE"); @@ -278,14 +259,18 @@ void AnasenEfficiency::CalculateEfficiency(const std::string& file) { RunDecay(file); break; } + case Mask::Kinematics::ONESTEP_RXN: + { + Run1Step(file); + } case Mask::Kinematics::TWOSTEP: { - RunTwoStep(file); + Run2Step(file); break; } case Mask::Kinematics::THREESTEP: { - RunThreeStep(file); + Run3Step(file); break; } } @@ -347,7 +332,12 @@ void AnasenEfficiency::RunDecay(const std::string& filename) { input->Close(); } -void AnasenEfficiency::RunTwoStep(const std::string& filename) { +void AnasenEfficiency::Run1Step(const std::string& filename) { + std::cout<<"SabreEfficiency::Run1Step Not Implemented!"<Get("DataTree"); @@ -456,7 +446,7 @@ void AnasenEfficiency::RunTwoStep(const std::string& filename) { input->Close(); } -void AnasenEfficiency::RunThreeStep(const std::string& filename) { +void AnasenEfficiency::Run3Step(const std::string& filename) { TFile* input = TFile::Open(filename.c_str(), "UPDATE"); TTree* tree = (TTree*) input->Get("DataTree"); diff --git a/src/Detectors/SabreEfficiency.cpp b/src/Detectors/SabreEfficiency.cpp index 88aa55b..4272d6c 100644 --- a/src/Detectors/SabreEfficiency.cpp +++ b/src/Detectors/SabreEfficiency.cpp @@ -7,12 +7,9 @@ #include #include #include -#include -#include -#include SabreEfficiency::SabreEfficiency() : - m_rxn_type(-1), deadlayer(DEADLAYER_THIN), sabre_eloss(SABRE_THICKNESS) + DetectorEfficiency(), deadlayer(DEADLAYER_THIN), sabre_eloss(SABRE_THICKNESS) { detectors.reserve(5); detectors.emplace_back(INNER_R,OUTER_R,PHI_COVERAGE*DEG2RAD,PHI0*DEG2RAD,TILT*DEG2RAD,DIST_2_TARG); @@ -31,28 +28,6 @@ SabreEfficiency::SabreEfficiency() : SabreEfficiency::~SabreEfficiency() {} -void SabreEfficiency::MyFill(THashTable* table, const std::string& name, const std::string& title, int bins, float min, float max, double val) { - TH1F* h = (TH1F*) table->FindObject(name.c_str()); - if(h) { - h->Fill(val); - } else { - h = new TH1F(name.c_str(), title.c_str(), bins, min, max); - h->Fill(val); - table->Add(h); - } -} - -void SabreEfficiency::MyFill(THashTable* table, const std::string& name, const std::string& title, int binsx, float minx, float maxx, double valx, int binsy, float miny, float maxy, double valy) { - TH2F* h = (TH2F*) table->FindObject(name.c_str()); - if(h) { - h->Fill(valx, valy); - } else { - h = new TH2F(name.c_str(), title.c_str(), binsx, minx, maxx, binsy, miny, maxy); - h->Fill(valx, valy); - table->Add(h); - } -} - void SabreEfficiency::CalculateEfficiency(const std::string& file) { std::cout<<"----------SABRE Efficiency Calculation----------"<