#include "PndMvdDetector.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 "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 "TGeoVoxelFinder.h" #include "TGeoMatrix.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("PixelActive");//Root_Test.root fListOfSensitives.push_back("StripSensor");//MVD14.root fListOfSensitives.push_back("SensorActiveArea");//MVD14.root fListOfSensitives.push_back("StripActive");//MVD_v1.0.root fListOfSensitives.push_back("PixelActive");//MVD_v1.0.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() { std::cout<<" -I- Initializing PndMvdDetector()"<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 (fVolumeIDMap[gMC->CurrentVolPath()] == 0){ // fVolumeIDMap[gMC->CurrentVolPath()] = fVolumeIDMap.size()+1; // } //fVolumeID = fVolumeIDMap[gMC->CurrentVolPath()]; if(0==fGeoH) { std::cout<<" -E- No PndMvdGeoHandling loaded."< 1){ std::cout << "******* Info from gMC *************" << std::endl; std::cout << "Hit in " << gMC->CurrentVolPath() << " with MCiD: " << vol->getMCid() << " PixelDetectorID: " << fVolumeID << std::endl; std::cout<<"VolumeID: "<GetID(gMC->CurrentVolPath())<CurrentVolPath()).Contains("Pixel") )fVolumeID = 1; else if( ((TString)gMC->CurrentVolPath()).Contains("Strip") )fVolumeID = 2; else std::cout << "Unknown Mvd Sensor type in volume\n"<CurrentVolPath()<TrackPosition(fPosOut); gMC->TrackMomentum(fMomOut); if (fELoss == 0.) return kFALSE; TString detPath = gMC->CurrentVolPath(); if (detPath.Contains("Strip")) fVolumeID = 2; else fVolumeID = 1; AddHit(fTrackID, fVolumeID, fGeoH->GetID(detPath), 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() { } // ----- 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 " <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);