1 |
pam-fi |
1.1 |
|
2 |
|
|
/** |
3 |
|
|
* \file TrkCalib.cpp |
4 |
|
|
* \author Elena Vannuccini |
5 |
|
|
*/ |
6 |
|
|
#include <TrkCalib.h> |
7 |
|
|
using namespace pamela; |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
TrkCalib::TrkCalib(){ |
11 |
|
|
|
12 |
|
|
calib1 = new CalibTrk1Event(); |
13 |
|
|
|
14 |
|
|
}; |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
TrkCalib::~TrkCalib(){ |
18 |
|
|
|
19 |
|
|
calib1->Delete(); |
20 |
|
|
|
21 |
|
|
}; |
22 |
|
|
|
23 |
|
|
/** |
24 |
|
|
* Method to get the view number of the ipkt-th stored DSP-packet. |
25 |
|
|
* The view number is extracted from the DSP-header. |
26 |
|
|
*/ |
27 |
|
|
Int_t TrkCalib::GetView(Int_t ipkt){ |
28 |
|
|
|
29 |
|
|
if( ipkt <0 || ipkt >=6 )return 0; |
30 |
|
|
return calib1->DSPnumber[ipkt]; |
31 |
|
|
|
32 |
|
|
}; |
33 |
|
|
|
34 |
|
|
Int_t TrkCalib::EvaluatePar(TString what, Int_t ipkt, Int_t ivk, Float_t* result){ |
35 |
|
|
|
36 |
|
|
// vector to store mean, RMS, n.points |
37 |
|
|
// Float_t* result = new Float_t[3]; |
38 |
|
|
*(result) = -1.; |
39 |
|
|
*(result+1) = 0.; |
40 |
|
|
*(result+2) = 0.; |
41 |
|
|
|
42 |
|
|
// evaluate strip range |
43 |
|
|
Int_t from = (ivk-1)*128 ; |
44 |
|
|
Int_t to= ivk*128; |
45 |
|
|
if( ivk > 0 && ivk <= 24){ |
46 |
|
|
from = (ivk-1)*128 ; |
47 |
|
|
to = ivk*128; |
48 |
|
|
}else if( ivk==0 ){ |
49 |
|
|
from = 0; |
50 |
|
|
to = 3072; |
51 |
|
|
}else if( ivk < 0 && ivk >= -3 ){ |
52 |
|
|
from = (-ivk-1)*1024; |
53 |
|
|
to = -ivk*1024; |
54 |
|
|
}else{ |
55 |
|
|
return 0; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
float mean =0; |
60 |
|
|
float rms =0; |
61 |
|
|
int nstrip =0; |
62 |
|
|
float *pt; |
63 |
|
|
|
64 |
|
|
if( what.Contains("PED") ){ |
65 |
|
|
pt = (float*)(calib1->DSPped_par); |
66 |
|
|
}else if( what.Contains("SIG") ){ |
67 |
|
|
pt = (float*)(calib1->DSPsig_par); |
68 |
|
|
}else{ |
69 |
|
|
cout << "TrkCalib::EvaluatePar() --> "<<what<<" not implemented\n"; |
70 |
|
|
return 0; |
71 |
|
|
}; |
72 |
|
|
|
73 |
|
|
int *ptbad; |
74 |
|
|
ptbad = (int*)(calib1->DSPbad_par); |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
for(Int_t is=from; is<to; is++){ |
78 |
|
|
int bad = 1; |
79 |
|
|
if( what.Contains("-BAD") && ptbad[ipkt*3072+is] == 1 )bad = 0; |
80 |
|
|
mean += pt[ipkt*3072+is] * bad; |
81 |
|
|
rms += pt[ipkt*3072+is] * pt[ipkt*3072+is] * bad ; |
82 |
|
|
nstrip += bad; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
*(result) = (Float_t)nstrip; |
86 |
|
|
|
87 |
|
|
if(!nstrip) return 1; |
88 |
|
|
|
89 |
|
|
mean = mean/nstrip; |
90 |
|
|
rms = rms/nstrip - mean * mean ; |
91 |
|
|
if (rms < 0) return 0; |
92 |
|
|
|
93 |
|
|
*(result+1) = mean; |
94 |
|
|
*(result+2) = sqrt(rms); |
95 |
|
|
|
96 |
|
|
return 1; |
97 |
|
|
|
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
/** |
101 |
|
|
* Method to evaluate mean value of calibration parameters, over a VA1 chip, a ladder or the whole view. |
102 |
|
|
* @param what Quantity to evaluate ("PED", "SIG" or "BAD") |
103 |
|
|
* @param ipkt Stored DSP-packet |
104 |
|
|
* @param ivk If ivk=1,24 the average is evaluated for the ivk-th VA1 chip. If ivk=-ladder, where |
105 |
|
|
* ladder=1-2, the average is evaluated over the ladder. If ivk=0 the average is evaluated over the whole view. |
106 |
|
|
*/ |
107 |
|
|
Float_t TrkCalib::GetMean(TString what, Int_t ipkt, Int_t ivk){ |
108 |
|
|
|
109 |
|
|
Float_t* result = new Float_t[3]; |
110 |
|
|
if( !EvaluatePar(what,ipkt,ivk, result) ) return 0.; |
111 |
|
|
Float_t mean = result[1]; |
112 |
|
|
delete [] result; |
113 |
|
|
return mean; |
114 |
|
|
}; |
115 |
|
|
/** |
116 |
|
|
* Method to evaluate RMS of calibration parameters, over a VA1 chip, a ladder or the whole view. |
117 |
|
|
* Input parameters follow the same notation of TrkCalib::GetMean(TString what, Int_t ipkt, Int_t ivk). |
118 |
|
|
*/ |
119 |
|
|
Float_t TrkCalib::GetRMS(TString what, Int_t ipkt, Int_t ivk){ |
120 |
|
|
|
121 |
|
|
Float_t* result = new Float_t[3]; |
122 |
|
|
if( !EvaluatePar(what,ipkt,ivk, result) ) return 0.; |
123 |
|
|
Float_t rms = result[2]; |
124 |
|
|
delete [] result; |
125 |
|
|
return rms; |
126 |
|
|
|
127 |
|
|
}; |
128 |
|
|
|
129 |
|
|
/** |
130 |
|
|
* Method to evaluate RMS of calibration parameters, over a VA1 chip, a ladder or the whole view. |
131 |
|
|
* Input parameters follow the same notation of TrkCalib::GetMean(TString what, Int_t ipkt, Int_t ivk). |
132 |
|
|
*/ |
133 |
|
|
Float_t TrkCalib::GetNGOOD(Int_t ipkt, Int_t ivk){ |
134 |
|
|
|
135 |
|
|
Float_t* result = new Float_t[3]; |
136 |
|
|
if( !EvaluatePar("SIG-BAD",ipkt,ivk, result) ) return 0.; |
137 |
|
|
Float_t ngood = result[0]; |
138 |
|
|
delete [] result; |
139 |
|
|
return ngood; |
140 |
|
|
|
141 |
|
|
}; |
142 |
|
|
Float_t TrkCalib::GetNBAD(Int_t ipkt, Int_t ivk){ |
143 |
|
|
|
144 |
|
|
Float_t* result = new Float_t[3]; |
145 |
|
|
|
146 |
|
|
if( !EvaluatePar("SIG",ipkt,ivk, result) ) return 0.; |
147 |
|
|
Float_t nbad = result[0]; |
148 |
|
|
if( !EvaluatePar("SIG-BAD",ipkt,ivk, result) ) return 0.; |
149 |
|
|
nbad = nbad - result[0]; |
150 |
|
|
delete [] result; |
151 |
|
|
return nbad; |
152 |
|
|
|
153 |
|
|
}; |
154 |
|
|
/** |
155 |
|
|
* Method to get an array with the calibration-parameters, for a VA1 chip, a ladder or a view. |
156 |
|
|
*/ |
157 |
|
|
Float_t* TrkCalib::Get(TString what, Int_t ipkt, Int_t ivk){ |
158 |
|
|
|
159 |
|
|
Int_t from = (ivk-1)*128 ; |
160 |
mocchiut |
1.4 |
// Int_t to= ivk*128; // EM GCC 4.7 unused |
161 |
pam-fi |
1.1 |
if( ivk > 0 && ivk <= 24){ |
162 |
|
|
from = (ivk-1)*128 ; |
163 |
mocchiut |
1.4 |
// to = ivk*128; |
164 |
pam-fi |
1.1 |
}else if( ivk==0 ){ |
165 |
|
|
from = 0; |
166 |
mocchiut |
1.4 |
// to = 3072; |
167 |
pam-fi |
1.1 |
}else if( ivk < 0 && ivk >= -3 ){ |
168 |
|
|
from = (-ivk-1)*1024; |
169 |
mocchiut |
1.4 |
// to = -ivk*1024; |
170 |
pam-fi |
1.1 |
}else{ |
171 |
|
|
return NULL; |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
|
175 |
|
|
float *pt; |
176 |
|
|
|
177 |
|
|
if( !what.CompareTo("PED") ){ |
178 |
|
|
pt = (float*)(calib1->DSPped_par); |
179 |
|
|
}else if( !what.CompareTo("SIG") ){ |
180 |
|
|
pt = (float*)(calib1->DSPsig_par); |
181 |
|
|
}else{ |
182 |
|
|
cout << "TrkCalib::Get(TString what, Int_t ipkt) --> "<<what<<" not implemented\n"; |
183 |
|
|
return NULL; |
184 |
|
|
}; |
185 |
|
|
|
186 |
|
|
return &pt[ipkt*3072+from]; |
187 |
|
|
}; |
188 |
|
|
|
189 |
|
|
void TrkCalib::HeaderDump(Int_t ipkt){ |
190 |
|
|
cout << "------------------------"<<endl; |
191 |
|
|
cout << " DSP "<<calib1->DSPnumber[ipkt]<<endl; |
192 |
|
|
cout << "------------------------"<<endl; |
193 |
|
|
cout << "DAQ mode "<<calib1->DAQmode[ipkt]<<endl; |
194 |
|
|
cout << "<PED> "<<calib1->ped_l1[ipkt]<<" "<<calib1->ped_l2[ipkt]<<" "<<calib1->ped_l3[ipkt]<<" "<<endl; |
195 |
|
|
cout << "<SIG> "<<calib1->sig_l1[ipkt]<<" "<<calib1->sig_l2[ipkt]<<" "<<calib1->sig_l3[ipkt]<<" "<<endl; |
196 |
|
|
cout << "n.BAD "<<calib1->nbad_l1[ipkt]<<" "<<calib1->nbad_l2[ipkt]<<" "<<calib1->nbad_l3[ipkt]<<" "<<endl; |
197 |
|
|
cout << "n.events "<<calib1->ncalib_event[ipkt]<<endl; |
198 |
|
|
cout << "flag "<<calib1->cal_flag[ipkt]<<endl; |
199 |
|
|
|
200 |
|
|
} |
201 |
|
|
/** |
202 |
|
|
* Method to get the histogram of calibration-parameters, for a VA1 chip, a ladder or a view. |
203 |
|
|
*/ |
204 |
pam-fi |
1.3 |
TH1F* TrkCalib::GetHisto(TString what, Int_t ipkt, Int_t ivk, Int_t rebin){ |
205 |
pam-fi |
1.1 |
|
206 |
|
|
Int_t from = (ivk-1)*128 ; |
207 |
|
|
Int_t to= ivk*128; |
208 |
|
|
if( ivk > 0 && ivk <= 24){ |
209 |
|
|
from = (ivk-1)*128 ; |
210 |
|
|
to = ivk*128; |
211 |
|
|
}else if( ivk==0 ){ |
212 |
|
|
from = 0; |
213 |
|
|
to = 3072; |
214 |
|
|
}else if( ivk < 0 && ivk >= -3 ){ |
215 |
|
|
from = (-ivk-1)*1024; |
216 |
|
|
to = -ivk*1024; |
217 |
|
|
}else{ |
218 |
|
|
return NULL; |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
TString title =""; |
222 |
|
|
title.Form(" view %i ",GetView(ipkt)); |
223 |
|
|
title = what + title; |
224 |
|
|
TH1F* h = new TH1F("h",title.Data(),to-from,from,to); |
225 |
|
|
Float_t* v = Get(what,ipkt,ivk); |
226 |
|
|
HeaderDump(ipkt); |
227 |
|
|
for(Int_t i=from; i<to; i++)h->Fill(i,v[i-from]); |
228 |
pam-fi |
1.3 |
if(rebin !=0 )h->Rebin(rebin); |
229 |
|
|
if(rebin !=0 )h->Scale(1./(float)rebin); |
230 |
pam-fi |
1.1 |
return h; |
231 |
|
|
|
232 |
|
|
} |
233 |
|
|
|
234 |
pam-fi |
1.2 |
|
235 |
|
|
|
236 |
pam-fi |
1.1 |
ClassImp(TrkCalib); |