Commit d8ee9991f826f5d81d04be9e53954b0e9fc5135b
1 parent
d4952241
add init_map and write out sky map
Showing
2 changed files
with
111 additions
and
84 deletions
src/ctskymap/ctskymap.cpp
| ... | ... | @@ -33,6 +33,7 @@ |
| 33 | 33 | #include "GTools.hpp" |
| 34 | 34 | |
| 35 | 35 | /* __ Method name definitions ____________________________________________ */ |
| 36 | +#define G_INIT_MAP "ctskymap::init_map(GCTAObservation* obs)" | |
| 36 | 37 | #define G_BIN_EVENTS "ctskymap::bin_events(GCTAObservation*)" |
| 37 | 38 | |
| 38 | 39 | /* __ Debug definitions __________________________________________________ */ |
| ... | ... | @@ -198,8 +199,7 @@ void ctskymap::clear(void) |
| 198 | 199 | /***********************************************************************//** |
| 199 | 200 | * @brief Execute application |
| 200 | 201 | * |
| 201 | - * This method bins the events data into a counts maps and saves the counts | |
| 202 | - * map into a FITS file. | |
| 202 | + * This method creates the sky map and saves the map into a FITS file. | |
| 203 | 203 | ***************************************************************************/ |
| 204 | 204 | void ctskymap::execute(void) |
| 205 | 205 | { |
| ... | ... | @@ -207,10 +207,10 @@ void ctskymap::execute(void) |
| 207 | 207 | // parameters log |
| 208 | 208 | m_outfile = (*this)["outfile"].filename(); |
| 209 | 209 | |
| 210 | - // Bin the event data | |
| 210 | + // Create the sky map | |
| 211 | 211 | run(); |
| 212 | 212 | |
| 213 | - // Save the counts map into FITS file | |
| 213 | + // Save the sky map into FITS file | |
| 214 | 214 | save(); |
| 215 | 215 | |
| 216 | 216 | // Return |
| ... | ... | @@ -219,13 +219,22 @@ void ctskymap::execute(void) |
| 219 | 219 | |
| 220 | 220 | |
| 221 | 221 | /***********************************************************************//** |
| 222 | - * @brief Bin the event data | |
| 222 | + * @brief Creates sky maps from data | |
| 223 | + * | |
| 224 | + * This method is the main code. It | |
| 225 | + * (1) reads task parameters from the par file | |
| 226 | + * (2) initialises the sky maps | |
| 227 | + * (3) loops over all observations to add its events to the sky map | |
| 223 | 228 | ***************************************************************************/ |
| 224 | 229 | void ctskymap::run(void) |
| 225 | 230 | { |
| 231 | + // Initialise statistics | |
| 232 | + int num_obs = 0; | |
| 233 | + | |
| 226 | 234 | // Switch screen logging on in debug mode |
| 227 | - if (logDebug()) | |
| 235 | + if (logDebug()) { | |
| 228 | 236 | log.cout(true); |
| 237 | + } | |
| 229 | 238 | |
| 230 | 239 | // Get parameters |
| 231 | 240 | get_parameters(); |
| ... | ... | @@ -239,20 +248,24 @@ void ctskymap::run(void) |
| 239 | 248 | // Write observation(s) into logger |
| 240 | 249 | if (logTerse()) { |
| 241 | 250 | log << std::endl; |
| 242 | - if (m_obs.size() > 1) | |
| 251 | + if (m_obs.size() > 1) { | |
| 243 | 252 | log.header1("Observations"); |
| 244 | - else | |
| 253 | + } | |
| 254 | + else { | |
| 245 | 255 | log.header1("Observation"); |
| 256 | + } | |
| 246 | 257 | log << m_obs << std::endl; |
| 247 | 258 | } |
| 248 | 259 | |
| 249 | 260 | // Write header |
| 250 | 261 | if (logTerse()) { |
| 251 | 262 | log << std::endl; |
| 252 | - if (m_obs.size() > 1) | |
| 253 | - log.header1("Bin observations"); | |
| 254 | - else | |
| 255 | - log.header1("Bin observation"); | |
| 263 | + if (m_obs.size() > 1) { | |
| 264 | + log.header1("Map observations"); | |
| 265 | + } | |
| 266 | + else { | |
| 267 | + log.header1("Map observation"); | |
| 268 | + } | |
| 256 | 269 | } |
| 257 | 270 | |
| 258 | 271 | // Loop over all observation in the container |
| ... | ... | @@ -264,30 +277,45 @@ void ctskymap::run(void) |
| 264 | 277 | // Continue only if observation is a CTA observation |
| 265 | 278 | if (obs != NULL) { |
| 266 | 279 | |
| 267 | - // Write header for observation | |
| 280 | + // Write header for current observation | |
| 268 | 281 | if (logTerse()) { |
| 269 | - if (obs->name().length() > 1) | |
| 282 | + if (obs->name().length() > 1) { | |
| 270 | 283 | log.header3("Observation "+obs->name()); |
| 271 | - else | |
| 284 | + } | |
| 285 | + else { | |
| 272 | 286 | log.header3("Observation"); |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + // If this is the first valid observation we're working on | |
| 291 | + // then initialise the sky maps | |
| 292 | + if (num_obs == 0) { | |
| 293 | + init_map(obs); | |
| 273 | 294 | } |
| 274 | 295 | |
| 275 | 296 | // Map events into sky map |
| 276 | 297 | map_events(obs); |
| 298 | + | |
| 299 | + // Increment observation counter | |
| 300 | + num_obs++; | |
| 277 | 301 | |
| 278 | 302 | } // endif: CTA observation found |
| 279 | 303 | |
| 280 | 304 | } // endfor: looped over observations |
| 281 | 305 | |
| 282 | 306 | // Write observation(s) into logger |
| 307 | +/* | |
| 283 | 308 | if (logTerse()) { |
| 284 | 309 | log << std::endl; |
| 285 | - if (m_obs.size() > 1) | |
| 286 | - log.header1("Binned observations"); | |
| 287 | - else | |
| 288 | - log.header1("Binned observation"); | |
| 310 | + if (m_obs.size() > 1) { | |
| 311 | + log.header1("Map observations"); | |
| 312 | + } | |
| 313 | + else { | |
| 314 | + log.header1("Map observation"); | |
| 315 | + } | |
| 289 | 316 | log << m_obs << std::endl; |
| 290 | 317 | } |
| 318 | +*/ | |
| 291 | 319 | |
| 292 | 320 | // Return |
| 293 | 321 | return; |
| ... | ... | @@ -301,45 +329,18 @@ void ctskymap::run(void) |
| 301 | 329 | ***************************************************************************/ |
| 302 | 330 | void ctskymap::save(void) |
| 303 | 331 | { |
| 304 | -/* | |
| 305 | 332 | // Write header |
| 306 | 333 | if (logTerse()) { |
| 307 | 334 | log << std::endl; |
| 308 | - if (m_obs.size() > 1) | |
| 309 | - log.header1("Save observations"); | |
| 310 | - else | |
| 311 | - log.header1("Save observation"); | |
| 335 | + log.header1("Save sky map"); | |
| 312 | 336 | } |
| 313 | 337 | |
| 314 | 338 | // Get output filename |
| 315 | 339 | m_outfile = (*this)["outfile"].filename(); |
| 316 | 340 | |
| 317 | - // Loop over all observations in the container | |
| 318 | - int file_num = 0; | |
| 319 | - for (int i = 0; i < m_obs.size(); ++i) { | |
| 320 | - | |
| 321 | - // Get CTA observation | |
| 322 | - GCTAObservation* obs = dynamic_cast<GCTAObservation*>(&m_obs[i]); | |
| 323 | - | |
| 324 | - // Save only if observation is a CTA observation | |
| 325 | - if (obs != NULL) { | |
| 341 | + // Save sky map | |
| 342 | + m_skymap.save(m_outfile, clobber()); | |
| 326 | 343 | |
| 327 | - // Set filename. If more than one file will be created an | |
| 328 | - // index "_xxx" will be appended. | |
| 329 | - std::string filename = m_outfile; | |
| 330 | - if (file_num > 0) | |
| 331 | - filename += "_"+str(file_num); | |
| 332 | - | |
| 333 | - // Save file | |
| 334 | - obs->save(filename, clobber()); | |
| 335 | - | |
| 336 | - // Increment file number | |
| 337 | - file_num++; | |
| 338 | - | |
| 339 | - } // endif: observation was a CTA observation | |
| 340 | - | |
| 341 | - } // endfor: looped over files | |
| 342 | -*/ | |
| 343 | 344 | // Return |
| 344 | 345 | return; |
| 345 | 346 | } |
| ... | ... | @@ -392,6 +393,60 @@ void ctskymap::get_parameters(void) |
| 392 | 393 | |
| 393 | 394 | |
| 394 | 395 | /***********************************************************************//** |
| 396 | + * @brief Initialise sky map | |
| 397 | + * | |
| 398 | + * @param[in] obs CTA observation (no NULL pointer allowed). | |
| 399 | + * | |
| 400 | + * @exception GCTAException::no_pointing | |
| 401 | + * No valid CTA pointing found. | |
| 402 | + * | |
| 403 | + * This method initialises the sky map. | |
| 404 | + ***************************************************************************/ | |
| 405 | +void ctskymap::init_map(GCTAObservation* obs) | |
| 406 | +{ | |
| 407 | + // Clear any existing sky map | |
| 408 | + m_skymap.clear(); | |
| 409 | + | |
| 410 | + // Get map centre. If no centre is specified then extract the map centre | |
| 411 | + // from the pointing direction. This obviously only works for | |
| 412 | + double xref; | |
| 413 | + double yref; | |
| 414 | + if (m_xref != 9999.0 && m_yref != 9999.0) { | |
| 415 | + xref = m_xref; | |
| 416 | + yref = m_yref; | |
| 417 | + } | |
| 418 | + else { | |
| 419 | + | |
| 420 | + | |
| 421 | + // Get pointer on CTA pointing | |
| 422 | + const GTime srcTime; // Dummy time | |
| 423 | + const GCTAPointing *pnt = obs->pointing(srcTime); | |
| 424 | + if (pnt == NULL) { | |
| 425 | + throw GCTAException::no_pointing(G_INIT_MAP); | |
| 426 | + } | |
| 427 | + | |
| 428 | + // Set reference point to pointing | |
| 429 | + if (toupper(m_coordsys) == "GAL") { | |
| 430 | + xref = pnt->dir().l_deg(); | |
| 431 | + yref = pnt->dir().b_deg(); | |
| 432 | + } | |
| 433 | + else { | |
| 434 | + xref = pnt->dir().ra_deg(); | |
| 435 | + yref = pnt->dir().dec_deg(); | |
| 436 | + } | |
| 437 | + | |
| 438 | + } // endelse: map centre set to pointing | |
| 439 | + | |
| 440 | + // Create skymap | |
| 441 | + m_skymap = GSkymap(m_proj, m_coordsys, xref, yref, m_binsz, m_binsz, | |
| 442 | + m_nxpix, m_nypix, 1); | |
| 443 | + | |
| 444 | + // Return | |
| 445 | + return; | |
| 446 | +} | |
| 447 | + | |
| 448 | + | |
| 449 | +/***********************************************************************//** | |
| 395 | 450 | * @brief Map events into a sky map |
| 396 | 451 | * |
| 397 | 452 | * @param[in] obs CTA observation. |
| ... | ... | @@ -421,38 +476,6 @@ void ctskymap::map_events(GCTAObservation* obs) |
| 421 | 476 | emin.TeV(m_emin); |
| 422 | 477 | emax.TeV(m_emax); |
| 423 | 478 | |
| 424 | - // Get map centre | |
| 425 | - double xref; | |
| 426 | - double yref; | |
| 427 | - if (m_xref != 9999.0 && m_yref != 9999.0) { | |
| 428 | - xref = m_xref; | |
| 429 | - yref = m_yref; | |
| 430 | - } | |
| 431 | - else { | |
| 432 | - | |
| 433 | - // Get pointer on CTA pointing | |
| 434 | - const GTime srcTime; // Dummy time | |
| 435 | - const GCTAPointing *pnt = obs->pointing(srcTime); | |
| 436 | - if (pnt == NULL) | |
| 437 | - throw GCTAException::no_pointing(G_BIN_EVENTS); | |
| 438 | - | |
| 439 | - // Set reference point to pointing | |
| 440 | - if (toupper(m_coordsys) == "GAL") { | |
| 441 | - xref = pnt->dir().l_deg(); | |
| 442 | - yref = pnt->dir().b_deg(); | |
| 443 | - } | |
| 444 | - else { | |
| 445 | - xref = pnt->dir().ra_deg(); | |
| 446 | - yref = pnt->dir().dec_deg(); | |
| 447 | - } | |
| 448 | - | |
| 449 | - } // endelse: map centre set to pointing | |
| 450 | - | |
| 451 | - // Create skymap | |
| 452 | - GSkymap map = GSkymap(m_proj, m_coordsys, | |
| 453 | - xref, yref, m_binsz, m_binsz, | |
| 454 | - m_nxpix, m_nypix, 1); | |
| 455 | - | |
| 456 | 479 | // Initialise binning statistics |
| 457 | 480 | int num_outside_map = 0; |
| 458 | 481 | int num_outside_erange = 0; |
| ... | ... | @@ -471,7 +494,7 @@ void ctskymap::map_events(GCTAObservation* obs) |
| 471 | 494 | // Determine sky pixel |
| 472 | 495 | GCTAInstDir* inst = (GCTAInstDir*)&(event->dir()); |
| 473 | 496 | GSkyDir dir = inst->skydir(); |
| 474 | - GSkyPixel pixel = map.dir2xy(dir); | |
| 497 | + GSkyPixel pixel = m_skymap.dir2xy(dir); | |
| 475 | 498 | |
| 476 | 499 | // Skip if pixel is out of range |
| 477 | 500 | if (pixel.x() < -0.5 || pixel.x() > (m_nxpix-0.5) || |
| ... | ... | @@ -481,7 +504,7 @@ void ctskymap::map_events(GCTAObservation* obs) |
| 481 | 504 | } |
| 482 | 505 | |
| 483 | 506 | // Fill event in skymap |
| 484 | - map(pixel) += 1.0; | |
| 507 | + m_skymap(pixel, 0) += 1.0; | |
| 485 | 508 | num_in_map++; |
| 486 | 509 | |
| 487 | 510 | } // endfor: looped over all events |
| ... | ... | @@ -504,7 +527,7 @@ void ctskymap::map_events(GCTAObservation* obs) |
| 504 | 527 | if (logTerse()) { |
| 505 | 528 | log << std::endl; |
| 506 | 529 | log.header1("Sky map"); |
| 507 | - log << map << std::endl; | |
| 530 | + log << m_skymap << std::endl; | |
| 508 | 531 | } |
| 509 | 532 | |
| 510 | 533 | } // endif: observation was valid |
| ... | ... | @@ -531,6 +554,7 @@ void ctskymap::init_members(void) |
| 531 | 554 | m_proj.clear(); |
| 532 | 555 | m_coordsys.clear(); |
| 533 | 556 | m_obs.clear(); |
| 557 | + m_skymap.clear(); | |
| 534 | 558 | m_emin = 0.0; |
| 535 | 559 | m_emax = 0.0; |
| 536 | 560 | m_xref = 9999.0; // Flags unset (use pointing direction) |
| ... | ... | @@ -560,6 +584,7 @@ void ctskymap::copy_members(const ctskymap& app) |
| 560 | 584 | m_proj = app.m_proj; |
| 561 | 585 | m_coordsys = app.m_coordsys; |
| 562 | 586 | m_obs = app.m_obs; |
| 587 | + m_skymap = app.m_skymap; | |
| 563 | 588 | m_emin = app.m_emin; |
| 564 | 589 | m_emax = app.m_emax; |
| 565 | 590 | m_xref = app.m_xref; | ... | ... |
src/ctskymap/ctskymap.hpp
| ... | ... | @@ -62,6 +62,7 @@ public: |
| 62 | 62 | void save(void); |
| 63 | 63 | GObservations& obs(void) { return m_obs; } |
| 64 | 64 | void get_parameters(void); |
| 65 | + void init_map(GCTAObservation* obs); | |
| 65 | 66 | void map_events(GCTAObservation* obs); |
| 66 | 67 | |
| 67 | 68 | protected: |
| ... | ... | @@ -85,6 +86,7 @@ protected: |
| 85 | 86 | |
| 86 | 87 | // Protected members |
| 87 | 88 | GObservations m_obs; //!< Observation container |
| 89 | + GSkymap m_skymap; //!< Sky map | |
| 88 | 90 | }; |
| 89 | 91 | |
| 90 | 92 | #endif /* CTSKYMAP_HPP */ | ... | ... |