Fork me on GitHub

source: svn/trunk/Examples/Trigger_Only.cpp@ 330

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

memory leak free

File size: 4.9 KB
Line 
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/// \file Trigger_Only.cpp
33/// \brief executable for the Trigger running
34
35#include "TChain.h"
36#include "TApplication.h"
37
38#include "ExRootTreeReader.h"
39#include "ExRootTreeWriter.h"
40#include "ExRootTreeBranch.h"
41#include "TriggerUtil.h"
42#include "BlockClasses.h"
43
44#include <iostream>
45#include <vector>
46#include <fstream>
47#include <iomanip>
48
49
50using namespace std;
51
52int main(int argc, char *argv[])
53{
54 int appargc = 2;
55 char *appName= new char[20];
56 char *appOpt= new char[20];
57 sprintf(appName,"Trigger_Only");
58 sprintf(appOpt,"-b");
59 char *appargv[] = {appName,appOpt};
60 TApplication app(appName, &appargc, appargv);
61 delete [] appName;
62 delete [] appOpt;
63
64 if(argc != 2 && argc !=3 ) {
65 cout << " Usage: " << argv[0] << " input_file output_file [detector_card] [trigger_card] " << endl;
66 cout << " input_file - file in Delphe root format," << endl;
67 cout << " trigger_card - Datacard containing the trigger algorithms (optional) "<<endl;
68 exit(1);
69 }
70
71 srand (time (NULL)); /* Initialisation du générateur */
72
73 //read the input TROOT file
74 string inputFile(argv[1]);
75
76 //create output log-file name
77 string forLog = inputFile;
78 string LogName = forLog.erase(forLog.find(".root"));
79 LogName = LogName+"_run.log";
80
81 string line,buffer;
82 TChain chain("Analysis");
83 chain.Add(inputFile.c_str());
84 ExRootTreeReader *treeReaderT = new ExRootTreeReader(&chain);
85
86 //read the datacard input file
87 string TrigDatacard("");
88 if(argc==3) TrigDatacard =argv[2];
89
90 //Trigger information
91 TriggerTable *TRIGT = new TriggerTable();
92 TRIGT->TriggerCardReader(TrigDatacard.c_str());
93 TRIGT->PrintTriggerTable(LogName);
94
95 TClonesArray *branchElecTrig = treeReaderT->UseBranch("Electron");
96 TClonesArray *branchMuonTrig = treeReaderT->UseBranch("Muon");
97 TClonesArray *branchJetTrig = treeReaderT->UseBranch("Jet");
98 TClonesArray *branchTauJetTrig = treeReaderT->UseBranch("TauJet");
99 TClonesArray *branchPhotonTrig = treeReaderT->UseBranch("Photon");
100 TClonesArray *branchETmisTrig = treeReaderT->UseBranch("ETmis");
101
102 ExRootTreeWriter *treeWriterT = new ExRootTreeWriter(inputFile, "Trigger");
103 ExRootTreeBranch *branchTrigger = treeWriterT->NewBranch("TrigResult", TRootTrigger::Class());
104
105 Long64_t entryT, allEntriesT = treeReaderT->GetEntries();
106 cout << "** Chain contains " << allEntriesT << " events" << endl;
107 for(entryT = 0; entryT < allEntriesT; ++entryT)
108 {
109 treeWriterT->Clear();
110 treeReaderT->ReadEntry(entryT);
111 TRIGT->GetGlobalResult(branchElecTrig, branchMuonTrig,branchJetTrig, branchTauJetTrig,branchPhotonTrig, branchETmisTrig,branchTrigger);
112 treeWriterT->Fill();
113 }
114
115 treeWriterT->Write();
116 delete treeWriterT;
117
118 cout << "** Exiting..." << endl;
119
120 delete TRIGT;
121
122}
123
Note: See TracBrowser for help on using the repository browser.