]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibraVector.cxx
Input number added to Print
[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     sf = parCom->GetSamplingFrequency();
988   }
989   else {
990     AliInfo("Could not get CommonParam, take the default 10MHz");
991   }
992   // Axis
993   Double_t x[35];  // Xaxis
994   Double_t y[35];  // Sum/entries
995   Double_t ex[35]; // Nentries
996   Double_t ey[35]; // Sum of square/nentries
997   Double_t step = 0.0;
998   Double_t min  = 0.0;
999   if(sf > 0.0) step = 1.0 / sf;
1000   min  = 0.0;
1001   Int_t offset = group*fTimeMax;
1002   
1003   // Fill histo
1004   for (Int_t k = 0; k < fTimeMax; k++) {
1005     x[k]  = min + k*step;
1006     y[k]  = 0.0;
1007     ex[k] = 0.0;
1008     ey[k] = 0.0;   
1009     Int_t bin = offset+k;
1010     // Fill only if there is more than 0 something
1011     if (((AliTRDEntriesInfo *)fPHEntries[det])->At(bin) > 0) {
1012       ex[k] = ((AliTRDEntriesInfo *)fPHEntries[det])->At(bin);
1013       y[k]  = ((AliTRDPhInfo *)fPHMean[det])->At(bin);
1014       ey[k] = ((AliTRDPhInfo *)fPHSquares[det])->AtS(bin);
1015     }
1016   }
1017
1018   // Define the TGraphErrors
1019   if(!fGraph) fGraph = new TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
1020   else{ 
1021     fGraph->~TGraphErrors();
1022     new(fGraph) TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
1023   } 
1024   fGraph->SetTitle(name); 
1025
1026   return fGraph;
1027
1028 }
1029 //_____________________________________________________________________________
1030 TGraphErrors *AliTRDCalibraVector::ConvertVectorPRFTGraphErrors(Int_t det, Int_t group , const Char_t * name)
1031 {
1032   //
1033   // Convert the fVectorPRFMean, fVectorPRFSquares and fVectorPRFEntries in TGraphErrors
1034   //
1035
1036   // Take the info
1037   fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
1038   fPRFMean[det]    = ((AliTRDPrfInfo     *)GetPRFMean(det,kTRUE));
1039   fPRFSquares[det] = ((AliTRDPrfInfo     *)GetPRFSquares(det,kTRUE));
1040   
1041
1042   // Axis
1043   Double_t x[200];  // Xaxis
1044   Double_t y[200];  // Sum/entries
1045   Double_t ex[200]; //Nentries
1046   Double_t ey[200]; // Sum of square/nentries
1047   Double_t step = 0.0;
1048   Double_t min  = 0.0;
1049   if(fNumberBinPRF) step = (2*TMath::Abs(fPRFRange)) / fNumberBinPRF;
1050   min  = -TMath::Abs(fPRFRange) + step / 2.0;
1051   Int_t offset = group*fNumberBinPRF;
1052   //printf("number of total: %d\n",fNumberBinPRF);
1053   // Fill histo
1054   for (Int_t k = 0; k < fNumberBinPRF; k++) {
1055     x[k]  = min + k*step;
1056     y[k]  = 0.0;
1057     ex[k] = 0.0;
1058     ey[k] = 0.0;
1059     Int_t bin = offset+k;
1060     // Fill only if there is more than 0 something
1061     if (((AliTRDEntriesInfo *)fPRFEntries[det])->At(bin) > 0) {
1062       ex[k] = ((AliTRDEntriesInfo *)fPRFEntries[det])->At(bin);
1063       y[k]  = ((AliTRDPrfInfo *)fPRFMean[det])->At(bin);
1064       ey[k] = ((AliTRDPrfInfo *)fPRFSquares[det])->At(bin);
1065     }
1066     //printf("Number of entries %f for %d\n",ex[k],k);
1067   }
1068
1069   // Define the TGraphErrors
1070   if(!fGraph) fGraph = new TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1071   else{ 
1072     fGraph->~TGraphErrors();
1073     new(fGraph) TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1074   }
1075   fGraph->SetTitle(name); 
1076
1077   return fGraph;
1078
1079
1080
1081 }
1082 //_____________________________________________________________________________
1083 TH1F *AliTRDCalibraVector::CorrectTheError(const TGraphErrors *hist, Int_t &nbEntries)
1084 {
1085   //
1086   // In the case of the vectors method the trees contains TGraphErrors for PH and PRF
1087   // to be able to add them after
1088   // We convert it to a TH1F to be able to applied the same fit function method
1089   // After having called this function you can not add the statistics anymore
1090   //
1091
1092   Int_t nbins       = hist->GetN();
1093   Double_t *x       = hist->GetX();
1094   Double_t *entries = hist->GetEX();
1095   Double_t *mean    = hist->GetY();
1096   Double_t *square  = hist->GetEY();
1097   nbEntries   = 0;
1098
1099   if (nbins < 2) {
1100     return 0x0; 
1101   }
1102
1103   Double_t step     = x[1] - x[0]; 
1104   Double_t minvalue = x[0] - step/2;
1105   Double_t maxvalue = x[(nbins-1)] + step/2;
1106
1107   if(!fHisto) fHisto = new TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1108   else{ 
1109     fHisto->~TH1F();
1110     new(fHisto) TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1111   }
1112
1113   for (Int_t k = 0; k < nbins; k++) {
1114     fHisto->SetBinContent(k+1,mean[k]);
1115     if (entries[k] > 0.0) {
1116       nbEntries += (Int_t) entries[k];
1117       Double_t d = TMath::Abs(square[k] - (mean[k]*mean[k]));
1118       fHisto->SetBinError(k+1,TMath::Sqrt(d/entries[k]));
1119     }
1120     else {
1121       fHisto->SetBinError(k+1,0.0);
1122     }
1123   }
1124
1125   return fHisto;
1126  
1127 }  
1128 //_____________________________________________________________________________
1129 TH1F *AliTRDCalibraVector::ConvertVectorCHHisto(Int_t det, Int_t group, const Char_t * name)
1130 {
1131   //
1132   // Convert the fVectorCHEntries in TH1F
1133   //
1134
1135   // Take the info
1136   fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
1137   
1138   // Init the stuff
1139   if(!fHisto) fHisto = new TH1F(name,name,fNumberBinCharge,0,300);
1140   else{ 
1141     fHisto->~TH1F();
1142     new(fHisto) TH1F(name,name,fNumberBinCharge,0,300);
1143   }
1144   fHisto->Sumw2();
1145   Int_t offset = group*fNumberBinCharge;
1146   // Fill histo
1147   for (Int_t k = 0; k < fNumberBinCharge; k++) {
1148     Int_t bin = offset+k;
1149     fHisto->SetBinContent(k+1,((AliTRDEntriesInfo *)fCHEntries[det])->At(bin));
1150     fHisto->SetBinError(k+1,TMath::Sqrt(TMath::Abs(((AliTRDEntriesInfo *)fCHEntries[det])->At(bin))));
1151   }
1152   
1153   return fHisto;
1154
1155
1156 //_____________________________________________________________________
1157 TObject* AliTRDCalibraVector::GetPHEntries(Int_t det
1158                                               , Bool_t force) /*FOLD00*/
1159 {
1160     //
1161     // return pointer to Carge ROC Calibration
1162     // if force is true create a new histogram if it doesn't exist allready
1163     //
1164     AliTRDEntriesInfo**arr = &fPHEntries[0];
1165     return (TObject *) GetEntriesPH(det, arr, force);
1166 }
1167 //_____________________________________________________________________
1168 TObject* AliTRDCalibraVector::GetPRFEntries(Int_t det
1169                                                , Bool_t force) /*FOLD00*/
1170 {
1171     //
1172     // return pointer to Carge ROC Calibration
1173     // if force is true create a new histogram if it doesn't exist allready
1174     //
1175     AliTRDEntriesInfo**arr = &fPRFEntries[0];
1176     return (TObject *) GetEntriesPRF(det, arr, force);
1177 }
1178 //_____________________________________________________________________
1179 TObject* AliTRDCalibraVector::GetCHEntries(Int_t det
1180                                               , Bool_t force) /*FOLD00*/
1181 {
1182     //
1183     // return pointer to Carge ROC Calibration
1184     // if force is true create a new histogram if it doesn't exist allready
1185     //
1186     AliTRDEntriesInfo**arr = &fCHEntries[0];
1187     return (TObject *) GetEntriesCH(det, arr, force);
1188 }
1189 //_____________________________________________________________________
1190 TObject* AliTRDCalibraVector::GetPHMean(Int_t det
1191                                            , Bool_t force) /*FOLD00*/
1192 {
1193     //
1194     // return pointer to ROC Calibration
1195     // if force is true create a new array
1196     //
1197     AliTRDPhInfo**arr = &fPHMean[0];
1198     return (TObject *) GetMeanSquaresPH(det, arr, force);
1199 }
1200 //_____________________________________________________________________
1201 TObject* AliTRDCalibraVector::GetPHSquares(Int_t det
1202                                               , Bool_t force) /*FOLD00*/
1203 {
1204     //
1205     // return pointer to ROC Calibration
1206     // if force is true create a new array
1207     //
1208     AliTRDPhInfo**arr = &fPHSquares[0];
1209     return (TObject *)  GetMeanSquaresPH(det, arr, force);
1210 }
1211 //_____________________________________________________________________
1212 TObject* AliTRDCalibraVector::GetPRFMean(Int_t det
1213                                             , Bool_t force) /*FOLD00*/
1214 {
1215     //
1216     // return pointer to ROC Calibration
1217     // if force is true create a new array
1218     //
1219     AliTRDPrfInfo**arr = &fPRFMean[0];
1220     return (TObject *) GetMeanSquaresPRF(det, arr, force);
1221 }
1222 //_____________________________________________________________________
1223 TObject* AliTRDCalibraVector::GetPRFSquares(Int_t det
1224                                                , Bool_t force) /*FOLD00*/
1225 {
1226     //
1227     // return pointer to ROC Calibration
1228     // if force is true create a new array
1229     //
1230     AliTRDPrfInfo**arr = &fPRFSquares[0];
1231     return (TObject *) GetMeanSquaresPRF(det, arr, force);
1232 }
1233 //_____________________________________________________________________
1234 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesCH(Int_t det
1235                                                , AliTRDEntriesInfo** arr
1236                                                , Bool_t force) /*FOLD00*/
1237 {
1238     //
1239     // return pointer to UShort_t array Entries
1240     // if force is true create a new UShort_t array if it doesn't exist allready
1241     //
1242   if ( (!force) || (arr[det]))
1243     return (AliTRDEntriesInfo*)arr[det];
1244
1245   // if we are forced and TArrayI doesn't yes exist create it
1246   Int_t ngroup = GetTotalNumberOfBinsInDetector(det,0,fNumberBinCharge); 
1247   // init
1248   arr[det] = new AliTRDEntriesInfo(ngroup);
1249   
1250   return (AliTRDEntriesInfo*)arr[det];
1251
1252 }
1253 //_____________________________________________________________________
1254 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesPRF(Int_t det
1255                                                , AliTRDEntriesInfo** arr
1256                                                , Bool_t force) /*FOLD00*/
1257 {
1258     //
1259     // return pointer to UShort_t array Entries
1260     // if force is true create a new UShort_t array if it doesn't exist allready
1261     //
1262   if ( (!force) || (arr[det]))
1263     return (AliTRDEntriesInfo*)arr[det];
1264
1265   // if we are forced and TArrayI doesn't yes exist create it
1266   Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF); 
1267   // init
1268   arr[det] = new AliTRDEntriesInfo(ngroup);
1269   
1270   return (AliTRDEntriesInfo*)arr[det];
1271
1272 }
1273 //_____________________________________________________________________
1274 AliTRDEntriesInfo *AliTRDCalibraVector::GetEntriesPH(Int_t det
1275                                               , AliTRDEntriesInfo ** arr
1276                                               , Bool_t force) /*FOLD00*/
1277 {
1278     //
1279     // return pointer to UShort_t array Entries
1280     // if force is true create a new UShort_t array if it doesn't exist allready
1281     //
1282     if ( (!force) || (arr[det]))
1283         return (AliTRDEntriesInfo *)arr[det];
1284
1285     // if we are forced and UShort_t doesn't yet exist create it
1286     Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax); 
1287     // init
1288     arr[det] = new AliTRDEntriesInfo(ngroup);
1289     
1290     return (AliTRDEntriesInfo*)arr[det];
1291    
1292 }
1293 //_____________________________________________________________________
1294 AliTRDPhInfo* AliTRDCalibraVector::GetMeanSquaresPH(Int_t det
1295                                                   , AliTRDPhInfo** arr
1296                                                   , Bool_t force) /*FOLD00*/
1297 {
1298     //
1299     // return pointer to Float_t array Mean or Squares
1300     // if force is true create a new Float_t array if it doesn't exist allready
1301     //
1302     if ( (!force) || (arr[det]))
1303         return (AliTRDPhInfo*)arr[det];
1304
1305     // if we are forced and Float_t array doesn't yes exist create it
1306     Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax); 
1307     // init
1308     arr[det] = new AliTRDPhInfo(ngroup);
1309     
1310     return ((AliTRDPhInfo *)arr[det]);
1311 }
1312 //_____________________________________________________________________
1313 AliTRDPrfInfo* AliTRDCalibraVector::GetMeanSquaresPRF(Int_t det
1314                                                    , AliTRDPrfInfo** arr
1315                                                    , Bool_t force) /*FOLD00*/
1316 {
1317     //
1318     // return pointer to Float_t array Mean or Squares
1319     // if force is true create a new array if it doesn't exist allready
1320     //
1321   if ( (!force) || (arr[det]))
1322     return arr[det];
1323   
1324   // if we are forced and the array doesn't yet exist create it
1325   Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF); 
1326   // init
1327   arr[det] = new AliTRDPrfInfo(ngroup);
1328   
1329   return (AliTRDPrfInfo*)arr[det];
1330    
1331 }
1332 //_____________________________________________________________________________
1333 Int_t AliTRDCalibraVector::GetTotalNumberOfBinsInDetector(Int_t det, Int_t i, Int_t nbBin) const
1334 {
1335   //
1336   // Get the total number of bins (Nb of bins*Nb of groups) in the detector det for the group i
1337   //
1338
1339   Int_t ngroup = 0;
1340   Int_t stack  = AliTRDgeometry::GetStack(det);
1341   if(stack == 2) ngroup = fDetCha2[i]*nbBin;
1342   else ngroup = fDetCha0[i]*nbBin;
1343
1344   return ngroup;
1345  
1346 }
1347 //____________________________________________________________________________
1348 Int_t AliTRDCalibraVector::GetNz(Int_t i) const
1349 {
1350   //
1351   // Get Nz the granularity in row
1352   //
1353
1354   Int_t nz = 0;
1355   if(i==0) nz = (Int_t)(fModeCH>>4);
1356   if(i==1) nz = (Int_t)(fModePH>>4);
1357   if(i==2) nz = (Int_t)(fModePRF>>4);
1358   
1359   return nz;
1360
1361 }
1362 //____________________________________________________________________________
1363 Int_t AliTRDCalibraVector::GetNrphi(Int_t i) const
1364 {
1365   //
1366   // Get Nrphi the granularity in col
1367   //
1368
1369   Int_t nrphi = 0;
1370   if(i==0) nrphi = (Int_t)(fModeCH&15);
1371   if(i==1) nrphi = (Int_t)(fModePH&15);
1372   if(i==2) nrphi = (Int_t)(fModePRF&15);
1373   
1374   return nrphi;
1375
1376 }
1377 //_________________________________________________________________________________
1378 TString AliTRDCalibraVector::GetNamePH() const
1379 {
1380   //
1381   // Get the name of PH to know the granularity
1382   //
1383   
1384   Int_t nz = GetNz(1);
1385   Int_t nrphi = GetNrphi(1);
1386
1387   TString name("Nz");
1388   name += nz;
1389   name += "Nrphi";
1390   name += nrphi;
1391   
1392   return name;
1393
1394 }   
1395 //_________________________________________________________________________________
1396 TString AliTRDCalibraVector::GetNameCH() const
1397 {
1398   //
1399   // Get the name of CH to know the granularity
1400   //
1401   
1402   Int_t nz = GetNz(0);
1403   Int_t nrphi = GetNrphi(0);
1404
1405   TString name("Nz");
1406   name += nz;
1407   name += "Nrphi";
1408   name += nrphi;
1409   
1410   return name;
1411
1412 }   
1413 //_________________________________________________________________________________
1414 TString AliTRDCalibraVector::GetNamePRF() const
1415 {
1416   //
1417   // Get the name of PRF to know the granularity
1418   //
1419
1420   Int_t nz = GetNz(2);
1421   Int_t nrphi = GetNrphi(2);
1422   
1423   TString name("Nz");
1424   name += nz;
1425   name += "Nrphi";
1426   name += nrphi;
1427   name += "Ngp";
1428   name += fNbGroupPRF;
1429   
1430   return name;
1431
1432 }
1433 //____________________________________________________________________________
1434 void AliTRDCalibraVector::SetNzNrphi(Int_t i, Int_t nz, Int_t nrphi) 
1435 {
1436   //
1437   // Set NzNrphi for the granularity
1438   //
1439   
1440   if(i==0) {
1441     fModeCH = nz;
1442     fModeCH = fModeCH << 4;
1443     fModeCH |= nrphi;
1444   }
1445   if(i==1) {
1446     fModePH = nz;
1447     fModePH = fModePH << 4;
1448     fModePH |= nrphi;
1449   }
1450   if(i==2) {
1451     fModePRF = nz;
1452     fModePRF = fModePRF << 4;
1453     fModePRF |= nrphi;
1454   }
1455   
1456 }
1457