BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
readScalers.C
Go to the documentation of this file.
1
2
#define PAD_WIDTH 720
3
#define PAD_HEIGHT 560
4
/**
5
* readScalers
6
* Example of reading scaler values
7
* @param fileName
8
* @param NExamples number of events to show (0 - all events)
9
*/
10
void
readScalers
(
TString
fileName =
""
,
Long64_t
NExamples = 0)
11
{
12
if
(fileName ==
""
) {
13
cout <<
"File not specified!"
<< endl;
14
return
;
15
}
16
17
TFile
* file =
new
TFile
(fileName,
"READ"
);
18
if
(file->
IsOpen
() ==
false
) {
19
printf(
"\nCannot open file %s !\n"
, fileName.Data());
20
return
;
21
}
22
/**
23
* Reading Run Header for the whole run statistics:
24
* beam counters, run start/end time
25
*/
26
printf(
"Run Header content:\n"
);
27
DigiRunHeader
* rh = (
DigiRunHeader
*)file->
Get
(
"DigiRunHeader"
);
28
29
UInt_t
PeriodId = rh->
GetPeriodId
();
30
UInt_t
RunId = rh->
GetRunId
();
31
printf(
"\tPeriod: %u Run: %u\n"
, PeriodId, RunId);
32
33
// Double_t BT = rh->GetBT(); // Beam Trigger
34
// Double_t BTnBusy = rh->GetBTnBusy(); // BT & not Busy
35
// // (BT & not Busy) normalized by Before&After protection ratio
36
// Double_t TotalFlux = rh->GetBTAccepted();
37
// printf("\tBeam Trigger : %f\n", BT);
38
// printf("\tBeam Trigger and Not Busy : %f\n", BTnBusy);
39
// printf("\tBeam Trigger Accepted Events (Flux): %f\n", TotalFlux);
40
TTimeStamp
RunStartTime = rh->
GetRunStartTime
();
41
TTimeStamp
RunEndTime = rh->
GetRunEndTime
();
42
printf(
"\tSTART : %s\n"
, RunStartTime.
AsString
());
43
printf(
"\tFINISH : %s\n"
, RunEndTime.
AsString
());
44
/**
45
* Reading Event Header for each event in the range:
46
* current spill statistics,
47
*/
48
const
vector<TString> trc_map{
"BC1L"
,
"pBT"
,
"BT"
,
"NiT"
,
"CCT1"
,
"MBT"
,
"BT&nBUSY"
,
"CCT2"
};
49
vector<uint64_t> trc_counts_BR;
50
vector<uint64_t> trc_counts_AR;
51
size_t
trigCount = trc_map.size();
52
uint64_t payloadEvCnt(0);
53
trc_counts_BR.resize(trigCount, 0);
54
trc_counts_AR.resize(trigCount, 0);
55
TString
name =
"Scalers"
;
56
TCanvas
*
can
=
new
TCanvas
(name, name,
PAD_WIDTH
* 1,
PAD_HEIGHT
* 2);
57
can
->Divide(1, 2);
58
name =
"Before_reduction"
;
59
TH1I
* hBR =
new
TH1I
(name, name, trigCount, 0, (
Double_t
)trigCount);
60
name =
"After__reduction"
;
61
TH1I
* hAR =
new
TH1I
(name, name, trigCount, 0, (
Double_t
)trigCount);
62
TAxis
* xaBR = hBR->
GetXaxis
();
63
TAxis
* xaAR = hAR->
GetXaxis
();
64
for
(
Int_t
i
= 0;
i
< trigCount; ++
i
) {
65
xaBR->
SetBinLabel
(
i
+ 1, trc_map[
i
]);
66
xaAR->
SetBinLabel
(
i
+ 1, trc_map[
i
]);
67
}
68
69
TTree
* tree = (
TTree
*)file->
Get
(
"bmndata"
);
70
BmnEventHeader
* eh =
nullptr
;
71
tree->
SetBranchAddress
(
"BmnEventHeader."
, &eh);
72
Long64_t
NEvents = tree->
GetEntries
();
73
NExamples = (NExamples == 0) ? NEvents :
min
(NEvents, NExamples);
74
for
(
Int_t
i
= 0;
i
< NExamples;
i
++) {
75
tree->
GetEntry
(
i
);
76
if
(eh->
GetEventType
() !=
kBMNPAYLOAD
)
77
continue
;
78
++payloadEvCnt;
79
// printf("ev %7d type %d \n\t BR %3u \n\t AR %3u\n",
80
// eh->GetEventId(), eh->GetEventType(),
81
// eh->GetInputSignalsBR(),
82
// eh->GetInputSignalsAR());
83
for
(
Int_t
iBit = 0; iBit < trigCount; ++iBit) {
84
bool
isSetBR = eh->
GetInputSignalsBR
() &
BIT
(iBit);
85
bool
isSetAR = eh->
GetInputSignalsAR
() &
BIT
(iBit);
86
trc_counts_BR[iBit] += isSetBR;
87
trc_counts_AR[iBit] += isSetAR;
88
if
(isSetBR) {
89
hBR->
Fill
(trc_map[iBit], 1);
90
}
91
if
(isSetAR) {
92
hAR->
Fill
(trc_map[iBit], 1);
93
}
94
}
95
}
96
can
->cd(1);
97
hBR->
Draw
();
98
can
->cd(2);
99
hAR->
Draw
();
100
can
->SaveAs(
"scalers.png"
);
101
printf(
"Before reduction\n"
);
102
for
(
Int_t
iBit = 0; iBit < trigCount; ++iBit) {
103
printf(
"%15s %lu\n"
, trc_map[iBit].Data(), trc_counts_BR[iBit]);
104
}
105
printf(
"After reduction\n"
);
106
for
(
Int_t
iBit = 0; iBit < trigCount; ++iBit) {
107
printf(
"%15s %lu\n"
, trc_map[iBit].Data(), trc_counts_AR[iBit]);
108
}
109
printf(
" %lld events shown.\n"
, NExamples);
110
printf(
" %lu payload events.\n"
, payloadEvCnt);
111
}
PAD_WIDTH
#define PAD_WIDTH
Definition
readScalers.C:2
PAD_HEIGHT
#define PAD_HEIGHT
Definition
readScalers.C:3
can
TCanvas * can(nullptr)
i
int i
Definition
P4_F32vec4.h:22
min
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition
P4_F32vec4.h:30
Int_t
int Int_t
UInt_t
unsigned int UInt_t
Double_t
double Double_t
Long64_t
long long Long64_t
BIT
#define BIT(n)
kBMNPAYLOAD
@ kBMNPAYLOAD
spill event.
Definition
BmnEnums.h:145
BmnEventHeader
Definition
BmnEventHeader.h:24
BmnEventHeader::GetInputSignalsBR
UInt_t GetInputSignalsBR()
Get Input signal states, before reduction.
Definition
BmnEventHeader.h:130
BmnEventHeader::GetInputSignalsAR
UInt_t GetInputSignalsAR()
Get Input signal states, after reduction.
Definition
BmnEventHeader.h:127
BmnEventHeader::GetEventType
BmnEventType GetEventType()
Get the type of this event.
Definition
BmnEventHeader.h:102
DigiRunHeader
Definition
DigiRunHeader.h:21
DigiRunHeader::GetPeriodId
uint64_t GetPeriodId()
Get the period ID for this run.
Definition
DigiRunHeader.h:75
DigiRunHeader::GetRunId
uint64_t GetRunId()
Get the run ID.
Definition
DigiRunHeader.h:77
DigiRunHeader::GetRunEndTime
TTimeStamp GetRunEndTime()
Definition
DigiRunHeader.h:135
DigiRunHeader::GetRunStartTime
TTimeStamp GetRunStartTime()
Definition
DigiRunHeader.h:133
TAxis
TAxis::SetBinLabel
virtual void SetBinLabel(Int_t bin, const char *label)
TCanvas
TDirectoryFile::Get
T * Get(const char *namecycle)
TFile
TFile::IsOpen
virtual Bool_t IsOpen() const
TH1I
TH1::GetXaxis
TAxis * GetXaxis()
TH1::Draw
void Draw(Option_t *option="") override
TH1::Fill
virtual Int_t Fill(const char *name, Double_t w)
TString
TTimeStamp
TTimeStamp::AsString
const char * AsString(const Option_t *option="") const
TTree
TTree::GetEntry
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
TTree::GetEntries
virtual Long64_t GetEntries() const
TTree::SetBranchAddress
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
readScalers
void readScalers(TString fileName="", Long64_t NExamples=0)
readScalers Example of reading scaler values
Definition
readScalers.C:10
macro
howTo
readScalers.C
Generated on
for BmnRoot by
1.17.0