1 |
/** |
2 |
* \file CaloPreSampler.cpp |
3 |
* \author Emiliano Mocchiutti (2007/07/18) |
4 |
*/ |
5 |
// |
6 |
// headers |
7 |
// |
8 |
#include <CaloPreSampler.h> |
9 |
//-------------------------------------- |
10 |
/** |
11 |
* Default constructor |
12 |
*/ |
13 |
CaloPreSampler::CaloPreSampler(){ |
14 |
Clear(); |
15 |
}; |
16 |
|
17 |
CaloPreSampler::CaloPreSampler(PamLevel2 *l2p){ |
18 |
// |
19 |
L2 = l2p; |
20 |
// |
21 |
if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n"); |
22 |
// |
23 |
OBT = 0; |
24 |
PKT = 0; |
25 |
atime = 0; |
26 |
// |
27 |
// Default variables |
28 |
// |
29 |
event = new CaloLevel0(); |
30 |
cstrip = new CaloStrip(false); |
31 |
// c1 = new CaloLevel1(); |
32 |
pcalo = new CaloLevel2(); |
33 |
N = 3; |
34 |
debug = false; |
35 |
sel = true; |
36 |
cont = false; |
37 |
emulate18 = true; |
38 |
simulation = false; |
39 |
// |
40 |
Clear(); |
41 |
// |
42 |
// loading magnetic field... |
43 |
// |
44 |
TrkLevel2 *trk = new TrkLevel2(); |
45 |
GL_PARAM *q4 = new GL_PARAM(); |
46 |
TSQLServer *dbc = 0; |
47 |
TString host = "mysql://localhost/pamelaprod"; |
48 |
TString user = "anonymous"; |
49 |
TString psw = ""; |
50 |
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
51 |
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
52 |
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
53 |
if ( !pamdbhost ) pamdbhost = ""; |
54 |
if ( !pamdbuser ) pamdbuser = ""; |
55 |
if ( !pamdbpsw ) pamdbpsw = ""; |
56 |
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
57 |
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
58 |
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
59 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
60 |
// |
61 |
q4->Query_GL_PARAM(1,1,dbc); |
62 |
printf(" Reading magnetic field maps at %s\n",(q4->PATH+q4->NAME).Data()); |
63 |
trk->LoadField(q4->PATH+q4->NAME); |
64 |
// |
65 |
}; |
66 |
|
67 |
void CaloPreSampler::Clear(){ |
68 |
// |
69 |
pcalo->Clear(); |
70 |
// |
71 |
}; |
72 |
|
73 |
void CaloPreSampler::Print(){ |
74 |
// |
75 |
Process(); |
76 |
// |
77 |
printf("========================================================================\n"); |
78 |
printf(" OBT: %u PKT: %u ATIME: %u \n",OBT,PKT,atime); |
79 |
printf(" debug [debug flag]:.. %i\n",debug); |
80 |
printf(" simulation [simulation flag]:.. %i\n",simulation); |
81 |
printf(" emulate18 [emulate dead plane 18]:.. %i\n",emulate18); |
82 |
printf(" selection mode :.. %i\n",sel); |
83 |
printf(" contamination mode :.. %i\n",cont); |
84 |
printf(" pre-sampler planes :.. %i\n",N); |
85 |
printf(" pcalo->qtot :.. %f\n",pcalo->qtot); |
86 |
printf(" pcalo->nstrip :.. %i\n",pcalo->nstrip); |
87 |
printf(" pcalo->track0->qtrack :.. %f\n",pcalo->GetCaloTrkVar(0)->qtrack); |
88 |
printf(" pcalo->track0->dX0l :.. %f\n",pcalo->GetCaloTrkVar(0)->dX0l); |
89 |
printf("========================================================================\n"); |
90 |
// |
91 |
}; |
92 |
|
93 |
void CaloPreSampler::Delete(){ |
94 |
Clear(); |
95 |
delete pcalo; |
96 |
//delete this; |
97 |
}; |
98 |
|
99 |
|
100 |
void CaloPreSampler::Process(){ |
101 |
// |
102 |
if ( !L2 ){ |
103 |
printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n"); |
104 |
printf(" ERROR: CaloPreSampler variables _NOT_ filled \n"); |
105 |
return; |
106 |
}; |
107 |
// |
108 |
Bool_t newentry = false; |
109 |
// |
110 |
if ( L2->IsORB() ){ |
111 |
if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || sel != ssel ){ |
112 |
newentry = true; |
113 |
OBT = L2->GetOrbitalInfo()->OBT; |
114 |
PKT = L2->GetOrbitalInfo()->pkt_num; |
115 |
atime = L2->GetOrbitalInfo()->absTime; |
116 |
ssel = sel; |
117 |
}; |
118 |
} else { |
119 |
newentry = true; |
120 |
}; |
121 |
// |
122 |
if ( !newentry ) return; |
123 |
// |
124 |
// Some variables |
125 |
// |
126 |
Int_t S3 = 0; |
127 |
Int_t S2 = 0; |
128 |
Int_t S12 = 0; |
129 |
Int_t S11 = 0; |
130 |
Float_t tmptrigty = -1.; |
131 |
Bool_t trackanyway = true; |
132 |
Float_t rigdefault = 50.; |
133 |
Bool_t hZn = true; |
134 |
Bool_t withtrk = true; |
135 |
Bool_t st = true; |
136 |
Int_t ntrkentry = 0; |
137 |
TrkLevel2 *trk = L2->GetTrkLevel2(); |
138 |
Bool_t filled = false; |
139 |
// |
140 |
if ( debug ) printf(" Processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime); |
141 |
// |
142 |
this->Clear(); |
143 |
// |
144 |
// find out if we have trkseqno = -1, -2 or -3 |
145 |
// |
146 |
Bool_t m1 = false; |
147 |
Bool_t m2 = false; |
148 |
Bool_t m3 = false; |
149 |
for (Int_t mm=0; mm < L2->GetCaloLevel2()->ntrk(); mm++ ){ |
150 |
if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -1 ) m1 = true; |
151 |
if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -2 ) m2 = true; |
152 |
if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -3 ) m3 = true; |
153 |
}; |
154 |
// |
155 |
if ( debug ) printf(" Fill estrip matrix needed to calculate variables \n"); |
156 |
// |
157 |
// Fill the estrip matrix |
158 |
// |
159 |
memset(event->clevel1->estrip, 0, 2*22*96*sizeof(Float_t)); |
160 |
Int_t view = 0; |
161 |
Int_t plane = 0; |
162 |
Int_t strip = 0; |
163 |
Float_t mip = 0.; |
164 |
for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){ |
165 |
// |
166 |
mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); |
167 |
// |
168 |
// Selection mode: fill the matrix only for plane < (22 - N) REMEMBER N = number of W planes to be used as presampler, ie if N = 2 then we want to use planes from 0 to 19 |
169 |
// included so plane < (22 - 2) |
170 |
// |
171 |
if ( sel ){ |
172 |
if ( plane < (22 - N) ){ |
173 |
// |
174 |
if ( emulate18 && plane == (18 - N) ) mip = 0.; |
175 |
event->clevel1->estrip[strip][plane][view] = mip; |
176 |
// |
177 |
}; |
178 |
}; |
179 |
// |
180 |
// Contamination mode: fill the matrix only for planes from N to 22 but shift all planes up to the first one |
181 |
// |
182 |
if ( cont ){ |
183 |
if ( plane >= N ){ |
184 |
// |
185 |
if ( emulate18 && plane == (18 + N) ) mip = 0.; |
186 |
event->clevel1->estrip[strip][(plane-N)][view] = mip; |
187 |
// |
188 |
}; |
189 |
}; |
190 |
// |
191 |
}; |
192 |
// |
193 |
// if data comes from the simulation we must use mechanical alignment parameters (default is flight parameters) |
194 |
// |
195 |
if ( simulation ){ |
196 |
cstrip->UseMechanicalAlig(); |
197 |
}; |
198 |
// |
199 |
// Set alignment parameter |
200 |
// |
201 |
event->clevel1->xalig = cstrip->GetXalig(); |
202 |
event->clevel1->yalig = cstrip->GetYalig(); |
203 |
event->clevel1->zalig = cstrip->GetZalig(); |
204 |
// |
205 |
event->clevel1->emin = 0.7; |
206 |
// |
207 |
// in case of the contamination mode we must play with the Z alignment in order to have the correct track in the calo since we have moved the planes up... |
208 |
// |
209 |
if ( cont ){ |
210 |
if ( !(N%2) ){ |
211 |
event->clevel1->reverse = 0; // if the number of planes is even we have taken away a full module no need to do anything strange... |
212 |
event->clevel1->zalig -= (N/2) * (8.09 + 10.09); |
213 |
} else { |
214 |
event->clevel1->reverse = 1; // if the number of planes is odd we have taken away half a module, we need to reverse silicon planes shifting |
215 |
event->clevel1->zalig -= ((N+1)/2) * 8.09 + ((N-1)/2) * 10.09; |
216 |
}; |
217 |
}; |
218 |
if ( debug ) printf(" xalig = %f \n",event->clevel1->xalig); |
219 |
if ( debug ) printf(" yalig = %f \n",event->clevel1->yalig); |
220 |
if ( debug ) printf(" zalig = %f \n",event->clevel1->zalig); |
221 |
// |
222 |
if ( debug ) printf(" Calculate variables as done in CaloCore, N = %i \n",N); |
223 |
// |
224 |
// Calculate variables |
225 |
// |
226 |
// |
227 |
// use only N W planes |
228 |
// |
229 |
event->clevel1->npla = 22-N; |
230 |
// |
231 |
S3 = 0; |
232 |
S2 = 0; |
233 |
S12 = 0; |
234 |
S11 = 0; |
235 |
S3 = L2->GetTrigLevel2()->patterntrig[2]; |
236 |
S2 = L2->GetTrigLevel2()->patterntrig[3]; |
237 |
S12 = L2->GetTrigLevel2()->patterntrig[4]; |
238 |
S11 = L2->GetTrigLevel2()->patterntrig[5]; |
239 |
if ( L2->GetTrigLevel2()->patterntrig[1] & (1<<0) ) tmptrigty = 1.; |
240 |
if ( L2->GetTrigLevel2()->patterntrig[0] ) tmptrigty = 2.; |
241 |
if ( S3 || S2 || S12 || S11 ) tmptrigty = 0.; |
242 |
if ( !(L2->GetTrigLevel2()->patterntrig[1] & (1<<0)) && !L2->GetTrigLevel2()->patterntrig[0] && !S3 && !S2 && !S12 && !S11 ) tmptrigty = 1.; |
243 |
event->clevel2->trigty = tmptrigty; |
244 |
// |
245 |
// do we have at least one track from the tracker? this check has been disabled |
246 |
// |
247 |
event->clevel1->good2 = 1; |
248 |
// |
249 |
// Calculate variables common to all tracks (qtot, nstrip, etc.) |
250 |
// |
251 |
if ( debug ) printf("1 Call GetCommonVar() \n"); |
252 |
event->GetCommonVar(); |
253 |
// |
254 |
// Fill common variables |
255 |
// |
256 |
if ( debug ) printf("1 Call FillCommonVar() \n"); |
257 |
event->FillCommonVar(NULL,pcalo); |
258 |
// |
259 |
// Calculate variables related to tracks only if we have at least one track (from selftrigger and/or tracker) |
260 |
// |
261 |
ntrkentry = 0; |
262 |
// |
263 |
filled = false; |
264 |
// |
265 |
// Run over tracks (tracker or calorimeter ) |
266 |
// |
267 |
if ( withtrk ){ |
268 |
// |
269 |
for (Int_t nt=0; nt < trk->ntrk(); nt++){ |
270 |
// |
271 |
event->clevel1->good2 = 1; |
272 |
// |
273 |
TrkTrack *ptt = trk->GetStoredTrack(nt); |
274 |
// |
275 |
event->clevel1->trkchi2 = 0; |
276 |
// |
277 |
// Copy the alpha vector in the input structure |
278 |
// |
279 |
for (Int_t e = 0; e < 5 ; e++){ |
280 |
event->clevel1->al_p[e][0] = ptt->al[e]; |
281 |
}; |
282 |
// |
283 |
// Get tracker related variables for this track |
284 |
// |
285 |
if ( debug ) printf("track %i Call GetTrkVar() \n",nt); |
286 |
event->GetTrkVar(); |
287 |
if ( debug ) printf(" event->clevel2->dX0l %f \n",event->clevel2->dX0l); |
288 |
// |
289 |
// Save tracker track sequence number |
290 |
// |
291 |
event->trkseqno = nt; |
292 |
// |
293 |
// Copy values in the class ca from the structure clevel2 |
294 |
// |
295 |
if ( debug ) printf("track %i Call FillTrkVar() \n",nt); |
296 |
event->FillTrkVar(pcalo,ntrkentry); |
297 |
|
298 |
|
299 |
ntrkentry++; |
300 |
filled = true; |
301 |
// |
302 |
}; // loop on all the tracks |
303 |
}; |
304 |
// |
305 |
// if no tracks found but there is the possibility to have a good track we should try to calculate anyway the track related variables using the calorimeter |
306 |
// fit of the track (to be used for example when TRK is off due to any reason like IPM3/5 off). |
307 |
// here we make an event selection so it must be done very carefully... |
308 |
// |
309 |
// conditions are: 0) no track from the tracker 1) we have a track fit both in x and y 2) no problems with calo for this event 3) no selftrigger event |
310 |
// |
311 |
// if ( trackanyway && !filled && event->clevel2->npcfit[0] >= 2 && event->clevel2->npcfit[1] >= 2 && event->clevel2->good != 0 && event->clevel2->trigty < 2. ){ |
312 |
if ( trackanyway && m3 ){ |
313 |
if ( debug ) printf(" Event with a track not fitted by the tracker \n"); |
314 |
// |
315 |
// Disable "track mode" in the fortran routine |
316 |
// |
317 |
event->clevel1->good2 = 0; |
318 |
event->clevel1->riginput = rigdefault; |
319 |
if ( debug ) printf(" Using as default rigidity: %f \n",event->clevel1->riginput); |
320 |
// |
321 |
// We have a selftrigger event to analyze. |
322 |
// |
323 |
for (Int_t e = 0; e < 5 ; e++){ |
324 |
event->clevel1->al_p[e][0] = 0.; |
325 |
event->clevel1->al_p[e][1] = 0.; |
326 |
}; |
327 |
event->clevel1->trkchi2 = 0; |
328 |
// |
329 |
if ( debug ) printf("-3 a Call GetTrkVar() \n"); |
330 |
event->GetTrkVar(); |
331 |
// |
332 |
// if we had no problem (clevel1->good2 = 0, NOTICE zero, not one in this mode!), fill and go on |
333 |
// |
334 |
if ( event->clevel1->good2 == 0 ) { |
335 |
// |
336 |
// In selftrigger mode the trkentry variable is set to -1 |
337 |
// |
338 |
event->trkseqno = -3; |
339 |
// |
340 |
// Copy values in the class ca from the structure clevel2 |
341 |
// |
342 |
if ( debug ) printf("-3 a Call FillTrkVar() \n"); |
343 |
event->FillTrkVar(pcalo,ntrkentry); |
344 |
ntrkentry++; |
345 |
filled = true; |
346 |
// |
347 |
} else { |
348 |
if ( debug ) printf(" Selftrigger: problems with event \n"); |
349 |
}; |
350 |
// |
351 |
}; |
352 |
// |
353 |
// Call high energy nuclei routine |
354 |
// |
355 |
// if ( hZn && event->clevel2->trigty >= 2. ){ |
356 |
if ( hZn && m2 ){ |
357 |
if ( debug ) printf(" Calling selftrigger high energy nuclei routine \n"); |
358 |
// |
359 |
// Disable "track mode" in the fortran routine |
360 |
// |
361 |
event->clevel1->good2 = 0; |
362 |
// |
363 |
// Set high energy nuclei flag to one |
364 |
// |
365 |
event->clevel1->hzn = 1; |
366 |
event->clevel1->riginput = rigdefault; |
367 |
// |
368 |
// We have a selftrigger event to analyze. |
369 |
// |
370 |
for (Int_t e = 0; e < 5 ; e++){ |
371 |
event->clevel1->al_p[e][0] = 0.; |
372 |
event->clevel1->al_p[e][1] = 0.; |
373 |
}; |
374 |
event->clevel1->trkchi2 = 0; |
375 |
// |
376 |
if ( debug ) printf("-2 a Call GetTrkVar() \n"); |
377 |
event->GetTrkVar(); |
378 |
// |
379 |
// if we had no problem (clevel1->good2 = 0, NOTICE zero, not one in this mode!), fill and go on |
380 |
// |
381 |
if ( event->clevel1->good2 == 0 ) { |
382 |
// |
383 |
// In selftrigger mode the trkentry variable is set to -1 |
384 |
// |
385 |
event->trkseqno = -2; |
386 |
// |
387 |
// Copy values in the class ca from the structure clevel2 |
388 |
// |
389 |
if ( debug ) printf("-2 a Call FillTrkVar() \n"); |
390 |
event->FillTrkVar(pcalo,ntrkentry); |
391 |
ntrkentry++; |
392 |
filled = true; |
393 |
// |
394 |
} else { |
395 |
if ( debug ) printf(" Selftrigger: problems with event \n"); |
396 |
}; |
397 |
// |
398 |
}; |
399 |
// |
400 |
// self trigger event |
401 |
// |
402 |
// if ( st && event->clevel2->trigty >= 2. ){ |
403 |
if ( st && m1 ){ |
404 |
if ( debug ) printf(" Selftrigger event \n"); |
405 |
// |
406 |
// Disable "track mode" in the fortran routine |
407 |
// |
408 |
event->clevel1->good2 = 0; |
409 |
// |
410 |
// disable high enery nuclei flag; |
411 |
// |
412 |
event->clevel1->hzn = 0; |
413 |
// |
414 |
// We have a selftrigger event to analyze. |
415 |
// |
416 |
for (Int_t e = 0; e < 5 ; e++){ |
417 |
event->clevel1->al_p[e][0] = 0.; |
418 |
event->clevel1->al_p[e][1] = 0.; |
419 |
}; |
420 |
event->clevel1->trkchi2 = 0; |
421 |
// |
422 |
if ( debug ) printf("-1 a Call GetTrkVar() \n"); |
423 |
event->GetTrkVar(); |
424 |
// |
425 |
// if we had no problem (clevel2->good = 0, NOTICE zero, not one in selftrigger mode!), fill and go on |
426 |
// |
427 |
if ( event->clevel1->good2 == 0 ) { |
428 |
// |
429 |
// In selftrigger mode the trkentry variable is set to -1 |
430 |
// |
431 |
event->trkseqno = -1; |
432 |
// |
433 |
// Copy values in the class ca from the structure clevel2 |
434 |
// |
435 |
if ( debug ) printf("-1 a Call FillTrkVar() \n"); |
436 |
event->FillTrkVar(pcalo,ntrkentry); |
437 |
ntrkentry++; |
438 |
filled = true; |
439 |
// |
440 |
} else { |
441 |
if ( debug ) printf(" Selftrigger: problems with event \n"); |
442 |
}; |
443 |
}; |
444 |
// |
445 |
// Clear structures used to communicate with fortran |
446 |
// |
447 |
event->ClearStructs(); |
448 |
// |
449 |
// |
450 |
// |
451 |
if ( debug ) this->Print(); |
452 |
if ( debug ) printf(" exit \n"); |
453 |
// |
454 |
}; |