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