Fork me on GitHub

source: git/examples/ExternalFastJetBasic.cpp@ 8e602e5

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 8e602e5 was 8e602e5, checked in by Michele Selvaggi <michele.selvaggi@…>, 10 years ago

move all cards from examples to cards directory, add ExternalFastJetBasic, rename StandaloneHepMC to ExternalFastJetHepMC

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Delphes: a framework for fast simulation of a generic collider experiment
3 * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdexcept>
20#include <iostream>
21#include <sstream>
22
23#include <stdio.h>
24
25#include "TROOT.h"
26#include "TApplication.h"
27
28#include "TFile.h"
29#include "TObjArray.h"
30#include "TDatabasePDG.h"
31#include "TParticlePDG.h"
32#include "TLorentzVector.h"
33
34#include "modules/Delphes.h"
35#include "classes/DelphesClasses.h"
36#include "classes/DelphesFactory.h"
37
38#include "ExRootAnalysis/ExRootTreeWriter.h"
39#include "ExRootAnalysis/ExRootTreeBranch.h"
40#include "ExRootAnalysis/ExRootProgressBar.h"
41
42#include "fastjet/PseudoJet.hh"
43#include "fastjet/JetDefinition.hh"
44#include "fastjet/ClusterSequence.hh"
45
46using namespace std;
47using namespace fastjet;
48
49//---------------------------------------------------------------------------
50
51const int NEVENTS = 2;
52const int NPARTICLES = 4;
53
54float EVENTS[NEVENTS][NPARTICLES][11] =
55{
56 {
57 {-211, 1, -2.91e-01, 1.99e-01, -1.30e+00, 1.35e+00, 1.3957e-01, 0.0, 0.0, 0.0, 0.0},
58 { 211, 1, -2.62e-02, 1.90e-01, 1.42e+00, 1.44e+00, 1.3957e-01, 0.0, 0.0, 0.0, 0.0},
59 {-211, 1, -3.08e-02, -2.30e-01, 5.13e+00, 5.14e+00, 1.3957e-01, 0.0, 0.0, 0.0, 0.0},
60 { 211, 1, 1.21e-01, -3.52e-01, 2.12e+01, 2.12e+01, 1.3957e-01, 0.0, 0.0, 0.0, 0.0}
61 },
62 {
63 {22, 1, -7.80e-02, -9.70e-02, 2.03e+01, 2.03e+01, 0.0, 0.0, 0.0, 0.0, 0.0},
64 {22, 1, -1.16e-02, -2.08e-02, 4.89e-01, 4.90e-01, 0.0, 0.0, 0.0, 0.0, 0.0},
65 {22, 1, 5.64e-02, -1.34e-02, 5.81e+00, 5.82e+00, 0.0, 0.0, 0.0, 0.0, 0.0},
66 {22, 1, 2.35e-01, -1.04e-01, 9.12e+00, 9.12e+00, 0.0, 0.0, 0.0, 0.0, 0.0}
67 }
68};
69
70//---------------------------------------------------------------------------
71
72void ConvertInput(Int_t event, DelphesFactory *factory, TObjArray *allParticleOutputArray, TObjArray *stableParticleOutputArray, TObjArray *partonOutputArray);
73
74int main(int argc, char *argv[])
75{
76 // Declaration of variables
77 ExRootConfReader *confReader = 0;
78 Delphes *modularDelphes = 0;
79 DelphesFactory *factory = 0;
80 TObjArray *allParticleOutputArray = 0;
81 TObjArray *stableParticleOutputArray = 0;
82 TObjArray *partonOutputArray = 0;
83
84 Int_t event;
85
86 TObjArray *inputArray = 0;
87 TIterator *inputIterator = 0;
88 Candidate *candidate = 0;
89 TLorentzVector momentum;
90
91 JetDefinition *definition = 0;
92 vector<PseudoJet> inputList, outputList;
93 PseudoJet jet;
94
95 gROOT->SetBatch();
96
97 int appargc = 1;
98 char appName[] = "ExternalFastJetBasic";
99 char *appargv[] = {appName};
100 TApplication app(appName, &appargc, appargv);
101
102 if(argc != 2)
103 {
104 cout << " Usage: " << appName << " config_file" << endl;
105 cout << " config_file - configuration file in Tcl format." << endl;
106 return 1;
107 }
108
109 try
110 {
111 // Initialization
112 confReader = new ExRootConfReader;
113 confReader->ReadFile(argv[1]);
114
115 modularDelphes = new Delphes("Delphes");
116 modularDelphes->SetConfReader(confReader);
117
118 factory = modularDelphes->GetFactory();
119
120 allParticleOutputArray = modularDelphes->ExportArray("allParticles");
121 stableParticleOutputArray = modularDelphes->ExportArray("stableParticles");
122 partonOutputArray = modularDelphes->ExportArray("partons");
123
124 modularDelphes->InitTask();
125
126 ClusterSequence::print_banner();
127 definition = new JetDefinition(antikt_algorithm, 0.5);
128
129 inputArray = modularDelphes->ImportArray("Calorimeter/towers");
130 inputIterator = inputArray->MakeIterator();
131
132 // Event loop
133 for(event = 0; event < NEVENTS; ++event)
134 {
135 modularDelphes->Clear();
136 ConvertInput(event, factory, allParticleOutputArray, stableParticleOutputArray, partonOutputArray);
137 modularDelphes->ProcessTask();
138
139 inputList.clear();
140 inputIterator->Reset();
141 while((candidate = static_cast<Candidate*>(inputIterator->Next())))
142 {
143 momentum = candidate->Momentum;
144 jet = PseudoJet(momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
145 inputList.push_back(jet);
146 }
147 ClusterSequence sequence(inputList, *definition);
148 outputList.clear();
149 outputList = sorted_by_pt(sequence.inclusive_jets(0.0));
150
151 // tell the user what was done
152 // - the description of the algorithm used
153 // - show the inclusive jets as
154 // {index, rapidity, phi, pt}
155 //----------------------------------------------------------
156 cout << "Ran " << definition->description() << endl;
157
158 // label the columns
159 printf("%5s %15s %15s %15s\n","jet #", "rapidity", "phi", "pt");
160
161 // print out the details for each jet
162 for (unsigned int i = 0; i < outputList.size(); i++) {
163 printf("%5u %15.8f %15.8f %15.8f\n",
164 i, outputList[i].rap(), outputList[i].phi(),
165 outputList[i].perp());
166 }
167 }
168
169 // Finalization
170 modularDelphes->FinishTask();
171 delete modularDelphes;
172 delete confReader;
173 return 0;
174 }
175 catch(runtime_error &e)
176 {
177 cerr << "** ERROR: " << e.what() << endl;
178 return 1;
179 }
180}
181
182void ConvertInput(Int_t event, DelphesFactory *factory, TObjArray *allParticleOutputArray, TObjArray *stableParticleOutputArray, TObjArray *partonOutputArray)
183{
184 Int_t particle;
185
186 Candidate *candidate;
187 TDatabasePDG *pdg;
188 TParticlePDG *pdgParticle;
189 Int_t pdgCode;
190
191 Int_t pid, status;
192 Double_t px, py, pz, e, mass;
193 Double_t x, y, z, t;
194
195 pdg = TDatabasePDG::Instance();
196
197 for(particle = 0; particle < NPARTICLES; ++particle)
198 {
199 pid = EVENTS[event][particle][0];
200 status = EVENTS[event][particle][1];
201 px = EVENTS[event][particle][2];
202 py = EVENTS[event][particle][3];
203 pz = EVENTS[event][particle][4];
204 e = EVENTS[event][particle][5];
205 mass = EVENTS[event][particle][6];
206 x = EVENTS[event][particle][7];
207 y = EVENTS[event][particle][8];
208 z = EVENTS[event][particle][9];
209 t = EVENTS[event][particle][10];
210
211 candidate = factory->NewCandidate();
212
213 candidate->PID = pid;
214 pdgCode = TMath::Abs(candidate->PID);
215
216 candidate->Status = status;
217
218 pdgParticle = pdg->GetParticle(pid);
219 candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
220 candidate->Mass = mass;
221
222 candidate->Momentum.SetPxPyPzE(px, py, pz, e);
223
224 candidate->Position.SetXYZT(x, y, z, t);
225
226 allParticleOutputArray->Add(candidate);
227
228 if(!pdgParticle) return;
229
230 if(status == 1)
231 {
232 stableParticleOutputArray->Add(candidate);
233 }
234 else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
235 {
236 partonOutputArray->Add(candidate);
237 }
238 }
239}
240
Note: See TracBrowser for help on using the repository browser.