Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- #include<sstream>
- #include<iostream>
- #include<stdio.h>
- #include<vector>
- // #define USEDEBUG 1
- // #define USEDEBUGSIMPLIFIED 1
- #ifdef USEDEBUG
- #define Debug(x) std::cout << x
- #else
- #define Debug(x)
- #endif
- #ifdef USEDEBUGSIMPLIFIED
- #define sDebug(x) std::cout << x
- #else
- #define sDebug(x)
- #endif
- #define DISPLAYWIDTH 1980
- #define DISPLAYHEIGHT 1080
- #define WINDOWLEN 300
- #define ENTRIES 250000
- #define VARIABLES 33
- #define NBINS 250
- #define RANGEMIN 0
- #define RANGEMAX 250
- #define SIGNALS 2
- #define COLOUR1 3
- #define COLOUR2 6
- string b ("b");
- string s ("s");
- using namespace std;
- int quiz3_(void){
- TH1F *background = new TH1F("background","DER_mass_MMC",NBINS,RANGEMIN,RANGEMAX);
- TH1F *signal = new TH1F("signal","signal",NBINS,RANGEMIN,RANGEMAX);
- // TCanvas *canvas = new TCanvas("canvas","canvas",(DISPLAYWIDTH-WINDOWLEN)/2,(DISPLAYHEIGHT-WINDOWLEN)/2, WINDOWLEN*2, WINDOWLEN);
- TF1 *g1 = new TF1("g1","gaus(0)+gaus(3)+gaus(6)",RANGEMIN,RANGEMAX);
- TF1 *g11 = new TF1("g11","gaus",RANGEMIN,50);
- TF1 *g12 = new TF1("g12","gaus",70,110);
- TF1 *g13 = new TF1("g13","gaus",112,RANGEMAX);
- Double_t g1Par[9];
- TF1 *g2 = new TF1("g2","gaus(0)+gaus(3)+gaus(6)",RANGEMIN,RANGEMAX);
- TF1 *g21 = new TF1("g21","gaus",RANGEMIN,98);
- TF1 *g22 = new TF1("g22","gaus",100, 148);
- TF1 *g23 = new TF1("g23","gaus",150, RANGEMAX);
- Double_t g2Par[9];
- int i, j, k;
- float data[VARIABLES-1];
- float plot_range[VARIABLES-1][2];
- float criteria_range[VARIABLES-1][2];
- ifstream f("training.csv");
- TFile tfile("Data.root","recreate");
- /* TTree stree("stree","stree");
- TTree btree("btree","btree");*/
- vector<TTree *> v;
- for(int i=0;i<2;i++){
- TTree *tree = new TTree();
- for(int j=0;j<VARIABLES-1;j++){
- stringstream ss;
- ss << j;
- string intStr = ss.str();
- intStr.append("var_");
- tree->Branch(intStr.c_str(),&data[j]);
- }
- v.push_back(tree);
- sDebug("TREE HAS BEEN MADE" << endl);
- }
- /*
- float xx[2];
- vector<TTree *> tempvector;
- TTree *temptree = new TTree("name","name");
- for(int i=0;i<2;i++){
- stringstream ss;
- ss << i;
- string intStr = ss.str();
- intStr.append("test");
- temptree->Branch(intStr.c_str(),&xx[i]);
- }
- tempvector.push_back(temptree);
- xx[0] = 3;
- xx[1] = 5;
- tempvector.at(0)->Fill();
- tempvector.at(0)->Write();
- */
- /*
- TTree* t1 = new TTree();
- float px, py, pz, ev;
- t1->Branch("px",&px,"px");
- t1->Branch("py",&py,"py");
- t1->Branch("pz",&pz,"pz");
- t1->Branch("ev",&ev,"ev");
- // fill the tree
- px = 3;
- py = 2;
- pz = px*px + py*py;
- ev = 1;
- t1->Fill();
- t1->Write();
- TBrowser q;
- */
- //아 시발 진짜 너무한거 아니냐 ㅡㅡ
- //2시간 넘게 뻘짓했는데, 데이터타입 때문이었다니 + C++ 기반이면서도 문자열과 숫자에 너무 관용적이어서 분명 타이틀로 들어갈 문자열을 값으로 받아들여서 시맨틱 에러가 ㅠㅠ
- string line;
- getline(f, line);
- while(getline(f, line)){
- Debug(i << "th line" << endl);
- k=0;
- stringstream iss(line);
- for (j=0; j<VARIABLES; j++){
- string val;
- getline(iss, val, ',');
- sDebug(j << "th component: " << val << " " << endl);
- if(j == VARIABLES-1){
- for(int k=0;k<VARIABLES-1;k++){
- sDebug(k << "th component: " << data[k] << " " << endl);
- }
- if(val == s){
- v.at(0)->Fill();
- sDebug("signal detected" << endl);
- }
- else if(val == b){
- v.at(1)->Fill();
- sDebug("background detected" << endl);
- }
- else{
- cout << "ERROR OCCURED" << endl;
- return -1;
- }
- }
- else{
- data[j] = atof(val.c_str());
- }
- }
- Debug(endl);
- i++;
- }
- for(int i=0;i<SIGNALS;i++){
- v.at(i)->Write();
- }
- //now make histograms
- vector<vector<TH1F*>> histograms;
- for(int i=0;i<SIGNALS;i++){
- vector<TH1F*> histogram;
- histograms.push_back(histogram);
- for(int j=0;j<VARIABLES-1;j++){
- TH1F* histo = new TH1F("","",NBINS,0,1000);
- histograms.at(i).push_back(histo);
- }
- }
- TH1F *temphisto = new TH1F("teest","temp",NBINS,0,250);
- for(i=0;i<v.at(0)->GetEntries();i++){
- v.at(0)->GetEntry(i);
- //cout << i << data[1] << endl;
- temphisto->Fill(data[1]);
- }
- temphisto->Draw();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement