source: trunk/Mars/hawc/plot_trace.C@ 19948

Last change on this file since 19948 was 19846, checked in by tbretz, 5 years ago
Example how to extract a calibrated trace.
File size: 5.8 KB
Line 
1// ==========================================================================
2// ============ see plot_callisto function at the end of the file ===========
3// ==========================================================================
4int HandleInput()
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
10 // While reading the input process gui events asynchronously
11 timer.TurnOn();
12 const char *gl = Getline("Type 'q' to exit, or event number and <return> to go on: ");
13 timer.TurnOff();
14
15 TString input = gl;
16 if (input=="q\n" || input==".q\n")
17 return kFALSE;
18
19 return kTRUE;
20}
21
22// Create a histogram for the trace
23TH1D hist("Trace", "Waveform", 1024, -0.25, 511.75);
24
25// All 'data members' that are required globally
26TCanvas *c;
27MPedestalSubtractedEvt *fEvt = 0;
28
29//
30// Called like all PreProcess functions of tasks. Get the access to
31// the containers necessary for you.
32//
33Int_t PreProcess(MParList *plist)
34{
35 fEvt = (MPedestalSubtractedEvt*)plist->FindObject("MPedestalSubtractedEvt");
36 if (!fEvt)
37 {
38 gfLog << err << "MPedestalSubtractedEvt not found... aborting." << endl;
39 return kALSE;
40 }
41
42 // Create a canvas and plot the histogram into it
43 c = new TCanvas;
44 hist.SetStats(kFALSE);
45 hist.Draw();
46
47 TF1 constant("zero", "[0]", -0.25, 511.75);
48 constant.SetParameter(0, 0);
49 constant.SetLineColor(kBlack);
50 constant.SetLineStyle(kDashed);
51 constant.DrawCopy("same");
52
53 // One p.e.
54 constant.SetParameter(0, 20);
55 constant.SetLineStyle(kDotted);
56 constant.DrawCopy("same");
57
58 constant.SetParameter(0, -20);
59 constant.DrawCopy("same");
60
61 return kTRUE;
62}
63
64Int_t Process()
65{
66 int pixel_index = 0;
67
68 // Number of samples per pixel (usually 1024)
69 int numsamples = fEvt->GetNumSamples();
70 Float_t *cal = fEvt->GetSamples(pixel_index);
71
72 // reset contents of histogram and fill new contents
73 hist.Reset();
74 for (int i=0; i<numsamples; i++)
75 hist.Fill(i*0.5, cal[i]); // Convert sample to nano-second
76
77 // Reset min/max range
78 hist.SetMinimum();
79 hist.SetMaximum();
80
81 // Set a reasonable range
82 if (hist.GetMinimum()>-50)
83 hist.SetMinimum(-50);
84 if (hist.GetMaximum()<250)
85 hist.SetMaximum(250);
86
87 // Signal root to update the canvas/pad
88 c->Modified();
89 c->Update();
90
91 bool rc = HandleInput();
92
93 // wait for 'return'
94 return rc;
95}
96
97
98/*****************************************************************
99
100 This is an example how to access and display calibrated raw data
101
102 datafile:
103 A data file written by the fadctrl or ceres, e.g.
104 20170727_006.fits.fz or
105 00000015.003_D_MonteCarlo019_Events.fits.fz
106
107 drsfile:
108 Usually the third of the three .drs.fits files from a
109 DRS calibration sequence, e.g. 20170727_004.drs.fits
110
111 To run the macro from the command line (assuming you are in a directory
112 Mars/build where you have built your Mars environment) ou can do
113
114 root ../hawc/plot_trace.C\(\"20191002_018.fits.fz\",\"20191002_013.drs.fits\"\)
115
116 or from within root
117
118 [0] .x ../hawc/plot_trace.C("20191002_018.fits.fz", "20191002_013.drs.fits")
119
120******************************************************************/
121int plot_trace(const char *datafile, const char *drsfile)
122{
123 // ======================================================
124
125 // true: Display correctly mapped pixels in the camera displays
126 // but the value-vs-index plot is in software/spiral indices
127 // false: Display pixels in hardware/linear indices,
128 // but the order is the camera display is distorted.
129 // false is assumed automatically for files with the ISMC flag set.
130 bool usemap = true;
131
132 // mapping file (found in Mars/hawc)
133 const char *mmap = usemap ? "../hawc/FAMOUSmap171218.txt" : NULL;
134
135 // ======================================================
136
137 // Check if the requested mapping file is available
138 if (mmap && gSystem->AccessPathName(mmap, kFileExists))
139 {
140 gLog << err << "ERROR - Cannot access mapping file '" << mmap << "'" << endl;
141 return 11;
142 }
143
144 // -------------------------------------------------------
145
146 // Check and read the DRS calibration constants
147 MDrsCalibration drscalib300;
148 if (drsfile && !drscalib300.ReadFits(drsfile))
149 return 31;
150
151 // -------------------------------------------------------
152
153 // Setup camera geometry
154 MGeomCamFAMOUS geom;
155
156 // ======================================================
157
158 // Setup task for reading the file
159 MRawFitsRead read;
160 read.LoadMap(mmap);
161 read.AddFile(datafile);
162
163 // Setup task which ensures sizes of containers consistent with camera geometry
164 MGeomApply apply;
165
166 // Setup task for DRS calibration
167 MDrsCalibApply drsapply;
168 drsapply.SetMaxNumPrevEvents(0); // Switched off step-correction -> crashes due to the requirement of N*9 ch
169
170 // Setup intercative task calling the functions defined above
171 MTaskInteractive mytask;
172 mytask.SetPreProcess(PreProcess);
173 mytask.SetProcess(Process);
174
175 // ======================================================
176
177 MTaskList tlist;
178
179 MParList plist;
180 plist.AddToList(&tlist);
181 plist.AddToList(&drscalib300);
182 plist.AddToList(&geom);
183
184 // ------------------ Setup eventloop and run analysis ---------------
185
186 tlist.AddToList(&read);
187 tlist.AddToList(&apply);
188 tlist.AddToList(&drsapply);
189 tlist.AddToList(&mytask);
190
191 // ------------------ Setup and run eventloop ---------------
192
193 MEvtLoop loop(gSystem->BaseName(datafile));
194 loop.SetParList(&plist);
195
196 if (!loop.Eventloop())
197 return 4;
198
199 // Print statistics information about your loop
200 tlist.PrintStatistics();
201
202 return 0;
203}
Note: See TracBrowser for help on using the repository browser.