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()
43 // Default constructor
45 //______________________________________________________________________
46 AliITSUSimulation::AliITSUSimulation(AliITSUSimuParam* sim,AliITSUSensMap* map)
57 // Default constructor
60 //__________________________________________________________________________
61 AliITSUSimulation::AliITSUSimulation(const AliITSUSimulation &s)
64 ,fCalibDead(s.fCalibDead)
65 ,fCalibNoisy(s.fCalibNoisy)
67 ,fSimuParam(s.fSimuParam)
68 ,fResponseParam(s.fResponseParam)
76 //_________________________________________________________________________
77 AliITSUSimulation& AliITSUSimulation::operator=(const AliITSUSimulation &s)
79 // Assignment operator
80 if(&s == this) return *this;
82 fCalibDead = s.fCalibDead;
83 fCalibNoisy= s.fCalibNoisy;
84 fSensMap = s.fSensMap;
85 fSimuParam = s.fSimuParam;
86 fResponseParam = s.fResponseParam;
92 //______________________________________________________________________
93 void AliITSUSimulation::InitSimulationModule(AliITSUModule* mod, Int_t event, AliITSsegmentation* seg, AliITSUParamList* resp)
95 // This function creates maps to build the list of tracks for each
96 // summable digit. Inputs defined by base class.
100 SetResponseParam(resp);
103 if (event != fEvent) GenerateReadOutCycleOffset();
108 //______________________________________________________________________
109 Bool_t AliITSUSimulation::AddSDigitsToModule(TSeqCollection *pItemArr,Int_t mask )
111 // Add Summable digits to module maps.
113 // pItemArr Array of AliITSpListItems (SDigits).
114 // mask Track number off set value
116 Int_t nItems = pItemArr->GetEntries();
119 for( Int_t i=0; i<nItems; i++ ) {
120 AliITSUSDigit * pItem = (AliITSUSDigit *)(pItemArr->At( i ));
121 if(pItem->GetModule() != int(fModule->GetIndex()) ) AliFatal(Form("SDigits module %d != current module %d: exit", pItem->GetModule(),fModule->GetIndex()));
122 if(pItem->GetSumSignal()>0.0 ) sig = kTRUE;
123 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(pItem);
125 oldItem = (AliITSUSDigit*)fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(*pItem) );
126 if (mask) oldItem->ShiftIndices(mask);
128 else oldItem->AddTo(mask, pItem);
133 //______________________________________________________________________
134 void AliITSUSimulation::UpdateMapSignal(UInt_t col,UInt_t row,Int_t trk,Int_t ht,Double_t signal, Int_t roCycle)
136 // update map with new hit
137 // Note: roCycle can be anything between -kMaxROCycleAccept : kMaxROCycleAccept, but the index should be built with pos.number
138 UInt_t ind = fSensMap->GetIndex(col,row,roCycle+kMaxROCycleAccept);
139 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
140 if (!oldItem) fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(trk,ht,fModule->GetIndex(),ind,signal,roCycle) );
141 else oldItem->AddSignal(trk,ht,signal);
144 //______________________________________________________________________
145 void AliITSUSimulation::UpdateMapNoise(UInt_t col,UInt_t row,Double_t noise, Int_t roCycle)
147 // update map with new hit
148 UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
149 AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
150 if (!oldItem) fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(fModule->GetIndex(),ind,noise,roCycle) );
151 else oldItem->AddNoise(noise);
154 //______________________________________________________________________
155 Int_t AliITSUSimulation::GenOrderedSample(UInt_t nmax,UInt_t ngen,TArrayI &vals,TArrayI &indx)
157 // generate random sample [0:nmax] of ngen variables, and fill orreder indices
158 // return actual number of generated values
159 if (vals.GetSize()<(int)ngen) vals.Set(ngen);
160 if (indx.GetSize()<(int)ngen) indx.Set(ngen);
161 int* valA = vals.GetArray();
162 int* indA = indx.GetArray();
165 for (int i=(int)ngen;i--;) {valA[i]=indA[i]=i;}
169 for (int i=0;i<(int)ngen;i++) {
170 do { // exclude repetitions
172 valA[i] = gRandom->Rndm()*nmax;
173 for (int j=i;j--;) if (valA[j]==valA[i]) {rep=kTRUE;break;}
176 Sort((int)ngen,valA,indA,kFALSE);