BmnRoot
Loading...
Searching...
No Matches
BmnSiMD.cxx
Go to the documentation of this file.
1#include <iostream>
2
3#include "TGeoMCGeometry.h"
4#include "TGeoManager.h"
5#include "TGeoArb8.h"
6#include "TObjArray.h"
7#include "TParticlePDG.h"
8
9#include "FairGeoInterface.h"
10#include "FairGeoLoader.h"
11#include "FairGeoNode.h"
12#include "FairGeoRootBuilder.h"
13#include "FairMCPoint.h"
14#include "FairRootManager.h"
15#include "FairVolume.h"
16// add on for debug
17//#include "FairGeoG3Builder.h"
18#include "FairRuntimeDb.h"
19#include "FairRun.h"
20
21#include "BmnSiMDGeo.h"
22#include "BmnSiMD.h"
23#include "CbmStack.h"
24
25
26// ----- Default constructor -------------------------------------------
28 fSiMDCollection = new TClonesArray("BmnSiMDPoint");
29 volDetector = 0;
30 fPosIndex = 0;
31 // fpreflag = 0;
32 //fpostflag = 0;
33 // fEventID=-1;
34 fVerboseLevel = 1;
35}
36
37// ----- Standard constructor ------------------------------------------
38BmnSiMD::BmnSiMD(const char* name, Bool_t active)
39 : FairDetector(name, active) {
40 fSiMDCollection = new TClonesArray("BmnSiMDPoint");
41 fPosIndex = 0;
42 volDetector = 0;
43 //fpreflag = 0;
44 //fpostflag = 0;
45 //fEventID=-1;
46 fVerboseLevel = 1;
47}
48
49// ----- Destructor ----------------------------------------------------
51 if (fSiMDCollection) {
52 fSiMDCollection->Delete();
53 delete fSiMDCollection;
54 }
55
56}
57
58
59// ----- Public method Intialize ---------------------------------------
61 // Init function
62
63 FairDetector::Initialize();
64 //FairRun* sim = FairRun::Instance();
65 //FairRuntimeDb* rtdb=sim->GetRuntimeDb();
66}
67// -------------------------------------------------------------------------
69 // Begin of the event
70}
71
72// ----- Public method ProcessHits --------------------------------------
73Bool_t BmnSiMD::ProcessHits(FairVolume* vol) {
74
75 // if (TMath::Abs(gMC->TrackCharge()) <= 0) return kFALSE;
76
77 //static const Double_t dP = 1.032;
78 //static const Double_t BirkC1 = 0.013/dP;
79 //static const Double_t BirkC2 = 9.6e-6/(dP * dP);
80
81 //static Double_t lightYield;
82 static Double_t timeIn;
83 static Double_t timeOut;
84 static Double_t lengthtrack;
85 //static Double_t de_dx;
86
87
88 Int_t ivol = vol->getMCid();
89 //TLorentzVector tPos1, tMom1;
90 //TLorentzVector tPos, tMom;
91
92
93
94 //#define EDEBUG
95#ifdef EDEBUG
96 static Int_t lEDEBUGcounter=0;
97 if (lEDEBUGcounter<1)
98 std::cout << "EDEBUG-- BmnSiMD::ProcessHits: entered" << gMC->CurrentVolPath() << endl;
99#endif
100
101 if(gMC->IsTrackEntering()){
102
103 ResetParameters();
104
105 fELoss = 0.;
106 fIsPrimary = 0;
107 fCharge = -1;
108 fPdgId = 0;
109
110 lengthtrack = 0.;
111
112 TLorentzVector PosIn;
113 gMC->TrackPosition(PosIn);
114 fPosIn.SetXYZ(PosIn.X(), PosIn.Y(), PosIn.Z());
115
116 TLorentzVector MomIn;
117 gMC->TrackMomentum(MomIn);
118 fMomIn.SetXYZ(MomIn.Px(), MomIn.Py(), MomIn.Pz());
119
120 timeIn = gMC->TrackTime() * 1.0e09;
121
122
123
124#ifdef EDEBUG
125 //gMC->TrackPosition(tPos1);
126 //gMC->TrackMomentum(tMom1);
127#endif
128
129 TParticle* part = 0;
130 part = gMC->GetStack()->GetCurrentTrack();
131
132 if (part) {
133 fIsPrimary = (Int_t)part->IsPrimary();
134 fCharge = (Int_t)part->GetPDG()->Charge() / 3.;
135 fPdgId = (Int_t)part->GetPdgCode();
136 }
137
138 }
139
140
141
142 Double_t eLoss = gMC->Edep();
143 if (eLoss > 0)
144 fELoss += eLoss;
145
146 Double_t slengthtrack = gMC-> TrackStep();
147 lengthtrack += slengthtrack;
148
149 if ((gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) && (fELoss > 0))
150 {
151 TLorentzVector PosOut;
152 gMC->TrackPosition(PosOut);
153 fPosOut.SetXYZ(PosOut.X(), PosOut.Y(), PosOut.Z());
154
155 TLorentzVector MomOut;
156 gMC->TrackMomentum(MomOut);
157 fMomOut.SetXYZ(MomOut.Px(), MomOut.Py(), MomOut.Pz());
158
159 timeOut = gMC->TrackTime() * 1.0e09;
160 /*
161 TArrayI processesID;
162
163 ofstream fout("process_SID.txt", ios::app);
164
165 //if (gMC->TrackPid() == 11 && gMC->Etot() <= 0.00006){
166
167 gMC->StepProcesses(processesID);
168 fout << gMC->TrackPid() << " " << gMC->Edep() << " " ;
169 for (Int_t i = 0; i<processesID.GetSize(); i++){
170
171 fout << TMCProcessName[processesID[i]] << " ";
172 }
173 fout << endl;
174
175 //fout<<" "<<gMC->TrackPid() <<" " <<gMC->Edep()<<" "<< TMCProcessName[processesID[i]]<<endl;
176 fout.close();
177*/
178
179#ifndef EDEBUG
180
181 if (fELoss == 0. ) return kFALSE;
182
183#endif
184
185 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
186
187 Double_t time = gMC->TrackTime() * 1.0e09;
188 Double_t length = gMC->TrackLength();
189
190 Int_t copyNo;
191 /*Int_t ivol1 = */gMC->CurrentVolID(copyNo);
192
193 Int_t iCell ;
194 gMC->CurrentVolOffID(1, iCell);
195
196
197#ifdef EDEBUG
198 if (lEDEBUGcounter<100) {
199 std::cout << "EDEBUG-- BmnSiMD::ProcessHits: TrackID:" << fTrackID <<
200 // " ELoss: " << fELoss <<
201 // " particle: " << (part->GetName()) <<
202 " " << gMC->CurrentVolPath() << " " << tPos.Z() <<
203 // " " << (gMC->GetStack()->GetCurrentTrack()->GetMother(1)) <<
204 " " << ivol << "=="<< gMC->CurrentVolID(copyNo) << ","<< copyNo <<
205 " " << gMC->CurrentVolOffID(1,iCell) << " " << iCell <<
206 " " << gMC->CurrentVolOffName(1) << " " << gMC->CurrentVolOffName(0) <<
207 // " " << vol->getRealName() << " " << gMC->CurrentVolPath() <<
208 // " ivol,iCell,copyNo= " << ivol << ","<< iCell << ","<< copyNo <<
209 // " " << vol->getRealName() << " "<< gMC->CurrentVolName() << " "<< gMC->CurrentVolPath() <<
210 // " " << ivol << ","<< vol->getVolumeId() << " : "<< gMC->CurrentVolID(copyNo) << ","<< copyNo <<
211 // " "<< gMC->CurrentVolOffName(2) << " "<< gMC->CurrentVolOffName(3) <<
212 std::endl;
213 lEDEBUGcounter++;
214 }
215
216 AddHit(fTrackID, ivol, copyNo, fPosIn, fPosOut,
217 fMomIn, fMomOut,
218 time, length, fELoss, fIsPrimary, fCharge, fPdgId, timeIn, timeOut, lengthtrack);
219#else
220
221 AddHit(fTrackID, ivol, copyNo, fPosIn, fPosOut,
222 fMomIn, fMomOut,
223 time, length, fELoss, fIsPrimary, fCharge, fPdgId, timeIn, timeOut, lengthtrack);
224#endif
225
227 // Int_t nBdPoints = (points & (1<<30)) >> 30;
228 // nBdPoints ++;
229 // if (nBdPoints > 1) nBdPoints = 1;
230 // points = ( points & ( ~ (1<<30) ) ) | (nBdPoints << 30);
233
234 ((CbmStack*)gMC->GetStack())->AddPoint(kSiMD);
235
236 }
237
238 return kTRUE;
239
240#undef EDEBUG
241}
242
243// ----- Public method EndOfEvent -----------------------------------------
245 if (fVerboseLevel) Print("");
246 Reset();
247}
248
249// ----- Public method Register -------------------------------------------
251 FairRootManager::Instance()->Register("SiMDPoint","SiMD", fSiMDCollection, kTRUE);
252}
253
254// ----- Public method GetCollection --------------------------------------
255TClonesArray* BmnSiMD::GetCollection(Int_t iColl) const {
256 if (iColl == 0) return fSiMDCollection;
257
258 return NULL;
259}
260
261// ----- Public method Print ----------------------------------------------
262void BmnSiMD::Print(Option_t*) const {
263 Int_t nHits = fSiMDCollection->GetEntriesFast();
264 cout << "-I- BmnSiMD: " << nHits << " points registered in this event."
265 << endl;
266
267 if (fVerboseLevel>1)
268 for (Int_t i=0; i<nHits; i++) (*fSiMDCollection)[i]->Print();
269}
270
271
272// ----- Public method Reset ----------------------------------------------
274 fSiMDCollection->Delete();
275
276 fPosIndex = 0;
277}
278
279// guarda in FairRootManager::CopyClones
280// ----- Public method CopyClones -----------------------------------------
281void BmnSiMD::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) {
282 Int_t nEntries = cl1->GetEntriesFast();
283 //cout << "-I- BmnSiMD: " << nEntries << " entries to add." << endl;
284 TClonesArray& clref = *cl2;
285 BmnSiMDPoint* oldpoint = NULL;
286 for (Int_t i=0; i<nEntries; i++) {
287 oldpoint = (BmnSiMDPoint*) cl1->At(i);
288 Int_t index = oldpoint->GetTrackID() + offset;
289 oldpoint->SetTrackID(index);
290 new (clref[fPosIndex]) BmnSiMDPoint(*oldpoint);
291 fPosIndex++;
292 }
293 cout << " -I- BmnSiMD: " << cl2->GetEntriesFast() << " merged entries."
294 << endl;
295}
296
297//--------------------------------------------------------------------------------------------------------------------------------------
299{
300 TString fileName = GetGeometryFileName();
301 if(fileName.EndsWith(".root"))
302 {
303 LOG(info) << "Constructing SiMD geometry from ROOT file " << fileName.Data();
304 ConstructRootGeometry();
305 }
306 else if ( fileName.EndsWith(".geo") )
307 {
308 LOG(info) << "Constructing SiMD geometry from ASCII file " << fileName.Data();
310 }
311 else LOG(fatal) << "Geometry format of SiMD file " << fileName.Data() << " not supported.";
312}
313//--------------------------------------------------------------------------------------------------------------------------------------
315{
316 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
317 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
318 BmnSiMDGeo* SiMDGeo = new BmnSiMDGeo();
319 SiMDGeo->setGeomFile(GetGeometryFileName());
320 geoFace->addGeoModule(SiMDGeo);
321
322 Bool_t rc = geoFace->readSet(SiMDGeo);
323 if (rc) SiMDGeo->create(geoLoad->getGeoBuilder());
324 TList* volList = SiMDGeo->getListOfVolumes();
325
326 // store geo parameter
327 FairRun *fRun = FairRun::Instance();
328 FairRuntimeDb *rtdb = FairRun::Instance()->GetRuntimeDb();
329 BmnSiMDGeoPar* par = (BmnSiMDGeoPar*)(rtdb->getContainer("BmnSiMDGeoPar"));
330 TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
331 TObjArray *fPassNodes = par->GetGeoPassiveNodes();
332
333 TListIter iter(volList);
334 FairGeoNode *node = nullptr;
335 FairGeoVolume *aVol = nullptr;
336
337 while( (node = (FairGeoNode*)iter.Next()) )
338 {
339 aVol = dynamic_cast<FairGeoVolume*>(node);
340
341 if(node->isSensitive()) fSensNodes->AddLast(aVol);
342 else fPassNodes->AddLast(aVol);
343 }
344
345 par->setChanged();
346 par->setInputVersion(fRun->GetRunId(),1);
347 ProcessNodes( volList );
348}
349
350//--------------------------------------------------------------------------------------------------------------------------------------
351Bool_t BmnSiMD::CheckIfSensitive(std::string name)
352{
353 TString tsname = name;
354 if (tsname.Contains("Active")) return kTRUE;
355
356 return kFALSE;
357}
358//-------------------------------------------------------------------------
359
360// ----- Private method AddHit --------------------------------------------
361BmnSiMDPoint* BmnSiMD::AddHit( Int_t trackID, Int_t detID, Int_t copyNo, TVector3 posIn, TVector3 posOut,
362 TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Bool_t isPrimary,
363 Double_t charge, Int_t pdgId, Double_t timeIn, Double_t timeOut, Double_t lengthtrack)
364{
365 TClonesArray& clref = *fSiMDCollection;
366 Int_t size = clref.GetEntriesFast();
367 return new(clref[size]) BmnSiMDPoint(trackID, detID, copyNo, posIn, posOut, momIn, momOut, time, length, eLoss, isPrimary,
368 charge, pdgId, timeIn, timeOut, lengthtrack);
369}
int i
Definition P4_F32vec4.h:22
@ kSiMD
TObjArray * GetGeoSensitiveNodes()
TObjArray * GetGeoPassiveNodes()
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition BmnSiMD.cxx:281
BmnSiMDPoint * 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)
Definition BmnSiMD.cxx:361
virtual void Print(Option_t *) const
Definition BmnSiMD.cxx:262
virtual void Reset()
Definition BmnSiMD.cxx:273
virtual Bool_t CheckIfSensitive(std::string name)
Definition BmnSiMD.cxx:351
BmnSiMD()
Definition BmnSiMD.cxx:27
virtual ~BmnSiMD()
Definition BmnSiMD.cxx:50
virtual void ConstructAsciiGeometry()
Definition BmnSiMD.cxx:314
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition BmnSiMD.cxx:255
virtual void Initialize()
Definition BmnSiMD.cxx:60
virtual void EndOfEvent()
Definition BmnSiMD.cxx:244
virtual void ConstructGeometry()
Definition BmnSiMD.cxx:298
virtual void BeginEvent()
Definition BmnSiMD.cxx:68
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition BmnSiMD.cxx:73
virtual void Register()
Definition BmnSiMD.cxx:250