/[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.15 - (hide annotations) (download)
Wed Apr 4 07:23:27 2007 UTC (17 years, 8 months ago) by pam-de
Branch: MAIN
Changes since 1.14: +15 -6 lines
more Doxygen comments added

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

  ViewVC Help
Powered by ViewVC 1.1.23