| 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, 12/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2003
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MHCamEvent
|
|---|
| 28 | //
|
|---|
| 29 | // A histogram to store the sum of camera events. This can be photons,
|
|---|
| 30 | // currents or enything else derived from MCamEvent
|
|---|
| 31 | //
|
|---|
| 32 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 33 | #include "MHCamEvent.h"
|
|---|
| 34 |
|
|---|
| 35 | #include <TCanvas.h>
|
|---|
| 36 |
|
|---|
| 37 | #include "MLog.h"
|
|---|
| 38 | #include "MLogManip.h"
|
|---|
| 39 |
|
|---|
| 40 | #include "MParList.h"
|
|---|
| 41 | #include "MCamEvent.h"
|
|---|
| 42 | #include "MHCamera.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "MGeomCam.h"
|
|---|
| 45 |
|
|---|
| 46 | ClassImp(MHCamEvent);
|
|---|
| 47 |
|
|---|
| 48 | using namespace std;
|
|---|
| 49 |
|
|---|
| 50 | // --------------------------------------------------------------------------
|
|---|
| 51 | //
|
|---|
| 52 | // Initialize the name and title of the task.
|
|---|
| 53 | // Resets the sum histogram
|
|---|
| 54 | //
|
|---|
| 55 | MHCamEvent::MHCamEvent(const char *name, const char *title)
|
|---|
| 56 | : fSum(NULL), fEvt(NULL), fType(0)
|
|---|
| 57 | {
|
|---|
| 58 | //
|
|---|
| 59 | // set the name and title of this object
|
|---|
| 60 | //
|
|---|
| 61 | fName = name ? name : "MHCamEvent";
|
|---|
| 62 | fTitle = title ? title : "Average of MCamEvents";
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | // --------------------------------------------------------------------------
|
|---|
| 66 | //
|
|---|
| 67 | // Delete the corresponding camera display if available
|
|---|
| 68 | //
|
|---|
| 69 | MHCamEvent::~MHCamEvent()
|
|---|
| 70 | {
|
|---|
| 71 | if (fSum)
|
|---|
| 72 | delete fSum;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // --------------------------------------------------------------------------
|
|---|
| 76 | //
|
|---|
| 77 | // Get the event (MCamEvent) the histogram might be filled with. If
|
|---|
| 78 | // it is not given, it is assumed, that it is filled with the argument
|
|---|
| 79 | // of the Fill function.
|
|---|
| 80 | // Looks for the camera geometry MGeomCam and resets the sum histogram.
|
|---|
| 81 | //
|
|---|
| 82 | Bool_t MHCamEvent::SetupFill(const MParList *plist)
|
|---|
| 83 | {
|
|---|
| 84 | fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
|
|---|
| 85 | if (!fEvt)
|
|---|
| 86 | {
|
|---|
| 87 | if (!fNameEvt.IsNull())
|
|---|
| 88 | {
|
|---|
| 89 | *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
|
|---|
| 90 | return kFALSE;
|
|---|
| 91 | }
|
|---|
| 92 | *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
|
|---|
| 96 | if (!cam)
|
|---|
| 97 | *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
|
|---|
| 98 |
|
|---|
| 99 | if (fSum)
|
|---|
| 100 | delete (fSum);
|
|---|
| 101 |
|
|---|
| 102 | const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
|
|---|
| 103 |
|
|---|
| 104 | fSum = new MHCamera(*cam, name+";avg", fTitle);
|
|---|
| 105 | fSum->SetYTitle("a.u.");
|
|---|
| 106 |
|
|---|
| 107 | return kTRUE;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // --------------------------------------------------------------------------
|
|---|
| 111 | //
|
|---|
| 112 | // Fill the histograms with data from a MCamEvent-Container.
|
|---|
| 113 | //
|
|---|
| 114 | Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
|
|---|
| 115 | {
|
|---|
| 116 | const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
|
|---|
| 117 | if (!evt)
|
|---|
| 118 | {
|
|---|
| 119 | *fLog << err << dbginf << "No MCamEvent found..." << endl;
|
|---|
| 120 | return kFALSE;
|
|---|
| 121 | }
|
|---|
| 122 | fSum->AddCamContent(*evt, fType);
|
|---|
| 123 |
|
|---|
| 124 | return kTRUE;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | // --------------------------------------------------------------------------
|
|---|
| 128 | //
|
|---|
| 129 | // Scale the sum container with the number of entries
|
|---|
| 130 | //
|
|---|
| 131 | Bool_t MHCamEvent::Finalize()
|
|---|
| 132 | {
|
|---|
| 133 | if (fSum->GetEntries()>0)
|
|---|
| 134 | fSum->Scale(1./fSum->GetEntries());
|
|---|
| 135 | return kTRUE;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | // --------------------------------------------------------------------------
|
|---|
| 139 | //
|
|---|
| 140 | // Return fSum.
|
|---|
| 141 | //
|
|---|
| 142 | TH1 *MHCamEvent::GetHistByName(const TString name)
|
|---|
| 143 | {
|
|---|
| 144 | return fSum;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | void MHCamEvent::Draw(Option_t *)
|
|---|
| 148 | {
|
|---|
| 149 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
|---|
| 150 | pad->SetBorderMode(0);
|
|---|
| 151 |
|
|---|
| 152 | pad->Divide(2,2);
|
|---|
| 153 |
|
|---|
| 154 | pad->cd(1);
|
|---|
| 155 | gPad->SetBorderMode(0);
|
|---|
| 156 | gPad->Divide(1,1);
|
|---|
| 157 | gPad->cd(1);
|
|---|
| 158 | gPad->SetBorderMode(0);
|
|---|
| 159 | fSum->Draw();
|
|---|
| 160 |
|
|---|
| 161 | pad->cd(3);
|
|---|
| 162 | gPad->SetBorderMode(0);
|
|---|
| 163 | fSum->Draw("EPhist");
|
|---|
| 164 | }
|
|---|