BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnBdHitProducer.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- BmnBdHitProducer source file -----
3// ----- Created 12/07/18 by A. Zinchenko -----
4// -------------------------------------------------------------------------
5
6#include "BmnBdHitProducer.h"
7
8#include "BmnBdHit.h"
9#include "BmnBdPoint.h"
10#include "FairRootManager.h"
11#include "TClonesArray.h"
12
13#include <iostream>
14
15using std::cout;
16using std::endl;
17
18// ----- Default constructor -------------------------------------------
20 : FairTask("Bmn Bd Hit Producer")
21 , fPointArray(NULL)
22 , fHitArray()
23{}
24// -------------------------------------------------------------------------
25
26// ----- Destructor ----------------------------------------------------
28// -------------------------------------------------------------------------
29
30// ----- Public method Init --------------------------------------------
32{
33
34 // Get RootManager
35 FairRootManager* ioman = FairRootManager::Instance();
36 if (!ioman) {
37 cout << "-E- BmnBdHitProducer::Init: "
38 << "RootManager not instantiated!" << endl;
39 return kFATAL;
40 }
41
42 // Get input array
43 fPointArray = (TClonesArray*)ioman->GetObject("BdPoint");
44 if (!fPointArray) {
45 cout << "-W- BmnBdHitProducer::Init: "
46 << "No BdPoint array!" << endl;
47 return kERROR;
48 }
49
50 // Create and register output array
51 fHitArray = new TClonesArray("BmnBdHit");
52 ioman->Register("BdHit", "BD", fHitArray, kTRUE);
53
54 cout << "-I- BmnBdHitProducer: Intialization successfull" << endl;
55 return kSUCCESS;
56}
57// -------------------------------------------------------------------------
58
59// ----- Public method Exec --------------------------------------------
61{
62
63 // Reset output array
64 if (!fHitArray)
65 Fatal("Exec", "No BdHit array");
66
67 fHitArray->Delete();
68 fHitMap.clear();
69
70 // Declare some variables
71 BmnBdPoint* point = NULL;
72 Int_t detID = 0; // Detector ID
73 // Int_t trackID = 0; // Track index
74 Double_t x, y, z; // Position
75 Double_t dx = 0.0001; // Position error
76 TVector3 pos, dpos; // Position and error vectors
77
78 // Loop over BdPoints
79 Int_t nPoints = fPointArray->GetEntriesFast();
80
81 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
82 point = (BmnBdPoint*)fPointArray->UncheckedAt(iPoint);
83 if (!point)
84 continue;
85
86 // Detector ID
87 detID = point->GetCopy();
88
89 // MCTrack ID
90 // trackID = point->GetTrackID();
91
92 // Hit position
93 x = point->GetX();
94 y = point->GetY();
95 z = point->GetZ();
96
97 // Create new hit
98 pos.SetXYZ(x, y, z);
99 dpos.SetXYZ(dx, dx, 0.);
100 // new ((*fHitArray)[iPoint]) BmnBdHit(detID, pos, dpos, iPoint);
101 if (fHitMap.find(detID) == fHitMap.end())
102 fHitMap[detID] = BmnBdHit(detID, pos, dpos, iPoint);
103 // Add point to the hit links
104 fHitMap[detID].AddLink(FairLink(0, iPoint));
105
106 } // Loop over MCPoints
107
108 // Store hits
109 Int_t ihit = 0;
110 for (map<Int_t, BmnBdHit>::iterator mit = fHitMap.begin(); mit != fHitMap.end(); ++mit)
111 new ((*fHitArray)[ihit++]) BmnBdHit(mit->second);
112
113 // Event summary
114 cout << "-I- BmnBdHitProducer: " << nPoints << " BdPoints, " << fHitMap.size() << " Hits created." << endl;
115}
116// -------------------------------------------------------------------------
int Int_t
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Fatal(const char *location, const char *msgfmt,...)
std::map< Int_t, BmnBdHit > fHitMap
BmnBdHitProducer()
Default constructor.
virtual InitStatus Init()
Virtual method Init.
virtual void Exec(Option_t *opt)
Virtual method Exec.
TClonesArray * fPointArray
Input array of BmnBdPoints.
~BmnBdHitProducer()
Destructor.
TClonesArray * fHitArray
Output array of BmnBdHits.
BmnBdHit.h.
Definition BmnBdHit.h:22
Short_t GetCopy() const
Accessors.
Definition BmnBdPoint.h:61
void SetXYZ(Double_t x, Double_t y, Double_t z)