Fix in the cycles container size
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUSimulation.cxx
CommitLineData
451f5018 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// This is the base class for ITS detector signal simulations. Data members //
17// include are a pointer to the AliITSDetTypeSim clas in order to access //
18// segmentation and response objects //
19// classes. See the detector specific implementations for the propper code. //
20//////////////////////////////////////////////////////////////////////////////
21#include <TRandom.h>
22#include "TSeqCollection.h"
23#include "AliITSUSimulation.h"
24#include "AliITSUSDigit.h"
c92b1537 25#include "AliITSUModule.h"
29ad4146 26#include "AliITSUParamList.h"
a11ef2e4 27using namespace TMath;
451f5018 28
29ClassImp(AliITSUSimulation)
30
31//______________________________________________________________________
32AliITSUSimulation::AliITSUSimulation()
33: fSeg(0)
34 ,fCalibDead(0)
35 ,fCalibNoisy(0)
36 ,fSensMap(0)
37 ,fSimuParam(0)
c92b1537 38 ,fResponseParam(0)
451f5018 39 ,fModule(0)
40 ,fEvent(0)
41 ,fDebug(0)
42{
43 // Default constructor
44}
45//______________________________________________________________________
46AliITSUSimulation::AliITSUSimulation(AliITSUSimuParam* sim,AliITSUSensMap* map)
47 :fSeg(0)
48 ,fCalibDead(0)
49 ,fCalibNoisy(0)
50 ,fSensMap(map)
51 ,fSimuParam(sim)
c92b1537 52 ,fResponseParam(0)
451f5018 53 ,fModule(0)
54 ,fEvent(0)
55 ,fDebug(0)
56{
57 // Default constructor
58}
59
60//__________________________________________________________________________
61AliITSUSimulation::AliITSUSimulation(const AliITSUSimulation &s)
62 :TObject(s)
63 ,fSeg(s.fSeg)
64 ,fCalibDead(s.fCalibDead)
65 ,fCalibNoisy(s.fCalibNoisy)
66 ,fSensMap(s.fSensMap)
67 ,fSimuParam(s.fSimuParam)
c92b1537 68 ,fResponseParam(s.fResponseParam)
451f5018 69 ,fModule(s.fModule)
70 ,fEvent(s.fEvent)
71 ,fDebug(s.fDebug)
72{
73 // Copy Constructor
74}
75
76//_________________________________________________________________________
77AliITSUSimulation& AliITSUSimulation::operator=(const AliITSUSimulation &s)
78{
79 // Assignment operator
80 if(&s == this) return *this;
81 fSeg = s.fSeg;
82 fCalibDead = s.fCalibDead;
83 fCalibNoisy= s.fCalibNoisy;
84 fSensMap = s.fSensMap;
85 fSimuParam = s.fSimuParam;
c92b1537 86 fResponseParam = s.fResponseParam;
451f5018 87 fModule = s.fModule;
88 fEvent = s.fEvent;
89 return *this;
90}
91
92//______________________________________________________________________
29ad4146 93void AliITSUSimulation::InitSimulationModule(AliITSUModule* mod, Int_t event, AliITSsegmentation* seg, AliITSUParamList* resp)
451f5018 94{
95 // This function creates maps to build the list of tracks for each
96 // summable digit. Inputs defined by base class.
97 //
c92b1537 98 SetModule(mod);
451f5018 99 SetSegmentation(seg);
c92b1537 100 SetResponseParam(resp);
451f5018 101 ClearMap();
6b847cde 102 memset(fCyclesID,0,(1+2*kMaxROCycleAccept)*sizeof(Bool_t));
c92b1537 103 //
0ebc85cf 104 if (event != fEvent) GenerateReadOutCycleOffset();
c92b1537 105 SetEvent(event);
106
451f5018 107}
108
109//______________________________________________________________________
110Bool_t AliITSUSimulation::AddSDigitsToModule(TSeqCollection *pItemArr,Int_t mask )
111{
112 // Add Summable digits to module maps.
113 // Inputs:
114 // pItemArr Array of AliITSpListItems (SDigits).
115 // mask Track number off set value
116 //
117 Int_t nItems = pItemArr->GetEntries();
118 Bool_t sig = kFALSE;
119 //
120 for( Int_t i=0; i<nItems; i++ ) {
121 AliITSUSDigit * pItem = (AliITSUSDigit *)(pItemArr->At( i ));
c92b1537 122 if(pItem->GetModule() != int(fModule->GetIndex()) ) AliFatal(Form("SDigits module %d != current module %d: exit", pItem->GetModule(),fModule->GetIndex()));
451f5018 123 if(pItem->GetSumSignal()>0.0 ) sig = kTRUE;
124 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(pItem);
125 if (!oldItem) {
126 oldItem = (AliITSUSDigit*)fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(*pItem) );
127 if (mask) oldItem->ShiftIndices(mask);
128 }
129 else oldItem->AddTo(mask, pItem);
130 }
131 return sig;
132}
133
134//______________________________________________________________________
b2679935 135void AliITSUSimulation::UpdateMapSignal(UInt_t col,UInt_t row,Int_t trk,Int_t ht,Double_t signal, Int_t roCycle)
451f5018 136{
137 // update map with new hit
fbcb7a55 138 // Note: roCycle can be anything between -kMaxROCycleAccept : kMaxROCycleAccept
6b847cde 139 if (Abs(roCycle)>kMaxROCycleAccept) {
140 AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
141 return;
142 }
fbcb7a55 143 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
6b847cde 144 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
145 if (!oldItem) {
fbcb7a55 146 fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(trk,ht,fModule->GetIndex(),ind,signal,roCycle) );
147 fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
148 }
451f5018 149 else oldItem->AddSignal(trk,ht,signal);
120e5202 150 //
451f5018 151}
152
153//______________________________________________________________________
b2679935 154void AliITSUSimulation::UpdateMapNoise(UInt_t col,UInt_t row,Double_t noise, Int_t roCycle)
451f5018 155{
156 // update map with new hit
6b847cde 157 if (Abs(roCycle)>kMaxROCycleAccept) {
158 AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
159 return;
160 }
b2679935 161 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
451f5018 162 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
fbcb7a55 163 if (!oldItem) {
164 fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(fModule->GetIndex(),ind,noise,roCycle) );
165 fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
166 }
451f5018 167 else oldItem->AddNoise(noise);
168}
169
170//______________________________________________________________________
171Int_t AliITSUSimulation::GenOrderedSample(UInt_t nmax,UInt_t ngen,TArrayI &vals,TArrayI &indx)
172{
173 // generate random sample [0:nmax] of ngen variables, and fill orreder indices
174 // return actual number of generated values
175 if (vals.GetSize()<(int)ngen) vals.Set(ngen);
176 if (indx.GetSize()<(int)ngen) indx.Set(ngen);
177 int* valA = vals.GetArray();
178 int* indA = indx.GetArray();
179 if (ngen>=nmax) {
180 ngen = nmax-1;
181 for (int i=(int)ngen;i--;) {valA[i]=indA[i]=i;}
182 return ngen;
183 }
184 Bool_t rep;
185 for (int i=0;i<(int)ngen;i++) {
186 do { // exclude repetitions
187 rep = kFALSE;
188 valA[i] = gRandom->Rndm()*nmax;
189 for (int j=i;j--;) if (valA[j]==valA[i]) {rep=kTRUE;break;}
190 } while(rep);
191 }
a11ef2e4 192 Sort((int)ngen,valA,indA,kFALSE);
451f5018 193 return ngen;
194}