]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSPlaneEffSDD.cxx
New AliPoissonCalculator class
[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
7167ae53 17// It is used for chip by chip efficiency (eventually with sui-bwing division
18// along the drift direction) of the SDD,
6344adcc 19// evaluated by tracks
20// (Inherits from AliITSPlaneEff)
21// Author: G.E. Bruno
22// giuseppe.bruno@ba.infn.it
23//
24///////////////////////////////////////////////////////////////////////////
25
4c555563 26/* $Id$ */
6344adcc 27
28#include <TMath.h>
3ebe30ad 29#include <TH1F.h>
30#include <TFile.h>
31#include <TTree.h>
32#include <TROOT.h>
6344adcc 33#include "AliITSPlaneEffSDD.h"
34#include "AliLog.h"
35#include "AliCDBStorage.h"
36#include "AliCDBEntry.h"
37#include "AliCDBManager.h"
38//#include "AliCDBRunRange.h"
7167ae53 39#include "AliITSgeom.h"
6344adcc 40#include "AliITSCalibrationSDD.h"
7167ae53 41#include "AliITSsegmentationSDD.h"
6344adcc 42
43ClassImp(AliITSPlaneEffSDD)
44//______________________________________________________________________
45AliITSPlaneEffSDD::AliITSPlaneEffSDD():
3ebe30ad 46 AliITSPlaneEff(),
47 fHisResX(0),
48 fHisResZ(0),
49 fHisResXZ(0),
50 fHisClusterSize(0),
41d18cd2 51 fProfResXvsCluSizeX(0),
52 //fHisResXclu(0),
3ebe30ad 53 fHisResZclu(0),
54 fProfResXvsX(0),
55 fProfResZvsX(0),
56 fProfClustSizeXvsX(0),
41d18cd2 57 fProfClustSizeZvsX(0),
58 fHisTrackErrX(0),
59 fHisTrackErrZ(0),
60 fHisClusErrX(0),
61 fHisClusErrZ(0){
6344adcc 62 for (UInt_t i=0; i<kNModule*kNChip*kNWing*kNSubWing; i++){
18562610 63 // default constructor
6344adcc 64 fFound[i]=0;
65 fTried[i]=0;
66 }
6344adcc 67 AliDebug(1,Form("Calling default constructor"));
68}
69//______________________________________________________________________
70AliITSPlaneEffSDD::~AliITSPlaneEffSDD(){
71 // destructor
72 // Inputs:
73 // none.
74 // Outputs:
75 // none.
76 // Return:
77 // none.
3ebe30ad 78 DeleteHistos();
6344adcc 79}
80//______________________________________________________________________
3ebe30ad 81AliITSPlaneEffSDD::AliITSPlaneEffSDD(const AliITSPlaneEffSDD &s) : AliITSPlaneEff(s),
6344adcc 82//fHis(s.fHis),
3ebe30ad 83fHisResX(0),
84fHisResZ(0),
85fHisResXZ(0),
86fHisClusterSize(0),
41d18cd2 87fProfResXvsCluSizeX(0),
88//fHisResXclu(0),
3ebe30ad 89fHisResZclu(0),
90fProfResXvsX(0),
91fProfResZvsX(0),
92fProfClustSizeXvsX(0),
41d18cd2 93fProfClustSizeZvsX(0),
94fHisTrackErrX(0),
95fHisTrackErrZ(0),
96fHisClusErrX(0),
97fHisClusErrZ(0)
6344adcc 98{
99 // Copy Constructor
100 // Inputs:
101 // AliITSPlaneEffSDD &s The original class for which
102 // this class is a copy of
103 // Outputs:
104 // none.
105 // Return:
106
3ebe30ad 107 for (UInt_t i=0; i<kNModule*kNChip*kNWing*kNSubWing; i++){
108 fFound[i]=s.fFound[i];
109 fTried[i]=s.fTried[i];
110 }
111 if(fHis) {
112 InitHistos();
113 for(Int_t i=0; i<kNHisto; i++) {
114 s.fHisResX[i]->Copy(*fHisResX[i]);
115 s.fHisResZ[i]->Copy(*fHisResZ[i]);
116 s.fHisResXZ[i]->Copy(*fHisResXZ[i]);
117 s.fHisClusterSize[i]->Copy(*fHisClusterSize[i]);
41d18cd2 118 s.fProfResXvsCluSizeX[i]->Copy(*fProfResXvsCluSizeX[i]);
3ebe30ad 119 for(Int_t clu=0; clu<kNclu; clu++) { // clu=0 --> cluster size 1
41d18cd2 120 //s.fHisResXclu[i][clu]->Copy(*fHisResXclu[i][clu]);
3ebe30ad 121 s.fHisResZclu[i][clu]->Copy(*fHisResZclu[i][clu]);
122 }
123 s.fProfResXvsX[i]->Copy(*fProfResXvsX[i]);
124 s.fProfResZvsX[i]->Copy(*fProfResZvsX[i]);
125 s.fProfClustSizeXvsX[i]->Copy(*fProfClustSizeXvsX[i]);
126 s.fProfClustSizeZvsX[i]->Copy(*fProfClustSizeZvsX[i]);
41d18cd2 127 s.fHisTrackErrX[i]->Copy(*fHisTrackErrX[i]);
128 s.fHisTrackErrZ[i]->Copy(*fHisTrackErrZ[i]);
129 s.fHisClusErrX[i]->Copy(*fHisClusErrX[i]);
130 s.fHisClusErrZ[i]->Copy(*fHisClusErrZ[i]);
3ebe30ad 131 }
132 }
6344adcc 133}
134//_________________________________________________________________________
135AliITSPlaneEffSDD& AliITSPlaneEffSDD::operator+=(const AliITSPlaneEffSDD &add){
136 // Add-to-me operator
137 // Inputs:
138 // const AliITSPlaneEffSDD &add simulation class to be added
139 // Outputs:
140 // none.
141 // Return:
142 // none
143 for (UInt_t i=0; i<kNModule*kNChip*kNWing*kNSubWing; i++){
144 fFound[i] += add.fFound[i];
145 fTried[i] += add.fTried[i];
146 }
3ebe30ad 147 if(fHis && add.fHis) {
148 for(Int_t i=0; i<kNHisto; i++) {
149 fHisResX[i]->Add(add.fHisResX[i]);
150 fHisResZ[i]->Add(add.fHisResZ[i]);
151 fHisResXZ[i]->Add(add.fHisResXZ[i]);
152 fHisClusterSize[i]->Add(add.fHisClusterSize[i]);
41d18cd2 153 fProfResXvsCluSizeX[i]->Add(add.fProfResXvsCluSizeX[i]);
3ebe30ad 154 for(Int_t clu=0; clu<kNclu; clu++) { // clu=0 --> cluster size 1
41d18cd2 155 //fHisResXclu[i][clu]->Add(add.fHisResXclu[i][clu]);
3ebe30ad 156 fHisResZclu[i][clu]->Add(add.fHisResZclu[i][clu]);
157 }
158 fProfResXvsX[i]->Add(add.fProfResXvsX[i]);
159 fProfResZvsX[i]->Add(add.fProfResZvsX[i]);
160 fProfClustSizeXvsX[i]->Add(add.fProfClustSizeXvsX[i]);
161 fProfClustSizeZvsX[i]->Add(add.fProfClustSizeZvsX[i]);
41d18cd2 162 fHisTrackErrX[i]->Add(add.fHisTrackErrX[i]);
163 fHisTrackErrZ[i]->Add(add.fHisTrackErrZ[i]);
164 fHisClusErrX[i]->Add(add.fHisClusErrX[i]);
165 fHisClusErrZ[i]->Add(add.fHisClusErrZ[i]);
3ebe30ad 166 }
167 }
6344adcc 168 return *this;
169}
170//______________________________________________________________________
171AliITSPlaneEffSDD& AliITSPlaneEffSDD::operator=(const
172 AliITSPlaneEffSDD &s){
173 // Assignment operator
174 // Inputs:
175 // AliITSPlaneEffSDD &s The original class for which
176 // this class is a copy of
177 // Outputs:
178 // none.
179 // Return:
180
181 if(this==&s) return *this;
182 s.Copy(*this);
6344adcc 183 return *this;
184}
185//______________________________________________________________________
186void AliITSPlaneEffSDD::Copy(TObject &obj) const {
187 // protected method. copy this to obj
188 AliITSPlaneEff::Copy(obj);
3ebe30ad 189 AliITSPlaneEffSDD& target = (AliITSPlaneEffSDD &) obj;
6344adcc 190 for(Int_t i=0;i<kNModule*kNChip*kNWing*kNSubWing;i++) {
3ebe30ad 191 target.fFound[i] = fFound[i];
192 target.fTried[i] = fTried[i];
193 }
194 CopyHistos(target);
195 return;
196}
197//_______________________________________________________________________
198void AliITSPlaneEffSDD::CopyHistos(AliITSPlaneEffSDD &target) const {
199 // protected method: copy histos from this to target
200 target.fHis = fHis; // this is redundant only in some cases. Leave as it is.
201 if(fHis) {
202 target.fHisResX=new TH1F*[kNHisto];
203 target.fHisResZ=new TH1F*[kNHisto];
204 target.fHisResXZ=new TH2F*[kNHisto];
205 target.fHisClusterSize=new TH2I*[kNHisto];
41d18cd2 206 target.fProfResXvsCluSizeX=new TProfile*[kNHisto];
207 //target.fHisResXclu=new TH1F**[kNHisto];
3ebe30ad 208 target.fHisResZclu=new TH1F**[kNHisto];
209 target.fProfResXvsX=new TProfile*[kNHisto];
210 target.fProfResZvsX=new TProfile*[kNHisto];
211 target.fProfClustSizeXvsX=new TProfile*[kNHisto];
212 target.fProfClustSizeZvsX=new TProfile*[kNHisto];
41d18cd2 213 target.fHisTrackErrX=new TH1F*[kNHisto];
214 target.fHisTrackErrZ=new TH1F*[kNHisto];
215 target.fHisClusErrX=new TH1F*[kNHisto];
216 target.fHisClusErrZ=new TH1F*[kNHisto];
3ebe30ad 217
218 for(Int_t i=0; i<kNHisto; i++) {
219 target.fHisResX[i] = new TH1F(*fHisResX[i]);
220 target.fHisResZ[i] = new TH1F(*fHisResZ[i]);
221 target.fHisResXZ[i] = new TH2F(*fHisResXZ[i]);
222 target.fHisClusterSize[i] = new TH2I(*fHisClusterSize[i]);
41d18cd2 223 target.fProfResXvsCluSizeX[i] = new TProfile(*fProfResXvsCluSizeX[i]);
224 //target.fHisResXclu[i]=new TH1F*[kNclu];
3ebe30ad 225 target.fHisResZclu[i]=new TH1F*[kNclu];
226 for(Int_t clu=0; clu<kNclu; clu++) { // clu=0 --> cluster size 1
41d18cd2 227 //target.fHisResXclu[i][clu] = new TH1F(*fHisResXclu[i][clu]);
3ebe30ad 228 target.fHisResZclu[i][clu] = new TH1F(*fHisResZclu[i][clu]);
229 }
230 target.fProfResXvsX[i]=new TProfile(*fProfResXvsX[i]);
231 target.fProfResZvsX[i]=new TProfile(*fProfResZvsX[i]);
232 target.fProfClustSizeXvsX[i]=new TProfile(*fProfClustSizeXvsX[i]);
233 target.fProfClustSizeZvsX[i]=new TProfile(*fProfClustSizeZvsX[i]);
41d18cd2 234 target.fHisTrackErrX[i] = new TH1F(*fHisTrackErrX[i]);
235 target.fHisTrackErrZ[i] = new TH1F(*fHisTrackErrZ[i]);
236 target.fHisClusErrX[i] = new TH1F(*fHisClusErrX[i]);
237 target.fHisClusErrZ[i] = new TH1F(*fHisClusErrZ[i]);
3ebe30ad 238 }
6344adcc 239 }
3ebe30ad 240return;
6344adcc 241}
6344adcc 242
6344adcc 243//_______________________________________________________________________
244Int_t AliITSPlaneEffSDD::GetMissingTracksForGivenEff(Double_t eff, Double_t RelErr,
245 UInt_t im, UInt_t ic, UInt_t iw, UInt_t is) const {
246
247 // Estimate the number of tracks still to be collected to attain a
248 // given efficiency eff, with relative error RelErr
249 // Inputs:
250 // eff -> Expected efficiency (e.g. those from actual estimate)
251 // RelErr -> tollerance [0,1]
252 // im -> module number [0,259]
253 // ic -> chip number [0,3]
254 // iw -> wing number [0,1]
255 // is -> chip number [0,kNSubWing-1]
256 // Outputs: none
257 // Return: the estimated n. of tracks
258 //
259if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
7167ae53 260 {AliError("GetMissingTracksForGivenEff: you asked for a non existing block");
6344adcc 261 return -1;}
879cdb02 262else {
263 UInt_t key=GetKey(im,ic,iw,is);
264 if (key<kNModule*kNChip*kNWing*kNSubWing) return GetNTracksForGivenEff(eff,RelErr)-fTried[key];
265 else return -1;
266}
6344adcc 267}
268//_________________________________________________________________________
269Double_t AliITSPlaneEffSDD::PlaneEff(const UInt_t im,const UInt_t ic,
270 const UInt_t iw,const UInt_t is) const {
271// Compute the efficiency for a basic block,
272// Inputs:
273// im -> module number [0,259]
274// ic -> chip number [0,3]
275// iw -> wing number [0,1]
276// is -> chip number [0,kNSubWing-1]
277if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
7167ae53 278 {AliError("PlaneEff(UInt_t,UInt_t,UInt_t,UInt_t): you asked for a non existing block"); return -1.;}
879cdb02 279UInt_t key=GetKey(im,ic,iw,is);
280Int_t nf=-1;
281Int_t nt=-1;
282if (key<kNModule*kNChip*kNWing*kNSubWing) {
283 nf=fFound[key];
284 nt=fTried[key];
285}
6344adcc 286return AliITSPlaneEff::PlaneEff(nf,nt);
287}
288//_________________________________________________________________________
289Double_t AliITSPlaneEffSDD::ErrPlaneEff(const UInt_t im,const UInt_t ic,
290 const UInt_t iw,const UInt_t is) const {
291 // Compute the statistical error on efficiency for a basic block,
292 // using binomial statistics
293 // Inputs:
294 // im -> module number [0,259]
295 // ic -> chip number [0,3]
296 // iw -> wing number [0,1]
297 // is -> chip number [0,kNSubWing-1]
298if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
7167ae53 299 {AliError("ErrPlaneEff(UInt_t,UInt_t,UInt_t,UInt_t): you asked for a non existing block"); return -1.;}
879cdb02 300UInt_t key=GetKey(im,ic,iw,is);
301Int_t nf=-1;
302Int_t nt=-1;
303if (key<kNModule*kNChip*kNWing*kNSubWing) {
304 nf=fFound[key];
305 nt=fTried[key];
306}
6344adcc 307return AliITSPlaneEff::ErrPlaneEff(nf,nt);
308}
309//_________________________________________________________________________
310Bool_t AliITSPlaneEffSDD::UpDatePlaneEff(const Bool_t Kfound,
311 const UInt_t im, const UInt_t ic,
312 const UInt_t iw, const UInt_t is) {
313 // Update efficiency for a basic block
314if (im>=kNModule || ic>=kNChip || iw>=kNWing || is>=kNSubWing)
7167ae53 315 {AliError("UpDatePlaneEff: you asked for a non existing block"); return kFALSE;}
879cdb02 316 UInt_t key=GetKey(im,ic,iw,is);
317 if (key<kNModule*kNChip*kNWing*kNSubWing) {
318 fTried[key]++;
319 if(Kfound) fFound[key]++;
320 return kTRUE;
321 }
0bf16b3f 322 else {
323 return kFALSE;
324 }
6344adcc 325}
326//_________________________________________________________________________
327void AliITSPlaneEffSDD::ChipAndWingFromAnode(const UInt_t anode, UInt_t& chip,
328 UInt_t& wing) const {
329 // Retun the chip number [0,3] and the wing number [0,1] given the anode number
330 // input: anode number [0,511]
331if(anode>=kNAnode*kNChip*kNWing)
7167ae53 332 {AliError("ChipAndWingFromAnode: you asked for a non existing anode");
6344adcc 333 chip=999;
334 wing=99;
335 return;}
336wing=0;
337chip=anode/kNAnode;
338if(anode>=kNChip*kNAnode) wing=1;
339if(wing==1) chip-=kNChip;
340return;
341}
342//_________________________________________________________________________
343UInt_t AliITSPlaneEffSDD::ChipFromAnode(const UInt_t anode) const {
344 // Retun the chip number [0,3] given the anode number
345 // input: anode number [0,511]
346if(anode>=kNAnode*kNChip*kNWing)
7167ae53 347 {AliError("ChipFromAnode: you asked for a non existing anode"); return 999;}
6344adcc 348Int_t wing=0;
349Int_t chip=anode/kNAnode;
350if(anode>=kNChip*kNAnode) wing=1;
351if(wing==1)chip-=kNChip;
352return chip;
353}
354//_________________________________________________________________________
355UInt_t AliITSPlaneEffSDD::WingFromAnode(const UInt_t anode) const {
356 // return the wing number [0,1] given the anode number
357 // input: anode number [0,511]
358if(anode>=kNAnode*kNChip*kNWing)
7167ae53 359 {AliError("WingFromAnode: you asked for a non existing anode"); return 99;}
6344adcc 360Int_t wing=0;
361if(anode>=kNChip*kNAnode) wing=1;
362return wing;
363}
364//__________________________________________________________________________
365UInt_t AliITSPlaneEffSDD::GetKey(const UInt_t mod, const UInt_t chip,
366 const UInt_t wing, const UInt_t subw) const {
367 // get key given a basic block
368if(mod>=kNModule || chip>=kNChip || wing>= kNWing || subw>=kNSubWing)
7167ae53 369 {AliError("GetKey: you asked for a non existing block"); return 99999;}
6344adcc 370return mod*kNChip*kNWing*kNSubWing+chip*kNWing*kNSubWing+wing*kNSubWing+subw;
371}
372//__________________________________________________________________________
373UInt_t AliITSPlaneEffSDD::GetModFromKey(const UInt_t key) const {
374 // get mod. from key
375if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 376 {AliError("GetModFromKey: you asked for a non existing key"); return 9999;}
6344adcc 377return key/(kNChip*kNWing*kNSubWing);
378}
379//__________________________________________________________________________
380UInt_t AliITSPlaneEffSDD::GetChipFromKey(const UInt_t key) const {
381 // retrieves chip from key
382if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 383 {AliError("GetChipFromKey: you asked for a non existing key"); return 999;}
6344adcc 384return (key%(kNChip*kNWing*kNSubWing))/(kNWing*kNSubWing);
385}
386//__________________________________________________________________________
387UInt_t AliITSPlaneEffSDD::GetWingFromKey(const UInt_t key) const {
388 // retrieves wing from key
389if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 390 {AliError("GetWingFromKey: you asked for a non existing key"); return 99;}
6344adcc 391return ((key%(kNChip*kNWing*kNSubWing))%(kNWing*kNSubWing))/(kNSubWing);
392}
393//__________________________________________________________________________
394UInt_t AliITSPlaneEffSDD::GetSubWingFromKey(const UInt_t key) const {
395 // retrieves sub-wing from key
396if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 397 {AliError("GetSubWingFromKey: you asked for a non existing key"); return 9;}
6344adcc 398return ((key%(kNChip*kNWing*kNSubWing))%(kNWing*kNSubWing))%(kNSubWing);
399}
400//__________________________________________________________________________
401void AliITSPlaneEffSDD::GetAllFromKey(const UInt_t key,UInt_t& mod,UInt_t& chip,
402 UInt_t& wing,UInt_t& subw) const {
403 // get module, chip, wing and subwing from a key
404if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 405 {AliError("GetAllFromKey: you asked for a non existing key");
6344adcc 406 mod=9999;
407 chip=999;
408 wing=99;
409 subw=9;
410 return;}
411mod=GetModFromKey(key);
412chip=GetChipFromKey(key);
413wing=GetWingFromKey(key);
414subw=GetSubWingFromKey(key);
415return;
416}
417//____________________________________________________________________________
418Double_t AliITSPlaneEffSDD::LivePlaneEff(UInt_t key) const {
419 // returns plane efficieny after adding the fraction of sensor which is bad
420if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 421 {AliError("LivePlaneEff: you asked for a non existing key");
6344adcc 422 return -1.;}
423Double_t leff=AliITSPlaneEff::LivePlaneEff(0); // this just for the Warning
424leff=PlaneEff(key)+GetFracBad(key);
425return leff>1?1:leff;
426}
427//____________________________________________________________________________
428Double_t AliITSPlaneEffSDD::ErrLivePlaneEff(UInt_t key) const {
429 // returns error on live plane efficiency
430if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 431 {AliError("ErrLivePlaneEff: you asked for a non existing key");
6344adcc 432 return -1.;}
433Int_t nf=fFound[key];
434Double_t triedInLive=GetFracLive(key)*fTried[key];
435Int_t nt=TMath::Max(nf,TMath::Nint(triedInLive));
436return AliITSPlaneEff::ErrPlaneEff(nf,nt); // for the time being: to be checked
437}
438//_____________________________________________________________________________
439Double_t AliITSPlaneEffSDD::GetFracLive(const UInt_t key) const {
440 // returns the fraction of the sensor which is OK
441if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 442 {AliError("GetFracLive: you asked for a non existing key");
6344adcc 443 return -1.;}
444 // Compute the fraction of bad (dead+noisy) detector
445UInt_t bad=0;
446GetBadInBlock(key,bad);
447Double_t live=bad;
448live/=(kNAnode);
449return 1.-live;
450}
451//_____________________________________________________________________________
452void AliITSPlaneEffSDD::GetBadInBlock(const UInt_t key, UInt_t& nrBadInBlock) const {
453 // Compute the number of bad (dead+noisy) anodes inside a block
454 // (it depends on the chip, not on the sub-wing)
455nrBadInBlock=0;
456if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 457 {AliError("GetBadInBlock: you asked for a non existing key");
6344adcc 458 return;}
459//
460if(!fInitCDBCalled)
7167ae53 461 {AliError("GetBadInBlock: CDB not inizialized: call InitCDB first");
6344adcc 462 return;};
463AliCDBManager* man = AliCDBManager::Instance();
464// retrieve map of dead Pixel
465AliCDBEntry *cdbSDD = man->Get("ITS/Calib/CalibSDD", fRunNumber);
466TObjArray* sddEntry;
467if(cdbSDD) {
468 sddEntry = (TObjArray*)cdbSDD->GetObject();
469 if(!sddEntry)
7167ae53 470 {AliError("GetBadInBlock: SDDEntry not found in CDB");
6344adcc 471 return;}
472} else {
7167ae53 473 AliError("GetBadInBlock: Did not find Calib/CalibSDD");
6344adcc 474 return;
475}
476//
477UInt_t mod=GetModFromKey(key);
478UInt_t chip=GetChipFromKey(key);
479UInt_t wing=GetWingFromKey(key);
480// count number of dead
481AliITSCalibrationSDD* calibSDD=(AliITSCalibrationSDD*) sddEntry->At(mod);
482UInt_t nrBad = calibSDD-> GetDeadChannels();
483for (UInt_t index=0; index<nrBad; index++) {
484 if(ChipFromAnode(calibSDD->GetBadChannel(index))==chip &&
485 WingFromAnode(calibSDD->GetBadChannel(index))==wing ) nrBadInBlock++;
486}
487return;
488}
489//_____________________________________________________________________________
490Double_t AliITSPlaneEffSDD::GetFracBad(const UInt_t key) const {
491 // returns 1-fractional live
492if(key>=kNModule*kNChip*kNWing*kNSubWing)
7167ae53 493 {AliError("GetFracBad: you asked for a non existing key");
6344adcc 494 return -1.;}
495return 1.-GetFracLive(key);
496}
497//_____________________________________________________________________________
498Bool_t AliITSPlaneEffSDD::WriteIntoCDB() const {
499// write onto CDB
500if(!fInitCDBCalled)
7167ae53 501 {AliError("WriteIntoCDB: CDB not inizialized: call InitCDB first");
6344adcc 502 return kFALSE;}
503// to be written properly: now only for debugging
504 AliCDBMetaData *md= new AliCDBMetaData(); // metaData describing the object
505 md->SetObjectClassName("AliITSPlaneEff");
506 md->SetResponsible("Giuseppe Eugenio Bruno");
507 md->SetBeamPeriod(0);
508 md->SetAliRootVersion("head 02/01/08"); //root version
509 AliCDBId id("ITS/PlaneEff/PlaneEffSDD",0,AliCDBRunRange::Infinity());
510 AliITSPlaneEffSDD eff;
511 eff=*this;
512 Bool_t r=AliCDBManager::Instance()->GetDefaultStorage()->Put(&eff,id,md);
513 delete md;
514 return r;
515}
516//_____________________________________________________________________________
517Bool_t AliITSPlaneEffSDD::ReadFromCDB() {
518// read from CDB
519if(!fInitCDBCalled)
7167ae53 520 {AliError("ReadFromCDB: CDB not inizialized: call InitCDB first");
6344adcc 521 return kFALSE;}
6344adcc 522AliCDBEntry *cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSDD",fRunNumber);
1cc5cedc 523if(!cdbEntry) return kFALSE;
6344adcc 524AliITSPlaneEffSDD* eff= (AliITSPlaneEffSDD*)cdbEntry->GetObject();
525if(this==eff) return kFALSE;
3ebe30ad 526if(fHis) CopyHistos(*eff); // If histos already exist then copy them to eff
527eff->Copy(*this); // copy everything (statistics and histos) from eff to this
6344adcc 528return kTRUE;
529}
7167ae53 530//_____________________________________________________________________________
1cc5cedc 531Bool_t AliITSPlaneEffSDD::AddFromCDB(AliCDBId *cdbId) {
18562610 532// read efficiency values from CDB
1cc5cedc 533AliCDBEntry *cdbEntry=0;
534if (!cdbId) {
535 if(!fInitCDBCalled)
536 {AliError("ReadFromCDB: CDB not inizialized. Call InitCDB first"); return kFALSE;}
537 cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSDD",fRunNumber);
538} else {
539 cdbEntry = AliCDBManager::Instance()->Get(*cdbId);
540}
541if(!cdbEntry) return kFALSE;
542AliITSPlaneEffSDD* eff= (AliITSPlaneEffSDD*)cdbEntry->GetObject();
543*this+=*eff;
544return kTRUE;
545}
546//_____________________________________________________________________________
7167ae53 547UInt_t AliITSPlaneEffSDD::GetKeyFromDetLocCoord(Int_t ilay, Int_t idet,
548 Float_t locx, Float_t locz) const {
549// method to locate a basic block from Detector Local coordinate (to be used in tracking)
550//
41d18cd2 551// From AliITSsegmentationSDD rev. 24315 2008-03-05:
552// ^x_loc
553// |
554// _________________________|0_________________________
555// |0 1 .. | |. | 255| (anode numbers)
556// | | |. | |
557// | | |. | | CHANNEL (i.e. WING) = 1
558// | chip=0 | chip=1 |. chip=2 | chip=3 |
559// | | |. | |
560// |____________|____________|256_________|____________|______\ local z (cm)
561// | | |. | | /
562// | | |. | |
563// | chip=7 | chip=6 |. chip=5 | chip=4 | CHANNEL (i.e. WING) = 0
564// | | |. | |
565// | | |. | |
566// |____________|____________|0___________|____________|
567// 511 510 ... ^ .. 257 256 (anode numbers)
568// |_ (time bins)
569//
7167ae53 570// If kNSubWing = 1, i.e. no sub-wing subdivision, then the numbering scheme of the
571// unique key is the following, e.g. for the first detector (idet=0, ilayer=2)
572//
573// ^x_loc (cm)
574// |
575// _________________________|__________________________ 3.5085
576// | | | | |
577// | | | | |
578// | | | | |
41d18cd2 579// | key=0 | key=2 | key=4 | key=6 |
7167ae53 580// | | | | |
581// |____________|____________|____________|____________|_0_____\ local z (cm)
582// | | | | | /
583// | | | | |
41d18cd2 584// | key=7 | key=5 | key=3 | key=1 |
7167ae53 585// | | | | |
586// | | | | |
587// |____________|____________|____________|____________| -3.5085
588//-3.7632 -1.8816 0 1.1186 3.7632
589//
41d18cd2 590// for the second detector (idet=2, ilay=2), the same as above but +8: first one 8 (bottom-left),
591// last one is 15 (lower-left), and so on.
7167ae53 592//
41d18cd2 593// If subwing division has been applied, then you count as in the schemes below
594// E.g. kNSubWing=2. (It was much simpler with old AliITSsegmentation numbering!)
7167ae53 595//
596// ^x_loc (cm)
597// |
598// _________________________|__________________________ 3.5085
599// | | | | |
41d18cd2 600// | key=0 | key=4 | key=8 | key=12 |
601// |____________|____________|____________|____________| 1.75425
7167ae53 602// | | | | |
41d18cd2 603// | key=1 | key=5 | key=9 | key=13 |
7167ae53 604// |____________|____________|____________|____________|_0_____\ local z (cm)
605// | | | | | /
41d18cd2 606// | key=15 | key=11 | key=7 | key=3 |
607// |____________|____________|____________|____________| -1.75425
7167ae53 608// | | | | |
41d18cd2 609// | key=14 | key=10 | key=6 | key=2 |
7167ae53 610// |____________|____________|____________|____________| -3.5085
611//-3.7632 -1.8816 0 1.1186 3.7632
612//
41d18cd2 613// E.g. kNSubWing=3
614// ^x_loc (cm)
615// |
616// _________________________|__________________________ 3.5085
617// | 0 | 6 | 12 | 18 |
618// |____________|____________|____________|____________| 2.339
619// | 1 | 7 | 13 | 19 |
620// |____________|____________|____________|____________| 1.1695
621// | 2 | 8 | 14 | 20 |
622// |____________|____________|____________|____________|_0_____\ local z (cm)
623// | 23 | 17 | 11 | 5 | /
624// |____________|____________|____________|____________| -1.1695
625// | key=22 | key=16 | key=10 | key=4 |
626// |____________|____________|____________|____________| -2.339
627// | 21 | 15 | 9 | 3 |
628// |____________|____________|____________|____________| -3.5085
629//-3.7632 -1.8816 0 1.1186 3.7632
7167ae53 630//___________________________________________________________________________
631//
632UInt_t key=999999;
633if(ilay<2 || ilay>3)
634 {AliError("GetKeyFromDetLocCoord: you asked for a non existing layer");
635 return key;}
636if(ilay==2 && (idet<0 || idet>83))
637 {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
638 return key;}
639if(ilay==3 && (idet<0 || idet>175))
640 {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
641 return key;}
642UInt_t mod=idet;
643if(ilay==3) mod+=84;
644UInt_t chip=0,wing=0,subw=0;
645ChipAndWingAndSubWingFromLocCoor(locx,locz,chip,wing,subw);
646key=GetKey(mod,chip,wing,subw);
647return key;
648}
649//_____________________________________________________________________________
650void AliITSPlaneEffSDD::ChipAndWingAndSubWingFromLocCoor(Float_t xloc, Float_t zloc,
651 UInt_t& chip, UInt_t& wing, UInt_t& subw) const {
41d18cd2 652//AliITSgeom* geom=NULL;
7167ae53 653//AliITSsegmentationSDD* sdd=new AliITSsegmentationSDD(geom);
41d18cd2 654AliITSsegmentationSDD sdd;
7167ae53 655sdd.SetDriftSpeed(sdd.GetDriftSpeed()); // this only for setting fSetDriftSpeed=kTRUE !!!
656Int_t ix,iz;
657Int_t ntb;
658UInt_t anode=0;
659if(sdd.LocalToDet(xloc,zloc,ix,iz)) {
660 anode+=iz;
661 ChipAndWingFromAnode(anode,chip,wing);
662 if(sdd.LocalToDet(0.,0.,ntb,iz)) { // in this way the sub-division along time coordinate
663 subw=SubWingFromTimeBin(ix,ntb); } // is purely geometrical one and it does not
664 else { // depen on the drift-velocity.
665 AliError("ChipAndWingAndSubWingFromLocCoor: cannot calculate n. of time bins for SubWing.");
666 subw=9;
667 }
668} else {
669 AliError("ChipAndWingAndSubWingFromLocCoor: cannot calculate anode number and time bin.");
670 chip=999;
671 wing=99;
672 subw=9;
673}
41d18cd2 674//delete geom;
7167ae53 675}
676//__________________________________________________________________________________
677UInt_t AliITSPlaneEffSDD::SubWingFromTimeBin(const Int_t tb, const Int_t ntb) const {
678if(tb<0 || tb>ntb || ntb<0) {
679 AliError(Form("SubWingFromTimeBin: you asked time bin = %d with %d n. of bins",tb,ntb));
680 return 9;
681}
682//AliDebug(Form("tb = %d, ntb= %d , NSubWing = %d",tb,ntb,kNSubWing));
683Float_t h=tb;
684 h/=ntb;
685 h*=(kNSubWing-1);
686return TMath::Nint(h);
687}
aa0de373 688//________________________________________________________
689Bool_t AliITSPlaneEffSDD::GetBlockBoundaries(const UInt_t key, Float_t& xmn,Float_t& xmx,
690 Float_t& zmn,Float_t& zmx) const {
691//
692// This method return the geometrical boundaries of the active volume of a given
693// basic block, in the detector reference system.
694// Input: unique key to locate a basic block.
695//
696// Output: Ymin, Ymax, Zmin, Zmax of a basic block (chip for SPD)
697// Return: kTRUE if computation was succesfully, kFALSE otherwise
698//
699// the following scheemes will help in following the method implementation
700// E.g. kNSubWing=1
701// ^x_loc (cm)
702// for all: subw=0 |
703// _________________________|__________________________ 3.5085
41d18cd2 704// | wing=0 | wing=0 | wing=0 | wing=0 |
aa0de373 705// | chip=0 | chip=1 | chip=2 | chip=3 |
706// | key=0 | key=2 | key=4 | key=6 |
41d18cd2 707// |____________|____________|____________|____________|_0_____\ local z (cm)
708// | wing=1 | wing=1 | wing=1 | wing=1 | /
709// | chip=3 | chip=2 | chip=1 | chip=0 |
710// | key=7 | key=5 | key=3 | key=1 |
aa0de373 711// |____________|____________|____________|____________| -3.5085
712//-3.7632 -1.8816 0 1.1186 3.7632
713//
714// E.g. kNSubWing=2
715// ^x_loc (cm)
716// |
717// _________________________|__________________________ 3.5085
718// | chip=0 | chip=1 | chip=2 | chip=3 |
41d18cd2 719// | key=0 | key=4 | key=8 | key=12 | subw=0
720// |____________|____________|____________|____________| wing=0
aa0de373 721// | chip=0 | chip=1 | chip=2 | chip=3 | subw=1
41d18cd2 722// | key=1 | key=5 | key=9 | key=13 |
aa0de373 723// |____________|____________|____________|____________|_0________\ local z (cm)
41d18cd2 724// | chip=3 | chip=2 | chip=1 | chip=0 | /
725// | key=15 | key=11 | key=7 | key=3 | subw=1
726// |____________|____________|____________|____________| wing=1
727// | chip=3 | chip=2 | chip=1 | chip=0 | subw=0
728// | key=14 | key=10 | key=6 | key=2 |
aa0de373 729// |____________|____________|____________|____________| -3.5085
730//-3.7632 -1.8816 0 1.1186 3.7632
731//
732if(key>=kNModule*kNChip*kNWing*kNSubWing)
733 {AliWarning("GetBlockBoundaries: you asked for a non existing key"); return kFALSE;}
41d18cd2 734// as it is now it is consistent with new AliITSsegmentationSDD numbering !
aa0de373 735const Float_t kDxDefault = 35085.; // For Plane Eff. purpouses, default values
736const Float_t kDzDefault = 75264.; // are precise enough !!!
737const Float_t kconv = 1.0E-04; //converts microns to cm.
738UInt_t chip=GetChipFromKey(key);
739UInt_t wing=GetWingFromKey(key);
740UInt_t subw=GetSubWingFromKey(key);
41d18cd2 741if(wing==1) { // count x from below, z from right
742 xmn=kconv*(kDxDefault/kNSubWing*subw-kDxDefault);
743 xmx=kconv*(kDxDefault/kNSubWing*(subw+1)-kDxDefault);
744 zmn=kconv*(kDzDefault*0.5-kDzDefault/kNChip*(chip+1));
745 zmx=kconv*(kDzDefault*0.5-kDzDefault/kNChip*chip);
aa0de373 746}
41d18cd2 747else if(wing==0) { // count x from top, z from left
748 xmx=kconv*(kDxDefault-kDxDefault/kNSubWing*subw);
749 xmn=kconv*(kDxDefault-kDxDefault/kNSubWing*(subw+1));
750 zmn=kconv*(kDzDefault/kNChip*chip-0.5*kDzDefault);
751 zmx=kconv*(kDzDefault/kNChip*(chip+1)-0.5*kDzDefault);
aa0de373 752}
753else {AliError("GetBlockBoundaries: you got wrong n. of wing"); return kFALSE;}
754return kTRUE;
755}
3ebe30ad 756//__________________________________________________________
757void AliITSPlaneEffSDD::InitHistos() {
758 // for the moment let's create the histograms
759 // module by module
760 TString histnameResX="HistResX_mod_",aux;
761 TString histnameResZ="HistResZ_mod_";
762 TString histnameResXZ="HistResXZ_mod_";
763 TString histnameClusterType="HistClusterType_mod_";
41d18cd2 764// TString histnameResXclu="HistResX_mod_";
765 TString profnameResXvsCluSizeX="ProfResXvsCluSizeX_mod_";
3ebe30ad 766 TString histnameResZclu="HistResZ_mod_";
767 TString profnameResXvsX="ProfResXvsX_mod_";
768 TString profnameResZvsX="ProfResZvsX_mod_";
769 TString profnameClustSizeXvsX="ProfClustSizeXvsX_mod_";
770 TString profnameClustSizeZvsX="ProfClustSizeZvsX_mod_";
41d18cd2 771 TString histnameTrackErrX="HistTrackErrX_mod_";
772 TString histnameTrackErrZ="HistTrackErrZ_mod_";
773 TString histnameClusErrX="HistClusErrX_mod_";
774 TString histnameClusErrZ="HistClusErrZ_mod_";
3ebe30ad 775//
4c555563 776
777 TH1::AddDirectory(kFALSE);
778
3ebe30ad 779 fHisResX=new TH1F*[kNHisto];
780 fHisResZ=new TH1F*[kNHisto];
781 fHisResXZ=new TH2F*[kNHisto];
782 fHisClusterSize=new TH2I*[kNHisto];
41d18cd2 783 fProfResXvsCluSizeX=new TProfile*[kNHisto];
784 //fHisResXclu=new TH1F**[kNHisto];
3ebe30ad 785 fHisResZclu=new TH1F**[kNHisto];
786 fProfResXvsX=new TProfile*[kNHisto];
787 fProfResZvsX=new TProfile*[kNHisto];
788 fProfClustSizeXvsX=new TProfile*[kNHisto];
789 fProfClustSizeZvsX=new TProfile*[kNHisto];
41d18cd2 790 fHisTrackErrX=new TH1F*[kNHisto];
791 fHisTrackErrZ=new TH1F*[kNHisto];
792 fHisClusErrX=new TH1F*[kNHisto];
793 fHisClusErrZ=new TH1F*[kNHisto];
3ebe30ad 794
795 for (Int_t nhist=0;nhist<kNHisto;nhist++){
796 aux=histnameResX;
797 aux+=nhist;
061c42a0 798 fHisResX[nhist]=new TH1F("histname","histname",2000,-0.40,0.40); // +- 4000 micron; 1 bin=4 micron
3ebe30ad 799 fHisResX[nhist]->SetName(aux.Data());
800 fHisResX[nhist]->SetTitle(aux.Data());
801
802 aux=histnameResZ;
803 aux+=nhist;
061c42a0 804 fHisResZ[nhist]=new TH1F("histname","histname",1000,-0.30,0.30); // +-3000 micron; 1 bin=6 micron
3ebe30ad 805 fHisResZ[nhist]->SetName(aux.Data());
806 fHisResZ[nhist]->SetTitle(aux.Data());
807
808 aux=histnameResXZ;
809 aux+=nhist;
061c42a0 810 fHisResXZ[nhist]=new TH2F("histname","histname",100,-0.4,0.4,60,-0.24,0.24); // binning:
41d18cd2 811 // 80 micron in x;
812 // 80 micron in z;
3ebe30ad 813 fHisResXZ[nhist]->SetName(aux.Data());
814 fHisResXZ[nhist]->SetTitle(aux.Data());
815
816 aux=histnameClusterType;
817 aux+=nhist;
818 fHisClusterSize[nhist]=new TH2I("histname","histname",10,0.5,10.5,10,0.5,10.5);
819 fHisClusterSize[nhist]->SetName(aux.Data());
820 fHisClusterSize[nhist]->SetTitle(aux.Data());
821
41d18cd2 822 aux=profnameResXvsCluSizeX;
823 aux+=nhist;
824 fProfResXvsCluSizeX[nhist]=new TProfile("histname","histname",10,0.5,10.5);
825 fProfResXvsCluSizeX[nhist]->SetName(aux.Data());
826 fProfResXvsCluSizeX[nhist]->SetTitle(aux.Data());
827
828// fHisResXclu[nhist]=new TH1F*[kNclu];
3ebe30ad 829 fHisResZclu[nhist]=new TH1F*[kNclu];
830 for(Int_t clu=0; clu<kNclu; clu++) { // clu=0 --> cluster size 1
41d18cd2 831 /*aux=histnameResXclu;
3ebe30ad 832 aux+=nhist;
833 aux+="_clu_";
834 aux+=clu+1; // clu=0 --> cluster size 1
835 fHisResXclu[nhist][clu]=new TH1F("histname","histname",1500,-0.15,0.15);// +- 1500 micron; 1 bin=2 micron
836 fHisResXclu[nhist][clu]->SetName(aux.Data());
41d18cd2 837 fHisResXclu[nhist][clu]->SetTitle(aux.Data());*/
3ebe30ad 838
839 aux=histnameResZclu;
840 aux+=nhist;
841 aux+="_clu_";
842 aux+=clu+1; // clu=0 --> cluster size 1
061c42a0 843 fHisResZclu[nhist][clu]=new TH1F("histname","histname",1000,-0.30,0.30); // +-3000 micron; 1 bin=6 micron
3ebe30ad 844 fHisResZclu[nhist][clu]->SetName(aux.Data());
845 fHisResZclu[nhist][clu]->SetTitle(aux.Data());
846 }
847
848 aux=profnameResXvsX;
849 aux+=nhist;
41d18cd2 850 fProfResXvsX[nhist]=new TProfile("histname","histname",140,-3.5,3.5);
3ebe30ad 851 fProfResXvsX[nhist]->SetName(aux.Data());
852 fProfResXvsX[nhist]->SetTitle(aux.Data());
853
854 aux=profnameResZvsX;
855 aux+=nhist;
41d18cd2 856 fProfResZvsX[nhist]=new TProfile("histname","histname",140,-3.5,3.5);
3ebe30ad 857 fProfResZvsX[nhist]->SetName(aux.Data());
858 fProfResZvsX[nhist]->SetTitle(aux.Data());
859
860 aux=profnameClustSizeXvsX;
861 aux+=nhist;
41d18cd2 862 fProfClustSizeXvsX[nhist]=new TProfile("histname","histname",140,-3.5,3.5);
3ebe30ad 863 fProfClustSizeXvsX[nhist]->SetName(aux.Data());
864 fProfClustSizeXvsX[nhist]->SetTitle(aux.Data());
865
866 aux=profnameClustSizeZvsX;
867 aux+=nhist;
41d18cd2 868 fProfClustSizeZvsX[nhist]=new TProfile("histname","histname",140,-3.5,3.5);
3ebe30ad 869 fProfClustSizeZvsX[nhist]->SetName(aux.Data());
870 fProfClustSizeZvsX[nhist]->SetTitle(aux.Data());
871
41d18cd2 872 aux=histnameTrackErrX;
873 aux+=nhist;
061c42a0 874 fHisTrackErrX[nhist]=new TH1F("histname","histname",500,0.,0.50); // 0-5000 micron; 1 bin=10 micron
41d18cd2 875 fHisTrackErrX[nhist]->SetName(aux.Data());
876 fHisTrackErrX[nhist]->SetTitle(aux.Data());
877
878 aux=histnameTrackErrZ;
879 aux+=nhist;
880 fHisTrackErrZ[nhist]=new TH1F("histname","histname",200,0.,0.32); // 0-3200 micron; 1 bin=16 micron
881 fHisTrackErrZ[nhist]->SetName(aux.Data());
882 fHisTrackErrZ[nhist]->SetTitle(aux.Data());
883
884 aux=histnameClusErrX;
885 aux+=nhist;
061c42a0 886 fHisClusErrX[nhist]=new TH1F("histname","histname",400,0.,0.24); // 0-2400 micron; 1 bin=6 micron
41d18cd2 887 fHisClusErrX[nhist]->SetName(aux.Data());
888 fHisClusErrX[nhist]->SetTitle(aux.Data());
889
890 aux=histnameClusErrZ;
891 aux+=nhist;
061c42a0 892 fHisClusErrZ[nhist]=new TH1F("histname","histname",400,0.,0.32); // 0-3200 micron; 1 bin=8 micron
41d18cd2 893 fHisClusErrZ[nhist]->SetName(aux.Data());
894 fHisClusErrZ[nhist]->SetTitle(aux.Data());
895
3ebe30ad 896 }
4c555563 897
898 TH1::AddDirectory(kTRUE);
899
3ebe30ad 900return;
901}
902//__________________________________________________________
903void AliITSPlaneEffSDD::DeleteHistos() {
18562610 904 // delete the histograms and clean the memory
3ebe30ad 905 if(fHisResX) {
906 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResX[i];
907 delete [] fHisResX; fHisResX=0;
908 }
909 if(fHisResZ) {
910 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResZ[i];
911 delete [] fHisResZ; fHisResZ=0;
912 }
913 if(fHisResXZ) {
914 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResXZ[i];
915 delete [] fHisResXZ; fHisResXZ=0;
916 }
917 if(fHisClusterSize) {
918 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusterSize[i];
919 delete [] fHisClusterSize; fHisClusterSize=0;
920 }
41d18cd2 921 if(fProfResXvsCluSizeX) {
922 for (Int_t i=0; i<kNHisto; i++ ) delete fProfResXvsCluSizeX[i];
923 delete [] fProfResXvsCluSizeX; fProfResXvsCluSizeX=0;
924 }
925 /*if(fHisResXclu) {
3ebe30ad 926 for (Int_t i=0; i<kNHisto; i++ ) {
927 for (Int_t clu=0; clu<kNclu; clu++) if (fHisResXclu[i][clu]) delete fHisResXclu[i][clu];
928 delete [] fHisResXclu[i];
929 }
930 delete [] fHisResXclu;
931 fHisResXclu = 0;
41d18cd2 932 }*/
3ebe30ad 933 if(fHisResZclu) {
934 for (Int_t i=0; i<kNHisto; i++ ) {
935 for (Int_t clu=0; clu<kNclu; clu++) if (fHisResZclu[i][clu]) delete fHisResZclu[i][clu];
936 delete [] fHisResZclu[i];
937 }
938 delete [] fHisResZclu;
939 fHisResZclu = 0;
940 }
941 if(fProfResXvsX) {
942 for (Int_t i=0; i<kNHisto; i++ ) delete fProfResXvsX[i];
943 delete [] fProfResXvsX; fProfResXvsX=0;
944 }
945 if(fProfResZvsX) {
946 for (Int_t i=0; i<kNHisto; i++ ) delete fProfResZvsX[i];
947 delete [] fProfResZvsX; fProfResZvsX=0;
948 }
949 if(fProfClustSizeXvsX) {
950 for (Int_t i=0; i<kNHisto; i++ ) delete fProfClustSizeXvsX[i];
951 delete [] fProfClustSizeXvsX; fProfClustSizeXvsX=0;
952 }
953 if(fProfClustSizeZvsX) {
954 for (Int_t i=0; i<kNHisto; i++ ) delete fProfClustSizeZvsX[i];
955 delete [] fProfClustSizeZvsX; fProfClustSizeZvsX=0;
956 }
41d18cd2 957 if(fHisTrackErrX) {
958 for (Int_t i=0; i<kNHisto; i++ ) delete fHisTrackErrX[i];
959 delete [] fHisTrackErrX; fHisTrackErrX=0;
960 }
961 if(fHisTrackErrZ) {
962 for (Int_t i=0; i<kNHisto; i++ ) delete fHisTrackErrZ[i];
963 delete [] fHisTrackErrZ; fHisTrackErrZ=0;
964 }
965 if(fHisClusErrX) {
966 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusErrX[i];
967 delete [] fHisClusErrX; fHisClusErrX=0;
968 }
969 if(fHisClusErrZ) {
970 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusErrZ[i];
971 delete [] fHisClusErrZ; fHisClusErrZ=0;
972 }
3ebe30ad 973
974return;
975}
976//__________________________________________________________
977Bool_t AliITSPlaneEffSDD::FillHistos(UInt_t key, Bool_t found,
879cdb02 978 Float_t *tr, Float_t *clu, Int_t *csize, Float_t*) {
3ebe30ad 979// this method fill the histograms
980// input: - key: unique key of the basic block
981// - found: Boolean to asses whether a cluster has been associated to the track or not
1cc5cedc 982// - tr[0],tr[1] local X and Z coordinates of the track prediction, respectively
983// - tr[2],tr[3] error on local X and Z coordinates of the track prediction, respectively
984// - clu[0],clu[1] local X and Z coordinates of the cluster associated to the track, respectively
985// - clu[2],clu[3] error on local X and Z coordinates of the cluster associated to the track, respectively
986// - csize[0][1] cluster size in X and Z, respectively
3ebe30ad 987// output: kTRUE if filling was succesfull kFALSE otherwise
988// side effects: updating of the histograms.
989//
990 if (!fHis) {
991 AliWarning("FillHistos: histograms do not exist! Call SetCreateHistos(kTRUE) first");
992 return kFALSE;
993 }
994 if(key>=kNModule*kNChip*kNWing*kNSubWing)
995 {AliWarning("FillHistos: you asked for a non existing key"); return kFALSE;}
996 Int_t id=GetModFromKey(key);
997 if(id>=kNHisto)
998 {AliWarning("FillHistos: you want to fill a non-existing histos"); return kFALSE;}
999 if(found) {
1cc5cedc 1000 Float_t resx=tr[0]-clu[0];
1001 Float_t resz=tr[1]-clu[1];
3ebe30ad 1002 fHisResX[id]->Fill(resx);
1003 fHisResZ[id]->Fill(resz);
1004 fHisResXZ[id]->Fill(resx,resz);
1cc5cedc 1005 fHisClusterSize[id]->Fill((Double_t)csize[0],(Double_t)csize[1]);
41d18cd2 1006 fProfResXvsCluSizeX[id]->Fill((Double_t)csize[0],resx);
1007 //if(csize[0]>0 && csize[0]<=kNclu) fHisResXclu[id][csize[0]-1]->Fill(resx);
1cc5cedc 1008 if(csize[1]>0 && csize[1]<=kNclu) fHisResZclu[id][csize[1]-1]->Fill(resz);
1009 fProfResXvsX[id]->Fill(clu[0],resx);
1010 fProfResZvsX[id]->Fill(clu[0],resz);
1011 fProfClustSizeXvsX[id]->Fill(clu[0],(Double_t)csize[0]);
1012 fProfClustSizeZvsX[id]->Fill(clu[0],(Double_t)csize[1]);
3ebe30ad 1013 }
41d18cd2 1014 fHisTrackErrX[id]->Fill(tr[2]);
1015 fHisTrackErrZ[id]->Fill(tr[3]);
1016 fHisClusErrX[id]->Fill(clu[2]);
1017 fHisClusErrZ[id]->Fill(clu[3]);
3ebe30ad 1018 return kTRUE;
1019}
1020//__________________________________________________________
1021Bool_t AliITSPlaneEffSDD::WriteHistosToFile(TString filename, Option_t* option) {
1022 //
1023 // Saves the histograms into a tree and saves the trees into a file
1024 //
1025 if (!fHis) return kFALSE;
5af4a2d0 1026 if (filename.IsNull() || filename.IsWhitespace()) {
3ebe30ad 1027 AliWarning("WriteHistosToFile: null output filename!");
1028 return kFALSE;
1029 }
943fb20f 1030 char branchname[51];
3ebe30ad 1031 TFile *hFile=new TFile(filename.Data(),option,
1032 "The File containing the TREEs with ITS PlaneEff Histos");
1033 TTree *SDDTree=new TTree("SDDTree","Tree whith Residuals and Cluster Type distributions for SDD");
1034 TH1F *histZ,*histX;
1035 TH2F *histXZ;
1036 TH2I *histClusterType;
41d18cd2 1037 TProfile *profileResXvsCluSizeX;
1038 //TH1F *histXclu[kNclu];
3ebe30ad 1039 TH1F *histZclu[kNclu];
1040 TProfile *profileResXvsX, *profileResZvsX, *profileClSizXvsX, *profileClSizZvsX;
41d18cd2 1041 TH1F *histTrErrZ,*histTrErrX;
1042 TH1F *histClErrZ,*histClErrX;
3ebe30ad 1043
1044 histZ=new TH1F();
1045 histX=new TH1F();
1046 histXZ=new TH2F();
1047 histClusterType=new TH2I();
41d18cd2 1048 profileResXvsCluSizeX=new TProfile();
3ebe30ad 1049 for(Int_t clu=0;clu<kNclu;clu++) {
41d18cd2 1050 //histXclu[clu]=new TH1F();
3ebe30ad 1051 histZclu[clu]=new TH1F();
1052 }
1053 profileResXvsX=new TProfile();
1054 profileResZvsX=new TProfile();
1055 profileClSizXvsX=new TProfile();
1056 profileClSizZvsX=new TProfile();
41d18cd2 1057 histTrErrX=new TH1F();
1058 histTrErrZ=new TH1F();
1059 histClErrX=new TH1F();
1060 histClErrZ=new TH1F();
3ebe30ad 1061
1062 SDDTree->Branch("histX","TH1F",&histX,128000,0);
1063 SDDTree->Branch("histZ","TH1F",&histZ,128000,0);
1064 SDDTree->Branch("histXZ","TH2F",&histXZ,128000,0);
1065 SDDTree->Branch("histClusterType","TH2I",&histClusterType,128000,0);
41d18cd2 1066 SDDTree->Branch("profileResXvsCluSizeX","TProfile",&profileResXvsCluSizeX,128000,0);
3ebe30ad 1067 for(Int_t clu=0;clu<kNclu;clu++) {
943fb20f 1068 //snprintf(branchname,50,"histXclu_%d",clu+1);
41d18cd2 1069 //SDDTree->Branch(branchname,"TH1F",&histXclu[clu],128000,0);
943fb20f 1070 snprintf(branchname,50,"histZclu_%d",clu+1);
3ebe30ad 1071 SDDTree->Branch(branchname,"TH1F",&histZclu[clu],128000,0);
1072 }
1073 SDDTree->Branch("profileResXvsX","TProfile",&profileResXvsX,128000,0);
1074 SDDTree->Branch("profileResZvsX","TProfile",&profileResZvsX,128000,0);
1075 SDDTree->Branch("profileClSizXvsX","TProfile",&profileClSizXvsX,128000,0);
1076 SDDTree->Branch("profileClSizZvsX","TProfile",&profileClSizZvsX,128000,0);
41d18cd2 1077 SDDTree->Branch("histTrErrX","TH1F",&histTrErrX,128000,0);
1078 SDDTree->Branch("histTrErrZ","TH1F",&histTrErrZ,128000,0);
1079 SDDTree->Branch("histClErrX","TH1F",&histClErrX,128000,0);
1080 SDDTree->Branch("histClErrZ","TH1F",&histClErrZ,128000,0);
3ebe30ad 1081
1082 for(Int_t j=0;j<kNHisto;j++){
1083 histX=fHisResX[j];
1084 histZ=fHisResZ[j];
1085 histXZ=fHisResXZ[j];
1086 histClusterType=fHisClusterSize[j];
41d18cd2 1087 profileResXvsCluSizeX=fProfResXvsCluSizeX[j];
3ebe30ad 1088 for(Int_t clu=0;clu<kNclu;clu++) {
41d18cd2 1089 //histXclu[clu]=fHisResXclu[j][clu];
3ebe30ad 1090 histZclu[clu]=fHisResZclu[j][clu];
1091 }
1092 profileResXvsX=fProfResXvsX[j];
1093 profileResZvsX=fProfResZvsX[j];
1094 profileClSizXvsX=fProfClustSizeXvsX[j];
1095 profileClSizZvsX=fProfClustSizeZvsX[j];
41d18cd2 1096 histTrErrX=fHisTrackErrX[j];
1097 histTrErrZ=fHisTrackErrZ[j];
1098 histClErrX=fHisClusErrX[j];
1099 histClErrZ=fHisClusErrZ[j];
3ebe30ad 1100
1101 SDDTree->Fill();
1102 }
1103 hFile->Write();
1104 hFile->Close();
1105return kTRUE;
1106}
1107//__________________________________________________________
1108Bool_t AliITSPlaneEffSDD::ReadHistosFromFile(TString filename) {
1109 //
1110 // Read histograms from an already existing file
1111 //
1112 if (!fHis) return kFALSE;
5af4a2d0 1113 if (filename.IsNull() || filename.IsWhitespace()) {
3ebe30ad 1114 AliWarning("ReadHistosFromFile: incorrect output filename!");
1115 return kFALSE;
1116 }
943fb20f 1117 char branchname[51];
3ebe30ad 1118
1119 TH1F *h = 0;
1120 TH2F *h2 = 0;
1121 TH2I *h2i= 0;
1122 TProfile *p = 0;
1123
1124 TFile *file=TFile::Open(filename.Data(),"READONLY");
1125
1126 if (!file || file->IsZombie()) {
1127 AliWarning(Form("Can't open %s !",filename.Data()));
1128 delete file;
1129 return kFALSE;
1130 }
1131 TTree *tree = (TTree*) file->Get("SDDTree");
1132
1133 TBranch *histX = (TBranch*) tree->GetBranch("histX");
1134 TBranch *histZ = (TBranch*) tree->GetBranch("histZ");
1135 TBranch *histXZ = (TBranch*) tree->GetBranch("histXZ");
1136 TBranch *histClusterType = (TBranch*) tree->GetBranch("histClusterType");
41d18cd2 1137 TBranch *profileResXvsCluSizeX = (TBranch*) tree->GetBranch("profileResXvsCluSizeX");
1138 //TBranch *histXclu[kNclu], *histZclu[kNclu];
1139 TBranch *histZclu[kNclu];
3ebe30ad 1140 for(Int_t clu=0; clu<kNclu; clu++) {
943fb20f 1141 //snprintf(branchname,50,"histXclu_%d",clu+1);
41d18cd2 1142 //histXclu[clu]= (TBranch*) tree->GetBranch(branchname);
943fb20f 1143 snprintf(branchname,50,"histZclu_%d",clu+1);
3ebe30ad 1144 histZclu[clu]= (TBranch*) tree->GetBranch(branchname);
1145 }
1146 TBranch *profileResXvsX = (TBranch*) tree->GetBranch("profileResXvsX");
1147 TBranch *profileResZvsX = (TBranch*) tree->GetBranch("profileResZvsX");
1148 TBranch *profileClSizXvsX = (TBranch*) tree->GetBranch("profileClSizXvsX");
1149 TBranch *profileClSizZvsX = (TBranch*) tree->GetBranch("profileClSizZvsX");
41d18cd2 1150 TBranch *histTrErrX = (TBranch*) tree->GetBranch("histTrErrX");
1151 TBranch *histTrErrZ = (TBranch*) tree->GetBranch("histTrErrZ");
1152 TBranch *histClErrX = (TBranch*) tree->GetBranch("histClErrX");
1153 TBranch *histClErrZ = (TBranch*) tree->GetBranch("histClErrZ");
3ebe30ad 1154
1155 gROOT->cd();
1156
1157 Int_t nevent = (Int_t)histX->GetEntries();
1158 if(nevent!=kNHisto)
1159 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1160 histX->SetAddress(&h);
1161 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1162 histX->GetEntry(j);
1163 fHisResX[j]->Add(h);
1164 }
1165
1166 nevent = (Int_t)histZ->GetEntries();
1167 if(nevent!=kNHisto)
1168 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1169 histZ->SetAddress(&h);
1170 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1171 histZ->GetEntry(j);
1172 fHisResZ[j]->Add(h);
1173 }
1174
1175 nevent = (Int_t)histXZ->GetEntries();
1176 if(nevent!=kNHisto)
1177 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1178 histXZ->SetAddress(&h2);
1179 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1180 histXZ->GetEntry(j);
1181 fHisResXZ[j]->Add(h2);
1182 }
1183
1184 nevent = (Int_t)histClusterType->GetEntries();
1185 if(nevent!=kNHisto)
1186 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1187 histClusterType->SetAddress(&h2i);
1188 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1189 histClusterType->GetEntry(j);
1190 fHisClusterSize[j]->Add(h2i);
1191 }
1192
41d18cd2 1193 nevent = (Int_t)profileResXvsCluSizeX->GetEntries();
1194 if(nevent!=kNHisto)
1195 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1196 profileResXvsCluSizeX->SetAddress(&p);
1197 for(Int_t j=0;j<kNHisto;j++){
41d18cd2 1198 profileResXvsCluSizeX->GetEntry(j);
1199 fProfResXvsCluSizeX[j]->Add(p);
1200 }
1201
3ebe30ad 1202 for(Int_t clu=0; clu<kNclu; clu++) {
1203
41d18cd2 1204 /*nevent = (Int_t)histXclu[clu]->GetEntries();
3ebe30ad 1205 if(nevent!=kNHisto)
1206 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1207 histXclu[clu]->SetAddress(&h);
1208 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1209 histXclu[clu]->GetEntry(j);
1210 fHisResXclu[j][clu]->Add(h);
41d18cd2 1211 }*/
3ebe30ad 1212
1213 nevent = (Int_t)histZclu[clu]->GetEntries();
1214 if(nevent!=kNHisto)
1215 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1216 histZclu[clu]->SetAddress(&h);
1217 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1218 histZclu[clu]->GetEntry(j);
1219 fHisResZclu[j][clu]->Add(h);
1220 }
1221 }
1222
1223 nevent = (Int_t)profileResXvsX->GetEntries();
1224 if(nevent!=kNHisto)
1225 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1226 profileResXvsX->SetAddress(&p);
1227 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1228 profileResXvsX->GetEntry(j);
1229 fProfResXvsX[j]->Add(p);
1230 }
1231
1232 nevent = (Int_t)profileResZvsX->GetEntries();
1233 if(nevent!=kNHisto)
1234 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1235 profileResZvsX->SetAddress(&p);
1236 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1237 profileResZvsX->GetEntry(j);
1238 fProfResZvsX[j]->Add(p);
1239 }
1240
1241 nevent = (Int_t)profileClSizXvsX->GetEntries();
1242 if(nevent!=kNHisto)
1243 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1244 profileClSizXvsX->SetAddress(&p);
1245 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1246 profileClSizXvsX->GetEntry(j);
1247 fProfClustSizeXvsX[j]->Add(p);
1248 }
1249
1250 nevent = (Int_t)profileClSizZvsX->GetEntries();
1251 if(nevent!=kNHisto)
1252 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1253 profileClSizZvsX->SetAddress(&p);
1254 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 1255 profileClSizZvsX->GetEntry(j);
1256 fProfClustSizeZvsX[j]->Add(p);
1257 }
1258
41d18cd2 1259 nevent = (Int_t)histTrErrX->GetEntries();
1260 if(nevent!=kNHisto)
1261 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1262 histTrErrX->SetAddress(&h);
1263 for(Int_t j=0;j<kNHisto;j++){
41d18cd2 1264 histTrErrX->GetEntry(j);
1265 fHisTrackErrX[j]->Add(h);
1266 }
1267
1268 nevent = (Int_t)histTrErrZ->GetEntries();
1269 if(nevent!=kNHisto)
1270 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1271 histTrErrZ->SetAddress(&h);
1272 for(Int_t j=0;j<kNHisto;j++){
41d18cd2 1273 histTrErrZ->GetEntry(j);
1274 fHisTrackErrZ[j]->Add(h);
1275 }
1276
1277 nevent = (Int_t)histClErrX->GetEntries();
1278 if(nevent!=kNHisto)
1279 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1280 histClErrX->SetAddress(&h);
1281 for(Int_t j=0;j<kNHisto;j++){
41d18cd2 1282 histClErrX->GetEntry(j);
1283 fHisClusErrX[j]->Add(h);
1284 }
1285
1286 nevent = (Int_t)histClErrZ->GetEntries();
1287 if(nevent!=kNHisto)
1288 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
1289 histClErrZ->SetAddress(&h);
1290 for(Int_t j=0;j<kNHisto;j++){
41d18cd2 1291 histClErrZ->GetEntry(j);
1292 fHisClusErrZ[j]->Add(h);
1293 }
1294
943fb20f 1295 delete h;
1296 delete h2;
1297 delete h2i;
1298 delete p;
3ebe30ad 1299
1300 if (file) {
1301 file->Close();
943fb20f 1302 delete file;
3ebe30ad 1303 }
1304return kTRUE;
1305}