source: trunk/Mars/datacenter/macros/fillmcstar.C@ 18679

Last change on this file since 18679 was 9221, checked in by hoehne, 16 years ago
*** empty log message ***
File size: 6.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 05/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Daniela Dorner, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
20! Author(s): Daniel Hoehne-Moench, 01/2009 <mailto:hoehne@astro.uni-wuerzburg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2009
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// fillmcstar.C
30// ==========
31//
32// This macro is used to read the star-output files.
33// These files are automatically called star00000000.root.
34// From these files the number of islands and a parameter describing the
35// inhomogeneity are extracted from the status display.
36// The sequence number is extracted from the filename.
37//
38// Usage:
39// .x fillmcstar.C("/magic/montecarlo/star/0002/00028270/star00028270.root", kTRUE)
40//
41// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
42// switched on and nothing will be written into the database. This is usefull
43// for tests.
44//
45// The macro can also be run without ACLiC but this is a lot slower...
46//
47// Remark: Running it from the commandline looks like this:
48// root -q -l -b fillmcstar.C+\(\"filename\"\,kFALSE\)
49//
50// Make sure, that database and password are corretly set in a resource
51// file called sql.rc and the resource file is found.
52//
53// Returns 2 in case of failure, 1 in case of success and 0 if the connection
54// to the database is not working.
55//
56/////////////////////////////////////////////////////////////////////////////
57#include <iostream>
58#include <iomanip>
59
60#include <TFile.h>
61#include <TH1.h>
62#include <TH2.h>
63#include <TGraph.h>
64
65#include "MSQLMagic.h"
66
67#include "MHCamera.h"
68#include "MHMuonPar.h"
69#include "MSequence.h"
70#include "MStatusArray.h"
71#include "MBadPixelsCam.h"
72#include "MHEffectiveOnTime.h"
73
74using namespace std;
75
76bool CheckGraph(const TGraph *g)
77{
78 return g && g->GetN()>0 && !(g->GetN()==1 && g->GetX()[0]==0);
79}
80
81int Process(MSQLMagic &serv, TString fname)
82{
83 TFile file(fname, "READ");
84 if (!file.IsOpen())
85 {
86 cout << "ERROR - Could not find file " << fname << endl;
87 return 2;
88 }
89
90
91 MStatusArray arr;
92 if (arr.Read()<=0)
93 {
94 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
95 return 2;
96 }
97
98 MHCamera *hevts = (MHCamera*)arr.FindObjectInCanvas("Sparkless;avg", "MHCamera", "Sparkless");
99 if (!hevts)
100 {
101 cout << "ERROR - Reading of Sparkless failed." << endl;
102 return 2;
103 }
104
105 MHCamera *hsparks = (MHCamera*)arr.FindObjectInCanvas("Sparks;avg", "MHCamera", "Sparks");
106 if (!hsparks)
107 {
108 cout << "ERROR - Reading of Sparks failed." << endl;
109 return 2;
110 }
111
112 TH2F *hcog = (TH2F*)arr.FindObjectInCanvas("Center", "TH2F", "MHHillas");
113 if (!hcog)
114 {
115 cout << "ERROR - Reading of MHHillas failed." << endl;
116 return 2;
117 }
118
119 MHMuonPar *hmuon = (MHMuonPar*)arr.FindObjectInCanvas("MHMuonPar", "MHMuonPar", "MHMuonPar");
120 if (!hmuon)
121 {
122 cout << "ERROR - Reading of MHMuon failed." << endl;
123 return 2;
124 }
125
126 Double_t val[6];
127 for (int x=1; x<hcog->GetNbinsX(); x++)
128 for (int y=1; y<hcog->GetNbinsY(); y++)
129 {
130 Stat_t px = hcog->GetXaxis()->GetBinCenter(x);
131 Stat_t py = hcog->GetYaxis()->GetBinCenter(y);
132 Int_t i = (TMath::Nint(3*TMath::ATan2(px,py)/TMath::Pi())+6)%6;
133 val[i] += hcog->GetBinContent(x, y);
134 }
135
136 Float_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
137 TString inhomogen = Form("%5.1f", inhom);
138
139 Int_t num = (int)hmuon->GetEntries();
140
141 Float_t ratiodatamc = (hmuon->GetMeanSize()/7216)*100;
142 TString ratio = Form("%5.1f", ratiodatamc);
143
144 TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
145 if (!h)
146 {
147 cout << "ERROR - Reading of Islands failed." << endl;
148 return 2;
149 }
150
151 TString islands = Form("%6.2f", h->GetMean());
152
153 Int_t numsparks = (int)hsparks->GetEntries();
154 Int_t numevents = (int)hevts->GetEntries();
155
156 MSequence seq;
157 if (seq.Read("sequence[0-9]{8}[.]txt|MSequence")<=0)
158 {
159 cout << "ERROR - Could not find sequence in file: " << fname << endl;
160 return 2;
161 }
162 if (!seq.IsValid())
163 {
164 cout << "ERROR - Sequence read from file inavlid: " << fname << endl;
165 return 2;
166 }
167
168 cout << "Sequence " << seq.GetSequence() << endl;
169 cout << " Inhomogeneity " << inhomogen << endl;
170 cout << " Island Quality " << islands << endl;
171 cout << " Muon Number " << num << endl;
172 cout << " # of Events (w/o sparks) " << numevents << endl;
173 cout << " # of Sparks " << numsparks << endl;
174
175 TString vars = Form(" fSequenceFirst=%d, "
176 " fMeanNumberIslands=%s,"
177 " fMuonNumber=%d,"
178 " fNumEvts=%d, "
179 " fNumSparks=%d, "
180 " fInhomogeneity=%s ",
181 seq.GetSequence(),
182 islands.Data(),
183 num,
184 numevents, numsparks,
185 inhomogen.Data());
186
187 TString where = Form("fSequenceFirst=%d", seq.GetSequence());
188
189 return serv.InsertUpdate("MCStar", vars, where) ? 1 : 2;
190}
191
192int fillmcstar(TString fname, Bool_t dummy=kTRUE)
193{
194 MSQLMagic serv("sql.rc");
195 if (!serv.IsConnected())
196 {
197 cout << "ERROR - Connection to database failed." << endl;
198 return 0;
199 }
200
201 cout << "fillmcstar" << endl;
202 cout << "--------" << endl;
203 cout << endl;
204 cout << "Connected to " << serv.GetName() << endl;
205 cout << "File: " << fname << endl;
206 cout << endl;
207
208 serv.SetIsDummy(dummy);
209
210 return Process(serv, fname);
211}
Note: See TracBrowser for help on using the repository browser.