]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUSimulation.cxx
Implemented possibility of synchronized, layer-staggered or fully randomized pixel...
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUSimulation.cxx
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"
25 #include "AliITSUModule.h"
26 #include "AliITSUParamList.h"
27 using namespace TMath;
28
29 ClassImp(AliITSUSimulation)
30
31 //______________________________________________________________________
32 AliITSUSimulation::AliITSUSimulation()
33 :  fSeg(0)
34   ,fCalibDead(0)
35   ,fCalibNoisy(0)
36   ,fSensMap(0)
37   ,fSimuParam(0)
38   ,fResponseParam(0)
39   ,fModule(0)
40   ,fReadOutCycleOffset(0)
41   ,fReadOutCycleLength(25e-6)  
42   ,fEvent(0)
43   ,fDebug(0)
44 {
45     // Default constructor
46 }
47 //______________________________________________________________________
48 AliITSUSimulation::AliITSUSimulation(AliITSUSimuParam* sim,AliITSUSensMap* map)
49   :fSeg(0)
50   ,fCalibDead(0)
51   ,fCalibNoisy(0)
52   ,fSensMap(map)
53   ,fSimuParam(sim)
54   ,fResponseParam(0)
55   ,fModule(0)
56   ,fReadOutCycleOffset(0)
57   ,fReadOutCycleLength(25e-6)
58   ,fEvent(0)
59   ,fDebug(0)
60 {
61     // Default constructor
62 }
63
64 //__________________________________________________________________________
65 AliITSUSimulation::AliITSUSimulation(const AliITSUSimulation &s) 
66   :TObject(s)
67   ,fSeg(s.fSeg)
68   ,fCalibDead(s.fCalibDead)
69   ,fCalibNoisy(s.fCalibNoisy)
70   ,fSensMap(s.fSensMap)
71   ,fSimuParam(s.fSimuParam)   
72   ,fResponseParam(s.fResponseParam)
73   ,fModule(s.fModule)
74   ,fReadOutCycleOffset(s.fReadOutCycleOffset)
75   ,fReadOutCycleLength(s.fReadOutCycleLength)
76   ,fEvent(s.fEvent)
77   ,fDebug(s.fDebug)
78 {
79   //     Copy Constructor 
80 }
81
82 //_________________________________________________________________________
83 AliITSUSimulation&  AliITSUSimulation::operator=(const AliITSUSimulation &s)
84 {
85   //    Assignment operator
86   if(&s == this) return *this;
87   fSeg       = s.fSeg;
88   fCalibDead = s.fCalibDead;
89   fCalibNoisy= s.fCalibNoisy;
90   fSensMap   = s.fSensMap;
91   fSimuParam = s.fSimuParam;
92   fResponseParam = s.fResponseParam;
93   fModule    = s.fModule;
94   fReadOutCycleOffset = s.fReadOutCycleOffset;
95   fReadOutCycleLength = s.fReadOutCycleLength;
96   fEvent     = s.fEvent;
97   return *this;
98 }
99
100 //______________________________________________________________________
101 void AliITSUSimulation::InitSimulationModule(AliITSUModule* mod, Int_t event, AliITSsegmentation* seg, AliITSUParamList* resp)
102 {
103   //  This function creates maps to build the list of tracks for each
104   //  summable digit. Inputs defined by base class.
105   //
106   SetModule(mod);
107   SetSegmentation(seg);
108   SetResponseParam(resp);
109   ClearMap();
110   memset(fCyclesID,0,(1+2*kMaxROCycleAccept)*sizeof(Bool_t));
111   //
112   SetEvent(event);
113   
114 }
115
116 //______________________________________________________________________
117 Bool_t AliITSUSimulation::AddSDigitsToModule(TSeqCollection *pItemArr,Int_t mask )
118 {
119   // Add Summable digits to module maps.
120   // Inputs:
121   //    pItemArr  Array of AliITSpListItems (SDigits).
122   //    mask    Track number off set value 
123   //
124   Int_t nItems = pItemArr->GetEntries();
125   Bool_t sig = kFALSE;
126   // 
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);
132     if (!oldItem) {
133       oldItem = (AliITSUSDigit*)fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(*pItem) );
134       if (mask) oldItem->ShiftIndices(mask);
135     }
136     else oldItem->AddTo(mask, pItem);
137   }
138   return sig;
139 }
140
141 //______________________________________________________________________
142 void AliITSUSimulation::UpdateMapSignal(UInt_t col,UInt_t row,Int_t trk,Int_t ht,Double_t signal, Int_t roCycle) 
143 {
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));
148     return;
149   }
150   UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
151   AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);  
152   if (!oldItem) {    
153     fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(trk,ht,fModule->GetIndex(),ind,signal,roCycle) );
154     fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
155   }
156   else oldItem->AddSignal(trk,ht,signal);
157   //
158 }
159
160 //______________________________________________________________________
161 void AliITSUSimulation::UpdateMapNoise(UInt_t col,UInt_t row,Double_t noise, Int_t roCycle) 
162 {
163   // update map with new hit
164   if (Abs(roCycle)>kMaxROCycleAccept) {
165     AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
166     return;
167   }
168   UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
169   AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
170   if (!oldItem) {
171     fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(fModule->GetIndex(),ind,noise,roCycle) );
172     fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
173   }
174   else oldItem->AddNoise(noise);
175 }
176
177 //______________________________________________________________________
178 Int_t AliITSUSimulation::GenOrderedSample(UInt_t nmax,UInt_t ngen,TArrayI &vals,TArrayI &indx)
179 {
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();
186   if (ngen>=nmax) {
187     ngen = nmax-1;
188     for (int i=(int)ngen;i--;) {valA[i]=indA[i]=i;}
189     return ngen;
190   }
191   Bool_t rep;
192   for (int i=0;i<(int)ngen;i++) {
193     do { // exclude repetitions
194       rep = kFALSE;
195       valA[i] = gRandom->Rndm()*nmax;
196       for (int j=i;j--;) if (valA[j]==valA[i]) {rep=kTRUE;break;}
197     } while(rep);
198   }
199   Sort((int)ngen,valA,indA,kFALSE);
200   return ngen;
201 }
202
203 //______________________________________________________________________
204 Double_t AliITSUSimulation::GenerateReadOutCycleOffset()
205 {
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
212  //
213 }