1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /* $Id: AliITSUSegmentationPix.cxx 47180 2011-02-08 09:42:29Z masera $ */
17 #include <TGeoManager.h>
18 #include <TGeoVolume.h>
20 #include <TObjArray.h>
24 #include "AliITSUGeomTGeo.h"
25 #include "AliITSUSegmentationPix.h"
26 using namespace TMath;
28 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 // Segmentation class for pixels //
30 // Questions to solve: are guardrings needed and do they belong to the sensor or to the module in TGeo //
31 // At the moment assume that the local coord syst. is located at bottom left corner //
32 // of the ACTIVE matrix. If the guardring to be accounted in the local coords, in //
33 // the Z and X conversions one needs to first subtract the fGuardLft and fGuardBot //
34 // from the local Z,X coordinates //
36 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
38 ClassImp(AliITSUSegmentationPix)
40 const char* AliITSUSegmentationPix::fgkSegmListName = "ITSUSegmentations";
42 //_____________________________________________________________________________RS
43 AliITSUSegmentationPix::AliITSUSegmentationPix(UInt_t id, int nchips,int ncol,int nrow,
44 double pitchX,double pitchZ,
46 double pitchLftC,double pitchRgtC,
47 double edgL,double edgR,double edgT,double edgB)
48 : AliITSsegmentation()
55 ,fPitchZLftCol(pitchLftC<0 ? pitchZ:pitchLftC)
56 ,fPitchZRgtCol(pitchRgtC<0 ? pitchZ:pitchRgtC)
59 ,fNColPerChip(nchips>0 ? ncol/nchips:0)
63 // Default constructor, sizes in cm
64 if (nchips) SetUniqueID( AliITSUGeomTGeo::ComposeDetTypeID(id) );
65 fChipDZ = (fNColPerChip-2)*fPitchZ + fPitchZLftCol + fPitchZRgtCol;
66 SetDetSize( fNRow*fPitchX /*+fGuardTop+fGuardBot*/,
67 fNChips*fChipDZ /*+fGuardLft+fGuardRgt*/,
72 //_____________________________________________________________________________RS
73 void AliITSUSegmentationPix::GetPadIxz(Float_t x,Float_t z,Int_t &ix,Int_t &iz) const
75 // Returns pixel coordinates (ix,iz) for given real local coordinates (x,z)
76 // expects x, z in cm. RS: TO CHECK: why from 1
77 ix = int(x/fPitchX) + 1;
78 iz = int(Z2Col(z)) + 1;
80 if (iz > fNCol) iz= fNCol;
81 if (ix > fNRow) ix= fNRow;
85 //_____________________________________________________________________________RS
86 void AliITSUSegmentationPix::GetPadTxz(Float_t &x,Float_t &z) const
88 // local transformation of real local coordinates (x,z)
95 //_____________________________________________________________________________RS
96 void AliITSUSegmentationPix::GetPadCxz(Int_t ix,Int_t iz,Float_t &x,Float_t&z) const
98 // Transform from pixel to real local coordinates
99 // returns x, z in cm.
100 x = Float_t((ix+0.5)*fPitchX);
105 //_____________________________________________________________________________RS
106 Float_t AliITSUSegmentationPix::Z2Col(Float_t z) const
108 // get column number (from 0) from local Z
109 int chip = int(z/fChipDZ);
110 float col = chip*fNColPerChip;
112 if (z>fPitchZLftCol) col += 1+(z-fPitchZLftCol)/fPitchZ;
116 //_____________________________________________________________________________RS
117 Float_t AliITSUSegmentationPix::Col2Z(Int_t col) const
119 // convert column number (from 0) to Z coordinate
120 int nchip = col/fNColPerChip;
122 float z = nchip*fChipDZ;
124 if (col<fNColPerChip-1) z += fPitchZLftCol + (col-0.5)*fPitchZ;
125 else z += fChipDZ - fPitchZRgtCol/2;
127 else z += fPitchZLftCol/2;
132 //______________________________________________________________________RS
133 AliITSUSegmentationPix& AliITSUSegmentationPix::operator=(const AliITSUSegmentationPix &src)
136 if(this==&src) return *this;
137 AliITSsegmentation::operator=(src);
140 fNColPerChip = src.fNColPerChip;
141 fNChips = src.fNChips;
142 fChipDZ = src.fChipDZ;
143 fPitchZRgtCol = src.fPitchZRgtCol;
144 fPitchZLftCol = src.fPitchZLftCol;
145 fPitchZ = src.fPitchZ;
146 fPitchX = src.fPitchX;
148 fGuardBot = src.fGuardBot;
149 fGuardTop = src.fGuardTop;
150 fGuardRgt = src.fGuardRgt;
151 fGuardLft = src.fGuardLft;
156 //____________________________________________________________________________RS
157 AliITSUSegmentationPix::AliITSUSegmentationPix(const AliITSUSegmentationPix &src) :
158 AliITSsegmentation(src)
159 ,fGuardLft(src.fGuardLft)
160 ,fGuardRgt(src.fGuardRgt)
161 ,fGuardTop(src.fGuardTop)
162 ,fGuardBot(src.fGuardBot)
163 ,fPitchX(src.fPitchX)
164 ,fPitchZ(src.fPitchZ)
165 ,fPitchZLftCol(src.fPitchZLftCol)
166 ,fPitchZRgtCol(src.fPitchZRgtCol)
167 ,fChipDZ(src.fChipDZ)
168 ,fNChips(src.fNChips)
169 ,fNColPerChip(src.fNColPerChip)
175 //____________________________________________________________________________RS
176 Float_t AliITSUSegmentationPix::Dpx(Int_t ) const
178 //returs x pixel pitch for a give pixel
182 //____________________________________________________________________________RS
183 Float_t AliITSUSegmentationPix::Dpz(Int_t col) const
185 // returns z pixel pitch for a given pixel (cols starts from 0)
187 if (!col) return fPitchZLftCol;
188 if (col==fNColPerChip-1) return fPitchZRgtCol;
193 //------------------------------
194 void AliITSUSegmentationPix::Neighbours(Int_t iX, Int_t iZ, Int_t* nlist, Int_t xlist[8], Int_t zlist[8]) const
196 // returns the neighbouring pixels for use in Cluster Finders and the like.
199 xlist[0]=xlist[1]=iX;
204 zlist[2]=zlist[3]=iZ;
220 //______________________________________________________________________
221 Bool_t AliITSUSegmentationPix::LocalToDet(Float_t x,Float_t z,Int_t &ix,Int_t &iz) const
223 // Transformation from Geant detector centered local coordinates (cm) to
224 // Pixel cell numbers ix and iz.
226 // Float_t x detector local coordinate x in cm with respect to
227 // the center of the sensitive volume.
228 // Float_t z detector local coordinate z in cm with respect to
229 // the center of the sensitive volulme.
231 // Int_t ix detector x cell coordinate. Has the range
233 // Int_t iz detector z cell coordinate. Has the range
236 // kTRUE if point x,z is inside sensitive volume, kFALSE otherwise.
237 // A value of -1 for ix or iz indecates that this point is outside of the
238 // detector segmentation as defined.
242 if(x<0 || x>Dx()) return kFALSE; // outside x range.
243 if(z<0 || z>Dz()) return kFALSE; // outside z range.
246 return kTRUE; // Found ix and iz, return.
249 //______________________________________________________________________
250 void AliITSUSegmentationPix::DetToLocal(Int_t ix,Int_t iz,Float_t &x,Float_t &z) const
252 // Transformation from Detector cell coordiantes to Geant detector centerd
253 // local coordinates (cm).
255 // Int_t ix detector x cell coordinate. Has the range 0<=ix<fNRow.
256 // Int_t iz detector z cell coordinate. Has the range 0<=iz<fNCol.
258 // Float_t x detector local coordinate x in cm with respect to the
259 // center of the sensitive volume.
260 // Float_t z detector local coordinate z in cm with respect to the
261 // center of the sensitive volulme.
262 // If ix and or iz is outside of the segmentation range a value of -0.5*Dx()
263 // or -0.5*Dz() is returned.
265 x = -0.5*Dx(); // default value.
266 z = -0.5*Dz(); // default value.
267 // RS: to check: why we don't do strict check for [0:n)
268 if(ix<0 || ix>fNRow) return; // outside of detector
269 if(iz<0 || iz>fNCol) return; // outside of detctor
270 x += (ix+0.5)*fPitchX; // RS: we go to the center of the pad, i.e. + pitch/2, not to the boundary as in SPD
272 return; // Found x and z, return.
275 //______________________________________________________________________
276 void AliITSUSegmentationPix::CellBoundries(Int_t ix,Int_t iz,Double_t &xl,Double_t &xu,Double_t &zl,Double_t &zu) const
278 // Transformation from Detector cell coordiantes to Geant detector centerd
279 // local coordinates (cm).
281 // Int_t ix detector x cell coordinate. Has the range 0<=ix<fNRow.
282 // Int_t iz detector z cell coordinate. Has the range 0<=iz<fNCol.
284 // Double_t xl detector local coordinate cell lower bounds x in cm
285 // with respect to the center of the sensitive volume.
286 // Double_t xu detector local coordinate cell upper bounds x in cm
287 // with respect to the center of the sensitive volume.
288 // Double_t zl detector local coordinate lower bounds z in cm with
289 // respect to the center of the sensitive volulme.
290 // Double_t zu detector local coordinate upper bounds z in cm with
291 // respect to the center of the sensitive volulme.
292 // If ix and or iz is outside of the segmentation range a value of -0.5*Dx()
293 // and -0.5*Dx() or -0.5*Dz() and -0.5*Dz() are returned.
295 DetToLocal(ix,iz,x,z);
297 if( ix<0 || ix>=fNRow || iz<0 || iz>=fNCol) {
298 xl = xu = -0.5*Dx(); // default value.
299 zl = zu = -0.5*Dz(); // default value.
300 return; // outside of detctor
302 float zpitchH = Dpz(iz)*0.5;
303 float xpitchH = fPitchX*0.5;
308 return; // Found x and z, return.
311 //______________________________________________________________________
312 Int_t AliITSUSegmentationPix::GetChipFromChannel(Int_t, Int_t iz) const
314 // returns chip number (in range 0-4) starting from channel number
315 if(iz>=fNCol || iz<0 ){
316 AliWarning("Bad cell number");
319 return iz/fNColPerChip;
322 //______________________________________________________________________
323 Int_t AliITSUSegmentationPix::GetChipFromLocal(Float_t, Float_t zloc) const
325 // returns chip number (in range 0-4) starting from local coordinates
327 if (!LocalToDet(0,zloc,ix0,iz)) {
328 AliWarning("Bad local coordinate");
331 return GetChipFromChannel(ix0,iz);
334 //______________________________________________________________________
335 Int_t AliITSUSegmentationPix::GetChipsInLocalWindow(Int_t* array, Float_t zmin, Float_t zmax, Float_t, Float_t) const
337 // returns the number of chips containing a road defined by given local coordinate limits
340 AliWarning("Bad coordinate limits: zmin>zmax!");
346 Float_t zminDet = -0.5*Dz();
347 Float_t zmaxDet = 0.5*Dz();
348 if(zmin<zminDet) zmin=zminDet;
349 if(zmax>zmaxDet) zmax=zmaxDet;
351 Int_t n1 = GetChipFromLocal(0,zmin);
352 array[nChipInW] = n1;
355 Int_t n2 = GetChipFromLocal(0,zmax);
358 Int_t imin=Min(n1,n2);
359 Int_t imax=Max(n1,n2);
360 for(Int_t ichip=imin; ichip<=imax; ichip++){
361 if(ichip==n1) continue;
362 array[nChipInW]=ichip;
370 //______________________________________________________________________
371 void AliITSUSegmentationPix::Init()
376 //______________________________________________________________________
377 Bool_t AliITSUSegmentationPix::Store(const char* outf)
379 // store in the special list under given ID
381 gSystem->ExpandPathName(fns);
382 if (fns.IsNull()) {AliFatal("No file name provided"); return kFALSE;}
383 TFile* fout = TFile::Open(fns.Data(),"update");
384 if (!fout) {AliFatal(Form("Failed to open output file %s",outf)); return kFALSE;}
385 TObjArray* arr = (TObjArray*)fout->Get(fgkSegmListName);
386 int id = GetUniqueID();
387 if (!arr) arr = new TObjArray();
388 else if (arr->At(id)) {AliFatal(Form("Segmenation %d already exists in file %s",id,outf));return kFALSE;}
390 arr->AddAtAndExpand(this,id);
391 arr->SetOwner(kTRUE);
392 fout->WriteObject(arr,fgkSegmListName,"kSingleKey");
397 AliInfo(Form("Stored segmentation %d in %s",id,outf));
402 //______________________________________________________________________
403 AliITSUSegmentationPix* AliITSUSegmentationPix::LoadWithID(UInt_t id, const char* inpf)
405 // store in the special list under given ID
407 gSystem->ExpandPathName(fns);
408 if (fns.IsNull()) {AliFatalGeneral("LoadWithID","No file name provided"); return 0;}
409 TFile* finp = TFile::Open(fns.Data());
410 if (!finp) {AliFatalGeneral("LoadWithID",Form("Failed to open file %s",inpf)); return 0;}
411 TObjArray* arr = (TObjArray*)finp->Get(fgkSegmListName);
413 AliFatalGeneral("LoadWithID",Form("Failed to find segmenation array %s in %s",fgkSegmListName,inpf));
416 AliITSUSegmentationPix* segm = dynamic_cast<AliITSUSegmentationPix*>(arr->At(id));
417 if (!segm || segm->GetUniqueID()!=id) {AliFatalGeneral("LoadWithID",Form("Failed to find segmenation %d in %s",id,inpf)); return 0;}
420 arr->SetOwner(kTRUE); // to not leave in memory other segmenations
428 //______________________________________________________________________
429 void AliITSUSegmentationPix::LoadSegmentations(TObjArray* dest, const char* inpf)
431 // store in the special list under given ID
434 gSystem->ExpandPathName(fns);
435 if (fns.IsNull()) AliFatalGeneral("LoadWithID","No file name provided");
436 TFile* finp = TFile::Open(fns.Data());
437 if (!finp) AliFatalGeneral("LoadWithID",Form("Failed to open file %s",inpf));
438 TObjArray* arr = (TObjArray*)finp->Get(fgkSegmListName);
439 if (!arr) AliFatalGeneral("LoadWithID",Form("Failed to find segmenation array %s in %s",fgkSegmListName,inpf));
440 int nent = arr->GetEntriesFast();
442 for (int i=nent;i--;) if ((segm=arr->At(i))) dest->AddAtAndExpand(segm,segm->GetUniqueID());
443 AliInfoGeneral("LoadSegmentations",Form("Loaded %d segmantions from %s",arr->GetEntries(),inpf));
444 arr->SetOwner(kFALSE);