1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 ITSU detector signal simulations. Data members //
17 ///////////////////////////////////////////////////////////////////////////////
19 #include "TSeqCollection.h"
20 #include "AliITSUSimulation.h"
21 #include "AliITSUSDigit.h"
22 #include "AliITSUChip.h"
23 #include "AliITSUParamList.h"
24 using namespace TMath;
26 ClassImp(AliITSUSimulation)
28 //______________________________________________________________________
29 AliITSUSimulation::AliITSUSimulation()
37 ,fReadOutCycleOffset(0)
38 ,fReadOutCycleLength(25e-6)
42 // Default constructor
44 //______________________________________________________________________
45 AliITSUSimulation::AliITSUSimulation(AliITSUSimuParam* sim,AliITSUSensMap* map)
53 ,fReadOutCycleOffset(0)
54 ,fReadOutCycleLength(25e-6)
58 // Default constructor
61 //__________________________________________________________________________
62 AliITSUSimulation::AliITSUSimulation(const AliITSUSimulation &s)
65 ,fCalibDead(s.fCalibDead)
66 ,fCalibNoisy(s.fCalibNoisy)
68 ,fSimuParam(s.fSimuParam)
69 ,fResponseParam(s.fResponseParam)
71 ,fReadOutCycleOffset(s.fReadOutCycleOffset)
72 ,fReadOutCycleLength(s.fReadOutCycleLength)
79 //_________________________________________________________________________
80 AliITSUSimulation& AliITSUSimulation::operator=(const AliITSUSimulation &s)
82 // Assignment operator
83 if(&s == this) return *this;
85 fCalibDead = s.fCalibDead;
86 fCalibNoisy= s.fCalibNoisy;
87 fSensMap = s.fSensMap;
88 fSimuParam = s.fSimuParam;
89 fResponseParam = s.fResponseParam;
91 fReadOutCycleOffset = s.fReadOutCycleOffset;
92 fReadOutCycleLength = s.fReadOutCycleLength;
97 //______________________________________________________________________
98 void AliITSUSimulation::InitSimulationChip(AliITSUChip* mod, Int_t event, AliITSsegmentation* seg, AliITSUParamList* resp)
100 // This function creates maps to build the list of tracks for each
101 // summable digit. Inputs defined by base class.
104 SetSegmentation(seg);
105 SetResponseParam(resp);
107 memset(fCyclesID,0,(1+2*kMaxROCycleAccept)*sizeof(Bool_t));
113 //______________________________________________________________________
114 Bool_t AliITSUSimulation::AddSDigitsToChip(TSeqCollection *pItemArr,Int_t mask )
116 // Add Summable digits to chip maps.
118 // pItemArr Array of AliITSpListItems (SDigits).
119 // mask Track number off set value
121 Int_t nItems = pItemArr->GetEntries();
124 for( Int_t i=0; i<nItems; i++ ) {
125 AliITSUSDigit * pItem = (AliITSUSDigit *)(pItemArr->At( i ));
126 if(pItem->GetChip() != int(fChip->GetIndex()) ) AliFatal(Form("SDigits chip %d != current chip %d: exit", pItem->GetChip(),fChip->GetIndex()));
127 if(pItem->GetSumSignal()>0.0 ) sig = kTRUE;
128 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(pItem);
130 oldItem = (AliITSUSDigit*)fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(*pItem) );
131 if (mask) oldItem->ShiftIndices(mask);
133 else oldItem->AddTo(mask, pItem);
138 //______________________________________________________________________
139 void AliITSUSimulation::UpdateMapSignal(UInt_t col,UInt_t row,Int_t trk,Int_t ht,Double_t signal, Int_t roCycle)
141 // update map with new hit
142 // Note: roCycle can be anything between -kMaxROCycleAccept : kMaxROCycleAccept
143 if (Abs(roCycle)>kMaxROCycleAccept) {
144 AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
147 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
148 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
150 fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(trk,ht,fChip->GetIndex(),ind,signal,roCycle) );
151 fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
153 else oldItem->AddSignal(trk,ht,signal);
157 //______________________________________________________________________
158 void AliITSUSimulation::UpdateMapNoise(UInt_t col,UInt_t row,Double_t noise, Int_t roCycle)
160 // update map with new hit
161 if (Abs(roCycle)>kMaxROCycleAccept) {
162 AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
165 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
166 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
168 fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(fChip->GetIndex(),ind,noise,roCycle) );
169 fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
171 else oldItem->AddNoise(noise);
174 //______________________________________________________________________
175 Int_t AliITSUSimulation::GenOrderedSample(UInt_t nmax,UInt_t ngen,TArrayI &vals,TArrayI &indx)
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();
185 for (int i=(int)ngen;i--;) {valA[i]=indA[i]=i;}
189 for (int i=0;i<(int)ngen;i++) {
190 do { // exclude repetitions
192 valA[i] = gRandom->Rndm()*nmax;
193 for (int j=i;j--;) if (valA[j]==valA[i]) {rep=kTRUE;break;}
196 Sort((int)ngen,valA,indA,kFALSE);
200 //______________________________________________________________________
201 Double_t AliITSUSimulation::GenerateReadOutCycleOffset()
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