artemisのProcessorでEvent Displayを作る
artemisのProcessorを回しながら、随時Histogramなどをリアルタイムで更新したり、Trackingがちゃんと出来ているかとかHit patternに対してFitがEvent by eventでちゃんと出来ているのかなどを確認したいときがあります。 そういったときに使えるのが"TEventDisplayProcessorHelper"クラスです(もしかすると現在標準のartemisでは実装されていないかもしれないのですが)。
artemisで実装されているProcessorHelperというのは、あるProcessorに機能を簡単に追加できる便利な機能です。
- 実装
THogeDisplayProcessorという名のProcessorを仮定します。この中でFillしたヒストグラムfHを画面に表示させ、Event毎に絵をアップデートします。
まずはコンストラクタ内での定義です。
THogeDisplayProcessor::THogeDisplayProcessor()
{
RegisterInputCollection("Input", "Input",
fInput, TString("hoge"),
&fInput, "TClonesArray", "art::THogeData");
fEventDisplayHelper = new TEventDisplayProcessorHelper; // Headerで予めfEventDisplayHelperを定義しておきます
RegisterHelper(fEventDisplayHelper);
}
この"RegisterHelper"ってのにHelperを登録します。DisplayHelperには
proc->RegisterInputCollection("EventHeader","name of event header",fNameEventHeader,TString("eventheader"));
proc->RegisterProcessorParameter("WaitTime","time wating for next draw (micro second)",fWaitTime,100000);
proc->RegisterProcessorParameter("DisplayMode",Form("draw flag, %d skip, %d draw, %d draw and save",kQuiet,kDrawOnly,kDrawSave),
(Int_t&)fDisplayMode,(Int_t)kQuiet);
proc->RegisterOptionalParameter("DirNameFmt","Name of directory to save the figures",fDirNameFmt,TString("figs/%s"));
proc->RegisterOptionalParameter("FileNameFmt","Name of files",fFileNameFmt,TString("%s%04d_%05d.png"));
なんて、Registerするようになっております。YAMLファイルでこちらのInputやParameterをきちんと定義しておきましょう(実はこれでハマった笑)
次に、Initでこのオブジェクトの生成が出来ているかの確認をします。
void THogeDisplayProcessor::Init(TEventCollection *col)
{
if (!fEventDisplayHelper->Displays()) {
printf("Display helper creation failed.");
return;
}
fEventDisplayHelper->Process();
fH = new TH1D("hoge","hoge",100,0,100); // 描きたいヒストグラム
}
続いて、書くヒストグラムとDrawです。これはEvent毎にやるのでProcessの中に書きます。
void THogeDisplayProcessor::Process()
{
if (!fEventDisplayHelper->Displays()) return;
/*
処理
*/
TPad* pad = fEventDisplayHelper->GetMainPad();
pad->cd(0);
fH->Draw();
fEventDisplayHelper->Process();
pad->Clear();
}
結構簡単に実装できちゃいますね! 最後のDrawのところではTPadの操作なので、Divideなども出来ます。