Fork me on GitHub

source: svn/trunk/Examples/Analysis_Ex.cpp@ 108

Last change on this file since 108 was 84, checked in by uid677, 16 years ago

add output tree to example

File size: 3.5 KB
RevLine 
[81]1#include <iostream>
2#include <fstream>
3#include <utility>
4#include <vector>
5
6#include "TTree.h"
7#include "TBranch.h"
8#include "TLeaf.h"
9#include "TString.h"
10#include "TApplication.h"
11#include "TLorentzVector.h"
12#include "TRandom.h"
13
14#include <string>
15
16#include "Utilities/ExRootAnalysis/interface/ExRootTreeReader.h"
17#include "Utilities/ExRootAnalysis/interface/ExRootTreeWriter.h"
18#include "Utilities/ExRootAnalysis/interface/ExRootTreeBranch.h"
19
20#include "Utilities/ExRootAnalysis/interface/BlockClasses.h"
21#include "Utilities/ExRootAnalysis/interface/TSimpleArray.h"
22
23#include "Examples/interface/Analysis_Ex.h"
24
25#include <time.h>
26
27using namespace std;
28
29//------------------------------------------------------------------------------
30
31int main(int argc, char *argv[])
32{
33 int appargc = 2;
34 char *appargv[] = {"Analysis_Ex", "-b"};
35 TApplication app("Analysis_Ex", &appargc, appargv);
36
37 if(argc !=3)
38 {
39 cout << " Usage: " << argv[0] << " input_file" << " [runs_list]" << endl;
40 cout << " input_list - list of files in Delphe ROOT format ('GEN, Analysis and Trigger ' trees )," << endl;
41 cout << " output file - name of the output analysis root file." << endl;
42 exit(1);
43 }
44
45 //*****************************************************************************
46 //************************Input files to the analysis**************************
47 //*****************************************************************************
48 TString inputFileList(argv[1]);
49 string buffer;
50 TChain chainGen("GEN");//generator level information
51 TChain chainRec("Analysis");//reconstructed level infomration
52 TChain chainTrig("Trigger");//trigger information
53
54 //run on the input file list of Delphe ROOT files
55 ifstream infile(inputFileList);
56 if(!infile.is_open())
57 {
58 cerr << "** ERROR: Can't open '" << inputFileList << "' for input" << endl;
59 exit(1);
60 }
61 while(1)
62 {
63 infile >> buffer;
64 if(!infile.good()) break;
65 chainGen.Add(buffer.c_str());
66 chainRec.Add(buffer.c_str());
67 chainTrig.Add(buffer.c_str());
68 }
69
70
71 //*****************************************************************************
72 //*********************Output root file of the analysis************************
73 //*****************************************************************************
74 ExRootTreeReader *treeReaderGen = new ExRootTreeReader(&chainGen);
75 ExRootTreeReader *treeReaderRec = new ExRootTreeReader(&chainRec);
76 ExRootTreeReader *treeReaderTrig = new ExRootTreeReader(&chainTrig);
77
78 //create output file containing selection information
79 string forLog = argv[2];
80 string LogName = forLog.erase(forLog.find(".root"));
81 LogName = LogName+"_cut.txt";
82 ofstream f_out(LogName.c_str(),ofstream::app);
83
[84]84 //create the output tree
85 string outputfilename = argv[2];
86 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
87 outputFile->Close();
88
89 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
90
[81]91 //*****************************************************************************
92 //***************************Run the analysis**********************************
93 //*****************************************************************************
94
95 Analysis_Ex *DefaultOne = new Analysis_Ex("Examples/Datacard_Analysis_Ex.dat",LogName);
[84]96 DefaultOne->Run(treeReaderGen,treeReaderRec,treeReaderTrig,treeWriter);
[81]97 DefaultOne->WriteOutput(LogName);
98 delete DefaultOne;
99
100 cout << "** Exiting..." << endl;
101 delete treeReaderGen;
102 delete treeReaderRec;
103 delete treeReaderTrig;
104}
105
Note: See TracBrowser for help on using the repository browser.