]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibraVector.cxx
removed RooFit usage (+ small change in the DebugTree class)
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraVector.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 ////////////////////////////////////////////////////////////////////////////
19 //                                                                        //   
20 // AliTRDCalibraVector                                                    //       
21 //                                                                        //   
22 // This class is for the vector method of the TRD calibration.            //
23 //                                                                        //
24 // Author:                                                                //
25 //   R. Bailhache (R.Bailhache@gsi.de)                                    //
26 //                                                                        //
27 ////////////////////////////////////////////////////////////////////////////
28
29 #include <TGraphErrors.h>
30 #include <TH1F.h>
31 #include <TObjArray.h>
32 #include <TObject.h>
33 #include <TMath.h>
34 #include <TDirectory.h>
35 #include <TROOT.h>
36 #include <TFile.h>
37 #include <TString.h>
38
39 #include "AliLog.h"
40
41 #include "AliTRDCalibraVector.h"
42 #include "AliTRDCommonParam.h"
43 #include "AliTRDCalibraMode.h"
44 #include "AliTRDPhInfo.h"
45 #include "AliTRDEntriesInfo.h"
46 #include "AliTRDPrfInfo.h"
47 #include "AliTRDgeometry.h"
48
49 ClassImp(AliTRDCalibraVector)
50
51 //______________________________________________________________________________________
52 AliTRDCalibraVector::AliTRDCalibraVector()
53   :TObject()
54   ,fModeCH(0)
55   ,fModePH(0)
56   ,fModePRF(0)
57   ,fNbGroupPRF(0)
58   ,fDetectorPH(-1)
59   ,fDetectorCH(-1)
60   ,fDetectorPRF(-1)
61   ,fStopFillCH(kFALSE)
62   ,fHisto(0x0)
63   ,fGraph(0x0)
64   ,fCalVector(0x0)
65   ,fNumberBinCharge(0)
66   ,fNumberBinPRF(0)
67   ,fTimeMax(0)
68   ,fPRFRange(1.5)
69 {
70   //
71   // Default constructor
72   //
73
74   for (Int_t idet = 0; idet < 540; idet++){
75     
76     fPHEntries[idet]= 0x0;
77     fPHMean[idet]= 0x0;
78     fPHSquares[idet]= 0x0;
79
80     fPRFEntries[idet]= 0x0;
81     fPRFMean[idet]= 0x0;
82     fPRFSquares[idet]= 0x0;
83
84
85     fCHEntries[idet]= 0x0;
86     
87   }
88   
89   for(Int_t k = 0; k < 3; k++){
90     fDetCha0[k] = 0;
91     fDetCha2[k] = 0;
92   }
93  
94 }
95 //______________________________________________________________________________________
96 AliTRDCalibraVector::AliTRDCalibraVector(const AliTRDCalibraVector &c)
97   :TObject(c)
98   ,fModeCH(c.fModeCH)
99   ,fModePH(c.fModePH)
100   ,fModePRF(c.fModePRF)
101   ,fNbGroupPRF(c.fNbGroupPRF)
102   ,fDetectorPH(-1)
103   ,fDetectorCH(-1)
104   ,fDetectorPRF(-1)
105   ,fStopFillCH(kFALSE)
106   ,fHisto(0x0)
107   ,fGraph(0x0)
108   ,fCalVector(0x0)
109   ,fNumberBinCharge(c.fNumberBinCharge)
110   ,fNumberBinPRF(c.fNumberBinPRF)
111   ,fTimeMax(c.fTimeMax)
112   ,fPRFRange(c.fPRFRange)
113 {
114   //
115   // Copy constructor
116   //
117   
118   for(Int_t k = 0; k < 3; k++){
119     fDetCha0[k] = c.fDetCha0[k];
120     fDetCha2[k] = c.fDetCha2[k];
121   }
122
123   for (Int_t idet = 0; idet < 540; idet++){
124     
125     const AliTRDEntriesInfo *phEntries  = (AliTRDEntriesInfo*)c.fPHEntries[idet];
126     const AliTRDPhInfo      *phMean     = (AliTRDPhInfo *)c.fPHMean[idet];
127     const AliTRDPhInfo      *phSquares  = (AliTRDPhInfo *)c.fPHSquares[idet];
128
129     const AliTRDEntriesInfo *prfEntries = (AliTRDEntriesInfo*)c.fPRFEntries[idet];
130     const AliTRDPrfInfo     *prfMean     = (AliTRDPrfInfo *)c.fPRFMean[idet];
131     const AliTRDPrfInfo     *prfSquares  = (AliTRDPrfInfo *)c.fPRFSquares[idet];
132
133     const AliTRDEntriesInfo *chEntries  = (AliTRDEntriesInfo*)c.fCHEntries[idet];
134
135     if ( chEntries != 0x0 ) fCHEntries[idet] = new AliTRDEntriesInfo(*chEntries);
136     
137     if ( phEntries != 0x0 ) {
138       fPHMean[idet]    = new AliTRDPhInfo(*phMean);
139       fPHSquares[idet] = new AliTRDPhInfo(*phSquares);
140       fPHEntries[idet] = new AliTRDEntriesInfo(*phEntries);
141     }
142
143     if ( prfEntries != 0x0 ) {
144       fPRFEntries[idet] = new AliTRDEntriesInfo(*prfEntries);
145       fPRFMean[idet] = new AliTRDPrfInfo(*prfMean);
146       fPRFSquares[idet] = new AliTRDPrfInfo(*prfSquares);
147     }
148     
149   }
150    
151 }
152 //_____________________________________________________________________
153 AliTRDCalibraVector& AliTRDCalibraVector::operator = (const  AliTRDCalibraVector &source)
154 {
155   //
156   // assignment operator
157   //
158   if (&source == this) return *this;
159   new (this) AliTRDCalibraVector(source);
160
161   return *this;
162 }
163 //____________________________________________________________________________________
164 AliTRDCalibraVector::~AliTRDCalibraVector()
165 {
166   //
167   // AliTRDCalibraVector destructor
168   //
169
170   if(fPHEntries) delete fPHEntries;
171   if(fPHMean) delete fPHMean;
172   if(fPHSquares) delete fPHSquares;
173   if(fPRFEntries) delete fPRFEntries;
174   if(fPRFMean) delete fPRFMean;
175   if(fPRFSquares) delete fPRFSquares;
176   if(fCHEntries) delete fCHEntries;
177   if(fHisto) delete fHisto;
178   if(fGraph) delete fGraph;
179   if(fCalVector) delete fCalVector;
180
181 }
182 //_____________________________________________________________________________
183 void AliTRDCalibraVector::TestInit(Int_t i, Int_t detmax)
184 {
185   //
186   // Init to see the size
187   //
188
189   for(Int_t det = 0; det < detmax; det++){
190
191     if(i==2) {
192       
193       fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
194       fPRFMean[det]    = ((AliTRDPrfInfo  *)GetPRFMean(det,kTRUE));
195       fPRFSquares[det] = ((AliTRDPrfInfo  *)GetPRFSquares(det,kTRUE));
196
197     }
198
199     if(i==1) {
200
201       fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
202       fPHMean[det]    = ((AliTRDPhInfo  *)GetPHMean(det,kTRUE));
203       fPHSquares[det] = ((AliTRDPhInfo  *)GetPHSquares(det,kTRUE));
204       
205     }
206     
207     if(i==0) fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
208
209   }
210
211 }
212 //_____________________________________________________________________________
213 Int_t AliTRDCalibraVector::SearchBin(Float_t value, Int_t i) const
214 {
215   //
216   // Search the bin
217   //
218
219   Int_t reponse        = 0;
220   Float_t fbinmin      = 0;
221   Float_t fbinmax      = value;
222   Int_t fNumberOfBin   = -1;
223
224   switch(i)
225     {
226     case 0:
227       fbinmax      = 300.0;
228       fbinmin      = 0.0;
229       fNumberOfBin = fNumberBinCharge;
230       break;
231
232     case 2:
233       fbinmax      =   TMath::Abs(fPRFRange);
234       fbinmin      =  -TMath::Abs(fPRFRange);
235       fNumberOfBin = fNumberBinPRF;
236       break;
237       
238     default: 
239       return -1;
240     }
241   
242   // Return -1 if out
243   if ((value >= fbinmax) || 
244       (value <  fbinmin)) {
245     return -1;
246   }
247   else {
248     reponse = (Int_t) ((fNumberOfBin*(value-fbinmin)) / (fbinmax-fbinmin));
249   }
250
251   return reponse;
252
253 }
254 //_____________________________________________________________________________
255 Bool_t AliTRDCalibraVector::UpdateVectorCH(Int_t det, Int_t group, Float_t value)
256 {
257   //
258   // Fill the vector CH   
259   //
260
261   // Search bin
262   Int_t bin = SearchBin(value,0);
263   // Out
264   if (bin == -1) {
265     return kFALSE; 
266   }
267
268
269
270   if(fDetectorCH != det){
271     fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
272   }
273
274   Int_t entries  = ((AliTRDEntriesInfo *)fCHEntries[det])->At(group*fNumberBinCharge+bin);
275   
276   Int_t entriesn = entries+1;
277
278   if(entriesn > 65535) {
279     fStopFillCH = kTRUE;
280     return kTRUE;
281   }
282
283   ((AliTRDEntriesInfo *)fCHEntries[det])->AddAt(entriesn,group*fNumberBinCharge+bin);
284   
285   fDetectorCH = det;
286
287  
288   return kTRUE;
289
290 }
291 //_____________________________________________________________________________
292 Bool_t AliTRDCalibraVector::UpdateVectorPRF(Int_t det, Int_t group, Float_t x, Float_t y)
293 {
294   //
295   // Fill the vector PRF
296   //
297
298   // Search bin
299   Int_t bin = SearchBin(x,2);
300   // Out
301   if (bin == -1) {
302     return kFALSE; 
303   }
304
305   
306   if(fDetectorPRF != det){
307     fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
308     fPRFMean[det]    = ((AliTRDPrfInfo  *)GetPRFMean(det,kTRUE));
309     fPRFSquares[det] = ((AliTRDPrfInfo  *)GetPRFSquares(det,kTRUE));
310   }
311
312   Int_t entries  = ((AliTRDEntriesInfo *)fPRFEntries[det])->At((Int_t)group*fNumberBinPRF+bin);
313   Float_t mean   = ((AliTRDPrfInfo  *)fPRFMean[det])->At((Int_t)group*fNumberBinPRF+bin);
314   Float_t square = ((AliTRDPrfInfo  *)fPRFSquares[det])->At((Int_t)group*fNumberBinPRF+bin);
315   
316   Int_t entriesn = entries+1;
317
318   if(entriesn > 65535) return kTRUE;
319   
320   ((AliTRDEntriesInfo *)fPRFEntries[det])->AddAt(entriesn,(Int_t)group*fNumberBinPRF+bin);
321   Float_t meann = (mean*((Float_t)entries)+y)/((Float_t)entriesn);
322   ((AliTRDPrfInfo *)fPRFMean[det])->AddAt(meann,(Int_t)group*fNumberBinPRF+bin);
323   Float_t squaren = ((square*((Float_t)entries))+(y*y))/((Float_t)entriesn);
324   ((AliTRDPrfInfo *)fPRFSquares[det])->AddAt(squaren,(Int_t)group*fNumberBinPRF+bin);
325
326   
327   fDetectorPRF = det;
328
329   return kTRUE;
330   
331 }
332 //_____________________________________________________________________________
333 Bool_t AliTRDCalibraVector::UpdateVectorPH(Int_t det, Int_t group, Int_t time, Float_t value)
334 {
335   //
336   // Fill the vector PH  
337   //
338
339   // Search bin
340   Int_t bin = time;
341   // Out
342   if ((bin <         0) || 
343       (bin >= fTimeMax)) {
344     return kFALSE; 
345   }
346
347
348   if(fDetectorPH != det){
349     fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
350     fPHMean[det]    = ((AliTRDPhInfo  *)GetPHMean(det,kTRUE));
351     fPHSquares[det] = ((AliTRDPhInfo  *)GetPHSquares(det,kTRUE));
352   }
353
354   Int_t entries  = ((AliTRDEntriesInfo *)fPHEntries[det])->At(group*fTimeMax+bin);
355   Float_t mean   = ((AliTRDPhInfo  *)fPHMean[det])->At(group*fTimeMax+bin);
356   Float_t square = ((AliTRDPhInfo  *)fPHSquares[det])->AtS(group*fTimeMax+bin);
357   
358   Int_t entriesn = entries+1;
359   Float_t meann = (mean*((Float_t)entries)+value)/((Float_t)entriesn);
360   Float_t squaren = ((square*((Float_t)entries))+(value*value))/((Float_t)entriesn);
361   
362   if(entriesn > 65535) return kTRUE;
363   //printf("meann %f, squaren %f\n",meann,squaren);
364   if((meann > 3000.0) || (meann < 0.0) || (squaren > (3000.0*3000.0)) || (squaren < 0.0)) return kFALSE;
365
366   ((AliTRDEntriesInfo *)fPHEntries[det])->AddAt(entriesn,group*fTimeMax+bin);
367   ((AliTRDPhInfo *)fPHMean[det])->AddAt(meann,group*fTimeMax+bin);
368   ((AliTRDPhInfo *)fPHSquares[det])->AddAtS(squaren,group*fTimeMax+bin);
369   
370   fDetectorPH = det;
371
372   return kTRUE;
373   
374 }
375 //_____________________________________________________________________________
376 Bool_t AliTRDCalibraVector::FillVectorCH(Int_t det, Int_t group, Int_t bin, Int_t entries)
377 {
378   //
379   // Fill the vector CH   
380   //
381
382   if(entries > 65535) return kFALSE;
383
384   if(fDetectorCH != det){
385     fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
386   }
387
388   ((AliTRDEntriesInfo *)fCHEntries[det])->AddAt(entries,group*fNumberBinCharge+bin);
389   
390   fDetectorCH = det;
391   
392   
393   return kTRUE;
394   
395 }
396 //_____________________________________________________________________________
397 Bool_t AliTRDCalibraVector::FillVectorPRF(Int_t det, Int_t group, Int_t bin, Int_t entries, Float_t mean, Float_t square)
398 {
399   //
400   // Fill the vector PRF
401   //
402
403   if((entries > 65535) || (mean > 1.0) || (mean < 0.0) || (square > 1.0) || (square < 0.0)) return kFALSE;
404
405   if(fDetectorPRF != det){
406     fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
407     fPRFMean[det]    = ((AliTRDPrfInfo  *)GetPRFMean(det,kTRUE));
408     fPRFSquares[det] = ((AliTRDPrfInfo  *)GetPRFSquares(det,kTRUE));
409   }
410
411   ((AliTRDEntriesInfo *)fPRFEntries[det])->AddAt(entries,(Int_t)group*fNumberBinPRF+bin);
412   ((AliTRDPrfInfo  *)fPRFMean[det])->AddAt(mean,(Int_t)group*fNumberBinPRF+bin);
413   ((AliTRDPrfInfo  *)fPRFSquares[det])->AddAt(square,(Int_t)group*fNumberBinPRF+bin);
414
415   
416   fDetectorPRF = det;
417
418   return kTRUE;
419   
420 }
421 //_____________________________________________________________________________
422 Bool_t AliTRDCalibraVector::FillVectorPH(Int_t det, Int_t group, Int_t bin, Int_t entries, Float_t mean, Float_t square)
423 {
424   //
425   // Fill the vector PH  
426   //
427
428   if((entries > 65535) || (mean > 3000.0) || (mean < 0.0) || (square > (3000.0*3000.0)) || (square < 0.0)) return kFALSE;
429
430
431   if(fDetectorPH != det){
432     fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
433     fPHMean[det]    = ((AliTRDPhInfo  *)GetPHMean(det,kTRUE));
434     fPHSquares[det] = ((AliTRDPhInfo  *)GetPHSquares(det,kTRUE));
435   }
436
437   ((AliTRDEntriesInfo *)fPHEntries[det])->AddAt(entries,group*fTimeMax+bin);
438   ((AliTRDPhInfo  *)fPHMean[det])->AddAt(mean,group*fTimeMax+bin);
439   ((AliTRDPhInfo  *)fPHSquares[det])->AddAtS(square,group*fTimeMax+bin);
440   
441   fDetectorPH = det;
442
443   return kTRUE;
444   
445 }
446 //__________________________________________________________________________________
447 Bool_t AliTRDCalibraVector::Add(AliTRDCalibraVector *calvect)
448 {
449   //
450   // Add a other AliTRCalibraVector to this one
451   //
452
453   Bool_t result = kTRUE;
454
455   // Check compatibility
456   if(fNumberBinCharge != calvect->GetNumberBinCharge()) return kFALSE;
457   if(fNumberBinPRF    != calvect->GetNumberBinPRF()) return kFALSE;
458   if(fPRFRange        != calvect->GetPRFRange()) return kFALSE;
459   if(fTimeMax         != calvect->GetTimeMax()) return kFALSE;
460   for(Int_t k = 0; k < 3; k++){
461     if(fDetCha0[k] != calvect->GetDetCha0(k)) return kFALSE;
462     if(fDetCha2[k] != calvect->GetDetCha2(k)) return kFALSE;
463   }
464
465   //printf("All ok for variables before adding!\n"); 
466
467   // Add
468   for (Int_t idet = 0; idet < 540; idet++){
469
470     //printf("Detector %d\n",idet);
471     
472     const AliTRDEntriesInfo *phEntriesvect    = (AliTRDEntriesInfo *) calvect->GetPHEntries(idet);
473     const AliTRDPhInfo      *phMeanvect       = (AliTRDPhInfo *) calvect->GetPHMean(idet);
474     const AliTRDPhInfo      *phSquaresvect    = (AliTRDPhInfo *) calvect->GetPHSquares(idet);
475     
476     const AliTRDEntriesInfo *prfEntriesvect   = (AliTRDEntriesInfo *) calvect->GetPRFEntries(idet);
477     const AliTRDPrfInfo    *prfMeanvect       = (AliTRDPrfInfo *) calvect->GetPRFMean(idet);
478     const AliTRDPrfInfo    *prfSquaresvect    = (AliTRDPrfInfo *) calvect->GetPRFSquares(idet);
479     
480     const AliTRDEntriesInfo *chEntriesvect    = (AliTRDEntriesInfo *) calvect->GetCHEntries(idet);
481
482     if ( phEntriesvect != 0x0 ){
483       //Take the stuff
484       fPHEntries[idet] = ((AliTRDEntriesInfo *)GetPHEntries(idet,kTRUE));
485       fPHMean[idet]    = ((AliTRDPhInfo *)GetPHMean(idet,kTRUE));
486       fPHSquares[idet] = ((AliTRDPhInfo *)GetPHSquares(idet,kTRUE));
487
488       Int_t total = fPHEntries[idet]->GetSize();
489       //printf("Total size PH %d\n",total);
490       // Add
491       for(Int_t k = 0; k < total; k++){
492         Int_t entriesv  = ((AliTRDEntriesInfo *)phEntriesvect)->At(k);
493         Float_t meanv   = ((AliTRDPhInfo  *)phMeanvect)->At(k);
494         Float_t squarev = ((AliTRDPhInfo  *)phSquaresvect)->AtS(k);
495         
496         Int_t entries  = ((AliTRDEntriesInfo *)fPHEntries[idet])->At(k);
497         Float_t mean   = ((AliTRDPhInfo  *)fPHMean[idet])->At(k);
498         Float_t square = ((AliTRDPhInfo  *)fPHSquares[idet])->AtS(k);
499   
500         Int_t entriesn = entries+entriesv;
501         Float_t meann = (mean*((Float_t)entries)+meanv*((Float_t)entriesv))/((Float_t)entriesn);
502         Float_t squaren = ((square*((Float_t)entries))+(squarev*((Float_t)entriesv)))/((Float_t)entriesn);
503         
504         if((entriesn > 0) && (entriesn <= 65535) && (meann >= 0) && (meann < 3000.0) && (squaren >= 0.0) && (squaren < (3000.0*3000.0))) {
505         
506           ((AliTRDEntriesInfo *)fPHEntries[idet])->AddAt(entriesn,k);
507           ((AliTRDPhInfo *)fPHMean[idet])->AddAt(meann,k);
508           ((AliTRDPhInfo *)fPHSquares[idet])->AddAtS(squaren,k);
509       
510         }
511       }
512     }     
513
514     if ( prfEntriesvect != 0x0 ){
515       //Take the stuff
516       fPRFEntries[idet] = ((AliTRDEntriesInfo *)GetPRFEntries(idet,kTRUE));
517       fPRFMean[idet]    = ((AliTRDPrfInfo  *)GetPRFMean(idet,kTRUE));
518       fPRFSquares[idet] = ((AliTRDPrfInfo  *)GetPRFSquares(idet,kTRUE));
519       
520       Int_t total = fPRFEntries[idet]->GetSize(); 
521       //Int_t total0 = fPRFMean[idet]->GetSize(); 
522       //Int_t total1 = fPRFSquares[idet]->GetSize(); 
523       //printf("Total size PRF %d\n",total);     
524       //printf("Total0 size PRF %d\n",total0);     
525       //printf("Total1 size PRF %d\n",total1);     
526       // Add
527       for(Int_t k = 0; k < total; k++){
528
529
530         Int_t entries  = ((AliTRDEntriesInfo *)fPRFEntries[idet])->At(k);
531         Float_t mean   = ((AliTRDPrfInfo  *)fPRFMean[idet])->At(k);
532         Float_t square = ((AliTRDPrfInfo  *)fPRFSquares[idet])->At(k);
533
534         Int_t entriesv  = ((AliTRDEntriesInfo *)prfEntriesvect)->At(k);
535         Float_t meanv   = ((AliTRDPrfInfo  *)prfMeanvect)->At(k);
536         Float_t squarev = ((AliTRDPrfInfo  *)prfSquaresvect)->At(k);
537
538         Int_t entriesn = entries + entriesv;
539         
540         if((entriesn > 0) && (entriesn <= 65535)) {
541           
542           ((AliTRDEntriesInfo *)fPRFEntries[idet])->AddAt(entriesn,k);
543           
544           Float_t meann = (mean*((Float_t)entries)+meanv*((Float_t)entriesv))/((Float_t)entriesn);
545           //printf("test0\n");
546           ((AliTRDPrfInfo *)fPRFMean[idet])->AddAt(meann,k);
547           //printf("test1\n");
548           
549           Float_t squaren = ((square*((Float_t)entries))+(squarev*((Float_t)entriesv)))/((Float_t)entriesn);
550           //printf("test2\n");
551           ((AliTRDPrfInfo *)fPRFSquares[idet])->AddAt(squaren,k);
552           //printf("test3\n");
553                   
554         }
555       }
556     }
557
558     if ( chEntriesvect != 0x0 ){
559       //Take the stuff
560       fCHEntries[idet] = ((AliTRDEntriesInfo *)GetCHEntries(idet,kTRUE));
561       //printf("TestAdd\n");
562       fStopFillCH = ((AliTRDEntriesInfo *)fCHEntries[idet])->TestAdd((AliTRDEntriesInfo *)chEntriesvect);
563       //
564       if(!fStopFillCH) {
565         fStopFillCH = kTRUE;
566         result = kFALSE;
567       }
568       else {
569         
570         ((AliTRDEntriesInfo *)fCHEntries[idet])->Add(chEntriesvect);
571         //printf("Add\n");
572       }
573     }           
574   }
575   
576   return result;
577 }
578 //_____________________________________________________________________________________________________________________
579 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorCH()
580 {
581   //
582   // Create a AliTRDCalibraVector detector wise
583   //
584
585   // Use a AliTRDCalibraMode to navigate in the calibration groups
586   AliTRDCalibraMode calibMode = AliTRDCalibraMode();
587   calibMode.SetNz(0,GetNz(0));
588   calibMode.SetNrphi(0,GetNrphi(0));
589   if(((calibMode.GetNz(0) == 100) && (calibMode.GetNrphi(0) == 100)) || ((calibMode.GetNz(0) == 10) && (calibMode.GetNrphi(0) == 10))) return 0x0;
590   
591   Int_t nybins = 6*4*18*fDetCha0[0]+6*18*fDetCha2[0];
592   Int_t nxbins = fNumberBinCharge;
593   
594   // Check 
595   Int_t perChamber2 = 0;
596   Int_t perChamber0 = 0;
597   calibMode.ModePadCalibration(2,0);
598   calibMode.ModePadFragmentation(0,2,0,0);
599   calibMode.SetDetChamb2(0);
600   perChamber2 = (Int_t) calibMode.GetDetChamb2(0);
601   calibMode.ModePadCalibration(0,0);
602   calibMode.ModePadFragmentation(0,0,0,0);
603   calibMode.SetDetChamb0(0);
604   perChamber0 = (Int_t) calibMode.GetDetChamb0(0);
605   if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
606     
607   // Create calvector 
608   if(!fCalVector) fCalVector = new AliTRDCalibraVector();
609   else{ 
610     fCalVector->~AliTRDCalibraVector();
611     new(fCalVector) AliTRDCalibraVector();
612   }
613   fCalVector->SetNumberBinCharge(nxbins);
614   fCalVector->SetDetCha0(0,1);
615   fCalVector->SetDetCha2(0,1);
616   fCalVector->SetNzNrphi(0,0,0);
617  
618   
619   for(Int_t det = 0; det < 540; det++){
620     
621     // Take
622     AliTRDEntriesInfo *entriesch = (AliTRDEntriesInfo *)GetCHEntries(det,kFALSE);
623     if(!entriesch) continue;  
624   
625     // Number of groups
626     Int_t numberofgroup = 0;
627     if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
628     else numberofgroup = perChamber0;
629   
630     // Check if one can merge calibration groups for this chamber
631     // entries is the number of entries in each bin after adding the different the calibration group in the detector
632     fStopFillCH = kFALSE;
633     Int_t firstnumberofgroup = -1;
634     Int_t entries[500];
635     for(Int_t k = 0; k < nxbins; k++){
636       entries[k] = 0;
637     }
638     // Loop over group in the detector
639     for(Int_t k = 0; k < numberofgroup; k++){
640       // Loop over bins
641       for(Int_t nx = 0; nx < nxbins; nx++) {
642         Int_t binnumber = k*nxbins+nx;
643         entries[nx] += entriesch->At(binnumber);
644         // as soon as one bin is over threshold stop 
645         if(!fStopFillCH) {
646           if(entries[nx] > 65535) {
647             firstnumberofgroup = k;
648             fStopFillCH = kTRUE;
649           }
650         }
651         else continue;
652       }
653     }
654     if(fStopFillCH && (firstnumberofgroup == 0)) return 0x0;
655     if(!fStopFillCH) firstnumberofgroup = numberofgroup;
656     
657     // Now add up to possible 
658     for(Int_t k = 0; k < nxbins; k++){
659       entries[k] = 0;
660     }
661     for(Int_t k = 0; k < firstnumberofgroup; k++){
662       for(Int_t nx = 0; nx < nxbins; nx++) {
663         Int_t binnumber = k*nxbins+nx;
664         entries[nx] += entriesch->At(binnumber);
665       }
666     }
667
668     // Finally fill
669     for(Int_t nx = 0; nx < nxbins; nx++){
670       fCalVector->FillVectorCH(det,0,nx,(Int_t)entries[nx]);  
671     }
672   }
673   
674   return fCalVector;
675
676 //_____________________________________________________________________________________________________________________
677 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorPH()
678 {
679   //
680   // Create a AliTRDCalibraVector detector wise
681   //
682
683   AliTRDCalibraMode calibMode = AliTRDCalibraMode();
684   calibMode.SetNz(1,GetNz(1));
685   calibMode.SetNrphi(1,GetNrphi(1));
686   if(((calibMode.GetNz(1) == 100) && (calibMode.GetNrphi(1) == 100)) || ((calibMode.GetNz(1) == 10) && (calibMode.GetNrphi(1) == 10))) return 0x0;
687   
688
689   // Check
690   Int_t nybins = 6*4*18*fDetCha0[1]+6*18*fDetCha2[1];
691   Int_t nxbins = fTimeMax;
692  
693   Int_t perChamber2 = 0;
694   Int_t perChamber0 = 0;
695   calibMode.ModePadCalibration(2,1);
696   calibMode.ModePadFragmentation(0,2,0,1);
697   calibMode.SetDetChamb2(1);
698   perChamber2 = (Int_t) calibMode.GetDetChamb2(1);
699   calibMode.ModePadCalibration(0,1);
700   calibMode.ModePadFragmentation(0,0,0,1);
701   calibMode.SetDetChamb0(1);
702   perChamber0 = (Int_t) calibMode.GetDetChamb0(1);
703   
704   if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
705   
706   // Create calvector 
707   if(!fCalVector) fCalVector = new AliTRDCalibraVector();
708   else{ 
709     fCalVector->~AliTRDCalibraVector();
710     new(fCalVector) AliTRDCalibraVector();
711   }
712   fCalVector->SetTimeMax(nxbins);
713   fCalVector->SetDetCha0(1,1);
714   fCalVector->SetDetCha2(1,1);
715   fCalVector->SetNzNrphi(1,0,0);
716   
717  
718   for(Int_t det = 0; det < 540; det++){
719     
720     // Take
721     AliTRDEntriesInfo *entriesph = (AliTRDEntriesInfo *)GetPHEntries(det,kFALSE);
722     if(!entriesph) continue;
723     AliTRDPhInfo      *meanph    = (AliTRDPhInfo *)GetPHMean(det,kFALSE);
724     AliTRDPhInfo      *squaresph = (AliTRDPhInfo *)GetPHSquares(det,kFALSE);
725
726     // Number of groups
727     Int_t numberofgroup = 0;
728     if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
729     else numberofgroup = perChamber0;
730     
731     // PH
732     for(Int_t nx = 0; nx < nxbins; nx++) {
733       
734       Double_t entries = 0.0;
735       Double_t sumw2   = 0.0;
736       Double_t sumw    = 0.0;
737
738       // Sum the contributions of the different calibration group in the detector      
739       for(Int_t k = 0; k < numberofgroup; k++){
740           
741         Int_t binnumber = k*nxbins+nx;    
742         
743         Int_t entriesv  = ((AliTRDEntriesInfo *)entriesph)->At(binnumber);
744         Float_t sumw2v  = ((AliTRDPhInfo *)squaresph)->AtS(binnumber)*entriesv;
745         Float_t sumwv   = ((AliTRDPhInfo *)meanph)->At(binnumber)*entriesv;
746         
747         
748         if(((entries+entriesv) > 65535) || ((entries+entriesv) <= 0)) continue;
749
750         entries += entriesv;
751         sumw2   += sumw2v;
752         sumw    += sumwv;
753       
754       }
755
756       if(entries > 0) {
757         sumw2 = sumw2/((Float_t)entries);
758         sumw  = sumw/((Float_t)entries);
759       }
760       
761       fCalVector->FillVectorPH(det,0,nx,(Int_t)entries,(Float_t)sumw,(Float_t)sumw2);
762     }
763   }
764
765   return fCalVector;
766   
767
768 //_____________________________________________________________________________________________________________________
769 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorPRF()
770 {
771   //
772   // Create a AliTRDCalibraVector detector wise
773   //
774
775   AliTRDCalibraMode calibMode = AliTRDCalibraMode();
776   calibMode.SetNz(2,GetNz(2));
777   calibMode.SetNrphi(2,GetNrphi(2));
778   if(((calibMode.GetNz(2) == 100) && (calibMode.GetNrphi(2) == 100)) || ((calibMode.GetNz(2) == 10) && (calibMode.GetNrphi(2) == 10))) return 0x0;
779
780   // Check  
781   Int_t nybins =  6*4*18*fDetCha0[2]+ 6*18*fDetCha2[2];
782   Int_t nxbins = fNumberBinPRF;
783   
784   Int_t perChamber2 = 0;
785   Int_t perChamber0 = 0;
786   calibMode.ModePadCalibration(2,2);
787   calibMode.ModePadFragmentation(0,2,0,2);
788   calibMode.SetDetChamb2(2);
789   perChamber2 = (Int_t) calibMode.GetDetChamb2(2);
790   calibMode.ModePadCalibration(0,2);
791   calibMode.ModePadFragmentation(0,0,0,2);
792   calibMode.SetDetChamb0(2);
793   perChamber0 = (Int_t) calibMode.GetDetChamb0(2);
794   
795   if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
796     
797   // Create calvector 
798   if(!fCalVector) fCalVector = new AliTRDCalibraVector();
799   else{ 
800     fCalVector->~AliTRDCalibraVector();
801     new(fCalVector) AliTRDCalibraVector();
802   }
803   fCalVector->SetNumberBinPRF(nxbins);
804   fCalVector->SetDetCha0(2,1);
805   fCalVector->SetDetCha2(2,1);
806   fCalVector->SetNzNrphi(2,0,0);
807   fCalVector->SetNbGroupPRF(fNbGroupPRF);
808
809   
810   for(Int_t det = 0; det < 540; det++){
811     
812     // Take
813     AliTRDEntriesInfo *entriesprf = (AliTRDEntriesInfo *) GetPRFEntries(det,kFALSE);
814     if(!entriesprf) continue;
815     AliTRDPrfInfo     *meanprf    = (AliTRDPrfInfo *) GetPRFMean(det,kFALSE);
816     AliTRDPrfInfo     *squaresprf = (AliTRDPrfInfo *) GetPRFSquares(det,kFALSE);
817
818     // Number of groups
819     Int_t numberofgroup = 0;
820     if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
821     else numberofgroup = perChamber0;
822     
823     for(Int_t nx = 0; nx < nxbins; nx++) {
824       
825       Double_t entries = 0.0;
826       Double_t sumw2   = 0.0;
827       Double_t sumw    = 0.0;
828       
829       // Sum the contributions of the different groups in the detector for one bin
830       for(Int_t k = 0; k < numberofgroup; k++){
831           
832         Int_t binnumber = k*nxbins+nx;    
833
834         Int_t entriesv  = ((AliTRDEntriesInfo *)entriesprf)->At(binnumber);
835         Float_t sumw2v  = ((AliTRDPrfInfo *)squaresprf)->At(binnumber)*entriesv;
836         Float_t sumwv   = ((AliTRDPrfInfo *)meanprf)->At(binnumber)*entriesv;
837         
838         if(((entries+entriesv) > 65535) || ((entries+entriesv) <= 0)) continue;
839
840         entries += entriesv;
841         sumw2   += sumw2v;
842         sumw    += sumwv;
843       
844       }
845
846       if(entries > 0) {
847         sumw2 = sumw2/((Float_t)entries);
848         sumw  = sumw/((Float_t)entries);
849       }
850       
851       fCalVector->FillVectorPRF(det,0,nx,(Int_t)entries,(Float_t)sumw,(Float_t)sumw2);
852       
853     }
854   }
855
856   return fCalVector;
857 }
858 //_______________________________________________________________________________
859 Bool_t AliTRDCalibraVector::FindTheMaxEntries(Int_t i, Int_t &detectormax, Int_t &groupmax)
860 {
861   //
862   // Find detectormax and groupmax with the biggest number of entries
863   //
864
865   Int_t numberofTB = 0;
866   if(i==0) numberofTB = (Int_t) GetNumberBinCharge();
867   if(i==1) numberofTB = GetTimeMax();
868   if(i==2) numberofTB = GetNumberBinPRF();
869   if((i!=0) && (i!=1) && (i!=2)) AliInfo("Didn't understand i");
870
871
872   // Init
873   Double_t entries [540];
874   for(Int_t idet = 0; idet < 540; idet++){
875     entries[idet] = 0.0;
876   }
877
878   AliTRDEntriesInfo *entriesd = 0x0;
879   // Take the number of entries per detector
880   for(Int_t idet = 0; idet < 540; idet++){
881  
882     if(i==0) entriesd = (AliTRDEntriesInfo *) GetCHEntries(idet,kFALSE);
883     if(i==1) entriesd = (AliTRDEntriesInfo *) GetPHEntries(idet,kFALSE);
884     if(i==2) entriesd = (AliTRDEntriesInfo *) GetPRFEntries(idet,kFALSE);
885     if(!entriesd) continue;
886
887     entries[idet] = entriesd->GetSum();
888     
889   }
890
891   // Search detector max
892   Double_t max = -10;
893   detectormax = -1;
894   for(Int_t idet = 0; idet < 540; idet++){
895     if(entries[idet] > max) {
896       max = entries[idet];
897       detectormax = idet;
898     }
899   }
900   if((max == 0.0) || (detectormax <0.0)) return kFALSE;
901
902   // Search group max
903   if(i==0) entriesd = (AliTRDEntriesInfo *) GetCHEntries(detectormax,kFALSE);
904   if(i==1) entriesd = (AliTRDEntriesInfo *) GetPHEntries(detectormax,kFALSE);
905   if(i==2) entriesd = (AliTRDEntriesInfo *) GetPRFEntries(detectormax,kFALSE);  
906   if(!entriesd) return kFALSE;
907   // Number of groups
908   Int_t numberofgroup = 0;
909   if(AliTRDgeometry::GetStack(detectormax) == 2) numberofgroup = fDetCha2[i];
910   else numberofgroup = fDetCha0[i];
911   // Init
912   Double_t nbgroup [2304];
913   for(Int_t k = 0; k < 2304; k++){
914     nbgroup[k] = 0.0;
915   }
916   Int_t nxbins = 0;
917   if(i==0) nxbins = fNumberBinCharge;
918   if(i==1) nxbins = fTimeMax;
919   if(i==2) nxbins = fNumberBinPRF;
920   // Compute the number of entries per group
921   for(Int_t k = 0; k < numberofgroup; k++){
922     for(Int_t nx = 0; nx < nxbins; nx++) {
923       Int_t binnumber = k*nxbins+nx;      
924       nbgroup[k] += ((AliTRDEntriesInfo  *)entriesd)->At(binnumber);
925     }
926   }
927   max = -10.0;
928   groupmax = -1;
929   for(Int_t io = 0; io < numberofgroup; io++){
930     if(nbgroup[io] > max){
931       max = nbgroup[io];
932       groupmax = io;
933     }
934   }
935   if((max == 0.0) || (groupmax < 0.0) || (groupmax >= numberofgroup)) return kFALSE;
936
937   return kTRUE;
938
939 }
940 //_____________________________________________________________________________
941 TGraphErrors *AliTRDCalibraVector::ConvertVectorPHTGraphErrors(Int_t det, Int_t group , const Char_t * name)
942 {
943   //
944   // Convert the fVectorPHMean, fVectorPHSquares and fVectorPHEntries in TGraphErrors
945   //
946
947   // Take the info
948   fPHEntries[det] = ((AliTRDEntriesInfo  *)GetPHEntries(det,kTRUE));
949   fPHMean[det]    = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
950   fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
951   
952
953   // Axis
954   Float_t sf = 10.0;
955   AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
956   if (!parCom) {
957     AliInfo("Could not get CommonParam, take the default 10MHz");
958   }
959   sf = parCom->GetSamplingFrequency();
960   // Axis
961   Double_t x[35];  // Xaxis
962   Double_t y[35];  // Sum/entries
963   Double_t ex[35]; // Nentries
964   Double_t ey[35]; // Sum of square/nentries
965   Double_t step = 0.0;
966   Double_t min  = 0.0;
967   if(sf > 0.0) step = 1.0 / sf;
968   min  = 0.0;
969   Int_t offset = group*fTimeMax;
970   
971   // Fill histo
972   for (Int_t k = 0; k < fTimeMax; k++) {
973     x[k]  = min + k*step;
974     y[k]  = 0.0;
975     ex[k] = 0.0;
976     ey[k] = 0.0;   
977     Int_t bin = offset+k;
978     // Fill only if there is more than 0 something
979     if (((AliTRDEntriesInfo *)fPHEntries[det])->At(bin) > 0) {
980       ex[k] = ((AliTRDEntriesInfo *)fPHEntries[det])->At(bin);
981       y[k]  = ((AliTRDPhInfo *)fPHMean[det])->At(bin);
982       ey[k] = ((AliTRDPhInfo *)fPHSquares[det])->AtS(bin);
983     }
984   }
985
986   // Define the TGraphErrors
987   if(!fGraph) fGraph = new TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
988   else{ 
989     fGraph->~TGraphErrors();
990     new(fGraph) TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
991   } 
992   fGraph->SetTitle(name); 
993
994   return fGraph;
995
996 }
997 //_____________________________________________________________________________
998 TGraphErrors *AliTRDCalibraVector::ConvertVectorPRFTGraphErrors(Int_t det, Int_t group , const Char_t * name)
999 {
1000   //
1001   // Convert the fVectorPRFMean, fVectorPRFSquares and fVectorPRFEntries in TGraphErrors
1002   //
1003
1004   // Take the info
1005   fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
1006   fPRFMean[det]    = ((AliTRDPrfInfo     *)GetPRFMean(det,kTRUE));
1007   fPRFSquares[det] = ((AliTRDPrfInfo     *)GetPRFSquares(det,kTRUE));
1008   
1009
1010   // Axis
1011   Double_t x[200];  // Xaxis
1012   Double_t y[200];  // Sum/entries
1013   Double_t ex[200]; //Nentries
1014   Double_t ey[200]; // Sum of square/nentries
1015   Double_t step = 0.0;
1016   Double_t min  = 0.0;
1017   if(fNumberBinPRF) step = (2*TMath::Abs(fPRFRange)) / fNumberBinPRF;
1018   min  = -TMath::Abs(fPRFRange) + step / 2.0;
1019   Int_t offset = group*fNumberBinPRF;
1020   //printf("number of total: %d\n",fNumberBinPRF);
1021   // Fill histo
1022   for (Int_t k = 0; k < fNumberBinPRF; k++) {
1023     x[k]  = min + k*step;
1024     y[k]  = 0.0;
1025     ex[k] = 0.0;
1026     ey[k] = 0.0;
1027     Int_t bin = offset+k;
1028     // Fill only if there is more than 0 something
1029     if (((AliTRDEntriesInfo *)fPRFEntries[det])->At(bin) > 0) {
1030       ex[k] = ((AliTRDEntriesInfo *)fPRFEntries[det])->At(bin);
1031       y[k]  = ((AliTRDPrfInfo *)fPRFMean[det])->At(bin);
1032       ey[k] = ((AliTRDPrfInfo *)fPRFSquares[det])->At(bin);
1033     }
1034     //printf("Number of entries %f for %d\n",ex[k],k);
1035   }
1036
1037   // Define the TGraphErrors
1038   if(!fGraph) fGraph = new TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1039   else{ 
1040     fGraph->~TGraphErrors();
1041     new(fGraph) TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1042   }
1043   fGraph->SetTitle(name); 
1044
1045   return fGraph;
1046
1047
1048
1049 }
1050 //_____________________________________________________________________________
1051 TH1F *AliTRDCalibraVector::CorrectTheError(const TGraphErrors *hist, Int_t &nbEntries)
1052 {
1053   //
1054   // In the case of the vectors method the trees contains TGraphErrors for PH and PRF
1055   // to be able to add them after
1056   // We convert it to a TH1F to be able to applied the same fit function method
1057   // After having called this function you can not add the statistics anymore
1058   //
1059
1060   Int_t nbins       = hist->GetN();
1061   Double_t *x       = hist->GetX();
1062   Double_t *entries = hist->GetEX();
1063   Double_t *mean    = hist->GetY();
1064   Double_t *square  = hist->GetEY();
1065   nbEntries   = 0;
1066
1067   if (nbins < 2) {
1068     return 0x0; 
1069   }
1070
1071   Double_t step     = x[1] - x[0]; 
1072   Double_t minvalue = x[0] - step/2;
1073   Double_t maxvalue = x[(nbins-1)] + step/2;
1074
1075   if(!fHisto) fHisto = new TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1076   else{ 
1077     fHisto->~TH1F();
1078     new(fHisto) TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1079   }
1080
1081   for (Int_t k = 0; k < nbins; k++) {
1082     fHisto->SetBinContent(k+1,mean[k]);
1083     if (entries[k] > 0.0) {
1084       nbEntries += (Int_t) entries[k];
1085       Double_t d = TMath::Abs(square[k] - (mean[k]*mean[k]));
1086       fHisto->SetBinError(k+1,TMath::Sqrt(d/entries[k]));
1087     }
1088     else {
1089       fHisto->SetBinError(k+1,0.0);
1090     }
1091   }
1092
1093   return fHisto;
1094  
1095 }  
1096 //_____________________________________________________________________________
1097 TH1F *AliTRDCalibraVector::ConvertVectorCHHisto(Int_t det, Int_t group, const Char_t * name)
1098 {
1099   //
1100   // Convert the fVectorCHEntries in TH1F
1101   //
1102
1103   // Take the info
1104   fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
1105   
1106   // Init the stuff
1107   if(!fHisto) fHisto = new TH1F(name,name,fNumberBinCharge,0,300);
1108   else{ 
1109     fHisto->~TH1F();
1110     new(fHisto) TH1F(name,name,fNumberBinCharge,0,300);
1111   }
1112   fHisto->Sumw2();
1113   Int_t offset = group*fNumberBinCharge;
1114   // Fill histo
1115   for (Int_t k = 0; k < fNumberBinCharge; k++) {
1116     Int_t bin = offset+k;
1117     fHisto->SetBinContent(k+1,((AliTRDEntriesInfo *)fCHEntries[det])->At(bin));
1118     fHisto->SetBinError(k+1,TMath::Sqrt(TMath::Abs(((AliTRDEntriesInfo *)fCHEntries[det])->At(bin))));
1119   }
1120   
1121   return fHisto;
1122
1123
1124 //_____________________________________________________________________
1125 TObject* AliTRDCalibraVector::GetPHEntries(Int_t det
1126                                               , Bool_t force) /*FOLD00*/
1127 {
1128     //
1129     // return pointer to Carge ROC Calibration
1130     // if force is true create a new histogram if it doesn't exist allready
1131     //
1132     AliTRDEntriesInfo**arr = &fPHEntries[0];
1133     return (TObject *) GetEntriesPH(det, arr, force);
1134 }
1135 //_____________________________________________________________________
1136 TObject* AliTRDCalibraVector::GetPRFEntries(Int_t det
1137                                                , Bool_t force) /*FOLD00*/
1138 {
1139     //
1140     // return pointer to Carge ROC Calibration
1141     // if force is true create a new histogram if it doesn't exist allready
1142     //
1143     AliTRDEntriesInfo**arr = &fPRFEntries[0];
1144     return (TObject *) GetEntriesPRF(det, arr, force);
1145 }
1146 //_____________________________________________________________________
1147 TObject* AliTRDCalibraVector::GetCHEntries(Int_t det
1148                                               , Bool_t force) /*FOLD00*/
1149 {
1150     //
1151     // return pointer to Carge ROC Calibration
1152     // if force is true create a new histogram if it doesn't exist allready
1153     //
1154     AliTRDEntriesInfo**arr = &fCHEntries[0];
1155     return (TObject *) GetEntriesCH(det, arr, force);
1156 }
1157 //_____________________________________________________________________
1158 TObject* AliTRDCalibraVector::GetPHMean(Int_t det
1159                                            , Bool_t force) /*FOLD00*/
1160 {
1161     //
1162     // return pointer to ROC Calibration
1163     // if force is true create a new array
1164     //
1165     AliTRDPhInfo**arr = &fPHMean[0];
1166     return (TObject *) GetMeanSquaresPH(det, arr, force);
1167 }
1168 //_____________________________________________________________________
1169 TObject* AliTRDCalibraVector::GetPHSquares(Int_t det
1170                                               , Bool_t force) /*FOLD00*/
1171 {
1172     //
1173     // return pointer to ROC Calibration
1174     // if force is true create a new array
1175     //
1176     AliTRDPhInfo**arr = &fPHSquares[0];
1177     return (TObject *)  GetMeanSquaresPH(det, arr, force);
1178 }
1179 //_____________________________________________________________________
1180 TObject* AliTRDCalibraVector::GetPRFMean(Int_t det
1181                                             , Bool_t force) /*FOLD00*/
1182 {
1183     //
1184     // return pointer to ROC Calibration
1185     // if force is true create a new array
1186     //
1187     AliTRDPrfInfo**arr = &fPRFMean[0];
1188     return (TObject *) GetMeanSquaresPRF(det, arr, force);
1189 }
1190 //_____________________________________________________________________
1191 TObject* AliTRDCalibraVector::GetPRFSquares(Int_t det
1192                                                , Bool_t force) /*FOLD00*/
1193 {
1194     //
1195     // return pointer to ROC Calibration
1196     // if force is true create a new array
1197     //
1198     AliTRDPrfInfo**arr = &fPRFSquares[0];
1199     return (TObject *) GetMeanSquaresPRF(det, arr, force);
1200 }
1201 //_____________________________________________________________________
1202 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesCH(Int_t det
1203                                                , AliTRDEntriesInfo** arr
1204                                                , Bool_t force) /*FOLD00*/
1205 {
1206     //
1207     // return pointer to UShort_t array Entries
1208     // if force is true create a new UShort_t array if it doesn't exist allready
1209     //
1210   if ( (!force) || (arr[det]))
1211     return (AliTRDEntriesInfo*)arr[det];
1212
1213   // if we are forced and TArrayI doesn't yes exist create it
1214   Int_t ngroup = GetTotalNumberOfBinsInDetector(det,0,fNumberBinCharge); 
1215   // init
1216   arr[det] = new AliTRDEntriesInfo(ngroup);
1217   
1218   return (AliTRDEntriesInfo*)arr[det];
1219
1220 }
1221 //_____________________________________________________________________
1222 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesPRF(Int_t det
1223                                                , AliTRDEntriesInfo** arr
1224                                                , Bool_t force) /*FOLD00*/
1225 {
1226     //
1227     // return pointer to UShort_t array Entries
1228     // if force is true create a new UShort_t array if it doesn't exist allready
1229     //
1230   if ( (!force) || (arr[det]))
1231     return (AliTRDEntriesInfo*)arr[det];
1232
1233   // if we are forced and TArrayI doesn't yes exist create it
1234   Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF); 
1235   // init
1236   arr[det] = new AliTRDEntriesInfo(ngroup);
1237   
1238   return (AliTRDEntriesInfo*)arr[det];
1239
1240 }
1241 //_____________________________________________________________________
1242 AliTRDEntriesInfo *AliTRDCalibraVector::GetEntriesPH(Int_t det
1243                                               , AliTRDEntriesInfo ** arr
1244                                               , Bool_t force) /*FOLD00*/
1245 {
1246     //
1247     // return pointer to UShort_t array Entries
1248     // if force is true create a new UShort_t array if it doesn't exist allready
1249     //
1250     if ( (!force) || (arr[det]))
1251         return (AliTRDEntriesInfo *)arr[det];
1252
1253     // if we are forced and UShort_t doesn't yet exist create it
1254     Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax); 
1255     // init
1256     arr[det] = new AliTRDEntriesInfo(ngroup);
1257     
1258     return (AliTRDEntriesInfo*)arr[det];
1259    
1260 }
1261 //_____________________________________________________________________
1262 AliTRDPhInfo* AliTRDCalibraVector::GetMeanSquaresPH(Int_t det
1263                                                   , AliTRDPhInfo** arr
1264                                                   , Bool_t force) /*FOLD00*/
1265 {
1266     //
1267     // return pointer to Float_t array Mean or Squares
1268     // if force is true create a new Float_t array if it doesn't exist allready
1269     //
1270     if ( (!force) || (arr[det]))
1271         return (AliTRDPhInfo*)arr[det];
1272
1273     // if we are forced and Float_t array doesn't yes exist create it
1274     Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax); 
1275     // init
1276     arr[det] = new AliTRDPhInfo(ngroup);
1277     
1278     return ((AliTRDPhInfo *)arr[det]);
1279 }
1280 //_____________________________________________________________________
1281 AliTRDPrfInfo* AliTRDCalibraVector::GetMeanSquaresPRF(Int_t det
1282                                                    , AliTRDPrfInfo** arr
1283                                                    , Bool_t force) /*FOLD00*/
1284 {
1285     //
1286     // return pointer to Float_t array Mean or Squares
1287     // if force is true create a new array if it doesn't exist allready
1288     //
1289   if ( (!force) || (arr[det]))
1290     return arr[det];
1291   
1292   // if we are forced and the array doesn't yet exist create it
1293   Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF); 
1294   // init
1295   arr[det] = new AliTRDPrfInfo(ngroup);
1296   
1297   return (AliTRDPrfInfo*)arr[det];
1298    
1299 }
1300 //_____________________________________________________________________________
1301 Int_t AliTRDCalibraVector::GetTotalNumberOfBinsInDetector(Int_t det, Int_t i, Int_t nbBin) const
1302 {
1303   //
1304   // Get the total number of bins (Nb of bins*Nb of groups) in the detector det for the group i
1305   //
1306
1307   Int_t ngroup = 0;
1308   Int_t stack  = AliTRDgeometry::GetStack(det);
1309   if(stack == 2) ngroup = fDetCha2[i]*nbBin;
1310   else ngroup = fDetCha0[i]*nbBin;
1311
1312   return ngroup;
1313  
1314 }
1315 //____________________________________________________________________________
1316 Int_t AliTRDCalibraVector::GetNz(Int_t i) const
1317 {
1318   //
1319   // Get Nz the granularity in row
1320   //
1321
1322   Int_t nz = 0;
1323   if(i==0) nz = (Int_t)(fModeCH>>4);
1324   if(i==1) nz = (Int_t)(fModePH>>4);
1325   if(i==2) nz = (Int_t)(fModePRF>>4);
1326   
1327   return nz;
1328
1329 }
1330 //____________________________________________________________________________
1331 Int_t AliTRDCalibraVector::GetNrphi(Int_t i) const
1332 {
1333   //
1334   // Get Nrphi the granularity in col
1335   //
1336
1337   Int_t nrphi = 0;
1338   if(i==0) nrphi = (Int_t)(fModeCH&15);
1339   if(i==1) nrphi = (Int_t)(fModePH&15);
1340   if(i==2) nrphi = (Int_t)(fModePRF&15);
1341   
1342   return nrphi;
1343
1344 }
1345 //_________________________________________________________________________________
1346 TString AliTRDCalibraVector::GetNamePH() const
1347 {
1348   //
1349   // Get the name of PH to know the granularity
1350   //
1351   
1352   Int_t nz = GetNz(1);
1353   Int_t nrphi = GetNrphi(1);
1354
1355   TString name("Nz");
1356   name += nz;
1357   name += "Nrphi";
1358   name += nrphi;
1359   
1360   return name;
1361
1362 }   
1363 //_________________________________________________________________________________
1364 TString AliTRDCalibraVector::GetNameCH() const
1365 {
1366   //
1367   // Get the name of CH to know the granularity
1368   //
1369   
1370   Int_t nz = GetNz(0);
1371   Int_t nrphi = GetNrphi(0);
1372
1373   TString name("Nz");
1374   name += nz;
1375   name += "Nrphi";
1376   name += nrphi;
1377   
1378   return name;
1379
1380 }   
1381 //_________________________________________________________________________________
1382 TString AliTRDCalibraVector::GetNamePRF() const
1383 {
1384   //
1385   // Get the name of PRF to know the granularity
1386   //
1387
1388   Int_t nz = GetNz(2);
1389   Int_t nrphi = GetNrphi(2);
1390   
1391   TString name("Nz");
1392   name += nz;
1393   name += "Nrphi";
1394   name += nrphi;
1395   name += "Ngp";
1396   name += fNbGroupPRF;
1397   
1398   return name;
1399
1400 }
1401 //____________________________________________________________________________
1402 void AliTRDCalibraVector::SetNzNrphi(Int_t i, Int_t nz, Int_t nrphi) 
1403 {
1404   //
1405   // Set NzNrphi for the granularity
1406   //
1407   
1408   if(i==0) {
1409     fModeCH = nz;
1410     fModeCH = fModeCH << 4;
1411     fModeCH |= nrphi;
1412   }
1413   if(i==1) {
1414     fModePH = nz;
1415     fModePH = fModePH << 4;
1416     fModePH |= nrphi;
1417   }
1418   if(i==2) {
1419     fModePRF = nz;
1420     fModePRF = fModePRF << 4;
1421     fModePRF |= nrphi;
1422   }
1423   
1424 }