#include "PndMvdDetector.h" #include "PndMvdGeoMappingPar.h" #include "PndMvdGeo.h" #include "PndMvdGeoPar.h" #include "CbmGeoInterface.h" #include "CbmGeoLoader.h" #include "CbmGeoNode.h" #include "CbmGeoRootBuilder.h" #include "CbmRootManager.h" #include "CbmRuntimeDb.h" #include "CbmRun.h" #include "CbmGeoMedia.h" #include "CbmGeoVolume.h" #include "CbmRunSim.h" #include "CbmVolume.h" #include "PndMvdGeoMappingPar.h" #include "PndMvdMCPoint.h" #include "PndMvdGeo.h" #include "PndMvdGeoPar.h" #include "TClonesArray.h" #include "TLorentzVector.h" #include "TParticle.h" #include "TVirtualMC.h" #include "TObjArray.h" #include "TList.h" #include "TKey.h" #include "TGeoManager.h" #include "PndMvdGeoHandling.h" #include #include #include class CbmVolume; // ----- Default constructor ------------------------------------------- PndMvdDetector::PndMvdDetector() { fPndMvdCollection = new TClonesArray("PndMvdMCPoint"); fPosIndex = 0; fVerboseLevel = 1; fListOfSensitives.push_back("Disk-Sensor");//Root_Test.root fListOfSensitives.push_back("Barrel-Sensor");//Root_Test.root fListOfSensitives.push_back("StripSensor");//MVD14.root fListOfSensitives.push_back("SensorActiveArea");//MVD14.root if (fVerboseLevel>0) { std::cout<<"-I- PndMvdDetector: fListOfSensitives contains:"; for(Int_t k=0;k0) { std::cout<<"- I - PndMvdDetector: fListOfSensitives contains:"; for(Int_t k=0;kDelete(); delete fPndMvdCollection; } delete fGeoH; } // ------------------------------------------------------------------------- void PndMvdDetector::Initialize() { CbmDetector::Initialize(); fGeoH = new PndMvdGeoHandling(gGeoManager); } // ----- Public method ProcessHits -------------------------------------- Bool_t PndMvdDetector::ProcessHits(CbmVolume* vol) { if ( gMC->IsTrackEntering() ) { // Set parameters at entrance of volume. Reset ELoss. 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(); // Create PndMvdMCPoint at exit of active volume if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); //if (fDetIDMap[gMC->CurrentVolPath()] == 0){ // fDetIDMap[gMC->CurrentVolPath()] = fDetIDMap.size()+1; // } //fVolumeID = fDetIDMap[gMC->CurrentVolPath()]; if (fVerboseLevel > 1){ std::cout << "******* Info from gMC *************" << std::endl; std::cout << "Hit in " << gMC->CurrentVolPath() << " with MCiD: " << vol->getMCid() << " volumeID: " << fVolumeID << std::endl; std::cout<<"VolumeID: "<GetID(gMC->CurrentVolPath())<GetCurrentNodeId(); gMC->TrackPosition(fPosOut); gMC->TrackMomentum(fMomOut); if (fELoss == 0.) return kFALSE; AddHit(fTrackID, fVolumeID, fGeoH->GetID(gMC->CurrentVolPath()), 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 PndMvd points for TParticle /* Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1); Int_t nPndMvdMCPoints = (points & (15<<24)) >> 24; nPndMvdMCPoints ++; if (nPndMvdMCPoints > 15) nPndMvdMCPoints = 15; points = ( points & ( ~ (15<<24) ) ) | (nPndMvdMCPoints << 24); gMC->GetStack()->GetCurrentTrack()->SetMother(1,points); */ ResetParameters(); } return kTRUE; } // ------------------------------------------------------------------------- // ----- Public method EndOfEvent -------------------------------------- void PndMvdDetector::EndOfEvent() { if (fVerboseLevel) Print(); fPndMvdCollection->Clear(); fPosIndex = 0; } // ------------------------------------------------------------------------- void PndMvdDetector::FinishRun() { /* CbmRun *fRun = CbmRun::Instance(); CbmRuntimeDb *rtdb= CbmRun::Instance()->GetRuntimeDb(); PndMvdGeoMappingPar *par= (PndMvdGeoMappingPar*)(rtdb->getContainer("PndMvdGeoMappingPar")); TObjArray* detIdPairs = par->getPairs(); for (std::map::const_iterator it = fDetIDMap.begin(); it!=fDetIDMap.end(); ++it) { detIdPairs->AddLast( new PndMvdDetIdPair(it->second, it->first) ); if(fVerboseLevel > 2){ std::cout<<"PndMvdDetector::fDetIDMap["<first<<"]=" <second<setChanged(); par->setInputVersion(fRun->GetRunId(),1);*/ } // ----- Public method Register ---------------------------------------- void PndMvdDetector::Register() { CbmRootManager::Instance()->Register("MVDPoint", "PndMvd", fPndMvdCollection, kTRUE); } // ------------------------------------------------------------------------- // ----- Public method GetCollection ----------------------------------- TClonesArray* PndMvdDetector::GetCollection(Int_t iColl) const { if (iColl == 0) return fPndMvdCollection; else return NULL; } // ------------------------------------------------------------------------- // ----- Public method Print ------------------------------------------- void PndMvdDetector::Print() const { Int_t nHits = fPndMvdCollection->GetEntriesFast(); std::cout << "-I- PndMvdDetector: " << nHits << " points registered in this event." << std::endl; if (fVerboseLevel>1) for (Int_t i=0; iPrint(); } // ------------------------------------------------------------------------- // ----- Public method Reset ------------------------------------------- void PndMvdDetector::Reset() { fPndMvdCollection->Clear(); ResetParameters(); } // ------------------------------------------------------------------------- // ----- Public method CopyClones -------------------------------------- void PndMvdDetector::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) { Int_t nEntries = cl1->GetEntriesFast(); std::cout << "-I- PndMvdDetector: " << nEntries << " entries to add." << std::endl; TClonesArray& clref = *cl2; PndMvdMCPoint *oldpoint = NULL; for (Int_t i=0; iAt(i); Int_t index = oldpoint->GetTrackID() + offset; oldpoint->SetTrackID(index); new (clref[fPosIndex]) PndMvdMCPoint(*oldpoint); fPosIndex++; } std::cout << "-I- PndMvdDetector: " << cl2->GetEntriesFast() << " merged entries." << std::endl; } // ------------------------------------------------------------------------- void PndMvdDetector::ConstructGeometry() { TString fileName=GetGeometryFileName(); if(fileName.EndsWith(".geo")){ ConstructASCIIGeometry(); }else if(fileName.EndsWith(".root")){ ConstructRootGeometry(); }else{ std::cout<< "Geometry format not supported " <GetListOfKeys(); TKey *k=(TKey *) l->At(0); TGeoVolume *Stt2=(TGeoVolume *)k->ReadObj(); TGeoNode *n=Stt2->GetNode(0); TGeoVolume *v1=n->GetVolume(); TGeoVolume *Cave= gGeoManager->GetTopVolume(); gGeoManager->AddVolume(v1); TGeoVoxelFinder *voxels = v1->GetVoxels(); if (voxels) voxels->SetNeedRebuild(); TGeoMatrix *M = n->GetMatrix(); M->SetDefaultName(); gGeoManager->GetListOfMatrices()->Remove(M); TGeoHMatrix *global = gGeoManager->GetHMatrix(); gGeoManager->GetListOfMatrices()->Remove(global); //Remove the Identity matrix Cave->AddNode(v1,0, M); ExpandNode(n); delete f; } void PndMvdDetector::ExpandNode(TGeoNode *fN){ CbmGeoLoader*geoLoad = CbmGeoLoader::Instance(); CbmGeoInterface *geoFace = geoLoad->getGeoInterface(); CbmGeoMedia *Media = geoFace->getMedia(); CbmGeoBuilder *geobuild=geoLoad->getGeoBuilder(); TGeoMatrix *Matrix =fN->GetMatrix(); if(gGeoManager->GetListOfMatrices()->FindObject(Matrix))gGeoManager->GetListOfMatrices()->Remove(Matrix); TGeoVolume *v1=fN->GetVolume(); //v1->RegisterYourself(); TObjArray *NodeList=v1->GetNodes(); //Int_t medId=MediaArray1->GetSize(); for (Int_t Nod=0; NodGetEntriesFast();Nod++) { TGeoNode *fNode =(TGeoNode *)NodeList->At(Nod); TGeoMatrix *M =fNode->GetMatrix(); M->SetDefaultName(); if(fNode->GetNdaughters()>0) ExpandNode(fNode); TGeoVolume *v= fNode->GetVolume(); Int_t MatId=0; TGeoMedium* med1=v->GetMedium(); if(med1){ TGeoMaterial*mat1=v->GetMaterial(); TGeoMaterial *newMat = gGeoManager->GetMaterial(mat1->GetName()); if( newMat==0){ std::cout<< "Material " << mat1->GetName() << " is not defined " << std::endl; CbmGeoMedium *CbmMedium=Media->getMedium(mat1->GetName()); if (!CbmMedium) { std::cout << "Material is not defined in ASCII file nor in Root file" << std::endl; CbmMedium=new CbmGeoMedium(mat1->GetName()); Media->addMedium(CbmMedium); } std::cout << "Create Medium " << mat1->GetName() << std::endl; Int_t nmed=geobuild->createMedium(CbmMedium); v->SetMedium(gGeoManager->GetMedium(nmed)); gGeoManager->SetAllIndex(); }else{ TGeoMedium *med2= gGeoManager->GetMedium(mat1->GetName()); v->SetMedium(med2); } } if (!gGeoManager->FindVolumeFast(v->GetName())) { if (fVerboseLevel>2)std::cout << "Register Volume : " << v->GetName() << " id " << std::endl; v->RegisterYourself(); } if (CheckIfSensitive(v->GetName())){ if (fVerboseLevel>2){ std::cout << "Sensitive Volume : " << v->GetName() << " id " << std::endl; } AddSensitiveVolume(v); } } } // ------------------------------------------------------------------------- // ----- Public method ConstructGeometry ------------------------------- void PndMvdDetector::ConstructASCIIGeometry() { // get pointer to the instantons which interface // to monte carlo CbmGeoLoader *geoLoad = CbmGeoLoader::Instance(); CbmGeoInterface *geoFace = geoLoad->getGeoInterface(); PndMvdGeo *thePndMvdGeo = new PndMvdGeo(); thePndMvdGeo->setGeomFile(GetGeometryFileName()); geoFace->addGeoModule(thePndMvdGeo); Bool_t rc = geoFace->readSet(thePndMvdGeo); if (rc) thePndMvdGeo->create(geoLoad->getGeoBuilder()); TList* volList = thePndMvdGeo->getListOfVolumes(); // store geo parameter CbmRun *fRun = CbmRun::Instance(); CbmRuntimeDb *rtdb= CbmRun::Instance()->GetRuntimeDb(); PndMvdGeoPar *par= (PndMvdGeoPar*)(rtdb->getContainer("PndMvdGeoPar")); 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 ----------------------------------------- PndMvdMCPoint* PndMvdDetector::AddHit(Int_t trackID, Int_t detID, TString detName, TVector3 posIn, TVector3 posOut,TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss) const { TClonesArray& clref = *fPndMvdCollection; Int_t size = clref.GetEntriesFast(); if (fVerboseLevel >= 2) std::cout << "-I- PndMvdDetector: Adding Point at (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z() << ") cm, (" << posOut.X() << ", " << posOut.Y() << ", " << posOut.Z() << ") cm, detector " << detName << " " << detID << ", track " << trackID << ", energy loss " << eLoss*1e06 << " keV" << std::endl; return new(clref[size]) PndMvdMCPoint(trackID, detID, detName, posIn, posOut, momIn, momOut, time, length, eLoss); } // ------------------------------------------------------------------------- ClassImp(PndMvdDetector);