]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUSimulation.cxx
Adding a time-acceptance window for good MC vertices
[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 ITSU detector signal simulations. Data members //
17 ///////////////////////////////////////////////////////////////////////////////
18 #include <TRandom.h>
19 #include "TSeqCollection.h"
20 #include "AliITSUSimulation.h"
21 #include "AliITSUSDigit.h"
22 #include "AliITSUChip.h"
23 #include "AliITSUParamList.h"
24 using namespace TMath;
25
26 ClassImp(AliITSUSimulation)
27
28 //______________________________________________________________________
29 AliITSUSimulation::AliITSUSimulation()
30 :  fSeg(0)
31   ,fCalibDead(0)
32   ,fCalibNoisy(0)
33   ,fSensMap(0)
34   ,fSimuParam(0)
35   ,fResponseParam(0)
36   ,fChip(0)
37   ,fReadOutCycleOffset(0)
38   ,fReadOutCycleLength(25e-6)  
39   ,fEvent(0)
40   ,fDebug(0)
41 {
42     // Default constructor
43 }
44 //______________________________________________________________________
45 AliITSUSimulation::AliITSUSimulation(AliITSUSimuParam* sim,AliITSUSensMap* map)
46   :fSeg(0)
47   ,fCalibDead(0)
48   ,fCalibNoisy(0)
49   ,fSensMap(map)
50   ,fSimuParam(sim)
51   ,fResponseParam(0)
52   ,fChip(0)
53   ,fReadOutCycleOffset(0)
54   ,fReadOutCycleLength(25e-6)
55   ,fEvent(0)
56   ,fDebug(0)
57 {
58     // Default constructor
59 }
60
61 //__________________________________________________________________________
62 AliITSUSimulation::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)   
69   ,fResponseParam(s.fResponseParam)
70   ,fChip(s.fChip)
71   ,fReadOutCycleOffset(s.fReadOutCycleOffset)
72   ,fReadOutCycleLength(s.fReadOutCycleLength)
73   ,fEvent(s.fEvent)
74   ,fDebug(s.fDebug)
75 {
76   //     Copy Constructor 
77 }
78
79 //_________________________________________________________________________
80 AliITSUSimulation&  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;
89   fResponseParam = s.fResponseParam;
90   fChip    = s.fChip;
91   fReadOutCycleOffset = s.fReadOutCycleOffset;
92   fReadOutCycleLength = s.fReadOutCycleLength;
93   fEvent     = s.fEvent;
94   return *this;
95 }
96
97 //______________________________________________________________________
98 void AliITSUSimulation::InitSimulationChip(AliITSUChip* mod, Int_t event, AliITSsegmentation* seg, AliITSUParamList* resp)
99 {
100   //  This function creates maps to build the list of tracks for each
101   //  summable digit. Inputs defined by base class.
102   //
103   SetChip(mod);
104   SetSegmentation(seg);
105   SetResponseParam(resp);
106   ClearMap();
107   memset(fCyclesID,0,(1+2*kMaxROCycleAccept)*sizeof(Bool_t));
108   //
109   SetEvent(event);
110   
111 }
112
113 //______________________________________________________________________
114 Bool_t AliITSUSimulation::AddSDigitsToChip(TSeqCollection *pItemArr,Int_t mask )
115 {
116   // Add Summable digits to chip maps.
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 ));
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);
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 //______________________________________________________________________
139 void AliITSUSimulation::UpdateMapSignal(UInt_t col,UInt_t row,Int_t trk,Int_t ht,Double_t signal, Int_t roCycle) 
140 {
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));
145     return;
146   }
147   UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
148   AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);  
149   if (!oldItem) {    
150     fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(trk,ht,fChip->GetIndex(),ind,signal,roCycle) );
151     fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
152   }
153   else oldItem->AddSignal(trk,ht,signal);
154   //
155 }
156
157 //______________________________________________________________________
158 void AliITSUSimulation::UpdateMapNoise(UInt_t col,UInt_t row,Double_t noise, Int_t roCycle) 
159 {
160   // update map with new hit
161   if (Abs(roCycle)>kMaxROCycleAccept) {
162     AliError(Form("CycleID %d is outside of allowed +-%d range",roCycle,kMaxROCycleAccept));
163     return;
164   }
165   UInt_t ind = fSensMap->GetIndex(col,row,roCycle);
166   AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
167   if (!oldItem) {
168     fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(fChip->GetIndex(),ind,noise,roCycle) );
169     fCyclesID[roCycle+kMaxROCycleAccept] = kTRUE;
170   }
171   else oldItem->AddNoise(noise);
172 }
173
174 //______________________________________________________________________
175 Int_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   }
196   Sort((int)ngen,valA,indA,kFALSE);
197   return ngen;
198 }
199
200 //______________________________________________________________________
201 Double_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 }