EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmMCEpoch.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmMCEpoch.cxx
1 
9 #include "CbmMCEpoch.h"
10 
11 #include <iostream>
12 
13 #include "FairLogger.h"
14 
15 #include "TClonesArray.h"
16 
17 using namespace std;
18 
19 
20 // ----- Default constructor -------------------------------------------
22  : TNamed("MCEpoch", "MCEpoch"),
23  fStartTime(0.),
24  fEpochLength(0.),
25  fPoints()
26 {
27  CreateArrays();
28 }
29 // ---------------------------------------------------------------------------
30 
31 
32 
33 // ----- Standard constructor ------------------------------------------
34 CbmMCEpoch::CbmMCEpoch(Double_t startTime,
35  Double_t epochLength)
36  : TNamed("MCEpoch", "MCEpoch"),
37  fStartTime(startTime),
38  fEpochLength(epochLength),
39  fPoints()
40 {
41  CreateArrays();
42 }
43 // ---------------------------------------------------------------------------
44 
45 
46 
47 // ----- Destructor ------------------------------------------------------
49 }
50 // ---------------------------------------------------------------------------
51 
52 
53 
54 // ----- Add a MCPoint to the epoch --------------------------------------
56  Int_t eventId, Double_t eventTime) {
57 
58  switch (det) {
59 #if _OFF_
60  case kSTS: {
61  CbmStsPoint* stsPoint = (CbmStsPoint*) point;
62  new ((*(fPoints[det]))[GetNofPoints(det)]) CbmStsPoint(*stsPoint,
63  eventId,
64  eventTime,
65  fStartTime);
66  }
67  break;
68 
69  case kMUCH: {
70  CbmMuchPoint* muchPoint = (CbmMuchPoint*) point;
71  new ((*(fPoints[det]))[GetNofPoints(det)]) CbmMuchPoint(*muchPoint,
72  eventId,
73  eventTime,
74  fStartTime);
75  }
76  break;
77 #endif
78  default:
79  LOG(FATAL) << "The functionality is not yet implemented for the detector with id " << det << FairLogger::endl;
80 
81  }
82 
83 }
84 // ---------------------------------------------------------------------------
85 
86 
87 
88 // ----- Clear epoch -----------------------------------------------------
90 
91  /* Note: The loop over the detetcor id works only if the corresponding
92  * enum is continuous. Did not find a better solution yet. V.F. */
93 
94  fStartTime = 0.;
95  for (Int_t iDet=kREF; iDet<kTutDet; iDet++) {
96  DetectorId det = DetectorId(iDet);
97  if ( fPoints[det] ) fPoints[det]->Clear("C");
98  }
99 
100 }
101 // ---------------------------------------------------------------------------
102 
103 
104 
105 // ----- Get number of points in epoch -----------------------------------
107 
108  if ( ! fPoints[det] ) {
109  cout << "-W- " << GetName() << "::GetNofPoints: "
110  << "No array for detector system " << det << endl;
111  return 0;
112  }
113 
114  return fPoints[det]->GetEntriesFast();
115 
116 }
117 // ---------------------------------------------------------------------------
118 
119 
120 
121 // ----- Get a MCPoint from the array ------------------------------------
123 
124  if ( ! fPoints[det] ) {
125  cout << "-W- " << GetName() << "::GetPoint: "
126  << "No array for detector system " << det << endl;
127  return NULL;
128  }
129 
130  if ( index < 0 || index >= GetNofPoints(det) ) {
131  cout << "-W- " << GetName() << "::GetPoint: Index " << index
132  << "out of range for system " << det << endl;
133  return NULL;
134  }
135 
136  return ( (FairMCPoint*) fPoints[det]->At(index) );
137 
138 }
139 // ---------------------------------------------------------------------------
140 
141 
142 
143 
144 // ----- Check for empty epoch -------------------------------------------
146 
147  Int_t nTotal = 0;
148 
149  for (Int_t iDet=kREF; iDet<kTutDet; iDet++) {
150  DetectorId det = DetectorId(iDet);
151  if ( fPoints[iDet] ) nTotal += GetNofPoints(det);
152  }
153 
154  if (nTotal) return kFALSE;
155  return kTRUE;
156 
157 }
158 // ---------------------------------------------------------------------------
159 
160 
161 
162 // ----- Print epoch info ------------------------------------------------
163 void CbmMCEpoch::Print(Option_t* opt) const {
164 
165  cout << "-I- " << GetName() << " Start time " << fStartTime << ", Points: ";
166  TString sysName;
167  for (Int_t iDet = kREF; iDet<kTutDet; iDet++) {
168  DetectorId det = DetectorId(iDet);
169  if ( fPoints[iDet] ) {
171  cout << sysName << " " << GetNofPoints(det) << " ";
172  }
173  }
174  cout << endl;
175 
176 }
177 // ---------------------------------------------------------------------------
178 
179 
180 
181 // ----- Create MCPoint arrays -------------------------------------------
183 
184  for (Int_t iDet=kREF; iDet<kTutDet; iDet++) {
185  DetectorId det = DetectorId(iDet);
186  switch(det) {
187 #if _OFF_
188  case kSTS: fPoints[det] = new TClonesArray("CbmStsPoint", 1000); break;
189  case kMUCH: fPoints[det] = new TClonesArray("CbmMuchPoint", 1000); break;
190 #endif
191  default: fPoints[det] = NULL; break;
192  }
193  }
194 
195 }
196 // ---------------------------------------------------------------------------
197 
198 
200