1 |
#ifndef PAMVMCRNDMGR_H |
2 |
#define PAMVMCRNDMGR_H |
3 |
#include <iostream> |
4 |
#include <TString.h> |
5 |
#include <TObjArray.h> |
6 |
#include <TRandom3.h> |
7 |
#include <TSystem.h> |
8 |
#include <TMap.h> |
9 |
#include "PamVMCOptMgr.h" |
10 |
#include "PamRootManager.h" |
11 |
//This class holds few different random objects |
12 |
//one for each digitization procedure, |
13 |
//include Trk digitizations during stepping |
14 |
|
15 |
using std::cout; |
16 |
using std::endl; |
17 |
|
18 |
#define RNDDEBUG 0 |
19 |
|
20 |
class PamVMCRndMgr: public TObject |
21 |
{ |
22 |
private: |
23 |
|
24 |
static PamVMCRndMgr * rm; |
25 |
TObjArray *frndArr; // An array of random objects; |
26 |
TMap frndmap; //map which holds all actual random objects |
27 |
|
28 |
|
29 |
|
30 |
protected: |
31 |
PamVMCRndMgr() |
32 |
{ |
33 |
|
34 |
frndArr = new TObjArray(); |
35 |
frndArr->SetOwner(kTRUE); |
36 |
if (PamVMCOptMgr::Instance()->GetSaveMode() == ALL_DETECTORS){ |
37 |
PamRootManager::Instance()->Register("RNDM","TObjArray",&frndArr); |
38 |
if (RNDDEBUG){ |
39 |
cout<<"Random objects Map was created and branch registered" <<endl; |
40 |
} |
41 |
} |
42 |
} |
43 |
PamVMCRndMgr( TString ext_dig ) |
44 |
{ |
45 |
frndArr = new TObjArray(); |
46 |
cout<<"Random objects Map was created and branch registered" <<ext_dig<<endl; |
47 |
} |
48 |
|
49 |
virtual ~PamVMCRndMgr() |
50 |
{ |
51 |
delete frndArr; |
52 |
} |
53 |
|
54 |
public: |
55 |
|
56 |
static PamVMCRndMgr * Instance(); |
57 |
static PamVMCRndMgr * Instance_ext(); //Another way to call instance... for ext_dig constructor |
58 |
|
59 |
/* Used only by PamVMCTrkF77 */ |
60 |
Double_t GenRandom(const char* name){ |
61 |
if((TRandom3*)frndmap(name)) |
62 |
return ((TRandom3*)frndmap(name))->Uniform(); |
63 |
else |
64 |
{ |
65 |
cout<<"Error while calling RndMgr::GenRandom, object not found"<<endl; |
66 |
return 0.; |
67 |
} |
68 |
} |
69 |
|
70 |
void RegisterRandom(const char* name, TRandom3 *detrnd){ |
71 |
frndmap.Add(new TObjString(name), detrnd); |
72 |
if(RNDDEBUG){ |
73 |
cout<<"RegisterRandom to rnd for "<<name<<endl; |
74 |
frndmap.Print(); |
75 |
} |
76 |
} |
77 |
|
78 |
|
79 |
|
80 |
void MakeRandomClones() |
81 |
{ |
82 |
if(RNDDEBUG) cout<<" Snapshot of random objects done"<<endl; |
83 |
TMapIter *n= (TMapIter *)frndmap.MakeIterator(); |
84 |
TObject *o; while( (o=(TObject *) n->Next())) { |
85 |
TRandom3 *tmp = (TRandom3*)frndmap.GetValue(o); |
86 |
frndArr->Add(tmp->Clone()); |
87 |
if(RNDDEBUG) { |
88 |
cout<<"Obj: "<<tmp<<" det: "<<tmp->GetName()<<endl; |
89 |
tmp->Dump(); |
90 |
} |
91 |
} |
92 |
delete n; |
93 |
} |
94 |
|
95 |
|
96 |
void ClearColl() { (*frndArr).Clear("C"); } |
97 |
void Compress() { (*frndArr).Compress(); } |
98 |
}; |
99 |
|
100 |
#endif |