26 #define USE_CANVASINTAB
28 #ifdef USE_CANVASINTAB
44 #include <TApplication.h>
45 #include <TGApplication.h>
52 #include <TGraphErrors.h>
56 #include <TGFileBrowser.h>
57 #include <TGFileDialog.h>
66 const char *gOpenAsTypes[] = {
67 "ROOT files",
"*.root",
72 fi.fFileTypes = gOpenAsTypes;
76 new TGFileDialog(gClient->GetRoot(),
77 gClient->GetRoot(), kFDOpen, &fi);
105 if(&right ==
this)
return *
this;
134 fRelatErr(right.fRelatErr),
140 if(
this == &right)
return *
this;
149 std::vector<double>
fG;
163 char speciesName[500];
168 TTree*
tree = (TTree*)file->Get(
"species");
169 tree->SetBranchAddress(
"speciesID", &speciesID);
170 tree->SetBranchAddress(
"number", &number);
171 tree->SetBranchAddress(
"nEvent", &nEvent);
172 tree->SetBranchAddress(
"speciesName", &speciesName);
173 tree->SetBranchAddress(
"time", &time);
174 tree->SetBranchAddress(
"sumG", &sumG);
175 tree->SetBranchAddress(
"sumG2", &sumG2);
177 Long64_t nentries = tree->GetEntries();
182 cout <<
"No entries found in the tree species contained in the file "
183 << file->GetPath() << endl;
191 std::map<int, std::map<double, SpeciesInfoAOS>> speciesTimeInfo;
193 for (
int j=0; j < nentries; j++)
201 infoAOS.
fG2 += sumG2;
203 infoAOS.
fName = speciesName;
208 std::map<int, SpeciesInfoSOA> speciesInfo;
210 auto it_SOA = speciesTimeInfo.begin();
211 auto end_SOA = speciesTimeInfo.end();
213 for (; it_SOA!=end_SOA ; ++it_SOA)
215 const int _speciesID = it_SOA->first;
218 auto it2 = it_SOA->second.begin();
219 auto end2 = it_SOA->second.end();
221 info.
fName = it2->second.fName;
222 const size_t size2 = it_SOA->second.size();
223 info.
fG.resize(size2);
224 info.
fGerr.resize(size2);
225 info.
fTime.resize(size2);
227 for(
int i2 = 0 ;it2!=end2;++it2, ++i2)
231 double _SumG2 = infoAOS.
fG2;
232 double _MeanG = infoAOS.
fG/infoAOS.
fNEvent;
233 double _Gerr = sqrt((_SumG2/infoAOS.
fNEvent - pow(_MeanG,2))
236 info.
fG[i2] = _MeanG;
237 info.
fGerr[i2] = _Gerr;
238 info.
fTime[i2] = it2->first;
239 info.
fRelatErr += _Gerr/(_MeanG + 1e-30);
245 #ifdef USE_CANVASINTAB
250 std::map<int, SpeciesInfoSOA>::iterator it = speciesInfo.begin();
251 std::map<int, SpeciesInfoSOA>::iterator end = speciesInfo.end();
253 for (; it != end; ++it)
255 speciesID = it->first;
259 if(info.
fG.empty())
continue;
261 TGraphErrors* gSpecies =
new TGraphErrors(info.
fG.size(),
267 #ifdef USE_CANVASINTAB
270 TCanvas* cSpecies = myFrame->
GetCanvas(nCanvas);
272 TCanvas* cSpecies =
new TCanvas(info.
fName.c_str(),
277 int color = (2+speciesID)%TColor::GetNumberOfColors();
278 if(color == 5 || color==10 || color==0) ++color;
282 gSpecies->SetMarkerStyle(20+speciesID);
283 gSpecies->SetMarkerColor(color);
286 gSpecies->SetTitle((info.
fName
288 + std::to_string(speciesID)+
" rel. Err. "
289 + std::to_string(info.
fRelatErr)).c_str() );
290 gSpecies->GetXaxis()->SetTitle(
"Time [ns]");
291 gSpecies->GetYaxis()->SetTitle(
"G [molecules/100 eV]");
292 gSpecies->Draw(
"ap");
296 #ifdef USE_CANVASINTAB
298 for(
int i = 0 ; i < nCanvas ; ++i)
309 if(filePath == 0 || strlen(filePath) == 0)
311 perror(
"You must provide a valid file");
315 TFile* file = TFile::Open(filePath);
319 perror (
"Error opening ntuple file");
325 perror (
"Error opening ntuple file");
330 cout <<
"Opening ntple file " << filePath << endl;
338 #define _PROCESS_ONE_FILE_ ProcessSingleFile
341 int main(
int argc,
char **argv)
344 int initialArgc = argc;
345 vector<char*> initialArgv(argc);
346 for(
int i = 0 ; i < argc ; ++i)
348 initialArgv[i] = argv[i];
352 TApplication* rootApp =
new TApplication(
"PlotG",&argc, argv);
354 const char* filePath = 0;
359 filePath = fileInfo->fFilename;
360 if(fileInfo->fFileNamesList && fileInfo->fFileNamesList->GetSize()>1)
364 perror(
"Multiple selection of files not supported, implement your own!");
379 filePath = initialArgv[1];
void ProcessSingleFile(TFile *file)
SpeciesInfoSOA(const SpeciesInfoSOA &right)
const XML_Char XML_Encoding * info
std::vector< double > fTime
TCanvas * GetCanvas(int i)
int main(int argc, char **argv)
std::vector< double > fGerr
size_t GetNCanvas() const
#define _PROCESS_ONE_FILE_
size_t AddCanvas(const char *name="New tab")
SpeciesInfoAOS & operator=(const SpeciesInfoAOS &right)
const TGFileInfo * OpenRootFile()
SpeciesInfoAOS(const SpeciesInfoAOS &right)
SpeciesInfoSOA & operator=(const SpeciesInfoSOA &right)