Add the first version of the TRD preprocessor
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibra.cxx
CommitLineData
8ec526a4 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$ */
77566f2a 17
18/////////////////////////////////////////////////////////////////////////////////
19//
20// AliTRDCalibra
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.
24// It can be used for the calibration per chamber but also per group of pads and eventually per pad.
25// The user has to choose with the functions SetNz and SetNrphi the precision of the calibration.
26//Begin_Html
8ec526a4 27/*
28<br>
29<CENTER>
30<TABLE border=1>
31<TR><TD><center>Nz</center></TD><TD><center> 0 </center></TD><TD><center> 1 </center></TD><TD><center> 2 </center></TD><TD><center> 3 </center></TD><TD><center> 4 </center></TD></TR>
32<TR><TD><CENTER>group of row pads per detector</CENTER></TD><TD><CENTER>1</CENTER></TD><TD><CENTER>2</CENTER></TD><TD><CENTER>4</CENTER></TD><TD><CENTER>6(chamb2)<br> 8(others chambers)</CENTER></TD><TD><CENTER>12 (chamb2)<br> 16 (chamb0)</CENTER></TD></TR>
33<TR><TD><CENTER>row pads per group</CENTER></TD><TD><CENTER>12 (chamb2)<br> 16 (chamb0)</CENTER></TD><TD><CENTER>6 (chamb2)<br> 8 (chamb0)</CENTER></TD><TD><CENTER>3 (chamb2)<br> 4 (chamb0)</CENTER></TD><TD><CENTER>2</CENTER></TD><TD><CENTER>1</CENTER></TD></TR>
34<TR><TD><CENTER>~distance [cm]</CENTER></TD><TD><CENTER>106 (chamb2)<br> 130 (chamb0)</CENTER></TD><TD><CENTER>53 (chamb2)<br> 65 (chamb0)</CENTER></TD><TD><CENTER>26.5 (chamb2)<br> 32.5 (chamb0)</CENTER></TD><TD><CENTER>17 (chamb2)<br> 17 (chamb0)</CENTER></TD><TD><CENTER>9 (chamb2)<br> 9 (chamb0)</CENTER></TD></TR>
35<CAPTION>In the z direction</CAPTION>
36</TABLE>
37</CENTER>
38<CENTER>
39<br>
40<TABLE border=1>
41<TR><TD><center>Nrphi</center></TD><TD><center> 0 </center></TD><TD><center> 1 </center></TD><TD><center> 2 </center></TD><TD><center> 3 </center></TD><TD><center> 4 </center></TD><TD><center> 5 </center></TD><TD><center> 6 </center></TD></TR>
42<TR><TD><CENTER>group of col pads per detector</CENTER></TD><TD><CENTER>1</CENTER></TD><TD><CENTER>2</CENTER></TD><TD><CENTER>4</CENTER></TD><TD><CENTER>8</CENTER></TD><TD><CENTER>16</CENTER></TD><TD><center>36</center></TD><TD><center>144</center></TD></TR>
43<TR><TD><CENTER>col pads per group</CENTER></TD><TD><CENTER>144</CENTER></TD><TD><CENTER>72</CENTER></TD><TD><CENTER>36</CENTER></TD><TD><CENTER>18</CENTER></TD><TD><CENTER>9</CENTER></TD><TD><center>4</center></TD><TD><center>1</center></TD></TR>
44<TR><TD><CENTER>~distance [cm]</CENTER></TD><TD><CENTER>113.4</CENTER></TD><TD><CENTER>56.7</CENTER></TD><TD><CENTER>25.3</CENTER></TD><TD><CENTER>14.3</CENTER></TD><TD><CENTER>7.25</CENTER></TD><TD><center>3.2</center></TD><TD><center>0.8</center></TD></TR>
45<CAPTION>In the rphi direction</CAPTION>
46</TABLE>
47</CENTER>
48<br>
49*/
77566f2a 50//End_Html
51//
52// Fill histograms or vectors
53//----------------------------
54//
55// 2D Histograms (Histo2d) or vectors (Vector2d), then converted in Trees, will be filled
56// from RAW DATA in a run or from reconstructed TRD tracks during the offline tracking
57// in the function "FollowBackProlongation" (AliTRDtracker)
58// Per default the functions to fill are off.
59//
60//Begin_Html
8ec526a4 61/*
62Example of 2D histos for the relative gain (left) and the drift velocity (right) calibration of the sector 13 <br>
63<center>
64<img src="./gif/2dhisto.gif" width="600" height="350"><br>
65</center>
66*/
77566f2a 67//End_Html
68//
69// Fit the histograms to find the coefficients
70//---------------------------------------------
71//
72// These 2D histograms or vectors (first converted in 1D histos) will be fitted
73// if they have enough entries, otherwise the (default) value of the choosen database
74// will be put. For the relative gain calibration the resulted factors will be globally
75// normalized to the gain factors of the choosen database. It unables to precise
76// previous calibration procedure.
77// The function SetDebug enables the user to see:
78// _fDebug = 0: nothing, only the values are written in the tree if wanted
79// _fDebug = 1: a comparaison of the coefficients found and the default values
80// in the choosen database.
81// fCoef , histogram of the coefs as function of the calibration group number
82// fDelta , histogram of the relative difference of the coef with the default
83// value in the database as function of the calibration group number
84// fError , dirstribution of this relative difference
85// _fDebug = 2: only the fit of the choosen calibration group fFitVoir (SetFitVoir)
86// _fDebug = 3: The coefficients in the choosen detector fDet (SetDet) as function of the
87// pad row and col number
88// _fDebug = 4; The coeffcicients in the choosen detector fDet (SetDet) like in the 3 but with
89// also the comparaison histograms of the 1 for this detector
90//
91//Begin_Html
8ec526a4 92/*
93Example of fCoef for the relative gain calibration of the sector 13 <br>
94<center>
95<img src="./gif/coef.gif" width="400" height="460">
96</center><br>
97Example of fDelta (right) and fError (left) for the relative gain calibration of the sector 13 <br>
98<center>
99<img src="./gif/detlaerror.gif" width="550" height="380"><br>
100</center>
101*/
77566f2a 102//End_Html
8ec526a4 103//
77566f2a 104// Author:
105// R. Bailhache (R.Bailhache@gsi.de)
106//
107//////////////////////////////////////////////////////////////////////////////////////
108
8ec526a4 109#include <TTree.h>
110#include <TLine.h>
111#include <TH1I.h>
112#include <TStyle.h>
113#include <TProfile2D.h>
114#include <TFile.h>
115#include <TCanvas.h>
116#include <TGraphErrors.h>
117#include <TObjArray.h>
118#include <TChain.h>
119#include <TH1.h>
120#include <TH1I.h>
121#include <TH1F.h>
122#include <TF1.h>
123#include <TH2F.h>
124#include <TAxis.h>
125#include <TStopwatch.h>
126#include <TMath.h>
127#include <TLegend.h>
128#include <TDirectory.h>
129#include <TROOT.h>
130
131#include "AliLog.h"
132#include "AliCDBManager.h"
133#include "AliRun.h"
134#include "AliRunLoader.h"
135#include "AliLoader.h"
136#include "AliRawReaderFile.h"
137#include "AliRawReader.h"
77566f2a 138
139#include "AliTRDCalibra.h"
8ec526a4 140#include "AliTRDcalibDB.h"
141#include "AliTRDCommonParam.h"
142#include "AliTRDmcmTracklet.h"
143#include "AliTRDpadPlane.h"
144#include "AliTRDcluster.h"
145#include "AliTRDtrack.h"
146#include "AliTRDdigit.h"
147#include "AliTRDdigitsManager.h"
148#include "AliTRD.h"
149#include "AliTRDgeometry.h"
150#include "./Cal/AliTRDCalROC.h"
151#include "./Cal/AliTRDCalPad.h"
152#include "./Cal/AliTRDCalDet.h"
153#include "AliTRDrawData.h"
77566f2a 154
155ClassImp(AliTRDCalibra)
156
157AliTRDCalibra* AliTRDCalibra::fgInstance = 0;
158Bool_t AliTRDCalibra::fgTerminated = kFALSE;
159
160//_____________singleton implementation_________________________________________________
8ec526a4 161AliTRDCalibra *AliTRDCalibra::Instance()
77566f2a 162{
163 //
164 // Singleton implementation
165 //
166
8ec526a4 167 if (fgTerminated != kFALSE) {
77566f2a 168 return 0;
8ec526a4 169 }
77566f2a 170
8ec526a4 171 if (fgInstance == 0) {
77566f2a 172 fgInstance = new AliTRDCalibra();
8ec526a4 173 }
77566f2a 174
175 return fgInstance;
176
177}
178
179//______________________________________________________________________________________
180void AliTRDCalibra::Terminate()
181{
182 //
183 // Singleton implementation
184 // Deletes the instance of this class
185 //
186
187 fgTerminated = kTRUE;
188
189 if (fgInstance != 0) {
190 delete fgInstance;
191 fgInstance = 0;
192 }
193
194}
195
196//______________________________________________________________________________________
197AliTRDCalibra::AliTRDCalibra()
198 :TObject()
8ec526a4 199 ,fMITracking(kFALSE)
200 ,fMcmTracking(kFALSE)
201 ,fMcmCorrectAngle(kFALSE)
77566f2a 202 ,fCH2dOn(kFALSE)
203 ,fPH2dOn(kFALSE)
204 ,fPRF2dOn(kFALSE)
205 ,fHisto2d(kFALSE)
206 ,fVector2d(kFALSE)
207 ,fRelativeScale(0)
208 ,fCountRelativeScale(0)
209 ,fRelativeScaleAuto(kFALSE)
8ec526a4 210 ,fThresholdDigit(0)
77566f2a 211 ,fThresholdClusterPRF1(0.0)
212 ,fThresholdClusterPRF2(0.0)
213 ,fCenterOfflineCluster(kFALSE)
214 ,fTraMaxPad(kFALSE)
215 ,fWriteNameCoef(0)
216 ,fWriteName(0)
217 ,fFitPHOn(kFALSE)
218 ,fFitPHPeriode(0)
219 ,fBeginFitCharge(0.0)
220 ,fRangeFitPRF(0.0)
221 ,fMeanChargeOn(kFALSE)
222 ,fFitChargeBisOn(kFALSE)
223 ,fT0Shift(0.0)
8ec526a4 224 ,fAccCDB(kFALSE)
225 ,fNumberFit(0)
e5c60cc7 226 ,fNumberEnt(0)
8ec526a4 227 ,fStatisticMean(0.0)
77566f2a 228 ,fDebug(0)
229 ,fFitVoir(0)
230 ,fPRF(0)
231 ,fGain(0)
232 ,fT0(0)
233 ,fVdrift(0)
234 ,fVdriftDetector(0)
235 ,fVdriftPad(0x0)
236 ,fT0Detector(0)
237 ,fT0Pad(0x0)
238 ,fPRFDetector(0)
239 ,fPRFPad(0x0)
8ec526a4 240 ,fCoefCH(0x0)
77566f2a 241 ,fDetectorAliTRDtrack(kFALSE)
242 ,fChamberAliTRDtrack(-1)
8ec526a4 243 ,fDetectorPreviousTrack(-1)
77566f2a 244 ,fGoodTrack(kTRUE)
8ec526a4 245 ,fAmpTotal(0x0)
246 ,fPHPlace(0x0)
247 ,fPHValue(0x0)
77566f2a 248 ,fNumberClusters(0)
8ec526a4 249 ,fProcent(0.0)
250 ,fDifference(0)
251 ,fNumberTrack(0)
77566f2a 252 ,fDeltaPRF(0)
253 ,fErrorPRF(0)
254 ,fCoefPRFDB(0)
255 ,fTimeMax(0)
256 ,fSf(0.0)
8ec526a4 257 ,fScaleFitFactor(0.0)
77566f2a 258 ,fMinEntries(0)
259 ,fEntriesCurrent(0)
8ec526a4 260 ,fL3P0(0.0)
261 ,fL3P2(0.0)
262 ,fG3P2(0.0)
77566f2a 263 ,fVectorPH(0)
264 ,fPlaPH(0)
265 ,fNumberBinCharge(0)
266 ,fVectorCH(0)
267 ,fPlaCH(0)
268 ,fVectorFitCH(0)
269 ,fNumberBinPRF(0)
270 ,fVectorPRF(0)
271 ,fPlaPRF(0)
272 ,fPH2d(0x0)
273 ,fPRF2d(0x0)
274 ,fCH2d(0x0)
275 ,fRebin(0)
276{
277 //
278 // Default constructor
279 //
280
281 for (Int_t i = 0; i < 3; i++) {
282 fNz[i] = 0;
283 fNrphi[i] = 0;
284 }
285
286 for (Int_t k = 0; k < 3; k++) {
287 fNtotal[k] = 0;
8ec526a4 288 fDetChamb2[k] = 0;
289 fDetChamb0[k] = 0;
77566f2a 290 }
291
292 // Write
293 for (Int_t i = 0; i < 3; i++) {
294 fWriteCoef[i] = kFALSE;
295 fWrite[i] = kFALSE;
296 }
297
298 // Debug Mode
299 for (Int_t k = 0; k < 3; k++) {
300 fDet[k] = 0;
301 }
302
e5c60cc7 303 for (Int_t i = 0; i < 3; i++) {
77566f2a 304 fPhd[i] = 0.0;
305 }
77566f2a 306
307 // Init
308 Init();
309
310}
311
312//______________________________________________________________________________________
313AliTRDCalibra::AliTRDCalibra(const AliTRDCalibra &c)
314 :TObject(c)
8ec526a4 315 ,fMITracking(kFALSE)
316 ,fMcmTracking(kFALSE)
317 ,fMcmCorrectAngle(kFALSE)
77566f2a 318 ,fCH2dOn(kFALSE)
319 ,fPH2dOn(kFALSE)
320 ,fPRF2dOn(kFALSE)
321 ,fHisto2d(kFALSE)
322 ,fVector2d(kFALSE)
323 ,fRelativeScale(0)
324 ,fCountRelativeScale(0)
325 ,fRelativeScaleAuto(kFALSE)
8ec526a4 326 ,fThresholdDigit(0)
77566f2a 327 ,fThresholdClusterPRF1(0.0)
328 ,fThresholdClusterPRF2(0.0)
329 ,fCenterOfflineCluster(kFALSE)
330 ,fTraMaxPad(kFALSE)
331 ,fWriteNameCoef(0)
332 ,fWriteName(0)
333 ,fFitPHOn(kFALSE)
334 ,fFitPHPeriode(0)
335 ,fBeginFitCharge(0.0)
336 ,fRangeFitPRF(0.0)
337 ,fMeanChargeOn(kFALSE)
338 ,fFitChargeBisOn(kFALSE)
339 ,fT0Shift(0.0)
8ec526a4 340 ,fAccCDB(kFALSE)
341 ,fNumberFit(0)
e5c60cc7 342 ,fNumberEnt(0)
8ec526a4 343 ,fStatisticMean(0.0)
77566f2a 344 ,fDebug(0)
345 ,fFitVoir(0)
346 ,fPRF(0)
347 ,fGain(0)
348 ,fT0(0)
349 ,fVdrift(0)
350 ,fVdriftDetector(0)
351 ,fVdriftPad(0x0)
352 ,fT0Detector(0)
353 ,fT0Pad(0x0)
354 ,fPRFDetector(0)
355 ,fPRFPad(0x0)
8ec526a4 356 ,fCoefCH(0x0)
77566f2a 357 ,fDetectorAliTRDtrack(kFALSE)
358 ,fChamberAliTRDtrack(-1)
8ec526a4 359 ,fDetectorPreviousTrack(-1)
77566f2a 360 ,fGoodTrack(kTRUE)
8ec526a4 361 ,fAmpTotal(0x0)
362 ,fPHPlace(0x0)
363 ,fPHValue(0x0)
77566f2a 364 ,fNumberClusters(0)
8ec526a4 365 ,fProcent(0.0)
366 ,fDifference(0)
367 ,fNumberTrack(0)
77566f2a 368 ,fDeltaPRF(0)
369 ,fErrorPRF(0)
370 ,fCoefPRFDB(0)
371 ,fTimeMax(0)
372 ,fSf(0.0)
8ec526a4 373 ,fScaleFitFactor(0.0)
77566f2a 374 ,fMinEntries(0)
375 ,fEntriesCurrent(0)
8ec526a4 376 ,fL3P0(0.0)
377 ,fL3P2(0.0)
378 ,fG3P2(0.0)
77566f2a 379 ,fVectorPH(0)
380 ,fPlaPH(0)
381 ,fNumberBinCharge(0)
382 ,fVectorCH(0)
383 ,fPlaCH(0)
384 ,fVectorFitCH(0)
385 ,fNumberBinPRF(0)
386 ,fVectorPRF(0)
387 ,fPlaPRF(0)
388 ,fPH2d(0x0)
389 ,fPRF2d(0x0)
390 ,fCH2d(0x0)
391 ,fRebin(0)
392{
393 //
394 // Copy constructor
395 //
396
397}
398
399//____________________________________________________________________________________
400AliTRDCalibra::~AliTRDCalibra()
401{
402 //
403 // AliTRDCalibra destructor
404 //
405
406 ClearHistos();
407 ClearTree();
77566f2a 408
409}
410
411//_____________________________________________________________________________
412void AliTRDCalibra::Destroy()
413{
414 //
8ec526a4 415 // Delete instance
77566f2a 416 //
417
418 if (fgInstance) {
77566f2a 419 delete fgInstance;
420 fgInstance = 0x0;
421 }
8ec526a4 422
77566f2a 423}
424
425//_____________________________________________________________________________
426void AliTRDCalibra::ClearHistos()
427{
428 //
8ec526a4 429 // Delete the histos
77566f2a 430 //
431
8ec526a4 432 if (fPH2d) {
77566f2a 433 delete fPH2d;
8ec526a4 434 fPH2d = 0x0;
77566f2a 435 }
8ec526a4 436 if (fCH2d) {
77566f2a 437 delete fCH2d;
8ec526a4 438 fCH2d = 0x0;
77566f2a 439 }
8ec526a4 440 if (fPRF2d) {
77566f2a 441 delete fPRF2d;
442 fPRF2d = 0x0;
443 }
444
445}
446
447//_____________________________________________________________________________
448void AliTRDCalibra::ClearTree()
449{
450 //
8ec526a4 451 // Delete the trees
77566f2a 452 //
453
8ec526a4 454 if (fPRF) {
77566f2a 455 delete fPRF;
8ec526a4 456 fPRF = 0x0;
77566f2a 457 }
8ec526a4 458 if (fGain) {
77566f2a 459 delete fGain;
8ec526a4 460 fGain = 0x0;
77566f2a 461 }
8ec526a4 462 if (fT0) {
77566f2a 463 delete fT0;
8ec526a4 464 fT0 = 0x0;
77566f2a 465 }
8ec526a4 466 if (fVdrift) {
77566f2a 467 delete fVdrift;
468 fVdrift = 0x0;
469 }
470
471}
472
473//_____________________________________________________________________________
474void AliTRDCalibra::Init()
475{
476 //
477 // Init some default values
478 //
479
8ec526a4 480 // How to fill the 2D
481 fThresholdDigit = 5;
77566f2a 482 fThresholdClusterPRF1 = 2.0;
483 fThresholdClusterPRF2 = 20.0;
484
8ec526a4 485 // Store the Info
486 fNumberBinCharge = 100;
487 fNumberBinPRF = 20;
77566f2a 488
8ec526a4 489 // Write
490 fWriteName = "TRD.calibration.root";
491 fWriteNameCoef = "TRD.coefficient.root";
492
493 // Fit
494 fFitPHPeriode = 1;
495 fBeginFitCharge = 3.5;
496 fRangeFitPRF = 0.5;
497 fMinEntries = 800;
498 fT0Shift = 0.143397;
499
500 // Internal variables
501
502 // Fill the 2D histos in the offline tracking
503 fDetectorPreviousTrack = -1;
504 fChamberAliTRDtrack = -1;
505 fGoodTrack = kTRUE;
506
507 fProcent = 6.0;
508 fDifference = 17;
509 fNumberClusters = 18;
510 fNumberTrack = 0;
511 fNumberUsedCh[0] = 0;
512 fNumberUsedCh[1] = 0;
513 fNumberUsedPh[0] = 0;
514 fNumberUsedPh[1] = 0;
515
516 // Variables in the loop
517 for (Int_t k = 0; k < 4; k++) {
77566f2a 518 fChargeCoef[k] = 1.0;
519 fVdriftCoef[k] = 1.5;
8ec526a4 520 fT0Coef[k] = -1.0;
77566f2a 521 }
8ec526a4 522 for (Int_t i = 0; i < 2; i++) {
523 fPRFCoef[i] = -1.0;
77566f2a 524 }
525
8ec526a4 526 // Pad calibration
527 for (Int_t i = 0; i < 3; i++) {
528 fRowMin[i] = -1;
529 fRowMax[i] = -1;
530 fColMax[i] = -1;
531 fColMin[i] = -1;
532 fNnZ[i] = -1;
533 fNnRphi[i] = -1;
534 fNfragZ[i] = -1;
535 fNfragRphi[i] = -1;
536 fXbins[i] = -1;
537 }
538
539 // Local database to be changed
77566f2a 540 fRebin = 1;
541
542}
543
8ec526a4 544//____________Functions fit Online CH2d________________________________________
545Bool_t AliTRDCalibra::FitCHOnline(TH2I *ch)
77566f2a 546{
547 //
8ec526a4 548 // Fit the 1D histos, projections of the 2D ch on the Xaxis, for each
549 // calibration group normalized the resulted coefficients (to 1 normally)
550 // and write the results in a tree
77566f2a 551 //
77566f2a 552
8ec526a4 553 // Number of Xbins (detectors or groups of pads)
554 TAxis *xch = ch->GetXaxis();
555 Int_t nbins = xch->GetNbins();
556 TAxis *yph = ch->GetYaxis();
557 Int_t nybins = yph->GetNbins();
77566f2a 558 Double_t lowedge = xch->GetBinLowEdge(1);
8ec526a4 559 Double_t upedge = xch->GetBinUpEdge(xch->GetNbins());
560 if (!InitFit(nbins,lowedge,upedge,0)) {
77566f2a 561 return kFALSE;
562 }
8ec526a4 563 fStatisticMean = 0.0;
564 fNumberFit = 0;
e5c60cc7 565 fNumberEnt = 0;
77566f2a 566
8ec526a4 567 // For memory
568 if (fVectorCH) {
569 fVectorCH->Clear();
570 }
571 if (fPlaCH) {
572 fPlaCH->Clear();
77566f2a 573 }
77566f2a 574
8ec526a4 575 // Init fCountDet and fCount
576 InitfCountDetAndfCount(0);
577
578 // Beginning of the loop betwwen dect1 and dect2
579 for (Int_t idect = fDect1[0]; idect < fDect2[0]; idect++) {
77566f2a 580
8ec526a4 581 TH1I *projch = (TH1I *) ch->ProjectionY("projch",idect+1,idect+1,(Option_t *)"e");
77566f2a 582 projch->SetDirectory(0);
583
8ec526a4 584 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
585 UpdatefCountDetAndfCount(idect,0);
77566f2a 586
8ec526a4 587 // Reconstruction of the row and pad group: rowmin, row max ...
588 ReconstructFitRowMinRowMax(idect, 0);
77566f2a 589
8ec526a4 590 // Number of entries for this calibration group
77566f2a 591 Double_t nentries = 0.0;
8ec526a4 592 for (Int_t k = 0; k < nybins; k++) {
77566f2a 593 nentries += ch->GetBinContent(ch->GetBin(idect+1,k+1));
594 }
e5c60cc7 595 if (nentries > 0) {
596 fNumberEnt++;
597 }
598
8ec526a4 599 // Rebin and statistic stuff
600 // Rebin
601 if (fRebin > 1) {
602 projch = ReBin((TH1I *) projch);
603 }
604 // This detector has not enough statistics or was off
605 if (nentries < fMinEntries) {
606 // Fill with the default infos
77566f2a 607 NotEnoughStatistic(idect,0);
8ec526a4 608 // Memory!!!
609 if (fDebug != 2) {
77566f2a 610 delete projch;
611 }
612 continue;
613 }
614
8ec526a4 615 // Statistics of the group fitted
616 AliInfo(Form("For the group number %d there are %f stats",idect,nentries));
617 fStatisticMean += nentries;
618 fNumberFit++;
77566f2a 619
8ec526a4 620 // Method Mean and fit
621 // idect is egal for fDebug = 0 and 2, only to fill the hist
622 FitCH((TH1 *) projch,(Int_t) (idect-fDect1[0]));
623 // Method fit bis
624 // idect is egal for fDebug = 0 and 2, only to fill the hist
625 if (fFitChargeBisOn) {
626 FitBisCH((TH1 *) projch,(Int_t) (idect-fDect1[0]));
77566f2a 627 }
628
8ec526a4 629 // Visualise the detector for fDebug 3 or 4
630 // Here is the reconstruction of the pad and row group is used!
631 if (fDebug >= 3) {
632 FillCoefChargeDB();
633 }
634 // Fill Infos Fit
77566f2a 635 FillInfosFit(idect,0);
636
8ec526a4 637 // Memory!!!
638 if (fDebug != 2) {
77566f2a 639 delete projch;
640 }
641
8ec526a4 642 } // Boucle object
77566f2a 643
8ec526a4 644 // Normierungcharge
645 if (fDebug != 2) {
646 NormierungCharge();
647 }
77566f2a 648
8ec526a4 649 // Error
650 if ((fDebug == 1) ||
651 (fDebug == 4)) {
652 ErrorCH();
653 }
77566f2a 654
8ec526a4 655 // Plot
656 // 0 no plot, 1 and 4 error plot, 3 and 4 DB plot
657 if ((fDebug == 1) ||
658 (fDebug == 4)) {
77566f2a 659 PlotCH();
8ec526a4 660 }
661 if ((fDebug == 4) ||
662 (fDebug == 3)) {
77566f2a 663 PlotCHDB();
8ec526a4 664 }
77566f2a 665
8ec526a4 666 // Mean Statistic
667 if (fNumberFit > 0) {
668 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean/fNumberFit));
669 fStatisticMean = fStatisticMean / fNumberFit;
77566f2a 670 }
671 else {
672 AliInfo("There is no fit!");
673 }
674
8ec526a4 675 // Write the things!
77566f2a 676 ConvertVectorFitCHTree();
8ec526a4 677 if (fWriteCoef[0]) {
77566f2a 678 WriteFitInfos(0);
679 }
8ec526a4 680
77566f2a 681 return kTRUE;
682
683}
77566f2a 684
8ec526a4 685//____________Functions fit Online CH2d________________________________________
77566f2a 686Bool_t AliTRDCalibra::FitCHOnline()
687{
688 //
8ec526a4 689 // Reconstruct a 1D histo from the vectorCH for each calibration group,
690 // fit the histo, normalized the resulted coefficients (to 1 normally)
691 // and write the results in a tree
77566f2a 692 //
693
8ec526a4 694 // Number of Xbins (detectors or groups of pads)
695 if (!InitFit(0,0,0,0)) {
77566f2a 696 return kFALSE;
697 }
8ec526a4 698 fStatisticMean = 0.0;
699 fNumberFit = 0;
e5c60cc7 700 fNumberEnt = 0;
77566f2a 701
8ec526a4 702 // Init fCountDet and fCount
703 InitfCountDetAndfCount(0);
77566f2a 704
8ec526a4 705 // Beginning of the loop between dect1 and dect2
706 for (Int_t idect = fDect1[0]; idect < fDect2[0]; idect++) {
77566f2a 707
8ec526a4 708 // Search if the group is in the VectorCH
77566f2a 709 Int_t place = SearchInVector(idect,0);
710
8ec526a4 711 // Is in
712 TH1F *projch = 0x0;
77566f2a 713 TString name("CH");
714 name += idect;
8ec526a4 715 if (place != -1) {
716 // Variable
717 AliTRDCTInfo *fCHInfo = new AliTRDCTInfo();
718 // Retrieve
719 fCHInfo = ((AliTRDCTInfo *) fVectorCH->At(place));
720 projch = ConvertVectorCTHisto(fCHInfo,(const char *) name);
77566f2a 721 projch->SetDirectory(0);
722 delete fCHInfo;
723 }
724
8ec526a4 725 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
726 UpdatefCountDetAndfCount(idect,0);
77566f2a 727
8ec526a4 728 // Reconstruction of the row and pad group: rowmin, row max ...
729 ReconstructFitRowMinRowMax(idect,0);
77566f2a 730
8ec526a4 731 // Number of entries
77566f2a 732 Double_t nentries = 0.0;
9244c78b 733 if (projch) {
734 for (Int_t k = 0; k < fNumberBinCharge; k++) {
735 nentries += projch->GetBinContent(k+1);
736 }
77566f2a 737 }
e5c60cc7 738 if (nentries > 0) {
739 fNumberEnt++;
740 }
77566f2a 741
8ec526a4 742 // Rebin and statistic stuff
743 // Rebin
744 if ((fRebin > 1) &&
745 (place != -1)) {
746 projch = ReBin((TH1F *) projch);
747 }
77566f2a 748
8ec526a4 749 // This detector has not enough statistics or was not found in VectorCH
750 if ((place == -1) ||
751 ((place != -1) &&
752 (nentries < fMinEntries))) {
77566f2a 753
8ec526a4 754 // Fill with the default infos
77566f2a 755 NotEnoughStatistic(idect,0);
756
8ec526a4 757 // Memory!!!
758 if (fDebug != 2) {
77566f2a 759 delete projch;
760 }
761
762 continue;
8ec526a4 763
77566f2a 764 }
765
8ec526a4 766 // Statistic of the histos fitted
767 AliInfo(Form("For the group number %d there are %f stats",idect,nentries));
768 fNumberFit++;
769 fStatisticMean += nentries;
77566f2a 770
8ec526a4 771 // Method Mean and fit
772 // idect is egal for fDebug = 0 and 2, only to fill the hist
773 FitCH((TH1 *) projch,(Int_t) (idect-fDect1[0]));
77566f2a 774
8ec526a4 775 // Method fit bis
776 // idect is egal for fDebug = 0 and 2, only to fill the hist
777 if (fFitChargeBisOn) {
778 FitBisCH((TH1 *) projch,(Int_t) (idect-fDect1[0]));
77566f2a 779 }
780
8ec526a4 781 // Visualise the detector for fDebug 3 or 4
782 // Here is the reconstruction of the pad and row group is used!
783 if (fDebug >= 3) {
784 FillCoefChargeDB();
785 }
77566f2a 786
8ec526a4 787 // Fill Infos Fit
77566f2a 788 FillInfosFit(idect,0);
789
8ec526a4 790 // Memory!!!
791 if (fDebug != 2) {
77566f2a 792 delete projch;
793 }
77566f2a 794
8ec526a4 795 } // Boucle object
77566f2a 796
8ec526a4 797 // Normierungcharge
798 if (fDebug != 2) {
799 NormierungCharge();
800 }
77566f2a 801
8ec526a4 802 // Error
803 if ((fDebug == 1) ||
804 (fDebug == 4)) {
805 ErrorCH();
806 }
77566f2a 807
8ec526a4 808 // Plot
809 // 0 no plot, 1 and 4 error plot, 3 and 4 DB plot
810 if ((fDebug == 1) ||
811 (fDebug == 4)){
77566f2a 812 PlotCH();
813 }
8ec526a4 814 if((fDebug == 4) ||
815 (fDebug == 3)){
77566f2a 816 PlotCHDB();
817 }
818
8ec526a4 819 // Mean Statistics
820 if (fNumberFit > 0) {
821 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean / fNumberFit));
822 fStatisticMean = fStatisticMean / fNumberFit;
77566f2a 823 }
824 else {
825 AliInfo("There is no fit!");
826 }
827
8ec526a4 828 // Write the things!
77566f2a 829 ConvertVectorFitCHTree();
8ec526a4 830 if (fWriteCoef[0]) {
77566f2a 831 WriteFitInfos(0);
832 }
8ec526a4 833
77566f2a 834 return kTRUE;
835
836}
77566f2a 837
8ec526a4 838//____________Functions fit Online CH2d________________________________________
77566f2a 839Bool_t AliTRDCalibra::FitCHOnline(TTree *tree)
840{
841 //
8ec526a4 842 // Look if the calibration group can be found in the tree, if yes take the
843 // histo, fit it, normalized the resulted coefficients (to 1 normally) and
844 // write the results in a tree
77566f2a 845 //
846
8ec526a4 847 // Number of Xbins (detectors or groups of pads)
848 if (!InitFit(0,0,0,0)) {
77566f2a 849 return kFALSE;
850 }
8ec526a4 851 fStatisticMean = 0.0;
852 fNumberFit = 0;
e5c60cc7 853 fNumberEnt = 0;
77566f2a 854
8ec526a4 855 // For memory
856 if (fVectorCH) {
857 fVectorCH->Clear();
77566f2a 858 }
8ec526a4 859 if (fPlaCH) {
860 fPlaCH->Clear();
77566f2a 861 }
8ec526a4 862
863 // Init fCountDet and fCount
864 InitfCountDetAndfCount(0);
865 TH1F *projch = 0x0;
77566f2a 866 tree->SetBranchAddress("histo",&projch);
8ec526a4 867 TObjArray *vectorplace = ConvertTreeVector(tree);
77566f2a 868
8ec526a4 869 // Beginning of the loop between dect1 and dect2
870 for (Int_t idect = fDect1[0]; idect < fDect2[0]; idect++) {
77566f2a 871
872 //Search if the group is in the VectorCH
873 Int_t place = SearchInTreeVector(vectorplace,idect);
874
8ec526a4 875 // Is in
876 if (place != -1) {
877 // Variable
77566f2a 878 tree->GetEntry(place);
879 }
880
8ec526a4 881 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
882 UpdatefCountDetAndfCount(idect,0);
77566f2a 883
8ec526a4 884 // Reconstruction of the row and pad group: rowmin, row max ...
885 ReconstructFitRowMinRowMax(idect,0);
77566f2a 886
8ec526a4 887 // Number of entries
77566f2a 888 Double_t nentries = 0.0;
9244c78b 889 if (projch) {
890 for (Int_t k = 0; k < projch->GetXaxis()->GetNbins(); k++) {
891 nentries += projch->GetBinContent(k+1);
892 }
e5c60cc7 893 }
894 if (nentries > 0) {
895 fNumberEnt++;
896 }
9244c78b 897
8ec526a4 898 // Rebin and statistic stuff
899 // Rebin
900 if ((fRebin > 1) &&
901 (place != -1)) {
902 projch = ReBin((TH1F *) projch);
903 }
904
905 // This detector has not enough statistics or was not found in VectorCH
906 if((place == -1) ||
907 ((place != -1) &&
908 (nentries < fMinEntries))) {
77566f2a 909
8ec526a4 910 // Fill with the default infos
77566f2a 911 NotEnoughStatistic(idect,0);
912
913 continue;
8ec526a4 914
77566f2a 915 }
916
8ec526a4 917 // Statistics of the group fitted
918 AliInfo(Form("For the group number %d there are %f stats",idect,nentries));
919 fNumberFit++;
920 fStatisticMean += nentries;
77566f2a 921
8ec526a4 922 // Method Mean and fit
923 // idect is egal for fDebug = 0 and 2, only to fill the hist
924 FitCH((TH1 *) projch,(Int_t) (idect-fDect1[0]));
77566f2a 925
8ec526a4 926 // Method fit bis
927 // idect is egal for fDebug = 0 and 2, only to fill the hist
928 if (fFitChargeBisOn) {
929 FitBisCH((TH1 *) projch,(Int_t) (idect-fDect1[0]));
77566f2a 930 }
77566f2a 931
8ec526a4 932 // Visualise the detector for fDebug 3 or 4
933 // Here is the reconstruction of the pad and row group is used!
934 if (fDebug >= 3) {
935 FillCoefChargeDB();
936 }
937
938 // Fill Infos Fit
77566f2a 939 FillInfosFit(idect,0);
77566f2a 940
8ec526a4 941 } // Boucle object
77566f2a 942
8ec526a4 943 // Normierungcharge
944 if (fDebug != 2) {
945 NormierungCharge();
946 }
77566f2a 947
8ec526a4 948 // Error
949 if ((fDebug == 1) ||
950 (fDebug == 4)) {
951 ErrorCH();
952 }
77566f2a 953
8ec526a4 954 // Plot
955 // 0 no plot, 1 and 4 error plot, 3 and 4 DB plot
956 if ((fDebug == 1) ||
957 (fDebug == 4)){
77566f2a 958 PlotCH();
8ec526a4 959 }
960 if ((fDebug == 4) ||
961 (fDebug == 3)){
77566f2a 962 PlotCHDB();
8ec526a4 963 }
77566f2a 964
8ec526a4 965 // Mean Statistic
966 if (fNumberFit > 0) {
967 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean / fNumberFit));
968 fStatisticMean = fStatisticMean / fNumberFit;
77566f2a 969 }
970 else {
971 AliInfo("There is no fit!");
972 }
973
8ec526a4 974 // Write the things!
77566f2a 975 ConvertVectorFitCHTree();
8ec526a4 976 if (fWriteCoef[0]) {
77566f2a 977 WriteFitInfos(0);
978 }
8ec526a4 979
77566f2a 980 return kTRUE;
981
982}
77566f2a 983
8ec526a4 984//________________functions fit Online PH2d____________________________________
985Bool_t AliTRDCalibra::FitPHOnline(TProfile2D *ph)
77566f2a 986{
987 //
8ec526a4 988 // Take the 1D profiles (average pulse height), projections of the 2D PH
989 // on the Xaxis, for each calibration group
990 // Fit or use the slope of the average pulse height to reconstruct the
991 // drift velocity write the results in a tree
77566f2a 992 // A first calibration of T0 is also made using the same method (slope method)
993 //
994
8ec526a4 995 // Number of Xbins (detectors or groups of pads)
996 TAxis *xph = ph->GetXaxis();
997 TAxis *yph = ph->GetYaxis();
998 Int_t nbins = xph->GetNbins();
999 Int_t nybins = yph->GetNbins();
77566f2a 1000 Double_t lowedge = xph->GetBinLowEdge(1);
8ec526a4 1001 Double_t upedge = xph->GetBinUpEdge(xph->GetNbins());
1002 if (!InitFit(nbins,lowedge,upedge,1)) {
77566f2a 1003 return kFALSE;
1004 }
8ec526a4 1005 fStatisticMean = 0.0;
1006 fNumberFit = 0;
e5c60cc7 1007 fNumberEnt = 0;
77566f2a 1008
8ec526a4 1009 // For memory
1010 if (fVectorPH) {
1011 fVectorPH->Clear();
1012 }
1013 if (fPlaPH) {
1014 fPlaPH->Clear();
77566f2a 1015 }
77566f2a 1016
8ec526a4 1017 // Init fCountDet and fCount
1018 InitfCountDetAndfCount(1);
1019
1020 // Beginning of the loop
1021 for (Int_t idect = fDect1[1]; idect < fDect2[1]; idect++) {
77566f2a 1022
8ec526a4 1023 TH1D *projph = (TH1D *) ph->ProjectionY("projph",idect+1,idect+1,(Option_t *) "e");
77566f2a 1024 projph->SetDirectory(0);
1025
8ec526a4 1026 // Number of entries for this calibration group
77566f2a 1027 Double_t nentries = 0;
8ec526a4 1028 for (Int_t k = 0; k < nybins; k++) {
1029 nentries += ph->GetBinEntries(ph->GetBin(idect+1,k+1));
77566f2a 1030 }
e5c60cc7 1031 if (nentries > 0) {
1032 fNumberEnt++;
1033 }
1034
8ec526a4 1035 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
1036 UpdatefCountDetAndfCount(idect,1);
77566f2a 1037
8ec526a4 1038 // Reconstruction of the row and pad group: rowmin, row max ...
1039 ReconstructFitRowMinRowMax(idect,1);
77566f2a 1040
8ec526a4 1041 // Rebin and statistic stuff
1042 // This detector has not enough statistics or was off
1043 if (nentries < fMinEntries) {
77566f2a 1044
8ec526a4 1045 // Fill with the default values
77566f2a 1046 NotEnoughStatistic(idect,1);
1047
8ec526a4 1048 // Memory!!!
1049 if (fDebug != 2) {
77566f2a 1050 delete projph;
1051 }
1052
1053 continue;
8ec526a4 1054
77566f2a 1055 }
1056
8ec526a4 1057 // Statistics of the histos fitted
1058 AliInfo(Form("For the group number %d there are %f stats",idect,nentries));
1059 fNumberFit++;
1060 fStatisticMean += nentries;
77566f2a 1061
8ec526a4 1062 // Calcul of "real" coef
1063 CalculVdriftCoefMean(fCountDet[1],(Int_t) (idect - fDect1[1]));
1064 CalculT0CoefMean(fCountDet[1],(Int_t) (idect - fDect1[1]));
77566f2a 1065
8ec526a4 1066 // Method Mean and fit
1067 // idect is egal for fDebug = 0 and 2, only to fill the hist
1068 FitPente((TH1 *) projph,(Int_t) (idect - fDect1[1]));
77566f2a 1069
8ec526a4 1070 // Method fit bis
1071 // idect is egal for fDebug = 0 and 2, only to fill the hist
1072 if (fFitPHOn) {
1073 FitPH((TH1 *) projph,(Int_t) (idect - fDect1[1]));
77566f2a 1074 }
1075
8ec526a4 1076 // Visualise the detector for fDebug 3 or 4
1077 // Here is the reconstruction of the pad and row group is used!
1078 if (fDebug >= 3) {
77566f2a 1079 FillCoefVdriftDB();
1080 FillCoefT0DB();
1081 }
1082
8ec526a4 1083 // Fill the tree if end of a detector or only the pointer to the branch!!!
1084 FillInfosFit(idect,1);
77566f2a 1085
8ec526a4 1086 // Memory!!!
1087 if (fDebug != 2) {
77566f2a 1088 delete projph;
1089 }
1090
8ec526a4 1091 } // Boucle object
77566f2a 1092
8ec526a4 1093 // Error
1094 if ((fDebug == 1) ||
1095 (fDebug == 4)) {
77566f2a 1096 ErrorPH();
1097 ErrorT0();
1098 }
1099
8ec526a4 1100 // Plot
1101 // 0 no plot, 1 and 4 error plot, 3 and 4 DB plot
1102 if ((fDebug == 1) ||
1103 (fDebug == 4)) {
77566f2a 1104 PlotPH();
1105 PlotT0();
8ec526a4 1106 }
1107 if ((fDebug == 4) ||
1108 (fDebug == 3)) {
77566f2a 1109 PlotPHDB();
1110 PlotT0DB();
8ec526a4 1111 }
77566f2a 1112
8ec526a4 1113 // Mean Statistic
1114 if (fNumberFit > 0) {
1115 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean / fNumberFit));
1116 fStatisticMean = fStatisticMean / fNumberFit;
77566f2a 1117 }
1118 else {
1119 AliInfo("There is no fit!");
1120 }
1121
8ec526a4 1122 // Write the things!
1123 if(fWriteCoef[1]) {
77566f2a 1124 WriteFitInfos(1);
1125 }
8ec526a4 1126
77566f2a 1127 return kTRUE;
1128
1129}
77566f2a 1130
8ec526a4 1131//____________Functions fit Online PH2d________________________________________
77566f2a 1132Bool_t AliTRDCalibra::FitPHOnline()
1133{
1134 //
8ec526a4 1135 // Reconstruct the average pulse height from the vectorPH for each
1136 // calibration group
1137 // Fit or use the slope of the average pulse height to reconstruct the
1138 // drift velocity write the results in a tree
77566f2a 1139 // A first calibration of T0 is also made using the same method (slope method)
1140 //
77566f2a 1141
8ec526a4 1142 // Number of Xbins (detectors or groups of pads)
1143 if (!InitFit(0,0,0,1)) {
77566f2a 1144 return kFALSE;
1145 }
8ec526a4 1146 fStatisticMean = 0.0;
1147 fNumberFit = 0;
e5c60cc7 1148 fNumberEnt = 0;
77566f2a 1149
8ec526a4 1150 // Init fCountDet and fCount
1151 InitfCountDetAndfCount(1);
77566f2a 1152
8ec526a4 1153 // Beginning of the loop
1154 for (Int_t idect = fDect1[1]; idect < fDect2[1]; idect++) {
77566f2a 1155
8ec526a4 1156 // Search if the group is in the VectorCH
77566f2a 1157 Int_t place = SearchInVector(idect,1);
1158
8ec526a4 1159 // Is in
1160 TH1F *projph = 0x0;
77566f2a 1161 TString name("PH");
1162 name += idect;
8ec526a4 1163 if (place != -1) {
e5c60cc7 1164 //Entries
1165 fNumberEnt++;
8ec526a4 1166 // Variable
1167 AliTRDPInfo *fPHInfo = new AliTRDPInfo();
1168 // Retrieve
1169 fPHInfo = (AliTRDPInfo *) fVectorPH->At(place);
1170 projph = CorrectTheError((TGraphErrors *) ConvertVectorPHisto(fPHInfo,(const char *) name));
77566f2a 1171 projph->SetDirectory(0);
1172 delete fPHInfo;
1173 }
1174
8ec526a4 1175 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
1176 UpdatefCountDetAndfCount(idect,1);
77566f2a 1177
8ec526a4 1178 // Reconstruction of the row and pad group: rowmin, row max ...
1179 ReconstructFitRowMinRowMax(idect,1);
77566f2a 1180
8ec526a4 1181 // Rebin and statistic stuff
1182 // This detector has not enough statistics or was off
1183 if ((place == -1) ||
1184 ((place != -1) &&
1185 (fEntriesCurrent < fMinEntries))) {
77566f2a 1186
8ec526a4 1187 // Fill with the default values
77566f2a 1188 NotEnoughStatistic(idect,1);
1189
8ec526a4 1190 // Memory!!!
1191 if (fDebug != 2) {
77566f2a 1192 delete projph;
1193 }
8ec526a4 1194
77566f2a 1195 continue;
8ec526a4 1196
77566f2a 1197 }
1198
8ec526a4 1199 // Statistic of the histos fitted
1200 AliInfo(Form("For the group number %d there are %d stats",idect,fEntriesCurrent));
1201 fNumberFit++;
1202 fStatisticMean += fEntriesCurrent;
77566f2a 1203
8ec526a4 1204 // Calcul of "real" coef
1205 CalculVdriftCoefMean(fCountDet[1],(Int_t) (idect - fDect1[1]));
1206 CalculT0CoefMean(fCountDet[1],(Int_t) (idect - fDect1[1]));
77566f2a 1207
8ec526a4 1208 // Method Mean and fit
1209 // idect is egal for fDebug = 0 and 2, only to fill the hist
1210 FitPente((TH1 *) projph,(Int_t) (idect - fDect1[1]));
77566f2a 1211
8ec526a4 1212 // Method fit bis
1213 // idect is egal for fDebug = 0 and 2, only to fill the hist
1214 if (fFitPHOn) {
1215 FitPH((TH1 *) projph,(Int_t) (idect - fDect1[1]));
77566f2a 1216 }
1217
8ec526a4 1218 // Visualise the detector for fDebug 3 or 4
1219 // Here is the reconstruction of the pad and row group is used!
1220 if (fDebug >= 3) {
77566f2a 1221 FillCoefVdriftDB();
1222 FillCoefT0DB();
1223 }
1224
8ec526a4 1225 // Fill the tree if end of a detector or only the pointer to the branch!!!
77566f2a 1226 FillInfosFit(idect,1);
1227
8ec526a4 1228 // Memory!!!
1229 if (fDebug != 2) {
77566f2a 1230 delete projph;
1231 }
1232
8ec526a4 1233 } // Boucle object
77566f2a 1234
8ec526a4 1235 // Error
1236 if ((fDebug == 1) ||
1237 (fDebug == 4)) {
77566f2a 1238 ErrorPH();
1239 ErrorT0();
1240 }
1241
8ec526a4 1242 // Plot
1243 // 0 no plot, 1 and 4 error plot, 3 and 4 DB plot
1244 if ((fDebug == 1) ||
1245 (fDebug == 4)) {
77566f2a 1246 PlotPH();
1247 PlotT0();
1248 }
8ec526a4 1249 if ((fDebug == 4) ||
1250 (fDebug == 3)) {
77566f2a 1251 PlotPHDB();
1252 PlotT0DB();
1253 }
1254
8ec526a4 1255 // Mean Statistic
1256 if (fNumberFit > 0) {
1257 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean / fNumberFit));
1258 fStatisticMean = fStatisticMean / fNumberFit;
77566f2a 1259 }
1260 else {
1261 AliInfo("There is no fit!");
1262 }
1263
8ec526a4 1264 // Write the things!
1265 if (fWriteCoef[1]) {
77566f2a 1266 WriteFitInfos(1);
1267 }
8ec526a4 1268
77566f2a 1269 return kTRUE;
1270
1271}
1272
8ec526a4 1273//____________Functions fit Online PH2d________________________________________
77566f2a 1274Bool_t AliTRDCalibra::FitPHOnline(TTree *tree)
1275{
1276 //
8ec526a4 1277 // Look if the calibration group can be found in the tree, if yes take the
1278 // histo, fit it, and write the results in a tree
77566f2a 1279 // A first calibration of T0 is also made using the same method (slope method)
1280 //
77566f2a 1281
8ec526a4 1282 // Number of Xbins (detectors or groups of pads)
1283 if (!InitFit(0,0,0,1)) {
77566f2a 1284 return kFALSE;
1285 }
8ec526a4 1286 fStatisticMean = 0.0;
1287 fNumberFit = 0;
e5c60cc7 1288 fNumberEnt = 0;
8ec526a4 1289
1290 // For memory
1291 if (fVectorPH) {
1292 fVectorPH->Clear();
77566f2a 1293 }
8ec526a4 1294 if (fPlaPH) {
1295 fPlaPH->Clear();
77566f2a 1296 }
1297
8ec526a4 1298 // Init fCountDet and fCount
1299 InitfCountDetAndfCount(1);
1300 TGraphErrors *projphtree = 0x0;
77566f2a 1301 tree->SetBranchAddress("histo",&projphtree);
8ec526a4 1302 TObjArray *vectorplace = ConvertTreeVector(tree);
77566f2a 1303
8ec526a4 1304 // Beginning of the loop
1305 for (Int_t idect = fDect1[1]; idect < fDect2[1]; idect++) {
77566f2a 1306
8ec526a4 1307 // Search if the group is in the VectorCH
77566f2a 1308 Int_t place = SearchInTreeVector(vectorplace,idect);
1309
1310 TH1F *projph = 0x0;
8ec526a4 1311 // Is in
1312 if (place != -1) {
e5c60cc7 1313 //Entries
1314 fNumberEnt++;
8ec526a4 1315 // Variable
77566f2a 1316 tree->GetEntry(place);
1317 projph = CorrectTheError(projphtree);
1318 }
1319
8ec526a4 1320 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
1321 UpdatefCountDetAndfCount(idect,1);
77566f2a 1322
8ec526a4 1323 // Reconstruction of the row and pad group: rowmin, row max ...
1324 ReconstructFitRowMinRowMax(idect,1);
77566f2a 1325
8ec526a4 1326 // Rebin and statistic stuff
1327 // This detector has not enough statistics or was off
1328 if((place == -1) ||
1329 ((place != -1) &&
1330 (fEntriesCurrent < fMinEntries))) {
77566f2a 1331
8ec526a4 1332 // Fill with the default values
77566f2a 1333 NotEnoughStatistic(idect,1);
1334
8ec526a4 1335 // Memory!!!
1336 if (fDebug != 2) {
77566f2a 1337 delete projph;
1338 }
1339
1340 continue;
8ec526a4 1341
77566f2a 1342 }
1343
8ec526a4 1344 // Statistics of the histos fitted
1345 AliInfo(Form("For the group number %d there are %d stats",idect,fEntriesCurrent));
1346 fNumberFit++;
1347 fStatisticMean += fEntriesCurrent;
77566f2a 1348
8ec526a4 1349 // Calcul of "real" coef
1350 CalculVdriftCoefMean(fCountDet[1],(Int_t) (idect - fDect1[1]));
1351 CalculT0CoefMean(fCountDet[1],(Int_t) (idect - fDect1[1]));
77566f2a 1352
8ec526a4 1353 // Method Mean and fit
1354 // idect is egal for fDebug = 0 and 2, only to fill the hist
1355 FitPente((TH1 *) projph,(Int_t) (idect - fDect1[1]));
1356 // Method fit bis
1357 // idect is egal for fDebug = 0 and 2, only to fill the hist
1358 if (fFitPHOn) {
1359 FitPH((TH1 *) projph,(Int_t) (idect - fDect1[1]));
77566f2a 1360 }
1361
8ec526a4 1362 // Visualise the detector for fDebug 3 or 4
1363 // Here is the reconstruction of the pad and row group is used!
1364 if (fDebug >= 3) {
77566f2a 1365 FillCoefVdriftDB();
1366 FillCoefT0DB();
1367 }
1368
8ec526a4 1369 // Fill the tree if end of a detector or only the pointer to the branch!!!
77566f2a 1370 FillInfosFit(idect,1);
77566f2a 1371
8ec526a4 1372 // Memory!!!
1373 if (fDebug != 2) {
77566f2a 1374 delete projph;
1375 }
77566f2a 1376
8ec526a4 1377 } // Boucle object
77566f2a 1378
8ec526a4 1379 // Error
1380 if ((fDebug == 1) ||
1381 (fDebug == 4)) {
77566f2a 1382 ErrorPH();
1383 ErrorT0();
1384 }
1385
8ec526a4 1386 // Plot
1387 // 0 no plot, 1 and 4 error plot, 3 and 4 DB plot
1388 if ((fDebug == 1) ||
1389 (fDebug == 4)){
77566f2a 1390 PlotPH();
1391 PlotT0();
1392 }
8ec526a4 1393 if ((fDebug == 4) ||
1394 (fDebug == 3)){
77566f2a 1395 PlotPHDB();
1396 PlotT0DB();
1397 }
1398
8ec526a4 1399 // Mean Statistics
1400 if (fNumberFit > 0) {
1401 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean / fNumberFit));
1402 fStatisticMean = fStatisticMean / fNumberFit;
77566f2a 1403 }
1404 else {
1405 AliInfo("There is no fit!");
1406 }
1407
8ec526a4 1408 // Write the things!
1409 if (fWriteCoef[1]) {
77566f2a 1410 WriteFitInfos(1);
1411 }
8ec526a4 1412
77566f2a 1413 return kTRUE;
1414
1415}
77566f2a 1416
8ec526a4 1417//____________Functions fit Online PRF2d_______________________________________
1418Bool_t AliTRDCalibra::FitPRFOnline(TProfile2D *prf)
77566f2a 1419{
1420 //
8ec526a4 1421 // Take the 1D profiles (pad response function), projections of the 2D PRF
1422 // on the Xaxis, for each calibration group
1423 // Fit with a gaussian to reconstruct the sigma of the pad response function
1424 // write the results in a tree
77566f2a 1425 //
1426
8ec526a4 1427 // Number of Xbins (detectors or groups of pads)
1428 TAxis *xprf = prf->GetXaxis();
1429 TAxis *yprf = prf->GetYaxis();
1430 Int_t nybins = yprf->GetNbins();
1431 Int_t nbins = xprf->GetNbins();
77566f2a 1432 Double_t lowedge = xprf->GetBinLowEdge(1);
8ec526a4 1433 Double_t upedge = xprf->GetBinUpEdge(xprf->GetNbins());
1434 if (!InitFit(nbins,lowedge,upedge,2)) {
77566f2a 1435 return kFALSE;
1436 }
8ec526a4 1437 fStatisticMean = 0.0;
1438 fNumberFit = 0;
e5c60cc7 1439 fNumberEnt = 0;
77566f2a 1440
8ec526a4 1441 // For memory
1442 if (fVectorPRF) {
1443 fVectorPRF->Clear();
1444 }
1445 if (fPlaPRF) {
1446 fPlaPRF->Clear();
77566f2a 1447 }
77566f2a 1448
8ec526a4 1449 // Init fCountDet and fCount
1450 InitfCountDetAndfCount(2);
77566f2a 1451
8ec526a4 1452 // Beginning of the loop
1453 for (Int_t idect = fDect1[2]; idect < fDect2[2]; idect++) {
77566f2a 1454
8ec526a4 1455 TH1D *projprf = (TH1D *) prf->ProjectionY("projprf",idect+1,idect+1,(Option_t *) "e");
77566f2a 1456 projprf->SetDirectory(0);
1457
8ec526a4 1458 // Number of entries for this calibration group
77566f2a 1459 Double_t nentries = 0;
8ec526a4 1460 for (Int_t k = 0; k < nybins; k++) {
1461 nentries += prf->GetBinEntries(prf->GetBin(idect+1,k+1));
77566f2a 1462 }
e5c60cc7 1463 if(nentries > 0) fNumberEnt++;
77566f2a 1464
8ec526a4 1465 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
1466 UpdatefCountDetAndfCount(idect,2);
77566f2a 1467
8ec526a4 1468 // Reconstruction of the row and pad group: rowmin, row max ...
1469 ReconstructFitRowMinRowMax(idect,2);
77566f2a 1470
8ec526a4 1471 // Rebin and statistic stuff
1472 // This detector has not enough statistics or was off
1473 if (nentries < fMinEntries) {
77566f2a 1474
8ec526a4 1475 // Fill with the default values
77566f2a 1476 NotEnoughStatistic(idect,2);
1477
8ec526a4 1478 // Memory!
1479 if (fDebug != 2) {
77566f2a 1480 delete projprf;
1481 }
1482
1483 continue;
8ec526a4 1484
77566f2a 1485 }
1486
8ec526a4 1487 // Statistics of the histos fitted
1488 AliInfo(Form("For the group number %d there are %f stats",idect,nentries));
1489 fNumberFit++;
1490 fStatisticMean += nentries;
77566f2a 1491
8ec526a4 1492 // Calcul of "real" coef
1493 if ((fDebug == 1) ||
1494 (fDebug == 4)) {
1495 CalculPRFCoefMean(fCountDet[2],(Int_t) (idect - fDect1[2]));
77566f2a 1496 }
1497
8ec526a4 1498 // Method Mean and fit
1499 // idect is egal for fDebug = 0 and 2, only to fill the hist
1500 FitPRF((TH1 *) projprf,(Int_t) (idect - fDect1[2]));
77566f2a 1501
8ec526a4 1502 // Visualise the detector for fDebug 3 or 4
1503 // Here is the reconstruction of the pad and row group is used!
1504 if (fDebug >= 3) {
1505 FillCoefPRFDB();
1506 }
77566f2a 1507
8ec526a4 1508 // Fill the tree if end of a detector or only the pointer to the branch!!!
77566f2a 1509 FillInfosFit(idect,2);
1510
8ec526a4 1511 // Memory!!!
1512 if (fDebug != 2) {
77566f2a 1513 delete projprf;
1514 }
1515
8ec526a4 1516 } // Boucle object
77566f2a 1517
8ec526a4 1518 // Error
1519 if ((fDebug == 1) ||
1520 (fDebug == 4)) {
1521 ErrorPRF();
1522 }
77566f2a 1523
8ec526a4 1524 // Plot
1525 // No plot, 1 and 4 error plot, 3 and 4 DB plot
1526 if ((fDebug == 1) ||
1527 (fDebug == 4)) {
77566f2a 1528 PlotPRF();
8ec526a4 1529 }
1530 if ((fDebug == 4) ||
1531 (fDebug == 3)){
77566f2a 1532 PlotPRFDB();
8ec526a4 1533 }
77566f2a 1534
8ec526a4 1535 // Mean Statistic
1536 if (fNumberFit > 0) {
1537 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean / fNumberFit));
1538 fStatisticMean = fStatisticMean / fNumberFit;
77566f2a 1539 }
1540 else {
1541 AliInfo("There is no fit!");
1542 }
1543
8ec526a4 1544 // Write the things!
1545 if (fWriteCoef[2]) {
77566f2a 1546 WriteFitInfos(2);
1547 }
8ec526a4 1548
77566f2a 1549 return kTRUE;
1550
1551}
77566f2a 1552
8ec526a4 1553//____________Functions fit Online PRF2d_______________________________________
77566f2a 1554Bool_t AliTRDCalibra::FitPRFOnline(TTree *tree)
1555{
1556 //
8ec526a4 1557 // Look if the calibration group can be found in the tree, if yes take
1558 // the histo, fit it, and write the results in a tree
77566f2a 1559 //
1560
8ec526a4 1561 // Number of Xbins (detectors or groups of pads)
1562 if (!InitFit(0,0,0,2)) {
77566f2a 1563 return kFALSE;
1564 }
8ec526a4 1565 fStatisticMean = 0.0;
1566 fNumberFit = 0;
e5c60cc7 1567 fNumberEnt = 0;
77566f2a 1568
8ec526a4 1569 // For memory
1570 if (fVectorPRF) {
1571 fVectorPRF->Clear();
1572 }
1573 if (fPlaPRF) {
1574 fPlaPRF->Clear();
77566f2a 1575 }
1576
8ec526a4 1577 // Init fCountDet and fCount
1578 InitfCountDetAndfCount(2);
1579 TGraphErrors *projprftree = 0x0;
77566f2a 1580 tree->SetBranchAddress("histo",&projprftree);
8ec526a4 1581 TObjArray *vectorplace = ConvertTreeVector(tree);
77566f2a 1582
8ec526a4 1583 // Beginning of the loop
1584 for (Int_t idect = fDect1[2]; idect < fDect2[2]; idect++) {
77566f2a 1585
8ec526a4 1586 // Search if the group is in the VectorCH
77566f2a 1587 Int_t place = SearchInTreeVector(vectorplace,idect);
1588
8ec526a4 1589 // Is in
77566f2a 1590 TH1F *projprf = 0x0;
8ec526a4 1591 if (place != -1) {
e5c60cc7 1592 //Entries
1593 fNumberEnt++;
8ec526a4 1594 // Variable
77566f2a 1595 tree->GetEntry(place);
1596 projprf = CorrectTheError(projprftree);
1597 }
1598
8ec526a4 1599 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
1600 UpdatefCountDetAndfCount(idect,2);
77566f2a 1601
8ec526a4 1602 // Reconstruction of the row and pad group: rowmin, row max ...
1603 ReconstructFitRowMinRowMax(idect,2);
77566f2a 1604
8ec526a4 1605 // Rebin and statistic stuff
1606 // This detector has not enough statistics or was off
1607 if ((place == -1) ||
1608 ((place != -1) &&
1609 (fEntriesCurrent < fMinEntries))) {
77566f2a 1610
8ec526a4 1611 // Fill with the default values
77566f2a 1612 NotEnoughStatistic(idect,2);
1613
8ec526a4 1614 // Memory!!!
1615 if (fDebug != 2) {
77566f2a 1616 delete projprf;
1617 }
1618
1619 continue;
8ec526a4 1620
77566f2a 1621 }
1622
8ec526a4 1623 // Statistics of the histos fitted
1624 AliInfo(Form("For the group number %d there are %d stats",idect,fEntriesCurrent));
1625 fNumberFit++;
1626 fStatisticMean += fEntriesCurrent;
77566f2a 1627
8ec526a4 1628 // Calcul of "real" coef
1629 if ((fDebug == 1) ||
1630 (fDebug == 4)){
1631 CalculPRFCoefMean(fCountDet[2],(Int_t) (idect - fDect1[2]));
1632 }
1633
1634 // Method Mean and fit
1635 // idect is egal for fDebug = 0 and 2, only to fill the hist
1636 FitPRF((TH1 *) projprf,(Int_t) (idect - fDect1[2]));
1637 // Visualise the detector for fDebug 3 or 4
1638 // Here is the reconstruction of the pad and row group is used!
1639 if (fDebug >= 3) {
1640 FillCoefPRFDB();
77566f2a 1641 }
8ec526a4 1642 // Fill the tree if end of a detector or only the pointer to the branch!!!
77566f2a 1643 FillInfosFit(idect,2);
77566f2a 1644
8ec526a4 1645 // Memory!!!
1646 if (fDebug != 2) {
77566f2a 1647 delete projprf;
1648 }
1649
8ec526a4 1650 } // Boucle object
77566f2a 1651
8ec526a4 1652 // Error
1653 if ((fDebug == 1) ||
1654 (fDebug == 4)) {
1655 ErrorPRF();
1656 }
77566f2a 1657
8ec526a4 1658 // Plot
1659 // No plot, 1 and 4 error plot, 3 and 4 DB plot
1660 if ((fDebug == 1) ||
1661 (fDebug == 4)){
77566f2a 1662 PlotPRF();
1663 }
8ec526a4 1664 if ((fDebug == 4) ||
1665 (fDebug == 3)){
77566f2a 1666 PlotPRFDB();
1667 }
1668
8ec526a4 1669 // Mean Statistics
1670 if (fNumberFit > 0) {
1671 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean / fNumberFit));
1672 fStatisticMean = fStatisticMean / fNumberFit;
77566f2a 1673 }
1674 else {
1675 AliInfo("There is no fit!");
1676 }
1677
8ec526a4 1678 // Write the things!
1679 if (fWriteCoef[2]) {
77566f2a 1680 WriteFitInfos(2);
1681 }
8ec526a4 1682
77566f2a 1683 return kTRUE;
1684
1685}
77566f2a 1686
8ec526a4 1687//____________Functions fit Online PRF2d_______________________________________
77566f2a 1688Bool_t AliTRDCalibra::FitPRFOnline()
1689{
1690 //
8ec526a4 1691 // Reconstruct the 1D histo (pad response function) from the vectorPRD for
1692 // each calibration group
1693 // Fit with a gaussian to reconstruct the sigma of the pad response function
1694 // write the results in a tree
77566f2a 1695 //
1696
8ec526a4 1697 // Number of Xbins (detectors or groups of pads)
1698 if (!InitFit(0,0,0,2)) {
77566f2a 1699 return kFALSE;
1700 }
8ec526a4 1701 fStatisticMean = 0.0;
1702 fNumberFit = 0;
e5c60cc7 1703 fNumberEnt = 0;
77566f2a 1704
8ec526a4 1705 // Init fCountDet and fCount
1706 InitfCountDetAndfCount(2);
77566f2a 1707
8ec526a4 1708 // Beginning of the loop
1709 for (Int_t idect = fDect1[2]; idect < fDect2[2]; idect++) {
77566f2a 1710
8ec526a4 1711 // Search if the group is in the VectorCH
77566f2a 1712 Int_t place = SearchInVector(idect,2);
1713
8ec526a4 1714 // Is in
1715 TH1F *projprf = 0x0;
77566f2a 1716 TString name("PRF");
1717 name += idect;
8ec526a4 1718 if (place != -1) {
e5c60cc7 1719 //Entries
1720 fNumberEnt++;
8ec526a4 1721 // Variable
1722 AliTRDPInfo *fPRFInfo = new AliTRDPInfo();
1723 // Retrieve
1724 fPRFInfo = (AliTRDPInfo *) fVectorPRF->At(place);
1725 projprf = CorrectTheError((TGraphErrors *) ConvertVectorPHisto(fPRFInfo,(const char *)name));
77566f2a 1726 projprf->SetDirectory(0);
1727 delete fPRFInfo;
1728 }
1729
8ec526a4 1730 // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
1731 UpdatefCountDetAndfCount(idect,2);
77566f2a 1732
8ec526a4 1733 // Reconstruction of the row and pad group: rowmin, row max ...
1734 ReconstructFitRowMinRowMax(idect,2);
77566f2a 1735
8ec526a4 1736 // Rebin and statistic stuff
1737 // This detector has not enough statistics or was off
1738 if ((place == -1) ||
1739 ((place != -1) &&
1740 (fEntriesCurrent < fMinEntries))) {
77566f2a 1741
8ec526a4 1742 // Fill with the default values
77566f2a 1743 NotEnoughStatistic(idect,2);
1744
8ec526a4 1745 // Memory
1746 if (fDebug != 2) {
77566f2a 1747 delete projprf;
1748 }
77566f2a 1749
1750 continue;
77566f2a 1751
8ec526a4 1752 }
77566f2a 1753
8ec526a4 1754 // Statistic of the histos fitted
1755 AliInfo(Form("For the group number %d there are %d stats", idect,fEntriesCurrent));
1756 fNumberFit++;
1757 fStatisticMean += fEntriesCurrent;
77566f2a 1758
8ec526a4 1759 // Calcul of "real" coef
1760 if ((fDebug == 1) ||
1761 (fDebug == 4)) {
1762 CalculPRFCoefMean(fCountDet[2],(Int_t) (idect-fDect1[2]));
1763 }
77566f2a 1764
8ec526a4 1765 // Method Mean and fit
1766 // idect is egal for fDebug = 0 and 2, only to fill the hist
1767 FitPRF((TH1 *) projprf,(Int_t) (idect-fDect1[2]));
1768 // Visualise the detector for fDebug 3 or 4
1769 // Here is the reconstruction of the pad and row group is used!
1770 if (fDebug >= 3) {
1771 FillCoefPRFDB();
77566f2a 1772 }
8ec526a4 1773 // Fill the tree if end of a detector or only the pointer to the branch!!!
77566f2a 1774 FillInfosFit(idect,2);
1775
8ec526a4 1776 // Memory!!!
1777 if (fDebug != 2) {
77566f2a 1778 delete projprf;
1779 }
1780
8ec526a4 1781 } // Boucle object
77566f2a 1782
8ec526a4 1783 // Error
1784 if ((fDebug == 1) ||
1785 (fDebug == 4)) {
1786 ErrorPRF();
1787 }
77566f2a 1788
8ec526a4 1789 // Plot
1790 // No plot, 1 and 4 error plot, 3 and 4 DB plot
1791 if ((fDebug == 1) ||
1792 (fDebug == 4)) {
77566f2a 1793 PlotPRF();
8ec526a4 1794 }
1795 if ((fDebug == 4) ||
1796 (fDebug == 3)) {
77566f2a 1797 PlotPRFDB();
8ec526a4 1798 }
77566f2a 1799
8ec526a4 1800 // Mean Statistics
1801 if (fNumberFit > 0) {
1802 AliInfo(Form("There is a mean statistic of: %d",(Int_t) fStatisticMean / fNumberFit));
77566f2a 1803 }
1804 else {
1805 AliInfo("There is no fit!");
1806 }
1807
8ec526a4 1808 // Write the things!
1809 if (fWriteCoef[2]) {
77566f2a 1810 WriteFitInfos(2);
1811 }
8ec526a4 1812
77566f2a 1813 return kTRUE;
1814
1815}
1816
8ec526a4 1817//____________Functions for initialising the AliTRDCalibra in the code_________
77566f2a 1818Bool_t AliTRDCalibra::Init2Dhistos()
1819{
8ec526a4 1820 //
1821 // For the offline tracking
1822 // This function will be called in the function AliReconstruction::Run()
1823 // Init the calibration mode (Nz, Nrphi), the 2D histograms if fHisto2d = kTRUE,
1824 //
77566f2a 1825
8ec526a4 1826 // DB Setting
1827 // Get cal
1828 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
77566f2a 1829 if (!cal) {
1830 AliInfo("Could not get calibDB");
1831 return kFALSE;
1832 }
1833
77566f2a 1834 // Some parameters
8ec526a4 1835 fTimeMax = cal->GetNumberOfTimeBins();
1836 fSf = cal->GetSamplingFrequency();
1837 if (fRelativeScaleAuto) {
1838 fRelativeScale = 0;
1839 }
1840 else {
1841 fRelativeScale = 20;
1842 }
77566f2a 1843
8ec526a4 1844 // Create the 2D histos corresponding to the pad groupCalibration mode
1845 if (fCH2dOn) {
77566f2a 1846
8ec526a4 1847 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d"
1848 ,fNz[0]
1849 ,fNrphi[0]));
77566f2a 1850
8ec526a4 1851 // Calcul the number of Xbins
77566f2a 1852 fNtotal[0] = 0;
1853 ModePadCalibration(2,0);
1854 ModePadFragmentation(0,2,0,0);
8ec526a4 1855 fDetChamb2[0] = fNfragZ[0] * fNfragRphi[0];
1856 if (fDebug == 4) {
1857 AliInfo(Form("For the chamber 2: %d",fDetChamb2[0]));
77566f2a 1858 }
8ec526a4 1859 fNtotal[0] += 6 * 18 * fDetChamb2[0];
77566f2a 1860 ModePadCalibration(0,0);
1861 ModePadFragmentation(0,0,0,0);
8ec526a4 1862 fDetChamb0[0] = fNfragZ[0] * fNfragRphi[0];
1863 if (fDebug == 4) {
1864 AliInfo(Form("For the other chamber 0: %d",fDetChamb0[0]));
77566f2a 1865 }
8ec526a4 1866 fNtotal[0] += 6 * 4 * 18 * fDetChamb0[0];
1867 AliInfo(Form("Total number of Xbins: %d",fNtotal[0]));
77566f2a 1868
8ec526a4 1869 // Create the 2D histo
1870 if (fHisto2d) {
1871 CreateCH2d(fNtotal[0]);
1872 }
1873 if (fVector2d) {
1874 fVectorCH = new TObjArray();
1875 fPlaCH = new TObjArray();
1876 }
77566f2a 1877
8ec526a4 1878 // Variable
1879 fAmpTotal = new Float_t[TMath::Max(fDetChamb2[0],fDetChamb0[0])];
1880 for (Int_t k = 0; k < TMath::Max(fDetChamb2[0],fDetChamb0[0]); k++) {
1881 fAmpTotal[k] = 0.0;
77566f2a 1882 }
1883
77566f2a 1884 }
1885
8ec526a4 1886 if (fPH2dOn) {
1887
1888 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d"
1889 ,fNz[1]
1890 ,fNrphi[1]));
77566f2a 1891
8ec526a4 1892 // Calcul the number of Xbins
77566f2a 1893 fNtotal[1] = 0;
1894 ModePadCalibration(2,1);
1895 ModePadFragmentation(0,2,0,1);
8ec526a4 1896 fDetChamb2[1] = fNfragZ[1]*fNfragRphi[1];
1897 if (fDebug == 4) {
1898 AliInfo(Form("For the chamber 2: %d",fDetChamb2[1]));
77566f2a 1899 }
8ec526a4 1900 fNtotal[1] += 6 * 18 * fDetChamb2[1];
77566f2a 1901 ModePadCalibration(0,1);
1902 ModePadFragmentation(0,0,0,1);
8ec526a4 1903 fDetChamb0[1] = fNfragZ[1] * fNfragRphi[1];
1904 if (fDebug == 4) {
1905 AliInfo(Form("For the chamber 0: %d",fDetChamb0[1]));
77566f2a 1906 }
8ec526a4 1907 fNtotal[1] += 6 * 4 * 18 * fDetChamb0[1];
1908 AliInfo(Form("Total number of Xbins: %d",fNtotal[1]));
77566f2a 1909
8ec526a4 1910 // Create the 2D histo
1911 if (fHisto2d) {
1912 CreatePH2d(fNtotal[1]);
1913 }
1914 if (fVector2d) {
1915 fVectorPH = new TObjArray();
1916 fPlaPH = new TObjArray();
1917 }
77566f2a 1918
8ec526a4 1919 // Variable
1920 fPHPlace = new Short_t[fTimeMax];
1921 for (Int_t k = 0; k < fTimeMax; k++) {
1922 fPHPlace[k] = -1;
77566f2a 1923 }
8ec526a4 1924 fPHValue = new Float_t[fTimeMax];
1925 for (Int_t k = 0; k < fTimeMax; k++) {
1926 fPHValue[k] = -1.0;
1927 }
77566f2a 1928
1929 }
1930
8ec526a4 1931 if (fPRF2dOn) {
1932
1933 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
1934 ,fNz[2]
1935 ,fNrphi[2]));
77566f2a 1936
8ec526a4 1937 // Calcul the number of Xbins
77566f2a 1938 fNtotal[2] = 0;
1939 ModePadCalibration(2,2);
1940 ModePadFragmentation(0,2,0,2);
8ec526a4 1941 fDetChamb2[2] = fNfragZ[2] * fNfragRphi[2];
1942 if (fDebug == 4) {
1943 AliInfo(Form("For the chamber 2: %d",fDetChamb2[2]));
77566f2a 1944 }
8ec526a4 1945 fNtotal[2] += 6 * 18 * fDetChamb2[2];
77566f2a 1946 ModePadCalibration(0,2);
1947 ModePadFragmentation(0,0,0,2);
8ec526a4 1948 fDetChamb0[2] = fNfragZ[2] * fNfragRphi[2];
1949 if (fDebug == 4) {
1950 AliInfo(Form("For the chamber 0: %d",fDetChamb0[2]));
77566f2a 1951 }
8ec526a4 1952 fNtotal[2] += 6 * 4 * 18 * fDetChamb0[2];
1953 AliInfo(Form("Total number of Xbins: %d",fNtotal[2]));
77566f2a 1954
8ec526a4 1955 // Create the 2D histo
1956 if (fHisto2d) {
1957 CreatePRF2d(fNtotal[2]);
1958 }
1959 if (fVector2d) {
1960 fVectorPRF = new TObjArray();
1961 fPlaPRF = new TObjArray();
1962 }
77566f2a 1963
1964 }
1965
1966 return kTRUE;
1967
1968}
1969
8ec526a4 1970//____________Functions for filling the histos in the code_____________________
77566f2a 1971
8ec526a4 1972//____________Offine tracking in the AliTRDtracker_____________________________
1973Bool_t AliTRDCalibra::ResetTrack()
77566f2a 1974{
1975 //
8ec526a4 1976 // For the offline tracking
1977 // This function will be called in the function
1978 // AliTRDtracker::FollowBackPropagation() at the beginning
1979 // Reset the parameter to know we have a new TRD track
77566f2a 1980 //
1981
1982 fDetectorAliTRDtrack = kFALSE;
1983 return kTRUE;
77566f2a 1984
8ec526a4 1985}
77566f2a 1986
8ec526a4 1987//____________Offline tracking in the AliTRDtracker____________________________
77566f2a 1988Bool_t AliTRDCalibra::UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *t)
1989{
1990 //
8ec526a4 1991 // For the offline tracking
1992 // This function will be called in the function
1993 // AliTRDtracker::FollowBackPropagation() in the loop over the clusters
1994 // of TRD tracks
1995 // Fill the 2D histos or the vectors with the info of the clusters at
1996 // the end of a detectors if the track is "good"
77566f2a 1997 //
1998
8ec526a4 1999 // Get the parameter object
77566f2a 2000 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
2001 if (!parCom) {
2002 AliInfo("Could not get CommonParam");
2003 return kFALSE;
2004 }
2005
2006 // Get the parameter object
2007 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2008 if (!cal) {
2009 AliInfo("Could not get calibDB");
2010 return kFALSE;
2011 }
2012
8ec526a4 2013 // Localisation of the detector
77566f2a 2014 Int_t detector = cl->GetDetector();
8ec526a4 2015 Int_t chamber = GetChamber(detector);
2016 Int_t plane = GetPlane(detector);
77566f2a 2017
8ec526a4 2018 // Fill the infos for the previous clusters if not the same
2019 // detector anymore or if not the same track
2020 if (((detector != fDetectorPreviousTrack) || (!fDetectorAliTRDtrack)) &&
2021 (fDetectorPreviousTrack != -1)) {
2022
2023 fNumberTrack++;
77566f2a 2024
8ec526a4 2025 // If the same track, then look if the previous detector is in
2026 // the same plane, if yes: not a good track
2027 if (fDetectorAliTRDtrack &&
2028 (GetPlane(detector) <= GetPlane(fDetectorPreviousTrack))) {
77566f2a 2029 fGoodTrack = kFALSE;
2030 }
2031
8ec526a4 2032 // Fill only if the track doesn't touch a masked pad or doesn't
2033 // appear in the middle (fGoodTrack)
2034 if (fGoodTrack) {
77566f2a 2035
8ec526a4 2036 // Gain calibration
2037 if (fCH2dOn) {
77566f2a 2038 FillTheInfoOfTheTrackCH();
8ec526a4 2039 }
77566f2a 2040
8ec526a4 2041 // PH calibration
2042 if (fPH2dOn) {
77566f2a 2043 FillTheInfoOfTheTrackPH();
8ec526a4 2044 }
77566f2a 2045
8ec526a4 2046 } // if a good track
77566f2a 2047
8ec526a4 2048 ResetfVariables();
77566f2a 2049
8ec526a4 2050 } // Fill at the end the charge
77566f2a 2051
8ec526a4 2052 // Calcul the position of the detector
2053 if (detector != fDetectorPreviousTrack) {
2054 LocalisationDetectorXbins(detector);
77566f2a 2055 }
2056
8ec526a4 2057 // Reset the good track for the PRF
77566f2a 2058 Bool_t good = kTRUE;
2059
8ec526a4 2060 // Localisation of the cluster
2061 Double_t pos[3] = { 0.0, 0.0, 0.0 };
77566f2a 2062 pos[0] = cl->GetX();
2063 pos[1] = cl->GetY();
2064 pos[2] = cl->GetZ();
8ec526a4 2065 Int_t time = cl->GetLocalTimeBin();
2066
2067 // Reset the detector
2068 fDetectorPreviousTrack = detector;
2069 fDetectorAliTRDtrack = kTRUE;
2070
2071 // Position of the cluster
2072 AliTRDpadPlane *padplane = parCom->GetPadPlane(plane,chamber);
2073 Int_t row = padplane->GetPadRowNumber(pos[2]);
2074 Double_t offsetz = padplane->GetPadRowOffset(row,pos[2]);
2075 Double_t offsettilt = padplane->GetTiltOffset(offsetz);
2076 Int_t col = padplane->GetPadColNumber(pos[1] + offsettilt,offsetz);
2077
2078 // See if we are not near a masked pad
2079 if (!IsPadOn(detector,col,row)) {
2080 good = kFALSE;
77566f2a 2081 fGoodTrack = kFALSE;
2082 }
2083
8ec526a4 2084 if (col > 0) {
2085 if (!IsPadOn(detector,col-1,row)) {
77566f2a 2086 fGoodTrack = kFALSE;
8ec526a4 2087 good = kFALSE;
77566f2a 2088 }
2089 }
2090
8ec526a4 2091 if (col < 143) {
2092 if (!IsPadOn(detector,col+1,row)) {
77566f2a 2093 fGoodTrack = kFALSE;
8ec526a4 2094 good = kFALSE;
77566f2a 2095 }
2096 }
2097
8ec526a4 2098 // Row of the cluster and position in the pad groups
2099 Int_t posr[3] = { 0, 0, 0 };
2100 if ((fCH2dOn) && (fNnZ[0] != 0)) {
2101 posr[0] = (Int_t) row / fNnZ[0];
2102 }
2103 if ((fPH2dOn) && (fNnZ[1] != 0)) {
2104 posr[1] = (Int_t) row / fNnZ[1];
2105 }
2106 if ((fPRF2dOn) && (fNnZ[2] != 0)) {
2107 posr[2] = (Int_t) row / fNnZ[2];
2108 }
77566f2a 2109
8ec526a4 2110 // Col of the cluster and position in the pad groups
2111 Int_t posc[3] = { 0, 0, 0 };
2112 if ((fCH2dOn) && (fNnRphi[0] != 0)) {
2113 posc[0] = (Int_t) col / fNnRphi[0];
2114 }
2115 if ((fPH2dOn) && (fNnRphi[1] != 0)) {
2116 posc[1] = (Int_t) col / fNnRphi[1];
2117 }
2118 if ((fPRF2dOn) && (fNnRphi[2] != 0)) {
2119 posc[2] = (Int_t) col / fNnRphi[2];
2120 }
77566f2a 2121
8ec526a4 2122 // Charge in the cluster
2123 // For the moment take the abs
2124 Float_t q = TMath::Abs(cl->GetQ());
2125 Short_t *signals = cl->GetSignals();
77566f2a 2126
8ec526a4 2127 // Correction due to the track angle
2128 Float_t correction = 1.0;
77566f2a 2129 Float_t normalisation = 6.67;
8ec526a4 2130 if ((q >0) && (t->GetNdedx() > 0)) {
2131 correction = t->GetClusterdQdl((t->GetNdedx() - 1)) / (q * normalisation);
77566f2a 2132 }
77566f2a 2133
8ec526a4 2134 // Fill the fAmpTotal with the charge
2135 if (fCH2dOn) {
2136 if (!fTraMaxPad){
2137 fAmpTotal[(Int_t) (posc[0]*fNfragZ[0]+posr[0])] += q * correction;
2138 }
2139 else {
2140 fAmpTotal[(Int_t) (posc[0]*fNfragZ[0]+posr[0])] += ((Float_t) signals[3]) * correction;
2141 }
2142 }
2143
2144 // Fill the fPHPlace and value
2145 if (fPH2dOn) {
2146 fPHPlace[time] = posc[1]*fNfragZ[1]+posr[1];
2147 if (!fTraMaxPad) {
2148 fPHValue[time] = q * correction;
2149 }
2150 else {
2151 fPHValue[time] = ((Float_t) signals[3]) * correction;
2152 }
2153 }
77566f2a 2154
8ec526a4 2155 // Fill direct the PRF
2156 if ((fPRF2dOn) && (good)) {
77566f2a 2157
8ec526a4 2158 Float_t yminus = 0.0;
77566f2a 2159 Float_t xcenter = 0.0;
2160 Float_t ycenter = 0.0;
8ec526a4 2161 Float_t ymax = 0.0;
2162 Bool_t echec = kFALSE;
77566f2a 2163
8ec526a4 2164 if ((cl->From3pad()) && (!cl->IsUsed())) {
77566f2a 2165
8ec526a4 2166 // Center 3 balanced
2167 if ((((Float_t) signals[3]) > fThresholdClusterPRF2) &&
2168 (((Float_t) signals[2]) > fThresholdClusterPRF2) &&
2169 (((Float_t) signals[4]) > fThresholdClusterPRF2) &&
2170 (((Float_t) signals[1]) < fThresholdClusterPRF1) &&
2171 (((Float_t) signals[5]) < fThresholdClusterPRF1) &&
2172 (q * correction > 130.0)) {
2173 // Col correspond to signals[3]
2174 if (fCenterOfflineCluster) {
2175 xcenter = cl->GetCenter();
2176 }
2177 else {
2178 // Security of the denomiateur is 0
2179 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
2180 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
2181 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
2182 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
2183 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
2184 }
2185 else {
2186 xcenter = -100.0;
77566f2a 2187 }
77566f2a 2188 }
8ec526a4 2189 if ((xcenter > -0.5) && (xcenter < 0.5)) {
2190 ycenter = (Float_t) (((Float_t) signals[3])
2191 / (((Float_t) signals[2]) + ((Float_t) signals[3]) + (((Float_t) signals[4]))));
2192 yminus = (Float_t) (((Float_t) signals[2])
2193 / (((Float_t) signals[2]) + ((Float_t) signals[3]) + (((Float_t) signals[4]))));
2194 ymax = (Float_t) (((Float_t) signals[4])
2195 / (((Float_t) signals[2]) + ((Float_t) signals[3]) + (((Float_t) signals[4]))));
2196 if ((ycenter > 0.485) &&
2197 (TMath::Abs(((Float_t) signals[2]) + ((Float_t) signals[3]) + (((Float_t) signals[4])) - q) < 8.0)) {
2198 echec = kTRUE;
2199 }
77566f2a 2200 }
2201 }
2202
8ec526a4 2203 // Fill only if it is in the drift region!
2204 if ((((Float_t) (((Float_t) time) / fSf)) > 0.3) && (echec)) {
2205 if (fHisto2d) {
2206 fPRF2d->Fill((fXbins[2]+posc[2]*fNfragZ[2]+posr[2]+0.5),xcenter,ycenter);
2207 if (xcenter < 0.0) {
2208 fPRF2d->Fill((fXbins[2]+posc[2]*fNfragZ[2]+posr[2]+0.5),-(xcenter+1.0),yminus);
2209 }
2210 if (xcenter > 0.0) {
2211 fPRF2d->Fill((fXbins[2]+posc[2]*fNfragZ[2]+posr[2]+0.5),1.0-xcenter,ymax);
2212 }
77566f2a 2213 }
8ec526a4 2214 if (fVector2d) {
2215 UpdateVectorPRF(fXbins[2]+posc[2]*fNfragZ[2]+posr[2],xcenter,ycenter);
2216 if (xcenter < 0.0) {
2217 UpdateVectorPRF(fXbins[2]+posc[2]*fNfragZ[2]+posr[2],-(xcenter+1.0),yminus);
2218 }
2219 if (xcenter > 0.0) {
2220 UpdateVectorPRF(fXbins[2]+posc[2]*fNfragZ[2]+posr[2],1.0-xcenter,ymax);
2221 }
77566f2a 2222 }
8ec526a4 2223 } // If in the drift region
2224
2225 } // Cluster isole
2226
2227 } // PRF2dOn
77566f2a 2228
2229 return kTRUE;
2230
2231}
2232
8ec526a4 2233//____________Online trackling in AliTRDtrigger________________________________
2234Bool_t AliTRDCalibra::UpdateHistogramcm(AliTRDmcmTracklet *trk)
77566f2a 2235{
2236 //
8ec526a4 2237 // For the tracking
2238 // This function will be called in the function AliTRDtrigger::TestTracklet
2239 // before applying the pt cut on the tracklets
2240 // Fill the infos for the tracklets fTrkTest if the tracklets is "good"
77566f2a 2241 //
2242
8ec526a4 2243 // Localisation of the Xbins involved
2244 Int_t idect = trk->GetDetector();
2245 LocalisationDetectorXbins(idect);
77566f2a 2246
2247 // Get the parameter object
8ec526a4 2248 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
77566f2a 2249 if (!cal) {
2250 AliInfo("Could not get calibDB");
2251 return kFALSE;
2252 }
2253
8ec526a4 2254 // Reset
2255 ResetfVariables();
2256
2257 // Row of the tracklet and position in the pad groups
2258 Int_t row = trk->GetRow();
2259 Int_t posr[3] = { 0, 0, 0 };
2260 if ((fCH2dOn) && (fNnZ[0] != 0)) {
2261 posr[0] = (Int_t) row / fNnZ[0];
2262 }
2263 if ((fPH2dOn) && (fNnZ[1] != 0)) {
2264 posr[1] = (Int_t) row / fNnZ[1];
2265 }
2266 if ((fPRF2dOn) && (fNnZ[2] != 0)) {
2267 posr[2] = (Int_t) row / fNnZ[2];
2268 }
2269
2270 // Eventuelle correction due to track angle in z direction
77566f2a 2271 Float_t correction = 1.0;
8ec526a4 2272 if (fMcmCorrectAngle) {
2273 Float_t z = trk->GetRowz();
2274 Float_t r = trk->GetTime0();
2275 correction = r / TMath::Sqrt((r*r+z*z));
77566f2a 2276 }
8ec526a4 2277
2278 // Boucle sur les clusters
2279 // Condition on number of cluster: don't come from the middle of the detector
2280 if (trk->GetNclusters() >= fNumberClusters) {
2281
2282 for (Int_t icl = 0; icl < trk->GetNclusters(); icl++) {
2283
2284 Float_t amp[3] = { 0.0, 0.0, 0.0 };
2285 Int_t time = trk->GetClusterTime(icl);
2286 Int_t col = trk->GetClusterCol(icl);
77566f2a 2287
8ec526a4 2288 amp[0] = trk->GetClusterADC(icl)[0] * correction;
2289 amp[1] = trk->GetClusterADC(icl)[1] * correction;
2290 amp[2] = trk->GetClusterADC(icl)[2] * correction;
77566f2a 2291
8ec526a4 2292 if ((amp[0] < 0.0) ||
2293 (amp[1] < 0.0) ||
2294 (amp[2] < 0.0)) {
2295 continue;
2296 }
2297
2298 // Col of cluster and position in the pad groups
2299 Int_t posc[3] = { 0, 0, 0 };
2300 if ((fCH2dOn) && (fNnRphi[0] != 0)) {
2301 posc[0] = (Int_t) col / fNnRphi[0];
2302 }
2303 if ((fPH2dOn) && (fNnRphi[1] != 0)) {
2304 posc[1] = (Int_t) col / fNnRphi[1];
2305 }
2306 if ((fPRF2dOn) && (fNnRphi[2] != 0)) {
2307 posc[2] = (Int_t) col / fNnRphi[2];
2308 }
2309
2310 // See if we are not near a masked pad
77566f2a 2311 Bool_t good = kTRUE;
8ec526a4 2312 if (!IsPadOn(idect,col,row)) {
77566f2a 2313 fGoodTrack = kFALSE;
8ec526a4 2314 good = kFALSE;
77566f2a 2315 }
8ec526a4 2316
2317 if (col > 0) {
2318 if (!IsPadOn(idect,col-1,row)) {
77566f2a 2319 fGoodTrack = kFALSE;
8ec526a4 2320 good = kFALSE;
77566f2a 2321 }
2322 }
2323
8ec526a4 2324 if (col < 143) {
2325 if (!IsPadOn(idect,col+1,row)) {
77566f2a 2326 fGoodTrack = kFALSE;
8ec526a4 2327 good = kFALSE;
77566f2a 2328 }
2329 }
77566f2a 2330
8ec526a4 2331 // Total spectrum
2332 if (fPH2dOn) {
2333 fPHPlace[time] = posc[1] * fNfragZ[1] + posr[1];
77566f2a 2334 }
77566f2a 2335
8ec526a4 2336 if (!fTraMaxPad) {
2337 if (fCH2dOn) {
2338 fAmpTotal[(Int_t) (posc[0]*fNfragZ[0]+posr[0])] += (Float_t) (amp[0]+amp[1]+amp[2]);
2339 }
2340 if (fPH2dOn) {
2341 fPHValue[time] = (Float_t) (amp[0]+amp[1]+amp[2]);
2342 }
2343 }
2344 else {
2345 if (fCH2dOn) {
2346 fAmpTotal[(Int_t) (posc[0]*fNfragZ[0]+posr[0])] += (Float_t) amp[1];
2347 }
2348 if (fPH2dOn) {
2349 fPHValue[time] = amp[1];
2350 }
77566f2a 2351 }
2352
8ec526a4 2353 // Fill PRF direct
2354 if (fPRF2dOn && good) {
2355 if ((amp[0] > fThresholdClusterPRF2) &&
2356 (amp[1] > fThresholdClusterPRF2) &&
2357 (amp[2] > fThresholdClusterPRF2) &&
2358 ((amp[0]+amp[1]+amp[2]) > 130.0)) {
2359 // Security of the denomiateur is 0
2360 if ((((Float_t) (((Float_t) amp[1]) * ((Float_t) amp[1])))
2361 / ((Float_t) (((Float_t) amp[0]) * ((Float_t) amp[2])))) != 1.0) {
2362 Float_t xcenter = 0.5 * (TMath::Log(amp[2] / amp[0]))
2363 / (TMath::Log((amp[1]*amp[1]) / (amp[0]*amp[2])));
2364 Float_t ycenter = amp[1] / (amp[0] + amp[1] + amp[2]);
2365 if ((xcenter > -0.5) &&
2366 (xcenter < 0.5) &&
2367 (ycenter > 0.485)) {
2368 Float_t yminus = amp[0] / (amp[0]+amp[1]+amp[2]);
2369 Float_t ymax = amp[2] / (amp[0]+amp[1]+amp[2]);
2370 // Fill only if it is in the drift region!
2371 if (((Float_t) time / fSf) > 0.3) {
2372 if (fHisto2d) {
2373 fPRF2d->Fill((fXbins[2]+posc[2]*fNfragZ[2]+posr[2]+0.5),xcenter,ycenter);
2374 if (xcenter < 0.0) {
2375 fPRF2d->Fill((fXbins[2]+posc[2]*fNfragZ[2]+posr[2]+0.5),-(xcenter+1.0),yminus);
2376 }
2377 if (xcenter > 0.0) {
2378 fPRF2d->Fill((fXbins[2]+posc[2]*fNfragZ[2]+posr[2]+0.5),(1.0-xcenter),ymax);
2379 }
2380 }
2381 if (fVector2d) {
2382 UpdateVectorPRF((fXbins[2]+posc[2]*fNfragZ[2]+posr[2]),xcenter,ycenter);
2383 if (xcenter < 0.0) {
2384 UpdateVectorPRF(fXbins[2]+posc[2]*fNfragZ[2]+posr[2],-(xcenter+1.0),yminus);
2385 }
2386 if (xcenter > 0.0) {
2387 UpdateVectorPRF(fXbins[2]+posc[2]*fNfragZ[2]+posr[2],(1.0-xcenter),ymax);
77566f2a 2388 }
77566f2a 2389 }
2390 }
2391 }
2392 }
2393 }
2394 }
2395
8ec526a4 2396 } // Boucle clusters
77566f2a 2397
8ec526a4 2398 // Fill the charge
2399 if (fCH2dOn && fGoodTrack) {
77566f2a 2400 FillTheInfoOfTheTrackCH();
8ec526a4 2401 }
77566f2a 2402
8ec526a4 2403 // PH calibration
2404 if (fPH2dOn && fGoodTrack) {
2405 FillTheInfoOfTheTrackPH();
2406 }
77566f2a 2407
8ec526a4 2408 } // Condition on number of clusters
2409
77566f2a 2410 return kTRUE;
2411
2412}
2413
8ec526a4 2414//____________Functions for seeing if the pad is really okey___________________
77566f2a 2415
8ec526a4 2416//_____________________________________________________________________________
2417Bool_t AliTRDCalibra::SetModeCalibrationFromTObject(TObject *object, Int_t i)
77566f2a 2418{
2419 //
8ec526a4 2420 // Set fNz[i] and fNrphi[i] of the AliTRDCalibra::Instance()
2421 // corresponding to the given TObject
77566f2a 2422 //
8ec526a4 2423
2424 const char *nametitle = object->GetTitle();
2425
2426 // Some patterns
2427 const Char_t *patternz0 = "Nz0";
2428 const Char_t *patternz1 = "Nz1";
2429 const Char_t *patternz2 = "Nz2";
2430 const Char_t *patternz3 = "Nz3";
2431 const Char_t *patternz4 = "Nz4";
2432 const Char_t *patternrphi0 = "Nrphi0";
2433 const Char_t *patternrphi1 = "Nrphi1";
2434 const Char_t *patternrphi2 = "Nrphi2";
2435 const Char_t *patternrphi3 = "Nrphi3";
2436 const Char_t *patternrphi4 = "Nrphi4";
2437 const Char_t *patternrphi5 = "Nrphi5";
2438 const Char_t *patternrphi6 = "Nrphi6";
2439
2440 UShort_t testz = 0;
2441 UShort_t testrphi = 0;
2442
2443 // Nz mode
2444 if (strstr(nametitle,patternz0)) {
2445 testz++;
2446 fNz[i] = 0;
2447 }
2448 if (strstr(nametitle,patternz1)) {
2449 testz++;
2450 fNz[i] = 1;
2451 }
2452 if (strstr(nametitle,patternz2)) {
2453 testz++;
2454 fNz[i] = 2;
2455 }
2456 if (strstr(nametitle,patternz3)) {
2457 testz++;
2458 fNz[i] = 3;
2459 }
2460 if (strstr(nametitle,patternz4)) {
2461 testz++;
2462 fNz[i] = 4;
2463 }
2464
2465 // Nrphi mode
2466 if (strstr(nametitle,patternrphi0)) {
2467 testrphi++;
2468 fNrphi[i] = 0;
2469 }
2470 if (strstr(nametitle,patternrphi1)) {
2471 testrphi++;
2472 fNrphi[i] = 1;
2473 }
2474 if (strstr(nametitle,patternrphi2)) {
2475 testrphi++;
2476 fNrphi[i] = 2;
2477 }
2478 if (strstr(nametitle,patternrphi3)) {
2479 testrphi++;
2480 fNrphi[i] = 3;
2481 }
2482 if (strstr(nametitle,patternrphi4)) {
2483 testrphi++;
2484 fNrphi[i] = 4;
2485 }
2486 if (strstr(nametitle,patternrphi5)) {
2487 testrphi++;
2488 fNrphi[i] = 5;
2489 }
2490 if (strstr(nametitle,patternrphi6)) {
2491 testrphi++;
2492 fNrphi[i] = 6;
2493 }
2494
2495 // Look if all is okey
2496 if ((testz == 1) &&
2497 (testrphi == 1)) {
2498 return kTRUE;
2499 }
2500 else {
2501 fNrphi[i] = 0;
2502 fNz[i] = 0;
2503 return kFALSE;
2504 }
77566f2a 2505
8ec526a4 2506}
2507
2508//_____________________________________________________________________________
2509Bool_t AliTRDCalibra::IsPadOn(Int_t detector, Int_t col, Int_t row) const
2510{
2511 //
2512 // Look in the choosen database if the pad is On.
2513 // If no the track will be "not good"
2514 //
77566f2a 2515
2516 // Get the parameter object
8ec526a4 2517 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
77566f2a 2518 if (!cal) {
2519 AliInfo("Could not get calibDB");
2520 return kFALSE;
2521 }
2522
8ec526a4 2523 Int_t npads = 18;
2524 Int_t colmcm = (Int_t) col / npads;
77566f2a 2525
8ec526a4 2526 if (!cal->IsChamberInstalled(detector) ||
2527 cal->IsChamberMasked(detector) ||
2528 cal->IsMCMMasked(detector,colmcm,row) ||
2529 cal->IsPadMasked(detector,col,row)) {
77566f2a 2530 return kFALSE;
2531 }
8ec526a4 2532 else {
2533 return kTRUE;
2534 }
77566f2a 2535
2536}
2537
8ec526a4 2538//____________Functions for plotting the 2D____________________________________
77566f2a 2539
8ec526a4 2540//_____________________________________________________________________________
77566f2a 2541void AliTRDCalibra::Plot2d()
2542{
2543 //
2544 // Plot the 2D histos
2545 //
2546
8ec526a4 2547 if (fCH2dOn) {
2548 PlotCH2d();
2549 }
2550 if (fPH2dOn) {
2551 PlotPH2d();
2552 }
2553 if (fPRF2dOn) {
2554 PlotPRF2d();
2555 }
77566f2a 2556
2557}
77566f2a 2558
8ec526a4 2559//____________Writing the 2D___________________________________________________
2560
2561//_____________________________________________________________________________
77566f2a 2562Bool_t AliTRDCalibra::Write2d()
2563{
2564 //
8ec526a4 2565 // Write the 2D histograms or the vectors converted in trees in the file
2566 // "TRD.calibration.root"
77566f2a 2567 //
2568
2569 TFile *fout = TFile::Open(fWriteName,"RECREATE");
8ec526a4 2570 // Check if the file could be opened
77566f2a 2571 if (!fout || !fout->IsOpen()) {
2572 AliInfo("No File found!");
2573 return kFALSE;
2574 }
8ec526a4 2575 AliInfo(Form("Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
2576 ,fNumberTrack
2577 ,fNumberUsedCh[0]
2578 ,fNumberUsedCh[1]
2579 ,fNumberUsedPh[0]
2580 ,fNumberUsedPh[1]));
77566f2a 2581
2582 TStopwatch stopwatch;
2583 stopwatch.Start();
2584 AliInfo("Write2d");
8ec526a4 2585
2586 if ((fCH2dOn ) && (fWrite[0])) {
2587 if (fHisto2d) {
2588 fout->WriteTObject(fCH2d);
2589 }
2590 if (fVector2d) {
2591 TString name("Nz");
2592 name += fNz[0];
2593 name += "Nrphi";
2594 name += fNrphi[0];
2595 TTree *treeCH2d = ConvertVectorCTTreeHisto(fVectorCH,fPlaCH,"treeCH2d",(const char *) name);
77566f2a 2596 fout->WriteTObject(treeCH2d);
2597 }
2598 }
8ec526a4 2599 if ((fPH2dOn ) && (fWrite[1])) {
2600 if (fHisto2d) {
2601 fout->WriteTObject(fPH2d);
2602 }
2603 if (fVector2d) {
2604 TString name("Nz");
2605 name += fNz[1];
2606 name += "Nrphi";
2607 name += fNrphi[1];
2608 TTree *treePH2d = ConvertVectorPTreeHisto(fVectorPH,fPlaPH,"treePH2d",(const char *) name);
77566f2a 2609 fout->WriteTObject(treePH2d);
2610 }
2611 }
8ec526a4 2612 if ((fPRF2dOn ) && (fWrite[2])) {
2613 if (fHisto2d) {
2614 fout->WriteTObject(fPRF2d);
2615 }
2616 if (fVector2d) {
2617 TString name("Nz");
2618 name += fNz[2];
2619 name += "Nrphi";
2620 name += fNrphi[2];
2621 TTree *treePRF2d = ConvertVectorPTreeHisto(fVectorPRF,fPlaPRF,"treePRF2d",(const char *) name);
77566f2a 2622 fout->WriteTObject(treePRF2d);
2623 }
2624 }
2625
2626 fout->Close();
2627
8ec526a4 2628 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs"
2629 ,stopwatch.RealTime(),stopwatch.CpuTime()));
2630
77566f2a 2631 return kTRUE;
2632
2633}
8ec526a4 2634
2635//_____________________________________________________________________________
2636AliTRDCalDet *AliTRDCalibra::CreateDetObjectTree(TTree *tree, Int_t i)
77566f2a 2637{
2638 //
8ec526a4 2639 // It creates the AliTRDCalDet object from the tree of the coefficient
2640 // for the calibration i (i != 2)
77566f2a 2641 // It takes the mean value of the coefficients per detector
2642 // This object has to be written in the database
2643 //
2644
8ec526a4 2645 // Create the DetObject
77566f2a 2646 AliTRDCalDet *object = 0x0;
8ec526a4 2647 if (i == 0) {
2648 object = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
2649 }
2650 if (i == 1) {
2651 object = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2652 }
2653 else {
2654 object = new AliTRDCalDet("ChamberT0","T0 (detector value)");
2655 }
77566f2a 2656
8ec526a4 2657 // Read the Tree
2658 Int_t detector = -1;
77566f2a 2659 Float_t values[2304];
2660 tree->SetBranchAddress("detector",&detector);
8ec526a4 2661 if (i == 0) {
2662 tree->SetBranchAddress("gainPad",values);
2663 }
2664 if (i == 1) {
2665 tree->SetBranchAddress("vdrift" ,values);
2666 }
2667 if (i == 3) {
2668 tree->SetBranchAddress("t0" ,values);
2669 }
77566f2a 2670
8ec526a4 2671 // For calculating the mean
2672 Float_t mean = 0.0;
2673 Int_t nto = 0;
2674 Int_t numberofentries = tree->GetEntries();
77566f2a 2675
8ec526a4 2676 if (numberofentries != 540) {
2677 AliInfo("The tree is not complete");
2678 }
77566f2a 2679
8ec526a4 2680 for (Int_t det = 0; det < numberofentries; ++det) {
77566f2a 2681 tree->GetEntry(det);
8ec526a4 2682 if (GetChamber(detector) == 2) {
2683 nto = 1728;
2684 }
2685 else {
2686 nto = 2304;
2687 }
77566f2a 2688 mean = 0.0;
8ec526a4 2689 for (Int_t k = 0; k < nto; k++) {
2690 mean += TMath::Abs(values[k]) / nto;
2691 }
77566f2a 2692 object->SetValue(detector,mean);
2693 }
8ec526a4 2694
77566f2a 2695 return object;
8ec526a4 2696
77566f2a 2697}
8ec526a4 2698
2699//_____________________________________________________________________________
2700TObject *AliTRDCalibra::CreatePadObjectTree(TTree *tree, Int_t i
2701 , AliTRDCalDet *detobject)
77566f2a 2702{
2703 //
8ec526a4 2704 // It Creates the AliTRDCalPad object from the tree of the
2705 // coefficient for the calibration i (i != 2)
2706 // You need first to create the object for the detectors,
2707 // where the mean value is put.
77566f2a 2708 // This object has to be written in the database
2709 //
2710
8ec526a4 2711 // Create the DetObject
77566f2a 2712 AliTRDCalPad *object = 0x0;
8ec526a4 2713 if (i == 0) {
2714 object = new AliTRDCalPad("GainFactor","GainFactor (local variations)");
2715 }
2716 if (i == 1) {
2717 object = new AliTRDCalPad("LocalVdrift","TRD drift velocities (local variations)");
2718 }
2719 else {
2720 object = new AliTRDCalPad("LocalT0","T0 (local variations)");
2721 }
77566f2a 2722
8ec526a4 2723 // Read the Tree
2724 Int_t detector = -1;
77566f2a 2725 Float_t values[2304];
2726 tree->SetBranchAddress("detector",&detector);
8ec526a4 2727 if (i == 0) {
2728 tree->SetBranchAddress("gainPad",values);
2729 }
2730 if (i == 1) {
2731 tree->SetBranchAddress("vdrift" ,values);
2732 }
2733 if (i == 3) {
2734 tree->SetBranchAddress("t0" ,values);
2735 }
77566f2a 2736
8ec526a4 2737 // Variables
2738 Float_t mean = 0.0;
2739 Int_t numberofentries = tree->GetEntries();
77566f2a 2740
8ec526a4 2741 if (numberofentries != 540) {
2742 AliInfo("The tree is not complete");
2743 }
77566f2a 2744
8ec526a4 2745 for (Int_t det = 0; det < numberofentries; ++det) {
77566f2a 2746 tree->GetEntry(det);
2747 AliTRDCalROC *calROC = object->GetCalROC(detector);
2748 mean = detobject->GetValue(detector);
8ec526a4 2749 if (mean == 0) {
2750 continue;
2751 }
77566f2a 2752 Int_t rowMax = calROC->GetNrows();
2753 Int_t colMax = calROC->GetNcols();
8ec526a4 2754 for (Int_t row = 0; row < rowMax; ++row) {
2755 for (Int_t col = 0; col < colMax; ++col) {
e5c60cc7 2756
2757 calROC->SetValue(col,row,TMath::Abs(values[(Int_t) (col*rowMax+row)])/mean);
2758
8ec526a4 2759 } // Col
2760 } // Row
77566f2a 2761 }
8ec526a4 2762
77566f2a 2763 return object;
8ec526a4 2764
77566f2a 2765}
8ec526a4 2766
2767//_____________________________________________________________________________
2768TObject *AliTRDCalibra::CreatePadObjectTree(TTree *tree)
77566f2a 2769{
2770 //
8ec526a4 2771 // It Creates the AliTRDCalPad object from the tree of the
2772 // coefficient for the calibration PRF (i = 2)
77566f2a 2773 // This object has to be written in the database
2774 //
2775
8ec526a4 2776 // Create the DetObject
77566f2a 2777 AliTRDCalPad *object = new AliTRDCalPad("PRFWidth","PRFWidth");
2778
8ec526a4 2779 // Read the Tree
2780 Int_t detector = -1;
77566f2a 2781 Float_t values[2304];
2782 tree->SetBranchAddress("detector",&detector);
8ec526a4 2783 tree->SetBranchAddress("width" ,values);
77566f2a 2784
8ec526a4 2785 // Variables
77566f2a 2786 Int_t numberofentries = tree->GetEntries();
2787
8ec526a4 2788 if (numberofentries != 540) {
2789 AliInfo("The tree is not complete");
2790 }
77566f2a 2791
8ec526a4 2792 for (Int_t det = 0; det < numberofentries; ++det) {
77566f2a 2793 tree->GetEntry(det);
2794 AliTRDCalROC *calROC = object->GetCalROC(detector);
2795 Int_t rowMax = calROC->GetNrows();
2796 Int_t colMax = calROC->GetNcols();
8ec526a4 2797 for (Int_t row = 0; row < rowMax; ++row) {
2798 for (Int_t col = 0; col < colMax; ++col) {
77566f2a 2799 calROC->SetValue(col,row,TMath::Abs(values[(Int_t) (col*rowMax+row)]));
8ec526a4 2800 } // Col
2801 } // Row
77566f2a 2802 }
8ec526a4 2803
77566f2a 2804 return object;
8ec526a4 2805
77566f2a 2806}
8ec526a4 2807
2808//_____________________________________________________________________________
2809void AliTRDCalibra::SetRelativeScale(Float_t RelativeScale)
77566f2a 2810{
2811 //
8ec526a4 2812 // Set the factor that will divide the deposited charge
2813 // to fit in the histo range [0,300]
77566f2a 2814 //
77566f2a 2815
8ec526a4 2816 if (RelativeScale > 0.0) {
2817 fRelativeScale = RelativeScale;
2818 }
2819 else {
2820 AliInfo("RelativeScale must be strict positif!");
2821 }
2822
2823}
2824
2825//_____________________________________________________________________________
2826void AliTRDCalibra::SetNz(Int_t i, Short_t Nz)
2827{
2828 //
2829 // Set the mode of calibration group in the z direction for the parameter i
2830 //
2831
2832 if ((Nz >= 0) &&
2833 (Nz < 5)) {
2834 fNz[i] = Nz;
2835 }
2836 else {
2837 AliInfo("You have to choose between 0 and 4");
2838 }
2839
2840}
2841
2842//_____________________________________________________________________________
2843void AliTRDCalibra::SetNrphi(Int_t i, Short_t Nrphi)
2844{
2845 //
2846 // Set the mode of calibration group in the rphi direction for the parameter i
2847 //
77566f2a 2848
8ec526a4 2849 if ((Nrphi >= 0) &&
2850 (Nrphi < 7)) {
2851 fNrphi[i] = Nrphi;
2852 }
2853 else {
2854 AliInfo("You have to choose between 0 and 6");
2855 }
2856
2857}
2858
2859//_____________________________________________________________________________
2860void AliTRDCalibra::SetPeriodeFitPH(Int_t periodeFitPH)
2861{
2862 //
2863 // Set FitPH if 1 then each detector will be fitted
2864 //
2865
2866 if (periodeFitPH > 0) {
2867 fFitPHPeriode = periodeFitPH;
2868 }
2869 else {
2870 AliInfo("periodeFitPH must be higher than 0!");
2871 }
2872
2873}
2874
2875//_____________________________________________________________________________
2876void AliTRDCalibra::SetBeginFitCharge(Float_t beginFitCharge)
2877{
2878 //
2879 // The fit of the deposited charge distribution begins at
2880 // histo->Mean()/beginFitCharge
2881 // You can here set beginFitCharge
2882 //
2883
2884 if (beginFitCharge > 0) {
2885 fBeginFitCharge = beginFitCharge;
2886 }
2887 else {
2888 AliInfo("beginFitCharge must be strict positif!");
2889 }
2890
2891}
2892
2893//_____________________________________________________________________________
2894void AliTRDCalibra::SetT0Shift(Float_t t0Shift)
2895{
2896 //
2897 // The t0 calculated with the maximum positif slope is shift from t0Shift
2898 // You can here set t0Shift
2899 //
2900
2901 if (t0Shift > 0) {
2902 fT0Shift = t0Shift;
2903 }
2904 else {
2905 AliInfo("t0Shift must be strict positif!");
2906 }
2907
2908}
2909
2910//_____________________________________________________________________________
2911void AliTRDCalibra::SetRangeFitPRF(Float_t rangeFitPRF)
2912{
2913 //
2914 // The fit of the PRF is from -rangeFitPRF to rangeFitPRF
2915 // You can here set rangeFitPRF
2916 //
2917
2918 if ((rangeFitPRF > 0) &&
2919 (rangeFitPRF <= 1.0)) {
2920 fRangeFitPRF = rangeFitPRF;
2921 }
2922 else {
2923 AliInfo("rangeFitPRF must be between 0 and 1.0");
2924 }
2925
2926}
2927
2928//_____________________________________________________________________________
2929void AliTRDCalibra::SetRebin(Short_t rebin)
2930{
2931 //
2932 // Rebin with rebin time less bins the Ch histo
2933 // You can set here rebin that should divide the number of bins of CH histo
2934 //
2935
2936 if (rebin > 0) {
2937 fRebin = rebin;
2938 AliInfo("You have to be sure that fRebin divides fNumberBinCharge used!");
2939 }
2940 else {
2941 AliInfo("You have to choose a positiv value!");
2942 }
2943
2944}
2945
2946//_____________________________________________________________________________
2947TTree *AliTRDCalibra::Sum2Trees(const Char_t *filename1
2948 , const Char_t *filename2
2949 , const Char_t *variablecali)
2950{
2951 //
2952 // It returns the sum of two trees with the name variablecali
2953 // in the files filenam1 and filename2 equivalent of merging two 2D histos
2954 // The name of the resulting tree is the same as the two input trees
2955 // variablecali can be treeCH2d, treePH2d or treePRF2d
2956 //
2957
2958 // Variables
2959 TChain *treeChain = new TChain(variablecali);
2960 TObjArray *vectorplace = new TObjArray();
2961 TObjArray *where = new TObjArray();
77566f2a 2962
8ec526a4 2963 // First tree
2964 // Take the tree
2965 TFile *file1 = new TFile(filename1,"READ");
77566f2a 2966 TTree *tree1 = (TTree *) file1->Get(variablecali);
8ec526a4 2967
2968 gDirectory = gROOT;
2969
2970 // Take the places
77566f2a 2971 vectorplace = ConvertTreeVector(tree1);
8ec526a4 2972
2973 // Say where it is in tree 1
2974 for (Int_t jui = 0; jui < (Int_t) vectorplace->GetEntriesFast(); jui++) {
2975 AliTRDPlace *placejui = new AliTRDPlace();
2976 placejui->SetPlace(jui);
2977 TObjArray *chainplace = new TObjArray();
2978 chainplace->Add((TObject *) placejui);
2979 where->Add((TObject *) chainplace);
77566f2a 2980 }
8ec526a4 2981
2982 // Add to the chain
77566f2a 2983 treeChain->Add(filename1);
2984 delete file1;
77566f2a 2985
8ec526a4 2986 // Second tree
2987 // Take the tree
2988 TFile *file2 = new TFile(filename2,"READ");
2989 TTree *tree2 = (TTree *) file2->Get(variablecali);
77566f2a 2990
8ec526a4 2991 gDirectory = gROOT;
77566f2a 2992
8ec526a4 2993 // Take the places
2994 TObjArray *vector2 = ConvertTreeVector(tree2);
77566f2a 2995 Int_t j = treeChain->GetEntries();
8ec526a4 2996
2997 for (Int_t jui = 0; jui < (Int_t) vector2->GetEntriesFast(); jui++) {
2998 // Search if already found
2999 Int_t place = SearchInTreeVector(vectorplace,((AliTRDPlace *) vector2->At(jui))->GetPlace());
3000 // Create a new element in the two std vectors
3001 if (place == -1) {
3002 AliTRDPlace *placejjui = new AliTRDPlace();
3003 placejjui->SetPlace((j+jui));
3004 TObjArray *chainplace = new TObjArray();
3005 chainplace->Add((TObject *) placejjui);
3006 vectorplace->Add((TObject *) (vector2->At(jui)));
3007 where->Add((TObject *) chainplace);
3008 }
3009 // Update the element at the place "place" in the std vector whereinthechain
77566f2a 3010 else {
8ec526a4 3011 AliTRDPlace *placejjui = new AliTRDPlace();
3012 placejjui->SetPlace((j+jui));
3013 TObjArray *chainplace = ((TObjArray *) where->At(place));
3014 chainplace->Add((TObject *) placejjui);
3015 where->AddAt((TObject *) chainplace,place);
77566f2a 3016 }
3017 }
8ec526a4 3018
3019 // Add to the Chain
77566f2a 3020 treeChain->Add(filename2);
3021 delete file2;
77566f2a 3022
8ec526a4 3023 // Take care of the profile
3024 const Char_t *pattern = "P";
77566f2a 3025 TTree *tree = 0x0;
3026
8ec526a4 3027 if (!strstr(variablecali,pattern)) {
3028
3029 // Ready to read the chain
77566f2a 3030 TH1F *his = 0x0;
3031 treeChain->SetBranchAddress("histo",&his);
8ec526a4 3032
3033 // Initialise the final tree
3034 Int_t group = -1;
77566f2a 3035 TH1F *histsum = 0x0;
3036
3037 tree = new TTree(variablecali,variablecali);
3038 tree->Branch("groupnumber",&group,"groupnumber/I");
3039 tree->Branch("histo","TH1F",&histsum,32000,0);
8ec526a4 3040
3041 // Init histsum
3042 if (treeChain->GetEntries() < 1) {
3043 return tree1;
3044 }
77566f2a 3045
8ec526a4 3046 for (Int_t h = 0; h < (Int_t) vectorplace->GetEntriesFast(); h++) {
3047 group = ((AliTRDPlace *) vectorplace->At(h))->GetPlace();
3048 TObjArray *chainplace = ((TObjArray *) where->At(h));
3049 treeChain->GetEntry(((AliTRDPlace *) chainplace->At(0))->GetPlace());
77566f2a 3050 //Init for the first time
8ec526a4 3051 if (h == 0) {
3052 histsum = new TH1F("","",his->GetXaxis()->GetNbins()
3053 ,his->GetXaxis()->GetBinLowEdge(1)
3054 ,his->GetXaxis()->GetBinUpEdge(his->GetXaxis()->GetNbins()));
3055 histsum->Sumw2();
77566f2a 3056 }
8ec526a4 3057 // Reset for each new group
77566f2a 3058 histsum->SetEntries(0.0);
8ec526a4 3059 for (Int_t l = 0; l <= histsum->GetXaxis()->GetNbins(); l++) {
77566f2a 3060 histsum->SetBinContent(l,0.0);
3061 histsum->SetBinError(l,0.0);
3062 }
3063 histsum->Add(his,1);
8ec526a4 3064 if ((Int_t) chainplace->GetEntriesFast() > 1) {
3065 for (Int_t s = 1; s < (Int_t) chainplace->GetEntriesFast(); s++) {
3066 treeChain->GetEntry(((AliTRDPlace *) chainplace->At(s))->GetPlace());
77566f2a 3067 histsum->Add(his,1);
3068 }
3069 }
3070 tree->Fill();
3071 }
8ec526a4 3072
77566f2a 3073 }
8ec526a4 3074 else {
3075
3076 // Ready to read the chain
77566f2a 3077 TGraphErrors *his = 0x0;
3078 treeChain->SetBranchAddress("histo",&his);
3079
8ec526a4 3080 // Initialise the final tree
3081 Int_t group = -1;
77566f2a 3082 TGraphErrors *histsum = 0x0;
8ec526a4 3083 Double_t *xref = 0x0;
77566f2a 3084
3085 tree = new TTree(variablecali,variablecali);
3086 tree->Branch("groupnumber",&group,"groupnumber/I");
3087 tree->Branch("histo","TGraphErrors",&histsum,32000,0);
8ec526a4 3088
3089 // Init histsum
3090 if (treeChain->GetEntries() < 1) {
3091 return tree1;
3092 }
3093
3094 for (Int_t h = 0; h < (Int_t) vectorplace->GetEntriesFast(); h++) {
3095
3096 group = ((AliTRDPlace *) vectorplace->At(h))->GetPlace();
3097 TObjArray *chainplace = ((TObjArray *) where->At(h));
3098 treeChain->GetEntry(((AliTRDPlace *) chainplace->At(0))->GetPlace());
77566f2a 3099 //Init or reset for a new group
3100 Int_t nbins = his->GetN();
3101 Double_t *x;
8ec526a4 3102 x = new Double_t[nbins];
77566f2a 3103 xref = his->GetX();
3104 Double_t *ex;
8ec526a4 3105 ex = new Double_t[nbins];
77566f2a 3106 Double_t *y;
8ec526a4 3107 y = new Double_t[nbins];
77566f2a 3108 Double_t *ey;
8ec526a4 3109 ey = new Double_t[nbins];
3110
3111 for (Int_t lo = 0; lo < nbins; lo++) {
3112 x[lo] = xref[lo];
77566f2a 3113 ex[lo] = 0.0;
3114 y[lo] = 0.0;
3115 ey[lo] = 0.0;
3116 }
3117 delete histsum;
3118 histsum = new TGraphErrors(nbins,x,y,ex,ey);
8ec526a4 3119
3120 // Add the first
77566f2a 3121 histsum = AddProfiles(his,histsum);
8ec526a4 3122 if ((Int_t) chainplace->GetEntriesFast() > 1) {
3123 for (Int_t s = 1; s < (Int_t) chainplace->GetEntriesFast(); s++) {
3124 treeChain->GetEntry(((AliTRDPlace *) chainplace->At(s))->GetPlace());
77566f2a 3125 histsum = AddProfiles(his,histsum);
3126 }
3127 }
8ec526a4 3128
77566f2a 3129 tree->Fill();
8ec526a4 3130
77566f2a 3131 }
8ec526a4 3132
77566f2a 3133 }
8ec526a4 3134
77566f2a 3135 return tree;
8ec526a4 3136
77566f2a 3137}
77566f2a 3138
8ec526a4 3139//____________Function fill 2D for the moment out of the code__________________
77566f2a 3140
8ec526a4 3141//____________Function fill 2D all objects from digits_________________________
3142Bool_t AliTRDCalibra::Create2DDiSimOnline(Int_t iev1, Int_t iev2)
77566f2a 3143{
3144 //
8ec526a4 3145 // Only for simulations, after the simulation, create the 2D histos
3146 // from the digits stored in the file "TRD.Digits.root"
77566f2a 3147 // Only for CH and PH
3148 //
77566f2a 3149
8ec526a4 3150 const Int_t kNplan = 6;
3151 const Int_t kNcham = 5;
77566f2a 3152
8ec526a4 3153 // RunLoader and so on
77566f2a 3154 if (gAlice) {
3155 delete gAlice->GetRunLoader();
3156 delete gAlice;
8ec526a4 3157 gAlice = 0;
77566f2a 3158 }
77566f2a 3159
8ec526a4 3160 AliRunLoader *rl = AliRunLoader::Open("galice.root");
77566f2a 3161 if (!rl) {
3162 return kFALSE;
3163 }
8ec526a4 3164
77566f2a 3165 rl->LoadgAlice();
3166 gAlice = rl->GetAliRun();
3167 if (!gAlice) {
3168 return kFALSE;
3169 }
3170
3171 // Import the Trees for the event nEvent in the file
3172 rl->LoadKinematics();
3173 rl->GetEvent(0);
3174 rl->LoadHeader();
3175
8ec526a4 3176 AliLoader *loader = rl->GetLoader("TRDLoader");
77566f2a 3177 if (!loader) {<