GEANT4中AIDA的调用.doc_第1页
GEANT4中AIDA的调用.doc_第2页
GEANT4中AIDA的调用.doc_第3页
GEANT4中AIDA的调用.doc_第4页
GEANT4中AIDA的调用.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Geant4 学习心得AIDA的使用 I AIDA(Abstract Interfaces for Data Analysis)主要是提供Hbook,ROOT,或者XML格式输出。在学习的过程中我们看到好几种不同的调用方式,在这里我们逐个总结出来。 extendedelectromagneticTestEM4例子的AIDA调用方式: (1)在RUNACTION.CC中定义hbook 一维谱(或者root,XML格式的文件) #ifdef G4ANALYSIS_USE #include AIDA/AIDA.h /需要的头文件 #endif RunAction:RunAction():af(0), tree(0) histo0 = 0; #ifdef G4ANALYSIS_USE / Creating the analysis factory af = AIDA_createAnalysisFactory(); if (af) / Creating the tree factory AIDA:ITreeFactory* tf = af-createTreeFactory(); / Creating a tree mapped to an hbook file. G4bool readOnly = false; G4bool createNew = true; G4String options = -noErrors uncompress; tree = tf-create(TestEm4.hbook,hbook,readOnly,createNew, options); /tree = tf-create(TestEm4.root,root,readOnly,createNew, options); /tree = tf-create(TestEm4.XML ,XML ,readOnly,createNew, options); delete tf; if (tree) / Creating a histogram factory AIDA:IHistogramFactory* hf = af-createHistogramFactory(*tree); / Creating the histogram histo0=hf-createHistogram1D / 头文件中定义了histo1 (1,total energy deposit in HpGe Detector(keV),3000,1.,3000); / energy ragin 1-5000keV delete hf; #endif RunAction:RunAction() #ifdef G4ANALYSIS_USE tree-commit(); / Writing the histograms to the file tree-close(); / and closing the tree (and the file) delete tree; delete af; #endif (2)在EVENTACTION.CC中累积谱 #ifdef G4ANALYSIS_USE #include AIDA/IHistogram1D.h #endif void EventAction:BeginOfEventAction( const G4Event* evt) G4int evtNb = evt-GetEventID(); /additional initializations TotalEnergyDeposit = 0.; / 初始化能量变量 void EventAction:EndOfEventAction( const G4Event* evt) #ifdef G4ANALYSIS_USE Run-GetHisto(0)-fill(TotalEnergyDeposit/MeV); #endif 总结:这是最简单的定义一维Histogram的办法。 Geant4 学习心得AIDA的使用 II AIDA(Abstract Interfaces for Data Analysis)主要是提供Hbook,ROOT,或者XML格式输出。在学习的过程中有几种不同的调用方式。 extendedhadronicHadr01例子的AIDA调用方式: (1)在RUNACTION.CC中调用HistoManager管理器 void RunAction:EndOfRunAction(const G4Run*) HistoManager:GetPointer()-EndOfRun(); /获得Histo的指针 (2)在HistoManger.CC中定义HisyoManger的子函数等 HistoManager* HistoManager:fManager = 0; HistoManager* HistoManager:GetPointer() if(!fManager) static HistoManager manager; fManager = &manager; return fManager; (3)在Histo.CC中定义Hbook文件等 #include Histo.hh #ifdef G4ANALYSIS_USE #include #include HistoMessenger.hh #endif Histo:Histo(G4int ver) verbose = ver; histName = histo; histType = hbook; option = -noErrors uncompress; nHisto = 0; defaultAct = 1; tupleName = tuple.hbook; tupleId = 100; tupleList = ; ntup = 0; messenger = 0; #ifdef G4ANALYSIS_USE messenger = new HistoMessenger(this); / messange 指针 tree = 0; af = 0; #endif Histo:Histo() #ifdef G4ANALYSIS_USE delete messenger; delete af; #endif void Histo:book() #ifdef G4ANALYSIS_USE / Creating the analysis factory if(!af) af = AIDA_createAnalysisFactory(); / Creating the tree factory AIDA:ITreeFactory* tf = af-createTreeFactory(); / Creating a tree mapped to a new hbook file. G4String name = histDir + histName + histExt + . + histType; tree = tf-create(name, histType, false, true, option); delete tf; / Creating a histogram factory, whose histograms will be handled by the tree AIDA:IHistogramFactory* hf = af-createHistogramFactory( *tree ); / Creating an 1-dimensional histograms in the root directory of the tree for(G4int i=0; icreateHistogram1D(idd, tittles, bins, xmin, xmax); else histo = 0; delete hf; / Creating a tuple factory, whose tuples will be handled by the tree if(tupleList != ) AIDA:ITupleFactory* tpf = af-createTupleFactory( *tree ); ntup = tpf-create(tupleId, tupleName, tupleList); delete tpf; #endif void Histo:save() #ifdef G4ANALYSIS_USE / Write histogram file tree-commit(); tree-close(); delete tree; tree = 0; #endif void Histo:reset() #ifdef G4ANALYSIS_USE delete tree; tree = 0; #endif void Histo:setFileType(const G4String& nam) if(nam = hbook | nam = root | nam = aida) histType = nam; else if(nam = XML | nam = xml) histType = aida; void Histo:add1D(const G4String& id, const G4String& name, G4int nb, G4double x1, G4double x2, G4double u) if(nHisto 0) for(G4int i=0; i=0 & i=0 & ifill(x/unit, w); #endif void Histo:scale(G4int i, G4double x) #ifdef G4ANALYSIS_USE if(i=0 & iscale(x); #endif void Histo:addTuple(const G4String& w1, const G4String& w2, const G4String& w3) tupleId = w1; tupleName = w2; tupleList = w3; void Histo:fillTuple(const G4String& parname, G4double x) #ifdef G4ANALYSIS_USE if(ntup) ntup-fill(ntup-findColumn(parname), (float)x); #endif void Histo:addRow() #ifdef G4ANALYSIS_USE if(ntup) ntup-addRow(); #endif void Histo:print(G4int i) #ifdef G4ANALYSIS_USE if(i=0 & inHisto) G4double step = (xmax - xmin)/G4double( bins); G4double x = xmin - step*0.5; G4double y, maxX=0, maxY=0; G4int maxJ=0; for(G4int j=0; jbinHeight(j); if(maxY GetRunID(); (HistoManager:GetPointer()-BeginOfRun(); void RunAction:EndOfRunAction(const G4Run*) HistoManager:GetPointer()-EndOfRun(); /开始累谱 (5)在灵敏探测器的定义中 TargetSD:TargetSD(const G4String& name) :G4VSensitiveDetector(name) theHisto = HistoManager:GetPointer(); G4bool TargetSD:ProcessHits(G4Step* aStep, G4TouchableHistory*) theHisto-AddTargetStep(aStep); return true; CheckVolumeSD:CheckVolumeSD(const G4String& name) :G4VSensitiveDetector(name) theHisto = HistoManager:GetPointer(); G4bool CheckVolumeSD:ProcessHits(G4Step* aStep, G4TouchableHistory*) const G4Track* track = aStep-GetTrack(); if(track-GetTrackID() 1) theHisto-AddLeakingParticle(track); return true; Geant4 学习心得AIDA的使用 III AIDA(Abstract Interfaces for Data Analysis)主要是提供Hbook,ROOT,或者XML格式输出。在学习的过程中有几种不同的调用方式。 extendedbiasingB02例子的AIDA调用方式: (1)在MAIN.CC中调用AIDA / AIDA stuff #include AIDA/IAnalysisFactory.h #include AIDA/ITree.h #include AIDA/ITreeFactory.h #include AIDA/IHistogram1D.h #include AIDA/IHistogramFactory.h int main(int , char *) / create a histogram for a special scorer for the last cell AIDA:IAnalysisFactory *af = AIDA_createAnalysisFactory(); AIDA:ITreeFactory *tf = af-createTreeFactory(); AIDA:ITree *tree = tf-create(b02.hbook, hbook,false,true); AIDA:IHistogramFactory *hf = af-createHistogramFactory( *tree ); AIDA:IHistogram1D *h = hf-createHistogram1D(10,w*sl vs. e, 30, 0., 20*MeV); tree-commit(); tree-close(); delete af; delete tf; delete tree; delete runManager; return 0; (2)在Score中调用Histo,在hh头文件中定义了fHisto B02CellScorer:B02CellScorer(AIDA:IHistogram1D *h):fHisto(h) void B02CellScorer:ScoreAnExitingStep(const G4Step &aStep, const G4GeometryCell &pre_gCell) fG4CellScorer.ScoreAnExitingStep(aStep, pre_gCell); FillHisto(aStep); void B02CellScorer:FillHisto(const G4Step &aStep) G4StepPoint *p = 0; p = aStep.GetPreStepPoint(); G4double sl = aStep.GetStepLength(); G4double slw = sl * p-GetWeight(); fHisto-fill(p-GetKineticEnergy(), slw); Geant4 学习心得AIDA的使用 IV AIDA(Abstract Interfaces for Data Analysis)主要是提供Hbook,ROOT,或者XML格式输出。在学习的过程中有几种不同的调用方式。 extendedAnalysisAnaEx01例子的AIDA调用方式:采用AnalysisManager.cc (1)在AnalysisManager.cc中定义所有的Histogram,Tuple 以及 Plotter等 #ifdef G4ANALYSIS_USE #include G4ios.hh #include G4SDManager.hh #include G4Run.hh #include G4Event.hh #include G4HCofThisEvent.hh #include #include #include #include #include #include #include #include AnaEx01CalorHit.hh #include AnaEx01AnalysisManager.hh AnaEx01AnalysisManager:AnaEx01AnalysisManager(AIDA:IAnalysisFactory* aAIDA) :fCalorimeterCollID(-1),fAIDA(aAIDA),fTree(0),fEAbs(0),fLAbs(0),fEGap(0), fLGap(0),fTuple(0) / Could fail if no AIDA implementation found : if(!fAIDA) G4cout AIDA analysis factory not found. createTreeFactory(); if(!treeFactory) return; / Create a tree-like container to handle histograms. / This tree is associated to a AnaEx01. file. std:string h_name_EAbs(EAbs); std:string h_name_LAbs(LAbs); std:string h_name_EGap(EGap); std:string h_name_LGap(LGap); std:string t_name(AnaEx01); / File format : std:string format(xml); /std:string format(hbook); /std:string format(root); std:string file(AnaEx01); std:string ext; ext = .+format; std:string opts; if(format=hbook) opts = compress=no; h_name_EAbs = 1; h_name_LAbs = 2; h_name_EGap = 3; h_name_LGap = 4; t_name = 101; else if(format=root) opts = compress=yes; else if(format=xml) ext = .aida; opts = compress=no; else G4cout storage format format not handled in this example. create(file,format,false,true,opts); / Factories are not managed by an AIDA analysis system. / They must be deleted by the AIDA user code. delete treeFactory; if(!fTree) G4cout cant create tree associated to file file . mkdir(histograms); fTree-cd(histograms); / Create an histo factory that will create histo in the tree : AIDA:IHistogramFactory* histoFactory = fAIDA-createHistogramFactory(*fTree); if(histoFactory) fEAbs = histoFactory-createHistogram1D(h_name_EAbs,EAbs,100,0,100); if(!fEAbs) G4cout cant create histo EAbs. createHistogram1D(h_name_LAbs,LAbs,100,0,100); if(!fLAbs) G4cout cant create histo LAbs. createHistogram1D(h_name_EGap,EGap,100,0,10); if(!fEGap) G4cout cant create histo EGap. createHistogram1D(h_name_LGap,LGap,100,0,100); if(!fLGap) G4cout cant create histo LGap. cd(.); fTree-mkdir(tuples); fTree-cd(tuples); / Get a tuple factory : AIDA:ITupleFactory* tupleFactory = fAIDA-createTupleFactory(*fTree); if(tupleFactory) / Create a tuple : fTuple = tupleFactory-create(t_name,AnaEx01, double EAbs,double LAbs,double EGap,double LGap); if(!fTuple) G4cout cant create tuple. cd(.); AnaEx01AnalysisManager:AnaEx01AnalysisManager() void AnaEx01AnalysisManager:BeginOfRun(const G4Run* aRun) G4cout # Run GetRunID() start. commit(); if(fEAbs) G4cout Histo : EAbs : mean mean() rms : rms() G4endl; G4cout Histo : LAbs : mean mean() rms : rms() G4endl; G4cout Histo : EGap : mean mean() rms : rms() G4endl; G4cout Histo : LGap : mean mean() rms : rms() GetCollectionID(CalCollection); void AnaEx01AnalysisManager:EndOfEvent(const G4Event* aEvent) if(!fEAbs) return; / No histo booked ! if(!fTuple) return; / No tuple booked ! /G4int evtNb = aEvent-GetEventID(); G4HCofThisEvent* HCE = aEvent-GetHCofThisEvent(); AnaEx01CalorHitsCollection* CHC = HCE ? (AnaEx01CalorHitsCollection*)(HCE-GetHC(fCalorimeterCollID) : 0; if(CHC) G4int n_hit = CHC-entries(); for (G4int i=0;iGetEdepAbs(); G4double LAbs = (*CHC)-GetTrakAbs(); G4double EGap = (*CHC)-GetEdepGap(); G4double LGap = (*CHC)-GetTrakGap(); fEAbs-fill(EAbs); fLAbs-fill(LAbs); fEGap-fill(EGap); fLGap-fill(LGap); fTuple-fill(0,EAbs); fTuple-fill(1,LAbs); fTuple-fill(2,EGap); fTuple-fill(3,LGap); fTuple-addRow(); void AnaEx01AnalysisManager:Step(const G4Step*) #endif (2)头文件定义为: #ifndef AnaEx01AnalysisManager_h #define AnaEx01AnalysisManager_h 1 #ifdef G4ANALYSIS_USE class G4Run; class G4Event; class G4Step; namespace AIDA class IAnalysisFactory; class ITree; class IHistogram1D; class ITuple; class AnaEx01AnalysisManager public: AnaEx01AnalysisManager(AIDA:IAnalysisFactory*); virtual AnaEx01AnalysisManager(); public: virtual void BeginOfRun(const G4Run*); virtual void EndOfRun(const G4Run*); virtual void BeginOfEvent(const G4Event*); virtual void EndOfEvent(const G4Event*); virtual void Step(const G4Step*); private: int fCalorimeterCollID; AIDA:IAnalysisFactory* fAIDA; AIDA:ITree* fTree; AIDA:IHistogram1D* fEAbs; AIDA:IHistogram1D* fLAbs; AIDA:IHistogram1D* fEGap; AIDA:IHistogram1D* fLGap; AIDA:ITuple* fTuple; ; #else class AnaEx01AnalysisManager; #endif #endif (3)在RunAction中调用,填谱 #ifdef G4ANALYSIS_USE #include AnaEx01AnalysisManager.hh #endif #include AnaEx01RunAction.hh AnaEx01RunAction:AnaEx01RunAction( AnaEx01AnalysisManager* aAnalysisManager ):fAnalysisManager(aAnaly

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论