Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. struct GenieData
  2. {
  3. unsigned int current;
  4. unsigned int intType;
  5. unsigned int incoming;
  6. unsigned int primaryLepton;
  7. unsigned int nFSPart;
  8. unsigned int FSPartPDG[500];
  9.  
  10. double w;
  11. double Q2;
  12. double vtx[4];
  13. double primFSLepton[4];
  14. };
  15.  
  16.  
  17.  
  18.  
  19. //======Reading the Truth File======
  20.  
  21.  
  22. void read_playlist(const char* filename, TChain* chain)
  23. {
  24.  
  25. std::ifstream playlist(filename);
  26. std::string line;
  27.  
  28. if (playlist.is_open()){
  29. while ( std::getline(playlist, line) ){
  30. std::cout << "File: " << line << std::endl;
  31. chain->Add( line.c_str() );
  32.  
  33. }
  34.  
  35. playlist.close();
  36. }
  37.  
  38. }
  39.  
  40. //=======Get Branches=====
  41.  
  42. void get_mc_branches(TChain* chain, GenieData& data){
  43.  
  44.  
  45. chain->SetBranchAddress("mc_intType", &data.intType);
  46. chain->SetBranchAddress("mc_incoming", &data.incoming);
  47. chain->SetBranchAddress("mc_current", &data.current);
  48. chain->SetBranchAddress("mc_primaryLepton", &data.primaryLepton);
  49. chain->SetBranchAddress("mc_nFSPart", &data.nFSPart);
  50. chain->SetBranchAddress("mc_FSPartPDG", &data.FSPartPDG);
  51. chain->SetBranchAddress("mc_w", &data.w);
  52. chain->SetBranchAddress("mc_Q2", &data.Q2);
  53. chain->SetBranchAddress("mc_vtx",&data.vtx);
  54. chain->SetBranchAddress("mc_primFSLepton", &data.primFSLepton);
  55.  
  56.  
  57. }
  58.  
  59.  
  60. //=========Output Branches========
  61.  
  62.  
  63. void set_output_branches(TTree* output, GenieData& data)
  64. {
  65. output->Branch("mc_current", &data.current, "mc_current/I");
  66. output->Branch("mc_intType", &data.intType,"mc_intType/I");
  67. output->Branch("mc_incoming", &data.incoming, "mc_incoming/I");
  68. output->Branch("mc_primaryLepton", &data.primaryLepton, "mc_primaryLepton/I");
  69. output->Branch("mc_nFSPart", &data.nFSPart, "mc_nFSPart/I");
  70. output->Branch("mc_FSPartPDG", &data.FSPartPDG, "mc_FSPartPDG[mc_nFSPart]/I");
  71. output->Branch("mc_w", &data.w, "mc_w/D");
  72. output->Branch("mc_Q2", &data.Q2, "mc_Q2/D");
  73. output->Branch("mc_vtx", &data.vtx, "mc_vtx[4]/D");
  74. output->Branch("mc_primFSLepton", &data.primFSLepton, "mc_primFSLepton[4]/D");
  75. }
  76.  
  77. //=======Genie Histos======
  78.  
  79.  
  80. struct GenieHistos
  81. {
  82. PlotUtils::MnvH1D* Q2;
  83. PlotUtils::MnvH1D* Q2_Res;
  84. PlotUtils::MnvH1D* Q2_Res_pi0;
  85. PlotUtils::MnvH1D* Q2_DES;
  86. PlotUtils::MnvH1D* Q2_DES_pi0;
  87.  
  88. PlotUtils::MnvH1D* w;
  89. PlotUtils::MnvH1D* w_Res;
  90. PlotUtils::MnvH1D* w_Res_pi0;
  91. PlotUtils::MnvH1D* w_DES;
  92. PlotUtils::MnvH1D* w_DES_pi0;
  93.  
  94. PlotUtils::MnvH1D* muonE;
  95. PlotUtils::MnvH1D* muonE_DES;
  96. PlotUtils::MnvH1D* muonE_pi0;
  97. PlotUtils::MnvH1D* muonE_DES_pi0;
  98.  
  99. };
  100.  
  101.  
  102.  
  103. //======Chains=====
  104.  
  105. void truth_minos(){
  106.  
  107. TChain* mc_chain = new TChain("Truth");
  108.  
  109. cout << "Creating the Truth chain" << endl;
  110. read_playlist("MC_playlist.txt", mc_chain);
  111.  
  112. GenieData mc;
  113. get_mc_branches(mc_chain, mc);
  114.  
  115. TFile *output_file = new TFile("truth_minos.root", "RECREATE");
  116. TTree *output_tree = new TTree("truth_minos", "truth_minos");
  117. set_output_branches(output_tree, mc);
  118.  
  119.  
  120. int n_entries = 10000;
  121. for (int i = 0; i < n_entries; i++){
  122. if (i % 100000 == 0) {
  123. cout << "Searching at the TruthMC entry: " << i << "/" << n_entries<< endl;
  124. }
  125.  
  126. mc_chain->GetEntry(i);
  127.  
  128. }
  129.  
  130. output_tree->Print();
  131. output_tree->Write();
  132.  
  133. output_file->Write();
  134. output_file->Clear();
  135. output_file->Close();
  136.  
  137.  
  138. }
  139.  
  140.  
  141.  
  142. //=======this is the end, my friend, the end=======
  143.  
  144. int main(int argc, char** argv)
  145. {
  146. truth_minos();
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement