| 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): Antonio Stamerra 02/2003 <mailto:antonio.stamerra@pi.infn.it>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2003
|
|---|
| 21 | !
|
|---|
| 22 | ! Filter to select events with a energy slope. 02/2003
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | // //
|
|---|
| 28 | // MFEnergySlope //
|
|---|
| 29 | // //
|
|---|
| 30 | // A filter to select MC events (generated with a energy slope MCSlope) //
|
|---|
| 31 | // with a different energy slope NewSlope set by the user. //
|
|---|
| 32 | // //
|
|---|
| 33 | // The new slope is set by the user with SetSlope(). //
|
|---|
| 34 | // Only negative slopes are admitted; positive ones are internally //
|
|---|
| 35 | // converted. //
|
|---|
| 36 | // Events are selected following the new energy power slope, and the //
|
|---|
| 37 | // sample is normalized to the number of events at: //
|
|---|
| 38 | // 1. McMaxEnergy, if abs(NewSlope) < abs(McSlope); //
|
|---|
| 39 | // 2. McMinEnergy, if abs(NewSlope) > abs(McSlope); //
|
|---|
| 40 | // Mc{Max,Min}Energy are set with SetMcMinEnergy() and SetMcMaxEnergy(); //
|
|---|
| 41 | // with GeV values. //
|
|---|
| 42 | // Default values are the min/max energy of the MC sample. //
|
|---|
| 43 | // //
|
|---|
| 44 | // With this filter the statistics of the MC sample is reduced. //
|
|---|
| 45 | // camera ver.0.6 and reflector ver.0.6 are required to fetch //
|
|---|
| 46 | // the correct MC information //
|
|---|
| 47 | // //
|
|---|
| 48 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 49 | #include "MFEnergySlope.h"
|
|---|
| 50 |
|
|---|
| 51 | //#include <fstream.h>
|
|---|
| 52 | #include <TRandom.h>
|
|---|
| 53 |
|
|---|
| 54 | #include "MParList.h"
|
|---|
| 55 |
|
|---|
| 56 | #include "MLog.h"
|
|---|
| 57 | #include "MLogManip.h"
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | #include "MMcEvt.hxx"
|
|---|
| 61 | #include "MMcCorsikaRunHeader.h"
|
|---|
| 62 |
|
|---|
| 63 | ClassImp(MFEnergySlope);
|
|---|
| 64 |
|
|---|
| 65 | // --------------------------------------------------------------------------
|
|---|
| 66 | //
|
|---|
| 67 | // Constructor
|
|---|
| 68 | //
|
|---|
| 69 | MFEnergySlope::MFEnergySlope(const char *name, const char *title):
|
|---|
| 70 | fNumSelectedEvts(0), fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
|
|---|
| 71 | {
|
|---|
| 72 | // fContName = cname;
|
|---|
| 73 | fName = name ? name : "MFEnergySlope";
|
|---|
| 74 | fTitle = title ? title : "Filter to select energy with given slope";
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | // --------------------------------------------------------------------------
|
|---|
| 78 | //
|
|---|
| 79 | // Destructor
|
|---|
| 80 | //
|
|---|
| 81 | MFEnergySlope::~MFEnergySlope()
|
|---|
| 82 | {
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | // --------------------------------------------------------------------------
|
|---|
| 86 | //
|
|---|
| 87 | // Preprocess
|
|---|
| 88 | //
|
|---|
| 89 | // MC slope and min/max energy are read
|
|---|
| 90 | // Normalization factor is computed
|
|---|
| 91 | //
|
|---|
| 92 | Bool_t MFEnergySlope::PreProcess(MParList *pList)
|
|---|
| 93 | {
|
|---|
| 94 |
|
|---|
| 95 | MMcCorsikaRunHeader *runheader = (MMcCorsikaRunHeader*)pList->FindObject("MMcCorsikaRunHeader");
|
|---|
| 96 |
|
|---|
| 97 | if (!runheader)
|
|---|
| 98 | {
|
|---|
| 99 | *fLog << err << dbginf << fName << " [MMcCorsikaRunHeader] not found... aborting." << endl;
|
|---|
| 100 | return kFALSE;
|
|---|
| 101 | }
|
|---|
| 102 | //
|
|---|
| 103 | // Read info from the MC sample (it must be generated with
|
|---|
| 104 | // reflector ver.0.6 and camera ver. 0.6)
|
|---|
| 105 | //
|
|---|
| 106 | fMcSlope = runheader->GetSlopeSpec();
|
|---|
| 107 | if (fMcMinEnergy<0)
|
|---|
| 108 | fMcMinEnergy = runheader->GetELowLim();
|
|---|
| 109 | if (fMcMinEnergy<0)
|
|---|
| 110 | fMcMaxEnergy = runheader->GetEUppLim();
|
|---|
| 111 |
|
|---|
| 112 | *fLog << "MFEnergySlope::PreProcess; fetched MC info:" << endl <<
|
|---|
| 113 | " E Slope: "<< fMcSlope << endl <<
|
|---|
| 114 | " E Min: "<< fMcMinEnergy << endl <<
|
|---|
| 115 | " E Max: "<< fMcMaxEnergy << endl <<
|
|---|
| 116 | " New E Slope: "<< fNewSlope << endl;
|
|---|
| 117 |
|
|---|
| 118 | // Slope is used with positive values in the code
|
|---|
| 119 | if (fNewSlope < 0)
|
|---|
| 120 | fNewSlope *= -1;
|
|---|
| 121 | if (fMcSlope < 0)
|
|---|
| 122 | fMcSlope *= -1;
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 | // Set normalization on energy
|
|---|
| 126 | fN0 = pow(fNewSlope>fMcSlope?fMcMinEnergy:fMcMaxEnergy,fNewSlope-fMcSlope);
|
|---|
| 127 |
|
|---|
| 128 | *fLog << "Normalization factor:" <<fN0 << endl;
|
|---|
| 129 |
|
|---|
| 130 | //---
|
|---|
| 131 | fEvt = (MMcEvt*)pList->FindObject("MMcEvt");
|
|---|
| 132 | if (!fEvt)
|
|---|
| 133 | {
|
|---|
| 134 | *fLog << err << dbginf << fName << " [MMcEvt] not found... aborting." << endl;
|
|---|
| 135 | return kFALSE;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | return kTRUE;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | // --------------------------------------------------------------------------
|
|---|
| 142 | //
|
|---|
| 143 | // Select events randomly according to the MC ("old") and required ("new")
|
|---|
| 144 | // energy slope.
|
|---|
| 145 | // Old E slope is fMcSlope
|
|---|
| 146 | // New E slope is set by the user (fval; fNewSlope)
|
|---|
| 147 | // If old and new energy slope are the same skip the selection.
|
|---|
| 148 | // The MC energy slope and lower and upper limits are taken from the
|
|---|
| 149 | // run header (requires reflector ver.>0.6 and camera ver.>0.6)
|
|---|
| 150 | //
|
|---|
| 151 | Bool_t MFEnergySlope::Process()
|
|---|
| 152 | {
|
|---|
| 153 | fResult = kTRUE;
|
|---|
| 154 |
|
|---|
| 155 | // Energy slopes are the same: skip it
|
|---|
| 156 | if (fNewSlope == fMcSlope)
|
|---|
| 157 | return kTRUE;
|
|---|
| 158 |
|
|---|
| 159 | // The value of the normalized spectrum is compared with a
|
|---|
| 160 | // random value in [0,1];
|
|---|
| 161 | // if the latter is higher the event is accepted
|
|---|
| 162 | const Float_t energy = fEvt->GetEnergy();
|
|---|
| 163 |
|
|---|
| 164 | /*
|
|---|
| 165 | //
|
|---|
| 166 | // If energy bounds different from MC ones are selected, then
|
|---|
| 167 | // events outside these bounds are rejected, as their slope has
|
|---|
| 168 | // not been changed.
|
|---|
| 169 | //
|
|---|
| 170 | if (energy > fMcMaxEnergy || energy < fMcMinEnergy)
|
|---|
| 171 | {
|
|---|
| 172 | fResult = kFALSE;
|
|---|
| 173 | return kTRUE;
|
|---|
| 174 | }
|
|---|
| 175 | */
|
|---|
| 176 |
|
|---|
| 177 | const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
|
|---|
| 178 | const Float_t Nrnd = gRandom->Uniform();
|
|---|
| 179 |
|
|---|
| 180 | fResult = Nexp > Nrnd;
|
|---|
| 181 |
|
|---|
| 182 | if (fResult)
|
|---|
| 183 | {
|
|---|
| 184 | fNumSelectedEvts++;
|
|---|
| 185 | return kTRUE;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | return kTRUE;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 | // --------------------------------------------------------------------------
|
|---|
| 193 | //
|
|---|
| 194 | // Postprocess all filters.
|
|---|
| 195 | //
|
|---|
| 196 | Bool_t MFEnergySlope::PostProcess()
|
|---|
| 197 | {
|
|---|
| 198 | //---------------------------------
|
|---|
| 199 |
|
|---|
| 200 | return kTRUE;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | void MFEnergySlope::StreamPrimitive(ofstream &out) const
|
|---|
| 204 | {
|
|---|
| 205 | /*
|
|---|
| 206 | if (fEvt)
|
|---|
| 207 | fEvt->SavePrimitive(out);
|
|---|
| 208 |
|
|---|
| 209 | out << " MFEnergySlope " << GetUniqueName() << "(";
|
|---|
| 210 |
|
|---|
| 211 | if (fEvt)
|
|---|
| 212 | out << "&" << fEvt->GetUniqueName();
|
|---|
| 213 | else
|
|---|
| 214 | out << "\"" << fContName << "\"";
|
|---|
| 215 |
|
|---|
| 216 | out << ", New Energy Slope= " << fValue << " Normalization factor: "
|
|---|
| 217 | << fN0 <<" );" << endl;
|
|---|
| 218 | */
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|