BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnVSPDigitizer.cxx
Go to the documentation of this file.
1#include "BmnVSPDigitizer.h"
2
3#include "BmnVSPPoint.h"
4#include "CbmMCTrack.h"
5#include "FairRootManager.h"
6#include "TSystem.h"
7
8#include <TRandom.h> // AZ-010725
9
10static Float_t workTime = 0.0;
11static int entries = 0;
12
17 , fSigma(-1)
18 , fThresh(12)
19{ // AZ-010725
20
21 fInputBranchName = "VSPPoint";
22 fOutputDigitsBranchName = "BmnVSPDigit";
23 fOutputDigitMatchesBranchName = "BmnVSPDigitMatch";
24
25 fVerbose = 1;
26
28 StationSet = nullptr;
29 fField = nullptr;
30 GlobalModTransfSet = nullptr;
31}
32
35{
36 switch (run_period) {
37 case 9: // BM@N RUN-9
39 break;
40
41 default:
43 }
44}
45
47{
48 if (StationSet) {
49 delete StationSet;
50 }
51
53 delete GlobalModTransfSet;
54 }
55}
56
58{
59
60 if (fVerbose)
61 cout << "\nBmnVSPDigitizer::Init()\n ";
62
63 if (fVerbose && fOnlyPrimary)
64 cout << " Only primary particles are processed!!! " << endl;
65
66 if (fVerbose && fStripMatching)
67 cout << " Strip Matching is activated!!! " << endl;
68 else
69 cout << " Strip matching is deactivated!!! " << endl;
70
71 FairRootManager* ioman = FairRootManager::Instance();
72
74 if (!fBmnVSPPointsArray) {
75 cout << "BmnVSPDigitizer::Init(): branch VSPPoint not found! Task "
76 "will be deactivated"
77 << endl;
78 SetActive(kFALSE);
79 return kERROR;
80 }
81
82 fMCTracksArray = (TClonesArray*)ioman->GetObject("MCTrack");
83
85 ioman->Register(fOutputDigitsBranchName, "VSP", fBmnVSPDigitsArray, kTRUE);
86
87 if (fStripMatching) {
88 fBmnVSPDigitMatchesArray = new TClonesArray("BmnMatch");
90 }
91
92 TString gPathVSPConfig = gSystem->Getenv("VMCWORKDIR");
93 gPathVSPConfig += "/parameters/vsp/XMLConfigs/";
94
95 // Create VSP detector -----------------------------------------------------
96 switch (fCurrentConfig) {
98 XMLConfigFile = gPathVSPConfig + "VSP_Run9.xml";
99 if (fVerbose)
100 cout << " Current SILICON Configuration : Run9"
101 << "\n";
102 break;
103
104 default:;
105 }
106
107 if (!gSystem->AccessPathName(XMLConfigFile)) { // returns FALSE if the file exists
108 if (fVerbose)
109 cout << " XMLConfigFile : " << XMLConfigFile << "\n";
112 GlobalModTransfSet->LoadFromXMLFile(XMLConfigFile);
113 } else {
114 Fatal("BmnVSPDigitizer::Init()", " !!! Current configuration is not set !!! ");
115 }
116 //--------------------------------------------------------------------------
117
118 if (fVerbose)
119 cout << "BmnVSPDigitizer::Init() finished\n\n";
120 return kSUCCESS;
121}
122
124{
125 clock_t tStart = clock();
126 fBmnVSPDigitsArray->Delete();
127
128 if (fStripMatching) {
129 fBmnVSPDigitMatchesArray->Delete();
130 }
131
132 if (!fBmnVSPPointsArray) {
133 Error("BmnVSPDigitizer::Exec()", " !!! Unknown branch name !!! ");
134 return;
135 }
136
137 if (fVerbose) {
138 cout << " BmnVSPDigitizer::Exec(), Number of BmnVSPPoints = " << fBmnVSPPointsArray->GetEntriesFast() << "\n";
139 }
140
142
143 if (fVerbose)
144 cout << " BmnVSPDigitizer::Exec() finished\n\n";
145 entries++;
146 clock_t tFinish = clock();
147 workTime += ((Float_t)(tFinish - tStart)) / CLOCKS_PER_SEC;
148}
149
151{
152
153 FairMCPoint* VSPPoint;
154 Int_t NNotPrimaries = 0;
155
156 for (Int_t ipoint = 0; ipoint < fBmnVSPPointsArray->GetEntriesFast(); ipoint++) {
157 VSPPoint = (FairMCPoint*)fBmnVSPPointsArray->At(ipoint);
158
159 if (fOnlyPrimary) {
160 CbmMCTrack* track = (CbmMCTrack*)fMCTracksArray->UncheckedAt(VSPPoint->GetTrackID());
161 if (!track)
162 continue;
163 if (track->GetMotherId() != -1) {
164 NNotPrimaries++;
165 continue;
166 }
167 }
168
169 Double_t x = -VSPPoint->GetX(); // invert because in current geometry +x is left, -x is right
170 Double_t y = VSPPoint->GetY();
171 Double_t z = VSPPoint->GetZ();
172
173 Double_t px = -VSPPoint->GetPx(); // invert because in current geometry +x is left, -x is right
174 Double_t py = VSPPoint->GetPy();
175 Double_t pz = VSPPoint->GetPz();
176
177 Double_t dEloss = VSPPoint->GetEnergyLoss() * 1e6; // in keV
178 Int_t refId = ipoint;
179
180 // Information from MC-points
181 Int_t mc_station_num = ((BmnVSPPoint*)VSPPoint)->GetStation();
182 Int_t mc_module_num = ((BmnVSPPoint*)VSPPoint)->GetModule();
183
184 // test output
185 // cout << "mc_station_num = " << mc_station_num << "\n";
186 // cout << "mc_module_num = " << mc_module_num << "\n";
187
188 // Apply inverse global module transforms to MC-point (in right-handed system)
189 if (GlobalModTransfSet && mc_station_num < StationSet->GetNStations()) {
190 if (mc_module_num < StationSet->GetStation(mc_station_num)->GetNModules()) {
191 Plane3D::Point point_transformed =
192 GlobalModTransfSet->ApplyInverseTransforms(Plane3D::Point(-x, y, z), mc_station_num, mc_module_num);
193 Plane3D::Point direction_transformed = GlobalModTransfSet->ApplyInverseTransforms(
194 Plane3D::Point(-(px + x), (py + y), (pz + z)), mc_station_num, mc_module_num);
195 x = -point_transformed.X(); // convert to detector system (x-inverted)
196 y = point_transformed.Y();
197 z = point_transformed.Z();
198
199 px = -(direction_transformed.X() - point_transformed.X()); // convert to detector system (x-inverted)
200 py = direction_transformed.Y() - point_transformed.Y();
201 pz = direction_transformed.Z() - point_transformed.Z();
202 }
203 }
204
205 // AZ-010725 - gain fluctuations
206 Double_t gain = 1;
207 // gain += gRandom->Gaus(0, 0.5);
208 if (gain < 0)
209 gain = 0;
210 dEloss *= gain;
211 //
212 StationSet->AddPointToDetector(x, y, z, px, py, pz, dEloss, refId);
213 }
214
215 Int_t NAddedPoints = StationSet->CountNAddedToDetectorPoints();
216 if (fVerbose && fOnlyPrimary)
217 cout << " Number of not primaries points : " << NNotPrimaries << "\n";
218 if (fVerbose)
219 cout << " Processed MC points : " << NAddedPoints << "\n";
220
221 for (Int_t iStation = 0; iStation < StationSet->GetNStations(); ++iStation) {
222 BmnVSPStation* station = StationSet->GetVSPStation(iStation);
223
224 for (Int_t iModule = 0; iModule < station->GetNModules(); ++iModule) {
225 BmnVSPModule* module = station->GetModule(iModule);
226 vector<Int_t> processed_zones;
227
228 for (Int_t iLayer = 0; iLayer < module->GetNStripLayers(); ++iLayer) {
229 BmnVSPLayer layer = module->GetStripLayer(iLayer);
230
231 Int_t zone_id = layer.GetZoneID();
232
233 Bool_t is_processed_zone = false;
234 for (size_t iz = 0; iz < processed_zones.size(); ++iz) {
235 if (zone_id == processed_zones[iz])
236 is_processed_zone = true;
237 }
238
239 if (!is_processed_zone) {
240 Int_t first_strip_in_zone = module->GetFirstStripInZone(zone_id);
241 Int_t last_strip_in_zone = module->GetLastStripInZone(zone_id);
242 map<int, int> noiseMap; // AZ-010725 - add noise to strips (including left neighbour
243
244 for (Int_t iStrip = first_strip_in_zone; iStrip < last_strip_in_zone + 1; ++iStrip) {
245 Double_t signal = module->GetStripSignalInZone(zone_id, iStrip);
246
247 if (signal > 0.0) {
248 signal = signal / (120. / 500.0); // el to ADC
249 signal *= 1.17; // AZ-110923 - for beam data
250 // AZ-130923 - gain fluctuations
251 //*
252 Double_t gain = 1;
253 // AZ-191223 gain += gRandom->Gaus(0, 0.5);
254 if (gain < 0)
255 gain = 0;
256 signal *= gain;
257 // AZ-240823 if (signal <= 12) continue;
258 // AZ-240823--->
259 if (fSigma > 0) {
260 // Add noise
261 signal += gRandom->Gaus(0, fSigma);
262 }
263 // AZ-130923 - gain fluctuations
264 /*
265 Double_t gain = 1;
266 //AZ-161223 gain += gRandom->Gaus(0, 0.2); //20%
267 gain += gRandom->Gaus(0, 0.5); //50%
268 if (gain < 0) gain = 0;
269 signal *= gain;
270 */
271 noiseMap[iStrip] = 1; // noise flag
272 if (signal <= fThresh)
273 continue;
274 if (signal >= 2048)
275 signal = 2047;
276 // <--- AZ
277
278 new ((*fBmnVSPDigitsArray)[fBmnVSPDigitsArray->GetEntriesFast()]) BmnVSPDigit(
279 iStation, iModule, zone_id, iStrip, signal); // zone_id == layer_num !!!!!!
280
281 if (fStripMatching) {
282 new ((*fBmnVSPDigitMatchesArray)[fBmnVSPDigitMatchesArray->GetEntriesFast()])
283 BmnMatch(module->GetStripMatchInZone(zone_id, iStrip));
284 }
285 } else if (fSigma > 0) { // AZ-010725
286 signal += gRandom->Gaus(0, fSigma);
287 // AZ-130923 - gain fluctuations
288 /*
289 Double_t gain = 1;
290 //AZ-161223 gain += gRandom->Gaus(0, 0.2);
291 gain += gRandom->Gaus(0, 0.5); //50%
292 if (gain < 0) gain = 0;
293 signal *= gain;
294 */
295 if (signal <= fThresh)
296 continue;
297 if (signal >= 2048)
298 signal = 2047;
299 new ((*fBmnVSPDigitsArray)[fBmnVSPDigitsArray->GetEntriesFast()]) BmnVSPDigit(
300 iStation, iModule, zone_id, iStrip, signal); // zone_id == layer_num !!!!!!
301
302 if (fStripMatching) {
303 new ((*fBmnVSPDigitMatchesArray)[fBmnVSPDigitMatchesArray->GetEntriesFast()])
304 BmnMatch(module->GetStripMatchInZone(zone_id, iStrip));
305 }
306 } // else if (fSigma > 0)
307 }
308 processed_zones.push_back(zone_id);
309 }
310 }
311 }
312 }
313
314 StationSet->Reset();
315}
316
318{
319 if (StationSet) {
320 delete StationSet;
321 StationSet = nullptr;
322 }
323
324 if (GlobalModTransfSet) {
325 delete GlobalModTransfSet;
326 GlobalModTransfSet = nullptr;
327 }
328
329 cout << "Work time of the VSP digitizer: " << workTime << endl;
330}
static int entries
bool Bool_t
int Int_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Error(const char *location, const char *msgfmt,...)
void Fatal(const char *location, const char *msgfmt,...)
R__EXTERN TRandom * gRandom
R__EXTERN TSystem * gSystem
TClonesArray * fMCTracksArray
Input array of MC Tracks.
FairField * fField
TClonesArray * fBmnVSPDigitMatchesArray
Output array of VSP Digit Matches.
TString fOutputDigitMatchesBranchName
TString fOutputDigitsBranchName
virtual ~BmnVSPDigitizer()
BmnVSPConfiguration::VSP_CONFIG fCurrentConfig
virtual void Finish()
virtual InitStatus Init()
TClonesArray * fBmnVSPPointsArray
Input array of VSP Points.
TClonesArray * fBmnVSPDigitsArray
Output array of VSP Digits.
virtual void Exec(Option_t *opt)
BmnVSPTransform * GlobalModTransfSet
BmnVSPStationSet * StationSet
Int_t GetZoneID()
Definition BmnVSPLayer.h:46
BmnMatch GetStripMatchInZone(Int_t zone_id, Int_t strip_num)
Int_t GetNStripLayers()
Int_t GetNModules()
BmnVSPModule * GetModule(Int_t module_num)
CbmMCTrack.h.
Definition CbmMCTrack.h:26
Int_t GetMotherId() const
Definition CbmMCTrack.h:57
PositionVector3D< Cartesian3D< T >, DefaultCoordinateSystemTag > Point