/* Generated by Together */ #include "CbmModule.h" #include "CbmVolume.h" #include "CbmVolumeList.h" #include "CbmBaseParSet.h" #include "CbmRun.h" #include "CbmGeoNode.h" #include "CbmRuntimeDb.h" #include "CbmGeoInterface.h" #include "CbmGeoLoader.h" #include "CbmGeoNode.h" #include "CbmGeoRootBuilder.h" #include "CbmGeoMedia.h" #include "TString.h" #include "TObjArray.h" #include "TGeoVolume.h" #include "TFile.h" #include "TList.h" #include "TKey.h" #include "TGeoManager.h" #include "TGeoVoxelFinder.h" #include "TGeoMatrix.h" #include "TSystem.h" #include #include using std::cout; using std::endl; TArrayI* CbmModule::volNumber=0; Int_t CbmModule::fNbOfVolumes=0; CbmVolumeList* CbmModule::vList=0; TRefArray* CbmModule::svList=0; //__________________________________________________________________________ void CbmModule::ConstructGeometry() { } //__________________________________________________________________________ void CbmModule::ConstructOpGeometry() { } //__________________________________________________________________________ CbmModule::~CbmModule() { } //__________________________________________________________________________ CbmModule::CbmModule(const char * Name, const char *title ,Bool_t Active) :TNamed(Name, title), fgeoVer("Not defined"), fgeoName("Not defined"), fModId(-1), fActive(Active), fNbOfSensitiveVol(0), fVerboseLevel(0), flGeoPar(0), kGeoSaved(kFALSE) { svList=new TRefArray(); vList=new CbmVolumeList(); } //__________________________________________________________________________ CbmModule::CbmModule() : fgeoVer("Not defined"), fgeoName("Not defined"), fModId(-1), fActive(kFALSE), fNbOfSensitiveVol(0), fVerboseLevel(0), flGeoPar(0), kGeoSaved(kFALSE) { } void CbmModule::Streamer(TBuffer& b) { TNamed::Streamer(b); if (b.IsReading()) { fgeoVer.Streamer(b); fgeoName.Streamer(b); b >> fActive; b >> fModId; }else{ fgeoVer.Streamer(b); fgeoName.Streamer(b); b << fActive; b << fModId; } } void CbmModule::SetGeometryFileName(TString fname, TString geoVer) { fgeoVer=geoVer; TString FileName = fname; TString work = getenv("VMCWORKDIR"); TString userwork = getenv("GEOMPATH"); if(userwork != ""){ fgeoName=userwork; if (!fgeoName.EndsWith("/")) fgeoName+="/"; //fgeoName+=fname; if (TString(gSystem->FindFile(fgeoName.Data(),fname)) != TString("")){ fgeoName=fname; cout << "------------------------------------------------------------------"<< endl; cout << "---User path for detector geometry : " << fgeoName.Data() << endl; }else{ cout << "---Detector geometry was not found in user path : " << FileName.Data() << endl; fgeoName=work+"/geometry/"; cout << "---Try the standard path : " << fgeoName.Data() << endl; if (TString(gSystem->FindFile(fgeoName.Data(),FileName)) != TString("")){ fgeoName=FileName; cout << "---Reading detector geometry from : "<< FileName.Data() << endl; }else{ Fatal("CBMModule::SetGeometryFileName", "Detector geometry not found."); } cout << "------------------------------------------------------------------"<< endl; } }else{ fgeoName=work+"/geometry/"; fgeoName+=fname; } } void CbmModule::ProcessNodes(TList *aList){ TListIter iter(aList); CbmGeoNode* node = NULL; CbmGeoNode* MotherNode =NULL; CbmVolume* volume = NULL; CbmRuntimeDb *rtdb= CbmRun::Instance()->GetRuntimeDb(); CbmBaseParSet* par=(CbmBaseParSet*)(rtdb->getContainer("CbmBaseParSet")); TObjArray *fNodes = par->GetGeoNodes(); while( (node = (CbmGeoNode*)iter.Next()) ) { node->calcLabTransform(); // cout << "-I ProcessNodes() Node: " << node->GetName() << " copyNo: " << node->getCopyNo() // << " LabTransform: " << node->getLabTransform() << endl; // node->Dump(); // GetListOfGeoPar()->Add( node ); MotherNode=node->getMotherNode(); volume = new CbmVolume( node->getTruncName(), fNbOfVolumes++); volume->setRealName(node->GetName()); vList->addVolume(volume); volume->setGeoNode(node); volume->setCopyNo( node->getCopyNo()); if(MotherNode!=0){ volume->setMotherId(node->getMCid()); volume->setMotherCopyNo(MotherNode->getCopyNo()); } CbmGeoVolume *aVol=NULL; if ( node->isSensitive() && fActive ) { volume->setModId(fModId); volume->SetModule(this); svList->Add(volume); aVol = dynamic_cast ( node ); fNodes->AddLast( aVol ); fNbOfSensitiveVol++; } } /* cout << " CbmModule::ProcessNodes "<< endl; svList->ls(); cout << " CbmModule::ProcessNodes "<< endl; */ } void CbmModule::AddSensitiveVolume(TGeoVolume *v){ // cout <<"CbmModule::AddSensitiveVolume " << v->GetName() << endl; CbmVolume* volume = NULL; volume = new CbmVolume(v->GetName(), fNbOfVolumes++); vList->addVolume(volume); volume->setModId(fModId); volume->SetModule(this); svList->Add(volume); fNbOfSensitiveVol++; } CbmVolume* CbmModule::getCbmVolume(CbmGeoNode *fN) { CbmVolume *fv; CbmVolume *fvol=0; // cout << " CbmModule::getCbmVolume " << fN << endl; for(Int_t i=0; igetEntries();i++){ fv=vList->At(i); // cout << "" << fv->getGeoNode() << " " << fN <getGeoNode())==fN){ // cout << "Inside " << fv->getGeoNode() << " " << fN <GetListOfKeys(); TKey *key; TIter next( l); TGeoNode *n=0; TGeoVolume *v1=0; while ((key = (TKey*)next())) { if (strcmp(key->GetClassName(),"TGeoManager") != 0) continue; gGeoManager=0; NewGeo = (TGeoManager*)key->ReadObj(); break; } if (NewGeo!=0){ NewGeo->cd(); volume=(TGeoVolume*)NewGeo->GetNode(0)->GetDaughter(0)->GetVolume(); v1=volume->MakeCopyVolume(volume->GetShape()); //n=NewGeo->GetTopNode(); n=v1->GetNode(0); // NewGeo=0; delete NewGeo; }else{ key=(TKey *) l->At(0); volume=(TGeoVolume *)key->ReadObj(); n=volume->GetNode(0); v1=n->GetVolume(); } if(v1==0) { cout << "CbmModule::ConstructRootGeometry(): could not find any geometry in File!! " << GetGeometryFileName().Data() << endl; exit(0); } gGeoManager=OldGeo; gGeoManager->cd(); 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 NewGeo; delete f; } void CbmModule::ConstructASCIIGeometry(){ cout << " CbmModule::ConstructASCIIGeometry() : this method has to be implimented in detector class " << endl; } Bool_t CbmModule::CheckIfSensitive(std::string name){ cout << " CbmModule::CheckIfSensitive(std::string name): this method has to be implimented in detector class " << endl; return kFALSE; } void CbmModule::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(); TObjArray *NodeList=v1->GetNodes(); 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); } }else{ if (strcmp(v->ClassName(),"TGeoVolumeAssembly") != 0) {; //[R.K.-3.3.08] // When there is NO material defined, set it to avoid conflicts in Geant std::cout<<" -E- Error in CbmModule::ExpandNode()! " <<"\tThe volume "<GetName()<<" Has no medium information."<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); } } } //__________________________________________________________________________ ClassImp(CbmModule)