Coding conventions for AliITSdigitXXX classes and AliITSTrackerV1
[u/mrichter/AliRoot.git] / ITS / AliITSdigitSDD.cxx
CommitLineData
e869281d 1/**************************************************************************
2 * Copyright(c) 2004-2006, 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#include <AliITSdigitSDD.h>
17#include <TArrayI.h>
18#include <TArrayF.h>
19#include <TMath.h>
20
21///////////////////////////////////////////////////////////////////
22// //
23// Class defining the digit object
24// for SDD
25// Inherits from AliITSdigit
26// //
27///////////////////////////////////////////////////////////////////
28
29ClassImp(AliITSdigitSDD)
30//______________________________________________________________________
31AliITSdigitSDD::AliITSdigitSDD():AliITSdigit(){
32 // default constructor, zero coordinates and set array
33 // elements to clearly unphysical values. A value of 0 may
34 // be a valide track of hit number.
35 Int_t i;
36
37 for(i=0;i<fgkSsdd;i++) fTracks[i] = -3;
38 for(i=0;i<fgkSsdd;i++) fHits[i] = -1;
39 fPhysics = 0;
40 for(i=0;i<fgkSsdd;i++) fTcharges[i] = 0;
41}
42//________________________________________________________________________
43AliITSdigitSDD::AliITSdigitSDD(Float_t phys,const Int_t *digits):
44 AliITSdigit(digits){
45 // Creates a simulated SDD digit object to be updated
46
47 fPhysics = phys;
48}
49//_____________________________________________________________________________
50AliITSdigitSDD::AliITSdigitSDD(Float_t phys,const Int_t *digits,
51 const Int_t *tracks,const Int_t *hits,
52 const Float_t *charges):
53 AliITSdigit(digits){
54 // Creates a simulated SDD digit object
55
56 fPhysics = phys;
57 for(Int_t i=0; i<fgkSsdd; i++) {
58 fTcharges[i] = charges[i];
59 fTracks[i] = tracks[i];
60 fHits[i] = hits[i];
61 } // end for i
62}
63//______________________________________________________________________
64Int_t AliITSdigitSDD::GetListOfTracks(TArrayI &t,TArrayF &c){
65 // Fills the TArrayI t with the tracks found in fTracks removing
66 // duplicated tracks, summing up their charge, and ordering the tracks
67 // by the charge contributed to this digit. It will return
68 // the number of tracks and fill the remaining elements to the array
69 // t with -1.
70 // Inputs:
71 // TArrayI &t Reference to a TArrayI to contain the list of
72 // nonduplicated track numbers.
73 // TArrayF &c Reference to a TArrayF to contain the summed charge
74 // contributed by each track.
75 // Output:
76 // TArrayI &t The input array filled with the nonduplicated track
77 // numbers.
78 // TArrayF &c The input array filled with the summed charge
79 // contributed by the corresponding track in the array t.
80 // Return:
81 // Int_t The number of none -1 entries in the TArrayI t.
82 Int_t nt = t.GetSize();
83 nt = TMath::Min(nt,c.GetSize());
84 Int_t nth = this->GetNTracks();
85 Int_t n = 0,i,j;
86 Bool_t inlist = kFALSE;
87
88 t.Reset(-1); // -1 array.
89 c.Reset(0.0); // zero array.
90 for(i=0;i<nth;i++) {
91 if(this->GetTrack(i) == -1) continue;
92 inlist = kFALSE;
93 for(j=0;j<n;j++)if(this->GetTrack(i) == t.At(j)){
94 inlist = kTRUE;
95 c.AddAt(this->GetCharge(i)+c.At(j),j);
96 } // end for j/end if
97 if(!inlist){ // add to end of list
98 t.AddAt(this->GetTrack(i),n);
99 c.AddAt(this->GetCharge(i),n);
100 if(n<nt) n++;
101 } // end if
102 } // end for i
103
104 // Now lets sort the TArrays according to the charge. This algorithm
105 // is based on the method from Chapter 8 section 1 Straight Insertion
106 // sort. Wiliam H. Press, Saul A. Teukolsky, William T. Vetterling
107 // and Brian P. Flannery, "Numerical Recipeis in C, The Art of Scientific
108 // Computing", second Edition page 330 (1997).
109 Int_t tr;
110 Float_t ch;
111 for(i=0;i<n;i++){
112 tr = t.At(i);
113 ch = c.At(i);
114 j = i-1;
115 while(j>-1 && c.At(j)>ch){
116 t.AddAt(t.At(j+1),j);
117 c.AddAt(c.At(j+1),j);
118 j--;
119 } // end while
120 t.AddAt(tr,j+1);
121 c.AddAt(ch,j+1);
122 } // end for i
123 //
124 return n;
125}
126//______________________________________________________________________
127void AliITSdigitSDD::Print(ostream *os){
128 //Standard output format for this class
129 Int_t i;
130
131 AliITSdigit::Print(os);
132 *os <<","<< fPhysics;
133 for(i=0; i<fgkSsdd; i++) *os <<","<< fTcharges[i];
134 for(i=0; i<fgkSsdd; i++) *os <<","<< fTracks[i];
135 for(i=0; i<fgkSsdd; i++) *os <<","<< fHits[i];
136}
137//______________________________________________________________________
138void AliITSdigitSDD::Read(istream *os){
139 //Standard input for this class
140 Int_t i;
141
142 AliITSdigit::Read(os);
143 *os >>fPhysics;
144 for(i=0; i<fgkSsdd; i++) *os >> fTcharges[i];
145 for(i=0; i<fgkSsdd; i++) *os >> fTracks[i];
146 for(i=0; i<fgkSsdd; i++) *os >> fHits[i];
147}
148//______________________________________________________________________
149ostream &operator<<(ostream &os,AliITSdigitSDD &source){
150 // Standard output streaming function.
151
152 source.Print(&os);
153 return os;
154}
155//______________________________________________________________________
156istream &operator>>(istream &os,AliITSdigitSDD &source){
157 // Standard output streaming function.
158
159 source.Read(&os);
160 return os;
161}