/[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.5 - (show annotations) (download)
Thu May 24 07:50:48 2007 UTC (17 years, 8 months ago) by mocchiut
Branch: MAIN
Changes since 1.4: +221 -80 lines
Small upgrade

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

  ViewVC Help
Powered by ViewVC 1.1.23