Coding rule violations corrected.
[u/mrichter/AliRoot.git] / ITS / AliITSMapA1.cxx
CommitLineData
e8189707 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 **************************************************************************/
766e3066 15#include <TObjArray.h>
16#include <TMath.h>
e8189707 17
18#include "AliITSMapA1.h"
19#include "AliITSsegmentation.h"
20#include "AliITSresponse.h"
21#include "AliITSdigit.h"
22
766e3066 23////////////////////////////////////////////////////////////////////////
24// Map Class for ITS. Implementation A1. In this implementation, the //
25// 2 dimensional (iz,ix) map is filled with integers values. For each //
26// cell a corresponding TObject, a hit, can also be stored. //
27// The detector geometry is accessed via the that detectors //
28// segmentation class and stored here for conveniance. //
29////////////////////////////////////////////////////////////////////////
e8189707 30
31ClassImp(AliITSMapA1)
766e3066 32//______________________________________________________________________
33AliITSMapA1::AliITSMapA1(){
34 // default constructor
35
36 fSegmentation = 0;
37 fNpz = 0;
38 fNpx = 0;
39 fMaxIndex = 0;
40 fHitMap = 0;
41 fObjects = 0;
42 fNobjects = 0;
43 fMapThreshold = 0;
44}
45//______________________________________________________________________
46AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg){
47 //constructor
48
49 fSegmentation = seg;
50 fNpz = fSegmentation->Npz();
51 fNpx = fSegmentation->Npx();
52 fMaxIndex = fNpz*fNpx+fNpx; // 2 halves of detector
53 fHitMap = new Int_t[fMaxIndex];
54 fObjects = 0;
55 fNobjects = 0;
56 fMapThreshold = 0;
57 ClearMap();
58}
59//______________________________________________________________________
60AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg, TObjArray *obj){
61 //constructor
62
63 fNobjects = 0;
64 fSegmentation = seg;
65 fNpz = fSegmentation->Npz();
66 fNpx = fSegmentation->Npx();
67 fMaxIndex = fNpz*fNpx+fNpx; // 2 halves of detector
68 fHitMap = new Int_t[fMaxIndex];
69 fObjects = obj;
70 if(fObjects) fNobjects = fObjects->GetEntriesFast();
71 fMapThreshold = 0;
72 ClearMap();
73}
74//______________________________________________________________________
75AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg, TObjArray *obj, Int_t thr){
76 //constructor
77
78 fNobjects = 0;
79 fSegmentation = seg;
80 fNpz = fSegmentation->Npz();
81 fNpx = fSegmentation->Npx();
82 fMaxIndex = fNpz*fNpx+fNpx; // 2 halves of detector
83 fHitMap = new Int_t[fMaxIndex];
84 fObjects = obj;
85 if(fObjects) fNobjects = fObjects->GetEntriesFast();
86 fMapThreshold = thr;
87 ClearMap();
88}
89//______________________________________________________________________
90AliITSMapA1::~AliITSMapA1(){
91 //destructor
92
93 if(fHitMap) delete[] fHitMap;
e8189707 94}
e8189707 95//_________________________________________________________________________
766e3066 96AliITSMapA1& AliITSMapA1::operator=(const AliITSMapA1 &source) {
97 // Assignment operator
e8189707 98
766e3066 99 if(&source == this) return *this;
100
101 this->fNpx = source.fNpx;
102 this->fNpz = source.fNpz;
103 this->fObjects = source.fObjects;
104 this->fNobjects = source.fNobjects;
105 this->fMaxIndex = source.fMaxIndex;
106 this->fHitMap = source.fHitMap;
107 this->fMapThreshold = source.fMapThreshold;
108 return *this;
e8189707 109}
766e3066 110//______________________________________________________________________
ac74f489 111AliITSMapA1::AliITSMapA1(const AliITSMapA1 &source) : AliITSMap(source){
766e3066 112 // Copy Constructor
113
114 *this = source;
e8189707 115}
766e3066 116//______________________________________________________________________
117void AliITSMapA1::ClearMap(){
118 //clear array
e8189707 119
766e3066 120 memset(fHitMap,0,sizeof(int)*fMaxIndex);
121}
122//______________________________________________________________________
123void AliITSMapA1::SetArray(TObjArray *obj){
124 // set array of objects
e8189707 125
766e3066 126 fObjects = obj;
127 if (fObjects) fNobjects = fObjects->GetEntriesFast();
e8189707 128}
766e3066 129//______________________________________________________________________
fb4e90e0 130Int_t AliITSMapA1::CheckedIndex(Int_t iz, Int_t ix) const {
766e3066 131 //check boundaries and return an index in array
132 Int_t index=fNpx*iz+ix;
e8189707 133
766e3066 134 //if (index > fMaxIndex) {
135 if (index > fMaxIndex || index < 0) {
136 printf("\n \n \n Try to read/write outside array !!!!"
137 " \n \n %d %d %d %d %d %d \n",iz,ix,fMaxIndex,index,fNpz,fNpx);
138 // force crash
139 return -1;
140 } else {
141 return index;
142 } // end if index>max or < 0
143}
144//______________________________________________________________________
145void AliITSMapA1::FillMap(){
146 // fill array with digits indices
e8189707 147
766e3066 148 Int_t ndigits = fObjects->GetEntriesFast();
149 if (!ndigits) return;
96f414e9 150
766e3066 151 AliITSdigit *dig;
152 for (Int_t ndig=0; ndig<ndigits; ndig++) {
153 dig = (AliITSdigit*)fObjects->UncheckedAt(ndig);
ecee53fc 154 if(dig->GetSignal() > fMapThreshold) {
155 SetHit(dig->GetCoord1(),dig->GetCoord2(),ndig);
766e3066 156 } // end if fSignal > fMapthreshold
157 } // end for ndig
e8189707 158}
766e3066 159//______________________________________________________________________
160void AliITSMapA1::SetHit(Int_t iz, Int_t ix, Int_t idigit){
161 // set the digit index at a certain position in array
e8189707 162
766e3066 163 fHitMap[CheckedIndex(iz, ix)]=idigit+1;
e8189707 164}
766e3066 165//______________________________________________________________________
166void AliITSMapA1::DeleteHit(Int_t iz, Int_t ix){
167 // delete an entry in array
e8189707 168
766e3066 169 fHitMap[CheckedIndex(iz, ix)]=0;
e8189707 170}
766e3066 171//______________________________________________________________________
172void AliITSMapA1::FlagHit(Int_t iz, Int_t ix){
173 // flag an entry in array
e8189707 174
766e3066 175 fHitMap[CheckedIndex(iz, ix)] = -TMath::Abs(fHitMap[CheckedIndex(iz, ix)]);
e8189707 176}
766e3066 177//______________________________________________________________________
fb4e90e0 178Int_t AliITSMapA1::GetHitIndex(Int_t iz, Int_t ix) const {
766e3066 179 // return the digit index from a specific entry in array
e8189707 180
766e3066 181 return TMath::Abs(fHitMap[CheckedIndex(iz, ix)])-1;
e8189707 182}
766e3066 183//______________________________________________________________________
184TObject* AliITSMapA1::GetHit(Int_t iz, Int_t ix){
185 // return the pointer to the digit
e8189707 186
766e3066 187 Int_t index=GetHitIndex(iz,ix);
188 // Force crash if index does not exist !
189 return (index <0) ? 0 : fObjects->UncheckedAt(GetHitIndex(iz,ix));
e8189707 190}
766e3066 191//______________________________________________________________________
192Double_t AliITSMapA1::GetSignal(Int_t iz, Int_t ix){
193 // get a pad signal
194 Double_t signal;
e8189707 195
766e3066 196 AliITSdigit *dig = (AliITSdigit*)GetHit(iz,ix);
ecee53fc 197 if(dig) signal=(Double_t)dig->GetSignal();
766e3066 198 else signal=0.;
199 return signal;
e8189707 200}
766e3066 201//______________________________________________________________________
202FlagType AliITSMapA1::TestHit(Int_t iz, Int_t ix){
203 // check whether the digit has already been flagged
e8189707 204
766e3066 205 if (CheckedIndex(iz, ix) < 0) return kEmpty;
206 Int_t inf=fHitMap[CheckedIndex(iz, ix)];
207 if (inf < 0) {
208 return kUsed;
209 } else if (inf == 0) {
210 return kEmpty;
211 } else {
212 return kUnused;
213 } // end if inf
e8189707 214}
766e3066 215