00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <iostream>
00015 #include <fstream>
00016
00017
00018 #include <string>
00019 #include <vector>
00020
00021
00022 #include "NtupleReader/NtupleReader.h"
00023
00024 #include "NtupleReader/MyDatasetInfo.h"
00025 #include "NtupleReader/MyTrigger.h"
00026
00027
00028 #include "TSystem.h"
00029 #include "TObjString.h"
00030
00031
00032
00033
00034 #include "MyHtautauAnalysis/MyHtautauAnalysis.h"
00035
00036
00037
00038
00039
00040
00041 using namespace std;
00042
00043
00044
00045
00046
00047
00048 void help(const char *argv0) {
00049
00050 cerr << "Usage: " << argv0 << " [options] <cut_values file> <infile> <outfile>"<< endl
00051 << " <infile> can be <textfile>.txt or <rootfile>.root " << endl
00052 << "Options:" << endl
00053 << "-o <path>:\tWrite outputfile in directory <path>" << endl
00054 << "-a <addon>:\tWrite outputfile as filename_<addon>.root" << endl
00055 << "-e <events>:\tRun analysis on <events> events" << endl
00056 << "-s <events>:\tSkip the first <events> events" << endl
00057 << "-i:\t\tQuit when outputfile already exits" << endl
00058 << "-h:\t\tShow this message and quit." << endl;
00059 exit(0);
00060 }
00061
00062
00063
00064
00065
00066
00067 int main(int argc, char * argv[]) {
00068
00069
00070
00071
00072
00073 cout<<"argc "<<argc<<endl;
00074
00075 extern char *optarg;
00076
00077 char c;
00078 string infile(""), outputpath(""), addon(""), outfile("");
00079 string settingsFile("");
00080 bool overwrite(true);
00081 int nb_events(-1);
00082 int first_event(0);
00083
00084 while((c = getopt(argc, argv, "-hio:a:e:s:")) !=-1)
00085 {
00086
00087 switch(c)
00088 {
00089 case 'i':
00090 {
00091 overwrite = false;
00092 break;
00093 }
00094 case 'o':
00095 {
00096 outputpath = optarg;
00097 break;
00098 }
00099 case 'a':
00100 {
00101 addon = optarg;
00102 break;
00103 }
00104 case 'e':
00105 {
00106 nb_events = atoi(optarg);
00107 break;
00108 }
00109 case 's':
00110 {
00111 first_event = atoi(optarg);
00112 break;
00113 }
00114 case 1:
00115 {
00116 if(settingsFile==""){
00117 settingsFile = optarg;
00118 }
00119 else if(infile==""){
00120 infile = optarg;
00121 }
00122 else{
00123 outfile = optarg;
00124 }
00125 break;
00126 }
00127 default:
00128 cerr << "Help or unknown argument!" << endl;
00129 help(argv[0]);
00130 break;
00131 }
00132
00133 }
00134 if(infile=="" || outfile==""){
00135 cerr<<"Provide a infile and a outfile"<<endl;
00136 help(argv[0]);
00137 exit(1);
00138 }
00139
00140 cout << endl
00141 << "command line arguments: " << endl
00142 << " outputpath: " << outputpath << endl
00143 << " cut_values: " << settingsFile << endl
00144 << " infile: " << infile << endl
00145 << " outfile: " << outfile << endl
00146 << " addon: " << addon << endl
00147 << " nb_events: " << nb_events << endl
00148 << " first event: " << first_event << endl
00149 << " overwrite: " << overwrite << endl
00150 << endl;
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 MyHtautauAnalysis my_analysis;
00169
00170
00171 string sdummy;
00172 vector<string> filename;
00173
00174
00175
00176
00177
00178
00179 if(TString(infile).Contains(".root")){
00180
00181 filename.push_back(infile);
00182 }
00183 else if(TString(infile).Contains(".txt")){
00184
00185 ifstream settings_file(infile.c_str());
00186 if (settings_file.fail()) {
00187 cerr << endl
00188 << "ERROR: Could not open file " << infile << endl
00189 << endl;
00190 return 1;
00191 }
00192
00193
00194
00195
00196
00197 while (!settings_file.eof()) {
00198 settings_file >> sdummy;
00199 if (settings_file.eof()) {
00200 break;
00201 }
00202 filename.push_back(sdummy);
00203 }
00204
00205 }else{
00206 cerr << endl
00207 << "ERROR: could not read inputfile " << infile << "," << endl
00208 << " please provide '.root' or '.txt' file." << endl
00209 << endl;
00210 return 1;
00211 }
00212
00213
00214
00215
00216
00217
00218 TFile testfile(filename[0].c_str());
00219
00220 TTree* Colltree = (TTree*)testfile.Get("CollectionTree");
00221 TTree* CBNTtree = (TTree*)testfile.Get("CBNT/T3333");
00222
00223 bool CBNT_flag = false;
00224
00225 if(Colltree!=NULL && CBNTtree==NULL){
00226 CBNT_flag = false;
00227 }
00228 else if(Colltree==NULL && CBNTtree!=NULL){
00229 CBNT_flag = true;
00230 }
00231 else{
00232 cerr << endl
00233 << "ERROR: could not read tree" << endl
00234 << " please provide 'CollectionTree' or 'CBNT/T3333'." << endl
00235 << endl;
00236 return 1;
00237 }
00238
00239 testfile.Close();
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 my_analysis.filename = outfile;
00253 my_analysis.settingsFilename = settingsFile;
00254
00255
00256
00257
00258
00259 if(!CBNT_flag){
00260 NtupleReader reader(filename, string("CollectionTree"), &my_analysis);
00261 reader.event_loop(nb_events, first_event);
00262 }
00263 else{
00264
00265
00266 }
00267
00268
00269 return 0;
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 }