3 #include "AliITSUSuze02.h"
5 //*******************************************************************
7 // Simulation of the SUZE02 readout
8 // Origin: Serhiy.Senuykov@cern.ch
10 //*******************************************************************
15 ClassImp(AliITSUSuze02)
17 AliITSUSuze02::AliITSUSuze02(Int_t Nrows, Int_t Ncols):
20 fChip(new TMatrixF(Nrows,Ncols)),
23 fNWindowsPer32colsMax(0),
24 fNWindowsPerHalfFSBBMax(0),
25 fNWindowsPerFSBBMax(0),
31 fNWindowsPer32colsMin(0),
32 fNWindowsPerHalfFSBBMin(0),
33 fNWindowsPerFSBBMin(0)
35 if (Ncols%(kNumberOfFSBB*kNumberOfHalfFSBB) != 0) {
36 printf("Number of columns should be multiple of %d. SUZE matrix wasn't created\n",kNumberOfFSBB*kNumberOfHalfFSBB);
40 AliITSUSuze02::AliITSUSuze02(const AliITSUSuze02& suze):
41 fNRowsChip(suze.fNRowsChip),
42 fNColsChip(suze.fNColsChip),
43 fChip(new TMatrixF(*suze.fChip)),
44 fTestColumnSize(suze.fTestColumnSize),
45 fTestRowSize(suze.fTestRowSize),
46 fNWindowsPer32colsMax(suze.fNWindowsPer32colsMax),
47 fNWindowsPerHalfFSBBMax(suze.fNWindowsPerHalfFSBBMax),
48 fNWindowsPerFSBBMax(suze.fNWindowsPerFSBBMax),
49 fNDigitsEncoded(suze.fNDigitsEncoded),
50 fNEncodedWindows(suze.fNEncodedWindows),
51 fNDigitsLost(suze.fNDigitsLost),
52 fNLostWindows(suze.fNLostWindows),
53 fDataSizePerChip(suze.fDataSizePerChip),
54 fNWindowsPer32colsMin(suze.fNWindowsPer32colsMin),
55 fNWindowsPerHalfFSBBMin(suze.fNWindowsPerHalfFSBBMin),
56 fNWindowsPerFSBBMin(suze.fNWindowsPerFSBBMin)
60 AliITSUSuze02 &AliITSUSuze02::operator=(const AliITSUSuze02& suze) {
61 if (&suze == this) return *this;
63 fNRowsChip = suze.fNRowsChip;
64 fNColsChip = suze.fNColsChip;
65 fChip = new TMatrixF(*suze.fChip);
66 fTestColumnSize = suze.fTestColumnSize;
67 fTestRowSize = suze.fTestRowSize;
68 fNWindowsPer32colsMax = suze.fNWindowsPer32colsMax;
69 fNWindowsPerHalfFSBBMax = suze.fNWindowsPerHalfFSBBMax;
70 fNWindowsPerFSBBMax = suze.fNWindowsPerFSBBMax;
71 fNDigitsEncoded = suze.fNDigitsEncoded;
72 fNEncodedWindows = suze.fNEncodedWindows;
73 fNDigitsLost = suze.fNDigitsLost;
74 fNLostWindows = suze.fNLostWindows;
75 fDataSizePerChip = suze.fDataSizePerChip;
76 fNWindowsPer32colsMin = suze.fNWindowsPer32colsMin;
77 fNWindowsPerHalfFSBBMin = suze.fNWindowsPerHalfFSBBMin;
78 fNWindowsPerFSBBMin = suze.fNWindowsPerFSBBMin;
83 AliITSUSuze02::~AliITSUSuze02() {
84 if(fChip) delete fChip;
87 void AliITSUSuze02::SetEncodingWindowSize(Int_t Wrows, Int_t Wcols){
88 fTestColumnSize=Wrows;
92 void AliITSUSuze02::SetQuotas(Int_t q32, Int_t qHalfFSBB, Int_t qFSBB){
93 fNWindowsPer32colsMax=q32;
94 fNWindowsPerHalfFSBBMax=qHalfFSBB;
95 fNWindowsPerFSBBMax=qFSBB;
98 void AliITSUSuze02::AddDigit(Int_t row, Int_t col){
102 //void AliITSUSuze02::Process(Bool_t Verbose){
103 void AliITSUSuze02::Process(TH1F* OverflowCodes, TH1F* NDigitsPerEncodingWindowDist, Bool_t Verbose) {
105 //cout<<"Processing"<<endl;
108 Int_t NRowsFSBB=fNRowsChip;
109 Int_t NColsFSBB=fNColsChip/kNumberOfFSBB;
110 TMatrixF FSBB(NRowsFSBB,NColsFSBB);
112 Int_t NRowsSuperLine=fTestColumnSize;
113 Int_t NColsSuperLine=NColsFSBB;
114 TMatrixF SuperLineUp(NRowsSuperLine,NColsSuperLine);
115 TMatrixF SuperLineDown(NRowsSuperLine,NColsSuperLine);
117 Int_t NRowsSuperLineX2=NRowsSuperLine*2;
118 Int_t NColsSuperLineX2=NColsSuperLine; //SuperLineX2 and SuperLine size in columns is equal to FSBB.
119 TMatrixF SuperLineX2(NRowsSuperLineX2,NColsSuperLineX2);
121 TMatrixF TestRow(1,fTestRowSize);
122 TMatrixF TestColumn(fTestColumnSize,1);
124 TMatrixF EncodingWindow(fTestColumnSize,fTestRowSize);
126 Int_t EncodingWindowStartRow=0;
127 Int_t EncodingWindowStopRow=0;
128 Int_t EncodingWindowStartCol=0;
129 Int_t EncodingWindowStopCol=0;
131 Int_t nMasks=fTestRowSize-1;
132 Int_t MaskSize=NRowsSuperLineX2-1;
133 TMatrixF Masks(MaskSize,nMasks);
135 //parameters for internal data size calculation
136 Int_t DataSizePerWindowInRow=8+fTestColumnSize*fTestRowSize+TMath::Ceil(TMath::Log2(fTestColumnSize));
137 Int_t DataSizePerSuperLineX2Header=30;
139 Int_t DataSizePerSuperLineX2=0;
141 Bool_t Overflow32=kFALSE;
142 Bool_t OverflowHalfFSBB=kFALSE;
143 Bool_t OverflowFSBB=kFALSE;
145 Int_t nWindowsPer32cols=fNWindowsPer32colsMax;
146 Int_t nWindowsPerHalfFSBB=fNWindowsPerHalfFSBBMax;
147 Int_t nWindowsPerFSBB=fNWindowsPerFSBBMax;
149 fNWindowsPer32colsMin=fNWindowsPer32colsMax;
150 fNWindowsPerHalfFSBBMin=fNWindowsPerHalfFSBBMax;
151 fNWindowsPerFSBBMin=fNWindowsPerFSBBMax;
159 for(Int_t FSBBindex=0; FSBBindex<kNumberOfFSBB; FSBBindex++){
160 FSBB=fChip->GetSub(0,NRowsFSBB-1,FSBBindex*NColsFSBB,(FSBBindex+1)*NColsFSBB-1);
161 SuperLineDown=FSBB.GetSub(0,NRowsSuperLine-1,0,NColsSuperLine-1);
162 for(Int_t SuperLineX2StartRow=0; SuperLineX2StartRow<NRowsFSBB; SuperLineX2StartRow+=NRowsSuperLine){
163 if(nWindowsPerFSBB<fNWindowsPerFSBBMin) {fNWindowsPerFSBBMin=nWindowsPerFSBB;} //saving the lowest number of remaining windows
164 nWindowsPerFSBB=fNWindowsPerFSBBMax; //Reset number of available encoding windows for the new double SuperLine
166 SuperLineUp=SuperLineDown;
167 if(SuperLineX2StartRow+NRowsSuperLineX2<=NRowsFSBB){
168 SuperLineDown=FSBB.GetSub(SuperLineX2StartRow+NRowsSuperLine,SuperLineX2StartRow+NRowsSuperLineX2-1,0,NColsSuperLine-1);
170 else if(SuperLineX2StartRow+NRowsSuperLine<NRowsFSBB){
171 SuperLineDown.Zero();
172 SuperLineDown.SetSub(0,0,FSBB.GetSub(SuperLineX2StartRow+NRowsSuperLine,NRowsFSBB-1,0,NColsSuperLine-1));
175 SuperLineDown.Zero();
177 if(SuperLineUp.Sum()>0){
178 DataSizePerSuperLineX2=0;
179 SuperLineX2.SetSub(0,0,SuperLineUp);
180 SuperLineX2.SetSub(NRowsSuperLine,0,SuperLineDown);
181 for(Int_t HalfFSBBindex=0; HalfFSBBindex<kNumberOfHalfFSBB; HalfFSBBindex++){
182 if(nWindowsPerHalfFSBB<fNWindowsPerHalfFSBBMin) {fNWindowsPerHalfFSBBMin=nWindowsPerHalfFSBB;}
183 nWindowsPerHalfFSBB=fNWindowsPerHalfFSBBMax; //reset counter per HalfFSBB
184 OverflowHalfFSBB=kFALSE;
185 for(Int_t i=0; i<MaskSize; i++){ //reset masks to 1111111
186 for(Int_t j=0; j<nMasks; j++){
191 for(Int_t TestRowStartCol=HalfFSBBindex*NColsSuperLineX2/kNumberOfHalfFSBB; TestRowStartCol<(HalfFSBBindex+1)*NColsSuperLineX2/kNumberOfHalfFSBB; TestRowStartCol++){
192 if(TestRowStartCol%32==0){
193 if(nWindowsPer32cols<fNWindowsPer32colsMin) fNWindowsPer32colsMin=nWindowsPer32cols;
194 nWindowsPer32cols=fNWindowsPer32colsMax; //reset nWindowsPer32cols counter every 32 columns
198 for(Int_t RowIndex=0; RowIndex<MaskSize; RowIndex++){
199 for(Int_t MaskIndex=0; MaskIndex<nMasks; MaskIndex++){
200 if(Masks(RowIndex,MaskIndex)==0){
201 // cout<<"Mask has zero bit at pos:"<<RowIndex<<":"<<MaskIndex<<endl;
202 // cout<<"will clean the pixels at row:"<<RowIndex<<" from pos.:"<<TestRowStartCol<<" till "<< TestRowStartCol+(nMasks-MaskIndex)<<endl;
203 for(Int_t ColIndex=TestRowStartCol; ColIndex<TestRowStartCol+(nMasks-MaskIndex); ColIndex++){
204 if(ColIndex<(HalfFSBBindex+1)*NColsSuperLineX2/kNumberOfHalfFSBB){
205 SuperLineX2(RowIndex,ColIndex)=0;
206 // cout<<"Mask has zero bit. Cleaning at pos:"<<RowIndex<<":"<<ColIndex<<endl;
207 if(RowIndex>=fTestColumnSize){
208 SuperLineDown(RowIndex-fTestColumnSize,ColIndex)=0;
217 for(Int_t RowIndex=0; RowIndex<MaskSize; RowIndex++){
218 for(Int_t MaskIndex=nMasks-1; MaskIndex>0; MaskIndex--){
219 Masks(RowIndex,MaskIndex)=Masks(RowIndex,MaskIndex-1);
224 for(Int_t TestRowStartRow=0; TestRowStartRow<fTestColumnSize; TestRowStartRow++){
226 for(Int_t TestRowIndex=0; TestRowIndex<fTestRowSize; TestRowIndex++){
227 if(TestRowStartCol+TestRowIndex<(HalfFSBBindex+1)*NColsSuperLineX2/kNumberOfHalfFSBB){
228 TestRowSum+=SuperLineX2(TestRowStartRow,TestRowStartCol+TestRowIndex);
231 //cout<<"TestR at col n."<<TestRowStartCol<<" and row n."<<TestRowStartRow<<" has a hit"<<endl;
236 TestColumn=SuperLineX2.GetSub(TestRowStartRow,TestRowStartRow+fTestColumnSize-1,TestRowStartCol,TestRowStartCol);
237 if(TestColumn.Sum()>0){
238 EncodingWindowStartRow=TestRowStartRow;
239 EncodingWindowStopRow=EncodingWindowStartRow+fTestColumnSize-1;
240 EncodingWindowStartCol=TestRowStartCol;
242 if(TestRowStartCol+fTestRowSize>(HalfFSBBindex+1)*NColsSuperLineX2/kNumberOfHalfFSBB){
243 EncodingWindowStopCol=((HalfFSBBindex+1)*NColsSuperLineX2/kNumberOfHalfFSBB)-1;
246 EncodingWindowStopCol=EncodingWindowStartCol+fTestRowSize-1;
249 EncodingWindow.Zero();
250 EncodingWindow.SetSub(0,0,SuperLineX2.GetSub(EncodingWindowStartRow,EncodingWindowStopRow,EncodingWindowStartCol,EncodingWindowStopCol));
252 if(nWindowsPer32cols && nWindowsPerHalfFSBB && nWindowsPerFSBB){
253 //cout<<"Will encode window starting at "<<TestRowStartRow<<":"<<TestRowStartCol<<endl;
254 fNDigitsEncoded+=EncodingWindow.Sum();
256 OverflowCodes->Fill(0);
257 NDigitsPerEncodingWindowDist->Fill(EncodingWindow.Sum());
259 nWindowsPerHalfFSBB--;
261 DataSizePerSuperLineX2+=DataSizePerWindowInRow;
262 //cout<<"Windows left:"<<nWindowsPerFSBB<<":"<<nWindowsPerHalfFSBB<<":"<<nWindowsPer32cols<<endl;
265 fNDigitsLost+=EncodingWindow.Sum();
267 //cout<<"------ No encoding at col.:"<<TestRowStartCol<<" at SuperLineX2 that starts at row:"<<SuperLineX2StartRow<<endl;
268 if(!nWindowsPer32cols) Overflow32=kTRUE;
269 if(!nWindowsPerHalfFSBB) OverflowHalfFSBB=kTRUE;
270 if(!nWindowsPerFSBB) OverflowFSBB=kTRUE;
271 OverflowCodes->Fill(Overflow32+2*OverflowHalfFSBB+4*OverflowFSBB);
273 for(Int_t k=TestRowStartRow;k<TestRowStartRow+fTestColumnSize; k++){
275 //cout<<"Setting Mask to 0 at "<<k<<endl;
276 //Setting to 0 the first column of the encoding window. This part if probably present in the real SUZE.
277 SuperLineX2(k,TestRowStartCol)=0;
278 if(k>=fTestColumnSize){
279 SuperLineDown(k-fTestColumnSize,TestRowStartCol)=0;
288 fDataSizePerChip+=(DataSizePerSuperLineX2+DataSizePerSuperLineX2Header);
293 cout<<fNDigitsEncoded<<" digits encoded in "<<fNEncodedWindows<<" windows"<<endl;
294 cout<<fNDigitsLost<<" digits lost in "<<fNLostWindows<<" windows"<<endl;
298 void AliITSUSuze02::GetResults(){
302 void AliITSUSuze02::InitHistos(){
303 fOverflowCodes = new TH1F("OverflowCodes","Overflow codes",8,0,8);
304 if(fNRowsChip*fNColsChip){
305 fNDigitsPerEncodingWindowDist = new TH1F("nDigitsPerEncodingWindowPerChip","nDigitsPerEncodingWindowPerChip",fTestColumnSize*fTestRowSize,1,fTestColumnSize*fTestRowSize+1);
308 printf("Run AliITSUSuze02::SetEncodingWindowSize first\n");
312 void AliITSUSuze02::ResetChip(){