ROOTANA
Loading...
Searching...
No Matches
manalyzer_example_root_graphics.cxx
Go to the documentation of this file.
1//
2// MIDAS analyzer example: ROOT analyzer with graphics
3//
4// K.Olchanski
5//
6
7#include <stdio.h>
8
9#include "manalyzer.h"
10#include "midasio.h"
11
12#include "TRandom3.h"
13#include "TCanvas.h"
14#include "TH1D.h"
15
17{
19 TCanvas *fCanvas;
20 TH1D* hperrun;
21 TH1D* hExample;
22 TRandom* fRndm;
23
25 : TARunObject(runinfo)
26 {
27 printf("ExampleGRoot::ctor!\n");
28 fModuleName = "ExampleGRoot";
29 fCanvas = new TCanvas("example", "example", 500, 500);
30 fRndm = new TRandom3(); // recommended random number generator
31 }
32
34 {
35 printf("ExampleGRoot::dtor!\n");
36 if (fCanvas)
37 delete fCanvas;
38 fCanvas = NULL;
39 }
40
41 void BeginRun(TARunInfo* runinfo)
42 {
43 printf("BeginRun, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
44 uint32_t run_start_time_binary = 0;
45 runinfo->fOdb->RU32("/Runinfo/Start time binary", &run_start_time_binary);
46 time_t run_start_time = run_start_time_binary;
47 printf("ODB Run start time: %d: %s", (int)run_start_time, ctime(&run_start_time));
48 fCounter = 0;
49 runinfo->fRoot->fOutputFile->cd(); // select correct ROOT directory
50 hperrun = new TH1D("hperrun", "hperrun", 200, -100, 100);
51 hExample = new TH1D("hexample", "hexample", 100, -5, 5);
52 fCanvas->Divide(1, 2);
53 fCanvas->cd(1);
54 hperrun->Draw();
55 fCanvas->cd(2);
56 hExample->Draw();
57 }
58
59 void EndRun(TARunInfo* runinfo)
60 {
61 printf("EndRun, run %d, events %d\n", runinfo->fRunNo, fCounter);
62 uint32_t run_stop_time_binary = 0;
63 runinfo->fOdb->RU32("/Runinfo/Stop time binary", &run_stop_time_binary);
64 time_t run_stop_time = run_stop_time_binary;
65 printf("ODB Run stop time: %d: %s", (int)run_stop_time, ctime(&run_stop_time));
66 hperrun->SaveAs("hperrun.root");
67 hperrun->SaveAs("hperrun.pdf");
68 }
69
70 void NextSubrun(TARunInfo* runinfo)
71 {
72 printf("NextSubrun, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
73 }
74
75 void PauseRun(TARunInfo* runinfo)
76 {
77 printf("PauseRun, run %d\n", runinfo->fRunNo);
78 }
79
80 void ResumeRun(TARunInfo* runinfo)
81 {
82 printf("ResumeRun, run %d\n", runinfo->fRunNo);
83 }
84
85 TAFlowEvent* Analyze(TARunInfo* runinfo, TMEvent* event, TAFlags* flags, TAFlowEvent* flow)
86 {
87 printf("Analyze, run %d, event serno %d, id 0x%04x, data size %d\n", runinfo->fRunNo, event->serial_number, (int)event->event_id, event->data_size);
88
89 double v = 0;
90 for (int i=0; i<12; i++)
91 v += fRndm->Rndm();
92 v -= 6.0;
93
94 hExample->Fill(v);
95
96 if (event->event_id == 2) {
97 TMBank* bslow = event->FindBank("SLOW");
98 if (bslow) {
99 float* dslow = (float*)event->GetBankData(bslow);
100 if (dslow) {
101 double v = *dslow;
102
103 printf("event %d, slow %f\n", event->serial_number, v);
104
105 hperrun->Fill(v);
106 fCounter++;
107 }
108 }
109 }
110
111 //fCanvas->cd();
112 //hperrun->Draw();
113
114 fCanvas->Modified();
115 fCanvas->Draw();
116 fCanvas->Update();
117
118 return flow;
119 }
120
121 void AnalyzeSpecialEvent(TARunInfo* runinfo, TMEvent* event)
122 {
123 printf("AnalyzeSpecialEvent, run %d, event serno %d, id 0x%04x, data size %d\n", runinfo->fRunNo, event->serial_number, (int)event->event_id, event->data_size);
124 }
125};
126
128{
129public:
130 void Init(const std::vector<std::string> &args)
131 {
132 printf("Init!\n");
133 }
134
135 void Finish()
136 {
137 printf("Finish!\n");
138 }
139
141 {
142 printf("NewRunObject, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
143 return new ExampleGRoot(runinfo);
144 }
145};
146
148
149/* emacs
150 * Local Variables:
151 * tab-width: 8
152 * c-basic-offset: 3
153 * indent-tabs-mode: nil
154 * End:
155 */
void Init(const std::vector< std::string > &args)
TARunObject * NewRunObject(TARunInfo *runinfo)
virtual void RU32(const char *varname, uint32_t *value, bool create=false, MVOdbError *error=NULL)=0
TFile * fOutputFile
Definition manalyzer.h:154
std::string fFileName
Definition manalyzer.h:25
MVOdb * fOdb
Definition manalyzer.h:26
int fRunNo
Definition manalyzer.h:24
TARootHelper * fRoot
Definition manalyzer.h:27
std::string fModuleName
Definition manalyzer.h:84
uint32_t serial_number
MIDAS event serial number.
Definition midasio.h:59
uint32_t data_size
MIDAS event data size.
Definition midasio.h:61
uint16_t event_id
MIDAS event ID.
Definition midasio.h:57
char * GetBankData(const TMBank *)
get pointer to MIDAS data bank
Definition midasio.cxx:1022
int TAFlags
Definition manalyzer.h:72
static TARegister tar(new ExampleGRootFactory)
void AnalyzeSpecialEvent(TARunInfo *runinfo, TMEvent *event)
void ResumeRun(TARunInfo *runinfo)
void EndRun(TARunInfo *runinfo)
ExampleGRoot(TARunInfo *runinfo)
TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
void BeginRun(TARunInfo *runinfo)
void PauseRun(TARunInfo *runinfo)
void NextSubrun(TARunInfo *runinfo)