All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
noise_ana.cxx
Go to the documentation of this file.
1 #define noise_ana_cxx
2 
3 #include <TGraph.h>
4 #include <TH1F.h>
5 #include <TCanvas.h>
6 #include <TFile.h>
7 
8 #include "TimeUtils.C"
9 
10 const float MAXRATE = 12.0; //khz
11 
12 size_t macNI[4] = {1,3,6,7};
13 size_t macNO[4] = {4,5,8,9};
14 size_t macWI[6] = {17,19,21,22,23,24};
15 size_t macWO[6] = {10,11,13,14,15,16};
16 
17 vector<string> locN = {"W Mezz","W Pit","E Mezz", "E Pit"};
18 vector<string> locW = {"N Mezz","N MezzPit","N Pit","S Pit","S MezzPit","S Mezz"};
19 
20 const char mode ='a'; //'n', 'w' or 'a'
21 
22 void noise_ana(){
23 
24  vector<string> fwo, fwi, fno, fni;
25 
26  //get all files from list
27  ifstream flist;
28  flist.open("./noisefiles.list");
29 
30  string line;
31  while(getline(flist,line)){
32  if(line.find("north_inner")!=UINT64_MAX){
33  fni.push_back(line);
34  }
35  if(line.find("north_outer")!=UINT64_MAX){
36  fno.push_back(line);
37  }
38  if(line.find("west_inner")!=UINT64_MAX){
39  fwi.push_back(line);
40  }
41  if(line.find("west_outer")!=UINT64_MAX){
42  fwo.push_back(line);
43  }
44 
45  }
46 
47  flist.close();
48 
49  cout << "--- found files ---" << endl;
50  cout << " north, inner: " << fni.size() << endl;
51  cout << " north, outer: " << fno.size() << endl;
52  cout << " west, inner: " << fwi.size() << endl;
53  cout << " west, outer: " << fwo.size() << endl;
54 
55 
56  const size_t n_wo = fwo.size();
57  const size_t n_wi = fwi.size();
58  const size_t n_no = fno.size();
59  const size_t n_ni = fni.size();
60  float rateWO[6][n_wo];
61  float rateWI[6][n_wi];
62  float rateNO[4][n_no];
63  float rateNI[4][n_ni];
64  float timeWO[n_wo];
65  float timeWI[n_wi];
66  float timeNO[n_no];
67  float timeNI[n_ni];
68 
69  Date date0 = PathToDate(fno[0]);
70 
71  if(mode=='n'||mode=='a'){
72  for(size_t i=0; i<n_no; i++){
73  cout << "opening file " << fno[i] << endl;
74  TFile fin(fno[i].c_str());
75  timeNO[i] = (float)DaysPassed(date0,PathToDate(fno[i]));
76 
77  for(size_t imac=0; imac<4; imac++){
78 
79  string hname = "h_"+to_string(macNO[imac]);
80  TH1F* h = (TH1F*)fin.FindObjectAny(hname.c_str());
81 
82  rateNO[imac][i] = h->GetMean();
83  }
84 
85  fin.Close();
86 
87  }
88 
89  for(size_t i=0; i<n_ni; i++){
90  cout << "opening file " << fni[i] << endl;
91  TFile fin(fni[i].c_str());
92  timeNI[i] = (float)DaysPassed(date0,PathToDate(fni[i]));
93 
94  for(size_t imac=0; imac<4; imac++){
95 
96  string hname = "h_"+to_string(macNI[imac]);
97  TH1F* h = (TH1F*)fin.FindObjectAny(hname.c_str());
98 
99  rateNI[imac][i] = h->GetMean();
100  }
101 
102  fin.Close();
103 
104  }
105  }
106 
107  if(mode=='w'||mode=='a'){
108  for(size_t i=0; i<n_wo; i++){
109  cout << "opening file " << fwo[i] << endl;
110  TFile fin(fwo[i].c_str());
111  timeWO[i] = (float)DaysPassed(date0,PathToDate(fwo[i]));
112 
113  for(size_t imac=0; imac<6; imac++){
114 
115  string hname = "h_"+to_string(macWO[imac]);
116  TH1F* h = (TH1F*)fin.FindObjectAny(hname.c_str());
117 
118  rateWO[imac][i] = h->GetMean();
119  }
120 
121  fin.Close();
122 
123  }
124 
125  for(size_t i=0; i<n_wi; i++){
126  cout << "opening file " << fwi[i] << endl;
127  TFile fin(fwi[i].c_str());
128  timeWI[i] = (float)DaysPassed(date0,PathToDate(fwi[i]));
129 
130  for(size_t imac=0; imac<6; imac++){
131 
132  string hname = "h_"+to_string(macWI[imac]);
133  TH1F* h = (TH1F*)fin.FindObjectAny(hname.c_str());
134 
135  rateWI[imac][i] = h->GetMean();
136  }
137 
138  fin.Close();
139 
140  }
141  }
142 
143  // --- plotting ---
144 
145  TLegend* leg_ni = new TLegend(0.3,0.65,0.6,0.9);
146  TLegend* leg_no = new TLegend(0.3,0.65,0.6,0.9);
147  TLegend* leg_wi = new TLegend(0.3,0.55,0.6,0.9);
148  TLegend* leg_wo = new TLegend(0.3,0.55,0.6,0.9);
149 
150  leg_ni->SetHeader("mac5 (location)", "C");
151  leg_no->SetHeader("mac5 (location)", "C");
152  leg_wi->SetHeader("mac5 (location)", "C");
153  leg_wo->SetHeader("mac5 (location)", "C");
154 
155  vector<TGraph*> gO;
156 
157  if(mode=='a' || mode=='n') {
158  TCanvas* cno = new TCanvas();
159  for(size_t imac=0; imac<4; imac++){
160  gO.push_back(new TGraph(n_no,timeNO,rateNO[imac]));
161  gO.back()->SetMarkerColor(imac+1);
162  gO.back()->SetMarkerStyle(8);
163  string text = to_string(macNO[imac])+" ("+locN[imac]+")";
164  leg_no->AddEntry(gO.back(),text.c_str(),"p");
165  if(imac==0){
166  gO.back()->GetXaxis()->SetTitle("days since start");
167  gO.back()->GetYaxis()->SetTitle("rate [kHz]");
168  gO.back()->GetXaxis()->SetTitleSize(0.05);
169  gO.back()->GetXaxis()->SetLabelSize(0.05);
170  gO.back()->GetYaxis()->SetTitleSize(0.05);
171  gO.back()->GetYaxis()->SetLabelSize(0.05);
172  gO.back()->GetXaxis()->SetTitleOffset(0.9);
173  gO.back()->GetYaxis()->SetTitleOffset(0.9);
174  gO.back()->GetYaxis()->SetRangeUser(0,MAXRATE);
175  gO.back()->SetTitle("CRT Noise Rate Over Time: North Wall, Out");
176  gO.back()->Draw("APL");
177  }
178  else{
179  gO.back()->Draw("samepl");
180  }
181  }
182  leg_no->Draw();
183  cno->SaveAs("noise_north_outer.png");
184  }
185 
186  vector<TGraph*> gI;
187 
188  if(mode=='a' || mode=='n') {
189  TCanvas* cni = new TCanvas();
190  for(size_t imac=0; imac<4; imac++){
191  gI.push_back(new TGraph(n_ni,timeNI,rateNI[imac]));
192  gI.back()->SetMarkerColor(imac+1);
193  gI.back()->SetMarkerStyle(8);
194  string text = to_string(macNI[imac])+" ("+locN[imac]+")";
195  leg_ni->AddEntry(gI.back(),text.c_str(),"p");
196 
197  if(imac==0){
198  gI.back()->GetXaxis()->SetTitle("days since start");
199  gI.back()->GetYaxis()->SetTitle("rate [kHz]");
200  gI.back()->GetXaxis()->SetTitleSize(0.05);
201  gI.back()->GetXaxis()->SetLabelSize(0.05);
202  gI.back()->GetYaxis()->SetTitleSize(0.05);
203  gI.back()->GetYaxis()->SetLabelSize(0.05);
204  gI.back()->GetXaxis()->SetTitleOffset(0.9);
205  gI.back()->GetYaxis()->SetTitleOffset(0.9);
206  gI.back()->GetYaxis()->SetRangeUser(0,MAXRATE);
207  gI.back()->SetTitle("CRT Noise Rate Over Time: North Wall, In");
208  gI.back()->Draw("APL");
209  }
210  else{
211  gI.back()->Draw("samepl");
212  }
213  }
214  leg_ni->Draw();
215  cni->SaveAs("noise_north_inner.png");
216 
217  /*new TCanvas();
218  gO[0]->GetYaxis()->SetRangeUser(-0.1,30);
219  //gO[0]->GetXaxis()->SetRangeUser(-0.5,7.5);
220  gO[0]->Draw("apl");
221  gI[0]->Draw("samepl");
222  for(size_t imac=1; imac<4; imac++){
223  gO[imac]->Draw("samepl");
224  gI[imac]->Draw("samepl");
225  }*/
226  }
227 
228  vector<TGraph*> gWO;
229  vector<TGraph*> gWI;
230 
231  if(mode=='a' || mode=='w') {
232  TCanvas* cwo = new TCanvas();
233  for(size_t imac=0; imac<6; imac++){
234  gWO.push_back(new TGraph(n_wo,timeWO,rateWO[imac]));
235  gWO.back()->SetMarkerColor(imac+1);
236  gWO.back()->SetMarkerStyle(8);
237  string text = to_string(macWO[imac])+" ("+locW[imac]+")";
238  leg_wo->AddEntry(gWO.back(),text.c_str(),"p");
239  if(imac==0){
240  gWO.back()->GetXaxis()->SetTitle("days since start");
241  gWO.back()->GetYaxis()->SetTitle("rate [kHz]");
242  gWO.back()->GetXaxis()->SetTitleSize(0.05);
243  gWO.back()->GetXaxis()->SetLabelSize(0.05);
244  gWO.back()->GetYaxis()->SetTitleSize(0.05);
245  gWO.back()->GetYaxis()->SetLabelSize(0.05);
246  gWO.back()->GetXaxis()->SetTitleOffset(0.9);
247  gWO.back()->GetYaxis()->SetTitleOffset(0.9);
248  gWO.back()->GetYaxis()->SetRangeUser(0,MAXRATE);
249  gWO.back()->SetTitle("CRT Noise Rate Over Time: West Wall, Out");
250  gWO.back()->Draw("APL");
251  }
252  else{
253  gWO.back()->Draw("samepl");
254  }
255  }
256  leg_wo->Draw();
257  cwo->SaveAs("noise_west_outer.png");
258 
259  TCanvas* cwi = new TCanvas();
260  for(size_t imac=0; imac<6; imac++){
261  gWI.push_back(new TGraph(n_wi,timeWI,rateWI[imac]));
262  gWI.back()->SetMarkerColor(imac+1);
263  gWI.back()->SetMarkerStyle(8);
264  string text = to_string(macWI[imac])+" ("+locW[imac]+")";
265  leg_wi->AddEntry(gWI.back(),text.c_str(),"p");
266  if(imac==0){
267  gWI.back()->GetXaxis()->SetTitle("days since start");
268  gWI.back()->GetYaxis()->SetTitle("rate [kHz]");
269  gWI.back()->GetXaxis()->SetTitleSize(0.05);
270  gWI.back()->GetXaxis()->SetLabelSize(0.05);
271  gWI.back()->GetYaxis()->SetTitleSize(0.05);
272  gWI.back()->GetYaxis()->SetLabelSize(0.05);
273  gWI.back()->GetXaxis()->SetTitleOffset(0.9);
274  gWI.back()->GetYaxis()->SetTitleOffset(0.9);
275  gWI.back()->GetYaxis()->SetRangeUser(0,MAXRATE);
276  gWI.back()->SetTitle("CRT Noise Rate Over Time: West Wall, In");
277  gWI.back()->Draw("APL");
278  }
279  else{
280  gWI.back()->Draw("samepl");
281  }
282  }
283  leg_wi->Draw();
284  cwi->SaveAs("noise_west_inner.png");
285 
286  /*new TCanvas();
287  gWO[0]->GetYaxis()->SetRangeUser(-0.1,30);
288  gWO[0]->Draw("apl");
289  gWI[0]->Draw("samepl");
290  for(size_t imac=1; imac<4; imac++){
291  gWO[imac]->Draw("samepl");
292  gWI[imac]->Draw("samepl");
293  }*/
294 
295  }
296 }
size_t macWO[6]
Definition: noise_ana.cxx:15
void noise_ana()
Definition: noise_ana.cxx:22
vector< string > locN
Definition: noise_ana.cxx:17
while getopts h
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the text(code) section.'echo ' 'echo 'U 'echo 'The symbol is undefined.'echo ' 'echo 'V 'echo 'The symbol is a weak object.When a weak defined symbol is'echo 'linked with a normal defined symbol
const char mode
Definition: noise_ana.cxx:20
size_t macNO[4]
Definition: noise_ana.cxx:13
std::string to_string(WindowPattern const &pattern)
const float MAXRATE
Definition: noise_ana.cxx:10
vector< string > locW
Definition: noise_ana.cxx:18
size_t macWI[6]
Definition: noise_ana.cxx:14
size_t macNI[4]
Definition: noise_ana.cxx:12
BEGIN_PROLOG could also be cout