source: trunk/MagicSoft/Mars/datacenter/macros/fillcamera.C@ 9186

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