Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include "Riostream.h"
  2. #include <vector>
  3. #include <string>
  4. #include <TString.h>
  5. #include <TSystem.h>
  6. #include <TInterpreter.h>
  7. #include <TFile.h>
  8. #include <TF1.h>
  9. #include <TF2.h>
  10. #include <TNtuple.h>
  11. #include <TH1.h>
  12. #include <TH2.h>
  13.  
  14.  
  15. struct vec {
  16. float x,y,z,t;
  17. };
  18.  
  19. void R_out() {
  20. // Read data from an ascii file and create a root file with an histogram and an ntuple.
  21. // see a variant of this macro in basic2.C
  22. //Author: Rene Brun
  23.  
  24.  
  25. // read file $ROOTSYS/tutorials/tree/basic.dat
  26. // this file has 3 columns of float data
  27. TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
  28. dir.ReplaceAll("R_out.C","");
  29. dir.ReplaceAll("/./","/");
  30. ifstream in;
  31. in.open(Form("%sbasic.dat",dir.Data()));
  32. std::vector<vec> values;
  33.  
  34. Float_t x,y,z,tout,anl,nstart=0;
  35. Float_t x1,x2,x3,x4;
  36. Int_t nphoto = 0, neven=0;
  37. TFile *f = new TFile("basic.root","RECREATE");
  38. TH1F *h1 = new TH1F("h1","x distribution",100,-1,1);
  39. TH1F *h2 = new TH1F("h2","Nphot distrb ",100,0,2000);
  40. TH2F *h3 = new TH2F("h3","x VS y ",100,-0.8,0.8,100,-2.2,-0.8);
  41. TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","x:y:z");
  42.  
  43. while ( in.good() ) {
  44. std::string s;
  45. struct vec v;
  46. std::getline (in, s);
  47. if (s.empty()) {
  48. continue;
  49. }
  50. sscanf (s.c_str(), "%f %f %f %f",&v.x, &v.y, &v.z, &v.t);
  51. sscanf (s.c_str(), "%f %f %f %f",&x, &y, &z, &tout);
  52. values.push_back(v);
  53.  
  54.  
  55. // in >> x >> y >> z >> tout ;
  56. // if (!in.good()) break;
  57. //// if (nphot < 5) printf("x=%8f, y=%8f, z=%8f\n",x,y,z);
  58. if(x != 9000 ) {
  59. ///// if (nphoto < 5) printf("x=%8f, y=%8f, z=%8f\n",x,y,z);
  60. h1->Fill(x);
  61. ntuple->Fill(x,y,z);
  62. h3->Fill(x,y);
  63. nphoto = nphoto + 1;
  64. } else
  65. {
  66. neven = neven + 1;
  67. printf("NPHOT =%8f\n",nphoto);
  68. anl = static_cast<float> (nphoto);
  69. if(nstart != 0 && anl > 0 ) {h2->Fill(anl);}
  70. nphoto = 0;
  71. nstart++;
  72. }
  73. }
  74. anl = static_cast<float> (nphoto);
  75. h2->Fill(anl);
  76. printf(" found %d points\n",nphoto);
  77. printf(" found %d Neven\n",neven);
  78.  
  79. in.close();
  80.  
  81. f->Write();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement