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"
27 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
28 // Segmentation class for pixels //
29 // Questions to solve: are guardrings needed and do they belong to the sensor or to the module in TGeo //
30 // At the moment assume that the local coord syst. is located at bottom left corner //
31 // of the ACTIVE matrix. If the guardring to be accounted in the local coords, in //
32 // the Z and X conversions one needs to first subtract the fGuardLft and fGuardBot //
33 // from the local Z,X coordinates //
35 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
37 ClassImp(AliITSUSegmentationPix)
39 const char* AliITSUSegmentationPix::fgkSegmListName = "ITSUpgradeSegmentations";
41 //_____________________________________________________________________________RS
42 AliITSUSegmentationPix::AliITSUSegmentationPix(UInt_t id, int nchips,int ncol,int nrow,
43 double pitchX,double pitchZ,
45 double pitchLftC,double pitchRgtC,
46 double edgL,double edgR,double edgT,double edgB)
47 : AliITSsegmentation()
54 ,fPitchZLftCol(pitchLftC<0 ? pitchZ:pitchLftC)
55 ,fPitchZRgtCol(pitchRgtC<0 ? pitchZ:pitchRgtC)
58 ,fNColPerChip(nchips>0 ? ncol/nchips:0)
62 // Default constructor, sizes in microns
63 if (nchips) SetUniqueID( AliITSUGeomTGeo::ComposeDetTypeID(id) );
64 fChipDZ = (fNColPerChip-2)*fPitchZ + fPitchZLftCol + fPitchZRgtCol;
65 SetDetSize( fNRow*fPitchX /*+fGuardTop+fGuardBot*/,
66 fNChips*fChipDZ /*+fGuardLft+fGuardRgt*/,
71 //_____________________________________________________________________________RS
72 void AliITSUSegmentationPix::GetPadIxz(Float_t x,Float_t z,Int_t &ix,Int_t &iz) const
74 // Returns pixel coordinates (ix,iz) for given real local coordinates (x,z)
75 // expects x, z in microns
76 ix = int(x/fPitchX) + 1;
77 iz = int(Z2Col(z)) + 1;
79 if (iz > fNCol) iz= fNCol;
80 if (ix > fNRow) ix= fNRow;
84 //_____________________________________________________________________________RS
85 void AliITSUSegmentationPix::GetPadTxz(Float_t &x,Float_t &z) const
87 // local transformation of real local coordinates (x,z)
88 // expects x, z in microns
94 //_____________________________________________________________________________RS
95 void AliITSUSegmentationPix::GetPadCxz(Int_t ix,Int_t iz,Float_t &x,Float_t&z) const
97 // Transform from pixel to real local coordinates
98 // returns x, z in microns
99 x = (ix>0) ? Float_t((ix-0.5)*fPitchX) : Float_t((ix+0.5)*fPitchX);
104 //_____________________________________________________________________________RS
105 Float_t AliITSUSegmentationPix::Z2Col(Float_t z) const
107 // get column number (from 0) from local Z
108 int chip = z/fChipDZ;
109 float col = chip*fNColPerChip;
111 if (z<fPitchZLftCol) col += z/fPitchZLftCol;
115 if (z<(fChipDZ-fPitchZRgtCol)) col += 1+z/fPitchZ;
116 else col += 1+(z - (fNColPerChip-2)*fPitchZ)/fPitchZRgtCol;
121 //_____________________________________________________________________________RS
122 Float_t AliITSUSegmentationPix::Col2Z(Int_t col) const
124 // convert column number (from 0) to Z coordinate
125 int nchip = col/fNColPerChip;
127 float z = nchip*fChipDZ;
128 if (!col) z -= fPitchZRgtCol/2;
129 else if (col==1) z += fPitchZLftCol/2;
130 else if (col==fNColPerChip-1) z += fChipDZ - fPitchZRgtCol/2;
131 else z += fPitchZLftCol + (col-0.5)*fChipDZ;
136 //______________________________________________________________________RS
137 AliITSUSegmentationPix& AliITSUSegmentationPix::operator=(const AliITSUSegmentationPix &src)
140 if(this==&src) return *this;
141 AliITSsegmentation::operator=(src);
144 fNColPerChip = src.fNColPerChip;
145 fNChips = src.fNChips;
146 fChipDZ = src.fChipDZ;
147 fPitchZRgtCol = src.fPitchZRgtCol;
148 fPitchZLftCol = src.fPitchZLftCol;
149 fPitchZ = src.fPitchZ;
150 fPitchX = src.fPitchX;
152 fGuardBot = src.fGuardBot;
153 fGuardTop = src.fGuardTop;
154 fGuardRgt = src.fGuardRgt;
155 fGuardLft = src.fGuardLft;
160 //____________________________________________________________________________RS
161 AliITSUSegmentationPix::AliITSUSegmentationPix(const AliITSUSegmentationPix &src) :
162 AliITSsegmentation(src)
163 ,fGuardLft(src.fGuardLft)
164 ,fGuardRgt(src.fGuardRgt)
165 ,fGuardTop(src.fGuardTop)
166 ,fGuardBot(src.fGuardBot)
167 ,fPitchX(src.fPitchX)
168 ,fPitchZ(src.fPitchZ)
169 ,fPitchZLftCol(src.fPitchZLftCol)
170 ,fPitchZRgtCol(src.fPitchZRgtCol)
171 ,fChipDZ(src.fChipDZ)
172 ,fNChips(src.fNChips)
173 ,fNColPerChip(src.fNColPerChip)
179 //____________________________________________________________________________RS
180 Float_t AliITSUSegmentationPix::Dpx(Int_t ) const
182 //returs x pixel pitch for a give pixel
186 //____________________________________________________________________________RS
187 Float_t AliITSUSegmentationPix::Dpz(Int_t col) const
189 // returns z pixel pitch for a given pixel (cols starts from 0)
191 if (!col) return fPitchZLftCol;
192 if (col==fNColPerChip-1) return fPitchZRgtCol;
197 //------------------------------
198 void AliITSUSegmentationPix::Neighbours(Int_t iX, Int_t iZ, Int_t* nlist, Int_t xlist[8], Int_t zlist[8]) const
200 // returns the neighbouring pixels for use in Cluster Finders and the like.
203 xlist[0]=xlist[1]=iX;
208 zlist[2]=zlist[3]=iZ;
224 //______________________________________________________________________
225 Bool_t AliITSUSegmentationPix::LocalToDet(Float_t x,Float_t z,Int_t &ix,Int_t &iz) const
227 // Transformation from Geant detector centered local coordinates (cm) to
228 // Pixel cell numbers ix and iz.
230 // Float_t x detector local coordinate x in cm with respect to
231 // the center of the sensitive volume.
232 // Float_t z detector local coordinate z in cm with respect to
233 // the center of the sensitive volulme.
235 // Int_t ix detector x cell coordinate. Has the range
237 // Int_t iz detector z cell coordinate. Has the range
240 // kTRUE if point x,z is inside sensitive volume, kFALSE otherwise.
241 // A value of -1 for ix or iz indecates that this point is outside of the
242 // detector segmentation as defined.
243 x = x*kCM2MC+0.5*Dx();
244 z = z*kCM2MC+0.5*Dz();
246 if(x<0 || x>Dx()) return kFALSE; // outside x range.
247 if(z<0 || z>Dz()) return kFALSE; // outside z range.
250 return kTRUE; // Found ix and iz, return.
253 //______________________________________________________________________
254 void AliITSUSegmentationPix::DetToLocal(Int_t ix,Int_t iz,Float_t &x,Float_t &z) const
256 // Transformation from Detector cell coordiantes to Geant detector centerd
257 // local coordinates (cm).
259 // Int_t ix detector x cell coordinate. Has the range 0<=ix<fNRow.
260 // Int_t iz detector z cell coordinate. Has the range 0<=iz<fNCol.
262 // Float_t x detector local coordinate x in cm with respect to the
263 // center of the sensitive volume.
264 // Float_t z detector local coordinate z in cm with respect to the
265 // center of the sensitive volulme.
266 // If ix and or iz is outside of the segmentation range a value of -0.5*Dx()
267 // or -0.5*Dz() is returned.
269 x = -0.5/kCM2MC*Dx(); // default value.
270 z = -0.5/kCM2MC*Dz(); // default value.
271 // RS: to check: why we don't do strict check for [0:n)
272 if(ix<0 || ix>=fNRow) return; // outside of detector
273 if(iz<0 || iz>=fNCol) return; // outside of detctor
274 x += (ix+0.5)*fPitchX*(1./kCM2MC); // RS: we go to the center of the pad, i.e. + pitch/2, not to the boundary as in SPD
275 z += Col2Z(iz)*(1./kCM2MC);
276 return; // Found x and z, return.
279 //______________________________________________________________________
280 void AliITSUSegmentationPix::CellBoundries(Int_t ix,Int_t iz,Double_t &xl,Double_t &xu,Double_t &zl,Double_t &zu) const
282 // Transformation from Detector cell coordiantes to Geant detector centerd
283 // local coordinates (cm).
285 // Int_t ix detector x cell coordinate. Has the range 0<=ix<fNRow.
286 // Int_t iz detector z cell coordinate. Has the range 0<=iz<fNCol.
288 // Double_t xl detector local coordinate cell lower bounds x in cm
289 // with respect to the center of the sensitive volume.
290 // Double_t xu detector local coordinate cell upper bounds x in cm
291 // with respect to the center of the sensitive volume.
292 // Double_t zl detector local coordinate lower bounds z in cm with
293 // respect to the center of the sensitive volulme.
294 // Double_t zu detector local coordinate upper bounds z in cm with
295 // respect to the center of the sensitive volulme.
296 // If ix and or iz is outside of the segmentation range a value of -0.5*Dx()
297 // and -0.5*Dx() or -0.5*Dz() and -0.5*Dz() are returned.
299 DetToLocal(ix,iz,x,z);
301 if( ix<0 || ix>=fNRow || iz<0 || iz>=fNCol) {
302 xl = xu = -0.5/kCM2MC*Dx(); // default value.
303 zl = zu = -0.5/kCM2MC*Dz(); // default value.
304 return; // outside of detctor
306 float zpitchH = Dpz(iz)/2./kCM2MC;
307 float xpitchH = fPitchX/2./kCM2MC;
312 return; // Found x and z, return.
315 //______________________________________________________________________
316 Int_t AliITSUSegmentationPix::GetChipFromChannel(Int_t, Int_t iz) const
318 // returns chip number (in range 0-4) starting from channel number
319 if(iz>=fNCol || iz<0 ){
320 AliWarning("Bad cell number");
323 return iz/fNColPerChip;
326 //______________________________________________________________________
327 Int_t AliITSUSegmentationPix::GetChipFromLocal(Float_t, Float_t zloc) const
329 // returns chip number (in range 0-4) starting from local coordinates
331 if (!LocalToDet(0,zloc,ix0,iz)) {
332 AliWarning("Bad local coordinate");
335 return GetChipFromChannel(ix0,iz);
338 //______________________________________________________________________
339 Int_t AliITSUSegmentationPix::GetChipsInLocalWindow(Int_t* array, Float_t zmin, Float_t zmax, Float_t, Float_t) const
341 // returns the number of chips containing a road defined by given local coordinate limits
343 const Float_t kconv = 1./kCM2MC; // converts microns to cm.
346 AliWarning("Bad coordinate limits: zmin>zmax!");
352 Float_t zminDet = -0.5*kconv*Dz();
353 Float_t zmaxDet = 0.5*kconv*Dz();
354 if(zmin<zminDet) zmin=zminDet;
355 if(zmax>zmaxDet) zmax=zmaxDet;
357 Int_t n1 = GetChipFromLocal(0,zmin);
358 array[nChipInW] = n1;
361 Int_t n2 = GetChipFromLocal(0,zmax);
364 Int_t imin=TMath::Min(n1,n2);
365 Int_t imax=TMath::Max(n1,n2);
366 for(Int_t ichip=imin; ichip<=imax; ichip++){
367 if(ichip==n1) continue;
368 array[nChipInW]=ichip;
376 //______________________________________________________________________
377 void AliITSUSegmentationPix::Init()
382 //______________________________________________________________________
383 Bool_t AliITSUSegmentationPix::Store(const char* outf)
385 // store in the special list under given ID
387 gSystem->ExpandPathName(fns);
388 if (fns.IsNull()) {AliFatal("No file name provided"); return kFALSE;}
389 TFile* fout = TFile::Open(fns.Data(),"update");
390 if (!fout) {AliFatal(Form("Failed to open output file %s",outf)); return kFALSE;}
391 TObjArray* arr = (TObjArray*)fout->Get(fgkSegmListName);
392 int id = GetUniqueID();
393 if (!arr) arr = new TObjArray();
394 else if (arr->At(id)) {AliFatal(Form("Segmenation %d already exists in file %s",id,outf));return kFALSE;}
396 arr->AddAtAndExpand(this,id);
397 arr->SetOwner(kTRUE);
398 fout->WriteObject(arr,fgkSegmListName,"kSingleKey");
403 AliInfo(Form("Stored segmentation %d in %s",id,outf));
408 //______________________________________________________________________
409 AliITSUSegmentationPix* AliITSUSegmentationPix::LoadWithID(UInt_t id, const char* inpf)
411 // store in the special list under given ID
413 gSystem->ExpandPathName(fns);
414 if (fns.IsNull()) {AliFatalGeneral("LoadWithID","No file name provided"); return 0;}
415 TFile* finp = TFile::Open(fns.Data());
416 if (!finp) {AliFatalGeneral("LoadWithID",Form("Failed to open file %s",inpf)); return 0;}
417 TObjArray* arr = (TObjArray*)finp->Get(fgkSegmListName);
419 AliFatalGeneral("LoadWithID",Form("Failed to find segmenation array %s in %s",fgkSegmListName,inpf));
422 AliITSUSegmentationPix* segm = dynamic_cast<AliITSUSegmentationPix*>(arr->At(id));
423 if (!segm || segm->GetUniqueID()!=id) {AliFatalGeneral("LoadWithID",Form("Failed to find segmenation %d in %s",id,inpf)); return 0;}
426 arr->SetOwner(kTRUE); // to not leave in memory other segmenations
434 //______________________________________________________________________
435 void AliITSUSegmentationPix::LoadSegmentations(TObjArray* dest, const char* inpf)
437 // store in the special list under given ID
440 gSystem->ExpandPathName(fns);
441 if (fns.IsNull()) AliFatalGeneral("LoadWithID","No file name provided");
442 TFile* finp = TFile::Open(fns.Data());
443 if (!finp) AliFatalGeneral("LoadWithID",Form("Failed to open file %s",inpf));
444 TObjArray* arr = (TObjArray*)finp->Get(fgkSegmListName);
445 if (!arr) AliFatalGeneral("LoadWithID",Form("Failed to find segmenation array %s in %s",fgkSegmListName,inpf));
446 int nent = arr->GetEntriesFast();
448 for (int i=nent;i--;) if ((segm=arr->At(i))) dest->AddAtAndExpand(segm,segm->GetUniqueID());
449 AliInfoGeneral("LoadSegmentations",Form("Loaded %d segmantions from %s",arr->GetEntries(),inpf));
450 arr->SetOwner(kFALSE);