]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUSimulation.cxx
1) Added classes for digitization
[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
26 ClassImp(AliITSUSimulation)
27
28 //______________________________________________________________________
29 AliITSUSimulation::AliITSUSimulation()
30 :  fSeg(0)
31   ,fCalibDead(0)
32   ,fCalibNoisy(0)
33   ,fSensMap(0)
34   ,fSimuParam(0)
35   ,fModule(0)
36   ,fEvent(0)
37   ,fDebug(0)
38 {
39     // Default constructor
40 }
41 //______________________________________________________________________
42 AliITSUSimulation::AliITSUSimulation(AliITSUSimuParam* sim,AliITSUSensMap* map)
43   :fSeg(0)
44   ,fCalibDead(0)
45   ,fCalibNoisy(0)
46   ,fSensMap(map)
47   ,fSimuParam(sim)
48   ,fModule(0)
49   ,fEvent(0)
50   ,fDebug(0)
51 {
52     // Default constructor
53 }
54
55 //__________________________________________________________________________
56 AliITSUSimulation::AliITSUSimulation(const AliITSUSimulation &s) 
57   :TObject(s)
58   ,fSeg(s.fSeg)
59   ,fCalibDead(s.fCalibDead)
60   ,fCalibNoisy(s.fCalibNoisy)
61   ,fSensMap(s.fSensMap)
62   ,fSimuParam(s.fSimuParam)   
63   ,fModule(s.fModule)
64   ,fEvent(s.fEvent)
65   ,fDebug(s.fDebug)
66 {
67   //     Copy Constructor 
68 }
69
70 //_________________________________________________________________________
71 AliITSUSimulation&  AliITSUSimulation::operator=(const AliITSUSimulation &s)
72 {
73   //    Assignment operator
74   if(&s == this) return *this;
75   fSeg       = s.fSeg;
76   fCalibDead = s.fCalibDead;
77   fCalibNoisy= s.fCalibNoisy;
78   fSensMap   = s.fSensMap;
79   fSimuParam = s.fSimuParam;
80   fModule    = s.fModule;
81   fEvent     = s.fEvent;
82   return *this;
83 }
84
85 //______________________________________________________________________
86 void AliITSUSimulation::InitSimulationModule(Int_t module, Int_t event, AliITSsegmentation* seg)
87 {
88   //  This function creates maps to build the list of tracks for each
89   //  summable digit. Inputs defined by base class.
90   //
91   SetModule(module);
92   SetEvent(event);
93   SetSegmentation(seg);
94   ClearMap();
95 }
96
97 //______________________________________________________________________
98 Bool_t AliITSUSimulation::AddSDigitsToModule(TSeqCollection *pItemArr,Int_t mask )
99 {
100   // Add Summable digits to module maps.
101   // Inputs:
102   //    pItemArr  Array of AliITSpListItems (SDigits).
103   //    mask    Track number off set value 
104   //
105   Int_t nItems = pItemArr->GetEntries();
106   Bool_t sig = kFALSE;
107   // 
108   for( Int_t i=0; i<nItems; i++ ) {
109     AliITSUSDigit * pItem = (AliITSUSDigit *)(pItemArr->At( i ));
110     if( pItem->GetModule() != fModule ) AliFatal(Form("SDigits module %d != current module %d: exit", pItem->GetModule(), fModule ));
111     if(pItem->GetSumSignal()>0.0 ) sig = kTRUE;
112     AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(pItem);
113     if (!oldItem) {
114       oldItem = (AliITSUSDigit*)fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(*pItem) );
115       if (mask) oldItem->ShiftIndices(mask);
116     }
117     else oldItem->AddTo(mask, pItem);
118   }
119   return sig;
120 }
121
122 //______________________________________________________________________
123 void AliITSUSimulation::UpdateMapSignal(UInt_t dim0,UInt_t dim1,Int_t trk,Int_t ht,Double_t signal) 
124 {
125   // update map with new hit
126   UInt_t ind = fSensMap->GetIndex(dim0,dim1);
127   AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
128   if (!oldItem) fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(trk,ht,fModule,ind,signal) );
129   else oldItem->AddSignal(trk,ht,signal);
130 }
131
132 //______________________________________________________________________
133 void AliITSUSimulation::UpdateMapNoise(UInt_t dim0,UInt_t dim1,Double_t noise) 
134 {
135   // update map with new hit
136   UInt_t ind = fSensMap->GetIndex(dim0,dim1);
137   AliITSUSDigit* oldItem = (AliITSUSDigit*)fSensMap->GetItem(ind);
138   if (!oldItem) fSensMap->RegisterItem( new(fSensMap->GetFree()) AliITSUSDigit(fModule,ind,noise) );
139   else oldItem->AddNoise(noise);
140 }
141
142 //______________________________________________________________________
143 Int_t AliITSUSimulation::GenOrderedSample(UInt_t nmax,UInt_t ngen,TArrayI &vals,TArrayI &indx)
144 {
145   // generate random sample [0:nmax] of ngen variables, and fill orreder indices 
146   // return actual number of generated values 
147   if (vals.GetSize()<(int)ngen) vals.Set(ngen);
148   if (indx.GetSize()<(int)ngen) indx.Set(ngen);
149   int* valA = vals.GetArray();
150   int* indA = indx.GetArray();
151   if (ngen>=nmax) {
152     ngen = nmax-1;
153     for (int i=(int)ngen;i--;) {valA[i]=indA[i]=i;}
154     return ngen;
155   }
156   Bool_t rep;
157   for (int i=0;i<(int)ngen;i++) {
158     do { // exclude repetitions
159       rep = kFALSE;
160       valA[i] = gRandom->Rndm()*nmax;
161       for (int j=i;j--;) if (valA[j]==valA[i]) {rep=kTRUE;break;}
162     } while(rep);
163   }
164   TMath::Sort((int)ngen,valA,indA,kFALSE);
165   return ngen;
166 }