BmnRoot 26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
light_yield.cpp
Go to the documentation of this file.
1#include <TCanvas.h>
2#include <TDirectory.h>
3#include <TH1.h>
4#include <TStyle.h>
5#include <fstream>
6#include <iostream>
7
8#define kTotalModules 54
9
11{
13 Mapper->ParseCalibration("FHCAL_calibration_2022.txt");
14
15 TString led_files_path = "/home/nikolay/BMN/FHCal/LED/";
16
17 double final_calib[kTotalModules + 1][11];
18 memset(final_calib, 0, sizeof(final_calib[0][0]) * (kTotalModules + 1) * 11);
19 for (uint32_t mod_iter = 1; mod_iter <= 54; mod_iter++) {
20
21 TString led_calib_par_file = led_files_path + Form("mod%02d.txt", mod_iter);
22 ifstream led_params_file(led_calib_par_file.Data(), std::ifstream::in);
23 cout << led_calib_par_file << endl;
24 vector<double> ledVec;
25 if (led_params_file.is_open()) {
26 // Got to the last character before EOF
27 led_params_file.seekg(-1, std::ios_base::end);
28 if (led_params_file.peek() == '\n') {
29 // Start searching for \n occurrences
30 led_params_file.seekg(-1, std::ios_base::cur);
31 int i = led_params_file.tellg();
32 for (i; i > 0; i--) {
33 if (led_params_file.peek() == '{') {
34 // Found
35 led_params_file.get();
36 break;
37 }
38 // Move one character back
39 led_params_file.seekg(i, std::ios_base::beg);
40 }
41 }
42
43 ledVec.clear();
44 ledVec.resize(10);
45 std::string lastline;
46 getline(led_params_file, lastline);
47 stringstream ss(lastline);
48 string result;
49
50 int counter = 0;
51 while (ss.good()) {
52 getline(ss, result, ',');
53 cout << result << endl;
54
55 ledVec.at(counter) = stod(result);
56 counter++;
57 }
58
59 for (auto it : ledVec)
60 cout << it << " ";
61 cout << endl;
62 }
63
64 for (uint32_t sec_iter = 1; sec_iter <= 10; sec_iter++) {
65 uint32_t address = BmnFHCalAddress::GetAddress(0, mod_iter, sec_iter, 0, 0, 0);
66 auto calib_pair = Mapper->GetCalibPairFromAddress(address);
67
68 double mip_calib = calib_pair.first;
69
70 cout << mod_iter << " " << sec_iter << " " << mip_calib << endl;
71 if (mip_calib < 1e-6)
72 mip_calib = 0.;
73 else
74 mip_calib = 1. / mip_calib;
75
76 final_calib[mod_iter][sec_iter] = mip_calib * ledVec.at(sec_iter - 1);
77 }
78 }
79
80 TH1* th1_hist_ptr = nullptr;
81 TCanvas* tcanv_ptr = nullptr;
82
83 TObjArray* result_array = new TObjArray;
84 result_array->SetName("calo_npe_calib");
85 result_array->SetOwner();
86
87 TObjArray* canvas_array = new TObjArray;
88 canvas_array->SetName("Canvas");
89
90 for (Int_t module_iter = 1; module_iter <= kTotalModules; module_iter++) {
91 TString module_name = Form("bmn_fhcal_module_%02d", module_iter);
92 th1_hist_ptr =
93 new TH1F(Form("Module_%s", module_name.Data()), Form("Module_%s", module_name.Data()), 12, -0.5, 11.5);
94 th1_hist_ptr->SetTitle(Form("%s; #section; Light yield [ph.e./mip]", module_name.Data()));
95 th1_hist_ptr->SetMarkerStyle(23);
96 result_array->Add(th1_hist_ptr);
97 }
98
99 for (Int_t module_iter = 1; module_iter <= kTotalModules; module_iter++) {
100 TString module_name = Form("bmn_fhcal_module_%02d", module_iter);
101 th1_hist_ptr = ((TH1*)(gDirectory->FindObjectAny(Form("Module_%s", module_name.Data()))));
102 for (int sec_iter = 1; sec_iter <= 10; sec_iter++)
103 th1_hist_ptr->Fill(sec_iter, final_calib[module_iter][sec_iter]);
104 }
105
106 TCanvas* canvas_ly = new TCanvas[kTotalModules + 1];
107 gStyle->SetOptStat(0);
108 for (Int_t module_iter = 1; module_iter <= kTotalModules; module_iter++) {
109 tcanv_ptr = &canvas_ly[module_iter];
110 tcanv_ptr->SetName(Form("c_light_yield_mod_%i", module_iter));
111 tcanv_ptr->SetTitle(Form("c_light_yield_mod_%i", module_iter));
112 canvas_array->Add(tcanv_ptr);
113 tcanv_ptr->cd();
114
115 TString module_name = Form("bmn_fhcal_module_%02d", module_iter);
116 th1_hist_ptr = ((TH1*)(gDirectory->FindObjectAny(Form("Module_%s", module_name.Data()))));
117 th1_hist_ptr->GetYaxis()->SetRangeUser(0, 1.1 * th1_hist_ptr->GetMaximum());
118 th1_hist_ptr->Draw("hist P");
119 }
120
121 TString result_file_name = "resss";
122 for (Int_t i = 0; i < canvas_array->GetLast(); i++)
123 ((TCanvas*)canvas_array->At(i))->SaveAs((result_file_name + ".pdf(").Data());
124 ((TCanvas*)canvas_array->At(canvas_array->GetLast()))->SaveAs((result_file_name + ".pdf)").Data());
125 printf("file %s was written\n", (result_file_name + ".pdf").Data());
126
127 TFile* result_file = new TFile((result_file_name + ".root").Data(), "RECREATE");
128 TString start_path = result_array->GetName();
129 result_file->mkdir(start_path.Data());
130 result_file->cd(start_path.Data());
131 TIter nx_iter((TCollection*)(result_array));
132 TObject* obj_ptr;
133 while ((obj_ptr = (TObjArray*)nx_iter())) {
134 if (obj_ptr == nullptr)
135 continue;
136 printf("Writing %s object\n", obj_ptr->GetName());
137 obj_ptr->Write();
138 }
139 printf("file %s was written\n", (result_file_name + ".root").Data());
140 result_file->Close();
141 delete result_file;
142}
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
#define gDirectory
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
static uint32_t GetAddress(uint32_t ModuleType, uint32_t ModuleId, uint32_t SectionId, uint32_t ScintillatorId=0)
Return address from system ID, Module type, Module ID, Section ID, Scintillator ID (optional).
void ParseCalibration(TString calibrationFile)
std::optional< std::pair< float, float > > GetCalibPairFromAddress(uint32_t address)
virtual void SetMarkerStyle(Style_t mstyle=1)
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
TVirtualPad * cd(Int_t subpadnumber=0) override
void SetTitle(const char *title="") override
void SetName(const char *name="") override
void SetName(const char *name)
const char * GetName() const override
virtual void SetOwner(Bool_t enable=kTRUE)
Bool_t cd() override
TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
void Close(Option_t *option="") override
void SetTitle(const char *title) override
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
TAxis * GetYaxis()
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
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)
const char * Data() const
void light_yield()
#define kTotalModules