BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
hodo_profile.cpp
Go to the documentation of this file.
1#include "TCutG.h"
2
3#include <TCanvas.h>
4#include <TF1.h>
5#include <TFile.h>
6#include <TGraph.h>
7#include <TH1F.h>
8#include <TNtuple.h>
9#include <TTree.h>
10#include <algorithm>
11#include <fstream>
12#include <iostream>
13#include <map>
14#include <numeric>
15#include <stdio.h>
16#include <vector>
17// #include "utils.h"
18#include "TH1D.h"
19#include "TH2.h"
20#include "TMultiGraph.h"
21#include "TString.h"
22#include "TStyle.h"
23// #include "BmnHodoDigi.h"
24#include "../common/utilites.h"
25#include "TClonesArray.h"
26
27#define kNstrips 16
28#define kNsides 2
29#define kNgains 2
30
31int make_flat_index(uint32_t StripId, uint32_t StripSide, uint32_t Gain)
32{
33 uint32_t address = BmnHodoAddress::GetAddress(0, StripId, StripSide, Gain);
34 return BmnHodoAddress::GetFlatIndex(address);
35}
36
37void hodo_profile(TString converted_root_file, TString result_file_name, int max_entries)
38{
39 TObjArray* canvas_array = new TObjArray;
40 canvas_array->SetName("Canvas");
41 TObjArray* result_array = new TObjArray;
42 result_array->SetName("Histo");
43
44 int variantes = BmnHodoAddress::GetMaxFlatIndex();
45 TH2F* profile_hist = new TH2F("profile", "profile", 18, 0, 18, 100, 0, 50);
46 profile_hist->SetTitle("Hodoscope profile; Strip # ; Z^{2} ");
47 profile_hist->SetStats(0);
48
49 TFile* _file0 = TFile::Open(converted_root_file, "READONLY");
50 TTree* tree = (TTree*)_file0->Get("bmndata");
51
52 BmnEventHeader* eventHeader = nullptr;
53 tree->SetBranchAddress("BmnEventHeader.", &eventHeader);
54
55 TClonesArray* DigiArray = nullptr; // leave nullptr!!!
56 tree->SetBranchAddress("HodoDigi", &DigiArray);
57
58 TClonesArray* ScWallDigiArray = nullptr; // leave nullptr!!!
59 tree->SetBranchAddress("ScWallDigi", &ScWallDigiArray);
60
61 double ScWallCtrEnergy = 0.;
62 int counter = 0;
63 int n_events = (max_entries > 0 && tree->GetEntries() > max_entries) ? max_entries : tree->GetEntries();
64 cout << n_events << endl;
65 for (int ev = 0; ev < n_events; ev++) ////nt1->GetEntries() //get entries from .root
66 {
67 tree->GetEntry(ev);
68 if (ev % 10000 == 0)
69 cout << "Event: " << ev << endl;
70
71 auto TrigPattern = eventHeader->GetInputSignalsAR();
72 auto BT = !(TrigPattern ^ (1 << 7));
73 auto ArmAnd = !(TrigPattern ^ (1 << 2));
74 auto ArmOr = !(TrigPattern ^ (1 << 3));
75 if (!ArmOr)
76 continue;
77
78 ScWallCtrEnergy = 0.;
79 for (int i = 0; i < ScWallDigiArray->GetEntriesFast(); i++) {
80 BmnScWallDigi* ThisDigi = (BmnScWallDigi*)ScWallDigiArray->At(i);
81
82 // ##################################
83 // SELECTION
84 if (ThisDigi->fFitR2 > 0.5)
85 continue;
86 auto cell_id = ThisDigi->GetCellId();
87 if (cell_id != 17 && cell_id != 18 && cell_id != 27 && cell_id != 28)
88 continue; // MF = 1650
89 ScWallCtrEnergy += ThisDigi->GetSignal();
90 }
91 // if(ScWallCtrEnergy < 40) continue;
92
93 float responses[kNstrips + 1][kNsides];
94 memset(responses, 0, sizeof(responses[0][0]) * (kNstrips + 1) * kNsides);
95 for (int i = 0; i < DigiArray->GetEntriesFast(); i++) {
96 BmnHodoDigi* ThisDigi = (BmnHodoDigi*)DigiArray->At(i);
97
98 // ##################################
99 // SELECTION
100 // if(ThisDigi->GetStripId() == 9) continue;
101 if (ThisDigi->fFitR2 > 0.4)
102 continue;
103 if (ThisDigi->fTimeMax > 28 || ThisDigi->fTimeMax < 25)
104 continue;
105 // ##################################
106
107 auto strip = ThisDigi->GetStripId();
108 auto side = ThisDigi->GetStripSide();
109 auto gain = ThisDigi->GetGain();
110 auto idx = make_flat_index(strip, side, gain);
111
112 if (gain != 1)
113 continue;
114 responses[strip][side] = ThisDigi->GetSignal();
115 }
116
117 for (int i = 1; i <= kNstrips; i++)
118 if (responses[i][0] * responses[i][1] > 0.001)
119 profile_hist->Fill(i, (responses[i][0] + responses[i][1]));
120 }
121
122 TCanvas* prof = new TCanvas("c_prof", "c_prof", 800, 800);
123 canvas_array->Add(prof);
124 result_array->Add(profile_hist);
125 profile_hist->Draw("colz");
126
127 for (int i = 1; i <= kNstrips; i++) {
128 TCanvas* canv_ptr = new TCanvas();
129 canvas_array->Add(canv_ptr);
130 auto hist_ptr = profile_hist->ProjectionY(Form("projection_strip%i", i), i, i + 1);
131 hist_ptr->SetTitle(Form("strip%i; Z^{2}; Counts", i));
132 result_array->Add(hist_ptr);
133 hist_ptr->Draw();
134 }
135
136 TFile* result_file = new TFile((result_file_name + ".root").Data(), "RECREATE");
137 TIter nx_iter((TCollection*)(result_array));
138 TObject* obj_ptr;
139 while ((obj_ptr = (TObjArray*)nx_iter())) {
140 if (obj_ptr == nullptr)
141 continue;
142 printf("Writing %s object\n", obj_ptr->GetName());
143 obj_ptr->Write();
144 }
145 printf("file %s was written\n", (result_file_name + ".root").Data());
146 result_file->Close();
147 delete result_file;
148
149 for (Int_t i = 0; i < canvas_array->GetLast(); i++)
150 ((TCanvas*)canvas_array->At(i))->SaveAs((result_file_name + ".pdf(").Data());
151 ((TCanvas*)canvas_array->At(canvas_array->GetLast()))->SaveAs((result_file_name + ".pdf)").Data());
152 printf("file %s was written\n", (result_file_name + ".pdf").Data());
153}
void memset(T *dest, T i, size_t num)
Copy to memory block [@dest, @dest+@num] num number of times the value of i of type @T with size @typ...
Definition L1Grid.h:27
int i
Definition P4_F32vec4.h:22
int Int_t
char * Form(const char *fmt,...)
double GetSignal() const
float fFitR2
Energy deposition from fit of waveform [adc counts].
int fTimeMax
Energy deposition from waveform [adc counts].
UInt_t GetInputSignalsAR()
Get Input signal states, after reduction.
static uint32_t GetAddress(uint32_t StripId, uint32_t StripSide, uint32_t Gain)
Return address from system ID, StripId, StripSide, Gain.
Data class for BmnHodo digital signal processing.
Definition BmnHodoDigi.h:25
uint32_t GetGain() const
Gain.
Definition BmnHodoDigi.h:70
uint32_t GetStripSide() const
Strip Side.
Definition BmnHodoDigi.h:65
uint32_t GetStripId() const
Class for experimental data at digi level.
uint32_t GetCellId() const
void SetName(const char *name)
T * Get(const char *namecycle)
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
void Close(Option_t *option="") override
void SetTitle(const char *title) override
void Draw(Option_t *option="") override
virtual void SetStats(Bool_t stats=kTRUE)
TH1D * ProjectionY(const char *name="_py", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="") const
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
Int_t GetLast() const override
void Add(TObject *obj) override
virtual const char * GetName() const
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
virtual void SaveAs(const char *filename="", Option_t *option="") const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
virtual Long64_t GetEntries() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
#define kNstrips
#define kNsides
void hodo_profile(TString converted_root_file, TString result_file_name, int max_entries)
int make_flat_index(uint32_t StripId, uint32_t StripSide, uint32_t Gain)