/[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.8 - (hide annotations) (download)
Thu Nov 9 17:05:48 2006 UTC (18 years, 1 month ago) by mocchiut
Branch: MAIN
Changes since 1.7: +3 -1 lines
Added unpackError in all classes, ToF .rz bug fixed, install_GL_PARAM time screw bug fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23