ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TSolidAngleProcessor.cc
Go to the documentation of this file.
1/**
2 * @file TSolidAngleProcessor.cc
3 * @brief
4 * @author Kodai Okawa <okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2024-01-18 22:37:37
6 * @note last modified: 2024-08-23 21:20:12
7 * @details
8 */
9
10////////////////////////////////////////////////////////////////////////////////
11/// ## Usage
12/// Using Monte Carlo Method, it calculate Solid angle.
13/// The related file is,
14/// - [prm/geo/hoge.yaml](https://github.com/okawak/artemis_crib/tree/main/prm/geo)
15/// : define the detector geometry
16/// - [steering/simSolidAngle.yaml](https://github.com/okawak/artemis_crib/blob/main/steering/simSolidAngle.yaml)
17/// : steering file to calculate Solid Angle
18///
19/// ### Solid Target
20///
21/// We can assume the reaction position is one point (like (0, 0, 0)).
22/// The art::crib::TNBodyReactionProcessor can produce events from this
23/// point uniformly in CM system (angle), so if we calculate the ratio
24/// of generated event number and detected event number.
25///
26/// The solid angle is defined like
27/// - Omega(theta, delta_theta): Solid angle at theta angle with delta_theta width
28///
29/// ### Gas Target
30///
31/// If we fix the Ecm of the reaction, the reaction point is also fixed.
32/// So with given Ecm, we can calculate the Solid angle by Monte Carlo method.
33///
34
36
39#include <TArtemisUtil.h>
40#include <TFile.h>
41
43
45
46////////////////////////////////////////////////////////////////////////////////
47/// steering file definition:
48/// - InputCollection: detected particle branch (size = 1 of art::TTelescopeData)
49/// - InputReacCollection: simulated reaction branch
50/// - Nbin_angle: A1
51/// - range_angle: [A2, A3]
52/// - histogram binning like tree->Draw(A1, A2, A3)
53/// - Nbin_energy: E1
54/// - range_energy: [E2, E3]
55/// - histogram binning like tree->Draw(E1, E2, E3)
56/// - HistFile: saved histogram ROOT file name
57///
58
59TSolidAngleProcessor::TSolidAngleProcessor() : fInData(nullptr), fInReacData(nullptr) {
60 RegisterInputCollection("InputCollection", "input branch name", fInputColName, TString("data"));
61 RegisterInputCollection("InputReacCollection", "input reaction branch name", fInputReacColName, TString("reaction"));
62
63 DoubleVec_t init_d_vec;
64 RegisterProcessorParameter("Nbin_angle", "Nbin of the angle histogram", fNbin_angle, 0);
65 RegisterProcessorParameter("range_angle", "range of the angle histogram", fRange_angle, init_d_vec);
66 RegisterProcessorParameter("Nbin_energy", "Nbin of the energy histogram", fNbin_energy, 0);
67 RegisterProcessorParameter("range_energy", "range of the energy histogram", fRange_energy, init_d_vec);
68
69 RegisterProcessorParameter("HistFile", "name of output histogram rootfile", fFileName, TString(""));
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// free the memory.
74
76 delete h1_e;
77 delete h1_e_all;
78 delete h1_a;
79 delete h1_a_all;
80 delete h2;
81 h1_e = nullptr;
82 h1_e_all = nullptr;
83 h1_a = nullptr;
84 h1_a_all = nullptr;
85 h2 = nullptr;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Initialization process
90
91void TSolidAngleProcessor::Init(TEventCollection *col) {
92 Info("Init", "make solid angle histogram Ecm and Thetacm");
93 if (fRange_angle.size() != 2 || fRange_energy.size() != 2) {
94 SetStateError("input steering yaml format is wrong, range size should be 2");
95 return;
96 }
97 Info("Init", "\tAcm(%d, %.1lf, %.1lf)", fNbin_angle, fRange_angle[0], fRange_angle[1]);
98 Info("Init", "\tEcm(%d, %.1lf, %.1lf)", fNbin_energy, fRange_energy[0], fRange_energy[1]);
99 Info("Init", "\t2D(%d, %.1lf, %.1lf, %d, %.1lf, %.1lf)",
102 Info("Init", "saved %s", fFileName.Data());
103
104 fInData = reinterpret_cast<TClonesArray **>(col->GetObjectRef(fInputColName.Data()));
105 if (!fInData) {
106 SetStateError(Form("input not found: %s", fInputColName.Data()));
107 return;
108 }
109 const TClass *const cl = (*fInData)->GetClass();
110 if (!cl->InheritsFrom(art::crib::TTelescopeData::Class())) {
111 SetStateError("contents of input array must inherit from art::crib::TTelescopeData");
112 }
113
114 fInReacData = reinterpret_cast<TClonesArray **>(col->GetObjectRef(fInputReacColName.Data()));
115 if (!fInReacData) {
116 SetStateError(Form("input not found: %s", fInputReacColName.Data()));
117 return;
118 }
119 const TClass *const cl_reac = (*fInReacData)->GetClass();
120 if (!cl_reac->InheritsFrom(art::crib::TReactionInfo::Class())) {
121 SetStateError("contents of input array must inherit from art::crib::TReactionInfo");
122 }
123
124 h1_a_all = new TH1D("norm_Acm", "norm_Acm", fNbin_angle, fRange_angle[0], fRange_angle[1]);
125 h1_e_all = new TH1D("norm_Ecm", "norm_Ecm", fNbin_energy, fRange_energy[0], fRange_energy[1]);
126 h2_all = new TH2D("norm_2D", "norm_2D", fNbin_energy, fRange_energy[0], fRange_energy[1],
128
129 h1_a = new TH1D("Acm", "Acm", fNbin_angle, fRange_angle[0], fRange_angle[1]);
130 h1_e = new TH1D("Ecm", "Ecm", fNbin_energy, fRange_energy[0], fRange_energy[1]);
131 h2 = new TH2D("2D", "2D", fNbin_energy, fRange_energy[0], fRange_energy[1],
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Judge the event is detected at the detector and fill
137/// to the histograms
138
140 if ((*fInReacData)->GetEntriesFast() != 1) {
141 SetStateError("input reaction data branch entry is not 1");
142 return;
143 }
144
145 if ((*fInData)->GetEntriesFast() != 1) {
146 SetStateError("input telescope data branch entry is not 1");
147 return;
148 }
149
150 const TDataObject *const inData = static_cast<TDataObject *>((*fInReacData)->At(0));
151 const TReactionInfo *const Data = dynamic_cast<const TReactionInfo *>(inData);
152 h1_a_all->Fill(Data->GetTheta());
153 h1_e_all->Fill(Data->GetEnergy());
154 h2_all->Fill(Data->GetEnergy(), Data->GetTheta());
155
156 // detected of not
157 const TDataObject *const inDetData = static_cast<TDataObject *>((*fInData)->At(0));
158 const TTelescopeData *const DetData = dynamic_cast<const TTelescopeData *>(inDetData);
159 if (DetData->GetTelID() > 0) {
160 h1_a->Fill(Data->GetTheta());
161 h1_e->Fill(Data->GetEnergy());
162 h2->Fill(Data->GetEnergy(), Data->GetTheta());
163 }
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// After all the events are processed, scale the histograms and
168/// save them
169
171 Util::PrepareDirectoryFor(fFileName);
172 TFile *file = TFile::Open(fFileName, "recreate");
173 if (!file || file->IsZombie()) {
174 std::cerr << "ERROR : cannot open " << fFileName << std::endl;
175 delete file;
176 return;
177 }
178
179 h1_a->Divide(h1_a_all);
180 h1_a->Scale(4.0 * TMath::Pi());
181 h1_a->SetTitle("Solid Angle;Angle CM (deg);");
182 h1_a->Write();
183
184 h1_e->Divide(h1_e_all);
185 h1_e->Scale(4.0 * TMath::Pi());
186 h1_e->SetTitle("Solid Angle;Energy CM (MeV);");
187 h1_e->Write();
188
189 h2->Divide(h2_all);
190 h2->Scale(4.0 * TMath::Pi());
191 h2->SetTitle("Solid Angle;Energy CM (MeV);Angle CM (deg)");
192 h2->Write();
193
194 file->Close();
195 delete file;
196}
ClassImp(TSolidAngleProcessor)
Double_t GetEnergy() const
Double_t GetTheta() const
TH2D * h2_all
for normalie (x: Ecm, y: angle_cm)
void EndOfRun() override
EndOfRun process (override)
DoubleVec_t fRange_energy
Histogram range (min, max)
TH1D * h1_e_all
for normalize (x: Ecm)
TString fInputReacColName
Input reaction object name.
TString fInputColName
Input detected particle object name.
DoubleVec_t fRange_angle
Histogram range (min, max)
~TSolidAngleProcessor() override
default destructor
TH2D * h2
solid angle (x: Ecm, y: angle_cm)
TClonesArray ** fInData
Input detected particle object.
TH1D * h1_a_all
for normalize (x: angle_cm)
void Init(TEventCollection *col) override
Init (override)
TH1D * h1_e
solid angle (x: Ecm)
TString fFileName
Output histogram ROOT file name.
TH1D * h1_a
solid angle (x: angle_cm)
Int_t fNbin_angle
Histogram bin number.
TClonesArray ** fInReacData
Input reaction object.
void Process() override
Process (override)
Int_t fNbin_energy
Histogram bin number.
return to the guide