BmnRoot
Loading...
Searching...
No Matches
BmnCSCDigitizer.cxx
Go to the documentation of this file.
1#include "BmnCSCDigitizer.h"
2
3#include "BmnCSCPoint.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 = "CSCPoint";
17 fOutputDigitsBranchName = "BmnCSCDigit";
18 fOutputDigitMatchesBranchName = "BmnCSCDigitMatch";
19
20 fVerbose = 1;
21
22 fCurrentConfig = BmnCSCConfiguration::None;
23 StationSet = nullptr;
24 TransfSet = nullptr;
25 fBmnCSCDigitsArray = nullptr;
26 fBmnCSCDigitMatchesArray = nullptr;
27}
28
31{
32 switch (run_period) {
33 case 7: // BM@N RUN-7
35 break;
36 case 8: // BM@N RUN-8
37 fCurrentConfig = BmnCSCConfiguration::FullCSC_Run8;
38 break;
39 case 9: // BM@N RUN-9
40 fCurrentConfig = BmnCSCConfiguration::Run9;
41 break;
42
43 default:
44 fCurrentConfig = BmnCSCConfiguration::None;
45 }
46}
47
49{
50 if (StationSet) {
51 delete StationSet;
52 }
53
54 if (TransfSet) {
55 delete TransfSet;
56 }
57 if (fBmnCSCDigitsArray) {
58 fBmnCSCDigitsArray->Delete();
59 delete fBmnCSCDigitsArray;
60 }
61 if (fBmnCSCDigitMatchesArray) {
62 fBmnCSCDigitMatchesArray->Delete();
63 delete fBmnCSCDigitMatchesArray;
64 }
65}
66
68{
69 if (fVerbose)
70 cout << "\nBmnCSCDigitizer::Init()\n ";
71
72 if (fVerbose && fOnlyPrimary)
73 cout << " Only primary particles are processed!!! " << endl;
74
75 if (fVerbose && fStripMatching)
76 cout << " Strip Matching is activated!!! " << endl;
77 else
78 cout << " Strip Matching is deactivated!!! " << endl;
79
80 FairRootManager* ioman = FairRootManager::Instance();
81
82 fBmnCSCPointsArray = (TClonesArray*)ioman->GetObject(fInputBranchName);
83 if (!fBmnCSCPointsArray) {
84 cout << "BmnCSCDigitizer::Init(): branch " << fInputBranchName << " not found! Task will be deactivated"
85 << endl;
86 SetActive(kFALSE);
87 return kERROR;
88 }
89
90 fMCTracksArray = (TClonesArray*)ioman->GetObject("MCTrack");
91
92 fBmnCSCDigitsArray = new TClonesArray(fOutputDigitsBranchName);
93 ioman->Register(fOutputDigitsBranchName, "CSC_DIGIT", fBmnCSCDigitsArray, kTRUE);
94
95 if (fStripMatching) {
96 fBmnCSCDigitMatchesArray = new TClonesArray("BmnMatch");
97 ioman->Register(fOutputDigitMatchesBranchName, "CSC_DIGIT", fBmnCSCDigitMatchesArray, kTRUE);
98 }
99
100 TString gPathCSCConfig = gSystem->Getenv("VMCWORKDIR");
101 gPathCSCConfig += "/parameters/csc/XMLConfigs/";
102
103 // Create CSC detector ------------------------------------------------------
104 switch (fCurrentConfig) {
106 XMLConfigFile = gPathCSCConfig + "CSCRunSpring2018.xml";
107 if (fVerbose)
108 cout << " Current CSC Configuration : RunSpring2018"
109 << "\n";
110 break;
111
113 XMLConfigFile = gPathCSCConfig + "CSCRunSRCSpring2018.xml";
114 if (fVerbose)
115 cout << " Current CSC Configuration : RunSRCSpring2018"
116 << "\n";
117 break;
118
120 XMLConfigFile = gPathCSCConfig + "CSCRun8.xml";
121 if (fVerbose)
122 cout << " Current CSC Configuration : Run8"
123 << "\n";
124 break;
125
127 XMLConfigFile = gPathCSCConfig + "CSCRunSRC2021.xml";
128 if (fVerbose)
129 cout << " Current CSC Configuration : RunSRC2021"
130 << "\n";
131 break;
132
134 XMLConfigFile = gPathCSCConfig + "LargeCSCRun8.xml";
135 if (fVerbose)
136 cout << " Current CSC Configuration : LargeCSCRun8"
137 << "\n";
138 break;
139
141 XMLConfigFile = gPathCSCConfig + "FullCSCRun8.xml";
142 if (fVerbose)
143 cout << " Current CSC Configuration : FullCSCRun8 (4 small + 1 large chambers)"
144 << "\n";
145 break;
146
148 XMLConfigFile = gPathCSCConfig + "CSCRun9.xml";
149 if (fVerbose)
150 cout << " Current CSC Configuration : Run9"
151 << "\n";
152
153 default:;
154 }
155 if (!gSystem->AccessPathName(XMLConfigFile)) { // returns FALSE if the file exists
156 if (fVerbose)
157 cout << " XMLConfigFile : " << XMLConfigFile << "\n";
158 StationSet = new BmnCSCStationSet(XMLConfigFile);
159 TransfSet = new BmnCSCTransform();
160 TransfSet->LoadFromXMLFile(XMLConfigFile);
161 } else {
162 Fatal("BmnCSCDigitizer::Init()", " !!! Current configuration is not set !!! ");
163 }
164 //--------------------------------------------------------------------------
165
166 if (fVerbose)
167 cout << "BmnCSCDigitizer::Init() finished\n\n";
168 return kSUCCESS;
169}
170
171void BmnCSCDigitizer::Exec(Option_t* opt)
172{
173
174 if (!IsActive())
175 return;
176
177 clock_t tStart = clock();
178 fBmnCSCDigitsArray->Delete();
179
180 if (fStripMatching) {
181 fBmnCSCDigitMatchesArray->Delete();
182 }
183
184 // if (!fBmnCSCPointsArray) {
185 // Error("BmnCSCDigitizer::Exec()", " !!! Unknown branch name !!! ");
186 // return;
187 // }
188
189 if (fVerbose) {
190 // cout << " BmnCSCDigitizer::Exec(), Number of BmnCSCPoints = " << fBmnCSCPointsArray->GetEntriesFast() <<
191 // "\n";
192 }
193
195
196 // if (fVerbose) cout << " BmnCSCDigitizer::Exec() finished\n\n";
197 entrys++;
198 clock_t tFinish = clock();
199 workTime += ((Float_t)(tFinish - tStart)) / CLOCKS_PER_SEC;
200}
201
203{
204
205 FairMCPoint* CSCPoint;
206 Int_t NNotPrimaries = 0;
207
208 for (Int_t ipoint = 0; ipoint < fBmnCSCPointsArray->GetEntriesFast(); ipoint++) {
209 CSCPoint = (FairMCPoint*)fBmnCSCPointsArray->At(ipoint);
210
211 if (fOnlyPrimary) {
212 CbmMCTrack* track = (CbmMCTrack*)fMCTracksArray->UncheckedAt(CSCPoint->GetTrackID());
213 if (!track)
214 continue;
215 if (track->GetMotherId() != -1) {
216 NNotPrimaries++;
217 continue;
218 }
219 }
220
221 Double_t x = -CSCPoint->GetX(); // invert because in the current geometry +x is left, -x is right
222 Double_t y = CSCPoint->GetY();
223 Double_t z = CSCPoint->GetZ();
224
225 Double_t px = -CSCPoint->GetPx(); // invert because in the current geometry +x is left, -x is right
226 Double_t py = CSCPoint->GetPy();
227 Double_t pz = CSCPoint->GetPz();
228
229 Double_t dEloss = CSCPoint->GetEnergyLoss() * 1e6; // in keV
230 Int_t refId = ipoint;
231
232 // Information from MC-points
233 Int_t mc_station_num = ((BmnCSCPoint*)CSCPoint)->GetStation();
234 Int_t mc_module_num = ((BmnCSCPoint*)CSCPoint)->GetModule();
235
236 // test output
237 // cout << "mc_station_num = " << mc_station_num << "\n";
238 // cout << "mc_module_num = " << mc_module_num << "\n";
239
240 // Transform mc-point coordinates to local coordinate system of CSC-planes
241 if (TransfSet && mc_station_num < StationSet->GetNStations()) {
242 if (mc_module_num < StationSet->GetStation(mc_station_num)->GetNModules()) {
243 Plane3D::Point loc_point =
244 TransfSet->ApplyInverseTransforms(Plane3D::Point(-x, y, z), mc_station_num, mc_module_num);
245 Plane3D::Point loc_direct = TransfSet->ApplyInverseTransforms(
246 Plane3D::Point(-(px + x), (py + y), (pz + z)), mc_station_num, mc_module_num);
247 x = -loc_point.X();
248 y = loc_point.Y();
249 z = loc_point.Z();
250
251 px = -(loc_direct.X() - loc_point.X());
252 py = loc_direct.Y() - loc_point.Y();
253 pz = loc_direct.Z() - loc_point.Z();
254 }
255 }
256
257 StationSet->AddPointToDetector(x, y, z, px, py, pz, dEloss, refId);
258 }
259
260 // Int_t NAddedPoints = StationSet->CountNAddedToDetectorPoints();
261 // if (fVerbose && fOnlyPrimary) cout << " Number of not primaries points : " << NNotPrimaries << "\n";
262 // if (fVerbose) cout << " Processed MC points : " << NAddedPoints << "\n";
263
264 for (Int_t iStation = 0; iStation < StationSet->GetNStations(); ++iStation) {
265 BmnCSCStation* station = StationSet->GetStation(iStation);
266
267 for (Int_t iModule = 0; iModule < station->GetNModules(); ++iModule) {
268 BmnCSCModule* module = station->GetModule(iModule);
269
270 for (Int_t iLayer = 0; iLayer < module->GetNStripLayers(); ++iLayer) {
271 BmnCSCLayer layer = module->GetStripLayer(iLayer);
272
273 for (Int_t iStrip = 0; iStrip < layer.GetNStrips(); ++iStrip) {
274 Double_t signal = layer.GetStripSignal(iStrip);
275 if (signal > 0.0) {
276 new ((*fBmnCSCDigitsArray)[fBmnCSCDigitsArray->GetEntriesFast()])
277 BmnCSCDigit(iStation, iModule, iLayer, iStrip, signal);
278
279 if (fStripMatching) {
280 new ((*fBmnCSCDigitMatchesArray)[fBmnCSCDigitMatchesArray->GetEntriesFast()])
281 BmnMatch(layer.GetStripMatch(iStrip));
282 }
283 }
284 }
285 }
286 }
287 }
288 StationSet->Reset();
289}
290
292{
293 if (StationSet) {
294 delete StationSet;
295 StationSet = nullptr;
296 }
297
298 if (TransfSet) {
299 delete TransfSet;
300 TransfSet = nullptr;
301 }
302
303 cout << "Work time of the CSC digitizer: " << workTime << endl;
304}
virtual void Finish()
virtual InitStatus Init()
virtual ~BmnCSCDigitizer()
virtual void Exec(Option_t *opt)
Int_t GetNStrips()
Double_t GetStripSignal(Int_t strip_num)
BmnMatch GetStripMatch(Int_t strip_num)
BmnCSCStation * 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)
Int_t GetNModules()
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