#include #include "TClonesArray.h" #include "TLorentzVector.h" #include "TMath.h" #include "TFile.h" #include "TSystem.h" #include "TParticle.h" #include "TGeoMaterial.h" #include "TGeoMedium.h" #include "TGeoArb8.h" #include "TGeoTrd2.h" #include "TGeoMatrix.h" #include "TGeoManager.h" #include "TVirtualMC.h" #include "FairVolume.h" // add on for debug #include "FairRuntimeDb.h" #include "FairRun.h" #include "FairModule.h" #include "PndDetectorList.h" #include "PndStack.h" #include "PndMdt.h" using namespace std; Int_t PndMdt::fTrkIn = -1; TLorentzVector PndMdt::fPos_In; TLorentzVector PndMdt::fMom_In; // ----- Default constructor ------------------------------------------- PndMdt::PndMdt() { fMdtCollection = new TClonesArray("PndMdtPoint"); fPosIndex = 0; fTrkIn = -1; ResetParameters(); SetVerbosity(kFALSE); fBarrel = ""; fEndcap = ""; fMuonFilter = ""; fForward = ""; mdtMagnet = kFALSE; mdtMFI = kFALSE; mdtCoil = kFALSE; } // ------------------------------------------------------------------------- // ----- Inherited constructor ----------------------------------------- PndMdt::PndMdt(const char* name, Bool_t active) : FairDetector(name,active) { fMdtCollection = new TClonesArray("PndMdtPoint"); fPosIndex = 0; fTrkIn = -1; ResetParameters(); SetVerbosity(kFALSE); fBarrel = ""; fEndcap = ""; fMuonFilter = ""; fForward = ""; mdtMagnet = kFALSE; mdtMFI = kFALSE; mdtCoil = kFALSE; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- PndMdt::~PndMdt() { if (fMdtCollection) { fMdtCollection->Delete(); delete fMdtCollection; }; } // ------------------------------------------------------------------------- // ----- Public method Print ---------------------------------------------- void PndMdt::Print() const { Int_t nHits = fMdtCollection->GetEntriesFast(); for (Int_t i=0; iPrint(); } // ---------------------------------------------------------------------------- // ----- Public method Reset ---------------------------------------------- void PndMdt::Reset() { fMdtCollection->Delete(); fPosIndex = 0; } // ---------------------------------------------------------------------------- // ----- Public method CopyClones ----------------------------------------- void PndMdt::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) { /* Int_t nEntries = cl1->GetEntriesFast(); TClonesArray& clref = *cl2; PndMdtPoint* oldpoint = NULL; for (Int_t i=0; iAt(i); Int_t index = oldpoint->GetTrackID() + offset; oldpoint->SetTrackID(index); new (clref[fPosIndex]) PndMdtPoint(*oldpoint); fPosIndex++; } cout << " -I- PndMdt: " << cl2->GetEntriesFast() << " merged entries." << endl; */ } // ---------------------------------------------------------------------------- // ----- Public method ResetParameters ------------------------------------ void PndMdt::ResetParameters() { /* fEventID = -999; fTrackID = -999; fTrackParentID = -999; fDetectorID = -999; fPDG = -999; */ fELoss = 0.; fPos.SetXYZT(0., 0., 0., 0.); fMom.SetXYZT(0., 0., 0., 0.) ; } // ---------------------------------------------------------------------------- // ----- Public method SetParFile -------------------------------------- void PndMdt::SetParFile(TString filename) { ffn = filename; } // ------------------------------------------------------------------------- // ----- Public method ConstructGeometry ---------------------------------- void PndMdt::ConstructGeometry() { TString sysFile = gSystem->Getenv("VMCWORKDIR"); if (fBarrel!="") { if (fBarrel=="fast" || fBarrel =="Fast") { ConstructGeometryFast(); } else if (fBarrel.EndsWith(".root")) { SetGeometryFileName(fBarrel); ConstructRootGeometry(); } else { std::cout<< "PndMdt::ConstructGeometry : No good MDT Barrel definition " <GetRuntimeDb(); //par=(PndGeoMdtPar*)(rtdb->getContainer("PndGeoMdtPar")); //TObjArray *fSensNodes = par->GetSensitiveNodes(); } // ------------------------------------------------------------------------- // ----- Public method BeginEvent -------------------------------------- void PndMdt::BeginEvent() { } // ------------------------------------------------------------------------- // ----- Public method ProcessHits -------------------------------------- Bool_t PndMdt::ProcessHits(FairVolume* vol) { TString name = gMC->CurrentVolOffName(1); if (name.Contains("BA")) ProcessHitsRoot(vol); else ProcessHitsFast(vol); if (gMC->IsTrackEntering() || gMC->IsNewTrack() ) return kTRUE; } // ----- Public method ProcessHitsFast -------------------------------------- Bool_t PndMdt::ProcessHitsFast(FairVolume* vol) { TString name = vol->GetName(); if (gMC->IsTrackEntering() || gMC->IsNewTrack() ) { fPos_In.SetXYZM(0.,0.,0.,0.); fMom_In.SetXYZM(0.,0.,0.,0.); gMC->TrackPosition(fPos_In); gMC->TrackMomentum(fMom_In); fTrkIn = gMC->GetStack()->GetCurrentTrackNumber(); }; // end entering fELoss = fELoss + gMC->Edep(); if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { Int_t TrNo=gMC->GetStack()->GetCurrentTrackNumber(); Int_t pdg= gMC->TrackPid(); if ( (TrNo == fTrkIn) && (fELoss >0.) ) { TLorentzVector lPos, lMom; Int_t iMod; Int_t iOct; Int_t iLayer; Int_t iBox; Int_t iWire; sscanf(name,"MDT%is%il%ib%iw%i", &iMod, &iOct, &iLayer, &iBox, &iWire); Int_t detectorId = iWire + 10*iBox + 1000*iLayer + 100000*iOct + 1000000*iMod; gMC->TrackPosition(lPos); // cm gMC->TrackMomentum(lMom); // GeV TClonesArray& clref = *fMdtCollection; Int_t size = fMdtCollection->GetEntriesFast(); PndMdtPoint *P= new(clref[size]) PndMdtPoint (TrNo,detectorId, lPos.Vect(), lMom.Vect(), gMC->TrackTime(), gMC->TrackLength(), fELoss, gMC->GetStack()->GetCurrentParentTrackNumber(),pdg, fPos_In.Vect(), fMom_In.Vect()); /**if you add a point then tell the stack! here*/ PndStack* stack = (PndStack*) gMC->GetStack(); stack->AddPoint(kMDT); }; ResetParameters(); }; //ResetParameters(); return kTRUE; } // ----- Public method ProcessHitsRoot -------------------------------------- Bool_t PndMdt::ProcessHitsRoot(FairVolume* vol) { TString name = gMC->CurrentVolName(); TString path = gMC->CurrentVolPath(); if (fVerboseLevel) std::cout << "Path: " << path << std::endl; if (gMC->IsTrackEntering() || gMC->IsNewTrack() ) { fPos_In.SetXYZM(0.,0.,0.,0.); fMom_In.SetXYZM(0.,0.,0.,0.); gMC->TrackPosition(fPos_In); gMC->TrackMomentum(fMom_In); fTrkIn = gMC->GetStack()->GetCurrentTrackNumber(); }; // end entering fELoss = fELoss + gMC->Edep(); if (fVerboseLevel) cout << "pdg: " << gMC->TrackPid() << "\teloss: " << fELoss << endl; if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { Int_t TrNo=gMC->GetStack()->GetCurrentTrackNumber(); Int_t pdg= gMC->TrackPid(); if ( (TrNo == fTrkIn) && (fELoss >0.) ) { TLorentzVector lPos, lMom; Int_t iMod = -1; Int_t iOct; Int_t iLayer; Int_t iBox; Int_t iWire; gMC->CurrentVolID(iWire); gMC->CurrentVolOffID(2,iBox); gMC->CurrentVolOffID(3,iLayer); gMC->CurrentVolOffID(4,iOct); if (path.Contains("Barrel")) iMod = 1; if (path.Contains("Endcap")) iMod = 2; if (path.Contains("MF")) iMod = 3; if (path.Contains("Forward")) iMod = 4; if (fVerboseLevel) cout << iMod << "\t" << iOct << "\t" << iLayer << "\t" << iBox << "\t" << iWire; Int_t detectorId = iWire + 10*iBox + 1000*iLayer + 100000*iOct + 1000000*iMod; if (fVerboseLevel) cout << "\t" << detectorId << endl; gMC->TrackPosition(lPos); // cm gMC->TrackMomentum(lMom); // GeV TClonesArray& clref = *fMdtCollection; Int_t size = fMdtCollection->GetEntriesFast(); PndMdtPoint *P= new(clref[size]) PndMdtPoint (TrNo,detectorId, lPos.Vect(), lMom.Vect(), gMC->TrackTime(), gMC->TrackLength(), fELoss, gMC->GetStack()->GetCurrentParentTrackNumber(),pdg, fPos_In.Vect(), fMom_In.Vect()); /**if you add a point then tell the stack! here*/ PndStack* stack = (PndStack*) gMC->GetStack(); stack->AddPoint(kMDT); }; ResetParameters(); }; //ResetParameters(); // if not each time eloss is reset to 0 instead to increase return kTRUE; } // ------------------------------------------------------------------------- Bool_t PndMdt::CheckIfSensitive(std::string name) { if (name.find("MDT") != std::string::npos) { return kTRUE; } return kFALSE; } // ---------------------------------------------------------------------------- TClonesArray* PndMdt::GetCollection(Int_t iColl) const { if(iColl==0) { return fMdtCollection; }else{ return NULL; } } // ----- Public method EndOfEvent ----------------------------------------- void PndMdt::EndOfEvent() { if (fVerboseLevel) Print(); Reset(); } // ---------------------------------------------------------------------------- ClassImp(PndMdt)