// ------------------------------------------------------------------------- #include "iostream.h" #include "TClonesArray.h" #include "TGeoMCGeometry.h" #include "TGeoManager.h" #include "TLorentzVector.h" #include "TParticle.h" #include "TVirtualMC.h" #include "CbmGeoInterface.h" #include "CbmGeoLoader.h" #include "CbmGeoNode.h" #include "CbmGeoMuo.h" #include "CbmGeoRootBuilder.h" #include "CbmStack.h" #include "CbmMuo.h" #include "CbmMuoPoint.h" #include "CbmRootManager.h" #include "CbmVolume.h" // add on for debug #include "CbmGeoG3Builder.h" #include "CbmRuntimeDb.h" #include "TObjArray.h" #include "CbmRun.h" // ----- Default constructor ------------------------------------------- CbmMuo::CbmMuo() { fMuoCollection = new TClonesArray("CbmMuoPoint"); fPosIndex = 0; nFlag = 0; nSec = -1; } // ------------------------------------------------------------------------- // ----- Standard constructor ------------------------------------------ CbmMuo::CbmMuo(const char* name, Bool_t active) : CbmDetector(name, active) { fMuoCollection = new TClonesArray("CbmMuoPoint"); fPosIndex = 0; nFlag = 0; nSec = -1; fEventID=-1; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmMuo::~CbmMuo() { if (fMuoCollection) { fMuoCollection->Delete(); delete fMuoCollection; } } // ------------------------------------------------------------------------- // ----- Public method Intialize --------------------------------------- void CbmMuo::Initialize() { // controlla-- forse non tutto e' necessario. CbmDetector::Initialize(); CbmRun* sim = CbmRun::Instance(); CbmRuntimeDb* rtdb=sim->GetRuntimeDb(); par=(CbmGeoMuoPar*)(rtdb->getContainer("CbmGeoMuoPar")); // TObjArray *fSensNodes = par->GetGeoSensitiveNodes(); } // ------------------------------------------------------------------------- void CbmMuo::BeginEvent(){ //cout<<">>>>>>>>>>>>>>>>>>>>inizio evento "<GetStack()->GetCurrentTrackNumber(); // trk ID fEventID = gMC->CurrentEvent(); // cout<<"nuova traccia"<IsTrackEntering() ) { nFlag = -1; } if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { nFlag = 1; } gMC->TrackPosition(fPos); // cm gMC->TrackMomentum(fMom); // GeV TString nam = gMC->CurrentVolName(); TVector3 pos(fPos.X(), fPos.Y(), fPos.Z()); Int_t nPlane = -1, nBox = -1, nTube = -1; nSec = nam[4]-49; gMC->CurrentVolOffID(3, nPlane); nPlane--; gMC->CurrentVolOffID(2, nBox); nBox--; gMC->CurrentVolOffID(0, nTube); nTube--; // Set additional parameters at exit of active volume. Create CbmMuoPoint. if (nFlag==1) AddHit(fTrackID, fVolumeID, fEventID, TVector3(fPos.X(), fPos.Y(), fPos.Z()), TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss, nFlag, nSec, (Short_t)nPlane, (Short_t)nBox, (Short_t)nTube); ResetParameters(); return kTRUE; } // ---------------------------------------------------------------------------- // ----- Public method EndOfEvent ----------------------------------------- void CbmMuo::EndOfEvent() { if (fVerboseLevel) Print(); Reset(); } // ---------------------------------------------------------------------------- // ----- Public method Register ------------------------------------------- void CbmMuo::Register() { CbmRootManager::Instance()->Register("MuoPoint","Muo", fMuoCollection, kTRUE); } // ---------------------------------------------------------------------------- // ----- Public method GetCollection -------------------------------------- TClonesArray* CbmMuo::GetCollection(Int_t iColl) const { if (iColl == 0) return fMuoCollection; return NULL; } // ---------------------------------------------------------------------------- // ----- Public method Print ---------------------------------------------- void CbmMuo::Print() const { Int_t nHits = fMuoCollection->GetEntriesFast(); cout << "-I- CbmMuo: " << nHits << " points registered in this event." << endl; if (fVerboseLevel>1) for (Int_t i=0; iPrint(); } // ---------------------------------------------------------------------------- // ----- Public method Reset ---------------------------------------------- void CbmMuo::Reset() { fMuoCollection->Clear(); fPosIndex = 0; } // ---------------------------------------------------------------------------- // guarda in CbmRootManager::CopyClones // ----- Public method CopyClones ----------------------------------------- void CbmMuo::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) { Int_t nEntries = cl1->GetEntriesFast(); cout << "-I- CbmMuo: " << nEntries << " entries to add." << endl; TClonesArray& clref = *cl2; CbmMuoPoint* oldpoint = NULL; for (Int_t i=0; iAt(i); Int_t index = oldpoint->GetTrackID() + offset; oldpoint->SetTrackID(index); new (clref[fPosIndex]) CbmMuoPoint(*oldpoint); fPosIndex++; } cout << " -I- CbmMuo: " << cl2->GetEntriesFast() << " merged entries." << endl; } // ---------------------------------------------------------------------------- // ----- Public method ConstructGeometry ---------------------------------- void CbmMuo::ConstructGeometry() { CbmGeoLoader* muogeoLoad = CbmGeoLoader::Instance(); CbmGeoInterface* muogeoFace = muogeoLoad->getGeoInterface(); CbmGeoMuo* muoGeo = new CbmGeoMuo(); muoGeo->setGeomFile(GetGeometryFileName()); muogeoFace->addGeoModule(muoGeo); Bool_t rc = muogeoFace->readSet(muoGeo); if (rc) muoGeo->create(muogeoLoad->getGeoBuilder()); TList* volList = muoGeo->getListOfVolumes(); // store geo parameter CbmRun *fRun = CbmRun::Instance(); CbmRuntimeDb *rtdb= CbmRun::Instance()->GetRuntimeDb(); CbmGeoMuoPar* par=(CbmGeoMuoPar*)(rtdb->getContainer("CbmGeoMuoPar")); 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 ); } } ProcessNodes ( volList ); par->setChanged(); par->setInputVersion(fRun->GetRunId(),1); } // ---------------------------------------------------------------------------- /* Short_t CbmMuo::GetPlane(TVector3 pos) { MuoTransform(pos); return (Short_t)((pos.Y()*10.-par->barrel_y)/par->dplane); } Short_t CbmMuo::GetBox(TVector3 pos) { MuoTransform(pos); return (Short_t)((pos.X()*10.+(par->nbox*par->dbox)*0.5)/par->dbox); } Short_t CbmMuo::GetTube(TVector3 pos) { MuoTransform(pos); return (Short_t)((pos.X()*10.+(par->nbox*par->dbox)*0.5-par->dbox*((Short_t)((pos.X()*10.+(par->nbox*par->dbox)*0.5)/par->dbox)))/par->dtube); } */ Short_t CbmMuo::GetStrip(TVector3 pos) { MuoTransform(pos); return (Short_t)((pos.Z()*10.-par->barrel_z)/par->dstrip); } void CbmMuo::MuoTransform(TVector3 &pos) { Double_t sec_x = pos.X(); Double_t sec_y = pos.Y(); pos.SetX(cos(TMath::Pi()/4.*nSec)*sec_x +sin(TMath::Pi()/4.*nSec)*sec_y); pos.SetY(-sin(TMath::Pi()/4.*nSec)*sec_x +cos(TMath::Pi()/4.*nSec)*sec_y); } // ----- Private method AddHit -------------------------------------------- CbmMuoPoint* CbmMuo::AddHit(Int_t trackID, Int_t detID, Int_t evtID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss, Short_t flag, Short_t sec, Short_t plane, Short_t box, Short_t tube) { TClonesArray& clref = *fMuoCollection; Int_t size = clref.GetEntriesFast(); if (fVerboseLevel>1) cout << "-I- CbmMuo: Adding Point at IN (" << pos.X() << ", " << pos.Y() << ", " << pos.Z() << ") cm, detector " << detID << ", evt " << evtID << ",flag "<< flag << ", track " << trackID <<", energy loss " << eLoss*1e06 << " keV, sec " << sec << " plane " << plane << " strip " << GetStrip(pos) << " box " << box << " tube " << tube << endl; return new(clref[size]) CbmMuoPoint(trackID, detID, evtID, pos, mom, time, length, eLoss, flag, sec, plane, GetStrip(pos), box, tube); } inline void CbmMuo::ResetParameters() { fTrackID = -999; fVolumeID = -999; fEventID = -999; fPos.SetXYZT(0., 0., 0., 0.); fMom.SetXYZT(0., 0., 0., 0.) ; fTime = -999; fLength = -999; fELoss = -999; nFlag = 0; nSec = -1; } // ---- ClassImp(CbmMuo)