BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnCSCHitMaker.cxx
Go to the documentation of this file.
1#include "BmnCSCHitMaker.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
16{
17
18 fInputPointsBranchName = "CSCPoint";
19 fInputDigitsBranchName = "BmnCSCDigit";
20 fInputDigitMatchesBranchName = "BmnCSCDigitMatch";
21
22 fOutputHitsBranchName = "BmnCSCHit";
23
24 fVerbose = 1;
25 fField = NULL;
26
28 StationSet = nullptr;
29 GlobalModTransfSet = nullptr;
30
31 fBmnCSCHitsArray = nullptr;
34}
35
36BmnCSCHitMaker::BmnCSCHitMaker(Int_t run_period, Int_t run_number, Bool_t isExp, TString alignFile, Bool_t isSrc)
38{
39
40 fInputPointsBranchName = "CSCPoint";
41 fInputDigitsBranchName = (!isExp) ? "BmnCSCDigit" : "CSC";
42 fIsExp = isExp;
43 fIsSrc = isSrc;
44
45 fInputDigitMatchesBranchName = "BmnCSCDigitMatch";
46
47 fOutputHitsBranchName = "BmnCSCHit";
48
49 fVerbose = 1;
50 fField = NULL;
51
53 StationSet = nullptr;
54 GlobalModTransfSet = nullptr;
55
56 fBmnCSCHitsArray = nullptr;
59
60 switch (run_period) {
61 case 7: // BM@N RUN-7 (and SRC)
63 if (run_number >= 2041 && run_number <= 3588) {
65 }
66 break;
67 case 8:
68 if (fIsSrc) {
70 } else {
72 }
73 break;
74 case 9:
76 break;
77
78 default:
80 }
81}
82
84{
85 if (StationSet) {
86 delete StationSet;
87 }
88
90 delete GlobalModTransfSet;
91 }
92
93 if (fBmnCSCHitsArray) {
94 fBmnCSCHitsArray->Delete();
95 delete fBmnCSCHitsArray;
96 }
100 }
104 }
105}
106
108{
109 TString gPathCSCConfig = gSystem->Getenv("VMCWORKDIR");
110 gPathCSCConfig += "/parameters/csc/XMLConfigs/";
111
112 switch (fCurrentConfig) {
114 XMLConfigFile = gPathCSCConfig + "CSCRunSpring2018.xml";
115 if (fVerbose)
116 cout << " Current CSC Configuration : RunSpring2018"
117 << "\n";
118 break;
119
121 XMLConfigFile = gPathCSCConfig + "CSCRunSRCSpring2018.xml";
122 if (fVerbose)
123 cout << " Current CSC Configuration : RunSRCSpring2018"
124 << "\n";
125 break;
126
128 XMLConfigFile = gPathCSCConfig + "CSCRun8.xml";
129 if (fVerbose)
130 cout << " Current CSC Configuration : Run8"
131 << "\n";
132 break;
133
135 XMLConfigFile = gPathCSCConfig + "CSCRunSRC2021.xml";
136 if (fVerbose)
137 cout << " Current CSC Configuration : RunSRC2021"
138 << "\n";
139 break;
140
142 XMLConfigFile = gPathCSCConfig + "LargeCSCRun8.xml";
143 if (fVerbose)
144 cout << " Current CSC Configuration : LargeCSCRun8"
145 << "\n";
146 break;
147
149 XMLConfigFile = gPathCSCConfig + "FullCSCRun8.xml";
150 if (fVerbose)
151 cout << " Current CSC Configuration : FullCSCRun8 (4 small + 1 large chambers)"
152 << "\n";
153 break;
154
156 XMLConfigFile = gPathCSCConfig + "CSCRun9.xml";
157 if (fVerbose)
158 cout << " Current CSC Configuration : Run9"
159 << "\n";
160 break;
161
162 default:;
163 }
164
165 if (!gSystem->AccessPathName(XMLConfigFile)) { // returns FALSE if the file exists
166 if (fVerbose)
167 cout << " XMLConfigFile : " << XMLConfigFile << "\n";
170 GlobalModTransfSet->LoadFromXMLFile(XMLConfigFile);
171 } else {
172 Fatal("BmnCSCHitMaker::LoadDetectorConfiguration()", " !!! Current configuration is not set !!! ");
173 }
174}
175
177{
178
179 if (fVerbose > 1)
180 cout << "=================== BmnCSCHitMaker::Init() started ====================" << endl;
181
182 FairRootManager* ioman = FairRootManager::Instance();
183
185 if (!fBmnCSCDigitsArray) {
186 cout << "BmnCSCHitMaker::Init(): branch " << fInputDigitsBranchName << " not found! Task will be deactivated"
187 << endl;
188 SetActive(kFALSE);
189 return kERROR;
190 }
191
193
194 if (fVerbose > 1) {
196 cout << " Strip matching information exists!\n";
197 else
198 cout << " Strip matching information doesn`t exist!\n";
199 }
200
202 ioman->Register(fOutputHitsBranchName, "CSC", fBmnCSCHitsArray, kTRUE);
203 fBmnCSCUpperClustersArray = new TClonesArray("StripCluster");
204 ioman->Register("BmnCSCUpperCluster", "CSC", fBmnCSCUpperClustersArray, kTRUE);
205 fBmnCSCLowerClustersArray = new TClonesArray("StripCluster");
206 ioman->Register("BmnCSCLowerCluster", "CSC", fBmnCSCLowerClustersArray, kTRUE);
207
208 // Create CSC detector ------------------------------------------------------
209
211
212 fField = FairRunAna::Instance()->GetField();
213 if (!fField)
214 Fatal("Init", "No Magnetic Field found");
215
216 //--------------------------------------------------------------------------
217
218 if (fVerbose > 1)
219 cout << "=================== BmnCSCHitMaker::Init() finished ===================" << endl;
220
221 return kSUCCESS;
222}
223
225{
226
227 TStopwatch sw;
228 sw.Start();
229
230 if (!IsActive())
231 return;
232
233 fBmnCSCHitsArray->Delete();
236
239
240 if (fVerbose > 1)
241 cout << "=================== BmnCSCHitMaker::Exec() started ====================" << endl;
242
243 if (fVerbose > 1)
244 cout << " BmnCSCHitMaker::Exec(), Number of BmnCSCDigits = " << fBmnCSCDigitsArray->GetEntriesFast() << "\n";
245
247
248 if (fVerbose > 1)
249 cout << "=================== BmnCSCHitMaker::Exec() finished ===================" << endl;
250
251 sw.Stop();
252 workTime += sw.RealTime();
253}
254
256{
257
258 // FairMCPoint* MCPoint;
259 BmnCSCDigit* digit;
260 BmnMatch* strip_match;
261
262 BmnCSCStation* station;
263 BmnCSCModule* module;
264
265 // Loading digits ---------------------------------------------------------------
266 Int_t AddedDigits = 0;
267 Int_t AddedStripDigitMatches = 0;
268
269 for (Int_t idigit = 0; idigit < fBmnCSCDigitsArray->GetEntriesFast(); idigit++) {
270 digit = (BmnCSCDigit*)fBmnCSCDigitsArray->At(idigit);
271 if (!digit->IsGoodDigit())
272 continue;
273 station = StationSet->GetStation(digit->GetStation());
274 module = station->GetModule(digit->GetModule());
275
276 if (module->SetStripSignalInLayer(digit->GetStripLayer(), digit->GetStripNumber(), digit->GetStripSignal()))
277 AddedDigits++;
278
280 strip_match = (BmnMatch*)fBmnCSCDigitMatchesArray->At(idigit);
281 if (module->SetStripMatchInLayer(digit->GetStripLayer(), digit->GetStripNumber(), *strip_match))
282 AddedStripDigitMatches++;
283 }
284
285 // Add a digit number match to the current strip
286 BmnMatch stripDigitNumberMatch; // digit number information for the current strip
287 stripDigitNumberMatch.AddLink(1.0, idigit);
288 module->SetStripDigitNumberMatchInLayer(digit->GetStripLayer(), digit->GetStripNumber(), stripDigitNumberMatch);
289 }
290
291 if (fVerbose > 1)
292 cout << " Processed strip digits : " << AddedDigits << "\n";
293 if (fVerbose > 1 && fBmnCSCDigitMatchesArray)
294 cout << " Added strip digit matches : " << AddedStripDigitMatches << "\n";
295 //------------------------------------------------------------------------------
296
297 // Processing digits
298 StationSet->ProcessPointsInDetector();
299
300 Int_t NCalculatedPoints = StationSet->CountNProcessedPointsInDetector();
301 if (fVerbose > 1)
302 cout << " Calculated points : " << NCalculatedPoints << "\n";
303 if (fVerbose == 1)
304 cout << "BmnCSCHitMaker: " << NCalculatedPoints << " hits\n";
305
306 Int_t clear_matched_points_cnt = 0; // points with the only one match-index
307
308 map<Int_t, StripCluster> UniqueUpperClusters;
309 map<Int_t, StripCluster> UniqueLowerClusters;
310
311 for (Int_t iStation = 0; iStation < StationSet->GetNStations(); ++iStation) {
312 station = StationSet->GetStation(iStation);
313
314 for (Int_t iModule = 0; iModule < station->GetNModules(); ++iModule) {
315 module = station->GetModule(iModule);
316
317 for (Int_t iLayer = 0; iLayer < module->GetNStripLayers(); ++iLayer) {
318 BmnCSCLayer layer = module->GetStripLayer(iLayer);
319
320 for (size_t iCluster = 0; iCluster < layer.GetStripClusters().size(); ++iCluster) {
321 StripCluster cluster = layer.GetStripClusters()[iCluster];
322 cluster.SetModule(iModule);
323 cluster.SetStation(iStation);
324
325 // Saving all strip clusters into branches (each cluster have its own unique id in the current
326 // event)
327 if (cluster.GetType() == UpperStripLayer) {
328 new ((*fBmnCSCUpperClustersArray)[fBmnCSCUpperClustersArray->GetEntriesFast()])
329 StripCluster(cluster);
330 } else {
331 new ((*fBmnCSCLowerClustersArray)[fBmnCSCLowerClustersArray->GetEntriesFast()])
332 StripCluster(cluster);
333 }
334 }
335 }
336
337 Int_t NIntersectionPointsInModule = module->GetNIntersectionPoints();
338
339 // Int_t NPseudoIntersectionsInModule = module->GetNPseudoIntersections();
340 Int_t NPseudoIntersectionsInModule = 0; // !!! IGNORE PSEUDO INTERSECTIONS !!!
341
342 for (Int_t iPoint = 0; iPoint < NIntersectionPointsInModule + NPseudoIntersectionsInModule; ++iPoint) {
343
344 // Double_t sigL;
345 // Double_t sigU;
346 Double_t x, y, z;
347 Double_t x_err, y_err, z_err;
348
349 if (iPoint < NIntersectionPointsInModule) {
350 // sigL = module->GetIntersectionPoint_LowerLayerSripTotalSignal(iPoint);
351 // sigU = module->GetIntersectionPoint_UpperLayerSripTotalSignal(iPoint);
352 x = module->GetIntersectionPointX(iPoint);
353 y = module->GetIntersectionPointY(iPoint);
354 z = module->GetZPositionRegistered();
355 x_err = module->GetIntersectionPointXError(iPoint);
356 y_err = module->GetIntersectionPointYError(iPoint);
357 z_err = 0.0;
358 } else {
359 // sigL =
360 // module->GetPseudoIntersection_LowerLayerSripTotalSignal(iPoint-NIntersectionPointsInModule); sigU
361 // = module->GetPseudoIntersection_UpperLayerSripTotalSignal(iPoint-NIntersectionPointsInModule);
362 x = module->GetPseudoIntersectionX(iPoint - NIntersectionPointsInModule);
363 y = module->GetPseudoIntersectionY(iPoint - NIntersectionPointsInModule);
364 z = module->GetZPositionRegistered();
365 x_err = module->GetPseudoIntersectionXError(iPoint - NIntersectionPointsInModule);
366 y_err = module->GetPseudoIntersectionYError(iPoint - NIntersectionPointsInModule);
367 z_err = 0.0;
368 }
369
370 // Apply global module transforms to detector hit (in right-handed system)
371 if (GlobalModTransfSet) {
372 Plane3D::Point point_transformed =
373 GlobalModTransfSet->ApplyTransforms(Plane3D::Point(-x, y, z), iStation, iModule);
374 x = -point_transformed.X(); // convert to detector system (x-inverted)
375 y = point_transformed.Y();
376 z = point_transformed.Z();
377 }
378
379 Int_t RefMCIndex = -1;
380
381 // MC-matching for the current hit (define RefMCIndex)) ---------
382 BmnMatch mc_match_hit;
383 if (iPoint < NIntersectionPointsInModule) {
384 mc_match_hit = module->GetIntersectionPointMatch(iPoint);
385 } else {
386 mc_match_hit = module->GetPseudoIntersectionMatch(iPoint - NIntersectionPointsInModule);
387 }
388
389 Int_t most_probably_index = -1;
390 Double_t max_weight = 0;
391
392 Int_t n_links = mc_match_hit.GetNofLinks();
393 if (n_links == 1)
394 clear_matched_points_cnt++;
395 for (Int_t ilink = 0; ilink < n_links; ilink++) {
396 Int_t index = mc_match_hit.GetLink(ilink).GetIndex();
397 Double_t weight = mc_match_hit.GetLink(ilink).GetWeight();
398 if (weight > max_weight) {
399 max_weight = weight;
400 most_probably_index = index;
401 }
402 }
403
404 RefMCIndex = most_probably_index;
405 //--------------------------------------------------------------
406
407 // Add hit ------------------------------------------------------
408 x *= -1; // invert to global X //Temporary switched off
409
410 new ((*fBmnCSCHitsArray)[fBmnCSCHitsArray->GetEntriesFast()])
411 BmnCSCHit(0, TVector3(x, y, z), TVector3(x_err, y_err, z_err), RefMCIndex);
412
413 BmnCSCHit* hit = (BmnCSCHit*)fBmnCSCHitsArray->At(fBmnCSCHitsArray->GetEntriesFast() - 1);
414 hit->SetStation(iStation);
415 hit->SetModule(iModule);
416 hit->SetIndex(fBmnCSCHitsArray->GetEntriesFast() - 1);
417
418 if (iPoint < NIntersectionPointsInModule) {
420 module->GetIntersectionPointDigitNumberMatch(iPoint)); // digit number match for the hit
421 hit->SetUpperClusterIndex(module->GetUpperCluster(iPoint).GetUniqueID());
422 hit->SetLowerClusterIndex(module->GetLowerCluster(iPoint).GetUniqueID());
423 hit->SetPseudo(false);
424 } else {
426 iPoint - NIntersectionPointsInModule)); // digit number match for the hit
428 module->GetUpperCluster_PseudoIntersections(iPoint - NIntersectionPointsInModule)
429 .GetUniqueID());
431 module->GetLowerCluster_PseudoIntersections(iPoint - NIntersectionPointsInModule)
432 .GetUniqueID());
433 hit->SetPseudo(true);
434 }
435
436 if (fVerbose) {
437 cout << " glob(x:y:z) = ( " << x << " : " << y << " : " << z << "\n";
438 cout << " hit(x:y:z) = ( " << hit->GetX() << " : " << hit->GetY() << " : " << hit->GetZ() << "\n";
439 cout << "\n";
440 }
441 /*
442 StripCluster ucls = module->GetUpperCluster(iPoint);
443 StripCluster lcls = module->GetLowerCluster(iPoint);
444 ucls.SetModule(iModule);
445 lcls.SetModule(iModule);
446 ucls.SetStation(iStation);
447 lcls.SetStation(iStation);
448 UniqueUpperClusters[ucls.GetUniqueID()] = ucls;
449 UniqueLowerClusters[lcls.GetUniqueID()] = lcls;
450 hit->SetUpperClusterIndex(ucls.GetUniqueID());
451 hit->SetLowerClusterIndex(lcls.GetUniqueID());
452 */
453 if (fHitMatching) {
454 // For future update
455
456 /*BmnMatch digiMatch;
457 Int_t idx0, idx1;
458 if(iPoint < NIntersectionPointsInModule) {
459 digiMatch = module->GetIntersectionPointDigitNumberMatch(iPoint);
460 idx0 = digiMatch.GetLink(0).GetIndex();
461 idx1 = digiMatch.GetLink(1).GetIndex();
462 }
463 else {
464 digiMatch = module->GetPseudoIntersectionDigitNumberMatch(iPoint-NIntersectionPointsInModule);
465 idx0 = digiMatch.GetLink(0).GetIndex();
466 idx1 = digiMatch.GetLink(0).GetIndex();
467 }
468 BmnMatch* digiMatch0 = (BmnMatch*)fBmnCSCDigitMatchesArray->At(idx0);
469 BmnMatch* digiMatch1 = (BmnMatch*)fBmnCSCDigitMatchesArray->At(idx1);
470
471 Bool_t hitOk = kFALSE;
472 for (Int_t ilink = 0; ilink < digiMatch0->GetNofLinks(); ilink++) {
473 Int_t iindex = digiMatch0->GetLink(ilink).GetIndex();
474 for (Int_t jlink = 0; jlink < digiMatch1->GetNofLinks(); jlink++) {
475 Int_t jindex = digiMatch1->GetLink(jlink).GetIndex();
476 if (iindex == jindex) {
477 hitOk = kTRUE;
478 break;
479 }
480 }
481 if (hitOk) break;
482 }
483
484 hit->SetType(hitOk);
485 if (!hitOk) hit->SetRefIndex(-1);*/
486 //--------------------------------------------------------------
487
488 // hit MC-matching ----------------------------------------------
489 FairRootManager::Instance()->SetUseFairLinks(kTRUE);
490 BmnMatch hitMatch;
491 if (iPoint < NIntersectionPointsInModule) {
492 hitMatch = module->GetIntersectionPointMatch(iPoint);
493 } else {
494 hitMatch = module->GetPseudoIntersectionMatch(iPoint - NIntersectionPointsInModule);
495 }
496
497 for (BmnLink lnk : hitMatch.GetLinks())
498 hit->AddLink(FairLink(-1, lnk.GetIndex(), lnk.GetWeight()));
499 FairRootManager::Instance()->SetUseFairLinks(kFALSE);
500 }
501 //--------------------------------------------------------------
502 }
503 }
504 }
505 /*
506 for (auto it : UniqueUpperClusters) {
507 for (Int_t i = 0; i < fBmnCSCHitsArray->GetEntriesFast(); i++) {
508 BmnCSCHit* hit = (BmnCSCHit*) fBmnCSCHitsArray->At(i);
509 if (hit->GetUpperClusterIndex() != it.first) continue;
510 hit->SetUpperClusterIndex(fBmnCSCUpperClustersArray->GetEntriesFast());
511 }
512 it.second.SetUniqueID(fBmnCSCUpperClustersArray->GetEntriesFast());
513 new ((*fBmnCSCUpperClustersArray)[fBmnCSCUpperClustersArray->GetEntriesFast()]) StripCluster(it.second);
514 }
515 for (auto it : UniqueLowerClusters) {
516 for (Int_t i = 0; i < fBmnCSCHitsArray->GetEntriesFast(); i++) {
517 BmnCSCHit* hit = (BmnCSCHit*) fBmnCSCHitsArray->At(i);
518 if (hit->GetLowerClusterIndex() != it.first) continue;
519 hit->SetLowerClusterIndex(fBmnCSCLowerClustersArray->GetEntriesFast());
520 }
521 it.second.SetUniqueID(fBmnCSCLowerClustersArray->GetEntriesFast());
522 new ((*fBmnCSCLowerClustersArray)[fBmnCSCLowerClustersArray->GetEntriesFast()]) StripCluster(it.second);
523 }
524 */
525 if (fVerbose > 1)
526 cout << " N clear matches with MC-points = " << clear_matched_points_cnt << "\n";
527 //------------------------------------------------------------------------------
528 StationSet->Reset();
529}
530
531void BmnCSCHitMaker::OnlineWrite(const std::unique_ptr<TTree>& resultTree)
532{
533 if (!IsActive())
534 return;
535
536 resultTree->Branch(fOutputHitsBranchName, &fBmnCSCHitsArray);
537 resultTree->Branch("BmnCSCUpperCluster", &fBmnCSCUpperClustersArray);
538 resultTree->Branch("BmnCSCLowerCluster", &fBmnCSCLowerClustersArray);
539 resultTree->Fill();
540}
541
543{
544 if (StationSet) {
545 delete StationSet;
546 StationSet = nullptr;
547 }
548
549 if (GlobalModTransfSet) {
550 delete GlobalModTransfSet;
551 GlobalModTransfSet = nullptr;
552 }
553
554 printf("Work time of BmnCSCHitMaker: %4.2f sec.\n", workTime);
555}
static Double_t workTime
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Fatal(const char *location, const char *msgfmt,...)
R__EXTERN TSystem * gSystem
@ UpperStripLayer
BmnCSCTransform * GlobalModTransfSet
TClonesArray * fBmnCSCDigitMatchesArray
void LoadDetectorConfiguration()
virtual InitStatus Init()
BmnCSCConfiguration::CSC_CONFIG fCurrentConfig
TString fInputDigitMatchesBranchName
virtual void OnlineWrite(const std::unique_ptr< TTree > &resultTree)
Write task resul to tree.
FairField * fField
TString XMLConfigFile
TString fInputPointsBranchName
TClonesArray * fBmnCSCDigitsArray
BmnCSCStationSet * StationSet
virtual ~BmnCSCHitMaker()
TString fInputDigitsBranchName
TClonesArray * fBmnCSCUpperClustersArray
Output array of CSC Upper Clusters.
TClonesArray * fBmnCSCLowerClustersArray
Output array of CSC Lower Clusters.
TString fOutputHitsBranchName
virtual void Finish()
virtual void Exec(Option_t *opt)
TClonesArray * fBmnCSCHitsArray
Output array of CSC Hits.
static void SetLowerUniqueID(Int_t id)
static void SetUpperUniqueID(Int_t id)
vector< StripCluster > GetStripClusters()
StripCluster GetLowerCluster(Int_t indx)
StripCluster GetUpperCluster(Int_t indx)
StripCluster GetUpperCluster_PseudoIntersections(Int_t indx)
BmnMatch GetIntersectionPointDigitNumberMatch(Int_t indx)
Bool_t SetStripMatchInLayer(Int_t layer_num, Int_t strip_num, BmnMatch mc_match)
Int_t GetNStripLayers()
BmnMatch GetPseudoIntersectionDigitNumberMatch(Int_t indx)
Bool_t SetStripSignalInLayer(Int_t layer_num, Int_t strip_num, Double_t signal)
StripCluster GetLowerCluster_PseudoIntersections(Int_t indx)
Int_t GetNModules()
void SetModule(Int_t mod)
Definition BmnHit.h:53
void SetUpperClusterIndex(Int_t idx)
Definition BmnHit.h:64
void SetDigitNumberMatch(BmnMatch match)
Definition BmnHit.h:63
void SetIndex(Int_t id)
Definition BmnHit.h:49
void SetPseudo(Bool_t pseudo)
Definition BmnHit.h:56
void SetStation(Short_t st)
Definition BmnHit.h:52
void SetLowerClusterIndex(Int_t idx)
Definition BmnHit.h:65
const BmnLink & GetLink(Int_t i) const
Definition BmnMatch.h:38
void AddLink(const BmnMatch &match)
Definition BmnMatch.cxx:40
const vector< BmnLink > & GetLinks() const
Definition BmnMatch.h:39
Int_t GetNofLinks() const
Definition BmnMatch.h:41
Bool_t IsGoodDigit()
Int_t GetStripNumber()
Int_t GetStripLayer()
Int_t GetStation()
Double_t GetStripSignal()
PositionVector3D< Cartesian3D< T >, DefaultCoordinateSystemTag > Point
void SetStation(Int_t st)
Int_t GetType()
void SetModule(Int_t m)
virtual UInt_t GetUniqueID() const
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
void Stop()