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