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 /////////////////////////////////////////////////////////////////////////////////
22 // This class is for the TRD calibration of the relative gain factor, the drift velocity,
23 // the time 0 and the pad response function. It fits the histos.
24 // The 2D histograms or vectors (first converted in 1D histos) will be fitted
25 // if they have enough entries, otherwise the (default) value of the choosen database
26 // will be put. For the relative gain calibration the resulted factors will be globally
27 // normalized to the gain factors of the choosen database. It unables to precise
28 // previous calibration procedure.
29 // The function SetDebug enables the user to see:
30 // _fDebug = 0: nothing, only the values are written in the tree if wanted
31 // _fDebug = 1: a comparaison of the coefficients found and the default values
32 // in the choosen database.
33 // fCoef , histogram of the coefs as function of the calibration group number
34 // fDelta , histogram of the relative difference of the coef with the default
35 // value in the database as function of the calibration group number
36 // fError , dirstribution of this relative difference
37 // _fDebug = 2: only the fit of the choosen calibration group fFitVoir (SetFitVoir)
38 // _fDebug = 3: The coefficients in the choosen detector fDet (SetDet) as function of the
39 // pad row and col number
40 // _fDebug = 4; The coeffcicients in the choosen detector fDet (SetDet) like in the 3 but with
41 // also the comparaison histograms of the 1 for this detector
45 // R. Bailhache (R.Bailhache@gsi.de)
47 //////////////////////////////////////////////////////////////////////////////////////
52 #include <TProfile2D.h>
54 #include <TGraphErrors.h>
55 #include <TObjArray.h>
61 #include <TDirectory.h>
63 #include <TTreeStream.h>
64 #include <TLinearFitter.h>
69 #include "AliMathBase.h"
71 #include "AliTRDCalibraFit.h"
72 #include "AliTRDCalibraMode.h"
73 #include "AliTRDCalibraVector.h"
74 #include "AliTRDCalibraVdriftLinearFit.h"
75 #include "AliTRDcalibDB.h"
76 #include "AliTRDgeometry.h"
77 #include "AliTRDpadPlane.h"
78 #include "AliTRDgeometry.h"
79 #include "./Cal/AliTRDCalROC.h"
80 #include "./Cal/AliTRDCalPad.h"
81 #include "./Cal/AliTRDCalDet.h"
84 ClassImp(AliTRDCalibraFit)
86 AliTRDCalibraFit* AliTRDCalibraFit::fgInstance = 0;
87 Bool_t AliTRDCalibraFit::fgTerminated = kFALSE;
89 //_____________singleton implementation_________________________________________________
90 AliTRDCalibraFit *AliTRDCalibraFit::Instance()
93 // Singleton implementation
96 if (fgTerminated != kFALSE) {
100 if (fgInstance == 0) {
101 fgInstance = new AliTRDCalibraFit();
108 //______________________________________________________________________________________
109 void AliTRDCalibraFit::Terminate()
112 // Singleton implementation
113 // Deletes the instance of this class
116 fgTerminated = kTRUE;
118 if (fgInstance != 0) {
125 //______________________________________________________________________________________
126 AliTRDCalibraFit::AliTRDCalibraFit()
129 ,fNumberOfBinsExpected(0)
131 ,fBeginFitCharge(3.5)
133 ,fTakeTheMaxPH(kTRUE)
141 ,fNumberFitSuccess(0)
148 ,fCalibraMode(new AliTRDCalibraMode())
153 ,fScaleFitFactor(0.0)
161 ,fCurrentCoefDetector(0x0)
162 ,fCurrentCoefDetector2(0x0)
167 // Default constructor
170 fGeo = new AliTRDgeometry();
172 // Current variables initialised
173 for (Int_t k = 0; k < 2; k++) {
174 fCurrentCoef[k] = 0.0;
175 fCurrentCoef2[k] = 0.0;
177 for (Int_t i = 0; i < 3; i++) {
183 //______________________________________________________________________________________
184 AliTRDCalibraFit::AliTRDCalibraFit(const AliTRDCalibraFit &c)
187 ,fNumberOfBinsExpected(c.fNumberOfBinsExpected)
189 ,fBeginFitCharge(c.fBeginFitCharge)
190 ,fFitPHPeriode(c.fFitPHPeriode)
191 ,fTakeTheMaxPH(c.fTakeTheMaxPH)
192 ,fT0Shift0(c.fT0Shift0)
193 ,fT0Shift1(c.fT0Shift1)
194 ,fRangeFitPRF(c.fRangeFitPRF)
196 ,fMinEntries(c.fMinEntries)
198 ,fNumberFit(c.fNumberFit)
199 ,fNumberFitSuccess(c.fNumberFitSuccess)
200 ,fNumberEnt(c.fNumberEnt)
201 ,fStatisticMean(c.fStatisticMean)
203 ,fDebugLevel(c.fDebugLevel)
204 ,fFitVoir(c.fFitVoir)
205 ,fMagneticField(c.fMagneticField)
207 ,fCurrentCoefE(c.fCurrentCoefE)
208 ,fCurrentCoefE2(c.fCurrentCoefE2)
211 ,fScaleFitFactor(c.fScaleFitFactor)
212 ,fEntriesCurrent(c.fEntriesCurrent)
213 ,fCountDet(c.fCountDet)
219 ,fCurrentCoefDetector(0x0)
220 ,fCurrentCoefDetector2(0x0)
228 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
230 //Current variables initialised
231 for (Int_t k = 0; k < 2; k++) {
232 fCurrentCoef[k] = 0.0;
233 fCurrentCoef2[k] = 0.0;
235 for (Int_t i = 0; i < 3; i++) {
239 if(c.fCalDet) fCalDet = new AliTRDCalDet(*c.fCalDet);
240 if(c.fCalDet2) fCalDet2 = new AliTRDCalDet(*c.fCalDet2);
242 if(c.fCalROC) fCalROC = new AliTRDCalROC(*c.fCalROC);
243 if(c.fCalROC2) fCalROC = new AliTRDCalROC(*c.fCalROC2);
245 fVectorFit.SetName(c.fVectorFit.GetName());
246 for(Int_t k = 0; k < c.fVectorFit.GetEntriesFast(); k++){
247 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
248 Int_t detector = ((AliTRDFitInfo *)c.fVectorFit.UncheckedAt(k))->GetDetector();
250 if (GetChamber(detector) == 2) {
256 Float_t *coef = new Float_t[ntotal];
257 for (Int_t i = 0; i < ntotal; i++) {
258 coef[i] = ((AliTRDFitInfo *)c.fVectorFit.UncheckedAt(k))->GetCoef()[i];
260 fitInfo->SetCoef(coef);
261 fitInfo->SetDetector(detector);
262 fVectorFit.Add((TObject *) fitInfo);
264 fVectorFit.SetName(c.fVectorFit.GetName());
265 for(Int_t k = 0; k < c.fVectorFit2.GetEntriesFast(); k++){
266 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
267 Int_t detector = ((AliTRDFitInfo *)c.fVectorFit2.UncheckedAt(k))->GetDetector();
269 if (GetChamber(detector) == 2) {
275 Float_t *coef = new Float_t[ntotal];
276 for (Int_t i = 0; i < ntotal; i++) {
277 coef[i] = ((AliTRDFitInfo *)c.fVectorFit2.UncheckedAt(k))->GetCoef()[i];
279 fitInfo->SetCoef(coef);
280 fitInfo->SetDetector(detector);
281 fVectorFit2.Add((TObject *) fitInfo);
286 fGeo = new AliTRDgeometry();
289 //____________________________________________________________________________________
290 AliTRDCalibraFit::~AliTRDCalibraFit()
293 // AliTRDCalibraFit destructor
295 if ( fDebugStreamer ) delete fDebugStreamer;
296 if ( fCalDet ) delete fCalDet;
297 if ( fCalDet2 ) delete fCalDet2;
298 if ( fCalROC ) delete fCalROC;
299 if ( fCalROC2 ) delete fCalROC2;
301 fVectorFit2.Delete();
307 //_____________________________________________________________________________
308 void AliTRDCalibraFit::Destroy()
320 //__________________________________________________________________________________
321 void AliTRDCalibraFit::RangeChargeIntegration(Float_t vdrift, Float_t t0, Int_t &begin, Int_t &peak, Int_t &end)
324 // From the drift velocity and t0
325 // return the position of the peak and maximum negative slope
328 const Float_t kDrWidth = AliTRDgeometry::DrThick(); // drift region
329 Double_t widbins = 0.1; // 0.1 mus
331 //peak and maxnegslope in mus
332 Double_t begind = t0*widbins + fT0Shift0;
333 Double_t peakd = t0*widbins + fT0Shift1;
334 Double_t maxnegslope = (kDrWidth + vdrift*peakd)/vdrift;
336 // peak and maxnegslope in timebin
337 begin = TMath::Nint(begind*widbins);
338 peak = TMath::Nint(peakd*widbins);
339 end = TMath::Nint(maxnegslope*widbins);
342 //____________Functions fit Online CH2d________________________________________
343 Bool_t AliTRDCalibraFit::AnalyseCH(TH2I *ch)
346 // Fit the 1D histos, projections of the 2D ch on the Xaxis, for each
347 // calibration group normalized the resulted coefficients (to 1 normally)
350 // Set the calibration mode
351 const char *name = ch->GetTitle();
352 SetModeCalibration(name,0);
354 // Number of Ybins (detectors or groups of pads)
355 Int_t nbins = ch->GetNbinsX();// charge
356 Int_t nybins = ch->GetNbinsY();// groups number
357 if (!InitFit(nybins,0)) {
363 fStatisticMean = 0.0;
365 fNumberFitSuccess = 0;
367 // Init fCountDet and fCount
368 InitfCountDetAndfCount(0);
369 // Beginning of the loop betwwen dect1 and dect2
370 for (Int_t idect = fDect1; idect < fDect2; idect++) {
371 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...
372 UpdatefCountDetAndfCount(idect,0);
373 ReconstructFitRowMinRowMax(idect, 0);
375 TH1I *projch = (TH1I *) ch->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
376 projch->SetDirectory(0);
377 // Number of entries for this calibration group
378 Double_t nentries = 0.0;
380 for (Int_t k = 0; k < nbins; k++) {
381 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
382 nentries += ch->GetBinContent(binnb);
383 mean += projch->GetBinCenter(k+1)*projch->GetBinContent(k+1);
384 projch->SetBinError(k+1,TMath::Sqrt(projch->GetBinContent(k+1)));
386 projch->SetEntries(nentries);
387 //printf("The number of entries for the group %d is %f\n",idect,nentries);
392 // Rebin and statistic stuff
394 projch = ReBin((TH1I *) projch);
396 // This detector has not enough statistics or was off
397 if (nentries <= fMinEntries) {
398 NotEnoughStatisticCH(idect);
399 if (fDebugLevel != 1) {
404 // Statistics of the group fitted
405 fStatisticMean += nentries;
410 case 0: FitMeanW((TH1 *) projch, nentries); break;
411 case 1: FitMean((TH1 *) projch, nentries, mean); break;
412 case 2: FitCH((TH1 *) projch, mean); break;
413 case 3: FitBisCH((TH1 *) projch, mean); break;
414 default: return kFALSE;
417 FillInfosFitCH(idect);
419 if (fDebugLevel != 1) {
424 if (fDebugLevel != 1) {
428 if (fNumberFit > 0) {
429 AliInfo(Form("There are %d with at least one entries. %d fits have been proceeded (sucessfully or not...). There is a mean statistic of: %d over these fitted histograms and %d successfulled fits",fNumberEnt, fNumberFit, (Int_t) fStatisticMean/fNumberFit, fNumberFitSuccess));
430 fStatisticMean = fStatisticMean / fNumberFit;
433 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
435 delete fDebugStreamer;
436 fDebugStreamer = 0x0;
440 //____________Functions fit Online CH2d________________________________________
441 Bool_t AliTRDCalibraFit::AnalyseCH(AliTRDCalibraVector *calvect)
444 // Reconstruct a 1D histo from the vectorCH for each calibration group,
445 // fit the histo, normalized the resulted coefficients (to 1 normally)
448 // Set the calibraMode
449 const char *name = calvect->GetNameCH();
450 SetModeCalibration(name,0);
452 // Number of Xbins (detectors or groups of pads)
453 if (!InitFit((432*calvect->GetDetCha0(0)+108*calvect->GetDetCha2(0)),0)) {
459 fStatisticMean = 0.0;
461 fNumberFitSuccess = 0;
463 // Init fCountDet and fCount
464 InitfCountDetAndfCount(0);
465 // Beginning of the loop between dect1 and dect2
466 for (Int_t idect = fDect1; idect < fDect2; idect++) {
467 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...........
468 UpdatefCountDetAndfCount(idect,0);
469 ReconstructFitRowMinRowMax(idect,0);
471 Double_t nentries = 0.0;
474 Bool_t something = kTRUE;
475 if(!calvect->GetCHEntries(fCountDet)) something = kFALSE;
479 projch = calvect->ConvertVectorCHHisto(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0)))),(const char *) name);
480 projch->SetDirectory(0);
481 for (Int_t k = 0; k < calvect->GetNumberBinCharge(); k++) {
482 nentries += projch->GetBinContent(k+1);
483 mean += projch->GetBinCenter(k+1)*projch->GetBinContent(k+1);
489 //printf("The number of entries for the group %d is %f\n",idect,nentries);
492 projch = ReBin((TH1F *) projch);
495 // This detector has not enough statistics or was not found in VectorCH
496 if (nentries <= fMinEntries) {
497 NotEnoughStatisticCH(idect);
498 if (fDebugLevel != 1) {
499 if(projch) delete projch;
503 // Statistic of the histos fitted
504 fStatisticMean += nentries;
509 case 0: FitMeanW((TH1 *) projch, nentries); break;
510 case 1: FitMean((TH1 *) projch, nentries, mean); break;
511 case 2: FitCH((TH1 *) projch, mean); break;
512 case 3: FitBisCH((TH1 *) projch, mean); break;
513 default: return kFALSE;
516 FillInfosFitCH(idect);
518 if (fDebugLevel != 1) {
523 if (fDebugLevel != 1) {
527 if (fNumberFit > 0) {
528 AliInfo(Form("There are %d with at least one entries. %d fits have been proceeded (sucessfully or not...). There is a mean statistic of: %d over these fitted histograms and %d successfulled fits",fNumberEnt, fNumberFit, (Int_t) fStatisticMean/fNumberFit, fNumberFitSuccess));
529 fStatisticMean = fStatisticMean / fNumberFit;
532 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
534 delete fDebugStreamer;
535 fDebugStreamer = 0x0;
538 //________________functions fit Online PH2d____________________________________
539 Bool_t AliTRDCalibraFit::AnalysePH(TProfile2D *ph)
542 // Take the 1D profiles (average pulse height), projections of the 2D PH
543 // on the Xaxis, for each calibration group
544 // Reconstruct a drift velocity
545 // A first calibration of T0 is also made using the same method
548 // Set the calibration mode
549 const char *name = ph->GetTitle();
550 SetModeCalibration(name,1);
552 // Number of Xbins (detectors or groups of pads)
553 Int_t nbins = ph->GetNbinsX();// time
554 Int_t nybins = ph->GetNbinsY();// calibration group
555 if (!InitFit(nybins,1)) {
561 fStatisticMean = 0.0;
563 fNumberFitSuccess = 0;
565 // Init fCountDet and fCount
566 InitfCountDetAndfCount(1);
567 // Beginning of the loop
568 for (Int_t idect = fDect1; idect < fDect2; idect++) {
569 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi.......
570 UpdatefCountDetAndfCount(idect,1);
571 ReconstructFitRowMinRowMax(idect,1);
573 TH1D *projph = (TH1D *) ph->ProjectionX("projph",idect+1,idect+1,(Option_t *) "e");
574 projph->SetDirectory(0);
575 // Number of entries for this calibration group
576 Double_t nentries = 0;
577 for (Int_t k = 0; k < nbins; k++) {
578 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
579 nentries += ph->GetBinEntries(binnb);
584 //printf("The number of entries for the group %d is %f\n",idect,nentries);
585 // This detector has not enough statistics or was off
586 if (nentries <= fMinEntries) {
587 //printf("Not enough statistic!\n");
588 NotEnoughStatisticPH(idect);
589 if (fDebugLevel != 1) {
594 // Statistics of the histos fitted
596 fStatisticMean += nentries;
597 // Calcul of "real" coef
598 CalculVdriftCoefMean();
603 case 0: FitLagrangePoly((TH1 *) projph); break;
604 case 1: FitPente((TH1 *) projph); break;
605 case 2: FitPH((TH1 *) projph,(Int_t) (idect - fDect1)); break;
606 default: return kFALSE;
608 // Fill the tree if end of a detector or only the pointer to the branch!!!
609 FillInfosFitPH(idect);
611 if (fDebugLevel != 1) {
616 if (fNumberFit > 0) {
617 AliInfo(Form("There are %d with at least one entries. %d fits have been proceeded (sucessfully or not...). There is a mean statistic of: %d over these fitted histograms and %d successfulled fits",fNumberEnt, fNumberFit, (Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
618 fStatisticMean = fStatisticMean / fNumberFit;
621 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
623 delete fDebugStreamer;
624 fDebugStreamer = 0x0;
627 //____________Functions fit Online PH2d________________________________________
628 Bool_t AliTRDCalibraFit::AnalysePH(AliTRDCalibraVector *calvect)
631 // Reconstruct the average pulse height from the vectorPH for each
633 // Reconstruct a drift velocity
634 // A first calibration of T0 is also made using the same method (slope method)
637 // Set the calibration mode
638 const char *name = calvect->GetNamePH();
639 SetModeCalibration(name,1);
641 // Number of Xbins (detectors or groups of pads)
642 if (!InitFit((432*calvect->GetDetCha0(1)+108*calvect->GetDetCha2(1)),1)) {
648 fStatisticMean = 0.0;
650 fNumberFitSuccess = 0;
652 // Init fCountDet and fCount
653 InitfCountDetAndfCount(1);
654 // Beginning of the loop
655 for (Int_t idect = fDect1; idect < fDect2; idect++) {
656 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...........
657 UpdatefCountDetAndfCount(idect,1);
658 ReconstructFitRowMinRowMax(idect,1);
662 Bool_t something = kTRUE;
663 if(!calvect->GetPHEntries(fCountDet)) something = kFALSE;
667 projph = CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPHTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) name)));
668 projph->SetDirectory(0);
670 //printf("The number of entries for the group %d is %d\n",idect,fEntriesCurrent);
671 // This detector has not enough statistics or was off
672 if (fEntriesCurrent <= fMinEntries) {
673 //printf("Not enough stat!\n");
674 NotEnoughStatisticPH(idect);
675 if (fDebugLevel != 1) {
676 if(projph) delete projph;
680 // Statistic of the histos fitted
682 fStatisticMean += fEntriesCurrent;
683 // Calcul of "real" coef
684 CalculVdriftCoefMean();
689 case 0: FitLagrangePoly((TH1 *) projph); break;
690 case 1: FitPente((TH1 *) projph); break;
691 case 2: FitPH((TH1 *) projph,(Int_t) (idect - fDect1)); break;
692 default: return kFALSE;
694 // Fill the tree if end of a detector or only the pointer to the branch!!!
695 FillInfosFitPH(idect);
697 if (fDebugLevel != 1) {
703 if (fNumberFit > 0) {
704 AliInfo(Form("There are %d with at least one entries. %d fits have been proceeded (sucessfully or not...). There is a mean statistic of: %d over these fitted histograms and %d successfulled fits",fNumberEnt, fNumberFit, (Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
705 fStatisticMean = fStatisticMean / fNumberFit;
708 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
710 delete fDebugStreamer;
711 fDebugStreamer = 0x0;
714 //____________Functions fit Online PRF2d_______________________________________
715 Bool_t AliTRDCalibraFit::AnalysePRF(TProfile2D *prf)
718 // Take the 1D profiles (pad response function), projections of the 2D PRF
719 // on the Xaxis, for each calibration group
720 // Fit with a gaussian to reconstruct the sigma of the pad response function
723 // Set the calibration mode
724 const char *name = prf->GetTitle();
725 SetModeCalibration(name,2);
727 // Number of Ybins (detectors or groups of pads)
728 Int_t nybins = prf->GetNbinsY();// calibration groups
729 Int_t nbins = prf->GetNbinsX();// bins
730 Int_t nbg = GetNumberOfGroupsPRF((const char *)prf->GetTitle());
731 if((nbg > 0) || (nbg == -1)) return kFALSE;
732 if (!InitFit(nybins,2)) {
738 fStatisticMean = 0.0;
740 fNumberFitSuccess = 0;
742 // Init fCountDet and fCount
743 InitfCountDetAndfCount(2);
744 // Beginning of the loop
745 for (Int_t idect = fDect1; idect < fDect2; idect++) {
746 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi......
747 UpdatefCountDetAndfCount(idect,2);
748 ReconstructFitRowMinRowMax(idect,2);
750 TH1D *projprf = (TH1D *) prf->ProjectionX("projprf",idect+1,idect+1,(Option_t *) "e");
751 projprf->SetDirectory(0);
752 // Number of entries for this calibration group
753 Double_t nentries = 0;
754 for (Int_t k = 0; k < nbins; k++) {
755 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
756 nentries += prf->GetBinEntries(binnb);
758 if(nentries > 0) fNumberEnt++;
759 // This detector has not enough statistics or was off
760 if (nentries <= fMinEntries) {
761 NotEnoughStatisticPRF(idect);
762 if (fDebugLevel != 1) {
767 // Statistics of the histos fitted
769 fStatisticMean += nentries;
770 // Calcul of "real" coef
775 case 0: FitPRF((TH1 *) projprf); break;
776 case 1: RmsPRF((TH1 *) projprf); break;
777 default: return kFALSE;
779 // Fill the tree if end of a detector or only the pointer to the branch!!!
780 FillInfosFitPRF(idect);
782 if (fDebugLevel != 1) {
787 if (fNumberFit > 0) {
788 AliInfo(Form("There are %d with at least one entries.",fNumberEnt));
789 AliInfo(Form("%d fits have been proceeded (sucessfully or not...).",fNumberFit));
790 AliInfo(Form("There is a mean statistic of: %d over these fitted histograms and %d successfulled fits"
791 ,(Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
792 fStatisticMean = fStatisticMean / fNumberFit;
795 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
797 delete fDebugStreamer;
798 fDebugStreamer = 0x0;
801 //____________Functions fit Online PRF2d_______________________________________
802 Bool_t AliTRDCalibraFit::AnalysePRFMarianFit(TProfile2D *prf)
805 // Take the 1D profiles (pad response function), projections of the 2D PRF
806 // on the Xaxis, for each calibration group
807 // Fit with a gaussian to reconstruct the sigma of the pad response function
810 // Set the calibration mode
811 const char *name = prf->GetTitle();
812 SetModeCalibration(name,2);
814 // Number of Ybins (detectors or groups of pads)
815 TAxis *xprf = prf->GetXaxis();
816 TAxis *yprf = prf->GetYaxis();
817 Int_t nybins = yprf->GetNbins();// calibration groups
818 Int_t nbins = xprf->GetNbins();// bins
819 Float_t lowedge = (Float_t) xprf->GetBinLowEdge(1);//lowedge in bins
820 Float_t upedge = (Float_t) xprf->GetBinUpEdge(nbins);//upedge in bins
821 Int_t nbg = GetNumberOfGroupsPRF((const char *)name);
822 if(nbg == -1) return kFALSE;
823 if(nbg > 0) fMethod = 1;
825 if (!InitFit(nybins,2)) {
831 fStatisticMean = 0.0;
833 fNumberFitSuccess = 0;
835 // Init fCountDet and fCount
836 InitfCountDetAndfCount(2);
837 // Beginning of the loop
838 for (Int_t idect = fDect1; idect < fDect2; idect++) {
839 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi.......
840 UpdatefCountDetAndfCount(idect,2);
841 ReconstructFitRowMinRowMax(idect,2);
842 // Build the array of entries and sum
843 TArrayD arraye = TArrayD(nbins);
844 TArrayD arraym = TArrayD(nbins);
845 TArrayD arrayme = TArrayD(nbins);
846 Double_t nentries = 0;
847 //printf("nbins %d\n",nbins);
848 for (Int_t k = 0; k < nbins; k++) {
849 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
850 Double_t entries = (Double_t)prf->GetBinEntries(binnb);
851 Double_t mean = (Double_t)prf->GetBinContent(binnb);
852 Double_t error = (Double_t)prf->GetBinError(binnb);
853 //printf("for %d we have %f\n",k,entries);
855 arraye.AddAt(entries,k);
856 arraym.AddAt(mean,k);
857 arrayme.AddAt(error,k);
859 if(nentries > 0) fNumberEnt++;
860 //printf("The number of entries for the group %d is %f\n",idect,nentries);
861 // This detector has not enough statistics or was off
862 if (nentries <= fMinEntries) {
863 NotEnoughStatisticPRF(idect);
866 // Statistics of the histos fitted
868 fStatisticMean += nentries;
869 // Calcul of "real" coef
874 case 0: FitPRFGausMI( arraye.GetArray(), arraym.GetArray(), arrayme.GetArray(), nbins, lowedge, upedge); break;
875 case 1: FitTnpRange( arraye.GetArray(), arraym.GetArray(), arrayme.GetArray(), nbg, nbins); break;
876 default: return kFALSE;
878 // Fill the tree if end of a detector or only the pointer to the branch!!!
879 FillInfosFitPRF(idect);
882 if (fNumberFit > 0) {
883 AliInfo(Form("There are %d with at least one entries.",fNumberEnt));
884 AliInfo(Form("%d fits have been proceeded (sucessfully or not...).",fNumberFit));
885 AliInfo(Form("There is a mean statistic of: %d over these fitted histograms and %d successfulled fits"
886 ,(Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
887 fStatisticMean = fStatisticMean / fNumberFit;
890 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
892 delete fDebugStreamer;
893 fDebugStreamer = 0x0;
896 //____________Functions fit Online PRF2d_______________________________________
897 Bool_t AliTRDCalibraFit::AnalysePRF(AliTRDCalibraVector *calvect)
900 // Reconstruct the 1D histo (pad response function) from the vectorPRD for
901 // each calibration group
902 // Fit with a gaussian to reconstruct the sigma of the pad response function
905 // Set the calibra mode
906 const char *name = calvect->GetNamePRF();
907 SetModeCalibration(name,2);
908 //printf("test0 %s\n",name);
910 // Number of Xbins (detectors or groups of pads)
911 if (!InitFit((432*calvect->GetDetCha0(2)+108*calvect->GetDetCha2(2)),2)) {
916 ///printf("test2\n");
919 fStatisticMean = 0.0;
921 fNumberFitSuccess = 0;
923 // Init fCountDet and fCount
924 InitfCountDetAndfCount(2);
925 // Beginning of the loop
926 for (Int_t idect = fDect1; idect < fDect2; idect++) {
927 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi........
928 UpdatefCountDetAndfCount(idect,2);
929 ReconstructFitRowMinRowMax(idect,2);
933 Bool_t something = kTRUE;
934 if(!calvect->GetPRFEntries(fCountDet)) something = kFALSE;
938 projprf = CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) name)));
939 projprf->SetDirectory(0);
941 // This detector has not enough statistics or was off
942 if (fEntriesCurrent <= fMinEntries) {
943 NotEnoughStatisticPRF(idect);
944 if (fDebugLevel != 1) {
945 if(projprf) delete projprf;
949 // Statistic of the histos fitted
951 fStatisticMean += fEntriesCurrent;
952 // Calcul of "real" coef
957 case 1: FitPRF((TH1 *) projprf); break;
958 case 2: RmsPRF((TH1 *) projprf); break;
959 default: return kFALSE;
961 // Fill the tree if end of a detector or only the pointer to the branch!!!
962 FillInfosFitPRF(idect);
964 if (fDebugLevel != 1) {
969 if (fNumberFit > 0) {
970 AliInfo(Form("There are %d with at least one entries. %d fits have been proceeded (sucessfully or not...). There is a mean statistic of: %d over these fitted histograms and %d successfulled fits",fNumberEnt, fNumberFit, (Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
973 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
975 delete fDebugStreamer;
976 fDebugStreamer = 0x0;
979 //____________Functions fit Online PRF2d_______________________________________
980 Bool_t AliTRDCalibraFit::AnalysePRFMarianFit(AliTRDCalibraVector *calvect)
983 // Reconstruct the 1D histo (pad response function) from the vectorPRD for
984 // each calibration group
985 // Fit with a gaussian to reconstruct the sigma of the pad response function
988 // Set the calibra mode
989 const char *name = calvect->GetNamePRF();
990 SetModeCalibration(name,2);
991 //printf("test0 %s\n",name);
992 Int_t nbg = GetNumberOfGroupsPRF((const char *)name);
993 printf("test1 %d\n",nbg);
994 if(nbg == -1) return kFALSE;
995 if(nbg > 0) fMethod = 1;
997 // Number of Xbins (detectors or groups of pads)
998 if (!InitFit((432*calvect->GetDetCha0(2)+108*calvect->GetDetCha2(2)),2)) {
1002 if (!InitFitPRF()) {
1003 //printf("test3\n");
1006 fStatisticMean = 0.0;
1008 fNumberFitSuccess = 0;
1012 Double_t *arrayx = 0;
1013 Double_t *arraye = 0;
1014 Double_t *arraym = 0;
1015 Double_t *arrayme = 0;
1016 Float_t lowedge = 0.0;
1017 Float_t upedge = 0.0;
1018 // Init fCountDet and fCount
1019 InitfCountDetAndfCount(2);
1020 // Beginning of the loop
1021 for (Int_t idect = fDect1; idect < fDect2; idect++) {
1022 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi......
1023 UpdatefCountDetAndfCount(idect,2);
1024 ReconstructFitRowMinRowMax(idect,2);
1026 TGraphErrors *projprftree = 0x0;
1027 fEntriesCurrent = 0;
1028 Bool_t something = kTRUE;
1029 if(!calvect->GetPRFEntries(fCountDet)) something = kFALSE;
1031 TString name("PRF");
1033 projprftree = calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) name);
1034 nbins = projprftree->GetN();
1035 arrayx = (Double_t *)projprftree->GetX();
1036 arraye = (Double_t *)projprftree->GetEX();
1037 arraym = (Double_t *)projprftree->GetY();
1038 arrayme = (Double_t *)projprftree->GetEY();
1039 Float_t step = arrayx[1]-arrayx[0];
1040 lowedge = arrayx[0] - step/2.0;
1041 upedge = arrayx[(nbins-1)] + step/2.0;
1042 //printf("nbins est %d\n",nbins);
1043 for(Int_t k = 0; k < nbins; k++){
1044 fEntriesCurrent += (Int_t)arraye[k];
1045 //printf("for %d we have %f, %f\n",k,arraye[k],((projprftree->GetEX())[k]));
1046 if(arraye[k]>0.0) arrayme[k] = TMath::Sqrt(TMath::Abs(arrayme[k]-arraym[k]*arraym[k])/arraye[k]);
1048 if(fEntriesCurrent > 0) fNumberEnt++;
1050 //printf("The number of entries for the group %d is %d\n",idect,fEntriesCurrent);
1051 // This detector has not enough statistics or was off
1052 if (fEntriesCurrent <= fMinEntries) {
1053 NotEnoughStatisticPRF(idect);
1054 if(projprftree) delete projprftree;
1057 // Statistic of the histos fitted
1059 fStatisticMean += fEntriesCurrent;
1060 // Calcul of "real" coef
1061 CalculPRFCoefMean();
1065 case 0: FitPRFGausMI(arraye,arraym,arrayme,nbins,lowedge,upedge); break;
1066 case 1: FitTnpRange(arraye,arraym,arrayme,nbg,nbins); break;
1067 default: return kFALSE;
1069 // Fill the tree if end of a detector or only the pointer to the branch!!!
1070 FillInfosFitPRF(idect);
1072 if (fDebugLevel != 1) {
1077 if (fNumberFit > 0) {
1078 AliInfo(Form("There are %d with at least one entries. %d fits have been proceeded (sucessfully or not...). There is a mean statistic of: %d over these fitted histograms and %d successfulled fits",fNumberEnt, fNumberFit, (Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
1081 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
1083 delete fDebugStreamer;
1084 fDebugStreamer = 0x0;
1087 //____________Functions fit Online CH2d________________________________________
1088 Bool_t AliTRDCalibraFit::AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli)
1091 // The linear method
1094 fStatisticMean = 0.0;
1096 fNumberFitSuccess = 0;
1098 if(!InitFitLinearFitter()) return kFALSE;
1101 for(Int_t idet = 0; idet < 540; idet++){
1104 //printf("detector number %d\n",idet);
1109 fEntriesCurrent = 0;
1111 Bool_t here = calivdli->GetParam(idet,¶m);
1112 Bool_t heree = calivdli->GetError(idet,&error);
1113 //printf("here %d and heree %d\n",here, heree);
1115 fEntriesCurrent = (Int_t) error[2];
1118 //printf("Number of entries %d\n",fEntriesCurrent);
1119 // Nothing found or not enough statistic
1120 if((!heree) || (!here) || (fEntriesCurrent <= fMinEntries)) {
1121 NotEnoughStatisticLinearFitter();
1128 fStatisticMean += fEntriesCurrent;
1131 if((-(param[1])) <= 0.0) {
1132 NotEnoughStatisticLinearFitter();
1136 // CalculDatabaseVdriftandTan
1137 CalculVdriftLorentzCoef();
1140 fNumberFitSuccess ++;
1142 // Put the fCurrentCoef
1143 fCurrentCoef[0] = -param[1];
1144 // here the database must be the one of the reconstruction for the lorentz angle....
1145 fCurrentCoef2[0] = (param[0]+fCurrentCoef[1]*fCurrentCoef2[1])/fCurrentCoef[0];
1146 fCurrentCoefE = error[1];
1147 fCurrentCoefE2 = error[0];
1148 if((fCurrentCoef2[0] != 0.0) && (param[0] != 0.0)){
1149 fCurrentCoefE2 = (fCurrentCoefE2/param[0]+fCurrentCoefE/fCurrentCoef[0])*fCurrentCoef2[0];
1153 FillInfosFitLinearFitter();
1158 if (fNumberFit > 0) {
1159 AliInfo(Form("There are %d with at least one entries. %d fits have been proceeded (sucessfully or not...). There is a mean statistic of: %d over these fitted histograms and %d successfulled fits",fNumberEnt, fNumberFit, (Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
1162 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
1164 delete fDebugStreamer;
1165 fDebugStreamer = 0x0;
1169 //____________Functions for seeing if the pad is really okey___________________
1170 //_____________________________________________________________________________
1171 Int_t AliTRDCalibraFit::GetNumberOfGroupsPRF(const char* nametitle)
1174 // Get numberofgroupsprf
1178 const Char_t *pattern0 = "Ngp0";
1179 const Char_t *pattern1 = "Ngp1";
1180 const Char_t *pattern2 = "Ngp2";
1181 const Char_t *pattern3 = "Ngp3";
1182 const Char_t *pattern4 = "Ngp4";
1183 const Char_t *pattern5 = "Ngp5";
1184 const Char_t *pattern6 = "Ngp6";
1187 if (strstr(nametitle,pattern0)) {
1190 if (strstr(nametitle,pattern1)) {
1193 if (strstr(nametitle,pattern2)) {
1196 if (strstr(nametitle,pattern3)) {
1199 if (strstr(nametitle,pattern4)) {
1202 if (strstr(nametitle,pattern5)) {
1205 if (strstr(nametitle,pattern6)){
1212 //_____________________________________________________________________________
1213 Bool_t AliTRDCalibraFit::SetModeCalibration(const char *name, Int_t i)
1216 // Set fNz[i] and fNrphi[i] of the AliTRDCalibraFit::Instance()
1217 // corresponding to the given name
1220 if(!SetNzFromTObject(name,i)) return kFALSE;
1221 if(!SetNrphiFromTObject(name,i)) return kFALSE;
1226 //_____________________________________________________________________________
1227 Bool_t AliTRDCalibraFit::SetNrphiFromTObject(const char *name, Int_t i)
1230 // Set fNrphi[i] of the AliTRDCalibraFit::Instance()
1231 // corresponding to the given TObject
1235 const Char_t *patternrphi0 = "Nrphi0";
1236 const Char_t *patternrphi1 = "Nrphi1";
1237 const Char_t *patternrphi2 = "Nrphi2";
1238 const Char_t *patternrphi3 = "Nrphi3";
1239 const Char_t *patternrphi4 = "Nrphi4";
1240 const Char_t *patternrphi5 = "Nrphi5";
1241 const Char_t *patternrphi6 = "Nrphi6";
1244 if (strstr(name,patternrphi0)) {
1245 fCalibraMode->SetNrphi(i ,0);
1248 if (strstr(name,patternrphi1)) {
1249 fCalibraMode->SetNrphi(i, 1);
1252 if (strstr(name,patternrphi2)) {
1253 fCalibraMode->SetNrphi(i, 2);
1256 if (strstr(name,patternrphi3)) {
1257 fCalibraMode->SetNrphi(i, 3);
1260 if (strstr(name,patternrphi4)) {
1261 fCalibraMode->SetNrphi(i, 4);
1264 if (strstr(name,patternrphi5)) {
1265 fCalibraMode->SetNrphi(i, 5);
1268 if (strstr(name,patternrphi6)) {
1269 fCalibraMode->SetNrphi(i, 6);
1273 fCalibraMode->SetNrphi(i ,0);
1277 //_____________________________________________________________________________
1278 Bool_t AliTRDCalibraFit::SetNzFromTObject(const char *name, Int_t i)
1281 // Set fNz[i] of the AliTRDCalibraFit::Instance()
1282 // corresponding to the given TObject
1286 const Char_t *patternz0 = "Nz0";
1287 const Char_t *patternz1 = "Nz1";
1288 const Char_t *patternz2 = "Nz2";
1289 const Char_t *patternz3 = "Nz3";
1290 const Char_t *patternz4 = "Nz4";
1292 if (strstr(name,patternz0)) {
1293 fCalibraMode->SetNz(i, 0);
1296 if (strstr(name,patternz1)) {
1297 fCalibraMode->SetNz(i ,1);
1300 if (strstr(name,patternz2)) {
1301 fCalibraMode->SetNz(i ,2);
1304 if (strstr(name,patternz3)) {
1305 fCalibraMode->SetNz(i ,3);
1308 if (strstr(name,patternz4)) {
1309 fCalibraMode->SetNz(i ,4);
1313 fCalibraMode->SetNz(i ,0);
1316 //_____________________________________________________________________________
1317 AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectVdrift(TObjArray *vectorFit, Bool_t perdetector)
1320 // It creates the AliTRDCalDet object from the AliTRDFitInfo
1321 // It takes the mean value of the coefficients per detector
1322 // This object has to be written in the database
1325 // Create the DetObject
1326 AliTRDCalDet *object = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
1328 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1329 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1330 Int_t detector = -1;
1331 Float_t value = 0.0;
1333 for (Int_t k = 0; k < loop; k++) {
1334 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1337 mean = TMath::Abs(((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0]);
1341 Int_t rowMax = fGeo->GetRowMax(GetPlane(detector),GetChamber(detector),GetSector(detector));
1342 Int_t colMax = fGeo->GetColMax(GetPlane(detector));
1343 for (Int_t row = 0; row < rowMax; row++) {
1344 for (Int_t col = 0; col < colMax; col++) {
1345 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1346 mean += TMath::Abs(value);
1350 if(count > 0) mean = mean/count;
1352 object->SetValue(detector,mean);
1357 //_____________________________________________________________________________
1358 AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectGain(TObjArray *vectorFit, Double_t scaleFitFactor, Bool_t perdetector)
1361 // It creates the AliTRDCalDet object from the AliTRDFitInfo
1362 // It takes the mean value of the coefficients per detector
1363 // This object has to be written in the database
1366 // Create the DetObject
1367 AliTRDCalDet *object = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
1370 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1371 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1372 Int_t detector = -1;
1373 Float_t value = 0.0;
1375 for (Int_t k = 0; k < loop; k++) {
1376 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1379 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
1380 if(value > 0) value = value*scaleFitFactor;
1381 mean = TMath::Abs(value);
1385 Int_t rowMax = fGeo->GetRowMax(GetPlane(detector),GetChamber(detector),GetSector(detector));
1386 Int_t colMax = fGeo->GetColMax(GetPlane(detector));
1387 for (Int_t row = 0; row < rowMax; row++) {
1388 for (Int_t col = 0; col < colMax; col++) {
1389 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1390 if(value > 0) value = value*scaleFitFactor;
1391 mean += TMath::Abs(value);
1395 if(count > 0) mean = mean/count;
1397 object->SetValue(detector,mean);
1402 //_____________________________________________________________________________
1403 AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectT0(TObjArray *vectorFit, Bool_t perdetector)
1406 // It creates the AliTRDCalDet object from the AliTRDFitInfo2
1407 // It takes the min value of the coefficients per detector
1408 // This object has to be written in the database
1411 // Create the DetObject
1412 AliTRDCalDet *object = new AliTRDCalDet("ChamberT0","T0 (detector value)");
1414 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1415 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1416 Int_t detector = -1;
1417 Float_t value = 0.0;
1419 for (Int_t k = 0; k < loop; k++) {
1420 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1421 Float_t min = 100.0;
1423 min = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
1426 Int_t rowMax = fGeo->GetRowMax(GetPlane(detector),GetChamber(detector),GetSector(detector));
1427 Int_t colMax = fGeo->GetColMax(GetPlane(detector));
1428 for (Int_t row = 0; row < rowMax; row++) {
1429 for (Int_t col = 0; col < colMax; col++) {
1430 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1431 if(min > value) min = value;
1435 object->SetValue(detector,min);
1441 //_____________________________________________________________________________
1442 AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectLorentzAngle(TObjArray *vectorFit)
1445 // It creates the AliTRDCalDet object from the AliTRDFitInfo2
1446 // It takes the min value of the coefficients per detector
1447 // This object has to be written in the database
1450 // Create the DetObject
1451 AliTRDCalDet *object = new AliTRDCalDet("tan(lorentzangle)","tan(lorentzangle) (detector value)");
1454 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1455 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1456 Int_t detector = -1;
1457 Float_t value = 0.0;
1459 for (Int_t k = 0; k < loop; k++) {
1460 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1462 Int_t rowMax = fGeo->GetRowMax(GetPlane(detector),GetChamber(detector),GetSector(detector));
1463 Int_t colMax = fGeo->GetColMax(GetPlane(detector));
1464 Float_t min = 100.0;
1465 for (Int_t row = 0; row < rowMax; row++) {
1466 for (Int_t col = 0; col < colMax; col++) {
1467 value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1468 mean += -TMath::Abs(value);
1472 if(count > 0) mean = mean/count;
1474 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
1475 object->SetValue(detector,-TMath::Abs(value));
1481 //_____________________________________________________________________________
1482 TObject *AliTRDCalibraFit::CreatePadObjectGain(TObjArray *vectorFit, Double_t scaleFitFactor, AliTRDCalDet *detobject)
1485 // It Creates the AliTRDCalPad object from AliTRDFitInfo
1486 // You need first to create the object for the detectors,
1487 // where the mean value is put.
1488 // This object has to be written in the database
1491 // Create the DetObject
1492 AliTRDCalPad *object = new AliTRDCalPad("GainFactor","GainFactor (local variations)");
1495 for(Int_t k = 0; k < 540; k++){
1496 AliTRDCalROC *calROC = object->GetCalROC(k);
1497 Int_t nchannels = calROC->GetNchannels();
1498 for(Int_t ch = 0; ch < nchannels; ch++){
1499 calROC->SetValue(ch,1.0);
1505 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1506 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1507 Int_t detector = -1;
1508 Float_t value = 0.0;
1510 for (Int_t k = 0; k < loop; k++) {
1511 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1512 AliTRDCalROC *calROC = object->GetCalROC(detector);
1513 Float_t mean = detobject->GetValue(detector);
1514 if(mean == 0) continue;
1515 Int_t rowMax = calROC->GetNrows();
1516 Int_t colMax = calROC->GetNcols();
1517 for (Int_t row = 0; row < rowMax; row++) {
1518 for (Int_t col = 0; col < colMax; col++) {
1519 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1520 if(value > 0) value = value*scaleFitFactor;
1521 calROC->SetValue(col,row,TMath::Abs(value)/mean);
1529 //_____________________________________________________________________________
1530 TObject *AliTRDCalibraFit::CreatePadObjectVdrift(TObjArray *vectorFit, AliTRDCalDet *detobject)
1533 // It Creates the AliTRDCalPad object from AliTRDFitInfo
1534 // You need first to create the object for the detectors,
1535 // where the mean value is put.
1536 // This object has to be written in the database
1539 // Create the DetObject
1540 AliTRDCalPad *object = new AliTRDCalPad("LocalVdrift","TRD drift velocities (local variations)");
1543 for(Int_t k = 0; k < 540; k++){
1544 AliTRDCalROC *calROC = object->GetCalROC(k);
1545 Int_t nchannels = calROC->GetNchannels();
1546 for(Int_t ch = 0; ch < nchannels; ch++){
1547 calROC->SetValue(ch,1.0);
1553 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1554 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1555 Int_t detector = -1;
1556 Float_t value = 0.0;
1558 for (Int_t k = 0; k < loop; k++) {
1559 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1560 AliTRDCalROC *calROC = object->GetCalROC(detector);
1561 Float_t mean = detobject->GetValue(detector);
1562 if(mean == 0) continue;
1563 Int_t rowMax = calROC->GetNrows();
1564 Int_t colMax = calROC->GetNcols();
1565 for (Int_t row = 0; row < rowMax; row++) {
1566 for (Int_t col = 0; col < colMax; col++) {
1567 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1568 calROC->SetValue(col,row,TMath::Abs(value)/mean);
1576 //_____________________________________________________________________________
1577 TObject *AliTRDCalibraFit::CreatePadObjectT0(TObjArray *vectorFit, AliTRDCalDet *detobject)
1580 // It Creates the AliTRDCalPad object from AliTRDFitInfo2
1581 // You need first to create the object for the detectors,
1582 // where the mean value is put.
1583 // This object has to be written in the database
1586 // Create the DetObject
1587 AliTRDCalPad *object = new AliTRDCalPad("LocalT0","T0 (local variations)");
1590 for(Int_t k = 0; k < 540; k++){
1591 AliTRDCalROC *calROC = object->GetCalROC(k);
1592 Int_t nchannels = calROC->GetNchannels();
1593 for(Int_t ch = 0; ch < nchannels; ch++){
1594 calROC->SetValue(ch,0.0);
1600 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1601 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1602 Int_t detector = -1;
1603 Float_t value = 0.0;
1605 for (Int_t k = 0; k < loop; k++) {
1606 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1607 AliTRDCalROC *calROC = object->GetCalROC(detector);
1608 Float_t min = detobject->GetValue(detector);
1609 Int_t rowMax = calROC->GetNrows();
1610 Int_t colMax = calROC->GetNcols();
1611 for (Int_t row = 0; row < rowMax; row++) {
1612 for (Int_t col = 0; col < colMax; col++) {
1613 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1614 calROC->SetValue(col,row,value-min);
1622 //_____________________________________________________________________________
1623 TObject *AliTRDCalibraFit::CreatePadObjectPRF(TObjArray *vectorFit)
1626 // It Creates the AliTRDCalPad object from AliTRDFitInfo
1627 // This object has to be written in the database
1630 // Create the DetObject
1631 AliTRDCalPad *object = new AliTRDCalPad("PRFWidth","PRFWidth");
1633 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1634 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1635 Int_t detector = -1;
1636 Float_t value = 0.0;
1638 for (Int_t k = 0; k < loop; k++) {
1639 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1640 AliTRDCalROC *calROC = object->GetCalROC(detector);
1641 Int_t rowMax = calROC->GetNrows();
1642 Int_t colMax = calROC->GetNcols();
1643 for (Int_t row = 0; row < rowMax; row++) {
1644 for (Int_t col = 0; col < colMax; col++) {
1645 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1646 calROC->SetValue(col,row,TMath::Abs(value));
1654 //_____________________________________________________________________________
1655 AliTRDCalDet *AliTRDCalibraFit::MakeOutliersStatDet(TObjArray *vectorFit, const char *name, Double_t &mean)
1658 // It Creates the AliTRDCalDet object from AliTRDFitInfo
1659 // 0 successful fit 1 not successful fit
1660 // mean is the mean value over the successful fit
1661 // do not use it for t0: no meaning
1664 // Create the CalObject
1665 AliTRDCalDet *object = new AliTRDCalDet(name,name);
1669 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1671 AliInfo("The Vector Fit is not complete! We initialise all outliers");
1672 for(Int_t k = 0; k < 540; k++){
1673 object->SetValue(k,1.0);
1676 Int_t detector = -1;
1677 Float_t value = 0.0;
1679 for (Int_t k = 0; k < loop; k++) {
1680 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1681 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
1682 if(value <= 0) object->SetValue(detector,1.0);
1684 object->SetValue(detector,0.0);
1689 if(count > 0) mean /= count;
1692 //_____________________________________________________________________________
1693 TObject *AliTRDCalibraFit::MakeOutliersStatPad(TObjArray *vectorFit, const char *name, Double_t &mean)
1696 // It Creates the AliTRDCalPad object from AliTRDFitInfo
1697 // 0 not successful fit 1 successful fit
1698 // mean mean value over the successful fit
1701 // Create the CalObject
1702 AliTRDCalPad *object = new AliTRDCalPad(name,name);
1706 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1708 AliInfo("The Vector Fit is not complete! We initialise all outliers");
1709 for(Int_t k = 0; k < 540; k++){
1710 AliTRDCalROC *calROC = object->GetCalROC(k);
1711 Int_t nchannels = calROC->GetNchannels();
1712 for(Int_t ch = 0; ch < nchannels; ch++){
1713 calROC->SetValue(ch,1.0);
1717 Int_t detector = -1;
1718 Float_t value = 0.0;
1720 for (Int_t k = 0; k < loop; k++) {
1721 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1722 AliTRDCalROC *calROC = object->GetCalROC(detector);
1723 Int_t nchannels = calROC->GetNchannels();
1724 for (Int_t ch = 0; ch < nchannels; ch++) {
1725 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[ch];
1726 if(value <= 0) calROC->SetValue(ch,1.0);
1728 calROC->SetValue(ch,0.0);
1734 if(count > 0) mean /= count;
1737 //_____________________________________________________________________________
1738 void AliTRDCalibraFit::SetPeriodeFitPH(Int_t periodeFitPH)
1741 // Set FitPH if 1 then each detector will be fitted
1744 if (periodeFitPH > 0) {
1745 fFitPHPeriode = periodeFitPH;
1748 AliInfo("periodeFitPH must be higher than 0!");
1752 //_____________________________________________________________________________
1753 void AliTRDCalibraFit::SetBeginFitCharge(Float_t beginFitCharge)
1756 // The fit of the deposited charge distribution begins at
1757 // histo->Mean()/beginFitCharge
1758 // You can here set beginFitCharge
1761 if (beginFitCharge > 0) {
1762 fBeginFitCharge = beginFitCharge;
1765 AliInfo("beginFitCharge must be strict positif!");
1770 //_____________________________________________________________________________
1771 void AliTRDCalibraFit::SetT0Shift0(Float_t t0Shift)
1774 // The t0 calculated with the maximum positif slope is shift from t0Shift0
1775 // You can here set t0Shift0
1779 fT0Shift0 = t0Shift;
1782 AliInfo("t0Shift0 must be strict positif!");
1787 //_____________________________________________________________________________
1788 void AliTRDCalibraFit::SetT0Shift1(Float_t t0Shift)
1791 // The t0 calculated with the maximum of the amplification region is shift from t0Shift1
1792 // You can here set t0Shift1
1796 fT0Shift1 = t0Shift;
1799 AliInfo("t0Shift must be strict positif!");
1804 //_____________________________________________________________________________
1805 void AliTRDCalibraFit::SetRangeFitPRF(Float_t rangeFitPRF)
1808 // The fit of the PRF is from -rangeFitPRF to rangeFitPRF
1809 // You can here set rangeFitPRF
1812 if ((rangeFitPRF > 0) &&
1813 (rangeFitPRF <= 1.5)) {
1814 fRangeFitPRF = rangeFitPRF;
1817 AliInfo("rangeFitPRF must be between 0 and 1.0");
1822 //_____________________________________________________________________________
1823 void AliTRDCalibraFit::SetMinEntries(Int_t minEntries)
1826 // Minimum entries for fitting
1829 if (minEntries > 0) {
1830 fMinEntries = minEntries;
1833 AliInfo("fMinEntries must be >= 0.");
1838 //_____________________________________________________________________________
1839 void AliTRDCalibraFit::SetRebin(Short_t rebin)
1842 // Rebin with rebin time less bins the Ch histo
1843 // You can set here rebin that should divide the number of bins of CH histo
1848 AliInfo("You have to be sure that fRebin divides fNumberBinCharge used!");
1851 AliInfo("You have to choose a positiv value!");
1855 //_____________________________________________________________________________
1856 Bool_t AliTRDCalibraFit::FillVectorFit()
1859 // For the Fit functions fill the vector Fit
1862 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
1865 if (GetChamber(fCountDet) == 2) {
1872 //printf("For the detector %d , ntotal %d and fCoefCH[0] %f\n",countdet,ntotal,fCoefCH[0]);
1873 Float_t *coef = new Float_t[ntotal];
1874 for (Int_t i = 0; i < ntotal; i++) {
1875 coef[i] = fCurrentCoefDetector[i];
1878 Int_t detector = fCountDet;
1880 fitInfo->SetCoef(coef);
1881 fitInfo->SetDetector(detector);
1882 fVectorFit.Add((TObject *) fitInfo);
1887 //_____________________________________________________________________________
1888 Bool_t AliTRDCalibraFit::FillVectorFit2()
1891 // For the Fit functions fill the vector Fit
1894 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
1897 if (GetChamber(fCountDet) == 2) {
1904 //printf("For the detector %d , ntotal %d and fCoefCH[0] %f\n",countdet,ntotal,fCoefCH[0]);
1905 Float_t *coef = new Float_t[ntotal];
1906 for (Int_t i = 0; i < ntotal; i++) {
1907 coef[i] = fCurrentCoefDetector2[i];
1910 Int_t detector = fCountDet;
1912 fitInfo->SetCoef(coef);
1913 fitInfo->SetDetector(detector);
1914 fVectorFit2.Add((TObject *) fitInfo);
1919 //____________Functions for initialising the AliTRDCalibraFit in the code_________
1920 Bool_t AliTRDCalibraFit::InitFit(Int_t nbins, Int_t i)
1923 // Init the number of expected bins and fDect1[i] fDect2[i]
1926 gStyle->SetPalette(1);
1927 gStyle->SetOptStat(1111);
1928 gStyle->SetPadBorderMode(0);
1929 gStyle->SetCanvasColor(10);
1930 gStyle->SetPadLeftMargin(0.13);
1931 gStyle->SetPadRightMargin(0.01);
1933 // Mode groups of pads: the total number of bins!
1934 CalculNumberOfBinsExpected(i);
1936 // Quick verification that we have the good pad calibration mode!
1937 if (fNumberOfBinsExpected != nbins) {
1938 AliInfo("It doesn't correspond to the mode of pad group calibration!");
1942 // Security for fDebug 3 and 4
1943 if ((fDebugLevel >= 3) &&
1947 AliInfo("This detector doesn't exit!");
1951 // Determine fDet1 and fDet2 and set the fNfragZ and fNfragRphi for debug 3 and 4
1952 CalculDect1Dect2(i);
1957 //____________Functions for initialising the AliTRDCalibraFit in the code_________
1958 Bool_t AliTRDCalibraFit::InitFitCH()
1961 // Init the fVectorFitCH for normalisation
1962 // Init the histo for debugging
1967 fScaleFitFactor = 0.0;
1968 fCurrentCoefDetector = new Float_t[2304];
1969 for (Int_t k = 0; k < 2304; k++) {
1970 fCurrentCoefDetector[k] = 0.0;
1972 fVectorFit.SetName("gainfactorscoefficients");
1974 // fDebug == 0 nothing
1975 // fDebug == 1 and fFitVoir no histo
1976 if (fDebugLevel == 1) {
1977 if(!CheckFitVoir()) return kFALSE;
1979 //Get the CalDet object
1981 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1983 AliInfo("Could not get calibDB");
1986 if(fCalDet) delete fCalDet;
1987 fCalDet = new AliTRDCalDet(*(cal->GetGainFactorDet()));
1990 Float_t devalue = 1.0;
1991 if(fCalDet) delete fCalDet;
1992 fCalDet = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
1993 for(Int_t k = 0; k < 540; k++){
1994 fCalDet->SetValue(k,devalue);
2000 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2001 Bool_t AliTRDCalibraFit::InitFitPH()
2004 // Init the arrays of results
2005 // Init the histos for debugging
2009 fVectorFit.SetName("driftvelocitycoefficients");
2010 fVectorFit2.SetName("t0coefficients");
2012 fCurrentCoefDetector = new Float_t[2304];
2013 for (Int_t k = 0; k < 2304; k++) {
2014 fCurrentCoefDetector[k] = 0.0;
2017 fCurrentCoefDetector2 = new Float_t[2304];
2018 for (Int_t k = 0; k < 2304; k++) {
2019 fCurrentCoefDetector2[k] = 0.0;
2022 //fDebug == 0 nothing
2023 // fDebug == 1 and fFitVoir no histo
2024 if (fDebugLevel == 1) {
2025 if(!CheckFitVoir()) return kFALSE;
2027 //Get the CalDet object
2029 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2031 AliInfo("Could not get calibDB");
2034 if(fCalDet) delete fCalDet;
2035 if(fCalDet2) delete fCalDet2;
2036 fCalDet = new AliTRDCalDet(*(cal->GetVdriftDet()));
2037 fCalDet2 = new AliTRDCalDet(*(cal->GetT0Det()));
2040 Float_t devalue = 1.5;
2041 Float_t devalue2 = 0.0;
2042 if(fCalDet) delete fCalDet;
2043 if(fCalDet2) delete fCalDet2;
2044 fCalDet = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2045 fCalDet2 = new AliTRDCalDet("ChamberT0","T0 (detector value)");
2046 for(Int_t k = 0; k < 540; k++){
2047 fCalDet->SetValue(k,devalue);
2048 fCalDet2->SetValue(k,devalue2);
2053 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2054 Bool_t AliTRDCalibraFit::InitFitPRF()
2057 // Init the calibration mode (Nz, Nrphi), the histograms for
2058 // debugging the fit methods if fDebug > 0,
2062 fVectorFit.SetName("prfwidthcoefficients");
2064 fCurrentCoefDetector = new Float_t[2304];
2065 for (Int_t k = 0; k < 2304; k++) {
2066 fCurrentCoefDetector[k] = 0.0;
2069 // fDebug == 0 nothing
2070 // fDebug == 1 and fFitVoir no histo
2071 if (fDebugLevel == 1) {
2072 if(!CheckFitVoir()) return kFALSE;
2076 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2077 Bool_t AliTRDCalibraFit::InitFitLinearFitter()
2080 // Init the fCalDet, fVectorFit fCurrentCoefDetector
2085 fCurrentCoefDetector = new Float_t[2304];
2086 fCurrentCoefDetector2 = new Float_t[2304];
2087 for (Int_t k = 0; k < 2304; k++) {
2088 fCurrentCoefDetector[k] = 0.0;
2089 fCurrentCoefDetector2[k] = 0.0;
2092 //printf("test0\n");
2094 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2096 AliInfo("Could not get calibDB");
2100 //Get the CalDet object
2102 if(fCalDet) delete fCalDet;
2103 if(fCalDet2) delete fCalDet2;
2104 fCalDet = new AliTRDCalDet(*(cal->GetVdriftDet()));
2105 //printf("test1\n");
2106 fCalDet2 = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
2107 //printf("test2\n");
2108 for(Int_t k = 0; k < 540; k++){
2109 fCalDet2->SetValue(k,cal->GetOmegaTau(fCalDet->GetValue(k),-fMagneticField));
2111 //printf("test3\n");
2114 Float_t devalue = 1.5;
2115 Float_t devalue2 = cal->GetOmegaTau(1.5,-fMagneticField);
2116 if(fCalDet) delete fCalDet;
2117 if(fCalDet2) delete fCalDet2;
2118 //printf("test1\n");
2119 fCalDet = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2120 fCalDet2 = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
2121 //printf("test2\n");
2122 for(Int_t k = 0; k < 540; k++){
2123 fCalDet->SetValue(k,devalue);
2124 fCalDet2->SetValue(k,devalue2);
2126 //printf("test3\n");
2131 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2132 void AliTRDCalibraFit::InitfCountDetAndfCount(Int_t i)
2135 // Init the current detector where we are fCountDet and the
2136 // next fCount for the functions Fit...
2139 // Loop on the Xbins of ch!!
2140 fCountDet = -1; // Current detector
2141 fCount = 0; // To find the next detector
2144 if (fDebugLevel >= 3) {
2145 // Set countdet to the detector
2146 fCountDet = AliTRDgeometry::GetDetector(fDet[0],fDet[1],fDet[2]);
2147 // Set counter to write at the end of the detector
2149 // Get the right calib objects
2152 if(fDebugLevel == 1) {
2154 fCalibraMode->CalculXBins(fCountDet,i);
2155 while(fCalibraMode->GetXbins(i) <=fFitVoir){
2157 fCalibraMode->CalculXBins(fCountDet,i);
2159 fCount = fCalibraMode->GetXbins(i);
2161 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
2162 fCalibraMode->ModePadCalibration((Int_t) GetChamber(fCountDet),i);
2163 fCalibraMode->ModePadFragmentation((Int_t) GetPlane(fCountDet)
2164 ,(Int_t) GetChamber(fCountDet)
2165 ,(Int_t) GetSector(fCountDet),i);
2168 //_______________________________________________________________________________
2169 void AliTRDCalibraFit::CalculNumberOfBinsExpected(Int_t i)
2172 // Calculate the number of bins expected (calibration groups)
2175 fNumberOfBinsExpected = 0;
2176 fCalibraMode->ModePadCalibration(2,i);
2177 fCalibraMode->ModePadFragmentation(0,2,0,i);
2178 fCalibraMode->SetDetChamb2(i);
2179 if (fDebugLevel > 1) {
2180 AliInfo(Form("For the chamber 2: %d",fCalibraMode->GetDetChamb2(i)));
2182 fNumberOfBinsExpected += 6 * 18 * fCalibraMode->GetDetChamb2(i);
2183 fCalibraMode->ModePadCalibration(0,i);
2184 fCalibraMode->ModePadFragmentation(0,0,0,i);
2185 fCalibraMode->SetDetChamb0(i);
2186 if (fDebugLevel > 1) {
2187 AliInfo(Form("For the other chamber 0: %d",fCalibraMode->GetDetChamb0(i)));
2189 fNumberOfBinsExpected += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
2192 //_______________________________________________________________________________
2193 void AliTRDCalibraFit::CalculDect1Dect2(Int_t i)
2196 // Calculate the range of fits
2201 if (fDebugLevel == 1) {
2205 if ((fDebugLevel == 2) || (fDebugLevel == 0)) {
2207 fDect2 = fNumberOfBinsExpected;
2209 if (fDebugLevel >= 3) {
2210 fCountDet = AliTRDgeometry::GetDetector(fDet[0],fDet[1],fDet[2]);
2211 fCalibraMode->CalculXBins(fCountDet,i);
2212 fDect1 = fCalibraMode->GetXbins(i);
2213 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
2214 fCalibraMode->ModePadCalibration((Int_t) GetChamber(fCountDet),i);
2215 fCalibraMode->ModePadFragmentation((Int_t) GetPlane(fCountDet)
2216 ,(Int_t) GetChamber(fCountDet)
2217 ,(Int_t) GetSector(fCountDet),i);
2218 // Set for the next detector
2219 fDect2 = fDect1 + fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i);
2222 //_______________________________________________________________________________
2223 Bool_t AliTRDCalibraFit::CheckFitVoir()
2226 // Check if fFitVoir is in the range
2229 if (fFitVoir < fNumberOfBinsExpected) {
2230 AliInfo(Form("We will see the fit of the object %d",fFitVoir));
2233 AliInfo("fFitVoir is out of range of the histo!");
2238 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2239 void AliTRDCalibraFit::UpdatefCountDetAndfCount(Int_t idect, Int_t i)
2242 // See if we are in a new detector and update the
2243 // variables fNfragZ and fNfragRphi if yes
2244 // Will never happen for only one detector (3 and 4)
2245 // Doesn't matter for 2
2247 if (fCount == idect) {
2248 // On en est au detector
2250 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
2251 fCalibraMode->ModePadCalibration((Int_t) GetChamber(fCountDet),i);
2252 fCalibraMode->ModePadFragmentation((Int_t) GetPlane(fCountDet)
2253 ,(Int_t) GetChamber(fCountDet)
2254 ,(Int_t) GetSector(fCountDet),i);
2255 // Set for the next detector
2256 fCount += fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i);
2261 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2262 void AliTRDCalibraFit::ReconstructFitRowMinRowMax(Int_t idect, Int_t i)
2265 // Reconstruct the min pad row, max pad row, min pad col and
2266 // max pad col of the calibration group for the Fit functions
2268 if (fDebugLevel != 1) {
2269 fCalibraMode->ReconstructionRowPadGroup((Int_t) (idect-(fCount-(fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i)))),i);
2272 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2273 Bool_t AliTRDCalibraFit::NotEnoughStatisticCH(Int_t idect)
2276 // For the case where there are not enough entries in the histograms
2277 // of the calibration group, the value present in the choosen database
2278 // will be put. A negativ sign enables to know that a fit was not possible.
2281 if (fDebugLevel == 1) {
2282 AliInfo("The element has not enough statistic to be fitted");
2287 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
2288 ,idect-(fCount-(fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))),fCountDet));
2290 // Calcul the coef from the database choosen
2291 CalculChargeCoefMean(kFALSE);
2293 //chamber 2, not chamber 2
2295 if(GetChamber(fCountDet) == 2) factor = 12;
2298 // Fill the fCurrentCoefDetector with negative value to say: not fitted
2299 for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
2300 for (Int_t j = fCalibraMode->GetColMin(0); j < fCalibraMode->GetColMax(0); j++) {
2301 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
2305 //Put default value negative
2306 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
2307 fCurrentCoefE = 0.0;
2316 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2317 Bool_t AliTRDCalibraFit::NotEnoughStatisticPH(Int_t idect)
2320 // For the case where there are not enough entries in the histograms
2321 // of the calibration group, the value present in the choosen database
2322 // will be put. A negativ sign enables to know that a fit was not possible.
2324 if (fDebugLevel == 1) {
2325 AliInfo("The element has not enough statistic to be fitted");
2329 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
2330 ,idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))),fCountDet));
2332 CalculVdriftCoefMean();
2335 //chamber 2 and not chamber 2
2337 if(GetChamber(fCountDet) == 2) factor = 12;
2341 // Fill the fCurrentCoefDetector 2
2342 for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
2343 for (Int_t j = fCalibraMode->GetColMin(1); j < fCalibraMode->GetColMax(1); j++) {
2344 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
2345 fCurrentCoefDetector2[(Int_t)(j*factor+k)] = fCurrentCoef2[1];
2349 // Put the default value
2350 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
2351 fCurrentCoefE = 0.0;
2352 fCurrentCoef2[0] = fCurrentCoef2[1];
2353 fCurrentCoefE2 = 0.0;
2364 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2365 Bool_t AliTRDCalibraFit::NotEnoughStatisticPRF(Int_t idect)
2368 // For the case where there are not enough entries in the histograms
2369 // of the calibration group, the value present in the choosen database
2370 // will be put. A negativ sign enables to know that a fit was not possible.
2373 if (fDebugLevel == 1) {
2374 AliInfo("The element has not enough statistic to be fitted");
2378 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
2379 ,idect-(fCount-(fCalibraMode->GetNfragZ(2)*fCalibraMode->GetNfragRphi(2))),fCountDet));
2381 CalculPRFCoefMean();
2383 // chamber 2 and not chamber 2
2385 if(GetChamber(fCountDet) == 2) factor = 12;
2389 // Fill the fCurrentCoefDetector
2390 for (Int_t k = fCalibraMode->GetRowMin(2); k < fCalibraMode->GetRowMax(2); k++) {
2391 for (Int_t j = fCalibraMode->GetColMin(2); j < fCalibraMode->GetColMax(2); j++) {
2392 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -fCurrentCoef[1];
2396 // Put the default value
2397 fCurrentCoef[0] = -fCurrentCoef[1];
2398 fCurrentCoefE = 0.0;
2406 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2407 Bool_t AliTRDCalibraFit::NotEnoughStatisticLinearFitter()
2410 // For the case where there are not enough entries in the histograms
2411 // of the calibration group, the value present in the choosen database
2412 // will be put. A negativ sign enables to know that a fit was not possible.
2415 // Calcul the coef from the database choosen
2416 CalculVdriftLorentzCoef();
2419 if(GetChamber(fCountDet) == 2) factor = 1728;
2423 // Fill the fCurrentCoefDetector
2424 for (Int_t k = 0; k < factor; k++) {
2425 fCurrentCoefDetector[k] = -TMath::Abs(fCurrentCoef[1]);
2426 // should be negative
2427 fCurrentCoefDetector2[k] = +TMath::Abs(fCurrentCoef2[1]);
2431 //Put default opposite sign
2432 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
2433 fCurrentCoefE = 0.0;
2434 fCurrentCoef2[0] = +TMath::Abs(fCurrentCoef2[1]);
2435 fCurrentCoefE2 = 0.0;
2437 FillFillLinearFitter();
2442 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2443 Bool_t AliTRDCalibraFit::FillInfosFitCH(Int_t idect)
2446 // Fill the coefficients found with the fits or other
2447 // methods from the Fit functions
2450 if (fDebugLevel != 1) {
2453 if(GetChamber(fCountDet) == 2) factor = 12;
2456 for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
2457 for (Int_t j = fCalibraMode->GetColMin(0); j < fCalibraMode->GetColMax(0); j++) {
2458 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
2469 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2470 Bool_t AliTRDCalibraFit::FillInfosFitPH(Int_t idect)
2473 // Fill the coefficients found with the fits or other
2474 // methods from the Fit functions
2477 if (fDebugLevel != 1) {
2480 if(GetChamber(fCountDet) == 2) factor = 12;
2483 for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
2484 for (Int_t j = fCalibraMode->GetColMin(1); j < fCalibraMode->GetColMax(1); j++) {
2485 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
2486 fCurrentCoefDetector2[(Int_t)(j*factor+k)] = fCurrentCoef2[0];
2493 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2494 Bool_t AliTRDCalibraFit::FillInfosFitPRF(Int_t idect)
2497 // Fill the coefficients found with the fits or other
2498 // methods from the Fit functions
2501 if (fDebugLevel != 1) {
2504 if(GetChamber(fCountDet) == 2) factor = 12;
2507 // Pointer to the branch
2508 for (Int_t k = fCalibraMode->GetRowMin(2); k < fCalibraMode->GetRowMax(2); k++) {
2509 for (Int_t j = fCalibraMode->GetColMin(2); j < fCalibraMode->GetColMax(2); j++) {
2510 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
2519 //____________Functions for initialising the AliTRDCalibraFit in the code_________
2520 Bool_t AliTRDCalibraFit::FillInfosFitLinearFitter()
2523 // Fill the coefficients found with the fits or other
2524 // methods from the Fit functions
2528 if(GetChamber(fCountDet) == 2) factor = 1728;
2531 // Pointer to the branch
2532 for (Int_t k = 0; k < factor; k++) {
2533 fCurrentCoefDetector[k] = fCurrentCoef[0];
2534 fCurrentCoefDetector2[k] = fCurrentCoef2[0];
2537 FillFillLinearFitter();
2542 //________________________________________________________________________________
2543 void AliTRDCalibraFit::FillFillCH(Int_t idect)
2546 // DebugStream and fVectorFit
2549 // End of one detector
2550 if ((idect == (fCount-1))) {
2553 for (Int_t k = 0; k < 2304; k++) {
2554 fCurrentCoefDetector[k] = 0.0;
2558 if(fDebugLevel > 1){
2560 if ( !fDebugStreamer ) {
2562 TDirectory *backup = gDirectory;
2563 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
2564 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2567 Int_t detector = fCountDet;
2568 Int_t caligroup = idect;
2569 Short_t rowmin = fCalibraMode->GetRowMin(0);
2570 Short_t rowmax = fCalibraMode->GetRowMax(0);
2571 Short_t colmin = fCalibraMode->GetColMin(0);
2572 Short_t colmax = fCalibraMode->GetColMax(0);
2573 Float_t gf = fCurrentCoef[0];
2574 Float_t gfs = fCurrentCoef[1];
2575 Float_t gfE = fCurrentCoefE;
2577 (*fDebugStreamer) << "FillFillCH" <<
2578 "detector=" << detector <<
2579 "caligroup=" << caligroup <<
2580 "rowmin=" << rowmin <<
2581 "rowmax=" << rowmax <<
2582 "colmin=" << colmin <<
2583 "colmax=" << colmax <<
2591 //________________________________________________________________________________
2592 void AliTRDCalibraFit::FillFillPH(Int_t idect)
2595 // DebugStream and fVectorFit and fVectorFit2
2598 // End of one detector
2599 if ((idect == (fCount-1))) {
2603 for (Int_t k = 0; k < 2304; k++) {
2604 fCurrentCoefDetector[k] = 0.0;
2605 fCurrentCoefDetector2[k] = 0.0;
2609 if(fDebugLevel > 1){
2611 if ( !fDebugStreamer ) {
2613 TDirectory *backup = gDirectory;
2614 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
2615 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2619 Int_t detector = fCountDet;
2620 Int_t caligroup = idect;
2621 Short_t rowmin = fCalibraMode->GetRowMin(1);
2622 Short_t rowmax = fCalibraMode->GetRowMax(1);
2623 Short_t colmin = fCalibraMode->GetColMin(1);
2624 Short_t colmax = fCalibraMode->GetColMax(1);
2625 Float_t vf = fCurrentCoef[0];
2626 Float_t vs = fCurrentCoef[1];
2627 Float_t vfE = fCurrentCoefE;
2628 Float_t t0f = fCurrentCoef2[0];
2629 Float_t t0s = fCurrentCoef2[1];
2630 Float_t t0E = fCurrentCoefE2;
2634 (* fDebugStreamer) << "FillFillPH"<<
2635 "detector="<<detector<<
2636 "caligroup="<<caligroup<<
2651 //________________________________________________________________________________
2652 void AliTRDCalibraFit::FillFillPRF(Int_t idect)
2655 // DebugStream and fVectorFit
2658 // End of one detector
2659 if ((idect == (fCount-1))) {
2662 for (Int_t k = 0; k < 2304; k++) {
2663 fCurrentCoefDetector[k] = 0.0;
2668 if(fDebugLevel > 1){
2670 if ( !fDebugStreamer ) {
2672 TDirectory *backup = gDirectory;
2673 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
2674 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2677 Int_t detector = fCountDet;
2678 Int_t plane = GetPlane(fCountDet);
2679 Int_t caligroup = idect;
2680 Short_t rowmin = fCalibraMode->GetRowMin(2);
2681 Short_t rowmax = fCalibraMode->GetRowMax(2);
2682 Short_t colmin = fCalibraMode->GetColMin(2);
2683 Short_t colmax = fCalibraMode->GetColMax(2);
2684 Float_t widf = fCurrentCoef[0];
2685 Float_t wids = fCurrentCoef[1];
2686 Float_t widfE = fCurrentCoefE;
2688 (* fDebugStreamer) << "FillFillPRF"<<
2689 "detector="<<detector<<
2691 "caligroup="<<caligroup<<
2703 //________________________________________________________________________________
2704 void AliTRDCalibraFit::FillFillLinearFitter()
2707 // DebugStream and fVectorFit
2710 // End of one detector
2716 for (Int_t k = 0; k < 2304; k++) {
2717 fCurrentCoefDetector[k] = 0.0;
2718 fCurrentCoefDetector2[k] = 0.0;
2722 if(fDebugLevel > 1){
2724 if ( !fDebugStreamer ) {
2726 TDirectory *backup = gDirectory;
2727 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
2728 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2731 //Debug: comparaison of the different methods (okey for first time but not for iterative procedure)
2732 AliTRDpadPlane *padplane = fGeo->GetPadPlane(GetPlane(fCountDet),GetChamber(fCountDet));
2733 Float_t rowmd = (padplane->GetRow0()+padplane->GetRowEnd())/2.;
2734 Float_t r = AliTRDgeometry::GetTime0(GetPlane(fCountDet));
2735 Float_t tiltangle = padplane->GetTiltingAngle();
2736 Int_t detector = fCountDet;
2737 Int_t chamber = GetChamber(fCountDet);
2738 Int_t plane = GetChamber(fCountDet);
2739 Float_t vf = fCurrentCoef[0];
2740 Float_t vs = fCurrentCoef[1];
2741 Float_t vfE = fCurrentCoefE;
2742 Float_t lorentzangler = fCurrentCoef2[0];
2743 Float_t elorentzangler = fCurrentCoefE2;
2744 Float_t lorentzangles = fCurrentCoef2[1];
2746 (* fDebugStreamer) << "FillFillLinearFitter"<<
2747 "detector="<<detector<<
2748 "chamber="<<chamber<<
2752 "tiltangle="<<tiltangle<<
2756 "lorentzangler="<<lorentzangler<<
2757 "Elorentzangler="<<elorentzangler<<
2758 "lorentzangles="<<lorentzangles<<
2764 //____________Calcul Coef Mean_________________________________________________
2766 //_____________________________________________________________________________
2767 Bool_t AliTRDCalibraFit::CalculT0CoefMean()
2770 // For the detector Dect calcul the mean time 0
2771 // for the calibration group idect from the choosen database
2774 fCurrentCoef2[1] = 0.0;
2775 if(fDebugLevel != 1){
2776 if((fCalibraMode->GetNz(1) > 0) ||
2777 (fCalibraMode->GetNrphi(1) > 0)) {
2778 for (Int_t row = fCalibraMode->GetRowMin(1); row < fCalibraMode->GetRowMax(1); row++) {
2779 for (Int_t col = fCalibraMode->GetColMin(1); col < fCalibraMode->GetColMax(1); col++) {
2780 fCurrentCoef2[1] += (Float_t) (fCalROC2->GetValue(col,row)+fCalDet2->GetValue(fCountDet));
2783 fCurrentCoef2[1] = fCurrentCoef2[1] / ((fCalibraMode->GetColMax(1)-fCalibraMode->GetColMin(1))*(fCalibraMode->GetRowMax(1)-fCalibraMode->GetRowMin(1)));
2787 fCurrentCoef2[1] = fCalDet2->GetValue(fCountDet);
2790 for(Int_t row = 0; row < fGeo->GetRowMax(GetPlane(fCountDet),GetChamber(fCountDet),GetSector(fCountDet)); row++){
2791 for(Int_t col = 0; col < fGeo->GetColMax(GetPlane(fCountDet)); col++){
2792 fCurrentCoef2[1] += (Float_t) (fCalROC2->GetValue(col,row)+fCalDet2->GetValue(fCountDet));
2795 fCurrentCoef2[1] = fCurrentCoef2[1] / ((fGeo->GetRowMax(GetPlane(fCountDet),GetChamber(fCountDet),GetSector(fCountDet)))*(fGeo->GetColMax(GetPlane(fCountDet))));
2802 //_____________________________________________________________________________
2803 Bool_t AliTRDCalibraFit::CalculChargeCoefMean(Bool_t vrai)
2806 // For the detector Dect calcul the mean gain factor
2807 // for the calibration group idect from the choosen database
2810 fCurrentCoef[1] = 0.0;
2811 if(fDebugLevel != 1){
2812 if ((fCalibraMode->GetNz(0) > 0) ||
2813 (fCalibraMode->GetNrphi(0) > 0)) {
2814 for (Int_t row = fCalibraMode->GetRowMin(0); row < fCalibraMode->GetRowMax(0); row++) {
2815 for (Int_t col = fCalibraMode->GetColMin(0); col < fCalibraMode->GetColMax(0); col++) {
2816 fCurrentCoef[1] += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
2817 if (vrai) fScaleFitFactor += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
2820 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(0)-fCalibraMode->GetColMin(0))*(fCalibraMode->GetRowMax(0)-fCalibraMode->GetRowMin(0)));
2824 fCurrentCoef[1] = (Float_t) fCalDet->GetValue(fCountDet);
2825 if (vrai) fScaleFitFactor += ((Float_t) fCalDet->GetValue(fCountDet))*(fCalibraMode->GetColMax(0)-fCalibraMode->GetColMin(0))*(fCalibraMode->GetRowMax(0)-fCalibraMode->GetRowMin(0));
2830 //_____________________________________________________________________________
2831 Bool_t AliTRDCalibraFit::CalculPRFCoefMean()
2834 // For the detector Dect calcul the mean sigma of pad response
2835 // function for the calibration group idect from the choosen database
2838 fCurrentCoef[1] = 0.0;
2839 if(fDebugLevel != 1){
2840 for (Int_t row = fCalibraMode->GetRowMin(2); row < fCalibraMode->GetRowMax(2); row++) {
2841 for (Int_t col = fCalibraMode->GetColMin(2); col < fCalibraMode->GetColMax(2); col++) {
2842 fCurrentCoef[1] += (Float_t) fCalROC->GetValue(col,row);
2845 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(2)-fCalibraMode->GetColMin(2))*(fCalibraMode->GetRowMax(2)-fCalibraMode->GetRowMin(2)));
2849 //_____________________________________________________________________________
2850 Bool_t AliTRDCalibraFit::CalculVdriftCoefMean()
2853 // For the detector dect calcul the mean drift velocity for the
2854 // calibration group idect from the choosen database
2857 fCurrentCoef[1] = 0.0;
2858 if(fDebugLevel != 1){
2859 if ((fCalibraMode->GetNz(1) > 0) ||
2860 (fCalibraMode->GetNrphi(1) > 0)) {
2861 for (Int_t row = fCalibraMode->GetRowMin(1); row < fCalibraMode->GetRowMax(1); row++) {
2862 for (Int_t col = fCalibraMode->GetColMin(1); col < fCalibraMode->GetColMax(1); col++) {
2863 fCurrentCoef[1] += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
2866 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(1)-fCalibraMode->GetColMin(1))*(fCalibraMode->GetRowMax(1)-fCalibraMode->GetRowMin(1)));
2870 fCurrentCoef[1] = (Float_t) fCalDet->GetValue(fCountDet);
2875 //_____________________________________________________________________________
2876 Bool_t AliTRDCalibraFit::CalculVdriftLorentzCoef()
2879 // For the detector fCountDet, mean drift velocity and tan lorentzangle
2882 fCurrentCoef[1] = fCalDet->GetValue(fCountDet);
2883 fCurrentCoef2[1] = fCalDet2->GetValue(fCountDet);
2887 //_____________________________________________________________________________
2888 Float_t AliTRDCalibraFit::GetPRFDefault(Int_t plane) const
2891 // Default width of the PRF if there is no database as reference
2896 //case 0: return 0.515;
2897 //case 1: return 0.502;
2898 //case 2: return 0.491;
2899 //case 3: return 0.481;
2900 //case 4: return 0.471;
2901 //case 5: return 0.463;
2902 //default: return 0.0;
2905 case 0: return 0.538429;
2906 case 1: return 0.524302;
2907 case 2: return 0.511591;
2908 case 3: return 0.500140;
2909 case 4: return 0.489821;
2910 case 5: return 0.480524;
2911 default: return 0.0;
2914 //________________________________________________________________________________
2915 void AliTRDCalibraFit::SetCalROC(Int_t i)
2918 // Set the calib object for fCountDet
2921 Float_t value = 0.0;
2923 //Get the CalDet object
2925 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2927 AliInfo("Could not get calibDB");
2933 if(fCalROC) delete fCalROC;
2934 fCalROC = new AliTRDCalROC(*(cal->GetGainFactorROC(fCountDet)));
2937 if(fCalROC) delete fCalROC;
2938 if(fCalROC2) delete fCalROC2;
2939 fCalROC = new AliTRDCalROC(*(cal->GetVdriftROC(fCountDet)));
2940 fCalROC2 = new AliTRDCalROC(*(cal->GetT0ROC(fCountDet)));
2943 if(fCalROC) delete fCalROC;
2944 fCalROC = new AliTRDCalROC(*(cal->GetPRFROC(fCountDet))); break;
2952 if(fCalROC) delete fCalROC;
2953 fCalROC = new AliTRDCalROC(GetPlane(fCountDet),GetChamber(fCountDet));
2954 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
2955 fCalROC->SetValue(k,1.0);
2959 if(fCalROC) delete fCalROC;
2960 if(fCalROC2) delete fCalROC2;
2961 fCalROC = new AliTRDCalROC(GetPlane(fCountDet),GetChamber(fCountDet));
2962 fCalROC2 = new AliTRDCalROC(GetPlane(fCountDet),GetChamber(fCountDet));
2963 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
2964 fCalROC->SetValue(k,1.0);
2965 fCalROC2->SetValue(k,0.0);
2969 if(fCalROC) delete fCalROC;
2970 value = GetPRFDefault(GetPlane(fCountDet));
2971 fCalROC = new AliTRDCalROC(GetPlane(fCountDet),GetChamber(fCountDet));
2972 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
2973 fCalROC->SetValue(k,value);
2981 //____________Fit Methods______________________________________________________
2983 //_____________________________________________________________________________
2984 void AliTRDCalibraFit::FitPente(TH1* projPH)
2987 // Slope methode for the drift velocity
2991 const Float_t kDrWidth = AliTRDgeometry::DrThick();
2998 fCurrentCoefE = 0.0;
2999 fCurrentCoefE2 = 0.0;
3000 fCurrentCoef[0] = 0.0;
3001 fCurrentCoef2[0] = 0.0;
3002 TLine *line = new TLine();
3005 TAxis *xpph = projPH->GetXaxis();
3006 Int_t nbins = xpph->GetNbins();
3007 Double_t lowedge = xpph->GetBinLowEdge(1);
3008 Double_t upedge = xpph->GetBinUpEdge(xpph->GetNbins());
3009 Double_t widbins = (upedge - lowedge) / nbins;
3010 Double_t limit = upedge + 0.5 * widbins;
3013 // Beginning of the signal
3014 TH1D *pentea = new TH1D("pentea","pentea",projPH->GetNbinsX(),0,(Float_t) limit);
3015 for (Int_t k = 1; k < projPH->GetNbinsX(); k++) {
3016 pentea->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
3018 binmax = (Int_t) pentea->GetMaximumBin();
3021 AliInfo("Put the binmax from 1 to 2 to enable the fit");
3023 if (binmax >= nbins) {
3026 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
3028 pentea->Fit("pol2","0MR","",TMath::Max(pentea->GetBinCenter(binmax-1),0.0),pentea->GetBinCenter(binmax+1));
3029 Float_t l3P1am = pentea->GetFunction("pol2")->GetParameter(1);
3030 Float_t l3P2am = pentea->GetFunction("pol2")->GetParameter(2);
3031 Float_t l3P1amE = pentea->GetFunction("pol2")->GetParError(1);
3032 Float_t l3P2amE = pentea->GetFunction("pol2")->GetParError(2);
3034 fPhd[0] = -(l3P1am / (2 * l3P2am));
3037 if((l3P1am != 0.0) && (l3P2am != 0.0)){
3038 fCurrentCoefE2 = (l3P1amE/l3P1am + l3P2amE/l3P2am)*fPhd[0];
3041 // Amplification region
3044 for (Int_t kbin = 1; kbin < projPH->GetNbinsX(); kbin ++) {
3045 if (((projPH->GetBinContent(kbin+1) - projPH->GetBinContent(kbin)) <= 0.0) && (ju == 0) && (kbin > (fPhd[0]/widbins))) {
3052 AliInfo("Put the binmax from 1 to 2 to enable the fit");
3054 if (binmax >= nbins) {
3057 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
3059 projPH->Fit("pol2","0MR","",TMath::Max(projPH->GetBinCenter(binmax-1),0.0),projPH->GetBinCenter(binmax+1));
3060 Float_t l3P1amf = projPH->GetFunction("pol2")->GetParameter(1);
3061 Float_t l3P2amf = projPH->GetFunction("pol2")->GetParameter(2);
3062 Float_t l3P1amfE = projPH->GetFunction("pol2")->GetParError(1);
3063 Float_t l3P2amfE = projPH->GetFunction("pol2")->GetParError(2);
3065 fPhd[1] = -(l3P1amf / (2 * l3P2amf));
3067 if((l3P1amf != 0.0) && (l3P2amf != 0.0)){
3068 fCurrentCoefE = (l3P1amfE/l3P1amf + l3P2amfE/l3P2amf)*fPhd[1];
3071 fCurrentCoefE2 = fCurrentCoefE;
3074 TH1D *pente = new TH1D("pente","pente",projPH->GetNbinsX(),0,(Float_t) limit);
3075 for (Int_t k = TMath::Min(binmax+4,projPH->GetNbinsX()); k < projPH->GetNbinsX(); k++) {
3076 pente->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
3079 if(pente->GetEntries() > 0) binmin = (Int_t) pente->GetMinimumBin();
3082 AliInfo("Put the binmax from 1 to 2 to enable the fit");
3084 if (binmin >= nbins) {
3087 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
3092 ,TMath::Max(pente->GetBinCenter(binmin-1), 0.0)
3093 ,TMath::Min(pente->GetBinCenter(binmin+1),(Double_t) limit));
3094 Float_t l3P1dr = pente->GetFunction("pol2")->GetParameter(1);
3095 Float_t l3P2dr = pente->GetFunction("pol2")->GetParameter(2);
3096 Float_t l3P1drE = pente->GetFunction("pol2")->GetParError(1);
3097 Float_t l3P2drE = pente->GetFunction("pol2")->GetParError(2);
3099 fPhd[2] = -(l3P1dr / (2 * l3P2dr));
3101 if((l3P1dr != 0.0) && (l3P2dr != 0.0)){
3102 fCurrentCoefE += (l3P1drE/l3P1dr + l3P2drE/l3P2dr)*fPhd[2];
3104 Float_t fPhdt0 = 0.0;
3105 Float_t t0Shift = 0.0;
3108 t0Shift = fT0Shift1;
3112 t0Shift = fT0Shift0;
3115 if ((fPhd[2] > fPhd[0]) &&
3116 (fPhd[2] > fPhd[1]) &&
3117 (fPhd[1] > fPhd[0]) &&
3119 fCurrentCoef[0] = (kDrWidth) / (fPhd[2]-fPhd[1]);
3120 fNumberFitSuccess++;
3122 if (fPhdt0 >= 0.0) {
3123 fCurrentCoef2[0] = (fPhdt0 - t0Shift) / widbins;
3124 if (fCurrentCoef2[0] < -1.0) {
3125 fCurrentCoef2[0] = fCurrentCoef2[1];
3129 fCurrentCoef2[0] = fCurrentCoef2[1];
3134 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3135 fCurrentCoef2[0] = fCurrentCoef2[1];
3138 if (fDebugLevel == 1) {
3139 TCanvas *cpentei = new TCanvas("cpentei","cpentei",50,50,600,800);
3142 line->SetLineColor(2);
3143 line->DrawLine(fPhd[0],0,fPhd[0],projPH->GetMaximum());
3144 line->DrawLine(fPhd[1],0,fPhd[1],projPH->GetMaximum());
3145 line->DrawLine(fPhd[2],0,fPhd[2],projPH->GetMaximum());
3146 AliInfo(Form("fPhd[0] (beginning of the signal): %f" ,(Float_t) fPhd[0]));
3147 AliInfo(Form("fPhd[1] (end of the amplification region): %f" ,(Float_t) fPhd[1]));
3148 AliInfo(Form("fPhd[2] (end of the drift region): %f" ,(Float_t) fPhd[2]));
3149 AliInfo(Form("fVriftCoef[1] (with only the drift region(default)): %f",(Float_t) fCurrentCoef[0]));
3150 TCanvas *cpentei2 = new TCanvas("cpentei2","cpentei2",50,50,600,800);
3153 TCanvas *cpentei3 = new TCanvas("cpentei3","cpentei3",50,50,600,800);
3162 //_____________________________________________________________________________
3163 void AliTRDCalibraFit::FitLagrangePoly(TH1* projPH)
3166 // Slope methode but with polynomes de Lagrange
3170 const Float_t kDrWidth = AliTRDgeometry::DrThick();
3173 Double_t *x = new Double_t[5];
3174 Double_t *y = new Double_t[5];
3189 fCurrentCoefE = 0.0;
3190 fCurrentCoefE2 = 1.0;
3191 fCurrentCoef[0] = 0.0;
3192 fCurrentCoef2[0] = 0.0;
3193 TLine *line = new TLine();
3194 TF1 * polynome = 0x0;
3195 TF1 * polynomea = 0x0;
3196 TF1 * polynomeb = 0x0;
3200 TAxis *xpph = projPH->GetXaxis();
3201 Int_t nbins = xpph->GetNbins();
3202 Double_t lowedge = xpph->GetBinLowEdge(1);
3203 Double_t upedge = xpph->GetBinUpEdge(xpph->GetNbins());
3204 Double_t widbins = (upedge - lowedge) / nbins;
3205 Double_t limit = upedge + 0.5 * widbins;
3210 // Beginning of the signal
3211 TH1D *pentea = new TH1D("pentea","pentea",projPH->GetNbinsX(),0,(Float_t) limit);
3212 for (Int_t k = 1; k < projPH->GetNbinsX(); k++) {
3213 pentea->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
3216 binmax = (Int_t) pentea->GetMaximumBin();
3218 Double_t minnn = 0.0;
3219 Double_t maxxx = 0.0;
3221 Int_t kase = nbins-binmax;
3229 minnn = pentea->GetBinCenter(binmax-2);
3230 maxxx = pentea->GetBinCenter(binmax);
3231 x[0] = pentea->GetBinCenter(binmax-2);
3232 x[1] = pentea->GetBinCenter(binmax-1);
3233 x[2] = pentea->GetBinCenter(binmax);
3234 y[0] = pentea->GetBinContent(binmax-2);
3235 y[1] = pentea->GetBinContent(binmax-1);
3236 y[2] = pentea->GetBinContent(binmax);
3237 c = CalculPolynomeLagrange2(x,y);
3238 AliInfo("At the limit for beginning!");
3241 minnn = pentea->GetBinCenter(binmax-2);
3242 maxxx = pentea->GetBinCenter(binmax+1);
3243 x[0] = pentea->GetBinCenter(binmax-2);
3244 x[1] = pentea->GetBinCenter(binmax-1);
3245 x[2] = pentea->GetBinCenter(binmax);
3246 x[3] = pentea->GetBinCenter(binmax+1);
3247 y[0] = pentea->GetBinContent(binmax-2);
3248 y[1] = pentea->GetBinContent(binmax-1);
3249 y[2] = pentea->GetBinContent(binmax);
3250 y[3] = pentea->GetBinContent(binmax+1);
3251 c = CalculPolynomeLagrange3(x,y);
3259 minnn = pentea->GetBinCenter(binmax);
3260 maxxx = pentea->GetBinCenter(binmax+2);
3261 x[0] = pentea->GetBinCenter(binmax);
3262 x[1] = pentea->GetBinCenter(binmax+1);
3263 x[2] = pentea->GetBinCenter(binmax+2);
3264 y[0] = pentea->GetBinContent(binmax);
3265 y[1] = pentea->GetBinContent(binmax+1);
3266 y[2] = pentea->GetBinContent(binmax+2);
3267 c = CalculPolynomeLagrange2(x,y);
3270 minnn = pentea->GetBinCenter(binmax-1);
3271 maxxx = pentea->GetBinCenter(binmax+2);
3272 x[0] = pentea->GetBinCenter(binmax-1);
3273 x[1] = pentea->GetBinCenter(binmax);
3274 x[2] = pentea->GetBinCenter(binmax+1);
3275 x[3] = pentea->GetBinCenter(binmax+2);
3276 y[0] = pentea->GetBinContent(binmax-1);
3277 y[1] = pentea->GetBinContent(binmax);
3278 y[2] = pentea->GetBinContent(binmax+1);
3279 y[3] = pentea->GetBinContent(binmax+2);
3280 c = CalculPolynomeLagrange3(x,y);
3283 minnn = pentea->GetBinCenter(binmax-2);
3284 maxxx = pentea->GetBinCenter(binmax+2);
3285 x[0] = pentea->GetBinCenter(binmax-2);
3286 x[1] = pentea->GetBinCenter(binmax-1);
3287 x[2] = pentea->GetBinCenter(binmax);
3288 x[3] = pentea->GetBinCenter(binmax+1);
3289 x[4] = pentea->GetBinCenter(binmax+2);
3290 y[0] = pentea->GetBinContent(binmax-2);
3291 y[1] = pentea->GetBinContent(binmax-1);
3292 y[2] = pentea->GetBinContent(binmax);
3293 y[3] = pentea->GetBinContent(binmax+1);
3294 y[4] = pentea->GetBinContent(binmax+2);
3295 c = CalculPolynomeLagrange4(x,y);
3303 polynomeb = new TF1("polb","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",minnn,maxxx);
3304 polynomeb->SetParameters(c[0],c[1],c[2],c[3],c[4]);
3306 Double_t step = (maxxx-minnn)/10000;
3308 Double_t maxvalue = 0.0;
3309 Double_t placemaximum = minnn;
3310 for(Int_t o = 0; o < 10000; o++){
3311 if(o == 0) maxvalue = polynomeb->Eval(l);
3312 if(maxvalue < (polynomeb->Eval(l))){
3313 maxvalue = polynomeb->Eval(l);
3318 fPhd[0] = placemaximum;
3321 // Amplification region
3324 for (Int_t kbin = 1; kbin < projPH->GetNbinsX(); kbin ++) {
3325 if (((projPH->GetBinContent(kbin+1) - projPH->GetBinContent(kbin)) <= 0.0) && (ju == 0) && (kbin > (fPhd[0]/widbins))) {
3331 Double_t minn = 0.0;
3332 Double_t maxx = 0.0;
3344 Int_t kase1 = nbins - binmax;
3346 //Determination of minn and maxx
3347 //case binmax = nbins
3352 minn = projPH->GetBinCenter(binmax-2);
3353 maxx = projPH->GetBinCenter(binmax);
3354 x[0] = projPH->GetBinCenter(binmax-2);
3355 x[1] = projPH->GetBinCenter(binmax-1);
3356 x[2] = projPH->GetBinCenter(binmax);
3357 y[0] = projPH->GetBinContent(binmax-2);
3358 y[1] = projPH->GetBinContent(binmax-1);
3359 y[2] = projPH->GetBinContent(binmax);
3360 c = CalculPolynomeLagrange2(x,y);
3361 //AliInfo("At the limit for the drift!");
3364 minn = projPH->GetBinCenter(binmax-2);
3365 maxx = projPH->GetBinCenter(binmax+1);
3366 x[0] = projPH->GetBinCenter(binmax-2);
3367 x[1] = projPH->GetBinCenter(binmax-1);
3368 x[2] = projPH->GetBinCenter(binmax);
3369 x[3] = projPH->GetBinCenter(binmax+1);
3370 y[0] = projPH->GetBinContent(binmax-2);
3371 y[1] = projPH->GetBinContent(binmax-1);
3372 y[2] = projPH->GetBinContent(binmax);
3373 y[3] = projPH->GetBinContent(binmax+1);
3374 c = CalculPolynomeLagrange3(x,y);
3383 minn = projPH->GetBinCenter(binmax);
3384 maxx = projPH->GetBinCenter(binmax+2);
3385 x[0] = projPH->GetBinCenter(binmax);
3386 x[1] = projPH->GetBinCenter(binmax+1);
3387 x[2] = projPH->GetBinCenter(binmax+2);
3388 y[0] = projPH->GetBinContent(binmax);
3389 y[1] = projPH->GetBinContent(binmax+1);
3390 y[2] = projPH->GetBinContent(binmax+2);
3391 c = CalculPolynomeLagrange2(x,y);
3394 minn = projPH->GetBinCenter(binmax-1);
3395 maxx = projPH->GetBinCenter(binmax+2);
3396 x[0] = projPH->GetBinCenter(binmax-1);
3397 x[1] = projPH->GetBinCenter(binmax);
3398 x[2] = projPH->GetBinCenter(binmax+1);
3399 x[3] = projPH->GetBinCenter(binmax+2);
3400 y[0] = projPH->GetBinContent(binmax-1);
3401 y[1] = projPH->GetBinContent(binmax);
3402 y[2] = projPH->GetBinContent(binmax+1);
3403 y[3] = projPH->GetBinContent(binmax+2);
3404 c = CalculPolynomeLagrange3(x,y);
3407 minn = projPH->GetBinCenter(binmax-2);
3408 maxx = projPH->GetBinCenter(binmax+2);
3409 x[0] = projPH->GetBinCenter(binmax-2);
3410 x[1] = projPH->GetBinCenter(binmax-1);
3411 x[2] = projPH->GetBinCenter(binmax);
3412 x[3] = projPH->GetBinCenter(binmax+1);
3413 x[4] = projPH->GetBinCenter(binmax+2);
3414 y[0] = projPH->GetBinContent(binmax-2);
3415 y[1] = projPH->GetBinContent(binmax-1);
3416 y[2] = projPH->GetBinContent(binmax);
3417 y[3] = projPH->GetBinContent(binmax+1);
3418 y[4] = projPH->GetBinContent(binmax+2);
3419 c = CalculPolynomeLagrange4(x,y);
3426 polynomea = new TF1("pola","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",minn,maxx);
3427 polynomea->SetParameters(c[0],c[1],c[2],c[3],c[4]);
3429 Double_t step = (maxx-minn)/1000;
3431 Double_t maxvalue = 0.0;
3432 Double_t placemaximum = minn;
3433 for(Int_t o = 0; o < 1000; o++){
3434 if(o == 0) maxvalue = polynomea->Eval(l);
3435 if(maxvalue < (polynomea->Eval(l))){
3436 maxvalue = polynomea->Eval(l);
3441 fPhd[1] = placemaximum;
3445 TH1D *pente = new TH1D("pente","pente", projPH->GetNbinsX(),0,(Float_t) limit);
3446 for (Int_t k = TMath::Min(binmax+4, projPH->GetNbinsX()); k < projPH->GetNbinsX(); k++) {
3447 pente->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
3450 if(pente->GetEntries() > 0) binmin = (Int_t) pente->GetMinimumBin();
3456 AliInfo("Put the binmax from 1 to 2 to enable the fit");
3460 if((projPH->GetBinContent(binmin)-projPH->GetBinError(binmin)) < (projPH->GetBinContent(binmin+1))) put = kFALSE;
3461 if((projPH->GetBinContent(binmin)+projPH->GetBinError(binmin)) > (projPH->GetBinContent(binmin-1))) put = kFALSE;
3475 Bool_t case1 = kFALSE;
3476 Bool_t case2 = kFALSE;
3477 Bool_t case4 = kFALSE;
3479 //Determination of min and max
3480 //case binmin <= nbins-3
3482 if((binmin <= (nbins-3)) && ((binmin-2) >= TMath::Min(binmax+4, projPH->GetNbinsX()))){
3483 min = pente->GetBinCenter(binmin-2);
3484 max = pente->GetBinCenter(binmin+2);
3485 x[0] = pente->GetBinCenter(binmin-2);
3486 x[1] = pente->GetBinCenter(binmin-1);
3487 x[2] = pente->GetBinCenter(binmin);
3488 x[3] = pente->GetBinCenter(binmin+1);
3489 x[4] = pente->GetBinCenter(binmin+2);
3490 y[0] = pente->GetBinContent(binmin-2);
3491 y[1] = pente->GetBinContent(binmin-1);
3492 y[2] = pente->GetBinContent(binmin);
3493 y[3] = pente->GetBinContent(binmin+1);
3494 y[4] = pente->GetBinContent(binmin+2);
3495 //Calcul the polynome de Lagrange
3496 c = CalculPolynomeLagrange4(x,y);
3498 if((pente->GetBinContent(binmin+2) <= pente->GetBinContent(binmin+1)) &&
3499 (pente->GetBinContent(binmin-2) <= pente->GetBinContent(binmin-1))) put = kFALSE;
3500 if(((binmin+3) <= (nbins-1)) &&
3501 (pente->GetBinContent(binmin+3) <= pente->GetBinContent(binmin+2)) &&
3502 ((binmin-3) >= TMath::Min(binmax+4, projPH->GetNbinsX())) &&
3503 (pente->GetBinContent(binmin-3) <= pente->GetBinContent(binmin-2))) put = kFALSE;
3504 if((pente->GetBinContent(binmin+2) <= pente->GetBinContent(binmin+1)) &&
3505 (pente->GetBinContent(binmin-2) > pente->GetBinContent(binmin-1))) case1 = kTRUE;
3506 if((pente->GetBinContent(binmin+2) > pente->GetBinContent(binmin+1)) &&
3507 (pente->GetBinContent(binmin-2) <= pente->GetBinContent(binmin-1))) case4 = kTRUE;
3509 //case binmin = nbins-2
3511 if(((binmin == (nbins-2)) && ((binmin-2) >= TMath::Min(binmax+4, projPH->GetNbinsX()))) ||
3513 min = pente->GetBinCenter(binmin-2);
3514 max = pente->GetBinCenter(binmin+1);
3515 x[0] = pente->GetBinCenter(binmin-2);
3516 x[1] = pente->GetBinCenter(binmin-1);
3517 x[2] = pente->GetBinCenter(binmin);
3518 x[3] = pente->GetBinCenter(binmin+1);
3519 y[0] = pente->GetBinContent(binmin-2);
3520 y[1] = pente->GetBinContent(binmin-1);
3521 y[2] = pente->GetBinContent(binmin);
3522 y[3] = pente->GetBinContent(binmin+1);
3523 //Calcul the polynome de Lagrange
3524 c = CalculPolynomeLagrange3(x,y);
3525 //richtung +: nothing
3527 if((pente->GetBinContent(binmin-2) <= pente->GetBinContent(binmin-1))) case2 = kTRUE;
3530 if(((binmin <= (nbins-3)) && ((binmin-1) == TMath::Min(binmax+4, projPH->GetNbinsX()))) ||
3532 min = pente->GetBinCenter(binmin-1);
3533 max = pente->GetBinCenter(binmin+2);
3534 x[0] = pente->GetBinCenter(binmin-1);
3535 x[1] = pente->GetBinCenter(binmin);
3536 x[2] = pente->GetBinCenter(binmin+1);
3537 x[3] = pente->GetBinCenter(binmin+2);
3538 y[0] = pente->GetBinContent(binmin-1);
3539 y[1] = pente->GetBinContent(binmin);
3540 y[2] = pente->GetBinContent(binmin+1);
3541 y[3] = pente->GetBinContent(binmin+2);
3542 //Calcul the polynome de Lagrange
3543 c = CalculPolynomeLagrange3(x,y);
3545 if((pente->GetBinContent(binmin+2) <= pente->GetBinContent(binmin+1))) case2 = kTRUE;
3548 if((binmin <= (nbins-3)) && (binmin == TMath::Min(binmax+4, projPH->GetNbinsX()))){
3549 min = pente->GetBinCenter(binmin);
3550 max = pente->GetBinCenter(binmin+2);
3551 x[0] = pente->GetBinCenter(binmin);
3552 x[1] = pente->GetBinCenter(binmin+1);
3553 x[2] = pente->GetBinCenter(binmin+2);
3554 y[0] = pente->GetBinContent(binmin);
3555 y[1] = pente->GetBinContent(binmin+1);
3556 y[2] = pente->GetBinContent(binmin+2);
3557 //Calcul the polynome de Lagrange
3558 c = CalculPolynomeLagrange2(x,y);
3560 if((pente->GetBinContent(binmin+2) <= pente->GetBinContent(binmin+1))) put = kFALSE;
3563 if(((binmin == (nbins-2)) && ((binmin-1) == TMath::Min(binmax+4, projPH->GetNbinsX()))) ||
3565 min = pente->GetBinCenter(binmin-1);
3566 max = pente->GetBinCenter(binmin+1);
3567 x[0] = pente->GetBinCenter(binmin-1);
3568 x[1] = pente->GetBinCenter(binmin);
3569 x[2] = pente->GetBinCenter(binmin+1);
3570 y[0] = pente->GetBinContent(binmin-1);
3571 y[1] = pente->GetBinContent(binmin);
3572 y[2] = pente->GetBinContent(binmin+1);
3573 //Calcul the polynome de Lagrange
3574 c = CalculPolynomeLagrange2(x,y);
3575 //richtung +: nothing
3576 //richtung -: nothing
3578 //case binmin = nbins-1
3580 if((binmin == (nbins-1)) && ((binmin-2) >= TMath::Min(binmax+4, projPH->GetNbinsX()))){
3581 min = pente->GetBinCenter(binmin-2);
3582 max = pente->GetBinCenter(binmin);
3583 x[0] = pente->GetBinCenter(binmin-2);
3584 x[1] = pente->GetBinCenter(binmin-1);
3585 x[2] = pente->GetBinCenter(binmin);
3586 y[0] = pente->GetBinContent(binmin-2);
3587 y[1] = pente->GetBinContent(binmin-1);
3588 y[2] = pente->GetBinContent(binmin);
3589 //Calcul the polynome de Lagrange
3590 c = CalculPolynomeLagrange2(x,y);
3591 //AliInfo("At the limit for the drift!");
3592 //fluctuation too big!
3593 //richtung +: nothing
3595 if((pente->GetBinContent(binmin-2) <= pente->GetBinContent(binmin-1))) put = kFALSE;
3597 if((binmin == (nbins-1)) && ((binmin-2) < TMath::Min(binmax+4, projPH->GetNbinsX()))) {
3599 AliInfo("At the limit for the drift and not usable!");
3603 if((binmin == (nbins-2)) && ((binmin-1) < TMath::Min(binmax+4, projPH->GetNbinsX()))){
3605 AliInfo("For the drift...problem!");
3607 //pass but should not happen
3608 if((binmin <= (nbins-3)) && (binmin < TMath::Min(binmax+4, projPH->GetNbinsX()))){
3610 AliInfo("For the drift...problem!");
3614 polynome = new TF1("pol","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",min,max);
3615 polynome->SetParameters(c[0],c[1],c[2],c[3],c[4]);
3616 //AliInfo(Form("GetMinimum of the function %f",polynome->GetMinimumX()));
3617 Double_t step = (max-min)/1000;
3619 Double_t minvalue = 0.0;
3620 Double_t placeminimum = min;
3621 for(Int_t o = 0; o < 1000; o++){
3622 if(o == 0) minvalue = polynome->Eval(l);
3623 if(minvalue > (polynome->Eval(l))){
3624 minvalue = polynome->Eval(l);
3629 fPhd[2] = placeminimum;
3632 Float_t fPhdt0 = 0.0;
3633 Float_t t0Shift = 0.0;
3636 t0Shift = fT0Shift1;
3640 t0Shift = fT0Shift0;
3643 if ((fPhd[2] > fPhd[0]) &&
3644 (fPhd[2] > fPhd[1]) &&
3645 (fPhd[1] > fPhd[0]) &&
3647 fCurrentCoef[0] = (kDrWidth) / (fPhd[2]-fPhd[1]);
3648 fNumberFitSuccess++;
3649 if (fPhdt0 >= 0.0) {
3650 fCurrentCoef2[0] = (fPhdt0 - t0Shift) / widbins;
3651 if (fCurrentCoef2[0] < -1.0) {
3652 fCurrentCoef2[0] = fCurrentCoef2[1];
3656 fCurrentCoef2[0] = fCurrentCoef2[1];
3660 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3661 fCurrentCoef2[0] = fCurrentCoef2[1];
3662 //printf("Fit failed!\n");
3665 if (fDebugLevel == 1) {
3666 TCanvas *cpentei = new TCanvas("cpentei","cpentei",50,50,600,800);
3669 line->SetLineColor(2);
3670 line->DrawLine(fPhd[0],0,fPhd[0],projPH->GetMaximum());
3671 line->DrawLine(fPhd[1],0,fPhd[1],projPH->GetMaximum());
3672 line->DrawLine(fPhd[2],0,fPhd[2],projPH->GetMaximum());
3673 AliInfo(Form("fPhd[0] (beginning of the signal): %f" ,(Float_t) fPhd[0]));
3674 AliInfo(Form("fPhd[1] (end of the amplification region): %f" ,(Float_t) fPhd[1]));
3675 AliInfo(Form("fPhd[2] (end of the drift region): %f" ,(Float_t) fPhd[2]));
3676 AliInfo(Form("fVriftCoef[3] (with only the drift region(default)): %f",(Float_t) fCurrentCoef[0]));
3677 TCanvas *cpentei2 = new TCanvas("cpentei2","cpentei2",50,50,600,800);
3680 TCanvas *cpentei3 = new TCanvas("cpentei3","cpentei3",50,50,600,800);
3692 projPH->SetDirectory(0);
3696 //_____________________________________________________________________________
3697 void AliTRDCalibraFit::FitPH(TH1* projPH, Int_t idect)
3700 // Fit methode for the drift velocity
3704 const Float_t kDrWidth = AliTRDgeometry::DrThick();
3707 TAxis *xpph = projPH->GetXaxis();
3708 Double_t upedge = xpph->GetBinUpEdge(xpph->GetNbins());
3710 TF1 *fPH = new TF1("fPH",AliTRDCalibraFit::PH,-0.05,3.2,6);
3711 fPH->SetParameter(0,0.469); // Scaling
3712 fPH->SetParameter(1,0.18); // Start
3713 fPH->SetParameter(2,0.0857325); // AR
3714 fPH->SetParameter(3,1.89); // DR
3715 fPH->SetParameter(4,0.08); // QA/QD
3716 fPH->SetParameter(5,0.0); // Baseline
3718 TLine *line = new TLine();
3720 fCurrentCoef[0] = 0.0;
3721 fCurrentCoef2[0] = 0.0;
3722 fCurrentCoefE = 0.0;
3723 fCurrentCoefE2 = 0.0;
3725 if (idect%fFitPHPeriode == 0) {
3727 AliInfo(Form("The detector %d will be fitted",idect));
3728 fPH->SetParameter(0,(projPH->Integral()-(projPH->GetBinContent(1)*projPH->GetNbinsX())) * 0.00028); // Scaling
3729 fPH->SetParameter(1,fPhd[0] - 0.1); // Start
3730 fPH->SetParameter(2,fPhd[1] - fPhd[0]); // AR
3731 fPH->SetParameter(3,fPhd[2] - fPhd[1]); // DR
3732 fPH->SetParameter(4,0.225); // QA/QD
3733 fPH->SetParameter(5,(Float_t) projPH->GetBinContent(1));
3735 if (fDebugLevel != 1) {
3736 projPH->Fit(fPH,"0M","",0.0,upedge);
3739 TCanvas *cpente = new TCanvas("cpente","cpente",50,50,600,800);
3741 projPH->Fit(fPH,"M+","",0.0,upedge);
3743 line->SetLineColor(4);
3744 line->DrawLine(fPH->GetParameter(1)
3746 ,fPH->GetParameter(1)
3747 ,projPH->GetMaximum());
3748 line->DrawLine(fPH->GetParameter(1)+fPH->GetParameter(2)
3750 ,fPH->GetParameter(1)+fPH->GetParameter(2)
3751 ,projPH->GetMaximum());
3752 line->DrawLine(fPH->GetParameter(1)+fPH->GetParameter(2)+fPH->GetParameter(3)
3754 ,fPH->GetParameter(1)+fPH->GetParameter(2)+fPH->GetParameter(3)
3755 ,projPH->GetMaximum());
3758 if (fPH->GetParameter(3) != 0) {
3759 fNumberFitSuccess++;
3760 fCurrentCoef[0] = kDrWidth / (fPH->GetParameter(3));
3761 fCurrentCoefE = (fPH->GetParError(3)/fPH->GetParameter(3))*fCurrentCoef[0];
3762 fCurrentCoef2[0] = fPH->GetParameter(1);
3763 fCurrentCoefE2 = fPH->GetParError(1);
3766 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3767 fCurrentCoef2[0] = fCurrentCoef2[1];
3773 // Put the default value
3774 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3775 fCurrentCoef2[0] = fCurrentCoef2[1];
3778 if (fDebugLevel != 1) {
3783 //_____________________________________________________________________________
3784 Bool_t AliTRDCalibraFit::FitPRFGausMI(Double_t *arraye, Double_t *arraym, Double_t *arrayme, Int_t nBins, Float_t xMin, Float_t xMax)
3787 // Fit methode for the sigma of the pad response function
3792 fCurrentCoef[0] = 0.0;
3793 fCurrentCoefE = 0.0;
3795 Double_t ret = FitGausMI(arraye, arraym, arrayme, nBins, xMin, xMax,¶m);
3798 fCurrentCoef[0] = -fCurrentCoef[1];
3802 fNumberFitSuccess++;
3803 fCurrentCoef[0] = param[2];
3804 fCurrentCoefE = ret;
3808 //_____________________________________________________________________________
3809 Double_t AliTRDCalibraFit::FitGausMI(Double_t *arraye, Double_t *arraym, Double_t *arrayme, Int_t nBins, Float_t xMin, Float_t xMax, TVectorD *param, Bool_t kError)
3812 // Fit methode for the sigma of the pad response function
3815 //We should have at least 3 points
3816 if(nBins <=3) return -4.0;
3818 TLinearFitter fitter(3,"pol2");
3819 fitter.StoreData(kFALSE);
3820 fitter.ClearPoints();
3822 Float_t binWidth = (xMax-xMin)/(Float_t)nBins;
3823 Float_t entries = 0;
3824 Int_t nbbinwithentries = 0;
3825 for (Int_t i=0; i<nBins; i++){
3827 if(arraye[i] > 15) nbbinwithentries++;
3828 //printf("entries for i %d: %f\n",i,arraye[i]);
3830 if ((entries<700) || (nbbinwithentries < ((Int_t)(nBins/2)))) return -4;
3831 //printf("entries %f\n",entries);
3832 //printf("nbbinwithentries %d\n",nbbinwithentries);
3835 Float_t errorm = 0.0;
3836 Float_t errorn = 0.0;
3837 Float_t error = 0.0;
3840 for (Int_t ibin=0;ibin<nBins; ibin++){
3841 Float_t entriesI = arraye[ibin];
3842 Float_t valueI = arraym[ibin];
3843 Double_t xcenter = 0.0;
3845 if ((entriesI>15) && (valueI>0.0)){
3846 xcenter = xMin+(ibin+0.5)*binWidth;
3851 if((valueI + 0.01) > 0.0) errorm = TMath::Log((valueI + 0.01)/valueI);
3852 if((valueI - 0.01) > 0.0) errorn = TMath::Log((valueI - 0.01)/valueI);
3853 error = TMath::Max(TMath::Abs(errorm),TMath::Abs(errorn));
3856 if((valueI + arrayme[ibin]) > 0.0) errorm = TMath::Log((valueI + arrayme[ibin])/valueI);
3857 if((valueI - arrayme[ibin]) > 0.0) errorn = TMath::Log((valueI - arrayme[ibin])/valueI);
3858 error = TMath::Max(TMath::Abs(errorm),TMath::Abs(errorn));
3860 if(error == 0.0) continue;
3861 val = TMath::Log(Float_t(valueI));
3862 fitter.AddPoint(&xcenter,val,error);
3866 if(fDebugLevel > 1){
3868 if ( !fDebugStreamer ) {
3870 TDirectory *backup = gDirectory;
3871 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
3872 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3875 Int_t detector = fCountDet;
3876 Int_t plane = GetPlane(fCountDet);
3879 (* fDebugStreamer) << "FitGausMIFill"<<
3880 "detector="<<detector<<
3884 "entriesI="<<entriesI<<
3887 "xcenter="<<xcenter<<
3897 if(npoints <=3) return -4.0;
3902 fitter.GetParameters(par);
3903 chi2 = fitter.GetChisquare()/Float_t(npoints);
3906 if (!param) param = new TVectorD(3);
3907 if(par[2] == 0.0) return -4.0;
3908 Double_t x = TMath::Sqrt(TMath::Abs(-2*par[2]));
3909 Double_t deltax = (fitter.GetParError(2))/x;
3910 Double_t errorparam2 = TMath::Abs(deltax)/(x*x);
3913 (*param)[1] = par[1]/(-2.*par[2]);
3914 (*param)[2] = 1./TMath::Sqrt(TMath::Abs(-2.*par[2]));
3915 Double_t lnparam0 = par[0]+ par[1]* (*param)[1] + par[2]*(*param)[1]*(*param)[1];
3916 if ( lnparam0>307 ) return -4;
3917 (*param)[0] = TMath::Exp(lnparam0);
3919 if(fDebugLevel > 1){
3921 if ( !fDebugStreamer ) {
3923 TDirectory *backup = gDirectory;
3924 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
3925 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3928 Int_t detector = fCountDet;
3929 Int_t plane = GetPlane(fCountDet);
3932 (* fDebugStreamer) << "FitGausMIFit"<<
3933 "detector="<<detector<<
3936 "errorsigma="<<chi2<<
3937 "mean="<<(*param)[1]<<
3938 "sigma="<<(*param)[2]<<
3939 "constant="<<(*param)[0]<<
3944 if((chi2/(*param)[2]) > 0.1){
3946 chi2 = FitGausMI(arraye,arraym,arrayme,nBins,xMin,xMax,param,kFALSE);
3951 if(fDebugLevel == 1){
3952 TString name("PRF");
3953 name += (Int_t)xMin;
3954 name += (Int_t)xMax;
3955 TCanvas *c1 = new TCanvas((const char *)name,(const char *)name,50,50,600,800);
3958 TH1F *histo = new TH1F((const char *)name,(const char *)name,nBins,xMin,xMax);
3959 for(Int_t k = 0; k < nBins; k++){
3960 histo->SetBinContent(k+1,arraym[k]);
3961 histo->SetBinError(k+1,arrayme[k]);
3964 name += "functionf";
3965 TF1 *f1= new TF1((const char*)name,"[0]*exp(-(x-[1])^2/(2*[2]*[2]))",xMin,xMax);
3966 f1->SetParameter(0, (*param)[0]);
3967 f1->SetParameter(1, (*param)[1]);
3968 f1->SetParameter(2, (*param)[2]);
3976 //_____________________________________________________________________________
3977 void AliTRDCalibraFit::FitPRF(TH1 *projPRF)
3980 // Fit methode for the sigma of the pad response function
3983 fCurrentCoef[0] = 0.0;
3984 fCurrentCoefE = 0.0;
3986 if (fDebugLevel != 1) {
3987 projPRF->Fit("gaus","0M","",-fRangeFitPRF,fRangeFitPRF);
3990 TCanvas *cfit = new TCanvas("cfit","cfit",50,50,600,800);
3992 projPRF->Fit("gaus","M+","",-fRangeFitPRF,fRangeFitPRF);
3995 fCurrentCoef[0] = projPRF->GetFunction("gaus")->GetParameter(2);
3996 fCurrentCoefE = projPRF->GetFunction("gaus")->GetParError(2);
3997 if(fCurrentCoef[0] <= 0.0) fCurrentCoef[0] = -fCurrentCoef[1];
3999 fNumberFitSuccess++;
4002 //_____________________________________________________________________________
4003 void AliTRDCalibraFit::RmsPRF(TH1 *projPRF)
4006 // Fit methode for the sigma of the pad response function
4008 fCurrentCoef[0] = 0.0;
4009 fCurrentCoefE = 0.0;
4010 if (fDebugLevel == 1) {
4011 TCanvas *cfit = new TCanvas("cfit","cfit",50,50,600,800);
4015 fCurrentCoef[0] = projPRF->GetRMS();
4016 if(fCurrentCoef[0] <= 0.0) fCurrentCoef[0] = -fCurrentCoef[1];
4018 fNumberFitSuccess++;
4021 //_____________________________________________________________________________
4022 void AliTRDCalibraFit::FitTnpRange(Double_t *arraye, Double_t *arraym, Double_t *arrayme, Int_t nbg, Int_t nybins)
4025 // Fit methode for the sigma of the pad response function with 2*nbg tan bins
4028 TLinearFitter linearfitter = TLinearFitter(3,"pol2");
4031 Int_t nbins = (Int_t)(nybins/(2*nbg));
4032 Float_t lowedge = -3.0*nbg;
4033 Float_t upedge = lowedge + 3.0;
4036 Double_t xvalues = -0.2*nbg+0.1;
4038 Int_t total = 2*nbg;
4041 for(Int_t k = 0; k < total; k++){
4042 if(FitPRFGausMI(arraye+offset, arraym+offset, arrayme+offset, nbins, lowedge, upedge)){
4044 y = fCurrentCoef[0]*fCurrentCoef[0];
4045 linearfitter.AddPoint(&xvalues,y,2*fCurrentCoefE*fCurrentCoef[0]);
4048 if(fDebugLevel > 1){
4050 if ( !fDebugStreamer ) {
4052 TDirectory *backup = gDirectory;
4053 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
4054 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
4057 Int_t detector = fCountDet;
4058 Int_t plane = GetPlane(fCountDet);
4059 Int_t nbtotal = total;
4061 Float_t low = lowedge;
4062 Float_t up = upedge;
4063 Float_t tnp = xvalues;
4064 Float_t wid = fCurrentCoef[0];
4065 Float_t widfE = fCurrentCoefE;
4067 (* fDebugStreamer) << "FitTnpRange0"<<
4068 "detector="<<detector<<
4070 "nbtotal="<<nbtotal<<
4088 fCurrentCoefE = 0.0;
4089 fCurrentCoef[0] = 0.0;
4091 //printf("npoints\n",npoints);
4094 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
4099 linearfitter.Eval();
4100 linearfitter.GetParameters(pars0);
4101 Double_t pointError0 = TMath::Sqrt(linearfitter.GetChisquare()/npoints);
4102 Double_t errorsx0 = linearfitter.GetParError(2)*pointError0;
4103 Double_t min0 = 0.0;
4104 Double_t ermin0 = 0.0;
4105 //Double_t prfe0 = 0.0;
4106 Double_t prf0 = 0.0;
4107 if((pars0[2] > 0.0) && (pars0[1] != 0.0)) {
4108 min0 = -pars0[1]/(2*pars0[2]);
4109 ermin0 = TMath::Abs(min0*(errorsx0/pars0[2]+linearfitter.GetParError(1)*pointError0/pars0[1]));
4110 prf0 = pars0[0]+pars0[1]*min0+pars0[2]*min0*min0;
4113 prfe0 = linearfitter->GetParError(0)*pointError0
4114 +(linearfitter->GetParError(1)*pointError0/pars0[1]+ermin0/min0)*pars0[1]*min0
4115 +(linearfitter->GetParError(2)*pointError0/pars0[2]+2*ermin0/min0)*pars0[2]*min0*min0;
4116 prfe0 = prfe0/(2*TMath::Sqrt(prf0));
4117 fCurrentCoefE = (Float_t) prfe0;
4119 fCurrentCoef[0] = (Float_t) TMath::Sqrt(TMath::Abs(prf0));
4122 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
4126 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
4129 if(fDebugLevel > 1){
4131 if ( !fDebugStreamer ) {
4133 TDirectory *backup = gDirectory;
4134 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
4135 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
4138 Int_t detector = fCountDet;
4139 Int_t plane = GetPlane(fCountDet);
4140 Int_t nbtotal = total;
4141 Double_t colsize[6] = {0.635,0.665,0.695,0.725,0.755,0.785};
4142 Double_t sigmax = TMath::Sqrt(TMath::Abs(pars0[2]))*10000*colsize[plane];
4144 (* fDebugStreamer) << "FitTnpRange1"<<
4145 "detector="<<detector<<
4147 "nbtotal="<<nbtotal<<
4151 "npoints="<<npoints<<
4154 "sigmaprf="<<fCurrentCoef[0]<<
4155 "sigprf="<<fCurrentCoef[1]<<
4162 //_____________________________________________________________________________
4163 void AliTRDCalibraFit::FitMean(TH1 *projch, Double_t nentries, Double_t mean)
4166 // Only mean methode for the gain factor
4169 fCurrentCoef[0] = mean;
4170 fCurrentCoefE = 0.0;
4171 if(nentries > 0) fCurrentCoefE = projch->GetRMS()/TMath::Sqrt(nentries);
4172 if (fDebugLevel == 1) {
4173 TCanvas *cpmean = new TCanvas("cpmean","cpmean",50,50,600,800);
4177 CalculChargeCoefMean(kTRUE);
4178 fNumberFitSuccess++;
4180 //_____________________________________________________________________________
4181 void AliTRDCalibraFit::FitMeanW(TH1 *projch, Double_t nentries)
4184 // mean w methode for the gain factor
4188 Int_t nybins = projch->GetNbinsX();
4190 //The weight function
4191 Double_t a = 0.00228515;
4192 Double_t b = -0.00231487;
4193 Double_t c = 0.00044298;
4194 Double_t d = -0.00379239;
4195 Double_t e = 0.00338349;
4205 //A arbitrary error for the moment
4206 fCurrentCoefE = 0.0;
4207 fCurrentCoef[0] = 0.0;
4210 Double_t sumw = 0.0;
4212 Float_t sumAll = (Float_t) nentries;
4213 Int_t sumCurrent = 0;
4214 for(Int_t k = 0; k <nybins; k++){
4215 Double_t fraction = Float_t(sumCurrent)/Float_t(sumAll);
4216 if (fraction>0.95) break;
4217 Double_t weight = a + b*fraction + c*fraction*fraction + d *fraction*fraction*fraction+
4218 e*fraction*fraction*fraction*fraction;
4219 sumw += weight*projch->GetBinContent(k+1)*projch->GetBinCenter(k+1);
4220 sum += weight*projch->GetBinContent(k+1);
4221 sumCurrent += (Int_t) projch->GetBinContent(k+1);
4222 //printf("fraction %f, weight %f, bincontent %f\n",fraction,weight,projch->GetBinContent(k+1));
4224 if(sum > 0.0) fCurrentCoef[0] = (sumw/sum);
4226 if (fDebugLevel == 1) {
4227 TCanvas *cpmeanw = new TCanvas("cpmeanw","cpmeanw",50,50,600,800);
4231 fNumberFitSuccess++;
4232 CalculChargeCoefMean(kTRUE);
4234 //_____________________________________________________________________________
4235 void AliTRDCalibraFit::FitMeanWSm(TH1 *projch, Float_t sumAll)
4238 // mean w methode for the gain factor
4242 Int_t nybins = projch->GetNbinsX();
4244 //The weight function
4245 Double_t a = 0.00228515;
4246 Double_t b = -0.00231487;
4247 Double_t c = 0.00044298;
4248 Double_t d = -0.00379239;
4249 Double_t e = 0.00338349;
4259 //A arbitrary error for the moment
4260 fCurrentCoefE = 0.0;
4261 fCurrentCoef[0] = 0.0;
4264 Double_t sumw = 0.0;
4266 Int_t sumCurrent = 0;
4267 for(Int_t k = 0; k <nybins; k++){
4268 Double_t fraction = Float_t(sumCurrent)/Float_t(sumAll);
4269 if (fraction>0.95) break;
4270 Double_t weight = a + b*fraction + c*fraction*fraction + d *fraction*fraction*fraction+
4271 e*fraction*fraction*fraction*fraction;
4272 sumw += weight*projch->GetBinContent(k+1)*projch->GetBinCenter(k+1);
4273 sum += weight*projch->GetBinContent(k+1);
4274 sumCurrent += (Int_t) projch->GetBinContent(k+1);
4275 //printf("fraction %f, weight %f, bincontent %f\n",fraction,weight,projch->GetBinContent(k+1));
4277 if(sum > 0.0) fCurrentCoef[0] = (sumw/sum);
4279 if (fDebugLevel == 1) {
4280 TCanvas *cpmeanw = new TCanvas("cpmeanw","cpmeanw",50,50,600,800);
4284 fNumberFitSuccess++;
4286 //_____________________________________________________________________________
4287 void AliTRDCalibraFit::FitCH(TH1 *projch, Double_t mean)
4290 // Fit methode for the gain factor
4293 fCurrentCoef[0] = 0.0;
4294 fCurrentCoefE = 0.0;
4295 Double_t chisqrl = 0.0;
4296 Double_t chisqrg = 0.0;
4297 Double_t chisqr = 0.0;
4298 TF1 *fLandauGaus = new TF1("fLandauGaus",FuncLandauGaus,0,300,5);
4300 projch->Fit("landau","0",""
4301 ,(Double_t) mean/fBeginFitCharge
4302 ,projch->GetBinCenter(projch->GetNbinsX()));
4303 Double_t l3P0 = projch->GetFunction("landau")->GetParameter(0);
4304 Double_t l3P1 = projch->GetFunction("landau")->GetParameter(1);
4305 Double_t l3P2 = projch->GetFunction("landau")->GetParameter(2);
4306 chisqrl = projch->GetFunction("landau")->GetChisquare();
4308 projch->Fit("gaus","0",""
4309 ,(Double_t) mean/fBeginFitCharge
4310 ,projch->GetBinCenter(projch->GetNbinsX()));
4311 Double_t g3P0 = projch->GetFunction("gaus")->GetParameter(0);
4312 Double_t g3P2 = projch->GetFunction("gaus")->GetParameter(2);
4313 chisqrg = projch->GetFunction("gaus")->GetChisquare();
4315 fLandauGaus->SetParameters(l3P0,l3P1,l3P2,g3P0,g3P2);
4316 if (fDebugLevel != 1) {
4317 projch->Fit("fLandauGaus","0",""
4318 ,(Double_t) mean/fBeginFitCharge
4319 ,projch->GetBinCenter(projch->GetNbinsX()));
4320 chisqr = projch->GetFunction("fLandauGaus")->GetChisquare();
4323 TCanvas *cp = new TCanvas("cp","cp",50,50,600,800);
4325 projch->Fit("fLandauGaus","+",""
4326 ,(Double_t) mean/fBeginFitCharge
4327 ,projch->GetBinCenter(projch->GetNbinsX()));
4328 chisqr = projch->GetFunction("fLandauGaus")->GetChisquare();
4330 fLandauGaus->Draw("same");
4333 if ((projch->GetFunction("fLandauGaus")->GetParameter(1) > 0) && (projch->GetFunction("fLandauGaus")->GetParError(1) < (0.05*projch->GetFunction("fLandauGaus")->GetParameter(1))) && (chisqr < chisqrl) && (chisqr < chisqrg)) {
4334 //if ((projch->GetFunction("fLandauGaus")->GetParameter(1) > 0) && (chisqr < chisqrl) && (chisqr < chisqrg)) {
4335 fNumberFitSuccess++;
4336 CalculChargeCoefMean(kTRUE);
4337 fCurrentCoef[0] = projch->GetFunction("fLandauGaus")->GetParameter(1);
4338 fCurrentCoefE = projch->GetFunction("fLandauGaus")->GetParError(1);
4341 CalculChargeCoefMean(kFALSE);
4342 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
4345 if (fDebugLevel != 1) {
4350 //_____________________________________________________________________________
4351 void AliTRDCalibraFit::FitBisCH(TH1* projch, Double_t mean)
4354 // Fit methode for the gain factor more time consuming
4358 //Some parameters to initialise
4359 Double_t widthLandau, widthGaus, mPV, integral;
4360 Double_t chisquarel = 0.0;
4361 Double_t chisquareg = 0.0;
4362 projch->Fit("landau","0M+",""
4364 ,projch->GetBinCenter(projch->GetNbinsX()));
4365 widthLandau = projch->GetFunction("landau")->GetParameter(2);
4366 chisquarel = projch->GetFunction("landau")->GetChisquare();
4367 projch->Fit("gaus","0M+",""
4369 ,projch->GetBinCenter(projch->GetNbinsX()));
4370 widthGaus = projch->GetFunction("gaus")->GetParameter(2);
4371 chisquareg = projch->GetFunction("gaus")->GetChisquare();
4373 mPV = (projch->GetFunction("landau")->GetParameter(1))/2;
4374 integral = (projch->GetFunction("gaus")->Integral(0.3*mean,3*mean)+projch->GetFunction("landau")->Integral(0.3*mean,3*mean))/2;
4376 // Setting fit range and start values
4378 //Double_t sv[4] = { l3P2, fChargeCoef[1], projch->Integral("width"), fG3P2 };
4379 //Double_t sv[4] = { fL3P2, fChargeCoef[1], fL3P0, fG3P2 };
4380 Double_t sv[4] = { widthLandau, mPV, integral, widthGaus};
4381 Double_t pllo[4] = { 0.001, 0.001, projch->Integral()/3, 0.001};
4382 Double_t plhi[4] = { 300.0, 300.0, 30*projch->Integral(), 300.0};
4383 Double_t fp[4] = { 1.0, 1.0, 1.0, 1.0 };
4384 Double_t fpe[4] = { 1.0, 1.0, 1.0, 1.0 };
4387 fCurrentCoef[0] = 0.0;
4388 fCurrentCoefE = 0.0;
4392 TF1 *fitsnr = LanGauFit(projch,&fr[0],&sv[0]
4397 Double_t projchPeak;
4398 Double_t projchFWHM;
4399 LanGauPro(fp,projchPeak,projchFWHM);
4401 if ((fp[1] > 0) && ((fpe[1] < (0.05*fp[1])) && (chisqr < chisquarel) && (chisqr < chisquareg))) {
4402 //if ((fp[1] > 0) && ((chisqr < chisquarel) && (chisqr < chisquareg))) {
4403 fNumberFitSuccess++;
4404 CalculChargeCoefMean(kTRUE);
4405 fCurrentCoef[0] = fp[1];
4406 fCurrentCoefE = fpe[1];
4407 //chargeCoefE2 = chisqr;
4410 CalculChargeCoefMean(kFALSE);
4411 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
4413 if (fDebugLevel == 1) {
4414 AliInfo(Form("fChargeCoef[0]: %f",(Float_t) fCurrentCoef[0]));
4415 TCanvas *cpy = new TCanvas("cpy","cpy",50,50,600,800);
4418 fitsnr->Draw("same");
4424 //_____________________________________________________________________________
4425 Double_t *AliTRDCalibraFit::CalculPolynomeLagrange2(Double_t *x, Double_t *y) const
4428 // Calcul the coefficients of the polynome passant par ces trois points de degre 2
4430 Double_t *c = new Double_t[5];
4431 Double_t x0 = y[0]/((x[0]-x[1])*(x[0]-x[2]));
4432 Double_t x1 = y[1]/((x[1]-x[0])*(x[1]-x[2]));
4433 Double_t x2 = y[2]/((x[2]-x[0])*(x[2]-x[1]));
4438 c[1] = -(x0*(x[1]+x[2])+x1*(x[0]+x[2])+x2*(x[0]+x[1]));
4439 c[0] = x0*x[1]*x[2]+x1*x[0]*x[2]+x2*x[0]*x[1];
4446 //_____________________________________________________________________________
4447 Double_t *AliTRDCalibraFit::CalculPolynomeLagrange3(Double_t *x, Double_t *y) const
4450 // Calcul the coefficients of the polynome passant par ces quatre points de degre 3
4452 Double_t *c = new Double_t[5];
4453 Double_t x0 = y[0]/((x[0]-x[1])*(x[0]-x[2])*(x[0]-x[3]));
4454 Double_t x1 = y[1]/((x[1]-x[0])*(x[1]-x[2])*(x[1]-x[3]));
4455 Double_t x2 = y[2]/((x[2]-x[0])*(x[2]-x[1])*(x[2]-x[3]));
4456 Double_t x3 = y[3]/((x[3]-x[0])*(x[3]-x[1])*(x[3]-x[2]));
4460 c[2] = -(x0*(x[1]+x[2]+x[3])
4461 +x1*(x[0]+x[2]+x[3])
4462 +x2*(x[0]+x[1]+x[3])
4463 +x3*(x[0]+x[1]+x[2]));
4464 c[1] = (x0*(x[1]*x[2]+x[1]*x[3]+x[2]*x[3])
4465 +x1*(x[0]*x[2]+x[0]*x[3]+x[2]*x[3])
4466 +x2*(x[0]*x[1]+x[0]*x[3]+x[1]*x[3])
4467 +x3*(x[0]*x[1]+x[0]*x[2]+x[1]*x[2]));
4469 c[0] = -(x0*x[1]*x[2]*x[3]
4472 +x3*x[0]*x[1]*x[2]);
4480 //_____________________________________________________________________________
4481 Double_t *AliTRDCalibraFit::CalculPolynomeLagrange4(Double_t *x, Double_t *y) const
4484 // Calcul the coefficients of the polynome passant par ces cinqs points de degre 4
4486 Double_t *c = new Double_t[5];
4487 Double_t x0 = y[0]/((x[0]-x[1])*(x[0]-x[2])*(x[0]-x[3])*(x[0]-x[4]));
4488 Double_t x1 = y[1]/((x[1]-x[0])*(x[1]-x[2])*(x[1]-x[3])*(x[1]-x[4]));
4489 Double_t x2 = y[2]/((x[2]-x[0])*(x[2]-x[1])*(x[2]-x[3])*(x[2]-x[4]));
4490 Double_t x3 = y[3]/((x[3]-x[0])*(x[3]-x[1])*(x[3]-x[2])*(x[3]-x[4]));
4491 Double_t x4 = y[4]/((x[4]-x[0])*(x[4]-x[1])*(x[4]-x[2])*(x[4]-x[3]));
4494 c[4] = x0+x1+x2+x3+x4;
4495 c[3] = -(x0*(x[1]+x[2]+x[3]+x[4])
4496 +x1*(x[0]+x[2]+x[3]+x[4])
4497 +x2*(x[0]+x[1]+x[3]+x[4])
4498 +x3*(x[0]+x[1]+x[2]+x[4])
4499 +x4*(x[0]+x[1]+x[2]+x[3]));
4500 c[2] = (x0*(x[1]*x[2]+x[1]*x[3]+x[1]*x[4]+x[2]*x[3]+x[2]*x[4]+x[3]*x[4])
4501 +x1*(x[0]*x[2]+x[0]*x[3]+x[0]*x[4]+x[2]*x[3]+x[2]*x[4]+x[3]*x[4])
4502 +x2*(x[0]*x[1]+x[0]*x[3]+x[0]*x[4]+x[1]*x[3]+x[1]*x[4]+x[3]*x[4])
4503 +x3*(x[0]*x[1]+x[0]*x[2]+x[0]*x[4]+x[1]*x[2]+x[1]*x[4]+x[2]*x[4])
4504 +x4*(x[0]*x[1]+x[0]*x[2]+x[0]*x[3]+x[1]*x[2]+x[1]*x[3]+x[2]*x[3]));
4506 c[1] = -(x0*(x[1]*x[2]*x[3]+x[1]*x[2]*x[4]+x[1]*x[3]*x[4]+x[2]*x[3]*x[4])
4507 +x1*(x[0]*x[2]*x[3]+x[0]*x[2]*x[4]+x[0]*x[3]*x[4]+x[2]*x[3]*x[4])
4508 +x2*(x[0]*x[1]*x[3]+x[0]*x[1]*x[4]+x[0]*x[3]*x[4]+x[1]*x[3]*x[4])
4509 +x3*(x[0]*x[1]*x[2]+x[0]*x[1]*x[4]+x[0]*x[2]*x[4]+x[1]*x[2]*x[4])
4510 +x4*(x[0]*x[1]*x[2]+x[0]*x[1]*x[3]+x[0]*x[2]*x[3]+x[1]*x[2]*x[3]));
4512 c[0] = (x0*x[1]*x[2]*x[3]*x[4]
4513 +x1*x[0]*x[2]*x[3]*x[4]
4514 +x2*x[0]*x[1]*x[3]*x[4]
4515 +x3*x[0]*x[1]*x[2]*x[4]
4516 +x4*x[0]*x[1]*x[2]*x[3]);
4522 //_____________________________________________________________________________
4523 void AliTRDCalibraFit::NormierungCharge()
4526 // Normalisation of the gain factor resulting for the fits
4529 // Calcul of the mean of choosen method by fFitChargeNDB
4531 //printf("total number of entries %d\n",fVectorFitCH->GetEntriesFast());
4532 for (Int_t k = 0; k < (Int_t) fVectorFit.GetEntriesFast(); k++) {
4534 Int_t detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
4535 Float_t *coef = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef();
4536 //printf("detector %d coef[0] %f\n",detector,coef[0]);
4537 if (GetChamber(detector) == 2) {
4540 if (GetChamber(detector) != 2) {
4543 for (Int_t j = 0; j < total; j++) {
4551 fScaleFitFactor = fScaleFitFactor / sum;
4554 fScaleFitFactor = 1.0;
4557 //methode de boeuf mais bon...
4558 Double_t scalefactor = fScaleFitFactor;
4560 if(fDebugLevel > 1){
4562 if ( !fDebugStreamer ) {
4564 TDirectory *backup = gDirectory;
4565 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
4566 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
4568 (* fDebugStreamer) << "NormierungCharge"<<
4569 "scalefactor="<<scalefactor<<
4573 //_____________________________________________________________________________
4574 TH1I *AliTRDCalibraFit::ReBin(TH1I *hist) const
4577 // Rebin of the 1D histo for the gain calibration if needed.
4578 // you have to choose fRebin, divider of fNumberBinCharge
4581 TAxis *xhist = hist->GetXaxis();
4582 TH1I *rehist = new TH1I("projrebin","",(Int_t) xhist->GetNbins()/fRebin
4583 ,xhist->GetBinLowEdge(1)
4584 ,xhist->GetBinUpEdge(xhist->GetNbins()));
4586 AliInfo(Form("fRebin: %d",fRebin));
4588 for (Int_t k = 1; k <= (Int_t) xhist->GetNbins()/fRebin; k++) {
4590 for (Int_t ji = i; ji < i+fRebin; ji++) {
4591 sum += hist->GetBinContent(ji);
4594 rehist->SetBinContent(k,sum);
4602 //_____________________________________________________________________________
4603 TH1F *AliTRDCalibraFit::ReBin(TH1F *hist) const
4606 // Rebin of the 1D histo for the gain calibration if needed
4607 // you have to choose fRebin divider of fNumberBinCharge
4610 TAxis *xhist = hist->GetXaxis();
4611 TH1F *rehist = new TH1F("projrebin","",(Int_t) xhist->GetNbins()/fRebin
4612 ,xhist->GetBinLowEdge(1)
4613 ,xhist->GetBinUpEdge(xhist->GetNbins()));
4615 AliInfo(Form("fRebin: %d",fRebin));
4617 for (Int_t k = 1; k <= (Int_t) xhist->GetNbins()/fRebin; k++) {
4619 for (Int_t ji = i; ji < i+fRebin; ji++) {
4620 sum += hist->GetBinContent(ji);
4623 rehist->SetBinContent(k,sum);
4631 //_____________________________________________________________________________
4632 TH1F *AliTRDCalibraFit::CorrectTheError(TGraphErrors *hist)
4635 // In the case of the vectors method the trees contains TGraphErrors for PH and PRF
4636 // to be able to add them after
4637 // We convert it to a TH1F to be able to applied the same fit function method
4638 // After having called this function you can not add the statistics anymore
4643 Int_t nbins = hist->GetN();
4644 Double_t *x = hist->GetX();
4645 Double_t *entries = hist->GetEX();
4646 Double_t *mean = hist->GetY();
4647 Double_t *square = hist->GetEY();
4648 fEntriesCurrent = 0;
4654 Double_t step = x[1] - x[0];
4655 Double_t minvalue = x[0] - step/2;
4656 Double_t maxvalue = x[(nbins-1)] + step/2;
4658 rehist = new TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
4660 for (Int_t k = 0; k < nbins; k++) {
4661 rehist->SetBinContent(k+1,mean[k]);
4662 if (entries[k] > 0.0) {
4663 fEntriesCurrent += (Int_t) entries[k];
4664 Double_t d = TMath::Abs(square[k] - (mean[k]*mean[k]));
4665 rehist->SetBinError(k+1,TMath::Sqrt(d/entries[k]));
4668 rehist->SetBinError(k+1,0.0);
4672 if(fEntriesCurrent > 0) fNumberEnt++;
4678 //____________Some basic geometry function_____________________________________
4681 //_____________________________________________________________________________
4682 Int_t AliTRDCalibraFit::GetPlane(Int_t d) const
4685 // Reconstruct the plane number from the detector number
4688 return ((Int_t) (d % 6));
4692 //_____________________________________________________________________________
4693 Int_t AliTRDCalibraFit::GetChamber(Int_t d) const
4696 // Reconstruct the chamber number from the detector number
4700 return ((Int_t) (d % 30) / fgkNplan);
4704 //_____________________________________________________________________________
4705 Int_t AliTRDCalibraFit::GetSector(Int_t d) const
4708 // Reconstruct the sector number from the detector number
4712 return ((Int_t) (d / fg));
4717 //____________Fill and Init tree Gain, PRF, Vdrift and T0______________________
4719 //_______________________________________________________________________________
4720 void AliTRDCalibraFit::ResetVectorFit()
4723 // Reset the VectorFits
4726 fVectorFit.SetOwner();
4728 fVectorFit2.SetOwner();
4729 fVectorFit2.Clear();
4733 //____________Private Functions________________________________________________
4736 //_____________________________________________________________________________
4737 Double_t AliTRDCalibraFit::PH(Double_t *x, Double_t *par)
4740 // Function for the fit
4743 //TF1 *fAsymmGauss = new TF1("fAsymmGauss",AsymmGauss,0,4,6);
4745 //PARAMETERS FOR FIT PH
4747 //fAsymmGauss->SetParameter(0,0.113755);
4748 //fAsymmGauss->SetParameter(1,0.350706);
4749 //fAsymmGauss->SetParameter(2,0.0604244);
4750 //fAsymmGauss->SetParameter(3,7.65596);
4751 //fAsymmGauss->SetParameter(4,1.00124);
4752 //fAsymmGauss->SetParameter(5,0.870597); // No tail cancelation
4760 Double_t dx = 0.005;
4761 Double_t xs = par[1];
4763 Double_t paras[2] = { 0.0, 0.0 };
4766 if ((xs >= par[1]) &&
4767 (xs < (par[1]+par[2]))) {
4768 //fAsymmGauss->SetParameter(0,par[0]);
4769 //fAsymmGauss->SetParameter(1,xs);
4770 //ss += fAsymmGauss->Eval(xx);
4773 ss += AsymmGauss(&xx,paras);
4775 if ((xs >= (par[1]+par[2])) &&
4776 (xs < (par[1]+par[2]+par[3]))) {
4777 //fAsymmGauss->SetParameter(0,par[0]*par[4]);
4778 //fAsymmGauss->SetParameter(1,xs);
4779 //ss += fAsymmGauss->Eval(xx);
4780 paras[0] = par[0]*par[4];
4782 ss += AsymmGauss(&xx,paras);
4791 //_____________________________________________________________________________
4792 Double_t AliTRDCalibraFit::AsymmGauss(Double_t *x, Double_t *par)
4795 // Function for the fit
4798 //par[0] = normalization
4806 Double_t par1save = par[1];
4807 //Double_t par2save = par[2];
4808 Double_t par2save = 0.0604244;
4809 //Double_t par3save = par[3];
4810 Double_t par3save = 7.65596;
4811 //Double_t par5save = par[5];
4812 Double_t par5save = 0.870597;
4813 Double_t dx = x[0] - par1save;
4815 Double_t sigma2 = par2save*par2save;
4816 Double_t sqrt2 = TMath::Sqrt(2.0);
4817 Double_t exp1 = par3save * TMath::Exp(-par3save * (dx - 0.5 * par3save * sigma2))
4818 * (1.0 - TMath::Erf((par3save * sigma2 - dx) / (sqrt2 * par2save)));
4819 Double_t exp2 = par5save * TMath::Exp(-par5save * (dx - 0.5 * par5save * sigma2))
4820 * (1.0 - TMath::Erf((par5save * sigma2 - dx) / (sqrt2 * par2save)));
4822 //return par[0]*(exp1+par[4]*exp2);
4823 return par[0] * (exp1 + 1.00124 * exp2);
4827 //_____________________________________________________________________________
4828 Double_t AliTRDCalibraFit::FuncLandauGaus(Double_t *x, Double_t *par)
4831 // Sum Landau + Gaus with identical mean
4834 Double_t valLandau = par[0] * TMath::Landau(x[0],par[1],par[2]);
4835 //Double_t valGaus = par[3] * TMath::Gaus(x[0],par[4],par[5]);
4836 Double_t valGaus = par[3] * TMath::Gaus(x[0],par[1],par[4]);
4837 Double_t val = valLandau + valGaus;
4843 //_____________________________________________________________________________
4844 Double_t AliTRDCalibraFit::LanGauFun(Double_t *x, Double_t *par)
4847 // Function for the fit
4850 // par[0]=Width (scale) parameter of Landau density
4851 // par[1]=Most Probable (MP, location) parameter of Landau density
4852 // par[2]=Total area (integral -inf to inf, normalization constant)
4853 // par[3]=Width (sigma) of convoluted Gaussian function
4855 // In the Landau distribution (represented by the CERNLIB approximation),
4856 // the maximum is located at x=-0.22278298 with the location parameter=0.
4857 // This shift is corrected within this function, so that the actual
4858 // maximum is identical to the MP parameter.
4861 // Numeric constants
4862 Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
4863 Double_t mpshift = -0.22278298; // Landau maximum location
4865 // Control constants
4866 Double_t np = 100.0; // Number of convolution steps
4867 Double_t sc = 5.0; // Convolution extends to +-sc Gaussian sigmas
4879 // MP shift correction
4880 mpc = par[1] - mpshift * par[0];
4882 // Range of convolution integral
4883 xlow = x[0] - sc * par[3];
4884 xupp = x[0] + sc * par[3];
4886 step = (xupp - xlow) / np;
4888 // Convolution integral of Landau and Gaussian by sum
4889 for (i = 1.0; i <= np/2; i++) {
4891 xx = xlow + (i-.5) * step;
4892 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
4893 sum += fland * TMath::Gaus(x[0],xx,par[3]);
4895 xx = xupp - (i-.5) * step;
4896 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
4897 sum += fland * TMath::Gaus(x[0],xx,par[3]);
4901 return (par[2] * step * sum * invsq2pi / par[3]);
4904 //_____________________________________________________________________________
4905 TF1 *AliTRDCalibraFit::LanGauFit(TH1 *his, Double_t *fitrange, Double_t *startvalues
4906 , Double_t *parlimitslo, Double_t *parlimitshi
4907 , Double_t *fitparams, Double_t *fiterrors
4908 , Double_t *chiSqr, Int_t *ndf) const
4911 // Function for the fit
4915 Char_t funname[100];
4917 TF1 *ffitold = (TF1 *) gROOT->GetListOfFunctions()->FindObject(funname);
4922 TF1 *ffit = new TF1(funname,LanGauFun,fitrange[0],fitrange[1],4);
4923 ffit->SetParameters(startvalues);
4924 ffit->SetParNames("Width","MP","Area","GSigma");
4926 for (i = 0; i < 4; i++) {
4927 ffit->SetParLimits(i,parlimitslo[i],parlimitshi[i]);
4930 his->Fit(funname,"RB0"); // Fit within specified range, use ParLimits, do not plot
4932 ffit->GetParameters(fitparams); // Obtain fit parameters
4933 for (i = 0; i < 4; i++) {
4934 fiterrors[i] = ffit->GetParError(i); // Obtain fit parameter errors
4936 chiSqr[0] = ffit->GetChisquare(); // Obtain chi^2
4937 ndf[0] = ffit->GetNDF(); // Obtain ndf
4939 return (ffit); // Return fit function
4943 //_____________________________________________________________________________
4944 Int_t AliTRDCalibraFit::LanGauPro(Double_t *params, Double_t &maxx, Double_t &fwhm)
4947 // Function for the fit
4960 Int_t maxcalls = 10000;
4962 // Search for maximum
4963 p = params[1] - 0.1 * params[0];
4964 step = 0.05 * params[0];
4968 while ((l != lold) && (i < maxcalls)) {
4972 l = LanGauFun(&x,params);
4974 step = -step / 10.0;
4979 if (i == maxcalls) {
4985 // Search for right x location of fy
4986 p = maxx + params[0];
4992 while ( (l != lold) && (i < maxcalls) ) {
4997 l = TMath::Abs(LanGauFun(&x,params) - fy);
5011 // Search for left x location of fy
5013 p = maxx - 0.5 * params[0];
5019 while ((l != lold) && (i < maxcalls)) {
5023 l = TMath::Abs(LanGauFun(&x,params) - fy);
5025 step = -step / 10.0;
5030 if (i == maxcalls) {
5039 //_____________________________________________________________________________
5040 Double_t AliTRDCalibraFit::GausConstant(Double_t *x, Double_t *par)
5043 // Gaus with identical mean
5046 Double_t gauss = par[0] * TMath::Gaus(x[0],0.0,par[1])+par[2];