BmnRoot
Loading...
Searching...
No Matches
BmnArmTrig.cxx
Go to the documentation of this file.
1#include <iostream>
2
3#include "TClonesArray.h"
4#include "TGeoMCGeometry.h"
5#include "TGeoManager.h"
6#include "TLorentzVector.h"
7#include "TParticle.h"
8#include "TVirtualMC.h"
9#include "TGeoArb8.h"
10
11#include "FairGeoInterface.h"
12#include "FairGeoLoader.h"
13#include "FairGeoNode.h"
14//#include "BmnArmTrigGeo.h"
15#include "FairGeoRootBuilder.h"
16#include "CbmStack.h"
17#include "BmnArmTrig.h"
18#include "BmnArmTrigPoint.h"
19
20#include "TVector3.h"
21#include "FairMCPoint.h"
22#include "FairRootManager.h"
23#include "FairVolume.h"
24// add on for debug
25//#include "FairGeoG3Builder.h"
26#include "FairRuntimeDb.h"
27#include "TObjArray.h"
28#include "FairRun.h"
29
30#include "TParticlePDG.h"
31
32// ----- Default constructor -------------------------------------------
33
35 fArmTrigCollection = new TClonesArray("BmnArmTrigPoint");
36 volDetector = 0;
37 fPosIndex = 0;
38 // fpreflag = 0;
39 //fpostflag = 0;
40 // fEventID=-1;
41 fVerboseLevel = 1;
42
43}
44// -------------------------------------------------------------------------
45
46// ----- Standard constructor ------------------------------------------
47
48BmnArmTrig::BmnArmTrig(const char* name, Bool_t active)
49: FairDetector(name, active) {
50 fArmTrigCollection = new TClonesArray("BmnArmTrigPoint");
51 fPosIndex = 0;
52 volDetector = 0;
53 //fpreflag = 0;
54 //fpostflag = 0;
55 //fEventID=-1;
56 fVerboseLevel = 1;
57}
58// -------------------------------------------------------------------------
59
60
61
62// ----- Destructor ----------------------------------------------------
63
65 if (fArmTrigCollection) {
66 fArmTrigCollection->Delete();
67 delete fArmTrigCollection;
68 }
69
70}
71// -------------------------------------------------------------------------
72
73// ----- Public method Intialize ---------------------------------------
74
76 // Init function
77
78 FairDetector::Initialize();
79 //FairRun* sim = FairRun::Instance();
80 //FairRuntimeDb* rtdb = sim->GetRuntimeDb();
81}
82// -------------------------------------------------------------------------
83
85 // Begin of the event
86
87}
88
89
90
91// ----- Public method ProcessHits --------------------------------------
92Bool_t BmnArmTrig::ProcessHits(FairVolume* vol) {
93
94 static Double_t timeIn;
95 static Double_t timeOut;
96 static Double_t lengthtrack;
97
98 Int_t ivol = vol->getMCid();
99
100 if (gMC->IsTrackEntering()) {
101
102 ResetParameters();
103
104 fELoss = 0.;
105 fIsPrimary = 0;
106 fCharge = -1;
107 fPdgId = 0;
108
109 lengthtrack = 0.;
110
111 TLorentzVector PosIn;
112 gMC->TrackPosition(PosIn);
113 fPosIn.SetXYZ(PosIn.X(), PosIn.Y(), PosIn.Z());
114
115 TLorentzVector MomIn;
116 gMC->TrackMomentum(MomIn);
117 fMomIn.SetXYZ(MomIn.Px(), MomIn.Py(), MomIn.Pz());
118
119 timeIn = gMC->TrackTime() * 1.0e09;
120
121 TParticle* part = 0;
122 part = gMC->GetStack()->GetCurrentTrack();
123
124 if (part) {
125 fIsPrimary = (Int_t) part->IsPrimary();
126 fCharge = (Int_t) part->GetPDG()->Charge() / 3.;
127 fPdgId = (Int_t) part->GetPdgCode();
128 }
129
130 }
131
132 Double_t eLoss = gMC->Edep();
133 if (eLoss > 0)
134 fELoss += eLoss;
135
136 Double_t slengthtrack = gMC-> TrackStep();
137 lengthtrack += slengthtrack;
138
139
140 if ((gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) && (fELoss > 0))
141 {
142 TLorentzVector PosOut;
143 gMC->TrackPosition(PosOut);
144 fPosOut.SetXYZ(PosOut.X(), PosOut.Y(), PosOut.Z());
145
146 TLorentzVector MomOut;
147 gMC->TrackMomentum(MomOut);
148 fMomOut.SetXYZ(MomOut.Px(), MomOut.Py(), MomOut.Pz());
149
150 timeOut = gMC->TrackTime() * 1.0e09;
151
152 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
153
154 Double_t time = gMC->TrackTime() * 1.0e09;
155 Double_t length = gMC->TrackLength();
156
157 Int_t copyNo = 0;
158
159 Int_t iCell;
160 gMC->CurrentVolOffID(1, iCell);
161
162 AddHit(fTrackID, ivol, copyNo, fPosIn, fPosOut,
163 fMomIn, fMomOut,
164 time, length, fELoss, fIsPrimary, fCharge, fPdgId, timeIn, timeOut, lengthtrack);
165
166 ((CbmStack*) gMC->GetStack())->AddPoint(kARMTRIG);
167
168 }
169
170 return kTRUE;
171}
172
173// ----- Public method EndOfEvent -----------------------------------------
174
176 if (fVerboseLevel) Print("");
177 Reset();
178}
179
180// ----- Public method Register -------------------------------------------
181
183 FairRootManager::Instance()->Register("ArmTrigPoint", "ArmTrig", fArmTrigCollection, kTRUE);
184}
185
186// ----- Public method GetCollection --------------------------------------
187
188TClonesArray* BmnArmTrig::GetCollection(Int_t iColl) const {
189 if (iColl == 0) return fArmTrigCollection;
190
191 return NULL;
192}
193
194// ----- Public method Print ----------------------------------------------
195
196void BmnArmTrig::Print(Option_t*) const {
197 Int_t nHits = fArmTrigCollection->GetEntriesFast();
198 cout << "-I- BmnArmTrig: " << nHits << " points registered in this event."
199 << endl;
200
201 if (fVerboseLevel > 1)
202 for (Int_t i = 0; i < nHits; i++) (*fArmTrigCollection)[i]->Print();
203}
204
205
206// ----- Public method Reset ----------------------------------------------
207
209 fArmTrigCollection->Delete();
210
211 fPosIndex = 0;
212}
213
214// guarda in FairRootManager::CopyClones
215// ----- Public method CopyClones -----------------------------------------
216
217void BmnArmTrig::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
218 Int_t nEntries = cl1->GetEntriesFast();
219 //cout << "-I- BmnArmTrig: " << nEntries << " entries to add." << endl;
220 TClonesArray& clref = *cl2;
221 BmnArmTrigPoint* oldpoint = NULL;
222 for (Int_t i = 0; i < nEntries; i++) {
223 oldpoint = (BmnArmTrigPoint*) cl1->At(i);
224 Int_t index = oldpoint->GetTrackID() + offset;
225 oldpoint->SetTrackID(index);
226 new (clref[fPosIndex]) BmnArmTrigPoint(*oldpoint);
227 fPosIndex++;
228 }
229 cout << " -I- BmnArmTrig: " << cl2->GetEntriesFast() << " merged entries."
230 << endl;
231}
232
233//--------------------------------------------------------------------------------------------------------------------------------------
234
236 TString fileName = GetGeometryFileName();
237
238 cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << fileName << endl;
239
240 if (fileName.EndsWith(".root")) {
241 LOG(info) << "Constructing ArmTrig geometry from ROOT file " << fileName.Data();
242 ConstructRootGeometry();
243 } else if (fileName.EndsWith(".geo")) {
244 LOG(info) << "Constructing ArmTrig geometry from ASCII file " << fileName.Data();
246 } else LOG(fatal) << "Geometry format of ArmTrig file " << fileName.Data() << " not supported.";
247}
248//--------------------------------------------------------------------------------------------------------------------------------------
249
251// FairGeoLoader* geoLoad = FairGeoLoader::Instance();
252// FairGeoInterface* geoFace = geoLoad->getGeoInterface();
253// BmnArmTrigGeo* ArmTrigGeo = new BmnArmTrigGeo();
254// ArmTrigGeo->setGeomFile(GetGeometryFileName());
255// geoFace->addGeoModule(ArmTrigGeo);
256//
257// Bool_t rc = geoFace->readSet(ArmTrigGeo);
258// if (rc) ArmTrigGeo->create(geoLoad->getGeoBuilder());
259// TList* volList = ArmTrigGeo->getListOfVolumes();
260//
261// // store geo parameter
262// FairRun *fRun = FairRun::Instance();
263// FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
264// BmnArmTrigGeoPar* par = (BmnArmTrigGeoPar*) (rtdb->getContainer("BmnArmTrigGeoPar"));
265// TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
266// TObjArray *fPassNodes = par->GetGeoPassiveNodes();
267//
268// TListIter iter(volList);
269// FairGeoNode *node = nullptr;
270// FairGeoVolume *aVol = nullptr;
271//
272// while ((node = (FairGeoNode*) iter.Next())) {
273// aVol = dynamic_cast<FairGeoVolume*> (node);
274//
275// if (node->isSensitive()) fSensNodes->AddLast(aVol);
276// else fPassNodes->AddLast(aVol);
277// }
278//
279// par->setChanged();
280// par->setInputVersion(fRun->GetRunId(), 1);
281// ProcessNodes(volList);
282}
283
284//--------------------------------------------------------------------------------------------------------------------------------------
285
286Bool_t BmnArmTrig::CheckIfSensitive(std::string name) {
287 TString tsname = name;
288 if (tsname.Contains("Active")) return kTRUE;
289
290 return kFALSE;
291}
292//-------------------------------------------------------------------------
293
294// ----- Private method AddHit --------------------------------------------
295
296BmnArmTrigPoint* BmnArmTrig::AddHit(Int_t trackID, Int_t detID, Int_t copyNo, TVector3 posIn, TVector3 posOut,
297 TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Bool_t isPrimary,
298 Double_t charge, Int_t pdgId, Double_t timeIn, Double_t timeOut, Double_t lengthtrack) {
299
300 TClonesArray& clref = *fArmTrigCollection;
301 Int_t size = clref.GetEntriesFast();
302 return new(clref[size]) BmnArmTrigPoint(trackID, detID, copyNo, posIn, posOut, momIn, momOut, time, length, eLoss, isPrimary,
303 charge, pdgId, timeIn, timeOut, lengthtrack);
304}
int i
Definition P4_F32vec4.h:22
@ kARMTRIG
virtual Bool_t CheckIfSensitive(std::string name)
virtual void BeginEvent()
virtual void Reset()
virtual void Initialize()
virtual void Register()
BmnArmTrigPoint * AddHit(Int_t trackID, Int_t detID, Int_t copyNo, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t tof, Double_t length, Double_t eLoss, Bool_t isPrimary, Double_t charge, Int_t pdgId, Double_t timeIn, Double_t timeOut, Double_t lengthtrack)
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
virtual void ConstructAsciiGeometry()
virtual Bool_t ProcessHits(FairVolume *vol=0)
virtual void ConstructGeometry()
virtual void EndOfEvent()
virtual ~BmnArmTrig()
virtual void Print(Option_t *) const
virtual TClonesArray * GetCollection(Int_t iColl) const