FairRoot/PandaRoot
Functions
CombineNeutronAna.C File Reference
#include <TH1D.h>
#include <TH2D.h>
#include <stdio.h>
#include <TString.h>
#include "TFile.h"
#include <iostream>
#include <fstream>

Go to the source code of this file.

Functions

int CombineNeutronAna (TString FileListname_ext, TString OutfileName_ext)
 

Function Documentation

int CombineNeutronAna ( TString  FileListname_ext,
TString  OutfileName_ext 
)

Definition at line 11 of file CombineNeutronAna.C.

References file, i, and TString.

12 {
13  TString PathFirstPart = getenv("SIMDATADIR");
14  TString FullPath = PathFirstPart;
15  FullPath += "/Neutron/Ana/";
16  TString FileListname = FullPath;
17  FileListname +=FileListname_ext;
18  //FileListname +="TripleBall30_urqmd_2_filelist.txt";
19  cout << FileListname<< endl;
20 
21  TH1D* hCombinedNHits;
22  TH1D* hCombinedNHits_p;
23  TH1D* hCombinedNAll;
24  TH1D* hCombinedPAll;
25  TH1D* hCombinedNMom;
26  TH1D* hCombinedCrystalHits;
27  TH1D* hCombinedNeutronEnergyDeposit;
28  TH2D* hCombinedNeutronXYDistribution;
29 
30  TH1D* hCombinedNHits_buffer;
31  TH1D* hCombinedNHits_p_buffer;
32  TH1D* hCombinedNAll_buffer;
33  TH1D* hCombinedPAll_buffer;
34  TH1D* hCombinedNMom_buffer;
35  TH1D* hCombinedCrystalHits_buffer;
36  TH1D* hCombinedNeutronEnergyDeposit_buffer;
37  TH2D* hCombinedNeutronXYDistribution_buffer;
38 
39  TH1D* hNeutronsPerCrystal = new TH1D("hNeutronsPerCrystal","Neutrons per Crystal",10000,0,9999);
40 
41  ifstream file(FileListname.Data());
42  if(!file) // check if file exists
43  {
44  cout << "ERROR - file does NOT exist" << endl;
45  }
46  else
47  {
48  Int_t i = 0;
49  char buffer[100];
50  TFile* InFile[1000];
51  while (file.good())
52  {
53  file.getline(buffer,200);
54  cout << buffer << endl;
55 
56  TString InFilename = FullPath;
57  InFilename += buffer;
58  cout << InFilename<< endl;
59  InFile[i]= new TFile(InFilename);
60  if (i ==0)
61  {
62  InFile[i]->GetObject("hNHits",hCombinedNHits);
63  InFile[i]->GetObject("hNHits_p",hCombinedNHits_p);
64  InFile[i]->GetObject("hNAll",hCombinedNAll);
65  InFile[i]->GetObject("hPAll",hCombinedPAll);
66  InFile[i]->GetObject("hNMom",hCombinedNMom);
67  InFile[i]->GetObject("hCrystalHit",hCombinedCrystalHits);
68  InFile[i]->GetObject("hNeutronEnergyDeposit",hCombinedNeutronEnergyDeposit);
69  InFile[i]->GetObject("hNeutronXYDistribution",hCombinedNeutronXYDistribution);
70  //hCombinedNAll->Draw();
71  //cout << i << " "<< hCrystalHits->GetEntries() << endl;
72  }
73  else
74  {
75  InFile[i]->GetObject("hNHits",hCombinedNHits_buffer);
76  InFile[i]->GetObject("hNHits_p",hCombinedNHits_p_buffer);
77  InFile[i]->GetObject("hNAll",hCombinedNAll_buffer);
78  InFile[i]->GetObject("hPAll",hCombinedPAll_buffer);
79  InFile[i]->GetObject("hNMom",hCombinedNMom_buffer);
80  InFile[i]->GetObject("hCrystalHit",hCombinedCrystalHits_buffer);
81  InFile[i]->GetObject("hNeutronXYDistribution",hCombinedNeutronXYDistribution_buffer);
82 
83  //cout << i << " "<< hCrystalHits_buffer->GetEntries()<< endl;
84 
85  hCombinedNHits->Add(hCombinedNHits_buffer,1);
86  hCombinedNHits_p->Add(hCombinedNHits_p_buffer,1);
87  hCombinedNAll->Add(hCombinedNAll_buffer,1);
88  hCombinedPAll->Add(hCombinedPAll_buffer,1);
89  hCombinedNMom->Add(hCombinedNMom_buffer,1);
90  hCombinedCrystalHits->Add(hCombinedCrystalHits_buffer,1);
91  hCombinedNeutronEnergyDeposit->Add(hCombinedNeutronEnergyDeposit_buffer,1);
92  hCombinedNeutronXYDistribution->Add(hCombinedNeutronXYDistribution_buffer,1);
93 
94  }
95  //InFile[i]->Close();
96  i++;
97  }
98  //TString InFilename = FullPath;
99  //InFilename += buffer;
100  //cout << InFilename<< endl;
101  //TFile InFile(InFilename);
102  //InFile.GetListOfKeys()->Print();
103  }
104  file.close();
105 
106 
107  TString OutFilename =FullPath;
108  OutFilename +="Combined/";
109  OutFilename += OutfileName_ext;
110  //OutFilename +="test1.root";
111  TString TxTOutFilename = OutFilename;
112  TxTOutFilename += ".txt";
113  ofstream TxTOutfile(TxTOutFilename.Data());
114  Int_t CrystalNumber = 1;
115  cout << "Bin\tCrystal\tCluster\tNeutron hits"<<endl;
116  TxTOutfile << "Bin\tCrystal\tCluster\tNeutron hits"<<endl;
117  for (Int_t iBin=0;iBin<1700;iBin++)
118  {
119 
120  if(hCombinedCrystalHits->GetBinContent(iBin))
121  {
122  cout << iBin << "\t"<< CrystalNumber <<"\t"<< iBin/100 <<"\t"<< hCombinedCrystalHits->GetBinContent(iBin)<< endl;
123  hNeutronsPerCrystal->Fill(hCombinedCrystalHits->GetBinContent(iBin));
124  TxTOutfile << iBin << "\t"<< CrystalNumber <<"\t"<< iBin/100 <<"\t"<< hCombinedCrystalHits->GetBinContent(iBin)<< endl;
125  CrystalNumber++;
126 
127  }
128  }
129  TxTOutfile.close();
130  //hCombinedCrystalHits->Draw();
131  // Write combined output to file
132 
133  cout << OutFilename << endl;
134  TFile *OutFile= new TFile(OutFilename,"RECREATE");
135  OutFile->cd();
136  hCombinedNHits->Write();
137  hCombinedNHits_p->Write();
138  hCombinedNAll->Write();
139  hCombinedPAll->Write();
140  hCombinedNMom->Write();
141  hCombinedCrystalHits->Write();
142  hNeutronsPerCrystal->Write();
143  hCombinedNeutronEnergyDeposit->Write();
144  hCombinedNeutronXYDistribution->Write();
145  //hNeutronsPerCrystal->Draw();
146  OutFile->ls();
147  OutFile->Close();
148  return 0;
149 }
Int_t i
Definition: run_full.C:25
TFile * file