// ------------------------------------------------------------------------- // ----- CbmZdc source file ----- // ----- Created 27/07/04 by V. Friese ----- // ------------------------------------------------------------------------- #include "iostream.h" #include "TClonesArray.h" #include "TGeoMCGeometry.h" #include "TParticle.h" #include "TVirtualMC.h" #include "CbmGeoInterface.h" #include "CbmGeoLoader.h" #include "CbmGeoNode.h" #include "CbmGeoRootBuilder.h" #include "CbmGeoZdc.h" #include "CbmRootManager.h" #include "CbmZdc.h" #include "CbmZdcPoint.h" class CbmVolume; // ----- Default constructor ------------------------------------------- CbmZdc::CbmZdc() { fZdcCollection = new TClonesArray("CbmZdcPoint"); fPosIndex = 0; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmZdc::CbmZdc(const char* name, Bool_t active) : CbmDetector(name, active) { fZdcCollection = new TClonesArray("CbmZdcPoint"); fPosIndex = 0; fDebug = ""; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmZdc::~CbmZdc() { if (fZdcCollection) { fZdcCollection->Delete(); delete fZdcCollection; } } // ------------------------------------------------------------------------- // ----- Public method ProcessHits -------------------------------------- Bool_t CbmZdc::ProcessHits(CbmVolume* vol) { // Stores all particles at entrance to active detector. // Set parameters at entrance of volume. ELoss is set to the // kinetic energy, mimicking complete stopping in the calorimeter. if ( gMC->IsTrackEntering() ) { gMC->TrackPosition(fPos); gMC->TrackMomentum(fMom); fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); fVolumeID = vol->getMCid(); fTime = gMC->TrackTime() * 1.0e09; // conversion to ns fLength = gMC->TrackLength(); Double_t mass = gMC->TrackMass(); // Calculate kinetic energy Double_t ekin = TMath::Sqrt( fMom.Px()*fMom.Px() + fMom.Py()*fMom.Py() + fMom.Pz()*fMom.Pz() + mass * mass ) - mass; fELoss = ekin; // Create CbmZdcPoint AddHit(fTrackID, fVolumeID, TVector3(fPos.X(), fPos.Y(), fPos.Z()), TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss); // Increment number of ecal points for TParticle Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1); Int_t nZdcPoints = (points & (15<<16)) >> 16; nZdcPoints ++; if (nZdcPoints > 15) nZdcPoints = 15; points = ( points & ( ~ (15<<16) ) ) | (nZdcPoints << 16); gMC->GetStack()->GetCurrentTrack()->SetMother(1,points); ResetParameters(); } return kTRUE; } // ------------------------------------------------------------------------- // ----- Public method EndOfEvent -------------------------------------- void CbmZdc::EndOfEvent() { if (fVerboseLevel) Print(); fZdcCollection->Clear(); fPosIndex = 0; } // ------------------------------------------------------------------------- // ----- Public method Register ---------------------------------------- void CbmZdc::Register() { CbmRootManager::Instance()->Register("ZDCPoint", "Zdc", fZdcCollection, kTRUE); } // ------------------------------------------------------------------------- // ----- Public method GetCollection ----------------------------------- TClonesArray* CbmZdc::GetCollection(Int_t iColl) const { if (iColl == 0) return fZdcCollection; else return NULL; } // ------------------------------------------------------------------------- // ----- Public method Print ------------------------------------------- void CbmZdc::Print() const { Int_t nHits = fZdcCollection->GetEntriesFast(); cout << "-I- CbmZdc: " << nHits << " points registered in this event." << endl; if (fVerboseLevel>1) for (Int_t i=0; iPrint(); } // ------------------------------------------------------------------------- // ----- Public method Reset ------------------------------------------- void CbmZdc::Reset() { fZdcCollection->Clear(); ResetParameters(); } // ------------------------------------------------------------------------- // ----- Public method CopyClones -------------------------------------- void CbmZdc::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset){ Int_t nEntries = cl1->GetEntriesFast(); cout << "-I- CbmZdc: " << nEntries << " entries to add." << endl; TClonesArray& clref = *cl2; CbmZdcPoint* oldpoint = NULL; for (Int_t i=0; iAt(i); Int_t index = oldpoint->GetTrackID() + offset; oldpoint->SetTrackID(index); new (clref[fPosIndex]) CbmZdcPoint(*oldpoint); fPosIndex++; } cout << "-I- CbmZdc: " << cl2->GetEntriesFast() << " merged entries." << endl; } // ------------------------------------------------------------------------- // ----- Public method ConstructGeometry ------------------------------- void CbmZdc::ConstructGeometry() { CbmGeoLoader* geoLoad = CbmGeoLoader::Instance(); CbmGeoInterface* geoFace = geoLoad->getGeoInterface(); CbmGeoZdc* ecalGeo = new CbmGeoZdc(); ecalGeo->setGeomFile(GetGeometryFileName()); geoFace->addGeoModule(ecalGeo); Bool_t rc = geoFace->readSet(ecalGeo); if (rc) ecalGeo->create(geoLoad->getGeoBuilder()); TList* volList = ecalGeo->getListOfVolumes(); TListIter iter(volList); CbmGeoNode* node = NULL; CbmVolume* volume = NULL; while( (node = (CbmGeoNode*)iter.Next()) ) { volume = new CbmVolume( node->getName(), fNbOfVolumes++); cout << fNbOfVolumes << endl; vList->addVolume(volume); if ( node->isSensitive() && fActive ) { volume->setDetId(fdetId); volume->SetModule(this); svList->Add(volume); fNbOfSensitiveVol++; } } } // ------------------------------------------------------------------------- // ----- Private method AddHit ----------------------------------------- CbmZdcPoint* CbmZdc::AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss) { TClonesArray& clref = *fZdcCollection; Int_t size = clref.GetEntriesFast(); return new(clref[size]) CbmZdcPoint(trackID, detID, pos, mom, time, length, eLoss); } // ------------------------------------------------------------------------- ClassImp(CbmZdc)