#include "PixelTo3.h" #include "PixelTo3Point.h" #include "PixelTo3Geo.h" #include "PixelTo3GeoPar.h" #include "FairVolume.h" #include "FairGeoVolume.h" #include "FairGeoNode.h" #include "FairRootManager.h" #include "FairGeoLoader.h" #include "FairGeoInterface.h" #include "FairRun.h" #include "FairRuntimeDb.h" #include "PndDetectorList.h" #include "PndStack.h" #include "TClonesArray.h" #include "TVirtualMC.h" #include using std::cout; using std::endl; PixelTo3::PixelTo3() : FairDetector("PixelTo3", kTRUE, kPixelTo3), fTrackID(-1), fVolumeID(-1), fPos(), fMom(), fTime(-1.), fLength(-1.), fELoss(-1), fPixelTo3PointCollection(new TClonesArray("PixelTo3Point")) { } PixelTo3::PixelTo3(const char* name, Bool_t active) : FairDetector(name, active, kPixelTo3), fTrackID(-1), fVolumeID(-1), fPos(), fMom(), fTime(-1.), fLength(-1.), fELoss(-1), fPixelTo3PointCollection(new TClonesArray("PixelTo3Point")) { } PixelTo3::~PixelTo3() { if (fPixelTo3PointCollection) { fPixelTo3PointCollection->Delete(); delete fPixelTo3PointCollection; } } void PixelTo3::Initialize() { FairDetector::Initialize(); FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb(); PixelTo3GeoPar* par=(PixelTo3GeoPar*)(rtdb->getContainer("PixelTo3GeoPar")); } Bool_t PixelTo3::ProcessHits(FairVolume* vol) { /** This method is called from the MC stepping */ //Set parameters at entrance of volume. Reset ELoss. if ( gMC->IsTrackEntering() ) { fELoss = 0.; fTime = gMC->TrackTime() * 1.0e09; fLength = gMC->TrackLength(); gMC->TrackPosition(fPos); gMC->TrackMomentum(fMom); } // Sum energy loss for all steps in the active volume fELoss += gMC->Edep(); // Create PixelTo3Point at exit of active volume if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); fVolumeID = vol->getMCid(); if (fELoss == 0. ) { return kFALSE; } AddHit(fTrackID, fVolumeID, TVector3(fPos.X(), fPos.Y(), fPos.Z()), TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss); // Increment number of PixelTo3 det points in TParticle PndStack* stack = (PndStack*) gMC->GetStack(); stack->AddPoint(kPixelTo3); } return kTRUE; } void PixelTo3::EndOfEvent() { fPixelTo3PointCollection->Clear(); } void PixelTo3::Register() { /** This will create a branch in the output tree called PixelTo3Point, setting the last parameter to kFALSE means: this collection will not be written to the file, it will exist only during the simulation. */ FairRootManager::Instance()->Register("PixelTo3Point", "PixelTo3", fPixelTo3PointCollection, kTRUE); } TClonesArray* PixelTo3::GetCollection(Int_t iColl) const { if (iColl == 0) { return fPixelTo3PointCollection; } else { return NULL; } } void PixelTo3::Reset() { fPixelTo3PointCollection->Clear(); } void PixelTo3::ConstructGeometry() { /** If you are using the standard ASCII input for the geometry just copy this and use it for your detector, otherwise you can implement here you own way of constructing the geometry. */ FairGeoLoader* geoLoad = FairGeoLoader::Instance(); FairGeoInterface* geoFace = geoLoad->getGeoInterface(); PixelTo3Geo* Geo = new PixelTo3Geo(); Geo->setGeomFile(GetGeometryFileName()); geoFace->addGeoModule(Geo); Bool_t rc = geoFace->readSet(Geo); if (rc) { Geo->create(geoLoad->getGeoBuilder()); } TList* volList = Geo->getListOfVolumes(); // store geo parameter FairRun* fRun = FairRun::Instance(); FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb(); PixelTo3GeoPar* par=(PixelTo3GeoPar*)(rtdb->getContainer("PixelTo3GeoPar")); TObjArray* fSensNodes = par->GetGeoSensitiveNodes(); TObjArray* fPassNodes = par->GetGeoPassiveNodes(); TListIter iter(volList); FairGeoNode* node = NULL; FairGeoVolume* aVol=NULL; while( (node = (FairGeoNode*)iter.Next()) ) { aVol = dynamic_cast ( node ); if ( node->isSensitive() ) { fSensNodes->AddLast( aVol ); } else { fPassNodes->AddLast( aVol ); } } par->setChanged(); par->setInputVersion(fRun->GetRunId(),1); ProcessNodes ( volList ); } PixelTo3Point* PixelTo3::AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss) { TClonesArray& clref = *fPixelTo3PointCollection; Int_t size = clref.GetEntriesFast(); return new(clref[size]) PixelTo3Point(trackID, detID, pos, mom, time, length, eLoss); } ClassImp(PixelTo3)