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