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 if(fPHEntries) delete fPHEntries;
171 if(fPHMean) delete fPHMean;
172 if(fPHSquares) delete fPHSquares;
173 if(fPRFEntries) delete fPRFEntries;
174 if(fPRFMean) delete fPRFMean;
175 if(fPRFSquares) delete fPRFSquares;
176 if(fCHEntries) delete fCHEntries;
177 if(fHisto) delete fHisto;
178 if(fGraph) delete fGraph;
179 if(fCalVector) delete fCalVector;
182 //_____________________________________________________________________________
183 void AliTRDCalibraVector::TestInit(Int_t i, Int_t detmax)
186 // Init to see the size
189 for(Int_t det = 0; det < detmax; det++){
193 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
194 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
195 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
201 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
202 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
203 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
207 if(i==0) fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
212 //_____________________________________________________________________________
213 Int_t AliTRDCalibraVector::SearchBin(Float_t value, Int_t i) const
221 Float_t fbinmax = value;
222 Int_t fNumberOfBin = -1;
229 fNumberOfBin = fNumberBinCharge;
233 fbinmax = TMath::Abs(fPRFRange);
234 fbinmin = -TMath::Abs(fPRFRange);
235 fNumberOfBin = fNumberBinPRF;
243 if ((value >= fbinmax) ||
248 reponse = (Int_t) ((fNumberOfBin*(value-fbinmin)) / (fbinmax-fbinmin));
254 //_____________________________________________________________________________
255 Bool_t AliTRDCalibraVector::UpdateVectorCH(Int_t det, Int_t group, Float_t value)
258 // Fill the vector CH
262 Int_t bin = SearchBin(value,0);
270 if(fDetectorCH != det){
271 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
274 Int_t entries = ((AliTRDEntriesInfo *)fCHEntries[det])->At(group*fNumberBinCharge+bin);
276 Int_t entriesn = entries+1;
278 if(entriesn > 65535) {
283 ((AliTRDEntriesInfo *)fCHEntries[det])->AddAt(entriesn,group*fNumberBinCharge+bin);
291 //_____________________________________________________________________________
292 Bool_t AliTRDCalibraVector::UpdateVectorPRF(Int_t det, Int_t group, Float_t x, Float_t y)
295 // Fill the vector PRF
299 Int_t bin = SearchBin(x,2);
306 if(fDetectorPRF != det){
307 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
308 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
309 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
312 Int_t entries = ((AliTRDEntriesInfo *)fPRFEntries[det])->At((Int_t)group*fNumberBinPRF+bin);
313 Float_t mean = ((AliTRDPrfInfo *)fPRFMean[det])->At((Int_t)group*fNumberBinPRF+bin);
314 Float_t square = ((AliTRDPrfInfo *)fPRFSquares[det])->At((Int_t)group*fNumberBinPRF+bin);
316 Int_t entriesn = entries+1;
318 if(entriesn > 65535) return kTRUE;
320 ((AliTRDEntriesInfo *)fPRFEntries[det])->AddAt(entriesn,(Int_t)group*fNumberBinPRF+bin);
321 Float_t meann = (mean*((Float_t)entries)+y)/((Float_t)entriesn);
322 ((AliTRDPrfInfo *)fPRFMean[det])->AddAt(meann,(Int_t)group*fNumberBinPRF+bin);
323 Float_t squaren = ((square*((Float_t)entries))+(y*y))/((Float_t)entriesn);
324 ((AliTRDPrfInfo *)fPRFSquares[det])->AddAt(squaren,(Int_t)group*fNumberBinPRF+bin);
332 //_____________________________________________________________________________
333 Bool_t AliTRDCalibraVector::UpdateVectorPH(Int_t det, Int_t group, Int_t time, Float_t value)
336 // Fill the vector PH
348 if(fDetectorPH != det){
349 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
350 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
351 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
354 Int_t entries = ((AliTRDEntriesInfo *)fPHEntries[det])->At(group*fTimeMax+bin);
355 Float_t mean = ((AliTRDPhInfo *)fPHMean[det])->At(group*fTimeMax+bin);
356 Float_t square = ((AliTRDPhInfo *)fPHSquares[det])->AtS(group*fTimeMax+bin);
358 Int_t entriesn = entries+1;
359 Float_t meann = (mean*((Float_t)entries)+value)/((Float_t)entriesn);
360 Float_t squaren = ((square*((Float_t)entries))+(value*value))/((Float_t)entriesn);
362 if(entriesn > 65535) return kTRUE;
363 //printf("meann %f, squaren %f\n",meann,squaren);
364 if((meann > 3000.0) || (meann < 0.0) || (squaren > (3000.0*3000.0)) || (squaren < 0.0)) return kFALSE;
366 ((AliTRDEntriesInfo *)fPHEntries[det])->AddAt(entriesn,group*fTimeMax+bin);
367 ((AliTRDPhInfo *)fPHMean[det])->AddAt(meann,group*fTimeMax+bin);
368 ((AliTRDPhInfo *)fPHSquares[det])->AddAtS(squaren,group*fTimeMax+bin);
375 //_____________________________________________________________________________
376 Bool_t AliTRDCalibraVector::FillVectorCH(Int_t det, Int_t group, Int_t bin, Int_t entries)
379 // Fill the vector CH
382 if(entries > 65535) return kFALSE;
384 if(fDetectorCH != det){
385 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
388 ((AliTRDEntriesInfo *)fCHEntries[det])->AddAt(entries,group*fNumberBinCharge+bin);
396 //_____________________________________________________________________________
397 Bool_t AliTRDCalibraVector::FillVectorPRF(Int_t det, Int_t group, Int_t bin, Int_t entries, Float_t mean, Float_t square)
400 // Fill the vector PRF
403 if((entries > 65535) || (mean > 1.0) || (mean < 0.0) || (square > 1.0) || (square < 0.0)) return kFALSE;
405 if(fDetectorPRF != det){
406 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
407 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
408 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
411 ((AliTRDEntriesInfo *)fPRFEntries[det])->AddAt(entries,(Int_t)group*fNumberBinPRF+bin);
412 ((AliTRDPrfInfo *)fPRFMean[det])->AddAt(mean,(Int_t)group*fNumberBinPRF+bin);
413 ((AliTRDPrfInfo *)fPRFSquares[det])->AddAt(square,(Int_t)group*fNumberBinPRF+bin);
421 //_____________________________________________________________________________
422 Bool_t AliTRDCalibraVector::FillVectorPH(Int_t det, Int_t group, Int_t bin, Int_t entries, Float_t mean, Float_t square)
425 // Fill the vector PH
428 if((entries > 65535) || (mean > 3000.0) || (mean < 0.0) || (square > (3000.0*3000.0)) || (square < 0.0)) return kFALSE;
431 if(fDetectorPH != det){
432 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
433 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
434 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
437 ((AliTRDEntriesInfo *)fPHEntries[det])->AddAt(entries,group*fTimeMax+bin);
438 ((AliTRDPhInfo *)fPHMean[det])->AddAt(mean,group*fTimeMax+bin);
439 ((AliTRDPhInfo *)fPHSquares[det])->AddAtS(square,group*fTimeMax+bin);
446 //__________________________________________________________________________________
447 Bool_t AliTRDCalibraVector::Add(AliTRDCalibraVector *calvect)
450 // Add a other AliTRCalibraVector to this one
453 Bool_t result = kTRUE;
455 // Check compatibility
456 if(fNumberBinCharge != calvect->GetNumberBinCharge()) return kFALSE;
457 if(fNumberBinPRF != calvect->GetNumberBinPRF()) return kFALSE;
458 if(fPRFRange != calvect->GetPRFRange()) return kFALSE;
459 if(fTimeMax != calvect->GetTimeMax()) return kFALSE;
460 for(Int_t k = 0; k < 3; k++){
461 if(fDetCha0[k] != calvect->GetDetCha0(k)) return kFALSE;
462 if(fDetCha2[k] != calvect->GetDetCha2(k)) return kFALSE;
465 //printf("All ok for variables before adding!\n");
468 for (Int_t idet = 0; idet < 540; idet++){
470 //printf("Detector %d\n",idet);
472 const AliTRDEntriesInfo *phEntriesvect = (AliTRDEntriesInfo *) calvect->GetPHEntries(idet);
473 const AliTRDPhInfo *phMeanvect = (AliTRDPhInfo *) calvect->GetPHMean(idet);
474 const AliTRDPhInfo *phSquaresvect = (AliTRDPhInfo *) calvect->GetPHSquares(idet);
476 const AliTRDEntriesInfo *prfEntriesvect = (AliTRDEntriesInfo *) calvect->GetPRFEntries(idet);
477 const AliTRDPrfInfo *prfMeanvect = (AliTRDPrfInfo *) calvect->GetPRFMean(idet);
478 const AliTRDPrfInfo *prfSquaresvect = (AliTRDPrfInfo *) calvect->GetPRFSquares(idet);
480 const AliTRDEntriesInfo *chEntriesvect = (AliTRDEntriesInfo *) calvect->GetCHEntries(idet);
482 if ( phEntriesvect != 0x0 ){
484 fPHEntries[idet] = ((AliTRDEntriesInfo *)GetPHEntries(idet,kTRUE));
485 fPHMean[idet] = ((AliTRDPhInfo *)GetPHMean(idet,kTRUE));
486 fPHSquares[idet] = ((AliTRDPhInfo *)GetPHSquares(idet,kTRUE));
488 Int_t total = fPHEntries[idet]->GetSize();
489 //printf("Total size PH %d\n",total);
491 for(Int_t k = 0; k < total; k++){
492 Int_t entriesv = ((AliTRDEntriesInfo *)phEntriesvect)->At(k);
493 Float_t meanv = ((AliTRDPhInfo *)phMeanvect)->At(k);
494 Float_t squarev = ((AliTRDPhInfo *)phSquaresvect)->AtS(k);
496 Int_t entries = ((AliTRDEntriesInfo *)fPHEntries[idet])->At(k);
497 Float_t mean = ((AliTRDPhInfo *)fPHMean[idet])->At(k);
498 Float_t square = ((AliTRDPhInfo *)fPHSquares[idet])->AtS(k);
500 Int_t entriesn = entries+entriesv;
501 Float_t meann = (mean*((Float_t)entries)+meanv*((Float_t)entriesv))/((Float_t)entriesn);
502 Float_t squaren = ((square*((Float_t)entries))+(squarev*((Float_t)entriesv)))/((Float_t)entriesn);
504 if((entriesn > 0) && (entriesn <= 65535) && (meann >= 0) && (meann < 3000.0) && (squaren >= 0.0) && (squaren < (3000.0*3000.0))) {
506 ((AliTRDEntriesInfo *)fPHEntries[idet])->AddAt(entriesn,k);
507 ((AliTRDPhInfo *)fPHMean[idet])->AddAt(meann,k);
508 ((AliTRDPhInfo *)fPHSquares[idet])->AddAtS(squaren,k);
514 if ( prfEntriesvect != 0x0 ){
516 fPRFEntries[idet] = ((AliTRDEntriesInfo *)GetPRFEntries(idet,kTRUE));
517 fPRFMean[idet] = ((AliTRDPrfInfo *)GetPRFMean(idet,kTRUE));
518 fPRFSquares[idet] = ((AliTRDPrfInfo *)GetPRFSquares(idet,kTRUE));
520 Int_t total = fPRFEntries[idet]->GetSize();
521 //Int_t total0 = fPRFMean[idet]->GetSize();
522 //Int_t total1 = fPRFSquares[idet]->GetSize();
523 //printf("Total size PRF %d\n",total);
524 //printf("Total0 size PRF %d\n",total0);
525 //printf("Total1 size PRF %d\n",total1);
527 for(Int_t k = 0; k < total; k++){
530 Int_t entries = ((AliTRDEntriesInfo *)fPRFEntries[idet])->At(k);
531 Float_t mean = ((AliTRDPrfInfo *)fPRFMean[idet])->At(k);
532 Float_t square = ((AliTRDPrfInfo *)fPRFSquares[idet])->At(k);
534 Int_t entriesv = ((AliTRDEntriesInfo *)prfEntriesvect)->At(k);
535 Float_t meanv = ((AliTRDPrfInfo *)prfMeanvect)->At(k);
536 Float_t squarev = ((AliTRDPrfInfo *)prfSquaresvect)->At(k);
538 Int_t entriesn = entries + entriesv;
540 if((entriesn > 0) && (entriesn <= 65535)) {
542 ((AliTRDEntriesInfo *)fPRFEntries[idet])->AddAt(entriesn,k);
544 Float_t meann = (mean*((Float_t)entries)+meanv*((Float_t)entriesv))/((Float_t)entriesn);
546 ((AliTRDPrfInfo *)fPRFMean[idet])->AddAt(meann,k);
549 Float_t squaren = ((square*((Float_t)entries))+(squarev*((Float_t)entriesv)))/((Float_t)entriesn);
551 ((AliTRDPrfInfo *)fPRFSquares[idet])->AddAt(squaren,k);
558 if ( chEntriesvect != 0x0 ){
560 fCHEntries[idet] = ((AliTRDEntriesInfo *)GetCHEntries(idet,kTRUE));
561 //printf("TestAdd\n");
562 fStopFillCH = ((AliTRDEntriesInfo *)fCHEntries[idet])->TestAdd((AliTRDEntriesInfo *)chEntriesvect);
570 ((AliTRDEntriesInfo *)fCHEntries[idet])->Add(chEntriesvect);
578 //_____________________________________________________________________________________________________________________
579 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorCH()
582 // Create a AliTRDCalibraVector detector wise
585 // Use a AliTRDCalibraMode to navigate in the calibration groups
586 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
587 calibMode.SetNz(0,GetNz(0));
588 calibMode.SetNrphi(0,GetNrphi(0));
589 if(((calibMode.GetNz(0) == 100) && (calibMode.GetNrphi(0) == 100)) || ((calibMode.GetNz(0) == 10) && (calibMode.GetNrphi(0) == 10))) return 0x0;
591 Int_t nybins = 6*4*18*fDetCha0[0]+6*18*fDetCha2[0];
592 Int_t nxbins = fNumberBinCharge;
595 Int_t perChamber2 = 0;
596 Int_t perChamber0 = 0;
597 calibMode.ModePadCalibration(2,0);
598 calibMode.ModePadFragmentation(0,2,0,0);
599 calibMode.SetDetChamb2(0);
600 perChamber2 = (Int_t) calibMode.GetDetChamb2(0);
601 calibMode.ModePadCalibration(0,0);
602 calibMode.ModePadFragmentation(0,0,0,0);
603 calibMode.SetDetChamb0(0);
604 perChamber0 = (Int_t) calibMode.GetDetChamb0(0);
605 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
608 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
610 fCalVector->~AliTRDCalibraVector();
611 new(fCalVector) AliTRDCalibraVector();
613 fCalVector->SetNumberBinCharge(nxbins);
614 fCalVector->SetDetCha0(0,1);
615 fCalVector->SetDetCha2(0,1);
616 fCalVector->SetNzNrphi(0,0,0);
619 for(Int_t det = 0; det < 540; det++){
622 AliTRDEntriesInfo *entriesch = (AliTRDEntriesInfo *)GetCHEntries(det,kFALSE);
623 if(!entriesch) continue;
626 Int_t numberofgroup = 0;
627 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
628 else numberofgroup = perChamber0;
630 // Check if one can merge calibration groups for this chamber
631 // entries is the number of entries in each bin after adding the different the calibration group in the detector
632 fStopFillCH = kFALSE;
633 Int_t firstnumberofgroup = -1;
635 for(Int_t k = 0; k < nxbins; k++){
638 // Loop over group in the detector
639 for(Int_t k = 0; k < numberofgroup; k++){
641 for(Int_t nx = 0; nx < nxbins; nx++) {
642 Int_t binnumber = k*nxbins+nx;
643 entries[nx] += entriesch->At(binnumber);
644 // as soon as one bin is over threshold stop
646 if(entries[nx] > 65535) {
647 firstnumberofgroup = k;
654 if(fStopFillCH && (firstnumberofgroup == 0)) return 0x0;
655 if(!fStopFillCH) firstnumberofgroup = numberofgroup;
657 // Now add up to possible
658 for(Int_t k = 0; k < nxbins; k++){
661 for(Int_t k = 0; k < firstnumberofgroup; k++){
662 for(Int_t nx = 0; nx < nxbins; nx++) {
663 Int_t binnumber = k*nxbins+nx;
664 entries[nx] += entriesch->At(binnumber);
669 for(Int_t nx = 0; nx < nxbins; nx++){
670 fCalVector->FillVectorCH(det,0,nx,(Int_t)entries[nx]);
676 //_____________________________________________________________________________________________________________________
677 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorPH()
680 // Create a AliTRDCalibraVector detector wise
683 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
684 calibMode.SetNz(1,GetNz(1));
685 calibMode.SetNrphi(1,GetNrphi(1));
686 if(((calibMode.GetNz(1) == 100) && (calibMode.GetNrphi(1) == 100)) || ((calibMode.GetNz(1) == 10) && (calibMode.GetNrphi(1) == 10))) return 0x0;
690 Int_t nybins = 6*4*18*fDetCha0[1]+6*18*fDetCha2[1];
691 Int_t nxbins = fTimeMax;
693 Int_t perChamber2 = 0;
694 Int_t perChamber0 = 0;
695 calibMode.ModePadCalibration(2,1);
696 calibMode.ModePadFragmentation(0,2,0,1);
697 calibMode.SetDetChamb2(1);
698 perChamber2 = (Int_t) calibMode.GetDetChamb2(1);
699 calibMode.ModePadCalibration(0,1);
700 calibMode.ModePadFragmentation(0,0,0,1);
701 calibMode.SetDetChamb0(1);
702 perChamber0 = (Int_t) calibMode.GetDetChamb0(1);
704 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
707 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
709 fCalVector->~AliTRDCalibraVector();
710 new(fCalVector) AliTRDCalibraVector();
712 fCalVector->SetTimeMax(nxbins);
713 fCalVector->SetDetCha0(1,1);
714 fCalVector->SetDetCha2(1,1);
715 fCalVector->SetNzNrphi(1,0,0);
718 for(Int_t det = 0; det < 540; det++){
721 AliTRDEntriesInfo *entriesph = (AliTRDEntriesInfo *)GetPHEntries(det,kFALSE);
722 if(!entriesph) continue;
723 AliTRDPhInfo *meanph = (AliTRDPhInfo *)GetPHMean(det,kFALSE);
724 AliTRDPhInfo *squaresph = (AliTRDPhInfo *)GetPHSquares(det,kFALSE);
727 Int_t numberofgroup = 0;
728 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
729 else numberofgroup = perChamber0;
732 for(Int_t nx = 0; nx < nxbins; nx++) {
734 Double_t entries = 0.0;
735 Double_t sumw2 = 0.0;
738 // Sum the contributions of the different calibration group in the detector
739 for(Int_t k = 0; k < numberofgroup; k++){
741 Int_t binnumber = k*nxbins+nx;
743 Int_t entriesv = ((AliTRDEntriesInfo *)entriesph)->At(binnumber);
744 Float_t sumw2v = ((AliTRDPhInfo *)squaresph)->AtS(binnumber)*entriesv;
745 Float_t sumwv = ((AliTRDPhInfo *)meanph)->At(binnumber)*entriesv;
748 if(((entries+entriesv) > 65535) || ((entries+entriesv) <= 0)) continue;
757 sumw2 = sumw2/((Float_t)entries);
758 sumw = sumw/((Float_t)entries);
761 fCalVector->FillVectorPH(det,0,nx,(Int_t)entries,(Float_t)sumw,(Float_t)sumw2);
768 //_____________________________________________________________________________________________________________________
769 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorPRF()
772 // Create a AliTRDCalibraVector detector wise
775 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
776 calibMode.SetNz(2,GetNz(2));
777 calibMode.SetNrphi(2,GetNrphi(2));
778 if(((calibMode.GetNz(2) == 100) && (calibMode.GetNrphi(2) == 100)) || ((calibMode.GetNz(2) == 10) && (calibMode.GetNrphi(2) == 10))) return 0x0;
781 Int_t nybins = 6*4*18*fDetCha0[2]+ 6*18*fDetCha2[2];
782 Int_t nxbins = fNumberBinPRF;
784 Int_t perChamber2 = 0;
785 Int_t perChamber0 = 0;
786 calibMode.ModePadCalibration(2,2);
787 calibMode.ModePadFragmentation(0,2,0,2);
788 calibMode.SetDetChamb2(2);
789 perChamber2 = (Int_t) calibMode.GetDetChamb2(2);
790 calibMode.ModePadCalibration(0,2);
791 calibMode.ModePadFragmentation(0,0,0,2);
792 calibMode.SetDetChamb0(2);
793 perChamber0 = (Int_t) calibMode.GetDetChamb0(2);
795 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
798 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
800 fCalVector->~AliTRDCalibraVector();
801 new(fCalVector) AliTRDCalibraVector();
803 fCalVector->SetNumberBinPRF(nxbins);
804 fCalVector->SetDetCha0(2,1);
805 fCalVector->SetDetCha2(2,1);
806 fCalVector->SetNzNrphi(2,0,0);
807 fCalVector->SetNbGroupPRF(fNbGroupPRF);
810 for(Int_t det = 0; det < 540; det++){
813 AliTRDEntriesInfo *entriesprf = (AliTRDEntriesInfo *) GetPRFEntries(det,kFALSE);
814 if(!entriesprf) continue;
815 AliTRDPrfInfo *meanprf = (AliTRDPrfInfo *) GetPRFMean(det,kFALSE);
816 AliTRDPrfInfo *squaresprf = (AliTRDPrfInfo *) GetPRFSquares(det,kFALSE);
819 Int_t numberofgroup = 0;
820 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
821 else numberofgroup = perChamber0;
823 for(Int_t nx = 0; nx < nxbins; nx++) {
825 Double_t entries = 0.0;
826 Double_t sumw2 = 0.0;
829 // Sum the contributions of the different groups in the detector for one bin
830 for(Int_t k = 0; k < numberofgroup; k++){
832 Int_t binnumber = k*nxbins+nx;
834 Int_t entriesv = ((AliTRDEntriesInfo *)entriesprf)->At(binnumber);
835 Float_t sumw2v = ((AliTRDPrfInfo *)squaresprf)->At(binnumber)*entriesv;
836 Float_t sumwv = ((AliTRDPrfInfo *)meanprf)->At(binnumber)*entriesv;
838 if(((entries+entriesv) > 65535) || ((entries+entriesv) <= 0)) continue;
847 sumw2 = sumw2/((Float_t)entries);
848 sumw = sumw/((Float_t)entries);
851 fCalVector->FillVectorPRF(det,0,nx,(Int_t)entries,(Float_t)sumw,(Float_t)sumw2);
858 //_______________________________________________________________________________
859 Bool_t AliTRDCalibraVector::FindTheMaxEntries(Int_t i, Int_t &detectormax, Int_t &groupmax)
862 // Find detectormax and groupmax with the biggest number of entries
865 Int_t numberofTB = 0;
866 if(i==0) numberofTB = (Int_t) GetNumberBinCharge();
867 if(i==1) numberofTB = GetTimeMax();
868 if(i==2) numberofTB = GetNumberBinPRF();
869 if((i!=0) && (i!=1) && (i!=2)) AliInfo("Didn't understand i");
873 Double_t entries [540];
874 for(Int_t idet = 0; idet < 540; idet++){
878 AliTRDEntriesInfo *entriesd = 0x0;
879 // Take the number of entries per detector
880 for(Int_t idet = 0; idet < 540; idet++){
882 if(i==0) entriesd = (AliTRDEntriesInfo *) GetCHEntries(idet,kFALSE);
883 if(i==1) entriesd = (AliTRDEntriesInfo *) GetPHEntries(idet,kFALSE);
884 if(i==2) entriesd = (AliTRDEntriesInfo *) GetPRFEntries(idet,kFALSE);
885 if(!entriesd) continue;
887 entries[idet] = entriesd->GetSum();
891 // Search detector max
894 for(Int_t idet = 0; idet < 540; idet++){
895 if(entries[idet] > max) {
900 if((max == 0.0) || (detectormax <0.0)) return kFALSE;
903 if(i==0) entriesd = (AliTRDEntriesInfo *) GetCHEntries(detectormax,kFALSE);
904 if(i==1) entriesd = (AliTRDEntriesInfo *) GetPHEntries(detectormax,kFALSE);
905 if(i==2) entriesd = (AliTRDEntriesInfo *) GetPRFEntries(detectormax,kFALSE);
906 if(!entriesd) return kFALSE;
908 Int_t numberofgroup = 0;
909 if(AliTRDgeometry::GetStack(detectormax) == 2) numberofgroup = fDetCha2[i];
910 else numberofgroup = fDetCha0[i];
912 Double_t nbgroup [2304];
913 for(Int_t k = 0; k < 2304; k++){
917 if(i==0) nxbins = fNumberBinCharge;
918 if(i==1) nxbins = fTimeMax;
919 if(i==2) nxbins = fNumberBinPRF;
920 // Compute the number of entries per group
921 for(Int_t k = 0; k < numberofgroup; k++){
922 for(Int_t nx = 0; nx < nxbins; nx++) {
923 Int_t binnumber = k*nxbins+nx;
924 nbgroup[k] += ((AliTRDEntriesInfo *)entriesd)->At(binnumber);
929 for(Int_t io = 0; io < numberofgroup; io++){
930 if(nbgroup[io] > max){
935 if((max == 0.0) || (groupmax < 0.0) || (groupmax >= numberofgroup)) return kFALSE;
940 //_____________________________________________________________________________
941 TGraphErrors *AliTRDCalibraVector::ConvertVectorPHTGraphErrors(Int_t det, Int_t group , const Char_t * name)
944 // Convert the fVectorPHMean, fVectorPHSquares and fVectorPHEntries in TGraphErrors
948 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
949 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
950 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
955 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
957 AliInfo("Could not get CommonParam, take the default 10MHz");
959 sf = parCom->GetSamplingFrequency();
961 Double_t x[35]; // Xaxis
962 Double_t y[35]; // Sum/entries
963 Double_t ex[35]; // Nentries
964 Double_t ey[35]; // Sum of square/nentries
967 if(sf > 0.0) step = 1.0 / sf;
969 Int_t offset = group*fTimeMax;
972 for (Int_t k = 0; k < fTimeMax; k++) {
977 Int_t bin = offset+k;
978 // Fill only if there is more than 0 something
979 if (((AliTRDEntriesInfo *)fPHEntries[det])->At(bin) > 0) {
980 ex[k] = ((AliTRDEntriesInfo *)fPHEntries[det])->At(bin);
981 y[k] = ((AliTRDPhInfo *)fPHMean[det])->At(bin);
982 ey[k] = ((AliTRDPhInfo *)fPHSquares[det])->AtS(bin);
986 // Define the TGraphErrors
987 if(!fGraph) fGraph = new TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
989 fGraph->~TGraphErrors();
990 new(fGraph) TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
992 fGraph->SetTitle(name);
997 //_____________________________________________________________________________
998 TGraphErrors *AliTRDCalibraVector::ConvertVectorPRFTGraphErrors(Int_t det, Int_t group , const Char_t * name)
1001 // Convert the fVectorPRFMean, fVectorPRFSquares and fVectorPRFEntries in TGraphErrors
1005 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
1006 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
1007 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
1011 Double_t x[200]; // Xaxis
1012 Double_t y[200]; // Sum/entries
1013 Double_t ex[200]; //Nentries
1014 Double_t ey[200]; // Sum of square/nentries
1015 Double_t step = 0.0;
1017 if(fNumberBinPRF) step = (2*TMath::Abs(fPRFRange)) / fNumberBinPRF;
1018 min = -TMath::Abs(fPRFRange) + step / 2.0;
1019 Int_t offset = group*fNumberBinPRF;
1020 //printf("number of total: %d\n",fNumberBinPRF);
1022 for (Int_t k = 0; k < fNumberBinPRF; k++) {
1023 x[k] = min + k*step;
1027 Int_t bin = offset+k;
1028 // Fill only if there is more than 0 something
1029 if (((AliTRDEntriesInfo *)fPRFEntries[det])->At(bin) > 0) {
1030 ex[k] = ((AliTRDEntriesInfo *)fPRFEntries[det])->At(bin);
1031 y[k] = ((AliTRDPrfInfo *)fPRFMean[det])->At(bin);
1032 ey[k] = ((AliTRDPrfInfo *)fPRFSquares[det])->At(bin);
1034 //printf("Number of entries %f for %d\n",ex[k],k);
1037 // Define the TGraphErrors
1038 if(!fGraph) fGraph = new TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1040 fGraph->~TGraphErrors();
1041 new(fGraph) TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1043 fGraph->SetTitle(name);
1050 //_____________________________________________________________________________
1051 TH1F *AliTRDCalibraVector::CorrectTheError(const TGraphErrors *hist, Int_t &nbEntries)
1054 // In the case of the vectors method the trees contains TGraphErrors for PH and PRF
1055 // to be able to add them after
1056 // We convert it to a TH1F to be able to applied the same fit function method
1057 // After having called this function you can not add the statistics anymore
1060 Int_t nbins = hist->GetN();
1061 Double_t *x = hist->GetX();
1062 Double_t *entries = hist->GetEX();
1063 Double_t *mean = hist->GetY();
1064 Double_t *square = hist->GetEY();
1071 Double_t step = x[1] - x[0];
1072 Double_t minvalue = x[0] - step/2;
1073 Double_t maxvalue = x[(nbins-1)] + step/2;
1075 if(!fHisto) fHisto = new TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1078 new(fHisto) TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1081 for (Int_t k = 0; k < nbins; k++) {
1082 fHisto->SetBinContent(k+1,mean[k]);
1083 if (entries[k] > 0.0) {
1084 nbEntries += (Int_t) entries[k];
1085 Double_t d = TMath::Abs(square[k] - (mean[k]*mean[k]));
1086 fHisto->SetBinError(k+1,TMath::Sqrt(d/entries[k]));
1089 fHisto->SetBinError(k+1,0.0);
1096 //_____________________________________________________________________________
1097 TH1F *AliTRDCalibraVector::ConvertVectorCHHisto(Int_t det, Int_t group, const Char_t * name)
1100 // Convert the fVectorCHEntries in TH1F
1104 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
1107 if(!fHisto) fHisto = new TH1F(name,name,fNumberBinCharge,0,300);
1110 new(fHisto) TH1F(name,name,fNumberBinCharge,0,300);
1113 Int_t offset = group*fNumberBinCharge;
1115 for (Int_t k = 0; k < fNumberBinCharge; k++) {
1116 Int_t bin = offset+k;
1117 fHisto->SetBinContent(k+1,((AliTRDEntriesInfo *)fCHEntries[det])->At(bin));
1118 fHisto->SetBinError(k+1,TMath::Sqrt(TMath::Abs(((AliTRDEntriesInfo *)fCHEntries[det])->At(bin))));
1124 //_____________________________________________________________________
1125 TObject* AliTRDCalibraVector::GetPHEntries(Int_t det
1126 , Bool_t force) /*FOLD00*/
1129 // return pointer to Carge ROC Calibration
1130 // if force is true create a new histogram if it doesn't exist allready
1132 AliTRDEntriesInfo**arr = &fPHEntries[0];
1133 return (TObject *) GetEntriesPH(det, arr, force);
1135 //_____________________________________________________________________
1136 TObject* AliTRDCalibraVector::GetPRFEntries(Int_t det
1137 , Bool_t force) /*FOLD00*/
1140 // return pointer to Carge ROC Calibration
1141 // if force is true create a new histogram if it doesn't exist allready
1143 AliTRDEntriesInfo**arr = &fPRFEntries[0];
1144 return (TObject *) GetEntriesPRF(det, arr, force);
1146 //_____________________________________________________________________
1147 TObject* AliTRDCalibraVector::GetCHEntries(Int_t det
1148 , Bool_t force) /*FOLD00*/
1151 // return pointer to Carge ROC Calibration
1152 // if force is true create a new histogram if it doesn't exist allready
1154 AliTRDEntriesInfo**arr = &fCHEntries[0];
1155 return (TObject *) GetEntriesCH(det, arr, force);
1157 //_____________________________________________________________________
1158 TObject* AliTRDCalibraVector::GetPHMean(Int_t det
1159 , Bool_t force) /*FOLD00*/
1162 // return pointer to ROC Calibration
1163 // if force is true create a new array
1165 AliTRDPhInfo**arr = &fPHMean[0];
1166 return (TObject *) GetMeanSquaresPH(det, arr, force);
1168 //_____________________________________________________________________
1169 TObject* AliTRDCalibraVector::GetPHSquares(Int_t det
1170 , Bool_t force) /*FOLD00*/
1173 // return pointer to ROC Calibration
1174 // if force is true create a new array
1176 AliTRDPhInfo**arr = &fPHSquares[0];
1177 return (TObject *) GetMeanSquaresPH(det, arr, force);
1179 //_____________________________________________________________________
1180 TObject* AliTRDCalibraVector::GetPRFMean(Int_t det
1181 , Bool_t force) /*FOLD00*/
1184 // return pointer to ROC Calibration
1185 // if force is true create a new array
1187 AliTRDPrfInfo**arr = &fPRFMean[0];
1188 return (TObject *) GetMeanSquaresPRF(det, arr, force);
1190 //_____________________________________________________________________
1191 TObject* AliTRDCalibraVector::GetPRFSquares(Int_t det
1192 , Bool_t force) /*FOLD00*/
1195 // return pointer to ROC Calibration
1196 // if force is true create a new array
1198 AliTRDPrfInfo**arr = &fPRFSquares[0];
1199 return (TObject *) GetMeanSquaresPRF(det, arr, force);
1201 //_____________________________________________________________________
1202 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesCH(Int_t det
1203 , AliTRDEntriesInfo** arr
1204 , Bool_t force) /*FOLD00*/
1207 // return pointer to UShort_t array Entries
1208 // if force is true create a new UShort_t array if it doesn't exist allready
1210 if ( (!force) || (arr[det]))
1211 return (AliTRDEntriesInfo*)arr[det];
1213 // if we are forced and TArrayI doesn't yes exist create it
1214 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,0,fNumberBinCharge);
1216 arr[det] = new AliTRDEntriesInfo(ngroup);
1218 return (AliTRDEntriesInfo*)arr[det];
1221 //_____________________________________________________________________
1222 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesPRF(Int_t det
1223 , AliTRDEntriesInfo** arr
1224 , Bool_t force) /*FOLD00*/
1227 // return pointer to UShort_t array Entries
1228 // if force is true create a new UShort_t array if it doesn't exist allready
1230 if ( (!force) || (arr[det]))
1231 return (AliTRDEntriesInfo*)arr[det];
1233 // if we are forced and TArrayI doesn't yes exist create it
1234 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF);
1236 arr[det] = new AliTRDEntriesInfo(ngroup);
1238 return (AliTRDEntriesInfo*)arr[det];
1241 //_____________________________________________________________________
1242 AliTRDEntriesInfo *AliTRDCalibraVector::GetEntriesPH(Int_t det
1243 , AliTRDEntriesInfo ** arr
1244 , Bool_t force) /*FOLD00*/
1247 // return pointer to UShort_t array Entries
1248 // if force is true create a new UShort_t array if it doesn't exist allready
1250 if ( (!force) || (arr[det]))
1251 return (AliTRDEntriesInfo *)arr[det];
1253 // if we are forced and UShort_t doesn't yet exist create it
1254 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax);
1256 arr[det] = new AliTRDEntriesInfo(ngroup);
1258 return (AliTRDEntriesInfo*)arr[det];
1261 //_____________________________________________________________________
1262 AliTRDPhInfo* AliTRDCalibraVector::GetMeanSquaresPH(Int_t det
1263 , AliTRDPhInfo** arr
1264 , Bool_t force) /*FOLD00*/
1267 // return pointer to Float_t array Mean or Squares
1268 // if force is true create a new Float_t array if it doesn't exist allready
1270 if ( (!force) || (arr[det]))
1271 return (AliTRDPhInfo*)arr[det];
1273 // if we are forced and Float_t array doesn't yes exist create it
1274 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax);
1276 arr[det] = new AliTRDPhInfo(ngroup);
1278 return ((AliTRDPhInfo *)arr[det]);
1280 //_____________________________________________________________________
1281 AliTRDPrfInfo* AliTRDCalibraVector::GetMeanSquaresPRF(Int_t det
1282 , AliTRDPrfInfo** arr
1283 , Bool_t force) /*FOLD00*/
1286 // return pointer to Float_t array Mean or Squares
1287 // if force is true create a new array if it doesn't exist allready
1289 if ( (!force) || (arr[det]))
1292 // if we are forced and the array doesn't yet exist create it
1293 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF);
1295 arr[det] = new AliTRDPrfInfo(ngroup);
1297 return (AliTRDPrfInfo*)arr[det];
1300 //_____________________________________________________________________________
1301 Int_t AliTRDCalibraVector::GetTotalNumberOfBinsInDetector(Int_t det, Int_t i, Int_t nbBin) const
1304 // Get the total number of bins (Nb of bins*Nb of groups) in the detector det for the group i
1308 Int_t stack = AliTRDgeometry::GetStack(det);
1309 if(stack == 2) ngroup = fDetCha2[i]*nbBin;
1310 else ngroup = fDetCha0[i]*nbBin;
1315 //____________________________________________________________________________
1316 Int_t AliTRDCalibraVector::GetNz(Int_t i) const
1319 // Get Nz the granularity in row
1323 if(i==0) nz = (Int_t)(fModeCH>>4);
1324 if(i==1) nz = (Int_t)(fModePH>>4);
1325 if(i==2) nz = (Int_t)(fModePRF>>4);
1330 //____________________________________________________________________________
1331 Int_t AliTRDCalibraVector::GetNrphi(Int_t i) const
1334 // Get Nrphi the granularity in col
1338 if(i==0) nrphi = (Int_t)(fModeCH&15);
1339 if(i==1) nrphi = (Int_t)(fModePH&15);
1340 if(i==2) nrphi = (Int_t)(fModePRF&15);
1345 //_________________________________________________________________________________
1346 TString AliTRDCalibraVector::GetNamePH() const
1349 // Get the name of PH to know the granularity
1352 Int_t nz = GetNz(1);
1353 Int_t nrphi = GetNrphi(1);
1363 //_________________________________________________________________________________
1364 TString AliTRDCalibraVector::GetNameCH() const
1367 // Get the name of CH to know the granularity
1370 Int_t nz = GetNz(0);
1371 Int_t nrphi = GetNrphi(0);
1381 //_________________________________________________________________________________
1382 TString AliTRDCalibraVector::GetNamePRF() const
1385 // Get the name of PRF to know the granularity
1388 Int_t nz = GetNz(2);
1389 Int_t nrphi = GetNrphi(2);
1396 name += fNbGroupPRF;
1401 //____________________________________________________________________________
1402 void AliTRDCalibraVector::SetNzNrphi(Int_t i, Int_t nz, Int_t nrphi)
1405 // Set NzNrphi for the granularity
1410 fModeCH = fModeCH << 4;
1415 fModePH = fModePH << 4;
1420 fModePRF = fModePRF << 4;