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