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