/[PAMELA software]/calo/flight/CaloNuclei/src/CaloNuclei.cpp
ViewVC logotype

Contents of /calo/flight/CaloNuclei/src/CaloNuclei.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations) (download)
Fri Sep 28 12:34:42 2007 UTC (17 years, 3 months ago) by mocchiut
Branch: MAIN
CVS Tags: v1r01
Changes since 1.9: +2 -0 lines
Bug in Get_StdEdx1() method fixed

1 #include <CaloNuclei.h>
2
3 //--------------------------------------
4 /**
5 * Default constructor
6 */
7 CaloNuclei::CaloNuclei(){
8 Clear();
9 };
10
11 CaloNuclei::CaloNuclei(PamLevel2 *l2p){
12 //
13 Clear();
14 //
15 L2 = l2p;
16 //
17 if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n");
18 //
19 OBT = 0;
20 PKT = 0;
21 atime = 0;
22 N = 5;
23 R = 3;
24 //
25 debug = false;
26 usetrack = true;
27 //
28 };
29
30 void CaloNuclei::Clear(){
31 //
32 tr = 0;
33 sntr = 0;
34 interplane = 0;
35 preq = 0.;
36 postq = 0.;
37 stdedx1 = 0.;
38 ethr = 0.;
39 dedx1 = 0.;
40 dedx3 = 0.;
41 qpremean = 0.;
42 qpremeanN = 0.;
43 //
44 multhit = false;
45 gap = false;
46 //
47 };
48
49 void CaloNuclei::Print(){
50 //
51 Process();
52 //
53 printf("========================================================================\n");
54 printf(" OBT: %u PKT: %u ATIME: %u Track %i Use track %i \n",OBT,PKT,atime,tr,usetrack);
55 printf(" interplane [number of available dE/dx before interaction]:.. %i\n",interplane);
56 printf(" ethr [threshold used to determine interplane]:.............. %f \n",ethr);
57 printf(" dedx1 [dE/dx from the first calorimeter plane]:............. %f \n",dedx1);
58 printf(" stdedx1 [dE/dx from the first calorimeter plane standalone]: %f \n",stdedx1);
59 printf(" dedx3 [dE/dx (average) if the first 3 Si planes]:........... %f \n",dedx3);
60 printf(" multhit [true if interplane determined by multiple hits]:... %i \n",multhit);
61 printf(" gap [true if interplane determined by a gap]:............... %i \n",gap);
62 printf(" preq [total energy in MIP before the interaction plane]:.... %f \n",preq);
63 printf(" postq [total energy in MIP after the interaction plane]:.... %f \n",postq);
64 printf(" qpremean [truncated mean using 3 planes and 3 strips]:...... %f \n",qpremean);
65 printf(" N [no of used plane]:....................................... %i \n",N);
66 printf(" R [no strip used per plane ]:............................... %i \n",R);
67 printf(" qpremeanN [truncated mean using N planes and R strips]:..... %f \n",qpremeanN);
68 printf("========================================================================\n");
69 //
70 };
71
72 void CaloNuclei::Delete(){
73 Clear();
74 //delete this;
75 };
76
77
78 void CaloNuclei::Process(){
79 Process(0);
80 };
81
82 void CaloNuclei::Process(Int_t ntr){
83 //
84 if ( !L2 ){
85 printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n");
86 printf(" ERROR: CaloNuclei variables not filled \n");
87 return;
88 };
89 //
90 Bool_t newentry = false;
91 //
92 if ( L2->IsORB() ){
93 if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || ntr != sntr ){
94 newentry = true;
95 OBT = L2->GetOrbitalInfo()->OBT;
96 PKT = L2->GetOrbitalInfo()->pkt_num;
97 atime = L2->GetOrbitalInfo()->absTime;
98 sntr = ntr;
99 };
100 } else {
101 newentry = true;
102 };
103 //
104 if ( !newentry ) return;
105 //
106 tr = ntr;
107 //
108 if ( debug ) printf(" Processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime);
109 //
110 Clear();
111 if ( debug ) printf(" Always calculate stdedx1 \n");
112 //
113 // Always calculate stdedx1
114 //
115 Int_t view = 0;
116 Int_t plane = 0;
117 Int_t strip = 0;
118 Int_t indx = 0;
119 Float_t vfpl[96];
120 Int_t stfpl[96];
121 memset(vfpl, 0, 96*sizeof(Float_t));
122 memset(stfpl, 0, 96*sizeof(Int_t));
123 Float_t mip = 0.;
124 for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){
125 //
126 mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
127 //
128 // put in vfpl vector the energy release on the first plane
129 //
130 if ( strip != -1 && view == 1 && plane == 0 ) {
131 stfpl[indx] = strip;
132 vfpl[indx] = mip;
133 indx++;
134 };
135 //
136 };
137 //
138 if ( debug ) printf(" find energy released along the strip of maximum on the first plane and on the two neighbour strips \n");
139 //
140 // find energy released along the strip of maximum on the first plane and on the two neighbour strips
141 //
142 if ( indx > 0 ){
143 Int_t mindx = (Int_t)TMath::LocMax(indx,stfpl);
144 for (Int_t ii=0; ii<indx; ii++){
145 if ( stfpl[ii] == stfpl[mindx] ) stdedx1 += vfpl[ii];
146 if ( (mindx-1)>=0 && stfpl[ii] == stfpl[mindx-1] ) stdedx1 += vfpl[ii];
147 if ( (mindx+1)<96 && stfpl[ii] == stfpl[mindx+1] ) stdedx1 += vfpl[ii];
148 };
149 } else {
150 stdedx1 = 0.;
151 };
152 //
153 if ( debug ) printf(" if ( !usetrack ) return: usetrack %i ntr %i \n",usetrack,ntr);
154 //
155 //
156 // if ( !usetrack ) return;
157 //
158 PamTrack *ptrack = 0;
159 CaloTrkVar *track = 0;
160 //
161 if ( usetrack ){
162 if ( ntr >= 0 ){
163 ptrack = L2->GetTrack(ntr);
164 if ( ptrack ) track = ptrack->GetCaloTrack();
165 } else {
166 track = L2->GetCaloStoredTrack(ntr);
167 };
168 //
169 if ( !track && ntr >= 0 ){
170 printf(" ERROR: cannot find any track!\n");
171 printf(" ERROR: CaloNuclei variables not completely filled \n");
172 return;
173 };
174 } else {
175 if ( ntr >= 0 ){
176 if ( debug ) printf(" ERROR: you asked not to use a track but you are looking for track number %i !\n",ntr);
177 if ( debug ) printf(" ERROR: CaloNuclei variables not completely filled \n");
178 return;
179 };
180 };
181 //
182 // Float_t defethr = 6. * 0.90;
183 Float_t defethr = 6.25; // = (sqrt(9) - 0.5) ** 2.;
184 //
185 // Calculate dedx1 and dedx3
186 //
187 for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){
188 //
189 mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
190 //
191 if ( ntr >= 0 ){
192 //
193 if ( strip != -1 &&
194 view == 1 &&
195 plane == 0 &&
196 ( strip == (track->tibar[0][1]-1) || strip == (track->tibar[0][1]-2) || strip == (track->tibar[0][1]) )
197 && true ){
198 dedx1 += mip;
199 };
200 if ( strip != -1 &&
201 (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
202 ( view == 0 && plane == 0 )) &&
203 (( view == 0 && ( strip == track->tibar[0][0] || strip == (track->tibar[0][0]-1) || strip == (track->tibar[0][0]-2) )) ||
204 ( view == 1 && ( strip == track->tibar[0][1] || strip == (track->tibar[0][1]-1) || strip == (track->tibar[0][1]-2) )) ||
205 ( view == 1 && ( strip == track->tibar[1][1] || strip == (track->tibar[1][1]-1) || strip == (track->tibar[1][1]-2) ))) &&
206 true ){
207 dedx3 += mip;
208 };
209 } else {
210 //
211 if ( strip != -1 &&
212 view == 1 &&
213 plane == 0 &&
214 ( strip == (L2->GetCaloLevel2()->cibar[0][1]-1) || strip == (L2->GetCaloLevel2()->cibar[0][1]-2) || strip == (L2->GetCaloLevel2()->cibar[0][1]) )
215 && true ){
216 dedx1 += mip;
217 };
218 if ( strip != -1 &&
219 (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
220 ( view == 0 && plane == 0 )) &&
221 (( view == 0 && ( strip == L2->GetCaloLevel2()->cibar[0][0] || strip == (L2->GetCaloLevel2()->cibar[0][0]-1) || strip == (L2->GetCaloLevel2()->cibar[0][0]-2) )) ||
222 ( view == 1 && ( strip == L2->GetCaloLevel2()->cibar[0][1] || strip == (L2->GetCaloLevel2()->cibar[0][1]-1) || strip == (L2->GetCaloLevel2()->cibar[0][1]-2) )) ||
223 ( view == 1 && ( strip == L2->GetCaloLevel2()->cibar[1][1] || strip == (L2->GetCaloLevel2()->cibar[1][1]-1) || strip == (L2->GetCaloLevel2()->cibar[1][1]-2) ))) &&
224 true ){
225 dedx3 += mip;
226 };
227 };
228 //
229 };
230 //
231 dedx3 /= 3.;
232 // Float_t mesethr = dedx1 * 0.90;
233 Float_t mesethr = 0.;
234 if ( dedx1 > 0. ) mesethr = (sqrt(dedx1) - 0.50)*(sqrt(dedx1) - 0.50);
235 Bool_t aldone = false;
236 //
237 retry:
238 //
239 if ( debug ) printf("retry\n");
240 //
241 interplane = 0;
242 //
243 ethr = TMath::Max(defethr,mesethr);
244 //
245 // Find the interaction plane "interplane"
246 //
247 Int_t gapth = 3;
248 Int_t nhit[2] = {0,0};
249 Int_t splane[2] = {-1,-1};
250 Int_t sview[2] = {-1,-1};
251 Int_t interpl[2] = {-1,-1};
252 Int_t interv[2] = {-1,-1};
253 Bool_t wmulthit[2] = {false,false};
254 Bool_t wgap[2] = {false,false};
255 Int_t ii = 0;
256 while ( ii<L2->GetCaloLevel1()->istrip ){
257 //
258 mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);
259 //
260 if ( ntr >= 0 ){
261 if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
262 ( strip == (track->tibar[plane][view]-1) || strip == (track->tibar[plane][view]-2) || strip == (track->tibar[plane][view]) )
263 && true ){
264 if ( debug ) printf(" inside loop: ii %i mip %f view %i plane %i strip %i tibar %i nhit %i splane %i sview %i \n",ii,mip,view,plane,strip,track->tibar[plane][view]-1,nhit[view],splane[view],sview[view]);
265 interpl[view] = plane;
266 interv[view] = view;
267 if ( splane[view] != plane || sview[view] != view ){
268 if ( nhit[view] > 1 ){
269 wmulthit[view] = true;
270 // if ( splane[view] == -1 ) splane[view] = 0; //
271 // if ( sview[view] == -1 ) sview[view] = view; //
272 interpl[view] = splane[view];
273 interv[view] = sview[view];
274 };
275 if ( plane > splane[view]+gapth ){
276 wgap[view] = true;
277 // if ( splane[view] == -1 ) splane[view] = 0;//
278 // if ( sview[view] == -1 ) sview[view] = view; //
279 interpl[view] = splane[view];
280 interv[view] = sview[view];
281 };
282 splane[view] = plane;
283 sview[view] = view;
284 nhit[view] = 1;
285 } else {
286 nhit[view]++;
287 };
288 };
289 } else {
290 if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
291 ( strip == (L2->GetCaloLevel2()->cibar[plane][view]-1) || strip == (L2->GetCaloLevel2()->cibar[plane][view]-2) || strip == (L2->GetCaloLevel2()->cibar[plane][view]) )
292 && true ){
293 if ( debug ) printf(" inside loop: ii %i mip %f view %i plane %i strip %i cibar %i nhit %i splane %i sview %i \n",ii,mip,view,plane,strip,L2->GetCaloLevel2()->cibar[plane][view]-1,nhit[view],splane[view],sview[view]);
294 interpl[view] = plane;
295 interv[view] = view;
296 if ( splane[view] != plane || sview[view] != view ){
297 if ( nhit[view] > 1 ){
298 wmulthit[view] = true;
299 // if ( splane[view] == -1 ) splane[view] = 0; //
300 // if ( sview[view] == -1 ) sview[view] = view; //
301 interpl[view] = splane[view];
302 interv[view] = sview[view];
303 };
304 if ( plane > splane[view]+gapth ){
305 wgap[view] = true;
306 // if ( splane[view] == -1 ) splane[view] = 0;//
307 // if ( sview[view] == -1 ) sview[view] = view; //
308 interpl[view] = splane[view];
309 interv[view] = sview[view];
310 };
311 splane[view] = plane;
312 sview[view] = view;
313 nhit[view] = 1;
314 } else {
315 nhit[view]++;
316 };
317 };
318 };
319 //
320 ii++;
321 //
322 };
323 //
324 if (debug ) printf("conversion interpl %i interv %i multhit %i interplane %i \n",interpl[0],interv[0],multhit,interplane);
325 Int_t winterplane[2] = {-1,-1};
326 //
327 for ( Int_t view = 0; view < 2; view++){
328 //
329 if ( nhit[view] > 1 && !wmulthit[view] && !wgap[view] ){
330 wmulthit[view] = true;
331 interpl[view] = splane[view];
332 interv[view] = sview[view];
333 };
334 //
335 if ( wmulthit[view] ) multhit = true;
336 if ( wgap[view] ) gap = true;
337 //
338 // convert view and plane number of interaction plane into number of available dE/dx measurements before the interaction plane
339 //
340 if ( interpl[view] >= 0 ) {
341 if ( interv[view] == 0 ){
342 winterplane[view] = (1 + interpl[view]) * 2;
343 } else {
344 winterplane[view] = (1 + interpl[view]) + (1 + interpl[view] - 1);
345 };
346 if ( wmulthit[view] ) winterplane[view]--;
347 };
348 };
349 if ( winterplane[0] > 0 && winterplane[1] > 0 ){
350 if ( multhit ){
351 interplane = TMath::Min(winterplane[0],winterplane[1]);
352 } else {
353 interplane = TMath::Max(winterplane[0],winterplane[1]);
354 };
355 } else {
356 if ( !winterplane[0] || !winterplane[1] ){
357 interplane = 0;
358 } else {
359 interplane = TMath::Max(winterplane[0],winterplane[1]);
360 };
361 };
362 //
363 if ( debug ) printf("2conversion interpl %i interv %i multhit %i interplane %i \n",interpl[1],interv[1],multhit,interplane);
364 if ( debug ) printf("3conversion winterpl0 %i winterpl1 %i \n",winterplane[0],winterplane[1]);
365 //
366 Int_t ipl = 0;
367 if ( interplane > 0 ){
368 //
369 // Calculate preq, postq, qpremean
370 //
371 ii = 0;
372 Int_t ind = -1;
373 Int_t qsplane = -1;
374 Int_t qsview = -1;
375 Int_t ind2 = -1;
376 Int_t qsplane2 = -1;
377 Int_t qsview2 = -1;
378 Float_t qme[200];
379 memset(qme,0,200*sizeof(Float_t));
380 Float_t qme2[2112];
381 memset(qme2,0,2112*sizeof(Float_t));
382 //
383 while ( ii<L2->GetCaloLevel1()->istrip ){
384 //
385 mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);
386 //
387 if ( strip != -1 ){
388 if ( view == 0 ){
389 ipl = (1 + plane) * 2;
390 } else {
391 ipl = (1 + plane) + (1 + plane - 1 );
392 };
393 if ( ipl > interplane ){
394 postq += mip;
395 } else {
396 preq += mip;
397 if ( ntr >= 0 ){
398 if ( strip == (track->tibar[plane][view]-1) || strip == (track->tibar[plane][view]-2) || strip == (track->tibar[plane][view]) ){
399 if ( qsplane != plane || qsview != view ){
400 qsplane = plane;
401 qsview = view;
402 ind++;
403 if ( debug && ind > 199 ) printf(" AAAGH!! \n");
404 qme[ind] = 0.;
405 };
406 qme[ind] += mip;
407 };
408 for ( Int_t ns = 0; ns < R ; ns++){
409 Int_t ms = track->tibar[plane][view] - 1 - ns + (R - 1)/2;
410 if ( strip == ms ){
411 if ( qsplane2 != plane || qsview2 != view ){
412 qsplane2 = plane;
413 qsview2 = view;
414 ind2++;
415 if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
416 qme2[ind2] = 0.;
417 };
418 qme2[ind2] += mip;
419 };
420 };
421 } else {
422 if ( strip == (L2->GetCaloLevel2()->cibar[plane][view]-1) || strip == (L2->GetCaloLevel2()->cibar[plane][view]-2) || strip == (L2->GetCaloLevel2()->cibar[plane][view]) ){
423 if ( qsplane != plane || qsview != view ){
424 qsplane = plane;
425 qsview = view;
426 ind++;
427 if ( debug && ind > 199 ) printf(" AAAGH!! \n");
428 qme[ind] = 0.;
429 };
430 qme[ind] += mip;
431 };
432 for ( Int_t ns = 0; ns < R ; ns++){
433 Int_t ms = L2->GetCaloLevel2()->cibar[plane][view] - 1 - ns + (R - 1)/2;
434 if ( strip == ms ){
435 if ( qsplane2 != plane || qsview2 != view ){
436 qsplane2 = plane;
437 qsview2 = view;
438 ind2++;
439 if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
440 qme2[ind2] = 0.;
441 };
442 qme2[ind2] += mip;
443 };
444 };
445 };
446 };
447 //
448 };
449 //
450 ii++;
451 //
452 };
453 //
454 // here we must calculate qpremean, order vector qme, select 3 lowest measurements and caculate the mean...
455 //
456 if ( debug ){
457 for (Int_t l=0; l < interplane; l++){
458 printf(" qme[%i] = %f \n",l,qme[l]);
459 };
460 };
461 //
462 Long64_t work[200];
463 ind = 0;
464 Int_t l = 0;
465 Int_t RN = 0;
466 Float_t qm = 0.;
467 Float_t qm2 = 0.;
468 //
469 Float_t qmt = ethr*0.8; // *0.9
470 //
471 Int_t uplim = TMath::Max(3,N);
472 //
473 while ( l < uplim && ind < interplane ){
474 qm = TMath::KOrdStat(interplane,qme,ind,work);
475 if ( qm >= qmt ){
476 if ( l < 3 ){
477 qpremean += qm;
478 RN++;
479 };
480 l++;
481 if ( debug ) printf(" value no %i qm %f qmt %f \n",l,qm,qmt);
482 };
483 ind++;
484 };
485 //
486 qpremean /= (Float_t)RN;
487 //
488 ind = 0;
489 l = 0;
490 RN = 0;
491 while ( l < uplim && ind < interplane ){
492 qm2 = TMath::KOrdStat(interplane,qme2,ind,work);
493 if ( qm2 >= qmt ){
494 if ( l < N ){
495 qpremeanN += qm2;
496 RN++;
497 };
498 l++;
499 if ( debug ) printf(" qm2 value no %i qm %f qmt %f RN %i \n",l,qm2,qmt,RN);
500 };
501 ind++;
502 };
503 //
504 qpremeanN /= (Float_t)RN;
505 //
506 if ( debug ) printf(" charge is %f \n",sqrt(qpremean));
507 //
508 if ( mesethr != ethr && interplane >= 3 && !aldone ){
509 Float_t mesethr2 = (sqrt(qpremean) - 0.50)*(sqrt(qpremean) - 0.50);
510 if ( mesethr2 < mesethr*0.90 ){
511 mesethr = (sqrt(dedx1) - 0.25)*(sqrt(dedx1) - 0.25);
512 } else {
513 mesethr = mesethr2;
514 };
515 aldone = true;
516 if ( mesethr > defethr ){
517 interplane = 0;
518 preq = 0.;
519 postq = 0.;
520 qpremean = 0.;
521 qpremeanN = 0.;
522 multhit = false;
523 gap = false;
524 goto retry;
525 };
526 };
527 };
528 //
529 if ( debug ) this->Print();
530 if ( debug ) printf(" esci \n");
531 //
532 };

  ViewVC Help
Powered by ViewVC 1.1.23