/[PAMELA software]/DarthVader/ToFLevel2/src/ToFLevel2.cpp
ViewVC logotype

Annotation of /DarthVader/ToFLevel2/src/ToFLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Thu Nov 30 15:44:55 2006 UTC (18 years ago) by mocchiut
Branch: MAIN
CVS Tags: v2r01
Changes since 1.8: +11 -2 lines
ToF upgrade (Gianfranca 06/11/30)

1 mocchiut 1.1 #include <TObject.h>
2     #include <ToFLevel2.h>
3     #include <iostream>
4     using namespace std;
5 mocchiut 1.4 ClassImp(ToFPMT);
6 mocchiut 1.1 ClassImp(ToFTrkVar);
7     ClassImp(ToFLevel2);
8    
9 mocchiut 1.4 ToFPMT::ToFPMT(){
10     pmt_id = 0;
11     adc = 0.;
12     tdc_tw = 0.;
13     }
14    
15     ToFPMT::ToFPMT(const ToFPMT &t){
16     pmt_id = t.pmt_id;
17     adc = t.adc;
18     tdc_tw = t.tdc_tw;
19     }
20    
21     void ToFPMT::Clear(){
22     pmt_id = 0;
23     adc = 0.;
24     tdc_tw = 0.;
25     }
26    
27    
28    
29 mocchiut 1.1 ToFTrkVar::ToFTrkVar() {
30 mocchiut 1.4 trkseqno = 0;
31     npmttdc = 0;
32     npmtadc = 0;
33     pmttdc = TArrayI(48);
34     pmtadc = TArrayI(48);
35 mocchiut 1.9 tdcflag = TArrayI(48); // gf: 30 Nov 2006
36     adcflag = TArrayI(48); // gf: 30 Nov 2006
37 mocchiut 1.4 dedx = TArrayF(48);
38     //
39     //
40     memset(beta, 0, 13*sizeof(Float_t));
41     memset(xtofpos, 0, 3*sizeof(Float_t));
42     memset(ytofpos, 0, 3*sizeof(Float_t));
43     //
44     };
45 mocchiut 1.1
46 mocchiut 1.4 void ToFTrkVar::Clear() {
47 mocchiut 1.1 trkseqno = 0;
48 mocchiut 1.4 npmttdc = 0;
49     npmtadc = 0;
50     pmttdc.Reset();
51     pmtadc.Reset();
52 mocchiut 1.9 tdcflag.Reset(); // gf: 30 Nov 2006
53     adcflag.Reset(); // gf: 30 Nov 2006
54 mocchiut 1.4 dedx.Reset();
55     //
56     memset(beta, 0, 13*sizeof(Float_t));
57     memset(xtofpos, 0, 3*sizeof(Float_t));
58     memset(ytofpos, 0, 3*sizeof(Float_t));
59     //
60     };
61 mocchiut 1.1
62     ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){
63    
64     trkseqno = t.trkseqno;
65 mocchiut 1.4 //
66     npmttdc = t.npmttdc;
67     npmtadc = t.npmtadc;
68     (t.pmttdc).Copy(pmttdc);
69     (t.pmtadc).Copy(pmtadc);
70 mocchiut 1.9 (t.tdcflag).Copy(tdcflag); // gf: 30 Nov 2006
71     (t.adcflag).Copy(adcflag); // gf: 30 Nov 2006
72 mocchiut 1.4 (t.dedx).Copy(dedx);
73     //
74     memcpy(beta,t.beta,sizeof(beta));
75     memcpy(xtofpos,t.xtofpos,sizeof(xtofpos));
76     memcpy(ytofpos,t.ytofpos,sizeof(ytofpos));
77     //
78     };
79 mocchiut 1.1
80     ToFLevel2::ToFLevel2() {
81     //
82 mocchiut 1.4 PMT = new TClonesArray("ToFPMT",12);
83     ToFTrk = new TClonesArray("ToFTrkVar",2);
84 mocchiut 1.1 //
85 mocchiut 1.8 this->Clear();
86     //
87 mocchiut 1.3 };
88    
89     void ToFLevel2::Clear(){
90     //
91     ToFTrk->Clear();
92 mocchiut 1.4 PMT->Clear();
93     memset(tof_j_flag, 0, 6*sizeof(Int_t));
94 mocchiut 1.8 unpackError = 0;
95 mocchiut 1.4 //
96 mocchiut 1.1 };
97    
98     ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){
99     //
100     if(itrk >= ntrk()){
101     printf(" ToFLevel2 ERROR: track related variables set %i does not exists! \n",itrk);
102     printf(" stored track related variables = %i \n",ntrk());
103     return(NULL);
104     }
105     //
106     TClonesArray &t = *(ToFTrk);
107     ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];
108     return toftrack;
109     }
110 mocchiut 1.4
111     ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){
112     //
113     if(ihit >= npmt()){
114     printf(" ToFLevel2 ERROR: pmt variables set %i does not exists! \n",ihit);
115     printf(" stored pmt variables = %i \n",npmt());
116     return(NULL);
117     }
118     //
119     TClonesArray &t = *(PMT);
120     ToFPMT *tofpmt = (ToFPMT*)t[ihit];
121     return tofpmt;
122     }
123 mocchiut 1.1 //--------------------------------------
124     //
125     //
126     //--------------------------------------
127     /**
128 mocchiut 1.4 * Method to get the plane ID (11 12 21 22 31 32) from the plane index (0 1 2 3 4 5)
129 mocchiut 1.1 */
130     Int_t ToFLevel2::GetToFPlaneID(Int_t ip){
131     if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1;
132     else return -1;
133     };
134     /**
135 mocchiut 1.4 * Method to get the plane index (0 1 2 3 4 5) from the plane ID (11 12 21 22 31 32)
136 mocchiut 1.1 */
137     Int_t ToFLevel2::GetToFPlaneIndex(Int_t plane_id){
138     if(
139     plane_id == 11 ||
140     plane_id == 12 ||
141     plane_id == 21 ||
142     plane_id == 22 ||
143     plane_id == 31 ||
144     plane_id == 32 ||
145     false)return (Int_t)(plane_id/10)*2-1- plane_id%2;
146     else return -1;
147     };
148     /**
149     * Method to know if a given ToF paddle was hit, that is there is a TDC signal from both PMTs
150     * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
151     * @param paddle_id Paddle ID.
152     * @return 1 if the paddle was hit.
153     */
154     Bool_t ToFLevel2::HitPaddle(Int_t plane, Int_t paddle_id){ //<<< NEW
155     Int_t ip = -1;
156     if (plane>=6 ) ip = GetToFPlaneIndex(plane);
157     else if(plane>=0 && plane < 6) ip = plane;
158     Int_t flag=0;
159 mocchiut 1.2 if(ip != -1)flag = tof_j_flag[ip] & (int)pow(2.,(double)paddle_id);
160 mocchiut 1.1 if(
161     (ip == 0 && paddle_id < 8 && flag) ||
162     (ip == 1 && paddle_id < 6 && flag) ||
163     (ip == 2 && paddle_id < 2 && flag) ||
164     (ip == 3 && paddle_id < 2 && flag) ||
165     (ip == 4 && paddle_id < 3 && flag) ||
166     (ip == 5 && paddle_id < 3 && flag) ||
167     false) return true;
168     else return false;
169     };
170     /**
171     * Method to get the number of hit paddles on a ToF plane.
172     * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
173     */
174     Int_t ToFLevel2::GetNHitPaddles(Int_t plane){
175     Int_t npad=0;
176     for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i);
177     return npad;
178     };
179 mocchiut 1.4
180    
181     Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane){
182     Float_t dedx = 0.;
183     Int_t ip = 0;
184     Int_t pmt_id = 0;
185     Int_t pl = 0;
186     if ( plane >= 6 ){
187     ip = GetToFPlaneIndex(plane);
188     } else {
189     ip = plane;
190     };
191     //
192     ToFTrkVar *trk = GetToFTrkVar(notrack);
193     //
194     for (Int_t i=0; i<trk->npmtadc; i++){
195     //
196     pmt_id = (trk->pmtadc).At(i);
197     //
198     pl = GetPlaneIndex(pmt_id);
199     //
200     if ( pl == ip ) dedx += (trk->dedx).At(i);
201     //
202     };
203     //
204     return(dedx);
205     };
206    
207    
208     void ToFLevel2::GetMatrix(Int_t notrack, Float_t adc[4][12], Float_t tdc[4][12]){
209     //
210     for (Int_t aa=0; aa<4;aa++){
211     for (Int_t bb=0; bb<12;bb++){
212     adc[aa][bb] = 1000.;
213     tdc[aa][bb] = 4095.;
214     };
215     };
216     //
217     Int_t pmt_id = 0;
218     Int_t hh = 0;
219     Int_t kk = 0;
220     //
221     ToFTrkVar *trk = GetToFTrkVar(notrack);
222     //
223     for (Int_t i=0; i<trk->npmtadc; i++){
224     //
225     pmt_id = (trk->pmtadc).At(i);
226     //
227     GetPMTIndex(pmt_id,hh,kk);
228 mocchiut 1.5 adc[kk][hh] = (trk->dedx).At(i);
229 mocchiut 1.4 //
230     };
231     //
232     for (Int_t i=0; i<npmt(); i++){
233     //
234     ToFPMT *pmt = GetToFPMT(i);
235     //
236     GetPMTIndex(pmt->pmt_id,hh,kk);
237     //
238 mocchiut 1.5 tdc[kk][hh] = pmt->tdc_tw;
239 mocchiut 1.4 //
240     };
241     //
242     return;
243     };
244    
245    
246    
247     Int_t ToFLevel2::GetPlaneIndex(Int_t pmt_id){
248     TString pmtname = GetPMTName(pmt_id);
249     pmtname.Resize(3);
250     if ( !strcmp(pmtname,"S11") ) return(0);
251     if ( !strcmp(pmtname,"S12") ) return(1);
252     if ( !strcmp(pmtname,"S21") ) return(2);
253     if ( !strcmp(pmtname,"S22") ) return(3);
254     if ( !strcmp(pmtname,"S31") ) return(4);
255     if ( !strcmp(pmtname,"S32") ) return(5);
256     return(-1);
257     };
258    
259    
260     Int_t ToFLevel2::GetPMTid(Int_t hh, Int_t kk){
261     //
262     short tof[4][24] = {
263     {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
264     {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
265     {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
266     {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
267     };
268     //
269     Int_t ind = 0;
270     Int_t k = 0;
271     while (k < 24){
272     Int_t j = 0;
273     while (j < 2){
274     Int_t ch = tof[2*j][k] - 1;
275     Int_t hb = tof[2*j + 1][k] - 1;
276     /* tofEvent->tdc[ch][hb] */
277     if( ch == hh && hb == kk ){
278     ind = 2*k + j;
279     break;
280     };
281     j++;
282     };
283     k++;
284     };
285     return ind;
286     };
287    
288     TString ToFLevel2::GetPMTName(Int_t ind){
289    
290     TString pmtname = " ";
291    
292     TString photoS[48] = {
293     "S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A", "S11_4B",
294     "S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A", "S11_8B",
295     "S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A", "S12_4B", "S12_5A", "S12_5B", "S12_6A", "S12_6B",
296     "S21_1A", "S21_1B", "S21_2A", "S21_2B",
297     "S22_1A", "S22_1B", "S22_2A", "S22_2B",
298     "S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B",
299     "S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B"
300     };
301    
302    
303     pmtname = photoS[ind].Data();
304    
305     return pmtname;
306     };
307    
308    
309 mocchiut 1.5 void ToFLevel2::GetPMTIndex(Int_t ind, Int_t &hb, Int_t &ch){
310 mocchiut 1.4 //
311     short tof[4][24] = {
312     {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
313     {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
314     {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
315     {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
316     };
317     //
318     Int_t k = 0;
319     while (k < 24){
320     Int_t j = 0;
321     while (j < 2){
322 mocchiut 1.5 /* tofEvent->tdc[ch][hb] */
323 mocchiut 1.4 if( ind == 2*k + j ){
324 mocchiut 1.5 ch = tof[2*j][k] - 1;
325     hb = tof[2*j + 1][k] - 1;
326     return;
327 mocchiut 1.4 };
328     j++;
329     };
330     k++;
331     };
332     return;
333     };
334 pam-fi 1.6
335     /**
336     * Fills a struct cToFLevel2 with values from a ToFLevel2 object (to put data into a F77 common).
337     */
338     void ToFLevel2::GetLevel2Struct(cToFLevel2 *l2) const{
339    
340     for(Int_t i=0;i<6;i++)
341     l2->tof_j_flag[i]=tof_j_flag[i];
342    
343     l2->ntoftrk = ToFTrk->GetEntries();
344     for(Int_t j=0;j<l2->ntoftrk;j++){
345 mocchiut 1.7 l2->toftrkseqno[j]= ((ToFTrkVar*)ToFTrk->At(j))->trkseqno;
346 pam-fi 1.6 l2->npmttdc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmttdc;
347 mocchiut 1.9 for(Int_t i=0;i<l2->npmttdc[j];i++){
348 pam-fi 1.6 l2->pmttdc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmttdc.At(i);
349 mocchiut 1.9 l2->tdcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->tdcflag.At(i); // gf: 30 Nov 2006
350     }
351 pam-fi 1.6 for(Int_t i=0;i<13;i++)
352     l2->beta[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->beta[i];
353 mocchiut 1.9
354 pam-fi 1.6 l2->npmtadc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmtadc;
355     for(Int_t i=0;i<l2->npmtadc[j];i++){
356     l2->pmtadc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmtadc.At(i);
357 mocchiut 1.9 l2->adcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->adcflag.At(i); // gf: 30 Nov 2006
358 pam-fi 1.6 l2->dedx[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->dedx.At(i);
359     }
360     for(Int_t i=0;i<3;i++){
361     l2->xtofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtofpos[i];
362     l2->ytofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytofpos[i];
363     }
364     }
365    
366     l2->npmt = PMT->GetEntries();
367     for(Int_t j=0;j<l2->npmt;j++){
368     l2->pmt_id[j] = ((ToFPMT*)PMT->At(j))->pmt_id;
369     l2->adc[j] =((ToFPMT*)PMT->At(j))->adc;
370     l2->tdc_tw[j] =((ToFPMT*)PMT->At(j))->tdc_tw;
371     }
372     }

  ViewVC Help
Powered by ViewVC 1.1.23