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

Contents of /PamelaDigitizer/DigitizeTRK.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Wed May 21 09:50:43 2008 UTC (16 years, 6 months ago) by pamelats
Branch: MAIN
CVS Tags: v3r00, v3r01, v3r02
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23