1 #include <TClonesArray.h>
2 #include "AliITSURecoLayer.h"
3 #include "AliITSsegmentation.h"
4 #include "AliITSUAux.h"
5 #include "AliITSUClusterPix.h"
6 #include "AliITSUGeomTGeo.h"
9 using namespace AliITSUAux;
10 using namespace TMath;
12 ClassImp(AliITSURecoLayer)
15 //______________________________________________________
16 AliITSURecoLayer::AliITSURecoLayer(const char* name)
21 ,fSensVIDtoMatrixID(0)
36 SetNameTitle(name,name);
39 //______________________________________________________
40 AliITSURecoLayer::AliITSURecoLayer(const char* name, Int_t activeID, AliITSUGeomTGeo* gm)
45 ,fSensVIDtoMatrixID(0)
60 SetNameTitle(name,name);
64 //______________________________________________________
65 AliITSURecoLayer::~AliITSURecoLayer()
69 delete[] fSensVIDtoMatrixID;
70 if (GetOwnsClusterArray()) delete fClusters;
73 //______________________________________________________
74 void AliITSURecoLayer::Print(Option_t* opt) const
77 printf("Lr %-15s %d (act:%+d), NSens: %4d in %d rows| MaxStep:%.2f ",
78 GetName(),GetID(),GetActiveID(),GetNSensors(),GetNSensorRows(),fMaxStep);
79 printf("%6.3f<R<%6.3f | %+8.3f<Z<%+8.3f dZ:%6.3f dPhi:%6.3f\n",fRMin,fRMax,fZMin,fZMax,
80 fSensDZInv>0 ? 1/fSensDZInv : 0, fSensDPhiInv>0 ? 1/fSensDPhiInv : 0);
81 TString opts = opt; opts.ToLower();
82 if (opts.Contains("sn")) for (int i=0;i<GetNSensors();i++) GetSensor(i)->Print(opt);
85 //______________________________________________________
86 void AliITSURecoLayer::Build()
88 // build internal structures
89 const double kSafeR = 0.05; // safety margin for Rmin,Rmax of the layer
90 if (fActiveID<0) return;
92 int nStaves=fITSGeom->GetNStaves(fActiveID);
93 // determine number of sensor rows (sensors aligned at same phi and spanning the Z range of the layer)
94 fNSensorRows = nStaves;
96 // if the stave has susbtaves, each substave can have multiple rows of sensors (but just 1 row of modules)
97 if (fITSGeom->GetNHalfStaves(fActiveID)>0) fNSensorRows *= fITSGeom->GetNHalfStaves(fActiveID);
99 // if there are modules defined, the module may have multiple rows of sensors (though not spanning full Z)
100 if (fITSGeom->GetNModules(fActiveID)>0) fNSensorRows *= fITSGeom->GetNChipRowsPerModule(fActiveID);
102 fNSensors = fITSGeom->GetNChipsPerLayer(fActiveID);
103 fNSensorsPerRow = fNSensors/fNSensorRows;
105 fSensors = new TObjArray(fNSensors);
106 fSensVIDtoMatrixID = new Int_t[fNSensors];
107 const AliITSsegmentation* kSegm = fITSGeom->GetSegmentation(fActiveID);
110 const TGeoHMatrix* mt2l;
111 double phiTF,rTF, loc[3]={0,0,0},glo[3];
113 int nSensPerStave = fITSGeom->GetNChipsPerStave(fActiveID);
114 for (int staveI=0;staveI<nStaves;staveI++) {
115 for (int sensI=0;sensI<nSensPerStave;sensI++) {
116 int sID = fITSGeom->GetChipIndex(fActiveID,staveI,sensI);
117 AliITSURecoSens* sens = new AliITSURecoSens( sID );
118 fSensors->AddLast(sens);
119 double phiMin=1e9,phiMax=-1e9,zMin=1e9,zMax=-1e9;
120 // this is NOT the sensor matrix, just the ideal chip matrix to get neighbors correct
121 fITSGeom->GetOrigMatrix(sID,mmod);
123 for (int ix=0;ix<2;ix++) { // determine sensor boundaries (ideal)
124 loc[0] = (ix-0.5)*kSegm->Dx(); // +-DX/2
125 for (int iy=0;iy<2;iy++) {
126 loc[1] = (iy-0.5)*kSegm->Dy(); // +-DY/2
127 for (int iz=0;iz<2;iz++) {
128 loc[2] = (iz-0.5)*kSegm->Dz(); // +-DZ/2
129 mmod.LocalToMaster(loc,glo);
130 double phi = ATan2(glo[1],glo[0]);
132 if (phiMin>1e8) phiMin=phi;
133 else if (!OKforPhiMin(phiMin,phi)) phiMin=phi;
134 if (phiMax<-1e8) phiMax=phi;
135 else if (!OKforPhiMax(phiMax,phi)) phiMax=phi;
136 if (glo[2]>zMax) zMax=glo[2];
137 if (glo[2]<zMin) zMin=glo[2];
141 sens->SetBoundaries(phiMin,phiMax,zMin,zMax);
144 fSensors->Sort(); // sort sensors to get the neighborhood correct
146 // now fill real sensor angles, Z's, accounting for misalignment
151 int firstSensID = fITSGeom->GetFirstChipIndex(fActiveID);
152 for (int sensI=0;sensI<fNSensors;sensI++) {
153 AliITSURecoSens* sens = GetSensor(sensI);
154 mmod = *fITSGeom->GetMatrixSens(sens->GetID());
155 fSensVIDtoMatrixID[sens->GetID() - firstSensID] = sensI;
156 double phiMin=1e9,phiMax=-1e9,zMin=1e9,zMax=-1e9;
157 for (int ix=0;ix<2;ix++) {
158 loc[0] = (ix-0.5)*kSegm->Dx(); // +-DX/2
159 for (int iy=0;iy<2;iy++) {
160 loc[1] = (iy-0.5)*kSegm->Dy(); // +-DY/2
161 for (int iz=0;iz<2;iz++) {
162 loc[2] = (iz-0.5)*kSegm->Dz(); // +-DZ/2
164 mmod.LocalToMaster(loc,glo);
165 double phi = ATan2(glo[1],glo[0]);
166 double r = glo[0]*glo[0] + glo[1]*glo[1];
167 if (fRMin>r) fRMin = r;
168 if (fRMax<r) fRMax = r;
170 if (phiMin>1e8) phiMin=phi;
171 else if (!OKforPhiMin(phiMin,phi)) phiMin=phi;
172 if (phiMax<-1e8) phiMax=phi;
173 else if (!OKforPhiMax(phiMax,phi)) phiMax=phi;
174 if (glo[2]>zMax) zMax=glo[2];
175 if (glo[2]<zMin) zMin=glo[2];
179 mt2l = fITSGeom->GetMatrixT2L( sens->GetID() );
181 loc[0]=loc[1]=loc[2]=0;
182 mmod.LocalToMaster(loc,glo);
183 rTF = Sqrt(glo[0]*glo[0] + glo[1]*glo[1]); // tracking params (misaligned)
184 phiTF = ATan2(glo[1],glo[0]);
188 sens->SetPhiTF(phiTF);
189 sens->SetBoundaries(phiMin,phiMax,zMin,zMax);
190 if (fZMin>zMin) fZMin = zMin;
191 if (fZMax<zMax) fZMax = zMax;
193 if (sensI<fNSensorsPerRow) fPhiOffs += MeanPhiSmall(phiMax,phiMin);
196 fPhiOffs /= fNSensorsPerRow; // average phi of the 1st row
197 fSensDZInv = fNSensorsPerRow/(fZMax-fZMin);
198 fSensDPhiInv = fNSensorRows/(2*Pi());
202 fR = 0.5*(fRMin+fRMax);
208 //______________________________________________________
209 Int_t AliITSURecoLayer::FindSensors(const double* impPar, AliITSURecoSens *sensors[kNNeighbors])
211 // find sensors having intersection with track
212 // impPar contains: lab phi of track, dphi, labZ, dz
216 double z = impPar[2];
217 if (z>fZMax+impPar[3]) return 0; // outside of Z coverage
219 if (z<-impPar[3]) return 0; // outside of Z coverage
220 int sensInRow = int(z*fSensDZInv);
221 if (sensInRow<0) sensInRow = 0;
222 else if (sensInRow>=fNSensorsPerRow) sensInRow = fNSensorsPerRow-1;
224 double phi = impPar[0] - fPhiOffs;
226 int rowID = int(phi*fSensDPhiInv); // stave id
228 int sensID = rowID*fNSensorsPerRow + sensInRow; // most probable candidate
231 AliITSURecoSens* sensN,*sens = GetSensor(sesnID);
233 // make sure this is best matching sensor
234 if (sens->GetZMin()<impPar[2] && sens->GetZMax()>impPar[2] &&
235 OKforPhiMin(sens->GetPhiMin(),impPar[0]) && OKforPhiMax(sens->GetPhiMax(),impPar[0]) )
237 sensors[nsens++] = sens;
240 double zMn=impPar[2]-impPar[3], zMx=impPar[2]+impPar[3], phiMn=impPar[0]-impPar[1], phiMx=impPar[0]+impPar[1];
244 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbR)); // neighbor on the right (smaller phi)
245 if (sensN && OKforPhiMin(phiMn,sensN->GetPhiMax())) sensors[nsens++] = sensN;
247 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbTR)); // neighbor on the top right (smaller phi, larger Z)
248 if (sensN && OKforPhiMin(phiMn,sensN->GetPhiMax()) && sensN->GetZMin()<zMx) sensors[nsens++] = sensN;
250 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbT)); // neighbor on the top (larger Z)
251 if (sensN && sensN->GetZMin()<zMx) sensors[nsens++] = sensN;
253 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbTL)); // neighbor on the top left (larger Z, larger phi)
254 if (sensN && OKforPhiMax(phiMx,sensN->GetPhiMin()) && sensN->GetZMin()<zMx) sensors[nsens++] = sensN;
256 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbL)); // neighbor on the left (larger phi)
257 if (sensN && OKforPhiMax(phiMx,sensN->GetPhiMin())) sensors[nsens++] = sensN;
259 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbBL)); // neighbor on the bottom left (smaller Z, larger phi)
260 if (sensN && OKforPhiMax(phiMx,sensN->GetPhiMin()) && sensN->GetZMax()>zMn) sensors[nsens++] = sensN;
262 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbB)); // neighbor on the bottom (smaller Z)
263 if (sensN && sensN->GetZMax()>zMn) sensors[nsens++] = sensN;
265 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbBR)); // neighbor on the bottom right (smaller Z, smaller phi)
266 if (sensN && OKforPhiMin(phiMn,sensN->GetPhiMax()) && sensN->GetZMax()>zMn) sensors[nsens++] = sensN;
274 Int_t AliITSURecoLayer::FindSensors(const double* impPar, AliITSURecoSens *sensors[AliITSURecoSens::kNNeighbors],int mcLab)
276 // find sensors having intersection with track
277 // impPar contains: lab phi of track, dphi, labZ, dz
282 if (mcLab>=0) { // find correct sensors from MC info
283 int ncl = GetNClusters();
284 for (int icl=ncl;icl--;) {
285 AliCluster* cl = GetCluster(icl);
286 for (int ilb=0;ilb<3;ilb++) {
287 if (cl->GetLabel(ilb)<0) break;
288 if (cl->GetLabel(ilb)==mcLab) {fndSens[nFnd++] = cl->GetVolumeId(); break;}
292 Int_t layS,staS,sensS;
293 for (int is=0;is<nFnd;is++) {
294 fITSGeom->GetChipId(fndSens[is],layS,staS,sensS);
295 printf("SNMC#%d(%d): %d %d %d | ",is,mcLab,layS,staS,sensS); GetSensorFromID(fndSens[is])->Print();
302 double z = impPar[2];
303 if (z>fZMax+impPar[3]) {
304 if (nFnd>0) printf("MissedSens!!!\n");
305 return 0; // outside of Z coverage
309 if (nFnd>0) printf("MissedSens!!!\n");
310 return 0; // outside of Z coverage
312 int sensInSta = int(z*fSensDZInv);
313 if (sensInSta<0) sensInSta = 0;
314 else if (sensInSta>=fNSensInStave) sensInSta = fNSensInStave-1;
316 double phi = impPar[0] - fPhiOffs;
318 int staID = int(phi*fSensDPhiInv); // stave id
321 AliITSURecoSens* sensN,*sens = GetSensor(staID*fNSensInStave+sensInSta);
322 sensors[nsens++] = sens;
325 double zMn=impPar[2]-impPar[3], zMx=impPar[2]+impPar[3], phiMn=impPar[0]-impPar[1], phiMx=impPar[0]+impPar[1];
329 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbR)); // neighbor on the right (smaller phi)
330 if (sensN && OKforPhiMin(phiMn,sensN->GetPhiMax())) sensors[nsens++] = sensN;
332 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbTR)); // neighbor on the top right (smaller phi, larger Z)
333 if (sensN && OKforPhiMin(phiMn,sensN->GetPhiMax()) && sensN->GetZMin()<zMx) sensors[nsens++] = sensN;
335 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbT)); // neighbor on the top (larger Z)
336 if (sensN && sensN->GetZMin()<zMx) sensors[nsens++] = sensN;
338 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbTL)); // neighbor on the top left (larger Z, larger phi)
339 if (sensN && OKforPhiMax(phiMx,sensN->GetPhiMin()) && sensN->GetZMin()<zMx) sensors[nsens++] = sensN;
341 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbL)); // neighbor on the left (larger phi)
342 if (sensN && OKforPhiMax(phiMx,sensN->GetPhiMin())) sensors[nsens++] = sensN;
344 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbBL)); // neighbor on the bottom left (smaller Z, larger phi)
345 if (sensN && OKforPhiMax(phiMx,sensN->GetPhiMin()) && sensN->GetZMax()>zMn) sensors[nsens++] = sensN;
347 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbB)); // neighbor on the bottom (smaller Z)
348 if (sensN && sensN->GetZMax()>zMn) sensors[nsens++] = sensN;
350 sensN = GetSensor(sens->GetNeighborID(AliITSURecoSens::kNghbBR)); // neighbor on the bottom right (smaller Z, smaller phi)
351 if (sensN && OKforPhiMin(phiMn,sensN->GetPhiMax()) && sensN->GetZMax()>zMn) sensors[nsens++] = sensN;
354 Int_t layS,staS,sensS;
355 printf("Found %d sensors for phi %.3f : %.3f | Z %.4f %.4f\n", nsens,phiMn,phiMx,zMn,zMx);
356 for (int is=0;is<nsens;is++) {
357 fITSGeom->GetChipId(sensors[is]->GetID()+fITSGeom->GetFirstModIndex(fActiveID),layS,staS,sensS);
358 printf("*SNF#%d: %d %d %d | ",is,layS,staS,sensS); sensors[is]->Print();
360 for (int ism=0;ism<nFnd;ism++) {
361 AliITSURecoSens* snMC = GetSensorFromID(fndSens[ism]);
363 for (int isf=0;isf<nsens;isf++) {
364 if (snMC==sensors[isf]) {ok=kTRUE;break;}
366 if (!ok) printf("MissedSens %d!!!\n",ism);
372 //______________________________________________________
373 void AliITSURecoLayer::ProcessClusters(Int_t mode)
375 // register in each sensor of the layer its cluster.
376 // the clusters of the layer must be sorted per sensor
377 int ncl = fClusters->GetEntriesFast();
379 for (int i=fNSensors;i--;) GetSensor(i)->SetNClusters(0);
380 AliITSURecoSens* curSens = 0;
381 for (int icl=0;icl<ncl;icl++) {
382 AliITSUClusterPix* cl = (AliITSUClusterPix*) fClusters->UncheckedAt(icl);
384 int vID = cl->GetVolumeId();
385 if (vID<curSensID) {AliFatal("Clusters are not sorted in increasing sensorID");}
387 if (curSens) curSens->ProcessClusters(mode); // prepare clusters for reconstruction
388 curSens = GetSensor(vID - fITSGeom->GetFirstChipIndex(fActiveID));
390 curSens->SetFirstClusterId(icl);
392 curSens->IncNClusters();
394 if (curSens) curSens->ProcessClusters(mode); // last sensor was not processed yet
398 //______________________________________________________
399 Bool_t AliITSURecoLayer::IsEqual(const TObject* obj) const
401 // check if layers are equal in R
402 const AliITSURecoLayer* lr = (const AliITSURecoLayer*)obj;
403 return Abs(lr->GetR()-GetR())<1e-6 ? kTRUE : kFALSE;
406 //______________________________________________________
407 Int_t AliITSURecoLayer::Compare(const TObject* obj) const
409 // compare two layers
410 const AliITSURecoLayer* lr = (const AliITSURecoLayer*)obj;
411 double dr = GetR() - lr->GetR();
412 if (Abs(dr)<1e-6) return 0;
417 //_________________________________________________________________
418 AliITSURecoSens* AliITSURecoLayer::GetSensorFromID(Int_t i) const
420 // get sensor from its global id
421 i -= fITSGeom->GetFirstChipIndex(fActiveID);
422 if (i<0||i>=fNSensors) AliFatal(Form("Sensor with id=%d is not in layer %d",i+fITSGeom->GetFirstChipIndex(fActiveID),fActiveID));
423 return GetSensor(SensVIDtoMatrixID(i));