Fork me on GitHub

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

Last change on this file since 300 was 272, checked in by Xavier Rouby, 16 years ago

memory-leak free

File size: 5.5 KB
RevLine 
[260]1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
6** \----------------------------------------------/ **
7** **
8** **
9** This package uses: **
10** ------------------ **
11** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] **
12** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] **
13** FROG: [hep-ex/0901.2718v1] **
14** **
15** ------------------------------------------------------------------ **
16** **
17** Main authors: **
18** ------------- **
19** **
20** Severine Ovyn Xavier Rouby **
21** severine.ovyn@uclouvain.be xavier.rouby@cern **
22** **
23** Center for Particle Physics and Phenomenology (CP3) **
24** Universite catholique de Louvain (UCL) **
25** Louvain-la-Neuve, Belgium **
26** **
27** Copyright (C) 2008-2009, **
28** All rights reserved. **
29** **
30***********************************************************************/
31
32
[81]33#include <iostream>
34#include <fstream>
35
36#include "TString.h"
37#include "TApplication.h"
[227]38#include "TChain.h"
39#include "TFile.h"
[81]40#include <string>
41
[227]42#include "ExRootTreeReader.h"
43#include "ExRootTreeWriter.h"
44#include "ExRootTreeBranch.h"
45#include "BlockClasses.h"
46#include "TSimpleArray.h"
[81]47
48#include "Examples/interface/Analysis_Ex.h"
49using namespace std;
50
51//------------------------------------------------------------------------------
52
53int main(int argc, char *argv[])
54{
55 int appargc = 2;
[272]56 char *appName= new char[20];
57 char *appOpt= new char[20];
58 sprintf(appName,"Analysis_Ex");
59 sprintf(appOpt,"-b");
60 char *appargv[] = {appName,appOpt};
61 TApplication app(appName, &appargc, appargv);
62 delete [] appName;
63 delete [] appOpt;
[81]64
65 if(argc !=3)
66 {
67 cout << " Usage: " << argv[0] << " input_file" << " [runs_list]" << endl;
68 cout << " input_list - list of files in Delphe ROOT format ('GEN, Analysis and Trigger ' trees )," << endl;
69 cout << " output file - name of the output analysis root file." << endl;
70 exit(1);
71 }
72
73 //*****************************************************************************
74 //************************Input files to the analysis**************************
75 //*****************************************************************************
76 TString inputFileList(argv[1]);
77 string buffer;
78 TChain chainGen("GEN");//generator level information
79 TChain chainRec("Analysis");//reconstructed level infomration
80 TChain chainTrig("Trigger");//trigger information
81
82 //run on the input file list of Delphe ROOT files
83 ifstream infile(inputFileList);
84 if(!infile.is_open())
85 {
86 cerr << "** ERROR: Can't open '" << inputFileList << "' for input" << endl;
87 exit(1);
88 }
89 while(1)
90 {
91 infile >> buffer;
92 if(!infile.good()) break;
93 chainGen.Add(buffer.c_str());
94 chainRec.Add(buffer.c_str());
95 chainTrig.Add(buffer.c_str());
96 }
97
98
99 //*****************************************************************************
100 //*********************Output root file of the analysis************************
101 //*****************************************************************************
102 ExRootTreeReader *treeReaderGen = new ExRootTreeReader(&chainGen);
103 ExRootTreeReader *treeReaderRec = new ExRootTreeReader(&chainRec);
104 ExRootTreeReader *treeReaderTrig = new ExRootTreeReader(&chainTrig);
105
106 //create output file containing selection information
107 string forLog = argv[2];
108 string LogName = forLog.erase(forLog.find(".root"));
109 LogName = LogName+"_cut.txt";
110 ofstream f_out(LogName.c_str(),ofstream::app);
111
[84]112 //create the output tree
113 string outputfilename = argv[2];
114 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
115 outputFile->Close();
116
117 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
118
[81]119 //*****************************************************************************
120 //***************************Run the analysis**********************************
121 //*****************************************************************************
122
123 Analysis_Ex *DefaultOne = new Analysis_Ex("Examples/Datacard_Analysis_Ex.dat",LogName);
[84]124 DefaultOne->Run(treeReaderGen,treeReaderRec,treeReaderTrig,treeWriter);
[81]125 DefaultOne->WriteOutput(LogName);
126 delete DefaultOne;
127
128 cout << "** Exiting..." << endl;
129 delete treeReaderGen;
130 delete treeReaderRec;
131 delete treeReaderTrig;
132}
133
Note: See TracBrowser for help on using the repository browser.