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