]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDCalibraFit.cxx
wierd coverty fixes
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFit.cxx
CommitLineData
55a288e5 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18/////////////////////////////////////////////////////////////////////////////////
19//
20// AliTRDCalibraFit
21//
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
64942b85 31// _fDebug = 1: only the fit of the choosen calibration group fFitVoir (SetFitVoir)
32// _fDebug = 2: a comparaison of the coefficients found and the default values
55a288e5 33// in the choosen database.
34// fCoef , histogram of the coefs as function of the calibration group number
35// fDelta , histogram of the relative difference of the coef with the default
36// value in the database as function of the calibration group number
37// fError , dirstribution of this relative difference
55a288e5 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
42//
43//
44// Author:
45// R. Bailhache (R.Bailhache@gsi.de)
46//
47//////////////////////////////////////////////////////////////////////////////////////
48
55a288e5 49#include <TLine.h>
50#include <TH1I.h>
51#include <TStyle.h>
52#include <TProfile2D.h>
55a288e5 53#include <TCanvas.h>
54#include <TGraphErrors.h>
55a288e5 55#include <TObjArray.h>
56#include <TH1.h>
57#include <TH1F.h>
58#include <TF1.h>
55a288e5 59#include <TAxis.h>
55a288e5 60#include <TMath.h>
55a288e5 61#include <TDirectory.h>
3a0f6479 62#include <TTreeStream.h>
63#include <TLinearFitter.h>
64#include <TVectorD.h>
daa7dc79 65#include <TROOT.h>
4c865c34 66#include <TString.h>
55a288e5 67
68#include "AliLog.h"
3a0f6479 69#include "AliMathBase.h"
55a288e5 70
71#include "AliTRDCalibraFit.h"
72#include "AliTRDCalibraMode.h"
73#include "AliTRDCalibraVector.h"
3a0f6479 74#include "AliTRDCalibraVdriftLinearFit.h"
55a288e5 75#include "AliTRDcalibDB.h"
76#include "AliTRDgeometry.h"
3a0f6479 77#include "AliTRDpadPlane.h"
78#include "AliTRDgeometry.h"
a076fc2f 79#include "AliTRDCommonParam.h"
55a288e5 80#include "./Cal/AliTRDCalROC.h"
81#include "./Cal/AliTRDCalPad.h"
82#include "./Cal/AliTRDCalDet.h"
83
84
85ClassImp(AliTRDCalibraFit)
86
87AliTRDCalibraFit* AliTRDCalibraFit::fgInstance = 0;
88Bool_t AliTRDCalibraFit::fgTerminated = kFALSE;
89
90//_____________singleton implementation_________________________________________________
91AliTRDCalibraFit *AliTRDCalibraFit::Instance()
92{
93 //
94 // Singleton implementation
95 //
96
97 if (fgTerminated != kFALSE) {
98 return 0;
99 }
100
101 if (fgInstance == 0) {
102 fgInstance = new AliTRDCalibraFit();
103 }
104
105 return fgInstance;
106
107}
55a288e5 108//______________________________________________________________________________________
109void AliTRDCalibraFit::Terminate()
110{
111 //
112 // Singleton implementation
113 // Deletes the instance of this class
114 //
115
116 fgTerminated = kTRUE;
117
118 if (fgInstance != 0) {
119 delete fgInstance;
120 fgInstance = 0;
121 }
122
123}
55a288e5 124//______________________________________________________________________________________
125AliTRDCalibraFit::AliTRDCalibraFit()
126 :TObject()
f162af62 127 ,fGeo(0)
3a0f6479 128 ,fNumberOfBinsExpected(0)
129 ,fMethod(0)
130 ,fBeginFitCharge(3.5)
131 ,fFitPHPeriode(1)
413153cb 132 ,fTakeTheMaxPH(kTRUE)
133 ,fT0Shift0(0.124797)
134 ,fT0Shift1(0.267451)
3a0f6479 135 ,fRangeFitPRF(1.0)
55a288e5 136 ,fAccCDB(kFALSE)
3a0f6479 137 ,fMinEntries(800)
138 ,fRebin(1)
54f2ff1c 139 ,fScaleGain(0.02431)
55a288e5 140 ,fNumberFit(0)
141 ,fNumberFitSuccess(0)
142 ,fNumberEnt(0)
143 ,fStatisticMean(0.0)
3a0f6479 144 ,fDebugStreamer(0x0)
145 ,fDebugLevel(0)
55a288e5 146 ,fFitVoir(0)
3a0f6479 147 ,fMagneticField(0.5)
148 ,fCalibraMode(new AliTRDCalibraMode())
149 ,fCurrentCoefE(0.0)
150 ,fCurrentCoefE2(0.0)
151 ,fDect1(0)
152 ,fDect2(0)
55a288e5 153 ,fScaleFitFactor(0.0)
154 ,fEntriesCurrent(0)
3a0f6479 155 ,fCountDet(0)
156 ,fCount(0)
64942b85 157 ,fNbDet(0)
3a0f6479 158 ,fCalDet(0x0)
159 ,fCalROC(0x0)
160 ,fCalDet2(0x0)
161 ,fCalROC2(0x0)
162 ,fCurrentCoefDetector(0x0)
163 ,fCurrentCoefDetector2(0x0)
164 ,fVectorFit(0)
165 ,fVectorFit2(0)
55a288e5 166{
167 //
168 // Default constructor
169 //
170
3a0f6479 171 fGeo = new AliTRDgeometry();
172
173 // Current variables initialised
174 for (Int_t k = 0; k < 2; k++) {
175 fCurrentCoef[k] = 0.0;
176 fCurrentCoef2[k] = 0.0;
55a288e5 177 }
55a288e5 178 for (Int_t i = 0; i < 3; i++) {
3a0f6479 179 fPhd[i] = 0.0;
180 fDet[i] = 0;
55a288e5 181 }
3a0f6479 182
55a288e5 183}
55a288e5 184//______________________________________________________________________________________
185AliTRDCalibraFit::AliTRDCalibraFit(const AliTRDCalibraFit &c)
3a0f6479 186:TObject(c)
187,fGeo(0)
188,fNumberOfBinsExpected(c.fNumberOfBinsExpected)
189,fMethod(c.fMethod)
190,fBeginFitCharge(c.fBeginFitCharge)
191,fFitPHPeriode(c.fFitPHPeriode)
192,fTakeTheMaxPH(c.fTakeTheMaxPH)
413153cb 193,fT0Shift0(c.fT0Shift0)
194,fT0Shift1(c.fT0Shift1)
3a0f6479 195,fRangeFitPRF(c.fRangeFitPRF)
196,fAccCDB(c.fAccCDB)
197,fMinEntries(c.fMinEntries)
198,fRebin(c.fRebin)
54f2ff1c 199,fScaleGain(c.fScaleGain)
3a0f6479 200,fNumberFit(c.fNumberFit)
201,fNumberFitSuccess(c.fNumberFitSuccess)
202,fNumberEnt(c.fNumberEnt)
203,fStatisticMean(c.fStatisticMean)
204,fDebugStreamer(0x0)
205,fDebugLevel(c.fDebugLevel)
206,fFitVoir(c.fFitVoir)
207,fMagneticField(c.fMagneticField)
208,fCalibraMode(0x0)
209,fCurrentCoefE(c.fCurrentCoefE)
210,fCurrentCoefE2(c.fCurrentCoefE2)
211,fDect1(c.fDect1)
212,fDect2(c.fDect2)
213,fScaleFitFactor(c.fScaleFitFactor)
214,fEntriesCurrent(c.fEntriesCurrent)
215,fCountDet(c.fCountDet)
216,fCount(c.fCount)
64942b85 217,fNbDet(c.fNbDet)
3a0f6479 218,fCalDet(0x0)
219,fCalROC(0x0)
220,fCalDet2(0x0)
221,fCalROC2(0x0)
222,fCurrentCoefDetector(0x0)
223,fCurrentCoefDetector2(0x0)
224,fVectorFit(0)
225,fVectorFit2(0)
55a288e5 226{
227 //
228 // Copy constructor
229 //
230
3a0f6479 231 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
232
233 //Current variables initialised
234 for (Int_t k = 0; k < 2; k++) {
235 fCurrentCoef[k] = 0.0;
236 fCurrentCoef2[k] = 0.0;
237 }
238 for (Int_t i = 0; i < 3; i++) {
239 fPhd[i] = 0.0;
240 fDet[i] = 0;
241 }
242 if(c.fCalDet) fCalDet = new AliTRDCalDet(*c.fCalDet);
243 if(c.fCalDet2) fCalDet2 = new AliTRDCalDet(*c.fCalDet2);
64942b85 244
3a0f6479 245 if(c.fCalROC) fCalROC = new AliTRDCalROC(*c.fCalROC);
246 if(c.fCalROC2) fCalROC = new AliTRDCalROC(*c.fCalROC2);
247
248 fVectorFit.SetName(c.fVectorFit.GetName());
249 for(Int_t k = 0; k < c.fVectorFit.GetEntriesFast(); k++){
250 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
251 Int_t detector = ((AliTRDFitInfo *)c.fVectorFit.UncheckedAt(k))->GetDetector();
252 Int_t ntotal = 1;
053767a4 253 if (GetStack(detector) == 2) {
3a0f6479 254 ntotal = 1728;
255 }
256 else {
257 ntotal = 2304;
258 }
259 Float_t *coef = new Float_t[ntotal];
260 for (Int_t i = 0; i < ntotal; i++) {
261 coef[i] = ((AliTRDFitInfo *)c.fVectorFit.UncheckedAt(k))->GetCoef()[i];
262 }
263 fitInfo->SetCoef(coef);
264 fitInfo->SetDetector(detector);
265 fVectorFit.Add((TObject *) fitInfo);
266 }
267 fVectorFit.SetName(c.fVectorFit.GetName());
268 for(Int_t k = 0; k < c.fVectorFit2.GetEntriesFast(); k++){
269 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
270 Int_t detector = ((AliTRDFitInfo *)c.fVectorFit2.UncheckedAt(k))->GetDetector();
271 Int_t ntotal = 1;
053767a4 272 if (GetStack(detector) == 2) {
3a0f6479 273 ntotal = 1728;
274 }
275 else {
276 ntotal = 2304;
277 }
278 Float_t *coef = new Float_t[ntotal];
279 for (Int_t i = 0; i < ntotal; i++) {
280 coef[i] = ((AliTRDFitInfo *)c.fVectorFit2.UncheckedAt(k))->GetCoef()[i];
281 }
282 fitInfo->SetCoef(coef);
283 fitInfo->SetDetector(detector);
284 fVectorFit2.Add((TObject *) fitInfo);
285 }
286 if (fGeo) {
287 delete fGeo;
288 }
289 fGeo = new AliTRDgeometry();
55a288e5 290
3a0f6479 291}
55a288e5 292//____________________________________________________________________________________
293AliTRDCalibraFit::~AliTRDCalibraFit()
294{
295 //
296 // AliTRDCalibraFit destructor
297 //
3a0f6479 298 if ( fDebugStreamer ) delete fDebugStreamer;
299 if ( fCalDet ) delete fCalDet;
300 if ( fCalDet2 ) delete fCalDet2;
301 if ( fCalROC ) delete fCalROC;
1ca79a00 302 if ( fCalROC2 ) delete fCalROC2;
303 if( fCurrentCoefDetector ) delete [] fCurrentCoefDetector;
304 if( fCurrentCoefDetector2 ) delete [] fCurrentCoefDetector2;
3a0f6479 305 fVectorFit.Delete();
306 fVectorFit2.Delete();
f162af62 307 if (fGeo) {
308 delete fGeo;
309 }
310
55a288e5 311}
55a288e5 312//_____________________________________________________________________________
313void AliTRDCalibraFit::Destroy()
314{
315 //
316 // Delete instance
317 //
318
319 if (fgInstance) {
320 delete fgInstance;
321 fgInstance = 0x0;
322 }
323
64942b85 324}
325//_____________________________________________________________________________
326void AliTRDCalibraFit::DestroyDebugStreamer()
327{
328 //
329 // Delete DebugStreamer
330 //
331
332 if ( fDebugStreamer ) delete fDebugStreamer;
333 fDebugStreamer = 0x0;
334
413153cb 335}
336//__________________________________________________________________________________
979b168f 337void AliTRDCalibraFit::RangeChargeIntegration(Float_t vdrift, Float_t t0, Int_t &begin, Int_t &peak, Int_t &end) const
413153cb 338{
339 //
340 // From the drift velocity and t0
341 // return the position of the peak and maximum negative slope
342 //
343
344 const Float_t kDrWidth = AliTRDgeometry::DrThick(); // drift region
345 Double_t widbins = 0.1; // 0.1 mus
346
347 //peak and maxnegslope in mus
348 Double_t begind = t0*widbins + fT0Shift0;
349 Double_t peakd = t0*widbins + fT0Shift1;
350 Double_t maxnegslope = (kDrWidth + vdrift*peakd)/vdrift;
351
352 // peak and maxnegslope in timebin
353 begin = TMath::Nint(begind*widbins);
354 peak = TMath::Nint(peakd*widbins);
355 end = TMath::Nint(maxnegslope*widbins);
356
55a288e5 357}
55a288e5 358//____________Functions fit Online CH2d________________________________________
979b168f 359Bool_t AliTRDCalibraFit::AnalyseCH(const TH2I *ch)
55a288e5 360{
361 //
362 // Fit the 1D histos, projections of the 2D ch on the Xaxis, for each
363 // calibration group normalized the resulted coefficients (to 1 normally)
55a288e5 364 //
365
3a0f6479 366 // Set the calibration mode
4c865c34 367 //const char *name = ch->GetTitle();
368 TString name = ch->GetTitle();
64942b85 369 if(!SetModeCalibration(name,0)) return kFALSE;
3a0f6479 370
371 // Number of Ybins (detectors or groups of pads)
372 Int_t nbins = ch->GetNbinsX();// charge
373 Int_t nybins = ch->GetNbinsY();// groups number
374 if (!InitFit(nybins,0)) {
55a288e5 375 return kFALSE;
376 }
3a0f6479 377 if (!InitFitCH()) {
55a288e5 378 return kFALSE;
379 }
380 fStatisticMean = 0.0;
381 fNumberFit = 0;
382 fNumberFitSuccess = 0;
383 fNumberEnt = 0;
55a288e5 384 // Init fCountDet and fCount
385 InitfCountDetAndfCount(0);
55a288e5 386 // Beginning of the loop betwwen dect1 and dect2
3a0f6479 387 for (Int_t idect = fDect1; idect < fDect2; idect++) {
388 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...
55a288e5 389 UpdatefCountDetAndfCount(idect,0);
55a288e5 390 ReconstructFitRowMinRowMax(idect, 0);
3a0f6479 391 // Take the histo
392 TH1I *projch = (TH1I *) ch->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
393 projch->SetDirectory(0);
55a288e5 394 // Number of entries for this calibration group
395 Double_t nentries = 0.0;
396 Double_t mean = 0.0;
3a0f6479 397 for (Int_t k = 0; k < nbins; k++) {
398 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
399 nentries += ch->GetBinContent(binnb);
55a288e5 400 mean += projch->GetBinCenter(k+1)*projch->GetBinContent(k+1);
3a0f6479 401 projch->SetBinError(k+1,TMath::Sqrt(projch->GetBinContent(k+1)));
55a288e5 402 }
3a0f6479 403 projch->SetEntries(nentries);
404 //printf("The number of entries for the group %d is %f\n",idect,nentries);
55a288e5 405 if (nentries > 0) {
406 fNumberEnt++;
407 mean /= nentries;
408 }
55a288e5 409 // Rebin and statistic stuff
55a288e5 410 if (fRebin > 1) {
411 projch = ReBin((TH1I *) projch);
412 }
413 // This detector has not enough statistics or was off
3a0f6479 414 if (nentries <= fMinEntries) {
415 NotEnoughStatisticCH(idect);
416 if (fDebugLevel != 1) {
55a288e5 417 delete projch;
418 }
419 continue;
420 }
55a288e5 421 // Statistics of the group fitted
55a288e5 422 fStatisticMean += nentries;
423 fNumberFit++;
3a0f6479 424 //Method choosen
425 switch(fMethod)
426 {
427 case 0: FitMeanW((TH1 *) projch, nentries); break;
428 case 1: FitMean((TH1 *) projch, nentries, mean); break;
429 case 2: FitCH((TH1 *) projch, mean); break;
430 case 3: FitBisCH((TH1 *) projch, mean); break;
431 default: return kFALSE;
432 }
55a288e5 433 // Fill Infos Fit
3a0f6479 434 FillInfosFitCH(idect);
55a288e5 435 // Memory!!!
3a0f6479 436 if (fDebugLevel != 1) {
55a288e5 437 delete projch;
438 }
55a288e5 439 } // Boucle object
55a288e5 440 // Normierungcharge
3a0f6479 441 if (fDebugLevel != 1) {
55a288e5 442 NormierungCharge();
443 }
55a288e5 444 // Mean Statistic
445 if (fNumberFit > 0) {
3a0f6479 446 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));
55a288e5 447 fStatisticMean = fStatisticMean / fNumberFit;
448 }
449 else {
450 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
451 }
3a0f6479 452 delete fDebugStreamer;
453 fDebugStreamer = 0x0;
454
55a288e5 455 return kTRUE;
55a288e5 456}
55a288e5 457//____________Functions fit Online CH2d________________________________________
3a0f6479 458Bool_t AliTRDCalibraFit::AnalyseCH(AliTRDCalibraVector *calvect)
55a288e5 459{
460 //
461 // Reconstruct a 1D histo from the vectorCH for each calibration group,
462 // fit the histo, normalized the resulted coefficients (to 1 normally)
55a288e5 463 //
464
3a0f6479 465 // Set the calibraMode
4c865c34 466 //const char *name = calvect->GetNameCH();
467 TString name = calvect->GetNameCH();
64942b85 468 if(!SetModeCalibration(name,0)) return kFALSE;
55a288e5 469
3a0f6479 470 // Number of Xbins (detectors or groups of pads)
471 if (!InitFit((432*calvect->GetDetCha0(0)+108*calvect->GetDetCha2(0)),0)) {
55a288e5 472 return kFALSE;
473 }
3a0f6479 474 if (!InitFitCH()) {
55a288e5 475 return kFALSE;
476 }
477 fStatisticMean = 0.0;
478 fNumberFit = 0;
479 fNumberFitSuccess = 0;
480 fNumberEnt = 0;
55a288e5 481 // Init fCountDet and fCount
482 InitfCountDetAndfCount(0);
55a288e5 483 // Beginning of the loop between dect1 and dect2
3a0f6479 484 for (Int_t idect = fDect1; idect < fDect2; idect++) {
485 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...........
55a288e5 486 UpdatefCountDetAndfCount(idect,0);
55a288e5 487 ReconstructFitRowMinRowMax(idect,0);
3a0f6479 488 // Take the histo
55a288e5 489 Double_t nentries = 0.0;
490 Double_t mean = 0.0;
e526983e 491 if(!calvect->GetCHEntries(fCountDet)) {
492 NotEnoughStatisticCH(idect);
493 continue;
494 }
495
496 TString tname("CH");
497 tname += idect;
498 TH1F *projch = calvect->ConvertVectorCHHisto(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0)))),(const char *) tname);
499 projch->SetDirectory(0);
500 for (Int_t k = 0; k < calvect->GetNumberBinCharge(); k++) {
501 nentries += projch->GetBinContent(k+1);
502 mean += projch->GetBinCenter(k+1)*projch->GetBinContent(k+1);
503 }
504 if (nentries > 0) {
505 fNumberEnt++;
506 mean /= nentries;
507 }
508 //printf("The number of entries for the group %d is %f\n",idect,nentries);
509 // Rebin
510 if (fRebin > 1) {
511 projch = ReBin((TH1F *) projch);
55a288e5 512 }
55a288e5 513 // This detector has not enough statistics or was not found in VectorCH
3a0f6479 514 if (nentries <= fMinEntries) {
515 NotEnoughStatisticCH(idect);
55a288e5 516 continue;
55a288e5 517 }
55a288e5 518 // Statistic of the histos fitted
55a288e5 519 fStatisticMean += nentries;
520 fNumberFit++;
3a0f6479 521 //Method choosen
522 switch(fMethod)
523 {
524 case 0: FitMeanW((TH1 *) projch, nentries); break;
525 case 1: FitMean((TH1 *) projch, nentries, mean); break;
526 case 2: FitCH((TH1 *) projch, mean); break;
527 case 3: FitBisCH((TH1 *) projch, mean); break;
528 default: return kFALSE;
529 }
55a288e5 530 // Fill Infos Fit
3a0f6479 531 FillInfosFitCH(idect);
55a288e5 532 } // Boucle object
55a288e5 533 // Normierungcharge
3a0f6479 534 if (fDebugLevel != 1) {
55a288e5 535 NormierungCharge();
536 }
55a288e5 537 // Mean Statistics
538 if (fNumberFit > 0) {
3a0f6479 539 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));
55a288e5 540 fStatisticMean = fStatisticMean / fNumberFit;
541 }
542 else {
543 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
544 }
3a0f6479 545 delete fDebugStreamer;
546 fDebugStreamer = 0x0;
55a288e5 547 return kTRUE;
55a288e5 548}
54f2ff1c 549//____________Functions fit Online CH2d________________________________________
550Double_t AliTRDCalibraFit::AnalyseCHAllTogether(const TH2I *ch)
551{
552 //
553 // Fit the 1D histos, projections of the 2D ch on the Xaxis, for each
554 // calibration group normalized the resulted coefficients (to 1 normally)
555 //
556 Int_t nbins = ch->GetNbinsX();// charge
557 Int_t nybins = ch->GetNbinsY();// groups number
558 // Take the histo
559 TH1I *projch = (TH1I *) ch->ProjectionX("projch",1,nybins+1,(Option_t *)"e");
560 projch->SetDirectory(0);
561 // Number of entries for this calibration group
562 Double_t nentries = 0.0;
563 Double_t mean = 0.0;
564 for (Int_t k = 0; k < nbins; k++) {
565 nentries += projch->GetBinContent(k+1);
566 mean += projch->GetBinCenter(k+1)*projch->GetBinContent(k+1);
567 projch->SetBinError(k+1,TMath::Sqrt(projch->GetBinContent(k+1)));
568 }
569 projch->SetEntries(nentries);
570 //printf("The number of entries for the group %d is %f\n",idect,nentries);
571 if (nentries > 0) {
572 fNumberEnt++;
573 mean /= nentries;
574 }
575 // This detector has not enough statistics or was off
576 if (nentries <= fMinEntries) {
577 delete projch;
578 AliInfo(Form("There are %d entries for all together, it is not enough (%d)",(Int_t) nentries, fMinEntries));
579 return -100.0;
580 }
581 //Method choosen
582 switch(fMethod)
583 {
584 case 0: FitMeanW((TH1 *) projch, nentries); break;
585 case 1: FitMean((TH1 *) projch, nentries, mean); break;
586 case 2: FitCH((TH1 *) projch, mean); break;
587 case 3: FitBisCH((TH1 *) projch, mean); break;
588 default: return kFALSE;
589 }
590 delete fDebugStreamer;
591 fDebugStreamer = 0x0;
592
593 if(fCurrentCoef[0] > 0.0) return fCurrentCoef[0];
594 else return -100.0;
595
596}
3a0f6479 597//________________functions fit Online PH2d____________________________________
979b168f 598Bool_t AliTRDCalibraFit::AnalysePH(const TProfile2D *ph)
55a288e5 599{
600 //
3a0f6479 601 // Take the 1D profiles (average pulse height), projections of the 2D PH
602 // on the Xaxis, for each calibration group
603 // Reconstruct a drift velocity
604 // A first calibration of T0 is also made using the same method
55a288e5 605 //
606
3a0f6479 607 // Set the calibration mode
4c865c34 608 //const char *name = ph->GetTitle();
609 TString name = ph->GetTitle();
64942b85 610 if(!SetModeCalibration(name,1)) return kFALSE;
3a0f6479 611
6aafa7ea 612 //printf("Mode calibration set\n");
613
3a0f6479 614 // Number of Xbins (detectors or groups of pads)
615 Int_t nbins = ph->GetNbinsX();// time
616 Int_t nybins = ph->GetNbinsY();// calibration group
617 if (!InitFit(nybins,1)) {
55a288e5 618 return kFALSE;
619 }
6aafa7ea 620
621 //printf("Init fit\n");
622
3a0f6479 623 if (!InitFitPH()) {
55a288e5 624 return kFALSE;
625 }
6aafa7ea 626
627 //printf("Init fit PH\n");
628
55a288e5 629 fStatisticMean = 0.0;
630 fNumberFit = 0;
631 fNumberFitSuccess = 0;
632 fNumberEnt = 0;
55a288e5 633 // Init fCountDet and fCount
3a0f6479 634 InitfCountDetAndfCount(1);
6aafa7ea 635 //printf("Init Count Det and fCount %d, %d\n",fDect1,fDect2);
636
3a0f6479 637 // Beginning of the loop
638 for (Int_t idect = fDect1; idect < fDect2; idect++) {
6aafa7ea 639 //printf("idect = %d\n",idect);
3a0f6479 640 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi.......
641 UpdatefCountDetAndfCount(idect,1);
642 ReconstructFitRowMinRowMax(idect,1);
643 // Take the histo
644 TH1D *projph = (TH1D *) ph->ProjectionX("projph",idect+1,idect+1,(Option_t *) "e");
645 projph->SetDirectory(0);
646 // Number of entries for this calibration group
647 Double_t nentries = 0;
648 for (Int_t k = 0; k < nbins; k++) {
649 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
650 nentries += ph->GetBinEntries(binnb);
55a288e5 651 }
55a288e5 652 if (nentries > 0) {
3a0f6479 653 fNumberEnt++;
654 }
655 //printf("The number of entries for the group %d is %f\n",idect,nentries);
656 // This detector has not enough statistics or was off
657 if (nentries <= fMinEntries) {
658 //printf("Not enough statistic!\n");
64942b85 659 NotEnoughStatisticPH(idect,nentries);
3a0f6479 660 if (fDebugLevel != 1) {
661 delete projph;
662 }
55a288e5 663 continue;
55a288e5 664 }
3a0f6479 665 // Statistics of the histos fitted
55a288e5 666 fNumberFit++;
667 fStatisticMean += nentries;
3a0f6479 668 // Calcul of "real" coef
669 CalculVdriftCoefMean();
670 CalculT0CoefMean();
671 //Method choosen
6aafa7ea 672 //printf("Method\n");
3a0f6479 673 switch(fMethod)
674 {
675 case 0: FitLagrangePoly((TH1 *) projph); break;
676 case 1: FitPente((TH1 *) projph); break;
677 case 2: FitPH((TH1 *) projph,(Int_t) (idect - fDect1)); break;
678 default: return kFALSE;
679 }
680 // Fill the tree if end of a detector or only the pointer to the branch!!!
64942b85 681 FillInfosFitPH(idect,nentries);
3a0f6479 682 // Memory!!!
683 if (fDebugLevel != 1) {
684 delete projph;
55a288e5 685 }
55a288e5 686 } // Boucle object
55a288e5 687 // Mean Statistic
688 if (fNumberFit > 0) {
3a0f6479 689 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));
55a288e5 690 fStatisticMean = fStatisticMean / fNumberFit;
691 }
692 else {
693 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
694 }
3a0f6479 695 delete fDebugStreamer;
696 fDebugStreamer = 0x0;
55a288e5 697 return kTRUE;
55a288e5 698}
3a0f6479 699//____________Functions fit Online PH2d________________________________________
700Bool_t AliTRDCalibraFit::AnalysePH(AliTRDCalibraVector *calvect)
55a288e5 701{
702 //
3a0f6479 703 // Reconstruct the average pulse height from the vectorPH for each
704 // calibration group
705 // Reconstruct a drift velocity
55a288e5 706 // A first calibration of T0 is also made using the same method (slope method)
707 //
708
3a0f6479 709 // Set the calibration mode
4c865c34 710 //const char *name = calvect->GetNamePH();
711 TString name = calvect->GetNamePH();
64942b85 712 if(!SetModeCalibration(name,1)) return kFALSE;
3a0f6479 713
714 // Number of Xbins (detectors or groups of pads)
715 if (!InitFit((432*calvect->GetDetCha0(1)+108*calvect->GetDetCha2(1)),1)) {
55a288e5 716 return kFALSE;
717 }
3a0f6479 718 if (!InitFitPH()) {
55a288e5 719 return kFALSE;
720 }
721 fStatisticMean = 0.0;
722 fNumberFit = 0;
723 fNumberFitSuccess = 0;
724 fNumberEnt = 0;
55a288e5 725 // Init fCountDet and fCount
726 InitfCountDetAndfCount(1);
55a288e5 727 // Beginning of the loop
3a0f6479 728 for (Int_t idect = fDect1; idect < fDect2; idect++) {
729 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...........
55a288e5 730 UpdatefCountDetAndfCount(idect,1);
55a288e5 731 ReconstructFitRowMinRowMax(idect,1);
3a0f6479 732 // Take the histo
3a0f6479 733 fEntriesCurrent = 0;
e526983e 734 if(!calvect->GetPHEntries(fCountDet)) {
735 NotEnoughStatisticPH(idect,fEntriesCurrent);
736 continue;
3a0f6479 737 }
e526983e 738 TString tname("PH");
739 tname += idect;
740 TH1F *projph = calvect->CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPHTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname)),fEntriesCurrent);
741 projph->SetDirectory(0);
742 if(fEntriesCurrent > 0) fNumberEnt++;
3a0f6479 743 //printf("The number of entries for the group %d is %d\n",idect,fEntriesCurrent);
55a288e5 744 // This detector has not enough statistics or was off
3a0f6479 745 if (fEntriesCurrent <= fMinEntries) {
746 //printf("Not enough stat!\n");
64942b85 747 NotEnoughStatisticPH(idect,fEntriesCurrent);
55a288e5 748 continue;
55a288e5 749 }
3a0f6479 750 // Statistic of the histos fitted
55a288e5 751 fNumberFit++;
3a0f6479 752 fStatisticMean += fEntriesCurrent;
55a288e5 753 // Calcul of "real" coef
3a0f6479 754 CalculVdriftCoefMean();
755 CalculT0CoefMean();
756 //Method choosen
757 switch(fMethod)
758 {
759 case 0: FitLagrangePoly((TH1 *) projph); break;
760 case 1: FitPente((TH1 *) projph); break;
761 case 2: FitPH((TH1 *) projph,(Int_t) (idect - fDect1)); break;
762 default: return kFALSE;
763 }
55a288e5 764 // Fill the tree if end of a detector or only the pointer to the branch!!!
64942b85 765 FillInfosFitPH(idect,fEntriesCurrent);
55a288e5 766 } // Boucle object
e526983e 767
55a288e5 768 // Mean Statistic
769 if (fNumberFit > 0) {
3a0f6479 770 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));
55a288e5 771 fStatisticMean = fStatisticMean / fNumberFit;
772 }
773 else {
774 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
775 }
3a0f6479 776 delete fDebugStreamer;
777 fDebugStreamer = 0x0;
55a288e5 778 return kTRUE;
55a288e5 779}
3a0f6479 780//____________Functions fit Online PRF2d_______________________________________
979b168f 781Bool_t AliTRDCalibraFit::AnalysePRF(const TProfile2D *prf)
55a288e5 782{
783 //
3a0f6479 784 // Take the 1D profiles (pad response function), projections of the 2D PRF
785 // on the Xaxis, for each calibration group
786 // Fit with a gaussian to reconstruct the sigma of the pad response function
55a288e5 787 //
788
3a0f6479 789 // Set the calibration mode
4c865c34 790 //const char *name = prf->GetTitle();
791 TString name = prf->GetTitle();
64942b85 792 if(!SetModeCalibration(name,2)) return kFALSE;
55a288e5 793
3a0f6479 794 // Number of Ybins (detectors or groups of pads)
795 Int_t nybins = prf->GetNbinsY();// calibration groups
796 Int_t nbins = prf->GetNbinsX();// bins
797 Int_t nbg = GetNumberOfGroupsPRF((const char *)prf->GetTitle());
798 if((nbg > 0) || (nbg == -1)) return kFALSE;
799 if (!InitFit(nybins,2)) {
55a288e5 800 return kFALSE;
801 }
3a0f6479 802 if (!InitFitPRF()) {
55a288e5 803 return kFALSE;
804 }
805 fStatisticMean = 0.0;
806 fNumberFit = 0;
807 fNumberFitSuccess = 0;
808 fNumberEnt = 0;
55a288e5 809 // Init fCountDet and fCount
3a0f6479 810 InitfCountDetAndfCount(2);
55a288e5 811 // Beginning of the loop
3a0f6479 812 for (Int_t idect = fDect1; idect < fDect2; idect++) {
813 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi......
814 UpdatefCountDetAndfCount(idect,2);
815 ReconstructFitRowMinRowMax(idect,2);
816 // Take the histo
817 TH1D *projprf = (TH1D *) prf->ProjectionX("projprf",idect+1,idect+1,(Option_t *) "e");
818 projprf->SetDirectory(0);
819 // Number of entries for this calibration group
820 Double_t nentries = 0;
821 for (Int_t k = 0; k < nbins; k++) {
822 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
823 nentries += prf->GetBinEntries(binnb);
55a288e5 824 }
3a0f6479 825 if(nentries > 0) fNumberEnt++;
55a288e5 826 // This detector has not enough statistics or was off
3a0f6479 827 if (nentries <= fMinEntries) {
828 NotEnoughStatisticPRF(idect);
829 if (fDebugLevel != 1) {
830 delete projprf;
55a288e5 831 }
55a288e5 832 continue;
55a288e5 833 }
3a0f6479 834 // Statistics of the histos fitted
55a288e5 835 fNumberFit++;
3a0f6479 836 fStatisticMean += nentries;
55a288e5 837 // Calcul of "real" coef
3a0f6479 838 CalculPRFCoefMean();
839 //Method choosen
840 switch(fMethod)
841 {
842 case 0: FitPRF((TH1 *) projprf); break;
843 case 1: RmsPRF((TH1 *) projprf); break;
844 default: return kFALSE;
845 }
55a288e5 846 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 847 FillInfosFitPRF(idect);
55a288e5 848 // Memory!!!
3a0f6479 849 if (fDebugLevel != 1) {
850 delete projprf;
55a288e5 851 }
55a288e5 852 } // Boucle object
55a288e5 853 // Mean Statistic
854 if (fNumberFit > 0) {
855 AliInfo(Form("There are %d with at least one entries.",fNumberEnt));
856 AliInfo(Form("%d fits have been proceeded (sucessfully or not...).",fNumberFit));
857 AliInfo(Form("There is a mean statistic of: %d over these fitted histograms and %d successfulled fits"
858 ,(Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
859 fStatisticMean = fStatisticMean / fNumberFit;
860 }
861 else {
862 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
863 }
3a0f6479 864 delete fDebugStreamer;
865 fDebugStreamer = 0x0;
55a288e5 866 return kTRUE;
55a288e5 867}
3a0f6479 868//____________Functions fit Online PRF2d_______________________________________
979b168f 869Bool_t AliTRDCalibraFit::AnalysePRFMarianFit(const TProfile2D *prf)
55a288e5 870{
871 //
3a0f6479 872 // Take the 1D profiles (pad response function), projections of the 2D PRF
873 // on the Xaxis, for each calibration group
874 // Fit with a gaussian to reconstruct the sigma of the pad response function
55a288e5 875 //
3a0f6479 876
877 // Set the calibration mode
4c865c34 878 //const char *name = prf->GetTitle();
879 TString name = prf->GetTitle();
64942b85 880 if(!SetModeCalibration(name,2)) return kFALSE;
3a0f6479 881
882 // Number of Ybins (detectors or groups of pads)
883 TAxis *xprf = prf->GetXaxis();
884 TAxis *yprf = prf->GetYaxis();
885 Int_t nybins = yprf->GetNbins();// calibration groups
886 Int_t nbins = xprf->GetNbins();// bins
887 Float_t lowedge = (Float_t) xprf->GetBinLowEdge(1);//lowedge in bins
888 Float_t upedge = (Float_t) xprf->GetBinUpEdge(nbins);//upedge in bins
889 Int_t nbg = GetNumberOfGroupsPRF((const char *)name);
890 if(nbg == -1) return kFALSE;
891 if(nbg > 0) fMethod = 1;
892 else fMethod = 0;
893 if (!InitFit(nybins,2)) {
55a288e5 894 return kFALSE;
895 }
3a0f6479 896 if (!InitFitPRF()) {
55a288e5 897 return kFALSE;
898 }
899 fStatisticMean = 0.0;
3a0f6479 900 fNumberFit = 0;
55a288e5 901 fNumberFitSuccess = 0;
902 fNumberEnt = 0;
55a288e5 903 // Init fCountDet and fCount
3a0f6479 904 InitfCountDetAndfCount(2);
55a288e5 905 // Beginning of the loop
3a0f6479 906 for (Int_t idect = fDect1; idect < fDect2; idect++) {
907 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi.......
908 UpdatefCountDetAndfCount(idect,2);
909 ReconstructFitRowMinRowMax(idect,2);
910 // Build the array of entries and sum
911 TArrayD arraye = TArrayD(nbins);
912 TArrayD arraym = TArrayD(nbins);
913 TArrayD arrayme = TArrayD(nbins);
914 Double_t nentries = 0;
915 //printf("nbins %d\n",nbins);
916 for (Int_t k = 0; k < nbins; k++) {
917 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
918 Double_t entries = (Double_t)prf->GetBinEntries(binnb);
919 Double_t mean = (Double_t)prf->GetBinContent(binnb);
920 Double_t error = (Double_t)prf->GetBinError(binnb);
921 //printf("for %d we have %f\n",k,entries);
922 nentries += entries;
923 arraye.AddAt(entries,k);
924 arraym.AddAt(mean,k);
925 arrayme.AddAt(error,k);
55a288e5 926 }
3a0f6479 927 if(nentries > 0) fNumberEnt++;
928 //printf("The number of entries for the group %d is %f\n",idect,nentries);
55a288e5 929 // This detector has not enough statistics or was off
3a0f6479 930 if (nentries <= fMinEntries) {
931 NotEnoughStatisticPRF(idect);
55a288e5 932 continue;
55a288e5 933 }
55a288e5 934 // Statistics of the histos fitted
55a288e5 935 fNumberFit++;
3a0f6479 936 fStatisticMean += nentries;
55a288e5 937 // Calcul of "real" coef
3a0f6479 938 CalculPRFCoefMean();
939 //Method choosen
940 switch(fMethod)
941 {
942 case 0: FitPRFGausMI( arraye.GetArray(), arraym.GetArray(), arrayme.GetArray(), nbins, lowedge, upedge); break;
943 case 1: FitTnpRange( arraye.GetArray(), arraym.GetArray(), arrayme.GetArray(), nbg, nbins); break;
944 default: return kFALSE;
945 }
55a288e5 946 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 947 FillInfosFitPRF(idect);
55a288e5 948 } // Boucle object
3a0f6479 949 // Mean Statistic
55a288e5 950 if (fNumberFit > 0) {
951 AliInfo(Form("There are %d with at least one entries.",fNumberEnt));
952 AliInfo(Form("%d fits have been proceeded (sucessfully or not...).",fNumberFit));
953 AliInfo(Form("There is a mean statistic of: %d over these fitted histograms and %d successfulled fits"
954 ,(Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
955 fStatisticMean = fStatisticMean / fNumberFit;
956 }
957 else {
958 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
959 }
3a0f6479 960 delete fDebugStreamer;
961 fDebugStreamer = 0x0;
55a288e5 962 return kTRUE;
55a288e5 963}
55a288e5 964//____________Functions fit Online PRF2d_______________________________________
3a0f6479 965Bool_t AliTRDCalibraFit::AnalysePRF(AliTRDCalibraVector *calvect)
55a288e5 966{
967 //
3a0f6479 968 // Reconstruct the 1D histo (pad response function) from the vectorPRD for
969 // each calibration group
55a288e5 970 // Fit with a gaussian to reconstruct the sigma of the pad response function
55a288e5 971 //
972
3a0f6479 973 // Set the calibra mode
4c865c34 974 //const char *name = calvect->GetNamePRF();
975 TString name = calvect->GetNamePRF();
64942b85 976 if(!SetModeCalibration(name,2)) return kFALSE;
3a0f6479 977 //printf("test0 %s\n",name);
55a288e5 978
979 // Number of Xbins (detectors or groups of pads)
3a0f6479 980 if (!InitFit((432*calvect->GetDetCha0(2)+108*calvect->GetDetCha2(2)),2)) {
981 //printf("test1\n");
982 return kFALSE;
983 }
984 if (!InitFitPRF()) {
985 ///printf("test2\n");
55a288e5 986 return kFALSE;
987 }
988 fStatisticMean = 0.0;
989 fNumberFit = 0;
990 fNumberFitSuccess = 0;
991 fNumberEnt = 0;
55a288e5 992 // Init fCountDet and fCount
993 InitfCountDetAndfCount(2);
55a288e5 994 // Beginning of the loop
3a0f6479 995 for (Int_t idect = fDect1; idect < fDect2; idect++) {
996 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi........
55a288e5 997 UpdatefCountDetAndfCount(idect,2);
55a288e5 998 ReconstructFitRowMinRowMax(idect,2);
3a0f6479 999 // Take the histo
3a0f6479 1000 fEntriesCurrent = 0;
e526983e 1001 if(!calvect->GetPRFEntries(fCountDet)) {
1002 NotEnoughStatisticPRF(idect);
1003 continue;
3a0f6479 1004 }
e526983e 1005 TString tname("PRF");
1006 tname += idect;
1007 TH1F *projprf = calvect->CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname)),fEntriesCurrent);
1008 projprf->SetDirectory(0);
1009 if(fEntriesCurrent > 0) fNumberEnt++;
55a288e5 1010 // This detector has not enough statistics or was off
3a0f6479 1011 if (fEntriesCurrent <= fMinEntries) {
1012 NotEnoughStatisticPRF(idect);
55a288e5 1013 continue;
55a288e5 1014 }
3a0f6479 1015 // Statistic of the histos fitted
55a288e5 1016 fNumberFit++;
3a0f6479 1017 fStatisticMean += fEntriesCurrent;
55a288e5 1018 // Calcul of "real" coef
3a0f6479 1019 CalculPRFCoefMean();
1020 //Method choosen
1021 switch(fMethod)
1022 {
1023 case 1: FitPRF((TH1 *) projprf); break;
1024 case 2: RmsPRF((TH1 *) projprf); break;
1025 default: return kFALSE;
1026 }
55a288e5 1027 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 1028 FillInfosFitPRF(idect);
55a288e5 1029 } // Boucle object
3a0f6479 1030 // Mean Statistics
55a288e5 1031 if (fNumberFit > 0) {
3a0f6479 1032 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));
55a288e5 1033 }
1034 else {
1035 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
1036 }
3a0f6479 1037 delete fDebugStreamer;
1038 fDebugStreamer = 0x0;
55a288e5 1039 return kTRUE;
55a288e5 1040}
55a288e5 1041//____________Functions fit Online PRF2d_______________________________________
3a0f6479 1042Bool_t AliTRDCalibraFit::AnalysePRFMarianFit(AliTRDCalibraVector *calvect)
55a288e5 1043{
1044 //
1045 // Reconstruct the 1D histo (pad response function) from the vectorPRD for
1046 // each calibration group
1047 // Fit with a gaussian to reconstruct the sigma of the pad response function
55a288e5 1048 //
1049
3a0f6479 1050 // Set the calibra mode
4c865c34 1051 //const char *name = calvect->GetNamePRF();
1052 TString name = calvect->GetNamePRF();
64942b85 1053 if(!SetModeCalibration(name,2)) return kFALSE;
3a0f6479 1054 //printf("test0 %s\n",name);
1055 Int_t nbg = GetNumberOfGroupsPRF((const char *)name);
64942b85 1056 //printf("test1 %d\n",nbg);
3a0f6479 1057 if(nbg == -1) return kFALSE;
1058 if(nbg > 0) fMethod = 1;
1059 else fMethod = 0;
1060 // Number of Xbins (detectors or groups of pads)
1061 if (!InitFit((432*calvect->GetDetCha0(2)+108*calvect->GetDetCha2(2)),2)) {
1062 //printf("test2\n");
55a288e5 1063 return kFALSE;
1064 }
3a0f6479 1065 if (!InitFitPRF()) {
1066 //printf("test3\n");
55a288e5 1067 return kFALSE;
1068 }
1069 fStatisticMean = 0.0;
1070 fNumberFit = 0;
1071 fNumberFitSuccess = 0;
1072 fNumberEnt = 0;
3a0f6479 1073 // Variables
1074 Int_t nbins = 0;
1075 Double_t *arrayx = 0;
1076 Double_t *arraye = 0;
1077 Double_t *arraym = 0;
1078 Double_t *arrayme = 0;
1079 Float_t lowedge = 0.0;
1080 Float_t upedge = 0.0;
55a288e5 1081 // Init fCountDet and fCount
1082 InitfCountDetAndfCount(2);
55a288e5 1083 // Beginning of the loop
3a0f6479 1084 for (Int_t idect = fDect1; idect < fDect2; idect++) {
1085 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi......
55a288e5 1086 UpdatefCountDetAndfCount(idect,2);
55a288e5 1087 ReconstructFitRowMinRowMax(idect,2);
3a0f6479 1088 // Take the histo
3a0f6479 1089 fEntriesCurrent = 0;
e526983e 1090 if(!calvect->GetPRFEntries(fCountDet)) {
1091 NotEnoughStatisticPRF(idect);
1092 continue;
3a0f6479 1093 }
e526983e 1094 TString tname("PRF");
1095 tname += idect;
1096 TGraphErrors *projprftree = calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname);
1097 nbins = projprftree->GetN();
1098 arrayx = (Double_t *)projprftree->GetX();
1099 arraye = (Double_t *)projprftree->GetEX();
1100 arraym = (Double_t *)projprftree->GetY();
1101 arrayme = (Double_t *)projprftree->GetEY();
1102 Float_t step = arrayx[1]-arrayx[0];
1103 lowedge = arrayx[0] - step/2.0;
1104 upedge = arrayx[(nbins-1)] + step/2.0;
1105 //printf("nbins est %d\n",nbins);
1106 for(Int_t k = 0; k < nbins; k++){
1107 fEntriesCurrent += (Int_t)arraye[k];
1108 //printf("for %d we have %f, %f\n",k,arraye[k],((projprftree->GetEX())[k]));
1109 if(arraye[k]>0.0) arrayme[k] = TMath::Sqrt(TMath::Abs(arrayme[k]-arraym[k]*arraym[k])/arraye[k]);
1110 }
1111 if(fEntriesCurrent > 0) fNumberEnt++;
3a0f6479 1112 //printf("The number of entries for the group %d is %d\n",idect,fEntriesCurrent);
1113 // This detector has not enough statistics or was off
1114 if (fEntriesCurrent <= fMinEntries) {
1115 NotEnoughStatisticPRF(idect);
55a288e5 1116 continue;
55a288e5 1117 }
55a288e5 1118 // Statistic of the histos fitted
55a288e5 1119 fNumberFit++;
1120 fStatisticMean += fEntriesCurrent;
55a288e5 1121 // Calcul of "real" coef
3a0f6479 1122 CalculPRFCoefMean();
1123 //Method choosen
1124 switch(fMethod)
1125 {
1126 case 0: FitPRFGausMI(arraye,arraym,arrayme,nbins,lowedge,upedge); break;
1127 case 1: FitTnpRange(arraye,arraym,arrayme,nbg,nbins); break;
1128 default: return kFALSE;
1129 }
55a288e5 1130 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 1131 FillInfosFitPRF(idect);
55a288e5 1132 } // Boucle object
55a288e5 1133 // Mean Statistics
1134 if (fNumberFit > 0) {
3a0f6479 1135 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));
55a288e5 1136 }
1137 else {
1138 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
1139 }
3a0f6479 1140 delete fDebugStreamer;
1141 fDebugStreamer = 0x0;
55a288e5 1142 return kTRUE;
55a288e5 1143}
3a0f6479 1144//____________Functions fit Online CH2d________________________________________
1145Bool_t AliTRDCalibraFit::AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli)
55a288e5 1146{
1147 //
3a0f6479 1148 // The linear method
55a288e5 1149 //
1150
55a288e5 1151 fStatisticMean = 0.0;
1152 fNumberFit = 0;
1153 fNumberFitSuccess = 0;
1154 fNumberEnt = 0;
3a0f6479 1155 if(!InitFitLinearFitter()) return kFALSE;
55a288e5 1156
3a0f6479 1157
1158 for(Int_t idet = 0; idet < 540; idet++){
55a288e5 1159
55a288e5 1160
3a0f6479 1161 //printf("detector number %d\n",idet);
55a288e5 1162
3a0f6479 1163 // Take the result
1164 TVectorD param(2);
1165 TVectorD error(3);
1166 fEntriesCurrent = 0;
1167 fCountDet = idet;
1168 Bool_t here = calivdli->GetParam(idet,&param);
1169 Bool_t heree = calivdli->GetError(idet,&error);
1170 //printf("here %d and heree %d\n",here, heree);
1171 if(heree) {
1172 fEntriesCurrent = (Int_t) error[2];
55a288e5 1173 fNumberEnt++;
55a288e5 1174 }
3a0f6479 1175 //printf("Number of entries %d\n",fEntriesCurrent);
1176 // Nothing found or not enough statistic
1177 if((!heree) || (!here) || (fEntriesCurrent <= fMinEntries)) {
1178 NotEnoughStatisticLinearFitter();
1179 continue;
1180 }
1181 //param.Print();
1182 //error.Print();
1183 //Statistics
1184 fNumberFit++;
1185 fStatisticMean += fEntriesCurrent;
55a288e5 1186
3a0f6479 1187 // Check the fit
1188 if((-(param[1])) <= 0.0) {
1189 NotEnoughStatisticLinearFitter();
1190 continue;
1191 }
55a288e5 1192
3a0f6479 1193 // CalculDatabaseVdriftandTan
1194 CalculVdriftLorentzCoef();
55a288e5 1195
3a0f6479 1196 // Statistics
1197 fNumberFitSuccess ++;
55a288e5 1198
3a0f6479 1199 // Put the fCurrentCoef
1200 fCurrentCoef[0] = -param[1];
1201 // here the database must be the one of the reconstruction for the lorentz angle....
1202 fCurrentCoef2[0] = (param[0]+fCurrentCoef[1]*fCurrentCoef2[1])/fCurrentCoef[0];
1203 fCurrentCoefE = error[1];
1204 fCurrentCoefE2 = error[0];
daa7dc79 1205 if((TMath::Abs(fCurrentCoef2[0]) > 0.0000001) && (TMath::Abs(param[0]) > 0.0000001)){
3a0f6479 1206 fCurrentCoefE2 = (fCurrentCoefE2/param[0]+fCurrentCoefE/fCurrentCoef[0])*fCurrentCoef2[0];
1207 }
55a288e5 1208
3a0f6479 1209 // Fill
1210 FillInfosFitLinearFitter();
55a288e5 1211
55a288e5 1212
55a288e5 1213 }
55a288e5 1214 // Mean Statistics
1215 if (fNumberFit > 0) {
3a0f6479 1216 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));
55a288e5 1217 }
1218 else {
1219 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
1220 }
3a0f6479 1221 delete fDebugStreamer;
1222 fDebugStreamer = 0x0;
55a288e5 1223 return kTRUE;
1224
54f2ff1c 1225}
1226//____________Functions fit Online CH2d________________________________________
1227Double_t AliTRDCalibraFit::AnalyseLinearFittersAllTogether(AliTRDCalibraVdriftLinearFit *calivdli)
1228{
1229 //
1230 // The linear method
1231 //
1232
1233 // Add histos
1234
1235 TH2S *linearfitterhisto = 0x0;
1236
1237 for(Int_t idet = 0; idet < 540; idet++){
1238
1239 TH2S * u = calivdli->GetLinearFitterHistoForce(idet);
1240 if(idet == 0) linearfitterhisto = u;
1241 else linearfitterhisto->Add(u);
1242
1243 }
1244
1245 // Fit
1246
1247 Int_t entries = 0;
1248 TAxis *xaxis = linearfitterhisto->GetXaxis();
1249 TAxis *yaxis = linearfitterhisto->GetYaxis();
1250 TLinearFitter linearfitter = TLinearFitter(2,"pol1");
1251 //printf("test\n");
1252 Double_t integral = linearfitterhisto->Integral();
1253 //printf("Integral is %f\n",integral);
1254 Bool_t securitybreaking = kFALSE;
1255 if(TMath::Abs(integral-1199) < 0.00001) securitybreaking = kTRUE;
1256 for(Int_t ibinx = 0; ibinx < linearfitterhisto->GetNbinsX(); ibinx++){
1257 for(Int_t ibiny = 0; ibiny < linearfitterhisto->GetNbinsY(); ibiny++){
1258 if(linearfitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){
1259 Double_t x = xaxis->GetBinCenter(ibinx+1);
1260 Double_t y = yaxis->GetBinCenter(ibiny+1);
1261
1262 for(Int_t k = 0; k < (Int_t)linearfitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){
1263 if(!securitybreaking){
1264 linearfitter.AddPoint(&x,y);
1265 entries++;
1266 }
1267 else {
1268 if(entries< 1198){
1269 linearfitter.AddPoint(&x,y);
1270 entries++;
1271 }
1272 }
1273 }
1274
1275 }
1276 }
1277 }
1278
1279 //printf("Find %d entries for the detector %d\n",arrayI[cb],cb);
1280
1281 // Eval the linear fitter
1282 if(entries > fMinEntries){
1283 TVectorD par = TVectorD(2);
1284 //printf("Fit\n");
1285 if((linearfitter.EvalRobust(0.8)==0)) {
1286 //printf("Take the param\n");
1287 linearfitter.GetParameters(par);
1288 //printf("Done\n");
1289 //par.Print();
1290 //printf("Finish\n");
1291 // Put the fCurrentCoef
1292 fCurrentCoef[0] = -par[1];
1293 // here the database must be the one of the reconstruction for the lorentz angle....
1294 fCurrentCoef2[0] = (par[0]+fCurrentCoef[1]*fCurrentCoef2[1])/fCurrentCoef[0];
1295
1296 return fCurrentCoef[0];
1297 }
1298 else return -100.0;
1299
1300
1301 }
1302 else {
1303 return -100.0;
1304 }
1305
1306 delete linearfitterhisto;
1307 delete fDebugStreamer;
1308 fDebugStreamer = 0x0;
1309
55a288e5 1310}
55a288e5 1311//____________Functions for seeing if the pad is really okey___________________
3a0f6479 1312//_____________________________________________________________________________
4c865c34 1313Int_t AliTRDCalibraFit::GetNumberOfGroupsPRF(TString nametitle)
3a0f6479 1314{
1315 //
1316 // Get numberofgroupsprf
1317 //
1318
1319 // Some patterns
1320 const Char_t *pattern0 = "Ngp0";
1321 const Char_t *pattern1 = "Ngp1";
1322 const Char_t *pattern2 = "Ngp2";
1323 const Char_t *pattern3 = "Ngp3";
1324 const Char_t *pattern4 = "Ngp4";
1325 const Char_t *pattern5 = "Ngp5";
1326 const Char_t *pattern6 = "Ngp6";
1327
1328 // Nrphi mode
4c865c34 1329 if (strstr(nametitle.Data(),pattern0)) {
3a0f6479 1330 return 0;
1331 }
4c865c34 1332 if (strstr(nametitle.Data(),pattern1)) {
3a0f6479 1333 return 1;
1334 }
4c865c34 1335 if (strstr(nametitle.Data(),pattern2)) {
3a0f6479 1336 return 2;
1337 }
4c865c34 1338 if (strstr(nametitle.Data(),pattern3)) {
3a0f6479 1339 return 3;
1340 }
4c865c34 1341 if (strstr(nametitle.Data(),pattern4)) {
3a0f6479 1342 return 4;
1343 }
4c865c34 1344 if (strstr(nametitle.Data(),pattern5)) {
3a0f6479 1345 return 5;
1346 }
4c865c34 1347 if (strstr(nametitle.Data(),pattern6)){
3a0f6479 1348 return 6;
1349 }
1350 else return -1;
1351
55a288e5 1352
3a0f6479 1353}
55a288e5 1354//_____________________________________________________________________________
4c865c34 1355Bool_t AliTRDCalibraFit::SetModeCalibration(TString name, Int_t i)
55a288e5 1356{
1357 //
1358 // Set fNz[i] and fNrphi[i] of the AliTRDCalibraFit::Instance()
3a0f6479 1359 // corresponding to the given name
55a288e5 1360 //
1361
3a0f6479 1362 if(!SetNzFromTObject(name,i)) return kFALSE;
1363 if(!SetNrphiFromTObject(name,i)) return kFALSE;
1364
1365 return kTRUE;
55a288e5 1366
3a0f6479 1367}
1368//_____________________________________________________________________________
4c865c34 1369Bool_t AliTRDCalibraFit::SetNrphiFromTObject(TString name, Int_t i)
3a0f6479 1370{
1371 //
1372 // Set fNrphi[i] of the AliTRDCalibraFit::Instance()
1373 // corresponding to the given TObject
1374 //
1375
55a288e5 1376 // Some patterns
55a288e5 1377 const Char_t *patternrphi0 = "Nrphi0";
1378 const Char_t *patternrphi1 = "Nrphi1";
1379 const Char_t *patternrphi2 = "Nrphi2";
1380 const Char_t *patternrphi3 = "Nrphi3";
1381 const Char_t *patternrphi4 = "Nrphi4";
1382 const Char_t *patternrphi5 = "Nrphi5";
1383 const Char_t *patternrphi6 = "Nrphi6";
1384
64942b85 1385
1386 const Char_t *patternrphi10 = "Nrphi10";
1387 const Char_t *patternrphi100 = "Nrphi100";
1388 const Char_t *patternz10 = "Nz10";
1389 const Char_t *patternz100 = "Nz100";
1390
55a288e5 1391 // Nrphi mode
4c865c34 1392 if ((strstr(name.Data(),patternrphi100)) && (strstr(name.Data(),patternz100))) {
64942b85 1393 fCalibraMode->SetAllTogether(i);
1394 fNbDet = 540;
1395 if (fDebugLevel > 1) {
1396 AliInfo(Form("fNbDet %d and 100",fNbDet));
1397 }
1398 return kTRUE;
1399 }
4c865c34 1400 if ((strstr(name.Data(),patternrphi10)) && (strstr(name.Data(),patternz10))) {
64942b85 1401 fCalibraMode->SetPerSuperModule(i);
1402 fNbDet = 30;
1403 if (fDebugLevel > 1) {
1404 AliInfo(Form("fNDet %d and 100",fNbDet));
1405 }
1406 return kTRUE;
1407 }
1408
4c865c34 1409 if (strstr(name.Data(),patternrphi0)) {
55a288e5 1410 fCalibraMode->SetNrphi(i ,0);
64942b85 1411 if (fDebugLevel > 1) {
1412 AliInfo(Form("fNbDet %d and 0",fNbDet));
1413 }
3a0f6479 1414 return kTRUE;
55a288e5 1415 }
4c865c34 1416 if (strstr(name.Data(),patternrphi1)) {
55a288e5 1417 fCalibraMode->SetNrphi(i, 1);
64942b85 1418 if (fDebugLevel > 1) {
1419 AliInfo(Form("fNbDet %d and 1",fNbDet));
1420 }
3a0f6479 1421 return kTRUE;
55a288e5 1422 }
4c865c34 1423 if (strstr(name.Data(),patternrphi2)) {
55a288e5 1424 fCalibraMode->SetNrphi(i, 2);
64942b85 1425 if (fDebugLevel > 1) {
1426 AliInfo(Form("fNbDet %d and 2",fNbDet));
1427 }
3a0f6479 1428 return kTRUE;
55a288e5 1429 }
4c865c34 1430 if (strstr(name.Data(),patternrphi3)) {
55a288e5 1431 fCalibraMode->SetNrphi(i, 3);
64942b85 1432 if (fDebugLevel > 1) {
1433 AliInfo(Form("fNbDet %d and 3",fNbDet));
1434 }
3a0f6479 1435 return kTRUE;
55a288e5 1436 }
4c865c34 1437 if (strstr(name.Data(),patternrphi4)) {
55a288e5 1438 fCalibraMode->SetNrphi(i, 4);
64942b85 1439 if (fDebugLevel > 1) {
1440 AliInfo(Form("fNbDet %d and 4",fNbDet));
1441 }
3a0f6479 1442 return kTRUE;
55a288e5 1443 }
4c865c34 1444 if (strstr(name.Data(),patternrphi5)) {
55a288e5 1445 fCalibraMode->SetNrphi(i, 5);
64942b85 1446 if (fDebugLevel > 1) {
1447 AliInfo(Form("fNbDet %d and 5",fNbDet));
1448 }
3a0f6479 1449 return kTRUE;
55a288e5 1450 }
4c865c34 1451 if (strstr(name.Data(),patternrphi6)) {
55a288e5 1452 fCalibraMode->SetNrphi(i, 6);
64942b85 1453 if (fDebugLevel > 1) {
1454 AliInfo(Form("fNbDet %d and 6",fNbDet));
1455 }
55a288e5 1456 return kTRUE;
1457 }
55a288e5 1458
64942b85 1459 if (fDebugLevel > 1) {
1460 AliInfo(Form("fNbDet %d and rest",fNbDet));
1461 }
3a0f6479 1462 fCalibraMode->SetNrphi(i ,0);
1463 return kFALSE;
64942b85 1464
55a288e5 1465}
55a288e5 1466//_____________________________________________________________________________
4c865c34 1467Bool_t AliTRDCalibraFit::SetNzFromTObject(TString name, Int_t i)
55a288e5 1468{
1469 //
3a0f6479 1470 // Set fNz[i] of the AliTRDCalibraFit::Instance()
1471 // corresponding to the given TObject
55a288e5 1472 //
3a0f6479 1473
1474 // Some patterns
1475 const Char_t *patternz0 = "Nz0";
1476 const Char_t *patternz1 = "Nz1";
1477 const Char_t *patternz2 = "Nz2";
1478 const Char_t *patternz3 = "Nz3";
1479 const Char_t *patternz4 = "Nz4";
64942b85 1480
1481 const Char_t *patternrphi10 = "Nrphi10";
1482 const Char_t *patternrphi100 = "Nrphi100";
1483 const Char_t *patternz10 = "Nz10";
1484 const Char_t *patternz100 = "Nz100";
1485
4c865c34 1486 if ((strstr(name.Data(),patternrphi100)) && (strstr(name.Data(),patternz100))) {
64942b85 1487 fCalibraMode->SetAllTogether(i);
1488 fNbDet = 540;
1489 if (fDebugLevel > 1) {
1490 AliInfo(Form("fNbDet %d and 100",fNbDet));
1491 }
1492 return kTRUE;
1493 }
4c865c34 1494 if ((strstr(name.Data(),patternrphi10)) && (strstr(name.Data(),patternz10))) {
64942b85 1495 fCalibraMode->SetPerSuperModule(i);
1496 fNbDet = 30;
1497 if (fDebugLevel > 1) {
1498 AliInfo(Form("fNbDet %d and 10",fNbDet));
1499 }
1500 return kTRUE;
1501 }
4c865c34 1502 if (strstr(name.Data(),patternz0)) {
3a0f6479 1503 fCalibraMode->SetNz(i, 0);
64942b85 1504 if (fDebugLevel > 1) {
1505 AliInfo(Form("fNbDet %d and 0",fNbDet));
1506 }
3a0f6479 1507 return kTRUE;
55a288e5 1508 }
4c865c34 1509 if (strstr(name.Data(),patternz1)) {
3a0f6479 1510 fCalibraMode->SetNz(i ,1);
64942b85 1511 if (fDebugLevel > 1) {
1512 AliInfo(Form("fNbDet %d and 1",fNbDet));
1513 }
3a0f6479 1514 return kTRUE;
55a288e5 1515 }
4c865c34 1516 if (strstr(name.Data(),patternz2)) {
3a0f6479 1517 fCalibraMode->SetNz(i ,2);
64942b85 1518 if (fDebugLevel > 1) {
1519 AliInfo(Form("fNbDet %d and 2",fNbDet));
1520 }
3a0f6479 1521 return kTRUE;
55a288e5 1522 }
4c865c34 1523 if (strstr(name.Data(),patternz3)) {
3a0f6479 1524 fCalibraMode->SetNz(i ,3);
64942b85 1525 if (fDebugLevel > 1) {
1526 AliInfo(Form("fNbDet %d and 3",fNbDet));
1527 }
3a0f6479 1528 return kTRUE;
55a288e5 1529 }
4c865c34 1530 if (strstr(name.Data(),patternz4)) {
3a0f6479 1531 fCalibraMode->SetNz(i ,4);
64942b85 1532 if (fDebugLevel > 1) {
1533 AliInfo(Form("fNbDet %d and 4",fNbDet));
1534 }
3a0f6479 1535 return kTRUE;
55a288e5 1536 }
64942b85 1537
1538 if (fDebugLevel > 1) {
1539 AliInfo(Form("fNbDet %d and rest",fNbDet));
1540 }
3a0f6479 1541 fCalibraMode->SetNz(i ,0);
1542 return kFALSE;
1543}
64942b85 1544//______________________________________________________________________
6aafa7ea 1545void AliTRDCalibraFit::RemoveOutliers(Int_t type, Bool_t perdetector){
1546 //
1547 // Remove the results too far from the mean value and rms
1548 // type: 0 gain, 1 vdrift
1549 // perdetector
1550 //
1551
1552 Int_t loop = (Int_t) fVectorFit.GetEntriesFast();
1553 if(loop != 540) {
1554 AliInfo("The Vector Fit is not complete!");
1555 return;
1556 }
1557 Int_t detector = -1;
1558 Int_t sector = -1;
1559 Float_t value = 0.0;
1560
1561 /////////////////////////////////
1562 // Calculate the mean values
1563 ////////////////////////////////
1564 // Initialisation
1565 ////////////////////////
1566 Double_t meanAll = 0.0;
1567 Double_t rmsAll = 0.0;
1568 Int_t countAll = 0;
1569 ////////////
1570 // compute
1571 ////////////
1572 for (Int_t k = 0; k < loop; k++) {
1573 detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
1574 sector = GetSector(detector);
1575 if(perdetector){
1576 value = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef()[0];
1577 if(value > 0.0) {
1578 rmsAll += value*value;
1579 meanAll += value;
1580 countAll++;
1581 }
1582 }
1583 else {
1584 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1585 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
1586 for (Int_t row = 0; row < rowMax; row++) {
1587 for (Int_t col = 0; col < colMax; col++) {
1588 value = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1589 if(value > 0.0) {
1590 rmsAll += value*value;
1591 meanAll += value;
1592 countAll++;
1593 }
1594
1595 } // Col
1596 } // Row
1597 }
1598 }
1599 if(countAll > 0) {
1600 meanAll = meanAll/countAll;
1601 rmsAll = TMath::Sqrt(TMath::Abs(rmsAll/countAll - (meanAll*meanAll)));
1602 }
1603 //printf("RemoveOutliers: meanAll %f and rmsAll %f\n",meanAll,rmsAll);
1604 /////////////////////////////////////////////////
1605 // Remove outliers
1606 ////////////////////////////////////////////////
1607 Double_t defaultvalue = -1.0;
1608 if(type==1) defaultvalue = -1.5;
1609 for (Int_t k = 0; k < loop; k++) {
1610 detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
1611 sector = GetSector(detector);
1612 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1613 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
1614 Float_t *coef = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef();
1615
1616 // remove the results too far away
1617 for (Int_t row = 0; row < rowMax; row++) {
1618 for (Int_t col = 0; col < colMax; col++) {
1619 value = coef[(Int_t)(col*rowMax+row)];
1620 if((value > 0.0) && (rmsAll > 0.0) && (TMath::Abs(value-meanAll) > (2*rmsAll))) {
1621 coef[(Int_t)(col*rowMax+row)] = defaultvalue;
1622 }
1623 } // Col
1624 } // Row
1625 }
1626}
1627//______________________________________________________________________
1628void AliTRDCalibraFit::RemoveOutliers2(Bool_t perdetector){
1629 //
1630 // Remove the results too far from the mean and rms
1631 // perdetector
1632 //
1633
1634 Int_t loop = (Int_t) fVectorFit2.GetEntriesFast();
1635 if(loop != 540) {
1636 AliInfo("The Vector Fit is not complete!");
1637 return;
1638 }
1639 Int_t detector = -1;
1640 Int_t sector = -1;
1641 Float_t value = 0.0;
1642
1643 /////////////////////////////////
1644 // Calculate the mean values
1645 ////////////////////////////////
1646 // Initialisation
1647 ////////////////////////
1648 Double_t meanAll = 0.0;
1649 Double_t rmsAll = 0.0;
1650 Int_t countAll = 0;
1651 /////////////
1652 // compute
1653 ////////////
1654 for (Int_t k = 0; k < loop; k++) {
1655 detector = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetDetector();
1656 sector = GetSector(detector);
1657 if(perdetector){
1658 value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[0];
1659 if(value < 70.0) {
1660 meanAll += value;
1661 rmsAll += value*value;
1662 countAll++;
1663 }
1664 }
1665 else {
1666 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1667 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
1668 for (Int_t row = 0; row < rowMax; row++) {
1669 for (Int_t col = 0; col < colMax; col++) {
1670 value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1671 if(value < 70.0) {
1672 rmsAll += value*value;
1673 meanAll += value;
1674 countAll++;
1675 }
1676 } // Col
1677 } // Row
1678 }
1679 }
1680 if(countAll > 0) {
1681 meanAll = meanAll/countAll;
1682 rmsAll = TMath::Sqrt(TMath::Abs(rmsAll/countAll - (meanAll*meanAll)));
1683 }
1684 //printf("Remove outliers 2: meanAll %f, rmsAll %f\n",meanAll,rmsAll);
1685 /////////////////////////////////////////////////
1686 // Remove outliers
1687 ////////////////////////////////////////////////
1688 for (Int_t k = 0; k < loop; k++) {
1689 detector = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetDetector();
1690 sector = GetSector(detector);
1691 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1692 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
1693 Float_t *coef = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef();
1694
1695 // remove the results too far away
1696 for (Int_t row = 0; row < rowMax; row++) {
1697 for (Int_t col = 0; col < colMax; col++) {
1698 value = coef[(Int_t)(col*rowMax+row)];
1699 if((value < 70.0) && (rmsAll > 0.0) && (TMath::Abs(value-meanAll) > (2.5*rmsAll))) coef[(Int_t)(col*rowMax+row)] = 100.0;
1700 } // Col
1701 } // Row
1702 }
1703}
1704//______________________________________________________________________
64942b85 1705void AliTRDCalibraFit::PutMeanValueOtherVectorFit(Int_t ofwhat, Bool_t perdetector){
1706 //
1707 // ofwhat is equaled to 0: mean value of all passing detectors
1708 // ofwhat is equaled to 1: mean value of the detector, otherwise supermodule, otherwise all
1709 //
1710
1711 Int_t loop = (Int_t) fVectorFit.GetEntriesFast();
1712 if(loop != 540) {
1713 AliInfo("The Vector Fit is not complete!");
1714 return;
1715 }
1716 Int_t detector = -1;
1717 Int_t sector = -1;
1718 Float_t value = 0.0;
1719
1720 /////////////////////////////////
1721 // Calculate the mean values
1722 ////////////////////////////////
1723 // Initialisation
1724 ////////////////////////
1725 Double_t meanAll = 0.0;
1726 Double_t meanSupermodule[18];
1727 Double_t meanDetector[540];
6aafa7ea 1728 Double_t rmsAll = 0.0;
1729 Double_t rmsSupermodule[18];
1730 Double_t rmsDetector[540];
64942b85 1731 Int_t countAll = 0;
1732 Int_t countSupermodule[18];
1733 Int_t countDetector[540];
1734 for(Int_t sm = 0; sm < 18; sm++){
6aafa7ea 1735 rmsSupermodule[sm] = 0.0;
64942b85 1736 meanSupermodule[sm] = 0.0;
1737 countSupermodule[sm] = 0;
1738 }
1739 for(Int_t det = 0; det < 540; det++){
6aafa7ea 1740 rmsDetector[det] = 0.0;
64942b85 1741 meanDetector[det] = 0.0;
1742 countDetector[det] = 0;
1743 }
6aafa7ea 1744 ////////////
64942b85 1745 // compute
1746 ////////////
1747 for (Int_t k = 0; k < loop; k++) {
1748 detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
1749 sector = GetSector(detector);
1750 if(perdetector){
1751 value = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef()[0];
1752 if(value > 0.0) {
6aafa7ea 1753 rmsDetector[detector] += value*value;
64942b85 1754 meanDetector[detector] += value;
1755 countDetector[detector]++;
6aafa7ea 1756 rmsSupermodule[sector] += value*value;
64942b85 1757 meanSupermodule[sector] += value;
1758 countSupermodule[sector]++;
6aafa7ea 1759 rmsAll += value*value;
64942b85 1760 meanAll += value;
1761 countAll++;
1762 }
1763 }
1764 else {
1765 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1766 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
1767 for (Int_t row = 0; row < rowMax; row++) {
1768 for (Int_t col = 0; col < colMax; col++) {
1769 value = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1770 if(value > 0.0) {
6aafa7ea 1771 rmsDetector[detector] += value*value;
64942b85 1772 meanDetector[detector] += value;
1773 countDetector[detector]++;
6aafa7ea 1774 rmsSupermodule[sector] += value*value;
64942b85 1775 meanSupermodule[sector] += value;
1776 countSupermodule[sector]++;
6aafa7ea 1777 rmsAll += value*value;
64942b85 1778 meanAll += value;
1779 countAll++;
1780 }
1781
1782 } // Col
1783 } // Row
1784 }
1785 }
6aafa7ea 1786 if(countAll > 0) {
1787 meanAll = meanAll/countAll;
1788 rmsAll = TMath::Abs(rmsAll/countAll - (meanAll*meanAll));
1789 }
64942b85 1790 for(Int_t sm = 0; sm < 18; sm++){
6aafa7ea 1791 if(countSupermodule[sm] > 0) {
1792 meanSupermodule[sm] = meanSupermodule[sm]/countSupermodule[sm];
1793 rmsSupermodule[sm] = TMath::Abs(rmsSupermodule[sm]/countSupermodule[sm] - (meanSupermodule[sm]*meanSupermodule[sm]));
1794 }
64942b85 1795 }
1796 for(Int_t det = 0; det < 540; det++){
6aafa7ea 1797 if(countDetector[det] > 0) {
1798 meanDetector[det] = meanDetector[det]/countDetector[det];
1799 rmsDetector[det] = TMath::Abs(rmsDetector[det]/countDetector[det] - (meanDetector[det]*meanDetector[det]));
1800 }
64942b85 1801 }
6aafa7ea 1802 //printf("Put mean value, meanAll %f, rmsAll %f\n",meanAll,rmsAll);
1803 ///////////////////////////////////////////////
64942b85 1804 // Put the mean value for the no-fitted
1805 /////////////////////////////////////////////
1806 for (Int_t k = 0; k < loop; k++) {
1807 detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
1808 sector = GetSector(detector);
1809 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1810 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
1811 Float_t *coef = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef();
1812
1813 for (Int_t row = 0; row < rowMax; row++) {
1814 for (Int_t col = 0; col < colMax; col++) {
1815 value = coef[(Int_t)(col*rowMax+row)];
1816 if(value < 0.0) {
6aafa7ea 1817 if((ofwhat == 0) && (meanAll > 0.0) && (countAll > 15)) coef[(Int_t)(col*rowMax+row)] = -TMath::Abs(meanAll);
64942b85 1818 if(ofwhat == 1){
6aafa7ea 1819 if((meanDetector[detector] > 0.0) && (countDetector[detector] > 20)) coef[(Int_t)(col*rowMax+row)] = -TMath::Abs(meanDetector[detector]);
1820 else if((meanSupermodule[sector] > 0.0) && (countSupermodule[sector] > 15)) coef[(Int_t)(col*rowMax+row)] = -TMath::Abs(meanSupermodule[sector]);
1821 else if((meanAll > 0.0) && (countAll > 15)) coef[(Int_t)(col*rowMax+row)] = -TMath::Abs(meanAll);
64942b85 1822 }
1823 }
1824 // Debug
1825 if(fDebugLevel > 1){
1826
1827 if ( !fDebugStreamer ) {
1828 //debug stream
1829 TDirectory *backup = gDirectory;
1830 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
1831 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1832 }
1833
1834 Float_t coefnow = coef[(Int_t)(col*rowMax+row)];
1835
1836 (* fDebugStreamer) << "PutMeanValueOtherVectorFit"<<
1837 "detector="<<detector<<
1838 "sector="<<sector<<
1839 "row="<<row<<
1840 "col="<<col<<
1841 "before="<<value<<
1842 "after="<<coefnow<<
1843 "\n";
1844 }
1845 } // Col
1846 } // Row
1847 }
64942b85 1848}
1849//______________________________________________________________________
1850void AliTRDCalibraFit::PutMeanValueOtherVectorFit2(Int_t ofwhat, Bool_t perdetector){
1851 //
1852 // ofwhat is equaled to 0: mean value of all passing detectors
1853 // ofwhat is equaled to 1: mean value of the detector, otherwise supermodule, otherwise all
1854 //
1855
1856 Int_t loop = (Int_t) fVectorFit2.GetEntriesFast();
1857 if(loop != 540) {
1858 AliInfo("The Vector Fit is not complete!");
1859 return;
1860 }
1861 Int_t detector = -1;
1862 Int_t sector = -1;
1863 Float_t value = 0.0;
1864
1865 /////////////////////////////////
1866 // Calculate the mean values
1867 ////////////////////////////////
1868 // Initialisation
1869 ////////////////////////
1870 Double_t meanAll = 0.0;
6aafa7ea 1871 Double_t rmsAll = 0.0;
64942b85 1872 Double_t meanSupermodule[18];
6aafa7ea 1873 Double_t rmsSupermodule[18];
64942b85 1874 Double_t meanDetector[540];
6aafa7ea 1875 Double_t rmsDetector[540];
64942b85 1876 Int_t countAll = 0;
1877 Int_t countSupermodule[18];
1878 Int_t countDetector[540];
1879 for(Int_t sm = 0; sm < 18; sm++){
6aafa7ea 1880 rmsSupermodule[sm] = 0.0;
64942b85 1881 meanSupermodule[sm] = 0.0;
1882 countSupermodule[sm] = 0;
1883 }
1884 for(Int_t det = 0; det < 540; det++){
6aafa7ea 1885 rmsDetector[det] = 0.0;
64942b85 1886 meanDetector[det] = 0.0;
1887 countDetector[det] = 0;
1888 }
1889 // compute
1890 ////////////
1891 for (Int_t k = 0; k < loop; k++) {
1892 detector = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetDetector();
1893 sector = GetSector(detector);
1894 if(perdetector){
1895 value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[0];
1896 if(value < 70.0) {
6aafa7ea 1897 rmsDetector[detector] += value*value;
64942b85 1898 meanDetector[detector] += value;
1899 countDetector[detector]++;
6aafa7ea 1900 rmsSupermodule[sector] += value*value;
64942b85 1901 meanSupermodule[sector] += value;
1902 countSupermodule[sector]++;
1903 meanAll += value;
6aafa7ea 1904 rmsAll += value*value;
64942b85 1905 countAll++;
1906 }
1907 }
1908 else {
1909 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1910 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
1911 for (Int_t row = 0; row < rowMax; row++) {
1912 for (Int_t col = 0; col < colMax; col++) {
1913 value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1914 if(value < 70.0) {
6aafa7ea 1915 rmsDetector[detector] += value*value;
64942b85 1916 meanDetector[detector] += value;
1917 countDetector[detector]++;
6aafa7ea 1918 rmsSupermodule[sector] += value*value;
64942b85 1919 meanSupermodule[sector] += value;
1920 countSupermodule[sector]++;
6aafa7ea 1921 rmsAll += value*value;
64942b85 1922 meanAll += value;
1923 countAll++;
1924 }
1925
1926 } // Col
1927 } // Row
1928 }
1929 }
6aafa7ea 1930 if(countAll > 0) {
1931 meanAll = meanAll/countAll;
1932 rmsAll = TMath::Abs(rmsAll/countAll - (meanAll*meanAll));
1933 }
64942b85 1934 for(Int_t sm = 0; sm < 18; sm++){
6aafa7ea 1935 if(countSupermodule[sm] > 0) {
1936 meanSupermodule[sm] = meanSupermodule[sm]/countSupermodule[sm];
1937 rmsSupermodule[sm] = TMath::Abs(rmsSupermodule[sm]/countSupermodule[sm] - (meanSupermodule[sm]*meanSupermodule[sm]));
1938 }
64942b85 1939 }
1940 for(Int_t det = 0; det < 540; det++){
6aafa7ea 1941 if(countDetector[det] > 0) {
1942 meanDetector[det] = meanDetector[det]/countDetector[det];
1943 rmsDetector[det] = TMath::Abs(rmsDetector[det]/countDetector[det] - (meanDetector[det]*meanDetector[det]));
1944 }
64942b85 1945 }
6aafa7ea 1946 //printf("Put mean value 2: meanAll %f, rmsAll %f\n",meanAll,rmsAll);
1947 ////////////////////////////////////////////
64942b85 1948 // Put the mean value for the no-fitted
1949 /////////////////////////////////////////////
1950 for (Int_t k = 0; k < loop; k++) {
1951 detector = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetDetector();
1952 sector = GetSector(detector);
1953 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1954 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
1955 Float_t *coef = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef();
1956
1957 for (Int_t row = 0; row < rowMax; row++) {
1958 for (Int_t col = 0; col < colMax; col++) {
1959 value = coef[(Int_t)(col*rowMax+row)];
1960 if(value > 70.0) {
6aafa7ea 1961 if((ofwhat == 0) && (meanAll > -1.5) && (countAll > 15)) coef[(Int_t)(col*rowMax+row)] = meanAll+100.0;
64942b85 1962 if(ofwhat == 1){
6aafa7ea 1963 if((meanDetector[detector] > -1.5) && (countDetector[detector] > 20)) coef[(Int_t)(col*rowMax+row)] = meanDetector[detector]+100.0;
1964 else if((meanSupermodule[sector] > -1.5) && (countSupermodule[sector] > 15)) coef[(Int_t)(col*rowMax+row)] = meanSupermodule[sector]+100.0;
1965 else if((meanAll > -1.5) && (countAll > 15)) coef[(Int_t)(col*rowMax+row)] = meanAll+100.0;
64942b85 1966 }
1967 }
1968 // Debug
1969 if(fDebugLevel > 1){
1970
1971 if ( !fDebugStreamer ) {
1972 //debug stream
1973 TDirectory *backup = gDirectory;
1974 fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
1975 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1976 }
1977
1978 Float_t coefnow = coef[(Int_t)(col*rowMax+row)];
1979
1980 (* fDebugStreamer) << "PutMeanValueOtherVectorFit2"<<
1981 "detector="<<detector<<
1982 "sector="<<sector<<
1983 "row="<<row<<
1984 "col="<<col<<
1985 "before="<<value<<
1986 "after="<<coefnow<<
1987 "\n";
1988 }
1989 } // Col
1990 } // Row
1991 }
1992
1993}
3a0f6479 1994//_____________________________________________________________________________
979b168f 1995AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectVdrift(const TObjArray *vectorFit, Bool_t perdetector)
3a0f6479 1996{
1997 //
1998 // It creates the AliTRDCalDet object from the AliTRDFitInfo
1999 // It takes the mean value of the coefficients per detector
2000 // This object has to be written in the database
2001 //
55a288e5 2002
3a0f6479 2003 // Create the DetObject
2004 AliTRDCalDet *object = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2005
2006 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2007 if(loop != 540) AliInfo("The Vector Fit is not complete!");
2008 Int_t detector = -1;
2009 Float_t value = 0.0;
64942b85 2010
2011 //
3a0f6479 2012 for (Int_t k = 0; k < loop; k++) {
2013 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2014 Float_t mean = 0.0;
2015 if(perdetector){
2016 mean = TMath::Abs(((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0]);
55a288e5 2017 }
2018 else {
3a0f6479 2019 Int_t count = 0;
053767a4 2020 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
2021 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
3a0f6479 2022 for (Int_t row = 0; row < rowMax; row++) {
2023 for (Int_t col = 0; col < colMax; col++) {
2024 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
2025 mean += TMath::Abs(value);
2026 count++;
2027 } // Col
2028 } // Row
2029 if(count > 0) mean = mean/count;
55a288e5 2030 }
2031 object->SetValue(detector,mean);
2032 }
3a0f6479 2033
55a288e5 2034 return object;
55a288e5 2035}
55a288e5 2036//_____________________________________________________________________________
979b168f 2037AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectGain(const TObjArray *vectorFit, Bool_t meanOtherBefore, Double_t scaleFitFactor, Bool_t perdetector)
55a288e5 2038{
2039 //
3a0f6479 2040 // It creates the AliTRDCalDet object from the AliTRDFitInfo
2041 // It takes the mean value of the coefficients per detector
55a288e5 2042 // This object has to be written in the database
2043 //
2044
2045 // Create the DetObject
3a0f6479 2046 AliTRDCalDet *object = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
55a288e5 2047
54f2ff1c 2048 fScaleGain = scaleFitFactor;
3a0f6479 2049
2050 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2051 if(loop != 540) AliInfo("The Vector Fit is not complete!");
2052 Int_t detector = -1;
2053 Float_t value = 0.0;
2054
2055 for (Int_t k = 0; k < loop; k++) {
2056 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2057 Float_t mean = 0.0;
2058 if(perdetector){
2059 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
64942b85 2060 if(!meanOtherBefore){
2061 if(value > 0) value = value*scaleFitFactor;
2062 }
2063 else value = value*scaleFitFactor;
3a0f6479 2064 mean = TMath::Abs(value);
2065 }
2066 else{
2067 Int_t count = 0;
053767a4 2068 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
2069 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
3a0f6479 2070 for (Int_t row = 0; row < rowMax; row++) {
2071 for (Int_t col = 0; col < colMax; col++) {
2072 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
64942b85 2073 if(!meanOtherBefore) {
2074 if(value > 0) value = value*scaleFitFactor;
2075 }
2076 else value = value*scaleFitFactor;
3a0f6479 2077 mean += TMath::Abs(value);
2078 count++;
2079 } // Col
2080 } // Row
2081 if(count > 0) mean = mean/count;
2082 }
ba1aa7a7 2083 if(mean < 0.1) mean = 0.1;
3a0f6479 2084 object->SetValue(detector,mean);
55a288e5 2085 }
3a0f6479 2086
2087 return object;
2088}
2089//_____________________________________________________________________________
979b168f 2090AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectT0(const TObjArray *vectorFit, Bool_t perdetector)
3a0f6479 2091{
2092 //
2093 // It creates the AliTRDCalDet object from the AliTRDFitInfo2
2094 // It takes the min value of the coefficients per detector
2095 // This object has to be written in the database
2096 //
55a288e5 2097
3a0f6479 2098 // Create the DetObject
2099 AliTRDCalDet *object = new AliTRDCalDet("ChamberT0","T0 (detector value)");
55a288e5 2100
3a0f6479 2101 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2102 if(loop != 540) AliInfo("The Vector Fit is not complete!");
2103 Int_t detector = -1;
2104 Float_t value = 0.0;
2105
2106 for (Int_t k = 0; k < loop; k++) {
2107 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2108 Float_t min = 100.0;
2109 if(perdetector){
64942b85 2110 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
2111 // check successful
2112 if(value > 70.0) value = value-100.0;
2113 //
2114 min = value;
55a288e5 2115 }
3a0f6479 2116 else{
053767a4 2117 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
2118 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
3a0f6479 2119 for (Int_t row = 0; row < rowMax; row++) {
2120 for (Int_t col = 0; col < colMax; col++) {
2121 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
64942b85 2122 // check successful
2123 if(value > 70.0) value = value-100.0;
2124 //
3a0f6479 2125 if(min > value) min = value;
2126 } // Col
2127 } // Row
2128 }
2129 object->SetValue(detector,min);
55a288e5 2130 }
2131
2132 return object;
2133
2134}
55a288e5 2135//_____________________________________________________________________________
979b168f 2136AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectLorentzAngle(const TObjArray *vectorFit)
55a288e5 2137{
2138 //
3a0f6479 2139 // It creates the AliTRDCalDet object from the AliTRDFitInfo2
2140 // It takes the min value of the coefficients per detector
55a288e5 2141 // This object has to be written in the database
2142 //
2143
2144 // Create the DetObject
3a0f6479 2145 AliTRDCalDet *object = new AliTRDCalDet("tan(lorentzangle)","tan(lorentzangle) (detector value)");
2146
2147
2148 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2149 if(loop != 540) AliInfo("The Vector Fit is not complete!");
2150 Int_t detector = -1;
2151 Float_t value = 0.0;
55a288e5 2152
3a0f6479 2153 for (Int_t k = 0; k < loop; k++) {
2154 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2155 /*
053767a4 2156 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
2157 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
3a0f6479 2158 Float_t min = 100.0;
2159 for (Int_t row = 0; row < rowMax; row++) {
2160 for (Int_t col = 0; col < colMax; col++) {
2161 value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
2162 mean += -TMath::Abs(value);
2163 count++;
55a288e5 2164 } // Col
3a0f6479 2165 } // Row
2166 if(count > 0) mean = mean/count;
2167 */
2168 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
2169 object->SetValue(detector,-TMath::Abs(value));
55a288e5 2170 }
2171
2172 return object;
3a0f6479 2173
55a288e5 2174}
55a288e5 2175//_____________________________________________________________________________
979b168f 2176TObject *AliTRDCalibraFit::CreatePadObjectGain(const TObjArray *vectorFit, Double_t scaleFitFactor, const AliTRDCalDet *detobject)
3a0f6479 2177{
55a288e5 2178 //
3a0f6479 2179 // It Creates the AliTRDCalPad object from AliTRDFitInfo
2180 // You need first to create the object for the detectors,
2181 // where the mean value is put.
2182 // This object has to be written in the database
55a288e5 2183 //
3a0f6479 2184
2185 // Create the DetObject
2186 AliTRDCalPad *object = new AliTRDCalPad("GainFactor","GainFactor (local variations)");
2187
2188 if(!vectorFit){
2189 for(Int_t k = 0; k < 540; k++){
2190 AliTRDCalROC *calROC = object->GetCalROC(k);
2191 Int_t nchannels = calROC->GetNchannels();
2192 for(Int_t ch = 0; ch < nchannels; ch++){
2193 calROC->SetValue(ch,1.0);
2194 }
2195 }
55a288e5 2196 }
3a0f6479 2197 else{
2198
2199 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2200 if(loop != 540) AliInfo("The Vector Fit is not complete!");
2201 Int_t detector = -1;
2202 Float_t value = 0.0;
2203
2204 for (Int_t k = 0; k < loop; k++) {
2205 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2206 AliTRDCalROC *calROC = object->GetCalROC(detector);
2207 Float_t mean = detobject->GetValue(detector);
daa7dc79 2208 if(TMath::Abs(mean) <= 0.0000000001) continue;
3a0f6479 2209 Int_t rowMax = calROC->GetNrows();
2210 Int_t colMax = calROC->GetNcols();
2211 for (Int_t row = 0; row < rowMax; row++) {
2212 for (Int_t col = 0; col < colMax; col++) {
2213 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
2214 if(value > 0) value = value*scaleFitFactor;
2215 calROC->SetValue(col,row,TMath::Abs(value)/mean);
2216 } // Col
2217 } // Row
2218 }
55a288e5 2219 }
2220
3a0f6479 2221 return object;
55a288e5 2222}
55a288e5 2223//_____________________________________________________________________________
979b168f 2224TObject *AliTRDCalibraFit::CreatePadObjectVdrift(const TObjArray *vectorFit, const AliTRDCalDet *detobject)
3a0f6479 2225{
55a288e5 2226 //
3a0f6479 2227 // It Creates the AliTRDCalPad object from AliTRDFitInfo
2228 // You need first to create the object for the detectors,
2229 // where the mean value is put.
2230 // This object has to be written in the database
55a288e5 2231 //
2232
3a0f6479 2233 // Create the DetObject
2234 AliTRDCalPad *object = new AliTRDCalPad("LocalVdrift","TRD drift velocities (local variations)");
2235
2236 if(!vectorFit){
2237 for(Int_t k = 0; k < 540; k++){
2238 AliTRDCalROC *calROC = object->GetCalROC(k);
2239 Int_t nchannels = calROC->GetNchannels();
2240 for(Int_t ch = 0; ch < nchannels; ch++){
2241 calROC->SetValue(ch,1.0);
2242 }
2243 }
55a288e5 2244 }
2245 else {
3a0f6479 2246
2247 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2248 if(loop != 540) AliInfo("The Vector Fit is not complete!");
2249 Int_t detector = -1;
2250 Float_t value = 0.0;
2251
2252 for (Int_t k = 0; k < loop; k++) {
2253 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2254 AliTRDCalROC *calROC = object->GetCalROC(detector);
2255 Float_t mean = detobject->GetValue(detector);
2256 if(mean == 0) continue;
2257 Int_t rowMax = calROC->GetNrows();
2258 Int_t colMax = calROC->GetNcols();
2259 for (Int_t row = 0; row < rowMax; row++) {
2260 for (Int_t col = 0; col < colMax; col++) {
2261 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
2262 calROC->SetValue(col,row,TMath::Abs(value)/mean);
2263 } // Col
2264 } // Row
2265 }
55a288e5 2266 }
3a0f6479 2267 return object;
55a288e5 2268
2269}
55a288e5 2270//_____________________________________________________________________________
979b168f 2271TObject *AliTRDCalibraFit::CreatePadObjectT0(const TObjArray *vectorFit, const AliTRDCalDet *detobject)
3a0f6479 2272{
55a288e5 2273 //
3a0f6479 2274 // It Creates the AliTRDCalPad object from AliTRDFitInfo2
2275 // You need first to create the object for the detectors,
2276 // where the mean value is put.
2277 // This object has to be written in the database
55a288e5 2278 //
3a0f6479 2279
2280 // Create the DetObject
2281 AliTRDCalPad *object = new AliTRDCalPad("LocalT0","T0 (local variations)");
2282
2283 if(!vectorFit){
2284 for(Int_t k = 0; k < 540; k++){
2285 AliTRDCalROC *calROC = object->GetCalROC(k);
2286 Int_t nchannels = calROC->GetNchannels();
2287 for(Int_t ch = 0; ch < nchannels; ch++){
2288 calROC->SetValue(ch,0.0);
2289 }
2290 }
55a288e5 2291 }
2292 else {
3a0f6479 2293
2294 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2295 if(loop != 540) AliInfo("The Vector Fit is not complete!");
2296 Int_t detector = -1;
2297 Float_t value = 0.0;
2298
2299 for (Int_t k = 0; k < loop; k++) {
2300 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2301 AliTRDCalROC *calROC = object->GetCalROC(detector);
2302 Float_t min = detobject->GetValue(detector);
2303 Int_t rowMax = calROC->GetNrows();
2304 Int_t colMax = calROC->GetNcols();
2305 for (Int_t row = 0; row < rowMax; row++) {
2306 for (Int_t col = 0; col < colMax; col++) {
2307 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
64942b85 2308 // check successful
2309 if(value > 70.0) value = value - 100.0;
2310 //
3a0f6479 2311 calROC->SetValue(col,row,value-min);
2312 } // Col
2313 } // Row
2314 }
55a288e5 2315 }
3a0f6479 2316 return object;
55a288e5 2317
2318}
3a0f6479 2319//_____________________________________________________________________________
979b168f 2320TObject *AliTRDCalibraFit::CreatePadObjectPRF(const TObjArray *vectorFit)
3a0f6479 2321{
2322 //
2323 // It Creates the AliTRDCalPad object from AliTRDFitInfo
2324 // This object has to be written in the database
2325 //
2326
2327 // Create the DetObject
2328 AliTRDCalPad *object = new AliTRDCalPad("PRFWidth","PRFWidth");
2329
2330 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2331 if(loop != 540) AliInfo("The Vector Fit is not complete!");
2332 Int_t detector = -1;
2333 Float_t value = 0.0;
55a288e5 2334
3a0f6479 2335 for (Int_t k = 0; k < loop; k++) {
2336 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2337 AliTRDCalROC *calROC = object->GetCalROC(detector);
2338 Int_t rowMax = calROC->GetNrows();
2339 Int_t colMax = calROC->GetNcols();
2340 for (Int_t row = 0; row < rowMax; row++) {
2341 for (Int_t col = 0; col < colMax; col++) {
2342 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
2343 calROC->SetValue(col,row,TMath::Abs(value));
2344 } // Col
2345 } // Row
2346 }
2347
2348 return object;
2349
2350}
55a288e5 2351//_____________________________________________________________________________
979b168f 2352AliTRDCalDet *AliTRDCalibraFit::MakeOutliersStatDet(const TObjArray *vectorFit, const char *name, Double_t &mean)
3a0f6479 2353{
2354 //
2355 // It Creates the AliTRDCalDet object from AliTRDFitInfo
2356 // 0 successful fit 1 not successful fit
2357 // mean is the mean value over the successful fit
2358 // do not use it for t0: no meaning
2359 //
2360
2361 // Create the CalObject
2362 AliTRDCalDet *object = new AliTRDCalDet(name,name);
2363 mean = 0.0;
2364 Int_t count = 0;
2365
2366 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2367 if(loop != 540) {
2368 AliInfo("The Vector Fit is not complete! We initialise all outliers");
2369 for(Int_t k = 0; k < 540; k++){
2370 object->SetValue(k,1.0);
2371 }
2372 }
2373 Int_t detector = -1;
2374 Float_t value = 0.0;
2375
2376 for (Int_t k = 0; k < loop; k++) {
2377 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2378 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
2379 if(value <= 0) object->SetValue(detector,1.0);
2380 else {
2381 object->SetValue(detector,0.0);
2382 mean += value;
2383 count++;
2384 }
2385 }
2386 if(count > 0) mean /= count;
2387 return object;
2388}
2389//_____________________________________________________________________________
979b168f 2390TObject *AliTRDCalibraFit::MakeOutliersStatPad(const TObjArray *vectorFit, const char *name, Double_t &mean)
3a0f6479 2391{
2392 //
2393 // It Creates the AliTRDCalPad object from AliTRDFitInfo
2394 // 0 not successful fit 1 successful fit
2395 // mean mean value over the successful fit
2396 //
2397
2398 // Create the CalObject
2399 AliTRDCalPad *object = new AliTRDCalPad(name,name);
2400 mean = 0.0;
2401 Int_t count = 0;
2402
2403 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
2404 if(loop != 540) {
2405 AliInfo("The Vector Fit is not complete! We initialise all outliers");
2406 for(Int_t k = 0; k < 540; k++){
2407 AliTRDCalROC *calROC = object->GetCalROC(k);
2408 Int_t nchannels = calROC->GetNchannels();
2409 for(Int_t ch = 0; ch < nchannels; ch++){
2410 calROC->SetValue(ch,1.0);
2411 }
2412 }
2413 }
2414 Int_t detector = -1;
2415 Float_t value = 0.0;
2416
2417 for (Int_t k = 0; k < loop; k++) {
2418 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
2419 AliTRDCalROC *calROC = object->GetCalROC(detector);
2420 Int_t nchannels = calROC->GetNchannels();
2421 for (Int_t ch = 0; ch < nchannels; ch++) {
2422 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[ch];
2423 if(value <= 0) calROC->SetValue(ch,1.0);
2424 else {
2425 calROC->SetValue(ch,0.0);
2426 mean += value;
2427 count++;
2428 }
2429 } // channels
2430 }
2431 if(count > 0) mean /= count;
2432 return object;
2433}
2434//_____________________________________________________________________________
2435void AliTRDCalibraFit::SetPeriodeFitPH(Int_t periodeFitPH)
55a288e5 2436{
2437 //
3a0f6479 2438 // Set FitPH if 1 then each detector will be fitted
55a288e5 2439 //
2440
3a0f6479 2441 if (periodeFitPH > 0) {
2442 fFitPHPeriode = periodeFitPH;
55a288e5 2443 }
2444 else {
3a0f6479 2445 AliInfo("periodeFitPH must be higher than 0!");
55a288e5 2446 }
2447
2448}
55a288e5 2449//_____________________________________________________________________________
2450void AliTRDCalibraFit::SetBeginFitCharge(Float_t beginFitCharge)
2451{
2452 //
2453 // The fit of the deposited charge distribution begins at
2454 // histo->Mean()/beginFitCharge
2455 // You can here set beginFitCharge
2456 //
2457
2458 if (beginFitCharge > 0) {
2459 fBeginFitCharge = beginFitCharge;
2460 }
2461 else {
2462 AliInfo("beginFitCharge must be strict positif!");
2463 }
2464
2465}
2466
2467//_____________________________________________________________________________
413153cb 2468void AliTRDCalibraFit::SetT0Shift0(Float_t t0Shift)
2469{
2470 //
2471 // The t0 calculated with the maximum positif slope is shift from t0Shift0
2472 // You can here set t0Shift0
2473 //
2474
2475 if (t0Shift > 0) {
2476 fT0Shift0 = t0Shift;
2477 }
2478 else {
2479 AliInfo("t0Shift0 must be strict positif!");
2480 }
2481
2482}
2483
2484//_____________________________________________________________________________
2485void AliTRDCalibraFit::SetT0Shift1(Float_t t0Shift)
55a288e5 2486{
2487 //
413153cb 2488 // The t0 calculated with the maximum of the amplification region is shift from t0Shift1
2489 // You can here set t0Shift1
55a288e5 2490 //
2491
2492 if (t0Shift > 0) {
413153cb 2493 fT0Shift1 = t0Shift;
55a288e5 2494 }
2495 else {
2496 AliInfo("t0Shift must be strict positif!");
2497 }
2498
2499}
2500
2501//_____________________________________________________________________________
2502void AliTRDCalibraFit::SetRangeFitPRF(Float_t rangeFitPRF)
2503{
2504 //
2505 // The fit of the PRF is from -rangeFitPRF to rangeFitPRF
2506 // You can here set rangeFitPRF
2507 //
2508
2509 if ((rangeFitPRF > 0) &&
2510 (rangeFitPRF <= 1.5)) {
2511 fRangeFitPRF = rangeFitPRF;
2512 }
2513 else {
2514 AliInfo("rangeFitPRF must be between 0 and 1.0");
2515 }
2516
2517}
2518
3a0f6479 2519//_____________________________________________________________________________
2520void AliTRDCalibraFit::SetMinEntries(Int_t minEntries)
2521{
2522 //
2523 // Minimum entries for fitting
2524 //
2525
2526 if (minEntries > 0) {
2527 fMinEntries = minEntries;
2528 }
2529 else {
2530 AliInfo("fMinEntries must be >= 0.");
2531 }
2532
2533}
2534
55a288e5 2535//_____________________________________________________________________________
2536void AliTRDCalibraFit::SetRebin(Short_t rebin)
2537{
2538 //
2539 // Rebin with rebin time less bins the Ch histo
2540 // You can set here rebin that should divide the number of bins of CH histo
2541 //
2542
2543 if (rebin > 0) {
2544 fRebin = rebin;
2545 AliInfo("You have to be sure that fRebin divides fNumberBinCharge used!");
2546 }
2547 else {
2548 AliInfo("You have to choose a positiv value!");
2549 }
2550
2551}
55a288e5 2552//_____________________________________________________________________________
3a0f6479 2553Bool_t AliTRDCalibraFit::FillVectorFit()
55a288e5 2554{
2555 //
3a0f6479 2556 // For the Fit functions fill the vector Fit
55a288e5 2557 //
55a288e5 2558
3a0f6479 2559 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
55a288e5 2560
3a0f6479 2561 Int_t ntotal = 1;
053767a4 2562 if (GetStack(fCountDet) == 2) {
3a0f6479 2563 ntotal = 1728;
55a288e5 2564 }
3a0f6479 2565 else {
2566 ntotal = 2304;
55a288e5 2567 }
3a0f6479 2568
2569 //printf("For the detector %d , ntotal %d and fCoefCH[0] %f\n",countdet,ntotal,fCoefCH[0]);
2570 Float_t *coef = new Float_t[ntotal];
2571 for (Int_t i = 0; i < ntotal; i++) {
2572 coef[i] = fCurrentCoefDetector[i];
55a288e5 2573 }
3a0f6479 2574
2575 Int_t detector = fCountDet;
2576 // Set
2577 fitInfo->SetCoef(coef);
2578 fitInfo->SetDetector(detector);
2579 fVectorFit.Add((TObject *) fitInfo);
2580
2581 return kTRUE;
55a288e5 2582
3a0f6479 2583}
55a288e5 2584//_____________________________________________________________________________
3a0f6479 2585Bool_t AliTRDCalibraFit::FillVectorFit2()
55a288e5 2586{
2587 //
3a0f6479 2588 // For the Fit functions fill the vector Fit
55a288e5 2589 //
55a288e5 2590
3a0f6479 2591 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
55a288e5 2592
3a0f6479 2593 Int_t ntotal = 1;
053767a4 2594 if (GetStack(fCountDet) == 2) {
3a0f6479 2595 ntotal = 1728;
55a288e5 2596 }
3a0f6479 2597 else {
2598 ntotal = 2304;
55a288e5 2599 }
3a0f6479 2600
2601 //printf("For the detector %d , ntotal %d and fCoefCH[0] %f\n",countdet,ntotal,fCoefCH[0]);
2602 Float_t *coef = new Float_t[ntotal];
2603 for (Int_t i = 0; i < ntotal; i++) {
2604 coef[i] = fCurrentCoefDetector2[i];
55a288e5 2605 }
3a0f6479 2606
2607 Int_t detector = fCountDet;
2608 // Set
2609 fitInfo->SetCoef(coef);
2610 fitInfo->SetDetector(detector);
2611 fVectorFit2.Add((TObject *) fitInfo);
55a288e5 2612
3a0f6479 2613 return kTRUE;
55a288e5 2614
3a0f6479 2615}
2616//____________Functions for initialising the AliTRDCalibraFit in the code_________
2617Bool_t AliTRDCalibraFit::InitFit(Int_t nbins, Int_t i)
55a288e5 2618{
2619 //
3a0f6479 2620 // Init the number of expected bins and fDect1[i] fDect2[i]
55a288e5 2621 //
2622
3a0f6479 2623 gStyle->SetPalette(1);
2624 gStyle->SetOptStat(1111);
2625 gStyle->SetPadBorderMode(0);
2626 gStyle->SetCanvasColor(10);
2627 gStyle->SetPadLeftMargin(0.13);
2628 gStyle->SetPadRightMargin(0.01);
2629
2630 // Mode groups of pads: the total number of bins!
2631 CalculNumberOfBinsExpected(i);
2632
2633 // Quick verification that we have the good pad calibration mode!
2634 if (fNumberOfBinsExpected != nbins) {
64942b85 2635 AliInfo(Form("It doesn't correspond to the mode of pad group calibration: expected %d and seen %d!",fNumberOfBinsExpected,nbins));
3a0f6479 2636 return kFALSE;
55a288e5 2637 }
3a0f6479 2638
2639 // Security for fDebug 3 and 4
2640 if ((fDebugLevel >= 3) &&
2641 ((fDet[0] > 5) ||
2642 (fDet[1] > 4) ||
2643 (fDet[2] > 17))) {
2644 AliInfo("This detector doesn't exit!");
2645 return kFALSE;
55a288e5 2646 }
2647
3a0f6479 2648 // Determine fDet1 and fDet2 and set the fNfragZ and fNfragRphi for debug 3 and 4
2649 CalculDect1Dect2(i);
55a288e5 2650
3a0f6479 2651
2652 return kTRUE;
55a288e5 2653}
3a0f6479 2654//____________Functions for initialising the AliTRDCalibraFit in the code_________
2655Bool_t AliTRDCalibraFit::InitFitCH()
55a288e5 2656{
2657 //
3a0f6479 2658 // Init the fVectorFitCH for normalisation
2659 // Init the histo for debugging
55a288e5 2660 //
2661
3a0f6479 2662 gDirectory = gROOT;
2663
2664 fScaleFitFactor = 0.0;
2665 fCurrentCoefDetector = new Float_t[2304];
2666 for (Int_t k = 0; k < 2304; k++) {
2667 fCurrentCoefDetector[k] = 0.0;
2668 }
2669 fVectorFit.SetName("gainfactorscoefficients");
55a288e5 2670
3a0f6479 2671 // fDebug == 0 nothing
2672 // fDebug == 1 and fFitVoir no histo
2673 if (fDebugLevel == 1) {
2674 if(!CheckFitVoir()) return kFALSE;
2675 }
2676 //Get the CalDet object
2677 if(fAccCDB){
2678 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2679 if (!cal) {
2680 AliInfo("Could not get calibDB");
2681 return kFALSE;
55a288e5 2682 }
3a0f6479 2683 if(fCalDet) delete fCalDet;
2684 fCalDet = new AliTRDCalDet(*(cal->GetGainFactorDet()));
55a288e5 2685 }
3a0f6479 2686 else{
2687 Float_t devalue = 1.0;
2688 if(fCalDet) delete fCalDet;
2689 fCalDet = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
2690 for(Int_t k = 0; k < 540; k++){
2691 fCalDet->SetValue(k,devalue);
55a288e5 2692 }
2693 }
3a0f6479 2694 return kTRUE;
2695
55a288e5 2696}
3a0f6479 2697//____________Functions for initialising the AliTRDCalibraFit in the code_________
2698Bool_t AliTRDCalibraFit::InitFitPH()
55a288e5 2699{
2700 //
3a0f6479 2701 // Init the arrays of results
2702 // Init the histos for debugging
55a288e5 2703 //
55a288e5 2704
3a0f6479 2705 gDirectory = gROOT;
2706 fVectorFit.SetName("driftvelocitycoefficients");
2707 fVectorFit2.SetName("t0coefficients");
55a288e5 2708
3a0f6479 2709 fCurrentCoefDetector = new Float_t[2304];
2710 for (Int_t k = 0; k < 2304; k++) {
2711 fCurrentCoefDetector[k] = 0.0;
2712 }
2713
2714 fCurrentCoefDetector2 = new Float_t[2304];
2715 for (Int_t k = 0; k < 2304; k++) {
2716 fCurrentCoefDetector2[k] = 0.0;
55a288e5 2717 }
2718
3a0f6479 2719 //fDebug == 0 nothing
2720 // fDebug == 1 and fFitVoir no histo
2721 if (fDebugLevel == 1) {
2722 if(!CheckFitVoir()) return kFALSE;
2723 }
2724 //Get the CalDet object
2725 if(fAccCDB){
2726 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2727 if (!cal) {
2728 AliInfo("Could not get calibDB");
2729 return kFALSE;
2730 }
2731 if(fCalDet) delete fCalDet;
2732 if(fCalDet2) delete fCalDet2;
2733 fCalDet = new AliTRDCalDet(*(cal->GetVdriftDet()));
2734 fCalDet2 = new AliTRDCalDet(*(cal->GetT0Det()));
2735 }
2736 else{
2737 Float_t devalue = 1.5;
2738 Float_t devalue2 = 0.0;
2739 if(fCalDet) delete fCalDet;
2740 if(fCalDet2) delete fCalDet2;
2741 fCalDet = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2742 fCalDet2 = new AliTRDCalDet("ChamberT0","T0 (detector value)");
2743 for(Int_t k = 0; k < 540; k++){
2744 fCalDet->SetValue(k,devalue);
2745 fCalDet2->SetValue(k,devalue2);
2746 }
2747 }
2748 return kTRUE;
55a288e5 2749}
3a0f6479 2750//____________Functions for initialising the AliTRDCalibraFit in the code_________
2751Bool_t AliTRDCalibraFit::InitFitPRF()
55a288e5 2752{
2753 //
3a0f6479 2754 // Init the calibration mode (Nz, Nrphi), the histograms for
2755 // debugging the fit methods if fDebug > 0,
2756 //
2757
2758 gDirectory = gROOT;
2759 fVectorFit.SetName("prfwidthcoefficients");
2760
2761 fCurrentCoefDetector = new Float_t[2304];
2762 for (Int_t k = 0; k < 2304; k++) {
2763 fCurrentCoefDetector[k] = 0.0;
55a288e5 2764 }
2765
3a0f6479 2766 // fDebug == 0 nothing
2767 // fDebug == 1 and fFitVoir no histo
2768 if (fDebugLevel == 1) {
2769 if(!CheckFitVoir()) return kFALSE;
2770 }
2771 return kTRUE;
55a288e5 2772}
3a0f6479 2773//____________Functions for initialising the AliTRDCalibraFit in the code_________
2774Bool_t AliTRDCalibraFit::InitFitLinearFitter()
55a288e5 2775{
2776 //
3a0f6479 2777 // Init the fCalDet, fVectorFit fCurrentCoefDetector
55a288e5 2778 //
3a0f6479 2779
2780 gDirectory = gROOT;
2781
2782 fCurrentCoefDetector = new Float_t[2304];
2783 fCurrentCoefDetector2 = new Float_t[2304];
2784 for (Int_t k = 0; k < 2304; k++) {
2785 fCurrentCoefDetector[k] = 0.0;
2786 fCurrentCoefDetector2[k] = 0.0;
55a288e5 2787 }
2788
3a0f6479 2789 //printf("test0\n");
2790
2791 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2792 if (!cal) {
2793 AliInfo("Could not get calibDB");
2794 return kFALSE;
55a288e5 2795 }
2796
3a0f6479 2797 //Get the CalDet object
2798 if(fAccCDB){
2799 if(fCalDet) delete fCalDet;
2800 if(fCalDet2) delete fCalDet2;
2801 fCalDet = new AliTRDCalDet(*(cal->GetVdriftDet()));
2802 //printf("test1\n");
2803 fCalDet2 = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
2804 //printf("test2\n");
2805 for(Int_t k = 0; k < 540; k++){
a076fc2f 2806 fCalDet2->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(fCalDet->GetValue(k)));
3a0f6479 2807 }
2808 //printf("test3\n");
2809 }
2810 else{
2811 Float_t devalue = 1.5;
a076fc2f 2812 Float_t devalue2 = AliTRDCommonParam::Instance()->GetOmegaTau(1.5);
3a0f6479 2813 if(fCalDet) delete fCalDet;
2814 if(fCalDet2) delete fCalDet2;
2815 //printf("test1\n");
2816 fCalDet = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2817 fCalDet2 = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
2818 //printf("test2\n");
2819 for(Int_t k = 0; k < 540; k++){
2820 fCalDet->SetValue(k,devalue);
2821 fCalDet2->SetValue(k,devalue2);
2822 }
2823 //printf("test3\n");
2824 }
55a288e5 2825 return kTRUE;
55a288e5 2826}
2827
2828//____________Functions for initialising the AliTRDCalibraFit in the code_________
3a0f6479 2829void AliTRDCalibraFit::InitfCountDetAndfCount(Int_t i)
55a288e5 2830{
2831 //
3a0f6479 2832 // Init the current detector where we are fCountDet and the
2833 // next fCount for the functions Fit...
55a288e5 2834 //
2835
3a0f6479 2836 // Loop on the Xbins of ch!!
2837 fCountDet = -1; // Current detector
2838 fCount = 0; // To find the next detector
2839
2840 // If fDebug >= 3
2841 if (fDebugLevel >= 3) {
2842 // Set countdet to the detector
2843 fCountDet = AliTRDgeometry::GetDetector(fDet[0],fDet[1],fDet[2]);
2844 // Set counter to write at the end of the detector
2845 fCount = fDect2;
2846 // Get the right calib objects
2847 SetCalROC(i);
2848 }
2849 if(fDebugLevel == 1) {
2850 fCountDet = 0;
2851 fCalibraMode->CalculXBins(fCountDet,i);
6aafa7ea 2852 if((fCalibraMode->GetNz(i)!=100) && (fCalibraMode->GetNrphi(i)!=100)){
2853 while(fCalibraMode->GetXbins(i) <=fFitVoir){
2854 fCountDet++;
2855 fCalibraMode->CalculXBins(fCountDet,i);
2856 //printf("GetXBins %d\n",fCalibraMode->GetXbins(i));
2857 }
2858 }
2859 else {
3a0f6479 2860 fCountDet++;
6aafa7ea 2861 }
3a0f6479 2862 fCount = fCalibraMode->GetXbins(i);
2863 fCountDet--;
2864 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
053767a4 2865 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
2866 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
2867 ,(Int_t) GetStack(fCountDet)
2868 ,(Int_t) GetSector(fCountDet),i);
3a0f6479 2869 }
2870}
2871//_______________________________________________________________________________
2872void AliTRDCalibraFit::CalculNumberOfBinsExpected(Int_t i)
2873{
2874 //
2875 // Calculate the number of bins expected (calibration groups)
2876 //
2877
2878 fNumberOfBinsExpected = 0;
64942b85 2879 // All
2880 if((fCalibraMode->GetNz(i) == 100) && (fCalibraMode->GetNrphi(i) == 100)){
2881 fNumberOfBinsExpected = 1;
2882 return;
2883 }
2884 // Per supermodule
2885 if((fCalibraMode->GetNz(i) == 10) && (fCalibraMode->GetNrphi(i) == 10)){
2886 fNumberOfBinsExpected = 18;
2887 return;
2888 }
2889 // More
55a288e5 2890 fCalibraMode->ModePadCalibration(2,i);
2891 fCalibraMode->ModePadFragmentation(0,2,0,i);
2892 fCalibraMode->SetDetChamb2(i);
3a0f6479 2893 if (fDebugLevel > 1) {
55a288e5 2894 AliInfo(Form("For the chamber 2: %d",fCalibraMode->GetDetChamb2(i)));
2895 }
3a0f6479 2896 fNumberOfBinsExpected += 6 * 18 * fCalibraMode->GetDetChamb2(i);
55a288e5 2897 fCalibraMode->ModePadCalibration(0,i);
2898 fCalibraMode->ModePadFragmentation(0,0,0,i);
2899 fCalibraMode->SetDetChamb0(i);
3a0f6479 2900 if (fDebugLevel > 1) {
55a288e5 2901 AliInfo(Form("For the other chamber 0: %d",fCalibraMode->GetDetChamb0(i)));
2902 }
3a0f6479 2903 fNumberOfBinsExpected += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
2904
2905}
2906//_______________________________________________________________________________
2907void AliTRDCalibraFit::CalculDect1Dect2(Int_t i)
2908{
2909 //
2910 // Calculate the range of fits
2911 //
55a288e5 2912
3a0f6479 2913 fDect1 = -1;
2914 fDect2 = -1;
2915 if (fDebugLevel == 1) {
2916 fDect1 = fFitVoir;
2917 fDect2 = fDect1 +1;
55a288e5 2918 }
3a0f6479 2919 if ((fDebugLevel == 2) || (fDebugLevel == 0)) {
2920 fDect1 = 0;
2921 fDect2 = fNumberOfBinsExpected;
55a288e5 2922 }
3a0f6479 2923 if (fDebugLevel >= 3) {
2924 fCountDet = AliTRDgeometry::GetDetector(fDet[0],fDet[1],fDet[2]);
2925 fCalibraMode->CalculXBins(fCountDet,i);
2926 fDect1 = fCalibraMode->GetXbins(i);
2927 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
053767a4 2928 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
2929 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
2930 ,(Int_t) GetStack(fCountDet)
2931 ,(Int_t) GetSector(fCountDet),i);
3a0f6479 2932 // Set for the next detector
2933 fDect2 = fDect1 + fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i);
55a288e5 2934 }
55a288e5 2935}
3a0f6479 2936//_______________________________________________________________________________
2937Bool_t AliTRDCalibraFit::CheckFitVoir()
55a288e5 2938{
2939 //
3a0f6479 2940 // Check if fFitVoir is in the range
55a288e5 2941 //
2942
3a0f6479 2943 if (fFitVoir < fNumberOfBinsExpected) {
2944 AliInfo(Form("We will see the fit of the object %d",fFitVoir));
55a288e5 2945 }
3a0f6479 2946 else {
2947 AliInfo("fFitVoir is out of range of the histo!");
2948 return kFALSE;
2949 }
2950 return kTRUE;
55a288e5 2951}
55a288e5 2952//____________Functions for initialising the AliTRDCalibraFit in the code_________
2953void AliTRDCalibraFit::UpdatefCountDetAndfCount(Int_t idect, Int_t i)
2954{
2955 //
2956 // See if we are in a new detector and update the
2957 // variables fNfragZ and fNfragRphi if yes
3a0f6479 2958 // Will never happen for only one detector (3 and 4)
2959 // Doesn't matter for 2
2960 //
2961 if (fCount == idect) {
64942b85 2962 // On en est au detector (or first detector in the group)
2963 fCountDet += 1;
2964 AliDebug(2,Form("We are at the detector %d\n",fCountDet));
2965 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
2966 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
2967 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
053767a4 2968 ,(Int_t) GetStack(fCountDet)
2969 ,(Int_t) GetSector(fCountDet),i);
64942b85 2970 // Set for the next detector
2971 fCount += fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i);
2972 // calib objects
2973 SetCalROC(i);
2974 }
55a288e5 2975}
55a288e5 2976//____________Functions for initialising the AliTRDCalibraFit in the code_________
2977void AliTRDCalibraFit::ReconstructFitRowMinRowMax(Int_t idect, Int_t i)
2978{
2979 //
2980 // Reconstruct the min pad row, max pad row, min pad col and
2981 // max pad col of the calibration group for the Fit functions
64942b85 2982 // idect is the calibration group inside the detector
55a288e5 2983 //
3a0f6479 2984 if (fDebugLevel != 1) {
2985 fCalibraMode->ReconstructionRowPadGroup((Int_t) (idect-(fCount-(fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i)))),i);
55a288e5 2986 }
64942b85 2987 AliDebug(2,Form("AliTRDCalibraFit::ReconstructFitRowMinRowMax: the local calibration group is %d",idect-(fCount-(fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i)))));
2988 AliDebug(2,Form("AliTRDCalibraFit::ReconstructFitRowMinRowMax: the number of group per detector is %d",fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i)));
55a288e5 2989}
55a288e5 2990//____________Functions for initialising the AliTRDCalibraFit in the code_________
3a0f6479 2991Bool_t AliTRDCalibraFit::NotEnoughStatisticCH(Int_t idect)
55a288e5 2992{
2993 //
2994 // For the case where there are not enough entries in the histograms
3a0f6479 2995 // of the calibration group, the value present in the choosen database
2996 // will be put. A negativ sign enables to know that a fit was not possible.
2997 //
2998
2999 if (fDebugLevel == 1) {
3000 AliInfo("The element has not enough statistic to be fitted");
55a288e5 3001 }
64942b85 3002 else if (fNbDet > 0){
3003 Int_t firstdetector = fCountDet;
3004 Int_t lastdetector = fCountDet+fNbDet;
3005 AliInfo(Form("The element %d containing the detectors %d to %d has not enough statistic to be fitted"
3006 ,idect,firstdetector,lastdetector));
3007 // loop over detectors
3008 for(Int_t det = firstdetector; det < lastdetector; det++){
3009
3010 //Set the calibration object again
3011 fCountDet = det;
3012 SetCalROC(0);
3013
3014 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
3015 // Put them at 1
3016 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),0);
3017 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
3018 ,(Int_t) GetStack(fCountDet)
3019 ,(Int_t) GetSector(fCountDet),0);
3020 // Reconstruct row min row max
3021 ReconstructFitRowMinRowMax(idect,0);
3022
3023 // Calcul the coef from the database choosen for the detector
3024 CalculChargeCoefMean(kFALSE);
3025
3026 //stack 2, not stack 2
3027 Int_t factor = 0;
3028 if(GetStack(fCountDet) == 2) factor = 12;
3029 else factor = 16;
3030
3031 // Fill the fCurrentCoefDetector with negative value to say: not fitted
3032 for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
3033 for (Int_t j = fCalibraMode->GetColMin(0); j < fCalibraMode->GetColMax(0); j++) {
3034 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
3035 }
3036 }
3037
3038 //Put default value negative
3039 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3040 fCurrentCoefE = 0.0;
3041
3042 // Fill the stuff
3043 FillVectorFit();
3044 // Debug
3045 if(fDebugLevel > 1){
3046
3047 if ( !fDebugStreamer ) {
3048 //debug stream
3049 TDirectory *backup = gDirectory;
3050 fDebugStreamer = new TTreeSRedirector("TRDDebugFitCH.root");
3051 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3052 }
3053
3054 Int_t detector = fCountDet;
3055 Int_t caligroup = idect;
3056 Short_t rowmin = fCalibraMode->GetRowMin(0);
3057 Short_t rowmax = fCalibraMode->GetRowMax(0);
3058 Short_t colmin = fCalibraMode->GetColMin(0);
3059 Short_t colmax = fCalibraMode->GetColMax(0);
3060 Float_t gf = fCurrentCoef[0];
3061 Float_t gfs = fCurrentCoef[1];
3062 Float_t gfE = fCurrentCoefE;
3063
3064 (*fDebugStreamer) << "FillFillCH" <<
3065 "detector=" << detector <<
3066 "caligroup=" << caligroup <<
3067 "rowmin=" << rowmin <<
3068 "rowmax=" << rowmax <<
3069 "colmin=" << colmin <<
3070 "colmax=" << colmax <<
3071 "gf=" << gf <<
3072 "gfs=" << gfs <<
3073 "gfE=" << gfE <<
3074 "\n";
3075
3076 }
3077 // Reset
3078 for (Int_t k = 0; k < 2304; k++) {
3079 fCurrentCoefDetector[k] = 0.0;
3080 }
3081
3082 }// loop detector
3083 AliDebug(2,Form("Check the count now: fCountDet %d",fCountDet));
3084 }
3a0f6479 3085 else {
55a288e5 3086
3a0f6479 3087 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
3088 ,idect-(fCount-(fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))),fCountDet));
3089
3090 // Calcul the coef from the database choosen
3091 CalculChargeCoefMean(kFALSE);
55a288e5 3092
053767a4 3093 //stack 2, not stack 2
3a0f6479 3094 Int_t factor = 0;
053767a4 3095 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 3096 else factor = 16;
55a288e5 3097
3a0f6479 3098 // Fill the fCurrentCoefDetector with negative value to say: not fitted
3099 for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
3100 for (Int_t j = fCalibraMode->GetColMin(0); j < fCalibraMode->GetColMax(0); j++) {
3101 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
55a288e5 3102 }
3103 }
3a0f6479 3104
3105 //Put default value negative
3106 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3107 fCurrentCoefE = 0.0;
3108
3109 FillFillCH(idect);
3110 }
3111
3112 return kTRUE;
55a288e5 3113}
3114
3a0f6479 3115
3116//____________Functions for initialising the AliTRDCalibraFit in the code_________
64942b85 3117Bool_t AliTRDCalibraFit::NotEnoughStatisticPH(Int_t idect,Double_t nentries)
55a288e5 3118{
3119 //
3a0f6479 3120 // For the case where there are not enough entries in the histograms
3121 // of the calibration group, the value present in the choosen database
3122 // will be put. A negativ sign enables to know that a fit was not possible.
55a288e5 3123 //
3a0f6479 3124 if (fDebugLevel == 1) {
3125 AliInfo("The element has not enough statistic to be fitted");
3126 }
64942b85 3127 else if (fNbDet > 0) {
3128
3129 Int_t firstdetector = fCountDet;
3130 Int_t lastdetector = fCountDet+fNbDet;
3131 AliInfo(Form("The element %d containing the detectors %d to %d has not enough statistic to be fitted"
3132 ,idect,firstdetector,lastdetector));
3133 // loop over detectors
3134 for(Int_t det = firstdetector; det < lastdetector; det++){
3135
3136 //Set the calibration object again
3137 fCountDet = det;
3138 SetCalROC(1);
3139
3140 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
3141 // Put them at 1
3142 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),1);
3143 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
3144 ,(Int_t) GetStack(fCountDet)
3145 ,(Int_t) GetSector(fCountDet),1);
3146 // Reconstruct row min row max
3147 ReconstructFitRowMinRowMax(idect,1);
3148
3149 // Calcul the coef from the database choosen for the detector
3150 CalculVdriftCoefMean();
3151 CalculT0CoefMean();
3152
3153 //stack 2, not stack 2
3154 Int_t factor = 0;
3155 if(GetStack(fCountDet) == 2) factor = 12;
3156 else factor = 16;
3157
3158 // Fill the fCurrentCoefDetector with negative value to say: not fitted
3159 for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
3160 for (Int_t j = fCalibraMode->GetColMin(1); j < fCalibraMode->GetColMax(1); j++) {
3161 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
3162 fCurrentCoefDetector2[(Int_t)(j*factor+k)] = fCurrentCoef2[1] + 100.0;
3163 }
3164 }
3165
3166 //Put default value negative
3167 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3168 fCurrentCoefE = 0.0;
3169 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
3170 fCurrentCoefE2 = 0.0;
3171
3172 // Fill the stuff
3173 FillVectorFit();
3174 FillVectorFit2();
3175 // Debug
3176 if(fDebugLevel > 1){
3177
3178 if ( !fDebugStreamer ) {
3179 //debug stream
3180 TDirectory *backup = gDirectory;
3181 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPH.root");
3182 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3183 }
3184
3185
3186 Int_t detector = fCountDet;
3187 Int_t caligroup = idect;
3188 Short_t rowmin = fCalibraMode->GetRowMin(1);
3189 Short_t rowmax = fCalibraMode->GetRowMax(1);
3190 Short_t colmin = fCalibraMode->GetColMin(1);
3191 Short_t colmax = fCalibraMode->GetColMax(1);
3192 Float_t vf = fCurrentCoef[0];
3193 Float_t vs = fCurrentCoef[1];
3194 Float_t vfE = fCurrentCoefE;
3195 Float_t t0f = fCurrentCoef2[0];
3196 Float_t t0s = fCurrentCoef2[1];
3197 Float_t t0E = fCurrentCoefE2;
3198
3199
3200
3201 (* fDebugStreamer) << "FillFillPH"<<
3202 "detector="<<detector<<
3203 "nentries="<<nentries<<
3204 "caligroup="<<caligroup<<
3205 "rowmin="<<rowmin<<
3206 "rowmax="<<rowmax<<
3207 "colmin="<<colmin<<
3208 "colmax="<<colmax<<
3209 "vf="<<vf<<
3210 "vs="<<vs<<
3211 "vfE="<<vfE<<
3212 "t0f="<<t0f<<
3213 "t0s="<<t0s<<
3214 "t0E="<<t0E<<
3215 "\n";
3216 }
3217 // Reset
3218 for (Int_t k = 0; k < 2304; k++) {
3219 fCurrentCoefDetector[k] = 0.0;
3220 fCurrentCoefDetector2[k] = 0.0;
3221 }
3222
3223 }// loop detector
3224 AliDebug(2,Form("Check the count now: fCountDet %d",fCountDet));
3225 }
3a0f6479 3226 else {
55a288e5 3227
3a0f6479 3228 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
3229 ,idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))),fCountDet));
55a288e5 3230
3a0f6479 3231 CalculVdriftCoefMean();
3232 CalculT0CoefMean();
55a288e5 3233
053767a4 3234 //stack 2 and not stack 2
3a0f6479 3235 Int_t factor = 0;
053767a4 3236 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 3237 else factor = 16;
55a288e5 3238
55a288e5 3239
3a0f6479 3240 // Fill the fCurrentCoefDetector 2
3241 for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
3242 for (Int_t j = fCalibraMode->GetColMin(1); j < fCalibraMode->GetColMax(1); j++) {
3243 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
64942b85 3244 fCurrentCoefDetector2[(Int_t)(j*factor+k)] = fCurrentCoef2[1] + 100.0;
55a288e5 3245 }
3246 }
55a288e5 3247
3a0f6479 3248 // Put the default value
3249 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3250 fCurrentCoefE = 0.0;
64942b85 3251 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
3a0f6479 3252 fCurrentCoefE2 = 0.0;
3253
64942b85 3254 FillFillPH(idect,nentries);
3a0f6479 3255
3256 }
55a288e5 3257
3a0f6479 3258 return kTRUE;
64942b85 3259
3a0f6479 3260}
3261
3262
3263//____________Functions for initialising the AliTRDCalibraFit in the code_________
3264Bool_t AliTRDCalibraFit::NotEnoughStatisticPRF(Int_t idect)
3265{
3266 //
3267 // For the case where there are not enough entries in the histograms
3268 // of the calibration group, the value present in the choosen database
3269 // will be put. A negativ sign enables to know that a fit was not possible.
3270 //
55a288e5 3271
3a0f6479 3272 if (fDebugLevel == 1) {
3273 AliInfo("The element has not enough statistic to be fitted");
55a288e5 3274 }
64942b85 3275 else if (fNbDet > 0){
3276
3277 Int_t firstdetector = fCountDet;
3278 Int_t lastdetector = fCountDet+fNbDet;
3279 AliInfo(Form("The element %d containing the detectors %d to %d has not enough statistic to be fitted"
3280 ,idect,firstdetector,lastdetector));
3281
3282 // loop over detectors
3283 for(Int_t det = firstdetector; det < lastdetector; det++){
3284
3285 //Set the calibration object again
3286 fCountDet = det;
3287 SetCalROC(2);
3288
3289 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
3290 // Put them at 1
3291 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),2);
3292 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
3293 ,(Int_t) GetStack(fCountDet)
3294 ,(Int_t) GetSector(fCountDet),2);
3295 // Reconstruct row min row max
3296 ReconstructFitRowMinRowMax(idect,2);
3297
3298 // Calcul the coef from the database choosen for the detector
3299 CalculPRFCoefMean();
3300
3301 //stack 2, not stack 2
3302 Int_t factor = 0;
3303 if(GetStack(fCountDet) == 2) factor = 12;
3304 else factor = 16;
3305
3306 // Fill the fCurrentCoefDetector with negative value to say: not fitted
3307 for (Int_t k = fCalibraMode->GetRowMin(2); k < fCalibraMode->GetRowMax(2); k++) {
3308 for (Int_t j = fCalibraMode->GetColMin(2); j < fCalibraMode->GetColMax(2); j++) {
3309 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
3310 }
3311 }
3312
3313 //Put default value negative
3314 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3315 fCurrentCoefE = 0.0;
3316
3317 // Fill the stuff
3318 FillVectorFit();
3319 // Debug
3320 if(fDebugLevel > 1){
3321
3322 if ( !fDebugStreamer ) {
3323 //debug stream
3324 TDirectory *backup = gDirectory;
3325 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPRF.root");
3326 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3327 }
3328
3329 Int_t detector = fCountDet;
3330 Int_t layer = GetLayer(fCountDet);
3331 Int_t caligroup = idect;
3332 Short_t rowmin = fCalibraMode->GetRowMin(2);
3333 Short_t rowmax = fCalibraMode->GetRowMax(2);
3334 Short_t colmin = fCalibraMode->GetColMin(2);
3335 Short_t colmax = fCalibraMode->GetColMax(2);
3336 Float_t widf = fCurrentCoef[0];
3337 Float_t wids = fCurrentCoef[1];
3338 Float_t widfE = fCurrentCoefE;
3339
3340 (* fDebugStreamer) << "FillFillPRF"<<
3341 "detector="<<detector<<
3342 "layer="<<layer<<
3343 "caligroup="<<caligroup<<
3344 "rowmin="<<rowmin<<
3345 "rowmax="<<rowmax<<
3346 "colmin="<<colmin<<
3347 "colmax="<<colmax<<
3348 "widf="<<widf<<
3349 "wids="<<wids<<
3350 "widfE="<<widfE<<
3351 "\n";
3352 }
3353 // Reset
3354 for (Int_t k = 0; k < 2304; k++) {
3355 fCurrentCoefDetector[k] = 0.0;
3356 }
3357
3358 }// loop detector
3359 AliDebug(2,Form("Check the count now: fCountDet %d",fCountDet));
3360 }
3a0f6479 3361 else {
3362
3363 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
3364 ,idect-(fCount-(fCalibraMode->GetNfragZ(2)*fCalibraMode->GetNfragRphi(2))),fCountDet));
3365
3366 CalculPRFCoefMean();
3367
053767a4 3368 // stack 2 and not stack 2
3a0f6479 3369 Int_t factor = 0;
053767a4 3370 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 3371 else factor = 16;
55a288e5 3372
55a288e5 3373
3a0f6479 3374 // Fill the fCurrentCoefDetector
3375 for (Int_t k = fCalibraMode->GetRowMin(2); k < fCalibraMode->GetRowMax(2); k++) {
3376 for (Int_t j = fCalibraMode->GetColMin(2); j < fCalibraMode->GetColMax(2); j++) {
64942b85 3377 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
55a288e5 3378 }
3379 }
55a288e5 3380
3a0f6479 3381 // Put the default value
64942b85 3382 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3a0f6479 3383 fCurrentCoefE = 0.0;
3384
3385 FillFillPRF(idect);
3386 }
3387
3388 return kTRUE;
55a288e5 3389
3a0f6479 3390}
3391//____________Functions for initialising the AliTRDCalibraFit in the code_________
3392Bool_t AliTRDCalibraFit::NotEnoughStatisticLinearFitter()
55a288e5 3393{
3394 //
3a0f6479 3395 // For the case where there are not enough entries in the histograms
3396 // of the calibration group, the value present in the choosen database
3397 // will be put. A negativ sign enables to know that a fit was not possible.
3398 //
3399
3400 // Calcul the coef from the database choosen
3401 CalculVdriftLorentzCoef();
3402
3403 Int_t factor = 0;
053767a4 3404 if(GetStack(fCountDet) == 2) factor = 1728;
3a0f6479 3405 else factor = 2304;
3406
3407
3408 // Fill the fCurrentCoefDetector
3409 for (Int_t k = 0; k < factor; k++) {
3410 fCurrentCoefDetector[k] = -TMath::Abs(fCurrentCoef[1]);
3411 // should be negative
3412 fCurrentCoefDetector2[k] = +TMath::Abs(fCurrentCoef2[1]);
55a288e5 3413 }
3a0f6479 3414
3415
3416 //Put default opposite sign
3417 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3418 fCurrentCoefE = 0.0;
3419 fCurrentCoef2[0] = +TMath::Abs(fCurrentCoef2[1]);
3420 fCurrentCoefE2 = 0.0;
3421
3422 FillFillLinearFitter();
3423
3424 return kTRUE;
55a288e5 3425}
3426
3a0f6479 3427//____________Functions for initialising the AliTRDCalibraFit in the code_________
3428Bool_t AliTRDCalibraFit::FillInfosFitCH(Int_t idect)
55a288e5 3429{
3430 //
3a0f6479 3431 // Fill the coefficients found with the fits or other
3432 // methods from the Fit functions
3433 //
3434
3435 if (fDebugLevel != 1) {
64942b85 3436 if (fNbDet > 0){
3437 Int_t firstdetector = fCountDet;
3438 Int_t lastdetector = fCountDet+fNbDet;
3439 AliInfo(Form("The element %d containing the detectors %d to %d has been fitted"
3440 ,idect,firstdetector,lastdetector));
3441 // loop over detectors
3442 for(Int_t det = firstdetector; det < lastdetector; det++){
3443
3444 //Set the calibration object again
3445 fCountDet = det;
3446 SetCalROC(0);
3447
3448 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
3449 // Put them at 1
3450 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),0);
3451 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
3452 ,(Int_t) GetStack(fCountDet)
3453 ,(Int_t) GetSector(fCountDet),0);
3454 // Reconstruct row min row max
3455 ReconstructFitRowMinRowMax(idect,0);
3456
3457 // Calcul the coef from the database choosen for the detector
3458 if(fCurrentCoef[0] < 0.0) CalculChargeCoefMean(kFALSE);
3459 else CalculChargeCoefMean(kTRUE);
3460
3461 //stack 2, not stack 2
3462 Int_t factor = 0;
3463 if(GetStack(fCountDet) == 2) factor = 12;
3464 else factor = 16;
3465
3466 // Fill the fCurrentCoefDetector with negative value to say: not fitted
3467 Double_t coeftoput = 1.0;
3468 if(fCurrentCoef[0] < 0.0) coeftoput = - TMath::Abs(fCurrentCoef[1]);
3469 else coeftoput = fCurrentCoef[0];
3470 for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
3471 for (Int_t j = fCalibraMode->GetColMin(0); j < fCalibraMode->GetColMax(0); j++) {
3472 fCurrentCoefDetector[(Int_t)(j*factor+k)] = coeftoput;
3473 }
3474 }
3475
3476 // Fill the stuff
3477 FillVectorFit();
3478 // Debug
3479 if(fDebugLevel > 1){
3480
3481 if ( !fDebugStreamer ) {
3482 //debug stream
3483 TDirectory *backup = gDirectory;
3484 fDebugStreamer = new TTreeSRedirector("TRDDebugFitCH.root");
3485 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3486 }
3487
3488 Int_t detector = fCountDet;
3489 Int_t caligroup = idect;
3490 Short_t rowmin = fCalibraMode->GetRowMin(0);
3491 Short_t rowmax = fCalibraMode->GetRowMax(0);
3492 Short_t colmin = fCalibraMode->GetColMin(0);
3493 Short_t colmax = fCalibraMode->GetColMax(0);
3494 Float_t gf = fCurrentCoef[0];
3495 Float_t gfs = fCurrentCoef[1];
3496 Float_t gfE = fCurrentCoefE;
3497
3498 (*fDebugStreamer) << "FillFillCH" <<
3499 "detector=" << detector <<
3500 "caligroup=" << caligroup <<
3501 "rowmin=" << rowmin <<
3502 "rowmax=" << rowmax <<
3503 "colmin=" << colmin <<
3504 "colmax=" << colmax <<
3505 "gf=" << gf <<
3506 "gfs=" << gfs <<
3507 "gfE=" << gfE <<
3508 "\n";
3509
3510 }
3511 // Reset
3512 for (Int_t k = 0; k < 2304; k++) {
3513 fCurrentCoefDetector[k] = 0.0;
3514 }
3515
3516 }// loop detector
3517 //printf("Check the count now: fCountDet %d\n",fCountDet);
3518 }
3519 else{
3520
3521 Int_t factor = 0;
3522 if(GetStack(fCountDet) == 2) factor = 12;
3523 else factor = 16;
3524
3525 for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
3526 for (Int_t j = fCalibraMode->GetColMin(0); j < fCalibraMode->GetColMax(0); j++) {
3527 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
3528 }
3a0f6479 3529 }
64942b85 3530
3531 FillFillCH(idect);
55a288e5 3532 }
3533 }
55a288e5 3534
3a0f6479 3535 return kTRUE;
3536
3537}
3538//____________Functions for initialising the AliTRDCalibraFit in the code_________
64942b85 3539Bool_t AliTRDCalibraFit::FillInfosFitPH(Int_t idect,Double_t nentries)
55a288e5 3540{
3541 //
3a0f6479 3542 // Fill the coefficients found with the fits or other
3543 // methods from the Fit functions
3544 //
3545
3546 if (fDebugLevel != 1) {
64942b85 3547 if (fNbDet > 0){
3548
3549 Int_t firstdetector = fCountDet;
3550 Int_t lastdetector = fCountDet+fNbDet;
3551 AliInfo(Form("The element %d containing the detectors %d to %d has been fitted"
3552 ,idect,firstdetector,lastdetector));
3553
3554 // loop over detectors
3555 for(Int_t det = firstdetector; det < lastdetector; det++){
3556
3557 //Set the calibration object again
3558 fCountDet = det;
3559 SetCalROC(1);
3560
3561 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
3562 // Put them at 1
3563 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),1);
3564 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
3565 ,(Int_t) GetStack(fCountDet)
3566 ,(Int_t) GetSector(fCountDet),1);
3567 // Reconstruct row min row max
3568 ReconstructFitRowMinRowMax(idect,1);
3569
3570 // Calcul the coef from the database choosen for the detector
3571 CalculVdriftCoefMean();
3572 CalculT0CoefMean();
3573
3574 //stack 2, not stack 2
3575 Int_t factor = 0;
3576 if(GetStack(fCountDet) == 2) factor = 12;
3577 else factor = 16;
3578
3579 // Fill the fCurrentCoefDetector with negative value to say: not fitted
3580 Double_t coeftoput = 1.5;
3581 Double_t coeftoput2 = 0.0;
3582
3583 if(fCurrentCoef[0] < 0.0) coeftoput = - TMath::Abs(fCurrentCoef[1]);
3584 else coeftoput = fCurrentCoef[0];
3585
3586 if(fCurrentCoef2[0] > 70.0) coeftoput2 = fCurrentCoef2[1] + 100.0;
3587 else coeftoput2 = fCurrentCoef2[0];
3588
3589 for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
3590 for (Int_t j = fCalibraMode->GetColMin(1); j < fCalibraMode->GetColMax(1); j++) {
3591 fCurrentCoefDetector[(Int_t)(j*factor+k)] = coeftoput;
3592 fCurrentCoefDetector2[(Int_t)(j*factor+k)] = coeftoput2;
3593 }
3594 }
3595
3596 // Fill the stuff
3597 FillVectorFit();
3598 FillVectorFit2();
3599 // Debug
3600 if(fDebugLevel > 1){
3601
3602 if ( !fDebugStreamer ) {
3603 //debug stream
3604 TDirectory *backup = gDirectory;
3605 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPH.root");
3606 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3607 }
3608
3609
3610 Int_t detector = fCountDet;
3611 Int_t caligroup = idect;
3612 Short_t rowmin = fCalibraMode->GetRowMin(1);
3613 Short_t rowmax = fCalibraMode->GetRowMax(1);
3614 Short_t colmin = fCalibraMode->GetColMin(1);
3615 Short_t colmax = fCalibraMode->GetColMax(1);
3616 Float_t vf = fCurrentCoef[0];
3617 Float_t vs = fCurrentCoef[1];
3618 Float_t vfE = fCurrentCoefE;
3619 Float_t t0f = fCurrentCoef2[0];
3620 Float_t t0s = fCurrentCoef2[1];
3621 Float_t t0E = fCurrentCoefE2;
3622
3623
3624
3625 (* fDebugStreamer) << "FillFillPH"<<
3626 "detector="<<detector<<
3627 "nentries="<<nentries<<
3628 "caligroup="<<caligroup<<
3629 "rowmin="<<rowmin<<
3630 "rowmax="<<rowmax<<
3631 "colmin="<<colmin<<
3632 "colmax="<<colmax<<
3633 "vf="<<vf<<
3634 "vs="<<vs<<
3635 "vfE="<<vfE<<
3636 "t0f="<<t0f<<
3637 "t0s="<<t0s<<
3638 "t0E="<<t0E<<
3639 "\n";
3640 }
3641 // Reset
3642 for (Int_t k = 0; k < 2304; k++) {
3643 fCurrentCoefDetector[k] = 0.0;
3644 fCurrentCoefDetector2[k] = 0.0;
3645 }
3646
3647 }// loop detector
3648 //printf("Check the count now: fCountDet %d\n",fCountDet);
3649 }
3650 else {
3651
3652 Int_t factor = 0;
3653 if(GetStack(fCountDet) == 2) factor = 12;
3654 else factor = 16;
3655
3656 for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
3657 for (Int_t j = fCalibraMode->GetColMin(1); j < fCalibraMode->GetColMax(1); j++) {
3658 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
3659 fCurrentCoefDetector2[(Int_t)(j*factor+k)] = fCurrentCoef2[0];
3660 }
3661 }
3662
3663 FillFillPH(idect,nentries);
3664 }
55a288e5 3665 }
3a0f6479 3666 return kTRUE;
55a288e5 3667}
3a0f6479 3668//____________Functions for initialising the AliTRDCalibraFit in the code_________
3669Bool_t AliTRDCalibraFit::FillInfosFitPRF(Int_t idect)
55a288e5 3670{
3671 //
3a0f6479 3672 // Fill the coefficients found with the fits or other
3673 // methods from the Fit functions
55a288e5 3674 //
3a0f6479 3675
3676 if (fDebugLevel != 1) {
64942b85 3677 if (fNbDet > 0){
3a0f6479 3678
64942b85 3679 Int_t firstdetector = fCountDet;
3680 Int_t lastdetector = fCountDet+fNbDet;
3681 AliInfo(Form("The element %d containing the detectors %d to %d has been fitted"
3682 ,idect,firstdetector,lastdetector));
3683
3684 // loop over detectors
3685 for(Int_t det = firstdetector; det < lastdetector; det++){
3686
3687 //Set the calibration object again
3688 fCountDet = det;
3689 SetCalROC(2);
3690
3691 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
3692 // Put them at 1
3693 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),2);
3694 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
3695 ,(Int_t) GetStack(fCountDet)
3696 ,(Int_t) GetSector(fCountDet),2);
3697 // Reconstruct row min row max
3698 ReconstructFitRowMinRowMax(idect,2);
3699
3700 // Calcul the coef from the database choosen for the detector
3701 CalculPRFCoefMean();
3702
3703 //stack 2, not stack 2
3704 Int_t factor = 0;
3705 if(GetStack(fCountDet) == 2) factor = 12;
3706 else factor = 16;
3707
3708 // Fill the fCurrentCoefDetector with negative value to say: not fitted
3709 Double_t coeftoput = 1.0;
3710 if(fCurrentCoef[0] < 0.0) coeftoput = - TMath::Abs(fCurrentCoef[1]);
3711 else coeftoput = fCurrentCoef[0];
3712 for (Int_t k = fCalibraMode->GetRowMin(2); k < fCalibraMode->GetRowMax(2); k++) {
3713 for (Int_t j = fCalibraMode->GetColMin(2); j < fCalibraMode->GetColMax(2); j++) {
3714 fCurrentCoefDetector[(Int_t)(j*factor+k)] = coeftoput;
3715 }
3716 }
3717
3718 // Fill the stuff
3719 FillVectorFit();
3720 // Debug
3721 if(fDebugLevel > 1){
3722
3723 if ( !fDebugStreamer ) {
3724 //debug stream
3725 TDirectory *backup = gDirectory;
3726 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPRF.root");
3727 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3728 }
3729
3730 Int_t detector = fCountDet;
3731 Int_t layer = GetLayer(fCountDet);
3732 Int_t caligroup = idect;
3733 Short_t rowmin = fCalibraMode->GetRowMin(2);
3734 Short_t rowmax = fCalibraMode->GetRowMax(2);
3735 Short_t colmin = fCalibraMode->GetColMin(2);
3736 Short_t colmax = fCalibraMode->GetColMax(2);
3737 Float_t widf = fCurrentCoef[0];
3738 Float_t wids = fCurrentCoef[1];
3739 Float_t widfE = fCurrentCoefE;
3740
3741 (* fDebugStreamer) << "FillFillPRF"<<
3742 "detector="<<detector<<
3743 "layer="<<layer<<
3744 "caligroup="<<caligroup<<
3745 "rowmin="<<rowmin<<
3746 "rowmax="<<rowmax<<
3747 "colmin="<<colmin<<
3748 "colmax="<<colmax<<
3749 "widf="<<widf<<
3750 "wids="<<wids<<
3751 "widfE="<<widfE<<
3752 "\n";
3753 }
3754 // Reset
3755 for (Int_t k = 0; k < 2304; k++) {
3756 fCurrentCoefDetector[k] = 0.0;
3757 }
3758
3759 }// loop detector
3760 //printf("Check the count now: fCountDet %d\n",fCountDet);
3761 }
3762 else {
3763
3764 Int_t factor = 0;
3765 if(GetStack(fCountDet) == 2) factor = 12;
3766 else factor = 16;
3767
3768 // Pointer to the branch
3769 for (Int_t k = fCalibraMode->GetRowMin(2); k < fCalibraMode->GetRowMax(2); k++) {
3770 for (Int_t j = fCalibraMode->GetColMin(2); j < fCalibraMode->GetColMax(2); j++) {
3771 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
3772 }
3a0f6479 3773 }
64942b85 3774 FillFillPRF(idect);
55a288e5 3775 }
3776 }
64942b85 3777
3a0f6479 3778 return kTRUE;
55a288e5 3779
3a0f6479 3780}
3781//____________Functions for initialising the AliTRDCalibraFit in the code_________
3782Bool_t AliTRDCalibraFit::FillInfosFitLinearFitter()
55a288e5 3783{
3784 //
3a0f6479 3785 // Fill the coefficients found with the fits or other
3786 // methods from the Fit functions
55a288e5 3787 //
3a0f6479 3788
3789 Int_t factor = 0;
053767a4 3790 if(GetStack(fCountDet) == 2) factor = 1728;
3a0f6479 3791 else factor = 2304;
3792
3793 // Pointer to the branch
3794 for (Int_t k = 0; k < factor; k++) {
3795 fCurrentCoefDetector[k] = fCurrentCoef[0];
3796 fCurrentCoefDetector2[k] = fCurrentCoef2[0];
55a288e5 3797 }
3a0f6479 3798
3799 FillFillLinearFitter();
3800
3801 return kTRUE;
55a288e5 3802
3803}
3a0f6479 3804//________________________________________________________________________________
3805void AliTRDCalibraFit::FillFillCH(Int_t idect)
55a288e5 3806{
3807 //
3a0f6479 3808 // DebugStream and fVectorFit
55a288e5 3809 //
3810
3a0f6479 3811 // End of one detector
3812 if ((idect == (fCount-1))) {
3813 FillVectorFit();
3814 // Reset
3815 for (Int_t k = 0; k < 2304; k++) {
3816 fCurrentCoefDetector[k] = 0.0;
3817 }
55a288e5 3818 }
3819
3a0f6479 3820 if(fDebugLevel > 1){
55a288e5 3821
3a0f6479 3822 if ( !fDebugStreamer ) {
3823 //debug stream
3824 TDirectory *backup = gDirectory;
4aad967c 3825 fDebugStreamer = new TTreeSRedirector("TRDDebugFitCH.root");
3a0f6479 3826 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3827 }
3828
3829 Int_t detector = fCountDet;
3830 Int_t caligroup = idect;
3831 Short_t rowmin = fCalibraMode->GetRowMin(0);
3832 Short_t rowmax = fCalibraMode->GetRowMax(0);
3833 Short_t colmin = fCalibraMode->GetColMin(0);
3834 Short_t colmax = fCalibraMode->GetColMax(0);
3835 Float_t gf = fCurrentCoef[0];
3836 Float_t gfs = fCurrentCoef[1];
3837 Float_t gfE = fCurrentCoefE;
3838
413153cb 3839 (*fDebugStreamer) << "FillFillCH" <<
3a0f6479 3840 "detector=" << detector <<
3841 "caligroup=" << caligroup <<
3842 "rowmin=" << rowmin <<
3843 "rowmax=" << rowmax <<
3844 "colmin=" << colmin <<
3845 "colmax=" << colmax <<
3846 "gf=" << gf <<
3847 "gfs=" << gfs <<
3848 "gfE=" << gfE <<
3849 "\n";
3850
3851 }
3852}
3853//________________________________________________________________________________
64942b85 3854void AliTRDCalibraFit::FillFillPH(Int_t idect,Double_t nentries)
55a288e5 3855{
3856 //
3a0f6479 3857 // DebugStream and fVectorFit and fVectorFit2
55a288e5 3858 //
3a0f6479 3859
3860 // End of one detector
3861 if ((idect == (fCount-1))) {
3862 FillVectorFit();
3863 FillVectorFit2();
3864 // Reset
3865 for (Int_t k = 0; k < 2304; k++) {
3866 fCurrentCoefDetector[k] = 0.0;
3867 fCurrentCoefDetector2[k] = 0.0;
3868 }
3869 }
3870
3871 if(fDebugLevel > 1){
3872
3873 if ( !fDebugStreamer ) {
3874 //debug stream
3875 TDirectory *backup = gDirectory;
4aad967c 3876 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPH.root");
3a0f6479 3877 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3878 }
3879
3880
3881 Int_t detector = fCountDet;
3882 Int_t caligroup = idect;
3883 Short_t rowmin = fCalibraMode->GetRowMin(1);
3884 Short_t rowmax = fCalibraMode->GetRowMax(1);
3885 Short_t colmin = fCalibraMode->GetColMin(1);
3886 Short_t colmax = fCalibraMode->GetColMax(1);
3887 Float_t vf = fCurrentCoef[0];
3888 Float_t vs = fCurrentCoef[1];
3889 Float_t vfE = fCurrentCoefE;
3890 Float_t t0f = fCurrentCoef2[0];
3891 Float_t t0s = fCurrentCoef2[1];
3892 Float_t t0E = fCurrentCoefE2;
3893
55a288e5 3894
3a0f6479 3895
413153cb 3896 (* fDebugStreamer) << "FillFillPH"<<
3a0f6479 3897 "detector="<<detector<<
64942b85 3898 "nentries="<<nentries<<
3a0f6479 3899 "caligroup="<<caligroup<<
3900 "rowmin="<<rowmin<<
3901 "rowmax="<<rowmax<<
3902 "colmin="<<colmin<<
3903 "colmax="<<colmax<<
3904 "vf="<<vf<<
3905 "vs="<<vs<<
3906 "vfE="<<vfE<<
3907 "t0f="<<t0f<<
3908 "t0s="<<t0s<<
3909 "t0E="<<t0E<<
3910 "\n";
3911 }
55a288e5 3912
3913}
3a0f6479 3914//________________________________________________________________________________
3915void AliTRDCalibraFit::FillFillPRF(Int_t idect)
3916{
3917 //
3918 // DebugStream and fVectorFit
3919 //
55a288e5 3920
3a0f6479 3921 // End of one detector
3922 if ((idect == (fCount-1))) {
3923 FillVectorFit();
3924 // Reset
3925 for (Int_t k = 0; k < 2304; k++) {
3926 fCurrentCoefDetector[k] = 0.0;
3927 }
3928 }
3929
3930
3931 if(fDebugLevel > 1){
3932
3933 if ( !fDebugStreamer ) {
3934 //debug stream
3935 TDirectory *backup = gDirectory;
4aad967c 3936 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPRF.root");
3a0f6479 3937 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3938 }
3939
3940 Int_t detector = fCountDet;
053767a4 3941 Int_t layer = GetLayer(fCountDet);
3a0f6479 3942 Int_t caligroup = idect;
3943 Short_t rowmin = fCalibraMode->GetRowMin(2);
3944 Short_t rowmax = fCalibraMode->GetRowMax(2);
3945 Short_t colmin = fCalibraMode->GetColMin(2);
3946 Short_t colmax = fCalibraMode->GetColMax(2);
3947 Float_t widf = fCurrentCoef[0];
3948 Float_t wids = fCurrentCoef[1];
3949 Float_t widfE = fCurrentCoefE;
3950
413153cb 3951 (* fDebugStreamer) << "FillFillPRF"<<
3a0f6479 3952 "detector="<<detector<<
053767a4 3953 "layer="<<layer<<
3a0f6479 3954 "caligroup="<<caligroup<<
3955 "rowmin="<<rowmin<<
3956 "rowmax="<<rowmax<<
3957 "colmin="<<colmin<<
3958 "colmax="<<colmax<<
3959 "widf="<<widf<<
3960 "wids="<<wids<<
3961 "widfE="<<widfE<<
3962 "\n";
3963 }
3964
3965}
3966//________________________________________________________________________________
3967void AliTRDCalibraFit::FillFillLinearFitter()
55a288e5 3968{
3969 //
3a0f6479 3970 // DebugStream and fVectorFit
55a288e5 3971 //
3a0f6479 3972
3973 // End of one detector
3974 FillVectorFit();
3975 FillVectorFit2();
3976
3977
3978 // Reset
3979 for (Int_t k = 0; k < 2304; k++) {
3980 fCurrentCoefDetector[k] = 0.0;
3981 fCurrentCoefDetector2[k] = 0.0;
55a288e5 3982 }
3a0f6479 3983
55a288e5 3984
3a0f6479 3985 if(fDebugLevel > 1){
55a288e5 3986
3a0f6479 3987 if ( !fDebugStreamer ) {
3988 //debug stream
3989 TDirectory *backup = gDirectory;
4aad967c 3990 fDebugStreamer = new TTreeSRedirector("TRDDebugFitLinearFitter.root");
3a0f6479 3991 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3992 }
3993
3994 //Debug: comparaison of the different methods (okey for first time but not for iterative procedure)
053767a4 3995 AliTRDpadPlane *padplane = fGeo->GetPadPlane(GetLayer(fCountDet),GetStack(fCountDet));
3a0f6479 3996 Float_t rowmd = (padplane->GetRow0()+padplane->GetRowEnd())/2.;
053767a4 3997 Float_t r = AliTRDgeometry::GetTime0(GetLayer(fCountDet));
3a0f6479 3998 Float_t tiltangle = padplane->GetTiltingAngle();
3999 Int_t detector = fCountDet;
053767a4 4000 Int_t stack = GetStack(fCountDet);
4001 Int_t layer = GetLayer(fCountDet);
3a0f6479 4002 Float_t vf = fCurrentCoef[0];
4003 Float_t vs = fCurrentCoef[1];
4004 Float_t vfE = fCurrentCoefE;
4005 Float_t lorentzangler = fCurrentCoef2[0];
e6381f8e 4006 Float_t elorentzangler = fCurrentCoefE2;
3a0f6479 4007 Float_t lorentzangles = fCurrentCoef2[1];
4008
413153cb 4009 (* fDebugStreamer) << "FillFillLinearFitter"<<
3a0f6479 4010 "detector="<<detector<<
053767a4 4011 "stack="<<stack<<
4012 "layer="<<layer<<
3a0f6479 4013 "rowmd="<<rowmd<<
4014 "r="<<r<<
4015 "tiltangle="<<tiltangle<<
4016 "vf="<<vf<<
4017 "vs="<<vs<<
4018 "vfE="<<vfE<<
4019 "lorentzangler="<<lorentzangler<<
e6381f8e 4020 "Elorentzangler="<<elorentzangler<<
3a0f6479 4021 "lorentzangles="<<lorentzangles<<
4022 "\n";
4023 }
4024
4025}
55a288e5 4026//
4027//____________Calcul Coef Mean_________________________________________________
4028//
55a288e5 4029//_____________________________________________________________________________
3a0f6479 4030Bool_t AliTRDCalibraFit::CalculT0CoefMean()
55a288e5 4031{
4032 //
4033 // For the detector Dect calcul the mean time 0
4034 // for the calibration group idect from the choosen database
4035 //
4036
3a0f6479 4037 fCurrentCoef2[1] = 0.0;
4038 if(fDebugLevel != 1){
64942b85 4039 if(((fCalibraMode->GetNz(1) > 0) ||
4040 (fCalibraMode->GetNrphi(1) > 0)) && ((fCalibraMode->GetNz(1) != 10) && (fCalibraMode->GetNz(1) != 100))) {
4041
3a0f6479 4042 for (Int_t row = fCalibraMode->GetRowMin(1); row < fCalibraMode->GetRowMax(1); row++) {
4043 for (Int_t col = fCalibraMode->GetColMin(1); col < fCalibraMode->GetColMax(1); col++) {
4044 fCurrentCoef2[1] += (Float_t) (fCalROC2->GetValue(col,row)+fCalDet2->GetValue(fCountDet));
55a288e5 4045 }
3a0f6479 4046 }
64942b85 4047
3a0f6479 4048 fCurrentCoef2[1] = fCurrentCoef2[1] / ((fCalibraMode->GetColMax(1)-fCalibraMode->GetColMin(1))*(fCalibraMode->GetRowMax(1)-fCalibraMode->GetRowMin(1)));
64942b85 4049
3a0f6479 4050 }
4051 else {
64942b85 4052
3a0f6479 4053 if(!fAccCDB){
4054 fCurrentCoef2[1] = fCalDet2->GetValue(fCountDet);
4055 }
4056 else{
64942b85 4057
053767a4 4058 for(Int_t row = 0; row < fGeo->GetRowMax(GetLayer(fCountDet),GetStack(fCountDet),GetSector(fCountDet)); row++){
4059 for(Int_t col = 0; col < fGeo->GetColMax(GetLayer(fCountDet)); col++){
3a0f6479 4060 fCurrentCoef2[1] += (Float_t) (fCalROC2->GetValue(col,row)+fCalDet2->GetValue(fCountDet));
4061 }
55a288e5 4062 }
053767a4 4063 fCurrentCoef2[1] = fCurrentCoef2[1] / ((fGeo->GetRowMax(GetLayer(fCountDet),GetStack(fCountDet),GetSector(fCountDet)))*(fGeo->GetColMax(GetLayer(fCountDet))));
64942b85 4064
55a288e5 4065 }
4066 }
55a288e5 4067 }
55a288e5 4068 return kTRUE;
55a288e5 4069}
4070
4071//_____________________________________________________________________________
3a0f6479 4072Bool_t AliTRDCalibraFit::CalculChargeCoefMean(Bool_t vrai)
55a288e5 4073{
4074 //
4075 // For the detector Dect calcul the mean gain factor
4076 // for the calibration group idect from the choosen database
4077 //
4078
3a0f6479 4079 fCurrentCoef[1] = 0.0;
4080 if(fDebugLevel != 1){
64942b85 4081 if (((fCalibraMode->GetNz(0) > 0) ||
4082 (fCalibraMode->GetNrphi(0) > 0)) && ((fCalibraMode->GetNz(0) != 10) && (fCalibraMode->GetNz(0) != 100))) {
3a0f6479 4083 for (Int_t row = fCalibraMode->GetRowMin(0); row < fCalibraMode->GetRowMax(0); row++) {
4084 for (Int_t col = fCalibraMode->GetColMin(0); col < fCalibraMode->GetColMax(0); col++) {
4085 fCurrentCoef[1] += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
4086 if (vrai) fScaleFitFactor += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
55a288e5 4087 }
4088 }
3a0f6479 4089 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(0)-fCalibraMode->GetColMin(0))*(fCalibraMode->GetRowMax(0)-fCalibraMode->GetRowMin(0)));
55a288e5 4090 }
3a0f6479 4091 else {
4092 //Per detectors
4093 fCurrentCoef[1] = (Float_t) fCalDet->GetValue(fCountDet);
4094 if (vrai) fScaleFitFactor += ((Float_t) fCalDet->GetValue(fCountDet))*(fCalibraMode->GetColMax(0)-fCalibraMode->GetColMin(0))*(fCalibraMode->GetRowMax(0)-fCalibraMode->GetRowMin(0));
4095 }
55a288e5 4096 }
55a288e5 4097 return kTRUE;
55a288e5 4098}
55a288e5 4099//_____________________________________________________________________________
3a0f6479 4100Bool_t AliTRDCalibraFit::CalculPRFCoefMean()
55a288e5 4101{
4102 //
4103 // For the detector Dect calcul the mean sigma of pad response
4104 // function for the calibration group idect from the choosen database
4105 //
3a0f6479 4106
4107 fCurrentCoef[1] = 0.0;
4108 if(fDebugLevel != 1){
55a288e5 4109 for (Int_t row = fCalibraMode->GetRowMin(2); row < fCalibraMode->GetRowMax(2); row++) {
4110 for (Int_t col = fCalibraMode->GetColMin(2); col < fCalibraMode->GetColMax(2); col++) {
3a0f6479 4111 fCurrentCoef[1] += (Float_t) fCalROC->GetValue(col,row);
55a288e5 4112 }
4113 }
3a0f6479 4114 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(2)-fCalibraMode->GetColMin(2))*(fCalibraMode->GetRowMax(2)-fCalibraMode->GetRowMin(2)));
55a288e5 4115 }
55a288e5 4116 return kTRUE;
55a288e5 4117}
55a288e5 4118//_____________________________________________________________________________
3a0f6479 4119Bool_t AliTRDCalibraFit::CalculVdriftCoefMean()
55a288e5 4120{
4121 //
4122 // For the detector dect calcul the mean drift velocity for the
4123 // calibration group idect from the choosen database
4124 //
4125
3a0f6479 4126 fCurrentCoef[1] = 0.0;
4127 if(fDebugLevel != 1){
64942b85 4128 if (((fCalibraMode->GetNz(1) > 0) ||
4129 (fCalibraMode->GetNrphi(1) > 0)) && ((fCalibraMode->GetNz(1) != 10) && (fCalibraMode->GetNz(1) != 100))) {
4130
3a0f6479 4131 for (Int_t row = fCalibraMode->GetRowMin(1); row < fCalibraMode->GetRowMax(1); row++) {
4132 for (Int_t col = fCalibraMode->GetColMin(1); col < fCalibraMode->GetColMax(1); col++) {
4133 fCurrentCoef[1] += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
55a288e5 4134 }
4135 }
64942b85 4136
3a0f6479 4137 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(1)-fCalibraMode->GetColMin(1))*(fCalibraMode->GetRowMax(1)-fCalibraMode->GetRowMin(1)));
64942b85 4138
55a288e5 4139 }
3a0f6479 4140 else {
4141 //per detectors
4142 fCurrentCoef[1] = (Float_t) fCalDet->GetValue(fCountDet);
4143 }
55a288e5 4144 }
55a288e5 4145 return kTRUE;
55a288e5 4146}
3a0f6479 4147//_____________________________________________________________________________
4148Bool_t AliTRDCalibraFit::CalculVdriftLorentzCoef()
4149{
4150 //
4151 // For the detector fCountDet, mean drift velocity and tan lorentzangle
4152 //
4153
4154 fCurrentCoef[1] = fCalDet->GetValue(fCountDet);
4155 fCurrentCoef2[1] = fCalDet2->GetValue(fCountDet);
55a288e5 4156
3a0f6479 4157 return kTRUE;
4158}
55a288e5 4159//_____________________________________________________________________________
053767a4 4160Float_t AliTRDCalibraFit::GetPRFDefault(Int_t layer) const
55a288e5 4161{
4162 //
4163 // Default width of the PRF if there is no database as reference
4164 //
053767a4 4165 switch(layer)
3a0f6479 4166 {
4167 // default database
4168 //case 0: return 0.515;
4169 //case 1: return 0.502;
4170 //case 2: return 0.491;
4171 //case 3: return 0.481;
4172 //case 4: return 0.471;
4173 //case 5: return 0.463;
4174 //default: return 0.0;
4175
4176 // fit database
4177 case 0: return 0.538429;
4178 case 1: return 0.524302;
4179 case 2: return 0.511591;
4180 case 3: return 0.500140;
4181 case 4: return 0.489821;
4182 case 5: return 0.480524;
4183 default: return 0.0;
55a288e5 4184 }
3a0f6479 4185}
4186//________________________________________________________________________________
4187void AliTRDCalibraFit::SetCalROC(Int_t i)
4188{
4189 //
4190 // Set the calib object for fCountDet
4191 //
4192
4193 Float_t value = 0.0;
4194
4195 //Get the CalDet object
4196 if(fAccCDB){
4197 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
4198 if (!cal) {
4199 AliInfo("Could not get calibDB");
4200 return;
4201 }
4202 switch (i)
4203 {
4204 case 0:
64942b85 4205 if( fCalROC ){
4206 fCalROC->~AliTRDCalROC();
4207 new(fCalROC) AliTRDCalROC(*(cal->GetGainFactorROC(fCountDet)));
4208 }else fCalROC = new AliTRDCalROC(*(cal->GetGainFactorROC(fCountDet)));
3a0f6479 4209 break;
4210 case 1:
64942b85 4211 if( fCalROC ){
4212 fCalROC->~AliTRDCalROC();
4213 new(fCalROC) AliTRDCalROC(*(cal->GetVdriftROC(fCountDet)));
4214 }else fCalROC = new AliTRDCalROC(*(cal->GetVdriftROC(fCountDet)));
4215 if( fCalROC2 ){
4216 fCalROC2->~AliTRDCalROC();
4217 new(fCalROC2) AliTRDCalROC(*(cal->GetT0ROC(fCountDet)));
4218 }else fCalROC2 = new AliTRDCalROC(*(cal->GetT0ROC(fCountDet)));
3a0f6479 4219 break;
4220 case 2:
64942b85 4221 if( fCalROC ){
4222 fCalROC->~AliTRDCalROC();
4223 new(fCalROC) AliTRDCalROC(*(cal->GetPRFROC(fCountDet)));
4224 }else fCalROC = new AliTRDCalROC(*(cal->GetPRFROC(fCountDet)));
4225 break;
3a0f6479 4226 default: return;
4227 }
55a288e5 4228 }
3a0f6479 4229 else{
4230 switch (i)
4231 {
4232 case 0:
4233 if(fCalROC) delete fCalROC;
053767a4 4234 fCalROC = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
3a0f6479 4235 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
4236 fCalROC->SetValue(k,1.0);
4237 }
4238 break;
4239 case 1:
4240 if(fCalROC) delete fCalROC;
4241 if(fCalROC2) delete fCalROC2;
053767a4 4242 fCalROC = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
4243 fCalROC2 = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
3a0f6479 4244 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
4245 fCalROC->SetValue(k,1.0);
4246 fCalROC2->SetValue(k,0.0);
4247 }
4248 break;
4249 case 2:
4250 if(fCalROC) delete fCalROC;
053767a4 4251 value = GetPRFDefault(GetLayer(fCountDet));
4252 fCalROC = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
3a0f6479 4253 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
4254 fCalROC->SetValue(k,value);
4255 }
4256 break;
4257 default: return;
4258 }
55a288e5 4259 }
4260
4261}
55a288e5 4262//____________Fit Methods______________________________________________________
4263
4264//_____________________________________________________________________________
3a0f6479 4265void AliTRDCalibraFit::FitPente(TH1* projPH)
55a288e5 4266{
4267 //
4268 // Slope methode for the drift velocity
4269 //
4270
4271 // Constants
4272 const Float_t kDrWidth = AliTRDgeometry::DrThick();
3a0f6479 4273 Int_t binmax = 0;
4274 Int_t binmin = 0;
4275 fPhd[0] = 0.0;
4276 fPhd[1] = 0.0;
4277 fPhd[2] = 0.0;
4278 Int_t ju = 0;
4279 fCurrentCoefE = 0.0;
4280 fCurrentCoefE2 = 0.0;
4281 fCurrentCoef[0] = 0.0;
4282 fCurrentCoef2[0] = 0.0;
4283 TLine *line = new TLine();
55a288e5 4284
4285 // Some variables
4286 TAxis *xpph = projPH->GetXaxis();
4287 Int_t nbins = xpph->GetNbins();
4288 Double_t lowedge = xpph->GetBinLowEdge(1);
4289 Double_t upedge = xpph->GetBinUpEdge(xpph->GetNbins());
4290 Double_t widbins = (upedge - lowedge) / nbins;
4291 Double_t limit = upedge + 0.5 * widbins;
4292 Bool_t put = kTRUE;
4293
4294 // Beginning of the signal
4295 TH1D *pentea = new TH1D("pentea","pentea",projPH->GetNbinsX(),0,(Float_t) limit);
4296 for (Int_t k = 1; k < projPH->GetNbinsX(); k++) {
4297 pentea->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
4298 }
55a288e5 4299 binmax = (Int_t) pentea->GetMaximumBin();
55a288e5 4300 if (binmax <= 1) {
4301 binmax = 2;
4302 AliInfo("Put the binmax from 1 to 2 to enable the fit");
4303 }
4304 if (binmax >= nbins) {
4305 binmax = nbins-1;
4306 put = kFALSE;
4307 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
4308 }
4309 pentea->Fit("pol2","0MR","",TMath::Max(pentea->GetBinCenter(binmax-1),0.0),pentea->GetBinCenter(binmax+1));
4310 Float_t l3P1am = pentea->GetFunction("pol2")->GetParameter(1);
4311 Float_t l3P2am = pentea->GetFunction("pol2")->GetParameter(2);
4312 Float_t l3P1amE = pentea->GetFunction("pol2")->GetParError(1);
4313 Float_t l3P2amE = pentea->GetFunction("pol2")->GetParError(2);
daa7dc79 4314 if (TMath::Abs(l3P2am) > 0.00000001) {
55a288e5 4315 fPhd[0] = -(l3P1am / (2 * l3P2am));
4316 }
4317 if(!fTakeTheMaxPH){
daa7dc79 4318 if((TMath::Abs(l3P1am) > 0.0000000001) && (TMath::Abs(l3P2am) > 0.00000000001)){
3a0f6479 4319 fCurrentCoefE2 = (l3P1amE/l3P1am + l3P2amE/l3P2am)*fPhd[0];
55a288e5 4320 }
4321 }
55a288e5 4322 // Amplification region
4323 binmax = 0;
4324 ju = 0;
4325 for (Int_t kbin = 1; kbin < projPH->GetNbinsX(); kbin ++) {
3a0f6479 4326 if (((projPH->GetBinContent(kbin+1) - projPH->GetBinContent(kbin)) <= 0.0) && (ju == 0) && (kbin > (fPhd[0]/widbins))) {
55a288e5 4327 binmax = kbin;
4328 ju = 1;
4329 }
4330 }
55a288e5 4331 if (binmax <= 1) {
4332 binmax = 2;
4333 AliInfo("Put the binmax from 1 to 2 to enable the fit");
4334 }
4335 if (binmax >= nbins) {
4336 binmax = nbins-1;
4337 put = kFALSE;
4338 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
4339 }
4340 projPH->Fit("pol2","0MR","",TMath::Max(projPH->GetBinCenter(binmax-1),0.0),projPH->GetBinCenter(binmax+1));
4341 Float_t l3P1amf = projPH->GetFunction("pol2")->GetParameter(1);
4342 Float_t l3P2amf = projPH->GetFunction("pol2")->GetParameter(2);
4343 Float_t l3P1amfE = projPH->GetFunction("pol2")->GetParError(1);
4344 Float_t l3P2amfE = projPH->GetFunction("pol2")->GetParError(2);
daa7dc79 4345 if (TMath::Abs(l3P2amf) > 0.00000000001) {
55a288e5 4346 fPhd[1] = -(l3P1amf / (2 * l3P2amf));
4347 }
daa7dc79 4348 if((TMath::Abs(l3P1amf) > 0.0000000001) && (TMath::Abs(l3P2amf) > 0.000000001)){
3a0f6479 4349 fCurrentCoefE = (l3P1amfE/l3P1amf + l3P2amfE/l3P2amf)*fPhd[1];
55a288e5 4350 }
4351 if(fTakeTheMaxPH){
3a0f6479 4352 fCurrentCoefE2 = fCurrentCoefE;
55a288e5 4353 }
55a288e5 4354 // Drift region
4355 TH1D *pente = new TH1D("pente","pente",projPH->GetNbinsX(),0,(Float_t) limit);
4356 for (Int_t k = TMath::Min(binmax+4,projPH->GetNbinsX()); k < projPH->GetNbinsX(); k++) {
4357 pente->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
4358 }
4359 binmin = 0;
4360 if(pente->GetEntries() > 0) binmin = (Int_t) pente->GetMinimumBin();
4361 if (binmin <= 1) {
4362 binmin = 2;
4363 AliInfo("Put the binmax from 1 to 2 to enable the fit");
4364 }
4365 if (binmin >= nbins) {
4366 binmin = nbins-1;
4367 put = kFALSE;
4368 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
4369 }
55a288e5 4370 pente->Fit("pol2"
4371 ,"0MR"
4372 ,""
4373 ,TMath::Max(pente->GetBinCenter(binmin-1), 0.0)
4374 ,TMath::Min(pente->GetBinCenter(binmin+1),(Double_t) limit));
4375 Float_t l3P1dr = pente->GetFunction("pol2")->GetParameter(1);
4376 Float_t l3P2dr = pente->GetFunction("pol2")->GetParameter(2);
4377 Float_t l3P1drE = pente->GetFunction("pol2")->GetParError(1);
4378 Float_t l3P2drE = pente->GetFunction("pol2")->GetParError(2);
daa7dc79 4379 if (TMath::Abs(l3P2dr) > 0.00000001) {
55a288e5 4380 fPhd[2] = -(l3P1dr / (2 * l3P2dr));
4381 }
daa7dc79 4382 if((TMath::Abs(l3P1dr) > 0.0000000001) && (TMath::Abs(l3P2dr) > 0.00000000001)){
3a0f6479 4383 fCurrentCoefE += (l3P1drE/l3P1dr + l3P2drE/l3P2dr)*fPhd[2];
55a288e5 4384 }
413153cb 4385 Float_t fPhdt0 = 0.0;
4386 Float_t t0Shift = 0.0;
4387 if(fTakeTheMaxPH) {
4388 fPhdt0 = fPhd[1];
4389 t0Shift = fT0Shift1;
4390 }
4391 else {
4392 fPhdt0 = fPhd[0];
4393 t0Shift = fT0Shift0;
4394 }
55a288e5 4395
4396 if ((fPhd[2] > fPhd[0]) &&
4397 (fPhd[2] > fPhd[1]) &&
4398 (fPhd[1] > fPhd[0]) &&
4399 (put)) {
3a0f6479 4400 fCurrentCoef[0] = (kDrWidth) / (fPhd[2]-fPhd[1]);
4401 fNumberFitSuccess++;
4402
55a288e5 4403 if (fPhdt0 >= 0.0) {
413153cb 4404 fCurrentCoef2[0] = (fPhdt0 - t0Shift) / widbins;
3a0f6479 4405 if (fCurrentCoef2[0] < -1.0) {
64942b85 4406 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
55a288e5 4407 }
4408 }
4409 else {
64942b85 4410 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
55a288e5 4411 }
3a0f6479 4412
55a288e5 4413 }
4414 else {
3a0f6479 4415 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
64942b85 4416 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
55a288e5 4417 }
4418
3a0f6479 4419 if (fDebugLevel == 1) {
55a288e5 4420 TCanvas *cpentei = new TCanvas("cpentei","cpentei",50,50,600,800);
4421 cpentei->cd();
4422 projPH->Draw();
4423 line->SetLineColor(2);
4424 line->DrawLine(fPhd[0],0,fPhd[0],projPH->GetMaximum());
4425 line->DrawLine(fPhd[1],0,fPhd[1],projPH->GetMaximum());
4426 line->DrawLine(fPhd[2],0,fPhd[2],projPH->GetMaximum());
4427 AliInfo(Form("fPhd[0] (beginning of the signal): %f" ,(Float_t) fPhd[0]));
4428 AliInfo(Form("fPhd[1] (end of the amplification region): %f" ,(Float_t) fPhd[1]));
4429 AliInfo(Form("fPhd[2] (end of the drift region): %f" ,(Float_t) fPhd[2]));
3a0f6479 4430 AliInfo(Form("fVriftCoef[1] (with only the drift region(default)): %f",(Float_t) fCurrentCoef[0]));
55a288e5 4431 TCanvas *cpentei2 = new TCanvas("cpentei2","cpentei2",50,50,600,800);
4432 cpentei2->cd();
4433 pentea->Draw();
4434 TCanvas *cpentei3 = new TCanvas("cpentei3","cpentei3",50,50,600,800);
4435 cpentei3->cd();
4436 pente->Draw();
4437 }
3a0f6479 4438 else {
55a288e5 4439 delete pentea;
55a288e5 4440 delete pente;
4441 }
55a288e5 4442}
55a288e5 4443//_____________________________________________________________________________
3a0f6479 4444void AliTRDCalibraFit::FitLagrangePoly(TH1* projPH)
55a288e5 4445{
4446 //
4447 // Slope methode but with polynomes de Lagrange
4448 //
6aafa7ea 4449
55a288e5 4450 // Constants
4451 const Float_t kDrWidth = AliTRDgeometry::DrThick();
3a0f6479 4452 Int_t binmax = 0;
4453 Int_t binmin = 0;
fdc15553 4454 //Double_t *x = new Double_t[5];
4455 //Double_t *y = new Double_t[5];
4456 Double_t x[5];
4457 Double_t y[5];
3a0f6479 4458 x[0] = 0.0;
4459 x[1] = 0.0;
4460 x[2] = 0.0;
4461 x[3] = 0.0;
4462 x[4] = 0.0;
4463 y[0] = 0.0;
4464 y[1] = 0.0;
4465 y[2] = 0.0;
4466 y[3] = 0.0;
4467 y[4] = 0.0;
4468 fPhd[0] = 0.0;
4469 fPhd[1] = 0.0;
4470 fPhd[2] = 0.0;
4471 Int_t ju = 0;
4472 fCurrentCoefE = 0.0;
4473 fCurrentCoefE2 = 1.0;
4474 fCurrentCoef[0] = 0.0;
4475 fCurrentCoef2[0] = 0.0;
55a288e5 4476 TLine *line = new TLine();
4477 TF1 * polynome = 0x0;
4478 TF1 * polynomea = 0x0;
4479 TF1 * polynomeb = 0x0;
3b0c1edc 4480 Double_t c0 = 0.0;
4481 Double_t c1 = 0.0;
4482 Double_t c2 = 0.0;
4483 Double_t c3 = 0.0;
4484 Double_t c4 = 0.0;
55a288e5 4485
4486 // Some variables
4487 TAxis *xpph = projPH->GetXaxis();
4488 Int_t nbins = xpph->GetNbins();
4489 Double_t lowedge = xpph->GetBinLowEdge(1);
4490 Double_t upedge = xpph->GetBinUpEdge(xpph->GetNbins());
4491 Double_t widbins = (upedge - lowedge) / nbins;
4492 Double_t limit = upedge + 0.5 * widbins;
4493
4494
4495 Bool_t put = kTRUE;
4496
4497 // Beginning of the signal
4498 TH1D *pentea = new TH1D("pentea","pentea",projPH->GetNbinsX(),0,(Float_t) limit);
4499 for (Int_t k = 1; k < projPH->GetNbinsX(); k++) {
4500 pentea->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
4501 }
4502
4503 binmax = (Int_t) pentea->GetMaximumBin();
55a288e5 4504
4505 Double_t minnn = 0.0;
4506 Double_t maxxx = 0.0;
4507
3a0f6479 4508 Int_t kase = nbins-binmax;
4509
4510 switch(kase)
4511 {
4512 case 0:
4513 put = kFALSE;
4514 break;
4515 case 1:
4516 minnn = pentea->GetBinCenter(binmax-2);
4517 maxxx = pentea->GetBinCenter(binmax);
4518 x[0] = pentea->GetBinCenter(binmax-2);
4519 x[1] = pentea->GetBinCenter(binmax-1);
4520 x[2] = pentea->GetBinCenter(binmax);
4521 y[0] = pentea->GetBinContent(binmax-2);
4522 y[1] = pentea->GetBinContent(binmax-1);
4523 y[2] = pentea->GetBinContent(binmax);
3b0c1edc 4524 CalculPolynomeLagrange2(x,y,c0,c1,c2,c3,c4);
3a0f6479 4525 AliInfo("At the limit for beginning!");
4526 break;
4527 case 2:
4528 minnn = pentea->GetBinCenter(binmax-2);
4529 maxxx = pentea->GetBinCenter(binmax+1);
4530 x[0] = pentea->GetBinCenter(binmax-2);
4531 x[1] = pentea->GetBinCenter(binmax-1);
4532 x[2] = pentea->GetBinCenter(binmax);
4533 x[3] = pentea->GetBinCenter(binmax+1);
4534 y[0] = pentea->GetBinContent(binmax-2);
4535 y[1] = pentea->GetBinContent(binmax-1);
4536 y[2] = pentea->GetBinContent(binmax);
4537 y[3] = pentea->GetBinContent(binmax+1);
3b0c1edc 4538 CalculPolynomeLagrange3(x,y,c0,c1,c2,c3,c4);
3a0f6479 4539 break;
4540 default:
4541 switch(binmax){
4542 case 0:
4543 put = kFALSE;
4544 break;
4545 case 1:
4546 minnn = pentea->GetBinCenter(binmax);
4547 maxxx = pentea->GetBinCenter(binmax+2);
4548 x[0] = pentea->GetBinCenter(binmax);
4549 x[1] = pentea->GetBinCenter(binmax+1);
4550 x[2] = pentea->GetBinCenter(binmax+2);
4551 y[0] = pentea->GetBinContent(binmax);
4552 y[1] = pentea->GetBinContent(binmax+1);
4553 y[2] = pentea->GetBinContent(binmax+2);
3b0c1edc 4554 CalculPolynomeLagrange2(x,y,c0,c1,c2,c3,c4);
3a0f6479 4555 break;
4556 case 2:
4557 minnn = pentea->GetBinCenter(binmax-1);
4558 maxxx = pentea->GetBinCenter(binmax+2);
4559 x[0] = pentea->GetBinCenter(binmax-1);
4560 x[1] = pentea->GetBinCenter(binmax);
4561 x[2] = pentea->GetBinCenter(binmax+1);
4562 x[3] = pentea->GetBinCenter(binmax+2);
4563 y[0] = pentea->GetBinContent(binmax-1);
4564 y[1] = pentea->GetBinContent(binmax);
4565 y[2] = pentea->GetBinContent(binmax+1);
4566 y[3] = pentea->GetBinContent(binmax+2);
3b0c1edc 4567 CalculPolynomeLagrange3(x,y,c0,c1,c2,c3,c4);
3a0f6479 4568 break;
4569 default:
4570 minnn = pentea->GetBinCenter(binmax-2);
4571 maxxx = pentea->GetBinCenter(binmax+2);
4572 x[0] = pentea->GetBinCenter(binmax-2);
4573 x[1] = pentea->GetBinCenter(binmax-1);
4574 x[2] = pentea->GetBinCenter(binmax);
4575 x[3] = pentea->GetBinCenter(binmax+1);
4576 x[4] = pentea->GetBinCenter(binmax+2);
4577 y[0] = pentea->GetBinContent(binmax-2);
4578 y[1] = pentea->GetBinContent(binmax-1);
4579 y[2] = pentea->GetBinContent(binmax);
4580 y[3] = pentea->GetBinContent(binmax+1);
4581 y[4] = pentea->GetBinContent(binmax+2);
3b0c1edc 4582 CalculPolynomeLagrange4(x,y,c0,c1,c2,c3,c4);
3a0f6479 4583 break;
4584 }
4585 break;
55a288e5 4586 }
3a0f6479 4587
4588
55a288e5 4589 if(put) {
4590 polynomeb = new TF1("polb","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",minnn,maxxx);
3b0c1edc 4591 polynomeb->SetParameters(c0,c1,c2,c3,c4);
3a0f6479 4592
55a288e5 4593 Double_t step = (maxxx-minnn)/10000;
4594 Double_t l = minnn;
4595 Double_t maxvalue = 0.0;
4596 Double_t placemaximum = minnn;
4597 for(Int_t o = 0; o < 10000; o++){
4598 if(o == 0) maxvalue = polynomeb->Eval(l);
4599 if(maxvalue < (polynomeb->Eval(l))){
4600 maxvalue = polynomeb->Eval(l);
4601 placemaximum = l;
4602 }
4603 l += step;
4604 }
4605 fPhd[0] = placemaximum;
4606 }
55a288e5 4607
4608 // Amplification region
4609 binmax = 0;
4610 ju = 0;
4611 for (Int_t kbin = 1; kbin < projPH->GetNbinsX(); kbin ++) {
3a0f6479 4612 if (((projPH->GetBinContent(kbin+1) - projPH->GetBinContent(kbin)) <= 0.0) && (ju == 0) && (kbin > (fPhd[0]/widbins))) {
55a288e5 4613 binmax = kbin;
4614 ju = 1;
4615 }
4616 }
3a0f6479 4617
55a288e5 4618 Double_t minn = 0.0;
4619 Double_t maxx = 0.0;
3a0f6479 4620 x[0] = 0.0;
4621 x[1] = 0.0;
4622 x[2] = 0.0;
4623 x[3] = 0.0;
4624 x[4] = 0.0;
4625 y[0] = 0.0;
4626 y[1] = 0.0;
4627 y[2] = 0.0;
4628 y[3] = 0.0;
4629 y[4] = 0.0;
4630
4631 Int_t kase1 = nbins - binmax;
55a288e5 4632
4633 //Determination of minn and maxx
4634 //case binmax = nbins
4635 //pol2
3a0f6479 4636 switch(kase1)
4637 {
4638 case 0:
4639 minn = projPH->GetBinCenter(binmax-2);
4640 maxx = projPH->GetBinCenter(binmax);
4641 x[0] = projPH->GetBinCenter(binmax-2);
4642 x[1] = projPH->GetBinCenter(binmax-1);
4643 x[2] = projPH->GetBinCenter(binmax);
4644 y[0] = projPH->GetBinContent(binmax-2);
4645 y[1] = projPH->GetBinContent(binmax-1);
4646 y[2] = projPH->GetBinContent(binmax);
3b0c1edc 4647 CalculPolynomeLagrange2(x,y,c0,c1,c2,c3,c4);
3a0f6479 4648 //AliInfo("At the limit for the drift!");
4649 break;
4650 case 1:
4651 minn = projPH->GetBinCenter(binmax-2);
4652 maxx = projPH->GetBinCenter(binmax+1);
4653 x[0] = projPH->GetBinCenter(binmax-2);
4654 x[1] = projPH->GetBinCenter(binmax-1);
4655 x[2] = projPH->GetBinCenter(binmax);
4656 x[3] = projPH->GetBinCenter(binmax+1);
4657 y[0] = projPH->GetBinContent(binmax-2);
4658 y[1] = projPH->GetBinContent(binmax-1);
4659 y[2] = projPH->GetBinContent(binmax);
4660 y[3] = projPH->GetBinContent(binmax+1);
3b0c1edc 4661 CalculPolynomeLagrange3(x,y,c0,c1,c2,c3,c4);
3a0f6479 4662 break;
4663 default:
4664 switch(binmax)
4665 {
4666 case 0:
4667 put = kFALSE;
4668 break;
4669 case 1:
4670 minn = projPH->GetBinCenter(binmax);
4671 maxx = projPH->GetBinCenter(binmax+2);
4672 x[0] = projPH->GetBinCenter(binmax);
4673 x[1] = projPH->GetBinCenter(binmax+1);
4674 x[2] = projPH->GetBinCenter(binmax+2);
4675 y[0] = projPH->GetBinContent(binmax);
4676 y[1] = projPH->GetBinContent(binmax+1);
4677 y[2] = projPH->GetBinContent(binmax+2);
3b0c1edc 4678 CalculPolynomeLagrange2(x,y,c0,c1,c2,c3,c4);
3a0f6479 4679 break;
4680 case 2:
4681 minn = projPH->GetBinCenter(binmax-1);
4682 maxx = projPH->GetBinCenter(binmax+2);
4683 x[0] = projPH->GetBinCenter(binmax-1);
4684 x[1] = projPH->GetBinCenter(binmax);
4685 x[2] = projPH->GetBinCenter(binmax+1);
4686 x[3] = projPH->GetBinCenter(binmax+2);
4687 y[0] = projPH->GetBinContent(binmax-1);
4688 y[1] = projPH->GetBinContent(binmax);
4689 y[2] = projPH->GetBinContent(binmax+1);
4690 y[3] = projPH->GetBinContent(binmax+2);
3b0c1edc 4691 CalculPolynomeLagrange3(x,y,c0,c1,c2,c3,c4);
3a0f6479 4692 break;
4693 default:
4694 minn = projPH->GetBinCenter(binmax-2);
4695 maxx = projPH->GetBinCenter(binmax+2);
4696 x[0] = projPH->GetBinCenter(binmax-2);
4697 x[1] = projPH->GetBinCenter(binmax-1);
4698 x[2] = projPH->GetBinCenter(binmax);
4699 x[3] = projPH->GetBinCenter(binmax+1);
4700 x[4] = projPH->GetBinCenter(binmax+2);
4701 y[0] = projPH->GetBinContent(binmax-2);
4702 y[1] = projPH->GetBinContent(binmax-1);
4703 y[2] = projPH->GetBinContent(binmax);
4704 y[3] = projPH->GetBinContent(binmax+1);
4705 y[4] = projPH->GetBinContent(binmax+2);
3b0c1edc 4706 CalculPolynomeLagrange4(x,y,c0,c1,c2,c3,c4);
3a0f6479 4707 break;
4708 }
4709 break;
55a288e5 4710 }
3a0f6479 4711
55a288e5 4712 if(put) {
4713 polynomea = new TF1("pola","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",minn,maxx);
3b0c1edc 4714 polynomea->SetParameters(c0,c1,c2,c3,c4);
3a0f6479 4715
55a288e5 4716 Double_t step = (maxx-minn)/1000;
4717 Double_t l = minn;
4718 Double_t maxvalue = 0.0;
4719 Double_t placemaximum = minn;
4720 for(Int_t o = 0; o < 1000; o++){
4721 if(o == 0) maxvalue = polynomea->Eval(l);
4722 if(maxvalue < (polynomea->Eval(l))){
4723 maxvalue = polynomea->Eval(l);
4724 placemaximum = l;
4725 }
4726 l += step;
4727 }
4728 fPhd[1] = placemaximum;
4729 }
4730
55a288e5 4731 // Drift region
4732 TH1D *pente = new TH1D("pente","pente", projPH->GetNbinsX(),0,(Float_t) limit);
4733 for (Int_t k = TMath::Min(binmax+4, projPH->GetNbinsX()); k < projPH->GetNbinsX(); k++) {
4734 pente->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
4735 }
4736 binmin = 0;
4737 if(pente->GetEntries() > 0) binmin = (Int_t) pente->GetMinimumBin();
4738
4739 //should not happen
4740 if (binmin <= 1) {
4741 binmin = 2;
4742 put = 1;
4743 AliInfo("Put the binmax from 1 to 2 to enable the fit");
4744 }
4745
4746 //check
64942b85 4747 if((projPH->GetBinContent(binmin)-projPH->GetBinError(binmin)) < (projPH->GetBinContent(binmin+1))) {
4748 AliInfo("Too many fluctuations at the end!");
4749 put = kFALSE;
4750 }
4751 if((projPH->GetBinContent(binmin)+projPH->GetBinError(binmin)) > (projPH->GetBinContent(binmin-1))) {
4752 AliInfo("Too many fluctuations at the end!");
4753 put = kFALSE;
4754 }
daa7dc79 4755 if(TMath::Abs(pente->GetBinContent(binmin+1)) <= 0.0000000000001){
64942b85 4756 AliInfo("No entries for the next bin!");
4757 pente->SetBinContent(binmin,0);
4758 if(pente->GetEntries() > 0) binmin = (Int_t) pente->GetMinimumBin();
4759 }
4760
3a0f6479 4761
4762 x[0] = 0.0;
4763 x[1] = 0.0;
4764 x[2] = 0.0;
4765 x[3] = 0.0;
4766 x[4] = 0.0;
4767 y[0] = 0.0;
4768 y[1] = 0.0;
4769 y[2] = 0.0;
4770 y[3] = 0.0;
4771 y[4] = 0.0;
55a288e5 4772 Double_t min = 0.0;
4773 Double_t max = 0.0;
4774 Bool_t case1 = kFALSE;
4775 Bool_t case2 = kFALSE;
4776 Bool_t case4 = kFALSE;
4777
4778 //Determination of min and max
4779 //case binmin <= nbins-3
4780 //pol4 case 3
4781 if((binmin <= (nbins-3)) && ((binmin-2) >= TMath::Min(binmax+4, projPH->GetNbinsX()))){
4782 min = pente->GetBinCenter(binmin-2);
4783 max = pente->GetBinCenter(binmin+2);
4784 x[0] = pente->GetBinCenter(binmin-2);
4785 x[1] = pente->GetBinCenter(binmin-1);
4786 x[2] = pente->GetBinCenter(binmin);
4787 x[3] = pente->GetBinCenter(binmin+1);
4788 x[4] = pente->GetBinCenter(binmin+2);
4789 y[0] = pente->GetBinContent(binmin-2);
4790 y[1] = pente->GetBinContent(binmin-1);
4791 y[2] = pente->GetBinContent(binmin);
4792 y[3] = pente->GetBinContent(binmin+1);
4793 y[4] = pente->GetBinContent(binmin+2);
4794 //Calcul the polynome de Lagrange
3b0c1edc 4795 CalculPolynomeLagrange4(x,y,c0,c1,c2,c3,c4);
55a288e5 4796 //richtung +/-
4797 if((pente->GetBinContent(binmin+2) <= pente->GetBinContent(binmin+1)) &&
64942b85 4798 (pente->GetBinContent(binmin-2) <= pente->GetBinContent(binmin-1))) {
4799 //AliInfo("polynome 4 false 1");
4800 put = kFALSE;
4801 }
55a288e5 4802 if(((binmin+3) <= (nbins-1)) &&
4803 (pente->GetBinContent(binmin+3) <= pente->GetBinContent(binmin+2)) &&
4804 ((binmin-3) >= TMath::Min(binmax+4, projPH->GetNbinsX())) &&
64942b85 4805 (pente->GetBinContent(binmin-3) <= pente->GetBinContent(binmin-2))) {
4806 AliInfo("polynome 4 false 2");
4807 put = kFALSE;
4808 }
4809 // poly 3
55a288e5 4810 if((pente->GetBinContent(binmin+2) <= pente->GetBinContent(binmin+1)) &&
64942b85 4811 (pente->GetBinContent(binmin-2) > pente->GetBinContent(binmin-1))) {
4812 //AliInfo("polynome 4 case 1");
4813 case1 = kTRUE;
4814 }
55a288e5 4815 if((pente->GetBinContent(binmin+2) > pente->GetBinContent(binmin+1)) &&
64942b85 4816 (pente->GetBinContent(binmin-2) <= pente->GetBinContent(binmin-1))) {
4817 //AliInfo("polynome 4 case 4");
4818 case4 = kTRUE;
4819 }
4820
55a288e5 4821 }
4822 //case binmin = nbins-2
4823 //pol3 case 1
4824 if(((binmin == (nbins-2)) && ((binmin-2) >= TMath::Min(binmax+4, projPH->GetNbinsX()))) ||
4825 (case1)){
4826 min = pente->GetBinCenter(binmin-2);
4827 max = pente->GetBinCenter(binmin+1);
4828 x[0] = pente->GetBinCenter(binmin-2);
4829 x[1] = pente->GetBinCenter(binmin-1);
4830 x[2] = pente->GetBinCenter(binmin);
4831 x[3] = pente->GetBinCenter(binmin+1);
4832 y[0] = pente->GetBinContent(binmin-2);
4833 y[1] = pente->GetBinContent(binmin-1);
4834 y[2] = pente->GetBinContent(binmin);
4835 y[3] = pente->GetBinContent(binmin+1);
4836 //Calcul the polynome de Lagrange
3b0c1edc 4837 CalculPolynomeLagrange3(x,y,c0,c1,c2,c3,c4);
55a288e5 4838 //richtung +: nothing
4839 //richtung -
64942b85 4840 if((pente->GetBinContent(binmin-2) <= pente->GetBinContent(binmin-1))) {
4841 //AliInfo("polynome 3- case 2");
4842 case2 = kTRUE;
4843 }
55a288e5 4844 }
4845 //pol3 case 4
4846 if(((binmin <= (nbins-3)) && ((binmin-1) == TMath::Min(binmax+4, projPH->GetNbinsX()))) ||
4847 (case4)){
4848 min = pente->GetBinCenter(binmin-1);
4849 max = pente->GetBinCenter(binmin+2);
4850 x[0] = pente->GetBinCenter(binmin-1);
4851 x[1] = pente->GetBinCenter(binmin);
4852 x[2] = pente->GetBinCenter(binmin+1);
4853 x[3] = pente->GetBinCenter(binmin+2);
4854 y[0] = pente->GetBinContent(binmin-1);
4855 y[1] = pente->GetBinContent(binmin);
4856 y[2] = pente->GetBinContent(binmin+1);
4857 y[3] = pente->GetBinContent(binmin+2);
4858 //Calcul the polynome de Lagrange
3b0c1edc 4859 CalculPolynomeLagrange3(x,y,c0,c1,c2,c3,c4);
55a288e5 4860 //richtung +
64942b85 4861 if((pente->GetBinContent(binmin+2) <= pente->GetBinContent(binmin+1))) {
4862 //AliInfo("polynome 3+ case 2");
4863 case2 = kTRUE;
4864 }
55a288e5 4865 }
4866 //pol2 case 5
4867 if((binmin <= (nbins-3)) && (binmin == TMath::Min(binmax+4, projPH->GetNbinsX()))){
4868 min = pente->GetBinCenter(binmin);
4869 max = pente->GetBinCenter(binmin+2);
4870 x[0] = pente->GetBinCenter(binmin);
4871 x[1] = pente->GetBinCenter(binmin+1);
4872 x[2] = pente->GetBinCenter(binmin+2);
4873 y[0] = pente->GetBinContent(binmin);
4874 y[1] = pente->GetBinContent(binmin+1);
4875 y[2] = pente->GetBinContent(binmin+2);
4876 //Calcul the polynome de Lagrange
3b0c1edc 4877 CalculPolynomeLagrange2(x,y,c0,c1,c2,c3,c4);
55a288e5 4878 //richtung +
64942b85 4879 if((pente->GetBinContent(binmin+2) <= pente->GetBinContent(binmin+1))) {
4880 //AliInfo("polynome 2+ false");
4881 put = kFALSE;
4882 }
55a288e5 4883 }
4884 //pol2 case 2
4885 if(((binmin == (nbins-2)) && ((binmin-1) == TMath::Min(binmax+4, projPH->GetNbinsX()))) ||
4886 (case2)){
4887 min = pente->GetBinCenter(binmin-1);
4888 max = pente->GetBinCenter(binmin+1);
4889 x[0] = pente->GetBinCenter(binmin-1);
4890 x[1] = pente->GetBinCenter(binmin);
4891 x[2] = pente->GetBinCenter(binmin+1);
4892 y[0] = pente->GetBinContent(binmin-1);
4893 y[1] = pente->GetBinContent(binmin);
4894 y[2] = pente->GetBinContent(binmin+1);
4895 //Calcul the polynome de Lagrange
3b0c1edc 4896 CalculPolynomeLagrange2(x,y,c0,c1,c2,c3,c4);
55a288e5 4897 //richtung +: nothing
4898 //richtung -: nothing
4899 }
4900 //case binmin = nbins-1
4901 //pol2 case 0
4902 if((binmin == (nbins-1)) && ((binmin-2) >= TMath::Min(binmax+4, projPH->GetNbinsX()))){
4903 min = pente->GetBinCenter(binmin-2);
4904 max = pente->GetBinCenter(binmin);
4905 x[0] = pente->GetBinCenter(binmin-2);
4906 x[1] = pente->GetBinCenter(binmin-1);
4907 x[2] = pente->GetBinCenter(binmin);
4908 y[0] = pente->GetBinContent(binmin-2);
4909 y[1] = pente->GetBinContent(binmin-1);
4910 y[2] = pente->GetBinContent(binmin);
4911 //Calcul the polynome de Lagrange
3b0c1edc 4912 CalculPolynomeLagrange2(x,y,c0,c1,c2,c3,c4);
3a0f6479 4913 //AliInfo("At the limit for the drift!");
55a288e5 4914 //fluctuation too big!
4915 //richtung +: nothing
4916 //richtung -
64942b85 4917 if((pente->GetBinContent(binmin-2) <= pente->GetBinContent(binmin-1))) {
4918 //AliInfo("polynome 2- false ");
4919 put = kFALSE;
4920 }
55a288e5 4921 }
4922 if((binmin == (nbins-1)) && ((binmin-2) < TMath::Min(binmax+4, projPH->GetNbinsX()))) {
4923 put = kFALSE;
4924 AliInfo("At the limit for the drift and not usable!");
4925 }
4926
4927 //pass
4928 if((binmin == (nbins-2)) && ((binmin-1) < TMath::Min(binmax+4, projPH->GetNbinsX()))){
4929 put = kFALSE;
4930 AliInfo("For the drift...problem!");
4931 }
55a288e5 4932 //pass but should not happen
64942b85 4933 if((binmin <= (nbins-3)) && (binmin < TMath::Min(binmax+6, projPH->GetNbinsX()))){
55a288e5 4934 put = kFALSE;
4935 AliInfo("For the drift...problem!");
4936 }
3a0f6479 4937
55a288e5 4938 if(put) {
4939 polynome = new TF1("pol","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",min,max);
3b0c1edc 4940 polynome->SetParameters(c0,c1,c2,c3,c4);
55a288e5 4941 //AliInfo(Form("GetMinimum of the function %f",polynome->GetMinimumX()));
4942 Double_t step = (max-min)/1000;
4943 Double_t l = min;
4944 Double_t minvalue = 0.0;
4945 Double_t placeminimum = min;
4946 for(Int_t o = 0; o < 1000; o++){
4947 if(o == 0) minvalue = polynome->Eval(l);
4948 if(minvalue > (polynome->Eval(l))){
4949 minvalue = polynome->Eval(l);
4950 placeminimum = l;
4951 }
4952 l += step;
4953 }
4954 fPhd[2] = placeminimum;
4955 }
64942b85 4956 //printf("La fin %d\n",((Int_t)(fPhd[2]*10.0))+2);
4957 if((((Int_t)(fPhd[2]*10.0))+2) >= projPH->GetNbinsX()) fPhd[2] = 0.0;
4958 if(((((Int_t)(fPhd[2]*10.0))+2) < projPH->GetNbinsX()) && (projPH->GetBinContent(((Int_t)(fPhd[2]*10.0))+2)==0)) fPhd[2] = 0.0;
3a0f6479 4959
413153cb 4960 Float_t fPhdt0 = 0.0;
4961 Float_t t0Shift = 0.0;
4962 if(fTakeTheMaxPH) {
4963 fPhdt0 = fPhd[1];
4964 t0Shift = fT0Shift1;
4965 }
4966 else {
4967 fPhdt0 = fPhd[0];
4968 t0Shift = fT0Shift0;
4969 }
55a288e5 4970
4971 if ((fPhd[2] > fPhd[0]) &&
4972 (fPhd[2] > fPhd[1]) &&
4973 (fPhd[1] > fPhd[0]) &&
4974 (put)) {
3a0f6479 4975 fCurrentCoef[0] = (kDrWidth) / (fPhd[2]-fPhd[1]);
6210514c 4976 if(fCurrentCoef[0] > 2.5) fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
6aafa7ea 4977 else fNumberFitSuccess++;
55a288e5 4978 if (fPhdt0 >= 0.0) {
413153cb 4979 fCurrentCoef2[0] = (fPhdt0 - t0Shift) / widbins;
3a0f6479 4980 if (fCurrentCoef2[0] < -1.0) {
64942b85 4981 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
55a288e5 4982 }
4983 }
4984 else {
64942b85 4985 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
55a288e5 4986 }
4987 }
4988 else {
6210514c 4989 //printf("Put default %f\n",-TMath::Abs(fCurrentCoef[1]));
4990 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
4991
64942b85 4992 if((fPhd[1] > fPhd[0]) &&
4993 (put)) {
4994 if (fPhdt0 >= 0.0) {
4995 fCurrentCoef2[0] = (fPhdt0 - t0Shift) / widbins;
4996 if (fCurrentCoef2[0] < -1.0) {
4997 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
4998 }
4999 }
5000 else {
5001 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
5002 }
5003 }
5004 else{
64942b85 5005 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
5006 //printf("Fit failed!\n");
5007 }
55a288e5 5008 }
5009
3a0f6479 5010 if (fDebugLevel == 1) {
55a288e5 5011 TCanvas *cpentei = new TCanvas("cpentei","cpentei",50,50,600,800);
5012 cpentei->cd();
5013 projPH->Draw();
5014 line->SetLineColor(2);
5015 line->DrawLine(fPhd[0],0,fPhd[0],projPH->GetMaximum());
5016 line->DrawLine(fPhd[1],0,fPhd[1],projPH->GetMaximum());
5017 line->DrawLine(fPhd[2],0,fPhd[2],projPH->GetMaximum());
5018 AliInfo(Form("fPhd[0] (beginning of the signal): %f" ,(Float_t) fPhd[0]));
5019 AliInfo(Form("fPhd[1] (end of the amplification region): %f" ,(Float_t) fPhd[1]));
5020 AliInfo(Form("fPhd[2] (end of the drift region): %f" ,(Float_t) fPhd[2]));
3a0f6479 5021 AliInfo(Form("fVriftCoef[3] (with only the drift region(default)): %f",(Float_t) fCurrentCoef[0]));
55a288e5 5022 TCanvas *cpentei2 = new TCanvas("cpentei2","cpentei2",50,50,600,800);
5023 cpentei2->cd();
5024 pentea->Draw();
5025 TCanvas *cpentei3 = new TCanvas("cpentei3","cpentei3",50,50,600,800);
5026 cpentei3->cd();
5027 pente->Draw();
5028 }
3a0f6479 5029 else {
a987273c 5030 delete pentea;
5031 delete pente;
1ca79a00 5032 if(polynome) delete polynome;
5033 if(polynomea) delete polynomea;
5034 if(polynomeb) delete polynomeb;
fdc15553 5035 //if(x) delete [] x;
5036 //if(y) delete [] y;
1ca79a00 5037 if(line) delete line;
5038
55a288e5 5039 }
64942b85 5040
5041 //Provisoire
5042 //if(fCurrentCoef[0] > 1.7) fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
5043 //if((fCurrentCoef2[0] > 2.6) || (fCurrentCoef2[0] < 2.1)) fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
3a0f6479 5044
55a288e5 5045 projPH->SetDirectory(0);
5046
5047}
5048
5049//_____________________________________________________________________________
5050void AliTRDCalibraFit::FitPH(TH1* projPH, Int_t idect)
5051{
5052 //
5053 // Fit methode for the drift velocity
5054 //
5055
5056 // Constants
5057 const Float_t kDrWidth = AliTRDgeometry::DrThick();
5058
5059 // Some variables
5060 TAxis *xpph = projPH->GetXaxis();
5061 Double_t upedge = xpph->GetBinUpEdge(xpph->GetNbins());
5062
5063 TF1 *fPH = new TF1("fPH",AliTRDCalibraFit::PH,-0.05,3.2,6);
5064 fPH->SetParameter(0,0.469); // Scaling
5065 fPH->SetParameter(1,0.18); // Start
5066 fPH->SetParameter(2,0.0857325); // AR
5067 fPH->SetParameter(3,1.89); // DR
5068 fPH->SetParameter(4,0.08); // QA/QD
5069 fPH->SetParameter(5,0.0); // Baseline
5070
5071 TLine *line = new TLine();
5072
3a0f6479 5073 fCurrentCoef[0] = 0.0;
5074 fCurrentCoef2[0] = 0.0;
5075 fCurrentCoefE = 0.0;
5076 fCurrentCoefE2 = 0.0;
55a288e5 5077
5078 if (idect%fFitPHPeriode == 0) {
5079
3a0f6479 5080 AliInfo(Form("The detector %d will be fitted",idect));
55a288e5 5081 fPH->SetParameter(0,(projPH->Integral()-(projPH->GetBinContent(1)*projPH->GetNbinsX())) * 0.00028); // Scaling
5082 fPH->SetParameter(1,fPhd[0] - 0.1); // Start
5083 fPH->SetParameter(2,fPhd[1] - fPhd[0]); // AR
5084 fPH->SetParameter(3,fPhd[2] - fPhd[1]); // DR
5085 fPH->SetParameter(4,0.225); // QA/QD
5086 fPH->SetParameter(5,(Float_t) projPH->GetBinContent(1));
5087
3a0f6479 5088 if (fDebugLevel != 1) {
55a288e5 5089 projPH->Fit(fPH,"0M","",0.0,upedge);
5090 }
3a0f6479 5091 else {
55a288e5 5092 TCanvas *cpente = new TCanvas("cpente","cpente",50,50,600,800);
5093 cpente->cd();
5094 projPH->Fit(fPH,"M+","",0.0,upedge);
5095 projPH->Draw("E0");
5096 line->SetLineColor(4);
5097 line->DrawLine(fPH->GetParameter(1)
5098 ,0
5099 ,fPH->GetParameter(1)
5100 ,projPH->GetMaximum());
5101 line->DrawLine(fPH->GetParameter(1)+fPH->GetParameter(2)
5102 ,0
5103 ,fPH->GetParameter(1)+fPH->GetParameter(2)
5104 ,projPH->GetMaximum());
5105 line->DrawLine(fPH->GetParameter(1)+fPH->GetParameter(2)+fPH->GetParameter(3)
5106 ,0
5107 ,fPH->GetParameter(1)+fPH->GetParameter(2)+fPH->GetParameter(3)
5108 ,projPH->GetMaximum());
5109 }
5110
5111 if (fPH->GetParameter(3) != 0) {
3a0f6479 5112 fNumberFitSuccess++;
5113 fCurrentCoef[0] = kDrWidth / (fPH->GetParameter(3));
5114 fCurrentCoefE = (fPH->GetParError(3)/fPH->GetParameter(3))*fCurrentCoef[0];
5115 fCurrentCoef2[0] = fPH->GetParameter(1);
5116 fCurrentCoefE2 = fPH->GetParError(1);
55a288e5 5117 }
5118 else {
3a0f6479 5119 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
64942b85 5120 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
55a288e5 5121 }
3a0f6479 5122
55a288e5 5123 }
55a288e5 5124 else {
5125
3a0f6479 5126 // Put the default value
5127 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
64942b85 5128 fCurrentCoef2[0] = fCurrentCoef2[1] + 100.0;
55a288e5 5129 }
5130
3a0f6479 5131 if (fDebugLevel != 1) {
55a288e5 5132 delete fPH;
5133 }
5134
5135}
55a288e5 5136//_____________________________________________________________________________
3a0f6479 5137Bool_t AliTRDCalibraFit::FitPRFGausMI(Double_t *arraye, Double_t *arraym, Double_t *arrayme, Int_t nBins, Float_t xMin, Float_t xMax)
55a288e5 5138{
5139 //
5140 // Fit methode for the sigma of the pad response function
5141 //
3a0f6479 5142
5143 TVectorD param(3);
55a288e5 5144
3a0f6479 5145 fCurrentCoef[0] = 0.0;
5146 fCurrentCoefE = 0.0;
5147
5148 Double_t ret = FitGausMI(arraye, arraym, arrayme, nBins, xMin, xMax,&param);
5149
daa7dc79 5150 if(TMath::Abs(ret+4) <= 0.000000001){
3a0f6479 5151 fCurrentCoef[0] = -fCurrentCoef[1];
5152 return kFALSE;
5153 }
5154 else {
5155 fNumberFitSuccess++;
5156 fCurrentCoef[0] = param[2];
5157 fCurrentCoefE = ret;
5158 return kTRUE;
5159 }
5160}
5161//_____________________________________________________________________________
7bce990c 5162Double_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 bError)
3a0f6479 5163{
5164 //
5165 // Fit methode for the sigma of the pad response function
5166 //
5167
5168 //We should have at least 3 points
5169 if(nBins <=3) return -4.0;
5170
5171 TLinearFitter fitter(3,"pol2");
5172 fitter.StoreData(kFALSE);
5173 fitter.ClearPoints();
5174 TVectorD par(3);
5175 Float_t binWidth = (xMax-xMin)/(Float_t)nBins;
5176 Float_t entries = 0;
5177 Int_t nbbinwithentries = 0;
5178 for (Int_t i=0; i<nBins; i++){
5179 entries+=arraye[i];
5180 if(arraye[i] > 15) nbbinwithentries++;
5181 //printf("entries for i %d: %f\n",i,arraye[i]);
5182 }
5183 if ((entries<700) || (nbbinwithentries < ((Int_t)(nBins/2)))) return -4;
5184 //printf("entries %f\n",entries);
5185 //printf("nbbinwithentries %d\n",nbbinwithentries);
5186
5187 Int_t npoints=0;
5188 Float_t errorm = 0.0;
5189 Float_t errorn = 0.0;
5190 Float_t error = 0.0;
5191
5192 //
5193 for (Int_t ibin=0;ibin<nBins; ibin++){
5194 Float_t entriesI = arraye[ibin];
5195 Float_t valueI = arraym[ibin];
5196 Double_t xcenter = 0.0;
5197 Float_t val = 0.0;
5198 if ((entriesI>15) && (valueI>0.0)){
5199 xcenter = xMin+(ibin+0.5)*binWidth;
5200 errorm = 0.0;
5201 errorn = 0.0;
5202 error = 0.0;
7bce990c 5203 if(!bError){
3a0f6479 5204 if((valueI + 0.01) > 0.0) errorm = TMath::Log((valueI + 0.01)/valueI);
5205 if((valueI - 0.01) > 0.0) errorn = TMath::Log((valueI - 0.01)/valueI);
5206 error = TMath::Max(TMath::Abs(errorm),TMath::Abs(errorn));
5207 }
5208 else{
5209 if((valueI + arrayme[ibin]) > 0.0) errorm = TMath::Log((valueI + arrayme[ibin])/valueI);
5210 if((valueI - arrayme[ibin]) > 0.0) errorn = TMath::Log((valueI - arrayme[ibin])/valueI);
5211 error = TMath::Max(TMath::Abs(errorm),TMath::Abs(errorn));
5212 }
daa7dc79 5213 if(TMath::Abs(error) < 0.000000001) continue;
3a0f6479 5214 val = TMath::Log(Float_t(valueI));
5215 fitter.AddPoint(&xcenter,val,error);
5216 npoints++;
5217 }
5218
5219 if(fDebugLevel > 1){
55a288e5 5220
3a0f6479 5221 if ( !fDebugStreamer ) {
5222 //debug stream
5223 TDirectory *backup = gDirectory;
4aad967c 5224 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPRF.root");
3a0f6479 5225 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
5226 }
5227
5228 Int_t detector = fCountDet;
053767a4 5229 Int_t layer = GetLayer(fCountDet);
3a0f6479 5230 Int_t group = ibin;
5231
5232 (* fDebugStreamer) << "FitGausMIFill"<<
5233 "detector="<<detector<<
053767a4 5234 "layer="<<layer<<
3a0f6479 5235 "nbins="<<nBins<<
5236 "group="<<group<<
5237 "entriesI="<<entriesI<<
5238 "valueI="<<valueI<<
5239 "val="<<val<<
5240 "xcenter="<<xcenter<<
5241 "errorm="<<errorm<<
5242 "errorn="<<errorn<<
5243 "error="<<error<<
7bce990c 5244 "bError="<<bError<<
3a0f6479 5245 "\n";
5246 }
5247
5248 }
5249
5250 if(npoints <=3) return -4.0;
5251
5252 Double_t chi2 = 0;
5253 if (npoints>3){
5254 fitter.Eval();
5255 fitter.GetParameters(par);
5256 chi2 = fitter.GetChisquare()/Float_t(npoints);
55a288e5 5257
3a0f6479 5258
5259 if (!param) param = new TVectorD(3);
daa7dc79 5260 if(TMath::Abs(par[2]) <= 0.000000001) return -4.0;
3a0f6479 5261 Double_t x = TMath::Sqrt(TMath::Abs(-2*par[2]));
5262 Double_t deltax = (fitter.GetParError(2))/x;
5263 Double_t errorparam2 = TMath::Abs(deltax)/(x*x);
5264 chi2 = errorparam2;
55a288e5 5265
3a0f6479 5266 (*param)[1] = par[1]/(-2.*par[2]);
5267 (*param)[2] = 1./TMath::Sqrt(TMath::Abs(-2.*par[2]));
5268 Double_t lnparam0 = par[0]+ par[1]* (*param)[1] + par[2]*(*param)[1]*(*param)[1];
5269 if ( lnparam0>307 ) return -4;
5270 (*param)[0] = TMath::Exp(lnparam0);
5271
5272 if(fDebugLevel > 1){
5273
5274 if ( !fDebugStreamer ) {
5275 //debug stream
5276 TDirectory *backup = gDirectory;
4aad967c 5277 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPRF.root");
3a0f6479 5278 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
5279 }
5280
5281 Int_t detector = fCountDet;
053767a4 5282 Int_t layer = GetLayer(fCountDet);
3a0f6479 5283
5284
5285 (* fDebugStreamer) << "FitGausMIFit"<<
5286 "detector="<<detector<<
053767a4 5287 "layer="<<layer<<
3a0f6479 5288 "nbins="<<nBins<<
5289 "errorsigma="<<chi2<<
5290 "mean="<<(*param)[1]<<
5291 "sigma="<<(*param)[2]<<
5292 "constant="<<(*param)[0]<<
5293 "\n";
5294 }
5295 }
5296
5297 if((chi2/(*param)[2]) > 0.1){
7bce990c 5298 if(bError){
3a0f6479 5299 chi2 = FitGausMI(arraye,arraym,arrayme,nBins,xMin,xMax,param,kFALSE);
5300 }
5301 else return -4.0;
55a288e5 5302 }
3a0f6479 5303
5304 if(fDebugLevel == 1){
5305 TString name("PRF");
5306 name += (Int_t)xMin;
5307 name += (Int_t)xMax;
5308 TCanvas *c1 = new TCanvas((const char *)name,(const char *)name,50,50,600,800);
5309 c1->cd();
5310 name += "histo";
5311 TH1F *histo = new TH1F((const char *)name,(const char *)name,nBins,xMin,xMax);
5312 for(Int_t k = 0; k < nBins; k++){
5313 histo->SetBinContent(k+1,arraym[k]);
5314 histo->SetBinError(k+1,arrayme[k]);
5315 }
5316 histo->Draw();
5317 name += "functionf";
5318 TF1 *f1= new TF1((const char*)name,"[0]*exp(-(x-[1])^2/(2*[2]*[2]))",xMin,xMax);
5319 f1->SetParameter(0, (*param)[0]);
5320 f1->SetParameter(1, (*param)[1]);
5321 f1->SetParameter(2, (*param)[2]);
5322 f1->Draw("same");
5323 }
5324
5325
5326 return chi2;
5327
5328}
5329//_____________________________________________________________________________
5330void AliTRDCalibraFit::FitPRF(TH1 *projPRF)
5331{
5332 //
5333 // Fit methode for the sigma of the pad response function
5334 //
55a288e5 5335
3a0f6479 5336 fCurrentCoef[0] = 0.0;
5337 fCurrentCoefE = 0.0;
5338
5339 if (fDebugLevel != 1) {
5340 projPRF->Fit("gaus","0M","",-fRangeFitPRF,fRangeFitPRF);
5341 }
5342 else {
55a288e5 5343 TCanvas *cfit = new TCanvas("cfit","cfit",50,50,600,800);
5344 cfit->cd();
5345 projPRF->Fit("gaus","M+","",-fRangeFitPRF,fRangeFitPRF);
5346 projPRF->Draw();
55a288e5 5347 }
3a0f6479 5348 fCurrentCoef[0] = projPRF->GetFunction("gaus")->GetParameter(2);
5349 fCurrentCoefE = projPRF->GetFunction("gaus")->GetParError(2);
5350 if(fCurrentCoef[0] <= 0.0) fCurrentCoef[0] = -fCurrentCoef[1];
55a288e5 5351 else {
3a0f6479 5352 fNumberFitSuccess++;
55a288e5 5353 }
3a0f6479 5354}
5355//_____________________________________________________________________________
5356void AliTRDCalibraFit::RmsPRF(TH1 *projPRF)
5357{
5358 //
5359 // Fit methode for the sigma of the pad response function
5360 //
5361 fCurrentCoef[0] = 0.0;
5362 fCurrentCoefE = 0.0;
5363 if (fDebugLevel == 1) {
5364 TCanvas *cfit = new TCanvas("cfit","cfit",50,50,600,800);
5365 cfit->cd();
5366 projPRF->Draw();
55a288e5 5367 }
3a0f6479 5368 fCurrentCoef[0] = projPRF->GetRMS();
5369 if(fCurrentCoef[0] <= 0.0) fCurrentCoef[0] = -fCurrentCoef[1];
5370 else {
5371 fNumberFitSuccess++;
55a288e5 5372 }
55a288e5 5373}
55a288e5 5374//_____________________________________________________________________________
3a0f6479 5375void AliTRDCalibraFit::FitTnpRange(Double_t *arraye, Double_t *arraym, Double_t *arrayme, Int_t nbg, Int_t nybins)
55a288e5 5376{
5377 //
3a0f6479 5378 // Fit methode for the sigma of the pad response function with 2*nbg tan bins
55a288e5 5379 //
5380
3a0f6479 5381 TLinearFitter linearfitter = TLinearFitter(3,"pol2");
55a288e5 5382
55a288e5 5383
3a0f6479 5384 Int_t nbins = (Int_t)(nybins/(2*nbg));
5385 Float_t lowedge = -3.0*nbg;
5386 Float_t upedge = lowedge + 3.0;
5387 Int_t offset = 0;
5388 Int_t npoints = 0;
5389 Double_t xvalues = -0.2*nbg+0.1;
5390 Double_t y = 0.0;
5391 Int_t total = 2*nbg;
55a288e5 5392
3a0f6479 5393
5394 for(Int_t k = 0; k < total; k++){
5395 if(FitPRFGausMI(arraye+offset, arraym+offset, arrayme+offset, nbins, lowedge, upedge)){
5396 npoints++;
5397 y = fCurrentCoef[0]*fCurrentCoef[0];
5398 linearfitter.AddPoint(&xvalues,y,2*fCurrentCoefE*fCurrentCoef[0]);
5399 }
5400
5401 if(fDebugLevel > 1){
5402
5403 if ( !fDebugStreamer ) {
5404 //debug stream
5405 TDirectory *backup = gDirectory;
4aad967c 5406 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPRF.root");
3a0f6479 5407 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
5408 }
5409
5410 Int_t detector = fCountDet;
053767a4 5411 Int_t layer = GetLayer(fCountDet);
3a0f6479 5412 Int_t nbtotal = total;
5413 Int_t group = k;
5414 Float_t low = lowedge;
5415 Float_t up = upedge;
5416 Float_t tnp = xvalues;
5417 Float_t wid = fCurrentCoef[0];
5418 Float_t widfE = fCurrentCoefE;
5419
413153cb 5420 (* fDebugStreamer) << "FitTnpRange0"<<
3a0f6479 5421 "detector="<<detector<<
053767a4 5422 "layer="<<layer<<
3a0f6479 5423 "nbtotal="<<nbtotal<<
5424 "group="<<group<<
5425 "low="<<low<<
5426 "up="<<up<<
5427 "offset="<<offset<<
5428 "tnp="<<tnp<<
5429 "wid="<<wid<<
5430 "widfE="<<widfE<<
5431 "\n";
5432 }
5433
5434 offset += nbins;
5435 lowedge += 3.0;
5436 upedge += 3.0;
5437 xvalues += 0.2;
5438
5439 }
5440
5441 fCurrentCoefE = 0.0;
5442 fCurrentCoef[0] = 0.0;
5443
5444 //printf("npoints\n",npoints);
5445
5446 if(npoints < 3){
5447 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
5448 }
5449 else{
5450
5451 TVectorD pars0;
5452 linearfitter.Eval();
5453 linearfitter.GetParameters(pars0);
5454 Double_t pointError0 = TMath::Sqrt(linearfitter.GetChisquare()/npoints);
5455 Double_t errorsx0 = linearfitter.GetParError(2)*pointError0;
5456 Double_t min0 = 0.0;
5457 Double_t ermin0 = 0.0;
5458 //Double_t prfe0 = 0.0;
5459 Double_t prf0 = 0.0;
daa7dc79 5460 if((pars0[2] > 0.000000000001) && (TMath::Abs(pars0[1]) >= 0.000000000001)) {
3a0f6479 5461 min0 = -pars0[1]/(2*pars0[2]);
5462 ermin0 = TMath::Abs(min0*(errorsx0/pars0[2]+linearfitter.GetParError(1)*pointError0/pars0[1]));
5463 prf0 = pars0[0]+pars0[1]*min0+pars0[2]*min0*min0;
5464 if(prf0 > 0.0) {
5465 /*
5466 prfe0 = linearfitter->GetParError(0)*pointError0
5467 +(linearfitter->GetParError(1)*pointError0/pars0[1]+ermin0/min0)*pars0[1]*min0
5468 +(linearfitter->GetParError(2)*pointError0/pars0[2]+2*ermin0/min0)*pars0[2]*min0*min0;
5469 prfe0 = prfe0/(2*TMath::Sqrt(prf0));
5470 fCurrentCoefE = (Float_t) prfe0;
5471 */
5472 fCurrentCoef[0] = (Float_t) TMath::Sqrt(TMath::Abs(prf0));
5473 }
5474 else{
5475 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
5476 }
5477 }
5478 else {
5479 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
5480 }
55a288e5 5481
3a0f6479 5482 if(fDebugLevel > 1){
5483
5484 if ( !fDebugStreamer ) {
5485 //debug stream
5486 TDirectory *backup = gDirectory;
4aad967c 5487 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPRF.root");
3a0f6479 5488 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
5489 }
5490
5491 Int_t detector = fCountDet;
053767a4 5492 Int_t layer = GetLayer(fCountDet);
3a0f6479 5493 Int_t nbtotal = total;
5494 Double_t colsize[6] = {0.635,0.665,0.695,0.725,0.755,0.785};
053767a4 5495 Double_t sigmax = TMath::Sqrt(TMath::Abs(pars0[2]))*10000*colsize[layer];
3a0f6479 5496
413153cb 5497 (* fDebugStreamer) << "FitTnpRange1"<<
3a0f6479 5498 "detector="<<detector<<
053767a4 5499 "layer="<<layer<<
3a0f6479 5500 "nbtotal="<<nbtotal<<
5501 "par0="<<pars0[0]<<
5502 "par1="<<pars0[1]<<
5503 "par2="<<pars0[2]<<
5504 "npoints="<<npoints<<
5505 "sigmax="<<sigmax<<
5506 "tan="<<min0<<
5507 "sigmaprf="<<fCurrentCoef[0]<<
5508 "sigprf="<<fCurrentCoef[1]<<
5509 "\n";
5510 }
5511
55a288e5 5512 }
5513
5514}
55a288e5 5515//_____________________________________________________________________________
3a0f6479 5516void AliTRDCalibraFit::FitMean(TH1 *projch, Double_t nentries, Double_t mean)
55a288e5 5517{
5518 //
5519 // Only mean methode for the gain factor
5520 //
5521
3a0f6479 5522 fCurrentCoef[0] = mean;
5523 fCurrentCoefE = 0.0;
5524 if(nentries > 0) fCurrentCoefE = projch->GetRMS()/TMath::Sqrt(nentries);
5525 if (fDebugLevel == 1) {
55a288e5 5526 TCanvas *cpmean = new TCanvas("cpmean","cpmean",50,50,600,800);
5527 cpmean->cd();
5528 projch->Draw();
5529 }
3a0f6479 5530 CalculChargeCoefMean(kTRUE);
5531 fNumberFitSuccess++;
55a288e5 5532}
55a288e5 5533//_____________________________________________________________________________
3a0f6479 5534void AliTRDCalibraFit::FitMeanW(TH1 *projch, Double_t nentries)
55a288e5 5535{
5536 //
5537 // mean w methode for the gain factor
5538 //
5539
5540 //Number of bins
5541 Int_t nybins = projch->GetNbinsX();
5542
5543 //The weight function
5544 Double_t a = 0.00228515;
5545 Double_t b = -0.00231487;
5546 Double_t c = 0.00044298;
5547 Double_t d = -0.00379239;
5548 Double_t e = 0.00338349;
5549
3a0f6479 5550// 0 |0.00228515
5551// 1 |-0.00231487
5552// 2 |0.00044298
5553// 3 |-0.00379239
5554// 4 |0.00338349
5555
5556
55a288e5 5557
5558 //A arbitrary error for the moment
3a0f6479 5559 fCurrentCoefE = 0.0;
5560 fCurrentCoef[0] = 0.0;
55a288e5 5561
5562 //Calcul
5563 Double_t sumw = 0.0;
5564 Double_t sum = 0.0;
3a0f6479 5565 Float_t sumAll = (Float_t) nentries;
55a288e5 5566 Int_t sumCurrent = 0;
5567 for(Int_t k = 0; k <nybins; k++){
5568 Double_t fraction = Float_t(sumCurrent)/Float_t(sumAll);
5569 if (fraction>0.95) break;
5570 Double_t weight = a + b*fraction + c*fraction*fraction + d *fraction*fraction*fraction+
5571 e*fraction*fraction*fraction*fraction;
5572 sumw += weight*projch->GetBinContent(k+1)*projch->GetBinCenter(k+1);
5573 sum += weight*projch->GetBinContent(k+1);
5574 sumCurrent += (Int_t) projch->GetBinContent(k+1);
5575 //printf("fraction %f, weight %f, bincontent %f\n",fraction,weight,projch->GetBinContent(k+1));
5576 }
3a0f6479 5577 if(sum > 0.0) fCurrentCoef[0] = (sumw/sum);
55a288e5 5578
3a0f6479 5579 if (fDebugLevel == 1) {
55a288e5 5580 TCanvas *cpmeanw = new TCanvas("cpmeanw","cpmeanw",50,50,600,800);
5581 cpmeanw->cd();
5582 projch->Draw();
5583 }
3a0f6479 5584 fNumberFitSuccess++;
5585 CalculChargeCoefMean(kTRUE);
5586}
5587//_____________________________________________________________________________
5588void AliTRDCalibraFit::FitMeanWSm(TH1 *projch, Float_t sumAll)
5589{
5590 //
5591 // mean w methode for the gain factor
5592 //
5593
5594 //Number of bins
5595 Int_t nybins = projch->GetNbinsX();
5596
5597 //The weight function
5598 Double_t a = 0.00228515;
5599 Double_t b = -0.00231487;
5600 Double_t c = 0.00044298;
5601 Double_t d = -0.00379239;
5602 Double_t e = 0.00338349;
5603
5604// 0 |0.00228515
5605// 1 |-0.00231487
5606// 2 |0.00044298
5607// 3 |-0.00379239
5608// 4 |0.00338349
5609
5610
5611
5612 //A arbitrary error for the moment
5613 fCurrentCoefE = 0.0;
5614 fCurrentCoef[0] = 0.0;
55a288e5 5615
3a0f6479 5616 //Calcul
5617 Double_t sumw = 0.0;
5618 Double_t sum = 0.0;
5619 Int_t sumCurrent = 0;
5620 for(Int_t k = 0; k <nybins; k++){
5621 Double_t fraction = Float_t(sumCurrent)/Float_t(sumAll);
5622 if (fraction>0.95) break;
5623 Double_t weight = a + b*fraction + c*fraction*fraction + d *fraction*fraction*fraction+
5624 e*fraction*fraction*fraction*fraction;
5625 sumw += weight*projch->GetBinContent(k+1)*projch->GetBinCenter(k+1);
5626 sum += weight*projch->GetBinContent(k+1);
5627 sumCurrent += (Int_t) projch->GetBinContent(k+1);
5628 //printf("fraction %f, weight %f, bincontent %f\n",fraction,weight,projch->GetBinContent(k+1));
55a288e5 5629 }
3a0f6479 5630 if(sum > 0.0) fCurrentCoef[0] = (sumw/sum);
55a288e5 5631
3a0f6479 5632 if (fDebugLevel == 1) {
5633 TCanvas *cpmeanw = new TCanvas("cpmeanw","cpmeanw",50,50,600,800);
5634 cpmeanw->cd();
5635 projch->Draw();
5636 }
5637 fNumberFitSuccess++;
55a288e5 5638}
55a288e5 5639//_____________________________________________________________________________
3a0f6479 5640void AliTRDCalibraFit::FitCH(TH1 *projch, Double_t mean)
55a288e5 5641{
5642 //
5643 // Fit methode for the gain factor
5644 //
5645
3a0f6479 5646 fCurrentCoef[0] = 0.0;
5647 fCurrentCoefE = 0.0;
55a288e5 5648 Double_t chisqrl = 0.0;
5649 Double_t chisqrg = 0.0;
3a0f6479 5650 Double_t chisqr = 0.0;
55a288e5 5651 TF1 *fLandauGaus = new TF1("fLandauGaus",FuncLandauGaus,0,300,5);
5652
5653 projch->Fit("landau","0",""
3a0f6479 5654 ,(Double_t) mean/fBeginFitCharge
55a288e5 5655 ,projch->GetBinCenter(projch->GetNbinsX()));
5656 Double_t l3P0 = projch->GetFunction("landau")->GetParameter(0);
5657 Double_t l3P1 = projch->GetFunction("landau")->GetParameter(1);
5658 Double_t l3P2 = projch->GetFunction("landau")->GetParameter(2);
5659 chisqrl = projch->GetFunction("landau")->GetChisquare();
5660
5661 projch->Fit("gaus","0",""
3a0f6479 5662 ,(Double_t) mean/fBeginFitCharge
55a288e5 5663 ,projch->GetBinCenter(projch->GetNbinsX()));
5664 Double_t g3P0 = projch->GetFunction("gaus")->GetParameter(0);
5665 Double_t g3P2 = projch->GetFunction("gaus")->GetParameter(2);
5666 chisqrg = projch->GetFunction("gaus")->GetChisquare();
5667
5668 fLandauGaus->SetParameters(l3P0,l3P1,l3P2,g3P0,g3P2);
3a0f6479 5669 if (fDebugLevel != 1) {
55a288e5 5670 projch->Fit("fLandauGaus","0",""
3a0f6479 5671 ,(Double_t) mean/fBeginFitCharge
55a288e5 5672 ,projch->GetBinCenter(projch->GetNbinsX()));
5673 chisqr = projch->GetFunction("fLandauGaus")->GetChisquare();
3a0f6479 5674 }
5675 else {
55a288e5 5676 TCanvas *cp = new TCanvas("cp","cp",50,50,600,800);
5677 cp->cd();
5678 projch->Fit("fLandauGaus","+",""
3a0f6479 5679 ,(Double_t) mean/fBeginFitCharge
55a288e5 5680 ,projch->GetBinCenter(projch->GetNbinsX()));
5681 chisqr = projch->GetFunction("fLandauGaus")->GetChisquare();
5682 projch->Draw();
5683 fLandauGaus->Draw("same");
5684 }
5685
3a0f6479 5686 if ((projch->GetFunction("fLandauGaus")->GetParameter(1) > 0) && (projch->GetFunction("fLandauGaus")->GetParError(1) < (0.05*projch->GetFunction("fLandauGaus")->GetParameter(1))) && (chisqr < chisqrl) && (chisqr < chisqrg)) {
5687 //if ((projch->GetFunction("fLandauGaus")->GetParameter(1) > 0) && (chisqr < chisqrl) && (chisqr < chisqrg)) {
5688 fNumberFitSuccess++;
5689 CalculChargeCoefMean(kTRUE);
5690 fCurrentCoef[0] = projch->GetFunction("fLandauGaus")->GetParameter(1);
5691 fCurrentCoefE = projch->GetFunction("fLandauGaus")->GetParError(1);
55a288e5 5692 }
5693 else {
3a0f6479 5694 CalculChargeCoefMean(kFALSE);
5695 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
55a288e5 5696 }
5697
3a0f6479 5698 if (fDebugLevel != 1) {
55a288e5 5699 delete fLandauGaus;
5700 }
5701
5702}
55a288e5 5703//_____________________________________________________________________________
3a0f6479 5704void AliTRDCalibraFit::FitBisCH(TH1* projch, Double_t mean)
55a288e5 5705{
5706 //
5707 // Fit methode for the gain factor more time consuming
5708 //
5709
3a0f6479 5710
55a288e5 5711 //Some parameters to initialise
e6381f8e 5712 Double_t widthLandau, widthGaus, mPV, integral;
55a288e5 5713 Double_t chisquarel = 0.0;
5714 Double_t chisquareg = 0.0;
55a288e5 5715 projch->Fit("landau","0M+",""
3a0f6479 5716 ,(Double_t) mean/6
55a288e5 5717 ,projch->GetBinCenter(projch->GetNbinsX()));
5718 widthLandau = projch->GetFunction("landau")->GetParameter(2);
5719 chisquarel = projch->GetFunction("landau")->GetChisquare();
55a288e5 5720 projch->Fit("gaus","0M+",""
3a0f6479 5721 ,(Double_t) mean/6
55a288e5 5722 ,projch->GetBinCenter(projch->GetNbinsX()));
5723 widthGaus = projch->GetFunction("gaus")->GetParameter(2);
5724 chisquareg = projch->GetFunction("gaus")->GetChisquare();
3a0f6479 5725
e6381f8e 5726 mPV = (projch->GetFunction("landau")->GetParameter(1))/2;
5727 integral = (projch->GetFunction("gaus")->Integral(0.3*mean,3*mean)+projch->GetFunction("landau")->Integral(0.3*mean,3*mean))/2;
3a0f6479 5728
55a288e5 5729 // Setting fit range and start values
5730 Double_t fr[2];
5731 //Double_t sv[4] = { l3P2, fChargeCoef[1], projch->Integral("width"), fG3P2 };
5732 //Double_t sv[4] = { fL3P2, fChargeCoef[1], fL3P0, fG3P2 };
e6381f8e 5733 Double_t sv[4] = { widthLandau, mPV, integral, widthGaus};
55a288e5 5734 Double_t pllo[4] = { 0.001, 0.001, projch->Integral()/3, 0.001};
5735 Double_t plhi[4] = { 300.0, 300.0, 30*projch->Integral(), 300.0};
5736 Double_t fp[4] = { 1.0, 1.0, 1.0, 1.0 };
5737 Double_t fpe[4] = { 1.0, 1.0, 1.0, 1.0 };
3a0f6479 5738 fr[0] = 0.3 * mean;
5739 fr[1] = 3.0 * mean;
5740 fCurrentCoef[0] = 0.0;
5741 fCurrentCoefE = 0.0;
55a288e5 5742
5743 Double_t chisqr;
5744 Int_t ndf;
5745 TF1 *fitsnr = LanGauFit(projch,&fr[0],&sv[0]
5746 ,&pllo[0],&plhi[0]
5747 ,&fp[0],&fpe[0]
5748 ,&chisqr,&ndf);
5749
5750 Double_t projchPeak;
5751 Double_t projchFWHM;
5752 LanGauPro(fp,projchPeak,projchFWHM);
5753
5754 if ((fp[1] > 0) && ((fpe[1] < (0.05*fp[1])) && (chisqr < chisquarel) && (chisqr < chisquareg))) {
5755 //if ((fp[1] > 0) && ((chisqr < chisquarel) && (chisqr < chisquareg))) {
3a0f6479 5756 fNumberFitSuccess++;
5757 CalculChargeCoefMean(kTRUE);
5758 fCurrentCoef[0] = fp[1];
5759 fCurrentCoefE = fpe[1];
55a288e5 5760 //chargeCoefE2 = chisqr;
5761 }
5762 else {
3a0f6479 5763 CalculChargeCoefMean(kFALSE);
5764 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
55a288e5 5765 }
3a0f6479 5766 if (fDebugLevel == 1) {
5767 AliInfo(Form("fChargeCoef[0]: %f",(Float_t) fCurrentCoef[0]));
55a288e5 5768 TCanvas *cpy = new TCanvas("cpy","cpy",50,50,600,800);
5769 cpy->cd();
5770 projch->Draw();
5771 fitsnr->Draw("same");
5772 }
3a0f6479 5773 else {
55a288e5 5774 delete fitsnr;
5775 }
3a0f6479 5776}
55a288e5 5777//_____________________________________________________________________________
3b0c1edc 5778void AliTRDCalibraFit::CalculPolynomeLagrange2(const Double_t *x, const Double_t *y, Double_t &c0, Double_t &c1, Double_t &c2, Double_t &c3, Double_t &c4) const
55a288e5 5779{
5780 //
5781 // Calcul the coefficients of the polynome passant par ces trois points de degre 2
5782 //
55a288e5 5783 Double_t x0 = y[0]/((x[0]-x[1])*(x[0]-x[2]));
5784 Double_t x1 = y[1]/((x[1]-x[0])*(x[1]-x[2]));
5785 Double_t x2 = y[2]/((x[2]-x[0])*(x[2]-x[1]));
5786
3b0c1edc 5787 c4 = 0.0;
5788 c3 = 0.0;
5789 c2 = x0+x1+x2;
5790 c1 = -(x0*(x[1]+x[2])+x1*(x[0]+x[2])+x2*(x[0]+x[1]));
5791 c0 = x0*x[1]*x[2]+x1*x[0]*x[2]+x2*x[0]*x[1];
3a0f6479 5792
55a288e5 5793}
5794
5795//_____________________________________________________________________________
3b0c1edc 5796void AliTRDCalibraFit::CalculPolynomeLagrange3(const Double_t *x, const Double_t *y, Double_t &c0, Double_t &c1, Double_t &c2, Double_t &c3, Double_t &c4) const
55a288e5 5797{
5798 //
5799 // Calcul the coefficients of the polynome passant par ces quatre points de degre 3
5800 //
55a288e5 5801 Double_t x0 = y[0]/((x[0]-x[1])*(x[0]-x[2])*(x[0]-x[3]));
5802 Double_t x1 = y[1]/((x[1]-x[0])*(x[1]-x[2])*(x[1]-x[3]));
5803 Double_t x2 = y[2]/((x[2]-x[0])*(x[2]-x[1])*(x[2]-x[3]));
5804 Double_t x3 = y[3]/((x[3]-x[0])*(x[3]-x[1])*(x[3]-x[2]));
5805
3b0c1edc 5806 c4 = 0.0;
5807 c3 = x0+x1+x2+x3;
5808 c2 = -(x0*(x[1]+x[2]+x[3])
55a288e5 5809 +x1*(x[0]+x[2]+x[3])
5810 +x2*(x[0]+x[1]+x[3])
5811 +x3*(x[0]+x[1]+x[2]));
3b0c1edc 5812 c1 = (x0*(x[1]*x[2]+x[1]*x[3]+x[2]*x[3])
55a288e5 5813 +x1*(x[0]*x[2]+x[0]*x[3]+x[2]*x[3])
5814 +x2*(x[0]*x[1]+x[0]*x[3]+x[1]*x[3])
5815 +x3*(x[0]*x[1]+x[0]*x[2]+x[1]*x[2]));
5816
3b0c1edc 5817 c0 = -(x0*x[1]*x[2]*x[3]
55a288e5 5818 +x1*x[0]*x[2]*x[3]
5819 +x2*x[0]*x[1]*x[3]
5820 +x3*x[0]*x[1]*x[2]);
5821
3a0f6479 5822
55a288e5 5823}
5824
5825//_____________________________________________________________________________
3b0c1edc 5826void AliTRDCalibraFit::CalculPolynomeLagrange4(const Double_t *x, const Double_t *y, Double_t &c0, Double_t &c1, Double_t &c2, Double_t &c3, Double_t &c4) const
55a288e5 5827{
5828 //
5829 // Calcul the coefficients of the polynome passant par ces cinqs points de degre 4
5830 //
55a288e5 5831 Double_t x0 = y[0]/((x[0]-x[1])*(x[0]-x[2])*(x[0]-x[3])*(x[0]-x[4]));
5832 Double_t x1 = y[1]/((x[1]-x[0])*(x[1]-x[2])*(x[1]-x[3])*(x[1]-x[4]));
5833 Double_t x2 = y[2]/((x[2]-x[0])*(x[2]-x[1])*(x[2]-x[3])*(x[2]-x[4]));
5834 Double_t x3 = y[3]/((x[3]-x[0])*(x[3]-x[1])*(x[3]-x[2])*(x[3]-x[4]));
5835 Double_t x4 = y[4]/((x[4]-x[0])*(x[4]-x[1])*(x[4]-x[2])*(x[4]-x[3]));
3a0f6479 5836
55a288e5 5837
3b0c1edc 5838 c4 = x0+x1+x2+x3+x4;
5839 c3 = -(x0*(x[1]+x[2]+x[3]+x[4])
55a288e5 5840 +x1*(x[0]+x[2]+x[3]+x[4])
5841 +x2*(x[0]+x[1]+x[3]+x[4])
5842 +x3*(x[0]+x[1]+x[2]+x[4])
5843 +x4*(x[0]+x[1]+x[2]+x[3]));
3b0c1edc 5844 c2 = (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])
55a288e5 5845 +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])
5846 +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])
5847 +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])
5848 +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]));
5849
3b0c1edc 5850 c1 = -(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])
55a288e5 5851 +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])
5852 +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])
5853 +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])
5854 +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]));
5855
3b0c1edc 5856 c0 = (x0*x[1]*x[2]*x[3]*x[4]
55a288e5 5857 +x1*x[0]*x[2]*x[3]*x[4]
5858 +x2*x[0]*x[1]*x[3]*x[4]
5859 +x3*x[0]*x[1]*x[2]*x[4]
5860 +x4*x[0]*x[1]*x[2]*x[3]);
5861
55a288e5 5862}
55a288e5 5863//_____________________________________________________________________________
5864void AliTRDCalibraFit::NormierungCharge()
5865{
5866 //
5867 // Normalisation of the gain factor resulting for the fits
5868 //
5869
5870 // Calcul of the mean of choosen method by fFitChargeNDB
5871 Double_t sum = 0.0;
5872 //printf("total number of entries %d\n",fVectorFitCH->GetEntriesFast());
3a0f6479 5873 for (Int_t k = 0; k < (Int_t) fVectorFit.GetEntriesFast(); k++) {
55a288e5 5874 Int_t total = 0;
3a0f6479 5875 Int_t detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
5876 Float_t *coef = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef();
55a288e5 5877 //printf("detector %d coef[0] %f\n",detector,coef[0]);
053767a4 5878 if (GetStack(detector) == 2) {
55a288e5 5879 total = 1728;
5880 }
053767a4 5881 if (GetStack(detector) != 2) {
55a288e5 5882 total = 2304;
5883 }
5884 for (Int_t j = 0; j < total; j++) {
5885 if (coef[j] >= 0) {
5886 sum += coef[j];
5887 }
5888 }
5889 }
5890
5891 if (sum > 0) {
5892 fScaleFitFactor = fScaleFitFactor / sum;
5893 }
5894 else {
5895 fScaleFitFactor = 1.0;
3a0f6479 5896 }
55a288e5 5897
3a0f6479 5898 //methode de boeuf mais bon...
5899 Double_t scalefactor = fScaleFitFactor;
55a288e5 5900
3a0f6479 5901 if(fDebugLevel > 1){
5902
5903 if ( !fDebugStreamer ) {
5904 //debug stream
5905 TDirectory *backup = gDirectory;
4aad967c 5906 fDebugStreamer = new TTreeSRedirector("TRDDebugFitCH.root");
3a0f6479 5907 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
5908 }
413153cb 5909 (* fDebugStreamer) << "NormierungCharge"<<
3a0f6479 5910 "scalefactor="<<scalefactor<<
5911 "\n";
5912 }
55a288e5 5913}
55a288e5 5914//_____________________________________________________________________________
979b168f 5915TH1I *AliTRDCalibraFit::ReBin(const TH1I *hist) const
55a288e5 5916{
5917 //
5918 // Rebin of the 1D histo for the gain calibration if needed.
5919 // you have to choose fRebin, divider of fNumberBinCharge
5920 //
5921
3a0f6479 5922 TAxis *xhist = hist->GetXaxis();
5923 TH1I *rehist = new TH1I("projrebin","",(Int_t) xhist->GetNbins()/fRebin
5924 ,xhist->GetBinLowEdge(1)
5925 ,xhist->GetBinUpEdge(xhist->GetNbins()));
55a288e5 5926
3a0f6479 5927 AliInfo(Form("fRebin: %d",fRebin));
5928 Int_t i = 1;
5929 for (Int_t k = 1; k <= (Int_t) xhist->GetNbins()/fRebin; k++) {
5930 Double_t sum = 0.0;
5931 for (Int_t ji = i; ji < i+fRebin; ji++) {
5932 sum += hist->GetBinContent(ji);
5933 }
5934 sum = sum / fRebin;
5935 rehist->SetBinContent(k,sum);
5936 i += fRebin;
5937 }
55a288e5 5938
3a0f6479 5939 return rehist;
55a288e5 5940
5941}
5942
5943//_____________________________________________________________________________
979b168f 5944TH1F *AliTRDCalibraFit::ReBin(const TH1F *hist) const
55a288e5 5945{
5946 //
5947 // Rebin of the 1D histo for the gain calibration if needed
5948 // you have to choose fRebin divider of fNumberBinCharge
5949 //
5950
5951 TAxis *xhist = hist->GetXaxis();
5952 TH1F *rehist = new TH1F("projrebin","",(Int_t) xhist->GetNbins()/fRebin
5953 ,xhist->GetBinLowEdge(1)
5954 ,xhist->GetBinUpEdge(xhist->GetNbins()));
5955
5956 AliInfo(Form("fRebin: %d",fRebin));
5957 Int_t i = 1;
5958 for (Int_t k = 1; k <= (Int_t) xhist->GetNbins()/fRebin; k++) {
5959 Double_t sum = 0.0;
5960 for (Int_t ji = i; ji < i+fRebin; ji++) {
5961 sum += hist->GetBinContent(ji);
5962 }
5963 sum = sum/fRebin;
5964 rehist->SetBinContent(k,sum);
5965 i += fRebin;
5966 }
5967
55a288e5 5968 return rehist;
5969
55a288e5 5970}
55a288e5 5971//
5972//____________Some basic geometry function_____________________________________
5973//
5974
5975//_____________________________________________________________________________
053767a4 5976Int_t AliTRDCalibraFit::GetLayer(Int_t d) const
55a288e5 5977{
5978 //
5979 // Reconstruct the plane number from the detector number
5980 //
5981
5982 return ((Int_t) (d % 6));
5983
5984}
5985
5986//_____________________________________________________________________________
053767a4 5987Int_t AliTRDCalibraFit::GetStack(Int_t d) const
55a288e5 5988{
5989 //
053767a4 5990 // Reconstruct the stack number from the detector number
55a288e5 5991 //
053767a4 5992 const Int_t kNlayer = 6;
55a288e5 5993
053767a4 5994 return ((Int_t) (d % 30) / kNlayer);
55a288e5 5995
5996}
5997
5998//_____________________________________________________________________________
5999Int_t AliTRDCalibraFit::GetSector(Int_t d) const
6000{
6001 //
6002 // Reconstruct the sector number from the detector number
6003 //
6004 Int_t fg = 30;
6005
6006 return ((Int_t) (d / fg));
6007
6008}
6009
6010//
6011//____________Fill and Init tree Gain, PRF, Vdrift and T0______________________
6012//
3a0f6479 6013//_______________________________________________________________________________
6014void AliTRDCalibraFit::ResetVectorFit()
55a288e5 6015{
e6381f8e 6016 //
6017 // Reset the VectorFits
6018 //
6019
3a0f6479 6020 fVectorFit.SetOwner();
6021 fVectorFit.Clear();
6022 fVectorFit2.SetOwner();
6023 fVectorFit2.Clear();
55a288e5 6024
55a288e5 6025}
55a288e5 6026//
6027//____________Private Functions________________________________________________
6028//
6029
6030//_____________________________________________________________________________
979b168f 6031Double_t AliTRDCalibraFit::PH(const Double_t *x, const Double_t *par)
55a288e5 6032{
6033 //
6034 // Function for the fit
6035 //
6036
6037 //TF1 *fAsymmGauss = new TF1("fAsymmGauss",AsymmGauss,0,4,6);
6038
6039 //PARAMETERS FOR FIT PH
6040 // PASAv.4
6041 //fAsymmGauss->SetParameter(0,0.113755);
6042 //fAsymmGauss->SetParameter(1,0.350706);
6043 //fAsymmGauss->SetParameter(2,0.0604244);
6044 //fAsymmGauss->SetParameter(3,7.65596);
6045 //fAsymmGauss->SetParameter(4,1.00124);
6046 //fAsymmGauss->SetParameter(5,0.870597); // No tail cancelation
6047
6048 Double_t xx = x[0];
6049
6050 if (xx < par[1]) {
6051 return par[5];
6052 }
6053
6054 Double_t dx = 0.005;
6055 Double_t xs = par[1];
6056 Double_t ss = 0.0;
6057 Double_t paras[2] = { 0.0, 0.0 };
6058
6059 while (xs < xx) {
6060 if ((xs >= par[1]) &&
6061 (xs < (par[1]+par[2]))) {
6062 //fAsymmGauss->SetParameter(0,par[0]);
6063 //fAsymmGauss->SetParameter(1,xs);
6064 //ss += fAsymmGauss->Eval(xx);
6065 paras[0] = par[0];
6066 paras[1] = xs;
6067 ss += AsymmGauss(&xx,paras);
6068 }
6069 if ((xs >= (par[1]+par[2])) &&
6070 (xs < (par[1]+par[2]+par[3]))) {
6071 //fAsymmGauss->SetParameter(0,par[0]*par[4]);
6072 //fAsymmGauss->SetParameter(1,xs);
6073 //ss += fAsymmGauss->Eval(xx);
6074 paras[0] = par[0]*par[4];
6075 paras[1] = xs;
6076 ss += AsymmGauss(&xx,paras);
6077 }
6078 xs += dx;
6079 }
6080
6081 return ss + par[5];
6082
6083}
6084
6085//_____________________________________________________________________________
979b168f 6086Double_t AliTRDCalibraFit::AsymmGauss(const Double_t *x, const Double_t *par)
55a288e5 6087{
6088 //
6089 // Function for the fit
6090 //
6091
6092 //par[0] = normalization
6093 //par[1] = mean
6094 //par[2] = sigma
6095 //norm0 = 1
6096 //par[3] = lambda0
6097 //par[4] = norm1
6098 //par[5] = lambda1
6099
6100 Double_t par1save = par[1];
6101 //Double_t par2save = par[2];
6102 Double_t par2save = 0.0604244;
6103 //Double_t par3save = par[3];
6104 Double_t par3save = 7.65596;
6105 //Double_t par5save = par[5];
6106 Double_t par5save = 0.870597;
6107 Double_t dx = x[0] - par1save;
6108
6109 Double_t sigma2 = par2save*par2save;
6110 Double_t sqrt2 = TMath::Sqrt(2.0);
6111 Double_t exp1 = par3save * TMath::Exp(-par3save * (dx - 0.5 * par3save * sigma2))
bb7e41dd 6112 * (1.0 - AliMathBase::ErfFast((par3save * sigma2 - dx) / (sqrt2 * par2save)));
55a288e5 6113 Double_t exp2 = par5save * TMath::Exp(-par5save * (dx - 0.5 * par5save * sigma2))
bb7e41dd 6114 * (1.0 - AliMathBase::ErfFast((par5save * sigma2 - dx) / (sqrt2 * par2save)));
55a288e5 6115
6116 //return par[0]*(exp1+par[4]*exp2);
6117 return par[0] * (exp1 + 1.00124 * exp2);
6118
6119}
6120
6121//_____________________________________________________________________________
979b168f 6122Double_t AliTRDCalibraFit::FuncLandauGaus(const Double_t *x, const Double_t *par)
55a288e5 6123{
6124 //
6125 // Sum Landau + Gaus with identical mean
6126 //
6127
6128 Double_t valLandau = par[0] * TMath::Landau(x[0],par[1],par[2]);
6129 //Double_t valGaus = par[3] * TMath::Gaus(x[0],par[4],par[5]);
6130 Double_t valGaus = par[3] * TMath::Gaus(x[0],par[1],par[4]);
6131 Double_t val = valLandau + valGaus;
6132
6133 return val;
6134
6135}
6136
6137//_____________________________________________________________________________
979b168f 6138Double_t AliTRDCalibraFit::LanGauFun(const Double_t *x, const Double_t *par)
55a288e5 6139{
6140 //
6141 // Function for the fit
6142 //
6143 // Fit parameters:
6144 // par[0]=Width (scale) parameter of Landau density
6145 // par[1]=Most Probable (MP, location) parameter of Landau density
6146 // par[2]=Total area (integral -inf to inf, normalization constant)
6147 // par[3]=Width (sigma) of convoluted Gaussian function
6148 //
6149 // In the Landau distribution (represented by the CERNLIB approximation),
6150 // the maximum is located at x=-0.22278298 with the location parameter=0.
6151 // This shift is corrected within this function, so that the actual
6152 // maximum is identical to the MP parameter.
6153 //
6154
6155 // Numeric constants
6156 Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
6157 Double_t mpshift = -0.22278298; // Landau maximum location
6158
6159 // Control constants
6160 Double_t np = 100.0; // Number of convolution steps
6161 Double_t sc = 5.0; // Convolution extends to +-sc Gaussian sigmas
6162
6163 // Variables
6164 Double_t xx;
6165 Double_t mpc;
6166 Double_t fland;
6167 Double_t sum = 0.0;
6168 Double_t xlow;
6169 Double_t xupp;
6170 Double_t step;
6171 Double_t i;
6172
6173 // MP shift correction
6174 mpc = par[1] - mpshift * par[0];
6175
6176 // Range of convolution integral
6177 xlow = x[0] - sc * par[3];
6178 xupp = x[0] + sc * par[3];
6179
6180 step = (xupp - xlow) / np;
6181
6182 // Convolution integral of Landau and Gaussian by sum
6183 for (i = 1.0; i <= np/2; i++) {
6184
6185 xx = xlow + (i-.5) * step;
6186 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
6187 sum += fland * TMath::Gaus(x[0],xx,par[3]);
6188
6189 xx = xupp - (i-.5) * step;
6190 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
6191 sum += fland * TMath::Gaus(x[0],xx,par[3]);
6192
6193 }
6194
6195 return (par[2] * step * sum * invsq2pi / par[3]);
6196
6197}
55a288e5 6198//_____________________________________________________________________________
979b168f 6199TF1 *AliTRDCalibraFit::LanGauFit(TH1 *his, const Double_t *fitrange, const Double_t *startvalues
6200 , const Double_t *parlimitslo, const Double_t *parlimitshi
55a288e5 6201 , Double_t *fitparams, Double_t *fiterrors
e6381f8e 6202 , Double_t *chiSqr, Int_t *ndf) const
55a288e5 6203{
6204 //
6205 // Function for the fit
6206 //
6207
6208 Int_t i;
6209 Char_t funname[100];
6210
6211 TF1 *ffitold = (TF1 *) gROOT->GetListOfFunctions()->FindObject(funname);
6212 if (ffitold) {
6213 delete ffitold;
6214 }
6215
6216 TF1 *ffit = new TF1(funname,LanGauFun,fitrange[0],fitrange[1],4);
6217 ffit->SetParameters(startvalues);
6218 ffit->SetParNames("Width","MP","Area","GSigma");
6219
6220 for (i = 0; i < 4; i++) {
6221 ffit->SetParLimits(i,parlimitslo[i],parlimitshi[i]);
6222 }
6223
6224 his->Fit(funname,"RB0"); // Fit within specified range, use ParLimits, do not plot
6225
6226 ffit->GetParameters(fitparams); // Obtain fit parameters
6227 for (i = 0; i < 4; i++) {
6228 fiterrors[i] = ffit->GetParError(i); // Obtain fit parameter errors
6229 }
6230 chiSqr[0] = ffit->GetChisquare(); // Obtain chi^2
6231 ndf[0] = ffit->GetNDF(); // Obtain ndf
6232
6233 return (ffit); // Return fit function
6234
6235}
6236
6237//_____________________________________________________________________________
979b168f 6238Int_t AliTRDCalibraFit::LanGauPro(const Double_t *params, Double_t &maxx, Double_t &fwhm)
55a288e5 6239{
6240 //
6241 // Function for the fit
6242 //
6243
6244 Double_t p;
6245 Double_t x;
6246 Double_t fy;
6247 Double_t fxr;
6248 Double_t fxl;
6249 Double_t step;
6250 Double_t l;
6251 Double_t lold;
6252
6253 Int_t i = 0;
6254 Int_t maxcalls = 10000;
6255
6256 // Search for maximum
6257 p = params[1] - 0.1 * params[0];
6258 step = 0.05 * params[0];
6259 lold = -2.0;
6260 l = -1.0;
6261
6262 while ((l != lold) && (i < maxcalls)) {
6263 i++;
6264 lold = l;
6265 x = p + step;
6266 l = LanGauFun(&x,params);
6267 if (l < lold) {
6268 step = -step / 10.0;
6269 }
6270 p += step;
6271 }
6272
6273 if (i == maxcalls) {
6274 return (-1);
6275 }
6276 maxx = x;
6277 fy = l / 2.0;
6278
6279 // Search for right x location of fy
6280 p = maxx + params[0];
6281 step = params[0];
6282 lold = -2.0;
6283 l = -1e300;
6284 i = 0;
6285
6286 while ( (l != lold) && (i < maxcalls) ) {
6287 i++;
6288
6289 lold = l;
6290 x = p + step;
6291 l = TMath::Abs(LanGauFun(&x,params) - fy);
6292
6293 if (l > lold)
6294 step = -step/10;
6295
6296 p += step;
6297 }
6298
6299 if (i == maxcalls)
6300 return (-2);
6301
6302 fxr = x;
6303
3a0f6479 6304
55a288e5 6305 // Search for left x location of fy
6306
6307 p = maxx - 0.5 * params[0];
6308 step = -params[0];
6309 lold = -2.0;
6310 l = -1.0e300;
6311 i = 0;
6312
6313 while ((l != lold) && (i < maxcalls)) {
6314 i++;
6315 lold = l;
6316 x = p + step;
6317 l = TMath::Abs(LanGauFun(&x,params) - fy);
6318 if (l > lold) {
6319 step = -step / 10.0;
6320 }
6321 p += step;
6322 }
6323
6324 if (i == maxcalls) {
6325 return (-3);
6326 }
6327
6328 fxl = x;
6329 fwhm = fxr - fxl;
6330
6331 return (0);
55a288e5 6332}
55a288e5 6333//_____________________________________________________________________________
979b168f 6334Double_t AliTRDCalibraFit::GausConstant(const Double_t *x, const Double_t *par)
55a288e5 6335{
6336 //
6337 // Gaus with identical mean
6338 //
6339
e6381f8e 6340 Double_t gauss = par[0] * TMath::Gaus(x[0],0.0,par[1])+par[2];
55a288e5 6341
e6381f8e 6342 return gauss;
55a288e5 6343
ef19f1da 6344}
4c865c34 6345
3b0c1edc 6346
6347