| 57 | |
| 58 | and here is its implementation: |
| 59 | |
| 60 | {{{ |
| 61 | |
| 62 | #include "modules/ExampleModule.h" |
| 63 | |
| 64 | #include "ExRootAnalysis/ExRootResult.h" |
| 65 | #include "ExRootAnalysis/ExRootClasses.h" |
| 66 | |
| 67 | #include "ExRootAnalysis/ExRootFilter.h" |
| 68 | #include "ExRootAnalysis/ExRootClassifier.h" |
| 69 | |
| 70 | #include "ExRootAnalysis/ExRootFactory.h" |
| 71 | #include "ExRootAnalysis/ExRootCandidate.h" |
| 72 | |
| 73 | #include "TMath.h" |
| 74 | #include "TRandom.h" |
| 75 | #include "TString.h" |
| 76 | #include "TFormula.h" |
| 77 | #include "TLorentzVector.h" |
| 78 | #include "TDatabasePDG.h" |
| 79 | #include "TClonesArray.h" |
| 80 | |
| 81 | #include <iostream> |
| 82 | #include <stdexcept> |
| 83 | #include <sstream> |
| 84 | #include <deque> |
| 85 | |
| 86 | using namespace std; |
| 87 | |
| 88 | //------------------------------------------------------------------------------ |
| 89 | |
| 90 | ExampleModule::ExampleModule() : |
| 91 | fFormula(0), fItInputArray(0) |
| 92 | { |
| 93 | fFormula = new TFormula; |
| 94 | } |
| 95 | |
| 96 | //------------------------------------------------------------------------------ |
| 97 | |
| 98 | ExampleModule::~ExampleModule() |
| 99 | { |
| 100 | if(fFormula) delete fFormula; |
| 101 | } |
| 102 | |
| 103 | //------------------------------------------------------------------------------ |
| 104 | |
| 105 | void ExampleModule::Init() |
| 106 | { |
| 107 | fIntParam = GetInt("IntParam", 10); |
| 108 | |
| 109 | fDoubleParam = GetDouble("DoubleParam", 1.0); |
| 110 | |
| 111 | fFormula->Compile(GetString("EfficiencyFormula", "0.4")); |
| 112 | |
| 113 | ExRootConfParam param = GetParam("ArrayParam"); |
| 114 | Long_t i, size; |
| 115 | fArrayParam.clear(); |
| 116 | |
| 117 | size = param.GetSize(); |
| 118 | for(i = 0; i < size; ++i) |
| 119 | { |
| 120 | fArrayParam.push_back(param[i].GetDouble()); |
| 121 | } |
| 122 | |
| 123 | // import input array(s) |
| 124 | |
| 125 | fInputArray = ImportArray(GetString("InputArray", "FastJetFinder/jets")); |
| 126 | fItInputArray = fInputArray->MakeIterator(); |
| 127 | |
| 128 | // create output array(s) |
| 129 | |
| 130 | fOutputArray = ExportArray(GetString("OutputArray", "jets")); |
| 131 | |
| 132 | } |
| 133 | |
| 134 | //------------------------------------------------------------------------------ |
| 135 | |
| 136 | void ExampleModule::Finish() |
| 137 | { |
| 138 | if(fItInputArray) delete fItInputArray; |
| 139 | } |
| 140 | |
| 141 | //------------------------------------------------------------------------------ |
| 142 | |
| 143 | void ExampleModule::Process() |
| 144 | { |
| 145 | ExRootCandidate *candidate; |
| 146 | TLorentzVector candidatePosition, candidateMomentum; |
| 147 | |
| 148 | // loop over all input candidates |
| 149 | fItInputArray->Reset(); |
| 150 | while((candidate = static_cast<ExRootCandidate*>(fItInputArray->Next()))) |
| 151 | { |
| 152 | candidatePosition = candidate->GetPosition(); |
| 153 | candidateMomentum = candidate->GetMomentum(); |
| 154 | |
| 155 | // apply an efficency formula |
| 156 | if(gRandom->Uniform() < fFormula->Eval(candidatePosition.Eta(), candidateMomentum.Pt())) |
| 157 | { |
| 158 | fOutputArray->Add(candidate); |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | }}} |