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 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 //////////////////////////////////////////////////////////////////////////////
22 #include "TSeqCollection.h"
23 #include "AliITSUSimulation.h"
24 #include "AliITSUSDigit.h"
25 #include "AliITSUModule.h"
26 #include "AliITSUParamList.h"
27 using namespace TMath;
29 ClassImp(AliITSUSimulation)
31 //______________________________________________________________________
32 AliITSUSimulation::AliITSUSimulation()
40 ,fReadOutCycleOffset(0)
41 ,fReadOutCycleLength(25e-6)
45 // Default constructor
47 //______________________________________________________________________
48 AliITSUSimulation::AliITSUSimulation(AliITSUSimuParam* sim,AliITSUSensMap* map)
56 ,fReadOutCycleOffset(0)
57 ,fReadOutCycleLength(25e-6)
61 // Default constructor
64 //__________________________________________________________________________
65 AliITSUSimulation::AliITSUSimulation(const AliITSUSimulation &s)
68 ,fCalibDead(s.fCalibDead)
69 ,fCalibNoisy(s.fCalibNoisy)
71 ,fSimuParam(s.fSimuParam)
72 ,fResponseParam(s.fResponseParam)
74 ,fReadOutCycleOffset(s.fReadOutCycleOffset)
75 ,fReadOutCycleLength(s.fReadOutCycleLength)
82 //_________________________________________________________________________
83 AliITSUSimulation& AliITSUSimulation::operator=(const AliITSUSimulation &s)
85 // Assignment operator
86 if(&s == this) return *this;
88 fCalibDead = s.fCalibDead;
89 fCalibNoisy= s.fCalibNoisy;
90 fSensMap = s.fSensMap;
91 fSimuParam = s.fSimuParam;
92 fResponseParam = s.fResponseParam;
94 fReadOutCycleOffset = s.fReadOutCycleOffset;
95 fReadOutCycleLength = s.fReadOutCycleLength;
100 //______________________________________________________________________
101 void AliITSUSimulation::InitSimulationModule(AliITSUModule* mod, Int_t event, AliITSsegmentation* seg, AliITSUParamList* resp)
103 // This function creates maps to build the list of tracks for each
104 // summable digit. Inputs defined by base class.
107 SetSegmentation(seg);
108 SetResponseParam(resp);
110 memset(fCyclesID,0,(1+2*kMaxROCycleAccept)*sizeof(Bool_t));
116 //______________________________________________________________________
117 Bool_t AliITSUSimulation::AddSDigitsToModule(TSeqCollection *pItemArr,Int_t mask )
119 // Add Summable digits to module maps.
121 // pItemArr Array of AliITSpListItems (SDigits).
122 // mask Track number off set value
124 Int_t nItems = pItemArr->GetEntries();
127 for( Int_t i=0; i<nItems; i++ ) {
128 AliITSUSDigit * pItem = (AliITSUSDigit *)(pItemArr->At( i ));
129 if(pItem->GetModule() != int(fModule->GetIndex()) ) AliFatal(Form("SDigits module %d != current module %d: exit", pItem->GetModule(),fModule->GetIndex()));
130 if(pItem->GetSumSignal()>0.0 ) sig = kTRUE;
131 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(pItem);
133 oldItem = (AliITSUSDigit*)fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(*pItem) );
134 if (mask) oldItem->ShiftIndices(mask);
136 else oldItem->AddTo(mask, pItem);
141 //______________________________________________________________________
142 void AliITSUSimulation::UpdateMapSignal(UInt_t col,UInt_t row,Int_t trk,Int_t ht,Double_t signal, Int_t roCycle)
144 // update map with new hit
145 // Note: roCycle can be anything between -kMaxROCycleAccept : kMaxROCycleAccept
146 if (Abs(roCycle)>kMaxROCycleAccept) {
147 AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
150 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
151 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
153 fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(trk,ht,fModule->GetIndex(),ind,signal,roCycle) );
154 fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
156 else oldItem->AddSignal(trk,ht,signal);
160 //______________________________________________________________________
161 void AliITSUSimulation::UpdateMapNoise(UInt_t col,UInt_t row,Double_t noise, Int_t roCycle)
163 // update map with new hit
164 if (Abs(roCycle)>kMaxROCycleAccept) {
165 AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
168 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
169 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
171 fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(fModule->GetIndex(),ind,noise,roCycle) );
172 fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
174 else oldItem->AddNoise(noise);
177 //______________________________________________________________________
178 Int_t AliITSUSimulation::GenOrderedSample(UInt_t nmax,UInt_t ngen,TArrayI &vals,TArrayI &indx)
180 // generate random sample [0:nmax] of ngen variables, and fill orreder indices
181 // return actual number of generated values
182 if (vals.GetSize()<(int)ngen) vals.Set(ngen);
183 if (indx.GetSize()<(int)ngen) indx.Set(ngen);
184 int* valA = vals.GetArray();
185 int* indA = indx.GetArray();
188 for (int i=(int)ngen;i--;) {valA[i]=indA[i]=i;}
192 for (int i=0;i<(int)ngen;i++) {
193 do { // exclude repetitions
195 valA[i] = gRandom->Rndm()*nmax;
196 for (int j=i;j--;) if (valA[j]==valA[i]) {rep=kTRUE;break;}
199 Sort((int)ngen,valA,indA,kFALSE);
203 //______________________________________________________________________
204 Double_t AliITSUSimulation::GenerateReadOutCycleOffset()
206 // Generate randomly the strobe
207 // phase w.r.t to the LHC clock
208 return fReadOutCycleOffset = fReadOutCycleLength*gRandom->Rndm();
209 // 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?!
210 // 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
211 // collision will be lost) untill real number is specified