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