source: branches/Corsika7405Compatibility/datacenter/macros/fillcamera.C@ 18528

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