1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // AliTRDCalibraVector //
22 // This class is for the vector method of the TRD calibration. //
25 // R. Bailhache (R.Bailhache@gsi.de) //
27 ////////////////////////////////////////////////////////////////////////////
29 #include <TGraphErrors.h>
31 #include <TObjArray.h>
34 #include <TDirectory.h>
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"
49 ClassImp(AliTRDCalibraVector)
51 //______________________________________________________________________________________
52 AliTRDCalibraVector::AliTRDCalibraVector()
71 // Default constructor
74 for (Int_t idet = 0; idet < 540; idet++){
76 fPHEntries[idet]= 0x0;
78 fPHSquares[idet]= 0x0;
80 fPRFEntries[idet]= 0x0;
82 fPRFSquares[idet]= 0x0;
85 fCHEntries[idet]= 0x0;
89 for(Int_t k = 0; k < 3; k++){
95 //______________________________________________________________________________________
96 AliTRDCalibraVector::AliTRDCalibraVector(const AliTRDCalibraVector &c)
100 ,fModePRF(c.fModePRF)
101 ,fNbGroupPRF(c.fNbGroupPRF)
109 ,fNumberBinCharge(c.fNumberBinCharge)
110 ,fNumberBinPRF(c.fNumberBinPRF)
111 ,fTimeMax(c.fTimeMax)
112 ,fPRFRange(c.fPRFRange)
118 for(Int_t k = 0; k < 3; k++){
119 fDetCha0[k] = c.fDetCha0[k];
120 fDetCha2[k] = c.fDetCha2[k];
123 for (Int_t idet = 0; idet < 540; idet++){
125 const AliTRDEntriesInfo *phEntries = (AliTRDEntriesInfo*)c.fPHEntries[idet];
126 const AliTRDPhInfo *phMean = (AliTRDPhInfo *)c.fPHMean[idet];
127 const AliTRDPhInfo *phSquares = (AliTRDPhInfo *)c.fPHSquares[idet];
129 const AliTRDEntriesInfo *prfEntries = (AliTRDEntriesInfo*)c.fPRFEntries[idet];
130 const AliTRDPrfInfo *prfMean = (AliTRDPrfInfo *)c.fPRFMean[idet];
131 const AliTRDPrfInfo *prfSquares = (AliTRDPrfInfo *)c.fPRFSquares[idet];
133 const AliTRDEntriesInfo *chEntries = (AliTRDEntriesInfo*)c.fCHEntries[idet];
135 if ( chEntries != 0x0 ) fCHEntries[idet] = new AliTRDEntriesInfo(*chEntries);
137 if ( phEntries != 0x0 ) {
138 fPHMean[idet] = new AliTRDPhInfo(*phMean);
139 fPHSquares[idet] = new AliTRDPhInfo(*phSquares);
140 fPHEntries[idet] = new AliTRDEntriesInfo(*phEntries);
143 if ( prfEntries != 0x0 ) {
144 fPRFEntries[idet] = new AliTRDEntriesInfo(*prfEntries);
145 fPRFMean[idet] = new AliTRDPrfInfo(*prfMean);
146 fPRFSquares[idet] = new AliTRDPrfInfo(*prfSquares);
152 //_____________________________________________________________________
153 AliTRDCalibraVector& AliTRDCalibraVector::operator = (const AliTRDCalibraVector &source)
156 // assignment operator
158 if (&source == this) return *this;
159 new (this) AliTRDCalibraVector(source);
163 //____________________________________________________________________________________
164 AliTRDCalibraVector::~AliTRDCalibraVector()
167 // AliTRDCalibraVector destructor
170 for (Int_t i=0; i<540; i++) {
171 delete fPHEntries[i];
173 delete fPHSquares[i];
174 delete fPRFEntries[i];
176 delete fPRFSquares[i];
177 delete fCHEntries[i];
180 if(fHisto) delete fHisto;
181 if(fGraph) delete fGraph;
182 if(fCalVector) delete fCalVector;
185 //_____________________________________________________________________________
186 Long64_t AliTRDCalibraVector::Merge(const TCollection* list)
188 // Merge list of objects (needed by PROOF)
196 TIterator* iter = list->MakeIterator();
199 // collection of generated histograms
201 while((obj = iter->Next()) != 0)
203 AliTRDCalibraVector* entry = dynamic_cast<AliTRDCalibraVector*>(obj);
204 if (entry == 0) continue;
206 if(this->Add(entry)) count++;
212 //_____________________________________________________________________________
213 void AliTRDCalibraVector::TestInit(Int_t i, Int_t detmax)
216 // Init to see the size
219 for(Int_t det = 0; det < detmax; det++){
223 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
224 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
225 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
231 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
232 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
233 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
237 if(i==0) fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
242 //_____________________________________________________________________________
243 Int_t AliTRDCalibraVector::SearchBin(Float_t value, Int_t i) const
251 Float_t fbinmax = value;
252 Int_t fNumberOfBin = -1;
259 fNumberOfBin = fNumberBinCharge;
263 fbinmax = TMath::Abs(fPRFRange);
264 fbinmin = -TMath::Abs(fPRFRange);
265 fNumberOfBin = fNumberBinPRF;
273 if ((value >= fbinmax) ||
278 reponse = (Int_t) ((fNumberOfBin*(value-fbinmin)) / (fbinmax-fbinmin));
284 //_____________________________________________________________________________
285 Bool_t AliTRDCalibraVector::UpdateVectorCH(Int_t det, Int_t group, Float_t value)
288 // Fill the vector CH
292 Int_t bin = SearchBin(value,0);
300 if(fDetectorCH != det){
301 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
304 Int_t entries = ((AliTRDEntriesInfo *)fCHEntries[det])->At(group*fNumberBinCharge+bin);
306 Int_t entriesn = entries+1;
308 if(entriesn > 65535) {
313 ((AliTRDEntriesInfo *)fCHEntries[det])->AddAt(entriesn,group*fNumberBinCharge+bin);
321 //_____________________________________________________________________________
322 Bool_t AliTRDCalibraVector::UpdateVectorPRF(Int_t det, Int_t group, Float_t x, Float_t y)
325 // Fill the vector PRF
329 Int_t bin = SearchBin(x,2);
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));
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);
346 Int_t entriesn = entries+1;
348 if(entriesn > 65535) return kTRUE;
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);
362 //_____________________________________________________________________________
363 Bool_t AliTRDCalibraVector::UpdateVectorPH(Int_t det, Int_t group, Int_t time, Float_t value)
366 // Fill the vector PH
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));
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);
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);
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;
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);
405 //_____________________________________________________________________________
406 Bool_t AliTRDCalibraVector::FillVectorCH(Int_t det, Int_t group, Int_t bin, Int_t entries)
409 // Fill the vector CH
412 if(entries > 65535) return kFALSE;
414 if(fDetectorCH != det){
415 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
418 ((AliTRDEntriesInfo *)fCHEntries[det])->AddAt(entries,group*fNumberBinCharge+bin);
426 //_____________________________________________________________________________
427 Bool_t AliTRDCalibraVector::FillVectorPRF(Int_t det, Int_t group, Int_t bin, Int_t entries, Float_t mean, Float_t square)
430 // Fill the vector PRF
433 if((entries > 65535) || (mean > 1.0) || (mean < 0.0) || (square > 1.0) || (square < 0.0)) return kFALSE;
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));
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);
451 //_____________________________________________________________________________
452 Bool_t AliTRDCalibraVector::FillVectorPH(Int_t det, Int_t group, Int_t bin, Int_t entries, Float_t mean, Float_t square)
455 // Fill the vector PH
458 if((entries > 65535) || (mean > 3000.0) || (mean < 0.0) || (square > (3000.0*3000.0)) || (square < 0.0)) return kFALSE;
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));
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);
476 //__________________________________________________________________________________
477 Bool_t AliTRDCalibraVector::Add(AliTRDCalibraVector *calvect)
480 // Add a other AliTRCalibraVector to this one
483 Bool_t result = kTRUE;
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;
495 //printf("All ok for variables before adding!\n");
498 for (Int_t idet = 0; idet < 540; idet++){
500 //printf("Detector %d\n",idet);
502 const AliTRDEntriesInfo *phEntriesvect = (AliTRDEntriesInfo *) calvect->GetPHEntries(idet);
503 const AliTRDPhInfo *phMeanvect = (AliTRDPhInfo *) calvect->GetPHMean(idet);
504 const AliTRDPhInfo *phSquaresvect = (AliTRDPhInfo *) calvect->GetPHSquares(idet);
506 const AliTRDEntriesInfo *prfEntriesvect = (AliTRDEntriesInfo *) calvect->GetPRFEntries(idet);
507 const AliTRDPrfInfo *prfMeanvect = (AliTRDPrfInfo *) calvect->GetPRFMean(idet);
508 const AliTRDPrfInfo *prfSquaresvect = (AliTRDPrfInfo *) calvect->GetPRFSquares(idet);
510 const AliTRDEntriesInfo *chEntriesvect = (AliTRDEntriesInfo *) calvect->GetCHEntries(idet);
512 if ( phEntriesvect != 0x0 ){
514 fPHEntries[idet] = ((AliTRDEntriesInfo *)GetPHEntries(idet,kTRUE));
515 fPHMean[idet] = ((AliTRDPhInfo *)GetPHMean(idet,kTRUE));
516 fPHSquares[idet] = ((AliTRDPhInfo *)GetPHSquares(idet,kTRUE));
518 Int_t total = fPHEntries[idet]->GetSize();
519 //printf("Total size PH %d\n",total);
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);
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);
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);
534 if((entriesn > 0) && (entriesn <= 65535) && (meann >= 0) && (meann < 3000.0) && (squaren >= 0.0) && (squaren < (3000.0*3000.0))) {
536 ((AliTRDEntriesInfo *)fPHEntries[idet])->AddAt(entriesn,k);
537 ((AliTRDPhInfo *)fPHMean[idet])->AddAt(meann,k);
538 ((AliTRDPhInfo *)fPHSquares[idet])->AddAtS(squaren,k);
544 if ( prfEntriesvect != 0x0 ){
546 fPRFEntries[idet] = ((AliTRDEntriesInfo *)GetPRFEntries(idet,kTRUE));
547 fPRFMean[idet] = ((AliTRDPrfInfo *)GetPRFMean(idet,kTRUE));
548 fPRFSquares[idet] = ((AliTRDPrfInfo *)GetPRFSquares(idet,kTRUE));
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);
557 for(Int_t k = 0; k < total; k++){
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);
564 Int_t entriesv = ((AliTRDEntriesInfo *)prfEntriesvect)->At(k);
565 Float_t meanv = ((AliTRDPrfInfo *)prfMeanvect)->At(k);
566 Float_t squarev = ((AliTRDPrfInfo *)prfSquaresvect)->At(k);
568 Int_t entriesn = entries + entriesv;
570 if((entriesn > 0) && (entriesn <= 65535)) {
572 ((AliTRDEntriesInfo *)fPRFEntries[idet])->AddAt(entriesn,k);
574 Float_t meann = (mean*((Float_t)entries)+meanv*((Float_t)entriesv))/((Float_t)entriesn);
576 ((AliTRDPrfInfo *)fPRFMean[idet])->AddAt(meann,k);
579 Float_t squaren = ((square*((Float_t)entries))+(squarev*((Float_t)entriesv)))/((Float_t)entriesn);
581 ((AliTRDPrfInfo *)fPRFSquares[idet])->AddAt(squaren,k);
588 if ( chEntriesvect != 0x0 ){
590 fCHEntries[idet] = ((AliTRDEntriesInfo *)GetCHEntries(idet,kTRUE));
591 //printf("TestAdd\n");
592 fStopFillCH = ((AliTRDEntriesInfo *)fCHEntries[idet])->TestAdd((AliTRDEntriesInfo *)chEntriesvect);
600 ((AliTRDEntriesInfo *)fCHEntries[idet])->Add(chEntriesvect);
608 //_____________________________________________________________________________________________________________________
609 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorCH()
612 // Create a AliTRDCalibraVector detector wise
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;
621 Int_t nybins = 6*4*18*fDetCha0[0]+6*18*fDetCha2[0];
622 Int_t nxbins = fNumberBinCharge;
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;
638 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
640 fCalVector->~AliTRDCalibraVector();
641 new(fCalVector) AliTRDCalibraVector();
643 fCalVector->SetNumberBinCharge(nxbins);
644 fCalVector->SetDetCha0(0,1);
645 fCalVector->SetDetCha2(0,1);
646 fCalVector->SetNzNrphi(0,0,0);
649 for(Int_t det = 0; det < 540; det++){
652 AliTRDEntriesInfo *entriesch = (AliTRDEntriesInfo *)GetCHEntries(det,kFALSE);
653 if(!entriesch) continue;
656 Int_t numberofgroup = 0;
657 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
658 else numberofgroup = perChamber0;
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;
665 for(Int_t k = 0; k < nxbins; k++){
668 // Loop over group in the detector
669 for(Int_t k = 0; k < numberofgroup; k++){
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
676 if(entries[nx] > 65535) {
677 firstnumberofgroup = k;
684 if(fStopFillCH && (firstnumberofgroup == 0)) return 0x0;
685 if(!fStopFillCH) firstnumberofgroup = numberofgroup;
687 // Now add up to possible
688 for(Int_t k = 0; k < nxbins; k++){
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);
699 for(Int_t nx = 0; nx < nxbins; nx++){
700 fCalVector->FillVectorCH(det,0,nx,(Int_t)entries[nx]);
706 //_____________________________________________________________________________________________________________________
707 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorPH()
710 // Create a AliTRDCalibraVector detector wise
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;
720 Int_t nybins = 6*4*18*fDetCha0[1]+6*18*fDetCha2[1];
721 Int_t nxbins = fTimeMax;
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);
734 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
737 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
739 fCalVector->~AliTRDCalibraVector();
740 new(fCalVector) AliTRDCalibraVector();
742 fCalVector->SetTimeMax(nxbins);
743 fCalVector->SetDetCha0(1,1);
744 fCalVector->SetDetCha2(1,1);
745 fCalVector->SetNzNrphi(1,0,0);
748 for(Int_t det = 0; det < 540; det++){
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);
757 Int_t numberofgroup = 0;
758 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
759 else numberofgroup = perChamber0;
762 for(Int_t nx = 0; nx < nxbins; nx++) {
764 Double_t entries = 0.0;
765 Double_t sumw2 = 0.0;
768 // Sum the contributions of the different calibration group in the detector
769 for(Int_t k = 0; k < numberofgroup; k++){
771 Int_t binnumber = k*nxbins+nx;
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;
778 if(((entries+entriesv) > 65535) || ((entries+entriesv) <= 0)) continue;
787 sumw2 = sumw2/((Float_t)entries);
788 sumw = sumw/((Float_t)entries);
791 fCalVector->FillVectorPH(det,0,nx,(Int_t)entries,(Float_t)sumw,(Float_t)sumw2);
798 //_____________________________________________________________________________________________________________________
799 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorPRF()
802 // Create a AliTRDCalibraVector detector wise
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;
811 Int_t nybins = 6*4*18*fDetCha0[2]+ 6*18*fDetCha2[2];
812 Int_t nxbins = fNumberBinPRF;
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);
825 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
828 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
830 fCalVector->~AliTRDCalibraVector();
831 new(fCalVector) AliTRDCalibraVector();
833 fCalVector->SetNumberBinPRF(nxbins);
834 fCalVector->SetDetCha0(2,1);
835 fCalVector->SetDetCha2(2,1);
836 fCalVector->SetNzNrphi(2,0,0);
837 fCalVector->SetNbGroupPRF(fNbGroupPRF);
840 for(Int_t det = 0; det < 540; det++){
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);
849 Int_t numberofgroup = 0;
850 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
851 else numberofgroup = perChamber0;
853 for(Int_t nx = 0; nx < nxbins; nx++) {
855 Double_t entries = 0.0;
856 Double_t sumw2 = 0.0;
859 // Sum the contributions of the different groups in the detector for one bin
860 for(Int_t k = 0; k < numberofgroup; k++){
862 Int_t binnumber = k*nxbins+nx;
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;
868 if(((entries+entriesv) > 65535) || ((entries+entriesv) <= 0)) continue;
877 sumw2 = sumw2/((Float_t)entries);
878 sumw = sumw/((Float_t)entries);
881 fCalVector->FillVectorPRF(det,0,nx,(Int_t)entries,(Float_t)sumw,(Float_t)sumw2);
888 //_______________________________________________________________________________
889 Bool_t AliTRDCalibraVector::FindTheMaxEntries(Int_t i, Int_t &detectormax, Int_t &groupmax)
892 // Find detectormax and groupmax with the biggest number of entries
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");
903 Double_t entries [540];
904 for(Int_t idet = 0; idet < 540; idet++){
908 AliTRDEntriesInfo *entriesd = 0x0;
909 // Take the number of entries per detector
910 for(Int_t idet = 0; idet < 540; idet++){
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;
917 entries[idet] = entriesd->GetSum();
921 // Search detector max
924 for(Int_t idet = 0; idet < 540; idet++){
925 if(entries[idet] > max) {
930 if((max == 0.0) || (detectormax <0.0)) return kFALSE;
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;
938 Int_t numberofgroup = 0;
939 if(AliTRDgeometry::GetStack(detectormax) == 2) numberofgroup = fDetCha2[i];
940 else numberofgroup = fDetCha0[i];
942 Double_t nbgroup [2304];
943 for(Int_t k = 0; k < 2304; k++){
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);
959 for(Int_t io = 0; io < numberofgroup; io++){
960 if(nbgroup[io] > max){
965 if((max == 0.0) || (groupmax < 0.0) || (groupmax >= numberofgroup)) return kFALSE;
970 //_____________________________________________________________________________
971 TGraphErrors *AliTRDCalibraVector::ConvertVectorPHTGraphErrors(Int_t det, Int_t group , const Char_t * name)
974 // Convert the fVectorPHMean, fVectorPHSquares and fVectorPHEntries in TGraphErrors
978 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
979 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
980 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
985 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
987 sf = parCom->GetSamplingFrequency();
990 AliInfo("Could not get CommonParam, take the default 10MHz");
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
999 if(sf > 0.0) step = 1.0 / sf;
1001 Int_t offset = group*fTimeMax;
1004 for (Int_t k = 0; k < fTimeMax; k++) {
1005 x[k] = min + k*step;
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);
1018 // Define the TGraphErrors
1019 if(!fGraph) fGraph = new TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
1021 fGraph->~TGraphErrors();
1022 new(fGraph) TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
1024 fGraph->SetTitle(name);
1029 //_____________________________________________________________________________
1030 TGraphErrors *AliTRDCalibraVector::ConvertVectorPRFTGraphErrors(Int_t det, Int_t group , const Char_t * name)
1033 // Convert the fVectorPRFMean, fVectorPRFSquares and fVectorPRFEntries in TGraphErrors
1037 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
1038 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
1039 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
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;
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);
1054 for (Int_t k = 0; k < fNumberBinPRF; k++) {
1055 x[k] = min + k*step;
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);
1066 //printf("Number of entries %f for %d\n",ex[k],k);
1069 // Define the TGraphErrors
1070 if(!fGraph) fGraph = new TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1072 fGraph->~TGraphErrors();
1073 new(fGraph) TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1075 fGraph->SetTitle(name);
1082 //_____________________________________________________________________________
1083 TH1F *AliTRDCalibraVector::CorrectTheError(const TGraphErrors *hist, Int_t &nbEntries)
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
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();
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;
1107 if(!fHisto) fHisto = new TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1110 new(fHisto) TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
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]));
1121 fHisto->SetBinError(k+1,0.0);
1128 //_____________________________________________________________________________
1129 TH1F *AliTRDCalibraVector::ConvertVectorCHHisto(Int_t det, Int_t group, const Char_t * name)
1132 // Convert the fVectorCHEntries in TH1F
1136 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
1139 if(!fHisto) fHisto = new TH1F(name,name,fNumberBinCharge,0,300);
1142 new(fHisto) TH1F(name,name,fNumberBinCharge,0,300);
1145 Int_t offset = group*fNumberBinCharge;
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))));
1156 //_____________________________________________________________________
1157 TObject* AliTRDCalibraVector::GetPHEntries(Int_t det
1158 , Bool_t force) /*FOLD00*/
1161 // return pointer to Carge ROC Calibration
1162 // if force is true create a new histogram if it doesn't exist allready
1164 AliTRDEntriesInfo**arr = &fPHEntries[0];
1165 return (TObject *) GetEntriesPH(det, arr, force);
1167 //_____________________________________________________________________
1168 TObject* AliTRDCalibraVector::GetPRFEntries(Int_t det
1169 , Bool_t force) /*FOLD00*/
1172 // return pointer to Carge ROC Calibration
1173 // if force is true create a new histogram if it doesn't exist allready
1175 AliTRDEntriesInfo**arr = &fPRFEntries[0];
1176 return (TObject *) GetEntriesPRF(det, arr, force);
1178 //_____________________________________________________________________
1179 TObject* AliTRDCalibraVector::GetCHEntries(Int_t det
1180 , Bool_t force) /*FOLD00*/
1183 // return pointer to Carge ROC Calibration
1184 // if force is true create a new histogram if it doesn't exist allready
1186 AliTRDEntriesInfo**arr = &fCHEntries[0];
1187 return (TObject *) GetEntriesCH(det, arr, force);
1189 //_____________________________________________________________________
1190 TObject* AliTRDCalibraVector::GetPHMean(Int_t det
1191 , Bool_t force) /*FOLD00*/
1194 // return pointer to ROC Calibration
1195 // if force is true create a new array
1197 AliTRDPhInfo**arr = &fPHMean[0];
1198 return (TObject *) GetMeanSquaresPH(det, arr, force);
1200 //_____________________________________________________________________
1201 TObject* AliTRDCalibraVector::GetPHSquares(Int_t det
1202 , Bool_t force) /*FOLD00*/
1205 // return pointer to ROC Calibration
1206 // if force is true create a new array
1208 AliTRDPhInfo**arr = &fPHSquares[0];
1209 return (TObject *) GetMeanSquaresPH(det, arr, force);
1211 //_____________________________________________________________________
1212 TObject* AliTRDCalibraVector::GetPRFMean(Int_t det
1213 , Bool_t force) /*FOLD00*/
1216 // return pointer to ROC Calibration
1217 // if force is true create a new array
1219 AliTRDPrfInfo**arr = &fPRFMean[0];
1220 return (TObject *) GetMeanSquaresPRF(det, arr, force);
1222 //_____________________________________________________________________
1223 TObject* AliTRDCalibraVector::GetPRFSquares(Int_t det
1224 , Bool_t force) /*FOLD00*/
1227 // return pointer to ROC Calibration
1228 // if force is true create a new array
1230 AliTRDPrfInfo**arr = &fPRFSquares[0];
1231 return (TObject *) GetMeanSquaresPRF(det, arr, force);
1233 //_____________________________________________________________________
1234 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesCH(Int_t det
1235 , AliTRDEntriesInfo** arr
1236 , Bool_t force) /*FOLD00*/
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
1242 if ( (!force) || (arr[det]))
1243 return (AliTRDEntriesInfo*)arr[det];
1245 // if we are forced and TArrayI doesn't yes exist create it
1246 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,0,fNumberBinCharge);
1248 arr[det] = new AliTRDEntriesInfo(ngroup);
1250 return (AliTRDEntriesInfo*)arr[det];
1253 //_____________________________________________________________________
1254 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesPRF(Int_t det
1255 , AliTRDEntriesInfo** arr
1256 , Bool_t force) /*FOLD00*/
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
1262 if ( (!force) || (arr[det]))
1263 return (AliTRDEntriesInfo*)arr[det];
1265 // if we are forced and TArrayI doesn't yes exist create it
1266 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF);
1268 arr[det] = new AliTRDEntriesInfo(ngroup);
1270 return (AliTRDEntriesInfo*)arr[det];
1273 //_____________________________________________________________________
1274 AliTRDEntriesInfo *AliTRDCalibraVector::GetEntriesPH(Int_t det
1275 , AliTRDEntriesInfo ** arr
1276 , Bool_t force) /*FOLD00*/
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
1282 if ( (!force) || (arr[det]))
1283 return (AliTRDEntriesInfo *)arr[det];
1285 // if we are forced and UShort_t doesn't yet exist create it
1286 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax);
1288 arr[det] = new AliTRDEntriesInfo(ngroup);
1290 return (AliTRDEntriesInfo*)arr[det];
1293 //_____________________________________________________________________
1294 AliTRDPhInfo* AliTRDCalibraVector::GetMeanSquaresPH(Int_t det
1295 , AliTRDPhInfo** arr
1296 , Bool_t force) /*FOLD00*/
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
1302 if ( (!force) || (arr[det]))
1303 return (AliTRDPhInfo*)arr[det];
1305 // if we are forced and Float_t array doesn't yes exist create it
1306 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax);
1308 arr[det] = new AliTRDPhInfo(ngroup);
1310 return ((AliTRDPhInfo *)arr[det]);
1312 //_____________________________________________________________________
1313 AliTRDPrfInfo* AliTRDCalibraVector::GetMeanSquaresPRF(Int_t det
1314 , AliTRDPrfInfo** arr
1315 , Bool_t force) /*FOLD00*/
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
1321 if ( (!force) || (arr[det]))
1324 // if we are forced and the array doesn't yet exist create it
1325 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF);
1327 arr[det] = new AliTRDPrfInfo(ngroup);
1329 return (AliTRDPrfInfo*)arr[det];
1332 //_____________________________________________________________________________
1333 Int_t AliTRDCalibraVector::GetTotalNumberOfBinsInDetector(Int_t det, Int_t i, Int_t nbBin) const
1336 // Get the total number of bins (Nb of bins*Nb of groups) in the detector det for the group i
1340 Int_t stack = AliTRDgeometry::GetStack(det);
1341 if(stack == 2) ngroup = fDetCha2[i]*nbBin;
1342 else ngroup = fDetCha0[i]*nbBin;
1347 //____________________________________________________________________________
1348 Int_t AliTRDCalibraVector::GetNz(Int_t i) const
1351 // Get Nz the granularity in row
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);
1362 //____________________________________________________________________________
1363 Int_t AliTRDCalibraVector::GetNrphi(Int_t i) const
1366 // Get Nrphi the granularity in col
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);
1377 //_________________________________________________________________________________
1378 TString AliTRDCalibraVector::GetNamePH() const
1381 // Get the name of PH to know the granularity
1384 Int_t nz = GetNz(1);
1385 Int_t nrphi = GetNrphi(1);
1395 //_________________________________________________________________________________
1396 TString AliTRDCalibraVector::GetNameCH() const
1399 // Get the name of CH to know the granularity
1402 Int_t nz = GetNz(0);
1403 Int_t nrphi = GetNrphi(0);
1413 //_________________________________________________________________________________
1414 TString AliTRDCalibraVector::GetNamePRF() const
1417 // Get the name of PRF to know the granularity
1420 Int_t nz = GetNz(2);
1421 Int_t nrphi = GetNrphi(2);
1428 name += fNbGroupPRF;
1433 //____________________________________________________________________________
1434 void AliTRDCalibraVector::SetNzNrphi(Int_t i, Int_t nz, Int_t nrphi)
1437 // Set NzNrphi for the granularity
1442 fModeCH = fModeCH << 4;
1447 fModePH = fModePH << 4;
1452 fModePRF = fModePRF << 4;