14 TString PathFirstPart = getenv(
"SIMDATADIR");
15 TString FullPath = PathFirstPart;
16 FullPath +=
"/COSY/Ana/ToCombine/";
18 TString OutputPath = PathFirstPart +
"/COSY/Ana/Combined/";
20 TString FileListFolder = FullPath;
22 TString FolderListname = FileListFolder +
"FolderListToCombine.txt";
24 char CommandBuffer[300];
25 sprintf(CommandBuffer,
".!ls -d %s*mom*Evts*/ > %s",FileListFolder.Data(),FolderListname.Data());
26 gROOT->ProcessLine(CommandBuffer);
27 ifstream FolderFile(FolderListname.Data());
31 cout <<
"ERROR - file does NOT exist" << endl;
35 cout <<
"opened " << FolderListname.Data() << endl;
36 while (FolderFile.good())
41 TH1D* hCombinedNHits_p;
45 TH1D* hCombinedCrystalHits;
46 TH1D* hCombinedNeutronEnergyDeposit;
47 TH2D* hCombinedNeutronXYDistribution;
49 TH1D* hCombinedNHits_buffer;
50 TH1D* hCombinedNHits_p_buffer;
51 TH1D* hCombinedNAll_buffer;
52 TH1D* hCombinedPAll_buffer;
53 TH1D* hCombinedNMom_buffer;
54 TH1D* hCombinedCrystalHits_buffer;
55 TH1D* hCombinedNeutronEnergyDeposit_buffer;
56 TH2D* hCombinedNeutronXYDistribution_buffer;
58 TH1D* hNeutronsPerCrystal =
new TH1D(
"hNeutronsPerCrystal",
"Neutrons per Crystal",10000,0,9999);
60 char FolderBuffer[200];
61 FolderFile.getline(FolderBuffer,200);
62 TString FolderStringBuffer = FolderBuffer;
63 if (FolderStringBuffer.Length() == 0)
65 cout <<
"No more data found!" << endl;
70 FolderStringBuffer.Remove(FolderStringBuffer.Length()-1);
71 FolderStringBuffer.Remove(0,FolderStringBuffer.Last(
'/')+1);
72 cout <<
"Combining Dataset No :" << nDataset<<
"\t\t" <<
"Folder: "<< FolderStringBuffer << endl;
74 FileListFolder = FullPath + FolderStringBuffer;
75 char CommandBuffer[400];
76 TString FileListname = FileListFolder +
"/FileList.txt";
77 sprintf(CommandBuffer,
".!ls %s/*.root > %s",FileListFolder.Data(),FileListname.Data());
78 cout <<
"Processing " << CommandBuffer<< endl;
79 gROOT->ProcessLine(CommandBuffer);
81 ifstream
file(FileListname.Data());
84 cout <<
"ERROR - file does NOT exist" << endl;
93 file.getline(buffer,500);
97 if (!InFilename.EndsWith(
".root"))
101 InFile[
i]=
new TFile(InFilename);
104 InFile[
i]->GetObject(
"hNHits",hCombinedNHits);
105 InFile[
i]->GetObject(
"hNHits_p",hCombinedNHits_p);
106 InFile[
i]->GetObject(
"hNAll",hCombinedNAll);
107 InFile[
i]->GetObject(
"hPAll",hCombinedPAll);
108 InFile[
i]->GetObject(
"hNMom",hCombinedNMom);
109 InFile[
i]->GetObject(
"hCrystalHit",hCombinedCrystalHits);
110 InFile[
i]->GetObject(
"hNeutronEnergyDeposit",hCombinedNeutronEnergyDeposit);
111 InFile[
i]->GetObject(
"hNeutronXYDistribution",hCombinedNeutronXYDistribution);
117 InFile[
i]->GetObject(
"hNHits",hCombinedNHits_buffer);
118 InFile[
i]->GetObject(
"hNHits_p",hCombinedNHits_p_buffer);
119 InFile[
i]->GetObject(
"hNAll",hCombinedNAll_buffer);
120 InFile[
i]->GetObject(
"hPAll",hCombinedPAll_buffer);
121 InFile[
i]->GetObject(
"hNMom",hCombinedNMom_buffer);
122 InFile[
i]->GetObject(
"hCrystalHit",hCombinedCrystalHits_buffer);
123 InFile[
i]->GetObject(
"hNeutronEnergyDeposit",hCombinedNeutronEnergyDeposit_buffer);
124 InFile[
i]->GetObject(
"hNeutronXYDistribution",hCombinedNeutronXYDistribution_buffer);
128 hCombinedNHits->Add(hCombinedNHits_buffer,1) ;
129 hCombinedNHits_p->Add(hCombinedNHits_p_buffer,1);
130 hCombinedNAll->Add(hCombinedNAll_buffer,1);
131 hCombinedPAll->Add(hCombinedPAll_buffer,1);
132 hCombinedNMom->Add(hCombinedNMom_buffer,1);
133 hCombinedCrystalHits->Add(hCombinedCrystalHits_buffer,1);
134 hCombinedNeutronEnergyDeposit->Add(hCombinedNeutronEnergyDeposit_buffer,1);
135 hCombinedNeutronXYDistribution->Add(hCombinedNeutronXYDistribution_buffer,1);
151 TString OutFilename =OutputPath;
152 OutFilename += FolderStringBuffer;
154 TString TxTOutFilename = OutFilename;
155 OutFilename +=
".root";
156 TxTOutFilename +=
".txt";
157 ofstream TxTOutfile(TxTOutFilename.Data());
158 Int_t CrystalNumber = 1;
159 cout <<
"Bin\tCrystal\tCluster\tNeutron hits"<<endl;
160 TxTOutfile <<
"Bin\tCrystal\tCluster\tNeutron hits"<<endl;
161 for (Int_t iBin=0;iBin<1700;iBin++)
164 if(hCombinedCrystalHits->GetBinContent(iBin))
166 cout << iBin <<
"\t"<< CrystalNumber <<
"\t"<< iBin/100 <<
"\t"<< hCombinedCrystalHits->GetBinContent(iBin)<< endl;
167 hNeutronsPerCrystal->Fill(hCombinedCrystalHits->GetBinContent(iBin));
168 TxTOutfile << iBin <<
"\t"<< CrystalNumber <<
"\t"<< iBin/100 <<
"\t"<< hCombinedCrystalHits->GetBinContent(iBin)<< endl;
177 cout << OutFilename << endl;
178 TFile *OutFile=
new TFile(OutFilename,
"RECREATE");
180 hCombinedNHits->Write();
181 hCombinedNHits_p->Write();
182 hCombinedNAll->Write();
183 hCombinedPAll->Write();
184 hCombinedNMom->Write();
185 hCombinedCrystalHits->Write();
186 hNeutronsPerCrystal->Write();
187 hCombinedNeutronEnergyDeposit->Write();
188 hCombinedNeutronXYDistribution->Write();
194 delete hNeutronsPerCrystal;
int Combine_Gamma_Ana(TString Path, TString FileList)