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 Long64_t AliTRDCalibraVector::Merge(const TCollection* list)
185 // Merge list of objects (needed by PROOF)
193 TIterator* iter = list->MakeIterator();
196 // collection of generated histograms
198 while((obj = iter->Next()) != 0)
200 AliTRDCalibraVector* entry = dynamic_cast<AliTRDCalibraVector*>(obj);
201 if (entry == 0) continue;
203 if(this->Add(entry)) count++;
209 //_____________________________________________________________________________
210 void AliTRDCalibraVector::TestInit(Int_t i, Int_t detmax)
213 // Init to see the size
216 for(Int_t det = 0; det < detmax; det++){
220 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
221 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
222 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
228 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
229 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
230 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
234 if(i==0) fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
239 //_____________________________________________________________________________
240 Int_t AliTRDCalibraVector::SearchBin(Float_t value, Int_t i) const
248 Float_t fbinmax = value;
249 Int_t fNumberOfBin = -1;
256 fNumberOfBin = fNumberBinCharge;
260 fbinmax = TMath::Abs(fPRFRange);
261 fbinmin = -TMath::Abs(fPRFRange);
262 fNumberOfBin = fNumberBinPRF;
270 if ((value >= fbinmax) ||
275 reponse = (Int_t) ((fNumberOfBin*(value-fbinmin)) / (fbinmax-fbinmin));
281 //_____________________________________________________________________________
282 Bool_t AliTRDCalibraVector::UpdateVectorCH(Int_t det, Int_t group, Float_t value)
285 // Fill the vector CH
289 Int_t bin = SearchBin(value,0);
297 if(fDetectorCH != det){
298 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
301 Int_t entries = ((AliTRDEntriesInfo *)fCHEntries[det])->At(group*fNumberBinCharge+bin);
303 Int_t entriesn = entries+1;
305 if(entriesn > 65535) {
310 ((AliTRDEntriesInfo *)fCHEntries[det])->AddAt(entriesn,group*fNumberBinCharge+bin);
318 //_____________________________________________________________________________
319 Bool_t AliTRDCalibraVector::UpdateVectorPRF(Int_t det, Int_t group, Float_t x, Float_t y)
322 // Fill the vector PRF
326 Int_t bin = SearchBin(x,2);
333 if(fDetectorPRF != det){
334 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
335 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
336 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
339 Int_t entries = ((AliTRDEntriesInfo *)fPRFEntries[det])->At((Int_t)group*fNumberBinPRF+bin);
340 Float_t mean = ((AliTRDPrfInfo *)fPRFMean[det])->At((Int_t)group*fNumberBinPRF+bin);
341 Float_t square = ((AliTRDPrfInfo *)fPRFSquares[det])->At((Int_t)group*fNumberBinPRF+bin);
343 Int_t entriesn = entries+1;
345 if(entriesn > 65535) return kTRUE;
347 ((AliTRDEntriesInfo *)fPRFEntries[det])->AddAt(entriesn,(Int_t)group*fNumberBinPRF+bin);
348 Float_t meann = (mean*((Float_t)entries)+y)/((Float_t)entriesn);
349 ((AliTRDPrfInfo *)fPRFMean[det])->AddAt(meann,(Int_t)group*fNumberBinPRF+bin);
350 Float_t squaren = ((square*((Float_t)entries))+(y*y))/((Float_t)entriesn);
351 ((AliTRDPrfInfo *)fPRFSquares[det])->AddAt(squaren,(Int_t)group*fNumberBinPRF+bin);
359 //_____________________________________________________________________________
360 Bool_t AliTRDCalibraVector::UpdateVectorPH(Int_t det, Int_t group, Int_t time, Float_t value)
363 // Fill the vector PH
375 if(fDetectorPH != det){
376 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
377 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
378 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
381 Int_t entries = ((AliTRDEntriesInfo *)fPHEntries[det])->At(group*fTimeMax+bin);
382 Float_t mean = ((AliTRDPhInfo *)fPHMean[det])->At(group*fTimeMax+bin);
383 Float_t square = ((AliTRDPhInfo *)fPHSquares[det])->AtS(group*fTimeMax+bin);
385 Int_t entriesn = entries+1;
386 Float_t meann = (mean*((Float_t)entries)+value)/((Float_t)entriesn);
387 Float_t squaren = ((square*((Float_t)entries))+(value*value))/((Float_t)entriesn);
389 if(entriesn > 65535) return kTRUE;
390 //printf("meann %f, squaren %f\n",meann,squaren);
391 if((meann > 3000.0) || (meann < 0.0) || (squaren > (3000.0*3000.0)) || (squaren < 0.0)) return kFALSE;
393 ((AliTRDEntriesInfo *)fPHEntries[det])->AddAt(entriesn,group*fTimeMax+bin);
394 ((AliTRDPhInfo *)fPHMean[det])->AddAt(meann,group*fTimeMax+bin);
395 ((AliTRDPhInfo *)fPHSquares[det])->AddAtS(squaren,group*fTimeMax+bin);
402 //_____________________________________________________________________________
403 Bool_t AliTRDCalibraVector::FillVectorCH(Int_t det, Int_t group, Int_t bin, Int_t entries)
406 // Fill the vector CH
409 if(entries > 65535) return kFALSE;
411 if(fDetectorCH != det){
412 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
415 ((AliTRDEntriesInfo *)fCHEntries[det])->AddAt(entries,group*fNumberBinCharge+bin);
423 //_____________________________________________________________________________
424 Bool_t AliTRDCalibraVector::FillVectorPRF(Int_t det, Int_t group, Int_t bin, Int_t entries, Float_t mean, Float_t square)
427 // Fill the vector PRF
430 if((entries > 65535) || (mean > 1.0) || (mean < 0.0) || (square > 1.0) || (square < 0.0)) return kFALSE;
432 if(fDetectorPRF != det){
433 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
434 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
435 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
438 ((AliTRDEntriesInfo *)fPRFEntries[det])->AddAt(entries,(Int_t)group*fNumberBinPRF+bin);
439 ((AliTRDPrfInfo *)fPRFMean[det])->AddAt(mean,(Int_t)group*fNumberBinPRF+bin);
440 ((AliTRDPrfInfo *)fPRFSquares[det])->AddAt(square,(Int_t)group*fNumberBinPRF+bin);
448 //_____________________________________________________________________________
449 Bool_t AliTRDCalibraVector::FillVectorPH(Int_t det, Int_t group, Int_t bin, Int_t entries, Float_t mean, Float_t square)
452 // Fill the vector PH
455 if((entries > 65535) || (mean > 3000.0) || (mean < 0.0) || (square > (3000.0*3000.0)) || (square < 0.0)) return kFALSE;
458 if(fDetectorPH != det){
459 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
460 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
461 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
464 ((AliTRDEntriesInfo *)fPHEntries[det])->AddAt(entries,group*fTimeMax+bin);
465 ((AliTRDPhInfo *)fPHMean[det])->AddAt(mean,group*fTimeMax+bin);
466 ((AliTRDPhInfo *)fPHSquares[det])->AddAtS(square,group*fTimeMax+bin);
473 //__________________________________________________________________________________
474 Bool_t AliTRDCalibraVector::Add(AliTRDCalibraVector *calvect)
477 // Add a other AliTRCalibraVector to this one
480 Bool_t result = kTRUE;
482 // Check compatibility
483 if(fNumberBinCharge != calvect->GetNumberBinCharge()) return kFALSE;
484 if(fNumberBinPRF != calvect->GetNumberBinPRF()) return kFALSE;
485 if(fPRFRange != calvect->GetPRFRange()) return kFALSE;
486 if(fTimeMax != calvect->GetTimeMax()) return kFALSE;
487 for(Int_t k = 0; k < 3; k++){
488 if(fDetCha0[k] != calvect->GetDetCha0(k)) return kFALSE;
489 if(fDetCha2[k] != calvect->GetDetCha2(k)) return kFALSE;
492 //printf("All ok for variables before adding!\n");
495 for (Int_t idet = 0; idet < 540; idet++){
497 //printf("Detector %d\n",idet);
499 const AliTRDEntriesInfo *phEntriesvect = (AliTRDEntriesInfo *) calvect->GetPHEntries(idet);
500 const AliTRDPhInfo *phMeanvect = (AliTRDPhInfo *) calvect->GetPHMean(idet);
501 const AliTRDPhInfo *phSquaresvect = (AliTRDPhInfo *) calvect->GetPHSquares(idet);
503 const AliTRDEntriesInfo *prfEntriesvect = (AliTRDEntriesInfo *) calvect->GetPRFEntries(idet);
504 const AliTRDPrfInfo *prfMeanvect = (AliTRDPrfInfo *) calvect->GetPRFMean(idet);
505 const AliTRDPrfInfo *prfSquaresvect = (AliTRDPrfInfo *) calvect->GetPRFSquares(idet);
507 const AliTRDEntriesInfo *chEntriesvect = (AliTRDEntriesInfo *) calvect->GetCHEntries(idet);
509 if ( phEntriesvect != 0x0 ){
511 fPHEntries[idet] = ((AliTRDEntriesInfo *)GetPHEntries(idet,kTRUE));
512 fPHMean[idet] = ((AliTRDPhInfo *)GetPHMean(idet,kTRUE));
513 fPHSquares[idet] = ((AliTRDPhInfo *)GetPHSquares(idet,kTRUE));
515 Int_t total = fPHEntries[idet]->GetSize();
516 //printf("Total size PH %d\n",total);
518 for(Int_t k = 0; k < total; k++){
519 Int_t entriesv = ((AliTRDEntriesInfo *)phEntriesvect)->At(k);
520 Float_t meanv = ((AliTRDPhInfo *)phMeanvect)->At(k);
521 Float_t squarev = ((AliTRDPhInfo *)phSquaresvect)->AtS(k);
523 Int_t entries = ((AliTRDEntriesInfo *)fPHEntries[idet])->At(k);
524 Float_t mean = ((AliTRDPhInfo *)fPHMean[idet])->At(k);
525 Float_t square = ((AliTRDPhInfo *)fPHSquares[idet])->AtS(k);
527 Int_t entriesn = entries+entriesv;
528 Float_t meann = (mean*((Float_t)entries)+meanv*((Float_t)entriesv))/((Float_t)entriesn);
529 Float_t squaren = ((square*((Float_t)entries))+(squarev*((Float_t)entriesv)))/((Float_t)entriesn);
531 if((entriesn > 0) && (entriesn <= 65535) && (meann >= 0) && (meann < 3000.0) && (squaren >= 0.0) && (squaren < (3000.0*3000.0))) {
533 ((AliTRDEntriesInfo *)fPHEntries[idet])->AddAt(entriesn,k);
534 ((AliTRDPhInfo *)fPHMean[idet])->AddAt(meann,k);
535 ((AliTRDPhInfo *)fPHSquares[idet])->AddAtS(squaren,k);
541 if ( prfEntriesvect != 0x0 ){
543 fPRFEntries[idet] = ((AliTRDEntriesInfo *)GetPRFEntries(idet,kTRUE));
544 fPRFMean[idet] = ((AliTRDPrfInfo *)GetPRFMean(idet,kTRUE));
545 fPRFSquares[idet] = ((AliTRDPrfInfo *)GetPRFSquares(idet,kTRUE));
547 Int_t total = fPRFEntries[idet]->GetSize();
548 //Int_t total0 = fPRFMean[idet]->GetSize();
549 //Int_t total1 = fPRFSquares[idet]->GetSize();
550 //printf("Total size PRF %d\n",total);
551 //printf("Total0 size PRF %d\n",total0);
552 //printf("Total1 size PRF %d\n",total1);
554 for(Int_t k = 0; k < total; k++){
557 Int_t entries = ((AliTRDEntriesInfo *)fPRFEntries[idet])->At(k);
558 Float_t mean = ((AliTRDPrfInfo *)fPRFMean[idet])->At(k);
559 Float_t square = ((AliTRDPrfInfo *)fPRFSquares[idet])->At(k);
561 Int_t entriesv = ((AliTRDEntriesInfo *)prfEntriesvect)->At(k);
562 Float_t meanv = ((AliTRDPrfInfo *)prfMeanvect)->At(k);
563 Float_t squarev = ((AliTRDPrfInfo *)prfSquaresvect)->At(k);
565 Int_t entriesn = entries + entriesv;
567 if((entriesn > 0) && (entriesn <= 65535)) {
569 ((AliTRDEntriesInfo *)fPRFEntries[idet])->AddAt(entriesn,k);
571 Float_t meann = (mean*((Float_t)entries)+meanv*((Float_t)entriesv))/((Float_t)entriesn);
573 ((AliTRDPrfInfo *)fPRFMean[idet])->AddAt(meann,k);
576 Float_t squaren = ((square*((Float_t)entries))+(squarev*((Float_t)entriesv)))/((Float_t)entriesn);
578 ((AliTRDPrfInfo *)fPRFSquares[idet])->AddAt(squaren,k);
585 if ( chEntriesvect != 0x0 ){
587 fCHEntries[idet] = ((AliTRDEntriesInfo *)GetCHEntries(idet,kTRUE));
588 //printf("TestAdd\n");
589 fStopFillCH = ((AliTRDEntriesInfo *)fCHEntries[idet])->TestAdd((AliTRDEntriesInfo *)chEntriesvect);
597 ((AliTRDEntriesInfo *)fCHEntries[idet])->Add(chEntriesvect);
605 //_____________________________________________________________________________________________________________________
606 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorCH()
609 // Create a AliTRDCalibraVector detector wise
612 // Use a AliTRDCalibraMode to navigate in the calibration groups
613 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
614 calibMode.SetNz(0,GetNz(0));
615 calibMode.SetNrphi(0,GetNrphi(0));
616 if(((calibMode.GetNz(0) == 100) && (calibMode.GetNrphi(0) == 100)) || ((calibMode.GetNz(0) == 10) && (calibMode.GetNrphi(0) == 10))) return 0x0;
618 Int_t nybins = 6*4*18*fDetCha0[0]+6*18*fDetCha2[0];
619 Int_t nxbins = fNumberBinCharge;
622 Int_t perChamber2 = 0;
623 Int_t perChamber0 = 0;
624 calibMode.ModePadCalibration(2,0);
625 calibMode.ModePadFragmentation(0,2,0,0);
626 calibMode.SetDetChamb2(0);
627 perChamber2 = (Int_t) calibMode.GetDetChamb2(0);
628 calibMode.ModePadCalibration(0,0);
629 calibMode.ModePadFragmentation(0,0,0,0);
630 calibMode.SetDetChamb0(0);
631 perChamber0 = (Int_t) calibMode.GetDetChamb0(0);
632 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
635 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
637 fCalVector->~AliTRDCalibraVector();
638 new(fCalVector) AliTRDCalibraVector();
640 fCalVector->SetNumberBinCharge(nxbins);
641 fCalVector->SetDetCha0(0,1);
642 fCalVector->SetDetCha2(0,1);
643 fCalVector->SetNzNrphi(0,0,0);
646 for(Int_t det = 0; det < 540; det++){
649 AliTRDEntriesInfo *entriesch = (AliTRDEntriesInfo *)GetCHEntries(det,kFALSE);
650 if(!entriesch) continue;
653 Int_t numberofgroup = 0;
654 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
655 else numberofgroup = perChamber0;
657 // Check if one can merge calibration groups for this chamber
658 // entries is the number of entries in each bin after adding the different the calibration group in the detector
659 fStopFillCH = kFALSE;
660 Int_t firstnumberofgroup = -1;
662 for(Int_t k = 0; k < nxbins; k++){
665 // Loop over group in the detector
666 for(Int_t k = 0; k < numberofgroup; k++){
668 for(Int_t nx = 0; nx < nxbins; nx++) {
669 Int_t binnumber = k*nxbins+nx;
670 entries[nx] += entriesch->At(binnumber);
671 // as soon as one bin is over threshold stop
673 if(entries[nx] > 65535) {
674 firstnumberofgroup = k;
681 if(fStopFillCH && (firstnumberofgroup == 0)) return 0x0;
682 if(!fStopFillCH) firstnumberofgroup = numberofgroup;
684 // Now add up to possible
685 for(Int_t k = 0; k < nxbins; k++){
688 for(Int_t k = 0; k < firstnumberofgroup; k++){
689 for(Int_t nx = 0; nx < nxbins; nx++) {
690 Int_t binnumber = k*nxbins+nx;
691 entries[nx] += entriesch->At(binnumber);
696 for(Int_t nx = 0; nx < nxbins; nx++){
697 fCalVector->FillVectorCH(det,0,nx,(Int_t)entries[nx]);
703 //_____________________________________________________________________________________________________________________
704 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorPH()
707 // Create a AliTRDCalibraVector detector wise
710 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
711 calibMode.SetNz(1,GetNz(1));
712 calibMode.SetNrphi(1,GetNrphi(1));
713 if(((calibMode.GetNz(1) == 100) && (calibMode.GetNrphi(1) == 100)) || ((calibMode.GetNz(1) == 10) && (calibMode.GetNrphi(1) == 10))) return 0x0;
717 Int_t nybins = 6*4*18*fDetCha0[1]+6*18*fDetCha2[1];
718 Int_t nxbins = fTimeMax;
720 Int_t perChamber2 = 0;
721 Int_t perChamber0 = 0;
722 calibMode.ModePadCalibration(2,1);
723 calibMode.ModePadFragmentation(0,2,0,1);
724 calibMode.SetDetChamb2(1);
725 perChamber2 = (Int_t) calibMode.GetDetChamb2(1);
726 calibMode.ModePadCalibration(0,1);
727 calibMode.ModePadFragmentation(0,0,0,1);
728 calibMode.SetDetChamb0(1);
729 perChamber0 = (Int_t) calibMode.GetDetChamb0(1);
731 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
734 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
736 fCalVector->~AliTRDCalibraVector();
737 new(fCalVector) AliTRDCalibraVector();
739 fCalVector->SetTimeMax(nxbins);
740 fCalVector->SetDetCha0(1,1);
741 fCalVector->SetDetCha2(1,1);
742 fCalVector->SetNzNrphi(1,0,0);
745 for(Int_t det = 0; det < 540; det++){
748 AliTRDEntriesInfo *entriesph = (AliTRDEntriesInfo *)GetPHEntries(det,kFALSE);
749 if(!entriesph) continue;
750 AliTRDPhInfo *meanph = (AliTRDPhInfo *)GetPHMean(det,kFALSE);
751 AliTRDPhInfo *squaresph = (AliTRDPhInfo *)GetPHSquares(det,kFALSE);
754 Int_t numberofgroup = 0;
755 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
756 else numberofgroup = perChamber0;
759 for(Int_t nx = 0; nx < nxbins; nx++) {
761 Double_t entries = 0.0;
762 Double_t sumw2 = 0.0;
765 // Sum the contributions of the different calibration group in the detector
766 for(Int_t k = 0; k < numberofgroup; k++){
768 Int_t binnumber = k*nxbins+nx;
770 Int_t entriesv = ((AliTRDEntriesInfo *)entriesph)->At(binnumber);
771 Float_t sumw2v = ((AliTRDPhInfo *)squaresph)->AtS(binnumber)*entriesv;
772 Float_t sumwv = ((AliTRDPhInfo *)meanph)->At(binnumber)*entriesv;
775 if(((entries+entriesv) > 65535) || ((entries+entriesv) <= 0)) continue;
784 sumw2 = sumw2/((Float_t)entries);
785 sumw = sumw/((Float_t)entries);
788 fCalVector->FillVectorPH(det,0,nx,(Int_t)entries,(Float_t)sumw,(Float_t)sumw2);
795 //_____________________________________________________________________________________________________________________
796 AliTRDCalibraVector *AliTRDCalibraVector::AddStatsPerDetectorPRF()
799 // Create a AliTRDCalibraVector detector wise
802 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
803 calibMode.SetNz(2,GetNz(2));
804 calibMode.SetNrphi(2,GetNrphi(2));
805 if(((calibMode.GetNz(2) == 100) && (calibMode.GetNrphi(2) == 100)) || ((calibMode.GetNz(2) == 10) && (calibMode.GetNrphi(2) == 10))) return 0x0;
808 Int_t nybins = 6*4*18*fDetCha0[2]+ 6*18*fDetCha2[2];
809 Int_t nxbins = fNumberBinPRF;
811 Int_t perChamber2 = 0;
812 Int_t perChamber0 = 0;
813 calibMode.ModePadCalibration(2,2);
814 calibMode.ModePadFragmentation(0,2,0,2);
815 calibMode.SetDetChamb2(2);
816 perChamber2 = (Int_t) calibMode.GetDetChamb2(2);
817 calibMode.ModePadCalibration(0,2);
818 calibMode.ModePadFragmentation(0,0,0,2);
819 calibMode.SetDetChamb0(2);
820 perChamber0 = (Int_t) calibMode.GetDetChamb0(2);
822 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return 0x0;
825 if(!fCalVector) fCalVector = new AliTRDCalibraVector();
827 fCalVector->~AliTRDCalibraVector();
828 new(fCalVector) AliTRDCalibraVector();
830 fCalVector->SetNumberBinPRF(nxbins);
831 fCalVector->SetDetCha0(2,1);
832 fCalVector->SetDetCha2(2,1);
833 fCalVector->SetNzNrphi(2,0,0);
834 fCalVector->SetNbGroupPRF(fNbGroupPRF);
837 for(Int_t det = 0; det < 540; det++){
840 AliTRDEntriesInfo *entriesprf = (AliTRDEntriesInfo *) GetPRFEntries(det,kFALSE);
841 if(!entriesprf) continue;
842 AliTRDPrfInfo *meanprf = (AliTRDPrfInfo *) GetPRFMean(det,kFALSE);
843 AliTRDPrfInfo *squaresprf = (AliTRDPrfInfo *) GetPRFSquares(det,kFALSE);
846 Int_t numberofgroup = 0;
847 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
848 else numberofgroup = perChamber0;
850 for(Int_t nx = 0; nx < nxbins; nx++) {
852 Double_t entries = 0.0;
853 Double_t sumw2 = 0.0;
856 // Sum the contributions of the different groups in the detector for one bin
857 for(Int_t k = 0; k < numberofgroup; k++){
859 Int_t binnumber = k*nxbins+nx;
861 Int_t entriesv = ((AliTRDEntriesInfo *)entriesprf)->At(binnumber);
862 Float_t sumw2v = ((AliTRDPrfInfo *)squaresprf)->At(binnumber)*entriesv;
863 Float_t sumwv = ((AliTRDPrfInfo *)meanprf)->At(binnumber)*entriesv;
865 if(((entries+entriesv) > 65535) || ((entries+entriesv) <= 0)) continue;
874 sumw2 = sumw2/((Float_t)entries);
875 sumw = sumw/((Float_t)entries);
878 fCalVector->FillVectorPRF(det,0,nx,(Int_t)entries,(Float_t)sumw,(Float_t)sumw2);
885 //_______________________________________________________________________________
886 Bool_t AliTRDCalibraVector::FindTheMaxEntries(Int_t i, Int_t &detectormax, Int_t &groupmax)
889 // Find detectormax and groupmax with the biggest number of entries
892 Int_t numberofTB = 0;
893 if(i==0) numberofTB = (Int_t) GetNumberBinCharge();
894 if(i==1) numberofTB = GetTimeMax();
895 if(i==2) numberofTB = GetNumberBinPRF();
896 if((i!=0) && (i!=1) && (i!=2)) AliInfo("Didn't understand i");
900 Double_t entries [540];
901 for(Int_t idet = 0; idet < 540; idet++){
905 AliTRDEntriesInfo *entriesd = 0x0;
906 // Take the number of entries per detector
907 for(Int_t idet = 0; idet < 540; idet++){
909 if(i==0) entriesd = (AliTRDEntriesInfo *) GetCHEntries(idet,kFALSE);
910 if(i==1) entriesd = (AliTRDEntriesInfo *) GetPHEntries(idet,kFALSE);
911 if(i==2) entriesd = (AliTRDEntriesInfo *) GetPRFEntries(idet,kFALSE);
912 if(!entriesd) continue;
914 entries[idet] = entriesd->GetSum();
918 // Search detector max
921 for(Int_t idet = 0; idet < 540; idet++){
922 if(entries[idet] > max) {
927 if((max == 0.0) || (detectormax <0.0)) return kFALSE;
930 if(i==0) entriesd = (AliTRDEntriesInfo *) GetCHEntries(detectormax,kFALSE);
931 if(i==1) entriesd = (AliTRDEntriesInfo *) GetPHEntries(detectormax,kFALSE);
932 if(i==2) entriesd = (AliTRDEntriesInfo *) GetPRFEntries(detectormax,kFALSE);
933 if(!entriesd) return kFALSE;
935 Int_t numberofgroup = 0;
936 if(AliTRDgeometry::GetStack(detectormax) == 2) numberofgroup = fDetCha2[i];
937 else numberofgroup = fDetCha0[i];
939 Double_t nbgroup [2304];
940 for(Int_t k = 0; k < 2304; k++){
944 if(i==0) nxbins = fNumberBinCharge;
945 if(i==1) nxbins = fTimeMax;
946 if(i==2) nxbins = fNumberBinPRF;
947 // Compute the number of entries per group
948 for(Int_t k = 0; k < numberofgroup; k++){
949 for(Int_t nx = 0; nx < nxbins; nx++) {
950 Int_t binnumber = k*nxbins+nx;
951 nbgroup[k] += ((AliTRDEntriesInfo *)entriesd)->At(binnumber);
956 for(Int_t io = 0; io < numberofgroup; io++){
957 if(nbgroup[io] > max){
962 if((max == 0.0) || (groupmax < 0.0) || (groupmax >= numberofgroup)) return kFALSE;
967 //_____________________________________________________________________________
968 TGraphErrors *AliTRDCalibraVector::ConvertVectorPHTGraphErrors(Int_t det, Int_t group , const Char_t * name)
971 // Convert the fVectorPHMean, fVectorPHSquares and fVectorPHEntries in TGraphErrors
975 fPHEntries[det] = ((AliTRDEntriesInfo *)GetPHEntries(det,kTRUE));
976 fPHMean[det] = ((AliTRDPhInfo *)GetPHMean(det,kTRUE));
977 fPHSquares[det] = ((AliTRDPhInfo *)GetPHSquares(det,kTRUE));
982 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
984 AliInfo("Could not get CommonParam, take the default 10MHz");
986 sf = parCom->GetSamplingFrequency();
988 Double_t x[35]; // Xaxis
989 Double_t y[35]; // Sum/entries
990 Double_t ex[35]; // Nentries
991 Double_t ey[35]; // Sum of square/nentries
994 if(sf > 0.0) step = 1.0 / sf;
996 Int_t offset = group*fTimeMax;
999 for (Int_t k = 0; k < fTimeMax; k++) {
1000 x[k] = min + k*step;
1004 Int_t bin = offset+k;
1005 // Fill only if there is more than 0 something
1006 if (((AliTRDEntriesInfo *)fPHEntries[det])->At(bin) > 0) {
1007 ex[k] = ((AliTRDEntriesInfo *)fPHEntries[det])->At(bin);
1008 y[k] = ((AliTRDPhInfo *)fPHMean[det])->At(bin);
1009 ey[k] = ((AliTRDPhInfo *)fPHSquares[det])->AtS(bin);
1013 // Define the TGraphErrors
1014 if(!fGraph) fGraph = new TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
1016 fGraph->~TGraphErrors();
1017 new(fGraph) TGraphErrors(fTimeMax,&x[0],&y[0],&ex[0],&ey[0]);
1019 fGraph->SetTitle(name);
1024 //_____________________________________________________________________________
1025 TGraphErrors *AliTRDCalibraVector::ConvertVectorPRFTGraphErrors(Int_t det, Int_t group , const Char_t * name)
1028 // Convert the fVectorPRFMean, fVectorPRFSquares and fVectorPRFEntries in TGraphErrors
1032 fPRFEntries[det] = ((AliTRDEntriesInfo *)GetPRFEntries(det,kTRUE));
1033 fPRFMean[det] = ((AliTRDPrfInfo *)GetPRFMean(det,kTRUE));
1034 fPRFSquares[det] = ((AliTRDPrfInfo *)GetPRFSquares(det,kTRUE));
1038 Double_t x[200]; // Xaxis
1039 Double_t y[200]; // Sum/entries
1040 Double_t ex[200]; //Nentries
1041 Double_t ey[200]; // Sum of square/nentries
1042 Double_t step = 0.0;
1044 if(fNumberBinPRF) step = (2*TMath::Abs(fPRFRange)) / fNumberBinPRF;
1045 min = -TMath::Abs(fPRFRange) + step / 2.0;
1046 Int_t offset = group*fNumberBinPRF;
1047 //printf("number of total: %d\n",fNumberBinPRF);
1049 for (Int_t k = 0; k < fNumberBinPRF; k++) {
1050 x[k] = min + k*step;
1054 Int_t bin = offset+k;
1055 // Fill only if there is more than 0 something
1056 if (((AliTRDEntriesInfo *)fPRFEntries[det])->At(bin) > 0) {
1057 ex[k] = ((AliTRDEntriesInfo *)fPRFEntries[det])->At(bin);
1058 y[k] = ((AliTRDPrfInfo *)fPRFMean[det])->At(bin);
1059 ey[k] = ((AliTRDPrfInfo *)fPRFSquares[det])->At(bin);
1061 //printf("Number of entries %f for %d\n",ex[k],k);
1064 // Define the TGraphErrors
1065 if(!fGraph) fGraph = new TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1067 fGraph->~TGraphErrors();
1068 new(fGraph) TGraphErrors(fNumberBinPRF,&x[0],&y[0],&ex[0],&ey[0]);
1070 fGraph->SetTitle(name);
1077 //_____________________________________________________________________________
1078 TH1F *AliTRDCalibraVector::CorrectTheError(const TGraphErrors *hist, Int_t &nbEntries)
1081 // In the case of the vectors method the trees contains TGraphErrors for PH and PRF
1082 // to be able to add them after
1083 // We convert it to a TH1F to be able to applied the same fit function method
1084 // After having called this function you can not add the statistics anymore
1087 Int_t nbins = hist->GetN();
1088 Double_t *x = hist->GetX();
1089 Double_t *entries = hist->GetEX();
1090 Double_t *mean = hist->GetY();
1091 Double_t *square = hist->GetEY();
1098 Double_t step = x[1] - x[0];
1099 Double_t minvalue = x[0] - step/2;
1100 Double_t maxvalue = x[(nbins-1)] + step/2;
1102 if(!fHisto) fHisto = new TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1105 new(fHisto) TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
1108 for (Int_t k = 0; k < nbins; k++) {
1109 fHisto->SetBinContent(k+1,mean[k]);
1110 if (entries[k] > 0.0) {
1111 nbEntries += (Int_t) entries[k];
1112 Double_t d = TMath::Abs(square[k] - (mean[k]*mean[k]));
1113 fHisto->SetBinError(k+1,TMath::Sqrt(d/entries[k]));
1116 fHisto->SetBinError(k+1,0.0);
1123 //_____________________________________________________________________________
1124 TH1F *AliTRDCalibraVector::ConvertVectorCHHisto(Int_t det, Int_t group, const Char_t * name)
1127 // Convert the fVectorCHEntries in TH1F
1131 fCHEntries[det] = ((AliTRDEntriesInfo *)GetCHEntries(det,kTRUE));
1134 if(!fHisto) fHisto = new TH1F(name,name,fNumberBinCharge,0,300);
1137 new(fHisto) TH1F(name,name,fNumberBinCharge,0,300);
1140 Int_t offset = group*fNumberBinCharge;
1142 for (Int_t k = 0; k < fNumberBinCharge; k++) {
1143 Int_t bin = offset+k;
1144 fHisto->SetBinContent(k+1,((AliTRDEntriesInfo *)fCHEntries[det])->At(bin));
1145 fHisto->SetBinError(k+1,TMath::Sqrt(TMath::Abs(((AliTRDEntriesInfo *)fCHEntries[det])->At(bin))));
1151 //_____________________________________________________________________
1152 TObject* AliTRDCalibraVector::GetPHEntries(Int_t det
1153 , Bool_t force) /*FOLD00*/
1156 // return pointer to Carge ROC Calibration
1157 // if force is true create a new histogram if it doesn't exist allready
1159 AliTRDEntriesInfo**arr = &fPHEntries[0];
1160 return (TObject *) GetEntriesPH(det, arr, force);
1162 //_____________________________________________________________________
1163 TObject* AliTRDCalibraVector::GetPRFEntries(Int_t det
1164 , Bool_t force) /*FOLD00*/
1167 // return pointer to Carge ROC Calibration
1168 // if force is true create a new histogram if it doesn't exist allready
1170 AliTRDEntriesInfo**arr = &fPRFEntries[0];
1171 return (TObject *) GetEntriesPRF(det, arr, force);
1173 //_____________________________________________________________________
1174 TObject* AliTRDCalibraVector::GetCHEntries(Int_t det
1175 , Bool_t force) /*FOLD00*/
1178 // return pointer to Carge ROC Calibration
1179 // if force is true create a new histogram if it doesn't exist allready
1181 AliTRDEntriesInfo**arr = &fCHEntries[0];
1182 return (TObject *) GetEntriesCH(det, arr, force);
1184 //_____________________________________________________________________
1185 TObject* AliTRDCalibraVector::GetPHMean(Int_t det
1186 , Bool_t force) /*FOLD00*/
1189 // return pointer to ROC Calibration
1190 // if force is true create a new array
1192 AliTRDPhInfo**arr = &fPHMean[0];
1193 return (TObject *) GetMeanSquaresPH(det, arr, force);
1195 //_____________________________________________________________________
1196 TObject* AliTRDCalibraVector::GetPHSquares(Int_t det
1197 , Bool_t force) /*FOLD00*/
1200 // return pointer to ROC Calibration
1201 // if force is true create a new array
1203 AliTRDPhInfo**arr = &fPHSquares[0];
1204 return (TObject *) GetMeanSquaresPH(det, arr, force);
1206 //_____________________________________________________________________
1207 TObject* AliTRDCalibraVector::GetPRFMean(Int_t det
1208 , Bool_t force) /*FOLD00*/
1211 // return pointer to ROC Calibration
1212 // if force is true create a new array
1214 AliTRDPrfInfo**arr = &fPRFMean[0];
1215 return (TObject *) GetMeanSquaresPRF(det, arr, force);
1217 //_____________________________________________________________________
1218 TObject* AliTRDCalibraVector::GetPRFSquares(Int_t det
1219 , Bool_t force) /*FOLD00*/
1222 // return pointer to ROC Calibration
1223 // if force is true create a new array
1225 AliTRDPrfInfo**arr = &fPRFSquares[0];
1226 return (TObject *) GetMeanSquaresPRF(det, arr, force);
1228 //_____________________________________________________________________
1229 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesCH(Int_t det
1230 , AliTRDEntriesInfo** arr
1231 , Bool_t force) /*FOLD00*/
1234 // return pointer to UShort_t array Entries
1235 // if force is true create a new UShort_t array if it doesn't exist allready
1237 if ( (!force) || (arr[det]))
1238 return (AliTRDEntriesInfo*)arr[det];
1240 // if we are forced and TArrayI doesn't yes exist create it
1241 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,0,fNumberBinCharge);
1243 arr[det] = new AliTRDEntriesInfo(ngroup);
1245 return (AliTRDEntriesInfo*)arr[det];
1248 //_____________________________________________________________________
1249 AliTRDEntriesInfo* AliTRDCalibraVector::GetEntriesPRF(Int_t det
1250 , AliTRDEntriesInfo** arr
1251 , Bool_t force) /*FOLD00*/
1254 // return pointer to UShort_t array Entries
1255 // if force is true create a new UShort_t array if it doesn't exist allready
1257 if ( (!force) || (arr[det]))
1258 return (AliTRDEntriesInfo*)arr[det];
1260 // if we are forced and TArrayI doesn't yes exist create it
1261 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF);
1263 arr[det] = new AliTRDEntriesInfo(ngroup);
1265 return (AliTRDEntriesInfo*)arr[det];
1268 //_____________________________________________________________________
1269 AliTRDEntriesInfo *AliTRDCalibraVector::GetEntriesPH(Int_t det
1270 , AliTRDEntriesInfo ** arr
1271 , Bool_t force) /*FOLD00*/
1274 // return pointer to UShort_t array Entries
1275 // if force is true create a new UShort_t array if it doesn't exist allready
1277 if ( (!force) || (arr[det]))
1278 return (AliTRDEntriesInfo *)arr[det];
1280 // if we are forced and UShort_t doesn't yet exist create it
1281 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax);
1283 arr[det] = new AliTRDEntriesInfo(ngroup);
1285 return (AliTRDEntriesInfo*)arr[det];
1288 //_____________________________________________________________________
1289 AliTRDPhInfo* AliTRDCalibraVector::GetMeanSquaresPH(Int_t det
1290 , AliTRDPhInfo** arr
1291 , Bool_t force) /*FOLD00*/
1294 // return pointer to Float_t array Mean or Squares
1295 // if force is true create a new Float_t array if it doesn't exist allready
1297 if ( (!force) || (arr[det]))
1298 return (AliTRDPhInfo*)arr[det];
1300 // if we are forced and Float_t array doesn't yes exist create it
1301 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,1,fTimeMax);
1303 arr[det] = new AliTRDPhInfo(ngroup);
1305 return ((AliTRDPhInfo *)arr[det]);
1307 //_____________________________________________________________________
1308 AliTRDPrfInfo* AliTRDCalibraVector::GetMeanSquaresPRF(Int_t det
1309 , AliTRDPrfInfo** arr
1310 , Bool_t force) /*FOLD00*/
1313 // return pointer to Float_t array Mean or Squares
1314 // if force is true create a new array if it doesn't exist allready
1316 if ( (!force) || (arr[det]))
1319 // if we are forced and the array doesn't yet exist create it
1320 Int_t ngroup = GetTotalNumberOfBinsInDetector(det,2,fNumberBinPRF);
1322 arr[det] = new AliTRDPrfInfo(ngroup);
1324 return (AliTRDPrfInfo*)arr[det];
1327 //_____________________________________________________________________________
1328 Int_t AliTRDCalibraVector::GetTotalNumberOfBinsInDetector(Int_t det, Int_t i, Int_t nbBin) const
1331 // Get the total number of bins (Nb of bins*Nb of groups) in the detector det for the group i
1335 Int_t stack = AliTRDgeometry::GetStack(det);
1336 if(stack == 2) ngroup = fDetCha2[i]*nbBin;
1337 else ngroup = fDetCha0[i]*nbBin;
1342 //____________________________________________________________________________
1343 Int_t AliTRDCalibraVector::GetNz(Int_t i) const
1346 // Get Nz the granularity in row
1350 if(i==0) nz = (Int_t)(fModeCH>>4);
1351 if(i==1) nz = (Int_t)(fModePH>>4);
1352 if(i==2) nz = (Int_t)(fModePRF>>4);
1357 //____________________________________________________________________________
1358 Int_t AliTRDCalibraVector::GetNrphi(Int_t i) const
1361 // Get Nrphi the granularity in col
1365 if(i==0) nrphi = (Int_t)(fModeCH&15);
1366 if(i==1) nrphi = (Int_t)(fModePH&15);
1367 if(i==2) nrphi = (Int_t)(fModePRF&15);
1372 //_________________________________________________________________________________
1373 TString AliTRDCalibraVector::GetNamePH() const
1376 // Get the name of PH to know the granularity
1379 Int_t nz = GetNz(1);
1380 Int_t nrphi = GetNrphi(1);
1390 //_________________________________________________________________________________
1391 TString AliTRDCalibraVector::GetNameCH() const
1394 // Get the name of CH to know the granularity
1397 Int_t nz = GetNz(0);
1398 Int_t nrphi = GetNrphi(0);
1408 //_________________________________________________________________________________
1409 TString AliTRDCalibraVector::GetNamePRF() const
1412 // Get the name of PRF to know the granularity
1415 Int_t nz = GetNz(2);
1416 Int_t nrphi = GetNrphi(2);
1423 name += fNbGroupPRF;
1428 //____________________________________________________________________________
1429 void AliTRDCalibraVector::SetNzNrphi(Int_t i, Int_t nz, Int_t nrphi)
1432 // Set NzNrphi for the granularity
1437 fModeCH = fModeCH << 4;
1442 fModePH = fModePH << 4;
1447 fModePRF = fModePRF << 4;