source: trunk/MagicSoft/Mars/mtemp/mmpi/macros/calculate_of_weights.C@ 9437

Last change on this file since 9437 was 5577, checked in by hbartko, 20 years ago
*** empty log message ***
File size: 4.4 KB
Line 
1const int no_samples=6;
2
3
4void calculate_of_weights(TH1F *shape, TString noise_file = "/mnt/home/pcmagic17/hbartko/mars/results/04sep12/noise_autocorr_AB_36038.root", Int_t t_offset = -10)
5{
6
7
8 TH1F * derivative = new TH1F("derivative","derivative",161,-1.05,15.05);
9
10
11 for (int i = 1; i<162;i++){
12 derivative->SetBinContent(i,((shape->GetBinContent(i+1)-shape->GetBinContent(i-1))/0.2));
13 derivative->SetBinError(i,(sqrt(shape->GetBinError(i+1)*shape->GetBinError(i+1)+shape->GetBinError(i-1)*shape->GetBinError(i-1))/0.2));
14 }
15
16 // normalize the shape, such that the integral for 6 slices is one!
17
18 float sum = 0;
19 for (int i=40; i<101; i++){sum+=shape->GetBinContent(i);}
20 sum /= 10;
21
22 shape->Scale(1./sum);
23 derivative->Scale(1./sum);
24
25
26 TCanvas * c1 = new TCanvas("c1","c1",600,400);
27 //c1= canvas();
28 shape->Draw();
29
30 TCanvas *c2 = new TCanvas("c2","c2",600,400);
31 //c2=canvas();
32 derivative->Draw();
33
34
35 // book the histograms for the weights
36
37 TH1F * hw_amp = new TH1F("hw_amp","hw_amp",no_samples*10,-0.5,no_samples-0.5);
38 TH1F * hw_time = new TH1F("hw_time","hw_time",no_samples*10,-0.5,no_samples-0.5);
39 TH1F * hshape = new TH1F("hshape","hshape",no_samples*10,-0.5,no_samples-0.5);
40 TH1F * hderivative = new TH1F("hderivative","hderivative",no_samples*10,-0.5,no_samples-0.5);
41
42
43 // read in the noise auto-correlation function:
44
45 TMatrix B(no_samples,no_samples);
46
47 f = new TFile(noise_file);
48 TH2F * noise_corr = (TH2F*)c_corr->FindObject("hcorr");
49 for (int i=0; i<no_samples; i++){
50 for (int j=0; j<no_samples; j++){
51 B[i][j]=noise_corr->GetBinContent(i+1,j+1);
52 }
53 }
54 f->Close();
55
56 B.Invert();
57
58 // now the loop over t_{rel} in [-0.4;0.6[ :
59
60 for (int i=-4; i<6; i++){
61
62
63 TMatrix g(no_samples,1);
64 TMatrix gT(1,no_samples);
65 TMatrix d(no_samples,1);
66 TMatrix dT(1,no_samples);
67
68
69 for (int count=0; count < no_samples; count++){
70
71 g[count][0]=shape->GetBinContent(55+t_offset-int((10*no_samples-50)/2.)+10*count+i);
72 gT[0][count]=shape->GetBinContent(55+t_offset-int((10*no_samples-50)/2.)+10*count+i);
73 d[count][0]=derivative->GetBinContent(55+t_offset-int((10*no_samples-50)/2.)+10*count+i);
74 dT[0][count]=derivative->GetBinContent(55+t_offset-int((10*no_samples-50)/2.)+10*count+i);
75
76 hshape->SetBinContent(i+5+10*count,shape->GetBinContent(55+t_offset-int((10*no_samples-50)/2.)+10*count+i));
77 hderivative->SetBinContent(i+5+10*count,derivative->GetBinContent(55+t_offset-int((10*no_samples-50)/2.)+10*count+i));
78 }
79
80
81 TMatrix m_denom = (gT*(B*g))*(dT*(B*d)) - (dT*(B*g))*(dT*(B*g));
82 float denom = m_denom[0][0]; // m_denom is a real number
83
84 TMatrix m_first = dT*(B*d); // m_first is a real number
85 float first = m_first[0][0]/denom;
86
87 TMatrix m_last = gT*(B*d); // m_last is a real number
88 float last = m_last[0][0]/denom;
89
90 TMatrix m1 = gT*B;
91
92 m1 *=first;
93
94 TMatrix m2 = dT*B;
95
96 m2 *=last;
97
98 TMatrix w_amp= m1 - m2;
99
100
101 TMatrix m_first1 = gT*(B*g);
102 float first1 = m_first1[0][0]/denom;
103
104 TMatrix m_last1 = gT*(B*d);
105 float last1 = m_last1[0][0]/denom;
106
107 TMatrix m11 = dT*B;
108
109 m11 *=first1;
110
111 TMatrix m21 = gT*B;
112
113 m21 *=last1;
114
115
116 TMatrix w_time= m11 - m21;
117
118
119 float amp = 0;
120 float amp_time = 0;
121
122 for (int count=0; count < no_samples; count++){
123 hw_amp->SetBinContent(i+5+10*count,w_amp[0][count]);
124 hw_time->SetBinContent(i+5+10*count,w_time[0][count]);
125 }
126
127
128
129 TMatrix m_delta_E = dT*(B*d); // m_last is a real number
130 float delta_E = m_delta_E[0][0]/denom;
131
132
133 TMatrix m_delta_Et = gT*(B*g); // m_last is a real number
134 float delta_Et = m_delta_Et[0][0]/denom;
135
136 cout << " i " << i << " delta E " << sqrt(delta_E) << " delta Et " << sqrt(delta_Et) << endl;
137
138
139 } // end loop over t_rel
140
141
142 TCanvas * c3 = new TCanvas("c3","c3",600,400);
143 hw_amp->Draw();
144
145 TCanvas * c4 = new TCanvas("c4","c4",600,400);
146 hw_time->Draw();
147
148 TCanvas * c5 = new TCanvas("c5","c5",600,400);
149 hshape->Draw();
150
151 TCanvas * c6 = new TCanvas("c6","c6",600,400);
152 hderivative->Draw();
153
154 /*
155 f_out = new TFile("/home/pcmagic17/hbartko/mars/results/04sep15/calibration_weights_corr_iterated.root","RECREATE"); //"../of_weights_bin4.root"
156 hw_amp->Write();
157 hw_time->Write();
158 hshape->Write();
159 hderivative->Write();
160 shape->Write();
161 derivative->Write();
162 f_out->Close();
163 */
164}
Note: See TracBrowser for help on using the repository browser.