]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSPlaneEffSDD.cxx
Plane efficiency for SDD and SSD. Minor modifications for SPD (G. Bruno)
[u/mrichter/AliRoot.git] / ITS / AliITSPlaneEffSDD.cxx
CommitLineData
6344adcc 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 (eventually with subwing division
18// along the drift direction ) of the SDD,
19// evaluated by tracks
20// (Inherits from AliITSPlaneEff)
21// Author: G.E. Bruno
22// giuseppe.bruno@ba.infn.it
23//
24///////////////////////////////////////////////////////////////////////////
25
26/* $Id$ */
27
28#include <TMath.h>
29#include "AliITSPlaneEffSDD.h"
30#include "AliLog.h"
31#include "AliCDBStorage.h"
32#include "AliCDBEntry.h"
33#include "AliCDBManager.h"
34//#include "AliCDBRunRange.h"
35#include "AliITSCalibrationSDD.h"
36
37ClassImp(AliITSPlaneEffSDD)
38//______________________________________________________________________
39AliITSPlaneEffSDD::AliITSPlaneEffSDD():
40 AliITSPlaneEff(){
41 // Default constructor
42 for (UInt_t i=0; i<kNModule*kNChip*kNWing*kNSubWing; i++){
43 fFound[i]=0;
44 fTried[i]=0;
45 }
46 // default constructor
47 AliDebug(1,Form("Calling default constructor"));
48}
49//______________________________________________________________________
50AliITSPlaneEffSDD::~AliITSPlaneEffSDD(){
51 // destructor
52 // Inputs:
53 // none.
54 // Outputs:
55 // none.
56 // Return:
57 // none.
58}
59//______________________________________________________________________
60AliITSPlaneEffSDD::AliITSPlaneEffSDD(const AliITSPlaneEffSDD &s) : AliITSPlaneEff(s) //,
61//fHis(s.fHis),
62{
63 // Copy Constructor
64 // Inputs:
65 // AliITSPlaneEffSDD &s The original class for which
66 // this class is a copy of
67 // Outputs:
68 // none.
69 // Return:
70
71}
72//_________________________________________________________________________
73AliITSPlaneEffSDD& AliITSPlaneEffSDD::operator+=(const AliITSPlaneEffSDD &add){
74 // Add-to-me operator
75 // Inputs:
76 // const AliITSPlaneEffSDD &add simulation class to be added
77 // Outputs:
78 // none.
79 // Return:
80 // none
81 for (UInt_t i=0; i<kNModule*kNChip*kNWing*kNSubWing; i++){
82 fFound[i] += add.fFound[i];
83 fTried[i] += add.fTried[i];
84 }
85 return *this;
86}
87//______________________________________________________________________
88AliITSPlaneEffSDD& AliITSPlaneEffSDD::operator=(const
89 AliITSPlaneEffSDD &s){
90 // Assignment operator
91 // Inputs:
92 // AliITSPlaneEffSDD &s The original class for which
93 // this class is a copy of
94 // Outputs:
95 // none.
96 // Return:
97
98 if(this==&s) return *this;
99 s.Copy(*this);
100// if(&s == this) return *this;
101// for (UInt_t i=0; i<kNModule*kNChip*kNWing*kNSubWing; i++){
102// this->fFound[i] = s.fFound[i];
103// this->fTried[i] = s.fTried[i];
104// }
105 return *this;
106}
107//______________________________________________________________________
108void AliITSPlaneEffSDD::Copy(TObject &obj) const {
109 // protected method. copy this to obj
110 AliITSPlaneEff::Copy(obj);
111 for(Int_t i=0;i<kNModule*kNChip*kNWing*kNSubWing;i++) {
112 ((AliITSPlaneEffSDD& ) obj).fFound[i] = fFound[i];
113 ((AliITSPlaneEffSDD& ) obj).fTried[i] = fTried[i];
114 }
115}
116//______________________________________________________________________
117AliITSPlaneEff& AliITSPlaneEffSDD::operator=(const
118 AliITSPlaneEff &s){
119 // Assignment operator
120 // Inputs:
121 // AliITSPlaneEffSDD &s The original class for which
122 // this class is a copy of
123 // Outputs:
124 // none.
125 // Return:
126
127 if(&s == this) return *this;
128 Error("AliITSPlaneEffSDD","Not allowed to make a = with "
129 "AliITSPlaneEffSDD","Using default creater instead");
130
131 return *this;
132}
133//_______________________________________________________________________
134Int_t AliITSPlaneEffSDD::GetMissingTracksForGivenEff(Double_t eff, Double_t RelErr,
135 UInt_t im, UInt_t ic, UInt_t iw, UInt_t is) const {
136
137 // Estimate the number of tracks still to be collected to attain a
138 // given efficiency eff, with relative error RelErr
139 // Inputs:
140 // eff -> Expected efficiency (e.g. those from actual estimate)
141 // RelErr -> tollerance [0,1]
142 // im -> module number [0,259]
143 // ic -> chip number [0,3]
144 // iw -> wing number [0,1]
145 // is -> chip number [0,kNSubWing-1]
146 // Outputs: none
147 // Return: the estimated n. of tracks
148 //
149if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
150 {Error("AliITSPlaneEffSDD","you asked for a non existing block");
151 return -1;}
152else return GetNTracksForGivenEff(eff,RelErr)-fTried[GetKey(im,ic,iw,is)];
153}
154//_________________________________________________________________________
155Double_t AliITSPlaneEffSDD::PlaneEff(const UInt_t im,const UInt_t ic,
156 const UInt_t iw,const UInt_t is) const {
157// Compute the efficiency for a basic block,
158// Inputs:
159// im -> module number [0,259]
160// ic -> chip number [0,3]
161// iw -> wing number [0,1]
162// is -> chip number [0,kNSubWing-1]
163if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
164 {Error("AliITSPlaneEffSDD","you asked for a non existing block"); return -1.;}
165 Int_t nf=fFound[GetKey(im,ic,iw,is)];
166 Int_t nt=fTried[GetKey(im,ic,iw,is)];
167return AliITSPlaneEff::PlaneEff(nf,nt);
168}
169//_________________________________________________________________________
170Double_t AliITSPlaneEffSDD::ErrPlaneEff(const UInt_t im,const UInt_t ic,
171 const UInt_t iw,const UInt_t is) const {
172 // Compute the statistical error on efficiency for a basic block,
173 // using binomial statistics
174 // Inputs:
175 // im -> module number [0,259]
176 // ic -> chip number [0,3]
177 // iw -> wing number [0,1]
178 // is -> chip number [0,kNSubWing-1]
179if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
180 {Error("AliITSPlaneEffSDD","you asked for a non existing block"); return -1.;}
181Int_t nf=fFound[GetKey(im,ic,iw,is)];
182Int_t nt=fTried[GetKey(im,ic,iw,is)];
183return AliITSPlaneEff::ErrPlaneEff(nf,nt);
184}
185//_________________________________________________________________________
186Bool_t AliITSPlaneEffSDD::UpDatePlaneEff(const Bool_t Kfound,
187 const UInt_t im, const UInt_t ic,
188 const UInt_t iw, const UInt_t is) {
189 // Update efficiency for a basic block
190if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
191 {Error("AliITSPlaneEffSDD","you asked for a non existing block"); return kFALSE;}
192 fTried[GetKey(im,ic,iw,is)]++;
193 if(Kfound) fFound[GetKey(im,ic,iw,is)]++;
194 return kTRUE;
195}
196//_________________________________________________________________________
197void AliITSPlaneEffSDD::ChipAndWingFromAnode(const UInt_t anode, UInt_t& chip,
198 UInt_t& wing) const {
199 // Retun the chip number [0,3] and the wing number [0,1] given the anode number
200 // input: anode number [0,511]
201if(anode>=kNAnode*kNChip*kNWing)
202 {Error("AliITSPlaneEffSDD::ChipAndWingFromAnode","you asked for a non existing anode");
203 chip=999;
204 wing=99;
205 return;}
206wing=0;
207chip=anode/kNAnode;
208if(anode>=kNChip*kNAnode) wing=1;
209if(wing==1) chip-=kNChip;
210return;
211}
212//_________________________________________________________________________
213UInt_t AliITSPlaneEffSDD::ChipFromAnode(const UInt_t anode) const {
214 // Retun the chip number [0,3] given the anode number
215 // input: anode number [0,511]
216if(anode>=kNAnode*kNChip*kNWing)
217 {Error("AliITSPlaneEffSDD::ChipFromAnode","you asked for a non existing anode"); return 999;}
218Int_t wing=0;
219Int_t chip=anode/kNAnode;
220if(anode>=kNChip*kNAnode) wing=1;
221if(wing==1)chip-=kNChip;
222return chip;
223}
224//_________________________________________________________________________
225UInt_t AliITSPlaneEffSDD::WingFromAnode(const UInt_t anode) const {
226 // return the wing number [0,1] given the anode number
227 // input: anode number [0,511]
228if(anode>=kNAnode*kNChip*kNWing)
229 {Error("AliITSPlaneEffSDD::GetWingFromAnode","you asked for a non existing anode"); return 99;}
230Int_t wing=0;
231if(anode>=kNChip*kNAnode) wing=1;
232return wing;
233}
234//__________________________________________________________________________
235UInt_t AliITSPlaneEffSDD::GetKey(const UInt_t mod, const UInt_t chip,
236 const UInt_t wing, const UInt_t subw) const {
237 // get key given a basic block
238if(mod>=kNModule || chip>=kNChip || wing>= kNWing || subw>=kNSubWing)
239 {Error("AliITSPlaneEffSDD::GetKey","you asked for a non existing block"); return 99999;}
240return mod*kNChip*kNWing*kNSubWing+chip*kNWing*kNSubWing+wing*kNSubWing+subw;
241}
242//__________________________________________________________________________
243UInt_t AliITSPlaneEffSDD::GetModFromKey(const UInt_t key) const {
244 // get mod. from key
245if(key>=kNModule*kNChip*kNWing*kNSubWing)
246 {Error("AliITSPlaneEffSDD::GetModFromKey","you asked for a non existing key"); return 9999;}
247return key/(kNChip*kNWing*kNSubWing);
248}
249//__________________________________________________________________________
250UInt_t AliITSPlaneEffSDD::GetChipFromKey(const UInt_t key) const {
251 // retrieves chip from key
252if(key>=kNModule*kNChip*kNWing*kNSubWing)
253 {Error("AliITSPlaneEffSDD::GetChipFromKey","you asked for a non existing key"); return 999;}
254return (key%(kNChip*kNWing*kNSubWing))/(kNWing*kNSubWing);
255}
256//__________________________________________________________________________
257UInt_t AliITSPlaneEffSDD::GetWingFromKey(const UInt_t key) const {
258 // retrieves wing from key
259if(key>=kNModule*kNChip*kNWing*kNSubWing)
260 {Error("AliITSPlaneEffSDD::GetWingFromKey","you asked for a non existing key"); return 99;}
261return ((key%(kNChip*kNWing*kNSubWing))%(kNWing*kNSubWing))/(kNSubWing);
262}
263//__________________________________________________________________________
264UInt_t AliITSPlaneEffSDD::GetSubWingFromKey(const UInt_t key) const {
265 // retrieves sub-wing from key
266if(key>=kNModule*kNChip*kNWing*kNSubWing)
267 {Error("AliITSPlaneEffSDD::GetSubWingFromKey","you asked for a non existing key"); return 9;}
268return ((key%(kNChip*kNWing*kNSubWing))%(kNWing*kNSubWing))%(kNSubWing);
269}
270//__________________________________________________________________________
271void AliITSPlaneEffSDD::GetAllFromKey(const UInt_t key,UInt_t& mod,UInt_t& chip,
272 UInt_t& wing,UInt_t& subw) const {
273 // get module, chip, wing and subwing from a key
274if(key>=kNModule*kNChip*kNWing*kNSubWing)
275 {Error("AliITSPlaneEffSDD::GetAllFromKey","you asked for a non existing key");
276 mod=9999;
277 chip=999;
278 wing=99;
279 subw=9;
280 return;}
281mod=GetModFromKey(key);
282chip=GetChipFromKey(key);
283wing=GetWingFromKey(key);
284subw=GetSubWingFromKey(key);
285return;
286}
287//____________________________________________________________________________
288Double_t AliITSPlaneEffSDD::LivePlaneEff(UInt_t key) const {
289 // returns plane efficieny after adding the fraction of sensor which is bad
290if(key>=kNModule*kNChip*kNWing*kNSubWing)
291 {Error("AliITSPlaneEffSDD::LivePlaneEff","you asked for a non existing key");
292 return -1.;}
293Double_t leff=AliITSPlaneEff::LivePlaneEff(0); // this just for the Warning
294leff=PlaneEff(key)+GetFracBad(key);
295return leff>1?1:leff;
296}
297//____________________________________________________________________________
298Double_t AliITSPlaneEffSDD::ErrLivePlaneEff(UInt_t key) const {
299 // returns error on live plane efficiency
300if(key>=kNModule*kNChip*kNWing*kNSubWing)
301 {Error("AliITSPlaneEffSDD::ErrLivePlaneEff","you asked for a non existing key");
302 return -1.;}
303Int_t nf=fFound[key];
304Double_t triedInLive=GetFracLive(key)*fTried[key];
305Int_t nt=TMath::Max(nf,TMath::Nint(triedInLive));
306return AliITSPlaneEff::ErrPlaneEff(nf,nt); // for the time being: to be checked
307}
308//_____________________________________________________________________________
309Double_t AliITSPlaneEffSDD::GetFracLive(const UInt_t key) const {
310 // returns the fraction of the sensor which is OK
311if(key>=kNModule*kNChip*kNWing*kNSubWing)
312 {Error("AliITSPlaneEffSDD::GetFracLive","you asked for a non existing key");
313 return -1.;}
314 // Compute the fraction of bad (dead+noisy) detector
315UInt_t bad=0;
316GetBadInBlock(key,bad);
317Double_t live=bad;
318live/=(kNAnode);
319return 1.-live;
320}
321//_____________________________________________________________________________
322void AliITSPlaneEffSDD::GetBadInBlock(const UInt_t key, UInt_t& nrBadInBlock) const {
323 // Compute the number of bad (dead+noisy) anodes inside a block
324 // (it depends on the chip, not on the sub-wing)
325nrBadInBlock=0;
326if(key>=kNModule*kNChip*kNWing*kNSubWing)
327 {Error("AliITSPlaneEffSDD::GetBadInBlock","you asked for a non existing key");
328 return;}
329//
330if(!fInitCDBCalled)
331 {Error("AliITSPlaneEffSDD::GetBadInBlock","CDB not inizialized: call InitCDB first");
332 return;};
333AliCDBManager* man = AliCDBManager::Instance();
334// retrieve map of dead Pixel
335AliCDBEntry *cdbSDD = man->Get("ITS/Calib/CalibSDD", fRunNumber);
336TObjArray* sddEntry;
337if(cdbSDD) {
338 sddEntry = (TObjArray*)cdbSDD->GetObject();
339 if(!sddEntry)
340 {Error("AliITSPlaneEffSDD::GetBadInBlock"," SDDEntry not found in CDB");
341 return;}
342} else {
343 Error("AliITSPlaneEffSDD::GetBadInBlock","Did not find Calib/CalibSDD");
344 return;
345}
346//
347UInt_t mod=GetModFromKey(key);
348UInt_t chip=GetChipFromKey(key);
349UInt_t wing=GetWingFromKey(key);
350// count number of dead
351AliITSCalibrationSDD* calibSDD=(AliITSCalibrationSDD*) sddEntry->At(mod);
352UInt_t nrBad = calibSDD-> GetDeadChannels();
353for (UInt_t index=0; index<nrBad; index++) {
354 if(ChipFromAnode(calibSDD->GetBadChannel(index))==chip &&
355 WingFromAnode(calibSDD->GetBadChannel(index))==wing ) nrBadInBlock++;
356}
357return;
358}
359//_____________________________________________________________________________
360Double_t AliITSPlaneEffSDD::GetFracBad(const UInt_t key) const {
361 // returns 1-fractional live
362if(key>=kNModule*kNChip*kNWing*kNSubWing)
363 {Error("AliITSPlaneEffSDD::GetFracBad","you asked for a non existing key");
364 return -1.;}
365return 1.-GetFracLive(key);
366}
367//_____________________________________________________________________________
368Bool_t AliITSPlaneEffSDD::WriteIntoCDB() const {
369// write onto CDB
370if(!fInitCDBCalled)
371 {Error("AliITSPlaneEffSDD::WriteIntoCDB","CDB not inizialized: call InitCDB first");
372 return kFALSE;}
373// to be written properly: now only for debugging
374 AliCDBMetaData *md= new AliCDBMetaData(); // metaData describing the object
375 md->SetObjectClassName("AliITSPlaneEff");
376 md->SetResponsible("Giuseppe Eugenio Bruno");
377 md->SetBeamPeriod(0);
378 md->SetAliRootVersion("head 02/01/08"); //root version
379 AliCDBId id("ITS/PlaneEff/PlaneEffSDD",0,AliCDBRunRange::Infinity());
380 AliITSPlaneEffSDD eff;
381 eff=*this;
382 Bool_t r=AliCDBManager::Instance()->GetDefaultStorage()->Put(&eff,id,md);
383 delete md;
384 return r;
385}
386//_____________________________________________________________________________
387Bool_t AliITSPlaneEffSDD::ReadFromCDB() {
388// read from CDB
389if(!fInitCDBCalled)
390 {Error("AliITSPlaneEffSDD::ReadFromCDB","CDB not inizialized: call InitCDB first");
391 return kFALSE;}
392//if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
393// AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
394// }
395AliCDBEntry *cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSDD",fRunNumber);
396AliITSPlaneEffSDD* eff= (AliITSPlaneEffSDD*)cdbEntry->GetObject();
397if(this==eff) return kFALSE;
398eff->Copy(*this);
399return kTRUE;
400}