BmnRoot
Loading...
Searching...
No Matches
BmnSiBTDigitizer.cxx
Go to the documentation of this file.
1#include "BmnSiBTDigitizer.h"
2
3#include "BmnSiBTPoint.h"
4#include "CbmMCTrack.h"
5#include "FairRootManager.h"
6#include "TSystem.h"
7
8static Float_t workTime = 0.0;
9static int entrys = 0;
10
12 : fOnlyPrimary(kFALSE)
13 , fStripMatching(kTRUE)
14{
15
16 fInputBranchName = "SiBTPoint";
17 fOutputDigitsBranchName = "BmnSiBTDigit";
18 fOutputDigitMatchesBranchName = "BmnSiBTDigitMatch";
19
20 fVerbose = 1;
21
22 fCurrentConfig = BmnSiBTConfiguration::None;
23 StationSet = nullptr;
24 TransfSet = nullptr;
25 fBmnSiBTDigitsArray = nullptr;
26 fBmnSiBTDigitMatchesArray = nullptr;
27}
28
31{
32 switch (run_period) {
33 case 8: // BM@N RUN-8
34 fCurrentConfig = BmnSiBTConfiguration::Run8;
35 break;
36 case 9: // BM@N RUN-9
37 fCurrentConfig = BmnSiBTConfiguration::Run9;
38 break;
39
40 default:
41 fCurrentConfig = BmnSiBTConfiguration::None;
42 }
43}
44
46{
47 if (StationSet) {
48 delete StationSet;
49 }
50 if (TransfSet) {
51 delete TransfSet;
52 }
53 if (fBmnSiBTDigitsArray) {
54 fBmnSiBTDigitsArray->Delete();
55 delete fBmnSiBTDigitsArray;
56 }
57 if (fBmnSiBTDigitMatchesArray) {
58 fBmnSiBTDigitMatchesArray->Delete();
59 delete fBmnSiBTDigitMatchesArray;
60 }
61}
62
64{
65 if (fVerbose)
66 cout << "\nBmnSiBTDigitizer::Init()\n ";
67
68 if (fVerbose && fOnlyPrimary)
69 cout << " Only primary particles are processed!!! " << endl;
70
71 if (fVerbose && fStripMatching)
72 cout << " Strip Matching is activated!!! " << endl;
73 else
74 cout << " Strip Matching is deactivated!!! " << endl;
75
76 FairRootManager* ioman = FairRootManager::Instance();
77
78 fBmnSiBTPointsArray = (TClonesArray*)ioman->GetObject(fInputBranchName);
79 if (!fBmnSiBTPointsArray) {
80 cout << "BmnSiBTDigitizer::Init(): branch " << fInputBranchName << " not found! Task will be deactivated"
81 << endl;
82 SetActive(kFALSE);
83 return kERROR;
84 }
85
86 fMCTracksArray = (TClonesArray*)ioman->GetObject("MCTrack");
87
88 fBmnSiBTDigitsArray = new TClonesArray(fOutputDigitsBranchName);
89 ioman->Register(fOutputDigitsBranchName, "SiBT_DIGIT", fBmnSiBTDigitsArray, kTRUE);
90
91 if (fStripMatching) {
92 fBmnSiBTDigitMatchesArray = new TClonesArray("BmnMatch");
93 ioman->Register(fOutputDigitMatchesBranchName, "SiBT_DIGIT", fBmnSiBTDigitMatchesArray, kTRUE);
94 }
95
96 TString gPathSiBTConfig = gSystem->Getenv("VMCWORKDIR");
97 gPathSiBTConfig += "/parameters/SiBT/XMLConfigs/";
98
99 // Create SiBT detector ----------------------------------------------------
100 switch (fCurrentConfig) {
102 XMLConfigFile = gPathSiBTConfig + "SiBTRun8.xml";
103 if (fVerbose)
104 cout << " Current SiBT Configuration : Run8"
105 << "\n";
106 break;
107
109 XMLConfigFile = gPathSiBTConfig + "SiBTRun9.xml";
110 if (fVerbose)
111 cout << " Current SiBT Configuration : Run9"
112 << "\n";
113 break;
114
115 default:;
116 }
117
118 if (!gSystem->AccessPathName(XMLConfigFile)) { // returns FALSE if the file exists
119 if (fVerbose)
120 cout << " XMLConfigFile : " << XMLConfigFile << "\n";
121 StationSet = new BmnSiBTStationSet(XMLConfigFile);
122 TransfSet = new BmnSiBTTransform();
123 TransfSet->LoadFromXMLFile(XMLConfigFile);
124 } else {
125 Fatal("BmnSiBTDigitizer::Init()", " !!! Current configuration is not set !!! ");
126 }
127 //--------------------------------------------------------------------------
128
129 if (fVerbose)
130 cout << "BmnSiBTDigitizer::Init() finished\n\n";
131 return kSUCCESS;
132}
133
134void BmnSiBTDigitizer::Exec(Option_t* opt)
135{
136
137 if (!IsActive())
138 return;
139
140 clock_t tStart = clock();
141 fBmnSiBTDigitsArray->Delete();
142
143 if (fStripMatching) {
144 fBmnSiBTDigitMatchesArray->Delete();
145 }
146
147 if (!fBmnSiBTPointsArray) {
148 Error("BmnSiBTDigitizer::Exec()", " !!! Unknown branch name !!! ");
149 return;
150 }
151
152 if (fVerbose) {
153 // cout << " BmnSiBTDigitizer::Exec(), Number of BmnSiBTPoints = " << fBmnSiBTPointsArray->GetEntriesFast() <<
154 // "\n";
155 }
156
158
159 // if (fVerbose) cout << " BmnSiBTDigitizer::Exec() finished\n\n";
160 entrys++;
161 clock_t tFinish = clock();
162 workTime += ((Float_t)(tFinish - tStart)) / CLOCKS_PER_SEC;
163}
164
166{
167
168 FairMCPoint* SiBTPoint;
169 Int_t NNotPrimaries = 0;
170
171 for (Int_t ipoint = 0; ipoint < fBmnSiBTPointsArray->GetEntriesFast(); ipoint++) {
172 SiBTPoint = (FairMCPoint*)fBmnSiBTPointsArray->At(ipoint);
173
174 if (fOnlyPrimary) {
175 CbmMCTrack* track = (CbmMCTrack*)fMCTracksArray->UncheckedAt(SiBTPoint->GetTrackID());
176 if (!track)
177 continue;
178 if (track->GetMotherId() != -1) {
179 NNotPrimaries++;
180 continue;
181 }
182 }
183
184 Double_t x = -SiBTPoint->GetX(); // invert because in the current geometry +x is left, -x is right
185 Double_t y = SiBTPoint->GetY();
186 Double_t z = SiBTPoint->GetZ();
187
188 Double_t px = -SiBTPoint->GetPx(); // invert because in the current geometry +x is left, -x is right
189 Double_t py = SiBTPoint->GetPy();
190 Double_t pz = SiBTPoint->GetPz();
191
192 Double_t dEloss = SiBTPoint->GetEnergyLoss() * 1e6; // in keV
193 Int_t refId = ipoint;
194
195 // Information from MC-points
196 Int_t mc_station_num = ((BmnSiBTPoint*)SiBTPoint)->GetStation();
197 Int_t mc_module_num = ((BmnSiBTPoint*)SiBTPoint)->GetModule();
198
199 // test output
200 // cout << "mc_station_num = " << mc_station_num << "\n";
201 // cout << "mc_module_num = " << mc_module_num << "\n";
202
203 // Transform mc-point coordinates to local coordinate system of SiBT-planes
204 if (TransfSet && mc_station_num < StationSet->GetNStations()) {
205 if (mc_module_num < StationSet->GetStation(mc_station_num)->GetNModules()) {
206 Plane3D::Point loc_point =
207 TransfSet->ApplyInverseTransforms(Plane3D::Point(-x, y, z), mc_station_num, mc_module_num);
208 Plane3D::Point loc_direct = TransfSet->ApplyInverseTransforms(
209 Plane3D::Point(-(px + x), (py + y), (pz + z)), mc_station_num, mc_module_num);
210 x = -loc_point.X();
211 y = loc_point.Y();
212 z = loc_point.Z();
213
214 px = -(loc_direct.X() - loc_point.X());
215 py = loc_direct.Y() - loc_point.Y();
216 pz = loc_direct.Z() - loc_point.Z();
217 }
218 }
219
220 StationSet->AddPointToDetector(x, y, z, px, py, pz, dEloss, refId);
221 }
222
223 // Int_t NAddedPoints = StationSet->CountNAddedToDetectorPoints();
224 // if (fVerbose && fOnlyPrimary) cout << " Number of not primaries points : " << NNotPrimaries << "\n";
225 // if (fVerbose) cout << " Processed MC points : " << NAddedPoints << "\n";
226
227 for (Int_t iStation = 0; iStation < StationSet->GetNStations(); ++iStation) {
228 BmnSiBTStation* station = StationSet->GetStation(iStation);
229
230 for (Int_t iModule = 0; iModule < station->GetNModules(); ++iModule) {
231 BmnSiBTModule* module = station->GetModule(iModule);
232
233 for (Int_t iLayer = 0; iLayer < module->GetNStripLayers(); ++iLayer) {
234 BmnSiBTLayer layer = module->GetStripLayer(iLayer);
235
236 for (Int_t iStrip = 0; iStrip < layer.GetNStrips(); ++iStrip) {
237 Double_t signal = layer.GetStripSignal(iStrip);
238 if (signal > 0.0) {
239 new ((*fBmnSiBTDigitsArray)[fBmnSiBTDigitsArray->GetEntriesFast()])
240 BmnSiBTDigit(iStation, iModule, iLayer, iStrip, signal);
241
242 if (fStripMatching) {
243 new ((*fBmnSiBTDigitMatchesArray)[fBmnSiBTDigitMatchesArray->GetEntriesFast()])
244 BmnMatch(layer.GetStripMatch(iStrip));
245 }
246 }
247 }
248 }
249 }
250 }
251 StationSet->Reset();
252}
253
255{
256 if (StationSet) {
257 delete StationSet;
258 StationSet = nullptr;
259 }
260
261 if (TransfSet) {
262 delete TransfSet;
263 TransfSet = nullptr;
264 }
265
266 cout << "Work time of the SiBT digitizer: " << workTime << endl;
267}
virtual InitStatus Init()
virtual void Finish()
virtual void Exec(Option_t *opt)
Int_t GetNStrips()
Double_t GetStripSignal(Int_t strip_num)
BmnMatch GetStripMatch(Int_t strip_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)
BmnSiBTStation * GetStation(Int_t station_num)
Plane3D::Point ApplyInverseTransforms(Plane3D::Point point, Int_t station, Int_t module)
Bool_t LoadFromXMLFile(TString xml_config_file)
Int_t GetMotherId() const
Definition CbmMCTrack.h:57