Advertisement
EstEsca

Untitled

May 7th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.49 KB | None | 0 0
  1. #include<fstream>
  2. #include<sstream>
  3. #include<iostream>
  4. #include<stdio.h>
  5. #include<vector>
  6.  
  7. // #define USEDEBUG 1
  8. // #define USEDEBUGSIMPLIFIED 1
  9.  
  10. #ifdef USEDEBUG
  11. #define Debug(x) std::cout << x
  12. #else
  13. #define Debug(x)
  14. #endif
  15.  
  16. #ifdef USEDEBUGSIMPLIFIED
  17. #define sDebug(x) std::cout << x
  18. #else
  19. #define sDebug(x)
  20. #endif
  21.  
  22. #define DISPLAYWIDTH 1980
  23. #define DISPLAYHEIGHT 1080
  24. #define WINDOWLEN 300
  25. #define ENTRIES 250000
  26. #define VARIABLES 33
  27. #define NBINS 250
  28. #define RANGEMIN 0
  29. #define RANGEMAX 250
  30. #define SIGNALS 2
  31.  
  32. #define COLOUR1 3
  33. #define COLOUR2 6
  34.  
  35. string b ("b");
  36. string s ("s");
  37.  
  38. using namespace std;
  39.  
  40. int quiz3_(void){
  41.  
  42.   TH1F *background = new TH1F("background","DER_mass_MMC",NBINS,RANGEMIN,RANGEMAX);
  43.   TH1F *signal = new TH1F("signal","signal",NBINS,RANGEMIN,RANGEMAX);
  44. //  TCanvas *canvas = new TCanvas("canvas","canvas",(DISPLAYWIDTH-WINDOWLEN)/2,(DISPLAYHEIGHT-WINDOWLEN)/2, WINDOWLEN*2, WINDOWLEN);
  45.  
  46.   TF1 *g1 = new TF1("g1","gaus(0)+gaus(3)+gaus(6)",RANGEMIN,RANGEMAX);
  47.   TF1 *g11 = new TF1("g11","gaus",RANGEMIN,50);
  48.   TF1 *g12 = new TF1("g12","gaus",70,110);
  49.   TF1 *g13 = new TF1("g13","gaus",112,RANGEMAX);
  50.   Double_t g1Par[9];
  51.  
  52.   TF1 *g2 = new TF1("g2","gaus(0)+gaus(3)+gaus(6)",RANGEMIN,RANGEMAX);
  53.   TF1 *g21 = new TF1("g21","gaus",RANGEMIN,98);
  54.   TF1 *g22 = new TF1("g22","gaus",100, 148);
  55.   TF1 *g23 = new TF1("g23","gaus",150, RANGEMAX);
  56.   Double_t g2Par[9];
  57.  
  58.   int i, j, k;
  59.  
  60.   float data[VARIABLES-1];
  61.   float plot_range[VARIABLES-1][2];
  62.   float criteria_range[VARIABLES-1][2];
  63.  
  64.   ifstream f("training.csv");
  65.   TFile tfile("Data.root","recreate");
  66.   /*  TTree stree("stree","stree");
  67.   TTree btree("btree","btree");*/
  68.  
  69.   vector<TTree *> v;
  70.  
  71.   for(int i=0;i<2;i++){
  72.  
  73.     TTree *tree = new TTree();
  74.  
  75.     for(int j=0;j<VARIABLES-1;j++){
  76.       stringstream ss;
  77.       ss << j;
  78.       string intStr = ss.str();
  79.       intStr.append("var_");
  80.       tree->Branch(intStr.c_str(),&data[j]);
  81.     }
  82.  
  83.     v.push_back(tree);
  84.     sDebug("TREE HAS BEEN MADE" << endl);
  85.   }
  86. /*
  87.     float xx[2];
  88.  
  89.     vector<TTree *> tempvector;
  90.  
  91.  
  92.     TTree *temptree = new TTree("name","name");
  93.     for(int i=0;i<2;i++){
  94.       stringstream ss;
  95.       ss << i;
  96.       string intStr = ss.str();
  97.       intStr.append("test");
  98.       temptree->Branch(intStr.c_str(),&xx[i]);
  99.     }
  100.  
  101.     tempvector.push_back(temptree);
  102.  
  103.     xx[0] = 3;
  104.     xx[1] = 5;
  105.  
  106.     tempvector.at(0)->Fill();
  107.     tempvector.at(0)->Write();
  108. */
  109.   /*
  110.   TTree* t1 = new TTree();
  111.   float px, py, pz, ev;
  112.   t1->Branch("px",&px,"px");
  113.   t1->Branch("py",&py,"py");
  114.   t1->Branch("pz",&pz,"pz");
  115.   t1->Branch("ev",&ev,"ev");
  116.   // fill the tree
  117.  
  118.   px = 3;
  119.   py = 2;
  120.   pz = px*px + py*py;
  121.   ev = 1;
  122.   t1->Fill();
  123.  
  124.   t1->Write();
  125.  
  126.   TBrowser q;
  127.   */
  128.   //아 시발 진짜 너무한거 아니냐 ㅡㅡ
  129.   //2시간 넘게 뻘짓했는데, 데이터타입 때문이었다니 + C++ 기반이면서도 문자열과 숫자에 너무 관용적이어서 분명 타이틀로 들어갈 문자열을 값으로 받아들여서 시맨틱 에러가 ㅠㅠ
  130.  
  131.   string line;
  132.   getline(f, line);
  133.  
  134.   while(getline(f, line)){
  135.     Debug(i << "th line" << endl);
  136.  
  137.     k=0;
  138.     stringstream iss(line);
  139.     for (j=0; j<VARIABLES; j++){
  140.  
  141.       string val;
  142.  
  143.       getline(iss, val, ',');
  144.       sDebug(j << "th component: " << val << " " << endl);
  145.  
  146.       if(j == VARIABLES-1){
  147.         for(int k=0;k<VARIABLES-1;k++){
  148.           sDebug(k << "th component: " << data[k] << " " << endl);
  149.         }
  150.  
  151.         if(val == s){
  152.           v.at(0)->Fill();
  153.           sDebug("signal detected" << endl);
  154.         }
  155.         else if(val == b){
  156.           v.at(1)->Fill();
  157.           sDebug("background detected" << endl);
  158.         }
  159.         else{
  160.           cout << "ERROR OCCURED" << endl;
  161.           return -1;
  162.         }
  163.       }
  164.       else{
  165.         data[j] = atof(val.c_str());
  166.       }
  167.     }
  168.  
  169.     Debug(endl);
  170.     i++;
  171.   }
  172.  
  173.   for(int i=0;i<SIGNALS;i++){
  174.     v.at(i)->Write();
  175.   }
  176.  
  177.   //now make histograms
  178.  
  179.   vector<vector<TH1F*>> histograms;
  180.   for(int i=0;i<SIGNALS;i++){
  181.  
  182.     vector<TH1F*> histogram;
  183.     histograms.push_back(histogram);
  184.  
  185.     for(int j=0;j<VARIABLES-1;j++){
  186.       TH1F* histo = new TH1F("","",NBINS,0,1000);
  187.       histograms.at(i).push_back(histo);
  188.     }
  189.  
  190.   }
  191.  
  192.   TH1F *temphisto = new TH1F("teest","temp",NBINS,0,250);
  193.   for(i=0;i<v.at(0)->GetEntries();i++){
  194.     v.at(0)->GetEntry(i);
  195.     //cout << i << data[1] << endl;
  196.     temphisto->Fill(data[1]);
  197.   }
  198.  
  199.   temphisto->Draw();
  200.  
  201.  
  202.   return 0;
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement