1 | /*
|
---|
2 | ======================================================================== *\
|
---|
3 | !
|
---|
4 | ! *
|
---|
5 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
6 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
7 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
8 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
9 | ! *
|
---|
10 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
11 | ! * documentation for any purpose is hereby granted without fee,
|
---|
12 | ! * provided that the above copyright notice appear in all copies and
|
---|
13 | ! * that both that copyright notice and this permission notice appear
|
---|
14 | ! * in supporting documentation. It is provided "as is" without express
|
---|
15 | ! * or implied warranty.
|
---|
16 | ! *
|
---|
17 | !
|
---|
18 | !
|
---|
19 | ! Author(s): Nicola Galante 02/2005 <mailto:nicola.galante@pi.infn.it>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2004
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MApplySupercuts
|
---|
28 | //
|
---|
29 | // Apply supercuts to a file containing Hillas parameters
|
---|
30 | // (usually a star file).
|
---|
31 | //
|
---|
32 | // Input:
|
---|
33 | // rootfile (starfile) of Hillas parameters
|
---|
34 | //
|
---|
35 | // Output:
|
---|
36 | // MHadronness estimated on event
|
---|
37 | //
|
---|
38 | /////////////////////////////////////////////////////////////////////////////
|
---|
39 | #include <TMath.h>
|
---|
40 | #include <TFile.h>
|
---|
41 | #include <TH1F.h>
|
---|
42 | #include <TCanvas.h>
|
---|
43 |
|
---|
44 | #include "MGeomCamMagic.h"
|
---|
45 | #include "MLog.h"
|
---|
46 | #include "MLogManip.h"
|
---|
47 | #include "MParList.h"
|
---|
48 | #include "MRawEvtHeader.h"
|
---|
49 | #include "MRawRunHeader.h"
|
---|
50 | #include "MSupercuts.h"
|
---|
51 | #include "MHadronness.h"
|
---|
52 | #include "MHillas.h"
|
---|
53 | #include "MHillasSrc.h"
|
---|
54 | #include "MHFindSignificance.h"
|
---|
55 | #include "MEnergyEst.h"
|
---|
56 | #include "MApplySupercuts.h"
|
---|
57 |
|
---|
58 | ClassImp(MApplySupercuts);
|
---|
59 |
|
---|
60 | using namespace std;
|
---|
61 |
|
---|
62 | // --------------------------------------------------------------------------
|
---|
63 | //
|
---|
64 | // Default constructor
|
---|
65 | //
|
---|
66 | MApplySupercuts::MApplySupercuts(const char *name, const char *title)
|
---|
67 | : fRunHeader(0), fEvtHeader(0), fSupercuts(0)
|
---|
68 | {
|
---|
69 | fName = name ? name : "MApplySupercuts";
|
---|
70 | fTitle = title ? title : "Task to apply supercuts to star files";
|
---|
71 |
|
---|
72 | fPhe = kTRUE;
|
---|
73 | fPlot = kFALSE;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | // --------------------------------------------------------------------------
|
---|
78 | //
|
---|
79 | Int_t MApplySupercuts::PreProcess(MParList *pList)
|
---|
80 | {
|
---|
81 | fGeom = (MGeomCamMagic *)pList->FindCreateObj("MGeomCamMagic");
|
---|
82 | if (!fGeom)
|
---|
83 | {
|
---|
84 | *fLog << err << "MGeomCamMagic not found... abort." << endl;
|
---|
85 | return kFALSE;
|
---|
86 | }
|
---|
87 |
|
---|
88 | fRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
|
---|
89 | if (!fRunHeader)
|
---|
90 | {
|
---|
91 | *fLog << err << "MRawRunHeader not found... abort." << endl;
|
---|
92 | return kFALSE;
|
---|
93 | }
|
---|
94 |
|
---|
95 | fEvtHeader = (MRawEvtHeader *)pList->FindObject("MRawEvtHeader");
|
---|
96 | if (!fEvtHeader)
|
---|
97 | {
|
---|
98 | *fLog << err << "MRawEvtHeader not found... but ok." << endl;
|
---|
99 | }
|
---|
100 |
|
---|
101 | fHillas = (MHillas *)pList->FindObject("MHillas");
|
---|
102 | if (!fHillas)
|
---|
103 | {
|
---|
104 | *fLog << err << "MHillas not found... abort." << endl;
|
---|
105 | return kFALSE;
|
---|
106 | }
|
---|
107 |
|
---|
108 | fHillasSrc = (MHillasSrc *)pList->FindObject("MHillasSrc");
|
---|
109 | if (!fHillasSrc)
|
---|
110 | {
|
---|
111 | *fLog << err << "MHillasSrc not found... abort." << endl;
|
---|
112 | return kFALSE;
|
---|
113 | }
|
---|
114 |
|
---|
115 | fHadronness = (MHadronness *)pList->FindCreateObj("MHadronness",AddSerialNumber("MHadronness"));
|
---|
116 | if (!fHadronness)
|
---|
117 | {
|
---|
118 | *fLog << err << "MHadronness not found... abort." << endl;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 |
|
---|
122 | fEnergyEst = (MEnergyEst *)pList->FindCreateObj("MEnergyEst");
|
---|
123 | if (!fEnergyEst)
|
---|
124 | {
|
---|
125 | *fLog << err << "MEnergyEst not found... abort." << endl;
|
---|
126 | return kFALSE;
|
---|
127 | }
|
---|
128 |
|
---|
129 | if(fPlot){
|
---|
130 | fAlpha = new TH1F("fHistAlpha","Alpha Plot",30,0,90);
|
---|
131 | if (!fAlpha)
|
---|
132 | {
|
---|
133 | *fLog << err << "Impossible to create Alpha histogram... abort." << endl;
|
---|
134 | return kFALSE;
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | fHFindSigma = (MHFindSignificance *)pList->FindCreateObj("MHFindSignificance");
|
---|
139 | if (!fHFindSigma)
|
---|
140 | {
|
---|
141 | *fLog << err << "MHFindSignificance not found... abort." << endl;
|
---|
142 | return kFALSE;
|
---|
143 | }
|
---|
144 |
|
---|
145 | // Start reading supercuts
|
---|
146 | fSupercuts = (MSupercuts *)pList->FindCreateObj("MSupercuts",AddSerialNumber("MSupercuts"));
|
---|
147 | if (!fSupercuts)
|
---|
148 | {
|
---|
149 | *fLog << err << "MSupercuts not found... abort." << endl;
|
---|
150 | return kFALSE;
|
---|
151 | }
|
---|
152 | // read the cuts coefficients
|
---|
153 | TFile inparam(fSCFilename);
|
---|
154 | fSupercuts->Read("MSupercuts");
|
---|
155 | inparam.Close();
|
---|
156 | *fLog << "MFindSupercutsONOFF::FindParams; initial values of parameters are taken from file "
|
---|
157 | << fSCFilename << endl;
|
---|
158 |
|
---|
159 | TArrayD params = fSupercuts->GetParameters();
|
---|
160 |
|
---|
161 | for (Int_t i=0; i<8; i++)
|
---|
162 | {
|
---|
163 | fLengthUp[i] = params[i];
|
---|
164 | fLengthLo[i] = params[i+8];
|
---|
165 | fWidthUp[i] = params[i+16];
|
---|
166 | fWidthLo[i] = params[i+24];
|
---|
167 | fDistUp[i] = params[i+32];
|
---|
168 | fDistLo[i] = params[i+40];
|
---|
169 | }
|
---|
170 |
|
---|
171 | // end reading supercuts
|
---|
172 | return kTRUE;
|
---|
173 | }
|
---|
174 |
|
---|
175 | // --------------------------------------------------------------------------
|
---|
176 | //
|
---|
177 | Int_t MApplySupercuts::Process()
|
---|
178 | {
|
---|
179 | fHadronness->SetHadronness(kHadronHadronness);
|
---|
180 |
|
---|
181 | Float_t fMm2Deg = fGeom->GetConvMm2Deg();
|
---|
182 | Double_t log3000 = TMath::Log(fSizeOffset);
|
---|
183 | Float_t fsize = fHillas->GetSize();
|
---|
184 | if(fPhe)
|
---|
185 | fsize /= kPhe2Ph;
|
---|
186 | Float_t fdist = fHillasSrc->GetDist()*fMm2Deg;
|
---|
187 | Double_t logsize = TMath::Log((Double_t)fsize);
|
---|
188 | Double_t lgsize = logsize-log3000;
|
---|
189 | Double_t lgsize2 = lgsize*lgsize;
|
---|
190 | Double_t dist2 = (Double_t)fdist*fdist - fDistOffset*fDistOffset;
|
---|
191 | //Double_t dist2 = (fDist-fDistOffset)*(fDist-fDistOffset);
|
---|
192 |
|
---|
193 | // parameters:
|
---|
194 | Float_t flength = (fHillas->GetLength()) * fMm2Deg;
|
---|
195 | Float_t fwidth = (fHillas->GetWidth())*fMm2Deg;
|
---|
196 | //Float_t fsize = fHillas.GetSize()/0.18;
|
---|
197 | //Float_t fmeanx = (fHillas.GetMeanX())*fMm2Deg;
|
---|
198 | //Float_t fmeany = (fHillas.GetMeanY())*fMm2Deg;
|
---|
199 | //Float_t falpha = fHillasSrc.GetAlpha();
|
---|
200 | //Float_t fDCAdelta = fHillasSrc.GetDCADelta();
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 | if ( flength < CalcLimit(fLengthUp, lgsize, lgsize2, dist2) &&
|
---|
205 | flength > CalcLimit(fLengthLo, lgsize, lgsize2, dist2) &&
|
---|
206 | fwidth < CalcLimit(fWidthUp, lgsize, lgsize2, dist2) &&
|
---|
207 | fwidth > CalcLimit(fWidthLo, lgsize, lgsize2, dist2) &&
|
---|
208 | fdist < CalcLimit(fDistUp, lgsize, lgsize2, dist2) &&
|
---|
209 | fdist > CalcLimit(fDistLo, lgsize, lgsize2, dist2) )
|
---|
210 | {
|
---|
211 | // gamma candidates!
|
---|
212 | fHadronness->SetHadronness(kGammaHadronness);
|
---|
213 | if( fPlot && fHillas->GetSize()>fSizeLow && fHillas->GetSize()<fSizeUp )
|
---|
214 | fAlpha->Fill(TMath::Floor(TMath::Abs(fHillasSrc->GetAlpha())));
|
---|
215 | }
|
---|
216 |
|
---|
217 | return kTRUE;
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | Int_t MApplySupercuts::PostProcess()
|
---|
222 | {
|
---|
223 | if(fPlot){
|
---|
224 | TFile f("shit_file.root","RECREATE");
|
---|
225 | fAlpha->Write();
|
---|
226 | f.Close();
|
---|
227 | TCanvas c;
|
---|
228 | if(fHFindSigma!=NULL){
|
---|
229 | cout << "W el cogno " << fAlphaSignal <<endl;
|
---|
230 | fHFindSigma->FindSigma((TH1 *)fAlpha,fAlphaMin,fAlphaMax,fDegree,fAlphaSignal,kTRUE,kTRUE,kTRUE);
|
---|
231 | *fLog << "SIGNIFICANCE = " << fHFindSigma->GetSignificance() << endl;
|
---|
232 | c.SaveAs("Alpha.gif");
|
---|
233 | }
|
---|
234 | else
|
---|
235 | *fLog << err << "ERROR: fHFindSigma already deleted" << endl;
|
---|
236 | }
|
---|
237 | return kTRUE;
|
---|
238 | }
|
---|
239 |
|
---|
240 |
|
---|
241 | Double_t MApplySupercuts::CalcLimit(Double_t *a, Double_t ls, Double_t ls2, Double_t dd2)
|
---|
242 | {
|
---|
243 |
|
---|
244 | Double_t limit = a[0] + a[1] * dd2 +
|
---|
245 | ls * (a[3] + a[4] * dd2) +
|
---|
246 | ls2 * (a[6] + a[7] * dd2);
|
---|
247 |
|
---|
248 | return limit;
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 | void MApplySupercuts::SetPrintOutSignificance(Double_t bgalphamin=50.0, Double_t bgalphamax=90.0,
|
---|
253 | Double_t alphasig=15.0, Int_t degree=4)
|
---|
254 | {
|
---|
255 | fAlphaMin = bgalphamin;
|
---|
256 | fAlphaMax = bgalphamax;
|
---|
257 | fDegree = degree;
|
---|
258 | fAlphaSignal = alphasig;
|
---|
259 |
|
---|
260 | fPlot = kTRUE;
|
---|
261 | }
|
---|
262 |
|
---|