BmnRoot
Loading...
Searching...
No Matches
BmnTof1HitProducerIdeal.cxx
Go to the documentation of this file.
2
3#include "BmnTOF1Point.h"
4#include "BmnTofHit.h"
5#include "FairLogger.h"
6#include "FairRootManager.h"
7#include "TFile.h"
8
9#include <assert.h>
10
12 Bool_t useMCdata,
13 Int_t verbose,
14 Bool_t test,
15 Bool_t merge)
16 : BmnTask(name, verbose)
17 , aMcPoints(nullptr)
18 , aMcTracks(nullptr)
19 , aExpDigits(nullptr)
20 , aTofHits(nullptr)
21 , fDoTest(test)
22 , fDoMergeHits(merge)
23 , fUseMCData(useMCdata)
24 , fOnlyPrimary(false)
25 , fTestFlnm("test.BmnTof1HitProducerIdeal.root")
26{}
27
29
31{
32 LOG(info) << "[BmnTof1HitProducerIdeal::Init] Begin initialization.";
33
34 FairRootManager* ioman = FairRootManager::Instance();
35 assert(ioman);
36
37 if (fUseMCData) {
38 aMcPoints = (TClonesArray*)FairRootManager::Instance()->GetObject("TOF400Point");
39 if (!aMcPoints) {
40 cout << "BmnTof1HitProducerIdeal::Init(): branch TOF1Point not found! Task will be deactivated" << endl;
41 SetActive(kFALSE);
42 return kERROR;
43 }
44 aMcTracks = (TClonesArray*)FairRootManager::Instance()->GetObject("MCTrack");
45 if (!aMcTracks) {
46 cout << "BmnTof1HitProducerIdeal::Init(): branch MCTrack not found! Task will be deactivated" << endl;
47 SetActive(kFALSE);
48 return kERROR;
49 }
50 } else {
51 aExpDigits = (TClonesArray*)FairRootManager::Instance()->GetObject("bmn_tof400");
52 if (!aExpDigits) {
53 cout << "BmnTof1HitProducerIdeal::Init(): branch bmn_tof400 not found! Task will be deactivated" << endl;
54 SetActive(kFALSE);
55 return kERROR;
56 }
57 }
58
59 // Create and register output array
60 aTofHits = new TClonesArray("BmnTofHit");
61 ioman->Register("TOF400Hit", "TOF1", aTofHits, kTRUE);
62
63 LOG(info) << "[BmnTof1HitProducerIdeal::Init] Initialization finished succesfully.";
64
65 return kSUCCESS;
66}
67
69{
70 if (!IsActive())
71 return;
72
73 static const TVector3 XYZ_err(0., 0., 0.); // FIXME:
74
75 aTofHits->Clear();
76
77 Int_t nSingleHits = 0;
78 TVector3 pos;
79
80 if (fUseMCData) {
81 BmnTOF1Point* pPoint;
82 Int_t nTofPoint = aMcPoints->GetEntriesFast();
83
84 for (Int_t pointIndex = 0; pointIndex < nTofPoint; pointIndex++) // cycle by TOF points
85 {
86 pPoint = (BmnTOF1Point*)aMcPoints->UncheckedAt(pointIndex);
87 pPoint->Position(pos);
88
89 AddHit(pPoint->GetDetectorID(), pos, XYZ_err, pointIndex, pPoint->GetTrackID(), pPoint->GetTime(), kTOF1);
90 nSingleHits++;
91 }
92 }
93
94 int nFinally;
95 if (fDoMergeHits) {
96 MergeHitsOnStrip(); // save only the fastest hit in the strip
97 nFinally = CompressHits(); // remove blank slotes
98 } else
99 nFinally = aTofHits->GetEntriesFast();
100
101 cout << " -I- [BmnTof1HitProducerIdeal::Exec] single hits= " << nSingleHits << ", final hits= " << nFinally
102 << endl;
103}
104
106
108{
109 typedef map<Int_t, BmnTofHit*> hitsMapType;
110 hitsMapType fHits; // pair<detectorUID, BmnTofHit*> fastest hits map
111 hitsMapType::iterator it;
112 Int_t mergedNmb = 0;
113
114 typedef multiset<Int_t> msUIDsType; // detectorUID for Hits
115 msUIDsType UIDs;
116
117 BmnTofHit *fastHit, *slowHit;
118 for (Int_t hitIndex = 0, nHits = aTofHits->GetEntriesFast(); hitIndex < nHits; hitIndex++) // cycle by hits
119 {
120 BmnTofHit* pHit = (BmnTofHit*)aTofHits->UncheckedAt(hitIndex);
121 assert(nullptr != pHit);
122
123 Int_t UID = pHit->GetDetectorID();
124
125 if (fDoTest)
126 UIDs.insert(UID);
127
128 it = fHits.find(UID);
129 if (it != fHits.end()) // hit for this detectorUID already exist
130 {
131 mergedNmb++;
132
133 if (pHit->GetTimeStamp() < it->second->GetTimeStamp()) // faster hit found
134 {
135 fastHit = pHit;
136 slowHit = it->second;
137 } else {
138 fastHit = it->second;
139 slowHit = pHit;
140 }
141
142 fastHit->AddLinks(slowHit->GetLinks()); // copy links
143 aTofHits->Remove(slowHit); // remove old hit --> make blank slote !!
144 it->second = fastHit; // change pair value to current UID
145 } else
146 fHits.insert(make_pair(UID, pHit)); // insert new detectorUID pair
147
148 } // cycle by hits
149
150 return mergedNmb;
151}
152
154 const TVector3& posHit,
155 const TVector3& posHitErr,
156 Int_t pointIndex,
157 Int_t trackIndex,
158 Double_t time,
159 Int_t Idd = kTOF1)
160{
161 BmnTofHit* pHit = new ((*aTofHits)[aTofHits->GetEntriesFast()]) BmnTofHit(detUID, posHit, posHitErr, pointIndex);
162
163 FairRootManager::Instance()->SetUseFairLinks(kTRUE);
164 pHit->SetTimeStamp(time);
165 pHit->AddLink(FairLink(0x1, pointIndex));
166 pHit->AddLink(FairLink(0x2, trackIndex));
167 pHit->AddLink(FairLink(0x4, detUID));
168 Int_t str = BmnTOF1Point::GetStrip(detUID) - 1;
169 Int_t plane = BmnTOF1Point::GetModule(detUID) - 1;
170 pHit->SetModule(plane);
171 pHit->SetStation(str);
172 pHit->SetDetId(DetectorId(Idd));
173 FairRootManager::Instance()->SetUseFairLinks(kFALSE);
174}
175
177{
178 aTofHits->Compress();
179 return aTofHits->GetEntriesFast();
180}
181
182void BmnTof1HitProducerIdeal::Dump(const char* title, ostream& out) const
183{
184 out << "\n [BmnTof1HitProducerIdeal::Dump] ";
185 if (title)
186 out << title;
187 out << ", size= " << aTofHits->GetEntriesFast();
188
189 BmnTOF1Point* point;
190 BmnTofHit* pHit;
191 TVector3 hitPos, pointPos;
192
193 TIterator* iter = aTofHits->MakeIterator();
194 while ((pHit = (BmnTofHit*)iter->Next())) {
195 pHit->Position(hitPos);
196 out << "\n hit detUID = " << pHit->GetDetectorID() << ", hit pos(" << hitPos.X() << "," << hitPos.Y() << ","
197 << hitPos.Z() << "), ";
198 if (aMcPoints) {
199 point = (BmnTOF1Point*)aMcPoints->UncheckedAt(pHit->GetRefIndex());
200 point->Position(pointPos);
201 out << "\n point detUID = " << point->GetDetectorID() << ", point pos(" << pointPos.X() << ","
202 << pointPos.Y() << "," << pointPos.Z() << "), dev=" << (hitPos - pointPos).Mag();
203 }
204 }
205
206 delete iter;
207}
DetectorId
@ kTOF1
void SetModule(Int_t mod)
Definition BmnHit.h:73
void SetDetId(DetectorId det)
Definition BmnHit.h:65
void SetStation(Short_t st)
Definition BmnHit.h:69
Int_t GetModule() const
Int_t GetStrip() const
BmnTask.
Definition BmnTask.h:13
void Dump(const char *comment=nullptr, std::ostream &out=std::cout) const
void AddHit(Int_t detUID, const TVector3 &posHit, const TVector3 &posHitErr, Int_t pointIndex, Int_t trackIndex, Double_t time, Int_t Idd)
virtual void Exec(Option_t *option)
TClonesArray * aExpDigits
<— MC input
TClonesArray * aTofHits
<— The T0 time is stored in 'BmnTrigInfo.' branch in Run9
BmnTof1HitProducerIdeal(const char *name="TOF1 Ideal HitProducer", Bool_t useMCdata=true, Int_t verbose=1, Bool_t DoTest=false, Bool_t DoMergeHits=false)
TClonesArray * aMcTracks
<— MC input