// ------------------------------------------------------------------------- // ----- CbmMvdStrips source file ----- // ----- Created 26/07/04 by V. Friese ----- // ------------------------------------------------------------------------- #include "CbmMvdStrips.h" #include "CbmGeoMvdStrips.h" #include "CbmMvdStripsPoint.h" #include "CbmGeoMvdStripsPar.h" #include "CbmDetectorList.h" #include "FairGeoInterface.h" #include "FairGeoLoader.h" #include "FairGeoNode.h" #include "FairGeoRootBuilder.h" #include "FairRootManager.h" #include "CbmStack.h" #include "FairRuntimeDb.h" #include "FairRun.h" #include "FairVolume.h" #include "TClonesArray.h" #include "TGeoMCGeometry.h" #include "TParticle.h" #include "TVirtualMC.h" #include "TObjArray.h" #include "TGeoManager.h" #include using std::cout; using std::cerr; using std::endl; // ----- Default constructor ------------------------------------------- CbmMvdStrips::CbmMvdStrips() : FairDetector("MVDSTRIPS", kTRUE, kMVDSTRIPS) { ResetParameters(); fMvdStripsCollection = new TClonesArray("CbmMvdStripsPoint"); fPosIndex = 0; kGeoSaved = kFALSE; flGeoPar = new TList(); flGeoPar->SetName( GetName()); fVerboseLevel = 1; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmMvdStrips::CbmMvdStrips(const char* name, Bool_t active) : FairDetector(name, active, kMVDSTRIPS) { ResetParameters(); fMvdStripsCollection = new TClonesArray("CbmMvdStripsPoint"); fPosIndex = 0; kGeoSaved = kFALSE; flGeoPar = new TList(); flGeoPar->SetName( GetName()); fVerboseLevel = 1; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmMvdStrips::~CbmMvdStrips() { if ( flGeoPar ) delete flGeoPar; if (fMvdStripsCollection) { fMvdStripsCollection->Delete(); delete fMvdStripsCollection; } } // ------------------------------------------------------------------------- // ----- Public method ProcessHits -------------------------------------- Bool_t CbmMvdStrips::ProcessHits(FairVolume* vol) { // cout << " -I process hit called for:" << vol->GetName() << endl; // Set parameters at entrance of volume. Reset ELoss. // if ( vol ) { // cout << " Name Id:copy " // << vol->getName() << " : " << vol->getMCid() << " : " << vol->getCopyNo() << endl; // Int_t copyNo=0; // cout << " Geant: " << gMC->CurrentVolID(copyNo) << ":" << copyNo << endl; // } if ( gMC->IsTrackEntering() ) { fELoss = 0.; fTime = gMC->TrackTime() * 1.0e09; fLength = gMC->TrackLength(); gMC->TrackPosition(fPosIn); gMC->TrackMomentum(fMomIn); } // Sum energy loss for all steps in the active volume fELoss += gMC->Edep(); // Set additional parameters at exit of active volume. Create CbmMvdStripsPoint. if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); fVolumeID = vol->getMCid(); gMC->TrackPosition(fPosOut); gMC->TrackMomentum(fMomOut); if (fELoss == 0. ) return kFALSE; if (gMC->IsTrackExiting()) { const Double_t* oldpos; const Double_t* olddirection; Double_t newpos[3]; Double_t newdirection[3]; Double_t safety; gGeoManager->FindNode(fPosOut.X(),fPosOut.Y(),fPosOut.Z()); oldpos = gGeoManager->GetCurrentPoint(); olddirection = gGeoManager->GetCurrentDirection(); // cout << "1st direction: " << olddirection[0] << "," << olddirection[1] << "," << olddirection[2] << endl; for (Int_t i=0; i<3; i++){ newdirection[i] = -1*olddirection[i]; } gGeoManager->SetCurrentDirection(newdirection); TGeoNode *bla = gGeoManager->FindNextBoundary(2); safety = gGeoManager->GetSafeDistance(); gGeoManager->SetCurrentDirection(-newdirection[0],-newdirection[1],-newdirection[2]); for (Int_t i=0; i<3; i++){ newpos[i] = oldpos[i] - (3*safety*olddirection[i]); } /*if ( fPosIn.Z() < 30. && newpos[2] > 30.02 ) { cerr << "2nd direction: " << olddirection[0] << "," << olddirection[1] << "," << olddirection[2] << " with safety = " << safety << endl; cerr << "oldpos = " << oldpos[0] << "," << oldpos[1] << "," << oldpos[2] << endl; cerr << "newpos = " << newpos[0] << "," << newpos[1] << "," << newpos[2] << endl; }*/ fPosOut.SetX(newpos[0]); fPosOut.SetY(newpos[1]); fPosOut.SetZ(newpos[2]); } 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); // Increment number of MvdStripsPoints for this track CbmStack* stack = (CbmStack*) gMC->GetStack(); stack->AddPoint(kMVDSTRIPS); ResetParameters(); } return kTRUE; } // ---------------------------------------------------------------------------- //void CbmMvdStrips::SaveGeoParams(){ // // cout << " -I Save MVDSTRIPS geo params " << endl; // // TFolder *mf = (TFolder*) gDirectory->FindObjectAny("cbmroot"); // cout << " mf: " << mf << endl; // TFolder *MvdStripsf = NULL; // if (mf ) MvdStripsf = (TFolder*) mf->FindObjectAny(GetName()); // cout << " MvdStripsf: " << MvdStripsf << endl; // if (MvdStripsf) MvdStripsf->Add( flGeoPar0 ) ; // FairRootManager::Instance()->WriteFolder(); // mf->Write("cbmroot",TObject::kWriteDelete); //} // ----- Public method EndOfEvent ----------------------------------------- void CbmMvdStrips::BeginEvent() { // if (! kGeoSaved ) { // SaveGeoParams(); // cout << "-I MVDSTRIPS geometry parameters saved " << endl; // kGeoSaved = kTRUE; // } } // ----- Public method EndOfEvent ----------------------------------------- void CbmMvdStrips::EndOfEvent() { if (fVerboseLevel) Print(); fMvdStripsCollection->Clear(); ResetParameters(); } // ---------------------------------------------------------------------------- // ----- Public method Register ------------------------------------------- void CbmMvdStrips::Register() { FairRootManager::Instance()->Register("MvdStripsPoint", GetName(), fMvdStripsCollection, kTRUE); } // ---------------------------------------------------------------------------- // ----- Public method GetCollection -------------------------------------- TClonesArray* CbmMvdStrips::GetCollection(Int_t iColl) const { if (iColl == 0) return fMvdStripsCollection; else return NULL; } // ---------------------------------------------------------------------------- // ----- Public method Print ---------------------------------------------- void CbmMvdStrips::Print() const { Int_t nHits = fMvdStripsCollection->GetEntriesFast(); cout << "-I- CbmMvdStrips: " << nHits << " points registered in this event." << endl; } // ---------------------------------------------------------------------------- // ----- Public method Reset ---------------------------------------------- void CbmMvdStrips::Reset() { fMvdStripsCollection->Clear(); ResetParameters(); } // ---------------------------------------------------------------------------- // ----- Public method CopyClones ----------------------------------------- void CbmMvdStrips::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) { Int_t nEntries = cl1->GetEntriesFast(); cout << "-I- CbmMvdStrips: " << nEntries << " entries to add." << endl; TClonesArray& clref = *cl2; CbmMvdStripsPoint* oldpoint = NULL; for (Int_t i=0; iAt(i); Int_t index = oldpoint->GetTrackID() + offset; oldpoint->SetTrackID(index); new (clref[fPosIndex]) CbmMvdStripsPoint(*oldpoint); fPosIndex++; } cout << " -I- CbmMvdStrips: " << cl2->GetEntriesFast() << " merged entries." << endl; } // ---------------------------------------------------------------------------- // ----- Public method ConstructGeometry ---------------------------------- void CbmMvdStrips::ConstructGeometry() { FairGeoLoader* geoLoad = FairGeoLoader::Instance(); FairGeoInterface* geoFace = geoLoad->getGeoInterface(); CbmGeoMvdStrips* MvdStripsGeo = new CbmGeoMvdStrips(); MvdStripsGeo->setGeomFile(GetGeometryFileName()); geoFace->addGeoModule(MvdStripsGeo); Bool_t rc = geoFace->readSet(MvdStripsGeo); if (rc) MvdStripsGeo->create(geoLoad->getGeoBuilder()); TList* volList = MvdStripsGeo->getListOfVolumes(); // store geo parameter FairRun *fRun = FairRun::Instance(); FairRuntimeDb *rtdb= FairRun::Instance()->GetRuntimeDb(); CbmGeoMvdStripsPar* par=(CbmGeoMvdStripsPar*)(rtdb->getContainer("CbmGeoMvdStripsPar")); 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 ); } // ---------------------------------------------------------------------------- // ----- Private method AddHit -------------------------------------------- CbmMvdStripsPoint* CbmMvdStrips::AddHit(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss) { TClonesArray& clref = *fMvdStripsCollection; Int_t size = clref.GetEntriesFast(); if (fVerboseLevel>1) cout << "-I- CbmMvdStrips: Adding Point at (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z() << ") cm, detector " << detID << ", track " << trackID << ", energy loss " << eLoss*1e06 << " keV" << endl; return new(clref[size]) CbmMvdStripsPoint(trackID, detID, posIn, posOut, momIn, momOut, time, length, eLoss); } // ---------------------------------------------------------------------------- ClassImp(CbmMvdStrips)