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