source: trunk/Mars/hawc/plot_callisto.C@ 20084

Last change on this file since 20084 was 19845, checked in by tbretz, 5 years ago
Allow also .q
File size: 4.1 KB
Line 
1// ==========================================================================
2// ============ see plot_callisto function at the end of the file ===========
3// ==========================================================================
4int HandleInput(int evtnum)
5{
6 // This is a pure man's command line interface to wait for a key input
7 // and allow exit but at the same time allow interaction with the GUI
8 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
9 while (1)
10 {
11 // While reading the input process gui events asynchronously
12 timer.TurnOn();
13 const char *gl = Getline("Type 'q' to exit, or event number and <return> to go on: ");
14 timer.TurnOff();
15
16 TString input = gl;
17 if (input=="q\n" || input==".q\n")
18 return -1;
19
20 if (input=="\n")
21 return evtnum+1;
22
23 return atoi(input.Data());
24 };
25
26 return -1;
27}
28
29// ==========================================================================
30//
31// Run the macro with
32//
33// root hawc/plot_callisto.C\(\"00000001.003_Y_MonteCarlo003_Events.root\"\)
34//
35// The default file name is a Y-file (either as Monte Carlo-truth from ceres
36// or from the callisto)
37//
38// From within root, the escape characters can be omitted, e.g.
39//
40// root
41// [0] .x hawc/plot_callisto.C("00000001.003_Y_MonteCarlo003_Events.root")
42//
43// ==========================================================================
44
45void plot_callisto(const char *fname)
46{
47 // Create the file for reading and get the tree
48 TFile file(fname);
49 if (file.IsZombie())
50 {
51 cout << "Could not open file." << endl;
52 return;
53 }
54
55 TTree *T = 0;
56 file.GetObject("Events", T);
57 if (!T)
58 {
59 cout << "Could not access tree." << endl;
60 return;
61 }
62
63 // Setup the branch with the calibrated datafor reading
64 MSignalCam *signal = NULL;
65 chain.SetBranchAddress("MSignalCam.", &signal);
66
67 // Create the FAMOUS style camera with a
68 // focal distance of 0.5m and 61 pixels
69 MGeomCamFAMOUS geom(0.5, kFALSE);
70
71 // Instantiate three camera histograms
72 MHCamera cam_signal(geom);
73 MHCamera cam_cleaned(geom);
74 MHCamera cam_time(geom);
75
76 // Setup names for the cameras
77 cam_signal.SetName("Signal");
78 cam_cleaned.SetName("Cleaned");
79 cam_time.SetName("Time");
80
81 // Fix minimum for amplitude at 0 ("disable zero suppression")
82 cam_signal.SetMinimum(0);
83 cam_cleaned.SetMinimum(0);
84
85 // Create a canvas and divide it into 4 (2x2) pads
86 // Add all four camera displays in the pads
87 TCanvas c;
88 c.Divide(2,2);
89
90 c.cd(1);
91 cam_signal.Draw();
92
93 c.cd(2);
94 cam_cleaned.Draw();
95
96 c.cd(3);
97 cam_time.Draw();
98
99 // Loop over the data
100 int evtnum = 0;
101 while (evtnum>=0)
102 {
103 // Infinite loop (start over at the beginning)
104 if (evtnum>=T->GetEntries())
105 evtnum = 0;
106
107 // Get event
108 chain.GetEntry(evtnum);
109
110 // 0: Number of Photons*PixRatio <default>
111 // 1: Error*sqrt(PixRatio)
112 // 2: Cleaning level = Num Photons*sqrt(PixRatio)/Error
113 // 3: Number of Photons
114 // 4: Error
115 // 5: Island index
116 // 6: arrival time of mapped pixels
117 // 7: arrival time if signa avove 20phe
118 // 8: arrival time
119 // 10: as 0, but returns kFALSE if signal <=0
120 // 11: as 8, but returns kFALSE if signal <=0
121
122 // This is a function which directly copies the entries
123 // from *signal into the camera histograms. The number
124 // is an ID which contents to be copied. This could also
125 // be done in a manula loop over all pixels.
126 cam_signal.SetCamContent(*signal, 10); // num phot uncleaned
127 cam_cleaned.SetCamContent(*signal, 3); // num phot cleaned
128 cam_time.SetCamContent(*signal, 8); // arr time cleaned
129
130 // Signal root that the objects displayed in all four pads
131 // were changed and the pads have to be updated
132 for (int i=0; i<4; i++)
133 {
134 c.GetPad(i+1)->Modified();
135 c.GetPad(i+1)->Update();
136 }
137
138 // Wait for user intput
139 evtnum = HandleInput(evtnum);
140 }
141}
Note: See TracBrowser for help on using the repository browser.