siscone is hosted by Hepforge, IPPP Durham

The SISCone Jet Algorithm

Version 3.0.6



SISCone 3.0.6
options.cpp
1
2// File: options.cpp //
3// Description: management of the cmdline options of the main program //
4// This file is part of the SISCone project. //
5// For more details, see http://projects.hepforge.org/siscone //
6// //
7// Copyright (c) 2006 Gavin Salam and Gregory Soyez //
8// //
9// This program is free software; you can redistribute it and/or modify //
10// it under the terms of the GNU General Public License as published by //
11// the Free Software Foundation; either version 2 of the License, or //
12// (at your option) any later version. //
13// //
14// This program is distributed in the hope that it will be useful, //
15// but WITHOUT ANY WARRANTY; without even the implied warranty of //
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
17// GNU General Public License for more details. //
18// //
19// You should have received a copy of the GNU General Public License //
20// along with this program; if not, write to the Free Software //
21// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
22// //
23// $Revision:: $//
24// $Date:: $//
26
27#include "options.h"
28#include <string.h>
29#include <getopt.h>
30#include <iostream>
31
32using namespace std;
33using namespace siscone;
34
35#define N_DEFAULT -1
36#define R_DEFAULT 0.7
37#define THRESHOLD_DEFAULT 0.5
38#define PTMIN_DEFAULT 0.0
39#define NPASS_DEFAULT 0
40#define DEFAULT_EVENT "events/single-event.dat"
41#define SM_DEFAULT SM_pttilde
42
43/*******************************************
44 * Coptions implementation *
45 * options for the 'cone' sample *
46 *******************************************/
47
48// default ctor
49//--------------
51 // set default flags values
52 help_flag=0;
55
56 // set default options values
57 N_stop = N_DEFAULT;
58 R = R_DEFAULT;
59 f = THRESHOLD_DEFAULT;
60 npass = NPASS_DEFAULT;
61 ev_name = NULL;
62 SM_var = SM_DEFAULT;
63}
64
65
66// default dtor
67//--------------
69 if (ev_name!=NULL)
70 delete[] ev_name;
71}
72
73
74// parse oprions
75// - argc number of arguments from the command line
76// - argv arguments from the command line
77// return 1 on error, 0 on success
78//---------------------------------
79int Coptions::parse_options(int argc, char **argv){
80 int opt_param;
81 int option_index;
82 bool stop=false;
83
84 // browse the command-line options{
85 static struct option siscone_options[]={
86 // options that set a flag
87 {"verbose", no_argument, &verbose_flag, 1},
88 {"quiet", no_argument, &verbose_flag, 0},
89 {"help", no_argument, &help_flag , 1},
90 {"version", no_argument, &version_flag, 1},
91 // options setting parameters
92 {"number", required_argument, NULL, 'N'},
93 {"radius", required_argument, NULL, 'R'},
94 {"fraction", required_argument, NULL, 'f'},
95 {"ptmin", required_argument, NULL, 'p'},
96 {"npass", required_argument, NULL, 'n'},
97 {"event", required_argument, NULL, 'e'},
98 {"sm", required_argument, NULL, 's'},
99 {0,0,0,0}
100 };
101
102
103 do{
104 // getopt_long stores the option index here.
105 option_index=0;
106
107 // retreive options
108 opt_param = getopt_long(argc, argv, "hvqN:R:f:p:n:e:s:",
109 siscone_options, &option_index);
110
111 // Detect the end of the options.
112 if (opt_param == -1)
113 stop=true;
114
115 // branch according to 'opt_param'
116 switch (opt_param){
117 case 'h': help_flag = 1; break; // help
118 case 'v': verbose_flag = 1; break; // verbose
119 case 'q': verbose_flag = 0; break; // quiet
120 case 'N': // max number of paprticles
121 sscanf(optarg, "%d", &N_stop);
122 if (N_stop<=0){
123 cout << "Warning: the specified number of particles must be positive. Using default one" << endl;
124 N_stop = N_DEFAULT;
125 }
126 break;
127 case 'R':
128 sscanf(optarg, "%lf", &R);
129 if (R<=0){
130 cout << "Warning: the specified cone radius must be positive. Using default one" << endl;
131 R = R_DEFAULT;
132 }
133 break;
134 case 'f':
135 sscanf(optarg, "%lf", &f);
136 if ((f<0) || (f>1)){
137 cout << "Warning: the specified split/merge threshold must be in [0,1]. Using default one" << endl;
138 f = THRESHOLD_DEFAULT;
139 }
140 break;
141 case 'p':
142 sscanf(optarg, "%lf", &ptmin);
143 if (ptmin<0){
144 cout << "Warning: the specified minimal pT must be non-negative. Using default one" << endl;
145 ptmin = PTMIN_DEFAULT;
146 }
147 break;
148 case 'n': // max number of paprticles
149 sscanf(optarg, "%d", &npass);
150 if (npass<0){
151 cout << "Warning: the specified number of passes must be non negative. Using default one" << endl;
152 npass = NPASS_DEFAULT;
153 }
154 break;
155 case 'e':
156 if (ev_name==NULL){
157 ev_name = new char[strlen(optarg)+1];
158 strcpy(ev_name, optarg);
159 }
160 break;
161 case 's':
162 char tmp[512];
163 strcpy(tmp, optarg);
164 if (strcmp(tmp, "pttilde")==0){
165 SM_var = SM_pttilde;
166 } else if (strcmp(tmp, "mt")==0){
167 SM_var = SM_mt;
168 } else if (strcmp(tmp, "pt")==0){
169 SM_var = SM_pt;
170 } else if (strcmp(tmp, "Et")==0){
171 SM_var = SM_Et;
172 } else {
173 cout << "Warning: the specified varible for split--merge is not valid (should be pttilde, pt, mt or Et). Using pttilde as the default one." << endl;
174 SM_var = SM_pttilde;
175 }
176 break;
177 case 0:
178 case -1:
179 break;
180 case '?':
181 fprintf(stderr, "Giving up.\n");
182 return 1;
183 break;
184 default:
185 if (!help_flag){
186 fprintf(stderr, "unrecognized option %c. Giving up.\n", opt_param);
187 return 1;
188 }
189 }
190 } while (!stop);
191
192 if (ev_name==NULL){
193 ev_name = new char[strlen(DEFAULT_EVENT)+1];
194 strcpy(ev_name, DEFAULT_EVENT);
195 }
196
197 return 0;
198}
199
200
201// print the help message
202//------------------------
204 cout << siscone_package_name() << " " << siscone_version() << endl;
205 cout << "Usage: " << siscone_package_name() << " <args>" << endl;
206 cout << endl;
207 cout << "Here is an exhaustive list of the arguments:" << endl;
208 cout << "Parameters control (with default values):" << endl;
209 cout << " -n <val>, --number=<val> : set the maximum number of particles allowed (all)" << endl;
210 cout << " -R <val>, --radius=<val> : set the radius (" << R_DEFAULT << ")" << endl;
211 cout << " -f <val>, --fraction=<val>: set the overlap parameter (" << THRESHOLD_DEFAULT << ")" << endl;
212 cout << " -p <val>, --ptmin=<val> : set the minimal pT for protojets (" << PTMIN_DEFAULT << ")" << endl;
213 cout << " -n <val>, --npass=<val> : set the maximal number of passes (0 for no limit) (" << NPASS_DEFAULT << ")" << endl;
214 cout << " -e <val>, --event=<val> : set the event filename (" << DEFAULT_EVENT << ")" << endl;
215 cout << " -s <val>, --sm=<val> : variable for split--merge: pttilde, mt, pt or Et (pttilde)" << endl;
216 cout << endl;
217 cout << "Output flags" << endl;
218 cout << " --version : show version information" << endl;
219 cout << " -h, --help : show this message" << endl;
220 cout << " -v, --verbose: be verbose (on by default)" << endl;
221 cout << " -q, --quiet : be quiet" << endl;
222 cout << endl;
223
224 return 0;
225}
226
227
228// print program version
229//-----------------------
231 cout << siscone_package_name() << " " << siscone_version() << endl;
232 cout << "Copyright (C) 2006." << endl;
233 cout << siscone_package_name() << " comes with NO WARRANTY," << endl;
234 cout << "to the extent permitted by law." << endl;
235 cout << "You may redistribute copies of " << siscone_package_name() << endl;
236 cout << "under the terms of the GNU General Public License." << endl;
237 cout << "For more information about these matters," << endl;
238 cout << "see the files named COPYING." << endl;
239 cout << "Please send bugs or comments to AUTHORS" << endl;
240
241 return 0;
242}
int print_version()
print program version
Definition: options.cpp:230
char * ev_name
event to read
Definition: options.h:67
int parse_options(int argc, char **argv)
parse oprions
Definition: options.cpp:79
double R
cone radius
Definition: options.h:64
int verbose_flag
do we need to print the help message
Definition: options.h:60
siscone::Esplit_merge_scale SM_var
variable for split-merge
Definition: options.h:71
~Coptions()
default dtor
Definition: options.cpp:68
int print_help()
print the help message
Definition: options.cpp:203
int help_flag
do we need to print the help message
Definition: options.h:58
int npass
number of passes (0 for \infty)
Definition: options.h:68
Coptions()
default ctor
Definition: options.cpp:50
double ptmin
minimal pT for jet candidates
Definition: options.h:66
int version_flag
do we need to print the version description
Definition: options.h:59
double f
split/merge threshold
Definition: options.h:65
int N_stop
maximum number of particle
Definition: options.h:63

The SISCone project has been developed by Gavin Salam and Gregory Soyez
Documentation generated on Tue Jun 20 2023 18:08:37 for SISCone by  Doxygen 1.9.4