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

Contents of /PamelaDigitizer/DigitizeCalo.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Fri Nov 13 09:08:53 2009 UTC (15 years ago) by pizzolot
Branch: MAIN
Changes since 1.3: +3 -1 lines
fixed crc calculation of TOF and CALOCompress, implemented crc of AC

1 #include "Digitizer.h"
2
3 extern "C"{
4 short crc(short, short);
5 };
6
7 void Digitizer::ClearCaloCalib(Int_t s){
8 //
9 fcstwerr[s] = 0;
10 fcperror[s] = 0.;
11 for ( Int_t d=0 ; d<11 ;d++ ){
12 Int_t pre = -1;
13 for ( Int_t j=0; j<96 ;j++){
14 if ( j%16 == 0 ) pre++;
15 fcalped[s][d][j] = 0.;
16 fcstwerr[s] = 0.;
17 fcperror[s] = 0.;
18 fcalgood[s][d][j] = 0.;
19 fcalthr[s][d][pre] = 0.;
20 fcalrms[s][d][j] = 0.;
21 fcalbase[s][d][pre] = 0.;
22 fcalvar[s][d][pre] = 0.;
23 };
24 };
25 return;
26 }
27
28 Int_t Digitizer::CaloLoadCalib(Int_t s,TString fcalname, UInt_t calibno){
29 //
30 //
31 UInt_t e = 0;
32 if ( s == 0 ) e = 0;
33 if ( s == 1 ) e = 2;
34 if ( s == 2 ) e = 3;
35 if ( s == 3 ) e = 1;
36 //
37 ifstream myfile;
38 myfile.open(fcalname.Data());
39 if ( !myfile ){
40 return(-107);
41 };
42 myfile.close();
43 //
44 TFile *File = new TFile(fcalname.Data());
45 if ( !File ) return(-108);
46 TTree *tr = (TTree*)File->Get("CalibCalPed");
47 if ( !tr ) return(-109);
48 //
49 TBranch *calo = tr->GetBranch("CalibCalPed");
50 //
51 pamela::CalibCalPedEvent *ce = 0;
52 tr->SetBranchAddress("CalibCalPed", &ce);
53 //
54 Long64_t ncalibs = calo->GetEntries();
55 //
56 if ( !ncalibs ) return(-110);
57 //
58 calo->GetEntry(calibno);
59 //
60 if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) {
61 fcstwerr[s] = ce->cstwerr[s];
62 fcperror[s] = ce->cperror[s];
63 for ( Int_t d=0 ; d<11 ;d++ ){
64 Int_t pre = -1;
65 for ( Int_t j=0; j<96 ;j++){
66 if ( j%16 == 0 ) pre++;
67 fcalped[s][d][j] = ce->calped[e][d][j];
68 fcalgood[s][d][j] = ce->calgood[e][d][j];
69 fcalthr[s][d][pre] = ce->calthr[e][d][pre];
70 fcalrms[s][d][j] = ce->calrms[e][d][j];
71 fcalbase[s][d][pre] = ce->calbase[e][d][pre];
72 fcalvar[s][d][pre] = ce->calvar[e][d][pre];
73 };
74 };
75 } else {
76 printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n ");
77 File->Close();
78 return(-111);
79 };
80 File->Close();
81 return(0);
82 }
83
84
85 void Digitizer::DigitizeCALOCALIB() {
86 //
87 // Header of the four sections
88 //
89 fSecCalo[0] = 0xAA00; // XE
90 fSecCalo[1] = 0xB100; // XO
91 fSecCalo[2] = 0xB600; // YE
92 fSecCalo[3] = 0xAD00; // YO
93 //
94 // length of the data is 0x1215
95 //
96 fSecCALOLength[0] = 0x1215; // XE
97 fSecCALOLength[1] = 0x1215; // XO
98 fSecCALOLength[2] = 0x1215; // YE
99 fSecCALOLength[3] = 0x1215; // YO
100 //
101 Int_t chksum = 0;
102 UInt_t tstrip = 0;
103 UInt_t fSecPointer = 0;
104 //
105 for (Int_t sec=0; sec < 4; sec++){
106 //
107 // sec = 0 -> XE 1 -> XO 2-> YE 3 -> YO
108 //
109 fCALOlength = 0;
110 memset(fDataCALO,0,sizeof(UShort_t)*fCALObuffer);
111 fSecPointer = fCALOlength;
112 //
113 // First of all we have section header and packet length
114 //
115 fDataCALO[fCALOlength] = fSecCalo[sec];
116 fCALOlength++;
117 fDataCALO[fCALOlength] = fSecCALOLength[sec];
118 fCALOlength++;
119 //
120 // Section XO is read in the opposite direction respect to the others
121 //
122 chksum = 0;
123 //
124 for (Int_t plane=0; plane < 11; plane++){
125 //
126 if ( sec == 1 ) tstrip = fCALOlength + 96*2;
127 //
128 for (Int_t strip=0; strip < 96; strip++){
129 //
130 chksum += (Int_t)fcalped[sec][plane][strip];
131 //
132 // save value
133 //
134 if ( sec == 1 ){
135 tstrip -= 2;
136 fDataCALO[tstrip] = (Int_t)fcalped[sec][plane][strip];
137 fDataCALO[tstrip+1] = (Int_t)fcalgood[sec][plane][strip];
138 } else {
139 fDataCALO[fCALOlength] = (Int_t)fcalped[sec][plane][strip];
140 fDataCALO[fCALOlength+1] = (Int_t)fcalgood[sec][plane][strip];
141 };
142 fCALOlength +=2;
143 };
144 //
145 };
146 //
147 fDataCALO[fCALOlength] = (UShort_t)chksum;
148 fCALOlength++;
149 fDataCALO[fCALOlength] = 0;
150 fCALOlength++;
151 fDataCALO[fCALOlength] = (UShort_t)((Int_t)(chksum >> 16));
152 fCALOlength++;
153 //
154 // Section XO is read in the opposite direction respect to the others
155 //
156 chksum = 0;
157 //
158 for (Int_t plane=0; plane < 11; plane++){
159 //
160 if ( sec == 1 ) tstrip = fCALOlength+6*2;
161 //
162 for (Int_t strip=0; strip < 6; strip++){
163 //
164 chksum += (Int_t)fcalthr[sec][plane][strip];
165 //
166 // save value
167 //
168 if ( sec == 1 ){
169 tstrip -= 2;
170 fDataCALO[tstrip] = 0;
171 fDataCALO[tstrip+1] = (Int_t)fcalthr[sec][plane][strip];
172 } else {
173 fDataCALO[fCALOlength] = 0;
174 fDataCALO[fCALOlength+1] = (Int_t)fcalthr[sec][plane][strip];
175 };
176 fCALOlength +=2;
177 };
178 //
179 };
180 //
181 fDataCALO[fCALOlength] = 0;
182 fCALOlength++;
183 fDataCALO[fCALOlength] = (UShort_t)chksum;
184 fCALOlength++;
185 fDataCALO[fCALOlength] = 0;
186 fCALOlength++;
187 fDataCALO[fCALOlength] = (UShort_t)((Int_t)(chksum >> 16));
188 fCALOlength++;
189 //
190 // Section XO is read in the opposite direction respect to the others
191 //
192 for (Int_t plane=0; plane < 11; plane++){
193 //
194 if ( sec == 1 ) tstrip = fCALOlength+96*2;
195 //
196 for (Int_t strip=0; strip < 96; strip++){
197 //
198 // save value
199 //
200 if ( sec == 1 ){
201 tstrip -= 2;
202 fDataCALO[tstrip] = 0;
203 fDataCALO[tstrip+1] = (Int_t)fcalrms[sec][plane][strip];
204 } else {
205 fDataCALO[fCALOlength] = 0;
206 fDataCALO[fCALOlength+1] = (Int_t)fcalrms[sec][plane][strip];
207 };
208 fCALOlength += 2;
209 };
210 //
211 };
212 //
213 // Section XO is read in the opposite direction respect to the others
214 //
215 for (Int_t plane=0; plane < 11; plane++){
216 //
217 if ( sec == 1 ) tstrip = fCALOlength+6*4;
218 //
219 for (Int_t strip=0; strip < 6; strip++){
220 //
221 // save value
222 //
223 if ( sec == 1 ){
224 tstrip -= 4;
225 fDataCALO[tstrip] = 0;
226 fDataCALO[tstrip+1] = (Int_t)fcalbase[sec][plane][strip];
227 fDataCALO[tstrip+2] = 0;
228 fDataCALO[tstrip+3] = (Int_t)fcalvar[sec][plane][strip];
229 } else {
230 fDataCALO[fCALOlength] = 0;
231 fDataCALO[fCALOlength+1] = (Int_t)fcalbase[sec][plane][strip];
232 fDataCALO[fCALOlength+2] = 0;
233 fDataCALO[fCALOlength+3] = (Int_t)fcalvar[sec][plane][strip];
234 };
235 fCALOlength +=4;
236 };
237 //
238 };
239 //
240 //
241 // here we calculate and save the CRC
242 //
243 fDataCALO[fCALOlength] = 0;
244 fCALOlength++;
245 Short_t CRC = 0;
246 for (UInt_t i=0; i<(fCALOlength-fSecPointer); i++){
247 CRC=crc(CRC,fDataCALO[i+fSecPointer]);
248 };
249 fDataCALO[fCALOlength] = (UShort_t)CRC;
250 fCALOlength++;
251 //
252 UInt_t length=fCALOlength*2;
253 DigitizePSCU(length,0x18,fDataPSCU);
254 //
255 // Add padding to 64 bits
256 //
257 AddPadding();
258 //
259 fOutputfile.write(reinterpret_cast<char*>(fDataPSCU),sizeof(UShort_t)*fPSCUbuffer);
260 UShort_t temp[1000000];
261 memset(temp,0,sizeof(UShort_t)*1000000);
262 swab(fDataCALO,temp,sizeof(UShort_t)*fCALOlength); // WE MUST SWAP THE BYTES!!!
263 fOutputfile.write(reinterpret_cast<char*>(temp),sizeof(UShort_t)*fCALOlength);
264 //
265 // padding to 64 bytes
266 //
267 if ( fPadding ){
268 fOutputfile.write(reinterpret_cast<char*>(fDataPadding),sizeof(UChar_t)*fPadding);
269 };
270 //
271 //
272 };
273 //
274 };
275
276 void Digitizer::CaloLoadCalib() {
277 //
278 fGivenCaloCalib = 0; // ####@@@@ should be given as input par @@@@####
279 //
280 // first of all load the MIP to ADC conversion values
281 //
282 stringstream calfile;
283 Int_t error = 0;
284 GL_PARAM *glparam = new GL_PARAM();
285 //
286 // determine where I can find calorimeter ADC to MIP conversion file
287 //
288 error = 0;
289 error = glparam->Query_GL_PARAM(3,101,fDbc);
290 //
291 calfile.str("");
292 calfile << glparam->PATH.Data() << "/";
293 calfile << glparam->NAME.Data();
294 //
295 printf("\n Using Calorimeter ADC to MIP conversion file: \n %s \n",calfile.str().c_str());
296 FILE *f;
297 f = fopen(calfile.str().c_str(),"rb");
298 //
299 memset(fCalomip,0,4224*sizeof(fCalomip[0][0][0]));
300 //
301 for (Int_t m = 0; m < 2 ; m++ ){
302 for (Int_t k = 0; k < 22; k++ ){
303 for (Int_t l = 0; l < 96; l++ ){
304 fread(&fCalomip[m][k][l],sizeof(fCalomip[m][k][l]),1,f);
305 };
306 };
307 };
308 fclose(f);
309 //
310 // determine which calibration has to be used and load it for each section
311 //
312 GL_CALO_CALIB *glcalo = new GL_CALO_CALIB();
313 GL_ROOT *glroot = new GL_ROOT();
314 TString fcalname;
315 UInt_t idcalib;
316 UInt_t calibno;
317 UInt_t utime = 0;
318 //
319 for (UInt_t s=0; s<4; s++){
320 //
321 // clear calo calib variables for section s
322 //
323 ClearCaloCalib(s);
324 //
325 if ( fGivenCaloCalib ){
326 //
327 // a time has been given as input on the command line so retrieve the calibration that preceed that time
328 //
329 glcalo->Query_GL_CALO_CALIB(fGivenCaloCalib,utime,s,fDbc);
330 //
331 calibno = glcalo->EV_ROOT;
332 idcalib = glcalo->ID_ROOT_L0;
333 //
334 // determine path and name and entry of the calibration file
335 //
336 printf("\n");
337 printf(" ** SECTION %i **\n",s);
338 //
339 glroot->Query_GL_ROOT(idcalib,fDbc);
340 //
341 stringstream name;
342 name.str("");
343 name << glroot->PATH.Data() << "/";
344 name << glroot->NAME.Data();
345 //
346 fcalname = (TString)name.str().c_str();
347 //
348 printf("\n Section %i : using file %s calibration at entry %i: \n",s,fcalname.Data(),calibno);
349 //
350 } else {
351 error = 0;
352 error = glparam->Query_GL_PARAM(1,104,fDbc);
353 //
354 calfile.str("");
355 calfile << glparam->PATH.Data() << "/";
356 calfile << glparam->NAME.Data();
357 //
358 printf("\n Section %i : using default calorimeter calibration: \n %s \n",s,calfile.str().c_str());
359 //
360 fcalname = (TString)calfile.str().c_str();
361 calibno = s;
362 //
363 };
364 //
365 // load calibration variables in memory
366 //
367 CaloLoadCalib(s,fcalname,calibno);
368 //
369 };
370 //
371 // at this point we have in memory the calorimeter calibration and we can save it to disk in the correct format and use it to digitize the data
372 //
373 delete glparam;
374 delete glcalo;
375 delete glroot;
376 };
377
378 void Digitizer::DigitizeCALO() {
379 //
380 //
381 fCALOlength = 0; // reset total dimension of calo data
382 //
383 // gpamela variables to be used
384 //
385 // fhBookTree->SetBranchStatus("Nthcali",1);//modified by E.Vannuccini 03/08
386 // fhBookTree->SetBranchStatus("Icaplane",1);
387 // fhBookTree->SetBranchStatus("Icastrip",1);
388 // fhBookTree->SetBranchStatus("Icamod",1);
389 // fhBookTree->SetBranchStatus("Enestrip",1);
390 //
391 // call different routines depending on the acq mode you want to simulate
392 //
393 switch ( fModCalo ){
394 case 0:
395 this->DigitizeCALORAW();
396 break;
397 case 1:
398 this->DigitizeCALOCOMPRESS();
399 break;
400 case 2:
401 this->DigitizeCALOFULL();
402 break;
403 };
404 //
405 };
406
407 Float_t Digitizer::GetCALOen(Int_t sec, Int_t plane, Int_t strip){
408 //
409 // determine plane and strip
410 //
411 Int_t mplane = 0;
412 //
413 // wrong!
414 //
415 // if ( sec == 0 || sec == 3 ) mplane = (plane * 4) + sec + 1;
416 // if ( sec == 1 ) mplane = (plane * 4) + 2 + 1;
417 // if ( sec == 2 ) mplane = (plane * 4) + 1 + 1;
418 //
419 if ( sec == 0 ) mplane = plane * 4 + 1; // it must be 0, 4, 8, ... (+1) from plane = 0, 11
420 if ( sec == 1 ) mplane = plane * 4 + 2 + 1; // it must be 2, 6, 10, ... (+1) from plane = 0, 11
421 if ( sec == 2 ) mplane = plane * 4 + 3 + 1; // it must be 3, 7, 11, ... (+1) from plane = 0, 11
422 if ( sec == 3 ) mplane = plane * 4 + 1 + 1; // it must be 1, 5, 9, ... (+1) from plane = 0, 11
423 //
424 Int_t mstrip = strip + 1;
425 //
426 // search energy release in gpamela output
427 //
428 for (Int_t i=0; i<Nthcali;i++){
429 if ( Icaplane[i] == mplane && Icastrip[i] == mstrip ){
430 return (Enestrip[i]);
431 };
432 };
433 //
434 // if not found it means no energy release so return 0.
435 //
436 return(0.);
437 };
438
439 void Digitizer::DigitizeCALORAW() {
440 //
441 // some variables
442 //
443 Float_t ens = 0.;
444 UInt_t adcsig = 0;
445 UInt_t adcbase = 0;
446 UInt_t adc = 0;
447 Int_t pre = 0;
448 UInt_t l = 0;
449 UInt_t lpl = 0;
450 UInt_t tstrip = 0;
451 UInt_t fSecPointer = 0;
452 Double_t pedenoise;
453 Float_t rms = 0.;
454 Float_t pedestal = 0.;
455 //
456 // clean the data structure
457 //
458 memset(fDataCALO,0,sizeof(UShort_t)*fCALObuffer);
459 //
460 // Header of the four sections
461 //
462 fSecCalo[0] = 0xEA08; // XE
463 fSecCalo[1] = 0xF108; // XO
464 fSecCalo[2] = 0xF608; // YE
465 fSecCalo[3] = 0xED08; // YO
466 //
467 // length of the data is 0x0428 in RAW mode
468 //
469 fSecCALOLength[0] = 0x0428; // XE
470 fSecCALOLength[1] = 0x0428; // XO
471 fSecCALOLength[2] = 0x0428; // YE
472 fSecCALOLength[3] = 0x0428; // YO
473 //
474 // let's start
475 //
476 fCALOlength = 0;
477 //
478 for (Int_t sec=0; sec < 4; sec++){
479 //
480 // sec = 0 -> XE 1 -> XO 2-> YE 3 -> YO
481 //
482 l = 0; // XE and XO are Y planes
483 if ( sec < 2 ) l = 1; // while YE and YO are X planes
484 //
485 fSecPointer = fCALOlength;
486 //
487 // First of all we have section header and packet length
488 //
489 fDataCALO[fCALOlength] = fSecCalo[sec];
490 fCALOlength++;
491 fDataCALO[fCALOlength] = fSecCALOLength[sec];
492 fCALOlength++;
493 //
494 // selftrigger coincidences - in the future we should add here some code to simulate timing response of pre-amplifiers
495 //
496 for (Int_t autoplane=0; autoplane < 7; autoplane++){
497 fDataCALO[fCALOlength] = 0x0000;
498 fCALOlength++;
499 };
500 //
501 //
502 // here comes data
503 //
504 //
505 // Section XO is read in the opposite direction respect to the others
506 //
507 if ( sec == 1 ){
508 tstrip = 96*11 + fCALOlength;
509 } else {
510 tstrip = 0;
511 };
512 //
513 pre = -1;
514 //
515 for (Int_t strip=0; strip < 96; strip++){
516 //
517 // which is the pre for this strip?
518 //
519 if (strip%16 == 0) {
520 pre++;
521 };
522 //
523 if ( sec == 1 ) tstrip -= 11;
524 //
525 for (Int_t plane=0; plane < 11; plane++){
526 //
527 // here is wrong!!!!
528 //
529 //
530 // if ( plane%2 == 0 && sec%2 != 0){
531 // lpl = plane*2;
532 // } else {
533 // lpl = (plane*2) + 1;
534 // };
535 //
536 if ( sec == 0 || sec == 3 ) lpl = plane * 2;
537 if ( sec == 1 || sec == 2 ) lpl = (plane * 2) + 1;
538 //
539 // get the energy in GeV from the simulation for that strip
540 //
541 ens = this->GetCALOen(sec,plane,strip);
542 //
543 // convert it into ADC channels
544 //
545 adcsig = int(ens*fCalomip[l][lpl][strip]/fCALOGeV2MIPratio);
546 //
547 // sum baselines
548 //
549 adcbase = (UInt_t)fcalbase[sec][plane][pre];
550 //
551 // add noise and pedestals
552 //
553 pedestal = fcalped[sec][plane][strip];
554 rms = fcalrms[sec][plane][strip]/4.;
555 //
556 // Add random gaussian noise of RMS rms and Centered in the pedestal
557 //
558 pedenoise = gRandom->Gaus((Double_t)pedestal,(Double_t)rms);
559 //
560 // Sum all contribution
561 //
562 adc = adcsig + adcbase + (Int_t)round(pedenoise);
563 //
564 // Signal saturation
565 //
566 if ( adc > 0x7FFF ) adc = 0x7FFF;
567 //
568 // save value
569 //
570 if ( sec == 1 ){
571 fDataCALO[tstrip] = adc;
572 tstrip++;
573 } else {
574 fDataCALO[fCALOlength] = adc;
575 };
576 fCALOlength++;
577 //
578 };
579 //
580 if ( sec == 1 ) tstrip -= 11;
581 //
582 };
583 //
584 // here we calculate and save the CRC
585 //
586 Short_t CRC = 0;
587 for (UInt_t i=0; i<(fCALOlength-fSecPointer); i++){
588 CRC=crc(CRC,fDataCALO[i+fSecPointer]);
589 };
590 fDataCALO[fCALOlength] = (UShort_t)CRC;
591 fCALOlength++;
592 //
593 };
594 //
595 // for (Int_t i=0; i<fCALOlength; i++){
596 // printf(" WORD %i DIGIT %0x \n",i,fDataCALO[i]);
597 // };
598 //
599 };
600
601
602 void Digitizer::DigitizeCALOCOMPRESS() {
603 //
604 // CompressMode: implemented by C.Pizzolotto october 2009
605 //
606 // some variables
607 //
608 Float_t ens = 0.;
609 UInt_t adcsig = 0;
610 UInt_t adcbase = 0;
611 UInt_t adc[16];
612 Float_t rms = 0.;
613 Double_t pedenoise=0.;
614 Float_t pedestal = 0.;
615 UInt_t pedround[16];
616 Float_t thres[16];
617 Float_t goodflag[16];
618 UInt_t min_adc = 0x7FFF;
619 UInt_t min_adc_ch = 0;
620 UInt_t l = 0;
621 UInt_t lpl = 0;
622 Int_t plane = 0;
623 Int_t pre;
624 Int_t npre = 0; // number of pre between 0-5
625 UInt_t strip = 0;
626 UInt_t remainder;
627 Float_t basesum=0.;
628 Float_t basenof=0.;
629 UInt_t baseline=0;
630 UInt_t fSecPointer = 0;
631 UInt_t fNofTStripsPointer = 0;
632 UInt_t NofTransmittedStrips = 0 ;
633 //
634 // clean the data structure
635 //
636 memset(adc, 0,sizeof(adc));
637 memset(pedround, 0,sizeof(pedround));
638 memset(thres, 0,sizeof(thres));
639 memset(goodflag, 0,sizeof(goodflag));
640 //
641 memset(fDataCALO,0,sizeof(UShort_t)*fCALObuffer);
642 //
643 // Header of the four sections
644 //
645 fSecCalo[0] = 0xEA00; // XE
646 fSecCalo[1] = 0xF100; // XO
647 fSecCalo[2] = 0xF600; // YE
648 fSecCalo[3] = 0xED00; // YO
649 //
650 // here comes raw data
651 //
652 fCALOlength = 0;
653 //
654 for (Int_t sec=0; sec < 4; sec++){ //
655 //
656 // sec = 0 -> XE 1 -> XO 2-> YE 3 -> YO
657 //
658 l = 0; // XE and XO are Y planes
659 if ( sec < 2 ) l = 1; // while YE and YO are X planes
660 //
661 fSecPointer = fCALOlength;
662 //
663 // First of all we have section header and packet length
664 //
665 fDataCALO[fCALOlength] = fSecCalo[sec];
666 fCALOlength++;
667 fDataCALO[fCALOlength] = 0; // Unknown: length must be calculated on fly
668 fCALOlength++;
669 //
670 // selftrigger coincidences - in the future we should add here some code to simulate timing response of pre-amplifiers
671 //
672 for (Int_t autoplane=0; autoplane < 7; autoplane++){
673 fDataCALO[fCALOlength] = 0x0000;
674 fCALOlength++;
675 };
676 //
677 // second level trigger
678 //
679 fDataCALO[fCALOlength] = 0x0000;
680 fCALOlength++;
681 //
682 // Nof strips transmetted: must be calculated on fly
683 //
684 fNofTStripsPointer = fCALOlength;
685 fDataCALO[fCALOlength] = 0x0000;
686 fCALOlength++;
687 NofTransmittedStrips=0;
688 //
689 // Identifier of calo data
690 //
691 fDataCALO[fCALOlength] = 0xCA50;
692 fCALOlength++;
693 fDataCALO[fCALOlength] = 0xCA50;
694 fCALOlength++;
695 fDataCALO[fCALOlength] = 0xFFFF; // compress mode
696 fCALOlength++;
697 //
698 // Pedestal threashold table checksum
699 //
700 fDataCALO[fCALOlength] = 0x0000;
701 fCALOlength++;
702 //
703 // Calorimeter event counter
704 //
705 fDataCALO[fCALOlength] = fEvent;
706 fCALOlength++;
707 //
708 // Start here with data
709 //
710 plane=-1;
711 npre =-1;
712 for (Int_t ipre=0; ipre< 66; ipre++){ // (11 planes*6 preampl)
713 //
714 // which plane
715 if ( (ipre % 6) == 0) {
716 plane++;
717 }
718 //
719 pre=ipre;
720 //
721 // Adjust counter for plane X0
722 if (sec==1) // conto invertito
723 {
724 remainder = pre % 6 ;
725 pre = ((plane+1)*6) - remainder ;
726 }
727 //
728 if ( sec == 0 || sec == 3 ) lpl = plane * 2;
729 if ( sec == 1 || sec == 2 ) lpl = (plane * 2) + 1;
730 //
731 // initialize min_adc
732 min_adc = 0x7FFF;
733 for (Int_t ch=0; ch <16; ch++){ // 16 channels each pre
734 //
735 // strip number
736 //
737 strip=((pre-(6*plane))*16)+ch;
738 if(sec==1) strip = ((pre-(6*plane))*16)+(15-ch)-16;
739 //
740 // calculate npre: a number between 0-5
741 //
742 if( sec==1) {
743 if ( ((95-strip) % 16) == 0) {
744 npre++;
745 if(npre>5) npre=0;
746 }
747 } else {
748 if ( (strip % 16) == 0) {
749 npre++;
750 if(npre>5) npre=0;
751 }
752 }
753 //
754 // get the energy in GeV from the simulation for that strip
755 //
756 ens = this->GetCALOen(sec,plane,strip);
757 //
758 // convert it into ADC channels
759 //
760 adcsig = int(ens*fCalomip[l][lpl][strip]/fCALOGeV2MIPratio);
761 //
762 // sum baselines
763 //
764 adcbase = (UInt_t)fcalbase[sec][plane][npre];
765 //
766 // add noise and pedestals
767 //
768 pedestal = fcalped[sec][plane][strip];
769 rms = fcalrms[sec][plane][strip]/4.;
770 //
771 // Add random gaussian noise of RMS rms and Centered in the pedestal
772 //
773 pedenoise = gRandom->Gaus((Double_t)pedestal,(Double_t)rms);
774 //
775 // Sum all contribution
776 //
777 adc[ch] = adcsig + adcbase + (Int_t)round(pedenoise);
778 //
779 // Signal saturation
780 //
781 if ( adc[ch] > 0x7FFF ) adc[ch] = 0x7FFF;
782 //
783 // save infos
784 //
785 pedround[ch] = (Int_t)round(pedestal) ;
786 thres[ch] = ( fcalthr[sec][plane][npre] );
787 goodflag[ch] = ( fcalgood[sec][plane][strip] ); // if bad should be 255
788 //
789 // Find minimum adc in this preamp
790 //
791 if ( goodflag[ch]==0 && (adc[ch]-pedround[ch])<min_adc )
792 {
793 min_adc = ( adc[ch]-pedround[ch] ) ;
794 min_adc_ch = ch ;
795 };
796 }; // close channel loop ch
797 //
798 // Find how many channels are below threshold in current preampl
799 //
800 Int_t nof_chs_below = 0;
801 for (Int_t ch=0; ch <16; ch++){
802 if ( goodflag[ch]==0 && ((adc[ch]-pedround[ch]) < (min_adc+thres[min_adc_ch])) )
803 nof_chs_below++;
804 };
805 //
806 // Transmit data: CASE nof_chs_below<9
807 //
808 if(nof_chs_below<9)
809 {
810 if(sec==1) {
811 fDataCALO[fCALOlength] = 0x1000 + ipre ;
812 } else {
813 fDataCALO[fCALOlength] = 0x1000 + pre ;
814 };
815 fCALOlength++;
816 for (Int_t ch=0; ch <16; ch++)
817 {
818 fDataCALO[fCALOlength] = adc[ch];
819 fCALOlength++;
820 NofTransmittedStrips++;
821 };
822 }
823 else
824 //
825 // Transmit data: CASE nof_chs_below>=9
826 //
827 {
828 if(sec==1) {
829 fDataCALO[fCALOlength] = 0x0800 + ipre ;
830 } else {
831 fDataCALO[fCALOlength] = 0x0800 + pre;
832 };
833 fCALOlength++;
834 //
835 // calculate baseline and save it
836 //
837 basenof=0;
838 baseline=0;
839 basesum=0;
840 for (Int_t ch=0; ch <16; ch++){
841 if( goodflag[ch]==0 && ( (adc[ch]-pedround[ch])<(min_adc+thres[ch]) ) )
842 {
843 basesum = basesum + (adc[ch]-pedround[ch]) ;
844 basenof++;
845 };
846 };
847 baseline = (Int_t)round( basesum / basenof );
848 fDataCALO[fCALOlength] = baseline;
849 fCALOlength++;
850 //
851 // Transmit only channels > (min_adc+thres[ch])
852 //
853 for (Int_t ch=0; ch <16; ch++){
854 if ( (adc[ch]-pedround[ch] )>(min_adc+thres[ch]) )
855 {
856 fDataCALO[fCALOlength] = ch;
857 fCALOlength++;
858 fDataCALO[fCALOlength] = adc[ch];
859 fCALOlength++;
860 NofTransmittedStrips++;
861 };
862 };
863 }; // close if nof_chs_below
864 }; // close preampl loop
865 //
866 // Write the correct length
867 //
868 fDataCALO[fSecPointer+1] = (fCALOlength-fSecPointer+1)-2 ;
869 // total length of the packet: -2: because the words with status and length are not included
870 fDataCALO[fNofTStripsPointer] = NofTransmittedStrips ;
871 //
872 // here we calculate and save the CRC
873 //
874 Short_t CRC = 0;
875 fDataCALO[fCALOlength] =0 ;
876 for (UInt_t i=0; i<(fCALOlength-fSecPointer); i++){
877 CRC=crc(CRC,fDataCALO[i+fSecPointer]);
878 };
879 fDataCALO[fCALOlength] = (UShort_t)CRC;
880 fCALOlength++;
881 //
882 }; // close sec loop
883 // The End
884 }
885
886
887
888 void Digitizer::DigitizeCALOFULL() {
889 //
890 printf(" FULL MODE STILL NOT IMPLEMENTED! %d\n",fEvent);
891 //
892 this->DigitizeCALORAW();
893 return;
894 //
895 fSecCalo[0] = 0xEA00;
896 fSecCalo[1] = 0xF100;
897 fSecCalo[2] = 0xF600;
898 fSecCalo[3] = 0xED00;
899 //
900 // length of the data in DSP mode must be calculated on fly during digitization
901 //
902 memset(fSecCALOLength,0x0,4*sizeof(UShort_t));
903 //
904 // here comes raw data
905 //
906 Int_t en = 0;
907 //
908 for (Int_t sec=0; sec < 4; sec++){
909 fDataCALO[en] = fSecCalo[sec];
910 en++;
911 fDataCALO[en] = fSecCALOLength[sec];
912 en++;
913 for (Int_t plane=0; plane < 11; plane++){
914 for (Int_t strip=0; strip < 11; strip++){
915 fDataCALO[en] = 0x0;
916 en++;
917 };
918 };
919 };
920 //
921 }

  ViewVC Help
Powered by ViewVC 1.1.23