1 |
mocchiut |
1.1 |
/** |
2 |
|
|
* \file src/CaloLevel0.cpp |
3 |
|
|
* \author Emiliano Mocchiutti |
4 |
|
|
**/ |
5 |
|
|
// |
6 |
|
|
// C/C++ headers |
7 |
|
|
// |
8 |
|
|
#include <sstream> |
9 |
|
|
#include <fstream> |
10 |
|
|
// |
11 |
|
|
// ROOT headers |
12 |
|
|
// |
13 |
|
|
#include <TTree.h> |
14 |
|
|
#include <TBranch.h> |
15 |
|
|
#include <TFile.h> |
16 |
|
|
#include <TObject.h> |
17 |
|
|
// |
18 |
|
|
// YODA headers |
19 |
|
|
// |
20 |
|
|
#include <PamelaRun.h> |
21 |
|
|
#include <physics/calorimeter/CalorimeterEvent.h> |
22 |
|
|
#include <CalibCalPedEvent.h> |
23 |
|
|
// |
24 |
|
|
// |
25 |
|
|
// |
26 |
|
|
#include <GLTables.h> |
27 |
|
|
// |
28 |
|
|
// this package headers |
29 |
|
|
// |
30 |
|
|
#include <delay.h> |
31 |
|
|
#include <CaloLevel0.h> |
32 |
|
|
// |
33 |
|
|
// |
34 |
|
|
// Declaration of the core fortran routines |
35 |
|
|
// |
36 |
|
|
#define calol2cm calol2cm_ |
37 |
|
|
extern "C" int calol2cm(); |
38 |
|
|
#define calol2tr calol2tr_ |
39 |
|
|
extern "C" int calol2tr(); |
40 |
|
|
// |
41 |
|
|
using namespace std; |
42 |
|
|
// |
43 |
|
|
// |
44 |
|
|
// Public methods |
45 |
|
|
// |
46 |
|
|
|
47 |
|
|
CaloLevel0::~CaloLevel0(){ |
48 |
|
|
if ( de ) delete de; |
49 |
|
|
delete this; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
CaloLevel0::CaloLevel0(){ |
53 |
|
|
// |
54 |
|
|
extern struct FlCaLevel1 clevel1_; |
55 |
|
|
extern struct FlCaLevel2 clevel2_; |
56 |
|
|
clevel1 = &clevel1_; |
57 |
|
|
clevel2 = &clevel2_; |
58 |
|
|
// |
59 |
|
|
trkseqno = 0; |
60 |
|
|
ClearStructs(); |
61 |
|
|
// |
62 |
|
|
memset(dexy, 0, 2*22*96*sizeof(Float_t)); |
63 |
|
|
memset(dexyc, 0, 2*22*96*sizeof(Float_t)); |
64 |
|
|
memset(mip, 0, 2*22*96*sizeof(Float_t)); |
65 |
|
|
memset(base, 0, 2*22*6*sizeof(Float_t)); |
66 |
|
|
memset(sbase, 0, 2*22*6*sizeof(Float_t)); |
67 |
mocchiut |
1.9 |
memset(obadmask, 0, 2*22*96*sizeof(Int_t)); |
68 |
|
|
memset(obadpulsemask, 0, 2*22*6*sizeof(Int_t)); |
69 |
|
|
memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); |
70 |
|
|
memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); |
71 |
mocchiut |
1.1 |
calopar1 = true; |
72 |
|
|
calopar2 = true; |
73 |
|
|
calopar3 = true; |
74 |
|
|
crosst = true; |
75 |
|
|
ftcalopar1 = 0; |
76 |
|
|
ttcalopar1 = 0; |
77 |
|
|
ftcalopar2 = 0; |
78 |
|
|
ttcalopar2 = 0; |
79 |
|
|
ftcalopar3 = 0; |
80 |
|
|
ttcalopar3 = 0; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
void CaloLevel0::SetCrossTalk(Bool_t ct){ |
84 |
|
|
crosst = ct; |
85 |
mocchiut |
1.12 |
} |
86 |
mocchiut |
1.1 |
|
87 |
mocchiut |
1.9 |
void CaloLevel0::SetCrossTalkType(Bool_t ct){ |
88 |
|
|
ctground = ct; |
89 |
mocchiut |
1.12 |
} |
90 |
mocchiut |
1.9 |
|
91 |
mocchiut |
1.1 |
void CaloLevel0::SetVerbose(Bool_t ct){ |
92 |
|
|
verbose = ct; |
93 |
mocchiut |
1.12 |
} |
94 |
mocchiut |
1.1 |
|
95 |
|
|
/** |
96 |
|
|
* Initialize CaloLevel0 object |
97 |
|
|
**/ |
98 |
mocchiut |
1.7 |
void CaloLevel0::ProcessingInit(GL_TABLES *glt, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){ |
99 |
|
|
// |
100 |
|
|
const TString host = glt->CGetHost(); |
101 |
|
|
const TString user = glt->CGetUser(); |
102 |
|
|
const TString psw = glt->CGetPsw(); |
103 |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
104 |
|
|
if ( !dbc->IsConnected() ) throw -116; |
105 |
mocchiut |
1.8 |
stringstream myquery; |
106 |
|
|
myquery.str(""); |
107 |
|
|
myquery << "SET time_zone='+0:00'"; |
108 |
|
|
dbc->Query(myquery.str().c_str()); |
109 |
mocchiut |
1.1 |
// |
110 |
|
|
debug = isdeb; |
111 |
|
|
verbose = isverb; |
112 |
|
|
// |
113 |
|
|
l0tr=(TTree*)l0tree; |
114 |
|
|
de = new pamela::calorimeter::CalorimeterEvent(); |
115 |
|
|
l0calo = (TBranch*)l0tr->GetBranch("Calorimeter"); |
116 |
|
|
l0tr->SetBranchAddress("Calorimeter", &de); |
117 |
|
|
// |
118 |
|
|
trkseqno = 0; |
119 |
|
|
ClearStructs(); |
120 |
|
|
// |
121 |
|
|
GL_CALO_CALIB *glcalo = new GL_CALO_CALIB(); |
122 |
|
|
// |
123 |
|
|
sgnl = 0; |
124 |
|
|
UInt_t uptime = 0; |
125 |
|
|
// |
126 |
|
|
for (Int_t s = 0; s < 4; s++){ |
127 |
|
|
idcalib[s] = 0; |
128 |
|
|
fromtime[s] = 0; |
129 |
|
|
totime[s] = 0; |
130 |
|
|
calibno[s] = 0; |
131 |
|
|
ClearCalibVals(s); |
132 |
|
|
// |
133 |
|
|
sgnl = glcalo->Query_GL_CALO_CALIB(hs,uptime,s,dbc); |
134 |
|
|
if ( sgnl < 0 ){ |
135 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
136 |
|
|
return; |
137 |
|
|
}; |
138 |
|
|
// |
139 |
|
|
idcalib[s] = glcalo->ID_ROOT_L0; |
140 |
|
|
fromtime[s] = glcalo->FROM_TIME; |
141 |
|
|
if ( glcalo->TO_TIME < hs ){ // calibration is corrupted and we are using the one that preceed the good one |
142 |
|
|
totime[s] = uptime; |
143 |
|
|
} else { |
144 |
|
|
totime[s] = glcalo->TO_TIME; |
145 |
|
|
}; |
146 |
|
|
calibno[s] = glcalo->EV_ROOT; |
147 |
|
|
// |
148 |
|
|
if ( totime[s] == 0 ){ |
149 |
|
|
if ( verbose ) printf(" CALORIMETER - WARNING: data with no associated calibration\n"); |
150 |
|
|
ClearCalibVals(s); |
151 |
|
|
sgnl = 100; |
152 |
|
|
}; |
153 |
|
|
}; |
154 |
|
|
// |
155 |
|
|
// determine path and name and entry of the calibration file |
156 |
|
|
// |
157 |
|
|
GL_ROOT *glroot = new GL_ROOT(); |
158 |
|
|
if ( verbose ) printf("\n"); |
159 |
|
|
for (Int_t s = 0; s < 4; s++){ |
160 |
|
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
161 |
|
|
if ( totime[s] > 0 ){ |
162 |
|
|
// |
163 |
|
|
sgnl = glroot->Query_GL_ROOT(idcalib[s],dbc); |
164 |
|
|
if ( sgnl < 0 ){ |
165 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
166 |
|
|
return; |
167 |
|
|
}; |
168 |
|
|
// |
169 |
|
|
stringstream name; |
170 |
|
|
name.str(""); |
171 |
|
|
name << glroot->PATH.Data() << "/"; |
172 |
|
|
name << glroot->NAME.Data(); |
173 |
|
|
// |
174 |
|
|
fcalname[s] = (TString)name.str().c_str(); |
175 |
|
|
if ( verbose ) printf(" - runheader at time %u. From time %u to time %u \n use file %s \n calibration at entry %i \n\n",hs,fromtime[s],totime[s],fcalname[s].Data(),calibno[s]); |
176 |
|
|
} else { |
177 |
|
|
if ( verbose ) printf(" - runheader at time %u. NO CALIBRATION INCLUDE THE RUNHEADER! ",hs); |
178 |
|
|
}; |
179 |
|
|
sgnl = LoadCalib(s); |
180 |
|
|
if ( sgnl ) break; |
181 |
|
|
}; |
182 |
|
|
// |
183 |
|
|
delete glcalo; |
184 |
|
|
delete glroot; |
185 |
mocchiut |
1.7 |
dbc->Close(); |
186 |
|
|
delete dbc; |
187 |
mocchiut |
1.1 |
// |
188 |
|
|
return; |
189 |
|
|
// |
190 |
|
|
} |
191 |
|
|
|
192 |
mocchiut |
1.7 |
Int_t CaloLevel0::ChkCalib(GL_TABLES *glt, UInt_t atime){ |
193 |
mocchiut |
1.1 |
Int_t sgnl = 0; |
194 |
|
|
for ( Int_t s = 0; s < 4; s++){ |
195 |
|
|
if ( atime > totime[s] ){ |
196 |
mocchiut |
1.7 |
sgnl = Update(glt,atime,s); |
197 |
mocchiut |
1.1 |
if ( sgnl < 0 ) return(sgnl); |
198 |
|
|
}; |
199 |
|
|
}; |
200 |
|
|
return(sgnl); |
201 |
|
|
} |
202 |
|
|
|
203 |
mocchiut |
1.7 |
Int_t CaloLevel0::ChkParam(GL_TABLES *glt, UInt_t runheader, Bool_t mechal){ |
204 |
|
|
const TString host = glt->CGetHost(); |
205 |
|
|
const TString user = glt->CGetUser(); |
206 |
|
|
const TString psw = glt->CGetPsw(); |
207 |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
208 |
|
|
if ( !dbc->IsConnected() ) throw -116; |
209 |
mocchiut |
1.8 |
stringstream myquery; |
210 |
|
|
myquery.str(""); |
211 |
|
|
myquery << "SET time_zone='+0:00'"; |
212 |
|
|
dbc->Query(myquery.str().c_str()); |
213 |
mocchiut |
1.7 |
// |
214 |
mocchiut |
1.1 |
stringstream calfile; |
215 |
|
|
stringstream bmfile; |
216 |
|
|
stringstream aligfile; |
217 |
|
|
Int_t error = 0; |
218 |
|
|
FILE *f = 0; |
219 |
|
|
ifstream badfile; |
220 |
|
|
GL_PARAM *glparam = new GL_PARAM(); |
221 |
|
|
// |
222 |
|
|
if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){ |
223 |
mocchiut |
1.2 |
// |
224 |
|
|
// |
225 |
|
|
// |
226 |
|
|
if ( debug ) printf(" calopar1 %i ftcalopar1 %u ttcalopar1 %u runheader %u \n",calopar1,ftcalopar1,ttcalopar1,runheader); |
227 |
|
|
// |
228 |
mocchiut |
1.1 |
calopar1 = false; |
229 |
|
|
// |
230 |
|
|
// determine where I can find calorimeter ADC to MIP conversion file |
231 |
|
|
// |
232 |
|
|
if ( verbose ) printf(" Querying DB for calorimeter parameters files...\n"); |
233 |
|
|
// |
234 |
|
|
error = 0; |
235 |
|
|
error = glparam->Query_GL_PARAM(runheader,101,dbc); |
236 |
|
|
if ( error < 0 ) return(error); |
237 |
|
|
// |
238 |
|
|
calfile.str(""); |
239 |
|
|
calfile << glparam->PATH.Data() << "/"; |
240 |
|
|
calfile << glparam->NAME.Data(); |
241 |
|
|
ftcalopar1 = glparam->FROM_TIME; |
242 |
|
|
ttcalopar1 = glparam->TO_TIME; |
243 |
|
|
// |
244 |
|
|
if ( verbose ) printf("\n Using ADC to MIP conversion file: \n %s \n",calfile.str().c_str()); |
245 |
|
|
f = fopen(calfile.str().c_str(),"rb"); |
246 |
|
|
if ( !f ){ |
247 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no ADC to MIP file!\n"); |
248 |
|
|
return(-105); |
249 |
|
|
}; |
250 |
|
|
// |
251 |
|
|
for (Int_t m = 0; m < 2 ; m++ ){ |
252 |
|
|
for (Int_t k = 0; k < 22; k++ ){ |
253 |
|
|
for (Int_t l = 0; l < 96; l++ ){ |
254 |
|
|
fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f); |
255 |
mocchiut |
1.5 |
if ( debug ) printf(" %f \n",mip[m][k][l]); |
256 |
mocchiut |
1.1 |
}; |
257 |
|
|
}; |
258 |
|
|
}; |
259 |
|
|
fclose(f); |
260 |
|
|
}; |
261 |
|
|
// |
262 |
|
|
if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){ |
263 |
mocchiut |
1.2 |
if ( debug ) printf(" calopar2 %i ftcalopar2 %u ttcalopar2 %u runheader %u \n",calopar2,ftcalopar2,ttcalopar2,runheader); |
264 |
mocchiut |
1.1 |
calopar2 = false; |
265 |
|
|
// |
266 |
|
|
// determine where I can find calorimeter alignment file |
267 |
|
|
// |
268 |
|
|
// |
269 |
|
|
error = 0; |
270 |
|
|
error = glparam->Query_GL_PARAM(runheader,102,dbc); |
271 |
|
|
if ( error < 0 ) return(error); |
272 |
|
|
// |
273 |
|
|
aligfile.str(""); |
274 |
|
|
aligfile << glparam->PATH.Data() << "/"; |
275 |
|
|
aligfile << glparam->NAME.Data(); |
276 |
|
|
ftcalopar2 = glparam->FROM_TIME; |
277 |
|
|
ttcalopar2 = glparam->TO_TIME; |
278 |
|
|
// |
279 |
mocchiut |
1.2 |
if ( verbose ) printf("\n Using parameter file: \n %s \n",aligfile.str().c_str()); |
280 |
mocchiut |
1.1 |
f = fopen(aligfile.str().c_str(),"rb"); |
281 |
|
|
if ( !f ){ |
282 |
mocchiut |
1.2 |
if ( verbose ) printf(" CALORIMETER - ERROR: no parameter file!\n"); |
283 |
mocchiut |
1.1 |
return(-106); |
284 |
|
|
}; |
285 |
|
|
// |
286 |
mocchiut |
1.2 |
if ( !mechal ){ |
287 |
|
|
// |
288 |
|
|
fread(&clevel1->xalig,sizeof(clevel1->xalig),1,f); |
289 |
|
|
if ( debug ) printf(" xalig = %f \n",clevel1->xalig); |
290 |
|
|
fread(&clevel1->yalig,sizeof(clevel1->yalig),1,f); |
291 |
|
|
if ( debug ) printf(" yalig = %f \n",clevel1->yalig); |
292 |
|
|
fread(&clevel1->zalig,sizeof(clevel1->zalig),1,f); |
293 |
|
|
if ( debug ) printf(" zalig = %f \n",clevel1->zalig); |
294 |
|
|
} else { |
295 |
|
|
if ( verbose ) printf("\n Using MECHANICAL alignement parameters \n"); |
296 |
|
|
// |
297 |
|
|
CaloStrip cs = CaloStrip(); |
298 |
|
|
cs.UseMechanicalAlig(); |
299 |
|
|
clevel1->xalig = cs.GetXalig(); |
300 |
|
|
if ( debug ) printf(" xalig = %f \n",clevel1->xalig); |
301 |
|
|
clevel1->yalig = cs.GetYalig(); |
302 |
|
|
if ( debug ) printf(" yalig = %f \n",clevel1->yalig); |
303 |
|
|
clevel1->zalig = cs.GetZalig(); |
304 |
|
|
if ( debug ) printf(" zalig = %f \n",clevel1->zalig); |
305 |
|
|
// |
306 |
|
|
Float_t tmp = 0; |
307 |
|
|
fread(&tmp,sizeof(clevel1->xalig),1,f); |
308 |
|
|
fread(&tmp,sizeof(clevel1->yalig),1,f); |
309 |
|
|
fread(&tmp,sizeof(clevel1->zalig),1,f); |
310 |
mocchiut |
1.11 |
// clevel1->zalig = -265.82; |
311 |
mocchiut |
1.2 |
// |
312 |
|
|
}; |
313 |
mocchiut |
1.1 |
fread(&clevel1->emin,sizeof(clevel1->emin),1,f); |
314 |
|
|
if ( debug ) printf(" signal threshold = %f \n",clevel1->emin); |
315 |
|
|
// |
316 |
|
|
fclose(f); |
317 |
|
|
}; |
318 |
|
|
// |
319 |
|
|
// Load offline bad strip mask |
320 |
|
|
// |
321 |
|
|
if ( calopar3 || ( ttcalopar3 != 0 && ttcalopar3 < runheader ) ){ |
322 |
mocchiut |
1.2 |
if ( debug ) printf(" calopar3 %i ftcalopar3 %u ttcalopar3 %u runheader %u \n",calopar3,ftcalopar3,ttcalopar3,runheader); |
323 |
mocchiut |
1.1 |
calopar3 = false; |
324 |
|
|
// |
325 |
|
|
// determine where I can find calorimeter alignment file |
326 |
|
|
// |
327 |
|
|
// |
328 |
|
|
error = 0; |
329 |
|
|
error = glparam->Query_GL_PARAM(runheader,103,dbc); |
330 |
|
|
if ( error < 0 ) return(error); |
331 |
|
|
// |
332 |
|
|
bmfile.str(""); |
333 |
|
|
bmfile << glparam->PATH.Data() << "/"; |
334 |
|
|
bmfile << glparam->NAME.Data(); |
335 |
|
|
ftcalopar3 = glparam->FROM_TIME; |
336 |
|
|
ttcalopar3 = glparam->TO_TIME; |
337 |
|
|
// |
338 |
|
|
if ( verbose ) printf("\n Using bad strip offline mask file: \n %s \n\n",bmfile.str().c_str()); |
339 |
|
|
badfile.open(bmfile.str().c_str()); |
340 |
|
|
if ( !badfile ){ |
341 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no bad strip offline mask file!\n"); |
342 |
|
|
return(-115); |
343 |
|
|
}; |
344 |
|
|
// |
345 |
|
|
Bool_t isdone = false; |
346 |
|
|
Int_t bad = 0; |
347 |
|
|
Int_t view = 1; |
348 |
|
|
Int_t strip = 0; |
349 |
|
|
Int_t plane = 21; |
350 |
|
|
while ( !isdone ) { |
351 |
|
|
badfile >> bad; |
352 |
|
|
obadmask[view][plane][strip] = bad; |
353 |
|
|
if ( debug && bad ) printf(" SETTING view %i plane %i strip %i BAD = %i \n",view,plane,strip,bad); |
354 |
|
|
strip++; |
355 |
|
|
if ( strip > 95 ){ |
356 |
|
|
strip = 0; |
357 |
|
|
plane--; |
358 |
|
|
if ( plane < 0 ){ |
359 |
|
|
plane = 21; |
360 |
|
|
view--; |
361 |
|
|
}; |
362 |
|
|
if ( view < 0 ) isdone = true; |
363 |
|
|
}; |
364 |
|
|
}; |
365 |
|
|
// |
366 |
|
|
badfile.close(); |
367 |
|
|
}; |
368 |
|
|
// |
369 |
|
|
delete glparam; |
370 |
mocchiut |
1.7 |
dbc->Close(); |
371 |
|
|
delete dbc; |
372 |
mocchiut |
1.1 |
// |
373 |
|
|
return(0); |
374 |
|
|
} |
375 |
|
|
|
376 |
mocchiut |
1.9 |
Int_t CaloLevel0::CalcCrossTalkCorr(GL_TABLES *glt, UInt_t runheader){ |
377 |
|
|
// |
378 |
|
|
if ( ctground ) return(0); |
379 |
|
|
// |
380 |
|
|
const TString host = glt->CGetHost(); |
381 |
|
|
const TString user = glt->CGetUser(); |
382 |
|
|
const TString psw = glt->CGetPsw(); |
383 |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
384 |
|
|
if ( !dbc->IsConnected() ) throw -116; |
385 |
|
|
stringstream myquery; |
386 |
|
|
myquery.str(""); |
387 |
|
|
myquery << "SET time_zone='+0:00'"; |
388 |
|
|
dbc->Query(myquery.str().c_str()); |
389 |
|
|
// |
390 |
|
|
stringstream bmfile; |
391 |
|
|
Int_t error = 0; |
392 |
|
|
ifstream badfile; |
393 |
|
|
GL_PARAM *glparam = new GL_PARAM(); |
394 |
|
|
// |
395 |
|
|
// determine where I can find file with offline bad pulser mask |
396 |
|
|
// |
397 |
|
|
error = 0; |
398 |
|
|
error = glparam->Query_GL_PARAM(runheader,105,dbc); |
399 |
|
|
if ( error < 0 ) return(error); |
400 |
|
|
// |
401 |
|
|
bmfile.str(""); |
402 |
|
|
bmfile << glparam->PATH.Data() << "/"; |
403 |
|
|
bmfile << glparam->NAME.Data(); |
404 |
|
|
// |
405 |
|
|
if ( verbose ) printf("\n Using bad pulser offline mask file: \n %s \n\n",bmfile.str().c_str()); |
406 |
|
|
badfile.open(bmfile.str().c_str()); |
407 |
|
|
if ( !badfile ){ |
408 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: no bad pulser offline mask file!\n"); |
409 |
|
|
return(-115); |
410 |
|
|
}; |
411 |
|
|
// |
412 |
|
|
Bool_t isdone = false; |
413 |
|
|
Int_t bad = 0; |
414 |
|
|
Int_t view = 1; |
415 |
|
|
Int_t pre = 0; |
416 |
|
|
Int_t plane = 21; |
417 |
|
|
while ( !isdone ) { |
418 |
|
|
badfile >> bad; |
419 |
|
|
obadpulsemask[view][plane][pre] = bad; |
420 |
|
|
if ( debug && bad ) printf(" SETTING view %i plane %i pre %i BAD = %i \n",view,plane,pre,bad); |
421 |
|
|
pre++; |
422 |
|
|
if ( pre > 5 ){ |
423 |
|
|
pre = 0; |
424 |
|
|
plane--; |
425 |
|
|
if ( plane < 0 ){ |
426 |
|
|
plane = 21; |
427 |
|
|
view--; |
428 |
|
|
}; |
429 |
|
|
if ( view < 0 ) isdone = true; |
430 |
|
|
}; |
431 |
|
|
}; |
432 |
|
|
// |
433 |
|
|
delete glparam; |
434 |
|
|
badfile.close(); |
435 |
|
|
// |
436 |
|
|
// Let's start with cross-talk correction calculation |
437 |
|
|
// |
438 |
|
|
GL_CALOPULSE_CALIB *glp = new GL_CALOPULSE_CALIB(); |
439 |
|
|
Float_t adcp[2][22][96]; |
440 |
|
|
Float_t adcpcal[2][22][96]; |
441 |
|
|
memset(adcp , 0, 2*22*96*sizeof(Float_t)); |
442 |
|
|
memset(adcpcal , 0, 2*22*96*sizeof(Float_t)); |
443 |
|
|
// |
444 |
|
|
UInt_t pampli = 0; |
445 |
|
|
for (Int_t s=0; s<4; s++){ |
446 |
|
|
// |
447 |
|
|
// Save into matrix adcp the values of the highest pulse calibration (pulse amplitude = 2) |
448 |
|
|
// |
449 |
|
|
pampli = 2; |
450 |
|
|
error = 0; |
451 |
|
|
error = glp->Query_GL_CALOPULSE_CALIB(runheader,s,pampli,dbc); |
452 |
|
|
if ( error < 0 ){ |
453 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
454 |
|
|
return(error); |
455 |
|
|
}; |
456 |
|
|
// |
457 |
|
|
UInt_t idcalib = glp->ID_ROOT_L0; |
458 |
|
|
UInt_t fromtime = glp->FROM_TIME; |
459 |
|
|
UInt_t calibno = glp->EV_ROOT; |
460 |
|
|
// |
461 |
|
|
// determine path and name and entry of the calibration file |
462 |
|
|
// |
463 |
|
|
GL_ROOT *glroot = new GL_ROOT(); |
464 |
|
|
if ( verbose ) printf("\n"); |
465 |
|
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
466 |
|
|
// |
467 |
|
|
error = 0; |
468 |
|
|
error = glroot->Query_GL_ROOT(idcalib,dbc); |
469 |
|
|
if ( error < 0 ){ |
470 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
471 |
|
|
return(error); |
472 |
|
|
}; |
473 |
|
|
// |
474 |
|
|
stringstream name; |
475 |
|
|
name.str(""); |
476 |
|
|
name << glroot->PATH.Data() << "/"; |
477 |
|
|
name << glroot->NAME.Data(); |
478 |
|
|
// |
479 |
|
|
TString fcalname = (TString)name.str().c_str(); |
480 |
|
|
ifstream myfile; |
481 |
|
|
myfile.open(fcalname.Data()); |
482 |
|
|
if ( !myfile ){ |
483 |
|
|
return(-107); |
484 |
|
|
}; |
485 |
|
|
myfile.close(); |
486 |
|
|
// |
487 |
|
|
TFile *File = new TFile(fcalname.Data()); |
488 |
|
|
if ( !File ) return(-108); |
489 |
|
|
TTree *tr = (TTree*)File->Get("CalibCalPulse2"); |
490 |
|
|
if ( !tr ) return(-119); |
491 |
|
|
// |
492 |
|
|
TBranch *calo = tr->GetBranch("CalibCalPulse2"); |
493 |
|
|
// |
494 |
|
|
pamela::CalibCalPulse2Event *ce = 0; |
495 |
|
|
tr->SetBranchAddress("CalibCalPulse2", &ce); |
496 |
|
|
// |
497 |
|
|
Long64_t ncalibs = calo->GetEntries(); |
498 |
|
|
// |
499 |
|
|
if ( !ncalibs ) return(-110); |
500 |
|
|
// |
501 |
|
|
calo->GetEntry(calibno); |
502 |
|
|
if ( verbose ) printf(" PULSE2 using entry %u from file %s",calibno,fcalname.Data()); |
503 |
|
|
// |
504 |
|
|
// retrieve calibration table |
505 |
|
|
// |
506 |
|
|
if ( ce->pstwerr[s] && ce->pperror[s] == 0 && ce->unpackError == 0 ){ |
507 |
|
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
508 |
|
|
for ( Int_t j=0; j<96 ;j++){ |
509 |
|
|
if ( s == 2 ){ |
510 |
|
|
adcp[0][2*d+1][j] = ce->calpuls[3][d][j]; |
511 |
|
|
}; |
512 |
|
|
if ( s == 3 ){ |
513 |
|
|
adcp[0][2*d][j] = ce->calpuls[1][d][j]; |
514 |
|
|
}; |
515 |
|
|
if ( s == 0 ){ |
516 |
|
|
adcp[1][2*d][j] = ce->calpuls[0][d][j]; |
517 |
|
|
}; |
518 |
|
|
if ( s == 1 ){ |
519 |
|
|
adcp[1][2*d+1][j] = ce->calpuls[2][d][j]; |
520 |
|
|
}; |
521 |
|
|
}; |
522 |
|
|
}; |
523 |
|
|
} else { |
524 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
525 |
|
|
return(-111); |
526 |
|
|
}; |
527 |
|
|
// |
528 |
|
|
File->Close(); |
529 |
|
|
delete glroot; |
530 |
|
|
// |
531 |
|
|
// Save into matrix adcpcal the calibrated values of the pulse calibration (subtraction of pulse amplitude = 0 relative to the pulse2 calibration used) |
532 |
|
|
// |
533 |
|
|
pampli = 0; |
534 |
|
|
error = 0; |
535 |
|
|
error = glp->Query_GL_CALOPULSE_CALIB(fromtime,s,pampli,dbc); |
536 |
|
|
if ( error < 0 ){ |
537 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
538 |
|
|
return(error); |
539 |
|
|
}; |
540 |
|
|
// |
541 |
|
|
idcalib = glp->ID_ROOT_L0; |
542 |
|
|
calibno = glp->EV_ROOT; |
543 |
|
|
// |
544 |
|
|
// determine path and name and entry of the calibration file |
545 |
|
|
// |
546 |
|
|
glroot = new GL_ROOT(); |
547 |
|
|
if ( verbose ) printf("\n"); |
548 |
|
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
549 |
|
|
// |
550 |
|
|
error = 0; |
551 |
|
|
error = glroot->Query_GL_ROOT(idcalib,dbc); |
552 |
|
|
if ( error < 0 ){ |
553 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
554 |
|
|
return(error); |
555 |
|
|
}; |
556 |
|
|
// |
557 |
|
|
name.str(""); |
558 |
|
|
name << glroot->PATH.Data() << "/"; |
559 |
|
|
name << glroot->NAME.Data(); |
560 |
|
|
// |
561 |
|
|
fcalname = (TString)name.str().c_str(); |
562 |
|
|
myfile.open(fcalname.Data()); |
563 |
|
|
if ( !myfile ){ |
564 |
|
|
return(-107); |
565 |
|
|
}; |
566 |
|
|
myfile.close(); |
567 |
|
|
// |
568 |
|
|
TFile *File1 = new TFile(fcalname.Data()); |
569 |
|
|
if ( !File1 ) return(-108); |
570 |
|
|
TTree *tr1 = (TTree*)File1->Get("CalibCalPulse1"); |
571 |
|
|
if ( !tr1 ) return(-120); |
572 |
|
|
// |
573 |
|
|
TBranch *calo1 = tr1->GetBranch("CalibCalPulse1"); |
574 |
|
|
// |
575 |
|
|
pamela::CalibCalPulse1Event *ce1 = 0; |
576 |
|
|
tr1->SetBranchAddress("CalibCalPulse1", &ce1); |
577 |
|
|
// |
578 |
|
|
ncalibs = calo1->GetEntries(); |
579 |
|
|
// |
580 |
|
|
if ( !ncalibs ) return(-110); |
581 |
|
|
// |
582 |
|
|
calo1->GetEntry(calibno); |
583 |
|
|
if ( verbose ) printf(" PULSE1 using entry %u from file %s",calibno,fcalname.Data()); |
584 |
|
|
// |
585 |
|
|
// retrieve calibration table |
586 |
|
|
// |
587 |
|
|
if ( ce1->pstwerr[s] && ce1->pperror[s] == 0 && ce1->unpackError == 0 ){ |
588 |
|
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
589 |
|
|
for ( Int_t j=0; j<96 ;j++){ |
590 |
|
|
if ( s == 2 ){ |
591 |
|
|
adcpcal[0][2*d+1][j] = adcp[0][2*d+1][j] - ce1->calpuls[3][d][j]; |
592 |
|
|
}; |
593 |
|
|
if ( s == 3 ){ |
594 |
|
|
adcpcal[0][2*d][j] = adcp[0][2*d][j] - ce1->calpuls[1][d][j]; |
595 |
|
|
}; |
596 |
|
|
if ( s == 0 ){ |
597 |
|
|
adcpcal[1][2*d][j] = adcp[1][2*d][j] - ce1->calpuls[0][d][j]; |
598 |
|
|
}; |
599 |
|
|
if ( s == 1 ){ |
600 |
|
|
adcpcal[1][2*d+1][j] = adcp[1][2*d+1][j] - ce1->calpuls[2][d][j]; |
601 |
|
|
}; |
602 |
|
|
}; |
603 |
|
|
}; |
604 |
|
|
} else { |
605 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
606 |
|
|
return(-111); |
607 |
|
|
}; |
608 |
|
|
// |
609 |
|
|
File1->Close(); |
610 |
|
|
// |
611 |
|
|
delete glroot; |
612 |
|
|
// |
613 |
|
|
};// loop on the four sections |
614 |
|
|
// |
615 |
|
|
// |
616 |
|
|
delete glp; |
617 |
|
|
dbc->Close(); |
618 |
|
|
delete dbc; |
619 |
|
|
// |
620 |
|
|
// Ok, now we can try to calculate the cross-talk correction for each pre-amplifier |
621 |
|
|
// |
622 |
|
|
for ( Int_t v=0; v<2; v++){ |
623 |
|
|
if ( debug ) printf(" \n\n NEW VIEW \n"); |
624 |
|
|
for ( Int_t p=0; p<22; p++){ |
625 |
|
|
for ( Int_t npre=0; npre<6; npre++){ |
626 |
|
|
ctprecor[v][p][npre] = 1000.; |
627 |
|
|
ctneigcor[v][p][npre] = 1000.; |
628 |
|
|
Int_t str0=npre*16; |
629 |
|
|
Int_t str16= -1 + (1+npre)*16; |
630 |
|
|
// |
631 |
|
|
UInt_t neigc = 0; |
632 |
|
|
UInt_t farc = 0; |
633 |
|
|
UInt_t pulsc = 0; |
634 |
|
|
Float_t sigpulsed = 0.; |
635 |
|
|
Float_t neigbase = 0.; |
636 |
|
|
Float_t farbase = 0.; |
637 |
|
|
// |
638 |
|
|
// Loop over the strip of the pre and sum all signal far away from pulsed strip, signal in the neighbour(s) strip(s) and save the pulsed signal |
639 |
|
|
// moreover count the number of strips in each case |
640 |
|
|
// |
641 |
|
|
for (Int_t s=str0; s<=str16; s++){ |
642 |
|
|
if ( adcpcal[v][p][s] > 10000.){ |
643 |
|
|
sigpulsed = adcpcal[v][p][s]; |
644 |
|
|
pulsc++; |
645 |
|
|
if ( s > str0 ){ |
646 |
|
|
neigbase += adcpcal[v][p][s-1]; |
647 |
|
|
neigc++; |
648 |
|
|
farbase -= adcpcal[v][p][s-1]; |
649 |
|
|
farc--; |
650 |
|
|
}; |
651 |
|
|
if ( s < str16 ){ |
652 |
|
|
neigbase += adcpcal[v][p][s+1]; |
653 |
|
|
neigc++; |
654 |
|
|
farbase -= adcpcal[v][p][s+1]; |
655 |
|
|
farc--; |
656 |
|
|
}; |
657 |
|
|
} else { |
658 |
|
|
farc++; |
659 |
|
|
farbase += adcpcal[v][p][s]; |
660 |
|
|
}; |
661 |
|
|
}; |
662 |
|
|
// |
663 |
|
|
// Now calculate the corrections |
664 |
|
|
// |
665 |
|
|
Float_t avefarbase = 0.; |
666 |
|
|
if ( farc ) avefarbase = farbase/(Float_t)farc; |
667 |
|
|
Float_t aveneigbase = 0.; |
668 |
|
|
if ( neigc ) aveneigbase = neigbase/(Float_t)neigc; |
669 |
|
|
// |
670 |
|
|
if ( pulsc == 1 && farc && neigc ){ |
671 |
|
|
ctprecor[v][p][npre] = -avefarbase/(sigpulsed+fabs(avefarbase)); |
672 |
|
|
ctneigcor[v][p][npre] = fabs(aveneigbase-avefarbase)/(sigpulsed+fabs(avefarbase)); |
673 |
|
|
if ( debug ) printf(" Cross-talk correction View %i Plane %i Pre %i : pre-correction: %f neighbour strips correction %f \n",v,p,npre,ctprecor[v][p][npre],ctneigcor[v][p][npre]); |
674 |
|
|
} else { |
675 |
|
|
// |
676 |
|
|
// did not find the pulsed strip or more than one pulsed strip found! |
677 |
|
|
// |
678 |
|
|
if ( debug ) printf(" Problems finding the cross-talk corrections: \n View %i Plane %i Pre %i number of pulsed strip %i \n Average faraway baseline %f number of strips %i Average neighbour baseline %f number of neighbour strips %i \n",v,p,npre,pulsc,avefarbase,farc,aveneigbase,neigc); |
679 |
|
|
// |
680 |
|
|
}; |
681 |
|
|
}; |
682 |
|
|
if ( debug ) printf(" \n ==================== \n"); |
683 |
|
|
}; |
684 |
|
|
}; |
685 |
|
|
// |
686 |
|
|
// Check the calculated corrections |
687 |
|
|
// |
688 |
|
|
Int_t opre=0; |
689 |
|
|
Int_t ppre=0; |
690 |
|
|
Bool_t found = false; |
691 |
|
|
for ( Int_t v=0; v<2; v++){ |
692 |
|
|
for ( Int_t p=0; p<22; p++){ |
693 |
|
|
for ( Int_t npre=0; npre<6; npre++){ |
694 |
|
|
if ( ctprecor[v][p][npre] == 1000. || ctneigcor[v][p][npre] == 1000. || obadpulsemask[v][p][npre] != 0 ){ |
695 |
|
|
if ( debug ) printf(" Cross-talk correction CHANGED for view %i Plane %i Pre %i\n BEFORE: pre-correction: %f neighbour strips correction %f \n",v,p,npre,ctprecor[v][p][npre],ctneigcor[v][p][npre]); |
696 |
|
|
if ( npre%2 ){ |
697 |
|
|
opre = npre-1; |
698 |
|
|
} else { |
699 |
|
|
opre = npre+1; |
700 |
|
|
}; |
701 |
|
|
if ( ctprecor[v][p][opre] == 1000. || ctneigcor[v][p][opre] == 1000. || obadpulsemask[v][p][opre] != 0 ){ |
702 |
|
|
ppre=0; |
703 |
|
|
found = false; |
704 |
|
|
while ( ppre < 6 ){ |
705 |
|
|
if ( ctprecor[v][p][ppre] != 1000. && ctneigcor[v][p][ppre] != 1000. && !obadpulsemask[v][p][ppre] ){ |
706 |
|
|
found = true; |
707 |
|
|
ctprecor[v][p][npre] = ctprecor[v][p][ppre]; |
708 |
|
|
ctneigcor[v][p][npre] = ctneigcor[v][p][ppre]; |
709 |
|
|
break; |
710 |
|
|
}; |
711 |
|
|
ppre++; |
712 |
|
|
}; |
713 |
|
|
if ( !found ){ |
714 |
|
|
if ( verbose ) printf(" WARNING: cannot find a good cross-talk correction for view %i plane %i pre %i \n Setting to default values 0.002 0.002\n",v,p,npre); |
715 |
|
|
ctprecor[v][p][npre] = 0.002; |
716 |
|
|
ctneigcor[v][p][npre] = 0.002; |
717 |
|
|
}; |
718 |
|
|
} else { |
719 |
|
|
ctprecor[v][p][npre] = ctprecor[v][p][opre]; |
720 |
|
|
ctneigcor[v][p][npre] = ctneigcor[v][p][opre]; |
721 |
|
|
}; |
722 |
|
|
if ( debug ) printf(" AFTER: pre-correction: %f neighbour strips correction %f \n",ctprecor[v][p][npre],ctneigcor[v][p][npre]); |
723 |
|
|
}; |
724 |
|
|
}; |
725 |
|
|
}; |
726 |
|
|
}; |
727 |
|
|
// |
728 |
|
|
return(0); |
729 |
mocchiut |
1.12 |
} |
730 |
mocchiut |
1.1 |
|
731 |
mocchiut |
1.16 |
void CaloLevel0::FindBaseCompress(Int_t l, Int_t m, Int_t pre){ |
732 |
|
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
733 |
|
|
dexy[l][m][e] = dexyc[l][m][e]; |
734 |
|
|
}; |
735 |
|
|
this->FindBaseRaw(l,m,pre); |
736 |
|
|
} |
737 |
|
|
|
738 |
mocchiut |
1.1 |
void CaloLevel0::FindBaseRaw(Int_t l, Int_t m, Int_t pre){ |
739 |
|
|
Float_t minstrip = 100000.; |
740 |
|
|
Float_t rms = 0.; |
741 |
|
|
base[l][m][pre] = 0.; |
742 |
|
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
743 |
|
|
if ( calgood[l][m][e] == 0. && obadmask[l][m][e] == 0 && dexy[l][m][e]-calped[l][m][e] < minstrip && dexy[l][m][e] > 0.) { |
744 |
|
|
minstrip = dexy[l][m][e]-calped[l][m][e]; |
745 |
|
|
rms = calthr[l][m][pre]; |
746 |
|
|
}; |
747 |
|
|
}; |
748 |
mocchiut |
1.16 |
if ( debug && l==1 ){ |
749 |
|
|
printf("\n BASELINE CALCULATION for view %i pl %i pre %i: \n => minstrip %f rms %f \n",l,m,pre,minstrip,rms); |
750 |
|
|
}; |
751 |
mocchiut |
1.1 |
if ( minstrip != 100000. ) { |
752 |
|
|
Float_t strip6s = 0.; |
753 |
|
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
754 |
|
|
if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) { |
755 |
|
|
strip6s += 1.; |
756 |
|
|
base[l][m][pre] += (dexy[l][m][e] - calped[l][m][e]); |
757 |
|
|
}; |
758 |
|
|
// |
759 |
|
|
// compression |
760 |
|
|
// |
761 |
|
|
if ( abs((int)(dexy[l][m][e]-calped[l][m][e])) <= (minstrip+rms) ) { |
762 |
|
|
dexyc[l][m][e] = 0.; |
763 |
|
|
} else { |
764 |
|
|
dexyc[l][m][e] = dexy[l][m][e]; |
765 |
|
|
}; |
766 |
|
|
}; |
767 |
mocchiut |
1.16 |
if ( debug && l==1 ){ |
768 |
|
|
printf(" strip6s %f \n",strip6s); |
769 |
|
|
}; |
770 |
|
|
// if ( strip6s >= 9. ){ |
771 |
|
|
if ( strip6s >= 2. ){ |
772 |
mocchiut |
1.1 |
Double_t arro = base[l][m][pre]/strip6s; |
773 |
|
|
Float_t deci = 1000.*((float)arro - float(int(arro))); |
774 |
|
|
if ( deci < 500. ) { |
775 |
|
|
arro = double(int(arro)); |
776 |
|
|
} else { |
777 |
|
|
arro = 1. + double(int(arro)); |
778 |
|
|
}; |
779 |
|
|
base[l][m][pre] = arro; |
780 |
|
|
} else { |
781 |
|
|
base[l][m][pre] = 31000.; |
782 |
|
|
for (Int_t e = pre*16; e < (pre+1)*16 ; e++){ |
783 |
|
|
dexyc[l][m][e] = dexy[l][m][e]; |
784 |
|
|
}; |
785 |
|
|
}; |
786 |
|
|
} else { |
787 |
|
|
base[l][m][pre] = 31000.; |
788 |
|
|
}; |
789 |
|
|
} |
790 |
|
|
|
791 |
|
|
Int_t CaloLevel0::Calibrate(Int_t ei){ |
792 |
|
|
// |
793 |
|
|
// get entry ei |
794 |
|
|
// |
795 |
|
|
l0calo->GetEntry(ei); |
796 |
|
|
// |
797 |
|
|
// if it was not a selftrigger event, could it ever been a selftrigger event? if so trigty = 3. |
798 |
|
|
// |
799 |
mocchiut |
1.14 |
clevel2->nsatstrip = 0.; |
800 |
mocchiut |
1.1 |
Int_t val = 0; |
801 |
|
|
Int_t del = 1100; |
802 |
mocchiut |
1.6 |
for (Int_t sec = 0; sec < 4; sec++){ |
803 |
|
|
for (Int_t dsec = 0; dsec < 7; dsec++){ |
804 |
|
|
val = (Int_t)de->calselftrig[sec][dsec]; |
805 |
|
|
del = delay(val); |
806 |
|
|
clevel2->selfdelay[sec][dsec] = del; |
807 |
|
|
}; |
808 |
|
|
}; |
809 |
|
|
val = 0; |
810 |
|
|
del = 1100; |
811 |
mocchiut |
1.1 |
if ( clevel2->trigty != 2. ){ |
812 |
|
|
Bool_t ck = false; |
813 |
|
|
for (Int_t sec = 0; sec < 4; sec++){ |
814 |
|
|
val = (Int_t)de->calselftrig[sec][6]; |
815 |
|
|
del = delay(val); |
816 |
|
|
if ( del < 1100 ){ |
817 |
|
|
clevel2->wartrig = 0.; |
818 |
|
|
clevel2->trigty = 3.; |
819 |
|
|
ck = true; |
820 |
|
|
break; |
821 |
|
|
}; |
822 |
|
|
}; |
823 |
|
|
if ( !ck ) clevel2->wartrig = 100.; |
824 |
|
|
} else { |
825 |
|
|
Bool_t ck = false; |
826 |
|
|
for (Int_t sec = 0; sec < 4; sec++){ |
827 |
|
|
val = (Int_t)de->calselftrig[sec][6]; |
828 |
|
|
del = delay(val); |
829 |
|
|
if ( del < 1100 ){ |
830 |
|
|
clevel2->wartrig = 0.; |
831 |
|
|
ck = true; |
832 |
|
|
}; |
833 |
|
|
}; |
834 |
|
|
if ( !ck ) clevel2->wartrig = 100.; |
835 |
|
|
}; |
836 |
|
|
// |
837 |
|
|
Int_t se = 5; |
838 |
|
|
Int_t done = 0; |
839 |
|
|
Int_t pre = -1; |
840 |
|
|
Bool_t isCOMP = false; |
841 |
|
|
Bool_t isFULL = false; |
842 |
|
|
Bool_t isRAW = false; |
843 |
|
|
Float_t ener; |
844 |
|
|
Int_t doneb = 0; |
845 |
|
|
Int_t donec = 0; |
846 |
|
|
Int_t ck = 0; |
847 |
|
|
Int_t ipre = 0; |
848 |
|
|
Int_t ip[3] = {0}; |
849 |
|
|
Float_t base0, base1, base2; |
850 |
|
|
base0 = 0.; |
851 |
|
|
base1 = 0.; |
852 |
|
|
base2 = 0.; |
853 |
|
|
Float_t qpre[6] = {0.,0.,0.,0.,0.,0.}; |
854 |
|
|
Float_t ene[96]; |
855 |
|
|
Int_t chdone[4] = {0,0,0,0}; |
856 |
|
|
Int_t pe = 0; |
857 |
|
|
// |
858 |
|
|
Float_t ener0 = 0.; |
859 |
|
|
Float_t cbase0 = 0.; |
860 |
|
|
Bool_t pproblem = false; |
861 |
|
|
// |
862 |
|
|
Float_t tim = 0.; |
863 |
|
|
Int_t plo = 0; |
864 |
|
|
Int_t fbi = 0; |
865 |
|
|
Int_t cle = 0; |
866 |
|
|
// |
867 |
|
|
// run over views and planes |
868 |
|
|
// |
869 |
|
|
for (Int_t l = 0; l < 2; l++){ |
870 |
|
|
for (Int_t m = 0; m < 22; m++){ |
871 |
|
|
// |
872 |
mocchiut |
1.2 |
// determine the section number |
873 |
mocchiut |
1.1 |
// |
874 |
|
|
se = 5; |
875 |
mocchiut |
1.2 |
if (l == 0 && m%2 == 0) se = 3; |
876 |
mocchiut |
1.1 |
if (l == 0 && m%2 != 0) se = 2; |
877 |
mocchiut |
1.2 |
if (l == 1 && m%2 != 0) se = 1; |
878 |
|
|
if (l == 1 && m%2 == 0) se = 0; |
879 |
mocchiut |
1.1 |
// |
880 |
|
|
// determine what kind of event we are going to analyze |
881 |
|
|
// |
882 |
|
|
isCOMP = false; |
883 |
|
|
isFULL = false; |
884 |
|
|
isRAW = false; |
885 |
|
|
if ( de->stwerr[se] & (1 << 16) ) isCOMP = true; |
886 |
|
|
if ( de->stwerr[se] & (1 << 17) ) isFULL = true; |
887 |
|
|
if ( de->stwerr[se] & (1 << 3) ) isRAW = true; |
888 |
|
|
if ( !chdone[se] ){ |
889 |
|
|
// |
890 |
|
|
// check for any error in the event |
891 |
|
|
// |
892 |
|
|
clevel2->crc[se] = 0; |
893 |
|
|
if ( de->perror[se] == 132 ){ |
894 |
|
|
clevel2->crc[se] = 1; |
895 |
|
|
pe++; |
896 |
|
|
}; |
897 |
|
|
clevel2->perr[se] = 0; |
898 |
|
|
if ( de->perror[se] != 0 ){ |
899 |
|
|
clevel2->perr[se] = 1; |
900 |
|
|
pe++; |
901 |
|
|
}; |
902 |
|
|
clevel2->swerr[se] = 0; |
903 |
|
|
for (Int_t j = 0; j < 7 ; j++){ |
904 |
|
|
if ( (j != 3) && (de->stwerr[se] & (1 << j)) ){ |
905 |
|
|
clevel2->swerr[se] = 1; |
906 |
|
|
pe++; |
907 |
|
|
}; |
908 |
|
|
}; |
909 |
|
|
chdone[se] = 1; |
910 |
|
|
}; |
911 |
|
|
if ( clevel2->crc[se] == 0 && (clevel1->good2 == 1 || clevel2->trigty >= 2) ){ |
912 |
|
|
pre = -1; |
913 |
|
|
// |
914 |
|
|
for (Int_t nn = 0; nn < 96; nn++){ |
915 |
|
|
ene[nn] = 0.; |
916 |
|
|
dexy[l][m][nn] = de->dexy[l][m][nn] ; |
917 |
|
|
dexyc[l][m][nn] = de->dexyc[l][m][nn] ; |
918 |
|
|
}; |
919 |
|
|
// |
920 |
|
|
// run over preamplifiers |
921 |
|
|
// |
922 |
|
|
pre = -1; |
923 |
|
|
cbase0 = 0.; |
924 |
|
|
for (Int_t i = 0; i < 3; i++){ |
925 |
|
|
for (Int_t j = 0; j < 2; j++){ |
926 |
|
|
pre = j + i*2; |
927 |
|
|
// |
928 |
|
|
// baseline check and calculation |
929 |
|
|
// |
930 |
mocchiut |
1.16 |
if ( !isRAW ){ |
931 |
|
|
if ( de->base[l][m][pre] != 0. && de->base[l][m][pre]<31000. ) { |
932 |
|
|
base[l][m][pre] = de->base[l][m][pre] ; |
933 |
|
|
} else { |
934 |
|
|
FindBaseCompress(l,m,pre); |
935 |
|
|
}; |
936 |
mocchiut |
1.1 |
cbase0 += base[l][m][pre]; |
937 |
|
|
} else { |
938 |
|
|
// |
939 |
|
|
// if it is a raw event and we haven't checked |
940 |
|
|
// yet, calculate the baseline. |
941 |
|
|
// |
942 |
|
|
FindBaseRaw(l,m,pre); |
943 |
|
|
cbase0 += base[l][m][pre]; |
944 |
|
|
}; |
945 |
|
|
}; |
946 |
|
|
}; |
947 |
|
|
// |
948 |
|
|
// run over strips |
949 |
|
|
// |
950 |
|
|
pre = -1; |
951 |
|
|
ener0 = 0.; |
952 |
|
|
for (Int_t i = 0 ; i < 3 ; i++){ |
953 |
|
|
ip[i] = 0; |
954 |
|
|
for (Int_t n = i*32 ; n < (i+1)*32 ; n++){ |
955 |
|
|
if (n%16 == 0) { |
956 |
|
|
ck = 0; |
957 |
|
|
done = 0; |
958 |
|
|
doneb = 0; |
959 |
|
|
donec = 0; |
960 |
|
|
pre++; |
961 |
|
|
qpre[pre] = 0.; |
962 |
|
|
}; |
963 |
|
|
// |
964 |
|
|
// baseline check and calculation |
965 |
|
|
// |
966 |
|
|
// no suitable new baseline, use old ones! |
967 |
|
|
// |
968 |
|
|
if ( !done ){ |
969 |
|
|
if ( (base[l][m][pre] == 31000. || base[l][m][pre] == 0.) ){ |
970 |
|
|
ck = 1; |
971 |
|
|
if (pre%2 == 0) { |
972 |
|
|
ip[i] = pre + 1; |
973 |
|
|
} else { |
974 |
|
|
ip[i] = pre - 1; |
975 |
|
|
}; |
976 |
mocchiut |
1.3 |
if ( (base[l][m][ip[i]] == 31000. || base[l][m][ip[i]] == 0. || !crosst ) ){ |
977 |
mocchiut |
1.1 |
// |
978 |
|
|
ck = 2; |
979 |
|
|
if ( sbase[l][m][pre] == 31000. || sbase[l][m][pre] == 0. ) { |
980 |
|
|
ck = 3; |
981 |
|
|
}; |
982 |
|
|
}; |
983 |
|
|
done = 1; |
984 |
|
|
}; |
985 |
|
|
}; |
986 |
|
|
// |
987 |
|
|
// CALIBRATION ALGORITHM |
988 |
|
|
// |
989 |
|
|
if ( !doneb ){ |
990 |
mocchiut |
1.3 |
if ( debug ) printf(" ck is %i \n",ck); |
991 |
mocchiut |
1.1 |
switch (ck) { |
992 |
|
|
case 0: |
993 |
|
|
base0 = base[l][m][pre]; |
994 |
|
|
base2 = calbase[l][m][pre]; |
995 |
mocchiut |
1.16 |
if ( debug ) printf(" base0 = base l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,base[l][m][pre],calbase[l][m][pre]); |
996 |
mocchiut |
1.1 |
break; |
997 |
|
|
case 1: |
998 |
|
|
base0 = base[l][m][ip[i]]; |
999 |
|
|
base2 = calbase[l][m][ip[i]]; |
1000 |
mocchiut |
1.16 |
if ( debug ) printf(" base0 = base l%i m%i ip(i)%i = %f base2 = calbase l m ip(i) = %f \n",l,m,ip[i],base[l][m][ip[i]],calbase[l][m][ip[i]]); |
1001 |
mocchiut |
1.1 |
break; |
1002 |
|
|
case 2: |
1003 |
|
|
base0 = sbase[l][m][pre]; |
1004 |
mocchiut |
1.3 |
base2 = calbase[l][m][pre]; |
1005 |
mocchiut |
1.16 |
if ( debug ) printf(" base0 = sbase l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,sbase[l][m][pre],calbase[l][m][pre]); |
1006 |
mocchiut |
1.1 |
break; |
1007 |
|
|
case 3: |
1008 |
|
|
base0 = calbase[l][m][pre]; |
1009 |
|
|
base2 = calbase[l][m][pre]; |
1010 |
mocchiut |
1.16 |
if ( debug ) printf(" base0 = calbase l%i m%i pre%i = %f base2 = calbase l m pre = %f \n",l,m,pre,calbase[l][m][pre],calbase[l][m][pre]); |
1011 |
mocchiut |
1.1 |
break; |
1012 |
|
|
}; |
1013 |
|
|
base1 = calbase[l][m][pre]; |
1014 |
|
|
doneb = 1; |
1015 |
|
|
}; |
1016 |
|
|
ener = dexyc[l][m][n]; |
1017 |
|
|
ener0 += ener; |
1018 |
|
|
clevel1->estrip[n][m][l] = 0.; |
1019 |
|
|
if ( base0>0 && base0 < 30000. ){ |
1020 |
mocchiut |
1.3 |
// if ( !donec && (base0 - base1 + base2) != 0. ){ |
1021 |
|
|
// sbase[l][m][pre] = base0 - base1 + base2; |
1022 |
|
|
if ( !donec && (base0 + base1 - base2) != 0. ){ |
1023 |
|
|
sbase[l][m][pre] = base0 + base1 - base2; |
1024 |
mocchiut |
1.1 |
donec = 1; |
1025 |
|
|
}; |
1026 |
|
|
if ( ener > 0. ){ |
1027 |
|
|
clevel1->estrip[n][m][l] = (ener - calped[l][m][n] - base0 - base1 + base2)/mip[l][m][n] ; |
1028 |
|
|
// |
1029 |
|
|
// OK, now in estrip we have the energy deposit in MIP of all the strips for this event (at the end of loops of course) |
1030 |
|
|
// |
1031 |
|
|
qpre[pre] += clevel1->estrip[n][m][l]; |
1032 |
mocchiut |
1.3 |
// |
1033 |
|
|
// |
1034 |
mocchiut |
1.1 |
}; |
1035 |
|
|
}; |
1036 |
|
|
}; |
1037 |
|
|
if ( crosst ){ |
1038 |
|
|
if (ck == 1){ |
1039 |
|
|
if (ip[i]%2 == 0) { |
1040 |
|
|
ipre = ip[i] + 1; |
1041 |
|
|
} else { |
1042 |
|
|
ipre = ip[i] - 1; |
1043 |
|
|
}; |
1044 |
|
|
for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){ |
1045 |
mocchiut |
1.9 |
if ( !ctground ){ |
1046 |
|
|
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * ctprecor[l][m][ipre]; |
1047 |
|
|
} else { |
1048 |
|
|
clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478; |
1049 |
|
|
}; |
1050 |
mocchiut |
1.1 |
}; |
1051 |
|
|
}; |
1052 |
|
|
if (ck == 2){ |
1053 |
|
|
for (Int_t j = i*32 ; j < (i+1)*32 ; j++){ |
1054 |
|
|
ipre = j/16 + 1; |
1055 |
mocchiut |
1.9 |
if ( !ctground ){ |
1056 |
|
|
clevel1->estrip[j][m][l] += qpre[ipre] * ctprecor[l][m][ipre]; |
1057 |
|
|
} else { |
1058 |
|
|
clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478; |
1059 |
|
|
}; |
1060 |
mocchiut |
1.1 |
}; |
1061 |
|
|
}; |
1062 |
|
|
}; |
1063 |
|
|
}; |
1064 |
|
|
// |
1065 |
|
|
if ( ener0 == 0. && cbase0 == 0. && !pproblem && clevel2->perr[se] == 0){ |
1066 |
|
|
if ( verbose ) printf(" L0 entry %i : calorimeter power problems! event marked as bad perr %f swerr %X view %i plane %i \n",ei,de->perror[se],de->stwerr[se],l,m); |
1067 |
|
|
pproblem = true; |
1068 |
|
|
pe++; |
1069 |
|
|
}; |
1070 |
|
|
// |
1071 |
|
|
Int_t j4 = -4; |
1072 |
|
|
Int_t jjj = -3; |
1073 |
|
|
Int_t jj = -2; |
1074 |
mocchiut |
1.9 |
Int_t jjpre = -1; |
1075 |
|
|
Int_t jjjpre = -1; |
1076 |
|
|
for (Int_t j = 0 ; j < 100 ; j++){ |
1077 |
mocchiut |
1.1 |
jj++; |
1078 |
|
|
jjj++; |
1079 |
|
|
j4++; |
1080 |
|
|
if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l]; |
1081 |
|
|
if ( crosst ){ |
1082 |
|
|
if ( jj >= 0 && jj < 96 ){ |
1083 |
mocchiut |
1.9 |
if ( !ctground ){ |
1084 |
|
|
if ( jj%16 == 0 ) jjpre++; |
1085 |
|
|
if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; |
1086 |
|
|
if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * ctneigcor[l][m][jjpre]; |
1087 |
|
|
} else { |
1088 |
|
|
if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * 0.01581; |
1089 |
|
|
if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * 0.01581; |
1090 |
|
|
}; |
1091 |
mocchiut |
1.1 |
}; |
1092 |
|
|
if ( jjj >= 0 && jjj < 96 ){ |
1093 |
mocchiut |
1.9 |
if ( !ctground ){ |
1094 |
|
|
if ( jjj%16 == 0 ) jjjpre++; |
1095 |
|
|
if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; |
1096 |
|
|
if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * ctneigcor[l][m][jjjpre]; |
1097 |
|
|
} else { |
1098 |
|
|
if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * 0.01581; |
1099 |
|
|
if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * 0.01581; |
1100 |
|
|
}; |
1101 |
mocchiut |
1.1 |
}; |
1102 |
|
|
}; |
1103 |
|
|
if ( j4 >= 0 && j4 < 96 ){ |
1104 |
|
|
// |
1105 |
|
|
// NOTICE: THE FOLLOWING LINE EXCLUDE ALL STRIPS FOR WHICH THE RMS*4 IS GREATER THAN 26 !!! <=============== IMPORTANT! =================> |
1106 |
|
|
// |
1107 |
|
|
if ( obadmask[l][m][j4] == 1 || clevel1->estrip[j4][m][l] <= clevel1->emin || calrms[l][m][j4] > 26 ){ |
1108 |
|
|
clevel1->estrip[j4][m][l] = 0.; |
1109 |
|
|
}; |
1110 |
mocchiut |
1.10 |
// |
1111 |
mocchiut |
1.1 |
// code and save the energy for each strip in svstrip |
1112 |
|
|
// |
1113 |
|
|
if ( clevel1->estrip[j4][m][l] > clevel1->emin ){ |
1114 |
|
|
// |
1115 |
mocchiut |
1.10 |
Float_t savel1 = clevel1->estrip[j4][m][l]; |
1116 |
mocchiut |
1.15 |
if ( dexyc[l][m][j4] == 32767. ){ |
1117 |
mocchiut |
1.13 |
savel1 += 5000.; |
1118 |
|
|
clevel2->nsatstrip += 1.; |
1119 |
|
|
}; |
1120 |
mocchiut |
1.10 |
// |
1121 |
mocchiut |
1.1 |
tim = 100000.; |
1122 |
|
|
plo = m; |
1123 |
|
|
fbi = 0; |
1124 |
mocchiut |
1.10 |
if ( savel1 > 0.99995 ){ |
1125 |
mocchiut |
1.1 |
tim = 10000.; |
1126 |
|
|
plo = m; |
1127 |
|
|
fbi = 1; |
1128 |
|
|
}; |
1129 |
mocchiut |
1.10 |
if ( savel1 > 9.9995 ){ |
1130 |
mocchiut |
1.1 |
tim = 1000.; |
1131 |
|
|
plo = 22 + m; |
1132 |
|
|
fbi = 1; |
1133 |
|
|
}; |
1134 |
mocchiut |
1.10 |
if ( savel1 > 99.995 ){ |
1135 |
mocchiut |
1.1 |
tim = 100.; |
1136 |
|
|
plo = 22 + m; |
1137 |
|
|
fbi = 0; |
1138 |
|
|
}; |
1139 |
mocchiut |
1.10 |
if ( savel1 > 999.95 ){ |
1140 |
mocchiut |
1.1 |
tim = 10.; |
1141 |
|
|
plo = 44 + m; |
1142 |
|
|
fbi = 0; |
1143 |
|
|
}; |
1144 |
mocchiut |
1.10 |
if ( savel1 > 9999.5 ){ |
1145 |
mocchiut |
1.1 |
tim = 1.; |
1146 |
|
|
plo = 66 + m; |
1147 |
|
|
fbi = 0; |
1148 |
|
|
}; |
1149 |
|
|
// |
1150 |
mocchiut |
1.10 |
cle = (Int_t)lroundf(tim*savel1); |
1151 |
mocchiut |
1.1 |
// |
1152 |
|
|
if ( l == 0 ){ |
1153 |
|
|
// |
1154 |
|
|
// +-PPSSmmmm.mmmm |
1155 |
|
|
// |
1156 |
|
|
svstrip[istrip] = fbi*1000000000 + plo*10000000 + j4*100000 + cle; |
1157 |
|
|
} else { |
1158 |
|
|
svstrip[istrip] = -(fbi*1000000000 + plo*10000000 + j4*100000 + cle); |
1159 |
|
|
}; |
1160 |
|
|
// |
1161 |
|
|
// if ( ei >= -770 ) printf(" j %i l %i m %i estrip %f \n",j4,l,m,clevel1->estrip[j4][m][l]); |
1162 |
|
|
// if ( ei >= -770 ) printf(" num lim %i fbi %i tim %f plo %i cle %i \n",numeric_limits<Int_t>::max(),fbi,tim,plo,cle); |
1163 |
|
|
// if ( ei >= -770 ) printf(" svstrip %i \n",svstrip[istrip]); |
1164 |
|
|
// |
1165 |
|
|
istrip++; |
1166 |
|
|
}; |
1167 |
|
|
}; |
1168 |
|
|
}; |
1169 |
|
|
// |
1170 |
|
|
} else { |
1171 |
|
|
for (Int_t nn = 0; nn < 96; nn++){ |
1172 |
|
|
clevel1->estrip[nn][m][l] = 0.; |
1173 |
|
|
}; |
1174 |
|
|
}; |
1175 |
|
|
}; |
1176 |
|
|
}; |
1177 |
|
|
if ( !pe ){ |
1178 |
|
|
clevel2->good = 1; |
1179 |
|
|
} else { |
1180 |
|
|
clevel2->good = 0; |
1181 |
|
|
}; |
1182 |
|
|
return(0); |
1183 |
|
|
} |
1184 |
|
|
|
1185 |
|
|
void CaloLevel0::GetTrkVar(){ |
1186 |
|
|
calol2tr(); |
1187 |
|
|
} |
1188 |
|
|
|
1189 |
|
|
void CaloLevel0::FillTrkVar(CaloLevel2 *ca, Int_t nutrk){ |
1190 |
|
|
// |
1191 |
|
|
CaloTrkVar *t_ca = new CaloTrkVar(); |
1192 |
|
|
// |
1193 |
|
|
t_ca->trkseqno = trkseqno; |
1194 |
|
|
t_ca->ncore = (Int_t)clevel2->ncore; |
1195 |
|
|
t_ca->qcore = clevel2->qcore; |
1196 |
|
|
t_ca->noint = (Int_t)clevel2->noint; |
1197 |
|
|
t_ca->ncyl = (Int_t)clevel2->ncyl; |
1198 |
|
|
t_ca->qcyl = clevel2->qcyl; |
1199 |
|
|
t_ca->qtrack = clevel2->qtrack; |
1200 |
|
|
t_ca->qtrackx = clevel2->qtrackx; |
1201 |
|
|
t_ca->qtracky = clevel2->qtracky; |
1202 |
|
|
t_ca->dxtrack = clevel2->dxtrack; |
1203 |
|
|
t_ca->dytrack = clevel2->dytrack; |
1204 |
|
|
t_ca->qlast = clevel2->qlast; |
1205 |
|
|
t_ca->nlast = (Int_t)clevel2->nlast; |
1206 |
|
|
t_ca->qpre = clevel2->qpre; |
1207 |
|
|
t_ca->npre = (Int_t)clevel2->npre; |
1208 |
|
|
t_ca->qpresh = clevel2->qpresh; |
1209 |
|
|
t_ca->npresh = (Int_t)clevel2->npresh; |
1210 |
|
|
t_ca->qtr = clevel2->qtr; |
1211 |
|
|
t_ca->ntr = (Int_t)clevel2->ntr; |
1212 |
|
|
t_ca->planetot = (Int_t)clevel2->planetot; |
1213 |
|
|
t_ca->qmean = clevel2->qmean; |
1214 |
|
|
t_ca->dX0l = clevel2->dX0l; |
1215 |
|
|
t_ca->qlow = clevel2->qlow; |
1216 |
|
|
t_ca->nlow = (Int_t)clevel2->nlow; |
1217 |
|
|
// |
1218 |
|
|
if ( trkseqno == -1 ){ |
1219 |
|
|
// ca->impx = clevel2->impx; |
1220 |
|
|
// ca->impy = clevel2->impy; |
1221 |
|
|
ca->tanx[1] = clevel2->tanx; |
1222 |
|
|
ca->tany[1] = clevel2->tany; |
1223 |
|
|
ca->elen = clevel2->elen; |
1224 |
|
|
ca->selen = clevel2->selen; |
1225 |
|
|
// memcpy(ca->cibar,clevel2->cibar,sizeof(clevel2->cibar)); |
1226 |
|
|
// memcpy(ca->cbar,clevel2->cbar,sizeof(clevel2->cbar)); |
1227 |
|
|
memcpy(t_ca->tibar,clevel2->cibar,sizeof(clevel2->cibar)); |
1228 |
|
|
memcpy(t_ca->tbar,clevel2->cbar,sizeof(clevel2->cbar)); |
1229 |
|
|
memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); |
1230 |
mocchiut |
1.6 |
memcpy(ca->selfdelay,clevel2->selfdelay,sizeof(clevel2->selfdelay)); |
1231 |
mocchiut |
1.1 |
ca->varcfit[2] = clevel2->varcfit[0]; |
1232 |
|
|
ca->varcfit[3] = clevel2->varcfit[1]; |
1233 |
|
|
ca->npcfit[2] = clevel2->npcfit[0]; |
1234 |
|
|
ca->npcfit[3] = clevel2->npcfit[1]; |
1235 |
|
|
// memcpy(ca->varcfit,clevel2->varcfit,sizeof(clevel2->varcfit)); |
1236 |
|
|
// memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit)); |
1237 |
|
|
} else { |
1238 |
|
|
memcpy(t_ca->tibar,clevel2->tibar,sizeof(clevel2->tibar)); |
1239 |
|
|
memcpy(t_ca->tbar,clevel2->tbar,sizeof(clevel2->tbar)); |
1240 |
|
|
}; |
1241 |
|
|
// |
1242 |
|
|
// |
1243 |
|
|
if ( !(ca->CaloTrk) ) ca->CaloTrk = new TClonesArray("CaloTrkVar",1); //ELENA |
1244 |
|
|
TClonesArray &t = *ca->CaloTrk; |
1245 |
|
|
new(t[nutrk]) CaloTrkVar(*t_ca); |
1246 |
|
|
// |
1247 |
|
|
delete t_ca; |
1248 |
|
|
// |
1249 |
|
|
ClearTrkVar(); |
1250 |
|
|
} |
1251 |
|
|
|
1252 |
|
|
void CaloLevel0::GetCommonVar(){ |
1253 |
|
|
calol2cm(); |
1254 |
|
|
} |
1255 |
|
|
|
1256 |
|
|
void CaloLevel0::FillCommonVar(CaloLevel1 *c1, CaloLevel2 *ca){ |
1257 |
|
|
// |
1258 |
|
|
ca->good = clevel2->good; |
1259 |
|
|
if ( clevel2->trigty == 2. ){ |
1260 |
|
|
ca->selftrigger = 1; |
1261 |
|
|
} else { |
1262 |
|
|
ca->selftrigger = 0; |
1263 |
|
|
}; |
1264 |
|
|
// |
1265 |
|
|
ca->selftrigger += (Int_t)clevel2->wartrig; |
1266 |
|
|
// |
1267 |
|
|
memcpy(ca->perr,clevel2->perr,sizeof(clevel2->perr)); |
1268 |
|
|
memcpy(ca->swerr,clevel2->swerr,sizeof(clevel2->swerr)); |
1269 |
|
|
memcpy(ca->crc,clevel2->crc,sizeof(clevel2->crc)); |
1270 |
|
|
ca->nstrip = (Int_t)clevel2->nstrip; |
1271 |
mocchiut |
1.13 |
ca->nsatstrip = (Int_t)clevel2->nsatstrip; |
1272 |
mocchiut |
1.1 |
ca->qtot = clevel2->qtot; |
1273 |
|
|
// ca->impx = clevel2->impx; |
1274 |
|
|
// ca->impy = clevel2->impy; |
1275 |
|
|
ca->tanx[0] = clevel2->tanx; |
1276 |
|
|
ca->tany[0] = clevel2->tany; |
1277 |
|
|
ca->nx22 = (Int_t)clevel2->nx22; |
1278 |
|
|
ca->qx22 = clevel2->qx22; |
1279 |
|
|
ca->qmax = clevel2->qmax; |
1280 |
|
|
ca->elen = clevel2->elen; |
1281 |
|
|
ca->selen = clevel2->selen; |
1282 |
|
|
memcpy(ca->qq,clevel2->qq,sizeof(clevel2->qq)); |
1283 |
|
|
memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax)); |
1284 |
mocchiut |
1.6 |
memcpy(ca->selfdelay,clevel2->selfdelay,sizeof(clevel2->selfdelay)); |
1285 |
mocchiut |
1.1 |
ca->varcfit[0] = clevel2->varcfit[0]; |
1286 |
|
|
ca->varcfit[1] = clevel2->varcfit[1]; |
1287 |
|
|
ca->npcfit[0] = clevel2->npcfit[0]; |
1288 |
|
|
ca->npcfit[1] = clevel2->npcfit[1]; |
1289 |
|
|
ca->fitmode[0] = clevel2->fmode[0]; |
1290 |
|
|
ca->fitmode[1] = clevel2->fmode[1]; |
1291 |
|
|
// memcpy(ca->varcfit,clevel2->varcfit,sizeof(clevel2->varcfit)); |
1292 |
|
|
// memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit)); |
1293 |
|
|
memcpy(ca->cibar,clevel2->cibar,sizeof(clevel2->cibar)); |
1294 |
|
|
memcpy(ca->cbar,clevel2->cbar,sizeof(clevel2->cbar)); |
1295 |
|
|
// |
1296 |
|
|
if ( c1 ){ |
1297 |
|
|
c1->istrip = istrip; |
1298 |
|
|
c1->estrip = TArrayI(istrip,svstrip); |
1299 |
|
|
}; |
1300 |
|
|
// |
1301 |
|
|
} |
1302 |
|
|
|
1303 |
|
|
void CaloLevel0::ClearStructs(){ |
1304 |
|
|
ClearTrkVar(); |
1305 |
|
|
ClearCommonVar(); |
1306 |
|
|
} |
1307 |
|
|
|
1308 |
|
|
void CaloLevel0::RunClose(){ |
1309 |
|
|
l0tr->Delete(); |
1310 |
|
|
ClearStructs(); |
1311 |
|
|
// |
1312 |
|
|
memset(dexy, 0, 2*22*96*sizeof(Float_t)); |
1313 |
|
|
memset(dexyc, 0, 2*22*96*sizeof(Float_t)); |
1314 |
|
|
memset(base, 0, 2*22*6*sizeof(Float_t)); |
1315 |
|
|
memset(sbase, 0, 2*22*6*sizeof(Float_t)); |
1316 |
mocchiut |
1.9 |
memset(ctprecor, 0, 2*22*6*sizeof(Float_t)); |
1317 |
|
|
memset(ctneigcor, 0, 2*22*6*sizeof(Float_t)); |
1318 |
mocchiut |
1.1 |
// |
1319 |
|
|
} |
1320 |
|
|
|
1321 |
|
|
// |
1322 |
|
|
// Private methods |
1323 |
|
|
// |
1324 |
|
|
|
1325 |
|
|
void CaloLevel0::ClearTrkVar(){ |
1326 |
|
|
clevel2->ncore = 0; |
1327 |
|
|
clevel2->qcore = 0.; |
1328 |
|
|
clevel2->noint = 0.; |
1329 |
|
|
clevel2->ncyl = 0.; |
1330 |
|
|
clevel2->qcyl = 0.; |
1331 |
|
|
clevel2->qtrack = 0.; |
1332 |
|
|
clevel2->qtrackx = 0.; |
1333 |
|
|
clevel2->qtracky = 0.; |
1334 |
|
|
clevel2->dxtrack = 0.; |
1335 |
|
|
clevel2->dytrack = 0.; |
1336 |
|
|
clevel2->qlast = 0.; |
1337 |
|
|
clevel2->nlast = 0.; |
1338 |
|
|
clevel2->qpre = 0.; |
1339 |
|
|
clevel2->npre = 0.; |
1340 |
|
|
clevel2->qpresh = 0.; |
1341 |
|
|
clevel2->npresh = 0.; |
1342 |
|
|
clevel2->qlow = 0.; |
1343 |
|
|
clevel2->nlow = 0.; |
1344 |
|
|
clevel2->qtr = 0.; |
1345 |
|
|
clevel2->ntr = 0.; |
1346 |
|
|
clevel2->planetot = 0.; |
1347 |
|
|
clevel2->qmean = 0.; |
1348 |
|
|
clevel2->dX0l = 0.; |
1349 |
|
|
clevel2->elen = 0.; |
1350 |
|
|
clevel2->selen = 0.; |
1351 |
|
|
memset(clevel1->al_p, 0, 5*2*sizeof(Double_t)); |
1352 |
|
|
memset(clevel2->tibar, 0, 2*22*sizeof(Int_t)); |
1353 |
|
|
memset(clevel2->tbar, 0, 2*22*sizeof(Float_t)); |
1354 |
|
|
} |
1355 |
|
|
|
1356 |
|
|
void CaloLevel0::ClearCommonVar(){ |
1357 |
|
|
istrip = 0; |
1358 |
|
|
clevel2->trigty = -1.; |
1359 |
|
|
clevel2->wartrig = 0.; |
1360 |
|
|
clevel2->good = 0; |
1361 |
|
|
clevel2->nstrip = 0.; |
1362 |
mocchiut |
1.13 |
clevel2->nsatstrip = 0.; |
1363 |
mocchiut |
1.1 |
clevel2->qtot = 0.; |
1364 |
|
|
// clevel2->impx = 0.; |
1365 |
|
|
// clevel2->impy = 0.; |
1366 |
|
|
clevel2->tanx = 0.; // this is correct since it refers to the fortran structure |
1367 |
|
|
clevel2->tany = 0.; // this is correct since it refers to the fortran structure |
1368 |
|
|
clevel2->qmax = 0.; |
1369 |
|
|
clevel2->nx22 = 0.; |
1370 |
|
|
clevel2->qx22 = 0.; |
1371 |
|
|
memset(clevel2->perr, 0, 4*sizeof(Int_t)); |
1372 |
|
|
memset(clevel2->swerr, 0, 4*sizeof(Int_t)); |
1373 |
|
|
memset(clevel2->crc, 0, 4*sizeof(Int_t)); |
1374 |
|
|
memset(clevel2->qq, 0, 4*sizeof(Int_t)); |
1375 |
|
|
memset(clevel2->varcfit, 0, 4*sizeof(Float_t)); |
1376 |
|
|
memset(clevel2->npcfit, 0, 4*sizeof(Int_t)); |
1377 |
|
|
memset(clevel2->planemax, 0, 2*sizeof(Int_t)); |
1378 |
mocchiut |
1.6 |
memset(clevel2->selfdelay, 0, 4*7*sizeof(Int_t)); |
1379 |
mocchiut |
1.1 |
memset(clevel2->fmode, 0, 2*sizeof(Int_t)); |
1380 |
|
|
memset(clevel2->cibar, 0, 2*22*sizeof(Int_t)); |
1381 |
|
|
memset(clevel2->cbar, 0, 2*22*sizeof(Float_t)); |
1382 |
|
|
} |
1383 |
|
|
|
1384 |
|
|
void CaloLevel0::ClearCalibVals(Int_t s){ |
1385 |
|
|
// |
1386 |
|
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
1387 |
|
|
Int_t pre = -1; |
1388 |
|
|
for ( Int_t j=0; j<96 ;j++){ |
1389 |
|
|
if ( j%16 == 0 ) pre++; |
1390 |
|
|
if ( s == 2 ){ |
1391 |
|
|
calped[0][2*d+1][j] = 0.; |
1392 |
|
|
cstwerr[3] = 0.; |
1393 |
|
|
cperror[3] = 0.; |
1394 |
|
|
calgood[0][2*d+1][j] = 0.; |
1395 |
|
|
calthr[0][2*d+1][pre] = 0.; |
1396 |
|
|
calrms[0][2*d+1][j] = 0.; |
1397 |
|
|
calbase[0][2*d+1][pre] = 0.; |
1398 |
|
|
calvar[0][2*d+1][pre] = 0.; |
1399 |
|
|
}; |
1400 |
|
|
if ( s == 3 ){ |
1401 |
|
|
calped[0][2*d][j] = 0.; |
1402 |
|
|
cstwerr[1] = 0.; |
1403 |
|
|
cperror[1] = 0.; |
1404 |
|
|
calgood[0][2*d][j] = 0.; |
1405 |
|
|
calthr[0][2*d][pre] = 0.; |
1406 |
|
|
calrms[0][2*d][j] = 0.; |
1407 |
|
|
calbase[0][2*d][pre] = 0.; |
1408 |
|
|
calvar[0][2*d][pre] = 0.; |
1409 |
|
|
}; |
1410 |
|
|
if ( s == 0 ){ |
1411 |
|
|
calped[1][2*d][j] = 0.; |
1412 |
|
|
cstwerr[0] = 0.; |
1413 |
|
|
cperror[0] = 0.; |
1414 |
|
|
calgood[1][2*d][j] = 0.; |
1415 |
|
|
calthr[1][2*d][pre] = 0.; |
1416 |
|
|
calrms[1][2*d][j] = 0.; |
1417 |
|
|
calbase[1][2*d][pre] = 0.; |
1418 |
|
|
calvar[1][2*d][pre] = 0.; |
1419 |
|
|
}; |
1420 |
|
|
if ( s == 1 ){ |
1421 |
|
|
calped[1][2*d+1][j] = 0.; |
1422 |
|
|
cstwerr[2] = 0.; |
1423 |
|
|
cperror[2] = 0.; |
1424 |
|
|
calgood[1][2*d+1][j] = 0.; |
1425 |
|
|
calthr[1][2*d+1][pre] = 0.; |
1426 |
|
|
calrms[1][2*d+1][j] = 0.; |
1427 |
|
|
calbase[1][2*d+1][pre] = 0.; |
1428 |
|
|
calvar[1][2*d+1][pre] = 0.; |
1429 |
|
|
}; |
1430 |
|
|
}; |
1431 |
|
|
}; |
1432 |
|
|
return; |
1433 |
|
|
} |
1434 |
|
|
|
1435 |
mocchiut |
1.7 |
Int_t CaloLevel0::Update(GL_TABLES *glt, UInt_t atime, Int_t s){ |
1436 |
mocchiut |
1.1 |
// |
1437 |
mocchiut |
1.7 |
const TString host = glt->CGetHost(); |
1438 |
|
|
const TString user = glt->CGetUser(); |
1439 |
|
|
const TString psw = glt->CGetPsw(); |
1440 |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
1441 |
|
|
if ( !dbc->IsConnected() ) throw -116; |
1442 |
mocchiut |
1.8 |
stringstream myquery; |
1443 |
|
|
myquery.str(""); |
1444 |
|
|
myquery << "SET time_zone='+0:00'"; |
1445 |
|
|
dbc->Query(myquery.str().c_str()); |
1446 |
mocchiut |
1.1 |
Int_t sgnl = 0; |
1447 |
|
|
// |
1448 |
|
|
GL_CALO_CALIB *glcalo = new GL_CALO_CALIB(); |
1449 |
|
|
// |
1450 |
|
|
sgnl = 0; |
1451 |
|
|
// |
1452 |
|
|
idcalib[s] = 0; |
1453 |
|
|
fromtime[s] = 0; |
1454 |
|
|
totime[s] = 0; |
1455 |
|
|
calibno[s] = 0; |
1456 |
|
|
ClearCalibVals(s); |
1457 |
|
|
// |
1458 |
|
|
UInt_t uptime = 0; |
1459 |
|
|
// |
1460 |
|
|
sgnl = glcalo->Query_GL_CALO_CALIB(atime,uptime,s,dbc); |
1461 |
|
|
if ( sgnl < 0 ){ |
1462 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
1463 |
|
|
return(sgnl); |
1464 |
|
|
}; |
1465 |
|
|
// |
1466 |
|
|
idcalib[s] = glcalo->ID_ROOT_L0; |
1467 |
|
|
fromtime[s] = glcalo->FROM_TIME; |
1468 |
|
|
if ( glcalo->TO_TIME < atime ){ // calibration is corrupted and we are using the one that preceed the good one |
1469 |
|
|
totime[s] = uptime; |
1470 |
|
|
} else { |
1471 |
|
|
totime[s] = glcalo->TO_TIME; |
1472 |
|
|
}; |
1473 |
|
|
// totime[s] = glcalo->TO_TIME; |
1474 |
|
|
calibno[s] = glcalo->EV_ROOT; |
1475 |
|
|
// |
1476 |
|
|
if ( totime[s] == 0 ){ |
1477 |
|
|
if ( verbose ) printf(" CALORIMETER - WARNING: data with no associated calibration\n"); |
1478 |
|
|
ClearCalibVals(s); |
1479 |
|
|
sgnl = 100; |
1480 |
|
|
}; |
1481 |
|
|
// |
1482 |
|
|
// determine path and name and entry of the calibration file |
1483 |
|
|
// |
1484 |
|
|
GL_ROOT *glroot = new GL_ROOT(); |
1485 |
|
|
if ( verbose ) printf("\n"); |
1486 |
|
|
if ( verbose ) printf(" ** SECTION %i **\n",s); |
1487 |
|
|
// |
1488 |
|
|
sgnl = glroot->Query_GL_ROOT(idcalib[s],dbc); |
1489 |
|
|
if ( sgnl < 0 ){ |
1490 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n"); |
1491 |
|
|
return(sgnl); |
1492 |
|
|
}; |
1493 |
|
|
// |
1494 |
|
|
stringstream name; |
1495 |
|
|
name.str(""); |
1496 |
|
|
name << glroot->PATH.Data() << "/"; |
1497 |
|
|
name << glroot->NAME.Data(); |
1498 |
|
|
// |
1499 |
|
|
fcalname[s] = (TString)name.str().c_str(); |
1500 |
|
|
if ( verbose ) printf(" - event at time %u. From time %u to time %u \n use file %s \n calibration at entry %i \n\n",atime,fromtime[s],totime[s],fcalname[s].Data(),calibno[s]); |
1501 |
|
|
// |
1502 |
|
|
sgnl = LoadCalib(s); |
1503 |
|
|
// |
1504 |
|
|
if ( sgnl != 0 ) return(sgnl); |
1505 |
|
|
delete glcalo; |
1506 |
|
|
delete glroot; |
1507 |
|
|
// |
1508 |
|
|
return(0); |
1509 |
|
|
// |
1510 |
|
|
} |
1511 |
|
|
|
1512 |
|
|
Int_t CaloLevel0::LoadCalib(Int_t s){ |
1513 |
|
|
// |
1514 |
|
|
ifstream myfile; |
1515 |
|
|
myfile.open(fcalname[s].Data()); |
1516 |
|
|
if ( !myfile ){ |
1517 |
|
|
return(-107); |
1518 |
|
|
}; |
1519 |
|
|
myfile.close(); |
1520 |
|
|
// |
1521 |
|
|
TFile *File = new TFile(fcalname[s].Data()); |
1522 |
|
|
if ( !File ) return(-108); |
1523 |
|
|
TTree *tr = (TTree*)File->Get("CalibCalPed"); |
1524 |
|
|
if ( !tr ) return(-109); |
1525 |
|
|
// |
1526 |
|
|
TBranch *calo = tr->GetBranch("CalibCalPed"); |
1527 |
|
|
// |
1528 |
|
|
pamela::CalibCalPedEvent *ce = 0; |
1529 |
|
|
tr->SetBranchAddress("CalibCalPed", &ce); |
1530 |
|
|
// |
1531 |
|
|
Long64_t ncalibs = calo->GetEntries(); |
1532 |
|
|
// |
1533 |
|
|
if ( !ncalibs ) return(-110); |
1534 |
|
|
// |
1535 |
|
|
calo->GetEntry(calibno[s]); |
1536 |
|
|
// |
1537 |
|
|
if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) { |
1538 |
|
|
for ( Int_t d=0 ; d<11 ;d++ ){ |
1539 |
|
|
Int_t pre = -1; |
1540 |
|
|
for ( Int_t j=0; j<96 ;j++){ |
1541 |
|
|
if ( j%16 == 0 ) pre++; |
1542 |
|
|
if ( s == 2 ){ |
1543 |
|
|
calped[0][2*d+1][j] = ce->calped[3][d][j]; |
1544 |
|
|
cstwerr[3] = ce->cstwerr[3]; |
1545 |
|
|
cperror[3] = ce->cperror[3]; |
1546 |
|
|
calgood[0][2*d+1][j] = ce->calgood[3][d][j]; |
1547 |
|
|
calthr[0][2*d+1][pre] = ce->calthr[3][d][pre]; |
1548 |
|
|
calrms[0][2*d+1][j] = ce->calrms[3][d][j]; |
1549 |
|
|
calbase[0][2*d+1][pre] = ce->calbase[3][d][pre]; |
1550 |
|
|
calvar[0][2*d+1][pre] = ce->calvar[3][d][pre]; |
1551 |
|
|
}; |
1552 |
|
|
if ( s == 3 ){ |
1553 |
|
|
calped[0][2*d][j] = ce->calped[1][d][j]; |
1554 |
|
|
cstwerr[1] = ce->cstwerr[1]; |
1555 |
|
|
cperror[1] = ce->cperror[1]; |
1556 |
|
|
calgood[0][2*d][j] = ce->calgood[1][d][j]; |
1557 |
|
|
calthr[0][2*d][pre] = ce->calthr[1][d][pre]; |
1558 |
|
|
calrms[0][2*d][j] = ce->calrms[1][d][j]; |
1559 |
|
|
calbase[0][2*d][pre] = ce->calbase[1][d][pre]; |
1560 |
|
|
calvar[0][2*d][pre] = ce->calvar[1][d][pre]; |
1561 |
|
|
}; |
1562 |
|
|
if ( s == 0 ){ |
1563 |
|
|
calped[1][2*d][j] = ce->calped[0][d][j]; |
1564 |
|
|
cstwerr[0] = ce->cstwerr[0]; |
1565 |
|
|
cperror[0] = ce->cperror[0]; |
1566 |
|
|
calgood[1][2*d][j] = ce->calgood[0][d][j]; |
1567 |
|
|
calthr[1][2*d][pre] = ce->calthr[0][d][pre]; |
1568 |
|
|
calrms[1][2*d][j] = ce->calrms[0][d][j]; |
1569 |
|
|
calbase[1][2*d][pre] = ce->calbase[0][d][pre]; |
1570 |
|
|
calvar[1][2*d][pre] = ce->calvar[0][d][pre]; |
1571 |
|
|
}; |
1572 |
|
|
if ( s == 1 ){ |
1573 |
|
|
calped[1][2*d+1][j] = ce->calped[2][d][j]; |
1574 |
|
|
cstwerr[2] = ce->cstwerr[2]; |
1575 |
|
|
cperror[2] = ce->cperror[2]; |
1576 |
|
|
calgood[1][2*d+1][j] = ce->calgood[2][d][j]; |
1577 |
|
|
calthr[1][2*d+1][pre] = ce->calthr[2][d][pre]; |
1578 |
|
|
calrms[1][2*d+1][j] = ce->calrms[2][d][j]; |
1579 |
|
|
calbase[1][2*d+1][pre] = ce->calbase[2][d][pre]; |
1580 |
|
|
calvar[1][2*d+1][pre] = ce->calvar[2][d][pre]; |
1581 |
|
|
}; |
1582 |
|
|
}; |
1583 |
|
|
}; |
1584 |
|
|
} else { |
1585 |
|
|
if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n "); |
1586 |
|
|
return(-111); |
1587 |
|
|
}; |
1588 |
|
|
File->Close(); |
1589 |
|
|
return(0); |
1590 |
|
|
} |