Added new inline function SetITSgeom needed for alignment. New function
[u/mrichter/AliRoot.git] / ITS / AliITSpList.cxx
CommitLineData
2134176d 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/* $Id$ */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <iostream.h>
20#include <iomanip.h>
21#include <TObjArray.h>
22#include <TRandom.h>
23#include <TMath.h>
24
25#include "AliITSpList.h"
26
27//______________________________________________________________________
28
29ClassImp(AliITSpList);
30//______________________________________________________________________
31AliITSpList::AliITSpList(){
32 // Default constructor
33
34 fNi = 0;
35 fNj = 0;
36 fa = 0;
37}
38//______________________________________________________________________
39AliITSpList::AliITSpList(Int_t imax,Int_t jmax){
40 // Standard constructor
41
42 fNi = imax;
43 fNj = jmax;
44 fa = new TObjArray(fNi*fNj); // elements are zeroed by
45 // TObjArray creator
46}
47//______________________________________________________________________
48AliITSpList::~AliITSpList(){
49 // Default destructor
50
51 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
52 delete fa->At(i);
53 fa->AddAt(0,i); // zero content
54 } // end for i && if
55 fNi = 0;
56 fNj = 0;
57 delete fa;
58 fa = 0;
59}
60//______________________________________________________________________
61void AliITSpList::ClearMap(){
62 // Delete all AliITSpListItems and zero TObjArray.
63
64 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
65 delete fa->At(i);
66 fa->AddAt(0,i); // zero content
67 } // end for i && if
68}
69//______________________________________________________________________
70void AliITSpList::DeleteHit(Int_t i,Int_t j){
71 // Delete a particular AliITSpListItems and zero TObjArray.
72 Int_t k = GetIndex(i,j);
73
74 if(fa->At(k)!=0){
75 delete fa->At(k);
76 fa->AddAt(0,k); // zero content
77 } // end for i && if
78}
79//______________________________________________________________________
80AliITSpList& AliITSpList::operator=(const AliITSpList &source){
81 // = operator
82
83 if(this == &source) return *this;
84
85 if(this->fa!=0){ // if this->fa exists delete it first.
86 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
87 delete fa->At(i);
88 fa->AddAt(0,i); // zero content
89 } // end for i && if
90 delete this->fa;
91 } // end if this->fa!=0
92 this->fNi = source.fNi;
93 this->fNj = source.fNj;
94 this->fa = new TObjArray(*(source.fa));
95
96 return *this;
97}
98//______________________________________________________________________
99AliITSpList::AliITSpList(AliITSpList &source){
100 // Copy operator
101
102 *this = source;
103}
104//______________________________________________________________________
105void AliITSpList::AddSignal(Int_t i,Int_t j,Int_t trk,Int_t ht,Int_t mod,
106 Double_t signal){
107 // Adds a Signal value to the TObjArray at i,j. Creates the AliITSpListItem
108 // if needed.
109
110 if(GetpListItem(i,j)==0){ // most create AliITSpListItem
111 fa->AddAt(new AliITSpListItem(trk,ht,mod,GetIndex(i,j),signal),
112 GetIndex(i,j));
113 }else{ // AliITSpListItem exists, just add signal to it.
114 GetpListItem(i,j)->AddSignal(trk,ht,mod,GetIndex(i,j),signal);
115 } // end if
116}
117//______________________________________________________________________
118void AliITSpList::AddNoise(Int_t i,Int_t j,Int_t mod,Double_t noise){
119 // Adds a noise value to the TObjArray at i,j. Creates the AliITSpListItem
120 // if needed.
121
122 if(GetpListItem(i,j)==0){ // most create AliITSpListItem
123 fa->AddAt(new AliITSpListItem(mod,GetIndex(i,j),noise),
124 GetIndex(i,j));
125 }else{ // AliITSpListItem exists, just add signal to it.
126 GetpListItem(i,j)->AddNoise(mod,GetIndex(i,j),noise);
127 } // end if
128}
129//______________________________________________________________________
130
131ClassImp(AliITSpListItem)
132//______________________________________________________________________
133AliITSpListItem::AliITSpListItem(){
134 // Default constructor
135
136 fmodule = -1;
137 findex = -1;
138 for(Int_t i=0;i<this->fkSize;i++){
139 this->fTrack[i] = -2;
140 this->fHits[i] = -2;
141 this->fSignal[i] = 0.0;
142 } // end if i
143 fTsignal = 0.0;
144 fNoise = 0.0;
145}
146//______________________________________________________________________
147AliITSpListItem::AliITSpListItem(Int_t module,Int_t index,Double_t noise){
148 // Standard noise constructor
149
150 this->fmodule = module;
151 this->findex = index;
152 for(Int_t i=0;i<this->fkSize;i++){
153 this->fTrack[i] = -2;
154 this->fSignal[i] = 0.0;
155 this->fHits[i] = 0;
156 } // end if i
157 this->fTsignal = 0.0;
158 this->fNoise = noise;
159}
160//______________________________________________________________________
161AliITSpListItem::AliITSpListItem(Int_t track,Int_t hit,Int_t module,
162 Int_t index,Double_t signal){
163 // Standard signal constructor
164
165 this->fmodule = module;
166 this->findex = index;
167 this->fTrack[0] = track;
168 this->fHits[0] = hit;
169 this->fSignal[0] = signal;
170 for(Int_t i=1;i<this->fkSize;i++){
171 this->fTrack[i] = -2;
172 this->fSignal[i] = 0.0;
173 this->fHits[i] = 0;
174 } // end if i
175 this->fTsignal = signal;
176 this->fNoise = 0.0;
177}
178//______________________________________________________________________
179AliITSpListItem::~AliITSpListItem(){
180 // Denstructor
181
182 this->fmodule = 0;
183 this->findex =0;
184 for(Int_t i=0;i<=this->GetNsignals();i++){
185 this->fTrack[i] = 0;
186 this->fSignal[i] = 0.0;
187 this->fHits[i] = 0;
188 } // end if i
189 this->fTsignal = 0.0;
190 this->fNoise =0.0;
191}
192//______________________________________________________________________
193AliITSpListItem& AliITSpListItem::operator=(const AliITSpListItem &source){
194 // = operator
195
196 if(this == &source) return *this;
197
198 this->fmodule = source.fmodule;
199 this->findex = source.findex;
200 for(Int_t i=0;i<this->fkSize;i++){
201 this->fTrack[i] = source.fTrack[i];
202 this->fSignal[i] = source.fSignal[i];
203 this->fHits[i] = source.fHits[i];
204 } // end if i
205 this->fTsignal = source.fTsignal;
206 this->fNoise = source.fNoise;
207
208 return *this;
209}
210//______________________________________________________________________
211AliITSpListItem::AliITSpListItem(AliITSpListItem &source){
212 // Copy operator
213
214 *this = source;
215}
216//______________________________________________________________________
217void AliITSpListItem::AddSignal(Int_t track,Int_t hit,Int_t module,
218 Int_t index,Double_t signal){
219 // Adds this track number and sinal to the pList and orders them
220 Int_t i,j,trk,hts;
221 Double_t sig;
222 Bool_t flg=kFALSE;
223
224 if(findex!=index || fmodule!=module)
225 Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
226 index,findex,module,fmodule);
227 fTsignal += signal; // Keep track of sum signal.
228 if(signal<=fSignal[fkSize-1]) return; // smaller than smallest
229 for(i=0;i<fkSize;i++)if(track==fTrack[i] && hit ==fHits[i]){
230 fSignal[i] += signal;
231 flg = kTRUE;
232 } // end for i & if.
9176630b 233
234 if(flg){ // the arrays are already sorted with the possible exception
235 // of one element
236 j=0;
237 for(i=0;i<fkSize-1;i++){
238 if(fSignal[i]<fSignal[i+1]){
239 j=i+1;
240 break;
241 }
242 }
243 /* debug printouts
244 if(j>0){
245 cout<<"AliITSpListItem::AddSignal - before sorting - signal="<<signal<<" mod="<<module<<endl;
246 for(i=0;i<fkSize-1;i++)cout<<fSignal[i]<<" ";
247 cout<<fSignal[fkSize-1]<<endl;
248 }
249 */
250 for(i=j;i>0;i--){
251 if(fSignal[i]>fSignal[i-1]){
252 trk = fTrack[i-1];
253 hts = fHits[i-1];
254 sig = fSignal[i-1];
255 fTrack[i-1]=fTrack[i];
256 fHits[i-1]=fHits[i];
257 fSignal[i-1]=fSignal[i];
258 fTrack[i]=trk;
259 fHits[i]=hts;
260 fSignal[i]=sig;
261 }
262 }
263 /* debug printouts
264 if(j>0){
265 cout<<"AliITSpListItem::AddSignal - after sorting\n";
266 for(i=0;i<fkSize-1;i++)cout<<fSignal[i]<<" ";
267 cout<<fSignal[fkSize-1]<<endl;
268 }
269 */
270 return;
271 }
272
ab5aed76 273 // new entry add it in order.
274 // if this signal is <= smallest then don't add it.
275 if(signal <= fSignal[fkSize-1]) return;
276 for(i=fkSize-2;i>=0;i--){
277 if(signal > fSignal[i]){
278 fSignal[i+1] = fSignal[i];
279 fTrack[i+1] = fTrack[i];
280 fHits[i+1] = fHits[i];
9176630b 281 }else{
282 fSignal[i+1] = signal; // changed m.m.
283 fTrack[i+1] = track; // changed m.m.
284 fHits[i+1] = hit; // changed m.m.
ab5aed76 285 return; // put it in the right place, now exit.
286 } // end if
287 } // end if; end for i
288 // Still haven't found the right place. Must be at top of list.
289 fSignal[0] = signal;
290 fTrack[0] = track;
291 fHits[0] = hit;
292 return;
2134176d 293}
294//______________________________________________________________________
295void AliITSpListItem::AddNoise(Int_t module,Int_t index,Double_t noise){
296 // Addes noise to this existing list.
297
298 if(findex!=index || fmodule!=module)
299 Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
300 index,findex,module,fmodule);
301 fNoise += noise; // Keep track of sum signal.
302}
303//______________________________________________________________________
304void AliITSpListItem::AddTo(Int_t fileIndex,AliITSpListItem *pl){
305 // Adds the contents of pl to this with track number off set given by
306 // fileIndex.
307 Int_t i,trk;
308 Double_t sig=0.0;
309
310 for(i=0;i<pl->GetNsignals()&&i<this->GetNsignals();i++){
311 trk = pl->GetTrack(i);
312 trk = pl->ShiftIndex(fileIndex,trk);
313 this->AddSignal(trk,pl->GetHit(i),pl->GetModule(),pl->GetIndex(),pl->GetSignal(i));
314 sig += pl->GetSignal(i);
315 } // end for i
316 this->fNoise += pl->fNoise;
317 return;
318}
319//______________________________________________________________________
320Int_t AliITSpListItem::ShiftIndex(Int_t in,Int_t trk){
321 // Shift an index number to occupy the upper four bits.
322 Int_t si = sizeof(Int_t) * 8;
323 UInt_t uin,utrk; // use UInt_t to avoid interger overflow-> goes negitive.
324
325 uin = in;
326 utrk = trk;
327 for(Int_t i=0;i<si-4;i++) uin *= 2;
328 uin += utrk;
329 in = uin;
330 return in;
331}
332//______________________________________________________________________
333void AliITSpListItem::Print(ostream *os){
334 //Standard output format for this class
335 Int_t i;
336
337 *os << fmodule <<","<<findex<<",";
338 *os << fkSize <<",";
339 for(i=0;i<fkSize;i++) *os << fTrack[i] <<",";
340 for(i=0;i<fkSize;i++) *os << fHits[i] <<",";
341 for(i=0;i<fkSize;i++) *os << fSignal[i] <<",";
342 *os << fTsignal <<","<< fNoise;
343}
344//______________________________________________________________________
345void AliITSpListItem::Read(istream *is){
346 // Standard output streaming function.
347 Int_t i,iss;
348
349 *is >> fmodule >> findex;
350 *is >> iss; // read in fkSize
351 for(i=0;i<fkSize&&i<iss;i++) *is >> fTrack[i];
352 for(i=0;i<fkSize&&i<iss;i++) *is >> fHits[i];
353 for(i=0;i<fkSize&&i<iss;i++) *is >> fSignal[i];
354 *is >> fTsignal >> fNoise;
355}
356//______________________________________________________________________
357ostream &operator<<(ostream &os,AliITSpListItem &source){
358 // Standard output streaming function.
359
360 source.Print(&os);
361 return os;
362}
363//______________________________________________________________________
364istream &operator>>(istream &os,AliITSpListItem &source){
365 // Standard output streaming function.
366
367 source.Read(&os);
368 return os;
369}