3 // Author: Anders Vestbo <mailto:vestbo$fi.uib.no>
4 //*-- Copyright © ASV
10 #include "AliL3Modeller.h"
11 #include "AliL3MemHandler.h"
12 #include "AliL3TrackArray.h"
13 #include "AliL3ModelTrack.h"
14 #include "AliL3DigitData.h"
15 #include "AliL3Transform.h"
17 #include "AliL3Defs.h"
19 ClassImp(AliL3Modeller)
21 AliL3Modeller::AliL3Modeller()
29 AliL3Modeller::~AliL3Modeller()
40 void AliL3Modeller::Init(Int_t slice,Int_t patch,Char_t *path)
46 fTransform = new AliL3Transform();
47 fTracks = new AliL3TrackArray("AliL3ModelTrack");
49 AliL3MemHandler *file = new AliL3MemHandler();
50 if(!file->SetBinaryInput("tracks.raw"))
52 cerr<<"AliL3Modeller::Init : Error opening trackfile"<<endl;
55 file->Binary2TrackArray(fTracks);
56 file->CloseBinaryInput();
60 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
62 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
64 track->Init(fSlice,fPatch);
65 track->Rotate(fSlice,kTRUE);
66 track->CalculateHelix();
69 CalculateCrossingPoints();
72 fMemHandler = new AliL3MemHandler();
74 sprintf(fname,"%sdigits_%d_%d.raw",path,fSlice,fPatch);
75 if(!fMemHandler->SetBinaryInput(fname))
77 cerr<<"AliL3Modeller::Init : Error opening file "<<fname<<endl;
81 AliL3DigitRowData *digits=(AliL3DigitRowData*)fMemHandler->CompBinary2Memory(ndigits);
86 void AliL3Modeller::Process()
91 cerr<<"AliL3Modeller::Process : No tracks"<<endl;
96 cerr<<"AliL3Modeller::Process : No data "<<endl;
100 AliL3DigitRowData *rowPt = fRowData;
101 AliL3DigitData *digPt=0;
103 Int_t ntimes = fTransform->GetNTimeBins()+1;
104 Int_t npads = fTransform->GetNPads(NRows[fPatch][1])+1;//Max num of pads.
105 Digit *row = new Digit[(ntimes)*(npads)];
112 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
114 memset((void*)row,0,ntimes*npads*sizeof(Digit));
115 digPt = (AliL3DigitData*)rowPt->fDigitData;
116 for(UInt_t j=0; j<rowPt->fNDigit; j++)
119 time = digPt[j].fTime;
120 charge = digPt[j].fCharge;
121 row[ntimes*pad+time].fCharge = charge;
122 row[ntimes*pad+time].fUsed = kFALSE;
125 for(Int_t k=0; k<fTracks->GetNTracks(); k++)
127 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(k);
129 if(track->GetOverlap()>=0) continue;//Track is overlapping
130 if(track->GetPadHit(i)<0 || track->GetTimeHit(i)<0)
132 track->SetCluster(0,0,0,0,0); //The track has left the patch.
136 Int_t hitpad = (Int_t)rint(track->GetPadHit(i));
137 Int_t hittime = (Int_t)rint(track->GetTimeHit(i));
138 //cout<<"Checking track with pad "<<hitpad<<" time "<<hittime<<endl;
144 memset(&cluster,0,sizeof(Cluster));
146 while(1)//Process this padrow
151 while(1) //Process sequence on this pad:
153 charge = row[ntimes*pad+time].fCharge;
154 if(charge==0 && timesign==-1)
155 {time=hittime+1; timesign=1; continue;}
156 else if(charge==0 && timesign==1)
158 //cout<<"Doing pad "<<pad<<" time "<<time<<" charge "<<charge<<endl;
160 seq_charge += charge;
162 cluster.fTime += time*charge;
163 cluster.fPad += pad*charge;
164 cluster.fCharge += charge;
165 cluster.fSigmaY2 += pad*pad*charge;
166 cluster.fSigmaZ2 += time*time*charge;
168 row[ntimes*pad+time].fUsed = kTRUE;
171 //cout<<"Finished on pad "<<pad<<" and time "<<time<<endl;
174 else //Nothing more on this pad, goto next pad
178 if(cluster.fCharge==0 && abs(pad-hitpad) < fPadOverlap/2)
180 pad--; //In this case, we haven't found anything yet,
181 } //so we will try to expand our search within the natural boundaries.
189 else if(padsign==1 && cluster.fCharge==0 && abs(pad-hitpad) < fPadOverlap/2)
194 else //Nothing more in this cluster
196 Float_t fcharge = (Float_t)cluster.fCharge;
197 Float_t fpad = ((Float_t)cluster.fPad/fcharge);
198 Float_t ftime = ((Float_t)cluster.fTime/fcharge);
199 Float_t sigmaY2,sigmaZ2;
200 CalcClusterWidth(&cluster,sigmaY2,sigmaZ2);
201 //cout<<"row "<<i<<" charge "<<fcharge<<endl;
202 track->SetCluster(fpad,ftime,fcharge,sigmaY2,sigmaZ2);
209 FillZeros(rowPt,row);
210 fMemHandler->UpdateRowPointer(rowPt);
216 void AliL3Modeller::FillZeros(AliL3DigitRowData *rowPt,Digit *row)
218 //Fill zero where data has been used.
220 Int_t ntimes = fTransform->GetNTimeBins()+1;
221 AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
222 for(UInt_t j=0; j<rowPt->fNDigit; j++)
224 Int_t pad = digPt[j].fPad;
225 Int_t time = digPt[j].fTime;
226 if(row[ntimes*pad+time].fUsed==kTRUE)
227 digPt[j].fCharge = 0;
231 void AliL3Modeller::WriteRemaining(Char_t *output)
233 //Write remaining (nonzero) digits to file.
235 cout<<"Writing remaining data to file "<<output<<endl;
236 AliL3DigitRowData *rowPt;
237 rowPt = (AliL3DigitRowData*)fRowData;
239 Int_t ndigits[(NumRows[fPatch])];
240 for(Int_t i=NRows[fPatch][0]; i<NRows[fPatch][1]; i++)
242 AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
243 ndigits[(i-NRows[fPatch][0])]=0;
244 for(UInt_t j=0; j<rowPt->fNDigit; j++)
246 if(digPt[j].fCharge==0) continue;
248 ndigits[(i-NRows[fPatch][0])]++;
250 //cout<<"Difference "<<(int)ndigits[(i-NRows[fPatch][0])]<<" "<<(int)rowPt->fNDigit<<endl;
251 fMemHandler->UpdateRowPointer(rowPt);
254 Int_t size = digitcount*sizeof(AliL3DigitData) + NumRows[fPatch]*sizeof(AliL3DigitRowData);
255 Byte_t *data = new Byte_t[size];
257 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)data;
258 rowPt = (AliL3DigitRowData*)fRowData;
260 for(Int_t i=NRows[fPatch][0]; i<NRows[fPatch][1]; i++)
264 tempPt->fNDigit = ndigits[(i-NRows[fPatch][0])];
265 AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
266 for(UInt_t j=0; j<rowPt->fNDigit; j++)
268 if(digPt[j].fCharge==0) continue;
269 if(localcount >= ndigits[(i-NRows[fPatch][0])])
271 cerr<<"AliL3Modeller::WriteRemaining : Digitarray out of range!!"<<endl;
274 tempPt->fDigitData[localcount].fCharge = digPt[j].fCharge;
275 tempPt->fDigitData[localcount].fPad = digPt[j].fPad;
276 tempPt->fDigitData[localcount].fTime = digPt[j].fTime;
279 if(ndigits[(i-NRows[fPatch][0])] != localcount)
281 cerr<<"AliL3Modeller::WriteRemaining : Mismatch in digitcount"<<endl;
284 fMemHandler->UpdateRowPointer(rowPt);
285 Byte_t *tmp = (Byte_t*)tempPt;
286 Int_t size = sizeof(AliL3DigitRowData) + ndigits[(i-NRows[fPatch][0])]*sizeof(AliL3DigitData);
288 tempPt = (AliL3DigitRowData*)tmp;
291 AliL3MemHandler *mem = new AliL3MemHandler();
292 mem->SetBinaryOutput(output);
293 mem->Memory2CompBinary((UInt_t)NumRows[fPatch],(AliL3DigitRowData*)data);
294 mem->CloseBinaryOutput();
299 void AliL3Modeller::CalculateCrossingPoints()
301 cout<<"Calculating crossing points on "<<fTracks->GetNTracks()<<" tracks"<<endl;
304 cerr<<"AliL3Modeller::CalculateCrossingPoints(): No tracks"<<endl;
308 for(Int_t i=NRows[fPatch][1]; i>=NRows[fPatch][0]; i--)
310 for(Int_t j=0; j<fTracks->GetNTracks(); j++)
312 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(j);
314 if(track->GetNHits() < 100)
316 if(!track->GetCrossingPoint(i,hit))
318 cerr<<"AliL3Modeller::CalculateCrossingPoints : Track does not intersect line "<<endl;
321 //cout<<" x "<<track->GetPointX()<<" y "<<track->GetPointY()<<" z "<<track->GetPointZ()<<endl;
323 fTransform->Local2Raw(hit,fSlice,i);
324 if(hit[1]<0 || hit[1]>fTransform->GetNPads(i) ||
325 hit[2]<0 || hit[2]>fTransform->GetNTimeBins())
326 {//Track is leaving the patch, so flag the track hits (<0)
327 track->SetPadHit(i,-1);
328 track->SetTimeHit(i,-1);
332 track->SetPadHit(i,hit[1]);
333 track->SetTimeHit(i,hit[2]);
335 //if(hit[1]<0 || hit[2]>445)
336 //if(hit[2]<0 || hit[2]>445)
337 //cout<<"pad "<<hit[1]<<" time "<<hit[2]<<" pt "<<track->GetPt()<<" psi "<<track->GetPsi()<<" tgl "<<track->GetTgl()<<" firstpoint "<<track->GetFirstPointX()<<" "<<track->GetFirstPointY()<<" "<<track->GetFirstPointZ()<<endl;
338 //cout<<"Crossing pad "<<hit[1]<<" time "<<hit[2]<<endl;
342 //cout<<"And there are "<<fTracks->GetNTracks()<<" tracks remaining"<<endl;
345 void AliL3Modeller::CheckForOverlaps()
347 //Flag the tracks that overlap
349 cout<<"Checking for overlaps"<<endl;
351 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
353 AliL3ModelTrack *track1 = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
354 if(!track1) continue;
355 for(Int_t j=i+1; j<fTracks->GetNTracks(); j++)
357 AliL3ModelTrack *track2 = (AliL3ModelTrack*)fTracks->GetCheckedTrack(j);
358 if(!track2) continue;
359 for(Int_t k=NRows[fPatch][0]; k<NRows[fPatch][1]; k++)
361 if(track1->GetPadHit(k)<0 || track1->GetTimeHit(k)<0 ||
362 track2->GetPadHit(k)<0 || track2->GetTimeHit(k)<0)
364 if(fabs(track1->GetPadHit(k)-track2->GetPadHit(k)) < fPadOverlap &&
365 fabs(track1->GetTimeHit(k)-track2->GetTimeHit(k)) < fTimeOverlap)
367 track1->SetOverlap(j);
368 track2->SetOverlap(i);
377 void AliL3Modeller::CalcClusterWidth(Cluster *cl,Float_t &sigmaY2,Float_t &sigmaZ2)
382 padw = fTransform->GetPadPitchWidthLow();
384 padw = fTransform->GetPadPitchWidthUp();
385 Float_t charge = (Float_t)cl->fCharge;
386 Float_t pad = (Float_t)cl->fPad/charge;
387 Float_t time = (Float_t)cl->fTime/charge;
388 Float_t s2 = (Float_t)cl->fSigmaY2/charge - pad*pad;
389 sigmaY2 = (s2 + 1./12)*padw*padw;
393 sigmaY2 = sigmaY2*0.108;
395 sigmaY2 = sigmaY2*2.07;
398 s2 = (Float_t)cl->fSigmaZ2/charge - time*time;
399 timew = fTransform->GetZWidth();
400 sigmaZ2 = (s2 +1./12)*timew*timew;
403 sigmaZ2 = sigmaZ2*0.169;
405 sigmaZ2 = sigmaZ2*1.77;