Fixes for Coverity warnings (M. van Leeuwen)
[u/mrichter/AliRoot.git] / ITS / AliITSPlaneEffSSD.cxx
CommitLineData
1cc5cedc 1/**************************************************************************
6344adcc 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 module by module efficiency of the SSD,
18// evaluated by tracks
19// (Inherits from AliITSPlaneEff)
20// Author: G.E. Bruno
21// giuseppe.bruno@ba.infn.it
22//
23///////////////////////////////////////////////////////////////////////////
24
2802d754 25/* $Id$ */
6344adcc 26
27#include <TMath.h>
3ebe30ad 28#include <TH1F.h>
29#include <TFile.h>
30#include <TTree.h>
31#include <TROOT.h>
6344adcc 32#include "AliITSPlaneEffSSD.h"
33#include "AliLog.h"
34#include "AliCDBStorage.h"
35#include "AliCDBEntry.h"
36#include "AliCDBManager.h"
37//#include "AliCDBRunRange.h"
38#include "AliITSCalibrationSSD.h"
39
40ClassImp(AliITSPlaneEffSSD)
41//______________________________________________________________________
42AliITSPlaneEffSSD::AliITSPlaneEffSSD():
3ebe30ad 43 AliITSPlaneEff(),
44 fHisResX(0),
45 fHisResZ(0),
46 fHisResXZ(0),
2802d754 47 fHisClusterSize(0),
48 fHisTrackErrX(0),
49 fHisTrackErrZ(0),
50 fHisClusErrX(0),
51 fHisClusErrZ(0){
6344adcc 52 for (UInt_t i=0; i<kNModule; i++){
18562610 53 // default constructor
6344adcc 54 fFound[i]=0;
55 fTried[i]=0;
56 }
6344adcc 57 AliDebug(1,Form("Calling default constructor"));
58}
59//______________________________________________________________________
60AliITSPlaneEffSSD::~AliITSPlaneEffSSD(){
61 // destructor
62 // Inputs:
63 // none.
64 // Outputs:
65 // none.
66 // Return:
67 // none.
3ebe30ad 68 DeleteHistos();
6344adcc 69}
70//______________________________________________________________________
3ebe30ad 71AliITSPlaneEffSSD::AliITSPlaneEffSSD(const AliITSPlaneEffSSD &s) : AliITSPlaneEff(s),
72fHisResX(0),
73fHisResZ(0),
74fHisResXZ(0),
2802d754 75fHisClusterSize(0),
76fHisTrackErrX(0),
77fHisTrackErrZ(0),
78fHisClusErrX(0),
79fHisClusErrZ(0)
6344adcc 80{
81 // Copy Constructor
82 // Inputs:
83 // AliITSPlaneEffSSD &s The original class for which
84 // this class is a copy of
85 // Outputs:
86 // none.
87 // Return:
3ebe30ad 88
89 for (UInt_t i=0; i<kNModule; i++){
90 fFound[i]=s.fFound[i];
91 fTried[i]=s.fTried[i];
92 }
93 if(fHis) {
94 InitHistos();
95 for(Int_t i=0; i<kNHisto; i++) {
96 s.fHisResX[i]->Copy(*fHisResX[i]);
97 s.fHisResZ[i]->Copy(*fHisResZ[i]);
98 s.fHisResXZ[i]->Copy(*fHisResXZ[i]);
99 s.fHisClusterSize[i]->Copy(*fHisClusterSize[i]);
2802d754 100 s.fHisTrackErrX[i]->Copy(*fHisTrackErrX[i]);
101 s.fHisTrackErrZ[i]->Copy(*fHisTrackErrZ[i]);
102 s.fHisClusErrX[i]->Copy(*fHisTrackErrZ[i]);
103 s.fHisClusErrZ[i]->Copy(*fHisClusErrZ[i]);
3ebe30ad 104 }
105 }
6344adcc 106}
107//_________________________________________________________________________
108AliITSPlaneEffSSD& AliITSPlaneEffSSD::operator+=(const AliITSPlaneEffSSD &add){
109 // Add-to-me operator
110 // Inputs:
111 // const AliITSPlaneEffSSD &add simulation class to be added
112 // Outputs:
113 // none.
114 // Return:
115 // none
116 for (UInt_t i=0; i<kNModule; i++){
117 fFound[i] += add.fFound[i];
118 fTried[i] += add.fTried[i];
119 }
3ebe30ad 120 if(fHis && add.fHis) {
121 for(Int_t i=0; i<kNHisto; i++) {
122 fHisResX[i]->Add(add.fHisResX[i]);
123 fHisResZ[i]->Add(add.fHisResZ[i]);
124 fHisResXZ[i]->Add(add.fHisResXZ[i]);
125 fHisClusterSize[i]->Add(add.fHisClusterSize[i]);
2802d754 126 fHisTrackErrX[i]->Add(add.fHisTrackErrX[i]);
127 fHisTrackErrZ[i]->Add(add.fHisTrackErrZ[i]);
128 fHisClusErrX[i]->Add(add.fHisTrackErrZ[i]);
129 fHisClusErrZ[i]->Add(add.fHisClusErrZ[i]);
3ebe30ad 130 }
131 }
6344adcc 132 return *this;
133}
134//______________________________________________________________________
135AliITSPlaneEffSSD& AliITSPlaneEffSSD::operator=(const
136 AliITSPlaneEffSSD &s){
137 // Assignment operator
138 // Inputs:
139 // AliITSPlaneEffSSD &s The original class for which
140 // this class is a copy of
141 // Outputs:
142 // none.
143 // Return:
144
145 if(this==&s) return *this;
146 s.Copy(*this);
147 return *this;
148}
149//______________________________________________________________________
150void AliITSPlaneEffSSD::Copy(TObject &obj) const {
151 // protected method. copy this to obj
152 AliITSPlaneEff::Copy(obj);
3ebe30ad 153 AliITSPlaneEffSSD& target = (AliITSPlaneEffSSD &) obj;
6344adcc 154 for(Int_t i=0;i<kNModule;i++) {
3ebe30ad 155 target.fFound[i] = fFound[i];
156 target.fTried[i] = fTried[i];
157 }
158 CopyHistos(target);
159 return;
160}
161//_______________________________________________________________________
162void AliITSPlaneEffSSD::CopyHistos(AliITSPlaneEffSSD &target) const {
163 // protected method: copy histos from this to target
164 target.fHis = fHis; // this is redundant only in some cases. Leave as it is.
165 if(fHis) {
166 target.fHisResX=new TH1F*[kNHisto];
167 target.fHisResZ=new TH1F*[kNHisto];
168 target.fHisResXZ=new TH2F*[kNHisto];
169 target.fHisClusterSize=new TH2I*[kNHisto];
2802d754 170 target.fHisTrackErrX=new TH1F*[kNHisto];
171 target.fHisTrackErrZ=new TH1F*[kNHisto];
172 target.fHisClusErrX=new TH1F*[kNHisto];
173 target.fHisClusErrZ=new TH1F*[kNHisto];
3ebe30ad 174 for(Int_t i=0; i<kNHisto; i++) {
175 target.fHisResX[i] = new TH1F(*fHisResX[i]);
176 target.fHisResZ[i] = new TH1F(*fHisResZ[i]);
177 target.fHisResXZ[i] = new TH2F(*fHisResXZ[i]);
178 target.fHisClusterSize[i] = new TH2I(*fHisClusterSize[i]);
2802d754 179 target.fHisTrackErrX[i] = new TH1F(*fHisTrackErrX[i]);
180 target.fHisTrackErrZ[i] = new TH1F(*fHisTrackErrZ[i]);
181 target.fHisClusErrX[i] = new TH1F(*fHisClusErrX[i]);
182 target.fHisClusErrZ[i] = new TH1F(*fHisClusErrZ[i]);
3ebe30ad 183 }
6344adcc 184 }
3ebe30ad 185return;
6344adcc 186}
6344adcc 187
6344adcc 188//_______________________________________________________________________
189Int_t AliITSPlaneEffSSD::GetMissingTracksForGivenEff(Double_t eff, Double_t RelErr,
190 UInt_t im) const {
191
192 // Estimate the number of tracks still to be collected to attain a
193 // given efficiency eff, with relative error RelErr
194 // Inputs:
195 // eff -> Expected efficiency (e.g. those from actual estimate)
196 // RelErr -> tollerance [0,1]
197 // im -> module number [0,1697]
198 // Outputs: none
199 // Return: the estimated n. of tracks
200 //
201if (im>=kNModule)
7167ae53 202 {AliError("GetMissingTracksForGivenEff: you asked for a non existing module");
6344adcc 203 return -1;}
204else return GetNTracksForGivenEff(eff,RelErr)-fTried[GetKey(im)];
205}
206//_________________________________________________________________________
207Double_t AliITSPlaneEffSSD::PlaneEff(const UInt_t im) const {
208// Compute the efficiency for a basic block,
209// Inputs:
210// im -> module number [0,1697]
211if (im>=kNModule)
7167ae53 212 {AliError("PlaneEff(UInt_t): you asked for a non existing module"); return -1.;}
6344adcc 213 Int_t nf=fFound[GetKey(im)];
214 Int_t nt=fTried[GetKey(im)];
215return AliITSPlaneEff::PlaneEff(nf,nt);
216}
217//_________________________________________________________________________
218Double_t AliITSPlaneEffSSD::ErrPlaneEff(const UInt_t im) const {
219 // Compute the statistical error on efficiency for a basic block,
220 // using binomial statistics
221 // Inputs:
222 // im -> module number [0,1697]
223if (im>=kNModule)
7167ae53 224 {AliError("ErrPlaneEff(UInt_t): you asked for a non existing module"); return -1.;}
6344adcc 225Int_t nf=fFound[GetKey(im)];
226Int_t nt=fTried[GetKey(im)];
227return AliITSPlaneEff::ErrPlaneEff(nf,nt);
228}
229//_________________________________________________________________________
230Bool_t AliITSPlaneEffSSD::UpDatePlaneEff(const Bool_t Kfound, const UInt_t im) {
231 // Update efficiency for a basic block
232if (im>=kNModule)
7167ae53 233 {AliError("UpDatePlaneEff: you asked for a non existing module"); return kFALSE;}
6344adcc 234 fTried[GetKey(im)]++;
235 if(Kfound) fFound[GetKey(im)]++;
236 return kTRUE;
237}
238//_________________________________________________________________________
239UInt_t AliITSPlaneEffSSD::GetKey(const UInt_t mod) const {
240 // get key given a basic block
241if(mod>=kNModule)
7167ae53 242 {AliError("GetKey: you asked for a non existing block"); return 99999;}
6344adcc 243return mod;
244}
245//__________________________________________________________________________
246UInt_t AliITSPlaneEffSSD::GetModFromKey(const UInt_t key) const {
247 // get mod. from key
248if(key>=kNModule)
7167ae53 249 {AliError("GetModFromKey: you asked for a non existing key"); return 9999;}
6344adcc 250return key;
251}
252//__________________________________________________________________________
253Double_t AliITSPlaneEffSSD::LivePlaneEff(UInt_t key) const {
254 // returns plane efficieny after adding the fraction of sensor which is bad
255if(key>=kNModule)
7167ae53 256 {AliError("LivePlaneEff: you asked for a non existing key");
6344adcc 257 return -1.;}
258Double_t leff=AliITSPlaneEff::LivePlaneEff(0); // this just for the Warning
259leff=PlaneEff(key)+GetFracBad(key);
260return leff>1?1:leff;
261}
262//____________________________________________________________________________
263Double_t AliITSPlaneEffSSD::ErrLivePlaneEff(UInt_t key) const {
264 // returns error on live plane efficiency
265if(key>=kNModule)
7167ae53 266 {AliError("ErrLivePlaneEff: you asked for a non existing key");
6344adcc 267 return -1.;}
268Int_t nf=fFound[key];
269Double_t triedInLive=GetFracLive(key)*fTried[key];
270Int_t nt=TMath::Max(nf,TMath::Nint(triedInLive));
271return AliITSPlaneEff::ErrPlaneEff(nf,nt); // for the time being: to be checked
272}
273//_____________________________________________________________________________
274Double_t AliITSPlaneEffSSD::GetFracLive(const UInt_t key) const {
3ebe30ad 275 // returns the fraction of the sensor area which is OK (neither noisy nor dead)
276 // As for now, it computes only the fraction of good strips / total strips.
277 // If this fraction is large, then the computation is a good approximation.
278 // In any case, it is a lower limit of the fraction of the live area.
279 // The next upgrades would be to add the fraction of area of superoposition
280 // between bad N-side strips and bad P-side strips.
6344adcc 281if(key>=kNModule)
7167ae53 282 {AliError("GetFracLive: you asked for a non existing key");
6344adcc 283 return -1.;}
3ebe30ad 284AliInfo("GetFracLive: it computes only the fraction of working strips (N+P side) / total strips");
6344adcc 285UInt_t bad=0;
286GetBadInModule(key,bad);
287Double_t live=bad;
288live/=(kNChip*kNSide*kNStrip);
289return 1.-live;
290}
291//_____________________________________________________________________________
292void AliITSPlaneEffSSD::GetBadInModule(const UInt_t key, UInt_t& nrBadInMod) const {
3ebe30ad 293 // returns the number of dead and noisy strips (sum of P and N sides).
6344adcc 294nrBadInMod=0;
295if(key>=kNModule)
7167ae53 296 {AliError("GetBadInModule: you asked for a non existing key");
6344adcc 297 return;}
298 // Compute the number of bad (dead+noisy) pixel in a module
299//
300if(!fInitCDBCalled)
7167ae53 301 {AliError("GetBadInModule: CDB not inizialized: call InitCDB first");
6344adcc 302 return;};
303AliCDBManager* man = AliCDBManager::Instance();
304// retrieve map of dead Pixel
305AliCDBEntry *cdbSSD = man->Get("ITS/Calib/BadChannelsSSD", fRunNumber);
306TObjArray* ssdEntry;
307if(cdbSSD) {
308 ssdEntry = (TObjArray*)cdbSSD->GetObject();
309 if(!ssdEntry)
7167ae53 310 {AliError("GetBadInChip: SSDEntry not found in CDB");
6344adcc 311 return;}
312} else {
7167ae53 313 AliError("GetBadInChip: did not find Calib/BadChannelsSSD");
6344adcc 314 return;
315}
316//
ced4d9bc 317//UInt_t mod=GetModFromKey(key);
6344adcc 318//
ced4d9bc 319//AliITSBadChannelsSSD* badchannels=(AliITSBadChannelsSSD*) ssdEntry->At(mod);
6344adcc 320// count the number of bad channels on the p side
ced4d9bc 321//nrBadInMod += (badchannels->GetBadPChannelsList()).GetSize();
6344adcc 322// add the number of bad channels on the s side
ced4d9bc 323//nrBadInMod += (badchannels->GetBadNChannelsList()).GetSize();
6344adcc 324return;
325}
326//_____________________________________________________________________________
327Double_t AliITSPlaneEffSSD::GetFracBad(const UInt_t key) const {
328 // returns 1-fractional live
329if(key>=kNModule)
7167ae53 330 {AliError("GetFracBad: you asked for a non existing key");
6344adcc 331 return -1.;}
332return 1.-GetFracLive(key);
333}
334//_____________________________________________________________________________
335Bool_t AliITSPlaneEffSSD::WriteIntoCDB() const {
336// write onto CDB
337if(!fInitCDBCalled)
7167ae53 338 {AliError("WriteIntoCDB: CDB not inizialized. Call InitCDB first");
6344adcc 339 return kFALSE;}
340// to be written properly: now only for debugging
341 AliCDBMetaData *md= new AliCDBMetaData(); // metaData describing the object
342 md->SetObjectClassName("AliITSPlaneEff");
343 md->SetResponsible("Giuseppe Eugenio Bruno");
344 md->SetBeamPeriod(0);
345 md->SetAliRootVersion("head 02/01/08"); //root version
346 AliCDBId id("ITS/PlaneEff/PlaneEffSSD",0,AliCDBRunRange::Infinity());
347 AliITSPlaneEffSSD eff;
348 eff=*this;
349 Bool_t r=AliCDBManager::Instance()->GetDefaultStorage()->Put(&eff,id,md);
350 delete md;
351 return r;
352}
353//_____________________________________________________________________________
354Bool_t AliITSPlaneEffSSD::ReadFromCDB() {
355// read from CDB
356if(!fInitCDBCalled)
7167ae53 357 {AliError("ReadFromCDB: CDB not inizialized. Call InitCDB first");
6344adcc 358 return kFALSE;}
6344adcc 359AliCDBEntry *cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSSD",fRunNumber);
1cc5cedc 360if(!cdbEntry) return kFALSE;
6344adcc 361AliITSPlaneEffSSD* eff= (AliITSPlaneEffSSD*)cdbEntry->GetObject();
362if(this==eff) return kFALSE;
3ebe30ad 363if(fHis) CopyHistos(*eff); // If histos already exist then copy them to eff
364eff->Copy(*this); // copy everything (statistics and histos) from eff to this
6344adcc 365return kTRUE;
366}
7167ae53 367//_____________________________________________________________________________
1cc5cedc 368Bool_t AliITSPlaneEffSSD::AddFromCDB(AliCDBId *cdbId) {
18562610 369// Read (actually add the statistics) plane eff. from Data Base
1cc5cedc 370AliCDBEntry *cdbEntry=0;
371if (!cdbId) {
372 if(!fInitCDBCalled)
373 {AliError("ReadFromCDB: CDB not inizialized. Call InitCDB first"); return kFALSE;}
374 cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSSD",fRunNumber);
375} else {
376 cdbEntry = AliCDBManager::Instance()->Get(*cdbId);
377}
378if(!cdbEntry) return kFALSE;
379AliITSPlaneEffSSD* eff= (AliITSPlaneEffSSD*)cdbEntry->GetObject();
380*this+=*eff;
381return kTRUE;
382}
383//_____________________________________________________________________________
7167ae53 384UInt_t AliITSPlaneEffSSD::GetKeyFromDetLocCoord(Int_t ilay, Int_t idet,
385 Float_t, Float_t) const {
386// method to locate a basic block from Detector Local coordinate (to be used in tracking)
387UInt_t key=999999;
388if(ilay<4 || ilay>5)
389 {AliError("GetKeyFromDetLocCoord: you asked for a non existing layer");
390 return key;}
391if(ilay==4 && (idet<0 || idet>747))
392 {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
393 return key;}
394if(ilay==5 && (idet<0 || idet>949))
395 {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
396 return key;}
397
398UInt_t mod=idet;
41d18cd2 399if(ilay==5) mod+=748;
7167ae53 400key=GetKey(mod);
401return key;
402}
3ebe30ad 403//__________________________________________________________
404void AliITSPlaneEffSSD::InitHistos() {
405 // for the moment let's create the histograms
406 // module by module
407 TString histnameResX="HistResX_mod_",aux;
408 TString histnameResZ="HistResZ_mod_";
409 TString histnameResXZ="HistResXZ_mod_";
410 TString histnameClusterType="HistClusterType_mod_";
2802d754 411 TString histnameTrackErrX="HistTrackErrX_mod_";
412 TString histnameTrackErrZ="HistTrackErrZ_mod_";
413 TString histnameClusErrX="HistClusErrX_mod_";
414 TString histnameClusErrZ="HistClusErrZ_mod_";
3ebe30ad 415//
f61b891f 416
417 TH1::AddDirectory(kFALSE);
418
3ebe30ad 419 fHisResX=new TH1F*[kNHisto];
420 fHisResZ=new TH1F*[kNHisto];
421 fHisResXZ=new TH2F*[kNHisto];
422 fHisClusterSize=new TH2I*[kNHisto];
2802d754 423 fHisTrackErrX=new TH1F*[kNHisto];
424 fHisTrackErrZ=new TH1F*[kNHisto];
425 fHisClusErrX=new TH1F*[kNHisto];
426 fHisClusErrZ=new TH1F*[kNHisto];
3ebe30ad 427
428 for (Int_t nhist=0;nhist<kNHisto;nhist++){
429 aux=histnameResX;
430 aux+=nhist;
061c42a0 431 fHisResX[nhist]=new TH1F("histname","histname",500,-0.10,0.10); // +- 1000 micron; 1 bin=4 micron
3ebe30ad 432 fHisResX[nhist]->SetName(aux.Data());
433 fHisResX[nhist]->SetTitle(aux.Data());
434
435 aux=histnameResZ;
436 aux+=nhist;
061c42a0 437 fHisResZ[nhist]=new TH1F("histname","histname",750,-0.75,0.75); // +-5000 micron; 1 bin=20 micron
3ebe30ad 438 fHisResZ[nhist]->SetName(aux.Data());
439 fHisResZ[nhist]->SetTitle(aux.Data());
440
441 aux=histnameResXZ;
442 aux+=nhist;
061c42a0 443 fHisResXZ[nhist]=new TH2F("histname","histname",40,-0.04,0.04,40,-0.32,0.32); // binning:
444 // 20 micron in x;
445 // 160 micron in z;
3ebe30ad 446 fHisResXZ[nhist]->SetName(aux.Data());
447 fHisResXZ[nhist]->SetTitle(aux.Data());
448
449 aux=histnameClusterType;
450 aux+=nhist;
451 fHisClusterSize[nhist]=new TH2I("histname","histname",6,0.5,6.5,6,0.5,6.5);
452 fHisClusterSize[nhist]->SetName(aux.Data());
453 fHisClusterSize[nhist]->SetTitle(aux.Data());
454
2802d754 455 aux=histnameTrackErrX;
456 aux+=nhist;
061c42a0 457 fHisTrackErrX[nhist]=new TH1F("histname","histname",300,0.,0.24); // 0-2400 micron; 1 bin=8 micron
2802d754 458 fHisTrackErrX[nhist]->SetName(aux.Data());
459 fHisTrackErrX[nhist]->SetTitle(aux.Data());
460
461 aux=histnameTrackErrZ;
462 aux+=nhist;
061c42a0 463 fHisTrackErrZ[nhist]=new TH1F("histname","histname",300,0.,0.48); // 0-4800 micron; 1 bin=16 micron
2802d754 464 fHisTrackErrZ[nhist]->SetName(aux.Data());
465 fHisTrackErrZ[nhist]->SetTitle(aux.Data());
466
467 aux=histnameClusErrX;
468 aux+=nhist;
061c42a0 469 fHisClusErrX[nhist]=new TH1F("histname","histname",300,0.,0.24); // 0-2400 micron; 1 bin=8 micron
2802d754 470 fHisClusErrX[nhist]->SetName(aux.Data());
471 fHisClusErrX[nhist]->SetTitle(aux.Data());
472
473 aux=histnameClusErrZ;
474 aux+=nhist;
061c42a0 475 fHisClusErrZ[nhist]=new TH1F("histname","histname",200,0.,0.32); // 0-1600 micron; 1 bin=16 micron
2802d754 476 fHisClusErrZ[nhist]->SetName(aux.Data());
477 fHisClusErrZ[nhist]->SetTitle(aux.Data());
478
3ebe30ad 479 }
f61b891f 480
481 TH1::AddDirectory(kTRUE);
482
3ebe30ad 483return;
484}
485//__________________________________________________________
486void AliITSPlaneEffSSD::DeleteHistos() {
18562610 487// Delete histograms and remove them from memory
3ebe30ad 488 if(fHisResX) {
489 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResX[i];
490 delete [] fHisResX; fHisResX=0;
491 }
492 if(fHisResZ) {
493 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResZ[i];
494 delete [] fHisResZ; fHisResZ=0;
495 }
496 if(fHisResXZ) {
497 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResXZ[i];
498 delete [] fHisResXZ; fHisResXZ=0;
499 }
500 if(fHisClusterSize) {
501 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusterSize[i];
502 delete [] fHisClusterSize; fHisClusterSize=0;
503 }
2802d754 504 if(fHisTrackErrX) {
505 for (Int_t i=0; i<kNHisto; i++ ) delete fHisTrackErrX[i];
506 delete [] fHisTrackErrX; fHisTrackErrX=0;
507 }
508 if(fHisTrackErrZ) {
509 for (Int_t i=0; i<kNHisto; i++ ) delete fHisTrackErrZ[i];
510 delete [] fHisTrackErrZ; fHisTrackErrZ=0;
511 }
512 if(fHisClusErrX) {
513 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusErrX[i];
514 delete [] fHisClusErrX; fHisClusErrX=0;
515 }
516 if(fHisClusErrZ) {
517 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusErrZ[i];
518 delete [] fHisClusErrZ; fHisClusErrZ=0;
519 }
3ebe30ad 520
521return;
522}
523//__________________________________________________________
524Bool_t AliITSPlaneEffSSD::FillHistos(UInt_t key, Bool_t found,
879cdb02 525 Float_t *tr, Float_t *clu, Int_t *csize, Float_t*) {
3ebe30ad 526// this method fill the histograms
527// input: - key: unique key of the basic block
528// - found: Boolean to asses whether a cluster has been associated to the track or not
1cc5cedc 529// - tr[0],tr[1] local X and Z coordinates of the track prediction, respectively
530// - tr[2],tr[3] error on local X and Z coordinates of the track prediction, respectively
531// - clu[0],clu[1] local X and Z coordinates of the cluster associated to the track, respectively
532// - clu[2],clu[3] error on local X and Z coordinates of the cluster associated to the track, respectively
533// - csize[0][1] cluster size in X and Z, respectively
3ebe30ad 534// output: kTRUE if filling was succesfull kFALSE otherwise
535// side effects: updating of the histograms.
536//
537 if (!fHis) {
538 AliWarning("FillHistos: histograms do not exist! Call SetCreateHistos(kTRUE) first");
539 return kFALSE;
540 }
541 if(key>=kNModule)
542 {AliWarning("FillHistos: you asked for a non existing key"); return kFALSE;}
543 Int_t id=GetModFromKey(key);
544 if(id>=kNHisto)
545 {AliWarning("FillHistos: you want to fill a non-existing histos"); return kFALSE;}
546 if(found) {
1cc5cedc 547 Float_t resx=tr[0]-clu[0];
548 Float_t resz=tr[1]-clu[1];
3ebe30ad 549 fHisResX[id]->Fill(resx);
550 fHisResZ[id]->Fill(resz);
551 fHisResXZ[id]->Fill(resx,resz);
1cc5cedc 552 fHisClusterSize[id]->Fill((Double_t)csize[0],(Double_t)csize[1]);
3ebe30ad 553 }
2802d754 554 fHisTrackErrX[id]->Fill(tr[2]);
555 fHisTrackErrZ[id]->Fill(tr[3]);
556 fHisClusErrX[id]->Fill(clu[2]);
557 fHisClusErrZ[id]->Fill(clu[3]);
3ebe30ad 558 return kTRUE;
559}
560//__________________________________________________________
561Bool_t AliITSPlaneEffSSD::WriteHistosToFile(TString filename, Option_t* option) {
562 //
563 // Saves the histograms into a tree and saves the trees into a file
564 //
565 if (!fHis) return kFALSE;
5af4a2d0 566 if (filename.IsNull() || filename.IsWhitespace()) {
3ebe30ad 567 AliWarning("WriteHistosToFile: null output filename!");
568 return kFALSE;
569 }
943fb20f 570
3ebe30ad 571 TFile *hFile=new TFile(filename.Data(),option,
572 "The File containing the TREEs with ITS PlaneEff Histos");
573 TTree *SSDTree=new TTree("SSDTree","Tree whith Residuals and Cluster Type distributions for SSD");
574 TH1F *histZ,*histX;
575 TH2F *histXZ;
576 TH2I *histClusterType;
2802d754 577 TH1F *histTrErrZ,*histTrErrX;
578 TH1F *histClErrZ,*histClErrX;
3ebe30ad 579
580 histZ=new TH1F();
581 histX=new TH1F();
582 histXZ=new TH2F();
583 histClusterType=new TH2I();
2802d754 584 histTrErrX=new TH1F();
585 histTrErrZ=new TH1F();
586 histClErrX=new TH1F();
587 histClErrZ=new TH1F();
3ebe30ad 588
589 SSDTree->Branch("histX","TH1F",&histX,128000,0);
590 SSDTree->Branch("histZ","TH1F",&histZ,128000,0);
591 SSDTree->Branch("histXZ","TH2F",&histXZ,128000,0);
592 SSDTree->Branch("histClusterType","TH2I",&histClusterType,128000,0);
2802d754 593 SSDTree->Branch("histTrErrX","TH1F",&histTrErrX,128000,0);
594 SSDTree->Branch("histTrErrZ","TH1F",&histTrErrZ,128000,0);
595 SSDTree->Branch("histClErrX","TH1F",&histClErrX,128000,0);
596 SSDTree->Branch("histClErrZ","TH1F",&histClErrZ,128000,0);
3ebe30ad 597
598 for(Int_t j=0;j<kNHisto;j++){
599 histX=fHisResX[j];
600 histZ=fHisResZ[j];
601 histXZ=fHisResXZ[j];
602 histClusterType=fHisClusterSize[j];
2802d754 603 histTrErrX=fHisTrackErrX[j];
604 histTrErrZ=fHisTrackErrZ[j];
605 histClErrX=fHisClusErrX[j];
606 histClErrZ=fHisClusErrZ[j];
3ebe30ad 607
608 SSDTree->Fill();
609 }
610 hFile->Write();
611 hFile->Close();
612return kTRUE;
613}
614//__________________________________________________________
615Bool_t AliITSPlaneEffSSD::ReadHistosFromFile(TString filename) {
616 //
617 // Read histograms from an already existing file
618 //
619 if (!fHis) return kFALSE;
5af4a2d0 620 if (filename.IsNull() || filename.IsWhitespace()) {
3ebe30ad 621 AliWarning("ReadHistosFromFile: incorrect output filename!");
622 return kFALSE;
623 }
3ebe30ad 624
625 TH1F *h = 0;
626 TH2F *h2 = 0;
627 TH2I *h2i= 0;
628
629 TFile *file=TFile::Open(filename.Data(),"READONLY");
630
631 if (!file || file->IsZombie()) {
632 AliWarning(Form("Can't open %s !",filename.Data()));
633 delete file;
634 return kFALSE;
635 }
636 TTree *tree = (TTree*) file->Get("SSDTree");
637
638 TBranch *histX = (TBranch*) tree->GetBranch("histX");
639 TBranch *histZ = (TBranch*) tree->GetBranch("histZ");
640 TBranch *histXZ = (TBranch*) tree->GetBranch("histXZ");
641 TBranch *histClusterType = (TBranch*) tree->GetBranch("histClusterType");
2802d754 642 TBranch *histTrErrX = (TBranch*) tree->GetBranch("histTrErrX");
643 TBranch *histTrErrZ = (TBranch*) tree->GetBranch("histTrErrZ");
644 TBranch *histClErrX = (TBranch*) tree->GetBranch("histClErrX");
645 TBranch *histClErrZ = (TBranch*) tree->GetBranch("histClErrZ");
3ebe30ad 646
647 gROOT->cd();
648
649 Int_t nevent = (Int_t)histX->GetEntries();
650 if(nevent!=kNHisto)
651 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
652 histX->SetAddress(&h);
653 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 654 histX->GetEntry(j);
655 fHisResX[j]->Add(h);
656 }
657
658 nevent = (Int_t)histZ->GetEntries();
659 if(nevent!=kNHisto)
660 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
661 histZ->SetAddress(&h);
662 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 663 histZ->GetEntry(j);
664 fHisResZ[j]->Add(h);
665 }
666
667 nevent = (Int_t)histXZ->GetEntries();
668 if(nevent!=kNHisto)
669 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
670 histXZ->SetAddress(&h2);
671 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 672 histXZ->GetEntry(j);
673 fHisResXZ[j]->Add(h2);
674 }
675
676 nevent = (Int_t)histClusterType->GetEntries();
677 if(nevent!=kNHisto)
678 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
679 histClusterType->SetAddress(&h2i);
680 for(Int_t j=0;j<kNHisto;j++){
3ebe30ad 681 histClusterType->GetEntry(j);
682 fHisClusterSize[j]->Add(h2i);
683 }
684
2802d754 685 nevent = (Int_t)histTrErrX->GetEntries();
686 if(nevent!=kNHisto)
687 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
688 histTrErrX->SetAddress(&h);
689 for(Int_t j=0;j<kNHisto;j++){
2802d754 690 histTrErrX->GetEntry(j);
691 fHisTrackErrX[j]->Add(h);
692 }
693
694 nevent = (Int_t)histTrErrZ->GetEntries();
695 if(nevent!=kNHisto)
696 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
697 histTrErrZ->SetAddress(&h);
698 for(Int_t j=0;j<kNHisto;j++){
2802d754 699 histTrErrZ->GetEntry(j);
700 fHisTrackErrZ[j]->Add(h);
701 }
702
703 nevent = (Int_t)histClErrX->GetEntries();
704 if(nevent!=kNHisto)
705 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
706 histClErrX->SetAddress(&h);
707 for(Int_t j=0;j<kNHisto;j++){
943fb20f 708 //delete h; h=0;
2802d754 709 histClErrX->GetEntry(j);
710 fHisClusErrX[j]->Add(h);
711 }
712
713 nevent = (Int_t)histClErrZ->GetEntries();
714 if(nevent!=kNHisto)
715 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
716 histClErrZ->SetAddress(&h);
717 for(Int_t j=0;j<kNHisto;j++){
943fb20f 718 //delete h; h=0;
2802d754 719 histClErrZ->GetEntry(j);
720 fHisClusErrZ[j]->Add(h);
721 }
722
943fb20f 723 delete h;
724 delete h2;
725 delete h2i;
3ebe30ad 726
727 if (file) {
728 file->Close();
943fb20f 729 delete file;
3ebe30ad 730 }
731return kTRUE;
732}
061c42a0 733