Changeset 8760 for trunk/MagicSoft
- Timestamp:
- 10/16/07 09:43:12 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/fillcamera.C
r8606 r8760 18 18 ! Author(s): Thomas Bretz, 06/2007 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! Author(s): Daniela Dorner, 11/2005 <mailto:dorner@astro.uni-wuerzburg.de> 20 ! Author(s): Daniel Hoehne, 06/2007 <mailto:hoehne@astro.uni-wuerzburg.de>20 ! Author(s): Daniel Hoehne, 10/2007 <mailto:hoehne@astro.uni-wuerzburg.de> 21 21 ! 22 22 ! Copyright: MAGIC Software Development, 2000-2007 … … 30 30 // ============ 31 31 // 32 // This macro is used to read the camera-output files. 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. 33 37 // 34 38 // Make sure, that database and password are corretly set in a resource 35 // file called sql.rc and the resource file is found.39 // file called mcsql.rc and the resource file is found. 36 40 // 37 // Returns 0 in case of failure and 1 in case of success. 41 // Returns 2 in case of failure and 1 in case of success. 42 // Returns 0 in case of no connection to the db. 38 43 // 39 44 // … … 44 49 #include <TEnv.h> 45 50 #include <TRegexp.h> 51 #include <TObjectTable.h> 46 52 47 53 #include <TFile.h> … … 49 55 #include <TBranch.h> 50 56 51 #include <TH1.h>57 //#include <TH1.h> 52 58 53 59 #include <TSQLResult.h> 54 60 #include <TSQLRow.h> 61 #include <TSystem.h> 55 62 56 63 #include "MSQLServer.h" … … 62 69 #include "MMcFadcHeader.hxx" 63 70 #include "MMcEvtBasic.h" 64 #include "MGeomCamMagic.h"65 71 #include "MRawRunHeader.h" 72 //#include "MRawEvtData.h" 73 #include <MDirIter.h> 66 74 67 75 #include <math.h> 68 #include <MBinning.h>69 76 70 77 using namespace std; … … 72 79 int Process(MSQLMagic &serv, TString fname, Bool_t dummy) 73 80 { 81 // 82 // Read file 83 // 74 84 TFile file(fname, "READ"); 75 85 if (!file.IsOpen()) … … 92 102 // Get branch MMcCorsikaRunHeader from tree RunHeaders 93 103 // 94 TBranch *b1 = tree->GetBranch("MMcCorsikaRunHeader.");104 /* TBranch *b1 = tree->GetBranch("MMcCorsikaRunHeader."); 95 105 if (!b1) 96 106 { … … 98 108 return 2; 99 109 } 100 101 110 MMcCorsikaRunHeader *runheader1 = 0; 102 111 b1->SetAddress(&runheader1); 112 */ 113 MMcCorsikaRunHeader *runheader1 = 0; 114 tree->SetBranchAddress("MMcCorsikaRunHeader.", &runheader1); 103 115 104 116 // 105 117 // Get branch MMcConfigRunHeader from tree RunHeaders 106 118 // 107 TBranch *b2 = tree->GetBranch("MMcConfigRunHeader.");108 if (!b2)109 {110 cout << "ERROR - Branch MMcConfigRunHeader. not found in file " << fname << endl;111 return 2;112 }113 114 119 MMcConfigRunHeader *runheader2 = 0; 115 b2->SetAddress(&runheader2);120 tree->SetBranchAddress("MMcConfigRunHeader.", &runheader2); 116 121 117 122 // 118 123 // Get branch MMcRunHeader from tree RunHeaders 119 124 // 120 TBranch *b3 = tree->GetBranch("MMcRunHeader.");121 if (!b3)122 {123 cout << "ERROR - Branch MMcRunHeader. not found in file " << fname << endl;124 return 2;125 }126 127 125 MMcRunHeader *runheader3 = 0; 128 b3->SetAddress(&runheader3);126 tree->SetBranchAddress("MMcRunHeader.", &runheader3); 129 127 130 128 // 131 129 // Get branch MMcFadcRunHeader from tree RunHeaders 132 130 // 133 TBranch *b4 = tree->GetBranch("MMcFadcHeader.");134 if (!b4)135 {136 cout << "ERROR - Branch MMcFadcHeader. not found in file " << fname << endl;137 return 2;138 }139 140 131 MMcFadcHeader *fadcheader = 0; 141 b4->SetAddress(&fadcheader);132 tree->SetBranchAddress("MMcFadcHeader.", &fadcheader); 142 133 143 134 // 144 135 // Get branch MRawRunHearder from tree RunHeaders 145 136 // 146 TBranch *b5 = tree->GetBranch("MRawRunHeader.");147 if (!b5)148 {149 cout << "ERROR - Branch MRawRunHeader. not found in file " << fname << endl;150 return 2;151 }152 153 137 MRawRunHeader *rawheader = 0; 154 b5->SetAddress(&rawheader); 155 156 tree->GetEvent(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 } 157 145 158 146 // … … 169 157 // Get branch MMcEvtBasic from tree Events 170 158 // 171 TBranch *b6 = tree2->GetBranch("MMcEvtBasic.");172 if (!b6)173 {174 cout << "ERROR - Branch MMcEvtBasic. not found in file " << fname << endl;175 return 2;176 }177 178 159 MMcEvtBasic *evtbasic = 0; 179 b6->SetAddress(&evtbasic); 180 181 tree2->GetEvent(0); 182 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 183 170 Double_t misptx = runheader2->GetMissPointingX(); 184 171 Double_t mispty = runheader2->GetMissPointingY(); 172 Double_t point = runheader2->GetPointSpread(); 185 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(); 186 178 Double_t tmin = runheader3->GetShowerThetaMin(); 187 179 Double_t tmax = runheader3->GetShowerThetaMax(); 180 UInt_t corsvers = runheader3->GetCorsikaVersion(); 188 181 UInt_t reflvers = runheader3->GetReflVersion(); 189 182 UInt_t camvers = runheader3->GetCamVersion(); … … 191 184 UInt_t numevents = tree2->GetEntries(); 192 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 193 195 TString elow = Form("%5.1f", runheader1->GetELowLim()); 194 196 TString eupp = Form("%5.1f", runheader1->GetEUppLim()); 195 TString slope = Form("%5.1f", runheader1->GetSlopeSpec());197 TString slope = Form("%5.1f", spectrum); 196 198 TString wobble = Form("%5.0f", runheader1->GetWobbleMode()); 197 199 TString corsika1 = Form("%5.0f", runheader1->GetCorsikaVersion()); 198 TString psf = Form("%5.1f", runheader2->GetPointSpread()); 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); 199 204 TString psfx = Form("%5.2f", pointspreadx); 200 TString psfy = Form("%5.2f", runheader2->GetPointSpreadY());205 TString psfy = Form("%5.2f", pointspready); 201 206 TString psfadd = Form("%5.2f", TMath::Hypot(runheader2->GetPointSpreadX(), runheader2->GetPointSpread())); 202 207 TString mirrfrac = Form("%5.2f", runheader2->GetMirrorFraction()); 203 208 TString misx = Form("%5.2f", misptx); 204 209 TString misy = Form("%5.2f", mispty); 205 // TString reflector = Form("%5.0f", runheader3->GetReflVersion());206 210 TString reflector = Form("%5.0i", reflvers); 207 211 TString camera = Form("%5.0i", camvers); 208 // TString camera = Form("%5.0f", runheader3->GetCamVersion());209 212 TString imax = Form("%5.1f", runheader3->GetImpactMax()); 210 213 TString numphe = Form("%5.1f", runheader3->GetNumPheFromDNSB()); … … 216 219 TString ped = Form("%5.1f", fadcheader->GetPedestal(1)); 217 220 TString low2high = Form("%5.1f", fadcheader->GetLow2HighGain()); 218 TString amplfadc = Form("%5. 1f", fadcheader->GetAmplitud());219 TString amplfadco = Form("%5. 1f", fadcheader->GetAmplitudOuter());221 TString amplfadc = Form("%5.2f", fadcheader->GetAmplitud()); 222 TString amplfadco = Form("%5.2f", fadcheader->GetAmplitudOuter()); 220 223 TString enoise = Form("%5.1f", fadcheader->GetElecNoise(1)); 221 224 TString dnoise = Form("%5.1f", fadcheader->GetDigitalNoise(1)); 222 223 TH1I h("myhist", "", 1, -0.5, 0.5);224 tree2->Draw("MRawEvtData.GetNumPixels()>>myhist", "", "goff");225 h.SetDirectory(0);226 227 TString numtrig = Form("%7.0i", TMath::Nint(h.GetBinContent(2)));228 225 TString numevt = Form("%7.0i", numevents); 229 226 TString partid = Form("%5.0f", evtbasic->GetPartId()); 230 227 TString partname = evtbasic->GetParticleName(); 231 228 232 // Bestimmung von fakewobble aus file 233 // Kombination aus Wobble(0,1) und MissPoint 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 234 243 TString wobblemod="Wobble"; 235 236 // Fake Wobble: als ObservationModeKEY 4 einfügen? 237 if (wobblemod != 1) 244 if (atoi(wobble)==0) 238 245 wobblemod = misptx == 0 && mispty == 0 ? "On" : "Fake Wobble"; 239 240 Float_t pointsfx=TMath::Floor(pointspreadx*10); 241 pointsfx=TMath::Nint(pointsfx); 242 TString pointsfuncx=Form("%5.1f",pointsfx); 243 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 244 255 Float_t zBin=TMath::Nint((1-((TMath::Cos(tmin*TMath::Pi()/180)+TMath::Cos(tmax*TMath::Pi()/180))/2))*100); 245 zBin=TMath::Nint(zBin); 246 247 // folgende Werte werden aus dem Pfadnamen gewonnen 248 // RunNumber 249 TRegexp reg2("_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_"); 250 TString Run = fname(reg2); 251 Int_t RunNum = atoi(Run.Data()+1); 252 if (RunNum < 1 || RunNum > 99999) 253 { 254 cout << "ERROR - RunNumber wrong value" << endl; 255 return 2; 256 } 257 258 // PointSpreadFunction 259 TRegexp reg4("/[12][0-9]/"); 260 TString pointsf = fname(reg4); 261 Int_t Point = atoi(pointsf.Data()+1); 262 if (Point < 0 || Point > 99) 263 { 264 cout << "ERROR - PointSpreadFunction wrong value" << endl; 265 return 2; 266 } 267 268 // zbin 269 TRegexp reg1("/19[0-9][0-9]/"); 270 TString zbin = fname(reg1); 271 Int_t ZBin = atoi(zbin.Data()+3); 272 if (ZBin < 0 || ZBin > 99) 273 { 274 cout << "ERROR - zbin wrong value" << endl; 275 return 2; 276 } 277 278 // WobbleMode 279 TRegexp reg3("/0[0-9]/"); /*extrahiert '/0X' mit X= 1-8 */ 280 TString wm = fname(reg3); /* weist WM den extrahierten Wert zu */ 281 Int_t wob = atoi(wm.Data()+1); /* schneidet fuehrenden '/' ab */ 282 283 284 // Umrechnung von WobbleModus Bezeichnung in 'wobble', 'nowobble', 'fakewobble' 285 TString wobmode; // dieser Wert wird in 'MCDB' Tabelle 'WobbleMode' eingetragen 286 switch (wob) 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) 287 686 { 288 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 289 707 case 3: 290 wobmode = "Wobble";708 obsmode = ""; 291 709 break; 292 710 293 case 2:294 711 case 4: 295 case 7: 296 case 8: 297 wobmode = "On"; 712 obsmode = "FW"; 298 713 break; 299 714 300 715 case 5: 301 case 6: 302 wobmode = "Fake Wobble"; 716 obsmode = "Diff"; 303 717 break; 304 718 305 719 default: 306 cout << "ERROR - ObservationMode wrong value" << endl; 307 return 2; 308 } 309 310 311 cout << endl; 312 cout << endl; 313 314 cout << "--- From File ---" << endl; 315 316 cout << endl; 317 cout << "Energy Range " << elow << " < E < " << eupp << endl; 318 cout << "SpectralIndex " << slope << endl; 319 cout << "ObservationMode " << wobblemod << endl; 320 cout << "CorsikaVer " << corsika1 << endl; 321 cout << "ReflVer " << reflector << endl; 322 cout << "CamVer " << camera << endl; 323 cout << "ParticleId " << partid << endl; 324 cout << "ParticleName " << partname << endl; 325 cout << "PointSpread " << psf << endl; 326 cout << "PointSpreadXY " << psfx << " /" << psfy << endl; 327 cout << "AdditionPSF " << psfadd << endl; 328 cout << "MispointingXY " << misx << " /" << misy <<endl; 329 cout << "NumSimShowers " << numss << endl; 330 cout << "ImpactMax " << imax << endl; 331 cout << "NumEvents " << numevt << endl; 332 cout << "NumTriggers " << numtrig << endl; 333 cout << "NumPheFromDNSB " << numphe << endl; 334 cout << "Pedestal " << ped << endl; 335 cout << "Low2HighGain " << low2high << endl; 336 cout << "AmplitudeFADC " << amplfadc << endl; 337 cout << "AmplFADCOuter " << amplfadco << endl; 338 cout << "ElecNoise " << enoise << endl; 339 cout << "DigiNoise " << dnoise << endl; 340 cout << "PhiMin " << pmin << endl; 341 cout << "PhiMax " << pmax << endl; 342 cout << "ThetaMin " << thetamin << endl; 343 cout << "ThetaMax " << thetamax << endl; 344 cout << "Zenith range " << tmin << " to " << tmax << endl; 345 cout << "MirrorFraction " << mirrfrac << endl; 346 cout << endl; 347 348 cout << endl; 349 cout << "--- key's from mcdb tables ---" << endl; 350 cout << endl; 351 352 Int_t corsikakey = serv.QueryKeyOfName("CorsikaVersion", corsika1.Data()); 353 Int_t reflectorkey = serv.QueryKeyOfName("ReflectorVersion", reflector.Data()); 354 Int_t camerakey = serv.QueryKeyOfName("CameraVersion", camera.Data()); 355 Int_t observationkey = serv.QueryKeyOfName("ObservationMode", wobblemod.Data()); 356 Int_t particlekey = serv.QueryKeyOfName("MCParticle", partname.Data()); 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 364 cout << endl; 365 cout << endl; 366 cout << "--- From File ---" << endl; 367 cout << endl; 368 cout << "WobbleMode " << wobblemod << endl; 369 cout << "PSF " << pointsfuncx << endl; 370 cout << "zBin " << zBin << endl; 371 cout << endl; 372 cout << "--- From FileName ---" << endl; 373 cout << endl; 374 cout << "WobbleMode " << wobmode << endl; 375 cout << "RunNum " << RunNum << endl; 376 cout << "PSF " << Point << endl; 377 cout << "ZBin " << ZBin << endl; 378 cout << "WobbleMode(dir) " << wob << endl; 379 cout << endl; 380 381 382 if (wobblemod!=wobmode) 383 { 384 cout << "Error, WobbleMode in file and filename are not the same" << endl; 385 return 2; 386 } 387 if (pointsfx!=Point) 388 { 389 cout << "Error, PSF in file and filename are not the same" << endl; 390 return 2; 391 } 392 if (zBin!=ZBin) 393 { 394 cout << "Error, ZBin in file and filename are not the same" << endl; 395 return 2; 396 } 397 398 TString vars = 399 Form("fELowLim=%s, fEUppLim=%s, fSlopeSpec=%s, " 400 "fImpactMax=%s, fNumSimulatedShowers=%d, fNumEvents=%d, " 401 "fNumPheFromDNSB=%s, fZBin=%d, fThetaMin=%s, " 402 "fThetaMax=%s, fPointSpread=%s, fPointSpreadX=%s, " 403 "fPointSpreadY=%s, fPedesMean=%s, fLow2HighGain=%s, ", 404 elow.Data(), eupp.Data(), slope.Data(), imax.Data(), 405 numsimshow, numevents, numphe.Data(), 406 zBin, thetamin.Data(), thetamax.Data(), psf.Data(), 407 psfx.Data(), psfy.Data(), ped.Data(), low2high.Data()); 408 vars += 409 Form("fAmplFadc=%s, fAmplFadcOuter=%s, fElectricNoise=%s, " 410 "fDigitalNoise=%s, fRunNumber=%d, fMisspointingX=%s, " 411 "fMissPointingY=%s, fCorsikaVersionKEY =%d, " 412 "fReflectorVersionKEY=%d, fCameraVersionKEY=%d, " 413 "fObservationModeKEY=%d, fMCParticleKEY=%d, " 414 "fSequenceFirst=0, fNumTriggers=%s ", 415 amplfadc.Data(), amplfadco.Data(), enoise.Data(), 416 dnoise.Data(), RunNum, misx.Data(), misy.Data(), corsikakey, 417 reflectorkey, camerakey, observationkey, particlekey, numtrig.Data()); 418 419 // Comming soon (-1: dummy, 0: failed, 1: succeeded) 420 // return serv.InsertUpdate("MCRunData", "fRunNumber", RunData()+1, vars); 421 422 if (!serv.ExistStr("fRunNumber", "MCRunData", Run.Data()+1)) 423 if (!serv.Insert("MCRunData", vars)==kFALSE) 424 return 2; 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 } 425 753 else 426 if (!serv.Update("MCRunData", vars, Form("fRunNumber=%d", Run))==kFALSE) 427 return 2; 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 428 768 429 769 return 1; 770 430 771 } 431 772 /* 432 773 int fillcamera(TString fname, Bool_t dummy=kTRUE) 433 774 { … … 453 794 return Process(serv, fname, dummy); 454 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 }
Note:
See TracChangeset
for help on using the changeset viewer.