Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TimeSortTree.C
Go to the documentation of this file.
1 //
2 // Sort waveburst root file IFILE_NAME according time[0] parameters and to the ISELECTION rules
3 // write the sorted root file to OFILE_NAME
4 // write the sorted selected parameters OEXPRESSION to file LOG_NAME
5 // Author : Gabriele Vedovato
6 
7 {
8 
9  #define IFILE_NAME "merge/wave_S6A_R4_SIM_SGQ9_L1H1V1_1G_run2.M1.root"
10  #define OFILE_NAME "wave_S6A_R4_SIM_SGQ9_L1H1V1_1G_run2.M1.sorted_factor_0d3.root"
11  #define TREE_NAME "waveburst"
12 
13  #define ISELECTION "abs(time[0]-time[3])<0.1 && abs(factor-0.3)<0.1"
14  #define OEXPRESSION "run:time[0]:rho[1]:netcc[0]"
15 
16  #define LOG_NAME "log.txt"
17 
19  TFile f(IFILE_NAME);
20  TTree *tree = (TTree*)f.Get(TREE_NAME);
21  //Drawing variable t with no graphics option.
22  //variable pz stored in array fV1 (see TTree::Draw)
23  tree->Draw("time[0]:Entry$",ISELECTION,"goff");
24  Int_t nentries = (Int_t)tree->GetSelectedRows();
25  Int_t *index = new Int_t[nentries];
26  double* entry = tree->GetV2();
27  //sort array containing pz in decreasing order
28  //The array index contains the entry numbers in decreasing order of t
29  TMath::Sort(nentries,tree->GetV1(),index,false);
30 
31  //open new file to store the sorted Tree
32  TFile f2(OFILE_NAME,"recreate");
33  //Create an empty clone of the original tree
34  TTree *tsorted = (TTree*)tree->CloneTree(0);
35  for (Int_t i=0;i<nentries;i++) {
36  if (i%1000==0 && i>0) cout << "write entry : " << i << endl;
37  tree->GetEntry(entry[index[i]]);
38  tsorted->Fill();
39  }
40  tsorted->Write();
41  delete [] index;
42 
43 #ifdef LOG_NAME
44  tsorted->SetScanField(0);
45  ((TTreePlayer*)(tsorted->GetPlayer()))->SetScanRedirect(true);
46  ((TTreePlayer*)(tsorted->GetPlayer()))->SetScanFileName(LOG_NAME);
47  tsorted->Scan(OEXPRESSION,"","");
48 #endif
49 
50  gSystem->Exit(0);
51 }
52 
TTree * tree
Definition: TimeSortTree.C:20
#define OFILE_NAME
Int_t nentries
Definition: TimeSortTree.C:24
#define IFILE_NAME
#define TREE_NAME
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
TFile f(IFILE_NAME)
Int_t * index
Definition: TimeSortTree.C:25
#define OEXPRESSION
#define ISELECTION
TFile f2(OFILE_NAME,"recreate")
#define LOG_NAME
double * entry
Definition: TimeSortTree.C:26
TTree * tsorted
Definition: TimeSortTree.C:34