er  dev
ERGadastDigitizer.cxx
1 #include "ERGadastDigitizer.h"
2 
3 #include "TVector3.h"
4 #include "TMath.h"
5 
6 #include "FairRun.h"
7 #include "FairRuntimeDb.h"
8 #include "FairEventHeader.h"
9 
10 #include "ERGadastCsIPoint.h"
11 #include "ERGadastLaBrPoint.h"
12 
13 using namespace std;
14 
15 // ----------------------------------------------------------------------------
17  : FairTask("ER Gadast Digitization scheme"),
18  fSetup(NULL),
19  fCsILC(1.),
20  fCsIEdepErrorA(0.),
21  fCsIEdepErrorB(0.),
22  fCsIEdepErrorC(0.),
23  fCsITimeErrorA(0.),
24  fLaBrLC(1.),
25  fLaBrEdepErrorA(0.),
26  fLaBrEdepErrorB(0.),
27  fLaBrEdepErrorC(0.),
28  fLaBrTimeErrorA(0.),
29  fCsIElossThreshold(0.),
30  fLaBrElossThreshold(0.)
31 {
32 }
33 // ----------------------------------------------------------------------------
34 
35 // ----------------------------------------------------------------------------
37  : FairTask("ER Gadast Digitization scheme ", verbose),
38  fSetup(NULL),
39  fCsILC(1.),
40  fCsIEdepErrorA(0.),
41  fCsIEdepErrorB(0.),
42  fCsIEdepErrorC(0.),
43  fCsITimeErrorA(0.),
44  fLaBrLC(1.),
45  fLaBrEdepErrorA(0.),
46  fLaBrEdepErrorB(0.),
47  fLaBrEdepErrorC(0.),
48  fLaBrTimeErrorA(0.),
49  fCsIElossThreshold(0.),
50  fLaBrElossThreshold(0.)
51 {
52 }
53 // ----------------------------------------------------------------------------
54 
55 // ----------------------------------------------------------------------------
57 {
58  delete fSetup;
59 }
60 // ----------------------------------------------------------------------------
61 
62 // ----------------------------------------------------------------------------
63 void ERGadastDigitizer::SetParContainers()
64 {
65  // Get run and runtime database
66  FairRun* run = FairRun::Instance();
67  if ( ! run ) Fatal("SetParContainers", "No analysis run");
68 
69  FairRuntimeDb* rtdb = run->GetRuntimeDb();
70  if ( ! rtdb ) Fatal("SetParContainers", "No runtime database");
71 
73  (rtdb->getContainer("ERGadastDigiPar"));
74  if ( fVerbose && fDigiPar ) {
75  std::cout << "ERGadastDigitizer::SetParContainers() "<< std::endl;
76  std::cout << "ERGadastDigiPar initialized! "<< std::endl;
77  }
78 }
79 // ----------------------------------------------------------------------------
80 
81 //----------------------------------------------------------------------------
83 {
84  // Get input array
85  FairRootManager* ioman = FairRootManager::Instance();
86  if ( ! ioman ) Fatal("Init", "No FairRootManager");
87 
88  fGadastCsIPoints = (TClonesArray*) ioman->GetObject("GadastCsIPoint");
89  fGadastLaBrPoints = (TClonesArray*) ioman->GetObject("GadastLaBrPoint");
90 
91  // Register output arrays
92  fGadastCsIDigi = new TClonesArray("ERGadastCsIDigi",1000);
93  fGadastLaBrDigi = new TClonesArray("ERGadastLaBrDigi",1000);
94  ioman->Register("GadastCsIDigi", "Digital response in Gadast CsI", fGadastCsIDigi, kTRUE);
95  ioman->Register("GadastLaBrDigi", "Digital response in Gadast LaBr", fGadastLaBrDigi, kTRUE);
96 
97  fSetup = ERGadastSetup::Instance();
98  if (!fSetup->Init()){
99  std::cerr << "Problems with ERGadastSetup initialization!" << std::endl;
100  }
101  return kSUCCESS;
102 }
103 // -------------------------------------------------------------------------
104 
105 // ----- Public method Exec --------------------------------------------
106 void ERGadastDigitizer::Exec(Option_t* opt)
107 {
108  // Reset entries in output arrays
109  Reset();
110 
111  // Sort points by sensentive volumes
112  // Map points by cells: pointsCsI[iWall][iBlock][iCell]
113  map<Int_t, map<Int_t, map <Int_t, vector<Int_t> > > > pointsCsI;
114  for (Int_t iPoint = 0; iPoint < fGadastCsIPoints->GetEntriesFast(); iPoint++){
115  ERGadastCsIPoint* point = (ERGadastCsIPoint*)fGadastCsIPoints->At(iPoint);
116  pointsCsI[point->GetWall()][point->GetBlock()][point->GetCell()].push_back(iPoint);
117  }
118 
119  // Map points by cells: pointsLaBr[iCell]
120  map<Int_t, vector<Int_t> > pointsLaBr;
121  for (Int_t iPoint = 0; iPoint < fGadastLaBrPoints->GetEntriesFast(); iPoint++){
122  ERGadastLaBrPoint* point = (ERGadastLaBrPoint*)fGadastLaBrPoints->At(iPoint);
123  pointsLaBr[point->GetCell()].push_back(iPoint);
124  }
125 
126  for (const auto &itWall : pointsCsI){
127  for (const auto &itBlock : itWall.second){
128  for (const auto &itCell : itBlock.second){
129  Float_t edep = 0; // sum edep in cell
130  Float_t time = std::numeric_limits<float>::max(); // first time in cell
131  for (const auto iPoint : itCell.second){
132  ERGadastCsIPoint* point = (ERGadastCsIPoint*)fGadastCsIPoints->At(iPoint);
133  edep += point->GetEnergyLoss();
134  if (point->GetTime() < time)
135  time = point->GetTime();
136  }
137  Float_t edepSigma = sqrt(pow(fCsIEdepErrorA,2) + pow(fCsIEdepErrorB*TMath::Sqrt(edep),2) + pow(fCsIEdepErrorC*edep,2));
138  edep = gRandom->Gaus(fCsILC*edep, edepSigma);
139  if (edep < fCsIElossThreshold)
140  continue;
141  Float_t timeSigma = TMath::Sqrt(fCsITimeErrorA/edep);
142  time = gRandom->Gaus(time, timeSigma);
143 
144  AddCsIDigi(edep,itWall.first,itBlock.first,itCell.first);
145  }
146  }
147  }
148 
149  for (const auto &itCell : pointsLaBr){
150  Float_t edep = 0; // sum edep in cell
151  Float_t time = std::numeric_limits<float>::max(); // first time in cell
152  for (const auto iPoint : itCell.second){
153  ERGadastLaBrPoint* point = (ERGadastLaBrPoint*)fGadastLaBrPoints->At(iPoint);
154  edep += point->GetEnergyLoss();
155  if (point->GetTime() < time)
156  time = point->GetTime();
157  }
158  Float_t edepSigma = sqrt(pow(fLaBrEdepErrorA,2) + pow(fLaBrEdepErrorB*TMath::Sqrt(edep),2) + pow(fLaBrEdepErrorC*edep,2));
159  edep = gRandom->Gaus(fLaBrLC*edep, edepSigma);
160  if (edep < fLaBrElossThreshold)
161  continue;
162  Float_t timeSigma = TMath::Sqrt(fLaBrTimeErrorA/edep);
163  time = gRandom->Gaus(time, timeSigma);
164 
165  AddLaBrDigi(edep,itCell.first);
166  }
167 }
168 //----------------------------------------------------------------------------
169 
170 //----------------------------------------------------------------------------
172 {
173  if (fGadastCsIDigi) {
174  fGadastCsIDigi->Delete();
175  }
176  if (fGadastLaBrDigi) {
177  fGadastLaBrDigi->Delete();
178  }
179 }
180 // ----------------------------------------------------------------------------
181 
182 // ----------------------------------------------------------------------------
184 {
185  std::cout << "========== Finish of ERGadastDigitizer =================="<< std::endl;
186 }
187 // ----------------------------------------------------------------------------
188 
189 // ----------------------------------------------------------------------------
190 ERGadastCsIDigi* ERGadastDigitizer::AddCsIDigi(Float_t Edep,Int_t wall,Int_t block, Int_t cell)
191 {
192  ERGadastCsIDigi *digi = new((*fGadastCsIDigi)[fGadastCsIDigi->GetEntriesFast()])
193  ERGadastCsIDigi(fGadastCsIDigi->GetEntriesFast(), Edep, wall, block, cell);
194  return digi;
195 }
196 // ----------------------------------------------------------------------------
197 ERGadastLaBrDigi* ERGadastDigitizer::AddLaBrDigi(Float_t Edep, Int_t cell)
198 {
199  ERGadastLaBrDigi *digi = new((*fGadastLaBrDigi)[fGadastLaBrDigi->GetEntriesFast()])
200  ERGadastLaBrDigi(fGadastLaBrDigi->GetEntriesFast(), Edep, cell);
201  return digi;
202 }
203 ClassImp(ERGadastDigitizer)
virtual void Exec(Option_t *opt)
The data class for storing pieces of charged tracks in sensitive volumes in CsI crystall.
virtual InitStatus Init()
ERGadastDigiPar * fDigiPar