/** CbmMuch class * * @author A.Kiseleva * @version 0.0 * @since 13.04.06 * * Class for MUon CHambers detector * */ #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 "CbmGeoMuch.h" #include "CbmRootManager.h" #include "CbmMuch.h" #include "CbmMuchPoint.h" #include "CbmRuntimeDb.h" #include "CbmGeoMuchPar.h" #include "TObjArray.h" #include "CbmRun.h" #include "CbmVolume.h"; ClassImp(CbmMuch) // ----- Default constructor ------------------------------------------- CbmMuch::CbmMuch() { ResetParameters(); fMuchCollection = new TClonesArray("CbmMuchPoint"); fPosIndex = 0; kGeoSaved = kFALSE; flGeoPar = new TList(); flGeoPar->SetName( GetName()); fVerboseLevel = 1; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmMuch::CbmMuch(const char* name, Bool_t active) : CbmDetector(name, active) { ResetParameters(); fMuchCollection = new TClonesArray("CbmMuchPoint"); fPosIndex = 0; kGeoSaved = kFALSE; flGeoPar = new TList(); flGeoPar->SetName( GetName()); fVerboseLevel = 1; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmMuch::~CbmMuch() { if ( flGeoPar ) delete flGeoPar; if (fMuchCollection) { fMuchCollection->Delete(); delete fMuchCollection; } } // ------------------------------------------------------------------------- // ----- Public method ProcessHits -------------------------------------- Bool_t CbmMuch::ProcessHits(CbmVolume* vol) { // Set parameters at entrance of volume. Reset ELoss. if ( gMC->IsTrackEntering() ) { fELoss = 0.; fTime = gMC->TrackTime() * 1.0e09; fLength = gMC->TrackLength(); gMC->TrackPosition(fPos); gMC->TrackMomentum(fMom); } // Sum energy loss for all steps in the active volume fELoss += gMC->Edep(); // Create CbmMuchPoint at exit of active volume if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); fVolumeID = vol->getMCid(); if (fELoss == 0. ) return kFALSE; AddHit(fTrackID, fVolumeID, TVector3(fPos.X(), fPos.Y(), fPos.Z()), TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss); // Increment number of muID points for TParticle Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1); Int_t nMuchPoints = (points & (15<<20)) >> 20; nMuchPoints ++; if (nMuchPoints > 15) nMuchPoints = 15; points = ( points & ( ~ (15<<20) ) ) | (nMuchPoints << 20); gMC->GetStack()->GetCurrentTrack()->SetMother(1,points); ResetParameters(); } return kTRUE; } // ---------------------------------------------------------------------------- //void CbmMuch::SaveGeoParams(){ // // cout << " -I Save Much geo params " << endl; // // TFolder *mf = (TFolder*) gDirectory->FindObjectAny("cbmroot"); // cout << " mf: " << mf << endl; // TFolder *Muchf = NULL; // if (mf ) Muchf = (TFolder*) mf->FindObjectAny(GetName()); // cout << " Muchf: " << Muchf << endl; // if (Muchf) Muchf->Add( flGeoPar0 ) ; // CbmRootManager::Instance()->WriteFolder(); // mf->Write("cbmroot",TObject::kWriteDelete); //} // ----- Public method EndOfEvent ----------------------------------------- void CbmMuch::BeginEvent() { // if (! kGeoSaved ) { // SaveGeoParams(); // cout << "-I Much geometry parameters saved " << endl; // kGeoSaved = kTRUE; // } } // ----- Public method EndOfEvent ----------------------------------------- void CbmMuch::EndOfEvent() { if (fVerboseLevel) Print(); fMuchCollection->Clear(); ResetParameters(); } // ---------------------------------------------------------------------------- // ----- Public method Register ------------------------------------------- void CbmMuch::Register() { CbmRootManager::Instance()->Register("MuchPoint", GetName(), fMuchCollection, kTRUE); } // ---------------------------------------------------------------------------- // ----- Public method GetCollection -------------------------------------- TClonesArray* CbmMuch::GetCollection(Int_t iColl) const { if (iColl == 0) return fMuchCollection; else return NULL; } // ---------------------------------------------------------------------------- // ----- Public method Print ---------------------------------------------- void CbmMuch::Print() const { Int_t nHits = fMuchCollection->GetEntriesFast(); cout << "-I- CbmMuch: " << nHits << " points registered in this event." << endl; } // ---------------------------------------------------------------------------- // ----- Public method Reset ---------------------------------------------- void CbmMuch::Reset() { fMuchCollection->Clear(); ResetParameters(); } // ---------------------------------------------------------------------------- // ----- Public method CopyClones ----------------------------------------- void CbmMuch::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) { Int_t nEntries = cl1->GetEntriesFast(); cout << "-I- CbmMuch: " << nEntries << " entries to add." << endl; TClonesArray& clref = *cl2; CbmMuchPoint* oldpoint = NULL; for (Int_t i=0; iAt(i); Int_t index = oldpoint->GetTrackID() + offset; oldpoint->SetTrackID(index); new (clref[fPosIndex]) CbmMuchPoint(*oldpoint); fPosIndex++; } cout << " -I- CbmMuch: " << cl2->GetEntriesFast() << " merged entries." << endl; } // ---------------------------------------------------------------------------- // ----- Public method ConstructGeometry ---------------------------------- void CbmMuch::ConstructGeometry() { cout<<"CbmMuch::ConstructGeometry() called"<getGeoInterface(); CbmGeoMuch* MuchGeo = new CbmGeoMuch(); MuchGeo->setGeomFile(GetGeometryFileName()); geoFace->addGeoModule(MuchGeo); Bool_t rc = geoFace->readSet(MuchGeo); if (rc) MuchGeo->create(geoLoad->getGeoBuilder()); TList* volList = MuchGeo->getListOfVolumes(); // store geo parameter CbmRun *fRun = CbmRun::Instance(); CbmRuntimeDb *rtdb= CbmRun::Instance()->GetRuntimeDb(); CbmGeoMuchPar* par=(CbmGeoMuchPar*)(rtdb->getContainer("CbmGeoMuchPar")); 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 -------------------------------------------- CbmMuchPoint* CbmMuch::AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss) { TClonesArray& clref = *fMuchCollection; Int_t size = clref.GetEntriesFast(); return new(clref[size]) CbmMuchPoint(trackID, detID, pos, mom, time, length, eLoss); } // ----------------------------------------------------------------------------