| 395 |
|
|
| 396 |
cout<<"Digitizing CALO..."<<endl; |
cout<<"Digitizing CALO..."<<endl; |
| 397 |
|
|
| 398 |
Int_t ModCalo = 0; // 0 is RAW, 1 is COMPRESS, 2 is FULL |
Int_t ModCalo = 1; // 0 is RAW, 1 is COMPRESS, 2 is FULL |
| 399 |
//####@@@@ should be given as input par @@@@#### |
//####@@@@ should be given as input par @@@@#### |
| 400 |
|
|
| 401 |
|
|
| 613 |
|
|
| 614 |
|
|
| 615 |
void PamVMCCaloDig::DigitizeCaloCompress(){ |
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 |
|
|
|
cout<<"!!!WARNING PamVMCCaloDig COMPRESS MODE STILL NOT IMPLEMENTED!!!"<<endl; |
|
|
|
|
|
this->DigitizeCaloRaw(); |
|
| 903 |
return; |
return; |
| 904 |
|
|
| 905 |
|
|
| 906 |
|
|
| 907 |
|
|
| 908 |
} |
} |
| 909 |
|
|
| 910 |
void PamVMCCaloDig::DigitizeCaloFull(){ |
void PamVMCCaloDig::DigitizeCaloFull(){ |