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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Wed Apr 4 11:31:27 2007 UTC (17 years, 8 months ago) by mocchiut
Branch: MAIN
Changes since 1.2: +12 -5 lines
Small changes in name of methods, added Process(track) method and example.cpp file

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

  ViewVC Help
Powered by ViewVC 1.1.23