19 void plot(std::vector<TH1F*> Map,
const sinfo& surface_info,
const std::string&
name){
21 std::string out_name = name+
"/"+surface_info.
name+
"/"+surface_info.
name+
"_"+surface_info.
idname;
22 gSystem->Exec( Form(
"mkdir %s", (name+
"/"+surface_info.
name).c_str()) );
25 if(surface_info.
type == 2){
27 TText *vol =
new TText(.1,.95,surface_info.
name.c_str());
29 TText *
surface =
new TText(.1,.9,surface_info.
id.c_str());
31 TText *surface_z =
new TText(.1,.85,(
"Z = " +
to_string(surface_info.
pos)).c_str() );
34 TCanvas *
c1 =
new TCanvas(
"c1",
"mat_R",1200,1200);
35 c1->SetRightMargin(0.14);
36 c1->SetTopMargin(0.14);
37 c1->SetLeftMargin(0.14);
38 c1->SetBottomMargin(0.14);
39 Map[0]->Draw(
"P HIST");
43 c1->Print( (out_name+
"_R.pdf").c_str());
46 TCanvas *
c2 =
new TCanvas(
"c2",
"mat_Phi",1200,1200);
47 c2->SetRightMargin(0.14);
48 c2->SetTopMargin(0.14);
49 c2->SetLeftMargin(0.14);
50 c2->SetBottomMargin(0.14);
51 Map[1]->Draw(
"P HIST");
55 c2->Print( (out_name+
"_Phi.pdf").c_str());
67 if(surface_info.
type == 1){
69 TText *vol =
new TText(.1,.95,surface_info.
name.c_str());
71 TText *
surface =
new TText(.1,.9,surface_info.
id.c_str());
73 TText *surface_r =
new TText(.1,.85,(
"R = " +
to_string(surface_info.
pos)).c_str() );
75 TCanvas *
c1 =
new TCanvas(
"c1",
"mat_Z",1200,1200);
76 c1->SetRightMargin(0.14);
77 c1->SetTopMargin(0.14);
78 c1->SetLeftMargin(0.14);
79 c1->SetBottomMargin(0.14);
80 Map[0]->Draw(
"P HIST");
84 c1->Print( (out_name+
"_Z.pdf").c_str());
87 TCanvas *
c2 =
new TCanvas(
"c2",
"mat_Phi",1200,1200);
88 c2->SetRightMargin(0.14);
89 c2->SetTopMargin(0.14);
90 c2->SetLeftMargin(0.14);
91 c2->SetBottomMargin(0.14);
92 Map[1]->Draw(
"P HIST");
96 c2->Print( (out_name+
"_Phi.pdf").c_str());
112 const sinfo& surface_info){
117 TH1F * Map_scale_Phi;
119 if(surface_info.
type == 1){
120 Map =
new TH1F((
"Map_"+surface_info.
idname).c_str(),(
"Map_"+surface_info.
idname).c_str(),
122 Map_Phi =
new TH1F((
"Map_Phi_"+surface_info.
idname).c_str(),(
"Map_Phi_"+surface_info.
idname).c_str(),
124 Map_scale =
new TH1F((
"Map_scale_"+surface_info.
idname).c_str(),(
"Map_scale_"+surface_info.
idname).c_str(),
126 Map_scale_Phi =
new TH1F((
"Map_scale_Phi_"+surface_info.
idname).c_str(),(
"Map_scale_Phi_"+surface_info.
idname).c_str(),
128 Map->GetXaxis()->SetTitle(
"Z [mm]");
129 Map->GetYaxis()->SetTitle(
"X0");
130 Map_Phi->GetXaxis()->SetTitle(
"Phi");
131 Map_Phi->GetYaxis()->SetTitle(
"X0");
134 if(surface_info.
type == 2){
135 Map =
new TH1F((
"Map_"+surface_info.
idname).c_str(),(
"Map_"+surface_info.
idname).c_str(),
137 Map_Phi =
new TH1F((
"Map_Phi_"+surface_info.
idname).c_str(),(
"Map_Phi_"+surface_info.
idname).c_str(),
139 Map_scale =
new TH1F((
"Map_scale_"+surface_info.
idname).c_str(),(
"Map_scale_"+surface_info.
idname).c_str(),
141 Map_scale_Phi =
new TH1F((
"Map_scale_Phi_"+surface_info.
idname).c_str(),(
"Map_scale_Phi_"+surface_info.
idname).c_str(),
143 Map->GetXaxis()->SetTitle(
"R [mm]");
144 Map->GetYaxis()->SetTitle(
"X0");
145 Map_Phi->GetXaxis()->SetTitle(
"Phi");
146 Map_Phi->GetYaxis()->SetTitle(
"X0");
149 Map->SetMarkerStyle(20);
150 Map_Phi->SetMarkerStyle(20);
152 std::vector<TH1F*> v_hist;
153 v_hist.push_back(Map);
154 v_hist.push_back(Map_Phi);
155 v_hist.push_back(Map_scale);
156 v_hist.push_back(Map_scale_Phi);
157 surface_hist = v_hist;
162 void Fill(std::map<uint64_t,std::vector<TH1F*>>& surface_hist, std::map<uint64_t,sinfo>& surface_info,
163 const std::string& input_file,
const std::string& json_surface_file,
const int& nbprocess){
166 std::map<std::string,std::string> surface_name;
168 if(json_surface_file !=
""){
169 std::ifstream lfile(json_surface_file.c_str());
175 std::map<uint64_t,float> surface_weight;
178 TFile *tfile =
new TFile(input_file.c_str());
179 TTree *
tree = (TTree*)tfile->Get(
"material-tracks");
183 std::vector<float> *mat_X0 = 0;
184 std::vector<float> *mat_L0 = 0;
185 std::vector<float> *mat_step_length = 0;
187 std::vector<uint64_t> *sur_id = 0;
188 std::vector<int32_t> *sur_type = 0;
189 std::vector<float> *sur_x = 0;
190 std::vector<float> *sur_y = 0;
191 std::vector<float> *sur_z = 0;
192 std::vector<float> *sur_range_min = 0;
193 std::vector<float> *sur_range_max = 0;
195 tree->SetBranchAddress(
"v_phi",&v_phi);
196 tree->SetBranchAddress(
"v_eta",&v_eta);
197 tree->SetBranchAddress(
"mat_X0",&mat_X0);
198 tree->SetBranchAddress(
"mat_L0",&mat_L0);
199 tree->SetBranchAddress(
"mat_step_length",&mat_step_length);
201 tree->SetBranchAddress(
"sur_id",&sur_id);
202 tree->SetBranchAddress(
"sur_type",&sur_type);
203 tree->SetBranchAddress(
"sur_x",&sur_x);
204 tree->SetBranchAddress(
"sur_y",&sur_y);
205 tree->SetBranchAddress(
"sur_z",&sur_z);
206 tree->SetBranchAddress(
"sur_range_min",&sur_range_min);
207 tree->SetBranchAddress(
"sur_range_max",&sur_range_max);
210 if(nentries > nbprocess && nbprocess != -1) nentries = nbprocess;
212 for (Long64_t i=0;i<
nentries; i++) {
213 if(i%10000==0) std::cout <<
"processed " << i <<
" events out of " << nentries << std::endl;
217 for (
auto weight_it = surface_weight.begin(); weight_it != surface_weight.end(); weight_it++){
218 weight_it->second = 0;
221 for(
int j=0; j<mat_X0->size(); j++ ){
224 if(sur_type->at(j) == -1)
continue;
226 if(surface_hist.find(sur_id->at(j))==surface_hist.end()){
229 if(sur_type->at(j) == 1){
230 pos = sqrt(sur_x->at(j)*sur_x->at(j)+sur_y->at(j)*sur_y->at(j));
232 if(sur_type->at(j) == 2){
236 surface_weight[sur_id->at(j)] = 0;
237 Initialise_info(surface_info[sur_id->at(j)], surface_name, sur_id->at(j), sur_type->at(j),
pos, sur_range_min->at(j), sur_range_max->at(j));
238 Initialise_hist(surface_hist[sur_id->at(j)], surface_info[sur_id->at(j)]);
241 surface_weight[sur_id->at(j)]++;
245 for(
int j=0; j<mat_X0->size(); j++ ){
248 if(sur_type->at(j) == -1)
continue;
250 if(sur_type->at(j) == 1){
251 surface_hist[sur_id->at(j)][0]->Fill(sur_z->at(j), (mat_step_length->at(j)/mat_X0->at(j)));
252 surface_hist[sur_id->at(j)][1]->Fill(v_phi, (mat_step_length->at(j)/mat_L0->at(j)));
253 surface_hist[sur_id->at(j)][2]->Fill(sur_z->at(j), (1/surface_weight[sur_id->at(j)]));
254 surface_hist[sur_id->at(j)][3]->Fill(v_phi, (1/surface_weight[sur_id->at(j)]));
256 if(sur_type->at(j) == 2){
257 surface_hist[sur_id->at(j)][0]->Fill(sqrt(sur_x->at(j)*sur_x->at(j)+sur_y->at(j)*sur_y->at(j)), (mat_step_length->at(j)/mat_X0->at(j)));
258 surface_hist[sur_id->at(j)][1]->Fill(v_phi, (mat_step_length->at(j)/mat_L0->at(j)));
259 surface_hist[sur_id->at(j)][2]->Fill(sqrt(sur_x->at(j)*sur_x->at(j)+sur_y->at(j)*sur_y->at(j)), (1/surface_weight[sur_id->at(j)]));
260 surface_hist[sur_id->at(j)][3]->Fill(v_phi, (1/surface_weight[sur_id->at(j)]));
265 for (
auto hist_it = surface_hist.begin(); hist_it != surface_hist.end(); hist_it++){
266 hist_it->second[0]->Divide(hist_it->second[2]);
267 hist_it->second[1]->Divide(hist_it->second[3]);
280 gStyle->SetOptStat(0);
281 gStyle->SetOptTitle(0);
283 std::map<uint64_t,std::vector<TH1F*>> surface_hist;
284 std::map<uint64_t,sinfo> surface_info;
286 Fill(surface_hist, surface_info, input_file, json_surface_file, nbprocess);
287 for (
auto hist_it = surface_hist.begin(); hist_it != surface_hist.end(); hist_it++){
288 plot(hist_it->second, surface_info[hist_it->first],
name);
289 for (
auto hist : hist_it->second){
292 hist_it->second.clear();