New version of SPD raw-data reconstruction. The format now correponds to the actual...
[u/mrichter/AliRoot.git] / HLT / trigger / AliL3Trigger.cxx
1
2 #include "AliL3Trigger.h"
3 #include "AliL3TrackArray.h"
4 #include "AliL3Transform.h"
5 #include "AliL3Vertex.h"
6 #include "AliL3Defs.h"
7 #include "AliL3DigitData.h"
8 #include "AliL3Logging.h"
9 #include "AliL3Track.h"
10 #include "AliL3MemHandler.h"
11
12 ClassImp(AliL3Trigger)
13
14 AliL3Trigger::AliL3Trigger()
15 {
16   fDataSize=0;
17   fTracks=0;
18   fDigitRowData=0;
19   fOutput=0;
20   fVertex=0;
21 }
22
23 AliL3Trigger::~AliL3Trigger()
24 {
25   if(fTracks)
26     delete fTracks;
27 }
28
29 void AliL3Trigger::InitTrigger()
30 {
31   if(fTracks)
32     delete fTracks;
33   fTracks = new AliL3TrackArray();
34 }
35
36 void AliL3Trigger::InitPatch(Int_t slice,Int_t patch)
37 {
38   fSlice=slice;
39   fPatch=patch;
40   fTracks->Reset();
41 }
42
43 void AliL3Trigger::FillTracks(Int_t ntracks,AliL3TrackSegmentData *tr)
44 {
45   fTracks->FillTracks(ntracks,tr);
46 }
47
48 void AliL3Trigger::FillData(AliL3DigitRowData *data)
49 {
50   fDigitRowData = data;
51 }
52
53 void AliL3Trigger::SetParameters(Float_t zcut,Int_t timematch,Int_t padmatch)
54 {
55   fZcut=zcut;
56   fTimeMatch=timematch;
57   fPadMatch=padmatch;
58 }
59
60 void AliL3Trigger::SetOutputData(AliL3DigitRowData *ptr)
61 {
62   fOutput=ptr;
63 }
64
65 void AliL3Trigger::RemovePileupTracks()
66 {
67   Double_t xc,yc,zc;
68   for(Int_t i=0; i<fTracks->GetNTracks(); i++)
69     {
70       AliL3Track *track = fTracks->GetCheckedTrack(i);
71       if(!track) continue;
72       track->Rotate(fSlice,kTRUE);
73       track->CalculateHelix();
74       track->GetClosestPoint(fVertex,xc,yc,zc);
75       if(fabs(zc) > fZcut)
76         {
77           fTracks->Remove(i);
78           continue;
79         }
80     }
81   fTracks->Compress();
82 }
83
84 void AliL3Trigger::RemovePileupData()
85 {
86   Float_t hit[3];
87   Int_t sector,row;
88   struct rowhit {Int_t pad; Int_t time;};
89   rowhit row_cross[(fTracks->GetNTracks())];
90   Int_t digitcount[(NumRows[fPatch])];
91   Int_t totalcount=0;
92   AliL3DigitRowData *rowPt = fDigitRowData;
93   for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
94     {
95       digitcount[(i-NRows[fPatch][0])]=0;
96       for(Int_t j=0; j<fTracks->GetNTracks(); j++)
97         {
98           AliL3Track *track = fTracks->GetCheckedTrack(j);
99           if(!track) continue;
100           track->GetCrossingPoint(i,hit);
101           AliL3Transform::Slice2Sector(fSlice,i,sector,row);
102           AliL3Transform::Local2Raw(hit,sector,row);
103           row_cross[j].pad = (Int_t)rint(hit[1]);
104           row_cross[j].time = (Int_t)rint(hit[2]);
105         }
106       AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
107       Bool_t mark;
108       for(Int_t k=0; k<rowPt->fNDigit; k++)
109         {
110           mark = kFALSE;
111           for(Int_t l=0; l<fTracks->GetNTracks(); l++)
112             {
113               if(abs((Int_t)digPt[k].fPad-row_cross[l].pad) < fPadMatch &&
114                  abs((Int_t)digPt[k].fTime-row_cross[l].time) < fTimeMatch)
115                 {
116                   digitcount[(i-NRows[fPatch][0])]++;
117                   totalcount++;
118                   mark=kTRUE;
119                   break;
120                 }
121             }
122           if(mark==kTRUE)
123             digPt[k].fCharge=0;
124         }
125       AliL3MemHandler::UpdateRowPointer(rowPt);
126     }
127   
128   Int_t size = totalcount*sizeof(AliL3DigitData) + NumRows[fPatch]*sizeof(AliL3DigitRowData);
129   fDataSize = size;
130   LOG(AliL3Log::kDebug,"AliL3Trigger::RemovePileupData","Memory")
131     <<"Allocating "<<size<<" bytes of data for trigger event"<<ENDLOG;
132   Byte_t *data = new Byte_t[size];
133   memset(data,0,size);
134   AliL3DigitRowData *tempPt = (AliL3DigitRowData*)data;
135   rowPt = fDigitRowData;
136   
137   Int_t localcount;
138   for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
139     {
140       tempPt->fRow = i;
141       tempPt->fNDigit = digitcount[(i-NRows[fPatch][0])];
142       AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
143       localcount=0;
144       for(Int_t j=0; j<rowPt->fNDigit; j++)
145         {
146           if(digPt[j].fCharge==0) continue;
147           if(localcount >= digitcount[(i-NRows[fPatch][0])])
148             {
149               LOG(AliL3Log::kFatal,"AliL§Trigger::RemovePileupData","Array")
150                 <<"Mismatch in digitcount: "<<localcount<<" "<<digitcount[(i-NRows[fPatch][0])]<<ENDLOG;
151               return;
152             }
153           tempPt->fDigitData[localcount].fCharge=digPt[j].fCharge;
154           tempPt->fDigitData[localcount].fPad=digPt[j].fPad;
155           tempPt->fDigitData[localcount].fTime=digPt[j].fTime;
156           localcount++;
157         }
158       if(digitcount[(i-NRows[fPatch][0])]!=localcount)
159         {
160           LOG(AliL3Log::kFatal,"AliL§Trigger::RemovePileupData","Array")
161             <<"Mismatch in digitcount: "<<localcount<<" "<<digitcount[(i-NRows[fPatch][0])]<<ENDLOG;
162         }
163       AliL3MemHandler::UpdateRowPointer(rowPt);
164       Byte_t *tmp = (Byte_t*)tempPt;
165       Int_t size = sizeof(AliL3DigitRowData)+digitcount[(i-NRows[fPatch][0])]*sizeof(AliL3DigitData);
166       tmp += size;
167       tempPt = (AliL3DigitRowData*)tmp;
168     }
169   
170   fOutput=(AliL3DigitRowData*)data;
171 }
172
173