]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPC.cxx
code defect corrected
[u/mrichter/AliRoot.git] / TPC / AliTPC.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
4c039060 17
fe4da5cc 18///////////////////////////////////////////////////////////////////////////////
19// //
20// Time Projection Chamber //
21// This class contains the basic functions for the Time Projection Chamber //
22// detector. Functions specific to one particular geometry are //
23// contained in the derived classes //
24// //
25//Begin_Html
26/*
1439f98e 27<img src="picts/AliTPCClass.gif">
fe4da5cc 28*/
29//End_Html
30// //
8c555625 31// //
fe4da5cc 32///////////////////////////////////////////////////////////////////////////////
33
73042f01 34//
35
88cb7938 36#include <Riostream.h>
37#include <stdlib.h>
38
f7a1cc68 39#include <TF2.h>
88cb7938 40#include <TFile.h>
f7a1cc68 41#include <TGeoGlobalMagField.h>
88cb7938 42#include <TInterpreter.h>
fe4da5cc 43#include <TMath.h>
e8d02863 44#include <TMatrixF.h>
fe4da5cc 45#include <TObjectTable.h>
88cb7938 46#include <TParticle.h>
afc42102 47#include <TROOT.h>
88cb7938 48#include <TRandom.h>
f7a1cc68 49#include <TStopwatch.h>
50#include <TString.h>
afc42102 51#include <TSystem.h>
88cb7938 52#include <TTree.h>
f7a1cc68 53#include <TVector.h>
88cb7938 54#include <TVirtualMC.h>
f546a4b4 55#include <TParameter.h>
cc80f89e 56
cc80f89e 57#include "AliDigits.h"
88cb7938 58#include "AliMagF.h"
88cb7938 59#include "AliRun.h"
60#include "AliRunLoader.h"
cc80f89e 61#include "AliSimDigits.h"
88cb7938 62#include "AliTPC.h"
63#include "AliTPC.h"
88cb7938 64#include "AliTPCDigitsArray.h"
65#include "AliTPCLoader.h"
66#include "AliTPCPRF2D.h"
67#include "AliTPCParamSR.h"
68#include "AliTPCRF1D.h"
792bb11c 69#include "AliTPCTrackHitsV2.h"
88cb7938 70#include "AliTrackReference.h"
5d12ce38 71#include "AliMC.h"
5bf6eb16 72#include "AliStack.h"
85a5290f 73#include "AliTPCDigitizer.h"
0421c3d1 74#include "AliTPCBuffer.h"
75#include "AliTPCDDLRawData.h"
8c2b3fd7 76#include "AliLog.h"
79fa3dc8 77#include "AliTPCcalibDB.h"
78#include "AliTPCCalPad.h"
79#include "AliTPCCalROC.h"
80#include "AliTPCExB.h"
bc807150 81#include "AliRawReader.h"
dbfbf54e 82#include "AliTPCRawStreamV3.h"
23effa8e 83#include "TTreeStream.h"
39c8eb58 84
fe4da5cc 85ClassImp(AliTPC)
fe4da5cc 86//_____________________________________________________________________________
179c6296 87 AliTPC::AliTPC():AliDetector(),
88 fDefaults(0),
89 fSens(0),
90 fNsectors(0),
91 fDigitsArray(0),
92 fTPCParam(0),
93 fTrackHits(0),
94 fHitType(0),
95 fDigitsSwitch(0),
96 fSide(0),
b97617a6 97 fPrimaryIonisation(0),
179c6296 98 fNoiseDepth(0),
99 fNoiseTable(0),
100 fCurrentNoise(0),
8261c673 101 fActiveSectors(0),
23effa8e 102 fGainFactor(1.),
f546a4b4 103 fDebugStreamer(0),
104 fLHCclockPhaseSw(0)
179c6296 105
fe4da5cc 106{
107 //
108 // Default constructor
109 //
110 fIshunt = 0;
712976a6 111 for(Int_t i=0;i<4;i++) fCurrentIndex[i]=0;
179c6296 112
be5ffbfe 113 // fTrackHitsOld = 0;
8c2b3fd7 114#if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
115 fHitType = 4; // ROOT containers
116#else
117 fHitType = 2; //default CONTAINERS - based on ROOT structure
118#endif
fe4da5cc 119}
120
121//_____________________________________________________________________________
122AliTPC::AliTPC(const char *name, const char *title)
179c6296 123 : AliDetector(name,title),
124 fDefaults(0),
125 fSens(0),
126 fNsectors(0),
127 fDigitsArray(0),
128 fTPCParam(0),
129 fTrackHits(0),
130 fHitType(0),
131 fDigitsSwitch(0),
132 fSide(0),
b97617a6 133 fPrimaryIonisation(0),
179c6296 134 fNoiseDepth(0),
135 fNoiseTable(0),
136 fCurrentNoise(0),
8261c673 137 fActiveSectors(0),
f546a4b4 138 fGainFactor(1.),
139 fDebugStreamer(0),
140 fLHCclockPhaseSw(0)
b97617a6 141
fe4da5cc 142{
143 //
144 // Standard constructor
145 //
146
147 //
148 // Initialise arrays of hits and digits
149 fHits = new TClonesArray("AliTPChit", 176);
5d12ce38 150 gAlice->GetMCApp()->AddHitList(fHits);
fe4da5cc 151 //
792bb11c 152 fTrackHits = new AliTPCTrackHitsV2;
39c8eb58 153 fTrackHits->SetHitPrecision(0.002);
154 fTrackHits->SetStepPrecision(0.003);
792bb11c 155 fTrackHits->SetMaxDistance(100);
156
be5ffbfe 157 //fTrackHitsOld = new AliTPCTrackHits; //MI - 13.09.2000
158 //fTrackHitsOld->SetHitPrecision(0.002);
159 //fTrackHitsOld->SetStepPrecision(0.003);
160 //fTrackHitsOld->SetMaxDistance(100);
792bb11c 161
39c8eb58 162
8c2b3fd7 163#if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
164 fHitType = 4; // ROOT containers
165#else
da33556f 166 fHitType = 2;
8c2b3fd7 167#endif
179c6296 168
712976a6 169 for(Int_t i=0;i<4;i++) fCurrentIndex[i]=0;
cc80f89e 170
fe4da5cc 171 //
172 fIshunt = 0;
173 //
174 // Initialise color attributes
e939a978 175 //PH SetMarkerColor(kYellow);
73042f01 176
177 //
178 // Set TPC parameters
179 //
180
afc42102 181
182 if (!strcmp(title,"Default")) {
db2fdcfb 183 //fTPCParam = new AliTPCParamSR;
184 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
73042f01 185 } else {
8c2b3fd7 186 AliWarning("In Config.C you must set non-default parameters.");
73042f01 187 fTPCParam=0;
188 }
23effa8e 189
fe4da5cc 190}
0f2ff24c 191void AliTPC::CreateDebugStremer(){
192 //
193 // Create Debug streamer to check simulation
194 //
195 fDebugStreamer = new TTreeSRedirector("TPCSimdebug.root");
196}
fe4da5cc 197//_____________________________________________________________________________
198AliTPC::~AliTPC()
199{
200 //
201 // TPC destructor
202 //
73042f01 203
fe4da5cc 204 fIshunt = 0;
205 delete fHits;
206 delete fDigits;
db2fdcfb 207 //delete fTPCParam;
39c8eb58 208 delete fTrackHits; //MI 15.09.2000
be5ffbfe 209 // delete fTrackHitsOld; //MI 10.12.2001
9ff4af81 210
211 fDigitsArray = 0x0;
212 delete [] fNoiseTable;
213 delete [] fActiveSectors;
23effa8e 214 if (fDebugStreamer) delete fDebugStreamer;
fe4da5cc 215}
216
fe4da5cc 217//_____________________________________________________________________________
218void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
219{
220 //
221 // Add a hit to the list
222 //
39c8eb58 223 if (fHitType&1){
224 TClonesArray &lhits = *fHits;
225 new(lhits[fNhits++]) AliTPChit(fIshunt,track,vol,hits);
226 }
792bb11c 227 if (fHitType>1)
8c2b3fd7 228 AddHit2(track,vol,hits);
fe4da5cc 229}
88cb7938 230
fe4da5cc 231//_____________________________________________________________________________
232void AliTPC::CreateMaterials()
233{
8c555625 234 //-----------------------------------------------
37831078 235 // Create Materials for for TPC simulations
8c555625 236 //-----------------------------------------------
237
238 //-----------------------------------------------------------------
239 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
240 //-----------------------------------------------------------------
1283eee5 241
f7a1cc68 242 Int_t iSXFLD=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
243 Float_t sXMGMX=((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
1283eee5 244
245 Float_t amat[5]; // atomic numbers
246 Float_t zmat[5]; // z
247 Float_t wmat[5]; // proportions
248
249 Float_t density;
37831078 250
1283eee5 251
1283eee5 252
c1637e41 253 //***************** Gases *************************
1283eee5 254
37831078 255
1283eee5 256 //--------------------------------------------------------------
c1637e41 257 // gases - air and CO2
1283eee5 258 //--------------------------------------------------------------
259
37831078 260 // CO2
1283eee5 261
262 amat[0]=12.011;
263 amat[1]=15.9994;
264
265 zmat[0]=6.;
266 zmat[1]=8.;
267
c1637e41 268 wmat[0]=0.2729;
269 wmat[1]=0.7271;
1283eee5 270
2556fc5b 271 density=0.001754609;
1283eee5 272
1283eee5 273
c1637e41 274 AliMixture(10,"CO2",amat,zmat,density,2,wmat);
275 //
276 // Air
277 //
278 amat[0]=15.9994;
279 amat[1]=14.007;
280 //
281 zmat[0]=8.;
282 zmat[1]=7.;
283 //
284 wmat[0]=0.233;
285 wmat[1]=0.767;
286 //
287 density=0.001205;
1283eee5 288
c1637e41 289 AliMixture(11,"Air",amat,zmat,density,2,wmat);
290
1283eee5 291 //----------------------------------------------------------------
c1637e41 292 // drift gases
1283eee5 293 //----------------------------------------------------------------
37831078 294
4f1c6f0b 295 //
37831078 296 // Drift gases 1 - nonsensitive, 2 - sensitive
4f1c6f0b 297 // Ne-CO2-N2 (90-10-5) (volume) values at 20deg and 1 atm.
298 // rho(Ne) = 0.839 g/cm^3, rho(CO2) = 1.842 g/cm^3, rho(N2) = 1.165 g/cm^3
299 // for the calculation - everything is normalized to 1
e4e763b9 300
301 amat[0]= 20.18;
302 amat[1]=12.011;
303 amat[2]=15.9994;
c1637e41 304 amat[3]=14.007;
e4e763b9 305
306 zmat[0]= 10.;
307 zmat[1]=6.;
308 zmat[2]=8.;
c1637e41 309 zmat[3]=7.;
e4e763b9 310
4f1c6f0b 311 wmat[0]=0.756992632;
312 wmat[1]=0.056235789;
313 wmat[2]=0.128469474;
314 wmat[3]=0.058395789;
c1637e41 315
2556fc5b 316 density=0.000904929;
e4e763b9 317
c1637e41 318 AliMixture(12,"Ne-CO2-N-1",amat,zmat,density,4,wmat);
319 AliMixture(13,"Ne-CO2-N-2",amat,zmat,density,4,wmat);
a1648281 320 AliMixture(35,"Ne-CO2-N-3",amat,zmat,density,4,wmat);
1283eee5 321 //----------------------------------------------------------------------
322 // solid materials
323 //----------------------------------------------------------------------
324
1283eee5 325
37831078 326 // Kevlar C14H22O2N2
1283eee5 327
37831078 328 amat[0] = 12.011;
329 amat[1] = 1.;
330 amat[2] = 15.999;
331 amat[3] = 14.006;
1283eee5 332
37831078 333 zmat[0] = 6.;
334 zmat[1] = 1.;
335 zmat[2] = 8.;
336 zmat[3] = 7.;
337
338 wmat[0] = 14.;
339 wmat[1] = 22.;
340 wmat[2] = 2.;
341 wmat[3] = 2.;
342
343 density = 1.45;
344
c1637e41 345 AliMixture(14,"Kevlar",amat,zmat,density,-4,wmat);
37831078 346
347 // NOMEX
1283eee5 348
37831078 349 amat[0] = 12.011;
350 amat[1] = 1.;
351 amat[2] = 15.999;
352 amat[3] = 14.006;
353
354 zmat[0] = 6.;
355 zmat[1] = 1.;
356 zmat[2] = 8.;
357 zmat[3] = 7.;
358
359 wmat[0] = 14.;
360 wmat[1] = 22.;
361 wmat[2] = 2.;
362 wmat[3] = 2.;
363
c1637e41 364 density = 0.029;
365
366 AliMixture(15,"NOMEX",amat,zmat,density,-4,wmat);
37831078 367
368 // Makrolon C16H18O3
369
370 amat[0] = 12.011;
371 amat[1] = 1.;
372 amat[2] = 15.999;
1283eee5 373
37831078 374 zmat[0] = 6.;
375 zmat[1] = 1.;
376 zmat[2] = 8.;
377
378 wmat[0] = 16.;
379 wmat[1] = 18.;
380 wmat[2] = 3.;
381
382 density = 1.2;
383
c1637e41 384 AliMixture(16,"Makrolon",amat,zmat,density,-3,wmat);
385
386 // Tedlar C2H3F
387
388 amat[0] = 12.011;
389 amat[1] = 1.;
390 amat[2] = 18.998;
391
392 zmat[0] = 6.;
393 zmat[1] = 1.;
394 zmat[2] = 9.;
395
396 wmat[0] = 2.;
397 wmat[1] = 3.;
398 wmat[2] = 1.;
399
400 density = 1.71;
401
402 AliMixture(17, "Tedlar",amat,zmat,density,-3,wmat);
37831078 403
1283eee5 404 // Mylar C5H4O2
405
406 amat[0]=12.011;
407 amat[1]=1.;
408 amat[2]=15.9994;
409
410 zmat[0]=6.;
411 zmat[1]=1.;
412 zmat[2]=8.;
413
414 wmat[0]=5.;
415 wmat[1]=4.;
416 wmat[2]=2.;
417
418 density = 1.39;
fe4da5cc 419
c1637e41 420 AliMixture(18, "Mylar",amat,zmat,density,-3,wmat);
421 // material for "prepregs"
422 // Epoxy - C14 H20 O3
423 // Quartz SiO2
424 // Carbon C
425 // prepreg1 60% C-fiber, 40% epoxy (vol)
426 amat[0]=12.011;
427 amat[1]=1.;
428 amat[2]=15.994;
1283eee5 429
c1637e41 430 zmat[0]=6.;
431 zmat[1]=1.;
432 zmat[2]=8.;
1283eee5 433
c1637e41 434 wmat[0]=0.923;
435 wmat[1]=0.023;
436 wmat[2]=0.054;
1283eee5 437
c1637e41 438 density=1.859;
1283eee5 439
c1637e41 440 AliMixture(19, "Prepreg1",amat,zmat,density,3,wmat);
1283eee5 441
c1637e41 442 //prepreg2 60% glass-fiber, 40% epoxy
1283eee5 443
c1637e41 444 amat[0]=12.01;
445 amat[1]=1.;
446 amat[2]=15.994;
447 amat[3]=28.086;
448
449 zmat[0]=6.;
450 zmat[1]=1.;
451 zmat[2]=8.;
452 zmat[3]=14.;
453
454 wmat[0]=0.194;
455 wmat[1]=0.023;
456 wmat[2]=0.443;
efbf94c5 457 wmat[3]=0.34;
c1637e41 458
459 density=1.82;
460
461 AliMixture(20, "Prepreg2",amat,zmat,density,4,wmat);
462
463 //prepreg3 50% glass-fiber, 50% epoxy
464
465 amat[0]=12.01;
466 amat[1]=1.;
467 amat[2]=15.994;
468 amat[3]=28.086;
469
470 zmat[0]=6.;
471 zmat[1]=1.;
472 zmat[2]=8.;
473 zmat[3]=14.;
1283eee5 474
efbf94c5 475 wmat[0]=0.257;
c1637e41 476 wmat[1]=0.03;
efbf94c5 477 wmat[2]=0.412;
c1637e41 478 wmat[3]=0.3;
479
0f788f87 480 density=1.725;
c1637e41 481
482 AliMixture(21, "Prepreg3",amat,zmat,density,4,wmat);
483
484 // G10 60% SiO2 40% epoxy
485
486 amat[0]=12.01;
487 amat[1]=1.;
488 amat[2]=15.994;
489 amat[3]=28.086;
490
491 zmat[0]=6.;
492 zmat[1]=1.;
493 zmat[2]=8.;
494 zmat[3]=14.;
495
496 wmat[0]=0.194;
497 wmat[1]=0.023;
498 wmat[2]=0.443;
499 wmat[3]=0.340;
500
501 density=1.7;
502
503 AliMixture(22, "G10",amat,zmat,density,4,wmat);
504
37831078 505 // Al
1283eee5 506
37831078 507 amat[0] = 26.98;
508 zmat[0] = 13.;
1283eee5 509
37831078 510 density = 2.7;
1283eee5 511
c1637e41 512 AliMaterial(23,"Al",amat[0],zmat[0],density,999.,999.);
1283eee5 513
c1637e41 514 // Si (for electronics
1283eee5 515
37831078 516 amat[0] = 28.086;
9a3667bd 517 zmat[0] = 14.;
1283eee5 518
37831078 519 density = 2.33;
1283eee5 520
c1637e41 521 AliMaterial(24,"Si",amat[0],zmat[0],density,999.,999.);
1283eee5 522
37831078 523 // Cu
1283eee5 524
37831078 525 amat[0] = 63.546;
526 zmat[0] = 29.;
1283eee5 527
37831078 528 density = 8.96;
1283eee5 529
c1637e41 530 AliMaterial(25,"Cu",amat[0],zmat[0],density,999.,999.);
1283eee5 531
0f788f87 532 // brass
533
534 amat[0] = 63.546;
535 zmat[0] = 29.;
536 //
537 amat[1]= 65.409;
538 zmat[1]= 30.;
539 //
540 wmat[0]= 0.6;
541 wmat[1]= 0.4;
542
543 //
544 density = 8.23;
545
546
547 //
548 AliMixture(33,"Brass",amat,zmat,density,2,wmat);
549
c1637e41 550 // Epoxy - C14 H20 O3
551
37831078 552 amat[0]=12.011;
553 amat[1]=1.;
554 amat[2]=15.9994;
1283eee5 555
37831078 556 zmat[0]=6.;
557 zmat[1]=1.;
558 zmat[2]=8.;
1283eee5 559
c1637e41 560 wmat[0]=14.;
561 wmat[1]=20.;
562 wmat[2]=3.;
1283eee5 563
c1637e41 564 density=1.25;
1283eee5 565
c1637e41 566 AliMixture(26,"Epoxy",amat,zmat,density,-3,wmat);
efbf94c5 567 //
568 // epoxy film - 90% epoxy, 10% glass fiber
569 //
570 amat[0]=12.01;
571 amat[1]=1.;
572 amat[2]=15.994;
573 amat[3]=28.086;
574
575 zmat[0]=6.;
576 zmat[1]=1.;
577 zmat[2]=8.;
578 zmat[3]=14.;
579
580 wmat[0]=0.596;
581 wmat[1]=0.071;
582 wmat[2]=0.257;
583 wmat[3]=0.076;
584
585
586 density=1.345;
587
588 AliMixture(34, "Epoxy-film",amat,zmat,density,4,wmat);
1283eee5 589
c1637e41 590 // Plexiglas C5H8O2
1283eee5 591
5a28a08f 592 amat[0]=12.011;
593 amat[1]=1.;
594 amat[2]=15.9994;
595
596 zmat[0]=6.;
597 zmat[1]=1.;
598 zmat[2]=8.;
599
c1637e41 600 wmat[0]=5.;
601 wmat[1]=8.;
602 wmat[2]=2.;
5a28a08f 603
c1637e41 604 density=1.18;
5a28a08f 605
c1637e41 606 AliMixture(27,"Plexiglas",amat,zmat,density,-3,wmat);
37831078 607
ba1d05f9 608 // Carbon
609
610 amat[0]=12.011;
611 zmat[0]=6.;
612 density= 2.265;
613
c1637e41 614 AliMaterial(28,"C",amat[0],zmat[0],density,999.,999.);
ba1d05f9 615
c1637e41 616 // Fe (steel for the inner heat screen)
e4e763b9 617
c1637e41 618 amat[0]=55.845;
e4e763b9 619
c1637e41 620 zmat[0]=26.;
e4e763b9 621
c1637e41 622 density=7.87;
ba1d05f9 623
c1637e41 624 AliMaterial(29,"Fe",amat[0],zmat[0],density,999.,999.);
f4441b15 625 //
626 // Peek - (C6H4-O-OC6H4-O-C6H4-CO)n
627 amat[0]=12.011;
628 amat[1]=1.;
629 amat[2]=15.9994;
630
631 zmat[0]=6.;
632 zmat[1]=1.;
633 zmat[2]=8.;
634
635 wmat[0]=19.;
636 wmat[1]=12.;
637 wmat[2]=3.;
638 //
639 density=1.3;
640 //
641 AliMixture(30,"Peek",amat,zmat,density,-3,wmat);
642 //
643 // Ceramics - Al2O3
644 //
645 amat[0] = 26.98;
646 amat[1]= 15.9994;
647
648 zmat[0] = 13.;
649 zmat[1]=8.;
650
651 wmat[0]=2.;
652 wmat[1]=3.;
653
654 density = 3.97;
655
656 AliMixture(31,"Alumina",amat,zmat,density,-2,wmat);
657
658 //
659 // liquids
660 //
661
662 // water
663
664 amat[0]=1.;
665 amat[1]=15.9994;
666
667 zmat[0]=1.;
668 zmat[1]=8.;
669
670 wmat[0]=2.;
671 wmat[1]=1.;
672
673 density=1.;
674
675 AliMixture(32,"Water",amat,zmat,density,-2,wmat);
efbf94c5 676
ba1d05f9 677
37831078 678 //----------------------------------------------------------
679 // tracking media for gases
680 //----------------------------------------------------------
681
c1637e41 682 AliMedium(0, "Air", 11, 0, iSXFLD, sXMGMX, 10., 999., .1, .01, .1);
683 AliMedium(1, "Ne-CO2-N-1", 12, 0, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
684 AliMedium(2, "Ne-CO2-N-2", 13, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
37831078 685 AliMedium(3,"CO2",10,0, iSXFLD, sXMGMX, 10., 999.,.1, .001, .001);
a1648281 686 AliMedium(20, "Ne-CO2-N-3", 35, 1, iSXFLD, sXMGMX, 10., 999.,.1,.001, .001);
37831078 687 //-----------------------------------------------------------
688 // tracking media for solids
689 //-----------------------------------------------------------
690
c1637e41 691 AliMedium(4,"Al",23,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
692 AliMedium(5,"Kevlar",14,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
693 AliMedium(6,"Nomex",15,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
694 AliMedium(7,"Makrolon",16,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
695 AliMedium(8,"Mylar",18,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
696 AliMedium(9,"Tedlar",17,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
697 //
698 AliMedium(10,"Prepreg1",19,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
699 AliMedium(11,"Prepreg2",20,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
700 AliMedium(12,"Prepreg3",21,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
701 AliMedium(13,"Epoxy",26,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
702
703 AliMedium(14,"Cu",25,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
704 AliMedium(15,"Si",24,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
705 AliMedium(16,"G10",22,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
706 AliMedium(17,"Plexiglas",27,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
707 AliMedium(18,"Steel",29,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
f4441b15 708 AliMedium(19,"Peek",30,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
709 AliMedium(21,"Alumina",31,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
0f788f87 710 AliMedium(22,"Water",32,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
efbf94c5 711 AliMedium(23,"Brass",33,0, iSXFLD, sXMGMX, 10., 999., .1, .001, .001);
712 AliMedium(24,"Epoxyfm",34,0, iSXFLD, sXMGMX, 10., 999., .1, .0005, .001);
fe4da5cc 713}
714
407ff276 715void AliTPC::GenerNoise(Int_t tablesize)
716{
717 //
718 //Generate table with noise
719 //
720 if (fTPCParam==0) {
721 // error message
722 fNoiseDepth=0;
723 return;
724 }
725 if (fNoiseTable) delete[] fNoiseTable;
726 fNoiseTable = new Float_t[tablesize];
727 fNoiseDepth = tablesize;
728 fCurrentNoise =0; //!index of the noise in the noise table
729
730 Float_t norm = fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac();
731 for (Int_t i=0;i<tablesize;i++) fNoiseTable[i]= gRandom->Gaus(0,norm);
732}
733
734Float_t AliTPC::GetNoise()
735{
736 // get noise from table
737 // if ((fCurrentNoise%10)==0)
738 // fCurrentNoise= gRandom->Rndm()*fNoiseDepth;
739 if (fCurrentNoise>=fNoiseDepth) fCurrentNoise=0;
740 return fNoiseTable[fCurrentNoise++];
741 //gRandom->Gaus(0, fTPCParam->GetNoise()*fTPCParam->GetNoiseNormFac());
742}
743
744
9bdd974b 745Bool_t AliTPC::IsSectorActive(Int_t sec) const
792bb11c 746{
747 //
748 // check if the sector is active
749 if (!fActiveSectors) return kTRUE;
750 else return fActiveSectors[sec];
751}
752
753void AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
754{
755 // activate interesting sectors
88cb7938 756 SetTreeAddress();//just for security
7ed5ec98 757 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
792bb11c 758 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
759 for (Int_t i=0;i<n;i++)
760 if ((sectors[i]>=0) && sectors[i]<fTPCParam->GetNSector()) fActiveSectors[sectors[i]]=kTRUE;
761
762}
763
12d8d654 764void AliTPC::SetActiveSectors(Int_t flag)
792bb11c 765{
766 //
767 // activate sectors which were hitted by tracks
768 //loop over tracks
88cb7938 769 SetTreeAddress();//just for security
792bb11c 770 if (fHitType==0) return; // if Clones hit - not short volume ID information
7ed5ec98 771 if (!fActiveSectors) fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
12d8d654 772 if (flag) {
773 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
774 return;
775 }
792bb11c 776 for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
097d753a 777 //TBranch * branch=0;
cb5b8b21 778 if (fLoader->TreeH() == 0x0)
88cb7938 779 {
8c2b3fd7 780 AliFatal("Can not find TreeH in folder");
88cb7938 781 return;
782 }
097d753a 783 //if (fHitType>1) branch = fLoader->TreeH()->GetBranch("TPC2");
784 if (fHitType>1) fLoader->TreeH()->GetBranch("TPC2");
785 //else branch = fLoader->TreeH()->GetBranch("TPC");
786 else fLoader->TreeH()->GetBranch("TPC");
cb5b8b21 787 Stat_t ntracks = fLoader->TreeH()->GetEntries();
792bb11c 788 // loop over all hits
7d85e147 789 AliDebug(1,Form("Got %d tracks", (Int_t) ntracks));
88cb7938 790
8c2b3fd7 791 for(Int_t track=0;track<ntracks;track++) {
792bb11c 792 ResetHits();
793 //
794 if (fTrackHits && fHitType&4) {
cb5b8b21 795 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
796 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
792bb11c 797 br1->GetEvent(track);
798 br2->GetEvent(track);
799 Int_t *volumes = fTrackHits->GetVolumes();
7ed5ec98 800 for (Int_t j=0;j<fTrackHits->GetNVolumes(); j++) {
e8631c7d 801 if (volumes[j]>-1 && volumes[j]<fTPCParam->GetNSector()) {
7ed5ec98 802 fActiveSectors[volumes[j]]=kTRUE;
803 }
804 else {
805 AliError(Form("Volume %d -> sector number %d is outside (0..%d)",
806 j,
807 volumes[j],
808 fTPCParam->GetNSector()));
809 }
810 }
792bb11c 811 }
812
813 //
be5ffbfe 814// if (fTrackHitsOld && fHitType&2) {
cb5b8b21 815// TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
be5ffbfe 816// br->GetEvent(track);
817// AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
818// for (UInt_t j=0;j<ar->GetSize();j++){
819// fActiveSectors[((AliTrackHitsInfo*)ar->At(j))->fVolumeID] =kTRUE;
820// }
821// }
792bb11c 822 }
792bb11c 823}
824
825
826
fe4da5cc 827
0421c3d1 828//_____________________________________________________________________________
829void AliTPC::Digits2Raw()
830{
831// convert digits of the current event to raw data
832
833 static const Int_t kThreshold = 0;
0421c3d1 834
835 fLoader->LoadDigits();
836 TTree* digits = fLoader->TreeD();
837 if (!digits) {
8c2b3fd7 838 AliError("No digits tree");
0421c3d1 839 return;
840 }
841
19bbb61d 842 //
0421c3d1 843 AliSimDigits digarr;
844 AliSimDigits* digrow = &digarr;
845 digits->GetBranch("Segment")->SetAddress(&digrow);
846
847 const char* fileName = "AliTPCDDL.dat";
848 AliTPCBuffer* buffer = new AliTPCBuffer(fileName);
849 //Verbose level
850 // 0: Silent
851 // 1: cout messages
852 // 2: txt files with digits
853 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
854 //it is highly suggested to use this mode only for debugging digits files
855 //reasonably small, because otherwise the size of the txt files can reach
856 //quickly several MB wasting time and disk space.
857 buffer->SetVerbose(0);
858
859 Int_t nEntries = Int_t(digits->GetEntries());
860 Int_t previousSector = -1;
861 Int_t subSector = 0;
862 for (Int_t i = 0; i < nEntries; i++) {
863 digits->GetEntry(i);
864 Int_t sector, row;
865 fTPCParam->AdjustSectorRow(digarr.GetID(), sector, row);
866 if(previousSector != sector) {
867 subSector = 0;
868 previousSector = sector;
869 }
870
871 if (sector < 36) { //inner sector [0;35]
872 if (row != 30) {
873 //the whole row is written into the output file
874 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
875 sector, subSector, row);
876 } else {
877 //only the pads in the range [37;48] are written into the output file
878 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 1,
879 sector, subSector, row);
880 subSector = 1;
881 //only the pads outside the range [37;48] are written into the output file
882 buffer->WriteRowBinary(kThreshold, digrow, 37, 48, 2,
883 sector, subSector, row);
884 }//end else
885
886 } else { //outer sector [36;71]
887 if (row == 54) subSector = 2;
888 if ((row != 27) && (row != 76)) {
889 buffer->WriteRowBinary(kThreshold, digrow, 0, 0, 0,
890 sector, subSector, row);
891 } else if (row == 27) {
8c2b3fd7 892 //only the pads outside the range [43;46] are written into the output file
893 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 2,
0421c3d1 894 sector, subSector, row);
8c2b3fd7 895 subSector = 1;
896 //only the pads in the range [43;46] are written into the output file
897 buffer->WriteRowBinary(kThreshold, digrow, 43, 46, 1,
0421c3d1 898 sector, subSector, row);
899 } else if (row == 76) {
8c2b3fd7 900 //only the pads outside the range [33;88] are written into the output file
901 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 2,
902 sector, subSector, row);
903 subSector = 3;
904 //only the pads in the range [33;88] are written into the output file
905 buffer->WriteRowBinary(kThreshold, digrow, 33, 88, 1,
0421c3d1 906 sector, subSector, row);
907 }
908 }//end else
909 }//end for
910
911 delete buffer;
912 fLoader->UnloadDigits();
913
914 AliTPCDDLRawData rawWriter;
915 rawWriter.SetVerbose(0);
916
917 rawWriter.RawData(fileName);
918 gSystem->Unlink(fileName);
919
0421c3d1 920}
921
922
bc807150 923//_____________________________________________________________________________
924Bool_t AliTPC::Raw2SDigits(AliRawReader* rawReader){
925 // Converts the TPC raw data into summable digits
926 // The method is used for merging simulated and
927 // real data events
928 if (fLoader->TreeS() == 0x0 ) {
929 fLoader->MakeTree("S");
930 }
931
932 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
933
934 //setup TPCDigitsArray
935 if(GetDigitsArray()) delete GetDigitsArray();
936
937 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
938 arr->SetClass("AliSimDigits");
939 arr->Setup(fTPCParam);
940 arr->MakeTree(fLoader->TreeS());
941
942 SetDigitsArray(arr);
943
944 // set zero suppression to "0"
945 fTPCParam->SetZeroSup(0);
946
947 // Loop over sectors
d899e254 948 const Int_t kmaxTime = fTPCParam->GetMaxTBin();
bc807150 949 const Int_t kNIS = fTPCParam->GetNInnerSector();
950 const Int_t kNOS = fTPCParam->GetNOuterSector();
951 const Int_t kNS = kNIS + kNOS;
952
dbfbf54e 953 // Setup storage
954 AliTPCROC * roc = AliTPCROC::Instance();
955 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
956 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
957 Short_t** allBins = new Short_t*[nRowsMax];
958 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
959 Int_t maxBin = kmaxTime*nPadsMax;
960 allBins[iRow] = new Short_t[maxBin];
961 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
962 }
963
bc807150 964 for(Int_t iSector = 0; iSector < kNS; iSector++) {
965
966 Int_t nRows = fTPCParam->GetNRow(iSector);
967 Int_t nDDLs = 0, indexDDL = 0;
968 if (iSector < kNIS) {
969 nDDLs = 2;
970 indexDDL = iSector * 2;
971 }
972 else {
973 nDDLs = 4;
974 indexDDL = (iSector-kNIS) * 4 + kNIS * 2;
975 }
976
dbfbf54e 977 // Load the raw data for corresponding DDLs
bc807150 978 rawReader->Reset();
dbfbf54e 979
980 AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
981 AliTPCRawStreamV3 input(rawReader,(AliAltroMapping**)mapping);
bc807150 982 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
983
dbfbf54e 984 // Clean storage
985 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
986 Int_t maxBin = kmaxTime*nPadsMax;
bc807150 987 memset(allBins[iRow],0,sizeof(Short_t)*maxBin);
988 }
989
990 // Begin loop over altro data
dbfbf54e 991 while (input.NextDDL()) {
bc807150 992
993 if (input.GetSector() != iSector)
994 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSector,input.GetSector()));
995
dbfbf54e 996 //loop over pads
997 while ( input.NextChannel() ) {
998
999 Int_t iRow = input.GetRow();
1000 if (iRow < 0 || iRow >= nRows)
1001 AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
1002 iRow, 0, nRows -1));
1003 Int_t iPad = input.GetPad();
1004
1005 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1006
1007 if (iPad < 0 || iPad >= maxPad)
1008 AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
1009 iPad, 0, maxPad -1));
1010
1011 //loop over bunches
1012 while ( input.NextBunch() ){
1013 Int_t startTbin = (Int_t)input.GetStartTimeBin();
1014 Int_t bunchlength = (Int_t)input.GetBunchLength();
1015 const UShort_t *sig = input.GetSignals();
1016 for (Int_t iTime = 0; iTime<bunchlength; iTime++){
1017 Int_t iTimeBin=startTbin-iTime;
1018 if ( iTimeBin < 0 || iTimeBin >= kmaxTime) {
1019 continue;
1020 //AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
1021 // iTimeBin, 0, kmaxTime -1));
1022 }
1023
1024 Int_t maxBin = kmaxTime*maxPad;
1025 if (((iPad*kmaxTime+iTimeBin) >= maxBin) ||
1026 ((iPad*kmaxTime+iTimeBin) < 0))
1027 AliFatal(Form("Index outside the allowed range"
1028 " Sector=%d Row=%d Pad=%d Timebin=%d"
1029 " (Max.index=%d)",iSector,iRow,iPad,iTimeBin,maxBin));
1030 allBins[iRow][iPad*kmaxTime+iTimeBin] = sig[iTime];
1031 }
1032 }
1033 } // End loop over altro data
1034 }
bc807150 1035
bc807150 1036 // Now fill the digits array
1037 if (fDigitsArray->GetTree()==0) {
1038 AliFatal("Tree not set in fDigitsArray");
1039 }
1040
1041 for (Int_t iRow = 0; iRow < nRows; iRow++) {
1042 AliDigits * dig = fDigitsArray->CreateRow(iSector,iRow);
bc807150 1043 Int_t maxPad = fTPCParam->GetNPads(iSector,iRow);
1044 for(Int_t iPad = 0; iPad < maxPad; iPad++) {
d899e254 1045 for(Int_t iTimeBin = 0; iTimeBin < kmaxTime; iTimeBin++) {
1046 Short_t q = allBins[iRow][iPad*kmaxTime + iTimeBin];
bc807150 1047 if (q <= 0) continue;
1048 q *= 16;
1049 dig->SetDigitFast((Short_t)q,iTimeBin,iPad);
1050 }
1051 }
1052 fDigitsArray->StoreRow(iSector,iRow);
1053 Int_t ndig = dig->GetDigitSize();
1054
1055 AliDebug(10,
1056 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1057 iSector,iRow,ndig));
1058
1059 fDigitsArray->ClearRow(iSector,iRow);
1060
1061 } // end of the sector digitization
bc807150 1062 }
19bbb61d 1063 // get LHC clock phase from the digits tree
13627b46 1064
19bbb61d 1065 TParameter<float> *ph;
13627b46 1066 Float_t phase;
1067 TTree *digtree = fLoader->TreeD();
1068 //
1069 if(digtree){ // if TreeD exists
1070 ph = (TParameter<float>*)digtree->GetUserInfo()->FindObject("lhcphase0");
1071 phase = ph->GetVal();
1072 }
1073 else{ //TreeD does not exist
1074 phase = 0.;
1075 }
19bbb61d 1076 //
1077 // store lhc clock phase in S-digits tree
1078 //
13627b46 1079 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",phase));
19bbb61d 1080 //
1081 fLoader->WriteSDigits("OVERWRITE");
bc807150 1082
1083 if(GetDigitsArray()) delete GetDigitsArray();
1084 SetDigitsArray(0x0);
1085
dbfbf54e 1086 // cleanup storage
1087 for (Int_t iRow = 0; iRow < nRowsMax; iRow++)
1088 delete [] allBins[iRow];
1089 delete [] allBins;
1090
bc807150 1091 return kTRUE;
1092}
0a61bf9d 1093
85a5290f 1094//______________________________________________________________________
9bdd974b 1095AliDigitizer* AliTPC::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 1096{
1097 return new AliTPCDigitizer(manager);
1098}
0a61bf9d 1099//__
176aff27 1100void AliTPC::SDigits2Digits2(Int_t /*eventnumber*/)
0a61bf9d 1101{
1102 //create digits from summable digits
407ff276 1103 GenerNoise(500000); //create teble with noise
0a61bf9d 1104
1105 //conect tree with sSDigits
88cb7938 1106 TTree *t = fLoader->TreeS();
1107
8c2b3fd7 1108 if (t == 0x0) {
1109 fLoader->LoadSDigits("READ");
1110 t = fLoader->TreeS();
1111 if (t == 0x0) {
1112 AliError("Can not get input TreeS");
1113 return;
1114 }
1115 }
88cb7938 1116
1117 if (fLoader->TreeD() == 0x0) fLoader->MakeTree("D");
1118
0a61bf9d 1119 AliSimDigits digarr, *dummy=&digarr;
88cb7938 1120 TBranch* sdb = t->GetBranch("Segment");
8c2b3fd7 1121 if (sdb == 0x0) {
1122 AliError("Can not find branch with segments in TreeS.");
1123 return;
1124 }
88cb7938 1125
1126 sdb->SetAddress(&dummy);
1127
0a61bf9d 1128 Stat_t nentries = t->GetEntries();
1129
5f16d237 1130 // set zero suppression
1131
1132 fTPCParam->SetZeroSup(2);
1133
1134 // get zero suppression
1135
1136 Int_t zerosup = fTPCParam->GetZeroSup();
1137
1138 //make tree with digits
1139
0a61bf9d 1140 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1141 arr->SetClass("AliSimDigits");
1142 arr->Setup(fTPCParam);
88cb7938 1143 arr->MakeTree(fLoader->TreeD());
0a61bf9d 1144
88cb7938 1145 AliTPCParam * par = fTPCParam;
5f16d237 1146
0a61bf9d 1147 //Loop over segments of the TPC
5f16d237 1148
0a61bf9d 1149 for (Int_t n=0; n<nentries; n++) {
1150 t->GetEvent(n);
1151 Int_t sec, row;
1152 if (!par->AdjustSectorRow(digarr.GetID(),sec,row)) {
8c2b3fd7 1153 AliWarning(Form("Invalid segment ID ! %d",digarr.GetID()));
0a61bf9d 1154 continue;
1155 }
8c2b3fd7 1156 if (!IsSectorActive(sec)) continue;
1157
0a61bf9d 1158 AliSimDigits * digrow =(AliSimDigits*) arr->CreateRow(sec,row);
1159 Int_t nrows = digrow->GetNRows();
1160 Int_t ncols = digrow->GetNCols();
1161
1162 digrow->ExpandBuffer();
1163 digarr.ExpandBuffer();
1164 digrow->ExpandTrackBuffer();
1165 digarr.ExpandTrackBuffer();
1166
5f16d237 1167
407ff276 1168 Short_t * pamp0 = digarr.GetDigits();
1169 Int_t * ptracks0 = digarr.GetTracks();
1170 Short_t * pamp1 = digrow->GetDigits();
1171 Int_t * ptracks1 = digrow->GetTracks();
1172 Int_t nelems =nrows*ncols;
e93a083a 1173 Int_t saturation = fTPCParam->GetADCSat() - 1;
407ff276 1174 //use internal structure of the AliDigits - for speed reason
1175 //if you cahnge implementation
1176 //of the Alidigits - it must be rewriten -
1177 for (Int_t i= 0; i<nelems; i++){
407ff276 1178 Float_t q = TMath::Nint(Float_t(*pamp0)/16.+GetNoise());
1179 if (q>zerosup){
1180 if (q>saturation) q=saturation;
1181 *pamp1=(Short_t)q;
8c2b3fd7 1182
407ff276 1183 ptracks1[0]=ptracks0[0];
1184 ptracks1[nelems]=ptracks0[nelems];
1185 ptracks1[2*nelems]=ptracks0[2*nelems];
1186 }
1187 pamp0++;
1188 pamp1++;
1189 ptracks0++;
1190 ptracks1++;
1191 }
5f16d237 1192
5f16d237 1193 arr->StoreRow(sec,row);
1194 arr->ClearRow(sec,row);
5f16d237 1195 }
0a61bf9d 1196
0a61bf9d 1197
5f16d237 1198 //write results
88cb7938 1199 fLoader->WriteDigits("OVERWRITE");
5f16d237 1200
88cb7938 1201 delete arr;
afc42102 1202}
1203//__________________________________________________________________
1204void AliTPC::SetDefaults(){
9bdd974b 1205 //
1206 // setting the defaults
1207 //
afc42102 1208
afc42102 1209 // Set response functions
1210
88cb7938 1211 //
024a7e64 1212 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
88cb7938 1213 rl->CdGAFile();
097d753a 1214 //AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
d5981cf4 1215 //gDirectory->Get("75x40_100x60");
097d753a 1216 AliTPCParamSR *param = (AliTPCParamSR*)AliTPCcalibDB::Instance()->GetParameters();
de0e19ab 1217 if(!param){
1218 AliFatal("No TPC parameters found");
d5981cf4 1219 return;
de0e19ab 1220 }
db2fdcfb 1221 if (!param->IsGeoRead()){
1222 //
1223 // read transformation matrices for gGeoManager
1224 //
1225 param->ReadGeoMatrices();
1226 }
de0e19ab 1227
7a09f434 1228
1229
2ab0c725 1230 AliTPCPRF2D * prfinner = new AliTPCPRF2D;
f03e3423 1231 AliTPCPRF2D * prfouter1 = new AliTPCPRF2D;
1232 AliTPCPRF2D * prfouter2 = new AliTPCPRF2D;
bfb1cfbd 1233
afc42102 1234
bfb1cfbd 1235 //AliTPCRF1D * rf = new AliTPCRF1D(kTRUE);
1236 //rf->SetGauss(param->GetZSigma(),param->GetZWidth(),1.);
1237 //rf->SetOffset(3*param->GetZSigma());
1238 //rf->Update();
1239 //
1240 // Use gamma 4
1241 //
1242 char strgamma4[1000];
04c5c48d 1243 sprintf(strgamma4,"AliTPCRF1D::Gamma4((x-0.135+%f)*%f,55,160)",3*param->GetZSigma(), 1000000000*param->GetTSample()/param->GetZWidth());
bfb1cfbd 1244
1245 TF1 * fgamma4 = new TF1("fgamma4",strgamma4, -1,1);
1246 AliTPCRF1D * rf = new AliTPCRF1D(kTRUE,1000);
1247 rf->SetParam(fgamma4,param->GetZWidth(), 1,0.2);
1248 rf->SetOffset(3*param->GetZSigma());
1249 rf->Update();
1250
afc42102 1251 TDirectory *savedir=gDirectory;
2ab0c725 1252 TFile *f=TFile::Open("$ALICE_ROOT/TPC/AliTPCprf2d.root");
8c2b3fd7 1253 if (!f->IsOpen())
1254 AliFatal("Can't open $ALICE_ROOT/TPC/AliTPCprf2d.root !");
2a336e15 1255
1256 TString s;
2ab0c725 1257 prfinner->Read("prf_07504_Gati_056068_d02");
2a336e15 1258 //PH Set different names
1259 s=prfinner->GetGRF()->GetName();
1260 s+="in";
1261 prfinner->GetGRF()->SetName(s.Data());
1262
f03e3423 1263 prfouter1->Read("prf_10006_Gati_047051_d03");
2a336e15 1264 s=prfouter1->GetGRF()->GetName();
1265 s+="out1";
1266 prfouter1->GetGRF()->SetName(s.Data());
1267
f03e3423 1268 prfouter2->Read("prf_15006_Gati_047051_d03");
2a336e15 1269 s=prfouter2->GetGRF()->GetName();
1270 s+="out2";
1271 prfouter2->GetGRF()->SetName(s.Data());
1272
2ab0c725 1273 f->Close();
afc42102 1274 savedir->cd();
1275
2ab0c725 1276 param->SetInnerPRF(prfinner);
f03e3423 1277 param->SetOuter1PRF(prfouter1);
1278 param->SetOuter2PRF(prfouter2);
2ab0c725 1279 param->SetTimeRF(rf);
1280
afc42102 1281 // set fTPCParam
1282
2ab0c725 1283 SetParam(param);
1284
afc42102 1285
1286 fDefaults = 1;
1287
1288}
1289//__________________________________________________________________
85a5290f 1290void AliTPC::Hits2Digits()
1291{
9bdd974b 1292 //
1293 // creates digits from hits
1294 //
506e60a6 1295 if (!fTPCParam->IsGeoRead()){
1296 //
1297 // read transformation matrices for gGeoManager
1298 //
1299 fTPCParam->ReadGeoMatrices();
1300 }
9bdd974b 1301
85a5290f 1302 fLoader->LoadHits("read");
1303 fLoader->LoadDigits("recreate");
1304 AliRunLoader* runLoader = fLoader->GetRunLoader();
1305
1306 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
7ed5ec98 1307 //PH runLoader->GetEvent(iEvent);
85a5290f 1308 Hits2Digits(iEvent);
1309 }
1310
1311 fLoader->UnloadHits();
1312 fLoader->UnloadDigits();
1313}
1314//__________________________________________________________________
afc42102 1315void AliTPC::Hits2Digits(Int_t eventnumber)
1316{
1317 //----------------------------------------------------
1318 // Loop over all sectors for a single event
1319 //----------------------------------------------------
024a7e64 1320 AliRunLoader* rl = (AliRunLoader*)fLoader->GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
88cb7938 1321 rl->GetEvent(eventnumber);
6db60b71 1322 SetActiveSectors();
8c2b3fd7 1323 if (fLoader->TreeH() == 0x0) {
1324 if(fLoader->LoadHits()) {
1325 AliError("Can not load hits.");
1326 }
1327 }
88cb7938 1328 SetTreeAddress();
1329
8c2b3fd7 1330 if (fLoader->TreeD() == 0x0 ) {
1331 fLoader->MakeTree("D");
1332 if (fLoader->TreeD() == 0x0 ) {
1333 AliError("Can not get TreeD");
1334 return;
1335 }
1336 }
afc42102 1337
1338 if(fDefaults == 0) SetDefaults(); // check if the parameters are set
407ff276 1339 GenerNoise(500000); //create teble with noise
2ab0c725 1340
1341 //setup TPCDigitsArray
afc42102 1342
1343 if(GetDigitsArray()) delete GetDigitsArray();
8c2b3fd7 1344
2ab0c725 1345 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1346 arr->SetClass("AliSimDigits");
afc42102 1347 arr->Setup(fTPCParam);
88cb7938 1348
1349 arr->MakeTree(fLoader->TreeD());
2ab0c725 1350 SetDigitsArray(arr);
1351
afc42102 1352 fDigitsSwitch=0; // standard digits
f546a4b4 1353 // here LHC clock phase
1354 Float_t lhcph = 0.;
1355 switch (fLHCclockPhaseSw){
1356 case 0:
1357 // no phase
1358 lhcph=0.;
1359 break;
1360 case 1:
1361 // random phase
1362 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1363 break;
1364 case 2:
1365 lhcph=0.;
1366 // not implemented yet
1367 break;
1368 }
1369 // adding phase to the TreeD user info
1370 fLoader->TreeD()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
1371 //
8c2b3fd7 1372 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1373 if (IsSectorActive(isec)) {
7d85e147 1374 AliDebug(1,Form("Hits2Digits: Sector %d is active.",isec));
8c2b3fd7 1375 Hits2DigitsSector(isec);
1376 }
1377 else {
7d85e147 1378 AliDebug(1,Form("Hits2Digits: Sector %d is NOT active.",isec));
8c2b3fd7 1379 }
1380
88cb7938 1381 fLoader->WriteDigits("OVERWRITE");
f2a509af 1382
1383//this line prevents the crash in the similar one
1384//on the beginning of this method
1385//destructor attempts to reset the tree, which is deleted by the loader
1386//need to be redesign
8c2b3fd7 1387 if(GetDigitsArray()) delete GetDigitsArray();
1388 SetDigitsArray(0x0);
f2a509af 1389
8c555625 1390}
1391
f8cf550c 1392//__________________________________________________________________
0a61bf9d 1393void AliTPC::Hits2SDigits2(Int_t eventnumber)
f8cf550c 1394{
1395
1396 //-----------------------------------------------------------
1397 // summable digits - 16 bit "ADC", no noise, no saturation
1398 //-----------------------------------------------------------
1399
8c2b3fd7 1400 //----------------------------------------------------
1401 // Loop over all sectors for a single event
1402 //----------------------------------------------------
88cb7938 1403
1404 AliRunLoader* rl = fLoader->GetRunLoader();
1405
1406 rl->GetEvent(eventnumber);
8c2b3fd7 1407 if (fLoader->TreeH() == 0x0) {
1408 if(fLoader->LoadHits()) {
1409 AliError("Can not load hits.");
1410 return;
1411 }
1412 }
88cb7938 1413 SetTreeAddress();
f8cf550c 1414
afc42102 1415
8c2b3fd7 1416 if (fLoader->TreeS() == 0x0 ) {
1417 fLoader->MakeTree("S");
1418 }
88cb7938 1419
afc42102 1420 if(fDefaults == 0) SetDefaults();
88cb7938 1421
407ff276 1422 GenerNoise(500000); //create table with noise
afc42102 1423 //setup TPCDigitsArray
1424
1425 if(GetDigitsArray()) delete GetDigitsArray();
1426
88cb7938 1427
afc42102 1428 AliTPCDigitsArray *arr = new AliTPCDigitsArray;
1429 arr->SetClass("AliSimDigits");
1430 arr->Setup(fTPCParam);
88cb7938 1431 arr->MakeTree(fLoader->TreeS());
1432
afc42102 1433 SetDigitsArray(arr);
1434
afc42102 1435 fDigitsSwitch=1; // summable digits
5f16d237 1436
1437 // set zero suppression to "0"
f546a4b4 1438 // here LHC clock phase
1439 Float_t lhcph = 0.;
1440 switch (fLHCclockPhaseSw){
1441 case 0:
1442 // no phase
1443 lhcph=0.;
1444 break;
1445 case 1:
1446 // random phase
1447 lhcph = (Int_t)(gRandom->Rndm()/0.25);
1448 break;
1449 case 2:
1450 lhcph=0.;
1451 // not implemented yet
1452 break;
1453 }
1454 // adding phase to the TreeS user info
1455
1456 fLoader->TreeS()->GetUserInfo()->Add(new TParameter<float>("lhcphase0",lhcph));
5f16d237 1457
1458 fTPCParam->SetZeroSup(0);
f8cf550c 1459
8c2b3fd7 1460 for(Int_t isec=0;isec<fTPCParam->GetNSector();isec++)
1461 if (IsSectorActive(isec)) {
1462 Hits2DigitsSector(isec);
1463 }
88cb7938 1464
8c2b3fd7 1465 fLoader->WriteSDigits("OVERWRITE");
88cb7938 1466
1467//this line prevents the crash in the similar one
1468//on the beginning of this method
1469//destructor attempts to reset the tree, which is deleted by the loader
1470//need to be redesign
8c2b3fd7 1471 if(GetDigitsArray()) delete GetDigitsArray();
1472 SetDigitsArray(0x0);
f8cf550c 1473}
0a61bf9d 1474//__________________________________________________________________
88cb7938 1475
0a61bf9d 1476void AliTPC::Hits2SDigits()
1477{
1478
1479 //-----------------------------------------------------------
1480 // summable digits - 16 bit "ADC", no noise, no saturation
1481 //-----------------------------------------------------------
1482
506e60a6 1483 if (!fTPCParam->IsGeoRead()){
1484 //
1485 // read transformation matrices for gGeoManager
1486 //
1487 fTPCParam->ReadGeoMatrices();
1488 }
1489
85a5290f 1490 fLoader->LoadHits("read");
1491 fLoader->LoadSDigits("recreate");
1492 AliRunLoader* runLoader = fLoader->GetRunLoader();
0a61bf9d 1493
85a5290f 1494 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1495 runLoader->GetEvent(iEvent);
1496 SetTreeAddress();
1497 SetActiveSectors();
1498 Hits2SDigits2(iEvent);
1499 }
f546a4b4 1500
85a5290f 1501 fLoader->UnloadHits();
1502 fLoader->UnloadSDigits();
23effa8e 1503 if (fDebugStreamer) {
1504 delete fDebugStreamer;
1505 fDebugStreamer=0;
1506 }
0a61bf9d 1507}
fe4da5cc 1508//_____________________________________________________________________________
88cb7938 1509
8c555625 1510void AliTPC::Hits2DigitsSector(Int_t isec)
fe4da5cc 1511{
8c555625 1512 //-------------------------------------------------------------------
fe4da5cc 1513 // TPC conversion from hits to digits.
8c555625 1514 //-------------------------------------------------------------------
1515
1516 //-----------------------------------------------------------------
1517 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1518 //-----------------------------------------------------------------
1519
fe4da5cc 1520 //-------------------------------------------------------
8c555625 1521 // Get the access to the track hits
fe4da5cc 1522 //-------------------------------------------------------
8c555625 1523
afc42102 1524 // check if the parameters are set - important if one calls this method
1525 // directly, not from the Hits2Digits
1526
1527 if(fDefaults == 0) SetDefaults();
cc80f89e 1528
cb5b8b21 1529 TTree *tH = fLoader->TreeH(); // pointer to the hits tree
8c2b3fd7 1530 if (tH == 0x0) {
1531 AliFatal("Can not find TreeH in folder");
1532 return;
1533 }
88cb7938 1534
73042f01 1535 Stat_t ntracks = tH->GetEntries();
8c555625 1536
8c2b3fd7 1537 Int_t nrows =fTPCParam->GetNRow(isec);
8c555625 1538
606d6545 1539 TObjArray **row=new TObjArray* [nrows+2]; // 2 extra rows for cross talk
1540 for(Int_t j=0;j<nrows+2;j++) row[j]=0;
fe4da5cc 1541
8c2b3fd7 1542 MakeSector(isec,nrows,tH,ntracks,row);
8c555625 1543
8c2b3fd7 1544 //--------------------------------------------------------
1545 // Digitize this sector, row by row
1546 // row[i] is the pointer to the TObjArray of TVectors,
1547 // each one containing electrons accepted on this
1548 // row, assigned into tracks
1549 //--------------------------------------------------------
8c555625 1550
8c2b3fd7 1551 Int_t i;
8c555625 1552
8c2b3fd7 1553 if (fDigitsArray->GetTree()==0) {
1554 AliFatal("Tree not set in fDigitsArray");
1555 }
8c555625 1556
8c2b3fd7 1557 for (i=0;i<nrows;i++){
1558
1559 AliDigits * dig = fDigitsArray->CreateRow(isec,i);
8c555625 1560
8c2b3fd7 1561 DigitizeRow(i,isec,row);
8c555625 1562
8c2b3fd7 1563 fDigitsArray->StoreRow(isec,i);
8c555625 1564
8c2b3fd7 1565 Int_t ndig = dig->GetDigitSize();
88cb7938 1566
8c2b3fd7 1567 AliDebug(10,
1568 Form("*** Sector, row, compressed digits %d %d %d ***\n",
1569 isec,i,ndig));
792bb11c 1570
8c2b3fd7 1571 fDigitsArray->ClearRow(isec,i);
8c555625 1572
cc80f89e 1573
8c2b3fd7 1574 } // end of the sector digitization
8c555625 1575
8c2b3fd7 1576 for(i=0;i<nrows+2;i++){
1577 row[i]->Delete();
1578 delete row[i];
1579 }
cc80f89e 1580
8c2b3fd7 1581 delete [] row; // delete the array of pointers to TObjArray-s
8c555625 1582
8c555625 1583
cc80f89e 1584} // end of Hits2DigitsSector
8c555625 1585
8c555625 1586
8c555625 1587//_____________________________________________________________________________
cc80f89e 1588void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
8c555625 1589{
1590 //-----------------------------------------------------------
1591 // Single row digitization, coupling from the neighbouring
1592 // rows taken into account
1593 //-----------------------------------------------------------
1594
1595 //-----------------------------------------------------------------
1596 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
cc80f89e 1597 // Modified: Marian Ivanov GSI Darmstadt, m.ivanov@gsi.de
8c555625 1598 //-----------------------------------------------------------------
1599
8c555625 1600 Float_t zerosup = fTPCParam->GetZeroSup();
28c55807 1601 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
1602 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
1603 AliTPCCalROC * gainROC = gainTPC->GetCalROC(isec); // pad gains per given sector
1604 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(isec); // noise per given sector
1605
8c2b3fd7 1606
cc80f89e 1607 fCurrentIndex[1]= isec;
8c555625 1608
8c555625 1609
73042f01 1610 Int_t nofPads = fTPCParam->GetNPads(isec,irow);
1611 Int_t nofTbins = fTPCParam->GetMaxTBin();
1612 Int_t indexRange[4];
8c555625 1613 //
1614 // Integrated signal for this row
1615 // and a single track signal
cc80f89e 1616 //
de61d5d5 1617
e8d02863 1618 TMatrixF *m1 = new TMatrixF(0,nofPads,0,nofTbins); // integrated
1619 TMatrixF *m2 = new TMatrixF(0,nofPads,0,nofTbins); // single
8c555625 1620 //
e8d02863 1621 TMatrixF &total = *m1;
8c555625 1622
1623 // Array of pointers to the label-signal list
1624
73042f01 1625 Int_t nofDigits = nofPads*nofTbins; // number of digits for this row
1626 Float_t **pList = new Float_t* [nofDigits];
8c555625 1627
1628 Int_t lp;
cc80f89e 1629 Int_t i1;
73042f01 1630 for(lp=0;lp<nofDigits;lp++)pList[lp]=0; // set all pointers to NULL
8c555625 1631 //
cc80f89e 1632 //calculate signal
1633 //
b584c7dd 1634 Int_t row1=irow;
1635 Int_t row2=irow+2;
cc80f89e 1636 for (Int_t row= row1;row<=row2;row++){
1637 Int_t nTracks= rows[row]->GetEntries();
1638 for (i1=0;i1<nTracks;i1++){
1639 fCurrentIndex[2]= row;
b584c7dd 1640 fCurrentIndex[3]=irow+1;
1641 if (row==irow+1){
cc80f89e 1642 m2->Zero(); // clear single track signal matrix
73042f01 1643 Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange);
1644 GetList(trackLabel,nofPads,m2,indexRange,pList);
cc80f89e 1645 }
73042f01 1646 else GetSignal(rows[row],i1,0,m1,indexRange);
cc80f89e 1647 }
8c555625 1648 }
cc80f89e 1649
8c555625 1650 Int_t tracks[3];
8c555625 1651
cc80f89e 1652 AliDigits *dig = fDigitsArray->GetRow(isec,irow);
de61d5d5 1653 Int_t gi=-1;
1654 Float_t fzerosup = zerosup+0.5;
1655 for(Int_t it=0;it<nofTbins;it++){
de61d5d5 1656 for(Int_t ip=0;ip<nofPads;ip++){
1657 gi++;
8c2b3fd7 1658 Float_t q=total(ip,it);
28c55807 1659 if(fDigitsSwitch == 0){
1660 Float_t gain = gainROC->GetValue(irow,ip); // get gain for given - pad-row pad
1661 Float_t noisePad = noiseROC->GetValue(irow,ip);
1662 //
1663 q*=gain;
1664 q+=GetNoise()*noisePad;
de61d5d5 1665 if(q <=fzerosup) continue; // do not fill zeros
68771f83 1666 q = TMath::Nint(q);
e93a083a 1667 if(q >= fTPCParam->GetADCSat()) q = fTPCParam->GetADCSat() - 1; // saturation
cc80f89e 1668
f8cf550c 1669 }
1670
1671 else {
8c2b3fd7 1672 if(q <= 0.) continue; // do not fill zeros
1673 if(q>2000.) q=2000.;
1674 q *= 16.;
1675 q = TMath::Nint(q);
f8cf550c 1676 }
8c555625 1677
1678 //
1679 // "real" signal or electronic noise (list = -1)?
1680 //
1681
1682 for(Int_t j1=0;j1<3;j1++){
407ff276 1683 tracks[j1] = (pList[gi]) ?(Int_t)(*(pList[gi]+j1)) : -2;
8c555625 1684 }
1685
cc80f89e 1686//Begin_Html
1687/*
1688 <A NAME="AliDigits"></A>
1689 using of AliDigits object
1690*/
1691//End_Html
1692 dig->SetDigitFast((Short_t)q,it,ip);
8c2b3fd7 1693 if (fDigitsArray->IsSimulated()) {
1694 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[0],it,ip,0);
1695 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[1],it,ip,1);
1696 ((AliSimDigits*)dig)->SetTrackIDFast(tracks[2],it,ip,2);
1697 }
8c555625 1698
1699 } // end of loop over time buckets
1700 } // end of lop over pads
58c45a5e 1701 //
1702 // test
1703 //
1704 //
8c555625 1705
58c45a5e 1706 // glitch filters if normal simulated digits
1707 //
1708 if(!fDigitsSwitch) ((AliSimDigits*)dig)->GlitchFilter();
8c555625 1709 //
1710 // This row has been digitized, delete nonused stuff
1711 //
1712
73042f01 1713 for(lp=0;lp<nofDigits;lp++){
8c555625 1714 if(pList[lp]) delete [] pList[lp];
1715 }
1716
1717 delete [] pList;
1718
1719 delete m1;
1720 delete m2;
8c555625 1721
1722} // end of DigitizeRow
cc80f89e 1723
8c555625 1724//_____________________________________________________________________________
cc80f89e 1725
de61d5d5 1726Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
e8d02863 1727 TMatrixF *m1, TMatrixF *m2,Int_t *indexRange)
8c555625 1728{
1729
1730 //---------------------------------------------------------------
1731 // Calculates 2-D signal (pad,time) for a single track,
1732 // returns a pointer to the signal matrix and the track label
1733 // No digitization is performed at this level!!!
1734 //---------------------------------------------------------------
1735
1736 //-----------------------------------------------------------------
1737 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
cc80f89e 1738 // Modified: Marian Ivanov
8c555625 1739 //-----------------------------------------------------------------
1740
8c2b3fd7 1741 TVector *tv;
de61d5d5 1742
8c2b3fd7 1743 tv = (TVector*)p1->At(ntr); // pointer to a track
1744 TVector &v = *tv;
8c555625 1745
1746 Float_t label = v(0);
506e60a6 1747 Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1))/2;
8c555625 1748
e61fd20d 1749 Int_t nElectrons = (tv->GetNrows()-1)/5;
73042f01 1750 indexRange[0]=9999; // min pad
1751 indexRange[1]=-1; // max pad
1752 indexRange[2]=9999; //min time
1753 indexRange[3]=-1; // max time
8c555625 1754
e8d02863 1755 TMatrixF &signal = *m1;
1756 TMatrixF &total = *m2;
8c555625 1757 //
f546a4b4 1758 // Get LHC clock phase
1759 //
1760 TParameter<float> *ph;
1761 if(fDigitsSwitch){// s-digits
1762 ph = (TParameter<float>*)fLoader->TreeS()->GetUserInfo()->FindObject("lhcphase0");
1763 }
1764 else{ // normal digits
1765 ph = (TParameter<float>*)fLoader->TreeD()->GetUserInfo()->FindObject("lhcphase0");
1766 }
8c555625 1767 // Loop over all electrons
1768 //
8c555625 1769 for(Int_t nel=0; nel<nElectrons; nel++){
e61fd20d 1770 Int_t idx=nel*5;
cc80f89e 1771 Float_t aval = v(idx+4);
1772 Float_t eltoadcfac=aval*fTPCParam->GetTotalNormFac();
e61fd20d 1773 Float_t xyz[4]={v(idx+1),v(idx+2),v(idx+3),v(idx+5)};
f546a4b4 1774 Int_t n = ((AliTPCParamSR*)fTPCParam)->CalcResponseFast(xyz,fCurrentIndex,
1775 fCurrentIndex[3],ph->GetVal());
de61d5d5 1776
1777 Int_t *index = fTPCParam->GetResBin(0);
1778 Float_t *weight = & (fTPCParam->GetResWeight(0));
1779
1780 if (n>0) for (Int_t i =0; i<n; i++){
e30e6a9c 1781 Int_t pad=index[1]+centralPad; //in digit coordinates central pad has coordinate 0
8c2b3fd7 1782
1783 if (pad>=0){
1784 Int_t time=index[2];
1785 Float_t qweight = *(weight)*eltoadcfac;
1786
1787 if (m1!=0) signal(pad,time)+=qweight;
1788 total(pad,time)+=qweight;
1789 if (indexRange[0]>pad) indexRange[0]=pad;
1790 if (indexRange[1]<pad) indexRange[1]=pad;
1791 if (indexRange[2]>time) indexRange[2]=time;
1792 if (indexRange[3]<time) indexRange[3]=time;
1793
1794 index+=3;
1795 weight++;
1796
1797 }
cc80f89e 1798 }
8c555625 1799 } // end of loop over electrons
cc80f89e 1800
8c555625 1801 return label; // returns track label when finished
1802}
1803
1804//_____________________________________________________________________________
e8d02863 1805void AliTPC::GetList(Float_t label,Int_t np,TMatrixF *m,
de61d5d5 1806 Int_t *indexRange, Float_t **pList)
8c555625 1807{
1808 //----------------------------------------------------------------------
1809 // Updates the list of tracks contributing to digits for a given row
1810 //----------------------------------------------------------------------
1811
1812 //-----------------------------------------------------------------
1813 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
1814 //-----------------------------------------------------------------
1815
e8d02863 1816 TMatrixF &signal = *m;
8c555625 1817
1818 // lop over nonzero digits
1819
73042f01 1820 for(Int_t it=indexRange[2];it<indexRange[3]+1;it++){
1821 for(Int_t ip=indexRange[0];ip<indexRange[1]+1;ip++){
8c555625 1822
1823
8c2b3fd7 1824 // accept only the contribution larger than 500 electrons (1/2 s_noise)
921bf71a 1825
8c2b3fd7 1826 if(signal(ip,it)<0.5) continue;
921bf71a 1827
8c2b3fd7 1828 Int_t globalIndex = it*np+ip; // globalIndex starts from 0!
8c555625 1829
8c2b3fd7 1830 if(!pList[globalIndex]){
8c555625 1831
8c2b3fd7 1832 //
1833 // Create new list (6 elements - 3 signals and 3 labels),
1834 //
8c555625 1835
8c2b3fd7 1836 pList[globalIndex] = new Float_t [6];
8c555625 1837
8c2b3fd7 1838 // set list to -1
1839
1840 *pList[globalIndex] = -1.;
1841 *(pList[globalIndex]+1) = -1.;
1842 *(pList[globalIndex]+2) = -1.;
1843 *(pList[globalIndex]+3) = -1.;
1844 *(pList[globalIndex]+4) = -1.;
1845 *(pList[globalIndex]+5) = -1.;
1846
1847 *pList[globalIndex] = label;
1848 *(pList[globalIndex]+3) = signal(ip,it);
1849 }
1850 else {
8c555625 1851
8c2b3fd7 1852 // check the signal magnitude
8c555625 1853
8c2b3fd7 1854 Float_t highest = *(pList[globalIndex]+3);
1855 Float_t middle = *(pList[globalIndex]+4);
1856 Float_t lowest = *(pList[globalIndex]+5);
1857
1858 //
1859 // compare the new signal with already existing list
1860 //
1861
1862 if(signal(ip,it)<lowest) continue; // neglect this track
8c555625 1863
8c2b3fd7 1864 //
8c555625 1865
8c2b3fd7 1866 if (signal(ip,it)>highest){
1867 *(pList[globalIndex]+5) = middle;
1868 *(pList[globalIndex]+4) = highest;
1869 *(pList[globalIndex]+3) = signal(ip,it);
1870
1871 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1872 *(pList[globalIndex]+1) = *pList[globalIndex];
1873 *pList[globalIndex] = label;
1874 }
1875 else if (signal(ip,it)>middle){
1876 *(pList[globalIndex]+5) = middle;
1877 *(pList[globalIndex]+4) = signal(ip,it);
1878
1879 *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
1880 *(pList[globalIndex]+1) = label;
1881 }
1882 else{
1883 *(pList[globalIndex]+5) = signal(ip,it);
1884 *(pList[globalIndex]+2) = label;
1885 }
1886 }
1887
8c555625 1888 } // end of loop over pads
1889 } // end of loop over time bins
1890
8c555625 1891}//end of GetList
1892//___________________________________________________________________
1893void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
1894 Stat_t ntracks,TObjArray **row)
1895{
1896
1897 //-----------------------------------------------------------------
1898 // Prepares the sector digitization, creates the vectors of
1899 // tracks for each row of this sector. The track vector
1900 // contains the track label and the position of electrons.
1901 //-----------------------------------------------------------------
1902
79fa3dc8 1903 //
1904 // The trasport of the electrons through TPC drift volume
1905 // Drift (drift velocity + velocity map(not yet implemented)))
1906 // Application of the random processes (diffusion, gas gain)
1907 // Systematic effects (ExB effect in drift volume + ROCs)
1908 //
1909 // Algorithm:
1910 // Loop over primary electrons:
1911 // Creation of the secondary electrons
1912 // Loop over electrons (primary+ secondaries)
1913 // Global coordinate frame:
1914 // 1. Skip electrons if attached
1915 // 2. ExB effect in drift volume
1916 // a.) Simulation calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1917 // b.) Reconstruction - calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
1918 // 3. Generation of gas gain (Random - Exponential distribution)
1919 // 4. TransportElectron function (diffusion)
1920 //
1921 // 5. Conversion to the local coordinate frame pad-row, pad, timebin
1922 // 6. Apply Time0 shift - AliTPCCalPad class
1923 // a.) Plus sign in simulation
1924 // b.) Minus sign in reconstruction
1925 // end of loop
1926 //
8c555625 1927 //-----------------------------------------------------------------
1928 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
79fa3dc8 1929 // Origin: Marian Ivanov, marian.ivanov@cern.ch
8c555625 1930 //-----------------------------------------------------------------
79fa3dc8 1931 AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
7bab76cf 1932 if (gAlice){ // Set correctly the magnetic field in the ExB calculation
9ac65c7c 1933 if (!calib->GetExB()){
1934 AliMagF * field = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField());
1935 if (field) {
1936 calib->SetExBField(field);
1937 }
7bab76cf 1938 }
1939 }
8c555625 1940
cc80f89e 1941 Float_t gasgain = fTPCParam->GetGasGain();
8261c673 1942 gasgain = gasgain/fGainFactor;
8c555625 1943 Int_t i;
e61fd20d 1944 Float_t xyz[5];
8c555625 1945
1946 AliTPChit *tpcHit; // pointer to a sigle TPC hit
39c8eb58 1947 //MI change
1948 TBranch * branch=0;
792bb11c 1949 if (fHitType>1) branch = TH->GetBranch("TPC2");
39c8eb58 1950 else branch = TH->GetBranch("TPC");
1951
8c555625 1952
1953 //----------------------------------------------
1954 // Create TObjArray-s, one for each row,
8c2b3fd7 1955 // each TObjArray will store the TVectors
1956 // of electrons, one TVectors per each track.
8c555625 1957 //----------------------------------------------
1958
b584c7dd 1959 Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
8c2b3fd7 1960 TVector **tracks = new TVector* [nrows+2]; //pointers to the track vectors
de61d5d5 1961
b584c7dd 1962 for(i=0; i<nrows+2; i++){
8c555625 1963 row[i] = new TObjArray;
f74bb6f5 1964 nofElectrons[i]=0;
1965 tracks[i]=0;
8c555625 1966 }
8c555625 1967
37831078 1968
1969
8c555625 1970 //--------------------------------------------------------------------
1971 // Loop over tracks, the "track" contains the full history
1972 //--------------------------------------------------------------------
8c2b3fd7 1973
8c555625 1974 Int_t previousTrack,currentTrack;
1975 previousTrack = -1; // nothing to store so far!
1976
1977 for(Int_t track=0;track<ntracks;track++){
39c8eb58 1978 Bool_t isInSector=kTRUE;
8c555625 1979 ResetHits();
792bb11c 1980 isInSector = TrackInVolume(isec,track);
39c8eb58 1981 if (!isInSector) continue;
1982 //MI change
1983 branch->GetEntry(track); // get next track
8c2b3fd7 1984
39c8eb58 1985 //M.I. changes
8c555625 1986
39c8eb58 1987 tpcHit = (AliTPChit*)FirstHit(-1);
8c555625 1988
1989 //--------------------------------------------------------------
1990 // Loop over hits
1991 //--------------------------------------------------------------
1992
8c555625 1993
39c8eb58 1994 while(tpcHit){
8c555625 1995
1996 Int_t sector=tpcHit->fSector; // sector number
39c8eb58 1997 if(sector != isec){
1998 tpcHit = (AliTPChit*) NextHit();
1999 continue;
2000 }
8c555625 2001
daf14717 2002 // Remove hits which arrive before the TPC opening gate signal
a1ec4d07 2003 if(((fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
daf14717 2004 /fTPCParam->GetDriftV()+tpcHit->Time())<fTPCParam->GetGateDelay()) {
2005 tpcHit = (AliTPChit*) NextHit();
2006 continue;
2007 }
2008
8c2b3fd7 2009 currentTrack = tpcHit->Track(); // track number
39c8eb58 2010
8c2b3fd7 2011 if(currentTrack != previousTrack){
8c555625 2012
8c2b3fd7 2013 // store already filled fTrack
8c555625 2014
8c2b3fd7 2015 for(i=0;i<nrows+2;i++){
2016 if(previousTrack != -1){
2017 if(nofElectrons[i]>0){
2018 TVector &v = *tracks[i];
2019 v(0) = previousTrack;
e61fd20d 2020 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
8c2b3fd7 2021 row[i]->Add(tracks[i]);
2022 }
2023 else {
2024 delete tracks[i]; // delete empty TVector
2025 tracks[i]=0;
2026 }
2027 }
2028
2029 nofElectrons[i]=0;
e61fd20d 2030 tracks[i] = new TVector(601); // TVectors for the next fTrack
8c2b3fd7 2031
2032 } // end of loop over rows
8c555625 2033
8c2b3fd7 2034 previousTrack=currentTrack; // update track label
2035 }
8c555625 2036
8c2b3fd7 2037 Int_t qI = (Int_t) (tpcHit->fQ); // energy loss (number of electrons)
8c555625 2038
8c2b3fd7 2039 //---------------------------------------------------
2040 // Calculate the electron attachment probability
2041 //---------------------------------------------------
8c555625 2042
cc80f89e 2043
a1ec4d07 2044 Float_t time = 1.e6*(fTPCParam->GetZLength(isec)-TMath::Abs(tpcHit->Z()))
8c2b3fd7 2045 /fTPCParam->GetDriftV();
2046 // in microseconds!
2047 Float_t attProb = fTPCParam->GetAttCoef()*
2048 fTPCParam->GetOxyCont()*time; // fraction!
8c555625 2049
8c2b3fd7 2050 //-----------------------------------------------
2051 // Loop over electrons
2052 //-----------------------------------------------
2053 Int_t index[3];
2054 index[1]=isec;
2055 for(Int_t nel=0;nel<qI;nel++){
2056 // skip if electron lost due to the attachment
2057 if((gRandom->Rndm(0)) < attProb) continue; // electron lost!
79fa3dc8 2058
2059 //
2060 // ExB effect
2061 //
2062 Double_t dxyz0[3],dxyz1[3];
2063 dxyz0[0]=tpcHit->X();
2064 dxyz0[1]=tpcHit->Y();
2065 dxyz0[2]=tpcHit->Z();
2066 if (calib->GetExB()){
2067 calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
2068 }else{
2069 AliError("Not valid ExB calibration");
2070 dxyz1[0]=tpcHit->X();
2071 dxyz1[1]=tpcHit->Y();
2072 dxyz1[2]=tpcHit->Z();
2073 }
2074 xyz[0]=dxyz1[0];
2075 xyz[1]=dxyz1[1];
2076 xyz[2]=dxyz1[2];
2077 //
2078 //
8c2b3fd7 2079 //
2080 // protection for the nonphysical avalanche size (10**6 maximum)
2081 //
2082 Double_t rn=TMath::Max(gRandom->Rndm(0),1.93e-22);
2083 xyz[3]= (Float_t) (-gasgain*TMath::Log(rn));
2084 index[0]=1;
79fa3dc8 2085
8c2b3fd7 2086 TransportElectron(xyz,index);
2087 Int_t rowNumber;
23effa8e 2088 Int_t padrow = fTPCParam->GetPadRow(xyz,index);
79fa3dc8 2089 //
2090 // Add Time0 correction due unisochronity
2091 // xyz[0] - pad row coordinate
2092 // xyz[1] - pad coordinate
2093 // xyz[2] - is in now time bin coordinate system
2094 Float_t correction =0;
2095 if (calib->GetPadTime0()){
23effa8e 2096 if (!calib->GetPadTime0()->GetCalROC(isec)) continue;
2097 Int_t npads = fTPCParam->GetNPads(isec,padrow);
17807087 2098 // Int_t pad = TMath::Nint(xyz[1]+fTPCParam->GetNPads(isec,TMath::Nint(xyz[0]))*0.5);
23effa8e 2099 // pad numbering from -npads/2 .. npads/2-1
2100 Int_t pad = TMath::Nint(xyz[1]+npads/2);
17807087 2101 if (pad<0) pad=0;
2102 if (pad>=npads) pad=npads-1;
23effa8e 2103 correction = calib->GetPadTime0()->GetCalROC(isec)->GetValue(padrow,pad);
2104 // printf("%d\t%d\t%d\t%f\n",isec,padrow,pad,correction);
2105 if (fDebugStreamer){
2106 (*fDebugStreamer)<<"Time0"<<
2107 "isec="<<isec<<
2108 "padrow="<<padrow<<
2109 "pad="<<pad<<
2110 "x0="<<xyz[0]<<
2111 "x1="<<xyz[1]<<
2112 "x2="<<xyz[2]<<
2113 "hit.="<<tpcHit<<
2114 "cor="<<correction<<
2115 "\n";
2116 }
79fa3dc8 2117 }
2118 xyz[2]+=correction;
c2940e77 2119 xyz[2]+=fTPCParam->GetNTBinsL1(); // adding Level 1 time bin offset
79fa3dc8 2120 //
e61fd20d 2121 // Electron track time (for pileup simulation)
c2940e77 2122 xyz[2]+=tpcHit->Time()/fTPCParam->GetTSample(); // adding time of flight
2123 xyz[4] =0;
2124
2125 //
8c2b3fd7 2126 // row 0 - cross talk from the innermost row
2127 // row fNRow+1 cross talk from the outermost row
2128 rowNumber = index[2]+1;
2129 //transform position to local digit coordinates
2130 //relative to nearest pad row
2131 if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
4555e0d2 2132 /* Float_t x1,y1;
8c2b3fd7 2133 if (isec <fTPCParam->GetNInnerSector()) {
2134 x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
2135 y1 = fTPCParam->GetYInner(rowNumber);
2136 }
2137 else{
2138 x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
2139 y1 = fTPCParam->GetYOuter(rowNumber);
2140 }
2141 // gain inefficiency at the wires edges - linear
2142 x1=TMath::Abs(x1);
2143 y1-=1.;
4555e0d2 2144 if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.)); */
8c2b3fd7 2145
2146 nofElectrons[rowNumber]++;
2147 //----------------------------------
2148 // Expand vector if necessary
2149 //----------------------------------
2150 if(nofElectrons[rowNumber]>120){
2151 Int_t range = tracks[rowNumber]->GetNrows();
e61fd20d 2152 if((nofElectrons[rowNumber])>(range-1)/5){
8c2b3fd7 2153
e61fd20d 2154 tracks[rowNumber]->ResizeTo(range+500); // Add 100 electrons
fe4da5cc 2155 }
8c2b3fd7 2156 }
2157
2158 TVector &v = *tracks[rowNumber];
e61fd20d 2159 Int_t idx = 5*nofElectrons[rowNumber]-4;
8c2b3fd7 2160 Real_t * position = &(((TVector&)v)(idx)); //make code faster
e61fd20d 2161 memcpy(position,xyz,5*sizeof(Float_t));
8c2b3fd7 2162
2163 } // end of loop over electrons
39c8eb58 2164
8c2b3fd7 2165 tpcHit = (AliTPChit*)NextHit();
2166
2167 } // end of loop over hits
2168 } // end of loop over tracks
8c555625 2169
2170 //
2171 // store remaining track (the last one) if not empty
2172 //
8c2b3fd7 2173
2174 for(i=0;i<nrows+2;i++){
2175 if(nofElectrons[i]>0){
2176 TVector &v = *tracks[i];
2177 v(0) = previousTrack;
e61fd20d 2178 tracks[i]->ResizeTo(5*nofElectrons[i]+1); // shrink if necessary
8c2b3fd7 2179 row[i]->Add(tracks[i]);
2180 }
2181 else{
2182 delete tracks[i];
2183 tracks[i]=0;
2184 }
2185 }
2186
2187 delete [] tracks;
2188 delete [] nofElectrons;
8c555625 2189
cc80f89e 2190} // end of MakeSector
8c555625 2191
fe4da5cc 2192
2193//_____________________________________________________________________________
2194void AliTPC::Init()
2195{
2196 //
2197 // Initialise TPC detector after definition of geometry
2198 //
8c2b3fd7 2199 AliDebug(1,"*********************************************");
fe4da5cc 2200}
2201
fe4da5cc 2202//_____________________________________________________________________________
2203void AliTPC::ResetDigits()
2204{
2205 //
2206 // Reset number of digits and the digits array for this detector
fe4da5cc 2207 //
2208 fNdigits = 0;
cc80f89e 2209 if (fDigits) fDigits->Clear();
fe4da5cc 2210}
2211
fe4da5cc 2212
fe4da5cc 2213
2214//_____________________________________________________________________________
2215void AliTPC::SetSens(Int_t sens)
2216{
8c555625 2217
2218 //-------------------------------------------------------------
2219 // Activates/deactivates the sensitive strips at the center of
2220 // the pad row -- this is for the space-point resolution calculations
2221 //-------------------------------------------------------------
2222
2223 //-----------------------------------------------------------------
2224 // Origin: Marek Kowalski IFJ, Krakow, Marek.Kowalski@ifj.edu.pl
2225 //-----------------------------------------------------------------
2226
fe4da5cc 2227 fSens = sens;
2228}
2b06d5c3 2229
4b0fdcad 2230
73042f01 2231void AliTPC::SetSide(Float_t side=0.)
4b0fdcad 2232{
73042f01 2233 // choice of the TPC side
2234
4b0fdcad 2235 fSide = side;
2236
2237}
cc80f89e 2238//_____________________________________________________________________________
2239
2240void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
2241{
2242 //
2243 // electron transport taking into account:
2244 // 1. diffusion,
2245 // 2.ExB at the wires
2246 // 3. nonisochronity
2247 //
2248 // xyz and index must be already transformed to system 1
2249 //
2250
23effa8e 2251 fTPCParam->Transform1to2(xyz,index); // mis-alignment applied in this step
cc80f89e 2252
2253 //add diffusion
2254 Float_t driftl=xyz[2];
2255 if(driftl<0.01) driftl=0.01;
2256 driftl=TMath::Sqrt(driftl);
73042f01 2257 Float_t sigT = driftl*(fTPCParam->GetDiffT());
2258 Float_t sigL = driftl*(fTPCParam->GetDiffL());
2259 xyz[0]=gRandom->Gaus(xyz[0],sigT);
2260 xyz[1]=gRandom->Gaus(xyz[1],sigT);
2261 xyz[2]=gRandom->Gaus(xyz[2],sigL);
cc80f89e 2262
2263 // ExB
2264
2265 if (fTPCParam->GetMWPCReadout()==kTRUE){
b584c7dd 2266 Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
cc80f89e 2267 xyz[1]+=dx*(fTPCParam->GetOmegaTau());
2268 }
79fa3dc8 2269 //add nonisochronity (not implemented yet)
2270
2271
1283eee5 2272}
fe4da5cc 2273
fe4da5cc 2274ClassImp(AliTPChit)
179c6296 2275 //______________________________________________________________________
2276 AliTPChit::AliTPChit()
2277 :AliHit(),
2278 fSector(0),
2279 fPadRow(0),
2280 fQ(0),
2281 fTime(0)
2282{
2283 //
2284 // default
2285 //
2286
2287}
fe4da5cc 2288//_____________________________________________________________________________
179c6296 2289AliTPChit::AliTPChit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits)
2290 :AliHit(shunt,track),
2291 fSector(0),
2292 fPadRow(0),
2293 fQ(0),
2294 fTime(0)
fe4da5cc 2295{
2296 //
2297 // Creates a TPC hit object
2298 //
2299 fSector = vol[0];
2300 fPadRow = vol[1];
2301 fX = hits[0];
2302 fY = hits[1];
2303 fZ = hits[2];
2304 fQ = hits[3];
e61fd20d 2305 fTime = hits[4];
fe4da5cc 2306}
2307
39c8eb58 2308//________________________________________________________________________
792bb11c 2309// Additional code because of the AliTPCTrackHitsV2
39c8eb58 2310
a6005888 2311void AliTPC::MakeBranch(Option_t *option)
39c8eb58 2312{
2313 //
2314 // Create a new branch in the current Root Tree
2315 // The branch of fHits is automatically split
2316 // MI change 14.09.2000
8c2b3fd7 2317 AliDebug(1,"");
792bb11c 2318 if (fHitType<2) return;
39c8eb58 2319 char branchname[10];
2320 sprintf(branchname,"%s2",GetName());
2321 //
2322 // Get the pointer to the header
5cf7bbad 2323 const char *cH = strstr(option,"H");
39c8eb58 2324 //
cb5b8b21 2325 if (fTrackHits && fLoader->TreeH() && cH && fHitType&4) {
8c2b3fd7 2326 AliDebug(1,"Making branch for Type 4 Hits");
cb5b8b21 2327 fLoader->TreeH()->Branch(branchname,"AliTPCTrackHitsV2",&fTrackHits,fBufferSize,99);
8c2b3fd7 2328 }
792bb11c 2329
cb5b8b21 2330// if (fTrackHitsOld && fLoader->TreeH() && cH && fHitType&2) {
be5ffbfe 2331// AliDebug(1,"Making branch for Type 2 Hits");
2332// AliObjectBranch * branch = new AliObjectBranch(branchname,"AliTPCTrackHits",&fTrackHitsOld,
cb5b8b21 2333// fLoader->TreeH(),fBufferSize,99);
2334// fLoader->TreeH()->GetListOfBranches()->Add(branch);
be5ffbfe 2335// }
39c8eb58 2336}
2337
2338void AliTPC::SetTreeAddress()
2339{
8c2b3fd7 2340 //Sets tree address for hits
2341 if (fHitType<=1) {
2342 if (fHits == 0x0 ) fHits = new TClonesArray("AliTPChit", 176);//skowron 20.06.03
2343 AliDetector::SetTreeAddress();
2344 }
792bb11c 2345 if (fHitType>1) SetTreeAddress2();
39c8eb58 2346}
2347
2348void AliTPC::SetTreeAddress2()
2349{
2350 //
2351 // Set branch address for the TrackHits Tree
2352 //
8c2b3fd7 2353 AliDebug(1,"");
88cb7938 2354
39c8eb58 2355 TBranch *branch;
2356 char branchname[20];
2357 sprintf(branchname,"%s2",GetName());
2358 //
2359 // Branch address for hit tree
cb5b8b21 2360 TTree *treeH = fLoader->TreeH();
792bb11c 2361 if ((treeH)&&(fHitType&4)) {
39c8eb58 2362 branch = treeH->GetBranch(branchname);
8c2b3fd7 2363 if (branch) {
2364 branch->SetAddress(&fTrackHits);
2365 AliDebug(1,"fHitType&4 Setting");
2366 }
f2a509af 2367 else
8c2b3fd7 2368 AliDebug(1,"fHitType&4 Failed (can not find branch)");
f2a509af 2369
39c8eb58 2370 }
be5ffbfe 2371 // if ((treeH)&&(fHitType&2)) {
2372// branch = treeH->GetBranch(branchname);
2373// if (branch) {
2374// branch->SetAddress(&fTrackHitsOld);
2375// AliDebug(1,"fHitType&2 Setting");
2376// }
2377// else
2378// AliDebug(1,"fHitType&2 Failed (can not find branch)");
2379// }
39c8eb58 2380}
2381
2382void AliTPC::FinishPrimary()
2383{
792bb11c 2384 if (fTrackHits &&fHitType&4) fTrackHits->FlushHitStack();
be5ffbfe 2385 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->FlushHitStack();
39c8eb58 2386}
2387
2388
2389void AliTPC::AddHit2(Int_t track, Int_t *vol, Float_t *hits)
2390{
2391 //
a6005888 2392 // add hit to the list
2393
39c8eb58 2394 Int_t rtrack;
2395 if (fIshunt) {
5d12ce38 2396 int primary = gAlice->GetMCApp()->GetPrimary(track);
2397 gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
39c8eb58 2398 rtrack=primary;
2399 } else {
2400 rtrack=track;
5d12ce38 2401 gAlice->GetMCApp()->FlagTrack(track);
39c8eb58 2402 }
792bb11c 2403 if (fTrackHits && fHitType&4)
39c8eb58 2404 fTrackHits->AddHitKartez(vol[0],rtrack, hits[0],
e61fd20d 2405 hits[1],hits[2],(Int_t)hits[3],hits[4]);
be5ffbfe 2406 // if (fTrackHitsOld &&fHitType&2 )
2407// fTrackHitsOld->AddHitKartez(vol[0],rtrack, hits[0],
2408// hits[1],hits[2],(Int_t)hits[3]);
792bb11c 2409
39c8eb58 2410}
2411
2412void AliTPC::ResetHits()
88cb7938 2413{
39c8eb58 2414 if (fHitType&1) AliDetector::ResetHits();
792bb11c 2415 if (fHitType>1) ResetHits2();
39c8eb58 2416}
2417
2418void AliTPC::ResetHits2()
2419{
2420 //
2421 //reset hits
792bb11c 2422 if (fTrackHits && fHitType&4) fTrackHits->Clear();
be5ffbfe 2423 // if (fTrackHitsOld && fHitType&2) fTrackHitsOld->Clear();
792bb11c 2424
39c8eb58 2425}
2426
2427AliHit* AliTPC::FirstHit(Int_t track)
2428{
792bb11c 2429 if (fHitType>1) return FirstHit2(track);
39c8eb58 2430 return AliDetector::FirstHit(track);
2431}
2432AliHit* AliTPC::NextHit()
2433{
9bdd974b 2434 //
2435 // gets next hit
2436 //
792bb11c 2437 if (fHitType>1) return NextHit2();
2438
39c8eb58 2439 return AliDetector::NextHit();
2440}
2441
2442AliHit* AliTPC::FirstHit2(Int_t track)
2443{
2444 //
2445 // Initialise the hit iterator
2446 // Return the address of the first hit for track
2447 // If track>=0 the track is read from disk
2448 // while if track<0 the first hit of the current
2449 // track is returned
2450 //
2451 if(track>=0) {
3e2e3ece 2452 gAlice->GetMCApp()->ResetHits();
cb5b8b21 2453 fLoader->TreeH()->GetEvent(track);
39c8eb58 2454 }
2455 //
792bb11c 2456 if (fTrackHits && fHitType&4) {
39c8eb58 2457 fTrackHits->First();
2458 return fTrackHits->GetHit();
2459 }
be5ffbfe 2460 // if (fTrackHitsOld && fHitType&2) {
2461// fTrackHitsOld->First();
2462// return fTrackHitsOld->GetHit();
2463// }
792bb11c 2464
39c8eb58 2465 else return 0;
2466}
2467
2468AliHit* AliTPC::NextHit2()
2469{
2470 //
2471 //Return the next hit for the current track
2472
792bb11c 2473
be5ffbfe 2474// if (fTrackHitsOld && fHitType&2) {
2475// fTrackHitsOld->Next();
2476// return fTrackHitsOld->GetHit();
2477// }
39c8eb58 2478 if (fTrackHits) {
2479 fTrackHits->Next();
2480 return fTrackHits->GetHit();
2481 }
2482 else
2483 return 0;
2484}
2485
39c8eb58 2486void AliTPC::RemapTrackHitIDs(Int_t *map)
2487{
9bdd974b 2488 //
2489 // remapping
2490 //
39c8eb58 2491 if (!fTrackHits) return;
39c8eb58 2492
be5ffbfe 2493// if (fTrackHitsOld && fHitType&2){
2494// AliObjectArray * arr = fTrackHitsOld->fTrackHitsInfo;
2495// for (UInt_t i=0;i<arr->GetSize();i++){
2496// AliTrackHitsInfo * info = (AliTrackHitsInfo *)(arr->At(i));
2497// info->fTrackID = map[info->fTrackID];
2498// }
2499// }
2500// if (fTrackHitsOld && fHitType&4){
2501 if (fTrackHits && fHitType&4){
792bb11c 2502 TClonesArray * arr = fTrackHits->GetArray();;
2503 for (Int_t i=0;i<arr->GetEntriesFast();i++){
2504 AliTrackHitsParamV2 * info = (AliTrackHitsParamV2 *)(arr->At(i));
b9671574 2505 info->SetTrackID(map[info->GetTrackID()]);
792bb11c 2506 }
2507 }
39c8eb58 2508}
2509
792bb11c 2510Bool_t AliTPC::TrackInVolume(Int_t id,Int_t track)
2511{
2512 //return bool information - is track in given volume
2513 //load only part of the track information
2514 //return true if current track is in volume
2515 //
2516 // return kTRUE;
be5ffbfe 2517 // if (fTrackHitsOld && fHitType&2) {
cb5b8b21 2518// TBranch * br = fLoader->TreeH()->GetBranch("fTrackHitsInfo");
be5ffbfe 2519// br->GetEvent(track);
2520// AliObjectArray * ar = fTrackHitsOld->fTrackHitsInfo;
2521// for (UInt_t j=0;j<ar->GetSize();j++){
2522// if ( ((AliTrackHitsInfo*)ar->At(j))->fVolumeID==id) return kTRUE;
2523// }
2524// }
792bb11c 2525
2526 if (fTrackHits && fHitType&4) {
cb5b8b21 2527 TBranch * br1 = fLoader->TreeH()->GetBranch("fVolumes");
2528 TBranch * br2 = fLoader->TreeH()->GetBranch("fNVolumes");
792bb11c 2529 br2->GetEvent(track);
2530 br1->GetEvent(track);
2531 Int_t *volumes = fTrackHits->GetVolumes();
2532 Int_t nvolumes = fTrackHits->GetNVolumes();
2533 if (!volumes && nvolumes>0) {
8c2b3fd7 2534 AliWarning(Form("Problematic track\t%d\t%d",track,nvolumes));
792bb11c 2535 return kFALSE;
2536 }
2537 for (Int_t j=0;j<nvolumes; j++)
2538 if (volumes[j]==id) return kTRUE;
2539 }
2540
2541 if (fHitType&1) {
cb5b8b21 2542 TBranch * br = fLoader->TreeH()->GetBranch("fSector");
792bb11c 2543 br->GetEvent(track);
2544 for (Int_t j=0;j<fHits->GetEntriesFast();j++){
2545 if ( ((AliTPChit*)fHits->At(j))->fSector==id) return kTRUE;
2546 }
2547 }
2548 return kFALSE;
2549
2550}
39c8eb58 2551
39c8eb58 2552
88cb7938 2553AliLoader* AliTPC::MakeLoader(const char* topfoldername)
2554{
8c2b3fd7 2555 //Makes TPC loader
2556 fLoader = new AliTPCLoader(GetName(),topfoldername);
2557 return fLoader;
88cb7938 2558}
2559
42157e55 2560////////////////////////////////////////////////////////////////////////
2561AliTPCParam* AliTPC::LoadTPCParam(TFile *file) {
2562//
2563// load TPC paarmeters from a given file or create new if the object
2564// is not found there
88cb7938 2565// 12/05/2003 This method should be moved to the AliTPCLoader
2566// and one has to decide where to store the TPC parameters
2567// M.Kowalski
42157e55 2568 char paramName[50];
2569 sprintf(paramName,"75x40_100x60_150x60");
2570 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
2571 if (paramTPC) {
8c2b3fd7 2572 AliDebugClass(1,Form("TPC parameters %s found.",paramName));
42157e55 2573 } else {
8c2b3fd7 2574 AliWarningClass("TPC parameters not found. Create new (they may be incorrect)");
db2fdcfb 2575 //paramTPC = new AliTPCParamSR;
2576 paramTPC = AliTPCcalibDB::Instance()->GetParameters();
2577 if (!paramTPC->IsGeoRead()){
2578 //
2579 // read transformation matrices for gGeoManager
2580 //
2581 paramTPC->ReadGeoMatrices();
2582 }
2583
42157e55 2584 }
2585 return paramTPC;
2586
2587// the older version of parameters can be accessed with this code.
2588// In some cases, we have old parameters saved in the file but
2589// digits were created with new parameters, it can be distinguish
2590// by the name of TPC TreeD. The code here is just for the case
2591// we would need to compare with old data, uncomment it if needed.
2592//
2593// char paramName[50];
2594// sprintf(paramName,"75x40_100x60");
2595// AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
2596// if (paramTPC) {
2597// cout<<"TPC parameters "<<paramName<<" found."<<endl;
2598// } else {
2599// sprintf(paramName,"75x40_100x60_150x60");
2600// paramTPC=(AliTPCParam*)in->Get(paramName);
2601// if (paramTPC) {
2602// cout<<"TPC parameters "<<paramName<<" found."<<endl;
2603// } else {
2604// cerr<<"TPC parameters not found. Create new (they may be incorrect)."
2605// <<endl;
2606// paramTPC = new AliTPCParamSR;
2607// }
2608// }
2609// return paramTPC;
2610
2611}
2612
85a5290f 2613