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 #include "NtupleReader/NtupleReaderFast.h"
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
00035 #include "MyZTauTauAnalysis/MyZTauTauAnalysis.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 using namespace std;
00050
00051
00052
00053
00054
00055
00056 void help(const char *argv0) {
00057
00058 cerr << "Usage: " << argv0 << " [options] <cut_values file> <infile> <outfile>"<< endl
00059 << " <infile> can be <textfile>.txt or <rootfile>.root " << endl
00060 << "Options:" << endl
00061 << "-o <path>:\tWrite outputfile in directory <path>" << endl
00062 << "-a <addon>:\tWrite outputfile as filename_<addon>.root" << endl
00063 << "-e <events>:\tRun analysis on <events> events" << endl
00064 << "-s <events>:\tSkip the first <events> events" << endl
00065 << "-i:\t\tQuit when outputfile already exits" << endl
00066 << "-h:\t\tShow this message and quit." << endl;
00067 exit(0);
00068 }
00069
00070
00071
00072
00073
00074
00075 int main(int argc, char * argv[]) {
00076
00077
00078
00079
00080
00081 cout<<"argc "<<argc<<endl;
00082
00083 extern char *optarg;
00084
00085 char c;
00086 string infile(""), outputpath(""), addon(""), outfile("");
00087 string settingsFile("");
00088 bool overwrite(true);
00089 int nb_events(-1);
00090 int first_event(0);
00091
00092 while((c = getopt(argc, argv, "-hio:a:e:s:")) !=-1)
00093 {
00094
00095 switch(c)
00096 {
00097 case 'i':
00098 {
00099 overwrite = false;
00100 break;
00101 }
00102 case 'o':
00103 {
00104 outputpath = optarg;
00105 break;
00106 }
00107 case 'a':
00108 {
00109 addon = optarg;
00110 break;
00111 }
00112 case 'e':
00113 {
00114 nb_events = atoi(optarg);
00115 break;
00116 }
00117 case 's':
00118 {
00119 first_event = atoi(optarg);
00120 break;
00121 }
00122 case 1:
00123 {
00124 if(settingsFile==""){
00125 settingsFile = optarg;
00126 }
00127 else if(infile==""){
00128 infile = optarg;
00129 }
00130 else{
00131 outfile = optarg;
00132 }
00133 break;
00134 }
00135 default:
00136 cerr << "Help or unknown argument!" << endl;
00137 help(argv[0]);
00138 break;
00139 }
00140
00141 }
00142 if(infile=="" || outfile==""){
00143 cerr<<"Provide a infile and a outfile"<<endl;
00144 help(argv[0]);
00145 exit(1);
00146 }
00147
00148 cout << endl
00149 << "command line arguments: " << endl
00150 << " outputpath: " << outputpath << endl
00151 << " cut_values: " << settingsFile << endl
00152 << " infile: " << infile << endl
00153 << " outfile: " << outfile << endl
00154 << " addon: " << addon << endl
00155 << " nb_events: " << nb_events << endl
00156 << " first event: " << first_event << endl
00157 << " overwrite: " << overwrite << endl
00158 << endl;
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 MyZTauTauAnalysis my_analysis;
00170
00171
00172 string sdummy;
00173 vector<string> filename;
00174
00175
00176
00177
00178
00179
00180 if(TString(infile).Contains(".root")){
00181
00182 filename.push_back(infile);
00183 }
00184 else if(TString(infile).Contains(".txt")){
00185
00186 ifstream settings_file(infile.c_str());
00187 if (settings_file.fail()) {
00188 cerr << endl
00189 << "ERROR: Could not open file " << infile << endl
00190 << endl;
00191 return 1;
00192 }
00193
00194
00195
00196
00197
00198 while (!settings_file.eof()) {
00199 settings_file >> sdummy;
00200 if (settings_file.eof()) {
00201 break;
00202 }
00203 filename.push_back(sdummy);
00204 }
00205
00206 }else{
00207 cerr << endl
00208 << "ERROR: could not read inputfile " << infile << "," << endl
00209 << " please provide '.root' or '.txt' file." << endl
00210 << endl;
00211 return 1;
00212 }
00213
00214
00215
00216
00217
00218
00219 TFile testfile(filename[0].c_str());
00220
00221 TTree* Colltree = (TTree*)testfile.Get("CollectionTree");
00222 TTree* CBNTtree = (TTree*)testfile.Get("CBNT/T3333");
00223 TTree* Fasttree = (TTree*)testfile.Get("FastTree");
00224
00225 bool CBNT_flag = false;
00226
00227 if(Colltree!=NULL && CBNTtree==NULL && Fasttree==NULL){
00228 CBNT_flag = false;
00229 }
00230 else if(Colltree!=NULL && CBNTtree==NULL && Fasttree!=NULL){
00231 CBNT_flag = true;
00232 }
00233 else if(Colltree==NULL && CBNTtree!=NULL){
00234 CBNT_flag = true;
00235 }
00236 else{
00237 cerr << endl
00238 << "ERROR: could not read tree" << endl
00239 << " please provide 'CollectionTree' or 'CBNT/T3333'." << endl
00240 << endl;
00241 return 1;
00242 }
00243
00244 testfile.Close();
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 my_analysis.filename = outfile;
00258 my_analysis.settingsFilename = settingsFile;
00259
00260
00261
00262
00263
00264 if(!CBNT_flag){
00265 cout<<"NtupleReader "<<endl;
00266 NtupleReader reader(filename, string("CollectionTree"), &my_analysis);
00267 reader.event_loop(nb_events, first_event);
00268 }
00269
00270
00271
00272
00273
00274
00275
00276 return 0;
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
00361
00362
00363
00364
00365
00366
00367 }