get_dca.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #include <Rtypes.h>
  2. #include <TChain.h>
  3. #include <TClonesArray.h>
  4. #include <TStopwatch.h>
  5. #include <TROOT.h>
  6. #include <TSystem.h>
  7. #include <TMath.h>
  8. // #include <TTree.h>
  9. #include <TFile.h>
  10. #include <TH1.h>
  11. #include <TF1.h>
  12. #include <FairMCEventHeader.h>
  13. #include <FairMCTrack.h>
  14. #include <MpdEvent.h>
  15. #include <MpdKalmanTrack.h>
  16. #include <MpdVertex.h>
  17. #include <MpdTrack.h>
  18. #include <MpdHelix.h>
  19. #include <iostream>
  20. #include "get_fit.c"
  21. #include "MakeFitDCA.c"
  22. using namespace std;
  23. int GetPtBin(Float_t pt);
  24. int GetEtaBin(Float_t eta);
  25. void get_fit(TString inFileName, TString outFileName);
  26. // const float ptBins[] = {0.,0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.};
  27. // const int NptBins = 12;
  28. // const float etaBins[] = {-1.5,-1.2,-1.,-0.8,-0.6,-0.4,-0.2,0.,0.2,0.4,0.6,0.8,1.,1.2,1.5};
  29. // const int NetaBins = 14;
  30. // const int Ndim = 3;
  31. const Double_t F_CUR0 = 0.3 * 0.01 * 5 / 10; // 5kG
  32. MpdHelix MakeHelix(const MpdKalmanTrack *tr)
  33. {
  34. Double_t r = tr->GetPosNew();
  35. Double_t phi = tr->GetParam(0) / r;
  36. Double_t x = r * TMath::Cos(phi);
  37. Double_t y = r * TMath::Sin(phi);
  38. Double_t dip = tr->GetParam(3);
  39. Double_t cur = F_CUR0 * TMath::Abs (tr->GetParam(4));
  40. TVector3 o(x, y, tr->GetParam(1));
  41. Int_t h = (Int_t) TMath::Sign(1.1,tr->GetParam(4));
  42. MpdHelix helix(cur, dip, tr->GetParam(2)-TMath::PiOver2()*h, o, h);
  43. return helix;
  44. }
  45. void get_dca(TString inFileName , TString outFileName)
  46. {
  47. if (inFileName.IsNull() || outFileName.IsNull())
  48. {
  49. std::cout << "Provide an input/output information!" << std::endl;
  50. return;
  51. }
  52. TStopwatch timer;
  53. timer.Start();
  54. // Init output histograms
  55. TH1F* h_dca[Ndim][NptBins][NetaBins];
  56. char name[200];
  57. char title[200];
  58. for (int dim = 0; dim < Ndim; ++dim)
  59. {
  60. for (int ptbin = 0; ptbin < NptBins; ++ptbin)
  61. {
  62. for (int etabin = 0; etabin < NetaBins; ++etabin)
  63. {
  64. sprintf(name,"h_dca_%i_%i_%i",dim,ptbin,etabin);
  65. sprintf(title,"DCA distribution for %.2f < p_{t} < %.2f and %.2f < #eta < %.2f", ptBins[ptbin], ptBins[ptbin+1],etaBins[etabin],etaBins[etabin+1]);
  66. h_dca[dim][ptbin][etabin] = new TH1F(name,title,4000,-50.,50);
  67. }
  68. }
  69. }
  70. TChain *dstTree = new TChain("mpdsim");
  71. dstTree->Add(inFileName.Data());
  72. TFile *outFile = new TFile(outFileName.Data(),"RECREATE");
  73. MpdEvent *MPDEvent = nullptr;
  74. dstTree->SetBranchAddress("MPDEvent.", &MPDEvent);
  75. // TClonesArray *MpdGlobalTracks = nullptr;
  76. // TClonesArray *mpdKalmanTracks = nullptr; //(TClonesArray*) inFile->FindObjectAny("TpcKalmanTrack");
  77. // dstTree->SetBranchAddress("TpcKalmanTrack", &mpdKalmanTracks);
  78. TClonesArray *vertexes = nullptr; //(TClonesArray*) inFile->FindObjectAny("Vertex");
  79. dstTree->SetBranchAddress("Vertex", &vertexes);
  80. Int_t n_events = dstTree->GetEntries();
  81. //Int_t n_events = 50;
  82. for (int event = 0; event < n_events; ++event)
  83. {
  84. cout << "EVENT N "<< event <<endl;
  85. dstTree->GetEntry(event);
  86. // MpdGlobalTracks = MPDEvent->GetGlobalTracks();
  87. Int_t Ntracks = MPDEvent->GetGlobalTracks()->GetEntriesFast();
  88. // MpdVertex *vertex = (MpdVertex*) vertexes->First();
  89. // TVector3 primaryVertex;
  90. // vertex->Position(primaryVertex);
  91. for (int track = 0; track < Ntracks; ++track)
  92. {
  93. // MpdKalmanTrack *kalmanTrack = (MpdKalmanTrack*) mpdKalmanTracks->UncheckedAt(track);
  94. // DCA stuff
  95. // MpdHelix helix = MakeHelix(kalmanTrack);
  96. // Double_t pathLength = helix.pathLength(primaryVertex);
  97. // TVector3 pca;
  98. // pca = helix.at(pathLength);
  99. // pca -= primaryVertex;
  100. // Double_t dcaX = pca.X();
  101. // Double_t dcaY = pca.Y();
  102. // Double_t dcaZ = pca.Z();
  103. MpdTrack *mpdtrack = (MpdTrack*) MPDEvent->GetGlobalTracks()->UncheckedAt(track);
  104. Int_t pt_bin = GetPtBin(TMath::Abs(mpdtrack->GetPt()));
  105. Int_t eta_bin = GetEtaBin(mpdtrack->GetEta());
  106. if ( (eta_bin == -1) || (pt_bin == -1 )) continue;
  107. h_dca[0][pt_bin][eta_bin]->Fill(mpdtrack->GetDCAX());
  108. h_dca[1][pt_bin][eta_bin]->Fill(mpdtrack->GetDCAY());
  109. h_dca[2][pt_bin][eta_bin]->Fill(mpdtrack->GetDCAZ());
  110. }
  111. }
  112. outFile->cd();
  113. for (int dim = 0; dim < Ndim; ++dim)
  114. {
  115. for (int ptbin = 0; ptbin < NptBins; ++ptbin)
  116. {
  117. for (int etabin = 0; etabin < NetaBins; ++etabin)
  118. {
  119. std::cout << h_dca[dim][ptbin][etabin]->GetName() << " ("
  120. << h_dca[dim][ptbin][etabin]->GetEntries() << " entries)"
  121. << std::endl;
  122. h_dca[dim][ptbin][etabin]->Write();
  123. }
  124. }
  125. }
  126. std::cout << "Closing output file." << std::endl;
  127. outFile->Close();
  128. }
  129. int GetPtBin(Float_t pt)
  130. {
  131. int pt_bin = -1;
  132. for (int i = 0; i < NptBins; ++i)
  133. if ((pt > ptBins[i]) && (pt <= ptBins[i + 1]))
  134. pt_bin = i;
  135. return pt_bin;
  136. }
  137. int GetEtaBin(Float_t eta)
  138. {
  139. int eta_bin = -1;
  140. for (int i = 0; i < NetaBins; ++i)
  141. if ((eta > etaBins[i]) && (eta <= etaBins[i + 1]))
  142. eta_bin = i;
  143. return eta_bin;
  144. }
  145. int main(int argc, char** argv)
  146. {
  147. TString iFileName, oFileName;
  148. Bool_t isFirstFit, isSecondFit;
  149. isFirstFit = kFALSE; isSecondFit = kFALSE;
  150. if (argc < 3){
  151. std::cerr << "./get_dca -i inputfile -o outputfile [--firstfit --secondfit]" << std::endl;
  152. return 1;
  153. }
  154. for (int i=1; i<argc; i++){
  155. if(std::string(argv[i]) != "-i" &&
  156. std::string(argv[i]) != "-o" &&
  157. std::string(argv[i]) != "--firstfit" &&
  158. std::string(argv[i]) != "--secondfit"){
  159. std::cerr << "\n[ERROR]: Unknown parameter " << i << ": " << argv[i] << std::endl;
  160. return 1;
  161. } else {
  162. if(std::string(argv[i]) == "-i" && i!=argc-1) {
  163. iFileName = argv[++i];
  164. continue;
  165. }
  166. if(std::string(argv[i]) == "-i" && i==argc-1) {
  167. std::cerr << "\n[ERROR]: Input file name was not specified " << std::endl;
  168. return 1;
  169. }
  170. if(std::string(argv[i]) == "-o" && i!=argc-1) {
  171. oFileName = argv[++i];
  172. continue;
  173. }
  174. if(std::string(argv[i]) == "-o" && i==argc-1){
  175. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  176. return 1;
  177. }
  178. if(std::string(argv[i]) == "--firstfit") {
  179. isFirstFit = kTRUE;
  180. continue;
  181. }
  182. if(std::string(argv[i]) == "--secondfit"){
  183. isSecondFit = kTRUE;
  184. continue;
  185. }
  186. }
  187. }
  188. if (isFirstFit == kTRUE && isSecondFit == kTRUE){
  189. std::cerr << "\n[ERROR]: Both --firstfit and --secondfit cannot be used at the same time " << std::endl;
  190. return 1;
  191. }
  192. if (isFirstFit == kFALSE && isSecondFit == kFALSE) get_dca(iFileName,oFileName);
  193. if (isFirstFit) get_fit(iFileName,oFileName);
  194. if (isSecondFit) MakeFitDCA(iFileName, oFileName);
  195. return 0;
  196. }