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