Fork me on GitHub

source: svn/trunk/src/LHCOConverter.cc@ 283

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

more things; not yet finished

File size: 7.4 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// local includes
33#include "LHCOConverter.h"
34#include "ExRootTreeReader.h"
35#include "BlockClasses.h"
36
37// root includes
38#include "TFile.h"
39#include "TChain.h"
40#include "TClonesArray.h"
41
42// c++ includes
43#include <iostream>
44#include <string>
45#include <fstream>
46#include <sstream>
47#include <iomanip>
48using namespace std;
49
50
51//------------------------------------------------------------------------------
52extern const float UNDEFINED;
53
54LHCOConverter::LHCOConverter(const string& inputroot, const string& inputlog):
55 inputfilename_(inputroot), inputlogname_(inputlog), outputfilename_(inputroot), valid_(true) {
56 if (inputfilename_ == "") {valid_ = false;}
57 else {
58 TFile ftest(inputfilename_.c_str(),"READ");
59 if (!ftest.IsOpen()) { cout << "ERROR: file " << inputfilename_ << " could not be opened\n"; valid_=false;
60 }
61 else {
62 ftest.Close();
63 const unsigned int r_find = outputfilename_.rfind(".root");
64 if(r_find > outputfilename_.size()) {
65 cout << "ERROR: the extension of the input file is not '.root'. Exiting...\n"; valid_=false;
66 }
67 else {
68 outputfilename_.replace(r_find,5,".lhco");
69 ofstream outfile( outputfilename_.c_str());
70 outfile.close();
71 cout << "INFO: " << outputfilename_ << " has been created\n";
72 }
73 }
74 }
75}
76
77void LHCOConverter::CopyRunLogFile() {
78 if(!valid_) {/*cout << "Nothing done\n";*/ return; }
79 if(inputlogname_ == "") {
80 // re-creates the logrun file name from the rootfile name
81 inputlogname_ = inputfilename_;
82 const unsigned int r_find = inputlogname_.rfind(".root");
83 inputlogname_.replace(r_find,5,"_run.log");
84 }
85 ifstream infile( inputlogname_.c_str() );
86 if (!infile.good()) { cout << "Warning: no input logfile found\n"; return; }
87
88 ofstream outfile( outputfilename_.c_str(),ios_base::app);
89
90 // else, if find is found
91 string linereader;
92 while ( getline(infile,linereader) ) {
93 outfile << " # " << linereader << endl;
94 }
95 outfile << " #" << endl;
96 infile.close();
97 outfile.close();
98}
99
100void LHCOConverter::ConvertExRootAnalysisToLHCO() {
101 if(!valid_) {/*cout << "Nothing done\n";*/ return; }
102
103 //output file
104 ofstream outfile( outputfilename_.c_str(),ios_base::app);
105 //# typ eta phi pt jmas ntrk btag had/em dum1 dum2
106 outfile << " ## More info on LHCO files: http://cp3wks05.fynu.ucl.ac.be/Manual/lhco.html\n #" << endl;
107 outfile << " # typ eta phi pt jmas ntrk btag had/em dum1 dum2" << endl;
108
109 // input files
110 TChain analysisChain("Analysis");
111 TChain triggerChain("Trigger");
112 analysisChain.Add(inputfilename_.c_str());
113 triggerChain.Add(inputfilename_.c_str());
114 ExRootTreeReader *analysisTree = new ExRootTreeReader(&analysisChain);
115 ExRootTreeReader *triggerTree = new ExRootTreeReader(&triggerChain);
116
117 TClonesArray *branchPhoton = analysisTree->UseBranch("Photon");
118 TClonesArray *branchElectron = analysisTree->UseBranch("Electron");
119 TClonesArray *branchMuon = analysisTree->UseBranch("Muon");
120 TClonesArray *branchTauJet = analysisTree->UseBranch("TauJet");
121 TClonesArray *branchJet = analysisTree->UseBranch("Jet");
122 TClonesArray *branchETmis = analysisTree->UseBranch("ETmis");
123
124 Long64_t Nevents = analysisTree->GetEntries();
125 cout << "** TTree 'Analysis' contains " << Nevents << " events" << endl;
126 Nevents = min(Nevents,triggerTree->GetEntries());
127 if (Nevents != analysisTree->GetEntries())
128 cout << "** WARNING: not the same number of entries in 'Analysis' and **\n** 'Trigger' trees\n";
129 for(Long64_t event = 0; event < Nevents; ++event) {
130 analysisTree->ReadEntry(event);
131 triggerTree->ReadEntry(event);
132 //TRIGT->GetGlobalResult(branchElecTrig, branchMuonTrig,branchJetTrig, branchTauJetTrig,branchPhotonTrig, branchETmisTrig,branchTrigger);
133 unsigned int triginfo = 0;
134 unsigned int line =0;
135 outfile << setw(3) << line++ << setw(4) << " " << setw(7) << event << setw(7) << triginfo << endl;
136
137 // 0 photon data
138 BranchReader(branchPhoton,line,lhcoPhotonID);
139
140 // 1 electron/positron data
141 BranchReader(branchElectron,line,lhcoElectronID);
142
143 // 2 muon data
144 BranchReader(branchMuon,line,lhcoMuonID);
145
146 // 3 tau-jets
147 BranchReader(branchTauJet,line,lhcoTauJetID);
148
149 // 4 jets
150 BranchReader(branchJet,line,lhcoJetID);
151
152 // 6 MET
153 BranchReader(branchETmis,line,lhcoETmisID);
154
155 } // event loop
156
157 outfile.close();
158 delete triggerTree;
159 delete analysisTree;
160}
161
162
163void LHCOConverter::BranchReader(const TClonesArray* branch, unsigned int& line, unsigned short int lhcoID) const {
164 ofstream outfile( outputfilename_.c_str(),ios_base::app);
165
166 unsigned int branch_size = branch->GetEntries();
167 TRootParticle * particle = 0;
168 for (unsigned int i=0; i< branch_size; i++) {
169 double jmass =0;
170 unsigned int ntrk = 0;
171 unsigned short int btag =0;
172 double ratioE = 0;
173 particle = (TRootParticle*) branch->At(i);
174 outfile << setw(3) << line++ // line counter
175 << setw(4) << lhcoID // object ID in lhco format
176 << setw(7) << particle->Eta
177// << setw(7) << fixed(3) << particle->Eta
178 << setw(7) << particle->Phi
179 << setw(7) << particle->PT
180 << setw(7) << jmass // invariant mass
181 << setw(7) << ntrk // number of tracks
182 << setw(7) << btag
183 << setw(7) << ratioE // E_had/E_em
184 << endl;
185 }
186 outfile.close();
187}
Note: See TracBrowser for help on using the repository browser.