source: fact/tools/rootmacros/calscope_batch.C@ 14962

Last change on this file since 14962 was 12365, checked in by kraehenb, 13 years ago
More comments in calscope_batch, and exclude spikes in the peakfinderscope.
File size: 3.6 KB
Line 
1#include <TROOT.h>
2#include <TCanvas.h>
3#include <TProfile.h>
4
5#include <stdint.h>
6#include <cstdio>
7
8#define HAVE_ZLIB
9#include "fits.h"
10#include "FOpenDataFile.c"
11#include "FOpenCalibFile.c"
12#include "FCalibrateEvent.c"
13
14int calscope_batch(const char *name, const char *drsname, size_t pixelnr)
15{
16//******************************************************************************
17//This program plots all calibrated events of a file when pressing ENTER to continue, a to abort.
18//ATTENTION: only works for ROI=1024
19// (array indices of the calibration wrong otherwise)
20//Example call in ROOT:
21//root [74] .x calscope_batch.C++("20110804_024.fits","20110804_023.drs.fits",10)
22//T. Krähenbühl, August 2011, tpk@phys.ethz.ch
23//******************************************************************************
24
25 gROOT->SetStyle("Plain");
26
27//-------------------------------------------
28//Open the file
29//-------------------------------------------
30 fits datafile(name);
31 if (!datafile)
32 {
33 cout << "Couldn't properly open the datafile." << endl;
34 return 1;
35 }
36
37//-------------------------------------------
38//Get the data
39//-------------------------------------------
40 vector<int16_t> data;
41 vector<int16_t> data_offset;
42 unsigned int data_num;
43 size_t data_n;
44 UInt_t data_px;
45 UInt_t data_roi;
46 FOpenDataFile(datafile, data, data_offset, data_num, data_n, data_roi, data_px);
47 UInt_t maxeventnr = datafile.GetNumRows();
48//-------------------------------------------
49//Get the DRS calibration
50//-------------------------------------------
51 size_t drs_n;
52 vector<float> drs_basemean;
53 vector<float> drs_gainmean;
54 vector<float> drs_triggeroffsetmean;
55 FOpenCalibFile(drsname, drs_basemean, drs_gainmean, drs_triggeroffsetmean, drs_n);
56
57//-------------------------------------------
58//Check the sizes of the data columns
59//-------------------------------------------
60 if(drs_n!=data_n)
61 {
62 cout << "Data and DRS file incompatible (Px*ROI disagree)" << endl;
63 return 1;
64 }
65
66//-------------------------------------------
67//Create the title
68//-------------------------------------------
69 char title[500];
70 vector<float> calevent(data_px*data_roi); //Vector for the calibrated event
71 cout << "--------------------- Data --------------------" << endl;
72
73 TCanvas *canv = new TCanvas( "canv", "Mean values of the first event", 100, 10, 700, 500 );
74 std::sprintf(title,"Data: %s, DRS: %s, Px %i Ev %i",name,drsname,pixelnr,0);
75 TProfile *pix = new TProfile("pix", title, 1024, -0.5, 1023.5);
76
77//-------------------------------------------
78//Start the loop
79//-------------------------------------------
80 char temp;
81 std::cout << "Plot the spectra out of limits: Enter for next, 'a' to abort." << std::endl;
82 for(int eventnr=0; eventnr<maxeventnr; eventnr++) {
83
84 datafile.GetRow(eventnr);
85 cout << "Event number: " << data_num << endl;
86
87//-------------------------------------------
88//Calibrate the event
89//-------------------------------------------
90 FCalibrateEvent(data, data_offset, drs_basemean, drs_gainmean, drs_triggeroffsetmean, calevent, data_px, data_roi);
91
92//-------------------------------------------
93//Draw the data
94//-------------------------------------------
95 pix->Reset();
96 std::sprintf(title,"Data: %s, DRS: %s, Px %i Ev %i",name,drsname,pixelnr,eventnr);
97 pix->SetTitle(title);
98 for (UInt_t k=0; k<data_roi; k++)
99 {
100 pix->Fill(k,calevent[pixelnr*data_roi+k]);
101 }
102
103 pix->Draw();
104 canv->Modified();
105 canv->Update();
106
107 temp='x';
108 while ((temp!='\n') && (temp!='a'))
109 cin.get(temp);
110 if(temp=='a') break;
111 }
112
113 return 0;
114}
Note: See TracBrowser for help on using the repository browser.