// To run the macro: // .L tree3ascii.C++; // tree3ascii("inputname"); #include "Riostream.h" #include "TTree.h" #include "TFile.h" void tree3ascii_new(TString inputfile) { // Example of a Tree where branches are variable length arrays // A second Tree is created and filled in parallel. // Run this script with // .x tree3.C // In the function treer, the first Tree is open. // The second Tree is declared friend of the first tree. // TTree::Draw is called with variables from both Trees. // // Author: Rene Brun const Int_t kMaxParticle = 10; Int_t nparticle; Float_t px[kMaxParticle]; Float_t py[kMaxParticle]; Float_t pz[kMaxParticle]; Float_t E[kMaxParticle]; Float_t kf[kMaxParticle]; Double_t wgt; Int_t event; // Float_t wgt_gg; // Float_t wgt_gq; // Float_t wgt_qq; // Float_t wgt_qqb; TFile f("tree3ascii.root","recreate"); TTree *t3 = new TTree("t3","Reconst ntuple"); t3->Branch("nparticle",&nparticle,"nparticle/I"); t3->Branch("px",px,"px[nparticle]/F"); t3->Branch("py",py,"py[nparticle]/F"); t3->Branch("pz",pz,"pz[nparticle]/F"); t3->Branch("E",E,"E[nparticle]/F"); t3->Branch("kf",kf,"kf[nparticle]/F"); t3->Branch("wgt",&wgt,"wtg/D"); // t3->Branch("wgt_gg",&wgt_gg,"wgt_gg/F"); // t3->Branch("wgt_gq",&wgt_gq,"wgt_gq/F"); // t3->Branch("wgt_qq",&wgt_qq,"wgt_qq/F"); // t3->Branch("wgt_qqb",&wgt_qqb,"wgt_qqb/F"); ifstream in; //TString inputfile = "W_only_lord_cteq6l1_80__test.ascii"; //TString inputfile = "W_only_tota_cteq6_m_80__cteq6_m.ascii"; TString headComment; bool openNewFile = true; while(!in.eof() || openNewFile) { cout << "Opening: " << inputfile << endl; in.open(inputfile); openNewFile = false; // Read comment lines int nlines = 0; while(nlines<1) { headComment.ReadLine(in); ++nlines; } // counter for events Int_t j=0; // Event loop while(!in.eof()) { char c; in.get(c); if(c=='\n') in.get(c); // if not a digit, assume is filename if(!isdigit(c)) { cout << "Found end of: " << inputfile << endl; if(!isalnum(c)) break; // no more filenames, exit in.putback(c); inputfile = ""; in >> inputfile; in.close(); openNewFile = true; break; } in.putback(c); in >> event >> wgt >> nparticle; //cout << "Event " << event << endl; //cout << "Weight " << wgt << endl; //cout << "N particles " << nparticle << endl; j++; // particle loop for (int i=0; i> kf[i] >> E[i] >> px[i] >> py[i] >> pz[i]; } if (!in.good()) { cout << "BAD INPUT" << endl; return; } if (j && j%1000 == 0) cout << "Processed " << j << " events" << endl; t3->Fill(); } } t3->Write(); }