source: HiSusy/trunk/Delphes-3.0.0/modules/Merger.cc @ 1

Last change on this file since 1 was 1, checked in by zerwas, 11 years ago

first import of structure, PYTHIA8 and DELPHES

File size: 3.4 KB
Line 
1
2/** \class Merger
3 *
4 *  Merges multiple input arrays into one output array
5 *  and sums transverse momenta of all input objects.
6 *
7 *  $Date: 2012-11-18 15:57:08 +0100 (Sun, 18 Nov 2012) $
8 *  $Revision: 814 $
9 *
10 *
11 *  \author P. Demin - UCL, Louvain-la-Neuve
12 *
13 */
14
15#include "modules/Merger.h"
16
17#include "classes/DelphesClasses.h"
18#include "classes/DelphesFactory.h"
19#include "classes/DelphesFormula.h"
20
21#include "ExRootAnalysis/ExRootResult.h"
22#include "ExRootAnalysis/ExRootFilter.h"
23#include "ExRootAnalysis/ExRootClassifier.h"
24
25#include "TMath.h"
26#include "TString.h"
27#include "TFormula.h"
28#include "TRandom3.h"
29#include "TObjArray.h"
30#include "TDatabasePDG.h"
31#include "TLorentzVector.h"
32
33#include <algorithm> 
34#include <stdexcept>
35#include <iostream>
36#include <sstream>
37
38using namespace std;
39
40//------------------------------------------------------------------------------
41
42Merger::Merger()
43{
44}
45
46//------------------------------------------------------------------------------
47
48Merger::~Merger()
49{
50}
51
52//------------------------------------------------------------------------------
53
54void Merger::Init()
55{
56  // import arrays with output from other modules
57
58  ExRootConfParam param = GetParam("InputArray");
59  Long_t i, size;
60  const TObjArray *array;
61  TIterator *iterator;
62  DelphesFormula *formula;
63
64  size = param.GetSize();
65  for(i = 0; i < size/2; ++i)
66  {
67    array = ImportArray(param[i*2].GetString());
68    iterator = array->MakeIterator();
69
70    formula = new DelphesFormula;
71    formula->Compile(param[i*2 + 1].GetString());
72
73    fInputMap[iterator] = formula;
74  }
75
76  // create output arrays
77
78  fOutputArray = ExportArray(GetString("OutputArray", "candidates"));
79
80  fMomentumOutputArray = ExportArray(GetString("MomentumOutputArray", "momentum"));
81}
82
83//------------------------------------------------------------------------------
84
85void Merger::Finish()
86{
87  map< TIterator *, DelphesFormula * >::iterator itInputMap;
88  TIterator *iterator;
89  DelphesFormula *formula;
90
91  for(itInputMap = fInputMap.begin(); itInputMap != fInputMap.end(); ++itInputMap)
92  {
93    iterator = itInputMap->first;
94    formula = itInputMap->second;
95
96    if(iterator) delete iterator;
97    if(formula) delete formula;
98  }
99}
100
101//------------------------------------------------------------------------------
102
103void Merger::Process()
104{
105  Candidate *candidate;
106  TLorentzVector momentum;
107  Double_t eta, pt; 
108  map< TIterator *, DelphesFormula * >::iterator itInputMap;
109  TIterator *iterator;
110  DelphesFormula *formula;
111 
112  DelphesFactory *factory = GetFactory();
113 
114  momentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
115
116  // loop over all input arrays
117  for(itInputMap = fInputMap.begin(); itInputMap != fInputMap.end(); ++itInputMap)
118  {
119    iterator = itInputMap->first;
120    formula = itInputMap->second;
121
122    // loop over all candidates
123    iterator->Reset();
124    while((candidate = static_cast<Candidate*>(iterator->Next())))
125    {
126      const TLorentzVector &candidatePosition = candidate->Position;
127      const TLorentzVector &candidateMomentum = candidate->Momentum;
128
129      eta = candidatePosition.Eta();
130      pt = candidateMomentum.Pt();
131
132      if(formula->Eval(pt, eta))
133      {
134        momentum += candidateMomentum;
135        fOutputArray->Add(candidate);
136      }
137    }
138  }
139
140  candidate = factory->NewCandidate();
141 
142  candidate->Position.SetXYZT(0.0, 0.0, 0.0, 0.0);
143  candidate->Momentum = momentum;
144 
145  fMomentumOutputArray->Add(candidate);
146}
147
148//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.