FairRoot/PandaRoot
softrig/compress.C
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TTree.h"
3 #include "TString.h"
4 #include "TEventList.h"
5 #include "TDirectory.h"
6 #include <iostream>
7 #include "TObjArray.h"
8 #include "TRegexp.h"
9 #include <vector>
10 
11 typedef std::vector<TString> StrVec;
12 
13 int SplitString(TString s, TString delim, StrVec &toks)
14 {
15  toks.clear();
16  TObjArray *tok = s.Tokenize(delim);
17  int N = tok->GetEntries();
18  for (int i=0;i<N;++i)
19  {
20  TString token = (((TObjString*)tok->At(i))->String()).Strip(TString::kBoth);
21  toks.push_back(token);
22  }
23  return toks.size();
24 }
25 
26 int compress(TString ntp, TString fnamein, TString fnameout, TString bnames="", TString precut="tag" )
27 {
28  if (bnames=="*" && precut=="")
29  {
30  cout <<"Nothing to compress. Exiting."<<endl;
31  return;
32  }
33 
34  TString smode = ntp(1,ntp.Length());
35  int mode = smode.Atoi()/10;
36  bool dst = (mode == 11 || mode == 13 || mode == 15);
37 
38  // default branches for SoftTrigger
39  if (bnames=="")
40  {
41  bnames += "ev mode run recmode reccnt nsig mmiss xm xmct";
42  bnames += " es* *p *tht *pcm *thtcm *pt *ang *pid* *poc*";
43  if (dst) bnames += " xmdif";
44 
45  // vetos
46  bnames +=" !*beam* !*vx !*vy !*vz !t* !*pdg* !*pocmag tag";
47  }
48 
49  StrVec toks;
50  if (bnames.Index(" ")>=0) SplitString(bnames," ", toks);
51  else SplitString(bnames,"§, toks); TFile *fi = new TFile(fnamein,"READ"); TTree *ti = (TTree*) fi->Get(ntp); cout <<"Converting tree '"<<ntp<<"': "<<fnamein<<" ("<<ti->GetNbranches()<<" br, "<<ti->GetEntriesFast()<<" ev) ... "<<flush; ti->Draw(">>el",precut); TEventList *el = (TEventList*)gDirectory->Get("el"); ti->SetBranchStatus("*",0); for (int i=0;i<toks.size();++i) { if (toks[i].BeginsWith("!")) { TString tmp=toks[i](1,100); ti->SetBranchStatus(tmp,0); } else ti->SetBranchStatus(toks[i].Data(),1); } ti->SetEventList(el); TFile *fo = new TFile(fnameout, "RECREATE"); TTree *to = ti->CopyTree(""); // to->SetEventList(el); cout <<"to "<<fnameout<<" ("<<to->GetNbranches()<<" br, "<<to->GetEntriesFast()<<" ev) "<<endl; fo->Write(); fo->Close(); fi->Close(); return 0; } ", toks);
52 
53  TFile *fi = new TFile(fnamein,"READ");
54  TTree *ti = (TTree*) fi->Get(ntp);
55 
56  cout <<"Converting tree '"<<ntp<<"': "<<fnamein<<" ("<<ti->GetNbranches()<<" br, "<<ti->GetEntriesFast()<<" ev) ... "<<flush;
57 
58  ti->Draw(">>el",precut);
59  TEventList *el = (TEventList*)gDirectory->Get("el");
60 
61  ti->SetBranchStatus("*",0);
62  for (int i=0;i<toks.size();++i)
63  {
64  if (toks[i].BeginsWith("!"))
65  {
66  TString tmp=toks[i](1,100);
67  ti->SetBranchStatus(tmp,0);
68  }
69  else
70  ti->SetBranchStatus(toks[i].Data(),1);
71  }
72 
73  ti->SetEventList(el);
74 
75  TFile *fo = new TFile(fnameout, "RECREATE");
76  TTree *to = ti->CopyTree("");
77 // to->SetEventList(el);
78 
79  cout <<"to "<<fnameout<<" ("<<to->GetNbranches()<<" br, "<<to->GetEntriesFast()<<" ev) "<<endl;
80 
81  fo->Write();
82  fo->Close();
83  fi->Close();
84  return 0;
85 }
Int_t i
Definition: run_full.C:25
int compress(TString ntp="", TString fnamein="", TString fnameout="", TString bnames="", TString precut="")
TLorentzVector s
Definition: Pnd2DStar.C:50
Int_t mode
Definition: autocutx.C:47
TFile * fi
int SplitString(TString s, TString delim, StrVec &toks)
Definition: invexp.C:43
std::vector< TString > StrVec