new database entry to store PID threshold at 90% efficiency (Markus)
[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
31// _fDebug = 1: a comparaison of the coefficients found and the default values
32// in the choosen database.
33// fCoef , histogram of the coefs as function of the calibration group number
34// fDelta , histogram of the relative difference of the coef with the default
35// value in the database as function of the calibration group number
36// fError , dirstribution of this relative difference
37// _fDebug = 2: only the fit of the choosen calibration group fFitVoir (SetFitVoir)
38// _fDebug = 3: The coefficients in the choosen detector fDet (SetDet) as function of the
39// pad row and col number
40// _fDebug = 4; The coeffcicients in the choosen detector fDet (SetDet) like in the 3 but with
41// also the comparaison histograms of the 1 for this detector
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>
62#include <TROOT.h>
3a0f6479 63#include <TTreeStream.h>
64#include <TLinearFitter.h>
65#include <TVectorD.h>
66#include <TArrayF.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"
55a288e5 79#include "./Cal/AliTRDCalROC.h"
80#include "./Cal/AliTRDCalPad.h"
81#include "./Cal/AliTRDCalDet.h"
82
83
84ClassImp(AliTRDCalibraFit)
85
86AliTRDCalibraFit* AliTRDCalibraFit::fgInstance = 0;
87Bool_t AliTRDCalibraFit::fgTerminated = kFALSE;
88
89//_____________singleton implementation_________________________________________________
90AliTRDCalibraFit *AliTRDCalibraFit::Instance()
91{
92 //
93 // Singleton implementation
94 //
95
96 if (fgTerminated != kFALSE) {
97 return 0;
98 }
99
100 if (fgInstance == 0) {
101 fgInstance = new AliTRDCalibraFit();
102 }
103
104 return fgInstance;
105
106}
107
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}
124
125//______________________________________________________________________________________
126AliTRDCalibraFit::AliTRDCalibraFit()
127 :TObject()
f162af62 128 ,fGeo(0)
3a0f6479 129 ,fNumberOfBinsExpected(0)
130 ,fMethod(0)
131 ,fBeginFitCharge(3.5)
132 ,fFitPHPeriode(1)
413153cb 133 ,fTakeTheMaxPH(kTRUE)
134 ,fT0Shift0(0.124797)
135 ,fT0Shift1(0.267451)
3a0f6479 136 ,fRangeFitPRF(1.0)
55a288e5 137 ,fAccCDB(kFALSE)
3a0f6479 138 ,fMinEntries(800)
139 ,fRebin(1)
55a288e5 140 ,fNumberFit(0)
141 ,fNumberFitSuccess(0)
142 ,fNumberEnt(0)
143 ,fStatisticMean(0.0)
3a0f6479 144 ,fDebugStreamer(0x0)
145 ,fDebugLevel(0)
55a288e5 146 ,fFitVoir(0)
3a0f6479 147 ,fMagneticField(0.5)
148 ,fCalibraMode(new AliTRDCalibraMode())
149 ,fCurrentCoefE(0.0)
150 ,fCurrentCoefE2(0.0)
151 ,fDect1(0)
152 ,fDect2(0)
55a288e5 153 ,fScaleFitFactor(0.0)
154 ,fEntriesCurrent(0)
3a0f6479 155 ,fCountDet(0)
156 ,fCount(0)
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)
215,fCalDet(0x0)
216,fCalROC(0x0)
217,fCalDet2(0x0)
218,fCalROC2(0x0)
219,fCurrentCoefDetector(0x0)
220,fCurrentCoefDetector2(0x0)
221,fVectorFit(0)
222,fVectorFit2(0)
55a288e5 223{
224 //
225 // Copy constructor
226 //
227
3a0f6479 228 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
229
230 //Current variables initialised
231 for (Int_t k = 0; k < 2; k++) {
232 fCurrentCoef[k] = 0.0;
233 fCurrentCoef2[k] = 0.0;
234 }
235 for (Int_t i = 0; i < 3; i++) {
236 fPhd[i] = 0.0;
237 fDet[i] = 0;
238 }
239 if(c.fCalDet) fCalDet = new AliTRDCalDet(*c.fCalDet);
240 if(c.fCalDet2) fCalDet2 = new AliTRDCalDet(*c.fCalDet2);
241
242 if(c.fCalROC) fCalROC = new AliTRDCalROC(*c.fCalROC);
243 if(c.fCalROC2) fCalROC = new AliTRDCalROC(*c.fCalROC2);
244
245 fVectorFit.SetName(c.fVectorFit.GetName());
246 for(Int_t k = 0; k < c.fVectorFit.GetEntriesFast(); k++){
247 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
248 Int_t detector = ((AliTRDFitInfo *)c.fVectorFit.UncheckedAt(k))->GetDetector();
249 Int_t ntotal = 1;
053767a4 250 if (GetStack(detector) == 2) {
3a0f6479 251 ntotal = 1728;
252 }
253 else {
254 ntotal = 2304;
255 }
256 Float_t *coef = new Float_t[ntotal];
257 for (Int_t i = 0; i < ntotal; i++) {
258 coef[i] = ((AliTRDFitInfo *)c.fVectorFit.UncheckedAt(k))->GetCoef()[i];
259 }
260 fitInfo->SetCoef(coef);
261 fitInfo->SetDetector(detector);
262 fVectorFit.Add((TObject *) fitInfo);
263 }
264 fVectorFit.SetName(c.fVectorFit.GetName());
265 for(Int_t k = 0; k < c.fVectorFit2.GetEntriesFast(); k++){
266 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
267 Int_t detector = ((AliTRDFitInfo *)c.fVectorFit2.UncheckedAt(k))->GetDetector();
268 Int_t ntotal = 1;
053767a4 269 if (GetStack(detector) == 2) {
3a0f6479 270 ntotal = 1728;
271 }
272 else {
273 ntotal = 2304;
274 }
275 Float_t *coef = new Float_t[ntotal];
276 for (Int_t i = 0; i < ntotal; i++) {
277 coef[i] = ((AliTRDFitInfo *)c.fVectorFit2.UncheckedAt(k))->GetCoef()[i];
278 }
279 fitInfo->SetCoef(coef);
280 fitInfo->SetDetector(detector);
281 fVectorFit2.Add((TObject *) fitInfo);
282 }
283 if (fGeo) {
284 delete fGeo;
285 }
286 fGeo = new AliTRDgeometry();
55a288e5 287
3a0f6479 288}
55a288e5 289//____________________________________________________________________________________
290AliTRDCalibraFit::~AliTRDCalibraFit()
291{
292 //
293 // AliTRDCalibraFit destructor
294 //
3a0f6479 295 if ( fDebugStreamer ) delete fDebugStreamer;
296 if ( fCalDet ) delete fCalDet;
297 if ( fCalDet2 ) delete fCalDet2;
298 if ( fCalROC ) delete fCalROC;
1ca79a00 299 if ( fCalROC2 ) delete fCalROC2;
300 if( fCurrentCoefDetector ) delete [] fCurrentCoefDetector;
301 if( fCurrentCoefDetector2 ) delete [] fCurrentCoefDetector2;
3a0f6479 302 fVectorFit.Delete();
303 fVectorFit2.Delete();
f162af62 304 if (fGeo) {
305 delete fGeo;
306 }
307
55a288e5 308}
55a288e5 309//_____________________________________________________________________________
310void AliTRDCalibraFit::Destroy()
311{
312 //
313 // Delete instance
314 //
315
316 if (fgInstance) {
317 delete fgInstance;
318 fgInstance = 0x0;
319 }
320
321}
413153cb 322//__________________________________________________________________________________
323void AliTRDCalibraFit::RangeChargeIntegration(Float_t vdrift, Float_t t0, Int_t &begin, Int_t &peak, Int_t &end)
324{
325 //
326 // From the drift velocity and t0
327 // return the position of the peak and maximum negative slope
328 //
329
330 const Float_t kDrWidth = AliTRDgeometry::DrThick(); // drift region
331 Double_t widbins = 0.1; // 0.1 mus
332
333 //peak and maxnegslope in mus
334 Double_t begind = t0*widbins + fT0Shift0;
335 Double_t peakd = t0*widbins + fT0Shift1;
336 Double_t maxnegslope = (kDrWidth + vdrift*peakd)/vdrift;
337
338 // peak and maxnegslope in timebin
339 begin = TMath::Nint(begind*widbins);
340 peak = TMath::Nint(peakd*widbins);
341 end = TMath::Nint(maxnegslope*widbins);
342
343}
55a288e5 344//____________Functions fit Online CH2d________________________________________
3a0f6479 345Bool_t AliTRDCalibraFit::AnalyseCH(TH2I *ch)
55a288e5 346{
347 //
348 // Fit the 1D histos, projections of the 2D ch on the Xaxis, for each
349 // calibration group normalized the resulted coefficients (to 1 normally)
55a288e5 350 //
351
3a0f6479 352 // Set the calibration mode
353 const char *name = ch->GetTitle();
354 SetModeCalibration(name,0);
355
356 // Number of Ybins (detectors or groups of pads)
357 Int_t nbins = ch->GetNbinsX();// charge
358 Int_t nybins = ch->GetNbinsY();// groups number
359 if (!InitFit(nybins,0)) {
55a288e5 360 return kFALSE;
361 }
3a0f6479 362 if (!InitFitCH()) {
55a288e5 363 return kFALSE;
364 }
365 fStatisticMean = 0.0;
366 fNumberFit = 0;
367 fNumberFitSuccess = 0;
368 fNumberEnt = 0;
55a288e5 369 // Init fCountDet and fCount
370 InitfCountDetAndfCount(0);
55a288e5 371 // Beginning of the loop betwwen dect1 and dect2
3a0f6479 372 for (Int_t idect = fDect1; idect < fDect2; idect++) {
373 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...
55a288e5 374 UpdatefCountDetAndfCount(idect,0);
55a288e5 375 ReconstructFitRowMinRowMax(idect, 0);
3a0f6479 376 // Take the histo
377 TH1I *projch = (TH1I *) ch->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
378 projch->SetDirectory(0);
55a288e5 379 // Number of entries for this calibration group
380 Double_t nentries = 0.0;
381 Double_t mean = 0.0;
3a0f6479 382 for (Int_t k = 0; k < nbins; k++) {
383 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
384 nentries += ch->GetBinContent(binnb);
55a288e5 385 mean += projch->GetBinCenter(k+1)*projch->GetBinContent(k+1);
3a0f6479 386 projch->SetBinError(k+1,TMath::Sqrt(projch->GetBinContent(k+1)));
55a288e5 387 }
3a0f6479 388 projch->SetEntries(nentries);
389 //printf("The number of entries for the group %d is %f\n",idect,nentries);
55a288e5 390 if (nentries > 0) {
391 fNumberEnt++;
392 mean /= nentries;
393 }
55a288e5 394 // Rebin and statistic stuff
55a288e5 395 if (fRebin > 1) {
396 projch = ReBin((TH1I *) projch);
397 }
398 // This detector has not enough statistics or was off
3a0f6479 399 if (nentries <= fMinEntries) {
400 NotEnoughStatisticCH(idect);
401 if (fDebugLevel != 1) {
55a288e5 402 delete projch;
403 }
404 continue;
405 }
55a288e5 406 // Statistics of the group fitted
55a288e5 407 fStatisticMean += nentries;
408 fNumberFit++;
3a0f6479 409 //Method choosen
410 switch(fMethod)
411 {
412 case 0: FitMeanW((TH1 *) projch, nentries); break;
413 case 1: FitMean((TH1 *) projch, nentries, mean); break;
414 case 2: FitCH((TH1 *) projch, mean); break;
415 case 3: FitBisCH((TH1 *) projch, mean); break;
416 default: return kFALSE;
417 }
55a288e5 418 // Fill Infos Fit
3a0f6479 419 FillInfosFitCH(idect);
55a288e5 420 // Memory!!!
3a0f6479 421 if (fDebugLevel != 1) {
55a288e5 422 delete projch;
423 }
55a288e5 424 } // Boucle object
55a288e5 425 // Normierungcharge
3a0f6479 426 if (fDebugLevel != 1) {
55a288e5 427 NormierungCharge();
428 }
55a288e5 429 // Mean Statistic
430 if (fNumberFit > 0) {
3a0f6479 431 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 432 fStatisticMean = fStatisticMean / fNumberFit;
433 }
434 else {
435 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
436 }
3a0f6479 437 delete fDebugStreamer;
438 fDebugStreamer = 0x0;
439
55a288e5 440 return kTRUE;
55a288e5 441}
55a288e5 442//____________Functions fit Online CH2d________________________________________
3a0f6479 443Bool_t AliTRDCalibraFit::AnalyseCH(AliTRDCalibraVector *calvect)
55a288e5 444{
445 //
446 // Reconstruct a 1D histo from the vectorCH for each calibration group,
447 // fit the histo, normalized the resulted coefficients (to 1 normally)
55a288e5 448 //
449
3a0f6479 450 // Set the calibraMode
451 const char *name = calvect->GetNameCH();
452 SetModeCalibration(name,0);
55a288e5 453
3a0f6479 454 // Number of Xbins (detectors or groups of pads)
455 if (!InitFit((432*calvect->GetDetCha0(0)+108*calvect->GetDetCha2(0)),0)) {
55a288e5 456 return kFALSE;
457 }
3a0f6479 458 if (!InitFitCH()) {
55a288e5 459 return kFALSE;
460 }
461 fStatisticMean = 0.0;
462 fNumberFit = 0;
463 fNumberFitSuccess = 0;
464 fNumberEnt = 0;
55a288e5 465 // Init fCountDet and fCount
466 InitfCountDetAndfCount(0);
55a288e5 467 // Beginning of the loop between dect1 and dect2
3a0f6479 468 for (Int_t idect = fDect1; idect < fDect2; idect++) {
469 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...........
55a288e5 470 UpdatefCountDetAndfCount(idect,0);
55a288e5 471 ReconstructFitRowMinRowMax(idect,0);
3a0f6479 472 // Take the histo
55a288e5 473 Double_t nentries = 0.0;
474 Double_t mean = 0.0;
3a0f6479 475 TH1F *projch = 0x0;
476 Bool_t something = kTRUE;
477 if(!calvect->GetCHEntries(fCountDet)) something = kFALSE;
478 if(something){
7bce990c 479 TString tname("CH");
480 tname += idect;
481 projch = calvect->ConvertVectorCHHisto(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0)))),(const char *) tname);
3a0f6479 482 projch->SetDirectory(0);
483 for (Int_t k = 0; k < calvect->GetNumberBinCharge(); k++) {
55a288e5 484 nentries += projch->GetBinContent(k+1);
485 mean += projch->GetBinCenter(k+1)*projch->GetBinContent(k+1);
486 }
3a0f6479 487 if (nentries > 0) {
488 fNumberEnt++;
489 mean /= nentries;
490 }
491 //printf("The number of entries for the group %d is %f\n",idect,nentries);
492 // Rebin
493 if (fRebin > 1) {
494 projch = ReBin((TH1F *) projch);
495 }
55a288e5 496 }
55a288e5 497 // This detector has not enough statistics or was not found in VectorCH
3a0f6479 498 if (nentries <= fMinEntries) {
499 NotEnoughStatisticCH(idect);
500 if (fDebugLevel != 1) {
501 if(projch) delete projch;
55a288e5 502 }
55a288e5 503 continue;
55a288e5 504 }
55a288e5 505 // Statistic of the histos fitted
55a288e5 506 fStatisticMean += nentries;
507 fNumberFit++;
3a0f6479 508 //Method choosen
509 switch(fMethod)
510 {
511 case 0: FitMeanW((TH1 *) projch, nentries); break;
512 case 1: FitMean((TH1 *) projch, nentries, mean); break;
513 case 2: FitCH((TH1 *) projch, mean); break;
514 case 3: FitBisCH((TH1 *) projch, mean); break;
515 default: return kFALSE;
516 }
55a288e5 517 // Fill Infos Fit
3a0f6479 518 FillInfosFitCH(idect);
55a288e5 519 // Memory!!!
3a0f6479 520 if (fDebugLevel != 1) {
55a288e5 521 delete projch;
522 }
55a288e5 523 } // Boucle object
55a288e5 524 // Normierungcharge
3a0f6479 525 if (fDebugLevel != 1) {
55a288e5 526 NormierungCharge();
527 }
55a288e5 528 // Mean Statistics
529 if (fNumberFit > 0) {
3a0f6479 530 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 531 fStatisticMean = fStatisticMean / fNumberFit;
532 }
533 else {
534 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
535 }
3a0f6479 536 delete fDebugStreamer;
537 fDebugStreamer = 0x0;
55a288e5 538 return kTRUE;
55a288e5 539}
55a288e5 540//________________functions fit Online PH2d____________________________________
3a0f6479 541Bool_t AliTRDCalibraFit::AnalysePH(TProfile2D *ph)
55a288e5 542{
543 //
544 // Take the 1D profiles (average pulse height), projections of the 2D PH
545 // on the Xaxis, for each calibration group
3a0f6479 546 // Reconstruct a drift velocity
547 // A first calibration of T0 is also made using the same method
55a288e5 548 //
549
3a0f6479 550 // Set the calibration mode
551 const char *name = ph->GetTitle();
552 SetModeCalibration(name,1);
55a288e5 553
554 // Number of Xbins (detectors or groups of pads)
3a0f6479 555 Int_t nbins = ph->GetNbinsX();// time
556 Int_t nybins = ph->GetNbinsY();// calibration group
557 if (!InitFit(nybins,1)) {
558 return kFALSE;
559 }
560 if (!InitFitPH()) {
55a288e5 561 return kFALSE;
562 }
563 fStatisticMean = 0.0;
564 fNumberFit = 0;
565 fNumberFitSuccess = 0;
566 fNumberEnt = 0;
55a288e5 567 // Init fCountDet and fCount
568 InitfCountDetAndfCount(1);
55a288e5 569 // Beginning of the loop
3a0f6479 570 for (Int_t idect = fDect1; idect < fDect2; idect++) {
571 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi.......
572 UpdatefCountDetAndfCount(idect,1);
573 ReconstructFitRowMinRowMax(idect,1);
574 // Take the histo
575 TH1D *projph = (TH1D *) ph->ProjectionX("projph",idect+1,idect+1,(Option_t *) "e");
55a288e5 576 projph->SetDirectory(0);
55a288e5 577 // Number of entries for this calibration group
578 Double_t nentries = 0;
3a0f6479 579 for (Int_t k = 0; k < nbins; k++) {
580 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
581 nentries += ph->GetBinEntries(binnb);
55a288e5 582 }
583 if (nentries > 0) {
584 fNumberEnt++;
585 }
3a0f6479 586 //printf("The number of entries for the group %d is %f\n",idect,nentries);
55a288e5 587 // This detector has not enough statistics or was off
3a0f6479 588 if (nentries <= fMinEntries) {
589 //printf("Not enough statistic!\n");
590 NotEnoughStatisticPH(idect);
591 if (fDebugLevel != 1) {
55a288e5 592 delete projph;
593 }
55a288e5 594 continue;
55a288e5 595 }
55a288e5 596 // Statistics of the histos fitted
55a288e5 597 fNumberFit++;
598 fStatisticMean += nentries;
55a288e5 599 // Calcul of "real" coef
3a0f6479 600 CalculVdriftCoefMean();
601 CalculT0CoefMean();
602 //Method choosen
603 switch(fMethod)
604 {
605 case 0: FitLagrangePoly((TH1 *) projph); break;
606 case 1: FitPente((TH1 *) projph); break;
607 case 2: FitPH((TH1 *) projph,(Int_t) (idect - fDect1)); break;
608 default: return kFALSE;
609 }
55a288e5 610 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 611 FillInfosFitPH(idect);
55a288e5 612 // Memory!!!
3a0f6479 613 if (fDebugLevel != 1) {
55a288e5 614 delete projph;
615 }
55a288e5 616 } // Boucle object
55a288e5 617 // Mean Statistic
618 if (fNumberFit > 0) {
3a0f6479 619 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 620 fStatisticMean = fStatisticMean / fNumberFit;
621 }
622 else {
623 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
624 }
3a0f6479 625 delete fDebugStreamer;
626 fDebugStreamer = 0x0;
55a288e5 627 return kTRUE;
55a288e5 628}
55a288e5 629//____________Functions fit Online PH2d________________________________________
3a0f6479 630Bool_t AliTRDCalibraFit::AnalysePH(AliTRDCalibraVector *calvect)
55a288e5 631{
632 //
633 // Reconstruct the average pulse height from the vectorPH for each
634 // calibration group
3a0f6479 635 // Reconstruct a drift velocity
55a288e5 636 // A first calibration of T0 is also made using the same method (slope method)
637 //
638
3a0f6479 639 // Set the calibration mode
640 const char *name = calvect->GetNamePH();
641 SetModeCalibration(name,1);
55a288e5 642
3a0f6479 643 // Number of Xbins (detectors or groups of pads)
644 if (!InitFit((432*calvect->GetDetCha0(1)+108*calvect->GetDetCha2(1)),1)) {
55a288e5 645 return kFALSE;
646 }
3a0f6479 647 if (!InitFitPH()) {
55a288e5 648 return kFALSE;
649 }
650 fStatisticMean = 0.0;
651 fNumberFit = 0;
652 fNumberFitSuccess = 0;
653 fNumberEnt = 0;
55a288e5 654 // Init fCountDet and fCount
655 InitfCountDetAndfCount(1);
55a288e5 656 // Beginning of the loop
3a0f6479 657 for (Int_t idect = fDect1; idect < fDect2; idect++) {
658 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi...........
55a288e5 659 UpdatefCountDetAndfCount(idect,1);
55a288e5 660 ReconstructFitRowMinRowMax(idect,1);
3a0f6479 661 // Take the histo
662 TH1F *projph = 0x0;
663 fEntriesCurrent = 0;
664 Bool_t something = kTRUE;
665 if(!calvect->GetPHEntries(fCountDet)) something = kFALSE;
666 if(something){
7bce990c 667 TString tname("PH");
668 tname += idect;
669 projph = CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPHTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname)));
3a0f6479 670 projph->SetDirectory(0);
671 }
672 //printf("The number of entries for the group %d is %d\n",idect,fEntriesCurrent);
55a288e5 673 // This detector has not enough statistics or was off
3a0f6479 674 if (fEntriesCurrent <= fMinEntries) {
675 //printf("Not enough stat!\n");
676 NotEnoughStatisticPH(idect);
677 if (fDebugLevel != 1) {
678 if(projph) delete projph;
55a288e5 679 }
55a288e5 680 continue;
55a288e5 681 }
55a288e5 682 // Statistic of the histos fitted
55a288e5 683 fNumberFit++;
684 fStatisticMean += fEntriesCurrent;
55a288e5 685 // Calcul of "real" coef
3a0f6479 686 CalculVdriftCoefMean();
687 CalculT0CoefMean();
688 //Method choosen
689 switch(fMethod)
690 {
691 case 0: FitLagrangePoly((TH1 *) projph); break;
692 case 1: FitPente((TH1 *) projph); break;
693 case 2: FitPH((TH1 *) projph,(Int_t) (idect - fDect1)); break;
694 default: return kFALSE;
695 }
55a288e5 696 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 697 FillInfosFitPH(idect);
55a288e5 698 // Memory!!!
3a0f6479 699 if (fDebugLevel != 1) {
55a288e5 700 delete projph;
701 }
55a288e5 702 } // Boucle object
3a0f6479 703
55a288e5 704 // Mean Statistic
705 if (fNumberFit > 0) {
3a0f6479 706 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 707 fStatisticMean = fStatisticMean / fNumberFit;
708 }
709 else {
710 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
711 }
3a0f6479 712 delete fDebugStreamer;
713 fDebugStreamer = 0x0;
55a288e5 714 return kTRUE;
55a288e5 715}
3a0f6479 716//____________Functions fit Online PRF2d_______________________________________
717Bool_t AliTRDCalibraFit::AnalysePRF(TProfile2D *prf)
55a288e5 718{
719 //
3a0f6479 720 // Take the 1D profiles (pad response function), projections of the 2D PRF
721 // on the Xaxis, for each calibration group
722 // Fit with a gaussian to reconstruct the sigma of the pad response function
55a288e5 723 //
3a0f6479 724
725 // Set the calibration mode
726 const char *name = prf->GetTitle();
727 SetModeCalibration(name,2);
728
729 // Number of Ybins (detectors or groups of pads)
730 Int_t nybins = prf->GetNbinsY();// calibration groups
731 Int_t nbins = prf->GetNbinsX();// bins
732 Int_t nbg = GetNumberOfGroupsPRF((const char *)prf->GetTitle());
733 if((nbg > 0) || (nbg == -1)) return kFALSE;
734 if (!InitFit(nybins,2)) {
55a288e5 735 return kFALSE;
736 }
3a0f6479 737 if (!InitFitPRF()) {
55a288e5 738 return kFALSE;
739 }
740 fStatisticMean = 0.0;
3a0f6479 741 fNumberFit = 0;
55a288e5 742 fNumberFitSuccess = 0;
743 fNumberEnt = 0;
55a288e5 744 // Init fCountDet and fCount
3a0f6479 745 InitfCountDetAndfCount(2);
55a288e5 746 // Beginning of the loop
3a0f6479 747 for (Int_t idect = fDect1; idect < fDect2; idect++) {
748 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi......
749 UpdatefCountDetAndfCount(idect,2);
750 ReconstructFitRowMinRowMax(idect,2);
751 // Take the histo
752 TH1D *projprf = (TH1D *) prf->ProjectionX("projprf",idect+1,idect+1,(Option_t *) "e");
753 projprf->SetDirectory(0);
754 // Number of entries for this calibration group
755 Double_t nentries = 0;
756 for (Int_t k = 0; k < nbins; k++) {
757 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
758 nentries += prf->GetBinEntries(binnb);
55a288e5 759 }
3a0f6479 760 if(nentries > 0) fNumberEnt++;
55a288e5 761 // This detector has not enough statistics or was off
3a0f6479 762 if (nentries <= fMinEntries) {
763 NotEnoughStatisticPRF(idect);
764 if (fDebugLevel != 1) {
765 delete projprf;
55a288e5 766 }
55a288e5 767 continue;
55a288e5 768 }
55a288e5 769 // Statistics of the histos fitted
55a288e5 770 fNumberFit++;
3a0f6479 771 fStatisticMean += nentries;
55a288e5 772 // Calcul of "real" coef
3a0f6479 773 CalculPRFCoefMean();
774 //Method choosen
775 switch(fMethod)
776 {
777 case 0: FitPRF((TH1 *) projprf); break;
778 case 1: RmsPRF((TH1 *) projprf); break;
779 default: return kFALSE;
780 }
55a288e5 781 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 782 FillInfosFitPRF(idect);
55a288e5 783 // Memory!!!
3a0f6479 784 if (fDebugLevel != 1) {
785 delete projprf;
55a288e5 786 }
55a288e5 787 } // Boucle object
3a0f6479 788 // Mean Statistic
55a288e5 789 if (fNumberFit > 0) {
790 AliInfo(Form("There are %d with at least one entries.",fNumberEnt));
791 AliInfo(Form("%d fits have been proceeded (sucessfully or not...).",fNumberFit));
792 AliInfo(Form("There is a mean statistic of: %d over these fitted histograms and %d successfulled fits"
793 ,(Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
794 fStatisticMean = fStatisticMean / fNumberFit;
795 }
796 else {
797 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
798 }
3a0f6479 799 delete fDebugStreamer;
800 fDebugStreamer = 0x0;
55a288e5 801 return kTRUE;
55a288e5 802}
55a288e5 803//____________Functions fit Online PRF2d_______________________________________
3a0f6479 804Bool_t AliTRDCalibraFit::AnalysePRFMarianFit(TProfile2D *prf)
55a288e5 805{
806 //
807 // Take the 1D profiles (pad response function), projections of the 2D PRF
808 // on the Xaxis, for each calibration group
809 // Fit with a gaussian to reconstruct the sigma of the pad response function
55a288e5 810 //
811
3a0f6479 812 // Set the calibration mode
813 const char *name = prf->GetTitle();
814 SetModeCalibration(name,2);
55a288e5 815
3a0f6479 816 // Number of Ybins (detectors or groups of pads)
55a288e5 817 TAxis *xprf = prf->GetXaxis();
818 TAxis *yprf = prf->GetYaxis();
3a0f6479 819 Int_t nybins = yprf->GetNbins();// calibration groups
820 Int_t nbins = xprf->GetNbins();// bins
821 Float_t lowedge = (Float_t) xprf->GetBinLowEdge(1);//lowedge in bins
822 Float_t upedge = (Float_t) xprf->GetBinUpEdge(nbins);//upedge in bins
823 Int_t nbg = GetNumberOfGroupsPRF((const char *)name);
824 if(nbg == -1) return kFALSE;
825 if(nbg > 0) fMethod = 1;
826 else fMethod = 0;
827 if (!InitFit(nybins,2)) {
828 return kFALSE;
829 }
830 if (!InitFitPRF()) {
55a288e5 831 return kFALSE;
832 }
833 fStatisticMean = 0.0;
834 fNumberFit = 0;
835 fNumberFitSuccess = 0;
836 fNumberEnt = 0;
55a288e5 837 // Init fCountDet and fCount
838 InitfCountDetAndfCount(2);
55a288e5 839 // Beginning of the loop
3a0f6479 840 for (Int_t idect = fDect1; idect < fDect2; idect++) {
841 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi.......
842 UpdatefCountDetAndfCount(idect,2);
843 ReconstructFitRowMinRowMax(idect,2);
844 // Build the array of entries and sum
845 TArrayD arraye = TArrayD(nbins);
846 TArrayD arraym = TArrayD(nbins);
847 TArrayD arrayme = TArrayD(nbins);
55a288e5 848 Double_t nentries = 0;
3a0f6479 849 //printf("nbins %d\n",nbins);
850 for (Int_t k = 0; k < nbins; k++) {
851 Int_t binnb = (nbins+2)*(idect+1)+(k+1);
852 Double_t entries = (Double_t)prf->GetBinEntries(binnb);
853 Double_t mean = (Double_t)prf->GetBinContent(binnb);
854 Double_t error = (Double_t)prf->GetBinError(binnb);
855 //printf("for %d we have %f\n",k,entries);
856 nentries += entries;
857 arraye.AddAt(entries,k);
858 arraym.AddAt(mean,k);
859 arrayme.AddAt(error,k);
55a288e5 860 }
861 if(nentries > 0) fNumberEnt++;
3a0f6479 862 //printf("The number of entries for the group %d is %f\n",idect,nentries);
55a288e5 863 // This detector has not enough statistics or was off
3a0f6479 864 if (nentries <= fMinEntries) {
865 NotEnoughStatisticPRF(idect);
55a288e5 866 continue;
55a288e5 867 }
55a288e5 868 // Statistics of the histos fitted
55a288e5 869 fNumberFit++;
870 fStatisticMean += nentries;
55a288e5 871 // Calcul of "real" coef
3a0f6479 872 CalculPRFCoefMean();
873 //Method choosen
874 switch(fMethod)
875 {
876 case 0: FitPRFGausMI( arraye.GetArray(), arraym.GetArray(), arrayme.GetArray(), nbins, lowedge, upedge); break;
877 case 1: FitTnpRange( arraye.GetArray(), arraym.GetArray(), arrayme.GetArray(), nbg, nbins); break;
878 default: return kFALSE;
879 }
55a288e5 880 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 881 FillInfosFitPRF(idect);
55a288e5 882 } // Boucle object
55a288e5 883 // Mean Statistic
884 if (fNumberFit > 0) {
885 AliInfo(Form("There are %d with at least one entries.",fNumberEnt));
886 AliInfo(Form("%d fits have been proceeded (sucessfully or not...).",fNumberFit));
887 AliInfo(Form("There is a mean statistic of: %d over these fitted histograms and %d successfulled fits"
888 ,(Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
889 fStatisticMean = fStatisticMean / fNumberFit;
890 }
891 else {
892 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
893 }
3a0f6479 894 delete fDebugStreamer;
895 fDebugStreamer = 0x0;
55a288e5 896 return kTRUE;
55a288e5 897}
55a288e5 898//____________Functions fit Online PRF2d_______________________________________
3a0f6479 899Bool_t AliTRDCalibraFit::AnalysePRF(AliTRDCalibraVector *calvect)
55a288e5 900{
901 //
902 // Reconstruct the 1D histo (pad response function) from the vectorPRD for
903 // each calibration group
904 // Fit with a gaussian to reconstruct the sigma of the pad response function
55a288e5 905 //
906
3a0f6479 907 // Set the calibra mode
908 const char *name = calvect->GetNamePRF();
909 SetModeCalibration(name,2);
910 //printf("test0 %s\n",name);
55a288e5 911
3a0f6479 912 // Number of Xbins (detectors or groups of pads)
913 if (!InitFit((432*calvect->GetDetCha0(2)+108*calvect->GetDetCha2(2)),2)) {
914 //printf("test1\n");
55a288e5 915 return kFALSE;
916 }
3a0f6479 917 if (!InitFitPRF()) {
918 ///printf("test2\n");
55a288e5 919 return kFALSE;
920 }
921 fStatisticMean = 0.0;
922 fNumberFit = 0;
923 fNumberFitSuccess = 0;
924 fNumberEnt = 0;
55a288e5 925 // Init fCountDet and fCount
926 InitfCountDetAndfCount(2);
55a288e5 927 // Beginning of the loop
3a0f6479 928 for (Int_t idect = fDect1; idect < fDect2; idect++) {
929 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi........
55a288e5 930 UpdatefCountDetAndfCount(idect,2);
55a288e5 931 ReconstructFitRowMinRowMax(idect,2);
3a0f6479 932 // Take the histo
933 TH1F *projprf = 0x0;
934 fEntriesCurrent = 0;
935 Bool_t something = kTRUE;
936 if(!calvect->GetPRFEntries(fCountDet)) something = kFALSE;
937 if(something){
7bce990c 938 TString tname("PRF");
939 tname += idect;
940 projprf = CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname)));
3a0f6479 941 projprf->SetDirectory(0);
942 }
55a288e5 943 // This detector has not enough statistics or was off
3a0f6479 944 if (fEntriesCurrent <= fMinEntries) {
945 NotEnoughStatisticPRF(idect);
946 if (fDebugLevel != 1) {
947 if(projprf) delete projprf;
55a288e5 948 }
55a288e5 949 continue;
55a288e5 950 }
55a288e5 951 // Statistic of the histos fitted
55a288e5 952 fNumberFit++;
953 fStatisticMean += fEntriesCurrent;
55a288e5 954 // Calcul of "real" coef
3a0f6479 955 CalculPRFCoefMean();
956 //Method choosen
957 switch(fMethod)
958 {
959 case 1: FitPRF((TH1 *) projprf); break;
960 case 2: RmsPRF((TH1 *) projprf); break;
961 default: return kFALSE;
962 }
55a288e5 963 // Fill the tree if end of a detector or only the pointer to the branch!!!
3a0f6479 964 FillInfosFitPRF(idect);
55a288e5 965 // Memory!!!
3a0f6479 966 if (fDebugLevel != 1) {
55a288e5 967 delete projprf;
968 }
55a288e5 969 } // Boucle object
55a288e5 970 // Mean Statistics
971 if (fNumberFit > 0) {
3a0f6479 972 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 973 }
974 else {
975 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
976 }
3a0f6479 977 delete fDebugStreamer;
978 fDebugStreamer = 0x0;
55a288e5 979 return kTRUE;
55a288e5 980}
55a288e5 981//____________Functions fit Online PRF2d_______________________________________
3a0f6479 982Bool_t AliTRDCalibraFit::AnalysePRFMarianFit(AliTRDCalibraVector *calvect)
55a288e5 983{
984 //
3a0f6479 985 // Reconstruct the 1D histo (pad response function) from the vectorPRD for
986 // each calibration group
987 // Fit with a gaussian to reconstruct the sigma of the pad response function
55a288e5 988 //
989
3a0f6479 990 // Set the calibra mode
991 const char *name = calvect->GetNamePRF();
992 SetModeCalibration(name,2);
993 //printf("test0 %s\n",name);
994 Int_t nbg = GetNumberOfGroupsPRF((const char *)name);
995 printf("test1 %d\n",nbg);
996 if(nbg == -1) return kFALSE;
997 if(nbg > 0) fMethod = 1;
998 else fMethod = 0;
999 // Number of Xbins (detectors or groups of pads)
1000 if (!InitFit((432*calvect->GetDetCha0(2)+108*calvect->GetDetCha2(2)),2)) {
1001 //printf("test2\n");
55a288e5 1002 return kFALSE;
1003 }
3a0f6479 1004 if (!InitFitPRF()) {
1005 //printf("test3\n");
55a288e5 1006 return kFALSE;
1007 }
1008 fStatisticMean = 0.0;
1009 fNumberFit = 0;
1010 fNumberFitSuccess = 0;
1011 fNumberEnt = 0;
3a0f6479 1012 // Variables
1013 Int_t nbins = 0;
1014 Double_t *arrayx = 0;
1015 Double_t *arraye = 0;
1016 Double_t *arraym = 0;
1017 Double_t *arrayme = 0;
1018 Float_t lowedge = 0.0;
1019 Float_t upedge = 0.0;
55a288e5 1020 // Init fCountDet and fCount
1021 InitfCountDetAndfCount(2);
55a288e5 1022 // Beginning of the loop
3a0f6479 1023 for (Int_t idect = fDect1; idect < fDect2; idect++) {
1024 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi......
55a288e5 1025 UpdatefCountDetAndfCount(idect,2);
55a288e5 1026 ReconstructFitRowMinRowMax(idect,2);
3a0f6479 1027 // Take the histo
1028 TGraphErrors *projprftree = 0x0;
1029 fEntriesCurrent = 0;
1030 Bool_t something = kTRUE;
1031 if(!calvect->GetPRFEntries(fCountDet)) something = kFALSE;
1032 if(something){
7bce990c 1033 TString tname("PRF");
1034 tname += idect;
1035 projprftree = calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname);
3a0f6479 1036 nbins = projprftree->GetN();
1037 arrayx = (Double_t *)projprftree->GetX();
1038 arraye = (Double_t *)projprftree->GetEX();
1039 arraym = (Double_t *)projprftree->GetY();
1040 arrayme = (Double_t *)projprftree->GetEY();
1041 Float_t step = arrayx[1]-arrayx[0];
1042 lowedge = arrayx[0] - step/2.0;
1043 upedge = arrayx[(nbins-1)] + step/2.0;
1044 //printf("nbins est %d\n",nbins);
1045 for(Int_t k = 0; k < nbins; k++){
1046 fEntriesCurrent += (Int_t)arraye[k];
1047 //printf("for %d we have %f, %f\n",k,arraye[k],((projprftree->GetEX())[k]));
1048 if(arraye[k]>0.0) arrayme[k] = TMath::Sqrt(TMath::Abs(arrayme[k]-arraym[k]*arraym[k])/arraye[k]);
55a288e5 1049 }
3a0f6479 1050 if(fEntriesCurrent > 0) fNumberEnt++;
1051 }
1052 //printf("The number of entries for the group %d is %d\n",idect,fEntriesCurrent);
1053 // This detector has not enough statistics or was off
1054 if (fEntriesCurrent <= fMinEntries) {
1055 NotEnoughStatisticPRF(idect);
1056 if(projprftree) delete projprftree;
55a288e5 1057 continue;
55a288e5 1058 }
3a0f6479 1059 // Statistic of the histos fitted
55a288e5 1060 fNumberFit++;
1061 fStatisticMean += fEntriesCurrent;
55a288e5 1062 // Calcul of "real" coef
3a0f6479 1063 CalculPRFCoefMean();
1064 //Method choosen
1065 switch(fMethod)
1066 {
1067 case 0: FitPRFGausMI(arraye,arraym,arrayme,nbins,lowedge,upedge); break;
1068 case 1: FitTnpRange(arraye,arraym,arrayme,nbg,nbins); break;
1069 default: return kFALSE;
1070 }
1071 // Fill the tree if end of a detector or only the pointer to the branch!!!
1072 FillInfosFitPRF(idect);
1073 // Memory!!!
1074 if (fDebugLevel != 1) {
1075 delete projprftree;
55a288e5 1076 }
3a0f6479 1077 } // Boucle object
1078 // Mean Statistics
1079 if (fNumberFit > 0) {
1080 AliInfo(Form("There are %d with at least one entries. %d fits have been proceeded (sucessfully or not...). There is a mean statistic of: %d over these fitted histograms and %d successfulled fits",fNumberEnt, fNumberFit, (Int_t) fStatisticMean/fNumberFit,fNumberFitSuccess));
1081 }
1082 else {
1083 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
1084 }
1085 delete fDebugStreamer;
1086 fDebugStreamer = 0x0;
1087 return kTRUE;
1088}
1089//____________Functions fit Online CH2d________________________________________
1090Bool_t AliTRDCalibraFit::AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli)
1091{
1092 //
1093 // The linear method
1094 //
1095
1096 fStatisticMean = 0.0;
1097 fNumberFit = 0;
1098 fNumberFitSuccess = 0;
1099 fNumberEnt = 0;
1100 if(!InitFitLinearFitter()) return kFALSE;
1101
1102
1103 for(Int_t idet = 0; idet < 540; idet++){
1104
1105
1106 //printf("detector number %d\n",idet);
1107
1108 // Take the result
1109 TVectorD param(2);
1110 TVectorD error(3);
1111 fEntriesCurrent = 0;
1112 fCountDet = idet;
1113 Bool_t here = calivdli->GetParam(idet,&param);
1114 Bool_t heree = calivdli->GetError(idet,&error);
1115 //printf("here %d and heree %d\n",here, heree);
1116 if(heree) {
1117 fEntriesCurrent = (Int_t) error[2];
1118 fNumberEnt++;
55a288e5 1119 }
3a0f6479 1120 //printf("Number of entries %d\n",fEntriesCurrent);
1121 // Nothing found or not enough statistic
1122 if((!heree) || (!here) || (fEntriesCurrent <= fMinEntries)) {
1123 NotEnoughStatisticLinearFitter();
1124 continue;
55a288e5 1125 }
3a0f6479 1126 //param.Print();
1127 //error.Print();
1128 //Statistics
1129 fNumberFit++;
1130 fStatisticMean += fEntriesCurrent;
1131
1132 // Check the fit
1133 if((-(param[1])) <= 0.0) {
1134 NotEnoughStatisticLinearFitter();
1135 continue;
55a288e5 1136 }
55a288e5 1137
3a0f6479 1138 // CalculDatabaseVdriftandTan
1139 CalculVdriftLorentzCoef();
1140
1141 // Statistics
1142 fNumberFitSuccess ++;
1143
1144 // Put the fCurrentCoef
1145 fCurrentCoef[0] = -param[1];
1146 // here the database must be the one of the reconstruction for the lorentz angle....
1147 fCurrentCoef2[0] = (param[0]+fCurrentCoef[1]*fCurrentCoef2[1])/fCurrentCoef[0];
1148 fCurrentCoefE = error[1];
1149 fCurrentCoefE2 = error[0];
1150 if((fCurrentCoef2[0] != 0.0) && (param[0] != 0.0)){
1151 fCurrentCoefE2 = (fCurrentCoefE2/param[0]+fCurrentCoefE/fCurrentCoef[0])*fCurrentCoef2[0];
1152 }
1153
1154 // Fill
1155 FillInfosFitLinearFitter();
1156
55a288e5 1157
55a288e5 1158 }
55a288e5 1159 // Mean Statistics
1160 if (fNumberFit > 0) {
3a0f6479 1161 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 1162 }
1163 else {
1164 AliInfo(Form("There are %d with at least one entries. There is no fit!",fNumberEnt));
1165 }
3a0f6479 1166 delete fDebugStreamer;
1167 fDebugStreamer = 0x0;
55a288e5 1168 return kTRUE;
1169
1170}
55a288e5 1171//____________Functions for seeing if the pad is really okey___________________
3a0f6479 1172//_____________________________________________________________________________
1173Int_t AliTRDCalibraFit::GetNumberOfGroupsPRF(const char* nametitle)
1174{
1175 //
1176 // Get numberofgroupsprf
1177 //
1178
1179 // Some patterns
1180 const Char_t *pattern0 = "Ngp0";
1181 const Char_t *pattern1 = "Ngp1";
1182 const Char_t *pattern2 = "Ngp2";
1183 const Char_t *pattern3 = "Ngp3";
1184 const Char_t *pattern4 = "Ngp4";
1185 const Char_t *pattern5 = "Ngp5";
1186 const Char_t *pattern6 = "Ngp6";
55a288e5 1187
3a0f6479 1188 // Nrphi mode
1189 if (strstr(nametitle,pattern0)) {
1190 return 0;
1191 }
1192 if (strstr(nametitle,pattern1)) {
1193 return 1;
1194 }
1195 if (strstr(nametitle,pattern2)) {
1196 return 2;
1197 }
1198 if (strstr(nametitle,pattern3)) {
1199 return 3;
1200 }
1201 if (strstr(nametitle,pattern4)) {
1202 return 4;
1203 }
1204 if (strstr(nametitle,pattern5)) {
1205 return 5;
1206 }
1207 if (strstr(nametitle,pattern6)){
1208 return 6;
1209 }
1210 else return -1;
1211
1212
1213}
55a288e5 1214//_____________________________________________________________________________
3a0f6479 1215Bool_t AliTRDCalibraFit::SetModeCalibration(const char *name, Int_t i)
55a288e5 1216{
1217 //
1218 // Set fNz[i] and fNrphi[i] of the AliTRDCalibraFit::Instance()
3a0f6479 1219 // corresponding to the given name
55a288e5 1220 //
1221
3a0f6479 1222 if(!SetNzFromTObject(name,i)) return kFALSE;
1223 if(!SetNrphiFromTObject(name,i)) return kFALSE;
1224
1225 return kTRUE;
55a288e5 1226
3a0f6479 1227}
1228//_____________________________________________________________________________
1229Bool_t AliTRDCalibraFit::SetNrphiFromTObject(const char *name, Int_t i)
1230{
1231 //
1232 // Set fNrphi[i] of the AliTRDCalibraFit::Instance()
1233 // corresponding to the given TObject
1234 //
1235
55a288e5 1236 // Some patterns
55a288e5 1237 const Char_t *patternrphi0 = "Nrphi0";
1238 const Char_t *patternrphi1 = "Nrphi1";
1239 const Char_t *patternrphi2 = "Nrphi2";
1240 const Char_t *patternrphi3 = "Nrphi3";
1241 const Char_t *patternrphi4 = "Nrphi4";
1242 const Char_t *patternrphi5 = "Nrphi5";
1243 const Char_t *patternrphi6 = "Nrphi6";
1244
55a288e5 1245 // Nrphi mode
3a0f6479 1246 if (strstr(name,patternrphi0)) {
55a288e5 1247 fCalibraMode->SetNrphi(i ,0);
3a0f6479 1248 return kTRUE;
55a288e5 1249 }
3a0f6479 1250 if (strstr(name,patternrphi1)) {
55a288e5 1251 fCalibraMode->SetNrphi(i, 1);
3a0f6479 1252 return kTRUE;
55a288e5 1253 }
3a0f6479 1254 if (strstr(name,patternrphi2)) {
55a288e5 1255 fCalibraMode->SetNrphi(i, 2);
3a0f6479 1256 return kTRUE;
55a288e5 1257 }
3a0f6479 1258 if (strstr(name,patternrphi3)) {
55a288e5 1259 fCalibraMode->SetNrphi(i, 3);
3a0f6479 1260 return kTRUE;
55a288e5 1261 }
3a0f6479 1262 if (strstr(name,patternrphi4)) {
55a288e5 1263 fCalibraMode->SetNrphi(i, 4);
3a0f6479 1264 return kTRUE;
55a288e5 1265 }
3a0f6479 1266 if (strstr(name,patternrphi5)) {
55a288e5 1267 fCalibraMode->SetNrphi(i, 5);
3a0f6479 1268 return kTRUE;
55a288e5 1269 }
3a0f6479 1270 if (strstr(name,patternrphi6)) {
55a288e5 1271 fCalibraMode->SetNrphi(i, 6);
55a288e5 1272 return kTRUE;
1273 }
55a288e5 1274
3a0f6479 1275 fCalibraMode->SetNrphi(i ,0);
1276 return kFALSE;
1277
55a288e5 1278}
55a288e5 1279//_____________________________________________________________________________
3a0f6479 1280Bool_t AliTRDCalibraFit::SetNzFromTObject(const char *name, Int_t i)
55a288e5 1281{
1282 //
3a0f6479 1283 // Set fNz[i] of the AliTRDCalibraFit::Instance()
1284 // corresponding to the given TObject
55a288e5 1285 //
3a0f6479 1286
1287 // Some patterns
1288 const Char_t *patternz0 = "Nz0";
1289 const Char_t *patternz1 = "Nz1";
1290 const Char_t *patternz2 = "Nz2";
1291 const Char_t *patternz3 = "Nz3";
1292 const Char_t *patternz4 = "Nz4";
55a288e5 1293
3a0f6479 1294 if (strstr(name,patternz0)) {
1295 fCalibraMode->SetNz(i, 0);
1296 return kTRUE;
55a288e5 1297 }
3a0f6479 1298 if (strstr(name,patternz1)) {
1299 fCalibraMode->SetNz(i ,1);
1300 return kTRUE;
55a288e5 1301 }
3a0f6479 1302 if (strstr(name,patternz2)) {
1303 fCalibraMode->SetNz(i ,2);
1304 return kTRUE;
55a288e5 1305 }
3a0f6479 1306 if (strstr(name,patternz3)) {
1307 fCalibraMode->SetNz(i ,3);
1308 return kTRUE;
55a288e5 1309 }
3a0f6479 1310 if (strstr(name,patternz4)) {
1311 fCalibraMode->SetNz(i ,4);
1312 return kTRUE;
55a288e5 1313 }
3a0f6479 1314
1315 fCalibraMode->SetNz(i ,0);
1316 return kFALSE;
1317}
1318//_____________________________________________________________________________
1319AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectVdrift(TObjArray *vectorFit, Bool_t perdetector)
1320{
1321 //
1322 // It creates the AliTRDCalDet object from the AliTRDFitInfo
1323 // It takes the mean value of the coefficients per detector
1324 // This object has to be written in the database
1325 //
55a288e5 1326
3a0f6479 1327 // Create the DetObject
1328 AliTRDCalDet *object = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
1329
1330 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1331 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1332 Int_t detector = -1;
1333 Float_t value = 0.0;
1334
1335 for (Int_t k = 0; k < loop; k++) {
1336 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1337 Float_t mean = 0.0;
1338 if(perdetector){
1339 mean = TMath::Abs(((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0]);
55a288e5 1340 }
1341 else {
3a0f6479 1342 Int_t count = 0;
053767a4 1343 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1344 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
3a0f6479 1345 for (Int_t row = 0; row < rowMax; row++) {
1346 for (Int_t col = 0; col < colMax; col++) {
1347 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1348 mean += TMath::Abs(value);
1349 count++;
1350 } // Col
1351 } // Row
1352 if(count > 0) mean = mean/count;
55a288e5 1353 }
1354 object->SetValue(detector,mean);
1355 }
3a0f6479 1356
55a288e5 1357 return object;
55a288e5 1358}
55a288e5 1359//_____________________________________________________________________________
3a0f6479 1360AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectGain(TObjArray *vectorFit, Double_t scaleFitFactor, Bool_t perdetector)
55a288e5 1361{
1362 //
3a0f6479 1363 // It creates the AliTRDCalDet object from the AliTRDFitInfo
1364 // It takes the mean value of the coefficients per detector
55a288e5 1365 // This object has to be written in the database
1366 //
1367
1368 // Create the DetObject
3a0f6479 1369 AliTRDCalDet *object = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
55a288e5 1370
3a0f6479 1371
1372 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1373 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1374 Int_t detector = -1;
1375 Float_t value = 0.0;
1376
1377 for (Int_t k = 0; k < loop; k++) {
1378 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1379 Float_t mean = 0.0;
1380 if(perdetector){
1381 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
1382 if(value > 0) value = value*scaleFitFactor;
1383 mean = TMath::Abs(value);
1384 }
1385 else{
1386 Int_t count = 0;
053767a4 1387 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1388 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
3a0f6479 1389 for (Int_t row = 0; row < rowMax; row++) {
1390 for (Int_t col = 0; col < colMax; col++) {
1391 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1392 if(value > 0) value = value*scaleFitFactor;
1393 mean += TMath::Abs(value);
1394 count++;
1395 } // Col
1396 } // Row
1397 if(count > 0) mean = mean/count;
1398 }
1399 object->SetValue(detector,mean);
55a288e5 1400 }
3a0f6479 1401
1402 return object;
1403}
1404//_____________________________________________________________________________
1405AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectT0(TObjArray *vectorFit, Bool_t perdetector)
1406{
1407 //
1408 // It creates the AliTRDCalDet object from the AliTRDFitInfo2
1409 // It takes the min value of the coefficients per detector
1410 // This object has to be written in the database
1411 //
55a288e5 1412
3a0f6479 1413 // Create the DetObject
1414 AliTRDCalDet *object = new AliTRDCalDet("ChamberT0","T0 (detector value)");
55a288e5 1415
3a0f6479 1416 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1417 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1418 Int_t detector = -1;
1419 Float_t value = 0.0;
1420
1421 for (Int_t k = 0; k < loop; k++) {
1422 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1423 Float_t min = 100.0;
1424 if(perdetector){
1425 min = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
55a288e5 1426 }
3a0f6479 1427 else{
053767a4 1428 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1429 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
3a0f6479 1430 for (Int_t row = 0; row < rowMax; row++) {
1431 for (Int_t col = 0; col < colMax; col++) {
1432 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1433 if(min > value) min = value;
1434 } // Col
1435 } // Row
1436 }
1437 object->SetValue(detector,min);
55a288e5 1438 }
1439
1440 return object;
1441
1442}
55a288e5 1443//_____________________________________________________________________________
3a0f6479 1444AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectLorentzAngle(TObjArray *vectorFit)
55a288e5 1445{
1446 //
3a0f6479 1447 // It creates the AliTRDCalDet object from the AliTRDFitInfo2
1448 // It takes the min value of the coefficients per detector
55a288e5 1449 // This object has to be written in the database
1450 //
1451
1452 // Create the DetObject
3a0f6479 1453 AliTRDCalDet *object = new AliTRDCalDet("tan(lorentzangle)","tan(lorentzangle) (detector value)");
1454
1455
1456 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1457 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1458 Int_t detector = -1;
1459 Float_t value = 0.0;
55a288e5 1460
3a0f6479 1461 for (Int_t k = 0; k < loop; k++) {
1462 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1463 /*
053767a4 1464 Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
1465 Int_t colMax = fGeo->GetColMax(GetLayer(detector));
3a0f6479 1466 Float_t min = 100.0;
1467 for (Int_t row = 0; row < rowMax; row++) {
1468 for (Int_t col = 0; col < colMax; col++) {
1469 value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1470 mean += -TMath::Abs(value);
1471 count++;
55a288e5 1472 } // Col
3a0f6479 1473 } // Row
1474 if(count > 0) mean = mean/count;
1475 */
1476 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
1477 object->SetValue(detector,-TMath::Abs(value));
55a288e5 1478 }
1479
1480 return object;
3a0f6479 1481
55a288e5 1482}
55a288e5 1483//_____________________________________________________________________________
3a0f6479 1484TObject *AliTRDCalibraFit::CreatePadObjectGain(TObjArray *vectorFit, Double_t scaleFitFactor, AliTRDCalDet *detobject)
1485{
55a288e5 1486 //
3a0f6479 1487 // It Creates the AliTRDCalPad object from AliTRDFitInfo
1488 // You need first to create the object for the detectors,
1489 // where the mean value is put.
1490 // This object has to be written in the database
55a288e5 1491 //
3a0f6479 1492
1493 // Create the DetObject
1494 AliTRDCalPad *object = new AliTRDCalPad("GainFactor","GainFactor (local variations)");
1495
1496 if(!vectorFit){
1497 for(Int_t k = 0; k < 540; k++){
1498 AliTRDCalROC *calROC = object->GetCalROC(k);
1499 Int_t nchannels = calROC->GetNchannels();
1500 for(Int_t ch = 0; ch < nchannels; ch++){
1501 calROC->SetValue(ch,1.0);
1502 }
1503 }
55a288e5 1504 }
3a0f6479 1505 else{
1506
1507 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1508 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1509 Int_t detector = -1;
1510 Float_t value = 0.0;
1511
1512 for (Int_t k = 0; k < loop; k++) {
1513 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1514 AliTRDCalROC *calROC = object->GetCalROC(detector);
1515 Float_t mean = detobject->GetValue(detector);
1516 if(mean == 0) continue;
1517 Int_t rowMax = calROC->GetNrows();
1518 Int_t colMax = calROC->GetNcols();
1519 for (Int_t row = 0; row < rowMax; row++) {
1520 for (Int_t col = 0; col < colMax; col++) {
1521 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1522 if(value > 0) value = value*scaleFitFactor;
1523 calROC->SetValue(col,row,TMath::Abs(value)/mean);
1524 } // Col
1525 } // Row
1526 }
55a288e5 1527 }
1528
3a0f6479 1529 return object;
55a288e5 1530}
55a288e5 1531//_____________________________________________________________________________
3a0f6479 1532TObject *AliTRDCalibraFit::CreatePadObjectVdrift(TObjArray *vectorFit, AliTRDCalDet *detobject)
1533{
55a288e5 1534 //
3a0f6479 1535 // It Creates the AliTRDCalPad object from AliTRDFitInfo
1536 // You need first to create the object for the detectors,
1537 // where the mean value is put.
1538 // This object has to be written in the database
55a288e5 1539 //
1540
3a0f6479 1541 // Create the DetObject
1542 AliTRDCalPad *object = new AliTRDCalPad("LocalVdrift","TRD drift velocities (local variations)");
1543
1544 if(!vectorFit){
1545 for(Int_t k = 0; k < 540; k++){
1546 AliTRDCalROC *calROC = object->GetCalROC(k);
1547 Int_t nchannels = calROC->GetNchannels();
1548 for(Int_t ch = 0; ch < nchannels; ch++){
1549 calROC->SetValue(ch,1.0);
1550 }
1551 }
55a288e5 1552 }
1553 else {
3a0f6479 1554
1555 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1556 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1557 Int_t detector = -1;
1558 Float_t value = 0.0;
1559
1560 for (Int_t k = 0; k < loop; k++) {
1561 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1562 AliTRDCalROC *calROC = object->GetCalROC(detector);
1563 Float_t mean = detobject->GetValue(detector);
1564 if(mean == 0) continue;
1565 Int_t rowMax = calROC->GetNrows();
1566 Int_t colMax = calROC->GetNcols();
1567 for (Int_t row = 0; row < rowMax; row++) {
1568 for (Int_t col = 0; col < colMax; col++) {
1569 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1570 calROC->SetValue(col,row,TMath::Abs(value)/mean);
1571 } // Col
1572 } // Row
1573 }
55a288e5 1574 }
3a0f6479 1575 return object;
55a288e5 1576
1577}
55a288e5 1578//_____________________________________________________________________________
3a0f6479 1579TObject *AliTRDCalibraFit::CreatePadObjectT0(TObjArray *vectorFit, AliTRDCalDet *detobject)
1580{
55a288e5 1581 //
3a0f6479 1582 // It Creates the AliTRDCalPad object from AliTRDFitInfo2
1583 // You need first to create the object for the detectors,
1584 // where the mean value is put.
1585 // This object has to be written in the database
55a288e5 1586 //
3a0f6479 1587
1588 // Create the DetObject
1589 AliTRDCalPad *object = new AliTRDCalPad("LocalT0","T0 (local variations)");
1590
1591 if(!vectorFit){
1592 for(Int_t k = 0; k < 540; k++){
1593 AliTRDCalROC *calROC = object->GetCalROC(k);
1594 Int_t nchannels = calROC->GetNchannels();
1595 for(Int_t ch = 0; ch < nchannels; ch++){
1596 calROC->SetValue(ch,0.0);
1597 }
1598 }
55a288e5 1599 }
1600 else {
3a0f6479 1601
1602 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1603 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1604 Int_t detector = -1;
1605 Float_t value = 0.0;
1606
1607 for (Int_t k = 0; k < loop; k++) {
1608 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1609 AliTRDCalROC *calROC = object->GetCalROC(detector);
1610 Float_t min = detobject->GetValue(detector);
1611 Int_t rowMax = calROC->GetNrows();
1612 Int_t colMax = calROC->GetNcols();
1613 for (Int_t row = 0; row < rowMax; row++) {
1614 for (Int_t col = 0; col < colMax; col++) {
1615 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1616 calROC->SetValue(col,row,value-min);
1617 } // Col
1618 } // Row
1619 }
55a288e5 1620 }
3a0f6479 1621 return object;
55a288e5 1622
1623}
3a0f6479 1624//_____________________________________________________________________________
1625TObject *AliTRDCalibraFit::CreatePadObjectPRF(TObjArray *vectorFit)
1626{
1627 //
1628 // It Creates the AliTRDCalPad object from AliTRDFitInfo
1629 // This object has to be written in the database
1630 //
1631
1632 // Create the DetObject
1633 AliTRDCalPad *object = new AliTRDCalPad("PRFWidth","PRFWidth");
1634
1635 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1636 if(loop != 540) AliInfo("The Vector Fit is not complete!");
1637 Int_t detector = -1;
1638 Float_t value = 0.0;
1639
1640 for (Int_t k = 0; k < loop; k++) {
1641 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1642 AliTRDCalROC *calROC = object->GetCalROC(detector);
1643 Int_t rowMax = calROC->GetNrows();
1644 Int_t colMax = calROC->GetNcols();
1645 for (Int_t row = 0; row < rowMax; row++) {
1646 for (Int_t col = 0; col < colMax; col++) {
1647 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
1648 calROC->SetValue(col,row,TMath::Abs(value));
1649 } // Col
1650 } // Row
1651 }
55a288e5 1652
3a0f6479 1653 return object;
1654
1655}
55a288e5 1656//_____________________________________________________________________________
3a0f6479 1657AliTRDCalDet *AliTRDCalibraFit::MakeOutliersStatDet(TObjArray *vectorFit, const char *name, Double_t &mean)
1658{
1659 //
1660 // It Creates the AliTRDCalDet object from AliTRDFitInfo
1661 // 0 successful fit 1 not successful fit
1662 // mean is the mean value over the successful fit
1663 // do not use it for t0: no meaning
1664 //
1665
1666 // Create the CalObject
1667 AliTRDCalDet *object = new AliTRDCalDet(name,name);
1668 mean = 0.0;
1669 Int_t count = 0;
1670
1671 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1672 if(loop != 540) {
1673 AliInfo("The Vector Fit is not complete! We initialise all outliers");
1674 for(Int_t k = 0; k < 540; k++){
1675 object->SetValue(k,1.0);
1676 }
1677 }
1678 Int_t detector = -1;
1679 Float_t value = 0.0;
1680
1681 for (Int_t k = 0; k < loop; k++) {
1682 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1683 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
1684 if(value <= 0) object->SetValue(detector,1.0);
1685 else {
1686 object->SetValue(detector,0.0);
1687 mean += value;
1688 count++;
1689 }
1690 }
1691 if(count > 0) mean /= count;
1692 return object;
1693}
1694//_____________________________________________________________________________
1695TObject *AliTRDCalibraFit::MakeOutliersStatPad(TObjArray *vectorFit, const char *name, Double_t &mean)
1696{
1697 //
1698 // It Creates the AliTRDCalPad object from AliTRDFitInfo
1699 // 0 not successful fit 1 successful fit
1700 // mean mean value over the successful fit
1701 //
1702
1703 // Create the CalObject
1704 AliTRDCalPad *object = new AliTRDCalPad(name,name);
1705 mean = 0.0;
1706 Int_t count = 0;
1707
1708 Int_t loop = (Int_t) vectorFit->GetEntriesFast();
1709 if(loop != 540) {
1710 AliInfo("The Vector Fit is not complete! We initialise all outliers");
1711 for(Int_t k = 0; k < 540; k++){
1712 AliTRDCalROC *calROC = object->GetCalROC(k);
1713 Int_t nchannels = calROC->GetNchannels();
1714 for(Int_t ch = 0; ch < nchannels; ch++){
1715 calROC->SetValue(ch,1.0);
1716 }
1717 }
1718 }
1719 Int_t detector = -1;
1720 Float_t value = 0.0;
1721
1722 for (Int_t k = 0; k < loop; k++) {
1723 detector = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
1724 AliTRDCalROC *calROC = object->GetCalROC(detector);
1725 Int_t nchannels = calROC->GetNchannels();
1726 for (Int_t ch = 0; ch < nchannels; ch++) {
1727 value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[ch];
1728 if(value <= 0) calROC->SetValue(ch,1.0);
1729 else {
1730 calROC->SetValue(ch,0.0);
1731 mean += value;
1732 count++;
1733 }
1734 } // channels
1735 }
1736 if(count > 0) mean /= count;
1737 return object;
1738}
1739//_____________________________________________________________________________
1740void AliTRDCalibraFit::SetPeriodeFitPH(Int_t periodeFitPH)
55a288e5 1741{
1742 //
3a0f6479 1743 // Set FitPH if 1 then each detector will be fitted
55a288e5 1744 //
1745
3a0f6479 1746 if (periodeFitPH > 0) {
1747 fFitPHPeriode = periodeFitPH;
55a288e5 1748 }
1749 else {
3a0f6479 1750 AliInfo("periodeFitPH must be higher than 0!");
55a288e5 1751 }
1752
1753}
55a288e5 1754//_____________________________________________________________________________
1755void AliTRDCalibraFit::SetBeginFitCharge(Float_t beginFitCharge)
1756{
1757 //
1758 // The fit of the deposited charge distribution begins at
1759 // histo->Mean()/beginFitCharge
1760 // You can here set beginFitCharge
1761 //
1762
1763 if (beginFitCharge > 0) {
1764 fBeginFitCharge = beginFitCharge;
1765 }
1766 else {
1767 AliInfo("beginFitCharge must be strict positif!");
1768 }
1769
1770}
1771
1772//_____________________________________________________________________________
413153cb 1773void AliTRDCalibraFit::SetT0Shift0(Float_t t0Shift)
1774{
1775 //
1776 // The t0 calculated with the maximum positif slope is shift from t0Shift0
1777 // You can here set t0Shift0
1778 //
1779
1780 if (t0Shift > 0) {
1781 fT0Shift0 = t0Shift;
1782 }
1783 else {
1784 AliInfo("t0Shift0 must be strict positif!");
1785 }
1786
1787}
1788
1789//_____________________________________________________________________________
1790void AliTRDCalibraFit::SetT0Shift1(Float_t t0Shift)
55a288e5 1791{
1792 //
413153cb 1793 // The t0 calculated with the maximum of the amplification region is shift from t0Shift1
1794 // You can here set t0Shift1
55a288e5 1795 //
1796
1797 if (t0Shift > 0) {
413153cb 1798 fT0Shift1 = t0Shift;
55a288e5 1799 }
1800 else {
1801 AliInfo("t0Shift must be strict positif!");
1802 }
1803
1804}
1805
1806//_____________________________________________________________________________
1807void AliTRDCalibraFit::SetRangeFitPRF(Float_t rangeFitPRF)
1808{
1809 //
1810 // The fit of the PRF is from -rangeFitPRF to rangeFitPRF
1811 // You can here set rangeFitPRF
1812 //
1813
1814 if ((rangeFitPRF > 0) &&
1815 (rangeFitPRF <= 1.5)) {
1816 fRangeFitPRF = rangeFitPRF;
1817 }
1818 else {
1819 AliInfo("rangeFitPRF must be between 0 and 1.0");
1820 }
1821
1822}
1823
1824//_____________________________________________________________________________
3a0f6479 1825void AliTRDCalibraFit::SetMinEntries(Int_t minEntries)
55a288e5 1826{
1827 //
3a0f6479 1828 // Minimum entries for fitting
55a288e5 1829 //
1830
3a0f6479 1831 if (minEntries > 0) {
1832 fMinEntries = minEntries;
55a288e5 1833 }
1834 else {
3a0f6479 1835 AliInfo("fMinEntries must be >= 0.");
55a288e5 1836 }
1837
1838}
1839
55a288e5 1840//_____________________________________________________________________________
3a0f6479 1841void AliTRDCalibraFit::SetRebin(Short_t rebin)
1842{
55a288e5 1843 //
3a0f6479 1844 // Rebin with rebin time less bins the Ch histo
1845 // You can set here rebin that should divide the number of bins of CH histo
55a288e5 1846 //
55a288e5 1847
3a0f6479 1848 if (rebin > 0) {
1849 fRebin = rebin;
1850 AliInfo("You have to be sure that fRebin divides fNumberBinCharge used!");
1851 }
1852 else {
1853 AliInfo("You have to choose a positiv value!");
55a288e5 1854 }
1855
1856}
55a288e5 1857//_____________________________________________________________________________
3a0f6479 1858Bool_t AliTRDCalibraFit::FillVectorFit()
55a288e5 1859{
1860 //
3a0f6479 1861 // For the Fit functions fill the vector Fit
55a288e5 1862 //
1863
3a0f6479 1864 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
55a288e5 1865
3a0f6479 1866 Int_t ntotal = 1;
053767a4 1867 if (GetStack(fCountDet) == 2) {
3a0f6479 1868 ntotal = 1728;
55a288e5 1869 }
3a0f6479 1870 else {
1871 ntotal = 2304;
55a288e5 1872 }
1873
3a0f6479 1874 //printf("For the detector %d , ntotal %d and fCoefCH[0] %f\n",countdet,ntotal,fCoefCH[0]);
1875 Float_t *coef = new Float_t[ntotal];
1876 for (Int_t i = 0; i < ntotal; i++) {
1877 coef[i] = fCurrentCoefDetector[i];
55a288e5 1878 }
55a288e5 1879
3a0f6479 1880 Int_t detector = fCountDet;
1881 // Set
1882 fitInfo->SetCoef(coef);
1883 fitInfo->SetDetector(detector);
1884 fVectorFit.Add((TObject *) fitInfo);
55a288e5 1885
3a0f6479 1886 return kTRUE;
55a288e5 1887
55a288e5 1888}
55a288e5 1889//_____________________________________________________________________________
3a0f6479 1890Bool_t AliTRDCalibraFit::FillVectorFit2()
55a288e5 1891{
1892 //
3a0f6479 1893 // For the Fit functions fill the vector Fit
55a288e5 1894 //
1895
3a0f6479 1896 AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
55a288e5 1897
1898 Int_t ntotal = 1;
053767a4 1899 if (GetStack(fCountDet) == 2) {
55a288e5 1900 ntotal = 1728;
1901 }
1902 else {
1903 ntotal = 2304;
1904 }
1905
1906 //printf("For the detector %d , ntotal %d and fCoefCH[0] %f\n",countdet,ntotal,fCoefCH[0]);
1907 Float_t *coef = new Float_t[ntotal];
1908 for (Int_t i = 0; i < ntotal; i++) {
3a0f6479 1909 coef[i] = fCurrentCoefDetector2[i];
55a288e5 1910 }
1911
3a0f6479 1912 Int_t detector = fCountDet;
55a288e5 1913 // Set
3a0f6479 1914 fitInfo->SetCoef(coef);
1915 fitInfo->SetDetector(detector);
1916 fVectorFit2.Add((TObject *) fitInfo);
55a288e5 1917
1918 return kTRUE;
1919
1920}
55a288e5 1921//____________Functions for initialising the AliTRDCalibraFit in the code_________
1922Bool_t AliTRDCalibraFit::InitFit(Int_t nbins, Int_t i)
1923{
1924 //
3a0f6479 1925 // Init the number of expected bins and fDect1[i] fDect2[i]
55a288e5 1926 //
1927
1928 gStyle->SetPalette(1);
1929 gStyle->SetOptStat(1111);
1930 gStyle->SetPadBorderMode(0);
1931 gStyle->SetCanvasColor(10);
1932 gStyle->SetPadLeftMargin(0.13);
1933 gStyle->SetPadRightMargin(0.01);
3a0f6479 1934
55a288e5 1935 // Mode groups of pads: the total number of bins!
3a0f6479 1936 CalculNumberOfBinsExpected(i);
55a288e5 1937
3a0f6479 1938 // Quick verification that we have the good pad calibration mode!
1939 if (fNumberOfBinsExpected != nbins) {
1940 AliInfo("It doesn't correspond to the mode of pad group calibration!");
1941 return kFALSE;
55a288e5 1942 }
3a0f6479 1943
55a288e5 1944 // Security for fDebug 3 and 4
3a0f6479 1945 if ((fDebugLevel >= 3) &&
55a288e5 1946 ((fDet[0] > 5) ||
1947 (fDet[1] > 4) ||
1948 (fDet[2] > 17))) {
1949 AliInfo("This detector doesn't exit!");
1950 return kFALSE;
1951 }
1952
3a0f6479 1953 // Determine fDet1 and fDet2 and set the fNfragZ and fNfragRphi for debug 3 and 4
1954 CalculDect1Dect2(i);
55a288e5 1955
3a0f6479 1956
1957 return kTRUE;
1958}
1959//____________Functions for initialising the AliTRDCalibraFit in the code_________
1960Bool_t AliTRDCalibraFit::InitFitCH()
1961{
1962 //
1963 // Init the fVectorFitCH for normalisation
1964 // Init the histo for debugging
1965 //
55a288e5 1966
3a0f6479 1967 gDirectory = gROOT;
1968
1969 fScaleFitFactor = 0.0;
1970 fCurrentCoefDetector = new Float_t[2304];
1971 for (Int_t k = 0; k < 2304; k++) {
1972 fCurrentCoefDetector[k] = 0.0;
55a288e5 1973 }
3a0f6479 1974 fVectorFit.SetName("gainfactorscoefficients");
55a288e5 1975
3a0f6479 1976 // fDebug == 0 nothing
1977 // fDebug == 1 and fFitVoir no histo
1978 if (fDebugLevel == 1) {
1979 if(!CheckFitVoir()) return kFALSE;
1980 }
1981 //Get the CalDet object
1982 if(fAccCDB){
1983 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1984 if (!cal) {
1985 AliInfo("Could not get calibDB");
1986 return kFALSE;
55a288e5 1987 }
3a0f6479 1988 if(fCalDet) delete fCalDet;
1989 fCalDet = new AliTRDCalDet(*(cal->GetGainFactorDet()));
55a288e5 1990 }
3a0f6479 1991 else{
1992 Float_t devalue = 1.0;
1993 if(fCalDet) delete fCalDet;
1994 fCalDet = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
1995 for(Int_t k = 0; k < 540; k++){
1996 fCalDet->SetValue(k,devalue);
55a288e5 1997 }
3a0f6479 1998 }
1999 return kTRUE;
2000
2001}
2002//____________Functions for initialising the AliTRDCalibraFit in the code_________
2003Bool_t AliTRDCalibraFit::InitFitPH()
2004{
2005 //
2006 // Init the arrays of results
2007 // Init the histos for debugging
2008 //
55a288e5 2009
3a0f6479 2010 gDirectory = gROOT;
2011 fVectorFit.SetName("driftvelocitycoefficients");
2012 fVectorFit2.SetName("t0coefficients");
55a288e5 2013
3a0f6479 2014 fCurrentCoefDetector = new Float_t[2304];
2015 for (Int_t k = 0; k < 2304; k++) {
2016 fCurrentCoefDetector[k] = 0.0;
2017 }
55a288e5 2018
3a0f6479 2019 fCurrentCoefDetector2 = new Float_t[2304];
2020 for (Int_t k = 0; k < 2304; k++) {
2021 fCurrentCoefDetector2[k] = 0.0;
2022 }
2023
2024 //fDebug == 0 nothing
2025 // fDebug == 1 and fFitVoir no histo
2026 if (fDebugLevel == 1) {
2027 if(!CheckFitVoir()) return kFALSE;
2028 }
2029 //Get the CalDet object
2030 if(fAccCDB){
2031 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2032 if (!cal) {
2033 AliInfo("Could not get calibDB");
2034 return kFALSE;
55a288e5 2035 }
3a0f6479 2036 if(fCalDet) delete fCalDet;
2037 if(fCalDet2) delete fCalDet2;
2038 fCalDet = new AliTRDCalDet(*(cal->GetVdriftDet()));
2039 fCalDet2 = new AliTRDCalDet(*(cal->GetT0Det()));
2040 }
2041 else{
2042 Float_t devalue = 1.5;
2043 Float_t devalue2 = 0.0;
2044 if(fCalDet) delete fCalDet;
2045 if(fCalDet2) delete fCalDet2;
2046 fCalDet = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2047 fCalDet2 = new AliTRDCalDet("ChamberT0","T0 (detector value)");
2048 for(Int_t k = 0; k < 540; k++){
2049 fCalDet->SetValue(k,devalue);
2050 fCalDet2->SetValue(k,devalue2);
55a288e5 2051 }
55a288e5 2052 }
55a288e5 2053 return kTRUE;
3a0f6479 2054}
2055//____________Functions for initialising the AliTRDCalibraFit in the code_________
2056Bool_t AliTRDCalibraFit::InitFitPRF()
2057{
2058 //
2059 // Init the calibration mode (Nz, Nrphi), the histograms for
2060 // debugging the fit methods if fDebug > 0,
2061 //
55a288e5 2062
3a0f6479 2063 gDirectory = gROOT;
2064 fVectorFit.SetName("prfwidthcoefficients");
2065
2066 fCurrentCoefDetector = new Float_t[2304];
2067 for (Int_t k = 0; k < 2304; k++) {
2068 fCurrentCoefDetector[k] = 0.0;
2069 }
2070
2071 // fDebug == 0 nothing
2072 // fDebug == 1 and fFitVoir no histo
2073 if (fDebugLevel == 1) {
2074 if(!CheckFitVoir()) return kFALSE;
2075 }
2076 return kTRUE;
2077}
2078//____________Functions for initialising the AliTRDCalibraFit in the code_________
2079Bool_t AliTRDCalibraFit::InitFitLinearFitter()
2080{
2081 //
2082 // Init the fCalDet, fVectorFit fCurrentCoefDetector
2083 //
2084
2085 gDirectory = gROOT;
2086
2087 fCurrentCoefDetector = new Float_t[2304];
2088 fCurrentCoefDetector2 = new Float_t[2304];
2089 for (Int_t k = 0; k < 2304; k++) {
2090 fCurrentCoefDetector[k] = 0.0;
2091 fCurrentCoefDetector2[k] = 0.0;
2092 }
2093
2094 //printf("test0\n");
2095
2096 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2097 if (!cal) {
2098 AliInfo("Could not get calibDB");
2099 return kFALSE;
2100 }
2101
2102 //Get the CalDet object
2103 if(fAccCDB){
2104 if(fCalDet) delete fCalDet;
2105 if(fCalDet2) delete fCalDet2;
2106 fCalDet = new AliTRDCalDet(*(cal->GetVdriftDet()));
2107 //printf("test1\n");
2108 fCalDet2 = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
2109 //printf("test2\n");
2110 for(Int_t k = 0; k < 540; k++){
2111 fCalDet2->SetValue(k,cal->GetOmegaTau(fCalDet->GetValue(k),-fMagneticField));
2112 }
2113 //printf("test3\n");
2114 }
2115 else{
2116 Float_t devalue = 1.5;
2117 Float_t devalue2 = cal->GetOmegaTau(1.5,-fMagneticField);
2118 if(fCalDet) delete fCalDet;
2119 if(fCalDet2) delete fCalDet2;
2120 //printf("test1\n");
2121 fCalDet = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2122 fCalDet2 = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
2123 //printf("test2\n");
2124 for(Int_t k = 0; k < 540; k++){
2125 fCalDet->SetValue(k,devalue);
2126 fCalDet2->SetValue(k,devalue2);
2127 }
2128 //printf("test3\n");
2129 }
2130 return kTRUE;
55a288e5 2131}
2132
2133//____________Functions for initialising the AliTRDCalibraFit in the code_________
2134void AliTRDCalibraFit::InitfCountDetAndfCount(Int_t i)
2135{
2136 //
2137 // Init the current detector where we are fCountDet and the
2138 // next fCount for the functions Fit...
2139 //
3a0f6479 2140
55a288e5 2141 // Loop on the Xbins of ch!!
3a0f6479 2142 fCountDet = -1; // Current detector
2143 fCount = 0; // To find the next detector
55a288e5 2144
2145 // If fDebug >= 3
3a0f6479 2146 if (fDebugLevel >= 3) {
55a288e5 2147 // Set countdet to the detector
3a0f6479 2148 fCountDet = AliTRDgeometry::GetDetector(fDet[0],fDet[1],fDet[2]);
55a288e5 2149 // Set counter to write at the end of the detector
3a0f6479 2150 fCount = fDect2;
2151 // Get the right calib objects
2152 SetCalROC(i);
2153 }
2154 if(fDebugLevel == 1) {
2155 fCountDet = 0;
2156 fCalibraMode->CalculXBins(fCountDet,i);
2157 while(fCalibraMode->GetXbins(i) <=fFitVoir){
2158 fCountDet++;
2159 fCalibraMode->CalculXBins(fCountDet,i);
2160 }
2161 fCount = fCalibraMode->GetXbins(i);
2162 fCountDet--;
2163 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
053767a4 2164 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
2165 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
2166 ,(Int_t) GetStack(fCountDet)
2167 ,(Int_t) GetSector(fCountDet),i);
55a288e5 2168 }
55a288e5 2169}
3a0f6479 2170//_______________________________________________________________________________
2171void AliTRDCalibraFit::CalculNumberOfBinsExpected(Int_t i)
2172{
2173 //
2174 // Calculate the number of bins expected (calibration groups)
2175 //
2176
2177 fNumberOfBinsExpected = 0;
2178 fCalibraMode->ModePadCalibration(2,i);
2179 fCalibraMode->ModePadFragmentation(0,2,0,i);
2180 fCalibraMode->SetDetChamb2(i);
2181 if (fDebugLevel > 1) {
2182 AliInfo(Form("For the chamber 2: %d",fCalibraMode->GetDetChamb2(i)));
2183 }
2184 fNumberOfBinsExpected += 6 * 18 * fCalibraMode->GetDetChamb2(i);
2185 fCalibraMode->ModePadCalibration(0,i);
2186 fCalibraMode->ModePadFragmentation(0,0,0,i);
2187 fCalibraMode->SetDetChamb0(i);
2188 if (fDebugLevel > 1) {
2189 AliInfo(Form("For the other chamber 0: %d",fCalibraMode->GetDetChamb0(i)));
2190 }
2191 fNumberOfBinsExpected += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
2192
2193}
2194//_______________________________________________________________________________
2195void AliTRDCalibraFit::CalculDect1Dect2(Int_t i)
2196{
2197 //
2198 // Calculate the range of fits
2199 //
2200
2201 fDect1 = -1;
2202 fDect2 = -1;
2203 if (fDebugLevel == 1) {
2204 fDect1 = fFitVoir;
2205 fDect2 = fDect1 +1;
2206 }
2207 if ((fDebugLevel == 2) || (fDebugLevel == 0)) {
2208 fDect1 = 0;
2209 fDect2 = fNumberOfBinsExpected;
2210 }
2211 if (fDebugLevel >= 3) {
2212 fCountDet = AliTRDgeometry::GetDetector(fDet[0],fDet[1],fDet[2]);
2213 fCalibraMode->CalculXBins(fCountDet,i);
2214 fDect1 = fCalibraMode->GetXbins(i);
2215 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
053767a4 2216 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
2217 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
2218 ,(Int_t) GetStack(fCountDet)
2219 ,(Int_t) GetSector(fCountDet),i);
3a0f6479 2220 // Set for the next detector
2221 fDect2 = fDect1 + fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i);
2222 }
2223}
2224//_______________________________________________________________________________
2225Bool_t AliTRDCalibraFit::CheckFitVoir()
2226{
2227 //
2228 // Check if fFitVoir is in the range
2229 //
2230
2231 if (fFitVoir < fNumberOfBinsExpected) {
2232 AliInfo(Form("We will see the fit of the object %d",fFitVoir));
2233 }
2234 else {
2235 AliInfo("fFitVoir is out of range of the histo!");
2236 return kFALSE;
2237 }
2238 return kTRUE;
2239}
55a288e5 2240//____________Functions for initialising the AliTRDCalibraFit in the code_________
2241void AliTRDCalibraFit::UpdatefCountDetAndfCount(Int_t idect, Int_t i)
2242{
2243 //
2244 // See if we are in a new detector and update the
2245 // variables fNfragZ and fNfragRphi if yes
3a0f6479 2246 // Will never happen for only one detector (3 and 4)
2247 // Doesn't matter for 2
2248 //
2249 if (fCount == idect) {
2250 // On en est au detector
2251 fCountDet += 1;
2252 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
053767a4 2253 fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
2254 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
2255 ,(Int_t) GetStack(fCountDet)
2256 ,(Int_t) GetSector(fCountDet),i);
3a0f6479 2257 // Set for the next detector
2258 fCount += fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i);
2259 // calib objects
2260 SetCalROC(i);
55a288e5 2261 }
55a288e5 2262}
55a288e5 2263//____________Functions for initialising the AliTRDCalibraFit in the code_________
2264void AliTRDCalibraFit::ReconstructFitRowMinRowMax(Int_t idect, Int_t i)
2265{
2266 //
2267 // Reconstruct the min pad row, max pad row, min pad col and
2268 // max pad col of the calibration group for the Fit functions
2269 //
3a0f6479 2270 if (fDebugLevel != 1) {
2271 fCalibraMode->ReconstructionRowPadGroup((Int_t) (idect-(fCount-(fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i)))),i);
55a288e5 2272 }
55a288e5 2273}
55a288e5 2274//____________Functions for initialising the AliTRDCalibraFit in the code_________
3a0f6479 2275Bool_t AliTRDCalibraFit::NotEnoughStatisticCH(Int_t idect)
55a288e5 2276{
2277 //
2278 // For the case where there are not enough entries in the histograms
2279 // of the calibration group, the value present in the choosen database
2280 // will be put. A negativ sign enables to know that a fit was not possible.
2281 //
3a0f6479 2282
2283 if (fDebugLevel == 1) {
55a288e5 2284 AliInfo("The element has not enough statistic to be fitted");
2285 }
3a0f6479 2286
2287 else {
55a288e5 2288
3a0f6479 2289 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
2290 ,idect-(fCount-(fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))),fCountDet));
55a288e5 2291
2292 // Calcul the coef from the database choosen
3a0f6479 2293 CalculChargeCoefMean(kFALSE);
2294
053767a4 2295 //stack 2, not stack 2
3a0f6479 2296 Int_t factor = 0;
053767a4 2297 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 2298 else factor = 16;
55a288e5 2299
3a0f6479 2300 // Fill the fCurrentCoefDetector with negative value to say: not fitted
55a288e5 2301 for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
2302 for (Int_t j = fCalibraMode->GetColMin(0); j < fCalibraMode->GetColMax(0); j++) {
3a0f6479 2303 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
55a288e5 2304 }
55a288e5 2305 }
2306
3a0f6479 2307 //Put default value negative
2308 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
2309 fCurrentCoefE = 0.0;
2310
2311 FillFillCH(idect);
55a288e5 2312 }
2313
2314 return kTRUE;
55a288e5 2315}
2316
3a0f6479 2317
55a288e5 2318//____________Functions for initialising the AliTRDCalibraFit in the code_________
3a0f6479 2319Bool_t AliTRDCalibraFit::NotEnoughStatisticPH(Int_t idect)
55a288e5 2320{
2321 //
3a0f6479 2322 // For the case where there are not enough entries in the histograms
2323 // of the calibration group, the value present in the choosen database
2324 // will be put. A negativ sign enables to know that a fit was not possible.
55a288e5 2325 //
3a0f6479 2326 if (fDebugLevel == 1) {
2327 AliInfo("The element has not enough statistic to be fitted");
55a288e5 2328 }
3a0f6479 2329 else {
55a288e5 2330
3a0f6479 2331 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
2332 ,idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))),fCountDet));
55a288e5 2333
3a0f6479 2334 CalculVdriftCoefMean();
2335 CalculT0CoefMean();
2336
053767a4 2337 //stack 2 and not stack 2
3a0f6479 2338 Int_t factor = 0;
053767a4 2339 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 2340 else factor = 16;
55a288e5 2341
55a288e5 2342
3a0f6479 2343 // Fill the fCurrentCoefDetector 2
55a288e5 2344 for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
2345 for (Int_t j = fCalibraMode->GetColMin(1); j < fCalibraMode->GetColMax(1); j++) {
3a0f6479 2346 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -TMath::Abs(fCurrentCoef[1]);
2347 fCurrentCoefDetector2[(Int_t)(j*factor+k)] = fCurrentCoef2[1];
55a288e5 2348 }
55a288e5 2349 }
2350
3a0f6479 2351 // Put the default value
2352 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
2353 fCurrentCoefE = 0.0;
2354 fCurrentCoef2[0] = fCurrentCoef2[1];
2355 fCurrentCoefE2 = 0.0;
2356
2357 FillFillPH(idect);
2358
55a288e5 2359 }
3a0f6479 2360
55a288e5 2361 return kTRUE;
2362
2363}
2364
3a0f6479 2365
55a288e5 2366//____________Functions for initialising the AliTRDCalibraFit in the code_________
3a0f6479 2367Bool_t AliTRDCalibraFit::NotEnoughStatisticPRF(Int_t idect)
55a288e5 2368{
2369 //
3a0f6479 2370 // For the case where there are not enough entries in the histograms
2371 // of the calibration group, the value present in the choosen database
2372 // will be put. A negativ sign enables to know that a fit was not possible.
55a288e5 2373 //
3a0f6479 2374
2375 if (fDebugLevel == 1) {
2376 AliInfo("The element has not enough statistic to be fitted");
55a288e5 2377 }
3a0f6479 2378 else {
2379
2380 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted"
2381 ,idect-(fCount-(fCalibraMode->GetNfragZ(2)*fCalibraMode->GetNfragRphi(2))),fCountDet));
2382
2383 CalculPRFCoefMean();
2384
053767a4 2385 // stack 2 and not stack 2
3a0f6479 2386 Int_t factor = 0;
053767a4 2387 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 2388 else factor = 16;
55a288e5 2389
3a0f6479 2390
2391 // Fill the fCurrentCoefDetector
2392 for (Int_t k = fCalibraMode->GetRowMin(2); k < fCalibraMode->GetRowMax(2); k++) {
2393 for (Int_t j = fCalibraMode->GetColMin(2); j < fCalibraMode->GetColMax(2); j++) {
2394 fCurrentCoefDetector[(Int_t)(j*factor+k)] = -fCurrentCoef[1];
2395 }
55a288e5 2396 }
55a288e5 2397
3a0f6479 2398 // Put the default value
2399 fCurrentCoef[0] = -fCurrentCoef[1];
2400 fCurrentCoefE = 0.0;
2401
2402 FillFillPRF(idect);
55a288e5 2403 }
3a0f6479 2404
55a288e5 2405 return kTRUE;
2406
2407}
3a0f6479 2408//____________Functions for initialising the AliTRDCalibraFit in the code_________
2409Bool_t AliTRDCalibraFit::NotEnoughStatisticLinearFitter()
55a288e5 2410{
2411 //
3a0f6479 2412 // For the case where there are not enough entries in the histograms
2413 // of the calibration group, the value present in the choosen database
2414 // will be put. A negativ sign enables to know that a fit was not possible.
55a288e5 2415 //
3a0f6479 2416
2417 // Calcul the coef from the database choosen
2418 CalculVdriftLorentzCoef();
55a288e5 2419
3a0f6479 2420 Int_t factor = 0;
053767a4 2421 if(GetStack(fCountDet) == 2) factor = 1728;
3a0f6479 2422 else factor = 2304;
2423
2424
2425 // Fill the fCurrentCoefDetector
2426 for (Int_t k = 0; k < factor; k++) {
2427 fCurrentCoefDetector[k] = -TMath::Abs(fCurrentCoef[1]);
2428 // should be negative
2429 fCurrentCoefDetector2[k] = +TMath::Abs(fCurrentCoef2[1]);
55a288e5 2430 }
3a0f6479 2431
2432
2433 //Put default opposite sign
2434 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
2435 fCurrentCoefE = 0.0;
2436 fCurrentCoef2[0] = +TMath::Abs(fCurrentCoef2[1]);
2437 fCurrentCoefE2 = 0.0;
2438
2439 FillFillLinearFitter();
2440
2441 return kTRUE;
55a288e5 2442}
2443
3a0f6479 2444//____________Functions for initialising the AliTRDCalibraFit in the code_________
2445Bool_t AliTRDCalibraFit::FillInfosFitCH(Int_t idect)
55a288e5 2446{
2447 //
3a0f6479 2448 // Fill the coefficients found with the fits or other
2449 // methods from the Fit functions
55a288e5 2450 //
2451
3a0f6479 2452 if (fDebugLevel != 1) {
2453
2454 Int_t factor = 0;
053767a4 2455 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 2456 else factor = 16;
2457
2458 for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
2459 for (Int_t j = fCalibraMode->GetColMin(0); j < fCalibraMode->GetColMax(0); j++) {
2460 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
55a288e5 2461 }
2462 }
3a0f6479 2463
2464 FillFillCH(idect);
2465
55a288e5 2466 }
2467
3a0f6479 2468 return kTRUE;
55a288e5 2469
2470}
3a0f6479 2471//____________Functions for initialising the AliTRDCalibraFit in the code_________
2472Bool_t AliTRDCalibraFit::FillInfosFitPH(Int_t idect)
55a288e5 2473{
2474 //
3a0f6479 2475 // Fill the coefficients found with the fits or other
2476 // methods from the Fit functions
55a288e5 2477 //
2478
3a0f6479 2479 if (fDebugLevel != 1) {
55a288e5 2480
3a0f6479 2481 Int_t factor = 0;
053767a4 2482 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 2483 else factor = 16;
55a288e5 2484
3a0f6479 2485 for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
2486 for (Int_t j = fCalibraMode->GetColMin(1); j < fCalibraMode->GetColMax(1); j++) {
2487 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
2488 fCurrentCoefDetector2[(Int_t)(j*factor+k)] = fCurrentCoef2[0];
55a288e5 2489 }
3a0f6479 2490 }
2491 FillFillPH(idect);
55a288e5 2492 }
3a0f6479 2493 return kTRUE;
55a288e5 2494}
3a0f6479 2495//____________Functions for initialising the AliTRDCalibraFit in the code_________
2496Bool_t AliTRDCalibraFit::FillInfosFitPRF(Int_t idect)
55a288e5 2497{
2498 //
3a0f6479 2499 // Fill the coefficients found with the fits or other
2500 // methods from the Fit functions
55a288e5 2501 //
55a288e5 2502
3a0f6479 2503 if (fDebugLevel != 1) {
55a288e5 2504
3a0f6479 2505 Int_t factor = 0;
053767a4 2506 if(GetStack(fCountDet) == 2) factor = 12;
3a0f6479 2507 else factor = 16;
55a288e5 2508
3a0f6479 2509 // Pointer to the branch
2510 for (Int_t k = fCalibraMode->GetRowMin(2); k < fCalibraMode->GetRowMax(2); k++) {
2511 for (Int_t j = fCalibraMode->GetColMin(2); j < fCalibraMode->GetColMax(2); j++) {
2512 fCurrentCoefDetector[(Int_t)(j*factor+k)] = fCurrentCoef[0];
55a288e5 2513 }
2514 }
3a0f6479 2515 FillFillPRF(idect);
55a288e5 2516 }
2517
3a0f6479 2518 return kTRUE;
55a288e5 2519
3a0f6479 2520}
2521//____________Functions for initialising the AliTRDCalibraFit in the code_________
2522Bool_t AliTRDCalibraFit::FillInfosFitLinearFitter()
55a288e5 2523{
2524 //
3a0f6479 2525 // Fill the coefficients found with the fits or other
2526 // methods from the Fit functions
55a288e5 2527 //
55a288e5 2528
3a0f6479 2529 Int_t factor = 0;
053767a4 2530 if(GetStack(fCountDet) == 2) factor = 1728;
3a0f6479 2531 else factor = 2304;
55a288e5 2532
3a0f6479 2533 // Pointer to the branch
2534 for (Int_t k = 0; k < factor; k++) {
2535 fCurrentCoefDetector[k] = fCurrentCoef[0];
2536 fCurrentCoefDetector2[k] = fCurrentCoef2[0];
55a288e5 2537 }
55a288e5 2538
3a0f6479 2539 FillFillLinearFitter();
2540
2541 return kTRUE;
55a288e5 2542
2543}
3a0f6479 2544//________________________________________________________________________________
2545void AliTRDCalibraFit::FillFillCH(Int_t idect)
55a288e5 2546{
2547 //
3a0f6479 2548 // DebugStream and fVectorFit
55a288e5 2549 //
2550
3a0f6479 2551 // End of one detector
2552 if ((idect == (fCount-1))) {
2553 FillVectorFit();
2554 // Reset
2555 for (Int_t k = 0; k < 2304; k++) {
2556 fCurrentCoefDetector[k] = 0.0;
55a288e5 2557 }
2558 }
55a288e5 2559
3a0f6479 2560 if(fDebugLevel > 1){
55a288e5 2561
3a0f6479 2562 if ( !fDebugStreamer ) {
2563 //debug stream
2564 TDirectory *backup = gDirectory;
4aad967c 2565 fDebugStreamer = new TTreeSRedirector("TRDDebugFitCH.root");
3a0f6479 2566 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2567 }
2568
2569 Int_t detector = fCountDet;
2570 Int_t caligroup = idect;
2571 Short_t rowmin = fCalibraMode->GetRowMin(0);
2572 Short_t rowmax = fCalibraMode->GetRowMax(0);
2573 Short_t colmin = fCalibraMode->GetColMin(0);
2574 Short_t colmax = fCalibraMode->GetColMax(0);
2575 Float_t gf = fCurrentCoef[0];
2576 Float_t gfs = fCurrentCoef[1];
2577 Float_t gfE = fCurrentCoefE;
2578
413153cb 2579 (*fDebugStreamer) << "FillFillCH" <<
3a0f6479 2580 "detector=" << detector <<
2581 "caligroup=" << caligroup <<
2582 "rowmin=" << rowmin <<
2583 "rowmax=" << rowmax <<
2584 "colmin=" << colmin <<
2585 "colmax=" << colmax <<
2586 "gf=" << gf <<
2587 "gfs=" << gfs <<
2588 "gfE=" << gfE <<
2589 "\n";
55a288e5 2590
55a288e5 2591 }
2592}
3a0f6479 2593//________________________________________________________________________________
2594void AliTRDCalibraFit::FillFillPH(Int_t idect)
55a288e5 2595{
2596 //
3a0f6479 2597 // DebugStream and fVectorFit and fVectorFit2
55a288e5 2598 //
3a0f6479 2599
2600 // End of one detector
2601 if ((idect == (fCount-1))) {
2602 FillVectorFit();
2603 FillVectorFit2();
2604 // Reset
2605 for (Int_t k = 0; k < 2304; k++) {
2606 fCurrentCoefDetector[k] = 0.0;
2607 fCurrentCoefDetector2[k] = 0.0;
2608 }
55a288e5 2609 }
55a288e5 2610
3a0f6479 2611 if(fDebugLevel > 1){
55a288e5 2612
3a0f6479 2613 if ( !fDebugStreamer ) {
2614 //debug stream
2615 TDirectory *backup = gDirectory;
4aad967c 2616 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPH.root");
3a0f6479 2617 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2618 }
2619
2620
2621 Int_t detector = fCountDet;
2622 Int_t caligroup = idect;
2623 Short_t rowmin = fCalibraMode->GetRowMin(1);
2624 Short_t rowmax = fCalibraMode->GetRowMax(1);
2625 Short_t colmin = fCalibraMode->GetColMin(1);
2626 Short_t colmax = fCalibraMode->GetColMax(1);
2627 Float_t vf = fCurrentCoef[0];
2628 Float_t vs = fCurrentCoef[1];
2629 Float_t vfE = fCurrentCoefE;
2630 Float_t t0f = fCurrentCoef2[0];
2631 Float_t t0s = fCurrentCoef2[1];
2632 Float_t t0E = fCurrentCoefE2;
2633
55a288e5 2634
55a288e5 2635
413153cb 2636 (* fDebugStreamer) << "FillFillPH"<<
3a0f6479 2637 "detector="<<detector<<
2638 "caligroup="<<caligroup<<
2639 "rowmin="<<rowmin<<
2640 "rowmax="<<rowmax<<
2641 "colmin="<<colmin<<
2642 "colmax="<<colmax<<
2643 "vf="<<vf<<
2644 "vs="<<vs<<
2645 "vfE="<<vfE<<
2646 "t0f="<<t0f<<
2647 "t0s="<<t0s<<
2648 "t0E="<<t0E<<
2649 "\n";
2650 }
55a288e5 2651
2652}
3a0f6479 2653//________________________________________________________________________________
2654void AliTRDCalibraFit::FillFillPRF(Int_t idect)
55a288e5 2655{
2656 //
3a0f6479 2657 // DebugStream and fVectorFit
55a288e5 2658 //
2659
3a0f6479 2660 // End of one detector
2661 if ((idect == (fCount-1))) {
2662 FillVectorFit();
2663 // Reset
2664 for (Int_t k = 0; k < 2304; k++) {
2665 fCurrentCoefDetector[k] = 0.0;
2666 }
2667 }
55a288e5 2668
3a0f6479 2669
2670 if(fDebugLevel > 1){
2671
2672 if ( !fDebugStreamer ) {
2673 //debug stream
2674 TDirectory *backup = gDirectory;
4aad967c 2675 fDebugStreamer = new TTreeSRedirector("TRDDebugFitPRF.root");
3a0f6479 2676 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2677 }
2678
2679 Int_t detector = fCountDet;
053767a4 2680 Int_t layer = GetLayer(fCountDet);
3a0f6479 2681 Int_t caligroup = idect;
2682 Short_t rowmin = fCalibraMode->GetRowMin(2);
2683 Short_t rowmax = fCalibraMode->GetRowMax(2);
2684 Short_t colmin = fCalibraMode->GetColMin(2);
2685 Short_t colmax = fCalibraMode->GetColMax(2);
2686 Float_t widf = fCurrentCoef[0];
2687 Float_t wids = fCurrentCoef[1];
2688 Float_t widfE = fCurrentCoefE;
2689
413153cb 2690 (* fDebugStreamer) << "FillFillPRF"<<
3a0f6479 2691 "detector="<<detector<<
053767a4 2692 "layer="<<layer<<
3a0f6479 2693 "caligroup="<<caligroup<<
2694 "rowmin="<<rowmin<<
2695 "rowmax="<<rowmax<<
2696 "colmin="<<colmin<<
2697 "colmax="<<colmax<<
2698 "widf="<<widf<<
2699 "wids="<<wids<<
2700 "widfE="<<widfE<<
2701 "\n";
2702 }
55a288e5 2703
3a0f6479 2704}
2705//________________________________________________________________________________
2706void AliTRDCalibraFit::FillFillLinearFitter()
55a288e5 2707{
2708 //
3a0f6479 2709 // DebugStream and fVectorFit
55a288e5 2710 //
2711
3a0f6479 2712 // End of one detector
2713 FillVectorFit();
2714 FillVectorFit2();
2715
2716
2717 // Reset
2718 for (Int_t k = 0; k < 2304; k++) {
2719 fCurrentCoefDetector[k] = 0.0;
2720 fCurrentCoefDetector2[k] = 0.0;
55a288e5 2721 }
3a0f6479 2722
55a288e5 2723
3a0f6479 2724 if(fDebugLevel > 1){
55a288e5 2725
3a0f6479 2726 if ( !fDebugStreamer ) {
2727 //debug stream
2728 TDirectory *backup = gDirectory;
4aad967c 2729 fDebugStreamer = new TTreeSRedirector("TRDDebugFitLinearFitter.root");
3a0f6479 2730 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2731 }
2732
2733 //Debug: comparaison of the different methods (okey for first time but not for iterative procedure)
053767a4 2734 AliTRDpadPlane *padplane = fGeo->GetPadPlane(GetLayer(fCountDet),GetStack(fCountDet));
3a0f6479 2735 Float_t rowmd = (padplane->GetRow0()+padplane->GetRowEnd())/2.;
053767a4 2736 Float_t r = AliTRDgeometry::GetTime0(GetLayer(fCountDet));
3a0f6479 2737 Float_t tiltangle = padplane->GetTiltingAngle();
2738 Int_t detector = fCountDet;
053767a4 2739 Int_t stack = GetStack(fCountDet);
2740 Int_t layer = GetLayer(fCountDet);
3a0f6479 2741 Float_t vf = fCurrentCoef[0];
2742 Float_t vs = fCurrentCoef[1];
2743 Float_t vfE = fCurrentCoefE;
2744 Float_t lorentzangler = fCurrentCoef2[0];
e6381f8e 2745 Float_t elorentzangler = fCurrentCoefE2;
3a0f6479 2746 Float_t lorentzangles = fCurrentCoef2[1];
2747
413153cb 2748 (* fDebugStreamer) << "FillFillLinearFitter"<<
3a0f6479 2749 "detector="<<detector<<
053767a4 2750 "stack="<<stack<<
2751 "layer="<<layer<<
3a0f6479 2752 "rowmd="<<rowmd<<
2753 "r="<<r<<
2754 "tiltangle="<<tiltangle<<
2755 "vf="<<vf<<
2756 "vs="<<vs<<
2757 "vfE="<<vfE<<
2758 "lorentzangler="<<lorentzangler<<
e6381f8e 2759 "Elorentzangler="<<elorentzangler<<
3a0f6479 2760 "lorentzangles="<<lorentzangles<<
2761 "\n";
55a288e5 2762 }
3a0f6479 2763
55a288e5 2764}
55a288e5 2765//
2766//____________Calcul Coef Mean_________________________________________________
2767//
55a288e5 2768//_____________________________________________________________________________
3a0f6479 2769Bool_t AliTRDCalibraFit::CalculT0CoefMean()
55a288e5 2770{
2771 //
2772 // For the detector Dect calcul the mean time 0
2773 // for the calibration group idect from the choosen database
2774 //
2775
3a0f6479 2776 fCurrentCoef2[1] = 0.0;
2777 if(fDebugLevel != 1){
2778 if((fCalibraMode->GetNz(1) > 0) ||
2779 (fCalibraMode->GetNrphi(1) > 0)) {
2780 for (Int_t row = fCalibraMode->GetRowMin(1); row < fCalibraMode->GetRowMax(1); row++) {
2781 for (Int_t col = fCalibraMode->GetColMin(1); col < fCalibraMode->GetColMax(1); col++) {
2782 fCurrentCoef2[1] += (Float_t) (fCalROC2->GetValue(col,row)+fCalDet2->GetValue(fCountDet));
55a288e5 2783 }
2784 }
3a0f6479 2785 fCurrentCoef2[1] = fCurrentCoef2[1] / ((fCalibraMode->GetColMax(1)-fCalibraMode->GetColMin(1))*(fCalibraMode->GetRowMax(1)-fCalibraMode->GetRowMin(1)));
55a288e5 2786 }
3a0f6479 2787 else {
2788 if(!fAccCDB){
2789 fCurrentCoef2[1] = fCalDet2->GetValue(fCountDet);
2790 }
2791 else{
053767a4 2792 for(Int_t row = 0; row < fGeo->GetRowMax(GetLayer(fCountDet),GetStack(fCountDet),GetSector(fCountDet)); row++){
2793 for(Int_t col = 0; col < fGeo->GetColMax(GetLayer(fCountDet)); col++){
3a0f6479 2794 fCurrentCoef2[1] += (Float_t) (fCalROC2->GetValue(col,row)+fCalDet2->GetValue(fCountDet));
2795 }
2796 }
053767a4 2797 fCurrentCoef2[1] = fCurrentCoef2[1] / ((fGeo->GetRowMax(GetLayer(fCountDet),GetStack(fCountDet),GetSector(fCountDet)))*(fGeo->GetColMax(GetLayer(fCountDet))));
3a0f6479 2798 }
55a288e5 2799 }
55a288e5 2800 }
55a288e5 2801 return kTRUE;
55a288e5 2802}
2803
2804//_____________________________________________________________________________
3a0f6479 2805Bool_t AliTRDCalibraFit::CalculChargeCoefMean(Bool_t vrai)
55a288e5 2806{
2807 //
2808 // For the detector Dect calcul the mean gain factor
2809 // for the calibration group idect from the choosen database
2810 //
2811
3a0f6479 2812 fCurrentCoef[1] = 0.0;
2813 if(fDebugLevel != 1){
2814 if ((fCalibraMode->GetNz(0) > 0) ||
2815 (fCalibraMode->GetNrphi(0) > 0)) {
2816 for (Int_t row = fCalibraMode->GetRowMin(0); row < fCalibraMode->GetRowMax(0); row++) {
2817 for (Int_t col = fCalibraMode->GetColMin(0); col < fCalibraMode->GetColMax(0); col++) {
2818 fCurrentCoef[1] += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
2819 if (vrai) fScaleFitFactor += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
55a288e5 2820 }
2821 }
3a0f6479 2822 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(0)-fCalibraMode->GetColMin(0))*(fCalibraMode->GetRowMax(0)-fCalibraMode->GetRowMin(0)));
55a288e5 2823 }
3a0f6479 2824 else {
2825 //Per detectors
2826 fCurrentCoef[1] = (Float_t) fCalDet->GetValue(fCountDet);
2827 if (vrai) fScaleFitFactor += ((Float_t) fCalDet->GetValue(fCountDet))*(fCalibraMode->GetColMax(0)-fCalibraMode->GetColMin(0))*(fCalibraMode->GetRowMax(0)-fCalibraMode->GetRowMin(0));
2828 }
55a288e5 2829 }
55a288e5 2830 return kTRUE;
55a288e5 2831}
55a288e5 2832//_____________________________________________________________________________
3a0f6479 2833Bool_t AliTRDCalibraFit::CalculPRFCoefMean()
55a288e5 2834{
2835 //
2836 // For the detector Dect calcul the mean sigma of pad response
2837 // function for the calibration group idect from the choosen database
2838 //
3a0f6479 2839
2840 fCurrentCoef[1] = 0.0;
2841 if(fDebugLevel != 1){
55a288e5 2842 for (Int_t row = fCalibraMode->GetRowMin(2); row < fCalibraMode->GetRowMax(2); row++) {
2843 for (Int_t col = fCalibraMode->GetColMin(2); col < fCalibraMode->GetColMax(2); col++) {
3a0f6479 2844 fCurrentCoef[1] += (Float_t) fCalROC->GetValue(col,row);
55a288e5 2845 }
2846 }
3a0f6479 2847 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(2)-fCalibraMode->GetColMin(2))*(fCalibraMode->GetRowMax(2)-fCalibraMode->GetRowMin(2)));
55a288e5 2848 }
55a288e5 2849 return kTRUE;
55a288e5 2850}
55a288e5 2851//_____________________________________________________________________________
3a0f6479 2852Bool_t AliTRDCalibraFit::CalculVdriftCoefMean()
55a288e5 2853{
2854 //
2855 // For the detector dect calcul the mean drift velocity for the
2856 // calibration group idect from the choosen database
2857 //
2858
3a0f6479 2859 fCurrentCoef[1] = 0.0;
2860 if(fDebugLevel != 1){
2861 if ((fCalibraMode->GetNz(1) > 0) ||
2862 (fCalibraMode->GetNrphi(1) > 0)) {
2863 for (Int_t row = fCalibraMode->GetRowMin(1); row < fCalibraMode->GetRowMax(1); row++) {
2864 for (Int_t col = fCalibraMode->GetColMin(1); col < fCalibraMode->GetColMax(1); col++) {
2865 fCurrentCoef[1] += (Float_t) (fCalROC->GetValue(col,row)*fCalDet->GetValue(fCountDet));
55a288e5 2866 }
2867 }
3a0f6479 2868 fCurrentCoef[1] = fCurrentCoef[1] / ((fCalibraMode->GetColMax(1)-fCalibraMode->GetColMin(1))*(fCalibraMode->GetRowMax(1)-fCalibraMode->GetRowMin(1)));
55a288e5 2869 }
3a0f6479 2870 else {
2871 //per detectors
2872 fCurrentCoef[1] = (Float_t) fCalDet->GetValue(fCountDet);
2873 }
55a288e5 2874 }
55a288e5 2875 return kTRUE;
55a288e5 2876}
3a0f6479 2877//_____________________________________________________________________________
2878Bool_t AliTRDCalibraFit::CalculVdriftLorentzCoef()
2879{
2880 //
2881 // For the detector fCountDet, mean drift velocity and tan lorentzangle
2882 //
55a288e5 2883
3a0f6479 2884 fCurrentCoef[1] = fCalDet->GetValue(fCountDet);
2885 fCurrentCoef2[1] = fCalDet2->GetValue(fCountDet);
2886
2887 return kTRUE;
2888}
55a288e5 2889//_____________________________________________________________________________
053767a4 2890Float_t AliTRDCalibraFit::GetPRFDefault(Int_t layer) const
55a288e5 2891{
2892 //
2893 // Default width of the PRF if there is no database as reference
2894 //
053767a4 2895 switch(layer)
3a0f6479 2896 {
2897 // default database
2898 //case 0: return 0.515;
2899 //case 1: return 0.502;
2900 //case 2: return 0.491;
2901 //case 3: return 0.481;
2902 //case 4: return 0.471;
2903 //case 5: return 0.463;
2904 //default: return 0.0;
2905
2906 // fit database
2907 case 0: return 0.538429;
2908 case 1: return 0.524302;
2909 case 2: return 0.511591;
2910 case 3: return 0.500140;
2911 case 4: return 0.489821;
2912 case 5: return 0.480524;
2913 default: return 0.0;
55a288e5 2914 }
3a0f6479 2915}
2916//________________________________________________________________________________
2917void AliTRDCalibraFit::SetCalROC(Int_t i)
2918{
2919 //
2920 // Set the calib object for fCountDet
2921 //
2922
2923 Float_t value = 0.0;
2924
2925 //Get the CalDet object
2926 if(fAccCDB){
2927 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2928 if (!cal) {
2929 AliInfo("Could not get calibDB");
2930 return;
2931 }
2932 switch (i)
2933 {
2934 case 0:
2935 if(fCalROC) delete fCalROC;
2936 fCalROC = new AliTRDCalROC(*(cal->GetGainFactorROC(fCountDet)));
2937 break;
2938 case 1:
2939 if(fCalROC) delete fCalROC;
2940 if(fCalROC2) delete fCalROC2;
2941 fCalROC = new AliTRDCalROC(*(cal->GetVdriftROC(fCountDet)));
2942 fCalROC2 = new AliTRDCalROC(*(cal->GetT0ROC(fCountDet)));
2943 break;
2944 case 2:
2945 if(fCalROC) delete fCalROC;
2946 fCalROC = new AliTRDCalROC(*(cal->GetPRFROC(fCountDet))); break;
2947 default: return;
2948 }
55a288e5 2949 }
3a0f6479 2950 else{
2951 switch (i)
2952 {
2953 case 0:
2954 if(fCalROC) delete fCalROC;
053767a4 2955 fCalROC = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
3a0f6479 2956 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
2957 fCalROC->SetValue(k,1.0);
2958 }
2959 break;
2960 case 1:
2961 if(fCalROC) delete fCalROC;
2962 if(fCalROC2) delete fCalROC2;
053767a4 2963 fCalROC = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
2964 fCalROC2 = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
3a0f6479 2965 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
2966 fCalROC->SetValue(k,1.0);
2967 fCalROC2->SetValue(k,0.0);
2968 }
2969 break;
2970 case 2:
2971 if(fCalROC) delete fCalROC;
053767a4 2972 value = GetPRFDefault(GetLayer(fCountDet));
2973 fCalROC = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
3a0f6479 2974 for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
2975 fCalROC->SetValue(k,value);
2976 }
2977 break;
2978 default: return;
2979 }
55a288e5 2980 }
2981
2982}
55a288e5 2983//____________Fit Methods______________________________________________________
2984
2985//_____________________________________________________________________________
3a0f6479 2986void AliTRDCalibraFit::FitPente(TH1* projPH)
55a288e5 2987{
2988 //
2989 // Slope methode for the drift velocity
2990 //
2991
2992 // Constants
2993 const Float_t kDrWidth = AliTRDgeometry::DrThick();
3a0f6479 2994 Int_t binmax = 0;
2995 Int_t binmin = 0;
2996 fPhd[0] = 0.0;
2997 fPhd[1] = 0.0;
2998 fPhd[2] = 0.0;
2999 Int_t ju = 0;
3000 fCurrentCoefE = 0.0;
3001 fCurrentCoefE2 = 0.0;
3002 fCurrentCoef[0] = 0.0;
3003 fCurrentCoef2[0] = 0.0;
3004 TLine *line = new TLine();
55a288e5 3005
3006 // Some variables
3007 TAxis *xpph = projPH->GetXaxis();
3008 Int_t nbins = xpph->GetNbins();
3009 Double_t lowedge = xpph->GetBinLowEdge(1);
3010 Double_t upedge = xpph->GetBinUpEdge(xpph->GetNbins());
3011 Double_t widbins = (upedge - lowedge) / nbins;
3012 Double_t limit = upedge + 0.5 * widbins;
3013 Bool_t put = kTRUE;
3014
3015 // Beginning of the signal
3016 TH1D *pentea = new TH1D("pentea","pentea",projPH->GetNbinsX(),0,(Float_t) limit);
3017 for (Int_t k = 1; k < projPH->GetNbinsX(); k++) {
3018 pentea->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
3019 }
55a288e5 3020 binmax = (Int_t) pentea->GetMaximumBin();
55a288e5 3021 if (binmax <= 1) {
3022 binmax = 2;
3023 AliInfo("Put the binmax from 1 to 2 to enable the fit");
3024 }
3025 if (binmax >= nbins) {
3026 binmax = nbins-1;
3027 put = kFALSE;
3028 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
3029 }
3030 pentea->Fit("pol2","0MR","",TMath::Max(pentea->GetBinCenter(binmax-1),0.0),pentea->GetBinCenter(binmax+1));
3031 Float_t l3P1am = pentea->GetFunction("pol2")->GetParameter(1);
3032 Float_t l3P2am = pentea->GetFunction("pol2")->GetParameter(2);
3033 Float_t l3P1amE = pentea->GetFunction("pol2")->GetParError(1);
3034 Float_t l3P2amE = pentea->GetFunction("pol2")->GetParError(2);
3035 if (l3P2am != 0) {
3036 fPhd[0] = -(l3P1am / (2 * l3P2am));
3037 }
3038 if(!fTakeTheMaxPH){
3039 if((l3P1am != 0.0) && (l3P2am != 0.0)){
3a0f6479 3040 fCurrentCoefE2 = (l3P1amE/l3P1am + l3P2amE/l3P2am)*fPhd[0];
55a288e5 3041 }
3042 }
55a288e5 3043 // Amplification region
3044 binmax = 0;
3045 ju = 0;
3046 for (Int_t kbin = 1; kbin < projPH->GetNbinsX(); kbin ++) {
3a0f6479 3047 if (((projPH->GetBinContent(kbin+1) - projPH->GetBinContent(kbin)) <= 0.0) && (ju == 0) && (kbin > (fPhd[0]/widbins))) {
55a288e5 3048 binmax = kbin;
3049 ju = 1;
3050 }
3051 }
55a288e5 3052 if (binmax <= 1) {
3053 binmax = 2;
3054 AliInfo("Put the binmax from 1 to 2 to enable the fit");
3055 }
3056 if (binmax >= nbins) {
3057 binmax = nbins-1;
3058 put = kFALSE;
3059 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
3060 }
3061 projPH->Fit("pol2","0MR","",TMath::Max(projPH->GetBinCenter(binmax-1),0.0),projPH->GetBinCenter(binmax+1));
3062 Float_t l3P1amf = projPH->GetFunction("pol2")->GetParameter(1);
3063 Float_t l3P2amf = projPH->GetFunction("pol2")->GetParameter(2);
3064 Float_t l3P1amfE = projPH->GetFunction("pol2")->GetParError(1);
3065 Float_t l3P2amfE = projPH->GetFunction("pol2")->GetParError(2);
55a288e5 3066 if (l3P2amf != 0) {
3067 fPhd[1] = -(l3P1amf / (2 * l3P2amf));
3068 }
3069 if((l3P1amf != 0.0) && (l3P2amf != 0.0)){
3a0f6479 3070 fCurrentCoefE = (l3P1amfE/l3P1amf + l3P2amfE/l3P2amf)*fPhd[1];
55a288e5 3071 }
3072 if(fTakeTheMaxPH){
3a0f6479 3073 fCurrentCoefE2 = fCurrentCoefE;
55a288e5 3074 }
55a288e5 3075 // Drift region
3076 TH1D *pente = new TH1D("pente","pente",projPH->GetNbinsX(),0,(Float_t) limit);
3077 for (Int_t k = TMath::Min(binmax+4,projPH->GetNbinsX()); k < projPH->GetNbinsX(); k++) {
3078 pente->SetBinContent(k,(Double_t) (projPH->GetBinContent(k+1) - projPH->GetBinContent(k)));
3079 }
3080 binmin = 0;
3081 if(pente->GetEntries() > 0) binmin = (Int_t) pente->GetMinimumBin();
3082 if (binmin <= 1) {
3083 binmin = 2;
3084 AliInfo("Put the binmax from 1 to 2 to enable the fit");
3085 }
3086 if (binmin >= nbins) {
3087 binmin = nbins-1;
3088 put = kFALSE;
3089 AliInfo("Put the binmax from nbins-1 to nbins-2 to enable the fit");
3090 }
55a288e5 3091 pente->Fit("pol2"
3092 ,"0MR"
3093 ,""
3094 ,TMath::Max(pente->GetBinCenter(binmin-1), 0.0)
3095 ,TMath::Min(pente->GetBinCenter(binmin+1),(Double_t) limit));
3096 Float_t l3P1dr = pente->GetFunction("pol2")->GetParameter(1);
3097 Float_t l3P2dr = pente->GetFunction("pol2")->GetParameter(2);
3098 Float_t l3P1drE = pente->GetFunction("pol2")->GetParError(1);
3099 Float_t l3P2drE = pente->GetFunction("pol2")->GetParError(2);
3100 if (l3P2dr != 0) {
3101 fPhd[2] = -(l3P1dr / (2 * l3P2dr));
3102 }
3103 if((l3P1dr != 0.0) && (l3P2dr != 0.0)){
3a0f6479 3104 fCurrentCoefE += (l3P1drE/l3P1dr + l3P2drE/l3P2dr)*fPhd[2];
55a288e5 3105 }
413153cb 3106 Float_t fPhdt0 = 0.0;
3107 Float_t t0Shift = 0.0;
3108 if(fTakeTheMaxPH) {
3109 fPhdt0 = fPhd[1];
3110 t0Shift = fT0Shift1;
3111 }
3112 else {
3113 fPhdt0 = fPhd[0];
3114 t0Shift = fT0Shift0;
3115 }
55a288e5 3116
3117 if ((fPhd[2] > fPhd[0]) &&
3118 (fPhd[2] > fPhd[1]) &&
3119 (fPhd[1] > fPhd[0]) &&
3120 (put)) {
3a0f6479 3121 fCurrentCoef[0] = (kDrWidth) / (fPhd[2]-fPhd[1]);
3122 fNumberFitSuccess++;
3123
55a288e5 3124 if (fPhdt0 >= 0.0) {
413153cb 3125 fCurrentCoef2[0] = (fPhdt0 - t0Shift) / widbins;
3a0f6479 3126 if (fCurrentCoef2[0] < -1.0) {
3127 fCurrentCoef2[0] = fCurrentCoef2[1];
55a288e5 3128 }
3129 }
3130 else {
3a0f6479 3131 fCurrentCoef2[0] = fCurrentCoef2[1];
55a288e5 3132 }
3a0f6479 3133
55a288e5 3134 }
3135 else {
3a0f6479 3136 fCurrentCoef[0] = -TMath::Abs(fCurrentCoef[1]);
3137 fCurrentCoef2[0] = fCurrentCoef2[1];
55a288e5 3138 }
3139
3a0f6479 3140 if (fDebugLevel == 1) {
55a288e5 3141 TCanvas *cpentei = new TCanvas("cpentei","cpentei",50,50,600,800);
3142 cpentei->cd();
3143 projPH->Draw();
3144 line->SetLineColor(2);
3145 line->DrawLine(fPhd[0],0,fPhd[0],projPH->GetMaximum());
3146 line->DrawLine(fPhd[1],0,fPhd[1],projPH->GetMaximum());
3147 line->DrawLine(fPhd[2],0,fPhd[2],projPH->GetMaximum());
3148 AliInfo(Form("fPhd[0] (beginning of the signal): %f" ,(Float_t) fPhd[0]));
3149 AliInfo(Form("fPhd[1] (end of the amplification region): %f" ,(Float_t) fPhd[1]));
3150 AliInfo(Form("fPhd[2] (end of the drift region): %f" ,(Float_t) fPhd[2]));
3a0f6479 3151 AliInfo(Form("fVriftCoef[1] (with only the drift region(default)): %f",(Float_t) fCurrentCoef[0]));
55a288e5 3152 TCanvas *cpentei2 = new TCanvas("cpentei2","cpentei2",50,50,600,800);
3153 cpentei2->cd();
3154 pentea->Draw();
3155 TCanvas *cpentei3 = new TCanvas("cpentei3","cpentei3",50,50,600,800);
3156 cpentei3->cd();
3157 pente->Draw();
3158 }
3a0f6479 3159 else {
55a288e5 3160 delete pentea;
55a288e5 3161 delete pente;
3162 }
55a288e5 3163}
55a288e5 3164//_____________________________________________________________________________
3a0f6479 3165void AliTRDCalibraFit::FitLagrangePoly(TH1* projPH)
55a288e5 3166{
3167 //
3168 // Slope methode but with polynomes de Lagrange
3169 //
3170 <