1 /**************************************************************************
2 * Copyright(c) 2007-2009, 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 **************************************************************************/
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)
22 // giuseppe.bruno@ba.infn.it
24 ///////////////////////////////////////////////////////////////////////////
29 #include "AliITSPlaneEffSDD.h"
31 #include "AliCDBStorage.h"
32 #include "AliCDBEntry.h"
33 #include "AliCDBManager.h"
34 //#include "AliCDBRunRange.h"
35 #include "AliITSCalibrationSDD.h"
37 ClassImp(AliITSPlaneEffSDD)
38 //______________________________________________________________________
39 AliITSPlaneEffSDD::AliITSPlaneEffSDD():
41 // Default constructor
42 for (UInt_t i=0; i<kNModule*kNChip*kNWing*kNSubWing; i++){
46 // default constructor
47 AliDebug(1,Form("Calling default constructor"));
49 //______________________________________________________________________
50 AliITSPlaneEffSDD::~AliITSPlaneEffSDD(){
59 //______________________________________________________________________
60 AliITSPlaneEffSDD::AliITSPlaneEffSDD(const AliITSPlaneEffSDD &s) : AliITSPlaneEff(s) //,
65 // AliITSPlaneEffSDD &s The original class for which
66 // this class is a copy of
72 //_________________________________________________________________________
73 AliITSPlaneEffSDD& AliITSPlaneEffSDD::operator+=(const AliITSPlaneEffSDD &add){
76 // const AliITSPlaneEffSDD &add simulation class to be added
81 for (UInt_t i=0; i<kNModule*kNChip*kNWing*kNSubWing; i++){
82 fFound[i] += add.fFound[i];
83 fTried[i] += add.fTried[i];
87 //______________________________________________________________________
88 AliITSPlaneEffSDD& AliITSPlaneEffSDD::operator=(const
89 AliITSPlaneEffSDD &s){
90 // Assignment operator
92 // AliITSPlaneEffSDD &s The original class for which
93 // this class is a copy of
98 if(this==&s) return *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];
107 //______________________________________________________________________
108 void 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];
116 //______________________________________________________________________
117 AliITSPlaneEff& AliITSPlaneEffSDD::operator=(const
119 // Assignment operator
121 // AliITSPlaneEffSDD &s The original class for which
122 // this class is a copy of
127 if(&s == this) return *this;
128 Error("AliITSPlaneEffSDD","Not allowed to make a = with "
129 "AliITSPlaneEffSDD","Using default creater instead");
133 //_______________________________________________________________________
134 Int_t AliITSPlaneEffSDD::GetMissingTracksForGivenEff(Double_t eff, Double_t RelErr,
135 UInt_t im, UInt_t ic, UInt_t iw, UInt_t is) const {
137 // Estimate the number of tracks still to be collected to attain a
138 // given efficiency eff, with relative error RelErr
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]
147 // Return: the estimated n. of tracks
149 if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
150 {Error("AliITSPlaneEffSDD","you asked for a non existing block");
152 else return GetNTracksForGivenEff(eff,RelErr)-fTried[GetKey(im,ic,iw,is)];
154 //_________________________________________________________________________
155 Double_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,
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]
163 if (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)];
167 return AliITSPlaneEff::PlaneEff(nf,nt);
169 //_________________________________________________________________________
170 Double_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
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]
179 if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
180 {Error("AliITSPlaneEffSDD","you asked for a non existing block"); return -1.;}
181 Int_t nf=fFound[GetKey(im,ic,iw,is)];
182 Int_t nt=fTried[GetKey(im,ic,iw,is)];
183 return AliITSPlaneEff::ErrPlaneEff(nf,nt);
185 //_________________________________________________________________________
186 Bool_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
190 if (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)]++;
196 //_________________________________________________________________________
197 void 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]
201 if(anode>=kNAnode*kNChip*kNWing)
202 {Error("AliITSPlaneEffSDD::ChipAndWingFromAnode","you asked for a non existing anode");
208 if(anode>=kNChip*kNAnode) wing=1;
209 if(wing==1) chip-=kNChip;
212 //_________________________________________________________________________
213 UInt_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]
216 if(anode>=kNAnode*kNChip*kNWing)
217 {Error("AliITSPlaneEffSDD::ChipFromAnode","you asked for a non existing anode"); return 999;}
219 Int_t chip=anode/kNAnode;
220 if(anode>=kNChip*kNAnode) wing=1;
221 if(wing==1)chip-=kNChip;
224 //_________________________________________________________________________
225 UInt_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]
228 if(anode>=kNAnode*kNChip*kNWing)
229 {Error("AliITSPlaneEffSDD::GetWingFromAnode","you asked for a non existing anode"); return 99;}
231 if(anode>=kNChip*kNAnode) wing=1;
234 //__________________________________________________________________________
235 UInt_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
238 if(mod>=kNModule || chip>=kNChip || wing>= kNWing || subw>=kNSubWing)
239 {Error("AliITSPlaneEffSDD::GetKey","you asked for a non existing block"); return 99999;}
240 return mod*kNChip*kNWing*kNSubWing+chip*kNWing*kNSubWing+wing*kNSubWing+subw;
242 //__________________________________________________________________________
243 UInt_t AliITSPlaneEffSDD::GetModFromKey(const UInt_t key) const {
245 if(key>=kNModule*kNChip*kNWing*kNSubWing)
246 {Error("AliITSPlaneEffSDD::GetModFromKey","you asked for a non existing key"); return 9999;}
247 return key/(kNChip*kNWing*kNSubWing);
249 //__________________________________________________________________________
250 UInt_t AliITSPlaneEffSDD::GetChipFromKey(const UInt_t key) const {
251 // retrieves chip from key
252 if(key>=kNModule*kNChip*kNWing*kNSubWing)
253 {Error("AliITSPlaneEffSDD::GetChipFromKey","you asked for a non existing key"); return 999;}
254 return (key%(kNChip*kNWing*kNSubWing))/(kNWing*kNSubWing);
256 //__________________________________________________________________________
257 UInt_t AliITSPlaneEffSDD::GetWingFromKey(const UInt_t key) const {
258 // retrieves wing from key
259 if(key>=kNModule*kNChip*kNWing*kNSubWing)
260 {Error("AliITSPlaneEffSDD::GetWingFromKey","you asked for a non existing key"); return 99;}
261 return ((key%(kNChip*kNWing*kNSubWing))%(kNWing*kNSubWing))/(kNSubWing);
263 //__________________________________________________________________________
264 UInt_t AliITSPlaneEffSDD::GetSubWingFromKey(const UInt_t key) const {
265 // retrieves sub-wing from key
266 if(key>=kNModule*kNChip*kNWing*kNSubWing)
267 {Error("AliITSPlaneEffSDD::GetSubWingFromKey","you asked for a non existing key"); return 9;}
268 return ((key%(kNChip*kNWing*kNSubWing))%(kNWing*kNSubWing))%(kNSubWing);
270 //__________________________________________________________________________
271 void 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
274 if(key>=kNModule*kNChip*kNWing*kNSubWing)
275 {Error("AliITSPlaneEffSDD::GetAllFromKey","you asked for a non existing key");
281 mod=GetModFromKey(key);
282 chip=GetChipFromKey(key);
283 wing=GetWingFromKey(key);
284 subw=GetSubWingFromKey(key);
287 //____________________________________________________________________________
288 Double_t AliITSPlaneEffSDD::LivePlaneEff(UInt_t key) const {
289 // returns plane efficieny after adding the fraction of sensor which is bad
290 if(key>=kNModule*kNChip*kNWing*kNSubWing)
291 {Error("AliITSPlaneEffSDD::LivePlaneEff","you asked for a non existing key");
293 Double_t leff=AliITSPlaneEff::LivePlaneEff(0); // this just for the Warning
294 leff=PlaneEff(key)+GetFracBad(key);
295 return leff>1?1:leff;
297 //____________________________________________________________________________
298 Double_t AliITSPlaneEffSDD::ErrLivePlaneEff(UInt_t key) const {
299 // returns error on live plane efficiency
300 if(key>=kNModule*kNChip*kNWing*kNSubWing)
301 {Error("AliITSPlaneEffSDD::ErrLivePlaneEff","you asked for a non existing key");
303 Int_t nf=fFound[key];
304 Double_t triedInLive=GetFracLive(key)*fTried[key];
305 Int_t nt=TMath::Max(nf,TMath::Nint(triedInLive));
306 return AliITSPlaneEff::ErrPlaneEff(nf,nt); // for the time being: to be checked
308 //_____________________________________________________________________________
309 Double_t AliITSPlaneEffSDD::GetFracLive(const UInt_t key) const {
310 // returns the fraction of the sensor which is OK
311 if(key>=kNModule*kNChip*kNWing*kNSubWing)
312 {Error("AliITSPlaneEffSDD::GetFracLive","you asked for a non existing key");
314 // Compute the fraction of bad (dead+noisy) detector
316 GetBadInBlock(key,bad);
321 //_____________________________________________________________________________
322 void 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)
326 if(key>=kNModule*kNChip*kNWing*kNSubWing)
327 {Error("AliITSPlaneEffSDD::GetBadInBlock","you asked for a non existing key");
331 {Error("AliITSPlaneEffSDD::GetBadInBlock","CDB not inizialized: call InitCDB first");
333 AliCDBManager* man = AliCDBManager::Instance();
334 // retrieve map of dead Pixel
335 AliCDBEntry *cdbSDD = man->Get("ITS/Calib/CalibSDD", fRunNumber);
338 sddEntry = (TObjArray*)cdbSDD->GetObject();
340 {Error("AliITSPlaneEffSDD::GetBadInBlock"," SDDEntry not found in CDB");
343 Error("AliITSPlaneEffSDD::GetBadInBlock","Did not find Calib/CalibSDD");
347 UInt_t mod=GetModFromKey(key);
348 UInt_t chip=GetChipFromKey(key);
349 UInt_t wing=GetWingFromKey(key);
350 // count number of dead
351 AliITSCalibrationSDD* calibSDD=(AliITSCalibrationSDD*) sddEntry->At(mod);
352 UInt_t nrBad = calibSDD-> GetDeadChannels();
353 for (UInt_t index=0; index<nrBad; index++) {
354 if(ChipFromAnode(calibSDD->GetBadChannel(index))==chip &&
355 WingFromAnode(calibSDD->GetBadChannel(index))==wing ) nrBadInBlock++;
359 //_____________________________________________________________________________
360 Double_t AliITSPlaneEffSDD::GetFracBad(const UInt_t key) const {
361 // returns 1-fractional live
362 if(key>=kNModule*kNChip*kNWing*kNSubWing)
363 {Error("AliITSPlaneEffSDD::GetFracBad","you asked for a non existing key");
365 return 1.-GetFracLive(key);
367 //_____________________________________________________________________________
368 Bool_t AliITSPlaneEffSDD::WriteIntoCDB() const {
371 {Error("AliITSPlaneEffSDD::WriteIntoCDB","CDB not inizialized: call InitCDB first");
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;
382 Bool_t r=AliCDBManager::Instance()->GetDefaultStorage()->Put(&eff,id,md);
386 //_____________________________________________________________________________
387 Bool_t AliITSPlaneEffSDD::ReadFromCDB() {
390 {Error("AliITSPlaneEffSDD::ReadFromCDB","CDB not inizialized: call InitCDB first");
392 //if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
393 // AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
395 AliCDBEntry *cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSDD",fRunNumber);
396 AliITSPlaneEffSDD* eff= (AliITSPlaneEffSDD*)cdbEntry->GetObject();
397 if(this==eff) return kFALSE;