]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSPlaneEffSPD.cxx
AliITSv11GeometrySPD has added missing parts, set up to help with
[u/mrichter/AliRoot.git] / ITS / AliITSPlaneEffSPD.cxx
CommitLineData
4a66240a 1/**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15///////////////////////////////////////////////////////////////////////////
16// Plane Efficiency class for ITS
17// It is used for chip by chip efficiency of the SPD,
18// evaluated by tracks
19// (Inherits from AliITSPlaneEff)
20// Author: G.E. Bruno
21// giuseppe.bruno@ba.infn.it
22//
23///////////////////////////////////////////////////////////////////////////
24
25/* $Id$ */
26
6344adcc 27#include <TMath.h>
4a66240a 28#include "AliITSPlaneEffSPD.h"
29#include "AliLog.h"
30#include "AliCDBStorage.h"
31#include "AliCDBEntry.h"
32#include "AliCDBManager.h"
33//#include "AliCDBRunRange.h"
7167ae53 34//#include "AliITSsegmentationSPD.h"
4a66240a 35#include "AliITSCalibrationSPD.h"
36
37ClassImp(AliITSPlaneEffSPD)
38//______________________________________________________________________
39AliITSPlaneEffSPD::AliITSPlaneEffSPD():
40 AliITSPlaneEff(){
41// for (UInt_t im=0; im<kNModule; im++){
42// for (UInt_t ic=0; ic<kNChip; ic++){
43// fFound[im][ic]=0;
44// fTried[im][ic]=0;
45// }}
46 for (UInt_t i=0; i<kNModule*kNChip; i++){
47 fFound[i]=0;
48 fTried[i]=0;
49 }
50 // default constructor
51 AliDebug(1,Form("Calling default constructor"));
52}
53//______________________________________________________________________
54AliITSPlaneEffSPD::~AliITSPlaneEffSPD(){
55 // destructor
56 // Inputs:
57 // none.
58 // Outputs:
59 // none.
60 // Return:
61 // none.
62}
63//______________________________________________________________________
64AliITSPlaneEffSPD::AliITSPlaneEffSPD(const AliITSPlaneEffSPD &s) : AliITSPlaneEff(s) //,
65//fHis(s.fHis),
66{
67 // Copy Constructor
68 // Inputs:
69 // AliITSPlaneEffSPD &s The original class for which
70 // this class is a copy of
71 // Outputs:
72 // none.
73 // Return:
74
75}
76//_________________________________________________________________________
77AliITSPlaneEffSPD& AliITSPlaneEffSPD::operator+=(const AliITSPlaneEffSPD &add){
78 // Add-to-me operator
79 // Inputs:
80 // const AliITSPlaneEffSPD &add simulation class to be added
81 // Outputs:
82 // none.
83 // Return:
84 // none
85 for (UInt_t i=0; i<kNModule*kNChip; i++){
86 fFound[i] += add.fFound[i];
87 fTried[i] += add.fTried[i];
88 }
89 return *this;
90}
91//______________________________________________________________________
92AliITSPlaneEffSPD& AliITSPlaneEffSPD::operator=(const
93 AliITSPlaneEffSPD &s){
94 // Assignment operator
95 // Inputs:
96 // AliITSPlaneEffSPD &s The original class for which
97 // this class is a copy of
98 // Outputs:
99 // none.
100 // Return:
101
102 if(this==&s) return *this;
103 s.Copy(*this);
104// if(&s == this) return *this;
105// for (UInt_t i=0; i<kNModule*kNChip; i++){
106// this->fFound[i] = s.fFound[i];
107// this->fTried[i] = s.fTried[i];
108// }
109 return *this;
110}
111//______________________________________________________________________
112void AliITSPlaneEffSPD::Copy(TObject &obj) const {
113 // protected method. copy this to obj
114 AliITSPlaneEff::Copy(obj);
115 //((AliITSPlaneEffSPD& ) obj).fNpx = fNpx;
116 for(Int_t i=0;i<kNModule*kNChip;i++) {
117 ((AliITSPlaneEffSPD& ) obj).fFound[i] = fFound[i];
118 ((AliITSPlaneEffSPD& ) obj).fTried[i] = fTried[i];
119 }
120}
121//______________________________________________________________________
122AliITSPlaneEff& AliITSPlaneEffSPD::operator=(const
123 AliITSPlaneEff &s){
124 // Assignment operator
125 // Inputs:
126 // AliITSPlaneEffSPD &s The original class for which
127 // this class is a copy of
128 // Outputs:
129 // none.
130 // Return:
131
132 if(&s == this) return *this;
7167ae53 133 AliError("operator=: Not allowed to make a =, use default creater instead");
4a66240a 134 return *this;
135}
136//_______________________________________________________________________
137Int_t AliITSPlaneEffSPD::GetMissingTracksForGivenEff(Double_t eff, Double_t RelErr,
138 UInt_t im, UInt_t ic) const {
139
140 // Estimate the number of tracks still to be collected to attain a
141 // given efficiency eff, with relative error RelErr
142 // Inputs:
143 // eff -> Expected efficiency (e.g. those from actual estimate)
144 // RelErr -> tollerance [0,1]
145 // im -> module number [0,249]
6344adcc 146 // ic -> chip number [0,4]
4a66240a 147 // Outputs: none
148 // Return: the estimated n. of tracks
149 //
150if (im>=kNModule || ic>=kNChip)
7167ae53 151 {AliError("GetMissingTracksForGivenEff: you asked for a non existing chip");
4a66240a 152 return -1;}
153else return GetNTracksForGivenEff(eff,RelErr)-fTried[GetKey(im,ic)];
154}
155//_________________________________________________________________________
156Double_t AliITSPlaneEffSPD::PlaneEff(const UInt_t im,const UInt_t ic) const {
157// Compute the efficiency for a basic block,
158// Inputs:
6344adcc 159// im -> module number [0,249]
160// ic -> chip number [0,4]
4a66240a 161if (im>=kNModule || ic>=kNChip)
7167ae53 162 {AliError("PlaneEff(Uint_t,Uint_t): you asked for a non existing chip"); return -1.;}
4a66240a 163 Int_t nf=fFound[GetKey(im,ic)];
164 Int_t nt=fTried[GetKey(im,ic)];
165return AliITSPlaneEff::PlaneEff(nf,nt);
166}
167//_________________________________________________________________________
168Double_t AliITSPlaneEffSPD::ErrPlaneEff(const UInt_t im,const UInt_t ic) const {
169 // Compute the statistical error on efficiency for a basic block,
170 // using binomial statistics
171 // Inputs:
6344adcc 172 // im -> module number [0,249]
173 // ic -> chip number [0,4]
4a66240a 174if (im>=kNModule || ic>=kNChip)
7167ae53 175 {AliError("ErrPlaneEff(Uint_t,Uint_t): you asked for a non existing chip"); return -1.;}
4a66240a 176Int_t nf=fFound[GetKey(im,ic)];
177Int_t nt=fTried[GetKey(im,ic)];
178return AliITSPlaneEff::ErrPlaneEff(nf,nt);
179}
180//_________________________________________________________________________
181Bool_t AliITSPlaneEffSPD::UpDatePlaneEff(const Bool_t Kfound,
182 const UInt_t im, const UInt_t ic) {
183 // Update efficiency for a basic block
184if (im>=kNModule || ic>=kNChip)
7167ae53 185 {AliError("UpDatePlaneEff: you asked for a non existing chip"); return kFALSE;}
4a66240a 186 fTried[GetKey(im,ic)]++;
187 if(Kfound) fFound[GetKey(im,ic)]++;
188 return kTRUE;
189}
190//_________________________________________________________________________
6344adcc 191UInt_t AliITSPlaneEffSPD::GetChipFromCol(const UInt_t col) const {
4a66240a 192 // get chip given the column
193if(col>=kNCol*kNChip)
7167ae53 194 {AliDebug(1,Form("GetChipFromCol: you asked for a non existing column %d",col)); return 10;}
4a66240a 195return col/kNCol;
196}
197//__________________________________________________________________________
198UInt_t AliITSPlaneEffSPD::GetKey(const UInt_t mod, const UInt_t chip) const {
199 // get key given a basic block
200if(mod>=kNModule || chip>=kNChip)
7167ae53 201 {AliWarning("GetKey: you asked for a non existing block"); return 99999;}
4a66240a 202return mod*kNChip+chip;
203}
204//__________________________________________________________________________
205UInt_t AliITSPlaneEffSPD::GetModFromKey(const UInt_t key) const {
206 // get mod. from key
207if(key>=kNModule*kNChip)
7167ae53 208 {AliError("GetModFromKey: you asked for a non existing key"); return 9999;}
4a66240a 209return key/kNChip;
210}
211//__________________________________________________________________________
212UInt_t AliITSPlaneEffSPD::GetChipFromKey(const UInt_t key) const {
213 // retrieves chip from key
214if(key>=kNModule*kNChip)
7167ae53 215 {AliError("GetChipFromKey: you asked for a non existing key"); return 999;}
4a66240a 216return (key%(kNModule*kNChip))%kNChip;
217}
218//__________________________________________________________________________
219void AliITSPlaneEffSPD::GetModAndChipFromKey(const UInt_t key,UInt_t& mod,UInt_t& chip) const {
220 // get module and chip from a key
221if(key>=kNModule*kNChip)
7167ae53 222 {AliError("GetModAndChipFromKey: you asked for a non existing key");
4a66240a 223 mod=9999;
224 chip=999;
225 return;}
226mod=key/kNChip;
227chip=(key%(kNModule*kNChip))%kNChip;
228return;
229}
230//____________________________________________________________________________
231Double_t AliITSPlaneEffSPD::LivePlaneEff(UInt_t key) const {
6344adcc 232 // returns plane efficieny after adding the fraction of sensor which is bad
4a66240a 233if(key>=kNModule*kNChip)
7167ae53 234 {AliError("LivePlaneEff: you asked for a non existing key");
4a66240a 235 return -1.;}
6344adcc 236Double_t leff=AliITSPlaneEff::LivePlaneEff(0); // this just for the Warning
237leff=PlaneEff(key)+GetFracBad(key);
238return leff>1?1:leff;
4a66240a 239}
240//____________________________________________________________________________
241Double_t AliITSPlaneEffSPD::ErrLivePlaneEff(UInt_t key) const {
242 // returns error on live plane efficiency
243if(key>=kNModule*kNChip)
7167ae53 244 {AliError("ErrLivePlaneEff: you asked for a non existing key");
4a66240a 245 return -1.;}
6344adcc 246Int_t nf=fFound[key];
247Double_t triedInLive=GetFracLive(key)*fTried[key];
248Int_t nt=TMath::Max(nf,TMath::Nint(triedInLive));
249return AliITSPlaneEff::ErrPlaneEff(nf,nt); // for the time being: to be checked
4a66240a 250}
251//_____________________________________________________________________________
252Double_t AliITSPlaneEffSPD::GetFracLive(const UInt_t key) const {
253 // returns the fraction of the sensor which is OK
254if(key>=kNModule*kNChip)
7167ae53 255 {AliError("GetFracLive: you asked for a non existing key");
4a66240a 256 return -1.;}
257 // Compute the fraction of bad (dead+noisy) detector
258UInt_t dead=0,noisy=0;
259GetDeadAndNoisyInChip(key,dead,noisy);
260Double_t live=dead+noisy;
261live/=(kNRow*kNCol);
262return 1.-live;
263}
264//_____________________________________________________________________________
265void AliITSPlaneEffSPD::GetDeadAndNoisyInChip(const UInt_t key,
266 UInt_t& nrDeadInChip, UInt_t& nrNoisyInChip) const {
267 // returns the number of dead and noisy pixels
268nrDeadInChip=0;
269nrNoisyInChip=0;
270if(key>=kNModule*kNChip)
7167ae53 271 {AliError("GetDeadAndNoisyInChip: you asked for a non existing key");
4a66240a 272 return;}
273 // Compute the number of bad (dead+noisy) pixel in a chip
274//
275if(!fInitCDBCalled)
7167ae53 276 {AliError("GetDeadAndNoisyInChip: CDB not inizialized: call InitCDB first");
4a66240a 277 return;};
278AliCDBManager* man = AliCDBManager::Instance();
279// retrieve map of dead Pixel
280AliCDBEntry *cdbSPDDead = man->Get("ITS/Calib/SPDDead", fRunNumber);
281TObjArray* spdDead;
282if(cdbSPDDead) {
283 spdDead = (TObjArray*)cdbSPDDead->GetObject();
284 if(!spdDead)
7167ae53 285 {AliError("GetDeadAndNoisyInChip: SPDDead not found in CDB");
4a66240a 286 return;}
287} else {
7167ae53 288 AliError("GetDeadAndNoisyInChip: did not find Calib/SPDDead.");
4a66240a 289 return;
290}
291// retrieve map of noisy Pixel
292AliCDBEntry *cdbSPDNoisy = man->Get("ITS/Calib/SPDNoisy", fRunNumber);
293TObjArray* spdNoisy;
294if(cdbSPDNoisy) {
295 spdNoisy = (TObjArray*)cdbSPDNoisy->GetObject();
296 if(!spdNoisy)
7167ae53 297 {AliError("GetDeadAndNoisyInChip: SPDNoisy not found in CDB");
4a66240a 298 return;}
299} else {
7167ae53 300 AliError("GetDeadAndNoisyInChip: did not find Calib/SPDNoisy.");
4a66240a 301 return;
302}
303//
304UInt_t mod=GetModFromKey(key);
305UInt_t chip=GetChipFromKey(key);
306// count number of dead
307AliITSCalibrationSPD* calibSPD=(AliITSCalibrationSPD*) spdDead->At(mod);
308UInt_t nrDead = calibSPD->GetNrBad();
309for (UInt_t index=0; index<nrDead; index++) {
6344adcc 310 if(GetChipFromCol(calibSPD->GetBadColAt(index))==chip) nrDeadInChip++;
4a66240a 311}
312calibSPD=(AliITSCalibrationSPD*) spdNoisy->At(mod);
313UInt_t nrNoisy = calibSPD->GetNrBad();
314for (UInt_t index=0; index<nrNoisy; index++) {
6344adcc 315 if(GetChipFromCol(calibSPD->GetBadColAt(index))==chip) nrNoisyInChip++;
4a66240a 316}
317return;
318}
319//_____________________________________________________________________________
320Double_t AliITSPlaneEffSPD::GetFracBad(const UInt_t key) const {
321 // returns 1-fractional live
322if(key>=kNModule*kNChip)
7167ae53 323 {AliError("GetFracBad: you asked for a non existing key");
4a66240a 324 return -1.;}
325return 1.-GetFracLive(key);
326}
327//_____________________________________________________________________________
328Bool_t AliITSPlaneEffSPD::WriteIntoCDB() const {
329// write onto CDB
330if(!fInitCDBCalled)
7167ae53 331 {AliError("WriteIntoCDB: CDB not inizialized. Call InitCDB first");
4a66240a 332 return kFALSE;}
333// to be written properly: now only for debugging
334 AliCDBMetaData *md= new AliCDBMetaData(); // metaData describing the object
335 md->SetObjectClassName("AliITSPlaneEff");
336 md->SetResponsible("Giuseppe Eugenio Bruno");
337 md->SetBeamPeriod(0);
338 md->SetAliRootVersion("head 19/11/07"); //root version
339 AliCDBId id("ITS/PlaneEff/PlaneEffSPD",0,AliCDBRunRange::Infinity());
340 AliITSPlaneEffSPD eff;
341 eff=*this;
342 Bool_t r=AliCDBManager::Instance()->GetDefaultStorage()->Put(&eff,id,md);
343 delete md;
344 return r;
345}
346//_____________________________________________________________________________
347Bool_t AliITSPlaneEffSPD::ReadFromCDB() {
348// read from CDB
349if(!fInitCDBCalled)
7167ae53 350 {AliError("ReadFromCDB: CDB not inizialized. Call InitCDB first");
4a66240a 351 return kFALSE;}
352//if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
353// AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
354// }
355AliCDBEntry *cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSPD",fRunNumber);
356AliITSPlaneEffSPD* eff= (AliITSPlaneEffSPD*)cdbEntry->GetObject();
357if(this==eff) return kFALSE;
358eff->Copy(*this);
359return kTRUE;
360}
7167ae53 361//_____________________________________________________________________________
362UInt_t AliITSPlaneEffSPD::GetKeyFromDetLocCoord(Int_t ilay, Int_t idet,
363 Float_t, Float_t locz) const {
364// method to locate a basic block from Detector Local coordinate (to be used in tracking)
365UInt_t key=999999;
366if(ilay<0 || ilay>1)
367 {AliError("GetKeyFromDetLocCoord: you asked for a non existing layer");
368 return key;}
369if(ilay==0 && (idet<0 || idet>79))
370 {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
371 return key;}
372if(ilay==1 && (idet<0 || idet>159))
373 {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
374 return key;}
375
376UInt_t mod=idet;
377if(ilay==1) mod+=80;
378key=GetKey(mod,GetChipFromCol(GetColFromLocZ(locz)));
379return key;
380}
381//_____________________________________________________________________________
382UInt_t AliITSPlaneEffSPD::GetColFromLocZ(Float_t zloc) const {
383UInt_t col=0;
384/* note: as it is now, the AliITSsegmentationSPD::Init() does not properly initialize (6 chips !!!)
385AliITSsegmentationSPD spd;
386spd.Init();
387Int_t ix,iz;
388if(spd.LocalToDet(0,zloc,ix,iz)) col+=iz;
389else {
390 AliError("GetColFromLocZ: cannot compute column number from local z");
391 col=99999;}
392return col;
393*/
394const Float_t kconv = 1.0E-04; // converts microns to cm.
395Float_t bz[160];
396for(Int_t i=000;i<160;i++) bz[i] = 425.0; // most are 425 microns except below
397bz[ 31] = bz[ 32] = 625.0; // first chip boundry
398bz[ 63] = bz[ 64] = 625.0; // first chip boundry
399bz[ 95] = bz[ 96] = 625.0; // first chip boundry
400bz[127] = bz[128] = 625.0; // first chip boundry
401//
402Int_t j=-1;
403Float_t dz=0;
404for(Int_t i=000;i<160;i++) dz+=bz[i];
405dz = -0.5*kconv*dz;
406if(zloc<dz || zloc>-1*dz) { // outside z range
407 AliDebug(1,Form("GetColFromLocZ: cannot compute column number from local z=%f",zloc));
408 return 99999;}
409for(j=0;j<160;j++){
410 dz += kconv*bz[j];
411 if(zloc<dz) break;
412} // end for j
413col+=j;
414//
415return col;
416}
417//________________________________________________________