BmnRoot
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 "BmnBdHit.h"
7#include "BmnBdHitProducer.h"
8#include "BmnBdPoint.h"
9
10#include "FairRootManager.h"
11
12#include "TClonesArray.h"
13
14#include <iostream>
15
16using std::cout;
17using std::endl;
18
19// ----- Default constructor -------------------------------------------
21 : FairTask("Bmn Bd Hit Producer"),
22 fPointArray(NULL),
23 fHitArray()
24{
25}
26// -------------------------------------------------------------------------
27
28// ----- Destructor ----------------------------------------------------
30// -------------------------------------------------------------------------
31
32// ----- Public method Init --------------------------------------------
34
35 // Get RootManager
36 FairRootManager* ioman = FairRootManager::Instance();
37 if ( ! ioman ) {
38 cout << "-E- BmnBdHitProducer::Init: "
39 << "RootManager not instantiated!" << endl;
40 return kFATAL;
41 }
42
43 // Get input array
44 fPointArray = (TClonesArray*) ioman->GetObject("BdPoint");
45 if ( ! fPointArray ) {
46 cout << "-W- BmnBdHitProducer::Init: "
47 << "No BdPoint array!" << endl;
48 return kERROR;
49 }
50
51 // Create and register output array
52 fHitArray = new TClonesArray("BmnBdHit");
53 ioman->Register("BdHit", "BD", fHitArray, kTRUE);
54
55 cout << "-I- BmnBdHitProducer: Intialization successfull" << endl;
56 return kSUCCESS;
57
58}
59// -------------------------------------------------------------------------
60
61// ----- Public method Exec --------------------------------------------
62void BmnBdHitProducer::Exec(Option_t* opt) {
63
64 // Reset output array
65 if ( ! fHitArray ) 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) continue;
84
85 // Detector ID
86 detID = point->GetCopy();
87
88 // MCTrack ID
89 //trackID = point->GetTrackID();
90
91 // Hit position
92 x = point->GetX();
93 y = point->GetY();
94 z = point->GetZ();
95
96 // Create new hit
97 pos.SetXYZ(x,y,z);
98 dpos.SetXYZ(dx, dx, 0.);
99 //new ((*fHitArray)[iPoint]) BmnBdHit(detID, pos, dpos, iPoint);
100 if (fHitMap.find(detID) == fHitMap.end()) fHitMap[detID] = BmnBdHit(detID, pos, dpos, iPoint);
101 // Add point to the hit links
102 fHitMap[detID].AddLink(FairLink(0,iPoint));
103
104 } // Loop over MCPoints
105
106 // Store hits
107 Int_t ihit = 0;
108 for (map<Int_t,BmnBdHit>::iterator mit = fHitMap.begin(); mit != fHitMap.end(); ++mit)
109 new ((*fHitArray)[ihit++]) BmnBdHit(mit->second);
110
111 // Event summary
112 cout << "-I- BmnBdHitProducer: " << nPoints << " BdPoints, "
113 << fHitMap.size() << " Hits created." << endl;
114
115}
116// -------------------------------------------------------------------------
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
Short_t GetCopy() const
Definition BmnBdPoint.h:54