/[PAMELA software]/PamelaDigitizer/DigitizeTRK.cxx
ViewVC logotype

Contents of /PamelaDigitizer/DigitizeTRK.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Wed Oct 15 14:03:19 2008 UTC (16 years, 1 month ago) by pamelats
Branch: MAIN
CVS Tags: v3r04, v3r05, v3r03
Changes since 1.1: +0 -28 lines
Cambiamenti principali: TOF, AC; cambiamenti di struttura (tutti *h esterni si trovano in Digitizer.h)

1 #include "Digitizer.h"
2
3 void Digitizer::DigitizeDummy() {
4
5 // fhBookTree->SetBranchStatus("Enestrip",1);//modified by E.Vannuccini 03/08
6
7 // dumy header
8 fDataDummy[0] = 0xCAAA;
9
10 for (Int_t i=1; i<fDummybuffer; i++){
11 fDataDummy[i] = 0xFFFF;
12 // printf("%0x ",fDataDummy[i]);
13 //if ((i+1)%8 ==0) cout << endl;
14 }
15 };
16
17
18 void Digitizer::DigitizeTrack() {
19 //std:: cout << "Entering DigitizeTrack " << endl;
20 Float_t AdcTrack[fNviews][fNstrips_view]; // Vector of strips to be compressed
21
22 Int_t Iview;
23 Int_t Nstrip;
24
25 for (Int_t j=0; j<fNviews;j++) {
26
27 for (Int_t i=0; i<fNladder;i++) {
28
29 Float_t commonN1=gRandom->Gaus(0.,fSigmaCommon);
30 Float_t commonN2=gRandom->Gaus(0.,fSigmaCommon);
31 for (Int_t k=0; k<fNstrips_ladder;k++) {
32 Nstrip=i*fNstrips_ladder+k;
33 Float_t Sigma=fabs(fSigmaTrack[j][Nstrip]);
34 AdcTrack[j][Nstrip]=gRandom->Gaus(fPedeTrack[j][Nstrip],Sigma );
35 if(k<4*128) {AdcTrack[j][Nstrip] += commonN1;} // full correlation of 4 VA1 Com. Noise
36 else {AdcTrack[j][Nstrip] += commonN2;} // full correlation of 4 VA1 Com. Noise
37 if(AdcTrack[j][Nstrip] < 0. ) AdcTrack[j][Nstrip]=0.;
38 if(AdcTrack[j][Nstrip] > 4095.) AdcTrack[j][Nstrip]=4095.;
39 // if(AdcTrack[j][Nstrip] < 10. ) cout << "j= " << j << "Nstrip= " << Nstrip <<"AdcTrack[j][Nstrip] " << AdcTrack[j][Nstrip] << endl;
40 };
41
42
43 };
44
45
46 };
47
48
49 // fhBookTree->SetBranchStatus("Nstrpx",1);//modified by E.Vannuccini 03/08
50 // fhBookTree->SetBranchStatus("Npstripx",1);
51 // fhBookTree->SetBranchStatus("Ntstripx",1);
52 // fhBookTree->SetBranchStatus("Istripx",1);
53 // fhBookTree->SetBranchStatus("Qstripx",1);
54 // fhBookTree->SetBranchStatus("Xstripx",1);
55 // fhBookTree->SetBranchStatus("Nstrpy",1);
56 // fhBookTree->SetBranchStatus("Npstripy",1);
57 // fhBookTree->SetBranchStatus("Ntstripy",1);
58 // fhBookTree->SetBranchStatus("Istripy",1);
59 // fhBookTree->SetBranchStatus("Qstripy",1);
60 // fhBookTree->SetBranchStatus("Ystripy",1);
61
62
63 Float_t ADCfull;
64 Int_t iladd=0;
65 for (Int_t ix=0; ix<Nstrpx;ix++) {
66 Iview=Npstripx[ix]*2-1;
67 Nstrip=(Int_t)Istripx[ix]-1;
68 if(Nstrip<fNstrips_ladder) iladd=0;
69 if((Nstrip>=fNstrips_ladder)&&(Nstrip<2*fNstrips_ladder)) iladd=1;
70 if((Nstrip>=2*fNstrips_ladder)&&(Nstrip<3*fNstrips_ladder)) iladd=2;
71 ADCfull=AdcTrack[Iview][Nstrip] += Qstripx[ix]*fMipCor[iladd][Iview];
72 AdcTrack[Iview][Nstrip] *= SaturationTrackx(ADCfull);
73
74 };
75
76
77 for (Int_t iy=0; iy<Nstrpy;iy++) {
78 Iview=Npstripy[iy]*2-2;
79 Nstrip=(Int_t)Istripy[iy]-1;
80 if(Nstrip<fNstrips_ladder) iladd=0;
81 if((Nstrip>=fNstrips_ladder)&&(Nstrip<2*fNstrips_ladder)) iladd=1;
82 if((Nstrip>=2*fNstrips_ladder)&&(Nstrip<3*fNstrips_ladder)) iladd=2;
83 ADCfull=AdcTrack[Iview][Nstrip] -= Qstripy[iy]*fMipCor[iladd][Iview];
84 AdcTrack[Iview][Nstrip] *= SaturationTracky(ADCfull);
85
86 };
87
88 CompressTrackData(AdcTrack); // Compress and Digitize data of one Ladder in turn for all ladders
89
90 };
91
92
93
94 void Digitizer::DigitizeTrackCalib(Int_t ii) {
95
96 std:: cout << "Entering DigitizeTrackCalib " << ii << endl;
97 if( (ii!=1)&&(ii!=2) ) {
98 std:: cout << "error wrong DigitizeTrackCalib argument" << endl;
99 return;
100 };
101
102 memset(fDataTrack,0,sizeof(UShort_t)*fTRACKbuffer);
103 fTracklength=0;
104
105 UShort_t Dato;
106
107 Float_t dato1;
108 Float_t dato2;
109 Float_t dato3;
110 Float_t dato4;
111
112 UShort_t DatoDec;
113 UShort_t DatoDec1;
114 UShort_t DatoDec2;
115 UShort_t DatoDec3;
116 UShort_t DatoDec4;
117
118 UShort_t EVENT_CAL;
119 UShort_t PED_L1;
120 UShort_t ReLength;
121 UShort_t OveCheckCode;
122 //UShort_t PED_L2;
123 //UShort_t PED_L3HI;
124 //UShort_t PED_L3LO;
125 //UShort_t SIG_L1HI;
126 //UShort_t SIG_L1LO;
127 //UShort_t SIG_L2HI;
128 //UShort_t SIG_L2LO;
129 //UShort_t SIG_L3;
130 //UShort_t BAD_L1;
131 //UShort_t BAD_L2LO;
132 //UShort_t BAD_L3HI;
133 //UShort_t BAD_L3LO;
134 //UShort_t FLAG;
135
136
137 Int_t DSPpos;
138 for (Int_t j=ii-1; j<fNviews;j+=2) {
139 UShort_t CkSum=0;
140 // here skip the dsp header and his trailer , to be written later
141 DSPpos=fTracklength;
142 fTracklength=fTracklength+13+3;
143
144
145 for (Int_t i=0; i<fNladder;i++) {
146 for (Int_t k=0; k<fNstrips_ladder;k++) {
147 // write in buffer the current LADDER
148 Dato=(UShort_t)fPedeTrack[j][i*fNstrips_ladder+k];
149 dato1=fPedeTrack[j][i*fNstrips_ladder+k]-Dato;
150
151 DatoDec1=(UShort_t)(dato1*2);
152 dato2=dato1*2-DatoDec1;
153
154 DatoDec2=(UShort_t)(dato2*2);
155 dato3=dato2*2-DatoDec2;
156
157 DatoDec3=(UShort_t)(dato3*2);
158 dato4=dato3*2-DatoDec3;
159
160 DatoDec4=(UShort_t)(dato4*2);
161
162 DatoDec=DatoDec1*0x0008+DatoDec2*0x0004+DatoDec3*0x0002+DatoDec4*0x0001;
163 fDataTrack[fTracklength]=( (Dato << 4) | (DatoDec & 0x000F) );
164 CkSum=CkSum^fDataTrack[fTracklength];
165 fTracklength++;
166 };
167
168 for (Int_t k=0; k<fNstrips_ladder;k++) {
169 // write in buffer the current LADDER
170
171 Dato=(UShort_t)fabs(fSigmaTrack[j][i*fNstrips_ladder+k]);
172 dato1=fabs(fSigmaTrack[j][i*fNstrips_ladder+k])-Dato;
173
174 DatoDec1=(UShort_t)(dato1*2);
175 dato2=dato1*2-DatoDec1;
176
177 DatoDec2=(UShort_t)(dato2*2);
178 dato3=dato2*2-DatoDec2;
179
180 DatoDec3=(UShort_t)(dato3*2);
181 dato4=dato3*2-DatoDec3;
182
183 DatoDec4=(UShort_t)(dato4*2);
184
185 DatoDec=DatoDec1*0x0008+DatoDec2*0x0004+DatoDec3*0x0002+DatoDec4*0x0001;
186
187 fDataTrack[fTracklength]=( (Dato << 4) | (DatoDec & 0x000F) );
188 CkSum=CkSum^fDataTrack[fTracklength];
189 fTracklength++;
190 };
191
192 for (Int_t k=0; k<64;k++) {
193 UShort_t DatoBad=0x0000;
194 for (Int_t nb=0; nb<16;nb++) {
195 if( fSigmaTrack[j][i*fNstrips_ladder+k*16+nb]<0. ) DatoBad=( DatoBad | (0x8000 >> nb) );
196
197 };
198 fDataTrack[fTracklength]=DatoBad;
199 CkSum=CkSum^fDataTrack[fTracklength];
200 fTracklength++;
201
202 };
203 // end ladder
204
205 // write in buffer the end ladder word
206 if(i==0) fDataTrack[fTracklength]=0x1807;
207 if(i==1) fDataTrack[fTracklength]=0x1808;
208 if(i==2) fDataTrack[fTracklength]=0x1809;
209 CkSum=CkSum^fDataTrack[fTracklength];
210 fTracklength++;
211
212 // write in buffer the TRAILER
213 ReLength=(UShort_t)((fNstrips_ladder*2+64+1)*2+3);
214 OveCheckCode=0x0000;
215
216 fDataTrack[fTracklength]=0x0000;
217 fTracklength++;
218
219 fDataTrack[fTracklength]=(ReLength >> 8);
220 fTracklength++;
221
222 fDataTrack[fTracklength]=( (ReLength << 8) | (OveCheckCode & 0x00FF) );
223 fTracklength++;
224
225 // end TRAILER
226 };
227
228 // write in buffer the DSP header
229
230 fDataTrack[DSPpos]=(0xE800 | ( ((j+1) << 3) | 0x0005) );
231
232 fDataTrack[DSPpos+1]=0x01A9;
233
234 fDataTrack[DSPpos+2]=0x8740;
235
236 EVENT_CAL=0;
237 fDataTrack[DSPpos+3]=(0x1A00 | ( (0x03FF & EVENT_CAL)>> 1) );
238
239 PED_L1=0;
240 fDataTrack[DSPpos+4]=( ((EVENT_CAL << 15) | 0x5002 ) | ((0x03FF & PED_L1) << 2) );
241
242 // FROM HERE WE WRITE AS ALL VARIABLE apart CkSum are =0
243
244 fDataTrack[DSPpos+5]=0x8014;
245
246 fDataTrack[DSPpos+6]=0x00A0;
247
248 fDataTrack[DSPpos+7]=0x0500;
249
250 fDataTrack[DSPpos+8]=0x2801;
251
252 fDataTrack[DSPpos+9]=0x400A;
253
254 fDataTrack[DSPpos+10]=0x0050;
255
256 CkSum=(CkSum >> 8)^(CkSum&0x00FF);
257 fDataTrack[DSPpos+11]=(0x0280 | (CkSum >> 3));
258
259 fDataTrack[DSPpos+12]=(0x1FFF | (CkSum << 13) );
260
261 // end dsp header
262
263 // write in buffer the TRAILER
264
265 ReLength=(UShort_t)((13*2)+3);
266 OveCheckCode=0x0000;
267 fDataTrack[DSPpos+13]=0x0000;
268
269 fDataTrack[DSPpos+14]=(ReLength >> 8);
270
271 fDataTrack[DSPpos+15]=( (ReLength << 8) | (OveCheckCode & 0x00FF) );
272
273 // end TRAILER
274
275
276
277
278 // end DSP
279 };
280
281
282
283 };
284
285 void Digitizer::WriteTrackCalib() {
286
287
288 std:: cout << " Entering WriteTrackCalib " << endl;
289
290 fOutputfile.write(reinterpret_cast<char*>(fDataPSCU),sizeof(UShort_t)*fPSCUbuffer);
291
292 UShort_t temp[1000000];
293 memset(temp,0,sizeof(UShort_t)*1000000);
294 swab(fDataTrack,temp,sizeof(UShort_t)*fTracklength); // WE MUST SWAP THE BYTES!!!
295 fOutputfile.write(reinterpret_cast<char*>(temp),sizeof(UShort_t)*fTracklength);
296 fTracklength=0;
297 if ( fPadding ){
298 fOutputfile.write(reinterpret_cast<char*>(fDataPadding),sizeof(UChar_t)*fPadding);
299 };
300
301 };
302
303
304 void Digitizer::ClearTrackCalib() {
305
306 std:: cout << "Entering ClearTrackCalib " << endl;
307
308
309 };
310
311
312 void Digitizer::LoadTrackCalib() {
313 std:: cout << "Entering LoadTrackCalib " << endl;
314
315
316 // prepare correction factors
317 Float_t sigmacorr[12];
318 sigmacorr[0]=1.;
319 sigmacorr[1]=1.;
320 sigmacorr[2]=1.;
321 sigmacorr[3]=1.;
322 sigmacorr[4]=1.;
323 sigmacorr[5]=1.;
324 sigmacorr[6]=1.;
325 sigmacorr[7]=1.;
326 sigmacorr[8]=1.;
327 sigmacorr[9]=1.;
328 sigmacorr[10]=1.;
329 sigmacorr[11]=1.;
330
331 stringstream calibfile;
332 Int_t error = 0;
333 TFile *FileCalib= NULL;
334
335 GL_PARAM *glparam = new GL_PARAM();
336 error = 0;
337 error = glparam->Query_GL_PARAM(0,8,fDbc);
338
339 if(error<0) {
340 FileCalib = new TFile("CalibTrk_00110_000_000.root");
341 printf("\n No entry in Database. Use file tracker GP calibration From Main Directory\n");
342 } else {
343 //
344 calibfile.str("");
345 calibfile << glparam->PATH.Data() << "/";
346 calibfile << glparam->NAME.Data();
347 //
348 printf("\n Using GP calibration file for tracker : \n %s \n",calibfile.str().c_str());
349 FileCalib = new TFile( calibfile.str().c_str() );
350
351
352 if ( FileCalib==NULL ) {
353 FileCalib = new TFile("CalibTrk_00110_000_000.root");
354 printf("\n No file in Database.Use file tracker GP calibration From Main Directory\n");
355 } else {
356 if ( FileCalib->IsZombie() ) {
357 FileCalib = new TFile("CalibTrk_00110_000_000.root");
358 printf("\n No file in Database. Use file tracker GP calibration From Main Directory\n");
359 };
360
361
362 };
363 };
364
365 TTree *tr1 = (TTree*)FileCalib->Get("CalibTrk1");
366 CalibTrk1Event *calibdata1 = 0;
367 tr1->SetBranchAddress("CalibTrk1",&calibdata1);
368 tr1->GetEntry(1);
369
370
371 Int_t ixbr=0;
372 Int_t iybr=0;
373 Int_t iva1=0;
374 Int_t Kview=0;
375 Int_t jj=0;
376 for (Int_t i=0; i<6;i++) {
377
378 for (Int_t j=0; j<3072;j++) {
379
380 jj=j;
381
382 // broken va1 replaced
383 ixbr=0;
384 iva1=4;
385 if(i==ixbr && j>=(256*(iva1-1)) && j<(256*iva1)) jj=j-(256*(iva1-1));
386
387 ixbr=5;
388 iva1=12;
389 if(i==ixbr && j>=(256*(iva1-1)) && j<(256*iva1)) jj=j-(256*(iva1-1));
390 //
391
392 //Kview=11-(i*2);
393 Kview=calibdata1->DSPnumber[i]-1;
394 fPedeTrack[Kview][j]=calibdata1->DSPped_par[i][jj];
395 fSigmaTrack[Kview][j]=sigmacorr[Kview]*calibdata1->DSPsig_par[i][jj];
396 if(calibdata1->DSPbad_par[i][jj]==1) fSigmaTrack[Kview][j]=-fSigmaTrack[Kview][j];
397
398 };
399 };
400
401 TTree *tr2 = (TTree*)FileCalib->Get("CalibTrk2");
402 CalibTrk2Event *calibdata2 = 0;
403 tr2->SetBranchAddress("CalibTrk2",&calibdata2);
404 tr2->GetEntry(1);
405 for (Int_t i=0; i<6;i++) {
406
407 for (Int_t j=0; j<3072;j++) {
408 jj=j;
409
410 // broken va1 replaced
411 iybr=2;
412 iva1=3;
413 if(i==iybr && j>=(256*(iva1-1)) && j<(256*iva1)) jj=j-(256*(iva1-1));
414
415 iybr=2;
416 iva1=5;
417 if(i==iybr && j>=(256*(iva1-1)) && j<(256*iva1)) jj=j-(256*(iva1-1));
418
419 iybr=2;
420 iva1=6;
421 if(i==iybr && j>=(256*(iva1-1)) && j<(256*iva1)) jj=j-(256*(iva1-1));
422
423
424 iybr=2;
425 iva1=7;
426 if(i==iybr && j>=(256*(iva1-1)) && j<(256*iva1)) jj=j-(256*(iva1-1));
427
428
429 iybr=2;
430 iva1=11;
431 if(i==iybr && j>=(256*(iva1-1)) && j<(256*iva1)) jj=j-(256*(iva1-1));
432 //
433
434 //Kview=11-(i*2+1);
435 Kview=calibdata2->DSPnumber[i]-1;
436 fPedeTrack[Kview][j]=calibdata2->DSPped_par[i][jj];
437 fSigmaTrack[Kview][j]=sigmacorr[Kview]*calibdata2->DSPsig_par[i][jj];
438 if(calibdata2->DSPbad_par[i][jj]==1) fSigmaTrack[Kview][j]=-fSigmaTrack[Kview][j];
439
440 };
441 };
442
443
444
445 FileCalib->Close();
446 delete glparam;
447 // Generate the pedestals and sigmas according to parametrization
448 // for (Int_t j=0; j<fNviews;j++) {
449 // for (Int_t i=0; i<fNstrips_view;i++) {
450
451 // if((j+1)%2==0) {
452 // fPedeTrack[j][i]=gRandom->Gaus(fAvePedex,fSigmaPedex);
453 // fSigmaTrack[j][i]=gRandom->Gaus(fAveSigmax,fSigmaSigmax);
454 // std:: cout << "j= " << j+1 << "i= " << i+1 <<"X ! fPedeTrack[j][i] " << fPedeTrack[j][i] << endl;
455 // std:: cout << "j= " << j+1 << "i= " << i+1 <<"X ! fSigmaTrack[j][i] " << fSigmaTrack[j][i] << endl;
456 // if (fSigmaTrack[j][i]<0.1) { fSigmaTrack[j][i]=0.1 ; };
457
458 // };
459 // if((j+1)%2==1) {
460 // fPedeTrack[j][i]=gRandom->Gaus(fAvePedey,fSigmaPedey);
461 // fSigmaTrack[j][i]=gRandom->Gaus(fAveSigmay,fSigmaSigmay);
462 // std:: cout << "j= " << j+1 << "i= " << i+1 <<"Y ! fPedeTrack[j][i] " << fPedeTrack[j][i] << endl;
463 // std:: cout << "j= " << j+1 << "i= " << i+1 <<"Y ! fSigmaTrack[j][i] " << fSigmaTrack[j][i] << endl;
464 // };
465 //
466 // };
467 // };
468
469
470
471 };
472
473 void Digitizer::LoadMipCor() {
474 std:: cout << "Entering LoadMipCor" << endl;
475 Float_t xfactor=1./151.6*1.04;
476 Float_t yfactor=1./152.1;
477
478 fMipCor[0][0]=140.02*yfactor;
479 fMipCor[0][1]=140.99*xfactor;
480 fMipCor[0][2]=134.48*yfactor;
481 fMipCor[0][3]=144.41*xfactor;
482 fMipCor[0][4]=140.74*yfactor;
483 fMipCor[0][5]=142.28*xfactor;
484 fMipCor[0][6]=134.53*yfactor;
485 fMipCor[0][7]=140.63*xfactor;
486 fMipCor[0][8]=135.55*yfactor;
487 fMipCor[0][9]=138.00*xfactor;
488 fMipCor[0][10]=154.95*yfactor;
489 fMipCor[0][11]=158.44*xfactor;
490
491
492 fMipCor[1][0]=136.07*yfactor;
493 fMipCor[1][1]=135.59*xfactor;
494 fMipCor[1][2]=142.69*yfactor;
495 fMipCor[1][3]=138.19*xfactor;
496 fMipCor[1][4]=137.35*yfactor;
497 fMipCor[1][5]=140.23*xfactor;
498 fMipCor[1][6]=153.15*yfactor;
499 fMipCor[1][7]=151.42*xfactor;
500 fMipCor[1][8]=129.76*yfactor;
501 fMipCor[1][9]=140.63*xfactor;
502 fMipCor[1][10]=157.87*yfactor;
503 fMipCor[1][11]=153.64*xfactor;
504
505 fMipCor[2][0]=134.98*yfactor;
506 fMipCor[2][1]=143.95*xfactor;
507 fMipCor[2][2]=140.23*yfactor;
508 fMipCor[2][3]=138.88*xfactor;
509 fMipCor[2][4]=137.95*yfactor;
510 fMipCor[2][5]=134.87*xfactor;
511 fMipCor[2][6]=157.56*yfactor;
512 fMipCor[2][7]=157.31*xfactor;
513 fMipCor[2][8]=141.37*yfactor;
514 fMipCor[2][9]=143.39*xfactor;
515 fMipCor[2][10]=156.15*yfactor;
516 fMipCor[2][11]=158.79*xfactor;
517
518 /*
519 for (Int_t j=0; j<fNviews;j++) {
520 for (Int_t i=0; i<fNstrips_view;i++) {
521 fMipCor[j][i]=1.;
522 };
523 };
524
525
526 */
527 };
528
529 void Digitizer::CompressTrackData(Float_t AdcTrack[fNviews][fNstrips_view]) {
530 // copy of the corresponding compression fortran routine + new digitization
531 // std:: cout << "Entering CompressTrackData " << endl;
532 Int_t oldval=0;
533 Int_t newval=0;
534 Int_t trasmesso=0;
535 Int_t ntrastot=0;
536 Float_t real;
537 Float_t inte;
538 Int_t cercacluster=0;
539 Int_t kt=0;
540 static const int DSPbufferSize = 4000; // 13 bit buffer to be rearranged in 16 bit Track buffer
541 UShort_t DataDSP[DSPbufferSize]; // 13 bit buffer to be rearranged in 16 bit Track buffer
542 UShort_t DSPlength; // 13 bit buffer to be rearranged in 16 bit Track buffer
543
544 memset(fDataTrack,0,sizeof(UShort_t)*fTRACKbuffer); // probably not necessary becouse already done ?
545 fTracklength=0;
546
547 for (Int_t iv=0; iv<fNviews;iv++) {
548 memset(DataDSP,0,sizeof(UShort_t)*DSPbufferSize);
549 DSPlength=16; // skip the header, to be written later
550 UShort_t CheckSum=0;
551 // write dsp header on buffer
552
553 // fDataTrack[fTracklength]=0xE805;
554 // fTracklength++;
555
556 // fDataTrack[fTracklength]=0x01A9;
557 // fTracklength++;
558
559 // end dsp header
560
561 //
562 // INIZIO VISTA IV - TAKE PROPER ACTION
563 //
564
565
566
567 for (Int_t ladder=0; ladder<fNladder;ladder++) {
568 Int_t k=0;
569 while (k<fNstrips_ladder) {
570 // compress write in buffer the current LADDER
571 if ( k == 0) {
572 real=modff(AdcTrack[iv][ladder*fNstrips_ladder+k],&inte);
573 if (real > 0.5) inte=inte+1;
574 newval=(Int_t)inte -(Int_t)fPedeTrack[iv][ladder*fNstrips_ladder+k];
575 // first strip of ladder is transmitted
576 // DC_TOT first " << AdcTrack[iv][ladder*fNstrips_ladder+k] << endl;
577 DataDSP[DSPlength]=( ((UShort_t)inte) & 0x0FFF);
578 DSPlength++;
579 ntrastot++;
580 trasmesso=1;
581 oldval=newval;
582 kt=k;
583 k++;
584 continue;
585 };
586 real=modff(AdcTrack[iv][ladder*fNstrips_ladder+k],&inte);
587 if (real > 0.5) inte=inte+1;
588 newval=(Int_t)inte -(Int_t)(fPedeTrack[iv][ladder*fNstrips_ladder+k]);
589 cercacluster=1; // ?????????
590 if (cercacluster==1) {
591
592 // controlla l'ordine di tutti queste strip ladder e DSP !!!!!!!
593 Int_t diff=0;
594
595
596 switch ((iv+1)%2) {
597 case 0: diff=newval-oldval;
598 break;
599 case 1: diff=oldval-newval;
600 break;
601 };
602
603 if (diff>fCutclu*(Int_t)fabs(fSigmaTrack[iv][ladder*fNstrips_ladder+k]) ) {
604 Int_t clval=newval;
605 Int_t klp=k; // go on to search for maximum
606 klp++;
607
608 while(klp<fNstrips_ladder) {
609 real=modff(AdcTrack[iv][ladder*fNstrips_ladder+klp],&inte);
610 if (real > 0.5) inte=inte+1;
611 Int_t clvalp=(Int_t)inte -(Int_t)fPedeTrack[iv][ladder*fNstrips_ladder+klp];
612 if((iv+1)%2==0) {
613
614 if(clvalp>clval) {
615 clval=clvalp;
616 k=klp;}
617 else break; // max of cluster found
618
619 } else {
620
621 if(clvalp<clval) {
622 clval=clvalp;
623 k=klp;}
624 else break; // max of cluster found
625
626 };
627
628 klp++;
629 };
630
631 Int_t kl1=k-fNclst; // max of cluster (or end of ladder ?)
632 trasmesso=0;
633 if(kl1<0) kl1=0;
634
635 if(kt>=kl1) kl1=kt+1;
636 if( (kt+1)==kl1 ) trasmesso=1;
637
638
639
640 Int_t kl2=k+fNclst;
641 if(kl2>=fNstrips_ladder) kl2=fNstrips_ladder-1;
642
643 for(Int_t klt=kl1 ; klt<=kl2 ; klt++) {
644 if(trasmesso==0) {
645 // std:: cout << "STRIP " << klt << endl;
646 // std:: cout << "ADC_TOT " <<AdcTrack[iv][ladder*fNstrips_ladder+klt] << endl;
647
648 DataDSP[DSPlength]=( ((UShort_t)klt) | 0x1000);
649 DSPlength++;
650 ntrastot++;
651
652
653 real=modff(AdcTrack[iv][ladder*fNstrips_ladder+klt],&inte);
654 if (real > 0.5) inte=inte+1;
655 DataDSP[DSPlength]=( ((UShort_t)inte) & 0x0FFF);
656 DSPlength++;
657 ntrastot++;
658
659 }
660 else {
661 // std:: cout << "ADC_TOT " <<AdcTrack[iv][ladder*fNstrips_ladder+klt] << endl;
662 real=modff(AdcTrack[iv][ladder*fNstrips_ladder+klt],&inte);
663 if (real > 0.5) inte=inte+1;
664 DataDSP[DSPlength]=( ((UShort_t)inte) & 0x0FFF);
665 DSPlength++;
666 ntrastot++;
667 };
668 trasmesso=1;
669 }; // end trasmission
670 kt=kl2;
671 k=kl2;
672 real=modff(AdcTrack[iv][ladder*fNstrips_ladder+kt],&inte);
673 if (real > 0.5) inte=inte+1;
674 oldval=(Int_t)inte -(Int_t)fPedeTrack[iv][ladder*fNstrips_ladder+kt];
675 k++;
676 continue;
677
678
679 }; // end cercacluster
680 }; // end cercacluster
681
682 // start ZOP check for strips no
683
684 if(abs(newval-oldval)>=fCutzop*(Int_t)fabs(fSigmaTrack[iv][ladder*fNstrips_ladder+k]) ) {
685
686 if(trasmesso==0) {
687 // std:: cout << "STRIP " << k << endl;
688 // std:: cout << "ADC_TOT " << AdcTrack[iv][ladder*fNstrips_ladder+k] << endl;
689
690 DataDSP[DSPlength]=( ((UShort_t)k) | 0x1000);
691 DSPlength++;
692 ntrastot++;
693
694
695 real=modff(AdcTrack[iv][ladder*fNstrips_ladder+k],&inte);
696 if (real > 0.5) inte=inte+1;
697 DataDSP[DSPlength]=( ((UShort_t)inte) & 0x0FFF);
698 DSPlength++;
699 ntrastot++;
700
701 }
702 else {
703 // std:: cout << "ADC_TOT " << AdcTrack[iv][ladder*fNstrips_ladder+k] << endl;
704 real=modff(AdcTrack[iv][ladder*fNstrips_ladder+k],&inte);
705 if (real > 0.5) inte=inte+1;
706 DataDSP[DSPlength]=( ((UShort_t)inte) & 0x0FFF);
707 DSPlength++;
708 ntrastot++;
709 };
710 trasmesso=1;
711 oldval=newval;
712 kt=k;
713
714 }
715 else trasmesso=0;
716 // end zop
717
718 k++;
719 }; // end cycle inside ladder
720 // write here the end ladder bytes
721 // std:: cout << "FINE LADDER " << ladder+1 << endl;
722
723 DataDSP[DSPlength]=( ((UShort_t)(ladder+1)) | 0x1800);
724 DSPlength++;
725 ntrastot++;
726 trasmesso=0;
727
728 }; //end cycle inside dsp
729 // std:: cout << "FINE DSP " << iv+1 << endl;
730 // here put DSP header
731 DataDSP[0]=(0x1CA0 | ((UShort_t)(iv+1)) );
732 UShort_t Nword=(DSPlength*13)/16;
733 if( ((DSPlength*13)%16)!=0) Nword++;
734 DataDSP[1]=(0x1400 | ( Nword >> 10));
735 DataDSP[2]=(0x1400 | ( Nword & 0x03FF) );
736 DataDSP[3]=(0x1400 | (( (UShort_t)(fCounter >> 10) ) & 0x03FF) );
737 DataDSP[4]=(0x1400 | (( (UShort_t)(fCounter) ) & 0x03FF) );
738 DataDSP[5]=(0x1400 | ( (UShort_t)(fNclst << 7) ) | ( (UShort_t)(fCutzop << 4) )
739 | ( (UShort_t)fCutzop ) );
740 DataDSP[6]=0x1400;
741 DataDSP[7]=0x1400;
742 DataDSP[8]=0x1400;
743 DataDSP[9]=0x1400;
744 DataDSP[10]=0x1400;
745 DataDSP[11]=0x1400;
746 DataDSP[12]=0x1400;
747 DataDSP[13]=0x1400;
748 DataDSP[14]=(0x1400 | (CheckSum & 0x00FF) );
749 DataDSP[15]=0x1C00;
750 // end DSP header
751
752
753 // write 13 bit DataDSP bufer inside 16 bit fDataTrack buffer
754 Int_t Bit16free=16;
755 UShort_t Dato;
756 for (Int_t NDSP=0; NDSP<DSPlength;NDSP++) {
757 Int_t Bit13ToWrite=13;
758 while(Bit13ToWrite>0) {
759 if(Bit13ToWrite<=Bit16free) {
760 Dato=((DataDSP[NDSP]&(0xFFFF >> (16-Bit13ToWrite)))<<(Bit16free-Bit13ToWrite));
761 fDataTrack[fTracklength]=fDataTrack[fTracklength] | Dato ;
762 Bit16free=Bit16free-Bit13ToWrite;
763 Bit13ToWrite=0;
764 if(Bit16free==0) {
765 if(NDSP>15) CheckSum=CheckSum^fDataTrack[fTracklength];
766 fTracklength++;
767 Bit16free=16;
768 };
769 }
770 else if(Bit13ToWrite>Bit16free) {
771 Dato=( (DataDSP[NDSP]&(0xFFFF >> (16-Bit13ToWrite) ) ) >> (Bit13ToWrite-Bit16free) );
772 fDataTrack[fTracklength]=fDataTrack[fTracklength] | Dato ;
773 if(NDSP>15) CheckSum=CheckSum^fDataTrack[fTracklength];
774 fTracklength++;
775 Bit13ToWrite=Bit13ToWrite-Bit16free;
776 Bit16free=16;
777 };
778
779 }; // end cycle while(Bit13ToWrite>0)
780
781 }; // end cycle DataDSP
782 if(Bit16free!=16) { fTracklength++; CheckSum=CheckSum^fDataTrack[fTracklength]; };
783 CheckSum=(CheckSum >> 8)^(CheckSum&0x00FF);
784 fDataTrack[fTracklength-Nword+11]=(0x0280 | (CheckSum >> 3));
785 fDataTrack[fTracklength-Nword+12]=(0x1C00 | (CheckSum << 13) );
786
787 // end write 13 bit DataDSP bufer inside 16 bit fDataTrack buffer
788
789 //write trailer on buffer
790 UShort_t ReLength=(UShort_t)((Nword+13)*2+3);
791 UShort_t OveCheckCode=0x0000;
792
793 fDataTrack[fTracklength]=0x0000;
794 fTracklength++;
795
796 fDataTrack[fTracklength]=(ReLength >> 8);
797 fTracklength++;
798
799 fDataTrack[fTracklength]=( (ReLength << 8) | (OveCheckCode & 0x00FF) );
800 fTracklength++;
801 // end trailer
802 // std:: cout << "DSPlength " <<DSPlength << endl;
803 // std:: cout << "Nword " << Nword << endl;
804 // std:: cout << "ReLength " << ReLength << endl;
805 };
806 // std:: cout << "ntrastot " << ntrastot << endl;
807
808 };
809
810
811 Float_t Digitizer::SaturationTrackx(Float_t ADC) {
812 Float_t SatFact=1.;
813 if(ADC<1.) { SatFact=1./ADC; };
814 if(ADC>3000.) { SatFact=3000./ADC; };
815 return SatFact;
816 };
817
818
819
820
821 Float_t Digitizer::SaturationTracky(Float_t ADC) {
822 Float_t SatFact=1.;
823 if(ADC<70.) { SatFact=70./ADC; };
824 if(ADC>4095.) { SatFact=4095./ADC; };
825 return SatFact;
826 };

  ViewVC Help
Powered by ViewVC 1.1.23