///////////////////////////////////////////////////////////// // CbmStt // // Class for STT1 // // authors: Pablo Genova - Pavia University // Lia Lavezzi - Pavia University // ///////////////////////////////////////////////////////////// #include #include "TClonesArray.h" #include "TGeoMCGeometry.h" #include "TGeoManager.h" #include "TLorentzVector.h" #include "TParticle.h" #include "TVirtualMC.h" #include "CbmGeoInterface.h" #include "CbmGeoLoader.h" #include "CbmGeoNode.h" #include "CbmGeoStt.h" #include "CbmGeoRootBuilder.h" #include "CbmStack.h" #include "CbmStt.h" #include "CbmSttPoint.h" #include "CbmRootManager.h" #include "CbmVolume.h" // add on for debug #include "CbmGeoG3Builder.h" #include "CbmRuntimeDb.h" #include "CbmGeoSttPar.h" #include "TObjArray.h" #include "CbmRun.h" using namespace std; // ----- Default constructor ------------------------------------------- CbmStt::CbmStt() { fSttCollection = new TClonesArray("CbmSttPoint"); fPosIndex = 0; fpreflag = 0; fpostflag = 0; volDetector = 0; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmStt::CbmStt(const char* name, Bool_t active) : CbmDetector(name, active) { fSttCollection = new TClonesArray("CbmSttPoint"); fPosIndex = 0; fpreflag = 0; fpostflag = 0; volDetector = 0; fevent=-1; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmStt::~CbmStt() { if (fSttCollection) { fSttCollection->Delete(); delete fSttCollection; } } // ------------------------------------------------------------------------- // ----- Public method Intialize --------------------------------------- void CbmStt::Initialize() { CbmDetector::Initialize(); CbmRun* sim = CbmRun::Instance(); CbmRuntimeDb* rtdb=sim->GetRuntimeDb(); CbmGeoSttPar *par=(CbmGeoSttPar*)(rtdb->getContainer("CbmGeoSttPar")); TObjArray *fSensNodes = par->GetGeoSensitiveNodes(); } // ------------------------------------------------------------------------- // ------- BeginEvent ------------------------------------------------------ void CbmStt::BeginEvent(){ fevent++; } // ------------------------------------------------------------------------- // ----- Public method ProcessHits -------------------------------------- Bool_t CbmStt::ProcessHits(CbmVolume* vol) { fmass = gMC->TrackMass(); // mass (GeV) fcharge = gMC->TrackCharge(); // charge fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); // trk ID Int_t copyNo; gMC->CurrentVolID(copyNo); // Geant4 copy number correction if (gMC->GetMC()->GetName()[6]=='4') copyNo--; fVolumeID = copyNo; // copy Number TString nam = gMC->CurrentVolName(); //string with the correct name fcurrnam=nam; nam = nam + "_"; nam +=copyNo; fcurrnam2 = nam; //------------------------------------------- // if entering if ( gMC->IsTrackEntering() ) { fpreflag = 1; fELoss = 0.; fTime = gMC->TrackTime() * 1.0e09; // time fLength = gMC->TrackLength(); gMC->TrackPosition(fPosIn); // cm gMC->TrackMomentum(fMomIn); // GeV } // Sum energy loss for all steps in the active volume fELoss += gMC->Edep(); // Set additional parameters at exit of active volume. Create CbmSttPoint. if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { if ( gMC->IsTrackExiting()) fpostflag = 1; gMC->TrackPosition(fPosOut); // cm gMC->TrackMomentum(fMomOut); // GeV // if (fELoss == 0. ) return kFALSE; } AddHit(fTrackID, fVolumeID, TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()), TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()), TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()), fTime, fLength, fELoss, fcharge, fmass, fpreflag, fpostflag, nam,fevent); // TO BE SET AS DEBUG // cout << "PARAMETERS ----------" << endl; // cout << "trk " << fTrackID << " vol " << fVolumeID << endl; // cout << " pos in " << fPosIn.X() << " " << fPosIn.Y() << " " << fPosIn.Z() << endl; // cout << " pos out " << fPosOut.X() << " " << fPosOut.Y() << " " << fPosOut.Z() << endl; // cout << " mom in " << fMomIn.X() << " " << fMomIn.Y() << " " << fMomIn.Z() << endl; // cout << " mom out " << fMomOut.X() << " " << fMomOut.Y() << " " << fMomOut.Z() << endl; // cout << " time " << fTime << " length " << fLength << " Eloss " << fELoss << endl; // cout << " charge " << fcharge << " mass " << fmass << " pre/pos " << fpreflag << " " << fpostflag << endl; // cout << " ----------" << endl; ResetParameters(); return kTRUE; } // ---------------------------------------------------------------------------- // ----- Public method EndOfEvent ----------------------------------------- void CbmStt::EndOfEvent() { if (fVerboseLevel) Print(); Reset(); } // ---------------------------------------------------------------------------- // ----- Public method Register ------------------------------------------- void CbmStt::Register() { CbmRootManager::Instance()->Register("SttPoint","Stt", fSttCollection, kTRUE); } // ---------------------------------------------------------------------------- // ----- Public method GetCollection -------------------------------------- TClonesArray* CbmStt::GetCollection(Int_t iColl) const { if (iColl == 0) return fSttCollection; return NULL; } // ---------------------------------------------------------------------------- // ----- Public method Print ---------------------------------------------- void CbmStt::Print() const { Int_t nHits = fSttCollection->GetEntriesFast(); cout << "-I- CbmStt: " << nHits << " points registered in this event." << endl; if (fVerboseLevel>1) for (Int_t i=0; iPrint(); } // ---------------------------------------------------------------------------- // ----- Public method Reset ---------------------------------------------- void CbmStt::Reset() { fSttCollection->Clear(); fPosIndex = 0; } // ---------------------------------------------------------------------------- // ----- Public method CopyClones ----------------------------------------- void CbmStt::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) { Int_t nEntries = cl1->GetEntriesFast(); cout << "-I- CbmStt: " << nEntries << " entries to add." << endl; TClonesArray& clref = *cl2; CbmSttPoint* oldpoint = NULL; for (Int_t i=0; iAt(i); Int_t index = oldpoint->GetTrackID() + offset; oldpoint->SetTrackID(index); new (clref[fPosIndex]) CbmSttPoint(*oldpoint); fPosIndex++; } cout << " -I- CbmStt: " << cl2->GetEntriesFast() << " merged entries." << endl; } // ---------------------------------------------------------------------------- // ----- Public method ConstructGeometry ---------------------------------- void CbmStt::ConstructGeometry() { CbmGeoLoader* sttgeoLoad = CbmGeoLoader::Instance(); CbmGeoInterface* sttgeoFace = sttgeoLoad->getGeoInterface(); CbmGeoStt* sttGeo = new CbmGeoStt(); sttGeo->setGeomFile(GetGeometryFileName()); sttgeoFace->addGeoModule(sttGeo); Bool_t rc = sttgeoFace->readSet(sttGeo); if (rc) sttGeo->create(sttgeoLoad->getGeoBuilder()); TList* volList = sttGeo->getListOfVolumes(); // store geo parameter CbmRun *fRun = CbmRun::Instance(); CbmRuntimeDb *rtdb= CbmRun::Instance()->GetRuntimeDb(); CbmGeoSttPar* par=(CbmGeoSttPar*)(rtdb->getContainer("CbmGeoSttPar")); 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 ); } } ProcessNodes ( volList ); par->setChanged(); par->setInputVersion(fRun->GetRunId(),1); } // ---------------------------------------------------------------------------- // ----- Private method AddHit -------------------------------------------- // see CbmSttPoint for hit description CbmSttPoint* CbmStt::AddHit(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Double_t charge, Double_t mass, Bool_t preflag, Bool_t postflag, TString nam,Int_t evt) { TClonesArray& clref = *fSttCollection; Int_t size = clref.GetEntriesFast(); if (fVerboseLevel>1) cout << "-I- CbmStt: Adding Point at IN (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z() << ") cm, OUT ("<< posOut.X()<< ", " << posOut.Y()<<" "<