Oscar97QA.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include "Oscar97QA.h"
  2. //___________
  3. Oscar97QA::Oscar97QA(const char *inFileList,
  4. const char *outFile) {
  5. mError = false;
  6. mDebug = false;
  7. //
  8. // Open list of root files
  9. //
  10. std::cout << "[Oscar97QA]: Trying to open file "
  11. << inFileList << "...";
  12. mListFile = fopen(inFileList, "r");
  13. if (!mListFile) {
  14. std::cout << " [FAIL]" << std::endl;
  15. mError = true;
  16. return;
  17. }
  18. else {
  19. std::cout << " [OK]" << std::endl;
  20. }
  21. //
  22. // Create/recreate output file
  23. //
  24. std::cout << "[Oscar97QA]: Trying to create/recreate output file "
  25. << outFile << "... ";
  26. mOut = new TFile(outFile, "RECREATE");
  27. if (!mOut) {
  28. std::cout << "[FAIL]" << std::endl;
  29. mError = true;
  30. return;
  31. }
  32. else {
  33. std::cout << "[OK]" << std::endl;
  34. }
  35. //
  36. // Create histograms
  37. //
  38. std::cout << "[Oscar97QA]: Creating histograms" << std::endl;
  39. // event
  40. hImpPar = new TH1D("hImpPar", ";impact (fm/c);#", 200, 0., 17.);
  41. // track
  42. hPx = new TH1D("hPx", ";p_{x} (GeV/c);#", 1000, -3., 3.);
  43. hPy = new TH1D("hPy", ";p_{y} (GeV/c);#", 1000, -3., 3.);
  44. hPz = new TH1D("hPz", ";p_{z} (GeV/c);#", 1000, -5., 5.);
  45. hPt = new TH1D("hPt", ";p_{t} (GeV/c);#", 500, 0., 3.);
  46. hXfr = new TH1D("hXfr", ";x_{fr} (fm/c);#", 1000, -50., 50.);
  47. hYfr = new TH1D("hYfr", ";y_{fr} (fm/c);#", 1000, -50., 50.);
  48. hZfr = new TH1D("hZfr", ";z_{fr} (fm/c);#", 1000, -50., 50.);
  49. hTfr = new TH1D("hTfr", ";t_{fr} (fm/c);#", 1000, 0., 200.);
  50. hEnergy = new TH1D("hEnergy", ";E (GeV);#", 1000, 0., 200.);
  51. hMSqrVsPt = new TH2D("hMSqrVsPt",
  52. ";p_{t} (GeV/c);m^{2} (GeV^{2}/c^{4})",
  53. 500, 0., 3.,
  54. 1000, 0., 2.);
  55. hEta = new TH1D("hEta", ";#eta;#", 1000, -5, 5.);
  56. }
  57. //_____________
  58. void Oscar97QA::MakeQA() {
  59. char buf[BFSZ] = {0};
  60. while (!feof(mListFile)) {
  61. // read next file from the list
  62. char *ret = fgets(buf, BFSZ, mListFile);
  63. if (!ret) break;
  64. int len = strlen(buf);
  65. if (len != BFSZ)
  66. buf[len - 1] = '\0'; // last character may be '\n' (see man fgets)
  67. ReadFile(buf);
  68. }
  69. mOut->cd();
  70. hImpPar->Write();
  71. hPx->Write();
  72. hPy->Write();
  73. hPz->Write();
  74. hPt->Write();
  75. hXfr->Write();
  76. hYfr->Write();
  77. hZfr->Write();
  78. hTfr->Write();
  79. hEnergy->Write();
  80. hMSqrVsPt->Write();
  81. hEta->Write();
  82. mOut->Close();
  83. }
  84. //_____________
  85. void Oscar97QA::ReadFile(const char *file) {
  86. //
  87. // Trying to open ROOT file
  88. //
  89. if (mDebug)
  90. std::cout << "[Oscar97QA]: Working with file "
  91. << file << std::endl;
  92. TFile *fIn = new TFile(file, "READ");
  93. if (!fIn) {
  94. std::cout << "[Oscar97QA]: Can't open file "
  95. << file << std::endl;
  96. return;
  97. }
  98. //
  99. // Associate tree
  100. //
  101. TTree *tree = (TTree *)fIn->Get("Oscar97Dst");
  102. Oscar97Event *event = new Oscar97Event;
  103. tree->SetBranchAddress("Oscar97Event", &event);
  104. unsigned long nEvents = tree->GetEntries();
  105. for (unsigned long iEvent = 0; iEvent < nEvents; iEvent++) {
  106. tree->GetEntry(iEvent);
  107. unsigned int nTracks = event->GetNTracks();
  108. hImpPar->Fill(event->GetImpactPar());
  109. TClonesArray *tracks = event->GetTracks();
  110. for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
  111. Oscar97Track *track = (Oscar97Track *)tracks->At(iTrack);
  112. float px = track->GetPx();
  113. float py = track->GetPy();
  114. float pz = track->GetPz();
  115. float pt = TMath::Sqrt(px*px + py*py);
  116. float p = TMath::Sqrt(px*px + py*py + pz*pz);
  117. float energy = track->GetEnergy();
  118. float mass = track->GetMass();
  119. float x = track->GetXfr();
  120. float y = track->GetYfr();
  121. float z = track->GetZfr();
  122. float t = track->GetTfr();
  123. float eta = 0.5*TMath::Log((p + pz)/(p - pz));
  124. hPx->Fill(px);
  125. hPy->Fill(py);
  126. hPz->Fill(pz);
  127. hXfr->Fill(x);
  128. hYfr->Fill(y);
  129. hZfr->Fill(z);
  130. hTfr->Fill(t);
  131. hPt->Fill(pt);
  132. hEnergy->Fill(energy);
  133. hMSqrVsPt->Fill(pt, mass*mass);
  134. hEta->Fill(eta);
  135. } // for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++)
  136. } // for (unsigned long iEvent = 0; iEvent < nEvent; iEvent++)
  137. }
  138. //_____________
  139. bool Oscar97QA::GetError() {
  140. return mError;
  141. }
  142. //_____________
  143. void Oscar97QA::SetDebug(bool val) {
  144. mDebug = val;
  145. }