source: branches/Mars_use_drstimefiles/fact/analysis/gain/extract_temp.C@ 18003

Last change on this file since 18003 was 17326, checked in by tbretz, 11 years ago
Added code to extract hv-patch wise temperatures from aux files.
File size: 3.7 KB
Line 
1#include <iostream>
2
3#include <TString.h>
4#include <TFile.h>
5#include <TGraph.h>
6
7#include "zfits.h"
8#include "PixelMap.h"
9#include "Interpolator2D.h"
10
11#include "MHCamera.h"
12#include "MGeomCamFACT.h"
13
14int extract_temp(UInt_t day=20130902, UInt_t run=146, const char *output=0)
15{
16 TString nraw = Form("/fact/raw/%4d/%02d/%02d/%8d_%03d.fits.fz",
17 day/10000, (day/100)%100, day%100, day, run);
18
19 TString naux = Form("/fact/aux/%4d/%02d/%02d/%8d.FSC_CONTROL_TEMPERATURE.fits",
20 day/10000, (day/100)%100, day%100, day);
21
22 PixelMap pmap;
23 if (!pmap.Read("FACTmap111030.txt"))
24 {
25 cout << "FACTmap111030.txt not found." << endl;
26 return 1;
27 }
28
29 Interpolator2D interpol;
30
31 const auto sens = Interpolator2D::ReadGrid("operation/sensor-pos.txt");
32 if (sens.size()!=31)
33 {
34 cout << "Reading sensor-pos.txt failed: " << interpol.getInputGrid().size() << endl;
35 return 2;
36 }
37
38 // =====================================================================
39
40 zfits fraw(nraw.Data());
41 if (!fraw)
42 {
43 cout << "Open raw file failed: " << nraw << endl;
44 return 1;
45 }
46
47 double tstart = fraw.GetUInt("TSTARTI") + fraw.GetFloat("TSTARTF");
48 double tstop = fraw.GetUInt("TSTOPI") + fraw.GetFloat("TSTOPF");
49
50 // =====================================================================
51
52 // Now we read the temperatures of the sensors during the
53 // single pe run and average them
54 fits faux(naux.Data());
55 if (!faux)
56 {
57 cout << "Could not open " << naux << endl;
58 return 1;
59 }
60
61 Double_t time;
62 Float_t temp[31];
63
64 if (!faux.SetPtrAddress("Time", &time))
65 return -1;
66 if (!faux.SetPtrAddress("T_sens", temp))
67 return -1;
68
69 TArrayD avg(31);
70 TArrayD rms(31);
71 TArrayI cnt(31);
72
73 while (faux.GetNextRow())
74 {
75 if (time<tstart || time>tstop)
76 continue;
77
78 for (int i=0; i<31; i++)
79 {
80 if (temp[i]==0)
81 continue;
82
83 double T = temp[i];
84
85 avg[i] += T;
86 rms[i] += T*T;
87 cnt[i]++;
88 }
89 }
90
91 vector<double> z;
92
93 vector<Interpolator2D::vec> pos;
94 for (int i=0; i<31; i++)
95 {
96 if (cnt[i]>0)
97 {
98 avg[i] /= cnt[i];
99 rms[i] /= cnt[i];
100 rms[i] = sqrt(rms[i]-avg[i]*avg[i]);
101
102 pos.push_back(sens[i]);
103 z.push_back(avg[i]);
104 }
105 }
106
107 // ================================================================
108
109 interpol.SetInputGrid(pos);
110
111 if (!interpol.ReadOutputGrid("operation/bias-positions.txt"))
112 {
113 cout << "Error setting output grid." << endl;
114 return 3;
115 }
116 if (interpol.getOutputGrid().size()!=320)
117 {
118 cout << "Reading bias-positions.txt failed: " << interpol.getOutputGrid().size() << endl;
119 return 3;
120 }
121
122 // ================================================================
123
124 const auto &input = interpol.getInputGrid();
125
126 TGraph sensors(input.size());
127
128 for (unsigned int i=0; i<input.size(); i++)
129 sensors.SetPoint(i, input[i].x, input[i].y);
130
131 const vector<double> rc = interpol.Interpolate(z);
132
133 // ================================================================
134
135 TCanvas *c = new TCanvas;
136 c->SetName("Temp");
137
138 MGeomCamFACT geom;
139
140 MHCamera h1(geom);
141 h1.SetName("Temp");
142 for (int i=0; i<1440; i++)
143 h1.SetBinContent(i+1, rc[pmap.index(i).hv()]);
144
145 h1.SetAllUsed();
146 h1.DrawCopy();
147
148 sensors.SetName("Sensors");
149 sensors.SetMarkerColor(kWhite);
150 sensors.DrawClone("*");
151
152 if (output)
153 c->SaveAs(output);
154
155 return 0;
156}
Note: See TracBrowser for help on using the repository browser.