Changing once more (hopefully we get it correct this time...) the logic to trig the...
[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++){
53 fFound[i]=0;
54 fTried[i]=0;
55 }
56 // default constructor
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}
85f5e9c2 187/* Commented out by M.Masera 8/3/08
6344adcc 188//______________________________________________________________________
189AliITSPlaneEff& AliITSPlaneEffSSD::operator=(const
190 AliITSPlaneEff &s){
191 // Assignment operator
192 // Inputs:
193 // AliITSPlaneEffSSD &s The original class for which
194 // this class is a copy of
195 // Outputs:
196 // none.
197 // Return:
198
199 if(&s == this) return *this;
7167ae53 200 AliError("operator=: Not allowed to make a =, use default creater instead");
6344adcc 201 return *this;
202}
85f5e9c2 203*/
6344adcc 204//_______________________________________________________________________
205Int_t AliITSPlaneEffSSD::GetMissingTracksForGivenEff(Double_t eff, Double_t RelErr,
206 UInt_t im) const {
207
208 // Estimate the number of tracks still to be collected to attain a
209 // given efficiency eff, with relative error RelErr
210 // Inputs:
211 // eff -> Expected efficiency (e.g. those from actual estimate)
212 // RelErr -> tollerance [0,1]
213 // im -> module number [0,1697]
214 // Outputs: none
215 // Return: the estimated n. of tracks
216 //
217if (im>=kNModule)
7167ae53 218 {AliError("GetMissingTracksForGivenEff: you asked for a non existing module");
6344adcc 219 return -1;}
220else return GetNTracksForGivenEff(eff,RelErr)-fTried[GetKey(im)];
221}
222//_________________________________________________________________________
223Double_t AliITSPlaneEffSSD::PlaneEff(const UInt_t im) const {
224// Compute the efficiency for a basic block,
225// Inputs:
226// im -> module number [0,1697]
227if (im>=kNModule)
7167ae53 228 {AliError("PlaneEff(UInt_t): you asked for a non existing module"); return -1.;}
6344adcc 229 Int_t nf=fFound[GetKey(im)];
230 Int_t nt=fTried[GetKey(im)];
231return AliITSPlaneEff::PlaneEff(nf,nt);
232}
233//_________________________________________________________________________
234Double_t AliITSPlaneEffSSD::ErrPlaneEff(const UInt_t im) const {
235 // Compute the statistical error on efficiency for a basic block,
236 // using binomial statistics
237 // Inputs:
238 // im -> module number [0,1697]
239if (im>=kNModule)
7167ae53 240 {AliError("ErrPlaneEff(UInt_t): you asked for a non existing module"); return -1.;}
6344adcc 241Int_t nf=fFound[GetKey(im)];
242Int_t nt=fTried[GetKey(im)];
243return AliITSPlaneEff::ErrPlaneEff(nf,nt);
244}
245//_________________________________________________________________________
246Bool_t AliITSPlaneEffSSD::UpDatePlaneEff(const Bool_t Kfound, const UInt_t im) {
247 // Update efficiency for a basic block
248if (im>=kNModule)
7167ae53 249 {AliError("UpDatePlaneEff: you asked for a non existing module"); return kFALSE;}
6344adcc 250 fTried[GetKey(im)]++;
251 if(Kfound) fFound[GetKey(im)]++;
252 return kTRUE;
253}
254//_________________________________________________________________________
255UInt_t AliITSPlaneEffSSD::GetKey(const UInt_t mod) const {
256 // get key given a basic block
257if(mod>=kNModule)
7167ae53 258 {AliError("GetKey: you asked for a non existing block"); return 99999;}
6344adcc 259return mod;
260}
261//__________________________________________________________________________
262UInt_t AliITSPlaneEffSSD::GetModFromKey(const UInt_t key) const {
263 // get mod. from key
264if(key>=kNModule)
7167ae53 265 {AliError("GetModFromKey: you asked for a non existing key"); return 9999;}
6344adcc 266return key;
267}
268//__________________________________________________________________________
269Double_t AliITSPlaneEffSSD::LivePlaneEff(UInt_t key) const {
270 // returns plane efficieny after adding the fraction of sensor which is bad
271if(key>=kNModule)
7167ae53 272 {AliError("LivePlaneEff: you asked for a non existing key");
6344adcc 273 return -1.;}
274Double_t leff=AliITSPlaneEff::LivePlaneEff(0); // this just for the Warning
275leff=PlaneEff(key)+GetFracBad(key);
276return leff>1?1:leff;
277}
278//____________________________________________________________________________
279Double_t AliITSPlaneEffSSD::ErrLivePlaneEff(UInt_t key) const {
280 // returns error on live plane efficiency
281if(key>=kNModule)
7167ae53 282 {AliError("ErrLivePlaneEff: you asked for a non existing key");
6344adcc 283 return -1.;}
284Int_t nf=fFound[key];
285Double_t triedInLive=GetFracLive(key)*fTried[key];
286Int_t nt=TMath::Max(nf,TMath::Nint(triedInLive));
287return AliITSPlaneEff::ErrPlaneEff(nf,nt); // for the time being: to be checked
288}
289//_____________________________________________________________________________
290Double_t AliITSPlaneEffSSD::GetFracLive(const UInt_t key) const {
3ebe30ad 291 // returns the fraction of the sensor area which is OK (neither noisy nor dead)
292 // As for now, it computes only the fraction of good strips / total strips.
293 // If this fraction is large, then the computation is a good approximation.
294 // In any case, it is a lower limit of the fraction of the live area.
295 // The next upgrades would be to add the fraction of area of superoposition
296 // between bad N-side strips and bad P-side strips.
6344adcc 297if(key>=kNModule)
7167ae53 298 {AliError("GetFracLive: you asked for a non existing key");
6344adcc 299 return -1.;}
3ebe30ad 300AliInfo("GetFracLive: it computes only the fraction of working strips (N+P side) / total strips");
6344adcc 301UInt_t bad=0;
302GetBadInModule(key,bad);
303Double_t live=bad;
304live/=(kNChip*kNSide*kNStrip);
305return 1.-live;
306}
307//_____________________________________________________________________________
308void AliITSPlaneEffSSD::GetBadInModule(const UInt_t key, UInt_t& nrBadInMod) const {
3ebe30ad 309 // returns the number of dead and noisy strips (sum of P and N sides).
6344adcc 310nrBadInMod=0;
311if(key>=kNModule)
7167ae53 312 {AliError("GetBadInModule: you asked for a non existing key");
6344adcc 313 return;}
314 // Compute the number of bad (dead+noisy) pixel in a module
315//
316if(!fInitCDBCalled)
7167ae53 317 {AliError("GetBadInModule: CDB not inizialized: call InitCDB first");
6344adcc 318 return;};
319AliCDBManager* man = AliCDBManager::Instance();
320// retrieve map of dead Pixel
321AliCDBEntry *cdbSSD = man->Get("ITS/Calib/BadChannelsSSD", fRunNumber);
322TObjArray* ssdEntry;
323if(cdbSSD) {
324 ssdEntry = (TObjArray*)cdbSSD->GetObject();
325 if(!ssdEntry)
7167ae53 326 {AliError("GetBadInChip: SSDEntry not found in CDB");
6344adcc 327 return;}
328} else {
7167ae53 329 AliError("GetBadInChip: did not find Calib/BadChannelsSSD");
6344adcc 330 return;
331}
332//
ced4d9bc 333//UInt_t mod=GetModFromKey(key);
6344adcc 334//
ced4d9bc 335//AliITSBadChannelsSSD* badchannels=(AliITSBadChannelsSSD*) ssdEntry->At(mod);
6344adcc 336// count the number of bad channels on the p side
ced4d9bc 337//nrBadInMod += (badchannels->GetBadPChannelsList()).GetSize();
6344adcc 338// add the number of bad channels on the s side
ced4d9bc 339//nrBadInMod += (badchannels->GetBadNChannelsList()).GetSize();
6344adcc 340return;
341}
342//_____________________________________________________________________________
343Double_t AliITSPlaneEffSSD::GetFracBad(const UInt_t key) const {
344 // returns 1-fractional live
345if(key>=kNModule)
7167ae53 346 {AliError("GetFracBad: you asked for a non existing key");
6344adcc 347 return -1.;}
348return 1.-GetFracLive(key);
349}
350//_____________________________________________________________________________
351Bool_t AliITSPlaneEffSSD::WriteIntoCDB() const {
352// write onto CDB
353if(!fInitCDBCalled)
7167ae53 354 {AliError("WriteIntoCDB: CDB not inizialized. Call InitCDB first");
6344adcc 355 return kFALSE;}
356// to be written properly: now only for debugging
357 AliCDBMetaData *md= new AliCDBMetaData(); // metaData describing the object
358 md->SetObjectClassName("AliITSPlaneEff");
359 md->SetResponsible("Giuseppe Eugenio Bruno");
360 md->SetBeamPeriod(0);
361 md->SetAliRootVersion("head 02/01/08"); //root version
362 AliCDBId id("ITS/PlaneEff/PlaneEffSSD",0,AliCDBRunRange::Infinity());
363 AliITSPlaneEffSSD eff;
364 eff=*this;
365 Bool_t r=AliCDBManager::Instance()->GetDefaultStorage()->Put(&eff,id,md);
366 delete md;
367 return r;
368}
369//_____________________________________________________________________________
370Bool_t AliITSPlaneEffSSD::ReadFromCDB() {
371// read from CDB
372if(!fInitCDBCalled)
7167ae53 373 {AliError("ReadFromCDB: CDB not inizialized. Call InitCDB first");
6344adcc 374 return kFALSE;}
6344adcc 375AliCDBEntry *cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSSD",fRunNumber);
1cc5cedc 376if(!cdbEntry) return kFALSE;
6344adcc 377AliITSPlaneEffSSD* eff= (AliITSPlaneEffSSD*)cdbEntry->GetObject();
378if(this==eff) return kFALSE;
3ebe30ad 379if(fHis) CopyHistos(*eff); // If histos already exist then copy them to eff
380eff->Copy(*this); // copy everything (statistics and histos) from eff to this
6344adcc 381return kTRUE;
382}
7167ae53 383//_____________________________________________________________________________
1cc5cedc 384Bool_t AliITSPlaneEffSSD::AddFromCDB(AliCDBId *cdbId) {
385AliCDBEntry *cdbEntry=0;
386if (!cdbId) {
387 if(!fInitCDBCalled)
388 {AliError("ReadFromCDB: CDB not inizialized. Call InitCDB first"); return kFALSE;}
389 cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSSD",fRunNumber);
390} else {
391 cdbEntry = AliCDBManager::Instance()->Get(*cdbId);
392}
393if(!cdbEntry) return kFALSE;
394AliITSPlaneEffSSD* eff= (AliITSPlaneEffSSD*)cdbEntry->GetObject();
395*this+=*eff;
396return kTRUE;
397}
398//_____________________________________________________________________________
7167ae53 399UInt_t AliITSPlaneEffSSD::GetKeyFromDetLocCoord(Int_t ilay, Int_t idet,
400 Float_t, Float_t) const {
401// method to locate a basic block from Detector Local coordinate (to be used in tracking)
402UInt_t key=999999;
403if(ilay<4 || ilay>5)
404 {AliError("GetKeyFromDetLocCoord: you asked for a non existing layer");
405 return key;}
406if(ilay==4 && (idet<0 || idet>747))
407 {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
408 return key;}
409if(ilay==5 && (idet<0 || idet>949))
410 {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
411 return key;}
412
413UInt_t mod=idet;
41d18cd2 414if(ilay==5) mod+=748;
7167ae53 415key=GetKey(mod);
416return key;
417}
3ebe30ad 418//__________________________________________________________
419void AliITSPlaneEffSSD::InitHistos() {
420 // for the moment let's create the histograms
421 // module by module
422 TString histnameResX="HistResX_mod_",aux;
423 TString histnameResZ="HistResZ_mod_";
424 TString histnameResXZ="HistResXZ_mod_";
425 TString histnameClusterType="HistClusterType_mod_";
2802d754 426 TString histnameTrackErrX="HistTrackErrX_mod_";
427 TString histnameTrackErrZ="HistTrackErrZ_mod_";
428 TString histnameClusErrX="HistClusErrX_mod_";
429 TString histnameClusErrZ="HistClusErrZ_mod_";
3ebe30ad 430//
f61b891f 431
432 TH1::AddDirectory(kFALSE);
433
3ebe30ad 434 fHisResX=new TH1F*[kNHisto];
435 fHisResZ=new TH1F*[kNHisto];
436 fHisResXZ=new TH2F*[kNHisto];
437 fHisClusterSize=new TH2I*[kNHisto];
2802d754 438 fHisTrackErrX=new TH1F*[kNHisto];
439 fHisTrackErrZ=new TH1F*[kNHisto];
440 fHisClusErrX=new TH1F*[kNHisto];
441 fHisClusErrZ=new TH1F*[kNHisto];
3ebe30ad 442
443 for (Int_t nhist=0;nhist<kNHisto;nhist++){
444 aux=histnameResX;
445 aux+=nhist;
446 fHisResX[nhist]=new TH1F("histname","histname",500,-0.05,0.05); // +- 500 micron; 1 bin=2 micron
447 fHisResX[nhist]->SetName(aux.Data());
448 fHisResX[nhist]->SetTitle(aux.Data());
449
450 aux=histnameResZ;
451 aux+=nhist;
452 fHisResZ[nhist]=new TH1F("histname","histname",500,-0.50,0.50); // +-5000 micron; 1 bin=20 micron
453 fHisResZ[nhist]->SetName(aux.Data());
454 fHisResZ[nhist]->SetTitle(aux.Data());
455
456 aux=histnameResXZ;
457 aux+=nhist;
458 fHisResXZ[nhist]=new TH2F("histname","histname",40,-0.02,0.02,40,-0.16,0.16); // binning:
459 // 10 micron in x;
460 // 80 micron in z;
461 fHisResXZ[nhist]->SetName(aux.Data());
462 fHisResXZ[nhist]->SetTitle(aux.Data());
463
464 aux=histnameClusterType;
465 aux+=nhist;
466 fHisClusterSize[nhist]=new TH2I("histname","histname",6,0.5,6.5,6,0.5,6.5);
467 fHisClusterSize[nhist]->SetName(aux.Data());
468 fHisClusterSize[nhist]->SetTitle(aux.Data());
469
2802d754 470 aux=histnameTrackErrX;
471 aux+=nhist;
472 fHisTrackErrX[nhist]=new TH1F("histname","histname",200,0.,0.08); // 0-800 micron; 1 bin=4 micron
473 fHisTrackErrX[nhist]->SetName(aux.Data());
474 fHisTrackErrX[nhist]->SetTitle(aux.Data());
475
476 aux=histnameTrackErrZ;
477 aux+=nhist;
478 fHisTrackErrZ[nhist]=new TH1F("histname","histname",200,0.,0.32); // 0-3200 micron; 1 bin=16 micron
479 fHisTrackErrZ[nhist]->SetName(aux.Data());
480 fHisTrackErrZ[nhist]->SetTitle(aux.Data());
481
482 aux=histnameClusErrX;
483 aux+=nhist;
484 fHisClusErrX[nhist]=new TH1F("histname","histname",200,0.,0.08); // 0-800 micron; 1 bin=4 micron
485 fHisClusErrX[nhist]->SetName(aux.Data());
486 fHisClusErrX[nhist]->SetTitle(aux.Data());
487
488 aux=histnameClusErrZ;
489 aux+=nhist;
490 fHisClusErrZ[nhist]=new TH1F("histname","histname",200,0.,0.16); // 0-1600 micron; 1 bin=8 micron
491 fHisClusErrZ[nhist]->SetName(aux.Data());
492 fHisClusErrZ[nhist]->SetTitle(aux.Data());
493
3ebe30ad 494 }
f61b891f 495
496 TH1::AddDirectory(kTRUE);
497
3ebe30ad 498return;
499}
500//__________________________________________________________
501void AliITSPlaneEffSSD::DeleteHistos() {
502 if(fHisResX) {
503 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResX[i];
504 delete [] fHisResX; fHisResX=0;
505 }
506 if(fHisResZ) {
507 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResZ[i];
508 delete [] fHisResZ; fHisResZ=0;
509 }
510 if(fHisResXZ) {
511 for (Int_t i=0; i<kNHisto; i++ ) delete fHisResXZ[i];
512 delete [] fHisResXZ; fHisResXZ=0;
513 }
514 if(fHisClusterSize) {
515 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusterSize[i];
516 delete [] fHisClusterSize; fHisClusterSize=0;
517 }
2802d754 518 if(fHisTrackErrX) {
519 for (Int_t i=0; i<kNHisto; i++ ) delete fHisTrackErrX[i];
520 delete [] fHisTrackErrX; fHisTrackErrX=0;
521 }
522 if(fHisTrackErrZ) {
523 for (Int_t i=0; i<kNHisto; i++ ) delete fHisTrackErrZ[i];
524 delete [] fHisTrackErrZ; fHisTrackErrZ=0;
525 }
526 if(fHisClusErrX) {
527 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusErrX[i];
528 delete [] fHisClusErrX; fHisClusErrX=0;
529 }
530 if(fHisClusErrZ) {
531 for (Int_t i=0; i<kNHisto; i++ ) delete fHisClusErrZ[i];
532 delete [] fHisClusErrZ; fHisClusErrZ=0;
533 }
3ebe30ad 534
535return;
536}
537//__________________________________________________________
538Bool_t AliITSPlaneEffSSD::FillHistos(UInt_t key, Bool_t found,
1cc5cedc 539 // Float_t tXZ[2], Float_t cXZ[2], Int_t ctXZ[2]) {
540 Float_t *tr, Float_t *clu, Int_t *csize) {
3ebe30ad 541// this method fill the histograms
542// input: - key: unique key of the basic block
543// - found: Boolean to asses whether a cluster has been associated to the track or not
1cc5cedc 544// - tr[0],tr[1] local X and Z coordinates of the track prediction, respectively
545// - tr[2],tr[3] error on local X and Z coordinates of the track prediction, respectively
546// - clu[0],clu[1] local X and Z coordinates of the cluster associated to the track, respectively
547// - clu[2],clu[3] error on local X and Z coordinates of the cluster associated to the track, respectively
548// - csize[0][1] cluster size in X and Z, respectively
3ebe30ad 549// output: kTRUE if filling was succesfull kFALSE otherwise
550// side effects: updating of the histograms.
551//
552 if (!fHis) {
553 AliWarning("FillHistos: histograms do not exist! Call SetCreateHistos(kTRUE) first");
554 return kFALSE;
555 }
556 if(key>=kNModule)
557 {AliWarning("FillHistos: you asked for a non existing key"); return kFALSE;}
558 Int_t id=GetModFromKey(key);
559 if(id>=kNHisto)
560 {AliWarning("FillHistos: you want to fill a non-existing histos"); return kFALSE;}
561 if(found) {
1cc5cedc 562 Float_t resx=tr[0]-clu[0];
563 Float_t resz=tr[1]-clu[1];
3ebe30ad 564 fHisResX[id]->Fill(resx);
565 fHisResZ[id]->Fill(resz);
566 fHisResXZ[id]->Fill(resx,resz);
1cc5cedc 567 fHisClusterSize[id]->Fill((Double_t)csize[0],(Double_t)csize[1]);
3ebe30ad 568 }
2802d754 569 fHisTrackErrX[id]->Fill(tr[2]);
570 fHisTrackErrZ[id]->Fill(tr[3]);
571 fHisClusErrX[id]->Fill(clu[2]);
572 fHisClusErrZ[id]->Fill(clu[3]);
3ebe30ad 573 return kTRUE;
574}
575//__________________________________________________________
576Bool_t AliITSPlaneEffSSD::WriteHistosToFile(TString filename, Option_t* option) {
577 //
578 // Saves the histograms into a tree and saves the trees into a file
579 //
580 if (!fHis) return kFALSE;
5af4a2d0 581 if (filename.IsNull() || filename.IsWhitespace()) {
3ebe30ad 582 AliWarning("WriteHistosToFile: null output filename!");
583 return kFALSE;
584 }
585// char branchname[30];
586 TFile *hFile=new TFile(filename.Data(),option,
587 "The File containing the TREEs with ITS PlaneEff Histos");
588 TTree *SSDTree=new TTree("SSDTree","Tree whith Residuals and Cluster Type distributions for SSD");
589 TH1F *histZ,*histX;
590 TH2F *histXZ;
591 TH2I *histClusterType;
2802d754 592 TH1F *histTrErrZ,*histTrErrX;
593 TH1F *histClErrZ,*histClErrX;
3ebe30ad 594
595 histZ=new TH1F();
596 histX=new TH1F();
597 histXZ=new TH2F();
598 histClusterType=new TH2I();
2802d754 599 histTrErrX=new TH1F();
600 histTrErrZ=new TH1F();
601 histClErrX=new TH1F();
602 histClErrZ=new TH1F();
3ebe30ad 603
604 SSDTree->Branch("histX","TH1F",&histX,128000,0);
605 SSDTree->Branch("histZ","TH1F",&histZ,128000,0);
606 SSDTree->Branch("histXZ","TH2F",&histXZ,128000,0);
607 SSDTree->Branch("histClusterType","TH2I",&histClusterType,128000,0);
2802d754 608 SSDTree->Branch("histTrErrX","TH1F",&histTrErrX,128000,0);
609 SSDTree->Branch("histTrErrZ","TH1F",&histTrErrZ,128000,0);
610 SSDTree->Branch("histClErrX","TH1F",&histClErrX,128000,0);
611 SSDTree->Branch("histClErrZ","TH1F",&histClErrZ,128000,0);
3ebe30ad 612
613 for(Int_t j=0;j<kNHisto;j++){
614 histX=fHisResX[j];
615 histZ=fHisResZ[j];
616 histXZ=fHisResXZ[j];
617 histClusterType=fHisClusterSize[j];
2802d754 618 histTrErrX=fHisTrackErrX[j];
619 histTrErrZ=fHisTrackErrZ[j];
620 histClErrX=fHisClusErrX[j];
621 histClErrZ=fHisClusErrZ[j];
3ebe30ad 622
623 SSDTree->Fill();
624 }
625 hFile->Write();
626 hFile->Close();
627return kTRUE;
628}
629//__________________________________________________________
630Bool_t AliITSPlaneEffSSD::ReadHistosFromFile(TString filename) {
631 //
632 // Read histograms from an already existing file
633 //
634 if (!fHis) return kFALSE;
5af4a2d0 635 if (filename.IsNull() || filename.IsWhitespace()) {
3ebe30ad 636 AliWarning("ReadHistosFromFile: incorrect output filename!");
637 return kFALSE;
638 }
1cc5cedc 639 //char branchname[30];
3ebe30ad 640
641 TH1F *h = 0;
642 TH2F *h2 = 0;
643 TH2I *h2i= 0;
644
645 TFile *file=TFile::Open(filename.Data(),"READONLY");
646
647 if (!file || file->IsZombie()) {
648 AliWarning(Form("Can't open %s !",filename.Data()));
649 delete file;
650 return kFALSE;
651 }
652 TTree *tree = (TTree*) file->Get("SSDTree");
653
654 TBranch *histX = (TBranch*) tree->GetBranch("histX");
655 TBranch *histZ = (TBranch*) tree->GetBranch("histZ");
656 TBranch *histXZ = (TBranch*) tree->GetBranch("histXZ");
657 TBranch *histClusterType = (TBranch*) tree->GetBranch("histClusterType");
2802d754 658 TBranch *histTrErrX = (TBranch*) tree->GetBranch("histTrErrX");
659 TBranch *histTrErrZ = (TBranch*) tree->GetBranch("histTrErrZ");
660 TBranch *histClErrX = (TBranch*) tree->GetBranch("histClErrX");
661 TBranch *histClErrZ = (TBranch*) tree->GetBranch("histClErrZ");
3ebe30ad 662
663 gROOT->cd();
664
665 Int_t nevent = (Int_t)histX->GetEntries();
666 if(nevent!=kNHisto)
667 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
668 histX->SetAddress(&h);
669 for(Int_t j=0;j<kNHisto;j++){
670 delete h; h=0;
671 histX->GetEntry(j);
672 fHisResX[j]->Add(h);
673 }
674
675 nevent = (Int_t)histZ->GetEntries();
676 if(nevent!=kNHisto)
677 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
678 histZ->SetAddress(&h);
679 for(Int_t j=0;j<kNHisto;j++){
680 delete h; h=0;
681 histZ->GetEntry(j);
682 fHisResZ[j]->Add(h);
683 }
684
685 nevent = (Int_t)histXZ->GetEntries();
686 if(nevent!=kNHisto)
687 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
688 histXZ->SetAddress(&h2);
689 for(Int_t j=0;j<kNHisto;j++){
690 delete h2; h2=0;
691 histXZ->GetEntry(j);
692 fHisResXZ[j]->Add(h2);
693 }
694
695 nevent = (Int_t)histClusterType->GetEntries();
696 if(nevent!=kNHisto)
697 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
698 histClusterType->SetAddress(&h2i);
699 for(Int_t j=0;j<kNHisto;j++){
700 delete h2i; h2i=0;
701 histClusterType->GetEntry(j);
702 fHisClusterSize[j]->Add(h2i);
703 }
704
2802d754 705 nevent = (Int_t)histTrErrX->GetEntries();
706 if(nevent!=kNHisto)
707 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
708 histTrErrX->SetAddress(&h);
709 for(Int_t j=0;j<kNHisto;j++){
710 delete h; h=0;
711 histTrErrX->GetEntry(j);
712 fHisTrackErrX[j]->Add(h);
713 }
714
715 nevent = (Int_t)histTrErrZ->GetEntries();
716 if(nevent!=kNHisto)
717 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
718 histTrErrZ->SetAddress(&h);
719 for(Int_t j=0;j<kNHisto;j++){
720 delete h; h=0;
721 histTrErrZ->GetEntry(j);
722 fHisTrackErrZ[j]->Add(h);
723 }
724
725 nevent = (Int_t)histClErrX->GetEntries();
726 if(nevent!=kNHisto)
727 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
728 histClErrX->SetAddress(&h);
729 for(Int_t j=0;j<kNHisto;j++){
730 delete h; h=0;
731 histClErrX->GetEntry(j);
732 fHisClusErrX[j]->Add(h);
733 }
734
735 nevent = (Int_t)histClErrZ->GetEntries();
736 if(nevent!=kNHisto)
737 {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
738 histClErrZ->SetAddress(&h);
739 for(Int_t j=0;j<kNHisto;j++){
740 delete h; h=0;
741 histClErrZ->GetEntry(j);
742 fHisClusErrZ[j]->Add(h);
743 }
744
3ebe30ad 745 delete h; h=0;
746 delete h2; h2=0;
747 delete h2i; h2i=0;
748
749 if (file) {
750 file->Close();
751 }
752return kTRUE;
753}