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