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, 06/2007 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Daniela Dorner, 11/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
20 | ! Author(s): Daniel Hoehne, 10/2007 <mailto:hoehne@astro.uni-wuerzburg.de>
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2007
|
---|
23 | !
|
---|
24 | !
|
---|
25 | \* ======================================================================== */
|
---|
26 |
|
---|
27 | /////////////////////////////////////////////////////////////////////////////
|
---|
28 | //
|
---|
29 | // fillcamera.C
|
---|
30 | // ============
|
---|
31 | //
|
---|
32 | // This macro is used to read the camera-output files and fill the values
|
---|
33 | // into the MC database.
|
---|
34 | // You have to specify the path where to search for the camera files.
|
---|
35 | // As default the dummy mode is kTRUE, so nothing will be filled but only
|
---|
36 | // the mysql orders are printed. To really fill the db, set dummy to kFALSE.
|
---|
37 | //
|
---|
38 | // Make sure, that database and password are corretly set in a resource
|
---|
39 | // file called mcsql.rc and the resource file is found.
|
---|
40 | //
|
---|
41 | // Returns 2 in case of failure and 1 in case of success.
|
---|
42 | // Returns 0 in case of no connection to the db.
|
---|
43 | //
|
---|
44 | //
|
---|
45 | /////////////////////////////////////////////////////////////////////////////
|
---|
46 | #include <iostream>
|
---|
47 | #include <iomanip>
|
---|
48 |
|
---|
49 | #include <TEnv.h>
|
---|
50 | #include <TRegexp.h>
|
---|
51 | #include <TObjectTable.h>
|
---|
52 |
|
---|
53 | #include <TFile.h>
|
---|
54 | #include <TTree.h>
|
---|
55 | #include <TBranch.h>
|
---|
56 |
|
---|
57 | //#include <TH1.h>
|
---|
58 |
|
---|
59 | #include <TSQLResult.h>
|
---|
60 | #include <TSQLRow.h>
|
---|
61 | #include <TSystem.h>
|
---|
62 |
|
---|
63 | #include "MSQLServer.h"
|
---|
64 | #include "MSQLMagic.h"
|
---|
65 |
|
---|
66 | #include "MMcRunHeader.hxx"
|
---|
67 | #include "MMcConfigRunHeader.h"
|
---|
68 | #include "MMcCorsikaRunHeader.h"
|
---|
69 | #include "MMcFadcHeader.hxx"
|
---|
70 | #include "MMcEvtBasic.h"
|
---|
71 | #include "MRawRunHeader.h"
|
---|
72 | //#include "MRawEvtData.h"
|
---|
73 | #include <MDirIter.h>
|
---|
74 |
|
---|
75 | #include <math.h>
|
---|
76 |
|
---|
77 | using namespace std;
|
---|
78 |
|
---|
79 | int Process(MSQLMagic &serv, TString fname, Bool_t dummy)
|
---|
80 | {
|
---|
81 | //
|
---|
82 | // Read file
|
---|
83 | //
|
---|
84 | TFile file(fname, "READ");
|
---|
85 | if (!file.IsOpen())
|
---|
86 | {
|
---|
87 | cout << "ERROR - Could not find file " << fname << endl;
|
---|
88 | return 2;
|
---|
89 | }
|
---|
90 |
|
---|
91 | //
|
---|
92 | // Get tree RunHeaders from file
|
---|
93 | //
|
---|
94 | TTree *tree = dynamic_cast<TTree*>(file.Get("RunHeaders"));
|
---|
95 | if (!tree)
|
---|
96 | {
|
---|
97 | cout << "ERROR - Tree RunHeaders not found in file " << fname << endl;
|
---|
98 | return 2;
|
---|
99 | }
|
---|
100 |
|
---|
101 | //
|
---|
102 | // Get branch MMcCorsikaRunHeader from tree RunHeaders
|
---|
103 | //
|
---|
104 | /* TBranch *b1 = tree->GetBranch("MMcCorsikaRunHeader.");
|
---|
105 | if (!b1)
|
---|
106 | {
|
---|
107 | cout << "ERROR - Branch MMcCorsikaRunHeader. not found in file " << fname << endl;
|
---|
108 | return 2;
|
---|
109 | }
|
---|
110 | MMcCorsikaRunHeader *runheader1 = 0;
|
---|
111 | b1->SetAddress(&runheader1);
|
---|
112 | */
|
---|
113 | MMcCorsikaRunHeader *runheader1 = 0;
|
---|
114 | tree->SetBranchAddress("MMcCorsikaRunHeader.", &runheader1);
|
---|
115 |
|
---|
116 | //
|
---|
117 | // Get branch MMcConfigRunHeader from tree RunHeaders
|
---|
118 | //
|
---|
119 | MMcConfigRunHeader *runheader2 = 0;
|
---|
120 | tree->SetBranchAddress("MMcConfigRunHeader.", &runheader2);
|
---|
121 |
|
---|
122 | //
|
---|
123 | // Get branch MMcRunHeader from tree RunHeaders
|
---|
124 | //
|
---|
125 | MMcRunHeader *runheader3 = 0;
|
---|
126 | tree->SetBranchAddress("MMcRunHeader.", &runheader3);
|
---|
127 |
|
---|
128 | //
|
---|
129 | // Get branch MMcFadcRunHeader from tree RunHeaders
|
---|
130 | //
|
---|
131 | MMcFadcHeader *fadcheader = 0;
|
---|
132 | tree->SetBranchAddress("MMcFadcHeader.", &fadcheader);
|
---|
133 |
|
---|
134 | //
|
---|
135 | // Get branch MRawRunHearder from tree RunHeaders
|
---|
136 | //
|
---|
137 | MRawRunHeader *rawheader = 0;
|
---|
138 | tree->SetBranchAddress("MRawRunHeader.", &rawheader);
|
---|
139 |
|
---|
140 | if (tree->GetEntry(0)<0)
|
---|
141 | {
|
---|
142 | cout << "ERROR - No entry found in tree RunHeaders of file: " << fname << endl;
|
---|
143 | return 2;
|
---|
144 | }
|
---|
145 |
|
---|
146 | //
|
---|
147 | // Get tree Events from file
|
---|
148 | //
|
---|
149 | TTree *tree2 = dynamic_cast<TTree*>(file.Get("Events"));
|
---|
150 | if (!tree2)
|
---|
151 | {
|
---|
152 | cout << "ERROR - Tree Events not found in file " << fname << endl;
|
---|
153 | return 2;
|
---|
154 | }
|
---|
155 |
|
---|
156 | //
|
---|
157 | // Get branch MMcEvtBasic from tree Events
|
---|
158 | //
|
---|
159 | MMcEvtBasic *evtbasic = 0;
|
---|
160 | tree2->SetBranchAddress("MMcEvtBasic.", &evtbasic);
|
---|
161 |
|
---|
162 | if (tree2->GetEntry(0)<0)
|
---|
163 | {
|
---|
164 | cout << "ERROR - No entry found in tree Events of file: " << fname << endl;
|
---|
165 | return 2;
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | // Definition of values
|
---|
170 | Double_t misptx = runheader2->GetMissPointingX();
|
---|
171 | Double_t mispty = runheader2->GetMissPointingY();
|
---|
172 | Double_t point = runheader2->GetPointSpread();
|
---|
173 | Double_t pointspreadx = runheader2->GetPointSpreadX();
|
---|
174 | Double_t pointspready = runheader2->GetPointSpreadY();
|
---|
175 | Double_t coneai = runheader1->GetViewconeAngleInner();
|
---|
176 | Double_t coneao = runheader1->GetViewconeAngleOuter();
|
---|
177 | Double_t spectrum = runheader1->GetSlopeSpec();
|
---|
178 | Double_t tmin = runheader3->GetShowerThetaMin();
|
---|
179 | Double_t tmax = runheader3->GetShowerThetaMax();
|
---|
180 | UInt_t corsvers = runheader3->GetCorsikaVersion();
|
---|
181 | UInt_t reflvers = runheader3->GetReflVersion();
|
---|
182 | UInt_t camvers = runheader3->GetCamVersion();
|
---|
183 | UInt_t numsimshow = runheader3->GetNumSimulatedShowers();
|
---|
184 | UInt_t numevents = tree2->GetEntries();
|
---|
185 |
|
---|
186 | // some calculations: round the given values
|
---|
187 | pointspreadx=TMath::Floor(pointspreadx*100+0.5)/100;
|
---|
188 | pointspready=TMath::Floor(pointspready*100+0.5)/100;
|
---|
189 | point=TMath::Floor(point*10+0.5)/10;
|
---|
190 | coneai=TMath::Floor(coneai*10+0.5)/10;
|
---|
191 | coneao=TMath::Floor(coneao*10+0.5)/10;
|
---|
192 | spectrum=TMath::Floor(spectrum*10+0.5)/10;
|
---|
193 |
|
---|
194 | // Definition of strings
|
---|
195 | TString elow = Form("%5.1f", runheader1->GetELowLim());
|
---|
196 | TString eupp = Form("%5.1f", runheader1->GetEUppLim());
|
---|
197 | TString slope = Form("%5.1f", spectrum);
|
---|
198 | TString wobble = Form("%5.0f", runheader1->GetWobbleMode());
|
---|
199 | TString corsika1 = Form("%5.0f", runheader1->GetCorsikaVersion());
|
---|
200 | TString coneanglei = Form("%5.1f", coneai);
|
---|
201 | TString coneangleo = Form("%5.1f", coneao);
|
---|
202 | TString atmomodel = Form("%5.1f", runheader1->GetAtmosphericModel());
|
---|
203 | TString psf = Form("%5.1f", point);
|
---|
204 | TString psfx = Form("%5.2f", pointspreadx);
|
---|
205 | TString psfy = Form("%5.2f", pointspready);
|
---|
206 | TString psfadd = Form("%5.2f", TMath::Hypot(runheader2->GetPointSpreadX(), runheader2->GetPointSpread()));
|
---|
207 | TString mirrfrac = Form("%5.2f", runheader2->GetMirrorFraction());
|
---|
208 | TString misx = Form("%5.2f", misptx);
|
---|
209 | TString misy = Form("%5.2f", mispty);
|
---|
210 | TString reflector = Form("%5.0i", reflvers);
|
---|
211 | TString camera = Form("%5.0i", camvers);
|
---|
212 | TString imax = Form("%5.1f", runheader3->GetImpactMax());
|
---|
213 | TString numphe = Form("%5.1f", runheader3->GetNumPheFromDNSB());
|
---|
214 | TString pmin = Form("%5.1f", runheader3->GetShowerPhiMin());
|
---|
215 | TString pmax = Form("%5.1f", runheader3->GetShowerPhiMax());
|
---|
216 | TString numss = Form("%7.0i", numsimshow);
|
---|
217 | TString thetamin = Form("%5.1f", tmin);
|
---|
218 | TString thetamax = Form("%5.1f", tmax);
|
---|
219 | TString ped = Form("%5.1f", fadcheader->GetPedestal(1));
|
---|
220 | TString low2high = Form("%5.1f", fadcheader->GetLow2HighGain());
|
---|
221 | TString amplfadc = Form("%5.2f", fadcheader->GetAmplitud());
|
---|
222 | TString amplfadco = Form("%5.2f", fadcheader->GetAmplitudOuter());
|
---|
223 | TString enoise = Form("%5.1f", fadcheader->GetElecNoise(1));
|
---|
224 | TString dnoise = Form("%5.1f", fadcheader->GetDigitalNoise(1));
|
---|
225 | TString numevt = Form("%7.0i", numevents);
|
---|
226 | TString partid = Form("%5.0f", evtbasic->GetPartId());
|
---|
227 | TString partname = evtbasic->GetParticleName();
|
---|
228 |
|
---|
229 | // get the number of triggers
|
---|
230 | UInt_t ntrig = (UInt_t)tree2->Draw("Length$(MRawEvtData.fHiGainPixId.fN)", "MRawEvtData.fHiGainPixId.fN!=0", "goff");
|
---|
231 | if (ntrig<0)
|
---|
232 | {
|
---|
233 | cout << "ERROR - Evaluating triggered events in file: " << fname << endl;
|
---|
234 | return 2;
|
---|
235 | }
|
---|
236 | TString numtrig = Form("%7.0i", ntrig);
|
---|
237 | // TH1I h("myhist", "", 1, -0.5, 0.5);
|
---|
238 | // tree2->Draw("MRawEvtData.GetNumPixels()>>myhist", "", "goff");
|
---|
239 | // h.SetDirectory(0);
|
---|
240 | // TString numtrig = Form("%7.0i", TMath::Nint(h.GetBinContent(2)));
|
---|
241 |
|
---|
242 | // Determine observation mode, fake wobble means On mode with mispointing
|
---|
243 | TString wobblemod="Wobble";
|
---|
244 | if (atoi(wobble)==0)
|
---|
245 | wobblemod = misptx == 0 && mispty == 0 ? "On" : "Fake Wobble";
|
---|
246 | if (atoi(coneangleo)>0)
|
---|
247 | wobblemod = "Diffuse";
|
---|
248 |
|
---|
249 | //get the psf value for the path for linking
|
---|
250 | Float_t pointsfuncx=pointspreadx*10;
|
---|
251 | pointsfuncx=TMath::Floor(pointsfuncx*10+0.5)/10;
|
---|
252 | Int_t pointsfx = TMath::Nint(pointsfuncx);
|
---|
253 |
|
---|
254 | // Get zbin
|
---|
255 | Float_t zBin=TMath::Nint((1-((TMath::Cos(tmin*TMath::Pi()/180)+TMath::Cos(tmax*TMath::Pi()/180))/2))*100);
|
---|
256 | Int_t zBin2=TMath::Nint(zBin);
|
---|
257 |
|
---|
258 | // Definition of keys
|
---|
259 | Int_t corsikakey;
|
---|
260 | Int_t reflectorkey;
|
---|
261 | Int_t camerakey;
|
---|
262 | Int_t observationkey;
|
---|
263 | Int_t particlekey;
|
---|
264 | Int_t atmomodelkey;
|
---|
265 | Int_t amplfadckey;
|
---|
266 | Int_t psfkey;
|
---|
267 | Int_t viewconeangleokey;
|
---|
268 | Int_t spectrumkey;
|
---|
269 |
|
---|
270 | // Definition of variables to be filled in the db
|
---|
271 | TString vars;
|
---|
272 |
|
---|
273 | // Separation of ped/cal and data runs by checking the value pointspread
|
---|
274 | // ped/cal runs
|
---|
275 | if(point==-1)
|
---|
276 | {
|
---|
277 | cout << endl;
|
---|
278 | cout << "psf value: " << point << " -> MC P or C run." << endl;
|
---|
279 | cout << endl;
|
---|
280 | cout << "--- From File ---" << endl;
|
---|
281 | cout << endl;
|
---|
282 | cout << "Energy Range " << elow << " < E < " << eupp << endl;
|
---|
283 | cout << "SpectralIndex " << slope << endl;
|
---|
284 | cout << "CorsikaVer " << corsika1 << endl;
|
---|
285 | cout << "ParticleId " << partid << endl;
|
---|
286 | cout << "ParticleName " << partname << endl;
|
---|
287 | cout << "PointSpread " << psf << endl;
|
---|
288 | cout << "NumSimShowers " << numsimshow << endl;
|
---|
289 | cout << "ImpactMax " << imax << endl;
|
---|
290 | cout << "NumEvents " << numevt << endl;
|
---|
291 | cout << "NumTriggers " << numtrig << endl;
|
---|
292 | cout << "NumPheFromDNSB " << numphe << endl;
|
---|
293 | cout << "ViewconeAngleInner " << coneanglei << endl;
|
---|
294 | cout << "ViewconeAngleOuter " << coneangleo << endl;
|
---|
295 | cout << "AtmosphericModel " << atmomodel << endl;
|
---|
296 | cout << "Pedestal " << ped << endl;
|
---|
297 | cout << "Low2HighGain " << low2high << endl;
|
---|
298 | cout << "AmplitudeFADC " << amplfadc << endl;
|
---|
299 | cout << "AmplFADCOuter " << amplfadco << endl;
|
---|
300 | cout << "ElecNoise " << enoise << endl;
|
---|
301 | cout << "DigiNoise " << dnoise << endl;
|
---|
302 | cout << "PhiMin " << pmin << endl;
|
---|
303 | cout << "PhiMax " << pmax << endl;
|
---|
304 | cout << "ThetaMin " << thetamin << endl;
|
---|
305 | cout << "ThetaMax " << thetamax << endl;
|
---|
306 | cout << "Zenith range " << tmin << " to " << tmax << endl;
|
---|
307 | cout << "MirrorFraction " << mirrfrac << endl;
|
---|
308 | cout << endl;
|
---|
309 | cout << endl;
|
---|
310 | cout << "P/C run: there will be fixed values inserted into the db for the following parameters:" << endl;
|
---|
311 | cout << "ObservationMode " << wobblemod << " -> " << "n/a" <<endl;
|
---|
312 | cout << "ReflVer " << reflvers << " -> " << "n/a" <<endl;
|
---|
313 | cout << "CamVer " << camvers << " -> " << "n/a" <<endl;
|
---|
314 | cout << "PointSpreadX " << psfx << " -> " << "0" <<endl;
|
---|
315 | cout << "PointSpreadY " << psfy << " -> " << "0" <<endl;
|
---|
316 | cout << "MispointingX " << misx << " -> " << "0" <<endl;
|
---|
317 | cout << "MispointingY " << misy << " -> " << "0" <<endl;
|
---|
318 | cout << endl;
|
---|
319 | cout << "--- key's from mcdb tables ---" << endl;
|
---|
320 | cout << endl;
|
---|
321 |
|
---|
322 | corsikakey=1;
|
---|
323 | reflectorkey=1;
|
---|
324 | camerakey=1;
|
---|
325 | observationkey=1;
|
---|
326 | particlekey = 1;
|
---|
327 | atmomodelkey = serv.QueryKeyOfName("AtmosphericModel", atmomodel.Data());
|
---|
328 | amplfadckey = serv.QueryKeyOfName("AmplFadc", amplfadc.Data());
|
---|
329 | viewconeangleokey = serv.QueryKeyOfName("ViewconeAngleO", coneangleo.Data());
|
---|
330 | spectrumkey = 1;
|
---|
331 | psfkey = 1;
|
---|
332 |
|
---|
333 | if (corsvers==0)
|
---|
334 | {
|
---|
335 | cout << "CorsikaVersion not available" << endl;
|
---|
336 | }
|
---|
337 | else
|
---|
338 | {
|
---|
339 | corsikakey = serv.QueryKeyOfName("CorsikaVersion", corsika1.Data());
|
---|
340 | }
|
---|
341 | if (reflvers==0)
|
---|
342 | {
|
---|
343 | cout << "ReflectorVersion not available" << endl;
|
---|
344 | }
|
---|
345 | else
|
---|
346 | {
|
---|
347 | reflectorkey = serv.QueryKeyOfName("ReflectorVersion", reflector.Data());
|
---|
348 | }
|
---|
349 | if (camvers==0)
|
---|
350 | {
|
---|
351 | cout << "CameraVersion not available" << endl;
|
---|
352 | }
|
---|
353 | else
|
---|
354 | {
|
---|
355 | camerakey = serv.QueryKeyOfName("CameraVersion", camera.Data());
|
---|
356 | }
|
---|
357 |
|
---|
358 | cout << "corsikakey: " << corsikakey << endl;
|
---|
359 | cout << "reflectorkey: " << reflectorkey << endl;
|
---|
360 | cout << "camerakey: " << camerakey << endl;
|
---|
361 | cout << "observationkey: " << observationkey << endl;
|
---|
362 | cout << "particlekey: " << particlekey << endl;
|
---|
363 | cout << "atmomodelkey: " << atmomodelkey << endl;
|
---|
364 | cout << "amplfadckey: " << amplfadckey << endl;
|
---|
365 | cout << "psfkey: " << psfkey << endl;
|
---|
366 | cout << "coneangleokey: " << viewconeangleokey << endl;
|
---|
367 | cout << "spectrumkey: " << spectrumkey << endl;
|
---|
368 | cout << endl;
|
---|
369 |
|
---|
370 | // For ped/cal: fixed values for psf and mispointing
|
---|
371 | vars = Form("fPointSpreadX=0, fPointSpreadY=0, fMissPointingX=0, fMissPointingY=0, ");
|
---|
372 |
|
---|
373 | }
|
---|
374 | // Data runs
|
---|
375 | else
|
---|
376 | {
|
---|
377 |
|
---|
378 | cout << endl;
|
---|
379 | cout << "psf value: " << point << " -> MC data run." << endl;
|
---|
380 | cout << endl;
|
---|
381 | cout << "--- From File ---" << endl;
|
---|
382 | cout << endl;
|
---|
383 | cout << "Energy Range " << elow << " < E < " << eupp << endl;
|
---|
384 | cout << "SpectralIndex " << slope << endl;
|
---|
385 | cout << "ObservationMode " << wobblemod << endl;
|
---|
386 | cout << "CorsikaVer " << corsika1 << endl;
|
---|
387 | cout << "ReflVer " << reflector << endl;
|
---|
388 | cout << "CamVer " << camera << endl;
|
---|
389 | cout << "ParticleId " << partid << endl;
|
---|
390 | cout << "ParticleName " << partname << endl;
|
---|
391 | cout << "PointSpread " << psf << endl;
|
---|
392 | cout << "PointSpreadX " << pointspreadx << endl;
|
---|
393 | cout << "PointSpreadXY " << psfx << " /" << psfy << endl;
|
---|
394 | // cout << "AdditionPSF " << psfadd << endl;
|
---|
395 | cout << "MispointingXY " << misx << " /" << misy <<endl;
|
---|
396 | cout << "NumSimShowers " << numss << endl;
|
---|
397 | cout << "ImpactMax " << imax << endl;
|
---|
398 | cout << "NumEvents " << numevt << endl;
|
---|
399 | cout << "NumTriggers " << numtrig << endl;
|
---|
400 | cout << "NumPheFromDNSB " << numphe << endl;
|
---|
401 | cout << "ViewconeAngleInner " << coneanglei << endl;
|
---|
402 | cout << "ViewconeAngleOuter " << coneangleo << endl;
|
---|
403 | cout << "AtmosphericModel " << atmomodel << endl;
|
---|
404 | cout << "Pedestal " << ped << endl;
|
---|
405 | cout << "Low2HighGain " << low2high << endl;
|
---|
406 | cout << "AmplitudeFADC " << amplfadc << endl;
|
---|
407 | cout << "AmplFADCOuter " << amplfadco << endl;
|
---|
408 | cout << "ElecNoise " << enoise << endl;
|
---|
409 | cout << "DigiNoise " << dnoise << endl;
|
---|
410 | cout << "PhiMin " << pmin << endl;
|
---|
411 | cout << "PhiMax " << pmax << endl;
|
---|
412 | cout << "ThetaMin " << thetamin << endl;
|
---|
413 | cout << "ThetaMax " << thetamax << endl;
|
---|
414 | cout << "Zenith range " << tmin << " to " << tmax << endl;
|
---|
415 | cout << "MirrorFraction " << mirrfrac << endl;
|
---|
416 | cout << endl;
|
---|
417 | cout << endl;
|
---|
418 | cout << "--- key's from mcdb tables ---" << endl;
|
---|
419 | cout << endl;
|
---|
420 |
|
---|
421 | corsikakey=1;
|
---|
422 | reflectorkey=1;
|
---|
423 | camerakey=1;
|
---|
424 | observationkey = serv.QueryKeyOfName("ObservationMode", wobblemod.Data());
|
---|
425 | particlekey = serv.QueryKeyOfName("MCParticle", partname.Data());
|
---|
426 | atmomodelkey = serv.QueryKeyOfName("AtmosphericModel", atmomodel.Data());
|
---|
427 | amplfadckey = serv.QueryKeyOfName("AmplFadc", amplfadc.Data());
|
---|
428 | viewconeangleokey = serv.QueryKeyOfName("ViewconeAngleO", coneangleo.Data());
|
---|
429 | psfkey = serv.QueryKeyOfName("PSF", psfx);
|
---|
430 | spectrumkey = serv.QueryKeyOfName("Spectrum", slope);
|
---|
431 |
|
---|
432 | if (corsvers==0)
|
---|
433 | {
|
---|
434 | cout << "CorsikaVersion not available" << endl;
|
---|
435 | }
|
---|
436 | else
|
---|
437 | {
|
---|
438 | corsikakey = serv.QueryKeyOfName("CorsikaVersion", corsika1.Data());
|
---|
439 | }
|
---|
440 | if (reflvers==0)
|
---|
441 | {
|
---|
442 | cout << "ReflectorVersion not available" << endl;
|
---|
443 | }
|
---|
444 | else
|
---|
445 | {
|
---|
446 | reflectorkey = serv.QueryKeyOfName("ReflectorVersion", reflector.Data());
|
---|
447 | }
|
---|
448 | if (camvers==0)
|
---|
449 | {
|
---|
450 | cout << "CameraVersion not available" << endl;
|
---|
451 | }
|
---|
452 | else
|
---|
453 | {
|
---|
454 | camerakey = serv.QueryKeyOfName("CameraVersion", camera.Data());
|
---|
455 | }
|
---|
456 |
|
---|
457 | cout << "corsikakey: " << corsikakey << endl;
|
---|
458 | cout << "reflectorkey: " << reflectorkey << endl;
|
---|
459 | cout << "camerakey: " << camerakey << endl;
|
---|
460 | cout << "observationkey: " << observationkey << endl;
|
---|
461 | cout << "particlekey: " << particlekey << endl;
|
---|
462 | cout << "atmomodelkey: " << atmomodelkey << endl;
|
---|
463 | cout << "amplfadckey: " << amplfadckey << endl;
|
---|
464 | cout << "psfkey: " << psfkey << endl;
|
---|
465 | cout << "coneangleokey: " << viewconeangleokey << endl;
|
---|
466 | cout << "spectrumkey: " << spectrumkey << endl;
|
---|
467 | cout << endl;
|
---|
468 |
|
---|
469 | // For data runs the values are taken from the file
|
---|
470 | vars = Form("fPointSpreadX=%5.2f, fPointSpreadY=%5.2f, fMissPointingX=%s, fMissPointingY=%s, ",
|
---|
471 | pointspreadx, pointspready, misx.Data(), misy.Data());
|
---|
472 |
|
---|
473 | }
|
---|
474 |
|
---|
475 | // Query maximum run number and add 1 to it, if no runnumber is found, start with 1
|
---|
476 | TString query(Form("SELECT IF (isnull(MAX(MCRunData.fRunNumber)+1),1,MAX(MCRunData.fRunNumber)+1) FROM MCRunData;"));
|
---|
477 | // TString query(Form("SELECT MCRunData.fRunNumber, IF (isnull(MAX(MCRunData.fRunNumber)+1),1,MAX(MCRunData.fRunNumber)+1), "
|
---|
478 | // "fFileName FROM MCRunData LEFT JOIN "
|
---|
479 | // "MCRunProcessStatus ON MCRunData.fRunNumber=MCRunProcessStatus.fRunNumber "
|
---|
480 | // "where fFileName=\"%s\" group by MCRunData.fRunNumber;", fname.Data()));
|
---|
481 |
|
---|
482 | TSQLResult *res = serv.Query(query);
|
---|
483 | if (!res)
|
---|
484 | {
|
---|
485 | cout << "ERROR - Query failed: " << query << endl;
|
---|
486 | return 2;
|
---|
487 | }
|
---|
488 |
|
---|
489 | TSQLRow *row = 0;
|
---|
490 | row = res->Next();
|
---|
491 | TString num=(*row)[0];
|
---|
492 | Int_t RunNum=atoi(num.Data());
|
---|
493 |
|
---|
494 | delete res;
|
---|
495 | // delete row;
|
---|
496 | // Query run number and filename from MCRunProcessStatus
|
---|
497 | TString query2(Form("SELECT fRunNumber, fFileName from MCRunProcessStatus where fFileName=\"%s\"", fname.Data()));
|
---|
498 | res = serv.Query(query2);
|
---|
499 | if (!res)
|
---|
500 | {
|
---|
501 | cout << "ERROR - Query failed: " << query2 << endl;
|
---|
502 | return 2;
|
---|
503 | }
|
---|
504 |
|
---|
505 | row = res->Next();
|
---|
506 | // If query gives no entry for the filename the file will be inserted into the db
|
---|
507 | if (!row)
|
---|
508 | {
|
---|
509 | cout << "No entry in query result: " << query2 << endl;
|
---|
510 | cout << "--------" << endl;
|
---|
511 | cout << "RunNum: " << RunNum << endl;
|
---|
512 | cout << "File: " << fname << endl;
|
---|
513 | cout << endl;
|
---|
514 |
|
---|
515 | vars +=
|
---|
516 | Form("fELowLim=%s, fEUppLim=%s, fSlopeSpec=%5.2f, "
|
---|
517 | "fImpactMax=%s, fNumSimulatedShowers=%d, fNumEvents=%d, "
|
---|
518 | "fNumPheFromDNSB=%s, fZBin=%d, fThetaMin=%s, "
|
---|
519 | "fThetaMax=%s, fPointSpread=%s, "
|
---|
520 | "fPedesMean=%s, fLow2HighGain=%s, "
|
---|
521 | "fAmplFadc=%s, fAmplFadcOuter=%s, ",
|
---|
522 | elow.Data(), eupp.Data(), spectrum,
|
---|
523 | imax.Data(), numsimshow, numevents,
|
---|
524 | numphe.Data(), zBin2, thetamin.Data(),
|
---|
525 | thetamax.Data(), psf.Data(),
|
---|
526 | ped.Data(), low2high.Data(),
|
---|
527 | amplfadc.Data(), amplfadco.Data());
|
---|
528 | vars +=
|
---|
529 | Form("fElectricNoise=%s, "
|
---|
530 | "fDigitalNoise=%s, fRunNumber=%d, "
|
---|
531 | "fCorsikaVersionKEY =%d, "
|
---|
532 | "fReflectorVersionKEY=%d, fCameraVersionKEY=%d, "
|
---|
533 | "fObservationModeKEY=%d, fMCParticleKEY=%d, "
|
---|
534 | "fSequenceFirst=0, fNumTriggers=%d, fViewconeAngleInner=%5.2f, fViewconeAngleOuter=%5.2f, "
|
---|
535 | "fAtmosphericModelKEY=%d, fAmplFadcKEY=%d, "
|
---|
536 | "fPSFKEY=%d, fViewconeAngleOKEY=%d, fSpectrumKEY=%d ",
|
---|
537 | enoise.Data(),
|
---|
538 | dnoise.Data(), RunNum,
|
---|
539 | corsikakey,
|
---|
540 | reflectorkey, camerakey,
|
---|
541 | observationkey, particlekey,
|
---|
542 | ntrig, coneai, coneao,
|
---|
543 | atmomodelkey, amplfadckey,
|
---|
544 | psfkey, viewconeangleokey, spectrumkey);
|
---|
545 |
|
---|
546 | TString vars2 =
|
---|
547 | Form("fRunFilled=Now(), fFileName=\"%s\", fRunNumber=%d ",
|
---|
548 | fname.Data(), RunNum);
|
---|
549 |
|
---|
550 |
|
---|
551 | if (!serv.ExistStr("fRunNumber", "MCRunData", Form("%d", RunNum)))
|
---|
552 | {
|
---|
553 | if (!serv.Insert("MCRunData", vars))
|
---|
554 | return 2;
|
---|
555 | }
|
---|
556 | else
|
---|
557 | if (!serv.Update("MCRunData", vars, Form("fRunNumber=%d", RunNum)))
|
---|
558 | return 2;
|
---|
559 |
|
---|
560 | //MarsVersion miteintragen bei Prozessierung
|
---|
561 |
|
---|
562 | if (!serv.ExistStr("fRunNumber", "MCRunProcessStatus", Form("%d", RunNum)))
|
---|
563 | {
|
---|
564 | if (!serv.Insert("MCRunProcessStatus", vars2))
|
---|
565 | return 2;
|
---|
566 | }
|
---|
567 | else
|
---|
568 | if (!serv.Update("MCRunProcessStatus", vars2, Form("fRunNumber=%d", RunNum)))
|
---|
569 | return 2;
|
---|
570 | }
|
---|
571 | // If the file is already filled into the db, the values will be updated
|
---|
572 | else
|
---|
573 | {
|
---|
574 | TString run=(*row)[0];
|
---|
575 | TString check=(*row)[1];
|
---|
576 | if (check==fname)
|
---|
577 | {
|
---|
578 | RunNum=atoi(run.Data());
|
---|
579 | cout << "File already inserted into db, do update " << endl;
|
---|
580 | cout << "--------" << endl;
|
---|
581 | cout << "RunNum: " << RunNum << endl;
|
---|
582 | cout << "File: " << fname << endl;
|
---|
583 | cout << endl;
|
---|
584 |
|
---|
585 | vars +=
|
---|
586 | Form("fELowLim=%s, fEUppLim=%s, fSlopeSpec=%5.2f, "
|
---|
587 | "fImpactMax=%s, fNumSimulatedShowers=%d, fNumEvents=%d, "
|
---|
588 | "fNumPheFromDNSB=%s, fZBin=%d, fThetaMin=%s, "
|
---|
589 | "fThetaMax=%s, fPointSpread=%s, "
|
---|
590 | "fPedesMean=%s, fLow2HighGain=%s, "
|
---|
591 | "fAmplFadc=%s, fAmplFadcOuter=%s, ",
|
---|
592 | elow.Data(), eupp.Data(), spectrum,
|
---|
593 | imax.Data(), numsimshow, numevents,
|
---|
594 | numphe.Data(), zBin2, thetamin.Data(),
|
---|
595 | thetamax.Data(), psf.Data(),
|
---|
596 | ped.Data(), low2high.Data(),
|
---|
597 | amplfadc.Data(), amplfadco.Data());
|
---|
598 | vars +=
|
---|
599 | Form("fElectricNoise=%s, "
|
---|
600 | "fDigitalNoise=%s, fRunNumber=%d, "
|
---|
601 | "fCorsikaVersionKEY =%d, "
|
---|
602 | "fReflectorVersionKEY=%d, fCameraVersionKEY=%d, "
|
---|
603 | "fObservationModeKEY=%d, fMCParticleKEY=%d, "
|
---|
604 | "fSequenceFirst=0, fNumTriggers=%d, fViewconeAngleInner=%5.2f, fViewconeAngleOuter=%5.2f, "
|
---|
605 | "fAtmosphericModelKEY=%d, fAmplFadcKEY=%d, "
|
---|
606 | "fPSFKEY=%d, fViewconeAngleOKEY=%d, fSpectrumKEY=%d ",
|
---|
607 | enoise.Data(),
|
---|
608 | dnoise.Data(), RunNum,
|
---|
609 | corsikakey,
|
---|
610 | reflectorkey, camerakey,
|
---|
611 | observationkey, particlekey,
|
---|
612 | ntrig, coneai, coneao,
|
---|
613 | atmomodelkey, amplfadckey,
|
---|
614 | psfkey, viewconeangleokey, spectrumkey);
|
---|
615 |
|
---|
616 | TString vars2 =
|
---|
617 | Form("fRunFilled=Now(), fFileName=\"%s\", fRunNumber=%d ",
|
---|
618 | fname.Data(), RunNum);
|
---|
619 |
|
---|
620 |
|
---|
621 | if (!serv.ExistStr("fRunNumber", "MCRunData", Form("%d", RunNum)))
|
---|
622 | {
|
---|
623 | if (!serv.Insert("MCRunData", vars))
|
---|
624 | return 2;
|
---|
625 | }
|
---|
626 | else
|
---|
627 | if (!serv.Update("MCRunData", vars, Form("fRunNumber=%d", RunNum)))
|
---|
628 | return 2;
|
---|
629 |
|
---|
630 | if (!serv.ExistStr("fRunNumber", "MCRunProcessStatus", Form("%d", RunNum)))
|
---|
631 | {
|
---|
632 | if (!serv.Insert("MCRunProcessStatus", vars2))
|
---|
633 | return 2;
|
---|
634 | }
|
---|
635 | else
|
---|
636 | if (!serv.Update("MCRunProcessStatus", vars2, Form("fRunNumber=%d", RunNum)))
|
---|
637 | return 2;
|
---|
638 | }
|
---|
639 | //If none of the above options is true, something must be wrong
|
---|
640 | else
|
---|
641 | {
|
---|
642 | cout << "ERROR - Filename in query (" << check << ") and processed filename (" << fname << ") should be the same!" << endl;
|
---|
643 | return 2;
|
---|
644 | }
|
---|
645 | }
|
---|
646 | delete res;
|
---|
647 | // delete row;
|
---|
648 |
|
---|
649 | //link file geht nur für data files, cal und ped haben keine psf... müssen aber in alle verzeichnisse verlinkt werden
|
---|
650 | //wieder mit if point 0.5/-1.0 else
|
---|
651 |
|
---|
652 | // TString query3(Form("SELECT fMCParticleName, fSpectrum, fFileName, fObservationModeKEY from MCRunData "
|
---|
653 | // "left join MCParticle on MCRunData.fMCParticleKEY=MCParticle.fMCParticleKEY "
|
---|
654 | // "left join Spectrum on Spectrum.fSpectrumKEY=MCRunData.fSpectrumKEY "
|
---|
655 | // "left join MCRunProcessStatus on MCRunProcessStatus.fRunNumber=MCRunData.fRunNumber "
|
---|
656 | // "where MCRunData.fRunNumber=%d;", RunNum));
|
---|
657 | TString query3(Form("SELECT fMCParticleName, fSpectrum FROM MCRunData "
|
---|
658 | "LEFT JOIN MCParticle ON MCRunData.fMCParticleKEY=MCParticle.fMCParticleKEY "
|
---|
659 | "LEFT JOIN Spectrum ON Spectrum.fSpectrumKEY=MCRunData.fSpectrumKEY "
|
---|
660 | "WHERE MCRunData.fRunNumber=%d;", RunNum));
|
---|
661 | res = serv.Query(query3);
|
---|
662 | if (!res)
|
---|
663 | {
|
---|
664 | cout << "ERROR - Query failed: " << query3 << endl;
|
---|
665 | return 2;
|
---|
666 | }
|
---|
667 |
|
---|
668 | row = res->Next();
|
---|
669 |
|
---|
670 | // Definition of variables for linking the file
|
---|
671 | TString rawpath;
|
---|
672 | TString type = "D"; //P, C, D
|
---|
673 | TString particle = (*row)[0]; //ParticleName abfragen
|
---|
674 | TString spec = (*row)[1]; //Spectrum.fSpectrum abfragen
|
---|
675 | TString obsmode; //wird über obskey präzisiert
|
---|
676 | TString mkdir;
|
---|
677 | TString link;
|
---|
678 | TString RunNumber=Form("%08d",RunNum);
|
---|
679 |
|
---|
680 | delete res;
|
---|
681 | rawpath = Form("/magic/montecarlo/rawfiles/19%02d/%02d/%02d", zBin2, amplfadckey, pointsfx);
|
---|
682 | // rawpath = Form("/home/hoehne/Analyse/TestMonteCarlo/montecarlo/rawfiles/19%02d/%02d/%02d", zBin2, amplfadckey, pointsfx);
|
---|
683 | mkdir = Form("mkdir -p -v %s", rawpath.Data());
|
---|
684 |
|
---|
685 | switch (observationkey)
|
---|
686 | {
|
---|
687 | case 1:
|
---|
688 | // obsmode = ""; //evtl für ped u cal verwenden
|
---|
689 | cout << "" << endl;
|
---|
690 | cout << "Ped or Cal run -> no linking by fillcamera.C" << endl;
|
---|
691 | // spec = "";
|
---|
692 | // particle="MonteCarlo";
|
---|
693 | // TRegexp pedcal("_._");
|
---|
694 | // TString peca = fname(pedcal);
|
---|
695 | // if (peca="_P_")
|
---|
696 | // type="P";
|
---|
697 | // if (peca="_C_")
|
---|
698 | // type="C";
|
---|
699 | break;
|
---|
700 | //Problem: zbin und psf
|
---|
701 | //19990101_00002_C_MonteCarlo_E.root
|
---|
702 |
|
---|
703 | case 2:
|
---|
704 | obsmode = "W";
|
---|
705 | break;
|
---|
706 |
|
---|
707 | case 3:
|
---|
708 | obsmode = "";
|
---|
709 | break;
|
---|
710 |
|
---|
711 | case 4:
|
---|
712 | obsmode = "FW";
|
---|
713 | break;
|
---|
714 |
|
---|
715 | case 5:
|
---|
716 | obsmode = "Diff";
|
---|
717 | break;
|
---|
718 |
|
---|
719 | default:
|
---|
720 | cout << "ERROR - ObservationModeKEY wrong value" << endl;
|
---|
721 | return 2;
|
---|
722 | }
|
---|
723 |
|
---|
724 | TRegexp reg("_w.");
|
---|
725 | TString add = fname(reg);
|
---|
726 | // add = add.Data()+2;
|
---|
727 | if (add=="_w+" || add=="_w-")
|
---|
728 | {
|
---|
729 | if (add=="_w+")
|
---|
730 | obsmode += "1";
|
---|
731 | else
|
---|
732 | obsmode += "2";
|
---|
733 | }
|
---|
734 |
|
---|
735 | if (obsmode!=1)
|
---|
736 | {
|
---|
737 | link = Form("ln -sv %s %s/19%02d%02d%02d_%s_%s_%s%s%s_E.root", fname.Data(), rawpath.Data(), zBin2, amplfadckey, pointsfx, RunNumber.Data(), type.Data(), particle.Data(), spec.Data(), obsmode.Data());
|
---|
738 |
|
---|
739 | if (dummy==kFALSE)
|
---|
740 | {
|
---|
741 | gSystem->Exec(mkdir);
|
---|
742 | gSystem->Exec(link);
|
---|
743 | }
|
---|
744 | else
|
---|
745 | {
|
---|
746 | cout << "" << endl;
|
---|
747 | cout << "Dummy mode. The following commands would be executed:" << endl;
|
---|
748 | cout << mkdir << endl;
|
---|
749 | cout << link << endl;
|
---|
750 | cout << "" << endl;
|
---|
751 | }
|
---|
752 | }
|
---|
753 | else
|
---|
754 | {
|
---|
755 | cout << "" << endl;
|
---|
756 | cout << "Linking will be done by fillcamera script" << endl;
|
---|
757 | cout << "" << endl;
|
---|
758 | }
|
---|
759 |
|
---|
760 | delete runheader1;
|
---|
761 | delete runheader2;
|
---|
762 | delete runheader3;
|
---|
763 | delete fadcheader;
|
---|
764 | delete rawheader;
|
---|
765 | delete evtbasic;
|
---|
766 |
|
---|
767 |
|
---|
768 |
|
---|
769 | return 1;
|
---|
770 |
|
---|
771 | }
|
---|
772 | /*
|
---|
773 | int fillcamera(TString fname, Bool_t dummy=kTRUE)
|
---|
774 | {
|
---|
775 | TEnv env("sql.rc");
|
---|
776 |
|
---|
777 | MSQLMagic serv(env);
|
---|
778 | if (!serv.IsConnected())
|
---|
779 | {
|
---|
780 | cout << "ERROR - Connection to database failed." << endl;
|
---|
781 | return 0;
|
---|
782 | }
|
---|
783 |
|
---|
784 | serv.SetIsDummy(dummy);
|
---|
785 |
|
---|
786 | cout << endl;
|
---|
787 | cout << "fillcamera" << endl;
|
---|
788 | cout << "----------" << endl;
|
---|
789 | cout << endl;
|
---|
790 | cout << "Connected to " << serv.GetName() << endl;
|
---|
791 | cout << "File: " << fname << endl;
|
---|
792 | cout << endl;
|
---|
793 |
|
---|
794 | return Process(serv, fname, dummy);
|
---|
795 | }
|
---|
796 | */
|
---|
797 | int fillcamera(TString path="/magic/montecarlo/camera", Bool_t dummy=kTRUE)
|
---|
798 | {
|
---|
799 | TEnv env("mcsql.rc");
|
---|
800 |
|
---|
801 | MSQLMagic serv(env);
|
---|
802 | if (!serv.IsConnected())
|
---|
803 | {
|
---|
804 | cout << "ERROR - Connection to database failed." << endl;
|
---|
805 | return 0;
|
---|
806 | }
|
---|
807 |
|
---|
808 | serv.SetIsDummy(dummy);
|
---|
809 |
|
---|
810 | cout << endl;
|
---|
811 | cout << "fillcamera" << endl;
|
---|
812 | cout << "----------" << endl;
|
---|
813 | cout << endl;
|
---|
814 | cout << "Connected to " << serv.GetName() << endl;
|
---|
815 | cout << "Search path: " << path << endl;
|
---|
816 | cout << endl;
|
---|
817 |
|
---|
818 |
|
---|
819 | TString fname;
|
---|
820 | TString name;
|
---|
821 |
|
---|
822 |
|
---|
823 | MDirIter Next(path,"*.root",-1);
|
---|
824 |
|
---|
825 | while(1)
|
---|
826 | {
|
---|
827 | TString name = Next();
|
---|
828 | if (name.IsNull())
|
---|
829 | break;
|
---|
830 | fname=name;
|
---|
831 | cout << endl;
|
---|
832 | cout << endl;
|
---|
833 | cout << "filename: " << fname << endl;
|
---|
834 |
|
---|
835 | // TObject::SetObjectStat(kTRUE);
|
---|
836 |
|
---|
837 | if (!Process(serv, name, dummy))
|
---|
838 | return 2;
|
---|
839 | /*
|
---|
840 | if (TObject::GetObjectStat())
|
---|
841 | {
|
---|
842 | TObject::SetObjectStat(kFALSE);
|
---|
843 | gObjectTable->Print();
|
---|
844 | }
|
---|
845 | */
|
---|
846 | }
|
---|
847 |
|
---|
848 | return 1;
|
---|
849 | }
|
---|