ITS UPGRADE
[u/mrichter/AliRoot.git] / ITS / UPGRADE / ITSUpgradeSim / 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 **************************************************************************/
852af72e 15///////////////////////////////////////////////////////////////////////////////
16// This is the base class for ITSU detector signal simulations. Data members //
17///////////////////////////////////////////////////////////////////////////////
451f5018 18#include <TRandom.h>
19#include "TSeqCollection.h"
20#include "AliITSUSimulation.h"
21#include "AliITSUSDigit.h"
852af72e 22#include "AliITSUChip.h"
29ad4146 23#include "AliITSUParamList.h"
a11ef2e4 24using namespace TMath;
451f5018 25
26ClassImp(AliITSUSimulation)
27
28//______________________________________________________________________
29AliITSUSimulation::AliITSUSimulation()
30: fSeg(0)
31 ,fCalibDead(0)
32 ,fCalibNoisy(0)
33 ,fSensMap(0)
34 ,fSimuParam(0)
c92b1537 35 ,fResponseParam(0)
852af72e 36 ,fChip(0)
344d4ff3 37 ,fReadOutCycleOffset(0)
38 ,fReadOutCycleLength(25e-6)
451f5018 39 ,fEvent(0)
40 ,fDebug(0)
41{
42 // Default constructor
43}
44//______________________________________________________________________
45AliITSUSimulation::AliITSUSimulation(AliITSUSimuParam* sim,AliITSUSensMap* map)
46 :fSeg(0)
47 ,fCalibDead(0)
48 ,fCalibNoisy(0)
49 ,fSensMap(map)
50 ,fSimuParam(sim)
c92b1537 51 ,fResponseParam(0)
852af72e 52 ,fChip(0)
344d4ff3 53 ,fReadOutCycleOffset(0)
54 ,fReadOutCycleLength(25e-6)
451f5018 55 ,fEvent(0)
56 ,fDebug(0)
57{
58 // Default constructor
59}
60
61//__________________________________________________________________________
62AliITSUSimulation::AliITSUSimulation(const AliITSUSimulation &s)
63 :TObject(s)
64 ,fSeg(s.fSeg)
65 ,fCalibDead(s.fCalibDead)
66 ,fCalibNoisy(s.fCalibNoisy)
67 ,fSensMap(s.fSensMap)
68 ,fSimuParam(s.fSimuParam)
c92b1537 69 ,fResponseParam(s.fResponseParam)
852af72e 70 ,fChip(s.fChip)
344d4ff3 71 ,fReadOutCycleOffset(s.fReadOutCycleOffset)
72 ,fReadOutCycleLength(s.fReadOutCycleLength)
451f5018 73 ,fEvent(s.fEvent)
74 ,fDebug(s.fDebug)
75{
76 // Copy Constructor
77}
78
79//_________________________________________________________________________
80AliITSUSimulation& AliITSUSimulation::operator=(const AliITSUSimulation &s)
81{
82 // Assignment operator
83 if(&s == this) return *this;
84 fSeg = s.fSeg;
85 fCalibDead = s.fCalibDead;
86 fCalibNoisy= s.fCalibNoisy;
87 fSensMap = s.fSensMap;
88 fSimuParam = s.fSimuParam;
c92b1537 89 fResponseParam = s.fResponseParam;
852af72e 90 fChip = s.fChip;
344d4ff3 91 fReadOutCycleOffset = s.fReadOutCycleOffset;
92 fReadOutCycleLength = s.fReadOutCycleLength;
451f5018 93 fEvent = s.fEvent;
94 return *this;
95}
96
97//______________________________________________________________________
852af72e 98void AliITSUSimulation::InitSimulationChip(AliITSUChip* mod, Int_t event, AliITSsegmentation* seg, AliITSUParamList* resp)
451f5018 99{
100 // This function creates maps to build the list of tracks for each
101 // summable digit. Inputs defined by base class.
102 //
852af72e 103 SetChip(mod);
451f5018 104 SetSegmentation(seg);
c92b1537 105 SetResponseParam(resp);
451f5018 106 ClearMap();
6b847cde 107 memset(fCyclesID,0,(1+2*kMaxROCycleAccept)*sizeof(Bool_t));
c92b1537 108 //
c92b1537 109 SetEvent(event);
110
451f5018 111}
112
113//______________________________________________________________________
852af72e 114Bool_t AliITSUSimulation::AddSDigitsToChip(TSeqCollection *pItemArr,Int_t mask )
451f5018 115{
852af72e 116 // Add Summable digits to chip maps.
451f5018 117 // Inputs:
118 // pItemArr Array of AliITSpListItems (SDigits).
119 // mask Track number off set value
120 //
121 Int_t nItems = pItemArr->GetEntries();
122 Bool_t sig = kFALSE;
123 //
124 for( Int_t i=0; i<nItems; i++ ) {
125 AliITSUSDigit * pItem = (AliITSUSDigit *)(pItemArr->At( i ));
852af72e 126 if(pItem->GetChip() != int(fChip->GetIndex()) ) AliFatal(Form("SDigits chip %d != current chip %d: exit", pItem->GetChip(),fChip->GetIndex()));
451f5018 127 if(pItem->GetSumSignal()>0.0 ) sig = kTRUE;
128 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(pItem);
129 if (!oldItem) {
130 oldItem = (AliITSUSDigit*)fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(*pItem) );
131 if (mask) oldItem->ShiftIndices(mask);
132 }
133 else oldItem->AddTo(mask, pItem);
134 }
135 return sig;
136}
137
138//______________________________________________________________________
b2679935 139void AliITSUSimulation::UpdateMapSignal(UInt_t col,UInt_t row,Int_t trk,Int_t ht,Double_t signal, Int_t roCycle)
451f5018 140{
141 // update map with new hit
fbcb7a55 142 // Note: roCycle can be anything between -kMaxROCycleAccept : kMaxROCycleAccept
6b847cde 143 if (Abs(roCycle)>kMaxROCycleAccept) {
144 AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
145 return;
146 }
fbcb7a55 147 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
6b847cde 148 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
149 if (!oldItem) {
852af72e 150 fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(trk,ht,fChip->GetIndex(),ind,signal,roCycle) );
fbcb7a55 151 fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
152 }
451f5018 153 else oldItem->AddSignal(trk,ht,signal);
120e5202 154 //
451f5018 155}
156
157//______________________________________________________________________
b2679935 158void AliITSUSimulation::UpdateMapNoise(UInt_t col,UInt_t row,Double_t noise, Int_t roCycle)
451f5018 159{
160 // update map with new hit
6b847cde 161 if (Abs(roCycle)>kMaxROCycleAccept) {
162 AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
163 return;
164 }
b2679935 165 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
451f5018 166 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
fbcb7a55 167 if (!oldItem) {
852af72e 168 fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(fChip->GetIndex(),ind,noise,roCycle) );
fbcb7a55 169 fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
170 }
451f5018 171 else oldItem->AddNoise(noise);
172}
173
174//______________________________________________________________________
175Int_t AliITSUSimulation::GenOrderedSample(UInt_t nmax,UInt_t ngen,TArrayI &vals,TArrayI &indx)
176{
177 // generate random sample [0:nmax] of ngen variables, and fill orreder indices
178 // return actual number of generated values
179 if (vals.GetSize()<(int)ngen) vals.Set(ngen);
180 if (indx.GetSize()<(int)ngen) indx.Set(ngen);
181 int* valA = vals.GetArray();
182 int* indA = indx.GetArray();
183 if (ngen>=nmax) {
184 ngen = nmax-1;
185 for (int i=(int)ngen;i--;) {valA[i]=indA[i]=i;}
186 return ngen;
187 }
188 Bool_t rep;
189 for (int i=0;i<(int)ngen;i++) {
190 do { // exclude repetitions
191 rep = kFALSE;
192 valA[i] = gRandom->Rndm()*nmax;
193 for (int j=i;j--;) if (valA[j]==valA[i]) {rep=kTRUE;break;}
194 } while(rep);
195 }
a11ef2e4 196 Sort((int)ngen,valA,indA,kFALSE);
451f5018 197 return ngen;
198}
344d4ff3 199
200//______________________________________________________________________
201Double_t AliITSUSimulation::GenerateReadOutCycleOffset()
202{
203 // Generate randomly the strobe
204 // phase w.r.t to the LHC clock
205 return fReadOutCycleOffset = fReadOutCycleLength*gRandom->Rndm();
206 // fReadOutCycleOffset = 25e-9*gRandom->Rndm(); // clm: I think this way we shift too much 10-30 us! The global shift should be between the BCs?!
207 // RS: 25 ns is too small number, the staggering will not work. Let's at the moment keep fully random shift (still, no particle from correct
208 // collision will be lost) untill real number is specified
209 //
210}