/* Generated by Together */ #include "FairMCApplication.h" #include "HadesTof.h" #include "FairVolume.h" #include "TGeoMCGeometry.h" #include "TGeoManager.h" #include "TGeoVolume.h" #include "TGeoMedium.h" #include "FairGeoInterface.h" #include "FairGeoBuilder.h" #include "FairGeoSet.h" #include "FairGeoNode.h" #include "TList.h" #include "HadesTofPoint.h" #include "TLorentzVector.h" #include "TVirtualMC.h" #include "TVirtualMC.h" #include "FairGeoLoader.h" #include "FairGeoRootBuilder.h" #include "hgeotof.h" #include "iostream.h" #include "FairRootManager.h" ClassImp(HadesTof) void HadesTof::ConstructGeometry() { FairGeoLoader *geoLoad=FairGeoLoader::Instance(); FairGeoInterface *geoFace =geoLoad->getGeoInterface(); Bool_t rc = kTRUE; cout <<" -I Constructing Hades Tof " << endl; gset = new HGeoTof(); geoFace->addGeoModule(gset); gset->setGeomFile(GetGeometryFileName()); rc = geoFace->readSet(gset); if (rc) gset->create(geoLoad->getGeoBuilder()); TList* volList = gset->getListOfVolumes(); ProcessNodes ( volList ); } HadesTof::HadesTof(){ gset = NULL; } HadesTof::~HadesTof() { } HadesTof::HadesTof(const char * name, Bool_t Active ) : FairDetector(name , Active), fTofCollection(0) { fTofCollection = new TClonesArray("HadesTofPoint"); } void HadesTof::Initialize() { TRefArray *SDList = FairDetector::svList; Int_t NoOfEntries=SDList->GetEntries(); TString cutName; for (Int_t i = 0 ; i < NoOfEntries ; i++ ) { FairVolume* aVol = (FairVolume*) SDList->At(i); cutName = aVol->getName(); // cout << " -I HadTof volume name 1 " << aVol->getName() << endl; cutName.Resize(4); if ( aVol->getModId() == GetModId() ) { cout << " -I HadTof sensitive: " << aVol->getName() << endl; TString motherName(""); FairGeoNode* node = aVol->getGeoNode(); // get the sectors number Int_t ll=0; TGeoNode *motherNode; /* while ( !motherName.Contains("SEC")){ ll++; motherNode = gGeoManager->GetMother(ll); motherName = motherNode->GetVolume()->GetName(); } */ aVol->setMCid(gMC->VolId(cutName)); } } } Bool_t HadesTof::ProcessHits(FairVolume *v) { // get info about volume Int_t vId = v->getMCid(); TGeoNode *cNode = gGeoManager->GetCurrentNode(); cout << "current node " << cNode->GetName() << endl; HGeoTof *fTof = (HGeoTof*) gset; TString nodname = cNode->GetName(); // find mother volume TGeoVolume* mVol = cNode->GetMotherVolume(); cout << "mother " << mVol->GetName() << endl; TGeoNode* motherNode = NULL; TString motherName(""); Int_t ll=0; while ( !motherName.Contains("SEC")){ ll++; motherNode = gGeoManager->GetMother(ll); motherName = motherNode->GetVolume()->GetName(); } cout <<" mother name " << motherName.Data() << endl; // nodname.Resize(4); // cout << "sec" << fTof->getSecNumInMod( nodname ) // << "mod" << fTof->getModNumInMod( nodname ) << endl; Double_t fEdep = 0.0; Int_t copyNo; HadesTofPoint *trdPoint=NULL; if ( gMC->IsTrackExiting() ) { // first test if E deposit is not null ! fEdep=gMC->Edep(); if (fEdep == 0.0 ) return kFALSE; trdPoint = AddHit(); Int_t volId = gMC->CurrentVolID(copyNo); cout << " volid : copy n0 " << volId << ":" << copyNo << endl; trdPoint->SetDetectorID(v->getMCid()); trdPoint->SetELoss(fEdep); trdPoint->SetEtot(gMC->Etot()); trdPoint->SetTime(gMC->TrackTime()); trdPoint->SetLength(gMC->TrackLength()); trdPoint->SetTrackID(gMC->GetStack()->GetCurrentTrackNumber()); TLorentzVector pos; gMC->TrackPosition(pos); // transform position Double_t xx[3]={0.,0.,0.}; Double_t ref[3]={pos.X(),pos.Y(),pos.Z()}; // Convert from master to local coordinates by spinning over levels // until we reach surface for ( Int_t ilev = gGeoManager->GetLevel(); ilev >= 0; ilev-- ) { TGeoNode* levnode = gGeoManager->GetMother(ilev); levnode->MasterToLocal(ref,xx); for ( int i=0; i<3; i++) ref[i] = xx[i]; } trdPoint->SetPos (TVector3(xx[0], xx[1], xx[2])); TLorentzVector mom; gMC->TrackMomentum(mom); trdPoint->SetMom (TVector3(mom.X(), mom.Y(), mom.Z())); } return kTRUE; } HadesTofPoint* HadesTof::AddHit() { // Creates a new hit in the TClonesArray. // --- TClonesArray& ref = *fTofCollection; Int_t size = ref.GetEntriesFast(); return new(ref[size]) HadesTofPoint(); } void HadesTof::EndOfEvent() { Reset(); } void HadesTof::Register() { FairRootManager::Instance()->Register("TofPoint","Tof", fTofCollection,kTRUE); } void HadesTof::Reset() { fTofCollection->Clear(); }