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