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