TreeTest.C 2.64 KB
Newer Older
1
void TreeEnergyWrite(){
Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
2
3


4
5
6
7
  int Ecol1;
  double Ecol2,Ecol3,Ecol4;
  string line_E;
   
Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
8
  
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  TFile* Efile = new TFile("Energy_table.root","recreate");
  TTree* ETree = new TTree("ETree","Energy tree");

  ETree->Branch("Ecol1",&Ecol1,"Ecol1/I"); // ECol1 = Energy values = {200,300.....14000}
  ETree->Branch("Ecol4",&Ecol4,"Ecol4/D"); // Voltage values 

  std::ifstream Energy_file("Energy_table.dat");
  if(Energy_file.is_open()){
    while(getline(Energy_file,line_E)){
      istringstream ssE(line_E);
      ssE >> Ecol1 >> Ecol2 >> Ecol3 >> Ecol4;
      ETree->Fill();
    }
  }

  ETree->Write();
  Efile->Close();
Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
26
  
27
28
}

29
30
31
32
void TreeTPWrite(){
 
  int energy, col, row, pc;
  double voltage,tot, tot_var, toa, toa_var, time_ref;
33
34
35
36
  string line_TP;

  TFile* Efile = new TFile("Energy_table.root");
  TTree* ETree = (TTree*)Efile->Get("ETree");
37
38
  ETree->SetBranchAddress("Ecol1",&energy);
  ETree->SetBranchAddress("Ecol4",&voltage);
39

Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
40
  
41
42
43
44
45
  TFile* TPfile = new TFile("TP.root","update");  
  TTree* TPtree = new TTree("TPtree"," TP tree");
  TPtree->Branch("col",&col,"col/I");
  TPtree->Branch("row",&row,"row/I");
  TPtree->Branch("pc",&pc,"pc/I");
Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
46
47
48
49
  TPtree->Branch("tot",&tot,"tot/D");
  TPtree->Branch("tot_var",&tot_var,"tot_var/D");
  TPtree->Branch("toa",&toa,"toa/D");
  TPtree->Branch("toa_var",&toa_var,"toa_var/D");
50
51
52
  TPtree->Branch("time_ref",&time_ref,"time_ref/D");
  auto voltageBranch = TPtree->Branch("voltage",&voltage,"voltage/D");// make a new branch and connect it to the same variable as the branch address of the energy tree
      
Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
53

54
55
56
57
58
59
  for(int i = 0; i < ETree->GetEntries(); i++){
    ETree->GetEntry(i);
    // std:: cout << energy << " " << voltage << std::endl;
    std::string TPfilename = "tp_dat_" + std::to_string(energy) + ".dat";
    //std:: cout << " The TPfilenames are : " <<  TPfilename.c_str() <<std::endl;
    std::ifstream TPdatafile(TPfilename.c_str());
Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
60

61
62
    voltageBranch->Fill();
    
63
64
65
66
    if(TPdatafile.is_open()){

      std::cout << " The data file " << TPfilename.c_str() << " is opened ..." <<std::endl;

67
      
68
69
70
      // reading through individial tp_dat_ files

      while(getline(TPdatafile,line_TP)){
71
72
73
74
75
76
77
	  if(line_TP.rfind("#", 0) == 0) {
	    continue;
	  }

	  istringstream ssTP(line_TP);
	  ssTP >> col >> row >> pc >> tot >> tot_var >> toa >> toa_var >> time_ref;
	  //  std:: cout << col << " " << row << " " << pulsecount << " " << toa << " " << toa_var << std::endl;
78
79
80
81
82
83
84
	  TPtree->Fill();
      } //While loop getline
    }//if statement TPdatafile open
  }//For loop GetEntries

  //Save only the new version of the tree 

85
  TPtree->Write("",TObject::kOverwrite);
86
87
  TPfile->Close();
}
Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
88

89
void TreeTest(){ 
90
91

  TreeEnergyWrite();
92
  TreeTPWrite();
Keerthi Nakkalil's avatar
Keerthi Nakkalil committed
93
}