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: AliITSsegmentationPixUpg.cxx 47180 2011-02-08 09:42:29Z masera $ */
17 #include <TGeoManager.h>
18 #include <TGeoVolume.h>
20 #include <TObjArray.h>
24 #include "AliITSsegmentationPixUpg.h"
26 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 // Segmentation class for pixels //
28 // Questions to solve: are guardrings needed and do they belong to the sensor or to the module in TGeo //
29 // At the moment assume that the local coord syst. is located at bottom left corner //
30 // of the ACTIVE matrix. If the guardring to be accounted in the local coords, in //
31 // the Z and X conversions one needs to first subtract the fGuardLft and fGuardBot //
32 // from the local Z,X coordinates //
34 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
36 ClassImp(AliITSsegmentationPixUpg)
38 const char* AliITSsegmentationPixUpg::fgkSegmListName = "ITSUpgradeSegmentations";
40 //_____________________________________________________________________________RS
41 AliITSsegmentationPixUpg::AliITSsegmentationPixUpg(int nchips,int ncol,int nrow,
42 double pitchX,double pitchZ,
44 double pitchLftC,double pitchRgtC,
45 double edgL,double edgR,double edgT,double edgB)
46 : AliITSsegmentation()
53 ,fPitchZLftCol(pitchLftC<0 ? pitchZ:pitchLftC)
54 ,fPitchZRgtCol(pitchRgtC<0 ? pitchZ:pitchRgtC)
57 ,fNColPerChip(nchips>0 ? ncol/nchips:0)
61 // Default constructor, sizes in microns
62 fChipDZ = (fNColPerChip-2)*fPitchZ + fPitchZLftCol + fPitchZRgtCol;
63 SetDetSize( fNRow*fPitchX /*+fGuardTop+fGuardBot*/,
64 fNChips*fChipDZ /*+fGuardLft+fGuardRgt*/,
69 //_____________________________________________________________________________RS
70 void AliITSsegmentationPixUpg::GetPadIxz(Float_t x,Float_t z,Int_t &ix,Int_t &iz) const
72 // Returns pixel coordinates (ix,iz) for given real local coordinates (x,z)
73 // expects x, z in microns
74 ix = int(x/fPitchX) + 1;
75 iz = int(Z2Col(z)) + 1;
77 if (iz > fNCol) iz= fNCol;
78 if (ix > fNRow) ix= fNRow;
82 //_____________________________________________________________________________RS
83 void AliITSsegmentationPixUpg::GetPadTxz(Float_t &x,Float_t &z) const
85 // local transformation of real local coordinates (x,z)
86 // expects x, z in microns
92 //_____________________________________________________________________________RS
93 void AliITSsegmentationPixUpg::GetPadCxz(Int_t ix,Int_t iz,Float_t &x,Float_t&z) const
95 // Transform from pixel to real local coordinates
96 // returns x, z in microns
97 x = (ix>0) ? Float_t((ix-0.5)*fPitchX) : Float_t((ix+0.5)*fPitchX);
102 //_____________________________________________________________________________RS
103 Float_t AliITSsegmentationPixUpg::Z2Col(Float_t z) const
105 // get column number (from 0) from local Z
106 int chip = z/fChipDZ;
107 float col = chip*fNColPerChip;
109 if (z<fPitchZLftCol) col += z/fPitchZLftCol;
113 if (z<(fChipDZ-fPitchZRgtCol)) col += 1+z/fPitchZ;
114 else col += 1+(z - (fNColPerChip-2)*fPitchZ)/fPitchZRgtCol;
119 //_____________________________________________________________________________RS
120 Float_t AliITSsegmentationPixUpg::Col2Z(Int_t col) const
122 // convert column number (from 0) to Z coordinate
123 int nchip = col/fNColPerChip;
125 float z = nchip*fChipDZ;
126 if (!col) z -= fPitchZRgtCol/2;
127 else if (col==1) z += fPitchZLftCol/2;
128 else if (col==fNColPerChip-1) z += fChipDZ - fPitchZRgtCol/2;
129 else z += fPitchZLftCol + (col-0.5)*fChipDZ;
134 //______________________________________________________________________RS
135 AliITSsegmentationPixUpg& AliITSsegmentationPixUpg::operator=(const AliITSsegmentationPixUpg &src)
138 if(this==&src) return *this;
139 AliITSsegmentation::operator=(src);
142 fNColPerChip = src.fNColPerChip;
143 fNChips = src.fNChips;
144 fChipDZ = src.fChipDZ;
145 fPitchZRgtCol = src.fPitchZRgtCol;
146 fPitchZLftCol = src.fPitchZLftCol;
147 fPitchZ = src.fPitchZ;
148 fPitchX = src.fPitchX;
150 fGuardBot = src.fGuardBot;
151 fGuardTop = src.fGuardTop;
152 fGuardRgt = src.fGuardRgt;
153 fGuardLft = src.fGuardLft;
158 //____________________________________________________________________________RS
159 AliITSsegmentationPixUpg::AliITSsegmentationPixUpg(const AliITSsegmentationPixUpg &src) :
160 AliITSsegmentation(src)
161 ,fGuardLft(src.fGuardLft)
162 ,fGuardRgt(src.fGuardRgt)
163 ,fGuardTop(src.fGuardTop)
164 ,fGuardBot(src.fGuardBot)
165 ,fPitchX(src.fPitchX)
166 ,fPitchZ(src.fPitchZ)
167 ,fPitchZLftCol(src.fPitchZLftCol)
168 ,fPitchZRgtCol(src.fPitchZRgtCol)
169 ,fChipDZ(src.fChipDZ)
170 ,fNChips(src.fNChips)
171 ,fNColPerChip(src.fNColPerChip)
177 //____________________________________________________________________________RS
178 Float_t AliITSsegmentationPixUpg::Dpx(Int_t ) const
180 //returs x pixel pitch for a give pixel
184 //____________________________________________________________________________RS
185 Float_t AliITSsegmentationPixUpg::Dpz(Int_t col) const
187 // returns z pixel pitch for a given pixel (cols starts from 0)
189 if (!col) return fPitchZLftCol;
190 if (col==fNColPerChip-1) return fPitchZRgtCol;
195 //------------------------------
196 void AliITSsegmentationPixUpg::Neighbours(Int_t iX, Int_t iZ, Int_t* nlist, Int_t xlist[8], Int_t zlist[8]) const
198 // returns the neighbouring pixels for use in Cluster Finders and the like.
201 xlist[0]=xlist[1]=iX;
206 zlist[2]=zlist[3]=iZ;
222 //______________________________________________________________________
223 Bool_t AliITSsegmentationPixUpg::LocalToDet(Float_t x,Float_t z,Int_t &ix,Int_t &iz) const
225 // Transformation from Geant detector centered local coordinates (cm) to
226 // Pixel cell numbers ix and iz.
228 // Float_t x detector local coordinate x in cm with respect to
229 // the center of the sensitive volume.
230 // Float_t z detector local coordinate z in cm with respect to
231 // the center of the sensitive volulme.
233 // Int_t ix detector x cell coordinate. Has the range
235 // Int_t iz detector z cell coordinate. Has the range
238 // kTRUE if point x,z is inside sensitive volume, kFALSE otherwise.
239 // A value of -1 for ix or iz indecates that this point is outside of the
240 // detector segmentation as defined.
241 x = x*kCM2MC+0.5*Dx();
242 z = z*kCM2MC+0.5*Dz();
244 if(x<0 || x>Dx()) return kFALSE; // outside x range.
245 if(z<0 || z>Dz()) return kFALSE; // outside z range.
248 return kTRUE; // Found ix and iz, return.
251 //______________________________________________________________________
252 void AliITSsegmentationPixUpg::DetToLocal(Int_t ix,Int_t iz,Float_t &x,Float_t &z) const
254 // Transformation from Detector cell coordiantes to Geant detector centerd
255 // local coordinates (cm).
257 // Int_t ix detector x cell coordinate. Has the range 0<=ix<fNRow.
258 // Int_t iz detector z cell coordinate. Has the range 0<=iz<fNCol.
260 // Float_t x detector local coordinate x in cm with respect to the
261 // center of the sensitive volume.
262 // Float_t z detector local coordinate z in cm with respect to the
263 // center of the sensitive volulme.
264 // If ix and or iz is outside of the segmentation range a value of -0.5*Dx()
265 // or -0.5*Dz() is returned.
267 x = -0.5/kCM2MC*Dx(); // default value.
268 z = -0.5/kCM2MC*Dz(); // default value.
269 // RS: to check: why we don't do strict check for [0:n)
270 if(ix<0 || ix>=fNRow) return; // outside of detector
271 if(iz<0 || iz>=fNCol) return; // outside of detctor
272 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
273 z += Col2Z(iz)*(1./kCM2MC);
274 return; // Found x and z, return.
277 //______________________________________________________________________
278 void AliITSsegmentationPixUpg::CellBoundries(Int_t ix,Int_t iz,Double_t &xl,Double_t &xu,Double_t &zl,Double_t &zu) const
280 // Transformation from Detector cell coordiantes to Geant detector centerd
281 // local coordinates (cm).
283 // Int_t ix detector x cell coordinate. Has the range 0<=ix<fNRow.
284 // Int_t iz detector z cell coordinate. Has the range 0<=iz<fNCol.
286 // Double_t xl detector local coordinate cell lower bounds x in cm
287 // with respect to the center of the sensitive volume.
288 // Double_t xu detector local coordinate cell upper bounds x in cm
289 // with respect to the center of the sensitive volume.
290 // Double_t zl detector local coordinate lower bounds z in cm with
291 // respect to the center of the sensitive volulme.
292 // Double_t zu detector local coordinate upper bounds z in cm with
293 // respect to the center of the sensitive volulme.
294 // If ix and or iz is outside of the segmentation range a value of -0.5*Dx()
295 // and -0.5*Dx() or -0.5*Dz() and -0.5*Dz() are returned.
297 DetToLocal(ix,iz,x,z);
299 if( ix<0 || ix>=fNRow || iz<0 || iz>=fNCol) {
300 xl = xu = -0.5/kCM2MC*Dx(); // default value.
301 zl = zu = -0.5/kCM2MC*Dz(); // default value.
302 return; // outside of detctor
304 float zpitchH = Dpz(iz)/2./kCM2MC;
305 float xpitchH = fPitchX/2./kCM2MC;
310 return; // Found x and z, return.
313 //______________________________________________________________________
314 Int_t AliITSsegmentationPixUpg::GetChipFromChannel(Int_t, Int_t iz) const
316 // returns chip number (in range 0-4) starting from channel number
317 if(iz>=fNCol || iz<0 ){
318 AliWarning("Bad cell number");
321 return iz/fNColPerChip;
324 //______________________________________________________________________
325 Int_t AliITSsegmentationPixUpg::GetChipFromLocal(Float_t, Float_t zloc) const
327 // returns chip number (in range 0-4) starting from local coordinates
329 if (!LocalToDet(0,zloc,ix0,iz)) {
330 AliWarning("Bad local coordinate");
333 return GetChipFromChannel(ix0,iz);
336 //______________________________________________________________________
337 Int_t AliITSsegmentationPixUpg::GetChipsInLocalWindow(Int_t* array, Float_t zmin, Float_t zmax, Float_t, Float_t) const
339 // returns the number of chips containing a road defined by given local coordinate limits
341 const Float_t kconv = 1./kCM2MC; // converts microns to cm.
344 AliWarning("Bad coordinate limits: zmin>zmax!");
350 Float_t zminDet = -0.5*kconv*Dz();
351 Float_t zmaxDet = 0.5*kconv*Dz();
352 if(zmin<zminDet) zmin=zminDet;
353 if(zmax>zmaxDet) zmax=zmaxDet;
355 Int_t n1 = GetChipFromLocal(0,zmin);
356 array[nChipInW] = n1;
359 Int_t n2 = GetChipFromLocal(0,zmax);
362 Int_t imin=TMath::Min(n1,n2);
363 Int_t imax=TMath::Max(n1,n2);
364 for(Int_t ichip=imin; ichip<=imax; ichip++){
365 if(ichip==n1) continue;
366 array[nChipInW]=ichip;
374 //______________________________________________________________________
375 void AliITSsegmentationPixUpg::Init()
380 //______________________________________________________________________
381 Bool_t AliITSsegmentationPixUpg::StoreWithID(UInt_t id, const char* outf)
383 // store in the special list under given ID
385 gSystem->ExpandPathName(fns);
386 if (fns.IsNull()) {AliFatal("No file name provided"); return kFALSE;}
387 TFile* fout = TFile::Open(fns.Data(),"update");
388 if (!fout) {AliFatal(Form("Failed to open output file %s",outf)); return kFALSE;}
389 TObjArray* arr = (TObjArray*)fout->Get(fgkSegmListName);
390 if (!arr) arr = new TObjArray();
392 int nent = arr->GetEntriesFast();
393 for (int i=nent;i--;) {
394 AliITSsegmentationPixUpg* segm = dynamic_cast<AliITSsegmentationPixUpg*>(arr->At(i));
395 if (segm && segm->GetUniqueID()==id) {
396 AliFatal(Form("Segmenation %d already exists in file %s",id,outf));
402 this->SetUniqueID(id);
404 arr->SetOwner(kTRUE);
405 fout->WriteObject(arr,fgkSegmListName,"kSingleKey");
410 AliInfo(Form("Stored segmentation %d in %s",id,outf));
415 //______________________________________________________________________
416 AliITSsegmentationPixUpg* AliITSsegmentationPixUpg::LoadWithID(UInt_t id, const char* inpf)
418 // store in the special list under given ID
420 gSystem->ExpandPathName(fns);
421 if (fns.IsNull()) {AliFatalGeneral("LoadWithID","No file name provided"); return 0;}
422 TFile* finp = TFile::Open(fns.Data());
423 if (!finp) {AliFatalGeneral("LoadWithID",Form("Failed to open file %s",inpf)); return 0;}
424 TObjArray* arr = (TObjArray*)finp->Get(fgkSegmListName);
426 AliFatalGeneral("LoadWithID",Form("Failed to find segmenation array %s in %s",fgkSegmListName,inpf));
429 AliITSsegmentationPixUpg* segm = 0;
430 int nent = arr->GetEntriesFast();
431 for (int i=nent;i--;) {
432 segm = dynamic_cast<AliITSsegmentationPixUpg*>(arr->At(i));
433 if (segm && segm->GetUniqueID()==id) {arr->RemoveAt(i); break;}
437 if (!segm) {AliFatalGeneral("LoadWithID",Form("Failed to find segmenation %d in %s",id,inpf)); return 0;}
439 arr->SetOwner(kTRUE); // to not leave in memory other segmenations