/[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.43 - (hide annotations) (download)
Thu Feb 26 11:27:35 2015 UTC (10 years ago) by mocchiut
Branch: MAIN
Changes since 1.42: +62 -249 lines
Bug in ToFLevel2::GetdEdx method fixed, overloading of ToFLevel2::GetdEdx method implemented with a better construction

1 pam-de 1.14 /**
2     * \file ToFLevel2.cpp
3     * \author Gianfranca DeRosa, Wolfgang Menn
4 pamelats 1.23 *
5     * WM dec 2008: Description of "GetdEdx" changed
6     * WM dec 2008: "GetdEdxPaddle" modified: Now includes saturation limit
7     * PMTs higher than the saturation limit are not used for dEdx
8 pamelats 1.25 * WM apr 2009: bug found by Nicola in method "GetPaddlePlane"
9 pam-de 1.14 */
10    
11 mocchiut 1.1 #include <ToFLevel2.h>
12     using namespace std;
13 mocchiut 1.4 ClassImp(ToFPMT);
14 carbone 1.26 ClassImp(ToFdEdx);
15     ClassImp(ToFGeom);
16 mocchiut 1.1 ClassImp(ToFTrkVar);
17     ClassImp(ToFLevel2);
18    
19 mocchiut 1.4 ToFPMT::ToFPMT(){
20     pmt_id = 0;
21     adc = 0.;
22     tdc_tw = 0.;
23 mocchiut 1.17 tdc = 0.;
24 mocchiut 1.36 l0flag_adc = 0.;
25     l0flag_tdc = 0.;
26 mocchiut 1.4 }
27    
28     ToFPMT::ToFPMT(const ToFPMT &t){
29     pmt_id = t.pmt_id;
30     adc = t.adc;
31     tdc_tw = t.tdc_tw;
32 mocchiut 1.17 tdc = t.tdc;
33 mocchiut 1.4 }
34    
35 mocchiut 1.18 void ToFPMT::Clear(Option_t *t){
36 mocchiut 1.4 pmt_id = 0;
37     adc = 0.;
38     tdc_tw = 0.;
39 mocchiut 1.17 tdc = 0.;
40 mocchiut 1.4 }
41    
42    
43    
44 mocchiut 1.1 ToFTrkVar::ToFTrkVar() {
45 mocchiut 1.4 trkseqno = 0;
46     npmttdc = 0;
47     npmtadc = 0;
48     pmttdc = TArrayI(48);
49     pmtadc = TArrayI(48);
50 mocchiut 1.9 tdcflag = TArrayI(48); // gf: 30 Nov 2006
51     adcflag = TArrayI(48); // gf: 30 Nov 2006
52 mocchiut 1.4 dedx = TArrayF(48);
53     //
54     //
55     memset(beta, 0, 13*sizeof(Float_t));
56     memset(xtofpos, 0, 3*sizeof(Float_t));
57     memset(ytofpos, 0, 3*sizeof(Float_t));
58 mocchiut 1.16 memset(xtr_tof, 0, 6*sizeof(Float_t));
59     memset(ytr_tof, 0, 6*sizeof(Float_t));
60 mocchiut 1.4 //
61     };
62 mocchiut 1.1
63 mocchiut 1.18 void ToFTrkVar::Clear(Option_t *t) {
64 mocchiut 1.1 trkseqno = 0;
65 mocchiut 1.4 npmttdc = 0;
66     npmtadc = 0;
67     pmttdc.Reset();
68     pmtadc.Reset();
69 mocchiut 1.9 tdcflag.Reset(); // gf: 30 Nov 2006
70     adcflag.Reset(); // gf: 30 Nov 2006
71 mocchiut 1.4 dedx.Reset();
72     //
73     memset(beta, 0, 13*sizeof(Float_t));
74     memset(xtofpos, 0, 3*sizeof(Float_t));
75     memset(ytofpos, 0, 3*sizeof(Float_t));
76 mocchiut 1.16 memset(xtr_tof, 0, 6*sizeof(Float_t));
77     memset(ytr_tof, 0, 6*sizeof(Float_t));
78 mocchiut 1.4 //
79     };
80 mocchiut 1.1
81     ToFTrkVar::ToFTrkVar(const ToFTrkVar &t){
82    
83     trkseqno = t.trkseqno;
84 mocchiut 1.4 //
85     npmttdc = t.npmttdc;
86     npmtadc = t.npmtadc;
87     (t.pmttdc).Copy(pmttdc);
88     (t.pmtadc).Copy(pmtadc);
89 mocchiut 1.9 (t.tdcflag).Copy(tdcflag); // gf: 30 Nov 2006
90     (t.adcflag).Copy(adcflag); // gf: 30 Nov 2006
91 mocchiut 1.4 (t.dedx).Copy(dedx);
92     //
93     memcpy(beta,t.beta,sizeof(beta));
94     memcpy(xtofpos,t.xtofpos,sizeof(xtofpos));
95     memcpy(ytofpos,t.ytofpos,sizeof(ytofpos));
96 mocchiut 1.16 memcpy(xtr_tof,t.xtr_tof,sizeof(xtr_tof));
97     memcpy(ytr_tof,t.ytr_tof,sizeof(ytr_tof));
98 mocchiut 1.4 //
99     };
100 mocchiut 1.1
101     ToFLevel2::ToFLevel2() {
102     //
103 mocchiut 1.13 // PMT = new TClonesArray("ToFPMT",12); //ELENA
104     // ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
105     PMT = 0; //ELENA
106     ToFTrk = 0; //ELENA
107 mocchiut 1.1 //
108 mocchiut 1.8 this->Clear();
109     //
110 mocchiut 1.3 };
111    
112 mocchiut 1.13 void ToFLevel2::Set(){//ELENA
113     if(!PMT)PMT = new TClonesArray("ToFPMT",12); //ELENA
114     if(!ToFTrk)ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
115     }//ELENA
116 pam-fi 1.42 //--------------------------------------
117     //
118     //
119     //--------------------------------------
120     void ToFLevel2::SetTrackArray(TClonesArray *track){//ELENA
121     if(track && strcmp(track->GetClass()->GetName(),"ToFTrkVar")==0){
122     if(ToFTrk)ToFTrk->Clear("C");
123     ToFTrk = track;
124     }
125     }
126 mocchiut 1.13
127 mocchiut 1.18 void ToFLevel2::Clear(Option_t *t){
128 mocchiut 1.3 //
129 mocchiut 1.13 if(ToFTrk)ToFTrk->Delete(); //ELENA
130     if(PMT)PMT->Delete(); //ELENA
131 mocchiut 1.4 memset(tof_j_flag, 0, 6*sizeof(Int_t));
132 mocchiut 1.8 unpackError = 0;
133 mocchiut 1.36 unpackWarning = 0;
134 mocchiut 1.4 //
135 mocchiut 1.1 };
136    
137 mocchiut 1.18 void ToFLevel2::Delete(Option_t *t){ //ELENA
138 mocchiut 1.13 //
139     if(ToFTrk){
140     ToFTrk->Delete(); //ELENA
141     delete ToFTrk; //ELENA
142     }
143     if(PMT){
144     PMT->Delete(); //ELENA
145     delete PMT; //ELENA
146     } //ELENA
147     //
148     }; //ELENA
149    
150 mocchiut 1.1 ToFTrkVar *ToFLevel2::GetToFTrkVar(Int_t itrk){
151     //
152     if(itrk >= ntrk()){
153     printf(" ToFLevel2 ERROR: track related variables set %i does not exists! \n",itrk);
154     printf(" stored track related variables = %i \n",ntrk());
155     return(NULL);
156     }
157     //
158 mocchiut 1.13 if(!ToFTrk)return 0; //ELENA
159 mocchiut 1.1 TClonesArray &t = *(ToFTrk);
160     ToFTrkVar *toftrack = (ToFTrkVar*)t[itrk];
161     return toftrack;
162     }
163 mocchiut 1.4
164 pam-fi 1.42 /**
165     * Retrieves the tof track matching the seqno-th tracker stored track.
166     *
167     */
168     ToFTrkVar *ToFLevel2::GetToFStoredTrack(int seqno){
169    
170     if( ntrk()==0 ){
171     printf("ToFLevel2::GetToFStoredTrack(int) : requested tracker SeqNo %i but no ToFrimeter tracks are stored\n",seqno);
172     return NULL;
173     };
174    
175     ToFTrkVar *c = 0;
176     Int_t it_tof=0;
177    
178     do {
179     c = GetToFTrkVar(it_tof);
180     it_tof++;
181     } while( c && seqno != c->trkseqno && it_tof < ntrk());
182    
183     if(!c || seqno != c->trkseqno){
184     c = 0;
185     if(seqno!=-1 ) printf("ToFLevel2::GetToFStoredTrack(int) : requested tracker SeqNo %i does not match ToFrimeter stored tracks\n",seqno);
186     };
187     return c;
188    
189     }
190    
191    
192 mocchiut 1.4 ToFPMT *ToFLevel2::GetToFPMT(Int_t ihit){
193     //
194     if(ihit >= npmt()){
195     printf(" ToFLevel2 ERROR: pmt variables set %i does not exists! \n",ihit);
196     printf(" stored pmt variables = %i \n",npmt());
197     return(NULL);
198     }
199     //
200 mocchiut 1.13 if(!PMT)return 0; //ELENA
201 mocchiut 1.4 TClonesArray &t = *(PMT);
202     ToFPMT *tofpmt = (ToFPMT*)t[ihit];
203     return tofpmt;
204     }
205 mocchiut 1.1 //--------------------------------------
206     //
207     //
208     //--------------------------------------
209     /**
210 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)
211 mocchiut 1.16 * @param Plane index (0,1,2,3,4,5).
212 mocchiut 1.1 */
213     Int_t ToFLevel2::GetToFPlaneID(Int_t ip){
214     if(ip>=0 && ip<6)return 10*((int)(ip/2+1.1))+(ip%2)+1;
215     else return -1;
216     };
217     /**
218 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)
219 pam-de 1.15 * @param plane Plane ID (11, 12, 21, 22, 31, 32)
220 mocchiut 1.1 */
221     Int_t ToFLevel2::GetToFPlaneIndex(Int_t plane_id){
222     if(
223     plane_id == 11 ||
224     plane_id == 12 ||
225     plane_id == 21 ||
226     plane_id == 22 ||
227     plane_id == 31 ||
228     plane_id == 32 ||
229     false)return (Int_t)(plane_id/10)*2-1- plane_id%2;
230     else return -1;
231     };
232     /**
233 mocchiut 1.13 * Method to know if a given ToF paddle was hit, that is there is a TDC signal
234 pam-de 1.15 * from both PMTs. The method uses the "tof_j_flag" variable.
235 mocchiut 1.1 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
236     * @param paddle_id Paddle ID.
237     * @return 1 if the paddle was hit.
238     */
239     Bool_t ToFLevel2::HitPaddle(Int_t plane, Int_t paddle_id){ //<<< NEW
240     Int_t ip = -1;
241     if (plane>=6 ) ip = GetToFPlaneIndex(plane);
242     else if(plane>=0 && plane < 6) ip = plane;
243     Int_t flag=0;
244 mocchiut 1.2 if(ip != -1)flag = tof_j_flag[ip] & (int)pow(2.,(double)paddle_id);
245 mocchiut 1.1 if(
246     (ip == 0 && paddle_id < 8 && flag) ||
247     (ip == 1 && paddle_id < 6 && flag) ||
248     (ip == 2 && paddle_id < 2 && flag) ||
249     (ip == 3 && paddle_id < 2 && flag) ||
250     (ip == 4 && paddle_id < 3 && flag) ||
251     (ip == 5 && paddle_id < 3 && flag) ||
252     false) return true;
253     else return false;
254     };
255 mocchiut 1.43
256 mocchiut 1.1 /**
257 mocchiut 1.43 * Strict method to get the number of hit paddles on a ToF plane.
258     * The method uses "HitPaddle" which checks if there is a TDC signal
259     * from both PMTs.
260 mocchiut 1.1 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
261     */
262     Int_t ToFLevel2::GetNHitPaddles(Int_t plane){
263     Int_t npad=0;
264     for(Int_t i=0; i<8; i++)npad = npad + (int)HitPaddle(plane,i);
265     return npad;
266     };
267 mocchiut 1.4
268 mocchiut 1.36 /**
269 mocchiut 1.43 * Optional method to get the number of hit paddles on a ToF plane.
270     * The method does NOT check if there is a signal from both PMTs, it only
271     * checks if there is some PMT signal in a paddle
272 mocchiut 1.36 * @param plane Plane ID (11, 12, 21, 22, 31, 32) or Plane index (0,1,2,3,4,5).
273     */
274     Int_t ToFLevel2::GetTrueNHitPaddles(Int_t plane){
275     Int_t npad=0;
276     TClonesArray* Pmt = this->PMT;
277     int paddle[24];
278     memset(paddle,0, 24*sizeof(int));
279     for(int i=0; i<Pmt->GetEntries(); i++) { //loop per vedere quale TOF è colpito
280     ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
281     int pplane = -1;
282     int ppaddle = -1;
283     GetPMTPaddle(pmthit->pmt_id,pplane,ppaddle);
284     if ( pplane == plane ) paddle[ppaddle]++;
285     }
286     for(int i=0;i<24;i++) if ( paddle[i]>0 ) npad++;
287    
288     return npad;
289     };
290    
291 mocchiut 1.43 //new, wm Feb 15
292 pamelats 1.23 //wm Nov 08
293 mocchiut 1.16 //gf Apr 07
294 pam-de 1.14 /**
295 mocchiut 1.43 * Method to get the mean dEdx from a ToF layer
296     * By definition there should be PMTs with dEdx values only in one paddle of a layer
297     * (the paddle hitted by the track), this method looks for the hitted paddle
298     * and gives the mean dEdx of that paddle as the output
299     * The method was modified for the "ToF-standalone" part in february 2015
300 pamelats 1.23 * The "adcfl" option is not very useful (an artificial dEdx is per
301     * definition= 1 mip and not a real measurement), anyway left in the code
302 pam-de 1.14 * @param notrack Track Number
303 mocchiut 1.16 * @param plane Plane index (0,1,2,3,4,5)
304     * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
305 pam-de 1.14 */
306 mocchiut 1.43 Float_t ToFLevel2::GetdEdx(Int_t notrack, Int_t plane, Int_t adcfl){
307     ToFTrkVar *trk = GetToFTrkVar(notrack);
308     return this->GetdEdx(trk, plane, adcfl);
309     }
310 mocchiut 1.39
311 mocchiut 1.43 //new, wm Feb 15
312 mocchiut 1.39 //wm Nov 08
313     //gf Apr 07
314     /**
315 mocchiut 1.43 * Method to get the mean dEdx from a ToF layer
316     * By definition there should be PMTs with dEdx values only in one paddle of a layer
317     * (the paddle hitted by the track), this method looks for the hitted paddle
318     * and gives the mean dEdx of that paddle as the output
319     * The method was modified for the "ToF-standalone" part in february 2015
320 mocchiut 1.39 * The "adcfl" option is not very useful (an artificial dEdx is per
321     * definition= 1 mip and not a real measurement), anyway left in the code
322 mocchiut 1.43 * @param trk Pointer to TofTrkVar class
323 mocchiut 1.39 * @param plane Plane index (0,1,2,3,4,5)
324     * @param adcflag in the plane (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
325     */
326 mocchiut 1.43 Float_t ToFLevel2::GetdEdx(ToFTrkVar *trk, Int_t plane, Int_t adcfl){
327    
328 mocchiut 1.4 Float_t dedx = 0.;
329 mocchiut 1.16 Float_t PadEdx =0.;
330     Int_t SatWarning;
331     Int_t pad=-1;
332 mocchiut 1.4 //
333 mocchiut 1.13 if(!trk) return 0; //ELENA
334 mocchiut 1.4 //
335 mocchiut 1.43 // ToF standalone part
336     //
337     if ( trk->trkseqno == -1 ){
338    
339 mocchiut 1.36 ToFTrkVar *t_tof = trk;
340    
341 mocchiut 1.43 // Find the hitted paddle (two good TDC values) using the tof_j_flag (from tofl2com.for)
342    
343     Int_t Ipaddle=-1;
344     // if tof_j_flag == 0: no paddle was hitted. Otherwise decode tof_j_flag to get the paddle
345     if (this->tof_j_flag[plane] > 0) Ipaddle = (Int_t)log2(this->tof_j_flag[plane]) ;
346    
347     Ipaddle = (Int_t)log2(this->tof_j_flag[plane]) ;
348    
349     // Get the dEdx of this paddle using "GetdEdxPaddle"
350     if (Ipaddle>-1) {
351     Int_t pad = GetPaddleid(plane,Ipaddle);
352     GetdEdxPaddle(notrack, pad, adcfl, PadEdx, SatWarning);
353     dedx = PadEdx;
354     }
355    
356     // If there was no correct hitted paddle, but there was one (and only one) paddle with some
357     // PMT entries in the PMT-class (found with "GetTrueNHitPaddles", use the dEdx of this paddle
358    
359     if ((Ipaddle<0) && (GetTrueNHitPaddles(plane)==1)) {
360     // find the paddle by looping over the paddles in each layer
361     // since GetTrueNHitPaddles==1 this is OK
362     for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
363     Int_t paddleid=ii;
364     Int_t pad = GetPaddleid(plane,paddleid);
365 mocchiut 1.36 GetdEdxPaddle(notrack, pad, adcfl, PadEdx, SatWarning);
366 mocchiut 1.43 dedx += PadEdx;
367 mocchiut 1.36 }
368 mocchiut 1.43 }
369 mocchiut 1.36 } else {
370 mocchiut 1.43 // track dependent dEdx: simple, there will be only one paddle hitted in each layer
371     // so just loop over the paddles in each layer
372 mocchiut 1.36 for (Int_t ii=0; ii<GetNPaddle(plane); ii++){
373     Int_t paddleid=ii;
374     pad = GetPaddleid(plane,paddleid);
375     GetdEdxPaddle(notrack, pad, adcfl, PadEdx, SatWarning);
376 mocchiut 1.43 dedx += PadEdx;
377     }
378 mocchiut 1.36 }
379 mocchiut 1.43 //
380 mocchiut 1.4 return(dedx);
381 mocchiut 1.43 }
382 mocchiut 1.4
383 pam-de 1.14 /**
384 pam-de 1.15 * Method to fill the ADC_C 4x12 matrix with the dEdx values and the TDC 4x12 matrix
385     * with the time-walk corrected TDC values.
386 pam-de 1.14 * @param notrack Track Number
387     * @param adc ADC_C matrix with dEdx values
388     * @param tdc TDC matrix
389     */
390 mocchiut 1.4 void ToFLevel2::GetMatrix(Int_t notrack, Float_t adc[4][12], Float_t tdc[4][12]){
391     //
392     for (Int_t aa=0; aa<4;aa++){
393     for (Int_t bb=0; bb<12;bb++){
394     adc[aa][bb] = 1000.;
395     tdc[aa][bb] = 4095.;
396     };
397     };
398     //
399     Int_t pmt_id = 0;
400     Int_t hh = 0;
401     Int_t kk = 0;
402     //
403     ToFTrkVar *trk = GetToFTrkVar(notrack);
404 mocchiut 1.13 if(!trk)return; //ELENA
405 mocchiut 1.4 //
406     for (Int_t i=0; i<trk->npmtadc; i++){
407     //
408     pmt_id = (trk->pmtadc).At(i);
409     //
410     GetPMTIndex(pmt_id,hh,kk);
411 mocchiut 1.5 adc[kk][hh] = (trk->dedx).At(i);
412 mocchiut 1.4 //
413     };
414     //
415     for (Int_t i=0; i<npmt(); i++){
416     //
417     ToFPMT *pmt = GetToFPMT(i);
418 mocchiut 1.13 if(!pmt)break; //ELENA
419 mocchiut 1.4 //
420     GetPMTIndex(pmt->pmt_id,hh,kk);
421     //
422 mocchiut 1.5 tdc[kk][hh] = pmt->tdc_tw;
423 mocchiut 1.4 //
424     };
425     //
426     return;
427     };
428    
429    
430 pam-de 1.14 /**
431     * Method to get the plane index (0 - 5) for the PMT_ID as input
432     * @param pmt_id PMT_ID (0 - 47)
433     */
434 mocchiut 1.4 Int_t ToFLevel2::GetPlaneIndex(Int_t pmt_id){
435     TString pmtname = GetPMTName(pmt_id);
436     pmtname.Resize(3);
437     if ( !strcmp(pmtname,"S11") ) return(0);
438     if ( !strcmp(pmtname,"S12") ) return(1);
439     if ( !strcmp(pmtname,"S21") ) return(2);
440     if ( !strcmp(pmtname,"S22") ) return(3);
441     if ( !strcmp(pmtname,"S31") ) return(4);
442     if ( !strcmp(pmtname,"S32") ) return(5);
443     return(-1);
444     };
445    
446 mocchiut 1.16
447 pam-de 1.14 /**
448 pam-de 1.15 * Method to get the PMT_ID if the index (4,12) is given. We have 4 channels on
449     * each of the 12 half-boards, this method decodes which PMT is cables to which
450     * channel.
451 pam-de 1.14 * @param hh Channel
452     * @param kk HalfBoard
453     */
454 mocchiut 1.4 Int_t ToFLevel2::GetPMTid(Int_t hh, Int_t kk){
455     //
456     short tof[4][24] = {
457     {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
458     {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
459     {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
460     {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
461     };
462     //
463     Int_t ind = 0;
464     Int_t k = 0;
465     while (k < 24){
466     Int_t j = 0;
467     while (j < 2){
468     Int_t ch = tof[2*j][k] - 1;
469     Int_t hb = tof[2*j + 1][k] - 1;
470     /* tofEvent->tdc[ch][hb] */
471     if( ch == hh && hb == kk ){
472     ind = 2*k + j;
473     break;
474     };
475     j++;
476     };
477     k++;
478     };
479     return ind;
480     };
481    
482    
483 pam-de 1.14 /**
484 pam-de 1.15 * Method to get the PMT index if the PMT ID is given. This method is the
485     * "reverse" of method "GetPMTid"
486 pam-de 1.14 * @param ind PMT_ID (0 - 47)
487     * @param hb HalfBoard
488     * @param ch Channel
489     */
490 mocchiut 1.5 void ToFLevel2::GetPMTIndex(Int_t ind, Int_t &hb, Int_t &ch){
491 mocchiut 1.4 //
492     short tof[4][24] = {
493     {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
494     {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
495     {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
496     {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
497     };
498     //
499     Int_t k = 0;
500     while (k < 24){
501     Int_t j = 0;
502     while (j < 2){
503 mocchiut 1.5 /* tofEvent->tdc[ch][hb] */
504 mocchiut 1.4 if( ind == 2*k + j ){
505 mocchiut 1.5 ch = tof[2*j][k] - 1;
506     hb = tof[2*j + 1][k] - 1;
507     return;
508 mocchiut 1.4 };
509     j++;
510     };
511     k++;
512     };
513     return;
514     };
515 pam-fi 1.6
516 mocchiut 1.16
517    
518 pamelats 1.23 // wm Nov 08 revision - saturation values included
519 mocchiut 1.16 /// gf Apr 07
520     /**
521     * Method to get the dEdx from a given ToF paddle.
522 pamelats 1.23 * If two PMTs are good, the mean dEdx of both PMTs is taken, otherwise
523     * just the dEdx of the "good" PMT. If both PMTs are above saturation => dEdx=1000
524 mocchiut 1.16 * @param notrack Track Number
525     * @param Paddle index (0,1,...,23).
526     * @param adcflag in the paddle (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
527     * @param PadEdx dEdx from a given ToF paddle
528     * @param SatWarning 1 if the PMT ios near saturation region (adcraw ~3000)
529     */
530     void ToFLevel2::GetdEdxPaddle(Int_t notrack, Int_t paddleid, Int_t adcfl, Float_t &PadEdx, Int_t &SatWarning){
531    
532 mocchiut 1.36 /*
533     Float_t PMTsat[48] = {
534     3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37,
535     3130.05, 3087.07, 3112.22, 3102.92, 3080.58, 3092.55, 3087.94, 3125.03,
536     3094.09, 3143.16, 3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53,
537     3097.11, 3133.53, 3114.73, 3113.01, 3091.19, 3097.99, 3033.84, 3134.98,
538     3081.37, 3111.04, 3066.77, 3108.17, 3133, 3111.06, 3052.52, 3140.66,
539     3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11 } ;
540     */
541 pamelats 1.23
542 mocchiut 1.36 // new values from Napoli dec 2008
543     Float_t PMTsat[48] = {
544     3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
545     3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
546     3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
547     3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
548     3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
549     3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
550    
551     for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.; // safety margin
552 pamelats 1.23
553    
554 mocchiut 1.16 PadEdx = 0.;
555 mocchiut 1.36 // SatWarning = 1000;
556 pamelats 1.23 SatWarning = 0; // 0=good, increase for each bad PMT
557 mocchiut 1.16
558     Float_t dEdx[48] = {0};
559     Int_t pmt_id = -1;
560     Float_t adcraw[48];
561     //
562     ToFTrkVar *trk = GetToFTrkVar(notrack);
563     if(!trk) return; //ELENA
564     //
565    
566     Int_t pmtleft=-1;
567     Int_t pmtright=-1;
568     GetPaddlePMT(paddleid, pmtleft, pmtright);
569    
570     adcraw[pmtleft] = 4095;
571     adcraw[pmtright] = 4095;
572    
573    
574     for (Int_t jj=0; jj<npmt(); jj++){
575    
576     ToFPMT *pmt = GetToFPMT(jj);
577     if(!pmt)break; //ELENA
578    
579     pmt_id = pmt->pmt_id;
580     if(pmt_id==pmtleft){
581     adcraw[pmtleft] = pmt->adc;
582     }
583    
584     if(pmt_id==pmtright){
585     adcraw[pmtright] = pmt->adc;
586     }
587     }
588 pamelats 1.23
589 mocchiut 1.16
590     for (Int_t i=0; i<trk->npmtadc; i++){
591    
592     if((trk->adcflag).At(i)==0 || adcfl==100){
593     if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = (trk->dedx).At(i);
594     if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = (trk->dedx).At(i);
595     }else{
596     if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = 0.;
597     if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = 0.;
598     }
599     }
600    
601 pamelats 1.23
602 mocchiut 1.36 // if( adcraw[pmtleft] >3000 || adcraw[pmtright] >3000)SatWarning=1; //old version
603 pamelats 1.23
604 mocchiut 1.36 // Increase SatWarning Counter for each PMT>Sat
605 pamelats 1.23 if( adcraw[pmtleft] > PMTsat[pmtleft])SatWarning++;
606     if( adcraw[pmtright] > PMTsat[pmtright])SatWarning++;
607    
608 mocchiut 1.36 // if ADC > sat set dEdx=1000
609 pamelats 1.23 if( adcraw[pmtleft] > PMTsat[pmtleft]) dEdx[pmtleft] = 1000.;
610     if( adcraw[pmtright] > PMTsat[pmtright]) dEdx[pmtright] = 1000. ;
611    
612 mocchiut 1.36 // if two PMT are good, take mean dEdx, otherwise only the good dEdx
613 pamelats 1.23 if(dEdx[pmtleft]<1000 && dEdx[pmtright]<1000) PadEdx = (dEdx[pmtleft]+dEdx[pmtright])*0.5;
614     if(dEdx[pmtleft]==1000 && dEdx[pmtright]<1000) PadEdx = dEdx[pmtright];
615     if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
616 mocchiut 1.16
617     };
618 mocchiut 1.39
619 mocchiut 1.16 //
620 mocchiut 1.39 // wm Nov 08 revision - saturation values included
621     /// gf Apr 07
622     /**
623     * Method to get the dEdx from a given ToF paddle.
624     * If two PMTs are good, the mean dEdx of both PMTs is taken, otherwise
625     * just the dEdx of the "good" PMT. If both PMTs are above saturation => dEdx=1000
626     * @param notrack Track Number
627     * @param Paddle index (0,1,...,23).
628     * @param adcflag in the paddle (100<-> independent of the adcflag; !=0&&!=100 <-> at least one PMT with adcflag!=0; )
629     * @param PadEdx dEdx from a given ToF paddle
630     * @param SatWarning 1 if the PMT ios near saturation region (adcraw ~3000)
631     */
632     void ToFLevel2::GetdEdxPaddle(ToFTrkVar *trk, Int_t paddleid, Int_t adcfl, Float_t &PadEdx, Int_t &SatWarning){
633 mocchiut 1.16
634 mocchiut 1.39 /*
635     Float_t PMTsat[48] = {
636     3162.14, 3165.48, 3153.85, 3085.73, 3089.65, 3107.64, 3097.52, 3078.37,
637     3130.05, 3087.07, 3112.22, 3102.92, 3080.58, 3092.55, 3087.94, 3125.03,
638     3094.09, 3143.16, 3125.51, 3181.27, 3092.09, 3124.98, 3069.3, 3095.53,
639     3097.11, 3133.53, 3114.73, 3113.01, 3091.19, 3097.99, 3033.84, 3134.98,
640     3081.37, 3111.04, 3066.77, 3108.17, 3133, 3111.06, 3052.52, 3140.66,
641     3106.33, 3094.85, 3150.85, 3118.8, 3096.24, 3118.47,3111.36, 3117.11 } ;
642     */
643    
644     // new values from Napoli dec 2008
645     Float_t PMTsat[48] = {
646     3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
647     3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
648     3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
649     3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
650     3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
651     3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
652    
653     for (Int_t i=0; i<48;i++) PMTsat[i] = PMTsat[i] - 5.; // safety margin
654    
655    
656     PadEdx = 0.;
657     // SatWarning = 1000;
658     SatWarning = 0; // 0=good, increase for each bad PMT
659    
660     Float_t dEdx[48] = {0};
661     Int_t pmt_id = -1;
662     Float_t adcraw[48];
663     //
664     if(!trk) return; //ELENA
665     //
666    
667     Int_t pmtleft=-1;
668     Int_t pmtright=-1;
669     GetPaddlePMT(paddleid, pmtleft, pmtright);
670    
671     adcraw[pmtleft] = 4095;
672     adcraw[pmtright] = 4095;
673    
674    
675     for (Int_t jj=0; jj<npmt(); jj++){
676    
677     ToFPMT *pmt = GetToFPMT(jj);
678     if(!pmt)break; //ELENA
679    
680     pmt_id = pmt->pmt_id;
681     if(pmt_id==pmtleft){
682     adcraw[pmtleft] = pmt->adc;
683     }
684    
685     if(pmt_id==pmtright){
686     adcraw[pmtright] = pmt->adc;
687     }
688     }
689    
690    
691     for (Int_t i=0; i<trk->npmtadc; i++){
692    
693     if((trk->adcflag).At(i)==0 || adcfl==100){
694     if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = (trk->dedx).At(i);
695     if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = (trk->dedx).At(i);
696     }else{
697     if((trk->pmtadc).At(i) == pmtleft)dEdx[pmtleft] = 0.;
698     if((trk->pmtadc).At(i) == pmtright)dEdx[pmtright] = 0.;
699     }
700     }
701    
702    
703     // if( adcraw[pmtleft] >3000 || adcraw[pmtright] >3000)SatWarning=1; //old version
704    
705     // Increase SatWarning Counter for each PMT>Sat
706     if( adcraw[pmtleft] > PMTsat[pmtleft])SatWarning++;
707     if( adcraw[pmtright] > PMTsat[pmtright])SatWarning++;
708    
709     // if ADC > sat set dEdx=1000
710     if( adcraw[pmtleft] > PMTsat[pmtleft]) dEdx[pmtleft] = 1000.;
711     if( adcraw[pmtright] > PMTsat[pmtright]) dEdx[pmtright] = 1000. ;
712    
713     // if two PMT are good, take mean dEdx, otherwise only the good dEdx
714     if(dEdx[pmtleft]<1000 && dEdx[pmtright]<1000) PadEdx = (dEdx[pmtleft]+dEdx[pmtright])*0.5;
715     if(dEdx[pmtleft]==1000 && dEdx[pmtright]<1000) PadEdx = dEdx[pmtright];
716     if(dEdx[pmtleft]<1000 && dEdx[pmtright]==1000) PadEdx = dEdx[pmtleft];
717    
718     };
719 mocchiut 1.16
720     // gf Apr 07
721    
722     /**
723     * Method to get the PMT name (like "S11_1A") if the PMT_ID is given.
724     * Indexes of corresponding plane, paddle and pmt are also given as output.
725     * @param ind PMT_ID (0 - 47)
726     * @param iplane plane index (0 - 5)
727     * @param ipaddle paddle index (relative to the plane)
728     * @param ipmt pmt index (0(A), 1(B))
729     */
730     TString ToFLevel2::GetPMTName(Int_t ind, Int_t &iplane, Int_t &ipaddle,Int_t &ipmt){
731    
732     TString pmtname = " ";
733    
734     TString photoS[48] = {
735     "S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A",
736     "S11_4B",
737     "S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A",
738     "S11_8B",
739     "S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A",
740     "S12_4B", "S12_5A", "S12_5B", "S12_6A", "S12_6B",
741     "S21_1A", "S21_1B", "S21_2A", "S21_2B",
742     "S22_1A", "S22_1B", "S22_2A", "S22_2B",
743     "S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B",
744     "S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B"
745     };
746    
747    
748     pmtname = photoS[ind].Data();
749    
750     TString ss = pmtname(1,2);
751     iplane = (int)(atoi(ss.Data())/10)*2-3+atoi(ss.Data())%10;
752     ss = pmtname(4);
753     ipaddle = atoi(ss.Data())-1 ;
754     if( pmtname.Contains("A") )ipmt=0;
755     if( pmtname.Contains("B") )ipmt=1;
756    
757     return pmtname;
758     };
759     /**
760     * Method to get the PMT name (like "S11_1A") if the PMT_ID is given
761     * @param ind PMT_ID (0 - 47)
762     */
763     TString ToFLevel2::GetPMTName(Int_t ind){
764    
765     Int_t iplane = -1;
766     Int_t ipaddle = -1;
767     Int_t ipmt = -1;
768     return GetPMTName(ind,iplane,ipaddle,ipmt);
769    
770     };
771    
772 pamela 1.22 // wm jun 08
773     Int_t ToFLevel2::GetPaddleIdOfTrack(Float_t xtr, Float_t ytr, Int_t plane){
774     return GetPaddleIdOfTrack(xtr ,ytr ,plane, 0.4);
775     }
776 mocchiut 1.16
777     // gf Apr 07
778 pamela 1.22 Int_t ToFLevel2::GetPaddleIdOfTrack(Float_t xtr, Float_t ytr, Int_t plane, Float_t margin){
779 pamelats 1.23
780 mocchiut 1.16 Double_t xt,yt,xl,xh,yl,yh;
781    
782     Float_t tof11_x[8] = {-17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85};
783     Float_t tof12_y[6] = { -13.75,-8.25,-2.75,2.75,8.25,13.75};
784     Float_t tof21_y[2] = { 3.75,-3.75};
785     Float_t tof22_x[2] = { -4.5,4.5};
786     Float_t tof31_x[3] = { -6.0,0.,6.0};
787     Float_t tof32_y[3] = { -5.0,0.0,5.0};
788    
789     // S11 8 paddles 33.0 x 5.1 cm
790     // S12 6 paddles 40.8 x 5.5 cm
791     // S21 2 paddles 18.0 x 7.5 cm
792     // S22 2 paddles 15.0 x 9.0 cm
793     // S31 3 paddles 15.0 x 6.0 cm
794     // S32 3 paddles 18.0 x 5.0 cm
795    
796     Int_t paddleidoftrack=-1;
797     //
798    
799     //--- S11 ------
800    
801     if(plane==0){
802     xt = xtr;
803     yt = ytr;
804     paddleidoftrack=-1;
805     yl = -33.0/2. ;
806     yh = 33.0/2. ;
807     if ((yt>yl)&&(yt<yh)) {
808     for (Int_t i1=0; i1<8;i1++){
809 pamela 1.22 xl = tof11_x[i1] - (5.1-margin)/2. ;
810     xh = tof11_x[i1] + (5.1-margin)/2. ;
811 mocchiut 1.16 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
812     }
813     }
814     }
815     // cout<<"S11 "<<paddleidoftrack[0]<<"\n";
816    
817     //--- S12 -------
818     if(plane==1){
819     xt = xtr;
820     yt = ytr;
821     paddleidoftrack=-1;
822     xl = -40.8/2. ;
823     xh = 40.8/2. ;
824    
825     if ((xt>xl)&&(xt<xh)) {
826     for (Int_t i1=0; i1<6;i1++){
827 pamela 1.22 yl = tof12_y[i1] - (5.5-margin)/2. ;
828     yh = tof12_y[i1] + (5.5-margin)/2. ;
829 mocchiut 1.16 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
830     }
831     }
832     }
833    
834     //--- S21 ------
835    
836     if(plane==2){
837     xt = xtr;
838     yt = ytr;
839     paddleidoftrack=-1;
840     xl = -18./2. ;
841     xh = 18./2. ;
842    
843     if ((xt>xl)&&(xt<xh)) {
844     for (Int_t i1=0; i1<2;i1++){
845 pamela 1.22 yl = tof21_y[i1] - (7.5-margin)/2. ;
846     yh = tof21_y[i1] + (7.5-margin)/2. ;
847 mocchiut 1.16 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
848     }
849     }
850     }
851    
852     //--- S22 ------
853     if(plane==3){
854     xt = xtr;
855     yt = ytr;
856     paddleidoftrack=-1;
857     yl = -15./2. ;
858     yh = 15./2. ;
859    
860     if ((yt>yl)&&(yt<yh)) {
861     for (Int_t i1=0; i1<2;i1++){
862 pamela 1.22 xl = tof22_x[i1] - (9.0-margin)/2. ;
863     xh = tof22_x[i1] + (9.0-margin)/2. ;
864 mocchiut 1.16 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
865     }
866     }
867     }
868    
869     //--- S31 ------
870     if(plane==4){
871     xt = xtr;
872     yt = ytr;
873     paddleidoftrack=-1;
874     yl = -15.0/2. ;
875     yh = 15.0/2. ;
876    
877     if ((yt>yl)&&(yt<yh)) {
878     for (Int_t i1=0; i1<3;i1++){
879 pamela 1.22 xl = tof31_x[i1] - (6.0-margin)/2. ;
880     xh = tof31_x[i1] + (6.0-margin)/2. ;
881 mocchiut 1.16 if ((xt>xl)&&(xt<xh)) paddleidoftrack=i1;
882     }
883     }
884     }
885    
886     //--- S32 ------
887     if(plane==5){
888     xt = xtr;
889     yt = ytr;
890     paddleidoftrack=-1;
891     xl = -18.0/2. ;
892     xh = 18.0/2. ;
893    
894     if ((xt>xl)&&(xt<xh)) {
895     for (Int_t i1=0; i1<3;i1++){
896 pamela 1.22 yl = tof32_y[i1] - (5.0-margin)/2. ;
897     yh = tof32_y[i1] + (5.0-margin)/2. ;
898 mocchiut 1.16 if ((yt>yl)&&(yt<yh)) paddleidoftrack=i1;
899     }
900     }
901     }
902    
903     return paddleidoftrack;
904    
905     }
906    
907     //
908    
909     // gf Apr 07
910    
911     void ToFLevel2::GetPMTPaddle(Int_t pmt_id, Int_t &plane, Int_t &paddle){
912    
913     plane = GetPlaneIndex(pmt_id);
914    
915     if(plane == 0){
916     if(pmt_id==0 || pmt_id==1)paddle=0;
917     if(pmt_id==2 || pmt_id==3)paddle=1;
918     if(pmt_id==4 || pmt_id==5)paddle=2;
919     if(pmt_id==6 || pmt_id==7)paddle=3;
920     if(pmt_id==8 || pmt_id==9)paddle=4;
921     if(pmt_id==10 || pmt_id==11)paddle=5;
922     if(pmt_id==12 || pmt_id==13)paddle=6;
923     if(pmt_id==14 || pmt_id==15)paddle=7;
924     }
925    
926     if(plane == 1){
927     if(pmt_id==16 || pmt_id==17)paddle=0;
928     if(pmt_id==18 || pmt_id==19)paddle=1;
929     if(pmt_id==20 || pmt_id==21)paddle=2;
930     if(pmt_id==22 || pmt_id==23)paddle=3;
931     if(pmt_id==24 || pmt_id==25)paddle=4;
932     if(pmt_id==26 || pmt_id==27)paddle=5;
933     }
934    
935     if(plane == 2){
936     if(pmt_id==28 || pmt_id==29)paddle=0;
937     if(pmt_id==30 || pmt_id==31)paddle=1;
938     }
939    
940     if(plane == 3){
941     if(pmt_id==32 || pmt_id==33)paddle=0;
942     if(pmt_id==34 || pmt_id==35)paddle=1;
943     }
944    
945     if(plane == 4){
946     if(pmt_id==36 || pmt_id==37)paddle=0;
947     if(pmt_id==38 || pmt_id==39)paddle=1;
948     if(pmt_id==40 || pmt_id==41)paddle=2;
949     }
950    
951     if(plane == 5){
952     if(pmt_id==42 || pmt_id==43)paddle=0;
953     if(pmt_id==44 || pmt_id==45)paddle=1;
954     if(pmt_id==46 || pmt_id==47)paddle=2;
955     }
956     return;
957     }
958    
959     //
960    
961     // gf Apr 07
962    
963     void ToFLevel2::GetPaddlePMT(Int_t paddle, Int_t &pmtleft, Int_t &pmtright){
964 mocchiut 1.24 pmtleft=paddle*2;
965     pmtright= pmtleft+1;
966 mocchiut 1.16 return;
967     }
968    
969     //
970    
971    
972    
973     // // gf Apr 07
974    
975     void ToFLevel2::GetPaddleGeometry(Int_t plane, Int_t paddle, Float_t &xleft, Float_t &xright, Float_t &yleft, Float_t &yright){
976    
977     Int_t i1;
978    
979     Float_t tof11_x[8] = {-17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85};
980     Float_t tof12_y[6] = { -13.75,-8.25,-2.75,2.75,8.25,13.75};
981     Float_t tof21_y[2] = { 3.75,-3.75};
982     Float_t tof22_x[2] = { -4.5,4.5};
983     Float_t tof31_x[3] = { -6.0,0.,6.0};
984     Float_t tof32_y[3] = { -5.0,0.0,5.0};
985    
986     // S11 8 paddles 33.0 x 5.1 cm
987     // S12 6 paddles 40.8 x 5.5 cm
988     // S21 2 paddles 18.0 x 7.5 cm
989     // S22 2 paddles 15.0 x 9.0 cm
990     // S31 3 paddles 15.0 x 6.0 cm
991     // S32 3 paddles 18.0 x 5.0 cm
992    
993     if(plane==0)
994     {
995     for (i1=0; i1<8;i1++){
996     if(i1 == paddle){
997     xleft = tof11_x[i1] - 5.1/2.;
998     xright = tof11_x[i1] + 5.1/2.;
999     yleft = -33.0/2.;
1000     yright = 33.0/2.;
1001     }
1002     }
1003     }
1004    
1005     if(plane==1)
1006     {
1007     for (i1=0; i1<6;i1++){
1008     if(i1 == paddle){
1009     xleft = -40.8/2.;
1010     xright = 40.8/2.;
1011     yleft = tof12_y[i1] - 5.5/2.;
1012     yright = tof12_y[i1] + 5.5/2.;
1013     }
1014     }
1015     }
1016    
1017     if(plane==2)
1018     {
1019     for (i1=0; i1<2;i1++){
1020     if(i1 == paddle){
1021     xleft = -18./2.;
1022     xright = 18./2.;
1023     yleft = tof21_y[i1] - 7.5/2.;
1024     yright = tof21_y[i1] + 7.5/2.;
1025     }
1026     }
1027     }
1028    
1029     if(plane==3)
1030     {
1031     for (i1=0; i1<2;i1++){
1032     if(i1 == paddle){
1033     xleft = tof22_x[i1] - 9.0/2.;
1034     xright = tof22_x[i1] + 9.0/2.;
1035     yleft = -15./2.;
1036     yright = 15./2.;
1037     }
1038     }
1039     }
1040    
1041    
1042     if(plane==4)
1043     {
1044     for (i1=0; i1<3;i1++){
1045     if(i1 == paddle){
1046     xleft = tof31_x[i1] - 6.0/2.;
1047     xright = tof31_x[i1] + 6.0/2.;
1048     yleft = -15./2.;
1049     yright = 15./2.;
1050     }
1051     }
1052     }
1053    
1054     if(plane==5)
1055     {
1056     for (i1=0; i1<3;i1++){
1057     if(i1 == paddle){
1058     xleft = -18.0/2.;
1059     xright = 18.0/2.;
1060     yleft = tof32_y[i1] - 5.0/2.;
1061     yright = tof32_y[i1] + 5.0/2.;
1062     }
1063     }
1064     }
1065     return;
1066     }
1067    
1068     // gf Apr 07
1069     /**
1070     * Method to get the paddle index (0,...23) if the plane ID and the paddle id in the plane is given.
1071     * This method is the
1072     * "reverse" of method "GetPaddlePlane"
1073     * @param plane (0 - 5)
1074     * @param paddle (plane=0, paddle = 0,...5)
1075     * @param padid (0 - 23)
1076     */
1077     Int_t ToFLevel2::GetPaddleid(Int_t plane, Int_t paddle)
1078     {
1079     Int_t padid=-1;
1080 mocchiut 1.24 Int_t pads[6]={8,6,2,2,3,3};
1081 mocchiut 1.16
1082 mocchiut 1.24 int somma=0;
1083     int np=plane;
1084     for(Int_t j=0; j<np; j++){
1085     somma+=pads[j];
1086 pamelats 1.23 }
1087 mocchiut 1.24 padid=paddle+somma;
1088 mocchiut 1.16 return padid;
1089 pamelats 1.23
1090 mocchiut 1.16 }
1091    
1092    
1093     // gf Apr 07
1094     /**
1095     * Method to get the plane ID and the paddle id in the plane if the paddle index (0,...23) is given.
1096     * This method is the
1097     * "reverse" of method "GetPaddleid"
1098     * @param pad (0 - 23)
1099     * @param plane (0 - 5)
1100     * @param paddle (plane=0, paddle = 0,...5)
1101     */
1102     void ToFLevel2::GetPaddlePlane(Int_t pad, Int_t &plane, Int_t &paddle)
1103     {
1104    
1105     Int_t pads11=8;
1106     Int_t pads12=6;
1107     Int_t pads21=2;
1108     Int_t pads22=2;
1109     Int_t pads31=3;
1110     // Int_t pads32=3;
1111    
1112     if(pad<8){
1113     plane=0;
1114     paddle=pad;
1115     return;
1116     }
1117    
1118 pamelats 1.25 if((7<pad)&&(pad<14)){
1119 mocchiut 1.16 plane=1;
1120     paddle=pad-pads11;
1121     return;
1122     }
1123    
1124 pamelats 1.25 if((13<pad)&&(pad<16)){
1125 mocchiut 1.16 plane=2;
1126     paddle=pad-pads11-pads12;
1127     return;
1128     }
1129    
1130 pamelats 1.25 if((15<pad)&&(pad<18)){
1131 mocchiut 1.16 plane=3;
1132     paddle=pad-pads11-pads12-pads21;
1133     return;
1134     }
1135    
1136 pamelats 1.25 if((17<pad)&&(pad<21)){
1137 mocchiut 1.16 plane=4;
1138     paddle=pad-pads11-pads12-pads21-pads22;
1139     return;
1140     }
1141    
1142 pamelats 1.25 if((20<pad)&&(pad<24)){
1143 mocchiut 1.16 plane=5;
1144     paddle=pad-pads11-pads12-pads21-pads22-pads31;
1145     return;
1146     }
1147    
1148     }
1149    
1150    
1151     Int_t ToFLevel2::GetNPaddle(Int_t plane){
1152    
1153     Int_t npaddle=-1;
1154    
1155     Int_t pads11=8;
1156     Int_t pads12=6;
1157     Int_t pads21=2;
1158     Int_t pads22=2;
1159     Int_t pads31=3;
1160     Int_t pads32=3;
1161    
1162     if(plane==0)npaddle=pads11;
1163     if(plane==1)npaddle=pads12;
1164     if(plane==2)npaddle=pads21;
1165     if(plane==3)npaddle=pads22;
1166     if(plane==4)npaddle=pads31;
1167     if(plane==5)npaddle=pads32;
1168    
1169     return npaddle;
1170    
1171     }
1172    
1173 pamelats 1.23
1174    
1175 mocchiut 1.19 /// wm feb 08
1176    
1177     /**
1178     * Method to calculate Beta from the 12 single measurements
1179     * we check the individual weights for artificial TDC values, then calculate
1180     * am mean beta for the first time. In a second step we loop again through
1181     * the single measurements, checking for the residual from the mean
1182     * The cut on the residual reject measurements > "x"-sigma. A chi2 value is
1183     * calculated, furthermore a "quality" value by adding the weights which
1184     * are finally used. If all measurements are taken, "quality" will be = 22.47.
1185     * A chi2 cut around 3-4 and a quality-cut > 20 is needed for clean beta
1186     * measurements like antiprotons etc.
1187     * The Level2 output is derived in the fortran routines using: 10.,10.,20.
1188     * @param notrack Track Number
1189     * @param cut on residual: difference between single measurement and mean
1190     * @param cut on "quality"
1191     * @param cut on chi2
1192     */
1193    
1194     Float_t ToFLevel2::CalcBeta(Int_t notrack, Float_t resmax, Float_t qualitycut, Float_t chi2cut){
1195    
1196     // cout<<" in CalcBeta "<<resmax<<" "<<chi2cut<<" "<<qualitycut<<endl;
1197    
1198     Float_t bxx = 100.;
1199     //
1200     ToFTrkVar *trk = GetToFTrkVar(notrack);
1201     if(!trk) return 0; //ELENA
1202    
1203    
1204     Float_t chi2,xhelp,beta_mean;
1205     Float_t w_i[12],quality,sw,sxw,res,betachi,beta_mean_inv;
1206     Float_t b[12],tdcfl;
1207     Int_t pmt_id,pmt_plane;
1208    
1209     for (Int_t i=0; i<12; i++){
1210     b[i] = trk->beta[i];
1211     }
1212    
1213    
1214     //========================================================================
1215     //--- Find out ToF layers with artificial TDC values & fill vector ---
1216     //========================================================================
1217    
1218     Float_t w_il[6];
1219    
1220     for (Int_t jj=0; jj<6;jj++) {
1221     w_il[jj] = 1000.;
1222     }
1223    
1224    
1225     for (Int_t i=0; i<trk->npmttdc; i++){
1226     //
1227     pmt_id = (trk->pmttdc).At(i);
1228     pmt_plane = GetPlaneIndex(pmt_id);
1229     tdcfl = (trk->tdcflag).At(i);
1230     if (w_il[pmt_plane] != 1.) w_il[pmt_plane] = tdcfl; //tdcflag
1231     };
1232    
1233     //========================================================================
1234     //--- Set weights for the 12 measurements using information for top and bottom:
1235     //--- if no measurements: weight = set to very high value=> not used
1236     //--- top or bottom artificial: weight*sqrt(2)
1237     //--- top and bottom artificial: weight*sqrt(2)*sqrt(2)
1238     //========================================================================
1239    
1240     Int_t itop[12] = {0,0,1,1,2,2,3,3,0,0,1,1};
1241     Int_t ibot[12] = {4,5,4,5,4,5,4,5,2,3,2,3};
1242    
1243     xhelp= 1E09;
1244    
1245     for (Int_t jj=0; jj<12;jj++) {
1246     if (jj<4) xhelp = 0.11; // S1-S3
1247     if ((jj>3)&&(jj<8)) xhelp = 0.18; // S2-S3
1248     if (jj>7) xhelp = 0.28; // S1-S2
1249     if ((w_il[itop[jj]] == 1000.) && (w_il[ibot[jj]] == 1000.)) xhelp = 1E09;
1250     if ((w_il[itop[jj]] == 1) || (w_il[ibot[jj]] == 1.)) xhelp = xhelp*1.414 ;
1251     if ((w_il[itop[jj]] == 1) && (w_il[ibot[jj]] == 1.)) xhelp = xhelp*2. ;
1252    
1253     w_i[jj] = 1./xhelp;
1254     }
1255    
1256    
1257     //========================================================================
1258     //--- Calculate mean beta for the first time -----------------------------
1259     //--- We are using "1/beta" since its error is gaussian ------------------
1260     //========================================================================
1261    
1262     Int_t icount=0;
1263     sw=0.;
1264     sxw=0.;
1265     beta_mean=100.;
1266    
1267     for (Int_t jj=0; jj<12;jj++){
1268     if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.))
1269     {
1270     icount= icount+1;
1271     sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ;
1272     sw =sw + w_i[jj]*w_i[jj] ;
1273    
1274     }
1275     }
1276    
1277     if (icount>0) beta_mean=1./(sxw/sw);
1278     beta_mean_inv = 1./beta_mean;
1279    
1280     //========================================================================
1281     //--- Calculate beta for the second time, use residuals of the single
1282     //--- measurements to get a chi2 value
1283     //========================================================================
1284    
1285     icount=0;
1286     sw=0.;
1287     sxw=0.;
1288     betachi = 100.;
1289     chi2 = 0.;
1290     quality=0.;
1291    
1292    
1293     for (Int_t jj=0; jj<12;jj++){
1294     if ((fabs(1./b[jj])>0.1)&&(fabs(1./b[jj])<15.)&&(w_i[jj]>0.01)) {
1295     res = beta_mean_inv - (1./b[jj]) ;
1296     if (fabs(res*w_i[jj])<resmax) {;
1297     chi2 = chi2 + pow((res*w_i[jj]),2) ;
1298     icount= icount+1;
1299     sxw=sxw + (1./b[jj])*w_i[jj]*w_i[jj] ;
1300     sw =sw + w_i[jj]*w_i[jj] ;
1301     }
1302     }
1303     }
1304     quality = sqrt(sw) ;
1305    
1306     if (icount==0) chi2 = 1000.;
1307     if (icount>0) chi2 = chi2/(icount) ;
1308     if (icount>0) betachi=1./(sxw/sw);
1309    
1310     bxx = 100.;
1311     if ((chi2 < chi2cut)&&(quality>qualitycut)) bxx = betachi;
1312     //
1313     return(bxx);
1314     };
1315    
1316    
1317     ////////////////////////////////////////////////////
1318 mocchiut 1.16 ////////////////////////////////////////////////////
1319    
1320    
1321 pam-fi 1.6 /**
1322     * Fills a struct cToFLevel2 with values from a ToFLevel2 object (to put data into a F77 common).
1323     */
1324     void ToFLevel2::GetLevel2Struct(cToFLevel2 *l2) const{
1325    
1326     for(Int_t i=0;i<6;i++)
1327     l2->tof_j_flag[i]=tof_j_flag[i];
1328    
1329 mocchiut 1.13 if(ToFTrk){ //ELENA
1330     l2->ntoftrk = ToFTrk->GetEntries();
1331     for(Int_t j=0;j<l2->ntoftrk;j++){
1332     l2->toftrkseqno[j]= ((ToFTrkVar*)ToFTrk->At(j))->trkseqno;
1333     l2->npmttdc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmttdc;
1334     for(Int_t i=0;i<l2->npmttdc[j];i++){
1335     l2->pmttdc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmttdc.At(i);
1336     l2->tdcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->tdcflag.At(i); // gf: 30 Nov 2006
1337     }
1338     for(Int_t i=0;i<13;i++)
1339     l2->beta[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->beta[i];
1340    
1341     l2->npmtadc[j]= ((ToFTrkVar*)ToFTrk->At(j))->npmtadc;
1342     for(Int_t i=0;i<l2->npmtadc[j];i++){
1343     l2->pmtadc[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->pmtadc.At(i);
1344     l2->adcflag[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->adcflag.At(i); // gf: 30 Nov 2006
1345     l2->dedx[i][j] = ((ToFTrkVar*)ToFTrk->At(j))->dedx.At(i);
1346     }
1347     for(Int_t i=0;i<3;i++){
1348     l2->xtofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtofpos[i];
1349     l2->ytofpos[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytofpos[i];
1350     }
1351 mocchiut 1.16 for(Int_t i=0;i<6;i++){
1352     l2->xtr_tof[i][j]=((ToFTrkVar*)ToFTrk->At(j))->xtr_tof[i];
1353     l2->ytr_tof[i][j]=((ToFTrkVar*)ToFTrk->At(j))->ytr_tof[i];
1354     }
1355 mocchiut 1.13 }
1356     } //ELENA
1357 pam-fi 1.6
1358 mocchiut 1.13 if(PMT){ //ELENA
1359     l2->npmt = PMT->GetEntries();
1360     for(Int_t j=0;j<l2->npmt;j++){
1361     l2->pmt_id[j] = ((ToFPMT*)PMT->At(j))->pmt_id;
1362     l2->adc[j] =((ToFPMT*)PMT->At(j))->adc;
1363     l2->tdc_tw[j] =((ToFPMT*)PMT->At(j))->tdc_tw;
1364     }
1365     } //ELENA
1366 pam-fi 1.6 }
1367 mocchiut 1.24
1368    
1369     //
1370     // Reprocessing tool // Emiliano 08/04/07
1371     //
1372     Int_t ToFLevel2::Process(TrkLevel2 *trk, TrigLevel2 *trg, GL_RUN *run, OrbitalInfo *orb, Bool_t force){
1373     //
1374     // Copiare qui qualcosa di simile a calonuclei per evitare di riprocessare sempre tutto
1375     //
1376 mocchiut 1.27 printf("\n\n\n ERROR: NOT IMPLEMENTED ANYMORE, write Emiliano if you need this method (Emiliano.Mocchiutti@ts.infn.it) \n\n\n");
1377     return(-1);
1378     // //
1379     // // structures to communicate with F77
1380     // //
1381     // extern struct ToFInput tofinput_;
1382     // extern struct ToFOutput tofoutput_;
1383     // //
1384     // // DB connection
1385     // //
1386     // TString host;
1387     // TString user;
1388     // TString psw;
1389     // const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
1390     // const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
1391     // const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
1392     // if ( !pamdbhost ) pamdbhost = "";
1393     // if ( !pamdbuser ) pamdbuser = "";
1394     // if ( !pamdbpsw ) pamdbpsw = "";
1395     // if ( strcmp(pamdbhost,"") ) host = pamdbhost;
1396     // if ( strcmp(pamdbuser,"") ) user = pamdbuser;
1397     // if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
1398     // //
1399     // //
1400     // TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
1401     // if ( !dbc->IsConnected() ) return 1;
1402     // stringstream myquery;
1403     // myquery.str("");
1404 mocchiut 1.41 // myquery << "SET time_zone='+0:00';";
1405 mocchiut 1.27 // dbc->Query(myquery.str().c_str());
1406 mocchiut 1.41 // delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");
1407 mocchiut 1.27 // GL_PARAM *glparam = new GL_PARAM();
1408     // glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table
1409     // trk->LoadField(glparam->PATH+glparam->NAME);
1410     // //
1411     // Bool_t defcal = true;
1412     // Int_t error=glparam->Query_GL_PARAM(run->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
1413     // if ( error<0 ) {
1414     // return(1);
1415     // };
1416     // printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
1417     // if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
1418     // //
1419     // Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
1420     // rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
1421     // //
1422     // Int_t adc[4][12];
1423     // Int_t tdc[4][12];
1424     // Float_t tdcc[4][12];
1425     // //
1426     // // process tof data
1427     // //
1428     // for (Int_t hh=0; hh<12;hh++){
1429     // for (Int_t kk=0; kk<4;kk++){
1430     // adc[kk][hh] = 4095;
1431     // tdc[kk][hh] = 4095;
1432     // tdcc[kk][hh] = 4095.;
1433     // tofinput_.adc[hh][kk] = 4095;
1434     // tofinput_.tdc[hh][kk] = 4095;
1435     // };
1436     // };
1437     // Int_t ntrkentry = 0;
1438     // Int_t npmtentry = 0;
1439     // Int_t gg = 0;
1440     // Int_t hh = 0;
1441     // Int_t adcf[48];
1442     // memset(adcf, 0, 48*sizeof(Int_t));
1443     // Int_t tdcf[48];
1444     // memset(tdcf, 0, 48*sizeof(Int_t));
1445     // for (Int_t pm=0; pm < this->ntrk() ; pm++){
1446     // ToFTrkVar *ttf = this->GetToFTrkVar(pm);
1447     // for ( Int_t nc=0; nc < ttf->npmttdc; nc++){
1448     // if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1;
1449     // };
1450     // for ( Int_t nc=0; nc < ttf->npmtadc; nc++){
1451     // if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1;
1452     // };
1453     // };
1454     // //
1455     // for (Int_t pm=0; pm < this->npmt() ; pm++){
1456     // ToFPMT *pmt = this->GetToFPMT(pm);
1457     // this->GetPMTIndex(pmt->pmt_id, gg, hh);
1458     // if ( adcf[pmt->pmt_id] == 0 ){
1459     // tofinput_.adc[gg][hh] = (int)pmt->adc;
1460     // adc[hh][gg] = (int)pmt->adc;
1461     // };
1462     // if ( tdcf[pmt->pmt_id] == 0 ){
1463     // tofinput_.tdc[gg][hh] = (int)pmt->tdc;
1464     // tdc[hh][gg] = (int)pmt->tdc;
1465     // };
1466     // tdcc[hh][gg] = (float)pmt->tdc_tw;
1467     // // Int_t pppid = this->GetPMTid(hh,gg);
1468     // // printf(" pm %i pmt_id %i pppid %i hh %i gg %i tdcc %f tdc %f adc %f \n",pm,pmt->pmt_id,pppid,hh,gg,pmt->tdc_tw,pmt->tdc,pmt->adc);
1469     // };
1470     // //
1471     // Int_t unpackError = this->unpackError;
1472     // //
1473     // for (Int_t hh=0; hh<5;hh++){
1474     // tofinput_.patterntrig[hh]=trg->patterntrig[hh];
1475     // };
1476     // //
1477     // this->Clear();
1478     // //
1479     // Int_t pmt_id = 0;
1480     // ToFPMT *t_pmt = new ToFPMT();
1481     // if(!(this->PMT)) this->PMT = new TClonesArray("ToFPMT",12); //ELENA
1482     // TClonesArray &tpmt = *this->PMT;
1483     // ToFTrkVar *t_tof = new ToFTrkVar();
1484     // if(!(this->ToFTrk)) this->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
1485     // TClonesArray &t = *this->ToFTrk;
1486     // //
1487     // //
1488     // // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
1489     // //
1490     // npmtentry = 0;
1491     // //
1492     // ntrkentry = 0;
1493     // //
1494     // // Calculate tracks informations from ToF alone
1495     // //
1496     // tofl2com();
1497     // //
1498     // memcpy(this->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
1499     // //
1500     // t_tof->trkseqno = -1;
1501     // //
1502     // // and now we must copy from the output structure to the level2 class:
1503     // //
1504     // t_tof->npmttdc = 0;
1505     // //
1506     // for (Int_t hh=0; hh<12;hh++){
1507     // for (Int_t kk=0; kk<4;kk++){
1508     // if ( tofoutput_.tofmask[hh][kk] != 0 ){
1509     // pmt_id = this->GetPMTid(kk,hh);
1510     // t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1511     // t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1512     // t_tof->npmttdc++;
1513     // };
1514     // };
1515     // };
1516     // for (Int_t kk=0; kk<13;kk++){
1517     // t_tof->beta[kk] = tofoutput_.betatof_a[kk];
1518     // }
1519     // //
1520     // t_tof->npmtadc = 0;
1521     // for (Int_t hh=0; hh<12;hh++){
1522     // for (Int_t kk=0; kk<4;kk++){
1523     // if ( tofoutput_.adctof_c[hh][kk] < 1000 ){
1524     // t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc);
1525     // pmt_id = this->GetPMTid(kk,hh);
1526     // t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1527     // t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1528     // t_tof->npmtadc++;
1529     // };
1530     // };
1531     // };
1532     // //
1533     // memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1534     // memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1535     // memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1536     // memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1537     // //
1538     // new(t[ntrkentry]) ToFTrkVar(*t_tof);
1539     // ntrkentry++;
1540     // t_tof->Clear();
1541     // //
1542     // //
1543     // //
1544     // t_pmt->Clear();
1545     // //
1546     // for (Int_t hh=0; hh<12;hh++){
1547     // for (Int_t kk=0; kk<4;kk++){
1548     // // new WM
1549     // if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){
1550     // // if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){
1551     // //
1552     // t_pmt->pmt_id = this->GetPMTid(kk,hh);
1553     // t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
1554     // t_pmt->adc = (Float_t)adc[kk][hh];
1555     // t_pmt->tdc = (Float_t)tdc[kk][hh];
1556     // //
1557     // new(tpmt[npmtentry]) ToFPMT(*t_pmt);
1558     // npmtentry++;
1559     // t_pmt->Clear();
1560     // };
1561     // };
1562     // };
1563     // //
1564     // // Calculate track-related variables
1565     // //
1566     // if ( trk->ntrk() > 0 ){
1567     // //
1568     // // We have at least one track
1569     // //
1570     // //
1571     // // Run over tracks
1572     // //
1573     // for(Int_t nt=0; nt < trk->ntrk(); nt++){
1574     // //
1575     // TrkTrack *ptt = trk->GetStoredTrack(nt);
1576     // //
1577     // // Copy the alpha vector in the input structure
1578     // //
1579     // for (Int_t e = 0; e < 5 ; e++){
1580     // tofinput_.al_pp[e] = ptt->al[e];
1581     // };
1582     // //
1583     // // Get tracker related variables for this track
1584     // //
1585     // toftrk();
1586     // //
1587     // // Copy values in the class from the structure (we need to use a temporary class to store variables).
1588     // //
1589     // t_tof->npmttdc = 0;
1590     // for (Int_t hh=0; hh<12;hh++){
1591     // for (Int_t kk=0; kk<4;kk++){
1592     // if ( tofoutput_.tofmask[hh][kk] != 0 ){
1593     // pmt_id = this->GetPMTid(kk,hh);
1594     // t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1595     // t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1596     // t_tof->npmttdc++;
1597     // };
1598     // };
1599     // };
1600     // for (Int_t kk=0; kk<13;kk++){
1601     // t_tof->beta[kk] = tofoutput_.beta_a[kk];
1602     // };
1603     // //
1604     // t_tof->npmtadc = 0;
1605     // for (Int_t hh=0; hh<12;hh++){
1606     // for (Int_t kk=0; kk<4;kk++){
1607     // if ( tofoutput_.adc_c[hh][kk] < 1000 ){
1608     // t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc);
1609     // pmt_id = this->GetPMTid(kk,hh);
1610     // t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1611     // t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
1612     // t_tof->npmtadc++;
1613     // };
1614     // };
1615     // };
1616     // //
1617     // memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1618     // memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1619     // memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1620     // memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1621     // //
1622     // // Store the tracker track number in order to be sure to have shyncronized data during analysis
1623     // //
1624     // t_tof->trkseqno = nt;
1625     // //
1626     // // create a new object for this event with track-related variables
1627     // //
1628     // new(t[ntrkentry]) ToFTrkVar(*t_tof);
1629     // ntrkentry++;
1630     // t_tof->Clear();
1631     // //
1632     // }; // loop on all the tracks
1633     // //
1634     // this->unpackError = unpackError;
1635     // if ( defcal ){
1636     // this->default_calib = 1;
1637     // } else {
1638     // this->default_calib = 0;
1639     // };
1640     //};
1641     // return(0);
1642 mocchiut 1.24 }
1643 carbone 1.26
1644 mocchiut 1.36 bool ToFLevel2::bit(int decimal, char pos){
1645     return( (decimal>>pos)%2 );
1646     }
1647    
1648     bool ToFLevel2::checkPMT(TString givenpmt){
1649     TClonesArray* Pmt = this->PMT;
1650     // printf(" ou %s entries %i \n",givenpmt.Data(),Pmt->GetEntries());
1651     for(int i=0; i<Pmt->GetEntries(); i++) {
1652     ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1653     TString pmtname = this->GetPMTName(pmthit->pmt_id);
1654     // printf(" name %s \n",pmtname.Data());
1655     if ( !strcmp(pmtname.Data(),givenpmt.Data()) )
1656     return true;
1657     }
1658     // printf(" PMT %s missing \n",givenpmt.Data());
1659     return false;
1660     }
1661    
1662     bool ToFLevel2::checkPMTpatternPMThit(TrigLevel2 *trg, int &pmtpattern, int &pmtnosignal){
1663     UInt_t *patterntrig = trg->patterntrig;
1664     pmtpattern = 0;
1665     pmtnosignal = 0;
1666     bool good = true;
1667     //S3
1668     if ( this->bit(patterntrig[2],0) ){ pmtpattern++; if ( !this->checkPMT("S31_1A")){ pmtnosignal++; good = false;}}
1669     if ( this->bit(patterntrig[2],1) ){ pmtpattern++; if ( !this->checkPMT("S31_2A")){ pmtnosignal++; good = false;}}
1670     if ( this->bit(patterntrig[2],2) ){ pmtpattern++; if ( !this->checkPMT("S31_3A")){ pmtnosignal++; good = false;}}
1671     if ( this->bit(patterntrig[2],3) ){ pmtpattern++; if ( !this->checkPMT("S31_1B")){ pmtnosignal++; good = false;}}
1672     if ( this->bit(patterntrig[2],4) ){ pmtpattern++; if ( !this->checkPMT("S31_2B")){ pmtnosignal++; good = false;}}
1673     if ( this->bit(patterntrig[2],5) ){ pmtpattern++; if ( !this->checkPMT("S31_3B")){ pmtnosignal++; good = false;}}
1674     if ( this->bit(patterntrig[2],6) ){ pmtpattern++; if ( !this->checkPMT("S32_1A")){ pmtnosignal++; good = false;}}
1675     if ( this->bit(patterntrig[2],7) ){ pmtpattern++; if ( !this->checkPMT("S32_2A")){ pmtnosignal++; good = false;}}
1676     if ( this->bit(patterntrig[2],8) ){ pmtpattern++; if ( !this->checkPMT("S32_3A")){ pmtnosignal++; good = false;}}
1677     if ( this->bit(patterntrig[2],9) ){ pmtpattern++; if ( !this->checkPMT("S32_1B")){ pmtnosignal++; good = false;}}
1678     if ( this->bit(patterntrig[2],10) ){ pmtpattern++; if ( !this->checkPMT("S32_2B")){ pmtnosignal++; good = false;}}
1679     if ( this->bit(patterntrig[2],11) ){ pmtpattern++; if ( !this->checkPMT("S32_3B")){ pmtnosignal++; good = false;}}
1680     //S2
1681     if ( this->bit(patterntrig[3],0) ){ pmtpattern++; if ( !this->checkPMT("S21_1A")){ pmtnosignal++; good = false;}}
1682     if ( this->bit(patterntrig[3],1) ){ pmtpattern++; if ( !this->checkPMT("S21_2A")){ pmtnosignal++; good = false;}}
1683     if ( this->bit(patterntrig[3],2) ){ pmtpattern++; if ( !this->checkPMT("S21_1B")){ pmtnosignal++; good = false;}}
1684     if ( this->bit(patterntrig[3],3) ){ pmtpattern++; if ( !this->checkPMT("S21_2B")){ pmtnosignal++; good = false;}}
1685     if ( this->bit(patterntrig[3],4) ){ pmtpattern++; if ( !this->checkPMT("S22_1A")){ pmtnosignal++; good = false;}}
1686     if ( this->bit(patterntrig[3],5) ){ pmtpattern++; if ( !this->checkPMT("S22_2A")){ pmtnosignal++; good = false;}}
1687     if ( this->bit(patterntrig[3],6) ){ pmtpattern++; if ( !this->checkPMT("S22_1B")){ pmtnosignal++; good = false;}}
1688     if ( this->bit(patterntrig[3],7) ){ pmtpattern++; if ( !this->checkPMT("S22_2B")){ pmtnosignal++; good = false;}}
1689     //S12
1690     if ( this->bit(patterntrig[4],0) ){ pmtpattern++; if ( !this->checkPMT("S12_1A")){ pmtnosignal++; good = false;}}
1691     if ( this->bit(patterntrig[4],1) ){ pmtpattern++; if ( !this->checkPMT("S12_2A")){ pmtnosignal++; good = false;}}
1692     if ( this->bit(patterntrig[4],2) ){ pmtpattern++; if ( !this->checkPMT("S12_3A")){ pmtnosignal++; good = false;}}
1693     if ( this->bit(patterntrig[4],3) ){ pmtpattern++; if ( !this->checkPMT("S12_4A")){ pmtnosignal++; good = false;}}
1694     if ( this->bit(patterntrig[4],4) ){ pmtpattern++; if ( !this->checkPMT("S12_5A")){ pmtnosignal++; good = false;}}
1695     if ( this->bit(patterntrig[4],5) ){ pmtpattern++; if ( !this->checkPMT("S12_6A")){ pmtnosignal++; good = false;}}
1696     if ( this->bit(patterntrig[4],6) ){ pmtpattern++; if ( !this->checkPMT("S12_1A")){ pmtnosignal++; good = false;}}
1697     if ( this->bit(patterntrig[4],7) ){ pmtpattern++; if ( !this->checkPMT("S12_2A")){ pmtnosignal++; good = false;}}
1698     if ( this->bit(patterntrig[4],8) ){ pmtpattern++; if ( !this->checkPMT("S12_3A")){ pmtnosignal++; good = false;}}
1699     if ( this->bit(patterntrig[4],9) ){ pmtpattern++; if ( !this->checkPMT("S12_4B")){ pmtnosignal++; good = false;}}
1700     if ( this->bit(patterntrig[4],10) ){ pmtpattern++; if ( !this->checkPMT("S12_5B")){ pmtnosignal++; good = false;}}
1701     if ( this->bit(patterntrig[4],11) ){ pmtpattern++; if ( !this->checkPMT("S12_6B")){ pmtnosignal++; good = false;}}
1702     //S11
1703     if ( this->bit(patterntrig[5],0) ){ pmtpattern++; if ( !this->checkPMT("S11_1A")){ pmtnosignal++; good = false;}}
1704     if ( this->bit(patterntrig[5],1) ){ pmtpattern++; if ( !this->checkPMT("S11_2A")){ pmtnosignal++; good = false;}}
1705     if ( this->bit(patterntrig[5],2) ){ pmtpattern++; if ( !this->checkPMT("S11_3A")){ pmtnosignal++; good = false;}}
1706     if ( this->bit(patterntrig[5],3) ){ pmtpattern++; if ( !this->checkPMT("S11_4A")){ pmtnosignal++; good = false;}}
1707     if ( this->bit(patterntrig[5],4) ){ pmtpattern++; if ( !this->checkPMT("S11_5A")){ pmtnosignal++; good = false;}}
1708     if ( this->bit(patterntrig[5],5) ){ pmtpattern++; if ( !this->checkPMT("S11_6A")){ pmtnosignal++; good = false;}}
1709     if ( this->bit(patterntrig[5],6) ){ pmtpattern++; if ( !this->checkPMT("S11_7A")){ pmtnosignal++; good = false;}}
1710     if ( this->bit(patterntrig[5],7) ){ pmtpattern++; if ( !this->checkPMT("S11_8A")){ pmtnosignal++; good = false;}}
1711     if ( this->bit(patterntrig[5],8) ){ pmtpattern++; if ( !this->checkPMT("S11_1B")){ pmtnosignal++; good = false;}}
1712     if ( this->bit(patterntrig[5],9) ){ pmtpattern++; if ( !this->checkPMT("S11_2B")){ pmtnosignal++; good = false;}}
1713     if ( this->bit(patterntrig[5],10) ){ pmtpattern++; if ( !this->checkPMT("S11_3B")){ pmtnosignal++; good = false;}}
1714     if ( this->bit(patterntrig[5],11) ){ pmtpattern++; if ( !this->checkPMT("S11_4B")){ pmtnosignal++; good = false;}}
1715     if ( this->bit(patterntrig[5],12) ){ pmtpattern++; if ( !this->checkPMT("S11_5B")){ pmtnosignal++; good = false;}}
1716     if ( this->bit(patterntrig[5],13) ){ pmtpattern++; if ( !this->checkPMT("S11_6B")){ pmtnosignal++; good = false;}}
1717     if ( this->bit(patterntrig[5],14) ){ pmtpattern++; if ( !this->checkPMT("S11_7B")){ pmtnosignal++; good = false;}}
1718     if ( this->bit(patterntrig[5],15) ){ pmtpattern++; if ( !this->checkPMT("S11_8B")){ pmtnosignal++; good = false;}}
1719    
1720     return good;
1721     }
1722    
1723     bool ToFLevel2::checkPMTpmttrig(TrigLevel2 *trg){
1724     // UInt_t *patterntrig = trg->patterntrig;
1725     int rS11 = 0;
1726     int rS12 = 0;
1727     int rS21 = 0;
1728     int rS22 = 0;
1729     int rS31 = 0;
1730     int rS32 = 0;
1731    
1732     // trigger configuration for the event from saved pmts
1733     TClonesArray* Pmt = this->PMT;
1734     for(int i=0; i<Pmt->GetEntries(); i++) {
1735     ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1736     TString pmtname = this->GetPMTName(pmthit->pmt_id);
1737     if ( pmtname.Contains("S11") ) rS11++;
1738     if ( pmtname.Contains("S12") ) rS12++;
1739     if ( pmtname.Contains("S21") ) rS21++;
1740     if ( pmtname.Contains("S22") ) rS22++;
1741     if ( pmtname.Contains("S31") ) rS31++;
1742     if ( pmtname.Contains("S32") ) rS32++;
1743     }
1744     int rTOF1 = (rS11 + rS12) * (rS21 + rS22) * (rS31 + rS32);
1745     int rTOF2 = (rS11 * rS12) * (rS21 * rS22) * (rS31 * rS32);
1746    
1747     int rTOF3 = (rS21 + rS22) * (rS31 + rS32);
1748     int rTOF4 = (rS21 * rS22) * (rS31 * rS32);
1749    
1750     int rTOF5 = rS12 * (rS21 * rS22);
1751    
1752     int rTOF6 = (rS11 + rS12) * (rS31 + rS32);
1753     int rTOF7 = (rS11 * rS12) * (rS31 * rS32);
1754    
1755    
1756     // trigger configuration of the run
1757     bool TCTOF1 = false;
1758     bool TCTOF2 = false;
1759     bool TCTOF3 = false;
1760     bool TCTOF4 = false;
1761     bool TCTOF5 = false;
1762     bool TCTOF6 = false;
1763     bool TCTOF7 = false;
1764     if ( trg->trigconf & (1<<0) ) TCTOF1 = true;
1765     if ( trg->trigconf & (1<<1) ) TCTOF2 = true;
1766     if ( trg->trigconf & (1<<2) ) TCTOF3 = true;
1767     if ( trg->trigconf & (1<<3) ) TCTOF4 = true;
1768     if ( trg->trigconf & (1<<4) ) TCTOF5 = true;
1769     if ( trg->trigconf & (1<<5) ) TCTOF6 = true;
1770     if ( trg->trigconf & (1<<6) ) TCTOF7 = true;
1771    
1772     // do patterntrig pmts match the trigger configuration?
1773     bool pmtsconf_trigconf_match = true;
1774     if ( rTOF1 == 0 && TCTOF1 ) pmtsconf_trigconf_match = false;
1775     if ( rTOF2 == 0 && TCTOF2 ) pmtsconf_trigconf_match = false;
1776     if ( rTOF3 == 0 && TCTOF3 ) pmtsconf_trigconf_match = false;
1777     if ( rTOF4 == 0 && TCTOF4 ) pmtsconf_trigconf_match = false;
1778     if ( rTOF5 == 0 && TCTOF5 ) pmtsconf_trigconf_match = false;
1779     if ( rTOF6 == 0 && TCTOF6 ) pmtsconf_trigconf_match = false;
1780     if ( rTOF7 == 0 && TCTOF7 ) pmtsconf_trigconf_match = false;
1781    
1782     return pmtsconf_trigconf_match;
1783     }
1784    
1785     void ToFLevel2::printPMT(){
1786     TClonesArray* Pmt = this->PMT;
1787     for(int i=0; i<Pmt->GetEntries(); i++) {
1788     ToFPMT* pmthit = (ToFPMT*)Pmt->At(i);
1789     TString pmtname = this->GetPMTName(pmthit->pmt_id);
1790     printf(" PMT hit: %s \n",pmtname.Data());
1791     }
1792     }
1793    
1794 carbone 1.26
1795     ToFdEdx::ToFdEdx()
1796     {
1797     memset(conn,0,12*sizeof(Bool_t));
1798     memset(ts,0,12*sizeof(UInt_t));
1799     memset(te,0,12*sizeof(UInt_t));
1800 mocchiut 1.34 eDEDXpmt = new TArrayF(48);
1801 carbone 1.26 Define_PMTsat();
1802     Clear();
1803     }
1804 mocchiut 1.35
1805     ToFdEdx::~ToFdEdx(){
1806     Clear();
1807     Delete();
1808     }
1809    
1810     void ToFdEdx::Delete(Option_t *option){
1811     if ( eDEDXpmt ){
1812     eDEDXpmt->Set(0);
1813     if ( eDEDXpmt) delete eDEDXpmt;
1814     }
1815     }
1816    
1817 carbone 1.26 //------------------------------------------------------------------------
1818     void ToFdEdx::CheckConnectors(UInt_t atime, GL_PARAM *glparam, TSQLServer *dbc)
1819     {
1820     for(int i=0; i<12; i++){
1821     if(atime<=ts[i] || atime>te[i]){
1822     Int_t error=glparam->Query_GL_PARAM(atime,210+i,dbc); // parameters stored in DB in GL_PRAM table
1823     if ( error<0 ) {
1824     conn[i]=false;
1825     ts[i]=0;
1826     te[i]=numeric_limits<UInt_t>::max();
1827     };
1828     if ( !error ){
1829     conn[i]=true;
1830     ts[i]=glparam->FROM_TIME;
1831     te[i]=glparam->TO_TIME;
1832     }
1833     if ( error>0 ){
1834     conn[i]=false;
1835     ts[i]=glparam->TO_TIME;
1836     TSQLResult *pResult;
1837     TSQLRow *row;
1838     TString query= Form("SELECT FROM_TIME FROM GL_PARAM WHERE TYPE=%i AND FROM_TIME>=%i ORDER BY FROM_TIME ASC LIMIT 1;",210+i,atime);
1839     pResult=dbc->Query(query.Data());
1840     if(!pResult->GetRowCount()){
1841     te[i]=numeric_limits<UInt_t>::max();
1842     }else{
1843     row=pResult->Next();
1844     te[i]=(UInt_t)atoll(row->GetField(0));
1845     }
1846     }
1847     //
1848    
1849     }
1850     }
1851    
1852     }
1853     //------------------------------------------------------------------------
1854     void ToFdEdx::Clear(Option_t *option)
1855     {
1856     //
1857     // Set arrays and initialize structure
1858 mocchiut 1.34 // eDEDXpmt.Set(48); eDEDXpmt.Reset(-1); // Set array size and reset structure
1859     eDEDXpmt->Set(48); eDEDXpmt->Reset(-1); // Set array size and reset structure
1860 carbone 1.26 //
1861     };
1862    
1863     //------------------------------------------------------------------------
1864     void ToFdEdx::Print(Option_t *option)
1865     {
1866     //
1867     printf("========================================================================\n");
1868    
1869     };
1870    
1871 mocchiut 1.27 //------------------------------------------------------------------------
1872     void ToFdEdx::Init(pamela::tof::TofEvent *tofl0)
1873     {
1874     //
1875     ToFLevel2 tf;
1876     for (Int_t gg=0; gg<4;gg++){
1877     for (Int_t hh=0; hh<12;hh++){
1878     // tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];
1879     int mm = tf.GetPMTid(gg,hh);
1880 mocchiut 1.37 adc[mm]= (0xFFF & tofl0->adc[gg][hh]); // EM, exclude warning bits
1881 mocchiut 1.27 };
1882     };
1883    
1884     };
1885 carbone 1.26
1886     //------------------------------------------------------------------------
1887 mocchiut 1.27 void ToFdEdx::Init(Int_t gg, Int_t hh, Float_t adce)
1888     {
1889     //
1890     ToFLevel2 tf;
1891     // for (Int_t gg=0; gg<4;gg++){
1892     // for (Int_t hh=0; hh<12;hh++){
1893     int mm = tf.GetPMTid(gg,hh);
1894     adc[mm]=adce;
1895    
1896     };
1897 carbone 1.26 //------------------------------------------------------------------------
1898 mocchiut 1.32 void ToFdEdx::Process(UInt_t atime, Float_t betamean, Float_t *xtr_tof, Float_t *ytr_tof, Int_t exitat)
1899 carbone 1.26 {
1900 mocchiut 1.36 bool debug = false;
1901     if ( debug ) printf(" INSIDE TOFDEDX PROCESS \n");
1902 carbone 1.26 // the parameters should be already initialised by InitPar()
1903 mocchiut 1.34 // printf(" in process \n");
1904 carbone 1.26 Clear();
1905    
1906     // define angle:
1907     double dx = xtr_tof[1] - xtr_tof[5];
1908     double dy = ytr_tof[0] - ytr_tof[4];
1909     double dr = sqrt(dx*dx+dy*dy);
1910     double theta=atan(dr/76.81);
1911 mocchiut 1.27 //
1912 mocchiut 1.28 if ( xtr_tof[1] > 99. || xtr_tof[5] > 99. || ytr_tof[0] > 99. || ytr_tof[4] > 99. ) theta = 0.;
1913 mocchiut 1.29 for (Int_t ii=0; ii<6; ii++){
1914     if ( xtr_tof[ii] > 99. ) xtr_tof[ii] = 0.;
1915 mocchiut 1.30 if ( ytr_tof[ii] > 99. ) ytr_tof[ii] = 0.;
1916 mocchiut 1.29 };
1917 mocchiut 1.28 //
1918 mocchiut 1.36 if ( debug ) printf(" theta %f \n",theta);
1919     if ( debug ) printf(" xtr_tof %.1f %.1f %.1f %.1f %.1f %.1f \n",xtr_tof[0],xtr_tof[1],xtr_tof[2],xtr_tof[3],xtr_tof[4],xtr_tof[5]);
1920     if ( debug ) printf(" ytr_tof %.1f %.1f %.1f %.1f %.1f %.1f \n",ytr_tof[0],ytr_tof[1],ytr_tof[2],ytr_tof[3],ytr_tof[4],ytr_tof[5]);
1921 mocchiut 1.32 //--------------------- TABLE OF PERIODS WITH HV PROBLEMS ----------------------------
1922    
1923     int Aconn=conn[0]; // PMT 0,20,22,24
1924     int Bconn=conn[1]; // PMT 6,12,26,34
1925     int Cconn=conn[2]; // PMT 4,14,28,32
1926     int Dconn=conn[3]; // PMT 2,8,10,30
1927     int Econn=conn[4]; // PMT 42,43,44,47
1928     int Fconn=conn[5]; // PMT 7,19,23,27
1929     int Gconn=conn[6]; // PMT 3,11,25,33
1930     int Hconn=conn[7]; // PMT 1,9,13,21
1931     int Iconn=conn[8]; // PMT 5,29,31,35
1932     int Lconn=conn[9]; // PMT 37,40,45,46
1933     int Mconn=conn[10]; // PMT 15,16,17,18
1934     int Nconn=conn[11]; // PMT 36,38,39,41
1935     if( false ) cout << Gconn << Iconn << Lconn <<endl; // to avoid compilation warnings
1936    
1937 mocchiut 1.34 // printf(" size %i \n",eDEDXpmt.GetSize());
1938 carbone 1.26 for( int ii=0; ii<48; ii++ ) {
1939 mocchiut 1.27 //
1940 mocchiut 1.34 // eDEDXpmt.SetAt(-1.,ii);
1941 mocchiut 1.27 // printf(" ii %i beta %f atime %u xtr 1 %f ytr 1 %f adc %f \n",ii,betamean,atime,xtr_tof[0],ytr_tof[0],adc[ii]);
1942 mocchiut 1.36 if ( debug ) printf("II %i adc %f \n",ii,adc[ii]);
1943 mocchiut 1.33
1944 mocchiut 1.34 if( adc[ii] >= 4095. ){
1945     // eDEDXpmt[ii] = 0.;
1946     eDEDXpmt->AddAt(0.,ii);
1947 mocchiut 1.36 if ( debug ) printf(" %i adc>4095 \n",ii);
1948 mocchiut 1.33 continue; // EMILIANO
1949     };
1950    
1951 mocchiut 1.34 if( adc[ii] >= (PMTsat[ii]-5.) && adc[ii] < 4095. ){
1952     eDEDXpmt->AddAt(1000.,ii);
1953 mocchiut 1.36 if ( debug ) printf(" %i adc> pmtsat && adc<4095 \n",ii);
1954 mocchiut 1.33 continue; // EMILIANO
1955     };
1956    
1957     if( adc[ii] <= 0. ) {
1958 mocchiut 1.34 eDEDXpmt->AddAt(1500.,ii);
1959 mocchiut 1.36 if ( debug ) printf(" %i adc<=0 \n",ii);
1960 mocchiut 1.33 continue;
1961     };
1962 mocchiut 1.27 //
1963 carbone 1.26 double adcpC = f_adcPC( adc[ii] ); // - adc conversion in pC
1964 mocchiut 1.32 if ( exitat == 0 ){
1965 mocchiut 1.34 eDEDXpmt->AddAt((Float_t)adcpC,ii);
1966 mocchiut 1.32 continue;
1967     }
1968 mocchiut 1.34 // printf(" e qua? \n");
1969 mocchiut 1.32
1970     double adccorr = adcpC*fabs(cos(theta));
1971 mocchiut 1.36 if ( debug ) printf(" adccorr %f \n",adccorr);
1972     if(adccorr<=0.){
1973     if ( debug ) printf(" %i adccorr<=0 \n",ii);
1974     // eDEDXpmt->AddAt((Float_t)adcpC,ii);//?
1975     continue;
1976     }
1977 mocchiut 1.32 if ( exitat == 1 ){
1978 mocchiut 1.34 eDEDXpmt->AddAt((Float_t)adccorr,ii);
1979 mocchiut 1.32 continue;
1980     }
1981 mocchiut 1.34 // printf(" e quo? \n");
1982 carbone 1.26
1983     // int standard=0;
1984     int S115B_ok=0;
1985     int S115B_break=0;
1986    
1987     if(atime<1158720000)S115B_ok=1;
1988     else S115B_break=1;
1989    
1990    
1991 mocchiut 1.27 //------------------------------------------------------------------------
1992 mocchiut 1.34 // printf(" e qui? \n");
1993 mocchiut 1.27 //---------------------------------------------------- Z reconstruction
1994 carbone 1.26
1995 mocchiut 1.38 double adcHe, adcnorm, adclin, dEdx;//, Zeta; // EM GCC4.7
1996 carbone 1.26
1997 mocchiut 1.27 adcHe=-2;
1998     adcnorm=-2;
1999     adclin=-2;
2000     dEdx=-2;
2001 mocchiut 1.38 // Zeta=-2;//EM GCC4.7
2002 mocchiut 1.32 Double_t correction = 1.;
2003 carbone 1.26
2004     if(Aconn==1 && (ii==0 || ii==20 || ii==22 || ii==24)){
2005 mocchiut 1.32 correction = 1.675;
2006 carbone 1.26 }
2007     else if(Bconn==1 && (ii==6 || ii==12 || ii==26 || ii==34)){
2008 mocchiut 1.32 correction = 2.482;
2009 carbone 1.26 }
2010     else if(Cconn==1 && (ii==4 || ii==14 || ii==28 || ii==32)){
2011 mocchiut 1.32 correction = 1.464;
2012 carbone 1.26 }
2013     else if(Dconn==1 && (ii==2 || ii==8 || ii==10 || ii==30)){
2014 mocchiut 1.32 correction = 1.995;
2015 carbone 1.26 }
2016     else if(Econn==1 && (ii==42 || ii==43 || ii==44 || ii==47)){
2017 mocchiut 1.32 correction = 1.273;
2018 carbone 1.26 }
2019     else if(Fconn==1 && (ii==7 || ii==19 || ii==23 || ii==27)){
2020 mocchiut 1.32 correction = 1.565;
2021 carbone 1.26 }
2022     else if(Mconn==1 && (ii==15 || ii==16 || ii==17 || ii==18)){
2023 mocchiut 1.32 correction = 1.565;
2024 carbone 1.26 }
2025     else if(Nconn==1 && (ii==36 || ii==38 || ii==39 || ii==41)){
2026 mocchiut 1.32 correction = 1.018;
2027 carbone 1.26 }
2028     else if(Hconn==1 && (ii==1 || ii==13 || ii==21 || (ii==9&&S115B_ok==1))){
2029 mocchiut 1.32 correction = 1.84;
2030 carbone 1.26 }
2031     else if(S115B_break==1 && ii==9 && Hconn==1){
2032 mocchiut 1.32 correction = 1.64;
2033 carbone 1.26 }
2034 mocchiut 1.32 else correction = 1.;
2035    
2036 mocchiut 1.34 if( ii==9 && S115B_break==1 ){
2037 mocchiut 1.32 adcHe = f_att5B( ytr_tof[0] )/correction;
2038     } else {
2039     adcHe = Get_adc_he(ii, xtr_tof, ytr_tof)/correction;
2040     };
2041 mocchiut 1.36 if(adcHe<=0){
2042     if ( debug ) printf(" %i adcHe<=0 \n",ii);
2043     // eDEDXpmt->AddAt((Float_t)adccorr,ii); //?
2044     continue;
2045     }
2046 mocchiut 1.32 if ( exitat == 2 ){
2047 mocchiut 1.34 if(ii==9 && S115B_break==1) eDEDXpmt->AddAt(36.*(Float_t)adccorr/adcHe,ii);
2048 mocchiut 1.32 else adclin = 4.*(Float_t)adccorr/adcHe;
2049     continue;
2050     }
2051 carbone 1.26
2052     if(ii==9 && S115B_break==1) adcnorm = f_pos5B(adccorr);
2053     else adcnorm = f_pos( (parPos[ii]), adccorr);
2054 mocchiut 1.36 if(adcnorm<=0){
2055     if ( debug ) printf(" %i adcnorm<=0 \n",ii);
2056     // eDEDXpmt->AddAt((Float_t)adccorr,ii);//?
2057     continue;
2058     }
2059     if ( debug ) printf(" adcnorm %f \n",adcnorm);
2060    
2061 carbone 1.26 if(ii==9 && S115B_break==1) adclin = 36.*adcnorm/adcHe;
2062     else adclin = 4.*adcnorm/adcHe;
2063 mocchiut 1.36 if ( debug ) printf(" adclin %f \n",adclin);
2064     if(adclin<=0){
2065     if ( debug ) printf(" %i adclin<=0 \n",ii);
2066     // eDEDXpmt->AddAt((Float_t)adccorr,ii);//?
2067     continue;
2068     }
2069 mocchiut 1.32 if ( exitat == 3 ){
2070 mocchiut 1.34 if(ii==9 && S115B_break==1) eDEDXpmt->AddAt((Float_t)adclin,ii);
2071     else eDEDXpmt->AddAt((Float_t)adclin,ii);
2072 mocchiut 1.32 continue;
2073     }
2074 mocchiut 1.27 //
2075     if ( betamean > 99. ){
2076 mocchiut 1.31 // eDEDXpmt.AddAt((Float_t)adclin,ii);
2077 mocchiut 1.34 eDEDXpmt->AddAt((Float_t)adclin,ii);
2078 mocchiut 1.31 // printf(" AAPMT IS %i dedx is %f vector is %f \n",ii,adclin,eDEDXpmt[ii]);
2079 mocchiut 1.36 if ( debug ) printf(" %i betamean > 99 \n",ii);
2080 mocchiut 1.27 continue;
2081     };
2082     //
2083 carbone 1.26 double dEdxHe=-2;
2084     if(ii==9 && S115B_break==1){
2085     if( betamean <1. ) dEdxHe = f_BB5B( betamean );
2086     else dEdxHe = 33;
2087     } else {
2088     if( betamean <1. ) dEdxHe = f_BB( (parBBneg[ii]), betamean );
2089     else dEdxHe = parBBpos[ii];
2090     }
2091 mocchiut 1.27
2092 mocchiut 1.36 if ( debug ) printf(" dEdxHe %f \n",dEdxHe);
2093 mocchiut 1.32
2094     if(dEdxHe<=0){
2095 mocchiut 1.34 eDEDXpmt->AddAt((Float_t)adclin,ii);
2096 mocchiut 1.36 if ( debug ) printf(" %i dEdxHe<=0 \n",ii);
2097 mocchiut 1.32 continue;
2098     };
2099 carbone 1.26
2100     if(ii==9 && S115B_break==1) dEdx = f_desatBB5B( adclin );
2101     else dEdx = f_desatBB((parDesatBB[ii]), adclin );
2102    
2103 mocchiut 1.32 if(dEdx<=0){
2104 mocchiut 1.34 eDEDXpmt->AddAt((Float_t)adclin,ii);
2105 mocchiut 1.36 if ( debug ) printf(" %i dEdx<=0 \n",ii);
2106 mocchiut 1.32 continue;
2107     };
2108 carbone 1.26
2109 mocchiut 1.36 if ( debug ) printf(" dEdx %f \n",dEdx);
2110 mocchiut 1.34 eDEDXpmt->AddAt((Float_t)dEdx,ii);
2111 mocchiut 1.31 // eDEDXpmt.AddAt((Float_t)dEdx,ii);
2112 carbone 1.26
2113 mocchiut 1.31 // printf(" PMT IS %i dedx is %f vector is %f \n",ii,dEdx,eDEDXpmt[ii]);
2114 carbone 1.26
2115 mocchiut 1.27 } //end loop on 48 PMT
2116 carbone 1.26
2117     };
2118    
2119    
2120     //------------------------------------------------------------------------
2121     void ToFdEdx::Define_PMTsat()
2122     {
2123     Float_t sat[48] = {
2124     3176.35,3178.19,3167.38,3099.73,3117.00,3126.29,3111.44,3092.27,
2125     3146.48,3094.41,3132.13,3115.37,3099.32,3110.97,3111.80,3143.14,
2126     3106.72,3153.44,3136.00,3188.96,3104.73,3140.45,3073.18,3106.62,
2127     3112.48,3146.92,3127.24,3136.52,3109.59,3112.89,3045.15,3147.26,
2128     3095.92,3121.05,3083.25,3123.62,3150.92,3125.30,3067.60,3160.18,
2129     3119.36,3108.92,3164.77,3133.64,3111.47,3131.98,3128.87,3135.56 };
2130     PMTsat.Set(48,sat);
2131     }
2132    
2133     //------------------------------------------------------------------------
2134     void ToFdEdx::ReadParBBpos( const char *fname )
2135     {
2136 mocchiut 1.27 // printf("read %s\n",fname);
2137 carbone 1.26 parBBpos.Set(48);
2138     FILE *fattin = fopen( fname , "r" );
2139     for (int i=0; i<48; i++) {
2140     int tid=0;
2141     float tp;
2142     if(fscanf(fattin,"%d %f",
2143     &tid, &tp )!=2) break;
2144     parBBpos[i]=tp;
2145     }
2146     fclose(fattin);
2147     }
2148    
2149     //------------------------------------------------------------------------
2150     void ToFdEdx::ReadParDesatBB( const char *fname )
2151     {
2152 mocchiut 1.27 // printf("read %s\n",fname);
2153 carbone 1.26 FILE *fattin = fopen( fname , "r" );
2154     for (int i=0; i<48; i++) {
2155     int tid=0;
2156     float tp[3];
2157     if(fscanf(fattin,"%d %f %f %f",
2158     &tid, &tp[0], &tp[1], &tp[2] )!=4) break;
2159     parDesatBB[i].Set(3,tp);
2160     }
2161     fclose(fattin);
2162     }
2163    
2164    
2165     //------------------------------------------------------------------------
2166     void ToFdEdx::ReadParBBneg( const char *fname )
2167    
2168     {
2169 mocchiut 1.27 // printf("read %s\n",fname);
2170 carbone 1.26 FILE *fattin = fopen( fname , "r" );
2171     for (int i=0; i<48; i++) {
2172     int tid=0;
2173     float tp[3];
2174     if(fscanf(fattin,"%d %f %f %f",
2175     &tid, &tp[0], &tp[1], &tp[2] )!=4) break;
2176     parBBneg[i].Set(3,tp);
2177     }
2178     fclose(fattin);
2179     }
2180    
2181     //------------------------------------------------------------------------
2182     void ToFdEdx::ReadParPos( const char *fname )
2183     {
2184 mocchiut 1.27 // printf("read %s\n",fname);
2185 carbone 1.26 FILE *fattin = fopen( fname , "r" );
2186     for (int i=0; i<48; i++) {
2187     int tid=0;
2188     float tp[4];
2189     if(fscanf(fattin,"%d %f %f %f %f",
2190     &tid, &tp[0], &tp[1], &tp[2], &tp[3])!=5) break;
2191     parPos[i].Set(4,tp);
2192     }
2193     fclose(fattin);
2194     }
2195    
2196     //------------------------------------------------------------------------
2197     void ToFdEdx::ReadParAtt( const char *fname )
2198     {
2199 mocchiut 1.27 // printf("read %s\n",fname);
2200 carbone 1.26 FILE *fattin = fopen( fname , "r" );
2201     for (int i=0; i<48; i++) {
2202     int tid=0;
2203     float tp[6];
2204     if(fscanf(fattin,"%d %f %f %f %f %f %f",
2205     &tid, &tp[0], &tp[1], &tp[2], &tp[3], &tp[4], &tp[5] )!=7) break;
2206     parAtt[i].Set(6,tp);
2207     }
2208     fclose(fattin);
2209     }
2210    
2211    
2212    
2213    
2214    
2215    
2216     double ToFdEdx::f_att( TArrayF &p, float x )
2217     {
2218     return
2219     p[0] +
2220     p[1]*x +
2221     p[2]*x*x +
2222     p[3]*x*x*x +
2223     p[4]*x*x*x*x +
2224     p[5]*x*x*x*x*x;
2225     }
2226     //------------------------------------------------------------------------
2227     double ToFdEdx::f_att5B( float x )
2228     {
2229     return
2230     101.9409 +
2231     6.643781*x +
2232     0.2765518*x*x +
2233     0.004617647*x*x*x +
2234     0.0006195132*x*x*x*x +
2235     0.00002813734*x*x*x*x*x;
2236     }
2237    
2238    
2239     double ToFdEdx::f_pos( TArrayF &p, float x )
2240     {
2241     return
2242     p[0] +
2243     p[1]*x +
2244     p[2]*x*x +
2245     p[3]*x*x*x;
2246     }
2247    
2248     double ToFdEdx::f_pos5B( float x )
2249     {
2250     return
2251     15.45132 +
2252     0.8369721*x +
2253     0.0005*x*x;
2254     }
2255    
2256    
2257    
2258     double ToFdEdx::f_adcPC( float x )
2259     {
2260     return 28.12+0.6312*x-5.647e-05*x*x+3.064e-08*x*x*x;
2261     }
2262    
2263    
2264     float ToFdEdx::Get_adc_he( int id, float pl_x[6], float pl_y[6])
2265     {
2266    
2267     //
2268     // input: id - pmt [0:47}
2269     // pl_x - coord x of the tof plane
2270     // pl_y - coord y
2271    
2272 mocchiut 1.27 adc_he = 0;
2273 carbone 1.26 if( eGeom.GetXY(id)==1 ) adc_he = f_att( (parAtt[id]), pl_x[eGeom.GetPlane(id)] );
2274     if( eGeom.GetXY(id)==2 ) adc_he = f_att( (parAtt[id]), pl_y[eGeom.GetPlane(id)] );
2275     return adc_he;
2276     }
2277    
2278     //------------------------------------------------------------------------
2279     double ToFdEdx::f_BB( TArrayF &p, float x )
2280     {
2281     return p[0]/(x*x)*(log(x*x/(1-x*x)) - p[1]*x*x - p[2]);
2282     }
2283    
2284     //------------------------------------------------------------------------
2285     double ToFdEdx::f_BB5B( float x )
2286     {
2287     return 0.165797/(x*x)*(log(x*x/(1-x*x)) + 140.481*x*x + 52.9258);
2288     }
2289     //------------------------------------------------------------------------
2290     double ToFdEdx::f_desatBB( TArrayF &p, float x )
2291     {
2292     return
2293     p[0] +
2294     p[1]*x +
2295     p[2]*x*x;
2296     }
2297    
2298     //------------------------------------------------------------------------
2299     double ToFdEdx::f_desatBB5B( float x )
2300     {
2301     return
2302     -2.4 +
2303     0.75*x +
2304     0.009*x*x;
2305     }
2306    

  ViewVC Help
Powered by ViewVC 1.1.23