BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
fhcal_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 kNmodules 55
28
29void fhcal_profile(TString converted_root_file, TString result_file_name, int max_entries)
30{
31
32 TObjArray* canvas_array = new TObjArray;
33 canvas_array->SetName("Canvas");
34
35 TH1F* calo_summ = new TH1F("calo_summ", "calo_summ", 300, 0, 300);
36 calo_summ->SetTitle(Form("%s; Energy [mip]; Counts", result_file_name.Data()));
37
38 TH2F* h2_calo = new TH2F("calo_2d", "calo_2d", 50, 0, 1500, 60, 0, 1200);
39 h2_calo->SetTitle(Form("%s; x [mm]; y [mm]; Average signal [mip]", result_file_name.Data()));
40 TH2F* h2_text_center = new TH2F("text_center", "text_center", 50, 0, 1500, 60, 0, 1200);
41
43 Mapper->ParseConfig("FHCAL_map_dry_run_2022.txt");
44 auto ThatVectorX = Mapper->GetUniqueXpositions();
45 auto ThatVectorY = Mapper->GetUniqueYpositions();
46 auto ThatVectorZ = Mapper->GetUniqueZpositions();
47 delete Mapper;
48
49 std::vector<TH1F*> profile_hist_vect;
50 profile_hist_vect.resize(kNmodules);
51 for (int mod_it = 1; mod_it < kNmodules; mod_it++)
52 profile_hist_vect.at(mod_it) = new TH1F(Form("module_%i", mod_it), Form("module_%i", mod_it), 10, 0.5, 10.5);
53
54 TFile* _file0 = TFile::Open(converted_root_file, "READONLY");
55 TTree* tree = (TTree*)_file0->Get("bmndata");
56
57 TClonesArray* DigiArray = nullptr; // leave nullptr!!!
58 tree->SetBranchAddress("FHCalDigi", &DigiArray);
59
60 TClonesArray* ScWallDigiArray = nullptr; // leave nullptr!!!
61 tree->SetBranchAddress("ScWallDigi", &ScWallDigiArray);
62
63 double SumEnergy = 0.;
64 double ScWallCtrEnergy = 0.;
65
66 int counter = 0;
67 int n_events = (max_entries > 0 && tree->GetEntries() > max_entries) ? max_entries : tree->GetEntries();
68 cout << n_events << endl;
69 for (int ev = 0; ev < n_events; ev++) ////nt1->GetEntries() //get entries from .root
70 {
71 tree->GetEntry(ev);
72
73 ScWallCtrEnergy = 0.;
74 for (int i = 0; i < ScWallDigiArray->GetEntriesFast(); i++) {
75 BmnScWallDigi* ThisDigi = (BmnScWallDigi*)ScWallDigiArray->At(i);
76
77 // ##################################
78 // SELECTION
79 if (ThisDigi->fFitR2 > 0.5)
80 continue;
81 auto cell_id = ThisDigi->GetCellId();
82 if (cell_id != 14 && cell_id != 15 && cell_id != 24 && cell_id != 25)
83 continue;
84 ScWallCtrEnergy += ThisDigi->GetSignal();
85 }
86 if (ScWallCtrEnergy < 60)
87 continue;
88
89 float responses[kNmodules];
90 memset(responses, 0, sizeof(responses[0]) * kNmodules);
91 SumEnergy = 0.;
92 for (int i = 0; i < DigiArray->GetEntriesFast(); i++) {
93 counter++;
94 BmnFHCalDigi* ThisDigi = (BmnFHCalDigi*)DigiArray->At(i);
95
96 // ##################################
97 // SELECTION
98 if (ThisDigi->fFitR2 > 0.2)
99 continue;
100 if (ThisDigi->fTimeMax <= 36 || ThisDigi->fTimeMax >= 39)
101 continue;
102 if (ThisDigi->fFitTimeMax <= 34 || ThisDigi->fFitTimeMax >= 39)
103 continue;
104 // ##################################
105
106 auto mod_id = ThisDigi->GetModuleId();
107 // if(mod_id != 16 && mod_id != 11 && mod_id != 17 && mod_id != 20 && mod_id != 40) continue;
108 // if(mod_id != 16) continue;
109 auto sec_id = ThisDigi->GetSectionId();
110 profile_hist_vect.at(mod_id)->Fill(sec_id, ThisDigi->GetSignal());
111
112 float realXpos = ThatVectorX.at(ThisDigi->GetX());
113 float realYpos = ThatVectorY.at(ThisDigi->GetY());
114 float realZpos = ThatVectorZ.at(ThisDigi->GetZ());
115
116 h2_calo->Fill(realXpos, realYpos, ThisDigi->GetSignal());
117 SumEnergy += ThisDigi->GetSignal();
118
119 auto ibin = h2_text_center->FindBin(realXpos, realYpos + 50);
120 if (h2_text_center->GetBinContent(ibin) < 1)
121 h2_text_center->Fill(realXpos, realYpos + 50, ThisDigi->GetModuleId());
122 }
123 if (SumEnergy > 0.1)
124 calo_summ->Fill(SumEnergy);
125 }
126
127 for (int mod_it = 1; mod_it < kNmodules; mod_it++)
128 profile_hist_vect.at(mod_it)->Scale(1. / n_events);
129
130 TCanvas* canv_summ = new TCanvas;
131 canvas_array->Add(canv_summ);
132 canv_summ->SetLogy();
133 calo_summ->Draw();
134
135 TCanvas* canv_2d = new TCanvas;
136 gPad->SetRightMargin(0.15);
137 canvas_array->Add(canv_2d);
138 h2_calo->SetBit(TH1::kNoStats);
139 h2_calo->Scale(1. / n_events);
140 h2_calo->Draw("colz");
141 h2_text_center->SetMarkerSize(1.3);
142 h2_text_center->Draw("text same");
143
144 /*
145 TCanvas* canv_all = new TCanvas;
146 canv_all->DivideSquare(kNmodules+1);
147 canvas_array->Add(canv_all);
148
149 std::vector<TCanvas*> canv_vect;
150 canv_vect.resize(kNmodules);
151 for(int mod_it = 1; mod_it < kNmodules; mod_it++){
152 canv_vect.at(mod_it) = new TCanvas;
153 canvas_array->Add(canv_vect.at(mod_it));
154 profile_hist_vect.at(mod_it)->SetTitle( Form("module_%i; # sec; Average signal [mip]", mod_it) );
155 //profile_hist_vect.at(mod_it)->GetYaxis()->SetRangeUser(0,10);
156 profile_hist_vect.at(mod_it)->Draw("hist");
157
158 canv_all->cd(mod_it);
159 profile_hist_vect.at(mod_it)->Draw("hist");
160 }
161 */
162
163 for (Int_t i = 0; i < canvas_array->GetLast(); i++)
164 ((TCanvas*)canvas_array->At(i))->SaveAs((result_file_name + ".pdf(").Data());
165 ((TCanvas*)canvas_array->At(canvas_array->GetLast()))->SaveAs((result_file_name + ".pdf)").Data());
166 printf("file %s was written\n", (result_file_name + ".pdf").Data());
167}
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,...)
#define gPad
double GetSignal() const
float fFitTimeMax
Quality of waveform fit [] – good near 0.
float fFitR2
Energy deposition from fit of waveform [adc counts].
int fTimeMax
Energy deposition from waveform [adc counts].
Data class for Bmn FHCal digital signal processing.
uint32_t GetSectionId() const
uint32_t GetModuleId() const
void ParseConfig(TString mappingFile)
Class for experimental data at digi level.
uint32_t GetCellId() const
virtual void SetMarkerSize(Size_t msize=1)
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 SetTitle(const char *title) override
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void Scale(Double_t c1=1, Option_t *option="")
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
virtual Double_t GetBinContent(Int_t bin) const
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
Int_t GetLast() const override
void Add(TObject *obj) override
void SetBit(UInt_t f)
void SetLogy(Int_t value=1) override
const char * Data() 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 kNmodules
void fhcal_profile(TString converted_root_file, TString result_file_name, int max_entries)