377 |
|
|
378 |
void Digitizer::DigitizeCALO() { |
void Digitizer::DigitizeCALO() { |
379 |
// |
// |
|
fModCalo = 0; // 0 is RAW, 1 is COMPRESS, 2 is FULL ####@@@@ should be given as input par @@@@#### |
|
|
// |
|
|
// |
|
380 |
// |
// |
381 |
fCALOlength = 0; // reset total dimension of calo data |
fCALOlength = 0; // reset total dimension of calo data |
382 |
// |
// |
598 |
// |
// |
599 |
}; |
}; |
600 |
|
|
601 |
|
|
602 |
void Digitizer::DigitizeCALOCOMPRESS() { |
void Digitizer::DigitizeCALOCOMPRESS() { |
603 |
// |
// |
604 |
printf(" COMPRESS MODE STILL NOT IMPLEMENTED! \n"); |
// CompressMode: implemented by C.Pizzolotto october 2009 |
605 |
// |
// |
606 |
this->DigitizeCALORAW(); |
// some variables |
|
return; |
|
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 |
fSecCalo[0] = 0xEA00; |
memset(adc, 0,sizeof(adc)); |
637 |
fSecCalo[1] = 0xF100; |
memset(pedround, 0,sizeof(pedround)); |
638 |
fSecCalo[2] = 0xF600; |
memset(thres, 0,sizeof(thres)); |
639 |
fSecCalo[3] = 0xED00; |
memset(goodflag, 0,sizeof(goodflag)); |
640 |
// |
// |
641 |
// length of the data in DSP mode must be calculated on fly during digitization |
memset(fDataCALO,0,sizeof(UShort_t)*fCALObuffer); |
642 |
// |
// |
643 |
memset(fSecCALOLength,0x0,4*sizeof(UShort_t)); |
// 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 |
// here comes raw data |
651 |
// |
// |
652 |
Int_t en = 0; |
fCALOlength = 0; |
653 |
// |
// |
654 |
for (Int_t sec=0; sec < 4; sec++){ |
for (Int_t sec=0; sec < 4; sec++){ // |
655 |
fDataCALO[en] = fSecCalo[sec]; |
// |
656 |
en++; |
// sec = 0 -> XE 1 -> XO 2-> YE 3 -> YO |
657 |
fDataCALO[en] = fSecCALOLength[sec]; |
// |
658 |
en++; |
l = 0; // XE and XO are Y planes |
659 |
for (Int_t plane=0; plane < 11; plane++){ |
if ( sec < 2 ) l = 1; // while YE and YO are X planes |
660 |
for (Int_t strip=0; strip < 11; strip++){ |
// |
661 |
fDataCALO[en] = 0x0; |
fSecPointer = fCALOlength; |
662 |
en++; |
// |
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() { |
void Digitizer::DigitizeCALOFULL() { |
889 |
// |
// |
890 |
printf(" FULL MODE STILL NOT IMPLEMENTED! \n"); |
printf(" FULL MODE STILL NOT IMPLEMENTED! %d\n",fEvent); |
891 |
// |
// |
892 |
this->DigitizeCALORAW(); |
this->DigitizeCALORAW(); |
893 |
return; |
return; |
918 |
}; |
}; |
919 |
}; |
}; |
920 |
// |
// |
921 |
}; |
} |