BmnRoot
Loading...
Searching...
No Matches
BmnSiBTHitMaker.cxx
Go to the documentation of this file.
1#include "BmnSiBTHitMaker.h"
2
3#include "BmnEventHeader.h"
4#include "FairRunAna.h"
5#include "TSystem.h"
6
7#include <TChain.h>
8#include <TRandom.h>
9#include <TStopwatch.h>
10#include <zlib.h>
11
12static Double_t workTime = 0.0;
13
15 : fHitMatching(kTRUE)
16{
17
18 fInputPointsBranchName = "SiBTPoint";
19 fInputDigitsBranchName = "BmnSiBTDigit";
20 fInputDigitMatchesBranchName = "BmnSiBTDigitMatch";
21
22 fOutputHitsBranchName = "BmnSiBTHit";
23 fOutputHitMatchesBranchName = "BmnSiBTHitMatch";
24
25 fVerbose = 1;
26 fField = NULL;
27
28 fCurrentConfig = BmnSiBTConfiguration::None;
29 StationSet = nullptr;
30 TransfSet = nullptr;
31}
32
33BmnSiBTHitMaker::BmnSiBTHitMaker(Int_t run_period, Int_t run_number, Bool_t isExp, TString alignFile)
34 : fHitMatching(kTRUE)
35{
36
37 fInputPointsBranchName = "SiBTPoint";
38 fInputDigitsBranchName = (!isExp) ? "BmnSiBTDigit" : "SiBT";
39 fIsExp = isExp;
40
41 fInputDigitMatchesBranchName = "BmnSiBTDigitMatch";
42
43 fOutputHitsBranchName = "BmnSiBTHit";
44 fOutputHitMatchesBranchName = "BmnSiBTHitMatch";
45
46 fBmnEvQualityBranchName = "BmnEventQuality";
47
48 fVerbose = 1;
49 fField = NULL;
50
51 fCurrentConfig = BmnSiBTConfiguration::None;
52 StationSet = nullptr;
53 TransfSet = nullptr;
54
55 switch (run_period) {
56 case 8: // BM@N RUN-8
57 fCurrentConfig = BmnSiBTConfiguration::Run8;
58 break;
59 case 9: // BM@N RUN-9
60 fCurrentConfig = BmnSiBTConfiguration::Run9;
61 break;
62
63 default:
64 fCurrentConfig = BmnSiBTConfiguration::None;
65 }
66}
67
69{
70 if (StationSet) {
71 delete StationSet;
72 }
73
74 if (TransfSet) {
75 delete TransfSet;
76 }
77}
78
79void BmnSiBTHitMaker::LoadDetectorConfiguration()
80{
81 TString gPathSiBTConfig = gSystem->Getenv("VMCWORKDIR");
82 gPathSiBTConfig += "/parameters/SiBT/XMLConfigs/";
83
84 switch (fCurrentConfig) {
86 XMLConfigFile = gPathSiBTConfig + "SiBTRun8.xml";
87 if (fVerbose)
88 cout << " Current SiBT Configuration : Run8"
89 << "\n";
90 break;
91
93 XMLConfigFile = gPathSiBTConfig + "SiBTRun9.xml";
94 if (fVerbose)
95 cout << " Current SiBT Configuration : Run9"
96 << "\n";
97 break;
98
99 default:;
100 }
101
102 if (!gSystem->AccessPathName(XMLConfigFile)) { // returns FALSE if the file exists
103 if (fVerbose)
104 cout << " XMLConfigFile : " << XMLConfigFile << "\n";
105 StationSet = new BmnSiBTStationSet(XMLConfigFile);
106 TransfSet = new BmnSiBTTransform();
107 TransfSet->LoadFromXMLFile(XMLConfigFile);
108 } else {
109 Fatal("BmnSiBTHitMaker::LoadDetectorConfiguration()", " !!! Current configuration is not set !!! ");
110 }
111}
112
114{
115
116 if (fVerbose > 1)
117 cout << "=================== BmnSiBTHitMaker::Init() started ====================" << endl;
118
119 FairRootManager* ioman = FairRootManager::Instance();
120
121 fBmnSiBTDigitsArray = (TClonesArray*)ioman->GetObject(fInputDigitsBranchName);
122 if (!fBmnSiBTDigitsArray) {
123 cout << "BmnSiBTHitMaker::Init(): branch " << fInputDigitsBranchName << " not found! Task will be deactivated"
124 << endl;
125 SetActive(kFALSE);
126 return kERROR;
127 }
128
129 fBmnSiBTDigitMatchesArray = (TClonesArray*)ioman->GetObject(fInputDigitMatchesBranchName);
130
131 if (fVerbose > 1) {
132 if (fBmnSiBTDigitMatchesArray)
133 cout << " Strip matching information exists!\n";
134 else
135 cout << " Strip matching information doesn`t exist!\n";
136 }
137
138 fBmnSiBTHitsArray = new TClonesArray(fOutputHitsBranchName);
139 ioman->Register(fOutputHitsBranchName, "SiBT", fBmnSiBTHitsArray, kTRUE);
140
141 if (fHitMatching && fBmnSiBTDigitMatchesArray) {
142 fBmnSiBTHitMatchesArray = new TClonesArray("BmnMatch");
143 ioman->Register(fOutputHitMatchesBranchName, "SiBT", fBmnSiBTHitMatchesArray, kTRUE);
144 } else {
145 fBmnSiBTHitMatchesArray = 0;
146 }
147
148 // Create SiBT detector ------------------------------------------------------
149 LoadDetectorConfiguration();
150
151 fField = FairRunAna::Instance()->GetField();
152 if (!fField)
153 Fatal("Init", "No Magnetic Field found");
154
155 //--------------------------------------------------------------------------
156
157 fBmnEvQuality = (TClonesArray*)ioman->GetObject(fBmnEvQualityBranchName);
158
159 if (fVerbose > 1)
160 cout << "=================== BmnSiBTHitMaker::Init() finished ===================" << endl;
161
162 return kSUCCESS;
163}
164
165void BmnSiBTHitMaker::Exec(Option_t* opt)
166{
167
168 TStopwatch sw;
169 sw.Start();
170
171 if (!IsActive())
172 return;
173
174 // Event separation by triggers ...
175 if (fIsExp && fBmnEvQuality) {
176 BmnEventQuality* evQual = (BmnEventQuality*)fBmnEvQuality->UncheckedAt(0);
177 if (!evQual->GetIsGoodEvent())
178 return;
179 }
180 fBmnSiBTHitsArray->Delete();
181
182 if (fHitMatching && fBmnSiBTHitMatchesArray) {
183 fBmnSiBTHitMatchesArray->Delete();
184 }
185
186 if (fVerbose > 1)
187 cout << "=================== BmnSiBTHitMaker::Exec() started ====================" << endl;
188
189 fField = FairRunAna::Instance()->GetField();
190
191 if (fVerbose > 1)
192 cout << " BmnSiBTHitMaker::Exec(), Number of BmnSiBTDigits = " << fBmnSiBTDigitsArray->GetEntriesFast() << "\n";
193
195
196 if (fVerbose > 1)
197 cout << "=================== BmnSiBTHitMaker::Exec() finished ===================" << endl;
198
199 sw.Stop();
200 workTime += sw.RealTime();
201}
202
204{
205
206 // FairMCPoint* MCPoint;
207 BmnSiBTDigit* digit;
208 BmnMatch* strip_match;
209
210 BmnSiBTStation* station;
211 BmnSiBTModule* module;
212
213 // Loading digits ---------------------------------------------------------------
214 Int_t AddedDigits = 0;
215 Int_t AddedStripDigitMatches = 0;
216
217 for (Int_t idigit = 0; idigit < fBmnSiBTDigitsArray->GetEntriesFast(); idigit++) {
218 digit = (BmnSiBTDigit*)fBmnSiBTDigitsArray->At(idigit);
219 if (!digit->IsGoodDigit())
220 continue;
221 station = StationSet->GetStation(digit->GetStation());
222 module = station->GetModule(digit->GetModule());
223
224 if (module->SetStripSignalInLayer(digit->GetStripLayer(), digit->GetStripNumber(), digit->GetStripSignal()))
225 AddedDigits++;
226
227 if (fBmnSiBTDigitMatchesArray) {
228 strip_match = (BmnMatch*)fBmnSiBTDigitMatchesArray->At(idigit);
229 if (module->SetStripMatchInLayer(digit->GetStripLayer(), digit->GetStripNumber(), *strip_match))
230 AddedStripDigitMatches++;
231 }
232 }
233
234 if (fVerbose > 1)
235 cout << " Processed strip digits : " << AddedDigits << "\n";
236 if (fVerbose > 1 && fBmnSiBTDigitMatchesArray)
237 cout << " Added strip digit matches : " << AddedStripDigitMatches << "\n";
238 //------------------------------------------------------------------------------
239
240 // Processing digits
241 StationSet->ProcessPointsInDetector();
242
243 Int_t NCalculatedPoints = StationSet->CountNProcessedPointsInDetector();
244 if (fVerbose > 1)
245 cout << " Calculated points : " << NCalculatedPoints << "\n";
246 if (fVerbose == 1)
247 cout << "BmnSiBTHitMaker: " << NCalculatedPoints << " hits\n";
248
249 Int_t clear_matched_points_cnt = 0; // points with the only one match-index
250
251 for (Int_t iStation = 0; iStation < StationSet->GetNStations(); ++iStation) {
252 station = StationSet->GetStation(iStation);
253
254 for (Int_t iModule = 0; iModule < station->GetNModules(); ++iModule) {
255 module = station->GetModule(iModule);
256
257 Int_t NIntersectionPointsInModule = module->GetNIntersectionPoints();
258
259 for (Int_t iPoint = 0; iPoint < NIntersectionPointsInModule; ++iPoint) {
260
261 Double_t sigL = module->GetIntersectionPoint_LowerLayerSripTotalSignal(iPoint);
262 Double_t sigU = module->GetIntersectionPoint_UpperLayerSripTotalSignal(iPoint);
263
264 Double_t x = module->GetIntersectionPointX(iPoint);
265 Double_t y = module->GetIntersectionPointY(iPoint);
266 Double_t z = module->GetZPositionRegistered();
267
268 Double_t x_err = module->GetIntersectionPointXError(iPoint);
269 Double_t y_err = module->GetIntersectionPointYError(iPoint);
270 Double_t z_err = 0.0;
271
272 // Transform hit coordinates from local coordinate system of GEM-planes to global
273 if (TransfSet) {
274 Plane3D::Point glob_point = TransfSet->ApplyTransforms(Plane3D::Point(-x, y, z), iStation, iModule);
275 x = -glob_point.X();
276 y = glob_point.Y();
277 z = glob_point.Z();
278 }
279
280 Int_t RefMCIndex = 0;
281
282 // hit matching (define RefMCIndex)) ----------------------------
283 BmnMatch match = module->GetIntersectionPointMatch(iPoint);
284
285 Int_t most_probably_index = -1;
286 Double_t max_weight = 0;
287
288 Int_t n_links = match.GetNofLinks();
289 if (n_links == 1)
290 clear_matched_points_cnt++;
291 for (Int_t ilink = 0; ilink < n_links; ilink++) {
292 Int_t index = match.GetLink(ilink).GetIndex();
293 Double_t weight = match.GetLink(ilink).GetWeight();
294 if (weight > max_weight) {
295 max_weight = weight;
296 most_probably_index = index;
297 }
298 }
299
300 RefMCIndex = most_probably_index;
301 //--------------------------------------------------------------
302
303 // Add hit ------------------------------------------------------
304 x *= -1; // invert to global X //Temporary switched off
305 //===Alignment====
306 //===Align stations (track-hit residuals without field)====
307 if (iStation == 1) {
308 x += 0.14256;
309 y += 0.11886;
310 }
311 //===General shift for vertex correlations====
312 x += -0.343396;
313 y += 0.195678;
314
315 // === Angle corrections=========
316 double k = 2.01370805; //(z0-z2)/(z1-z2)
317 double dx = -0.082;
318 double dy = 0.03;
319 if (iStation == 1) {
320 x += dx;
321 y += dy;
322 }
323
324 if (iStation == 0) {
325 x += dx * k;
326 y += dy * k;
327 }
328 //================================
329
330 new ((*fBmnSiBTHitsArray)[fBmnSiBTHitsArray->GetEntriesFast()])
331 BmnSiBTHit(0, TVector3(x, y, z), TVector3(x_err, y_err, z_err), RefMCIndex);
332
333 BmnSiBTHit* hit = (BmnSiBTHit*)fBmnSiBTHitsArray->At(fBmnSiBTHitsArray->GetEntriesFast() - 1);
334 hit->SetStation(iStation);
335 hit->SetModule(iModule);
336 hit->SetIndex(fBmnSiBTHitsArray->GetEntriesFast() - 1);
338 module->GetIntersectionPoint_LowerLayerClusterSize(iPoint)); // cluster size (lower layer |||)
339 hit->SetClusterSizeInUpperLayer(module->GetIntersectionPoint_UpperLayerClusterSize(
340 iPoint)); // cluster size (upper layer ///or\\\‍)
342 module->GetIntersectionPoint_LowerLayerSripPosition(iPoint)); // strip position (lower layer |||)
343 hit->SetStripPositionInUpperLayer(module->GetIntersectionPoint_UpperLayerSripPosition(
344 iPoint)); // strip position (upper layer ///or\\\‍)
347
348 if (fVerbose) {
349 cout << " glob(x:y:z) = ( " << x << " : " << y << " : " << z << "\n";
350 cout << " hit(x:y:z) = ( " << hit->GetX() << " : " << hit->GetY() << " : " << hit->GetZ() << "\n";
351 cout << "\n";
352 }
353 //--------------------------------------------------------------
354
355 // hit matching -------------------------------------------------
356 if (fHitMatching && fBmnSiBTHitMatchesArray) {
357 new ((*fBmnSiBTHitMatchesArray)[fBmnSiBTHitMatchesArray->GetEntriesFast()])
358 BmnMatch(module->GetIntersectionPointMatch(iPoint));
359 }
360 //--------------------------------------------------------------
361 }
362 }
363 }
364 if (fVerbose > 1)
365 cout << " N clear matches with MC-points = " << clear_matched_points_cnt << "\n";
366 //------------------------------------------------------------------------------
367 StationSet->Reset();
368}
369
370void BmnSiBTHitMaker::OnlineWrite(const std::unique_ptr<TTree>& resultTree)
371{
372 if (!IsActive())
373 return;
374
375 resultTree->Branch(fOutputHitsBranchName, &fBmnSiBTHitsArray);
376 resultTree->Fill();
377}
378
380{
381 if (StationSet) {
382 delete StationSet;
383 StationSet = nullptr;
384 }
385
386 if (TransfSet) {
387 delete TransfSet;
388 TransfSet = nullptr;
389 }
390
391 printf("Work time of BmnSiBTHitMaker: %4.2f sec.\n", workTime);
392}
Bool_t GetIsGoodEvent()
void SetModule(Int_t mod)
Definition BmnHit.h:73
void SetIndex(Int_t id)
Definition BmnHit.h:57
void SetStation(Short_t st)
Definition BmnHit.h:69
virtual void Finish()
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
virtual ~BmnSiBTHitMaker()
virtual void OnlineWrite(const std::unique_ptr< TTree > &resultTree)
Write task resul to tree.
void SetStripTotalSignalInLowerLayer(Double_t sig)
Definition BmnSiBTHit.h:40
void SetStripTotalSignalInUpperLayer(Double_t sig)
Definition BmnSiBTHit.h:44
void SetClusterSizeInLowerLayer(Int_t csize)
Definition BmnSiBTHit.h:24
void SetStripPositionInUpperLayer(Double_t spos)
Definition BmnSiBTHit.h:36
void SetStripPositionInLowerLayer(Double_t spos)
Definition BmnSiBTHit.h:32
void SetClusterSizeInUpperLayer(Int_t csize)
Definition BmnSiBTHit.h:28
Int_t CountNProcessedPointsInDetector()
BmnSiBTStation * GetStation(Int_t station_num)
Plane3D::Point ApplyTransforms(Plane3D::Point point, Int_t station, Int_t module)
Bool_t LoadFromXMLFile(TString xml_config_file)
Bool_t IsGoodDigit()
Int_t GetStripNumber()
Int_t GetStripLayer()
Int_t GetStation()
Double_t GetStripSignal()