Commit fe29729a1d272b781eba4acbd81f563792ae9479
1 parent
0c2ccf43
use eventcube for ctbkgcube
Showing
3 changed files
with
53 additions
and
35 deletions
src/ctbkgcube/ctbkgcube deleted
No preview for this file type
src/ctbkgcube/ctbkgcube.cpp
| ... | ... | @@ -320,42 +320,35 @@ void ctbkgcube::run(void) |
| 320 | 320 | ***************************************************************************/ |
| 321 | 321 | void ctbkgcube::fill_cube(GCTAObservation* obs, const GModels& models) |
| 322 | 322 | { |
| 323 | - | |
| 324 | - // Get pointing to do coordinate transformation | |
| 325 | - GCTAPointing pnt = obs->pointing(); | |
| 326 | - GTime time = (*obs->events())[0]->time(); | |
| 327 | - double ontime = obs->ontime(); | |
| 328 | 323 | // Continue only if observation pointer is valid |
| 329 | 324 | if (obs != NULL) { |
| 330 | 325 | |
| 331 | - // Initialise statistics | |
| 332 | - double sum = 0.0; | |
| 333 | - | |
| 334 | - // Loop over all pixels in sky map | |
| 335 | - for (int pixel = 0; pixel < m_bkgcube.npix(); ++pixel) { | |
| 336 | - | |
| 337 | - GSkyDir dir = m_bkgcube.inx2dir(pixel); | |
| 338 | - GCTAInstDir instdir = pnt.instdir(dir); | |
| 339 | - | |
| 340 | - // Loop over all background cube energy bins | |
| 341 | - for (int iebin = 0; iebin < m_ebounds.size(); ++iebin){ | |
| 326 | + obs->events(m_bkgcube); | |
| 327 | + GCTAEventCube* cube = | |
| 328 | + const_cast<GCTAEventCube*>(dynamic_cast<const GCTAEventCube*>(obs->events())); | |
| 329 | + // Initialise statistics | |
| 330 | + double sum = 0.0; | |
| 331 | + GCTAEventBin* bin = (*cube)[10000]; | |
| 332 | + std::cout << bin->counts() << std::endl; | |
| 333 | + // Loop over all events in counts map | |
| 334 | + for (int i = 0; i < cube->size(); ++i) { | |
| 342 | 335 | |
| 343 | 336 | // Get event bin |
| 344 | - GCTAEventBin* bin = new GCTAEventBin(); | |
| 345 | - | |
| 337 | + GCTAEventBin* bin = (*cube)[i]; | |
| 338 | + | |
| 346 | 339 | // Compute model value for event bin |
| 347 | 340 | double model = |
| 348 | 341 | models.eval(*(const_cast<const GCTAEventBin*>(bin)), *obs) * |
| 349 | 342 | bin->size(); |
| 350 | - | |
| 351 | - // Store value | |
| 352 | - bin->counts( bin->counts() + model ); | |
| 343 | + | |
| 344 | + // Store value | |
| 345 | + bin->counts( bin->counts() + model ); | |
| 346 | + | |
| 347 | + // Sum all events | |
| 348 | + sum += model; | |
| 353 | 349 | |
| 354 | - // Sum all events | |
| 355 | - sum += model; | |
| 356 | 350 | } |
| 357 | - } | |
| 358 | - | |
| 351 | + | |
| 359 | 352 | // Log results |
| 360 | 353 | if (logTerse()) { |
| 361 | 354 | log << gammalib::parformat("Model events in cube"); |
| ... | ... | @@ -384,7 +377,7 @@ void ctbkgcube::save(void) |
| 384 | 377 | m_outfile = (*this)["outfile"].filename(); |
| 385 | 378 | |
| 386 | 379 | // Save background cube |
| 387 | - m_bkgcube.save(m_outfile, clobber()); | |
| 380 | + m_map.save(m_outfile, clobber()); | |
| 388 | 381 | |
| 389 | 382 | // Return |
| 390 | 383 | return; |
| ... | ... | @@ -431,9 +424,20 @@ void ctbkgcube::get_parameters(void) |
| 431 | 424 | get_ebounds(); |
| 432 | 425 | |
| 433 | 426 | // Define background cube |
| 434 | - m_bkgcube = GSkymap(wcs, coordsys, xref, yref, | |
| 435 | - -binsz, binsz, nxpix, nypix, | |
| 436 | - m_ebounds.size()); | |
| 427 | + m_map = GSkymap(wcs, coordsys, xref, yref, | |
| 428 | + -binsz, binsz, nxpix, nypix, | |
| 429 | + m_ebounds.size()); | |
| 430 | + GGti gti = m_obs[0]->events()->gti(); | |
| 431 | + m_bkgcube = GCTAEventCube(m_map, m_ebounds, gti); | |
| 432 | + | |
| 433 | + // Loop over all events in background cube and | |
| 434 | + // set all pixels to 0 | |
| 435 | + for (int i = 0; i < m_bkgcube.size(); ++i) | |
| 436 | + { | |
| 437 | + // Get event bin | |
| 438 | + GCTAEventBin* bin = m_bkgcube[i]; | |
| 439 | + bin->counts(0); | |
| 440 | + } | |
| 437 | 441 | } |
| 438 | 442 | |
| 439 | 443 | // ... otherwise setup the background cube from the counts map |
| ... | ... | @@ -651,12 +655,23 @@ void ctbkgcube::set_from_cntmap(const std::string& filename) |
| 651 | 655 | |
| 652 | 656 | // Get energy definition |
| 653 | 657 | m_ebounds = cube->ebounds(); |
| 654 | - | |
| 658 | + | |
| 659 | + | |
| 655 | 660 | // Define background cube |
| 656 | - m_bkgcube = GSkymap(proj, coordsys, xref, yref, | |
| 657 | - dx, dy, nx, ny, | |
| 658 | - m_ebounds.size()); | |
| 659 | - | |
| 661 | + m_map = GSkymap(proj, coordsys, xref, yref, | |
| 662 | + dx, dy, nx, ny, | |
| 663 | + m_ebounds.size()); | |
| 664 | + GGti gti = m_obs[0]->events()->gti(); | |
| 665 | + m_bkgcube = GCTAEventCube(m_map, m_ebounds, gti); | |
| 666 | + // Loop over all events in background cube and | |
| 667 | + // set all pixels to 0 | |
| 668 | + for (int i = 0; i < m_bkgcube.size(); ++i) | |
| 669 | + { | |
| 670 | + // Get event bin | |
| 671 | + GCTAEventBin* bin = m_bkgcube[i]; | |
| 672 | + bin->counts(0); | |
| 673 | + } | |
| 674 | + | |
| 660 | 675 | } // endif: WCS projection was valid |
| 661 | 676 | |
| 662 | 677 | // ... projection is not of WCS type |
| ... | ... | @@ -698,6 +713,7 @@ void ctbkgcube::init_members(void) |
| 698 | 713 | m_read_ahead = false; |
| 699 | 714 | m_obs.clear(); |
| 700 | 715 | m_bkgcube.clear(); |
| 716 | + m_map.clear(); | |
| 701 | 717 | m_ebounds.clear(); |
| 702 | 718 | |
| 703 | 719 | // Set logger properties |
| ... | ... | @@ -723,6 +739,7 @@ void ctbkgcube::copy_members(const ctbkgcube& app) |
| 723 | 739 | m_read_ahead = app.m_read_ahead; |
| 724 | 740 | m_obs = app.m_obs; |
| 725 | 741 | m_bkgcube = app.m_bkgcube; |
| 742 | + m_map = app.m_map; | |
| 726 | 743 | m_ebounds = app.m_ebounds; |
| 727 | 744 | |
| 728 | 745 | // Return | ... | ... |
src/ctbkgcube/ctbkgcube.hpp
| ... | ... | @@ -81,7 +81,8 @@ protected: |
| 81 | 81 | // Protected members |
| 82 | 82 | bool m_read_ahead; //!< Read ahead parameters |
| 83 | 83 | GObservations m_obs; //!< Observation container |
| 84 | - GSkymap m_bkgcube; //!< Background cube | |
| 84 | + GCTAEventCube m_bkgcube; //!< Background cube | |
| 85 | + GSkymap m_map; //!< Background map | |
| 85 | 86 | GEbounds m_ebounds; //!< Energy boundaries |
| 86 | 87 | |
| 87 | 88 | }; | ... | ... |