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

  ViewVC Help
Powered by ViewVC 1.1.23