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