BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
SRC_EventCounter.C
Go to the documentation of this file.
1// @(#)bmnroot/macro/miscellaneous:$Id$
2// Author: Pavel Batyuk <pavel.batyuk@jinr.ru> 2018-05-20
3
4////////////////////////////////////////////////////////////////////////////////
5// //
6// SRC_EventCounter //
7// //
8// A useful macro to visualize number of collected events (RUN7) //
9// to be used for physics analysis in form of chart pies as a function of //
10// projectile, energy, target //
11// The BM@N UniDb used //
12////////////////////////////////////////////////////////////////////////////////
13
14#include "../run/bmnloadlibs.C"
15
16#include <Rtypes.h>
17#include <TCanvas.h>
18#include <TH2.h>
19#include <TMath.h>
20#include <TPie.h>
21#include <TPieSlice.h>
22#include <TString.h>
23#include <cfloat>
24#include <set>
25#include <vector>
26
27using namespace std;
28using namespace TMath;
29
30void SRC_EventCounter(Int_t run_period = 7)
31{
32 // ---- Load libraries --------------------------------------------------
33 bmnloadlibs(); // load BmnRoot libraries
34
35 // SRC file numbers ...
36 const Int_t kStart = 2041;
37 const Int_t kFinish = 3589;
38
39 set<Double_t> energies;
40 set<TString> targets;
41 set<TString> beams;
42
43 for (Int_t iRun = kStart; iRun < kFinish; iRun++) {
44 UniRun* pCurrentRun = UniRun::GetRun(run_period, iRun);
45
46 if (pCurrentRun == NULL) {
47 delete pCurrentRun;
48 continue;
49 }
50
51 TString* targStar = pCurrentRun->GetTargetParticle();
52 Double_t* eneStar = pCurrentRun->GetEnergy();
53 Double_t* apprCurrentStar = pCurrentRun->GetFieldVoltage();
54
55 if (targStar == NULL || eneStar == NULL || apprCurrentStar == NULL)
56 continue;
57
58 TString beamPart = pCurrentRun->GetBeamParticle();
59
60 energies.insert(*eneStar);
61 targets.insert(*targStar);
62 beams.insert(beamPart);
63 }
64
65 TCanvas* c = new TCanvas("c", "c", 800, 400);
66 c->Divide(energies.size(), beams.size());
67 TPie* charts[beams.size()][energies.size()];
68
69 const Int_t nProjectiles = 1; // beams.size();
70 TString PROJECTILES[nProjectiles] = {"C"};
71
72 const Int_t nEnergies = 1; // energies.size();
73 const Double_t ENERGIES[nEnergies] = {3.17};
74
75 const Int_t nTargs = 5; // targets.size();
76 const TString TARGETS[nTargs] = {"H2", "Pb", "SRC Lead 1", "SRC Lead 2", "SRC Lead 3"};
77
78 Long_t nEvs[beams.size()][energies.size()][nTargs]; // [] proj, [] ene, [] nEvs per each target
79 for (Int_t iProj = 0; iProj < beams.size(); iProj++)
80 for (Int_t iEne = 0; iEne < energies.size(); iEne++)
81 for (Int_t iTarg = 0; iTarg < nTargs; iTarg++)
82 nEvs[iProj][iEne][iTarg] = 0;
83
84 // Loop over projectiles ...
85 for (auto itBeam : beams) {
86 for (auto itEne : energies) {
87 for (Int_t iRun = kStart; iRun < kFinish; iRun++) {
88 UniRun* pCurrentRun = UniRun::GetRun(run_period, iRun);
89
90 if (pCurrentRun == NULL) {
91 delete pCurrentRun;
92 continue;
93 }
94
95 TString* targStar = pCurrentRun->GetTargetParticle();
96 Double_t* eneStar = pCurrentRun->GetEnergy();
97 Double_t* apprCurrentStar = pCurrentRun->GetFieldVoltage();
98
99 if (targStar == NULL || eneStar == NULL || apprCurrentStar == NULL)
100 continue;
101
102 // Get only data to be used for physics ...
103 if (*apprCurrentStar < FLT_EPSILON)
104 continue;
105
106 TString proj = pCurrentRun->GetBeamParticle();
107
108 if (proj != itBeam || *eneStar != itEne)
109 continue;
110
111 // Get target ...
112 TString targ = *pCurrentRun->GetTargetParticle();
113
114 // Set indices ...
115 Int_t idxBeam = (proj == PROJECTILES[0]) ? 0 : -1;
116
117 Int_t idxEne = (Abs(*eneStar - ENERGIES[0]) < FLT_EPSILON) ? 0 : -1;
118
119 Int_t idxTarg = -1;
120 for (Int_t iTarg = 0; iTarg < nTargs; iTarg++)
121 if (targ == TARGETS[iTarg]) {
122 idxTarg = iTarg;
123 break;
124 }
125
126 nEvs[idxBeam][idxEne][idxTarg] += *pCurrentRun->GetEventCount();
127 }
128 }
129 }
130
131 for (Int_t iProj = 0; iProj < beams.size(); iProj++)
132 for (Int_t iEne = 0; iEne < energies.size(); iEne++)
133 for (Int_t iTarg = 0; iTarg < nTargs; iTarg++)
134 cout << iProj << " " << iEne << " " << iTarg << " " << nEvs[iProj][iEne][iTarg] / 1e6 << " MEvs"
135 << endl;
136
137 Int_t iPad = 1;
138 for (Int_t iProj = 0; iProj < beams.size(); iProj++)
139 for (Int_t iEne = 0; iEne < energies.size(); iEne++) {
140 Double_t pieContent[nTargs];
141 Int_t colors[nTargs];
142 for (Int_t iTarg = 0; iTarg < nTargs; iTarg++) {
143 pieContent[iTarg] = nEvs[iProj][iEne][iTarg] / 1e6;
144 colors[iTarg] = 2 + iTarg;
145 }
146
147 Double_t pieContentSum = 0.;
148 for (Int_t iTarg = 0; iTarg < nTargs; iTarg++)
149 pieContentSum += pieContent[iTarg];
150
151 charts[iProj][iEne] =
152 new TPie(Form("Projectile %s (T = %G GeV/n)", PROJECTILES[iProj].Data(), ENERGIES[iEne]),
153 Form("Projectile %s (T = %G GeV/n)", PROJECTILES[iProj].Data(), ENERGIES[iEne]), nTargs,
154 pieContent, colors);
155 c->cd(iPad);
156 for (Int_t iTarg = 0; iTarg < nTargs; iTarg++) {
157 TPieSlice* slice = charts[iProj][iEne]->GetSlice(iTarg);
158 Double_t valSlice = slice->GetValue();
159 TString sliceTitle = (valSlice > FLT_EPSILON) ? TARGETS[iTarg] : "";
160 if (valSlice < FLT_EPSILON)
161 slice->SetRadiusOffset(DBL_MAX);
162 slice->SetTitle(Form("%s", sliceTitle.Data()));
163 }
164
165 charts[iProj][iEne]->SetRadius(.25);
166 charts[iProj][iEne]->SetLabelsOffset(.06);
167 charts[iProj][iEne]->SetAngularOffset(-75.);
168 charts[iProj][iEne]->SetTextSize(0.05);
169 charts[iProj][iEne]->SetLabelFormat("#splitline{%txt (%perc)}{%val MEvs}");
170 if (pieContentSum > FLT_EPSILON) {
171 // charts[iProj][iEne]->SetY(.75);
172 charts[iProj][iEne]->Draw("3d nol");
173 }
174
175 iPad++;
176 }
177 c->SaveAs("SRC_physEvents_Run7.pdf");
178}
int Int_t
long Long_t
double Double_t
char * Form(const char *fmt,...)
virtual void SetTextSize(Float_t tsize=1)
TVirtualPad * cd(Int_t subpadnumber=0) override
virtual void SetTitle(const char *title="")
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
void SaveAs(const char *filename="", Option_t *option="") const override
Double_t GetValue() const
void SetRadiusOffset(Double_t)
TPieSlice * GetSlice(Int_t i)
void SetAngularOffset(Double_t)
void SetLabelsOffset(Float_t)
void SetLabelFormat(const char *)
void SetRadius(Double_t)
void Draw(Option_t *option="l") override
const char * Data() const
UniRun.h Class for the table: run_.
Definition UniRun.h:21
double * GetEnergy()
get energy of the current run
Definition UniRun.h:113
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
TString GetBeamParticle()
get beam particle of the current run
Definition UniRun.h:109
double * GetFieldVoltage()
get field voltage of the current run
Definition UniRun.h:121
int * GetEventCount()
get event count of the current run
Definition UniRun.h:129
TString GetTargetParticle()
get target particle of the current run
Definition UniRun.h:111
void SRC_EventCounter(Int_t run_period=7)
Double_t Abs(Double_t d)
Definition json.hpp:4446