16#include "TClonesArray.h"
17#include "TGeoMCGeometry.h"
18#include "TGeoManager.h"
19#include "TLorentzVector.h"
21#include "TVirtualMC.h"
24#include "FairGeoInterface.h"
25#include "FairGeoLoader.h"
26#include "FairGeoNode.h"
28#include "FairGeoRootBuilder.h"
34#include "FairRootManager.h"
35#include "FairVolume.h"
38#include "FairRuntimeDb.h"
42#include "TParticlePDG.h"
46 fNdetCollection =
new TClonesArray(
"BmnNdetPoint");
61 : FairDetector(
name, active) {
62 fNdetCollection =
new TClonesArray(
"BmnNdetPoint");
76 if (fNdetCollection) {
77 fNdetCollection->Delete();
78 delete fNdetCollection;
87 FairDetector::Initialize();
88 FairRun* sim = FairRun::Instance();
89 FairRuntimeDb* rtdb=sim->GetRuntimeDb();
91 fVSCVolId = gMC->VolId(
"ndet01s");
92 fVSCNICAVolId = gMC->VolId(
"ndet01s_NICA");
93 fVSCVETOVolId = gMC->VolId(
"ndet01s_VETO");
98 Double_t modX[nbMods], modY[nbMods], sectZ[nbSect];
101 for (
int i = 0;
i < nbMods;
i++) { modX[
i] = -10000; modY[
i] = -10000; }
103 if (!(fMappingFile_modules ==
"nofile")) {
108 TString dir = getenv(
"VMCWORKDIR");
109 TString path = dir +
"/input/";
110 in.open((path + fMappingFile_modules).Data());
113 printf(
"Loading nDet modules Map from file: %s - file open error!\n", fMappingFile_modules.Data());
117 printf(
"Loading nDet modules Map from file: %s\n", fMappingFile_modules.Data());
118 in >> dummy >> dummy >> dummy;
123 if (!in.good())
break;
124 printf(
"%d %f %f\n",
id,x,y);
134 for (
int i = 0;
i <nbSect;
i++) { sectZ[
i] = -10000; }
136 if (!(fMappingFile_sections ==
"nofile")) {
141 TString dir = getenv(
"VMCWORKDIR");
142 TString path = dir +
"/input/";
143 in.open((path + fMappingFile_sections).Data());
146 printf(
"Loading nDet sections Map from file: %s - file open error!\n", fMappingFile_sections.Data());
150 printf(
"Loading nDet sections_Map from file: %s\n", fMappingFile_sections.Data());
151 in >> dummy >> dummy;
156 if (!in.good())
break;
157 printf(
"%d %f\n",
id,z);
165 for (Int_t im=0; im<nbMods; im++) {
166 for (Int_t iv=0; iv<nbSect; iv++) {
167 scintPos_X[im][iv] = modX[im+1];
168 scintPos_Y[im][iv] = modY[im+1];
169 scintPos_Z[im][iv] = sectZ[iv+1];
173 for (Int_t im=0; im<nbMods; im++) {
174 for (Int_t iv=0; iv<nbSect; iv++) {
175 if(iv==0) cout <<
"MODULE " <<im+1 <<
" " <<scintPos_X[im][iv] <<
" " <<scintPos_Y[im][iv] <<endl;
176 cout <<scintPos_Z[im][iv] <<
" ";
189 for (Int_t
i=0;
i<70;
i++)
191 for (Int_t ii=0; ii<1000; ii++)
192 fTofArray[
i][ii] = 100000;
212 Int_t nofHits = fNdetCollection->GetEntriesFast();
213 for (Int_t
i=0;
i<nofHits;
i++) {
219 if(hit->GetCopy() == vsc && hit->GetCopyMother() == mod)
226BmnNdetPoint* BmnNdet::GetHitPrint(Int_t vsc, Int_t mod)
const
232 Int_t nofHits = fNdetCollection->GetEntriesFast();
234 for (Int_t
i=0;
i<nofHits;
i++) {
236 if(hit->GetCopy() == vsc && hit->GetCopyMother() == mod)
237 cout <<
"GetHitPrint method " <<hit->GetCopyMother() <<
" " <<hit->GetCopy() <<
" " <<hit->GetEnergyLoss() <<
" " <<hit->GetZ() <<endl;
247 Int_t copyNoVSC,copyNoVTYVEC,copyNoVMOD,copyNoVZDC;
248 Int_t copyNoVSCNICA,copyNoVTYVECNICA,copyNoVMODNICA,copyNoVZDCNICA;
249 Int_t copyNoVSCVETO,copyNoVTYVECVETO,copyNoVMODVETO,copyNoVZDCVETO;
250 Int_t copyNoVSCCom,copyNoVTYVECCom,copyNoVMODCom,copyNoVZDCCom;
253 TLorentzVector tPos1, tMom1;
254 TLorentzVector tPos, tMom;
256 Int_t module, module_nica;
257 Int_t slice, slice_nica;
266 Double_t timeCut = 55;
268 Double_t BirkConst = 12.6;
273 static Int_t lEDEBUGcounter=0;
274 if (lEDEBUGcounter<1)
275 std::cout <<
"EDEBUG-- BmnNdet::ProcessHits: entered" << gMC->CurrentVolPath() << endl;
278 if (gMC->CurrentVolID(copyNoVSC) != fVSCVolId &&
279 gMC->CurrentVolID(copyNoVSCNICA) != fVSCNICAVolId &&
280 gMC->CurrentVolID(copyNoVSCVETO) != fVSCVETOVolId) {
284 ivol = vol->getMCid();
286 fEventID = gMC->CurrentEvent();
288 if (gMC->CurrentVolID(copyNoVSC) == fVSCVolId || gMC->CurrentVolID(copyNoVSCNICA) == fVSCNICAVolId || gMC->CurrentVolID(copyNoVSCVETO) == fVSCVETOVolId) {
289 gMC->CurrentVolOffID(0, slice);
290 gMC->CurrentVolOffID(1, module);
291 copyNoVTYVECCom = slice; copyNoVMODCom =
module;
295 if (gMC->IsTrackEntering()) {
301 gMC->TrackPosition(tPos);
302 gMC->TrackMomentum(tMom);
304 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
305 part = gMC->GetStack()->GetCurrentTrack();
309 gMC->TrackPosition(tPos1);
310 gMC->TrackMomentum(tMom1);
315 if ( gMC->IsTrackInside()) {
317 gMC->TrackPosition(tPos);
318 gMC->TrackMomentum(tMom);
322 time = gMC->TrackTime() * 1.0e09;
329 if(gMC->TrackStep()>0) QCF = 1.+(BirkConst/gMC->TrackStep())*gMC->Edep();
331 fELoss +=(gMC->Edep())/QCF;
334 part = gMC->GetStack()->GetCurrentTrack();
336 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
342 if(gMC->TrackTime() * 1.0e09 < fTofArray[slice][module]) fTofArray[slice][module] = gMC->TrackTime() * 1.0e09;
347 if ( gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) {
349 part = gMC->GetStack()->GetCurrentTrack();
350 charge = part->GetPDG()->Charge() / 3. ;
353 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
370 if(copyNoVTYVECCom==slice && copyNoVMODCom==module) {
373 AddHit(fTrackID, ivol, slice, module, TVector3(scintPos_X[module-1][slice-1], scintPos_Y[module-1][slice-1], scintPos_Z[module-1][slice-1]),TVector3(tMom.Px(), tMom.Py(), tMom.Pz()), fTofArray[slice][module], length, fELoss, fEventID );
387 if ( gMC->IsTrackExiting()) {
389 gMC->TrackPosition(tPos);
390 gMC->TrackMomentum(tMom);
391 part = gMC->GetStack()->GetCurrentTrack();
392 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
396 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
398 time = gMC->TrackTime() * 1.0e09;
405 if(gMC->TrackTime() * 1.0e09 < fTofArray[slice][module]) fTofArray[slice][module] = gMC->TrackTime() * 1.0e09;
412 if(gMC->TrackStep()>0) QCF = 1.+(BirkConst/gMC->TrackStep())*gMC->Edep();
414 fELoss +=(gMC->Edep())/QCF;
431 if(copyNoVTYVECCom==slice && copyNoVMODCom==module) {
434 AddHit(fTrackID, ivol, slice, module, TVector3(scintPos_X[module-1][slice-1], scintPos_Y[module-1][slice-1], scintPos_Z[module-1][slice-1]),TVector3(tMom.Px(), tMom.Py(), tMom.Pz()), fTofArray[slice][module], length, fELoss, fEventID );
447 Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1);
449 points = ( points & ( ~ (1<<30) ) ) | (1 << 30);
451 gMC->GetStack()->GetCurrentTrack()->SetMother(1,points);
461 if (fVerboseLevel)
Print();
468 FairRootManager::Instance()->Register(
"NdetPoint",
"Ndet", fNdetCollection, kTRUE);
473 if (iColl == 0)
return fNdetCollection;
480 Int_t nHits = fNdetCollection->GetEntriesFast();
481 cout <<
"-I- BmnNdet: " << nHits <<
" points registered in this event."
485 for (Int_t
i=0;
i<nHits;
i++) (*fNdetCollection)[
i]->Print();
490 fNdetCollection->Delete();
497void BmnNdet::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) {
498 Int_t nEntries = cl1->GetEntriesFast();
500 TClonesArray& clref = *cl2;
502 for (Int_t
i=0;
i<nEntries;
i++) {
504 Int_t index = oldpoint->GetTrackID() + offset;
505 oldpoint->SetTrackID(index);
509 cout <<
" -I- BmnNdet: " << cl2->GetEntriesFast() <<
" merged entries."
516 TString fileName = GetGeometryFileName();
517 if(fileName.EndsWith(
".root"))
519 FairLogger::GetLogger()->Info(MESSAGE_ORIGIN,
"Constructing NDET geometry from ROOT file %s", fileName.Data());
520 ConstructRootGeometry();
531 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
532 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
534 ndetGeo->setGeomFile(GetGeometryFileName());
535 geoFace->addGeoModule(ndetGeo);
537 Bool_t rc = geoFace->readSet(ndetGeo);
538 if (rc) ndetGeo->create(geoLoad->getGeoBuilder());
539 TList* volList = ndetGeo->getListOfVolumes();
542 FairRun *fRun = FairRun::Instance();
543 FairRuntimeDb *rtdb= FairRun::Instance()->GetRuntimeDb();
548 TListIter iter(volList);
549 FairGeoNode* node = NULL;
550 FairGeoVolume *aVol=NULL;
552 while( (node = (FairGeoNode*)iter.Next()) ) {
553 aVol =
dynamic_cast<FairGeoVolume*
> ( node );
556 if ( node->isSensitive() ) {
557 fSensNodes->AddLast( aVol );
559 fPassNodes->AddLast( aVol );
563 par->setInputVersion(fRun->GetRunId(),1);
565 ProcessNodes ( volList );
570 TString tsname =
name;
571 if (tsname.Contains(
"ndet01s") || tsname.Contains(
"ndet01s_NICA") || tsname.Contains(
"ndet01s_VETO")) {
579BmnNdetPoint*
BmnNdet::AddHit(Int_t trackID, Int_t detID, Int_t copyNo, Int_t copyNoMother, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss, UInt_t EventId) {
580 TClonesArray& clref = *fNdetCollection;
581 Int_t size = clref.GetEntriesFast();
584 return new(clref[size])
BmnNdetPoint(trackID, detID, copyNo, copyNoMother, pos, mom, time, length, eLoss, EventId);
TObjArray * GetGeoSensitiveNodes()
TObjArray * GetGeoPassiveNodes()
virtual Bool_t ProcessHits(FairVolume *vol=nullptr)
virtual void EndOfEvent()
BmnNdetPoint * AddHit(BmnNdetPoint *point)
virtual TClonesArray * GetCollection(Int_t iColl) const
virtual Bool_t CheckIfSensitive(std::string name)
virtual void ConstructGeometry()
BmnNdetPoint * GetHit(int trackID, uint32_t address)
virtual void Initialize()
virtual void BeginEvent()
virtual void Print(Option_t *) const