18 std::vector< std::vector<float> >& in_data,
19 TVectorD& out_weights,
24 int n_zdc = in_data.size();
27 std::cout <<
"Calculate weights for " << n_zdc <<
" modules!" << std::endl;
31 size_t nevt = in_data.at(0).size();
32 for (
size_t i = 0;
i<nevt;
i++)
34 for (
size_t ir=0;ir<n_zdc;ir++)
36 mom1(ir) += in_data.at(ir).at(
i)/
double(nevt);
37 for (
size_t ic=0;ic<n_zdc;ic++)
39 out_matrix(ir,ic) += 2*in_data.at(ir).at(
i)*in_data.at(ic).at(
i)/
double(nevt);
45 for (
size_t ir=0;ir<n_zdc;ir++)
47 out_matrix(ir,n_zdc)=mom1(ir);
48 out_matrix(n_zdc,ir)=mom1(ir);
51 TVectorD solution(dim);
54 TDecompLU lu(out_matrix);
56 bool status = lu.Solve(solution);
60 std::cout <<
"Fail!" << endl;
64 std::cout <<
"Success!" << endl;
69 out_weights = solution;
83 s_zdc += TString::Itoa(skip_zdc_mod[iz],10);
86 TFile
fout(
"output"+
filename+
"_"+s_zdc+
"_fout.root",
"RECREATE");
87 TH1F h_e_uncorr(
"h_e_uncorr",
"Uncorr. energy;E_{uncorr}",3000,0,6000);
88 TH2F h_e_uncorr2D(
"h_e_uncorr2D",
"Uncorr. energy;E_{ZDC} [GeV]};E_{EM} [GeV];",100,0,300,100,0,300);
89 TH1F h_e_corr(
"h_e_corr",
"corr. energy;E_{corr}",3000,0,6000);
90 TH2F h_e_corr2D(
"h_e_corr2D",
"corr. energy;E_{ZDC} [GeV];E_{EM} [GeV]",100,0,600,100,0,600);
92 int n_zdc = std::accumulate(skip_zdc_mod.begin(),skip_zdc_mod.end(),0);
93 std::cout <<
"Working with " << n_zdc <<
" modules!" << std::endl;
95 TMatrixD* zdcMatrix =
new TMatrixD(n_zdc+1,n_zdc+1);
96 TVectorD* zdcWeights =
new TVectorD(n_zdc+1);
99 std::vector< std::vector<float> >
data;
101 std::vector< std::vector<float> > all_data;
102 all_data.resize(n_zdc);
108 std::vector<float>
z(Nmodules);
117 ifs >> z[0] >> z[1] >> z[2];
121 bool fail_event =
false;
127 if (!skip_zdc_mod[iz] && z[iz]>10) fail_event =
true;
129 sum += z[iz]*skip_zdc_mod[iz];
130 if (iz>0) sum_had += z[iz]*skip_zdc_mod[iz];
132 if (fail_event)
continue;
139 if (skip_zdc_mod[iz])
141 data.at(ind).push_back(z[iz]);
150 if (skip_zdc_mod[iz])
152 all_data.at(ind).push_back(z[iz]);
157 h_e_uncorr.Fill(sum);
158 h_e_uncorr2D.Fill(sum_had,sum-sum_had);
163 int Nevt = all_data.at(0).size();
164 std::cout << Nevt <<
" events used!" << std::endl;
165 for (
int i = 0;
i<Nevt;
i++)
169 float e_corr_had = 0;
173 if (skip_zdc_mod[iz])
175 e_corr += all_data.at(ind).at(
i) * (*zdcWeights)(ind);
176 if (iz>0) e_corr_had += all_data.at(ind).at(
i) * (*zdcWeights)(ind);
181 h_e_corr.Fill(e_corr);
182 h_e_corr2D.Fill(e_corr_had,e_corr-e_corr_had);
187 zdcWeights->Write(
"zdcTBWeights");