/[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.4 - (show annotations) (download)
Thu Apr 5 13:38:32 2007 UTC (17 years, 9 months ago) by mocchiut
Branch: MAIN
Changes since 1.3: +28 -23 lines
Tuning and small bugs 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 //
27 };
28
29 void CaloNuclei::Clear(){
30 //
31 tr = 0;
32 interplane = 0;
33 preq = 0.;
34 postq = 0.;
35 dedx1 = 0.;
36 dedx3 = 0.;
37 qpremean = 0.;
38 qpremeanN = 0.;
39 //
40 multhit = false;
41 gap = false;
42 //
43 };
44
45 void CaloNuclei::Print(){
46 //
47 Process();
48 //
49 printf("========================================================================\n");
50 printf(" OBT: %u PKT: %u ATIME: %u Track %i \n",OBT,PKT,atime,tr);
51 printf(" interplane [number of available dE/dx before interaction]: %i\n",interplane);
52 printf(" ethr [threshold used to determine interplane]:............ %f \n",ethr);
53 printf(" dedx1 [dE/dx from the first calorimeter plane]:........... %f \n",dedx1);
54 printf(" dedx3 [dE/dx (average) if the first 3 Si planes]:......... %f \n",dedx3);
55 printf(" multhit [true if interplane determined by multiple hits]:. %i \n",multhit);
56 printf(" gap [true if interplane determined by a gap]:............. %i \n",gap);
57 printf(" preq [total energy in MIP before the interaction plane]:.. %f \n",preq);
58 printf(" postq [total energy in MIP after the interaction plane]:.. %f \n",postq);
59 printf(" qpremean [truncated mean using 3 planes and 3 strips]:.... %f \n",qpremean);
60 printf(" N [no of used plane]:..................................... %i \n",N);
61 printf(" R [no strip used per plane ]:............................. %i \n",R);
62 printf(" qpremeanN [truncated mean using N planes and R strips]:... %f \n",qpremeanN);
63 printf("========================================================================\n");
64 //
65 };
66
67 void CaloNuclei::Delete(){
68 Clear();
69 //delete this;
70 };
71
72
73 void CaloNuclei::Process(){
74 Process(0);
75 };
76
77 void CaloNuclei::Process(Int_t ntr){
78 //
79 if ( !L2 ){
80 printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n");
81 printf(" ERROR: CaloNuclei variables not filled \n");
82 return;
83 };
84 //
85 Bool_t newentry = false;
86 //
87 if ( L2->IsORB() ){
88 if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime ){
89 newentry = true;
90 OBT = L2->GetOrbitalInfo()->OBT;
91 PKT = L2->GetOrbitalInfo()->pkt_num;
92 atime = L2->GetOrbitalInfo()->absTime;
93 };
94 } else {
95 newentry = true;
96 };
97 //
98 if ( !newentry ) return;
99 //
100 tr = ntr;
101 //
102 if ( debug ) printf(" Processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime);
103 //
104 Clear();
105 //
106 PamTrack *track = 0;
107 track = L2->GetTrack(ntr);
108 //
109 Int_t view = 0;
110 Int_t plane = 0;
111 Int_t strip = 0;
112 Float_t mip = 0.;
113 // Float_t defethr = 6. * 0.90;
114 Float_t defethr = 6.25; // = (sqrt(9) - 0.5) ** 2.;
115 //
116 // Calculate dedx1 and dedx3
117 //
118 for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){
119 //
120 mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
121 //
122 if ( strip != -1 &&
123 view == 1 &&
124 plane == 0 &&
125 ( strip == (track->GetCaloTrack()->tibar[0][1]-1) || strip == (track->GetCaloTrack()->tibar[0][1]-2) || strip == (track->GetCaloTrack()->tibar[0][1]) )
126 && true ){
127 dedx1 += mip;
128 };
129 if ( strip != -1 &&
130 (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
131 ( view == 0 && plane == 0 )) &&
132 (( view == 0 && ( strip == track->GetCaloTrack()->tibar[0][0] || strip == (track->GetCaloTrack()->tibar[0][0]-1) || strip == (track->GetCaloTrack()->tibar[0][0]-2) )) ||
133 ( view == 1 && ( strip == track->GetCaloTrack()->tibar[0][1] || strip == (track->GetCaloTrack()->tibar[0][1]-1) || strip == (track->GetCaloTrack()->tibar[0][1]-2) )) ||
134 ( view == 1 && ( strip == track->GetCaloTrack()->tibar[1][1] || strip == (track->GetCaloTrack()->tibar[1][1]-1) || strip == (track->GetCaloTrack()->tibar[1][1]-2) ))) &&
135 true ){
136 dedx3 += mip;
137 };
138 //
139 };
140 //
141 dedx3 /= 3.;
142 // Float_t mesethr = dedx1 * 0.90;
143 Float_t mesethr = 0.;
144 if ( dedx1 > 0. ) mesethr = (sqrt(dedx1) - 0.50)*(sqrt(dedx1) - 0.50);
145 Bool_t aldone = false;
146 //
147 retry:
148 //
149 if ( debug ) printf("retry\n");
150 //
151 interplane = 0;
152 //
153 ethr = TMath::Max(defethr,mesethr);
154 //
155 // Find the interaction plane "interplane"
156 //
157 Int_t gapth = 3;
158 Int_t nhit[2] = {0,0};
159 Int_t splane[2] = {-1,-1};
160 Int_t sview[2] = {-1,-1};
161 Int_t interpl[2] = {-1,-1};
162 Int_t interv[2] = {-1,-1};
163 Bool_t wmulthit[2] = {false,false};
164 Bool_t wgap[2] = {false,false};
165 Int_t ii = 0;
166 while ( ii<L2->GetCaloLevel1()->istrip ){
167 //
168 mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);
169 //
170 if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
171 ( strip == (track->GetCaloTrack()->tibar[plane][view]-1) || strip == (track->GetCaloTrack()->tibar[plane][view]-2) || strip == (track->GetCaloTrack()->tibar[plane][view]) )
172 && true ){
173 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->GetCaloTrack()->tibar[plane][view]-1,nhit[view],splane[view],sview[view]);
174 interpl[view] = plane;
175 interv[view] = view;
176 if ( splane[view] != plane || sview[view] != view ){
177 if ( nhit[view] > 1 ){
178 wmulthit[view] = true;
179 // if ( splane[view] == -1 ) splane[view] = 0; //
180 // if ( sview[view] == -1 ) sview[view] = view; //
181 interpl[view] = splane[view];
182 interv[view] = sview[view];
183 };
184 if ( plane > splane[view]+gapth ){
185 wgap[view] = true;
186 // if ( splane[view] == -1 ) splane[view] = 0;//
187 // if ( sview[view] == -1 ) sview[view] = view; //
188 interpl[view] = splane[view];
189 interv[view] = sview[view];
190 };
191 splane[view] = plane;
192 sview[view] = view;
193 nhit[view] = 1;
194 } else {
195 nhit[view]++;
196 };
197 };
198 //
199 ii++;
200 //
201 };
202 //
203 if (debug ) printf("conversion interpl %i interv %i multhit %i interplane %i \n",interpl[0],interv[0],multhit,interplane);
204 Int_t winterplane[2] = {-1,-1};
205 //
206 for ( Int_t view = 0; view < 2; view++){
207 //
208 if ( nhit[view] > 1 && !wmulthit[view] && !wgap[view] ){
209 wmulthit[view] = true;
210 interpl[view] = splane[view];
211 interv[view] = sview[view];
212 };
213 //
214 if ( wmulthit[view] ) multhit = true;
215 if ( wgap[view] ) gap = true;
216 //
217 // convert view and plane number of interaction plane into number of available dE/dx measurements before the interaction plane
218 //
219 if ( interpl[view] >= 0 ) {
220 if ( interv[view] == 0 ){
221 winterplane[view] = (1 + interpl[view]) * 2;
222 } else {
223 winterplane[view] = (1 + interpl[view]) + (1 + interpl[view] - 1);
224 };
225 if ( wmulthit[view] ) winterplane[view]--;
226 };
227 };
228 if ( winterplane[0] > 0 && winterplane[1] > 0 ){
229 if ( multhit ){
230 interplane = TMath::Min(winterplane[0],winterplane[1]);
231 } else {
232 interplane = TMath::Max(winterplane[0],winterplane[1]);
233 };
234 } else {
235 if ( !winterplane[0] || !winterplane[1] ){
236 interplane = 0;
237 } else {
238 interplane = TMath::Max(winterplane[0],winterplane[1]);
239 };
240 };
241 //
242 if ( debug ) printf("2conversion interpl %i interv %i multhit %i interplane %i \n",interpl[1],interv[1],multhit,interplane);
243 if ( debug ) printf("3conversion winterpl0 %i winterpl1 %i \n",winterplane[0],winterplane[1]);
244 //
245 Int_t ipl = 0;
246 if ( interplane > 0 ){
247 //
248 // Calculate preq, postq, qpremean
249 //
250 ii = 0;
251 Int_t ind = -1;
252 Int_t qsplane = -1;
253 Int_t qsview = -1;
254 Int_t ind2 = -1;
255 Int_t qsplane2 = -1;
256 Int_t qsview2 = -1;
257 Float_t qme[200];
258 memset(qme,0,200*sizeof(Float_t));
259 Float_t qme2[2112];
260 memset(qme2,0,2112*sizeof(Float_t));
261 //
262 while ( ii<L2->GetCaloLevel1()->istrip ){
263 //
264 mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);
265 //
266 if ( strip != -1 ){
267 if ( view == 0 ){
268 ipl = (1 + plane) * 2;
269 } else {
270 ipl = (1 + plane) + (1 + plane - 1 );
271 };
272 if ( ipl > interplane ){
273 postq += mip;
274 } else {
275 preq += mip;
276 if ( strip == (track->GetCaloTrack()->tibar[plane][view]-1) || strip == (track->GetCaloTrack()->tibar[plane][view]-2) || strip == (track->GetCaloTrack()->tibar[plane][view]) ){
277 if ( qsplane != plane || qsview != view ){
278 qsplane = plane;
279 qsview = view;
280 ind++;
281 if ( debug && ind > 199 ) printf(" AAAGH!! \n");
282 qme[ind] = 0.;
283 };
284 qme[ind] += mip;
285 };
286 for ( Int_t ns = 0; ns < R ; ns++){
287 Int_t ms = track->GetCaloTrack()->tibar[plane][view] - 1 - ns + (R - 1)/2;
288 if ( strip == ms ){
289 if ( qsplane2 != plane || qsview2 != view ){
290 qsplane2 = plane;
291 qsview2 = view;
292 ind2++;
293 if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
294 qme2[ind2] = 0.;
295 };
296 qme2[ind2] += mip;
297 };
298 };
299 };
300 //
301 };
302 //
303 ii++;
304 //
305 };
306 //
307 // here we must calculate qpremean, order vector qme, select 3 lowest measurements and caculate the mean...
308 //
309 if ( debug ){
310 for (Int_t l=0; l < interplane; l++){
311 printf(" qme[%i] = %f \n",l,qme[l]);
312 };
313 };
314 //
315 Long64_t work[200];
316 ind = 0;
317 Int_t l = 0;
318 Float_t qm = 0.;
319 Float_t qm2 = 0.;
320 //
321 Float_t qmt = ethr*0.8; // *0.9
322 //
323 Int_t uplim = TMath::Max(3,N);
324 //
325 while ( l < uplim && ind < interplane ){
326 qm = TMath::KOrdStat(interplane,qme,ind,work);
327 if ( qm >= qmt ){
328 if ( l < 3 ) qpremean += qm;
329 l++;
330 if ( debug ) printf(" value no %i qm %f qmt %f \n",l,qm,qmt);
331 };
332 ind++;
333 };
334 //
335 qpremean /= l;
336 //
337 ind = 0;
338 l = 0;
339 while ( l < uplim && ind < interplane ){
340 qm2 = TMath::KOrdStat(interplane,qme2,ind,work);
341 if ( qm2 >= qmt ){
342 if ( l < N ) qpremeanN += qm2;
343 l++;
344 if ( debug ) printf(" qm2 value no %i qm %f qmt %f \n",l,qm2,qmt);
345 };
346 ind++;
347 };
348 //
349 qpremeanN /= l;
350 //
351 if ( debug ) printf(" charge is %f \n",sqrt(qpremean));
352 //
353 if ( mesethr != ethr && interplane >= 3 && !aldone ){
354 Float_t mesethr2 = (sqrt(qpremean) - 0.50)*(sqrt(qpremean) - 0.50);
355 if ( mesethr2 < mesethr*0.90 ){
356 mesethr = (sqrt(dedx1) - 0.25)*(sqrt(dedx1) - 0.25);
357 } else {
358 mesethr = mesethr2;
359 };
360 aldone = true;
361 if ( mesethr > defethr ) goto retry;
362 };
363 };
364 //
365 if ( debug ) printf(" esci \n");
366 //
367 };

  ViewVC Help
Powered by ViewVC 1.1.23