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