]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSPlaneEffSSD.cxx
Bug fix in assignign clusters to the track
[u/mrichter/AliRoot.git] / ITS / AliITSPlaneEffSSD.cxx
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 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
25 /*  $Id$ */
26
27 #include <TMath.h>
28 #include <TH1F.h>
29 #include <TFile.h>
30 #include <TTree.h>
31 #include <TROOT.h>
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
40 ClassImp(AliITSPlaneEffSSD)     
41 //______________________________________________________________________
42 AliITSPlaneEffSSD::AliITSPlaneEffSSD():
43   AliITSPlaneEff(),
44   fHisResX(0),
45   fHisResZ(0),
46   fHisResXZ(0),
47   fHisClusterSize(0),
48   fHisTrackErrX(0),
49   fHisTrackErrZ(0),
50   fHisClusErrX(0),
51   fHisClusErrZ(0){
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 //______________________________________________________________________
60 AliITSPlaneEffSSD::~AliITSPlaneEffSSD(){
61     // destructor
62     // Inputs:
63     //    none.
64     // Outputs:
65     //    none.
66     // Return:
67     //     none.
68     DeleteHistos();
69 }
70 //______________________________________________________________________
71 AliITSPlaneEffSSD::AliITSPlaneEffSSD(const AliITSPlaneEffSSD &s) : AliITSPlaneEff(s),
72 fHisResX(0),
73 fHisResZ(0),
74 fHisResXZ(0),
75 fHisClusterSize(0),
76 fHisTrackErrX(0),
77 fHisTrackErrZ(0),
78 fHisClusErrX(0),
79 fHisClusErrZ(0)
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:
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]);
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]);
104    }
105  }
106 }
107 //_________________________________________________________________________
108 AliITSPlaneEffSSD& 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     }
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]);
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]);
130       }
131     }
132     return *this;
133 }
134 //______________________________________________________________________
135 AliITSPlaneEffSSD&  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 //______________________________________________________________________
150 void AliITSPlaneEffSSD::Copy(TObject &obj) const {
151   // protected method. copy this to obj
152   AliITSPlaneEff::Copy(obj);
153   AliITSPlaneEffSSD& target = (AliITSPlaneEffSSD &) obj;
154   for(Int_t i=0;i<kNModule;i++) {
155       target.fFound[i] = fFound[i];
156       target.fTried[i] = fTried[i];
157   }
158   CopyHistos(target);
159   return;
160 }
161 //_______________________________________________________________________
162 void 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];
170     target.fHisTrackErrX=new TH1F*[kNHisto];
171     target.fHisTrackErrZ=new TH1F*[kNHisto];
172     target.fHisClusErrX=new TH1F*[kNHisto];
173     target.fHisClusErrZ=new TH1F*[kNHisto];
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]);
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]);
183     }
184   }
185 return;
186 }
187 /* Commented out by M.Masera 8/3/08
188 //______________________________________________________________________
189 AliITSPlaneEff&  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;
200     AliError("operator=: Not allowed to make a =, use default creater instead");
201     return *this;
202 }
203 */
204 //_______________________________________________________________________
205 Int_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   //
217 if (im>=kNModule) 
218  {AliError("GetMissingTracksForGivenEff: you asked for a non existing module");
219  return -1;}
220 else return GetNTracksForGivenEff(eff,RelErr)-fTried[GetKey(im)];
221 }
222 //_________________________________________________________________________
223 Double_t  AliITSPlaneEffSSD::PlaneEff(const UInt_t im) const {
224 // Compute the efficiency for a basic block, 
225 // Inputs:
226 //        im     -> module number [0,1697]
227 if (im>=kNModule) 
228  {AliError("PlaneEff(UInt_t): you asked for a non existing module"); return -1.;}
229  Int_t nf=fFound[GetKey(im)];
230  Int_t nt=fTried[GetKey(im)];
231 return AliITSPlaneEff::PlaneEff(nf,nt);
232 }
233 //_________________________________________________________________________
234 Double_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]
239 if (im>=kNModule) 
240  {AliError("ErrPlaneEff(UInt_t): you asked for a non existing module"); return -1.;}
241 Int_t nf=fFound[GetKey(im)];
242 Int_t nt=fTried[GetKey(im)];
243 return AliITSPlaneEff::ErrPlaneEff(nf,nt);
244
245 //_________________________________________________________________________
246 Bool_t AliITSPlaneEffSSD::UpDatePlaneEff(const Bool_t Kfound, const UInt_t im) {
247   // Update efficiency for a basic block
248 if (im>=kNModule) 
249  {AliError("UpDatePlaneEff: you asked for a non existing module"); return kFALSE;}
250  fTried[GetKey(im)]++;
251  if(Kfound) fFound[GetKey(im)]++;
252  return kTRUE;
253 }
254 //_________________________________________________________________________
255 UInt_t AliITSPlaneEffSSD::GetKey(const UInt_t mod) const {
256   // get key given a basic block
257 if(mod>=kNModule)
258   {AliError("GetKey: you asked for a non existing block"); return 99999;}
259 return mod;
260 }
261 //__________________________________________________________________________
262 UInt_t AliITSPlaneEffSSD::GetModFromKey(const UInt_t key) const {
263   // get mod. from key
264 if(key>=kNModule)
265   {AliError("GetModFromKey: you asked for a non existing key"); return 9999;}
266 return key;
267 }
268 //__________________________________________________________________________
269 Double_t AliITSPlaneEffSSD::LivePlaneEff(UInt_t key) const {
270   // returns plane efficieny after adding the fraction of sensor which is bad
271 if(key>=kNModule)
272   {AliError("LivePlaneEff: you asked for a non existing key");
273    return -1.;}
274 Double_t leff=AliITSPlaneEff::LivePlaneEff(0); // this just for the Warning
275 leff=PlaneEff(key)+GetFracBad(key);
276 return leff>1?1:leff;
277 }
278 //____________________________________________________________________________
279 Double_t AliITSPlaneEffSSD::ErrLivePlaneEff(UInt_t key) const {
280   // returns error on live plane efficiency
281 if(key>=kNModule)
282   {AliError("ErrLivePlaneEff: you asked for a non existing key");
283    return -1.;}
284 Int_t nf=fFound[key];
285 Double_t triedInLive=GetFracLive(key)*fTried[key];
286 Int_t nt=TMath::Max(nf,TMath::Nint(triedInLive));
287 return AliITSPlaneEff::ErrPlaneEff(nf,nt); // for the time being: to be checked
288 }
289 //_____________________________________________________________________________
290 Double_t AliITSPlaneEffSSD::GetFracLive(const UInt_t key) const {
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.  
297 if(key>=kNModule)
298   {AliError("GetFracLive: you asked for a non existing key");
299    return -1.;}
300 AliInfo("GetFracLive: it computes only the fraction of working strips (N+P side) / total strips");
301 UInt_t bad=0;
302 GetBadInModule(key,bad);
303 Double_t live=bad;
304 live/=(kNChip*kNSide*kNStrip);
305 return 1.-live;
306 }
307 //_____________________________________________________________________________
308 void AliITSPlaneEffSSD::GetBadInModule(const UInt_t key, UInt_t& nrBadInMod) const {
309   // returns the number of dead and noisy strips (sum of P and N sides).
310 nrBadInMod=0;
311 if(key>=kNModule)
312   {AliError("GetBadInModule: you asked for a non existing key");
313    return;}
314     // Compute the number of bad (dead+noisy) pixel in a module
315 //
316 if(!fInitCDBCalled) 
317   {AliError("GetBadInModule: CDB not inizialized: call InitCDB first");
318    return;};
319 AliCDBManager* man = AliCDBManager::Instance();
320 // retrieve map of dead Pixel 
321 AliCDBEntry *cdbSSD = man->Get("ITS/Calib/BadChannelsSSD", fRunNumber);
322 TObjArray* ssdEntry;
323 if(cdbSSD) {
324   ssdEntry = (TObjArray*)cdbSSD->GetObject();
325   if(!ssdEntry) 
326   {AliError("GetBadInChip: SSDEntry not found in CDB");
327    return;}
328 } else {
329   AliError("GetBadInChip: did not find Calib/BadChannelsSSD");
330   return;
331 }
332 //
333 //UInt_t mod=GetModFromKey(key);
334 //
335 //AliITSBadChannelsSSD* badchannels=(AliITSBadChannelsSSD*) ssdEntry->At(mod);
336 // count the  number of bad channels on the p side
337 //nrBadInMod += (badchannels->GetBadPChannelsList()).GetSize();
338 // add the  number of bad channels on the s side
339 //nrBadInMod += (badchannels->GetBadNChannelsList()).GetSize();
340 return;
341 }
342 //_____________________________________________________________________________
343 Double_t AliITSPlaneEffSSD::GetFracBad(const UInt_t key) const {
344   // returns 1-fractional live
345 if(key>=kNModule)
346   {AliError("GetFracBad: you asked for a non existing key");
347    return -1.;}
348 return 1.-GetFracLive(key);
349 }
350 //_____________________________________________________________________________
351 Bool_t AliITSPlaneEffSSD::WriteIntoCDB() const {
352 // write onto CDB
353 if(!fInitCDBCalled)
354   {AliError("WriteIntoCDB: CDB not inizialized. Call InitCDB first");
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 //_____________________________________________________________________________
370 Bool_t AliITSPlaneEffSSD::ReadFromCDB() {
371 // read from CDB
372 if(!fInitCDBCalled)
373   {AliError("ReadFromCDB: CDB not inizialized. Call InitCDB first");
374    return kFALSE;}
375 AliCDBEntry *cdbEntry = AliCDBManager::Instance()->Get("ITS/PlaneEff/PlaneEffSSD",fRunNumber);
376 if(!cdbEntry) return kFALSE;
377 AliITSPlaneEffSSD* eff= (AliITSPlaneEffSSD*)cdbEntry->GetObject();
378 if(this==eff) return kFALSE;
379 if(fHis) CopyHistos(*eff); // If histos already exist then copy them to eff
380 eff->Copy(*this);          // copy everything (statistics and histos) from eff to this
381 return kTRUE;
382 }
383 //_____________________________________________________________________________
384 Bool_t AliITSPlaneEffSSD::AddFromCDB(AliCDBId *cdbId) {
385 AliCDBEntry *cdbEntry=0;
386 if (!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 }
393 if(!cdbEntry) return kFALSE;
394 AliITSPlaneEffSSD* eff= (AliITSPlaneEffSSD*)cdbEntry->GetObject();
395 *this+=*eff;
396 return kTRUE;
397 }
398 //_____________________________________________________________________________
399 UInt_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)
402 UInt_t key=999999;
403 if(ilay<4 || ilay>5)
404   {AliError("GetKeyFromDetLocCoord: you asked for a non existing layer");
405    return key;}
406 if(ilay==4 && (idet<0 || idet>747))
407  {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
408    return key;}
409 if(ilay==5 && (idet<0 || idet>949))
410  {AliError("GetKeyFromDetLocCoord: you asked for a non existing detector");
411    return key;}
412
413 UInt_t mod=idet;
414 if(ilay==5) mod+=748;
415 key=GetKey(mod);
416 return key;
417 }
418 //__________________________________________________________
419 void 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_";
426   TString histnameTrackErrX="HistTrackErrX_mod_";
427   TString histnameTrackErrZ="HistTrackErrZ_mod_";
428   TString histnameClusErrX="HistClusErrX_mod_";
429   TString histnameClusErrZ="HistClusErrZ_mod_";
430 //
431
432   TH1::AddDirectory(kFALSE);
433
434   fHisResX=new TH1F*[kNHisto];
435   fHisResZ=new TH1F*[kNHisto];
436   fHisResXZ=new TH2F*[kNHisto];
437   fHisClusterSize=new TH2I*[kNHisto];
438   fHisTrackErrX=new TH1F*[kNHisto]; 
439   fHisTrackErrZ=new TH1F*[kNHisto]; 
440   fHisClusErrX=new TH1F*[kNHisto]; 
441   fHisClusErrZ=new TH1F*[kNHisto];
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.10,0.10); // +- 1000 micron; 1 bin=4 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",750,-0.75,0.75); // +-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.04,0.04,40,-0.32,0.32); // binning:
459                                                                                    // 20 micron in x;
460                                                                                    // 160 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
470     aux=histnameTrackErrX;
471     aux+=nhist;
472     fHisTrackErrX[nhist]=new TH1F("histname","histname",300,0.,0.24); // 0-2400 micron; 1 bin=8 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",300,0.,0.48); // 0-4800 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",300,0.,0.24); //  0-2400 micron; 1 bin=8 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.32); //  0-1600 micron; 1 bin=16 micron
491     fHisClusErrZ[nhist]->SetName(aux.Data());
492     fHisClusErrZ[nhist]->SetTitle(aux.Data());
493
494   }
495
496   TH1::AddDirectory(kTRUE);
497
498 return;
499 }
500 //__________________________________________________________
501 void 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   }
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   }
534
535 return;
536 }
537 //__________________________________________________________
538 Bool_t AliITSPlaneEffSSD::FillHistos(UInt_t key, Bool_t found,
539                                      Float_t *tr, Float_t *clu, Int_t *csize, Float_t*) {
540 // this method fill the histograms
541 // input: - key: unique key of the basic block
542 //        - found: Boolean to asses whether a cluster has been associated to the track or not
543 //        - tr[0],tr[1] local X and Z coordinates of the track prediction, respectively
544 //        - tr[2],tr[3] error on local X and Z coordinates of the track prediction, respectively
545 //        - clu[0],clu[1] local X and Z coordinates of the cluster associated to the track, respectively
546 //        - clu[2],clu[3] error on local X and Z coordinates of the cluster associated to the track, respectively
547 //        - csize[0][1] cluster size in X and Z, respectively
548 // output: kTRUE if filling was succesfull kFALSE otherwise
549 // side effects: updating of the histograms.
550 //
551   if (!fHis) {
552     AliWarning("FillHistos: histograms do not exist! Call SetCreateHistos(kTRUE) first");
553     return kFALSE;
554   }
555   if(key>=kNModule)
556     {AliWarning("FillHistos: you asked for a non existing key"); return kFALSE;}
557   Int_t id=GetModFromKey(key);
558   if(id>=kNHisto)
559     {AliWarning("FillHistos: you want to fill a non-existing histos"); return kFALSE;}
560   if(found) {
561     Float_t resx=tr[0]-clu[0];
562     Float_t resz=tr[1]-clu[1];
563     fHisResX[id]->Fill(resx);
564     fHisResZ[id]->Fill(resz);
565     fHisResXZ[id]->Fill(resx,resz);
566     fHisClusterSize[id]->Fill((Double_t)csize[0],(Double_t)csize[1]);
567   }
568   fHisTrackErrX[id]->Fill(tr[2]);
569   fHisTrackErrZ[id]->Fill(tr[3]);
570   fHisClusErrX[id]->Fill(clu[2]);
571   fHisClusErrZ[id]->Fill(clu[3]);
572   return kTRUE;
573 }
574 //__________________________________________________________
575 Bool_t AliITSPlaneEffSSD::WriteHistosToFile(TString filename, Option_t* option) {
576   //
577   // Saves the histograms into a tree and saves the trees into a file
578   //
579   if (!fHis) return kFALSE;
580   if (filename.IsNull() || filename.IsWhitespace()) {
581      AliWarning("WriteHistosToFile: null output filename!");
582      return kFALSE;
583   }
584 //  char branchname[30];
585   TFile *hFile=new TFile(filename.Data(),option,
586                          "The File containing the TREEs with ITS PlaneEff Histos");
587   TTree *SSDTree=new TTree("SSDTree","Tree whith Residuals and Cluster Type distributions for SSD");
588   TH1F *histZ,*histX;
589   TH2F *histXZ;
590   TH2I *histClusterType;
591   TH1F *histTrErrZ,*histTrErrX;
592   TH1F *histClErrZ,*histClErrX;
593
594   histZ=new TH1F();
595   histX=new TH1F();
596   histXZ=new TH2F();
597   histClusterType=new TH2I();
598   histTrErrX=new TH1F();
599   histTrErrZ=new TH1F();
600   histClErrX=new TH1F();
601   histClErrZ=new TH1F();
602
603   SSDTree->Branch("histX","TH1F",&histX,128000,0);
604   SSDTree->Branch("histZ","TH1F",&histZ,128000,0);
605   SSDTree->Branch("histXZ","TH2F",&histXZ,128000,0);
606   SSDTree->Branch("histClusterType","TH2I",&histClusterType,128000,0);
607   SSDTree->Branch("histTrErrX","TH1F",&histTrErrX,128000,0);
608   SSDTree->Branch("histTrErrZ","TH1F",&histTrErrZ,128000,0);
609   SSDTree->Branch("histClErrX","TH1F",&histClErrX,128000,0);
610   SSDTree->Branch("histClErrZ","TH1F",&histClErrZ,128000,0);
611
612   for(Int_t j=0;j<kNHisto;j++){
613     histX=fHisResX[j];
614     histZ=fHisResZ[j];
615     histXZ=fHisResXZ[j];
616     histClusterType=fHisClusterSize[j];
617     histTrErrX=fHisTrackErrX[j];
618     histTrErrZ=fHisTrackErrZ[j];
619     histClErrX=fHisClusErrX[j];
620     histClErrZ=fHisClusErrZ[j];
621
622     SSDTree->Fill();
623   }
624   hFile->Write();
625   hFile->Close();
626 return kTRUE;
627 }
628 //__________________________________________________________
629 Bool_t AliITSPlaneEffSSD::ReadHistosFromFile(TString filename) {
630   //
631   // Read histograms from an already existing file
632   //
633   if (!fHis) return kFALSE;
634   if (filename.IsNull() || filename.IsWhitespace()) {
635      AliWarning("ReadHistosFromFile: incorrect output filename!");
636      return kFALSE;
637   }
638   //char branchname[30];
639
640   TH1F *h  = 0;
641   TH2F *h2 = 0;
642   TH2I *h2i= 0;
643
644   TFile *file=TFile::Open(filename.Data(),"READONLY");
645
646   if (!file || file->IsZombie()) {
647     AliWarning(Form("Can't open %s !",filename.Data()));
648     delete file;
649     return kFALSE;
650   }
651   TTree *tree = (TTree*) file->Get("SSDTree");
652
653   TBranch *histX = (TBranch*) tree->GetBranch("histX");
654   TBranch *histZ = (TBranch*) tree->GetBranch("histZ");
655   TBranch *histXZ = (TBranch*) tree->GetBranch("histXZ");
656   TBranch *histClusterType = (TBranch*) tree->GetBranch("histClusterType");
657   TBranch *histTrErrX = (TBranch*) tree->GetBranch("histTrErrX");
658   TBranch *histTrErrZ = (TBranch*) tree->GetBranch("histTrErrZ");
659   TBranch *histClErrX = (TBranch*) tree->GetBranch("histClErrX");
660   TBranch *histClErrZ = (TBranch*) tree->GetBranch("histClErrZ");
661
662   gROOT->cd();
663
664   Int_t nevent = (Int_t)histX->GetEntries();
665   if(nevent!=kNHisto)
666     {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
667   histX->SetAddress(&h);
668   for(Int_t j=0;j<kNHisto;j++){
669     delete h; h=0;
670     histX->GetEntry(j);
671     fHisResX[j]->Add(h);
672   }
673
674   nevent = (Int_t)histZ->GetEntries();
675   if(nevent!=kNHisto)
676     {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
677   histZ->SetAddress(&h);
678   for(Int_t j=0;j<kNHisto;j++){
679     delete h; h=0;
680     histZ->GetEntry(j);
681     fHisResZ[j]->Add(h);
682   }
683
684   nevent = (Int_t)histXZ->GetEntries();
685   if(nevent!=kNHisto)
686     {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
687   histXZ->SetAddress(&h2);
688   for(Int_t j=0;j<kNHisto;j++){
689     delete h2; h2=0;
690     histXZ->GetEntry(j);
691     fHisResXZ[j]->Add(h2);
692   }
693
694   nevent = (Int_t)histClusterType->GetEntries();
695   if(nevent!=kNHisto)
696     {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
697   histClusterType->SetAddress(&h2i);
698   for(Int_t j=0;j<kNHisto;j++){
699     delete h2i; h2i=0;
700     histClusterType->GetEntry(j);
701     fHisClusterSize[j]->Add(h2i);
702   }
703
704   nevent = (Int_t)histTrErrX->GetEntries();
705   if(nevent!=kNHisto)
706     {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
707   histTrErrX->SetAddress(&h);
708   for(Int_t j=0;j<kNHisto;j++){
709     delete h; h=0;
710     histTrErrX->GetEntry(j);
711     fHisTrackErrX[j]->Add(h);
712   }
713
714   nevent = (Int_t)histTrErrZ->GetEntries();
715   if(nevent!=kNHisto)
716     {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
717   histTrErrZ->SetAddress(&h);
718   for(Int_t j=0;j<kNHisto;j++){
719     delete h; h=0;
720     histTrErrZ->GetEntry(j);
721     fHisTrackErrZ[j]->Add(h);
722   }
723
724   nevent = (Int_t)histClErrX->GetEntries();
725   if(nevent!=kNHisto)
726     {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
727   histClErrX->SetAddress(&h);
728   for(Int_t j=0;j<kNHisto;j++){
729     delete h; h=0;
730     histClErrX->GetEntry(j);
731     fHisClusErrX[j]->Add(h);
732   }
733
734   nevent = (Int_t)histClErrZ->GetEntries();
735   if(nevent!=kNHisto)
736     {AliWarning("ReadHistosFromFile: trying to read too many or too few histos!"); return kFALSE;}
737   histClErrZ->SetAddress(&h);
738   for(Int_t j=0;j<kNHisto;j++){
739     delete h; h=0;
740     histClErrZ->GetEntry(j);
741     fHisClusErrZ[j]->Add(h);
742   }
743
744   delete h;   h=0;
745   delete h2;  h2=0;
746   delete h2i; h2i=0;
747
748   if (file) {
749     file->Close();
750   }
751 return kTRUE;
752 }
753