/[PAMELA software]/PamVMC/tof/src/PamVMCTofDig.cxx
ViewVC logotype

Annotation of /PamVMC/tof/src/PamVMCTofDig.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Tue Feb 23 12:09:40 2010 UTC (14 years, 9 months ago) by pizzolot
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +3 -2 lines
corrected tof time resolution with factor 1.4, see digitizer

1 nikolas 1.1 #include "PamVMCTofDig.h"
2     #include "TDatabasePDG.h"
3    
4     #include <TMath.h>
5     #include <TRandom.h>
6    
7     using TMath::Power;
8     using TMath::Exp;
9     using TMath::Abs;
10    
11     ClassImp(PamVMCTofDig)
12    
13    
14     void PamVMCTofDig::LoadCalib(){
15    
16     cout<<"Loading Tof Calibrations..."<<endl;
17    
18     Int_t time=3;
19     Int_t type=202;
20    
21     fdberr = fsql->Query_GL_PARAM(time,type);
22    
23     fquery.str("");
24     fquery << fsql->GetPAR()->PATH.Data() << "/";
25     fquery << fsql->GetPAR()->NAME.Data();
26    
27     ThrowCalFileUsage("TOF",fquery.str().c_str());
28    
29     fcfile.open(fquery.str().c_str());
30    
31     if(!fcfile) ThrowCalFileWarning("TOF"); else {
32    
33     Int_t temp;
34    
35     for(Int_t i=0; i<NP; i++){
36     fcfile >> temp;
37     fcfile >> fatte1[i];
38     fcfile >> flambda1[i];
39     fcfile >> fatte2[i];
40     fcfile >> flambda2[i];
41     fcfile >> temp;
42     }
43    
44     }
45    
46     fcfile.close();
47     }
48    
49    
50    
51    
52     void PamVMCTofDig::DigitizeTOF(Int_t EventNo, Int_t PrimaryPDG){
53    
54     fDEBUG = kFALSE;
55    
56     // pC < 800
57     const Float_t ADC_pC0A = -4.437616e+01;
58     const Float_t ADC_pC1A = 1.573329e+00;
59     const Float_t ADC_pC2A = 2.780518e-04;
60     const Float_t ADC_pC3A = -2.302160e-07;
61     // pC > 800:
62     const Float_t ADC_pC0B = -2.245756e+02;
63     const Float_t ADC_pC1B = 2.184156e+00;
64     const Float_t ADC_pC2B = -4.171825e-04;
65     const Float_t ADC_pC3B = 3.789715e-08;
66    
67     const Float_t pCthres=40.; // threshold in charge
68     const Int_t ADClast=4095; // no signal --> ADC ch=4095
69     const Int_t ADCsat=3100; // saturation value for the ADCs
70     const Int_t TDClast=4095;
71    
72 pam-rm2 1.5
73 nikolas 1.1 for(Int_t i =0; i<NP; i++){
74     fQevePmt_pC[i]=ftdc[i]=ftdc1[i]=0.;
75     ftdcpmt[i]=1000.;
76     }
77    
78    
79    
80     TClonesArray* hc = 0;
81     const char* keyplane [6] = {"S11Y","S12X","S21X","S22Y","S31Y","S32X"};
82     for(Int_t i=0; i<6; i++){
83     hc = (TClonesArray*)fhitscolmap.GetValue(keyplane[i]);
84     if (hc) DigitizeTofPlane(i,hc, PrimaryPDG);
85     hc = 0;
86     }
87    
88 pam-rm2 1.5 if(fDEBUG){
89     cout<<"Summarized values for ADC in PC:"<<endl;
90     for(Int_t i=0; i<NP; i++){
91     cout<<"PMT #"<<i<<" fQevePmt_pC="<<fQevePmt_pC[i]<<endl;
92     }
93     }
94 nikolas 1.1 //+++++ ADC +++++
95    
96     for(Int_t i=0; i<NP; i++){
97 pizzolot 1.6 if (fQevePmt_pC[i] <= 800.)
98 nikolas 1.1 fADCtof[i]= (Int_t)(ADC_pC0A + ADC_pC1A*fQevePmt_pC[i]
99     + ADC_pC2A*Power(fQevePmt_pC[i],2)
100     + ADC_pC3A*Power(fQevePmt_pC[i],3));
101     if ((fQevePmt_pC[i] > 800.) && (fQevePmt_pC[i] <= 2485.))
102     fADCtof[i]= (Int_t)(ADC_pC0B + ADC_pC1B*fQevePmt_pC[i]
103     + ADC_pC2B*Power(fQevePmt_pC[i],2)
104     + ADC_pC3B*Power(fQevePmt_pC[i],3));
105     if (fQevePmt_pC[i] > 2485.) fADCtof[i]= (Int_t)(1758. + 0.54*fQevePmt_pC[i]);
106     //assuming a fictional 0.54 ch/pC above ADCsat
107     if (fADCtof[i]>ADCsat) fADCtof[i]=ADCsat;
108     if (fQevePmt_pC[i] < pCthres) fADCtof[i]= ADClast;
109     if (fADCtof[i] < 0) fADCtof[i]=ADClast;
110     if (fADCtof[i] > ADClast) fADCtof[i]=ADClast;
111     }
112    
113     // ====== TDC coincidence ======
114    
115 pam-rm2 1.5
116     for(Int_t i=0; i<NP; i++) {
117     if((ftdcpmt[i] - fc1_S[i]) > 1e-7) {
118     ftdcpmt[i] = 0.;
119     ftdc[i] = 0.;
120     }
121     }// cycle to introduce a window for tdc
122    
123     Double_t t_coinc = 0;
124 nikolas 1.1 Int_t ilast = 100;
125     for (Int_t ii=0; ii<NP;ii++)
126     if (ftdc[ii] > t_coinc) {
127     t_coinc = ftdc[ii];
128     ilast = ii;
129     }
130    
131     for (Int_t ii=0; ii<NP;ii++){
132     if (ftdc[ii] != 0) ftdc1[ii] = t_coinc - ftdcpmt[ii]; // test 2
133     ftdc1[ii] = ftdc1[ii]/ftdcres[ii]; // divide by TDC resolution
134     if (ftdc[ii] != 0) ftdc1[ii] = ftdc1[ii] + fc3_S[ii]; // add cable length c3
135     }
136    
137     if (fDEBUG)cout<<"====== TOF coincidence ======"<<endl;
138     for(Int_t i=0; i<NP; i++){
139     if(ftdc1[i] != 0.){
140     fTDCint[i]=(Int_t)ftdc1[i];
141     if (fTDCint[i]>4093) fTDCint[i]=TDClast; // 18-oct WM
142     if (fDEBUG)cout<<"PMT: "<<i<<" ADC: "<<fADCtof[i]<<" TDC: "
143     <<fTDCint[i]<<endl;
144     } else
145     fTDCint[i]= TDClast;
146     }
147     if (fDEBUG)cout<<"============================="<<endl;
148    
149     //------ use channelmap for ToF: 18-oct WM
150     Int_t channelmap[] = {3,21,11,29,19,45,27,37,36,28,44,20,5,12,13,4,
151     6,47,14,39,22,31,30,23,38,15,46,7,0,33,16,24,
152     8,41,32,40,25,17,34,9,42,1,2,10,18,26,35,43};
153     Int_t ADChelp[NP],TDChelp[NP];
154     for(Int_t i=0; i<NP; i++){
155     Int_t ii=channelmap[i];
156     ADChelp[ii]= fADCtof[i];
157     TDChelp[ii]= fTDCint[i];
158     }
159     for(Int_t i=0; i<NP; i++){
160     fADCtof[i]= ADChelp[i];
161     fTDCint[i]= TDChelp[i];
162     }
163    
164 pam-rm2 1.5 if (fDEBUG){
165     cout<<"====== TOF coincidence after... ======"<<endl;
166     for(Int_t i=0; i<NP; i++){
167     cout<<"PMT: "<<i<<" ADC: "<<fADCtof[i]<<" TDC: "
168     <<fTDCint[i]<<endl;
169     }
170     cout<<"============================="<<endl;
171     }
172 nikolas 1.1 // ====== write DataTof =======
173    
174     UChar_t Ctrl3bit[8]={32,0,96,64,160,128,224,192}; // DC (msb in 8 bit word )
175     UChar_t tofBin;
176     UChar_t DataTof[276];
177     for (Int_t j=0; j < 276; j++)DataTof[j]=0x00;
178     UChar_t *pTof=DataTof;
179     for (Int_t j=0; j < 12; j++){ // loop on TDC #12
180     Int_t j12=j*23; // for each TDC 23 bytes (8 bits)
181     DataTof[j12+0]=0x00; // TDC_ID
182     DataTof[j12+1]=0x00; // EV_COUNT
183     DataTof[j12+2]=0x00; // TDC_MASK (1)
184     DataTof[j12+3]=0x00; // TDC_MASK (2)
185     for (Int_t k=0; k < 4; k++){ // for each TDC 4 channels (ADC+TDC)
186     Int_t jk12=j12+4*k; // ADC,TDC channel (0-47)
187     tofBin =(UChar_t)(fADCtof[k+4*j]/256); // ADC# (msb)
188     DataTof[jk12+4] = Bin2GrayTof(tofBin,DataTof[jk12+4]);
189     /* control bits inserted here, after the bin to gray conv - DC*/
190     DataTof[jk12+4] = Ctrl3bit[2*k] | DataTof[jk12+4];
191     tofBin=(UChar_t)(fADCtof[k+4*j]%256); // ADC# (lsb)
192     DataTof[jk12+5] = Bin2GrayTof(tofBin,DataTof[jk12+5]);
193     tofBin=(UChar_t)(fTDCint[k+4*j]/256); // TDC# (msb)
194     DataTof[jk12+6]=Bin2GrayTof(tofBin,DataTof[jk12+6]);
195     /* control bits inserted here, after the bin to gray conv - DC*/
196     DataTof[jk12+6] = Ctrl3bit[2*k+1] | DataTof[jk12+6];
197     tofBin=(UChar_t)(fTDCint[k+4*j]%256); // TDC# (lsb)
198 pam-rm2 1.5 //if(fDEBUG) cout<<" digit TDC: "<<jk12<<" TDC:"<<(Int_t)tofBin<<endl;
199 nikolas 1.1 DataTof[jk12+7]=Bin2GrayTof(tofBin,DataTof[jk12+7]);
200     }
201     DataTof[j12+20]=0x00; // TEMP1
202     DataTof[j12+21]=0x00; // TEMP2
203     DataTof[j12+22]= EvaluateCrc(pTof,22); // CRC
204     pTof+=23;
205     }
206    
207     //===== write DataTrigger =======
208    
209     UChar_t DataTrigger[152];
210     for (Int_t j=0; j < 152; j++)DataTrigger[j]=0x00;
211     UChar_t *pTrg=DataTrigger;
212     // Only the variables with a (*) are modified; the others are set to 0
213     // info given in #bites data + #bites crc
214     // TB_READ_PMT_PLANE : 6 + 1
215     // TB_READ_EVENT_COUNT : 3 + 1 (*)
216     // TB_READ_TRIGGER_RATE : 12 + 1
217     // TB_READ_D_L_TIME : 4 + 1
218     // TB_READ_S4_CAL_COUNT : 4 + 1
219     // TB_READ_PMT_COUNT1 : 48 + 1
220     // TB_READ_PMT_COUNT2 : 48 + 1
221     // TB_READ_PATTERN_BUSY : 8 + 1
222     // TB_READ_PATTERN_TRIGGER: 7 + 1 (*)
223     // TB_READ_TRIGGER_CONF : 2 + 1 (*)
224     // TB_READ_EVENT_COUNT
225     UInt_t cTrg = EventNo; //counter
226     UInt_t cTrg2 = 0; //counter with bits inverted, according to document
227     //"formato dati provenienti dalla trigger board"
228     for (Int_t i=0; i < 24; i++){ // Use the first 24 bits
229     if (cTrg & (0x1 << i) )
230     cTrg2 = cTrg2 | (0x1 << (24-i));
231     }
232     DataTrigger[7] = (UChar_t)(cTrg2 >> 16); // 8 MSbits (out of 24)
233     DataTrigger[8] = (UChar_t)(cTrg2 >> 8); // 8 "middle" bits
234     DataTrigger[9] = (UChar_t)(cTrg2); // 8 LSbits
235     pTrg=DataTrigger+7;
236     DataTrigger[10]=EvaluateCrc(pTrg, 3);
237    
238     // TB_READ_PATTERN_TRIGGER: bytes 141-148:
239     // PatternTrigMap[i] corresponds to bit i in TB_READ_PATTERN_TRIGGER:
240     // mapping according to documents:
241     // 1. "formato dati provenienti dalla trigger board"
242     // 2. "The ToF quicklook software", Appendix A (Campana, Nagni)
243     Int_t PatternTrigMap[]={29,42,43,1,16,7,17,28,33,41,46,2,15,8,18,27,
244     30,40,44,3,14,9,19,26,32,37,47,4,13,10,20,25,
245     34,31,38,45,5,12,21,24,36,35,39,48,6,11,22,23};
246     for (Int_t i=0; i<NP; i++){
247     if (ftdc1[channelmap[i]]!=0)
248     DataTrigger[147-(Int_t)((PatternTrigMap[i]+1)/8)]=DataTrigger[147-(Int_t)((PatternTrigMap[i]+1)/8)] | (0x1 << (PatternTrigMap[i]%8));
249     }
250     pTrg=DataTrigger+141;
251     DataTrigger[148]=EvaluateCrc(pTrg, 7);
252    
253     // TB_READ_TRIGGER_CONF : set always acq.mode TOF4
254     //
255     // TOF1: S1-S2-S3 (&,|)
256     // TOF4: S2-S3 (&,&)
257     DataTrigger[149]=0x02;
258     DataTrigger[150]=0x0;
259     pTrg=DataTrigger+149;
260     DataTrigger[151]=EvaluateCrc(pTrg, 2);
261    
262    
263     //++++++ WRITE EVERYTHING TO DIGITIZER'S BUFFER +++//
264     cout<<"TOF Digitizing"<<endl;
265    
266     fDataC.clear(); //clearing Tof & Trig data buffer
267    
268     for(Int_t i= 0; i<152; i++) fDataC.push_back(DataTrigger[i]);
269    
270     for(Int_t i= 0; i<276; i++) fDataC.push_back(DataTof[i]);
271    
272     }
273    
274     Float_t PamVMCTofDig::TimeRes(Int_t PrimaryPDG){
275    
276 pizzolot 1.6 Float_t time_res[8] = {425.,210.,170.,130.,120.,120.,120.,120.};
277     for(Int_t i=0;i<8;i++) time_res[i]/=1.4;//1.17;1.5;1.3*/
278 nikolas 1.1 Int_t Z = Int_t((TDatabasePDG::Instance()->GetParticle(PrimaryPDG))->Charge()/3.);
279    
280     Float_t dt1 = 1.e-12*time_res[0]; // single PMT resolution for Z=1 (WM, Nov'07)
281     if ((Z > 1) && (Z < 9)) dt1=1.e-12*time_res[(Z-1)];
282     if (Z > 8) dt1=120.e-12;
283    
284     return dt1;
285     }
286    
287     void PamVMCTofDig::DigitizeTofPlane(Int_t planeNo, TClonesArray* HitColl, Int_t PrimaryPDG){
288    
289     PamVMCDetectorHit * hit = 0;
290     const Float_t veff0 = 100.*1.0e8;//(m/s) light velocity in scintillator
291     const Float_t veff1 = 100.*1.5e8;//(m/s) light velocity in lightguide
292     const Float_t FGeo[2] = {0.5, 0.5}; //geometrical factor
293     const Float_t Pho_keV = 10.;// photons per keV in scintillator
294     const Float_t effi = 0.21; //photocathofe efficiency
295     const Float_t pmGain = 3.5e6; //PMT Gain: the same for all PMTs
296     const Float_t echarge = 1.6e-19; // electron charge
297     const Float_t thresh=20.; // to be defined better... (Wolfgang)
298    
299     const Float_t dimel[6] = {33.0, 40.8 ,18.0, 15.0, 15.0, 18.0}; //(cm) TOF paddles dimensions
300     // S11 8 paddles 33.0 x 5.1 cm
301     // S12 6 paddles 40.8 x 5.5 cm
302     // S21 2 paddles 18.0 x 7.5 cm
303     // S22 2 paddles 15.0 x 9.0 cm
304     // S31 3 paddles 15.0 x 6.0 cm
305     // S32 3 paddles 18.0 x 5.0 cm
306    
307     const Float_t s_l_g[6] = {8.0, 8.0, 20.9, 22.0, 9.8, 8.3 }; //(cm) length of the lightguide
308    
309     const Float_t ScaleFact[48]={0.39, 0.49, 0.38, 0.40, 0.65, 0.51, 0.43,
310     0.49, 0.58, 0.38, 0.53, 0.57, 0.53, 0.45, 0.49, 0.16,
311     0.15, 0.44, 0.28, 0.57, 0.26, 0.72, 0.37, 0.29, 0.30, 0.89,
312     0.37, 0.08, 0.27, 0.23, 0.12, 0.22, 0.15, 0.16, 0.21,
313     0.19, 0.41, 0.32, 0.39, 0.38, 0.28, 0.66, 0.28, 0.40, 0.39, 0.40, 0.37, 0.35 };
314    
315     Float_t t1, t2, tpos, Npho;
316     Float_t path[2], knorm[2], Atten[2], QhitPad_pC[2], QhitPmt_pC[2];
317     Int_t padNo, pmtleft, pmtright;
318     //LOOP
319     for(Int_t i =0; i<HitColl->GetEntriesFast(); i++){
320    
321     hit = (PamVMCDetectorHit*)HitColl->At(i);
322    
323     t1=t2 = hit->GetTOF();
324     padNo = hit->GetPOS()-1;
325     pmtleft=pmtright=0;
326 pam-rm2 1.5 if(planeNo==2){
327 nikolas 1.1 if(padNo==0)
328     padNo=1;
329     else
330     padNo=0;
331 pam-rm2 1.5 }
332 nikolas 1.1
333     Paddle2Pmt(planeNo,padNo, &pmtleft, &pmtright);
334    
335     switch(planeNo){
336     case 0:
337     case 3:
338     case 4:
339     tpos = (hit->GetYIN()+hit->GetYOUT())/2.; //Y-planes
340     break;
341     case 1:
342     case 2:
343     case 5:
344     tpos = (hit->GetXIN()+hit->GetXOUT())/2.; //X-planes
345     break;
346     default:
347     cout<<"PamVMCTofDig::DigitizeTOFPlane wrong plane no "<<planeNo<<endl;
348     tpos = -100.;
349     break;
350     }
351    
352     path[0]= tpos + dimel[planeNo]/2.; // path to left PMT
353     path[1]= dimel[planeNo]/2.- tpos; // path to right PMT
354    
355     if (fDEBUG) {
356     cout <<"+++++ TOF HIT VERBOSE INFORMATION: +++++"<<endl;
357     cout <<"planeNo "<<planeNo<<" padNo "<< padNo <<" tpos "<< tpos <<"\n";
358     cout <<"pmtleft, pmtright "<<pmtleft<<","<<pmtright<<endl;
359     }
360    
361     Npho = hit->GetEREL()*Pho_keV*1.0e6; //calculation of photons number
362    
363     for(Int_t j=0; j<2; j++){
364     QhitPad_pC[j]= Npho*FGeo[j]*effi*pmGain*echarge*1.E12*ScaleFact[pmtleft+j];
365     knorm[j]=fatte1[pmtleft+j]*Exp(flambda1[pmtleft+j]*dimel[planeNo]/2.*Power(-1,j+1)) +
366     fatte2[pmtleft+j]*Exp(flambda2[pmtleft+j]*dimel[planeNo]/2.*Power(-1,j+1));
367     Atten[j]=fatte1[pmtleft+j]*Exp(tpos*flambda1[pmtleft+j]) +
368     fatte2[pmtleft+j]*Exp(tpos*flambda2[pmtleft+j]) ;
369     QhitPmt_pC[j]= QhitPad_pC[j]*Atten[j]/knorm[j];
370     if (fDEBUG) {
371     cout<<"pmtleft:"<<pmtleft<<" j:"<<j<<endl;
372     cout<<"atte1:"<<fatte1[pmtleft+j]<<" lambda1:"<<flambda1[pmtleft+j]
373     <<" atte2:"<<fatte2[pmtleft+j]<<" lambda2:"<<flambda2[pmtleft+j]
374     <<endl;
375     cout<<j<<" tpos:"<<tpos<<" knorm:"<<knorm[j]<<" "<<Atten[j]<<" "
376     <<"QhitPmt_pC "<<QhitPmt_pC[j]<<endl;
377     }
378     }
379    
380     if(fDEBUG)cout<<"Energy release (keV):"<<hit->GetEREL()*1.e6<<" Npho:"<<Npho<<
381     " QhitPmt_pC(left,right):"<<QhitPmt_pC[0]<<" "<<QhitPmt_pC[1]<<endl;
382    
383     fQevePmt_pC[pmtleft] += QhitPmt_pC[0]; //cdding charge from separate hits
384     fQevePmt_pC[pmtright] += QhitPmt_pC[1];
385    
386     // TDC
387     // WM right and left <->
388     t1 += Abs(path[0]/veff0) + s_l_g[planeNo]/veff1;
389     t2 += Abs(path[1]/veff0) + s_l_g[planeNo]/veff1; // Signal reaches PMT
390 pam-rm2 1.5 t1 = frandom->Gaus(t1,TimeRes(PrimaryPDG)); //apply gaussian error dt
391     t2 = frandom->Gaus(t2,TimeRes(PrimaryPDG)); //apply gaussian error dt
392 nikolas 1.1 t1 += fc1_S[pmtleft] ; // Signal reaches Discriminator ,TDC starts to run
393     t2 += fc1_S[pmtright] ;
394    
395     // check if signal is above threshold
396     // then check if tdcpmt is already filled by another hit...
397     // only re-fill if time is smaller
398     if (QhitPmt_pC[0] > thresh) {
399     if (ftdcpmt[pmtleft] == 1000.) { // fill for the first time
400     ftdcpmt[pmtleft] = t1;
401     ftdc[pmtleft] = t1 + fc2_S[pmtleft] ; // Signal reaches Coincidence
402     }
403     if (ftdcpmt[pmtleft] < 1000.) // is already filled!
404     if (t1 < ftdcpmt[pmtleft]) {
405     ftdcpmt[pmtleft] = t1;
406     t1 += fc2_S[pmtleft] ; // Signal reaches Coincidence
407     ftdc[pmtleft] = t1;
408     }
409     }
410     if (QhitPmt_pC[1] > thresh) {
411     if (ftdcpmt[pmtright] == 1000.) { // fill for the first time
412     ftdcpmt[pmtright] = t2;
413     ftdc[pmtright] = t2 + fc2_S[pmtright] ; // Signal reaches Coincidence
414     }
415     if (ftdcpmt[pmtright] < 1000.) // is already filled!
416     if (t2 < ftdcpmt[pmtright]) {
417     ftdcpmt[pmtright] = t2;
418 pam-rm2 1.5 t2 += fc2_S[pmtright] ;
419 nikolas 1.1 ftdc[pmtright] = t2;
420     }
421     }
422     if(fDEBUG)cout<<"Time(s):"<<hit->GetTOF()<<" t1:"<<t1<<" t2:"<<t2<<endl
423     <<"+++++ END OF TOF HIT +++++"<<endl;
424 pam-rm2 1.5 };
425     //END OF HIT COLLECTION LOOP
426 nikolas 1.1 }
427    
428     void PamVMCTofDig::Paddle2Pmt(Int_t planeNo, Int_t padNo, Int_t *pl, Int_t *pr){
429     //* @param plane (0 - 5)
430     //* @param paddle (plane=0, paddle = 0,...5)
431     //* @param padid (0 - 23)
432     //
433     Int_t padid=-1;
434     Int_t pads[6]={8,6,2,2,3,3};
435     //
436     Int_t somma=0;
437     for(Int_t j=0; j<planeNo; j++) somma+=pads[j];
438     padid=padNo+somma;
439     *pl = padid*2;
440     *pr = *pl + 1; // WM
441    
442     }
443    
444    
445     UChar_t PamVMCTofDig::Bin2GrayTof(UChar_t binaTOF,UChar_t grayTOF){
446     union graytof_data {
447     UChar_t word;
448     struct bit_field {
449     unsigned b0:1;
450     unsigned b1:1;
451     unsigned b2:1;
452     unsigned b3:1;
453     unsigned b4:1;
454     unsigned b5:1;
455     unsigned b6:1;
456     unsigned b7:1;
457     } bit;
458     } bi,gr;
459     //
460     bi.word = binaTOF;
461     gr.word = grayTOF;
462     //
463     gr.bit.b0 = bi.bit.b1 ^ bi.bit.b0;
464     gr.bit.b1 = bi.bit.b2 ^ bi.bit.b1;
465     gr.bit.b2 = bi.bit.b3 ^ bi.bit.b2;
466     gr.bit.b3 = bi.bit.b3;
467     //
468     /* bin to gray conversion 4 bit per time*/
469     //
470     gr.bit.b4 = bi.bit.b5 ^ bi.bit.b4;
471     gr.bit.b5 = bi.bit.b6 ^ bi.bit.b5;
472     gr.bit.b6 = bi.bit.b7 ^ bi.bit.b6;
473     gr.bit.b7 = bi.bit.b7;
474     //
475     return(gr.word);
476     }
477    
478     void PamVMCTofDig::Crc8Tof(UChar_t *oldCRC, UChar_t *crcTof){
479     union crctof_data {
480     UChar_t word;
481     struct bit_field {
482     unsigned b0:1;
483     unsigned b1:1;
484     unsigned b2:1;
485     unsigned b3:1;
486     unsigned b4:1;
487     unsigned b5:1;
488     unsigned b6:1;
489     unsigned b7:1;
490     } bit;
491     } c,d,r;
492    
493     c.word = *oldCRC;
494     //d.word = *newCRC;
495     d.word = *crcTof;
496     r.word = 0;
497    
498     r.bit.b0 = c.bit.b7 ^ c.bit.b6 ^ c.bit.b0 ^
499     d.bit.b0 ^ d.bit.b6 ^ d.bit.b7;
500    
501     r.bit.b1 = c.bit.b6 ^ c.bit.b1 ^ c.bit.b0 ^
502     d.bit.b0 ^ d.bit.b1 ^ d.bit.b6;
503    
504     r.bit.b2 = c.bit.b6 ^ c.bit.b2 ^ c.bit.b1 ^ c.bit.b0 ^
505     d.bit.b0 ^ d.bit.b1 ^ d.bit.b2 ^ d.bit.b6;
506    
507     r.bit.b3 = c.bit.b7 ^ c.bit.b3 ^ c.bit.b2 ^ c.bit.b1 ^
508     d.bit.b1 ^ d.bit.b2 ^ d.bit.b3 ^ d.bit.b7;
509    
510     r.bit.b4 = c.bit.b4 ^ c.bit.b3 ^ c.bit.b2 ^
511     d.bit.b2 ^ d.bit.b3 ^ d.bit.b4;
512    
513     r.bit.b5 = c.bit.b5 ^ c.bit.b4 ^ c.bit.b3 ^
514     d.bit.b3 ^ d.bit.b4 ^ d.bit.b5;
515    
516     r.bit.b6 = c.bit.b6 ^ c.bit.b5 ^ c.bit.b4 ^
517     d.bit.b4 ^ d.bit.b5 ^ d.bit.b6;
518    
519     r.bit.b7 = c.bit.b7 ^ c.bit.b6 ^ c.bit.b5 ^
520     d.bit.b5 ^ d.bit.b6 ^ d.bit.b7 ;
521    
522     *crcTof=r.word;
523     //return r.word;
524     };
525    
526    
527    
528    
529     UChar_t PamVMCTofDig::EvaluateCrc(UChar_t *pTrg, Int_t nb) {
530     Bool_t DEBUG=false;
531     if (DEBUG)
532     return(0x00);
533    
534     UChar_t crcTrg=0x00;
535     UChar_t *pc=&crcTrg, *pc2;
536     pc2=pTrg;
537     for (Int_t jp=0; jp < nb; jp++)
538     Crc8Tof(pc2++,pc);
539     return(crcTrg);
540     }

  ViewVC Help
Powered by ViewVC 1.1.23