#include #include #include #include #include #include #include #include #define NOFCHANNELS 5 int glow(const char *fname = "trial_3.txt") { int npoints = 0; // http://www.cplusplus.com/reference/string/ std::string line; // http://www.cplusplus.com/reference/iostream/ifstream/ std::ifstream ifs(fname); while(1) { // http://www.cplusplus.com/reference/string/getline/ getline(ifs, line); if ( ! ifs.good() ) break; npoints++; } // while(1) #if 0 /* 0 or 1 */ std::cout << "npoints = " << npoints << std::endl; #endif /* 0 or 1 */ if (npoints < 1) return npoints; ifs.clear(); ifs.seekg(0); TH1F *histo[(NOFCHANNELS)]; char name[50]; for(int i = 0; i < (NOFCHANNELS); i++) { snprintf(name, sizeof(name), "channel_%d", i + 1); gROOT->GetObject(name, histo[i]); if (histo[i]) delete histo[i]; histo[i] = new TH1F(name, name, npoints, 0, npoints); } // for(int i = 0; i < (NOFCHANNELS); i++) for(int i = 0; i < npoints; i++) { // http://www.cplusplus.com/reference/string/getline/ getline(ifs, line); if ( ! ifs.good() ) { std::cout << "ERROR reading line : " << (i + 1) << std::endl; break; } // if ( ! ifs.good() ) // http://www.cplusplus.com/reference/iostream/istringstream/ istringstream s(line); for(int j = 0; j < (NOFCHANNELS); j++) { #if 1 /* 0 or 1 */ s >> (histo[j]->GetArray())[(i + 1)]; // "number of entries" not changed if ( ! s.good() ) { std::cout << "ERROR in line : " << (i + 1) << " : in column : " << j << " or " << (j + 1) << std::endl; break; } // if ( ! s.good() ) histo[j]->SetEntries(histo[j]->GetEntries() + 1.0); #else /* 0 or 1 */ double tmp = 0.0; s >> tmp; if ( ! s.good() ) { std::cout << "ERROR in line : " << (i + 1) << " : in column : " << j << " or " << (j + 1) << std::endl; break; } // if ( ! s.good() ) histo[j]->SetBinContent(i + 1, tmp); // "number of entries" incremented #endif /* 0 or 1 */ } // for(int j = 0; j < (NOFCHANNELS); j++) } // for(int i = 0; i < npoints; i++) TCanvas *c = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("c"); if (c) delete c; c = new TCanvas("c", "c", 500, ((NOFCHANNELS) * 190)); c->Divide(1, (NOFCHANNELS)); // c->Modified(); // c->Update(); for(int i = 0; i < (NOFCHANNELS); i++) { c->cd(i + 1); histo[i]->Draw("C"); } // for(int i = 0; i < (NOFCHANNELS); i++) c->cd(0); // c->Modified(); c->Update(); return npoints; } // int glow(const char *fname = "trial_3.txt")