CbmRoot
CbmPsdIdealDigitizer.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmPsdIdealDigitizer source file -----
3 // ----- Created 15/05/12 by Alla & SELIM & FLORIAN -----
4 // -------------------------------------------------------------------------
5 #include <iostream>
6 #include <map>
7 
8 #include "TClonesArray.h"
9 
10 #include "FairLogger.h"
11 #include "FairRootManager.h"
12 
13 #include "CbmPsdDigi.h"
14 #include "CbmPsdIdealDigitizer.h"
15 #include "CbmPsdPoint.h"
16 #include "TMath.h"
17 
18 using std::cout;
19 using std::endl;
20 using std::map;
21 using std::pair;
22 
23 
24 // ----- Default constructor -------------------------------------------
26  : FairTask("Ideal Psd Digitizer", 1)
27  , fNDigis(0)
28  , fPointArray(NULL)
29  , fDigiArray(NULL) {
30  // Reset();
31 }
32 // -------------------------------------------------------------------------
33 
34 
35 // ----- Destructor ----------------------------------------------------
37  if (fDigiArray) {
38  fDigiArray->Delete();
39  delete fDigiArray;
40  }
41 }
42 // -------------------------------------------------------------------------
43 
44 
45 // ----- Public method Init --------------------------------------------
47 
48  // Get RootManager
49  FairRootManager* ioman = FairRootManager::Instance();
50  if (!ioman) {
51  LOG(fatal)
52  << "CbmPsdIdealDigitizer::Init: RootManager not instantised!"; //FLORIAN
53  return kFATAL;
54  }
55 
56  // Get input array
57  fPointArray = (TClonesArray*) ioman->GetObject("PsdPoint");
58  if (!fPointArray) {
59  LOG(fatal) << "CbmPsdIdealDigitizer::Init: No PSDPoint array!"; //FLORIAN
60  return kERROR;
61  }
62 
63  // Create and register output array
64  fDigiArray = new TClonesArray("CbmPsdDigi", 1000);
65  ioman->Register(
66  "PsdDigi", "PSD", fDigiArray, IsOutputBranchPersistent("PsdDigi"));
67 
68  cout << "-I- CbmPsdIdealDigitizer: Intialisation successfull " << kSUCCESS
69  << endl;
70  return kSUCCESS;
71 }
72 
73 
74 // -------------------------------------------------------------------------
75 
76 
77 // ----- Public method Exec --------------------------------------------
78 void CbmPsdIdealDigitizer::Exec(Option_t* /*opt*/) {
79 
80  cout << " CbmPsdIdealDigitizer::Exec begin " << endl;
81  // Reset output array
82  if (!fDigiArray) Fatal("Exec", "No PsdDigi array");
83  Reset(); // SELIM: reset!!!
84 
85  // Declare some variables
86  CbmPsdPoint* point = NULL;
87  Int_t modID = -1; // module ID
88  Int_t scinID = -1; // #sciillator
89 
90  Double_t edep
91  [NB_PSD_SECT]
92  [NB_PSD_MODS]; //SELIM: 49 modules, including central & corner modules (rejected in analysis/flow/eventPlane.cxx)
93  memset(edep, 0, (NB_PSD_SECT * NB_PSD_MODS) * sizeof(Double_t));
94 
95  TVector3 pos; // Position vector
96  fNDigis = 0;
97 
98  //for (Int_t imod=0; imod<100; imod++) //SELIM: 49 modules, including central & corner modules (rejected in analysis/flow/eventPlane.cxx)
99  for (Int_t imod = 0; imod < NB_PSD_MODS; imod++) //marina
100  {
101  for (Int_t isec = 0; isec < NB_PSD_SECT; isec++) {
102  edep[isec][imod] = 0.;
103  }
104  }
105 
106  map<pair<int, int>, double> edepmap;
107 
108  // Loop over PsdPoints
109  Int_t nPoints = fPointArray->GetEntriesFast();
110  cout << " nPoints " << nPoints << endl;
111 
112  Int_t sec;
113 
114  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
115  point = (CbmPsdPoint*) fPointArray->At(iPoint);
116  if (!point) continue;
117 
118  // Detector ID
119  //modID = point->GetModuleID(); // !!!!! correction SELIM: scintID <-> modID !!!!!!
120  //scinID = point->GetDetectorID();
121  //edep[sec][modID] += point->GetEnergyLoss();
122 
123  modID = point->GetModuleID(); //marina 1-44 (45)
124  scinID = point->GetDetectorID(); //1-60
125 
126  //sec = (Int_t)((scinID-1)/6); //marina 0-9
127  sec = (Int_t)((scinID - 1) / 6) + 1; //marina 1-10
128 
129  auto insert_result = edepmap.insert(
130  std::make_pair(std::make_pair(modID, sec), point->GetEnergyLoss()));
131 
132  if (!insert_result.second) { // this entry has existed before
133  (*insert_result.first).second += point->GetEnergyLoss();
134  }
135 
136  //edep[sec-1][modID-1] += (Double_t) point->GetEnergyLoss();
137  //cout <<"MARINA modID,scinID " <<modID <<" " <<scinID <<" " <<sec <<endl;
138 
139  //if ( sec > modID_max) modID_max = sec;
140  //if ( sec < modID_min) modID_min = sec;
141  } // Loop over MCPoints
142 
143  //cout << "modID in: " << modID_min << ", " << modID_max << endl;
144 
145  //for (Int_t imod=1; imod<50; imod++) //SELIM: 49 modules, including central & corner modules (rejected in analysis/flow/eventPlane.cxx)
146 
147  /*
148  for (Int_t imod=0; imod<NB_PSD_MODS; imod++)//marina
149  {
150  for (Int_t isec=0; isec<NB_PSD_SECT; isec++)
151  {
152  //if (edep[isec][imod]<=0.) cout << "!! edep !! : " << edep[isec][imod] << endl;
153  if ( edep[isec][imod] <= 0. ) continue;
154  else {
155  new ((*fDigiArray)[fNDigis]) CbmPsdDigi(isec+1, imod+1, edep[isec][imod]);
156  fNDigis++;
157  //cout <<"MARINA CbmPsdIdealDigitizer " <<fNDigis <<" " <<isec+1 <<" " <<imod+1 <<" " <<edep[isec][imod] <<endl;
158  }
159  } // section
160  }//module
161  */
162 
163  fNDigis = 0;
164  for (auto edep_entry : edepmap) {
165  modID = edep_entry.first.first;
166  int secID = edep_entry.first.second;
167  double edep1 = edep_entry.second;
168  new ((*fDigiArray)[fNDigis]) CbmPsdDigi(secID, modID, edep1);
169  fNDigis++;
170  }
171 
172  // Event summary
173  cout << "-I- CbmPsdIdealDigitizer: " << fNDigis << " CbmPsdDigi created."
174  << endl;
175 }
176 // -------------------------------------------------------------------------
177 
178 // ----- Private method Reset ------------------------------------------
180  fNDigis = 0;
181  if (fDigiArray) fDigiArray->Delete();
182 }
183 
184 
CbmPsdIdealDigitizer
Definition: CbmPsdIdealDigitizer.h:26
CbmPsdIdealDigitizer::Exec
virtual void Exec(Option_t *opt)
Definition: CbmPsdIdealDigitizer.cxx:78
CbmPsdPoint
Definition: CbmPsdPoint.h:24
CbmPsdDigi.h
memset
void memset(T *dest, T i, size_t num)
Definition: L1Grid.cxx:21
CbmPsdIdealDigitizer::fNDigis
Int_t fNDigis
Definition: CbmPsdIdealDigitizer.h:46
CbmPsdIdealDigitizer::CbmPsdIdealDigitizer
CbmPsdIdealDigitizer()
Definition: CbmPsdIdealDigitizer.cxx:25
NB_PSD_MODS
const Int_t NB_PSD_MODS
Definition: CbmPsdIdealDigitizer.h:23
CbmPsdIdealDigitizer::fPointArray
TClonesArray * fPointArray
Definition: CbmPsdIdealDigitizer.h:49
CbmPsdIdealDigitizer::Init
virtual InitStatus Init()
Definition: CbmPsdIdealDigitizer.cxx:46
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmPsdIdealDigitizer::Reset
void Reset()
Definition: CbmPsdIdealDigitizer.cxx:179
CbmPsdPoint::GetModuleID
Int_t GetModuleID() const
Definition: CbmPsdPoint.h:63
CbmPsdIdealDigitizer::fDigiArray
TClonesArray * fDigiArray
Definition: CbmPsdIdealDigitizer.h:52
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
CbmPsdDigi
Data class for PSD digital information.
Definition: CbmPsdDigi.h:31
CbmPsdIdealDigitizer.h
CbmPsdIdealDigitizer::~CbmPsdIdealDigitizer
~CbmPsdIdealDigitizer()
Definition: CbmPsdIdealDigitizer.cxx:36
CbmPsdPoint.h
NB_PSD_SECT
const Int_t NB_PSD_SECT
Definition: CbmPsdIdealDigitizer.h:24