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