CbmRoot
CbmPsdSimpleDigitizer.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmPsdSimpleDigitizer source file -----
3 // ----- Created 15/05/12 by Alla & SELIM & FLORIAN -----
4 // ----- Modified 17/03/18 by Sergey Morozov -----
5 // -------------------------------------------------------------------------
6 #include <cassert>
7 #include <iomanip>
8 #include <iostream>
9 #include <map>
10 
11 #include "TClonesArray.h"
12 
13 #include "FairLogger.h"
14 #include "FairRootManager.h"
15 
16 #include "CbmPsdDigi.h"
17 #include "CbmPsdPoint.h"
18 #include "CbmPsdSimpleDigitizer.h"
19 #include "TMath.h"
20 #include "TStopwatch.h"
21 
22 using std::cout;
23 using std::endl;
24 using std::fixed;
25 using std::right;
26 using std::setprecision;
27 using std::setw;
28 
29 using std::map;
30 using std::pair;
31 
32 
33 // ----- Default constructor -------------------------------------------
35  : CbmDigitize<CbmPsdDigi>("PsdDigitize")
36  , fNofEvents(0)
37  , fNofPoints(0.)
38  , fNofDigis(0.)
39  , fTimeTot(0.)
40  , fPointArray(NULL) {}
41 // -------------------------------------------------------------------------
42 
43 
44 // ----- Destructor ----------------------------------------------------
46 // -------------------------------------------------------------------------
47 
48 
49 // ----- Public method Init --------------------------------------------
51 
52  // Matches are not produced
53  fCreateMatches = kFALSE;
54 
55  // Get RootManager
56  FairRootManager* ioman = FairRootManager::Instance();
57  assert(ioman),
58 
59  // Get input array
60  fPointArray = (TClonesArray*) ioman->GetObject("PsdPoint");
61  assert(fPointArray);
62 
63  // Create and register output array
65 
66  // Statistics
67  fNofEvents = 0;
68  fNofPoints = 0;
69  fNofDigis = 0.;
70  fTimeTot = 0.;
71 
72  LOG(info) << fName << ": Initialisation successful " << kSUCCESS;
73  return kSUCCESS;
74 }
75 // -------------------------------------------------------------------------
76 
77 
78 // ----- Public method Exec --------------------------------------------
79 void CbmPsdSimpleDigitizer::Exec(Option_t*) {
80 
81  TStopwatch timer;
82  timer.Start();
83 
84  LOG(debug) << fName << ": processing event " << fCurrentEvent
85  << " at t = " << fCurrentEventTime << " ns";
86 
87  // Declare some variables
88  CbmPsdPoint* point = NULL;
89  Int_t modID = -1; // module ID
90  Int_t scinID = -1; // #sciillator
91 
92  Double_t edep
93  [N_PSD_SECT]
94  [N_PSD_MODS]; //SELIM: 49 modules, including central & corner modules (rejected in analysis/flow/eventPlane.cxx)
95  memset(edep, 0, (N_PSD_SECT * N_PSD_MODS) * sizeof(Double_t));
96 
97  map<pair<int, int>, double> edepmap;
98 
99  TVector3 pos; // Position vector
100 
101  //for (Int_t imod=0; imod<100; imod++) //SELIM: 49 modules, including central & corner modules (rejected in analysis/flow/eventPlane.cxx)
102  for (Int_t imod = 0; imod < N_PSD_MODS; imod++) //marina
103  {
104  for (Int_t isec = 0; isec < N_PSD_SECT; isec++) {
105  edep[isec][imod] = 0.;
106  }
107  }
108 
109  // Event info (for event time)
110  GetEventInfo();
111 
112  // Loop over PsdPoints
113  Int_t nPoints = fPointArray->GetEntriesFast();
114 
115  Int_t sec;
116 
117  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
118  point = (CbmPsdPoint*) fPointArray->At(iPoint);
119  if (!point) continue;
120 
121  modID = point->GetModuleID(); //marina 1-44 (45)
122  scinID = point->GetDetectorID(); //1-60
123  Double_t eLoss = point->GetEnergyLoss();
124 
125  sec = (Int_t)((scinID - 1) / 6) + 1; //marina 1-10
126  auto insert_result = edepmap.insert(
127  std::make_pair(std::make_pair(modID, sec), point->GetEnergyLoss()));
128 
129  if (!insert_result.second) { // this entry has existed before
130  (*insert_result.first).second += point->GetEnergyLoss();
131  }
132  //cout <<"PSD modID,scinID,eloss " << modID << ", " << scinID << ", " << eLoss <<endl;
133 
134  if (((sec - 1) >= 0 && (sec - 1) < N_PSD_SECT)
135  && ((modID - 1) >= 0 && (modID - 1) < N_PSD_MODS)) {
136  edep[sec - 1][modID - 1] += eLoss;
137  }
138 
139  } // Loop over MCPoints
140 
141  Int_t nDigis = 0;
142  /*
143  for (Int_t imod=0; imod<N_PSD_MODS; imod++) {
144  for (Int_t isec=0; isec<N_PSD_SECT; isec++) {
145  //if (edep[isec][imod]<=0.) cout << "!! edep !! : " << edep[isec][imod] << endl;
146  if ( edep[isec][imod] <= 0. ) continue;
147  else {
148  */
149  for (auto edep_entry : edepmap) {
150  modID = edep_entry.first.first;
151  int secID = edep_entry.first.second;
152  Double_t eDep = edep_entry.second;
153 
154  //Double_t eLossMIP = edep[isec][imod] / 0.005; // 5MeV per MIP
155  Double_t eLossMIP = eDep / 0.005; // 5MeV per MIP
156  Double_t pixPerMIP = 15.; // 15 pix per MIP
157  Double_t eLossMIPSmeared =
158  gRandom->Gaus(eLossMIP * pixPerMIP, sqrt(eLossMIP * pixPerMIP))
159  / pixPerMIP;
160  Double_t eLossSmeared = eLossMIPSmeared * 0.005;
161  Double_t eNoise = gRandom->Gaus(0, 15) / 50. * 0.005;
162  eLossSmeared += eNoise;
163  // V.F. The digi time is set to the event time. This is a workaround only
164  // to integrate PSD in the common digitisation scheme.
165  CbmPsdDigi* digi =
166  new CbmPsdDigi(modID, secID, eLossSmeared, fCurrentEventTime);
167  SendData(digi);
168  nDigis++;
169  LOG(debug1) << fName << ": Digi " << nDigis << " Section " << secID
170  << " Module " << modID << " energy " << eLossSmeared;
171  }
172  /*
173  }
174  }// section
175  }//module
176  */
177 
178 
179  // --- Event log
180  timer.Stop();
181  LOG(info) << "+ " << setw(15) << GetName() << ": Event " << setw(6) << right
182  << fCurrentEvent << " at " << fixed << setprecision(3)
183  << fCurrentEventTime << " ns, points: " << nPoints
184  << ", digis: " << nDigis << ". Exec time " << setprecision(6)
185  << timer.RealTime() << " s.";
186 
187  // --- Run statistics
188  fNofEvents++;
189  fNofPoints += nPoints;
190  fNofDigis += nDigis;
191  fTimeTot += timer.RealTime();
192 }
193 // -------------------------------------------------------------------------
194 
195 
196 // ----- End-of-run ----------------------------------------------------
198  std::cout << std::endl;
199  LOG(info) << "=====================================";
200  LOG(info) << GetName() << ": Run summary";
201  LOG(info) << "Events processed : " << fNofEvents;
202  LOG(info) << "PsdPoint / event : " << setprecision(1)
203  << fNofPoints / Double_t(fNofEvents);
204  LOG(info) << "PsdDigi / event : " << fNofDigis / Double_t(fNofEvents);
205  LOG(info) << "Digis per point : " << setprecision(6)
206  << fNofDigis / fNofPoints;
207  LOG(info) << "Real time per event : " << fTimeTot / Double_t(fNofEvents)
208  << " s";
209  LOG(info) << "=====================================";
210 }
211 // -------------------------------------------------------------------------
212 
213 
CbmPsdPoint
Definition: CbmPsdPoint.h:24
CbmPsdDigi.h
CbmDigitizeBase::GetEventInfo
void GetEventInfo()
Get event information.
Definition: CbmDigitizeBase.cxx:48
memset
void memset(T *dest, T i, size_t num)
Definition: L1Grid.cxx:21
CbmDigitizeBase::fCreateMatches
Bool_t fCreateMatches
Flag for production of inter-event noise.
Definition: CbmDigitizeBase.h:161
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
CbmPsdSimpleDigitizer::Init
virtual InitStatus Init()
Definition: CbmPsdSimpleDigitizer.cxx:50
CbmPsdSimpleDigitizer::fPointArray
TClonesArray * fPointArray
Definition: CbmPsdSimpleDigitizer.h:57
N_PSD_SECT
#define N_PSD_SECT
Definition: CbmPsdSimpleDigitizer.h:21
CbmPsdSimpleDigitizer
Definition: CbmPsdSimpleDigitizer.h:25
CbmPsdSimpleDigitizer::fNofDigis
Double_t fNofDigis
Definition: CbmPsdSimpleDigitizer.h:53
CbmPsdSimpleDigitizer::CbmPsdSimpleDigitizer
CbmPsdSimpleDigitizer()
Definition: CbmPsdSimpleDigitizer.cxx:34
CbmPsdSimpleDigitizer::~CbmPsdSimpleDigitizer
virtual ~CbmPsdSimpleDigitizer()
Definition: CbmPsdSimpleDigitizer.cxx:45
CbmPsdSimpleDigitizer::fNofPoints
Double_t fNofPoints
Definition: CbmPsdSimpleDigitizer.h:52
N_PSD_MODS
#define N_PSD_MODS
Definition: CbmPsdSimpleDigitizer.h:20
CbmDigitize
Base class template for CBM digitisation tasks.
Definition: CbmDigitize.h:39
CbmDigitizeBase::fCurrentEvent
Int_t fCurrentEvent
Number of current input.
Definition: CbmDigitizeBase.h:163
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmDigitizeBase::fCurrentEventTime
Double_t fCurrentEventTime
Number of current MC entry.
Definition: CbmDigitizeBase.h:165
CbmPsdSimpleDigitizer::Finish
virtual void Finish()
End-of-run action.
Definition: CbmPsdSimpleDigitizer.cxx:197
CbmPsdSimpleDigitizer.h
CbmPsdSimpleDigitizer::fNofEvents
Int_t fNofEvents
Definition: CbmPsdSimpleDigitizer.h:51
CbmDigitize< CbmPsdDigi >::SendData
void SendData(CbmPsdDigi *digi, CbmMatch *match=nullptr)
Send a digi and the corresponding match object to the DAQ.
Definition: CbmDigitize.h:219
CbmPsdSimpleDigitizer::Exec
virtual void Exec(Option_t *opt)
Definition: CbmPsdSimpleDigitizer.cxx:79
CbmPsdPoint::GetModuleID
Int_t GetModuleID() const
Definition: CbmPsdPoint.h:63
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
CbmPsdSimpleDigitizer::fTimeTot
Double_t fTimeTot
Definition: CbmPsdSimpleDigitizer.h:54
CbmPsdDigi
Data class for PSD digital information.
Definition: CbmPsdDigi.h:31
CbmDigitize< CbmPsdDigi >::RegisterOutput
void RegisterOutput()
Register the output arrays.
Definition: CbmDigitize.h:175
CbmPsdPoint.h