///////////////////////////////////////////////////////////// // // CbmHyp // // Filler of CbmHypPoint // // created by A. Sanchez // /////////////////////////////////////////////////////////////// #include "iostream.h" //#include "ostringstream.h" #include "TClonesArray.h" #include "TGeoManager.h" #include "TLorentzVector.h" #include "TParticle.h" #include "TVirtualMC.h" #include "CbmGeoInterface.h" #include "CbmGeoLoader.h" #include "TGeoMCGeometry.h" #include "CbmGeoNode.h" #include "CbmGeoMedium.h" #include "CbmGeoHyp.h" #include "CbmGeoRootBuilder.h" #include "CbmStack.h" #include "CbmHyp.h" #include "CbmHypPoint.h" #include "CbmRootManager.h" #include "CbmVolume.h" // add on for debug #include "CbmRuntimeDb.h" #include "TObjArray.h" #include "CbmRun.h" #include "TList.h" #include #include class CbmVolume; // ----- Default constructor ------------------------------------------- CbmHyp::CbmHyp() { fHypCollection = new TClonesArray("CbmHypPoint"); fHypSecTarCollection = new TClonesArray("CbmHypPoint"); fHypSTpipeCollection = new TClonesArray("CbmHypPoint"); SiId = 0; CId = 0; CpipeId = 0; alId = 0; beId = 0; fPosIndex = 0; // fpreflag = 0; //fpostflag = 0; fEventID=-1; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmHyp::CbmHyp(const char* name, Bool_t active) : CbmDetector(name, active) { fHypCollection = new TClonesArray("CbmHypPoint"); fHypSecTarCollection = new TClonesArray("CbmHypPoint"); fHypSTpipeCollection = new TClonesArray("CbmHypPoint"); SiId = 0; CId = 0; alId = 0; beId = 0; fPosIndex = 0; fEventID=-1; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmHyp::~CbmHyp() { if (fHypCollection) { fHypCollection->Delete(); delete fHypCollection; } if (fHypSecTarCollection) { fHypSecTarCollection->Delete(); delete fHypSecTarCollection; } if (fHypSTpipeCollection) { fHypSTpipeCollection->Delete(); delete fHypSTpipeCollection; } } // ------------------------------------------------------------------------- // ----- Public method Intialize --------------------------------------- void CbmHyp::Initialize() { // Init function CbmDetector::Initialize(); CbmRun* sim = CbmRun::Instance(); CbmRuntimeDb* rtdb=sim->GetRuntimeDb(); par=(CbmGeoHypPar*)(rtdb->getContainer("CbmGeoHypPar")); //TObjArray *fSensNodes = par->GetGeoSensitiveNodes(); //CbmGeoMedium* Si = gGeoManager->GetMedium("silicon");->getMediumIndex(); TGeoMedium *Si= gGeoManager->GetMedium("HYPsilicon"); SiId= Si->GetId(); //----disactivated when geo file is block TGeoMedium *C= gGeoManager->GetMedium("carbon"); CId= C->GetId(); TGeoMedium *Cpipe= gGeoManager->GetMedium("HYPcarbon"); CpipeId= Cpipe->GetId(); // TGeoMedium *al= gGeoManager->GetMedium("aluminium"); // alId= al->GetId(); // TGeoMedium *be= gGeoManager->GetMedium("beryllium"); // beId= be->GetId(); } // ------------------------------------------------------------------------- void CbmHyp::BeginEvent(){ // Begin of the event } // ----- Public method ProcessHits -------------------------------------- Bool_t CbmHyp::ProcessHits(CbmVolume* vol) { //CbmGeoMedium* Si = vol->getGeoNode()->getMedium(); //volSi = Si->getMediumIndex(); // TString nameSi = Si->getName(); // CbmGeoMedium* Si = gGeoManager->GetMedium("silicon"); // volSi = Si->getMediumIndex(); //fpdgCode = gMC->TrackPid(); Double_t beta, gamma; Int_t medId = gMC->CurrentMedium(); TVector3 radt; //cout<<"med = absorver "<TrackPid(); cout<<"silicon "<IsTrackEntering() ) { fELoss = 0.; fTime = gMC->TrackTime() * 1.0e09; fLength = gMC->TrackLength(); fmass = gMC->TrackMass(); // mass (GeV) fcharge = gMC->TrackCharge(); // charge? fpdgCode = gMC->TrackPid(); gMC->TrackPosition(fPosIn); gMC->TrackMomentum(fMomIn); float globalPos[3], localPos[3]; globalPos[0] = fPosIn.X(); globalPos[1] = fPosIn.Y(); globalPos[2] = fPosIn.Z(); gMC->Gmtod(globalPos, localPos, 1); fPosInLocal.SetXYZM(localPos[0], localPos[1], localPos[2], 0.0); } // Sum energy loss for all steps in the active volume fELoss += gMC->Edep(); // Set additional parameters at exit of active volume. Create CbmStsPoint. cout<<"Energy Loss "<< fpdgCode << " " << fELoss <TrackMomentum(PL); if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); fVolumeID = vol->getMCid(); CbmGeoNode* node = vol->getGeoNode(); TList* nodeList = node->getTree(); //cout << "FullName: " << vol->getName() << "/"; for (Int_t index=0; index < nodeList->GetSize(); index++) { CbmGeoNode* myNode = dynamic_cast ( nodeList->At(index) ); //cout << myNode->getName() << "/"; } //**************/// ostringstream FullName; //cout << "******* Info from gMC *************" << endl; Int_t cp=-1; Int_t fVolid = gMC->CurrentVolID(cp); // cout << " Vol Name: " << gMC->CurrentVolName() << endl; FullName << gMC->CurrentVolName() << "#" << cp << "/"; fVolid=gMC->CurrentVolOffID(1,cp); FullName << gMC->CurrentVolOffName(1) << "#" << cp << "/"; // cout << "Hit in " << FullName.str() << " with MCiD: " // << vol->getMCid() << " volumeID: " // << vol->getVolumeId() << " " << vol->getCopyNo() << std::endl; gMC->TrackPosition(fPosOut); gMC->TrackMomentum(fMomOut); float globalPos[3],localPos[3] = {0., 0., 0.}; globalPos[0] = fPosOut.X(); globalPos[1] = fPosOut.Y(); globalPos[2] = fPosOut.Z(); gMC->Gmtod(globalPos, localPos, 1); fPosOutLocal.SetXYZM(localPos[0], localPos[1], localPos[2], 0.0); if (fELoss == 0. ) return kFALSE; radt= fPosOut.Vect(); fdist=radt.Perp(); beta = fMomOut.Beta(); gamma = fMomOut.Gamma(); fPLin = beta; //fPLin = fMomIn.P(); fPLout = fMomOut.P(); AddHit(fTrackID, fVolumeID,FullName.str(), TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()), TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()), TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()), TVector3(fPosInLocal.X(), fPosInLocal.Y(), fPosInLocal.Z()), TVector3(fPosOutLocal.X(), fPosOutLocal.Y(),fPosOutLocal.Z()), fTime, fLength,fELoss,fcharge,fmass,fpdgCode, fdist,fPLin,fPLout); //cout<<" xi minus? "<IsTrackEntering() ) { fELoss = 0.; fTime = gMC->TrackTime() * 1.0e09; fLength = gMC->TrackLength(); fmass = gMC->TrackMass(); // mass (GeV) fcharge = gMC->TrackCharge(); // charge? fpdgCode = gMC->TrackPid(); gMC->TrackPosition(fPosIn); gMC->TrackMomentum(fMomIn); //cout<<" xi minus "<Edep(); // Gamma, Beta, tau(proper time) of ximnus TLorentzVector PL; gMC->TrackMomentum(PL); beta = PL.Beta(); gamma = PL.Gamma(); //cout<<"In absorver "<IsTrackStop()&&(PL.P()<1.0 ) //if ((PL.P()>=0.00&&PL.P()<=0.5)&& gMC->IsTrackDisappeared()) //---geant4: fStopButAlive() //if (gMC->IsTrackDisappeared()&&(!gMC->IsTrackStop()) ) //---geant4: fStopandKill() //if ((!gMC->IsTrackDisappeared())&&(gMC->IsTrackStop()) ) // gamma==1.0, tau==tau_proper particle at rest and alive //if (gamma==1.0) if (gamma==1.0) { fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); fVolumeID = vol->getMCid(); gMC->TrackPosition(fPosOut); gMC->TrackMomentum(fMomOut); ostringstream FullName; if (fELoss == 0. ) return kFALSE; //---Kinetic energy:###(PL.P())^2 + Mass^2 -Mass## radt= fPosOut.Vect(); fdist=radt.Perp(); //beta = fMomOut.Beta(); //gamma = fMomOut.Gamma(); fPLin = beta; //fPLin = fMomIn.P(); fPLout = fMomOut.P(); //cout<<"absorver "<IsTrackEntering() ) { fELoss = 0.; fTime = gMC->TrackTime() * 1.0e09; fLength = gMC->TrackLength(); fmass = gMC->TrackMass(); // mass (GeV) fcharge = gMC->TrackCharge(); // charge? fpdgCode = gMC->TrackPid(); gMC->TrackPosition(fPosIn); gMC->TrackMomentum(fMomIn); //cout<<" xi minus "<Edep(); // Gamma, Beta, tau(proper time) of ximnus TLorentzVector PL; gMC->TrackMomentum(PL); beta = PL.Beta(); gamma = PL.Gamma(); //cout<<"In absorver "<IsTrackStop()&&(PL.P()<1.0 ) //if ((PL.P()>=0.00&&PL.P()<=0.5)&& gMC->IsTrackDisappeared()) //---geant4: fStopButAlive() //if (gMC->IsTrackDisappeared()&&(!gMC->IsTrackStop()) ) //---geant4: fStopandKill() //if ((!gMC->IsTrackDisappeared())&&(gMC->IsTrackStop()) ) // gamma==1.0, tau==tau_proper particle at rest and alive //if (gamma==1.0) if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) { fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); fVolumeID = vol->getMCid(); gMC->TrackPosition(fPosOut); gMC->TrackMomentum(fMomOut); ostringstream FullName; if (fELoss == 0. ) return kFALSE; //---Kinetic energy:###(PL.P())^2 + Mass^2 -Mass## radt= fPosOut.Vect(); fdist=radt.Perp(); //beta = fMomOut.Beta(); //gamma = fMomOut.Gamma(); fPLin = beta; //fPLin = fMomIn.P(); fPLout = fMomOut.P(); //cout<<"pipe absorver "<Register("HypPoint","Hyp", fHypCollection, kTRUE); CbmRootManager::Instance()->Register("HypSegTarPoint","HypSecTarg", fHypSecTarCollection, kTRUE); CbmRootManager::Instance()->Register("HypSTpipePoint","HypSTpipe", fHypSTpipeCollection, kTRUE); } // ---------------------------------------------------------------------------- // ----- Public method GetCollection -------------------------------------- TClonesArray* CbmHyp::GetCollection(Int_t iColl) const { if (iColl == 0) return fHypCollection; if (iColl == 1) return fHypSecTarCollection; if (iColl == 2) return fHypSTpipeCollection; return NULL; } // ---------------------------------------------------------------------------- // ----- Public method Print ---------------------------------------------- void CbmHyp::Print() const { Int_t nHits = fHypCollection->GetEntriesFast(); cout << "-I- CbmHyp: " << nHits << " points registered in this event." << endl; if (fVerboseLevel>1) for (Int_t i=0; iPrint(); } // ---------------------------------------------------------------------------- // ----- Public method Reset ---------------------------------------------- void CbmHyp::Reset() { fHypCollection->Clear(); fHypSecTarCollection->Clear(); fHypSTpipeCollection->Clear(); fPosIndex = 0; } // ---------------------------------------------------------------------------- // guarda in CbmRootManager::CopyClones // ----- Public method CopyClones ----------------------------------------- void CbmHyp::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) { Int_t nEntries = cl1->GetEntriesFast(); //cout << "-I- CbmHyp: " << nEntries << " entries to add." << endl; TClonesArray& clref = *cl2; CbmHypPoint* oldpoint = NULL; for (Int_t i=0; iAt(i); Int_t index = oldpoint->GetTrackID() + offset; oldpoint->SetTrackID(index); new (clref[fPosIndex]) CbmHypPoint(*oldpoint); fPosIndex++; } cout << " -I- CbmHyp: " << cl2->GetEntriesFast() << " merged entries." << endl; } // ---------------------------------------------------------------------------- // ----- Public method ConstructGeometry ---------------------------------- void CbmHyp::ConstructGeometry() { CbmGeoLoader* geoLoad = CbmGeoLoader::Instance(); CbmGeoInterface* geoFace = geoLoad->getGeoInterface(); CbmGeoHyp* hypGeo = new CbmGeoHyp(); hypGeo->setGeomFile(GetGeometryFileName()); geoFace->addGeoModule(hypGeo); Bool_t rc = geoFace->readSet(hypGeo); if (rc) hypGeo->create(geoLoad->getGeoBuilder()); TList* volList = hypGeo->getListOfVolumes(); // store geo parameter CbmRun *fRun = CbmRun::Instance(); CbmRuntimeDb *rtdb= CbmRun::Instance()->GetRuntimeDb(); CbmGeoHypPar* par=(CbmGeoHypPar*)(rtdb->getContainer("CbmGeoHypPar")); TObjArray *fSensNodes = par->GetGeoSensitiveNodes(); TObjArray *fPassNodes = par->GetGeoPassiveNodes(); TListIter iter(volList); CbmGeoNode* node = NULL; CbmGeoVolume *aVol=NULL; while( (node = (CbmGeoNode*)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 ); } // ----- Private method AddHit -------------------------------------------- CbmHypPoint* CbmHyp::AddHit(Int_t trackID, Int_t detID, TString detName, TVector3 pos, TVector3 mom, TVector3 posout, TVector3 momout, TVector3 posInLocal, TVector3 posOutLocal, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Int_t pdgCode, Double_t dist, Double_t PLin,Double_t PLout) { TClonesArray& clref = *fHypCollection; Int_t size = clref.GetEntriesFast(); return new(clref[size]) CbmHypPoint(trackID, detID, detName,pos, mom, posout, momout, posInLocal, posOutLocal, time, length, eLoss,charge, mass,pdgCode, dist,PLin,PLout); } // ---- // ----- Private method AddSecTarHit -------------------------------------------- CbmHypPoint* CbmHyp::AddSecTarHit(Int_t trackID, Int_t detID, TString detName, TVector3 pos, TVector3 mom, TVector3 posout, TVector3 momout, TVector3 posInLocal, TVector3 posOutLocal, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Int_t pdgCode,Double_t dist, Double_t PLin,Double_t PLout) { TClonesArray& clref = *fHypSecTarCollection; Int_t size = clref.GetEntriesFast(); return new(clref[size]) CbmHypPoint(trackID, detID, detName, pos, mom, posout, momout, posInLocal, posOutLocal, time, length, eLoss,charge, mass, pdgCode, dist,PLin,PLout); } // ---- // ----- Private method AddSTpipeHit -------------------------------------------- CbmHypPoint* CbmHyp::AddSTpipeHit(Int_t trackID, Int_t detID, TString detName, TVector3 pos, TVector3 mom, TVector3 posout, TVector3 momout, TVector3 posInLocal, TVector3 posOutLocal, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Int_t pdgCode,Double_t dist, Double_t PLin,Double_t PLout) { TClonesArray& clref = *fHypSTpipeCollection; Int_t size = clref.GetEntriesFast(); return new(clref[size]) CbmHypPoint(trackID, detID, detName, pos, mom, posout, momout, posInLocal, posOutLocal, time, length, eLoss,charge, mass, pdgCode, dist,PLin,PLout); } // ---- ClassImp(CbmHyp)