/[PAMELA software]/PamVMC/cal/src/PamVMCCaloDig.cxx
ViewVC logotype

Contents of /PamVMC/cal/src/PamVMCCaloDig.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Wed Sep 15 06:54:17 2010 UTC (14 years, 2 months ago) by pizzolot
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +3 -2 lines
correcteted datacalo length in compress mode

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

  ViewVC Help
Powered by ViewVC 1.1.23