BmnRoot
Loading...
Searching...
No Matches
BmnGemStripDigitizer.cxx
Go to the documentation of this file.
2
3#include "CbmMCTrack.h"
4#include "CbmStsPoint.h"
5#include "FairRootManager.h"
6#include "TSystem.h"
7
8#include <TRandom.h> //AZ-240823
9
10static Float_t workTime = 0.0;
11static int entrys = 0;
12
14 : fOnlyPrimary(kFALSE)
15 , fStripMatching(kTRUE)
16 , fUseRealEffects(kFALSE)
17{
18
19 fInputBranchName = "StsPoint";
20 fOutputDigitsBranchName = "BmnGemStripDigit";
21 fOutputDigitMatchesBranchName = "BmnGemStripDigitMatch";
22
23 fVerbose = 1;
24
25 fCurrentConfig = BmnGemStripConfiguration::None;
26 StationSet = nullptr;
27 TransfSet = nullptr;
28 fField = nullptr;
29
30 fBmnGemStripDigitsArray = nullptr;
31 fBmnGemStripDigitMatchesArray = nullptr;
32
33 fSigma = -1; // AZ-240823
34 fThresh = 12; // AZ-240823 - initial value
35 SetName("GemDigitizer"); // AZ-110124
36}
37
40{
41 switch (run_period) {
42 case 6: // BM@N RUN-6
44 break;
45 case 7: // BM@N RUN-7
47 break;
48 case 8: // BM@N RUN-8
49 fCurrentConfig = BmnGemStripConfiguration::Run8;
50 break;
51 case 9: // BM@N RUN-9
52 fCurrentConfig = BmnGemStripConfiguration::Run9;
53 break;
54
55 default:
56 fCurrentConfig = BmnGemStripConfiguration::None;
57 }
58}
59
61{
62 if (StationSet)
63 delete StationSet;
64
65 if (TransfSet)
66 delete TransfSet;
67
68 if (fBmnGemStripDigitsArray) {
69 fBmnGemStripDigitsArray->Delete();
70 delete fBmnGemStripDigitsArray;
71 }
72 if (fBmnGemStripDigitMatchesArray) {
73 fBmnGemStripDigitMatchesArray->Delete();
74 delete fBmnGemStripDigitMatchesArray;
75 }
76}
77
79{
80
81 if (fVerbose)
82 cout << "\nBmnGemStripDigitizer::Init()\n ";
83
84 if (fVerbose && fOnlyPrimary)
85 cout << " Only primary particles are processed!!! " << endl;
86
87 if (fVerbose && fStripMatching)
88 cout << " Strip Matching is activated!!! " << endl;
89 else
90 cout << " Strip Matching is deactivated!!! " << endl;
91
92 FairRootManager* ioman = FairRootManager::Instance();
93
94 fBmnGemStripPointsArray = (TClonesArray*)ioman->GetObject(fInputBranchName);
95 if (!fBmnGemStripPointsArray) {
96 cout << "BmnGemStripDigitizer::Init(): branch StsPoint not found! Task "
97 "will be deactivated"
98 << endl;
99 SetActive(kFALSE);
100 return kERROR;
101 }
102
103 fMCTracksArray = (TClonesArray*)ioman->GetObject("MCTrack");
104
105 fBmnGemStripDigitsArray = new TClonesArray(fOutputDigitsBranchName);
106 ioman->Register(fOutputDigitsBranchName, "GEM_DIGIT", fBmnGemStripDigitsArray, kTRUE);
107
108 if (fStripMatching) {
109 fBmnGemStripDigitMatchesArray = new TClonesArray("BmnMatch");
110 ioman->Register(fOutputDigitMatchesBranchName, "GEM_DIGIT", fBmnGemStripDigitMatchesArray, kTRUE);
111 }
112
113 TString gPathGemConfig = gSystem->Getenv("VMCWORKDIR");
114 gPathGemConfig += "/parameters/gem/XMLConfigs/";
115
116 // Create GEM detector ------------------------------------------------------
117 switch (fCurrentConfig) {
119 XMLConfigFile = gPathGemConfig + "GemRunSpring2017.xml";
120 if (fVerbose)
121 cout << " Current GEM Configuration : RunSpring2017"
122 << "\n";
123 break;
124
126 XMLConfigFile = gPathGemConfig + "GemRunSpring2018.xml";
127 if (fVerbose)
128 cout << " Current GEM Configuration : RunSpring2018"
129 << "\n";
130 break;
131
133
134 XMLConfigFile = gPathGemConfig + "GemRunSRCSpring2018.xml";
135 if (fVerbose)
136 cout << " Current GEM Configuration : GemRunSRCSpring2018"
137 << "\n";
138 break;
139
141 XMLConfigFile = gPathGemConfig + "GemRunSRC2021.xml";
142 if (fVerbose)
143 cout << " Current GEM Configuration : RunSRC2021"
144 << "\n";
145 break;
146
148 XMLConfigFile = gPathGemConfig + "GemRun8.xml";
149 if (fVerbose)
150 cout << " Current GEM Configuration : Run8"
151 << "\n";
152 break;
153
155 XMLConfigFile = gPathGemConfig + "GemRun9.xml";
156 if (fVerbose)
157 cout << " Current GEM Configuration : Run9"
158 << "\n";
159 break;
160
161 default:;
162 }
163
164 if (!gSystem->AccessPathName(XMLConfigFile)) { // returns FALSE if the file exists
165 if (fVerbose)
166 cout << " XMLConfigFile : " << XMLConfigFile << "\n";
167 StationSet = new BmnGemStripStationSet(XMLConfigFile);
168 TransfSet = new BmnGemStripTransform();
169 TransfSet->LoadFromXMLFile(XMLConfigFile);
170 } else {
171 Fatal("BmnGemStripDigitizer::Init()", " !!! Current configuration is not set !!! ");
172 }
173
174 if (fUseRealEffects)
175 ;
176
177 //--------------------------------------------------------------------------
178
179 if (fVerbose)
180 cout << "BmnGemStripDigitizer::Init() finished\n\n";
181 return kSUCCESS;
182}
183
184void BmnGemStripDigitizer::Exec(Option_t* opt)
185{
186
187 if (!IsActive())
188 return;
189
190 clock_t tStart = clock();
191 fBmnGemStripDigitsArray->Delete();
192
193 if (fStripMatching)
194 fBmnGemStripDigitMatchesArray->Delete();
195
196 if (!fBmnGemStripPointsArray) {
197 Error("BmnGemStripDigitizer::Exec()", " !!! Unknown branch name !!! ");
198 return;
199 }
200
201 if (fVerbose) {
202 // cout << " BmnGemStripDigitizer::Exec(), Number of BmnGemStripPoints = "
203 // << fBmnGemStripPointsArray->GetEntriesFast() << "\n";
204 }
205
207
208 // if (fVerbose) cout << " BmnGemStripDigitizer::Exec() finished\n\n";
209 entrys++;
210 clock_t tFinish = clock();
211 workTime += ((Float_t)(tFinish - tStart)) / CLOCKS_PER_SEC;
212}
213
215{
216
217 FairMCPoint* GemStripPoint;
218 // Int_t NNotPrimaries = 0;
219
220 for (Int_t ipoint = 0; ipoint < fBmnGemStripPointsArray->GetEntriesFast(); ipoint++) {
221 GemStripPoint = (FairMCPoint*)fBmnGemStripPointsArray->At(ipoint);
222
223 if (fOnlyPrimary) {
224 CbmMCTrack* track = (CbmMCTrack*)fMCTracksArray->UncheckedAt(GemStripPoint->GetTrackID());
225 if (!track)
226 continue;
227 if (track->GetMotherId() != -1) {
228 // NNotPrimaries++;
229 continue;
230 }
231 }
232
233 Double_t x = -GemStripPoint->GetX(); // invert because in current geometry
234 // +x -left, -x - right
235 Double_t y = GemStripPoint->GetY();
236 Double_t z = GemStripPoint->GetZ();
237
238 Double_t px = -GemStripPoint->GetPx(); // invert because in current geometry
239 // +x -left, -x - right
240 Double_t py = GemStripPoint->GetPy();
241 Double_t pz = GemStripPoint->GetPz();
242
243 Double_t dEloss = GemStripPoint->GetEnergyLoss() * 1e6; // in keV
244 Int_t refId = ipoint;
245
246 Int_t mc_station_num = ((CbmStsPoint*)GemStripPoint)->GetStation();
247 Int_t mc_module_num = ((CbmStsPoint*)GemStripPoint)->GetModule();
248
249 // cout << "mc_station_num = " << mc_station_num << "\n";
250 // cout << "mc_module_num = " << mc_module_num << "\n";
251
252 // Transform mc-point coordinates to local coordinate system of GEM-planes
253 if (TransfSet && mc_station_num < StationSet->GetNStations()) {
254 BmnGemStripStation* station = StationSet->GetGemStation(mc_station_num);
255 if (mc_module_num < station->GetNModules()) {
256
257 Plane3D::Point loc_point =
258 TransfSet->ApplyInverseTransforms(Plane3D::Point(-x, y, z), mc_station_num, mc_module_num);
259 Plane3D::Point loc_direct = TransfSet->ApplyInverseTransforms(
260 Plane3D::Point(-(px + x), (py + y), (pz + z)), mc_station_num, mc_module_num);
261 x = -loc_point.X();
262 y = loc_point.Y();
263 z = loc_point.Z();
264
265 px = -(loc_direct.X() - loc_point.X());
266 py = loc_direct.Y() - loc_point.Y();
267 pz = loc_direct.Z() - loc_point.Z();
268 }
269 }
270 if (fUseRealEffects)
271 ;
272
273 // AZ-191223 - gain fluctuations
274 Double_t gain = 1;
275 // gain += gRandom->Gaus(0, 0.5);
276 if (gain < 0)
277 gain = 0;
278 dEloss *= gain;
279 //
280 StationSet->AddPointToDetector(x, y, z, px, py, pz, dEloss, refId);
281 }
282
283 /*Int_t NAddedPoints = */ StationSet->CountNAddedToDetectorPoints();
284 // if (fVerbose && fOnlyPrimary) cout << " Number of not primaries points :
285 // " << NNotPrimaries << "\n"; if (fVerbose) cout << " Processed MC points
286 // : " << NAddedPoints << "\n";
287
288 for (Int_t iStation = 0; iStation < StationSet->GetNStations(); ++iStation) {
289 BmnGemStripStation* station = StationSet->GetGemStation(iStation);
290
291 for (Int_t iModule = 0; iModule < station->GetNModules(); ++iModule) {
292 BmnGemStripModule* module = station->GetModule(iModule);
293
294 for (Int_t iLayer = 0; iLayer < module->GetNStripLayers(); ++iLayer) {
295 BmnGemStripLayer layer = module->GetStripLayer(iLayer);
296
297 for (Int_t iStrip = 0; iStrip < layer.GetNStrips(); ++iStrip) {
298 Double_t signal = layer.GetStripSignal(iStrip);
299 if (signal > 0.0) {
300 signal = signal / (120. / 2.0); // el to ADC
301 // AZ-110124 signal /= 2.5; //AZ-110923 - for beam data
302 signal /= 1.3; // AZ-110124
303 // AZ-130923 - gain fluctuations
304 Double_t gain = 1;
305 // AZ-191223 gain += gRandom->Gaus(0, 0.5);
306 if (gain < 0)
307 gain = 0;
308 signal *= gain;
309 // AZ-240823 if (signal <= 12) continue;
310 // AZ-240823
311 if (fSigma > 0) {
312 // Add noise
313 signal += gRandom->Gaus(0, fSigma);
314 }
315 if (signal <= fThresh)
316 continue;
317 // AZ
318 if (signal >= 2048)
319 signal = 2047;
320 new ((*fBmnGemStripDigitsArray)[fBmnGemStripDigitsArray->GetEntriesFast()])
321 BmnGemStripDigit(iStation, iModule, iLayer, iStrip, signal);
322
323 if (fStripMatching) {
324 new ((*fBmnGemStripDigitMatchesArray)[fBmnGemStripDigitMatchesArray->GetEntriesFast()])
325 BmnMatch(layer.GetStripMatch(iStrip));
326 }
327 } else if (fSigma > 0) {
328 // AZ-120923
329 signal += gRandom->Gaus(0, fSigma);
330 // AZ-161223 - gain fluctuations
331 /*
332 Double_t gain = 1;
333 gain += gRandom->Gaus(0, 0.5); //50%
334 if (gain < 0) gain = 0;
335 signal *= gain;
336 */
337 if (signal <= fThresh)
338 continue;
339 if (signal >= 2048)
340 signal = 2047;
341 new ((*fBmnGemStripDigitsArray)[fBmnGemStripDigitsArray->GetEntriesFast()])
342 BmnGemStripDigit(iStation, iModule, iLayer, iStrip, signal);
343 if (fStripMatching) {
344 new ((*fBmnGemStripDigitMatchesArray)[fBmnGemStripDigitMatchesArray->GetEntriesFast()])
345 BmnMatch(layer.GetStripMatch(iStrip));
346 }
347 }
348 }
349 }
350 }
351 }
352 StationSet->Reset();
353}
354
356{
357 if (StationSet) {
358 delete StationSet;
359 StationSet = nullptr;
360 }
361
362 if (TransfSet) {
363 delete TransfSet;
364 TransfSet = nullptr;
365 }
366
367 cout << "Work time of the GEM digitizer: " << workTime << endl;
368}
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
BmnMatch GetStripMatch(Int_t strip_num)
Double_t GetStripSignal(Int_t strip_num)
BmnGemStripStation * GetGemStation(Int_t station_num)
Bool_t AddPointToDetector(Double_t xcoord, Double_t ycoord, Double_t zcoord, Double_t px, Double_t py, Double_t pz, Double_t dEloss, Int_t refID)
Bool_t LoadFromXMLFile(TString xml_config_file)
Plane3D::Point ApplyInverseTransforms(Plane3D::Point point, Int_t station, Int_t module)
Int_t GetMotherId() const
Definition CbmMCTrack.h:57