G2A Many GEOs
SHARE
TWEET

20200407_Run15pp200_save_small_tree.C

a guest Apr 8th, 2020 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define Run15pp200_cxx
  2. #include "Run15pp200.h"
  3. #include <TH2.h>
  4. #include <TStyle.h>
  5. #include <TVector.h>
  6. #include <TTree.h>
  7. #include <TMath.h>
  8.  
  9. //This code is for saving small tree which contents variables below with track and dimuon trigger selection
  10. //Also contents boolin value of muon candidate
  11.  
  12. // Event level variable
  13. double vtxz;
  14. double vpdvz;
  15. double bbcx;
  16. // Track level variable
  17. int ntrk;
  18. vector<double> dca;
  19. vector<double> dedx;
  20. vector<double> charge;
  21. vector<double> pt;
  22. vector<double> eta;
  23. vector<double> phi;
  24. vector<double> nSigmaPion;
  25. vector<double> nSigmaKaon;
  26. vector<double> nSigmaProton;
  27. // MTD variable
  28. vector<double> deltaY;
  29. vector<double> deltaZ;
  30. vector<double> deltaToF;
  31. // ToF variable
  32. vector<int> ToF_matchFlag;
  33. vector<double> ToF;
  34. vector<double> beta;
  35. vector<bool> isMuon;
  36.  
  37. TFile *output = new TFile("Run15pp200.root", "recreate");
  38. TTree *MyTree = new TTree("MyTree","MyTree");
  39.  
  40. int BadRunEvent[219];
  41. // Check whether this run is bad run or not
  42. bool CheckBadRun(int Run)
  43. {
  44.     bool Bad = false;
  45.     for(int i = 0; i < 219; i++)
  46.     {
  47.         if(Run == BadRunEvent[i]) Bad = true;
  48.     }
  49.    
  50.     return Bad;
  51. }
  52.  
  53. // Check muon candidate
  54. bool CheckMuon(float pt, float eta, float mtd_match)
  55. {
  56.     bool muon = false;
  57.     if(pt>1.3 && fabs(eta)<0.5 && mtd_match > 0) muon = true;
  58.    
  59.     return muon;
  60. }
  61.  
  62. void Run15pp200::Begin(TTree * /*tree*/)
  63. {
  64.    // The Begin() function is called at the start of the query.
  65.    // When running with PROOF Begin() is only called on the client.
  66.    // The tree argument is deprecated (on PROOF 0 is passed).
  67.  
  68.     TString option = GetOption();
  69.  
  70.     // Event level variable
  71.     MyTree->Branch("vtxz", &vtxz, "vtxz/D");
  72.     MyTree->Branch("vpdvz", &vpdvz, "vpdvz/D");
  73.     MyTree->Branch("bbcx", &bbcx, "bbcx/D");
  74.     MyTree->Branch("ntrk", &ntrk, "ntrk/I");
  75.     // Track level variable
  76.     MyTree->Branch("dca", &dca);
  77.     MyTree->Branch("dedx", &dedx);
  78.     MyTree->Branch("charge", &charge);
  79.     MyTree->Branch("pt", &pt);
  80.     MyTree->Branch("eta", &eta);
  81.     MyTree->Branch("phi", &phi);
  82.     MyTree->Branch("nSigmaPion", &nSigmaPion);
  83.     MyTree->Branch("nSigmaKaon", &nSigmaKaon);
  84.     MyTree->Branch("nSigmaProton", &nSigmaProton);
  85.     // MTD variable
  86.     MyTree->Branch("deltaY", &deltaY);
  87.     MyTree->Branch("deltaZ", &deltaZ);
  88.     MyTree->Branch("deltaToF", &deltaToF);
  89.     // ToF variable
  90.     MyTree->Branch("ToF_matchFlag", &ToF_matchFlag);
  91.     MyTree->Branch("ToF", &ToF);
  92.     MyTree->Branch("beta", &beta);
  93.     MyTree->Branch("isMuon", &isMuon);
  94.    
  95.     // Bad run event number (Bad run list from Rongrong's report in 2019/9/12 MTD meeting)
  96.     BadRunEvent[0] = 16046039;
  97.     BadRunEvent[1] = 16046040;
  98.     BadRunEvent[2] = 16046041;
  99.     BadRunEvent[3] = 16046042;
  100.     BadRunEvent[4] = 16046043;
  101.     BadRunEvent[5] = 16046044;
  102.     BadRunEvent[6] = 16046045;
  103.     BadRunEvent[7] = 16046046;
  104.     BadRunEvent[8] = 16046048;
  105.     BadRunEvent[9] = 16046049;
  106.     BadRunEvent[10] = 16046050;
  107.     BadRunEvent[11] = 16046057;
  108.     BadRunEvent[12] = 16046058;
  109.     BadRunEvent[13] = 16046059;
  110.     BadRunEvent[14] = 16046061;
  111.     BadRunEvent[15] = 16046062;
  112.     BadRunEvent[16] = 16046064;
  113.     BadRunEvent[17] = 16046065;
  114.     BadRunEvent[18] = 16046066;
  115.     BadRunEvent[19] = 16046067;
  116.    
  117.     BadRunEvent[20] = 16046073;
  118.     BadRunEvent[21] = 16046074;
  119.     BadRunEvent[22] = 16046075;
  120.     BadRunEvent[23] = 16046076;
  121.     BadRunEvent[24] = 16046077;
  122.     BadRunEvent[25] = 16046078;
  123.     BadRunEvent[26] = 16046080;
  124.     BadRunEvent[27] = 16046081;
  125.     BadRunEvent[28] = 16046082;
  126.     BadRunEvent[29] = 16046083;
  127.     BadRunEvent[30] = 16047004;
  128.     BadRunEvent[31] = 16047005;
  129.     BadRunEvent[32] = 16047008;
  130.     BadRunEvent[33] = 16047101;
  131.     BadRunEvent[34] = 16047102;
  132.     BadRunEvent[35] = 16047103;
  133.     BadRunEvent[36] = 16047104;
  134.     BadRunEvent[37] = 16047106;
  135.     BadRunEvent[38] = 16047108;
  136.     BadRunEvent[39] = 16047121;
  137.    
  138.     BadRunEvent[40] = 16047122;
  139.     BadRunEvent[41] = 16047124;
  140.     BadRunEvent[42] = 16047125;
  141.     BadRunEvent[43] = 16047126;
  142.     BadRunEvent[44] = 16047131;
  143.     BadRunEvent[45] = 16047136;
  144.     BadRunEvent[46] = 16047137;
  145.     BadRunEvent[47] = 16047138;
  146.     BadRunEvent[48] = 16048001;
  147.     BadRunEvent[49] = 16048002;
  148.     BadRunEvent[50] = 16048003;
  149.     BadRunEvent[51] = 16048004;
  150.     BadRunEvent[52] = 16048009;
  151.     BadRunEvent[53] = 16048014;
  152.     BadRunEvent[54] = 16048015;
  153.     BadRunEvent[55] = 16048016;
  154.     BadRunEvent[56] = 16048017;
  155.     BadRunEvent[57] = 16048018;
  156.     BadRunEvent[58] = 16048019;
  157.     BadRunEvent[59] = 16048022;
  158.    
  159.     BadRunEvent[60] = 16048023;
  160.     BadRunEvent[61] = 16048024;
  161.     BadRunEvent[62] = 16048025;
  162.     BadRunEvent[63] = 16048026;
  163.     BadRunEvent[64] = 16048027;
  164.     BadRunEvent[65] = 16048028;
  165.     BadRunEvent[66] = 16048109;
  166.     BadRunEvent[67] = 16048110;
  167.     BadRunEvent[68] = 16048111;
  168.     BadRunEvent[69] = 16048115;
  169.     BadRunEvent[70] = 16048116;
  170.     BadRunEvent[71] = 16048117;
  171.     BadRunEvent[72] = 16048118;
  172.     BadRunEvent[73] = 16048119;
  173.     BadRunEvent[74] = 16048120;
  174.     BadRunEvent[75] = 16048121;
  175.     BadRunEvent[76] = 16048122;
  176.     BadRunEvent[77] = 16048125;
  177.     BadRunEvent[78] = 16048126;
  178.     BadRunEvent[79] = 16048127;
  179.    
  180.     BadRunEvent[80] = 16048128;
  181.     BadRunEvent[81] = 16049010;
  182.     BadRunEvent[82] = 16049012;
  183.     BadRunEvent[83] = 16049013;
  184.     BadRunEvent[84] = 16049017;
  185.     BadRunEvent[85] = 16049018;
  186.     BadRunEvent[86] = 16049020;
  187.     BadRunEvent[87] = 16049022;
  188.     BadRunEvent[88] = 16049023;
  189.     BadRunEvent[89] = 16049024;
  190.     BadRunEvent[90] = 16049025;
  191.     BadRunEvent[91] = 16050044;
  192.     BadRunEvent[92] = 16050048;
  193.     BadRunEvent[93] = 16051026;
  194.     BadRunEvent[94] = 16051029;
  195.     BadRunEvent[95] = 16051104;
  196.     BadRunEvent[96] = 16052036;
  197.     BadRunEvent[97] = 16052037;
  198.     BadRunEvent[98] = 16052038;
  199.     BadRunEvent[99] = 16053054;
  200.    
  201.     BadRunEvent[100] = 16054059;
  202.     BadRunEvent[101] = 16054060;
  203.     BadRunEvent[102] = 16054061;
  204.     BadRunEvent[103] = 16054062;
  205.     BadRunEvent[104] = 16054063;
  206.     BadRunEvent[105] = 16054064;
  207.     BadRunEvent[106] = 16054069;
  208.     BadRunEvent[107] = 16054070;
  209.     BadRunEvent[108] = 16054072;
  210.     BadRunEvent[109] = 16054073;
  211.     BadRunEvent[110] = 16054074;
  212.     BadRunEvent[111] = 16054075;
  213.     BadRunEvent[112] = 16054077;
  214.     BadRunEvent[113] = 16054078;
  215.     BadRunEvent[114] = 16054079;
  216.     BadRunEvent[115] = 16054080;
  217.     BadRunEvent[116] = 16054082;
  218.     BadRunEvent[117] = 16054086;
  219.     BadRunEvent[118] = 16054087;
  220.     BadRunEvent[119] = 16055002;
  221.    
  222.     BadRunEvent[120] = 16055003;
  223.     BadRunEvent[121] = 16055004;
  224.     BadRunEvent[122] = 16055005;
  225.     BadRunEvent[123] = 16055007;
  226.     BadRunEvent[124] = 16055010;
  227.     BadRunEvent[125] = 16055011;
  228.     BadRunEvent[126] = 16055012;
  229.     BadRunEvent[127] = 16055013;
  230.     BadRunEvent[128] = 16055018;
  231.     BadRunEvent[129] = 16055019;
  232.     BadRunEvent[130] = 16055021;
  233.     BadRunEvent[131] = 16055022;
  234.     BadRunEvent[132] = 16055024;
  235.     BadRunEvent[133] = 16055025;
  236.     BadRunEvent[134] = 16055124;
  237.     BadRunEvent[135] = 16055127;
  238.     BadRunEvent[136] = 16058072;
  239.     BadRunEvent[137] = 16060018;
  240.     BadRunEvent[138] = 16060025;
  241.     BadRunEvent[139] = 16060036;
  242.  
  243.     BadRunEvent[140] = 16060053;
  244.     BadRunEvent[141] = 16060054;
  245.     BadRunEvent[142] = 16060055;
  246.     BadRunEvent[143] = 16060056;
  247.     BadRunEvent[144] = 16060057;
  248.     BadRunEvent[145] = 16060058;
  249.     BadRunEvent[146] = 16060059;
  250.     BadRunEvent[147] = 16060060;
  251.     BadRunEvent[148] = 16060061;
  252.     BadRunEvent[149] = 16060062;
  253.     BadRunEvent[150] = 16060063;
  254.     BadRunEvent[151] = 16060064;
  255.     BadRunEvent[152] = 16060065;
  256.     BadRunEvent[153] = 16062008;
  257.     BadRunEvent[154] = 16062009;
  258.     BadRunEvent[155] = 16062011;
  259.     BadRunEvent[156] = 16062014;
  260.     BadRunEvent[157] = 16063096;
  261.     BadRunEvent[158] = 16063097;
  262.     BadRunEvent[159] = 16063099;
  263.  
  264.     BadRunEvent[160] = 16065011;
  265.     BadRunEvent[161] = 16065059;
  266.     BadRunEvent[162] = 16066028;
  267.     BadRunEvent[163] = 16069045;
  268.     BadRunEvent[164] = 16069050;
  269.     BadRunEvent[165] = 16069060;
  270.     BadRunEvent[166] = 16071043;
  271.     BadRunEvent[167] = 16071044;
  272.     BadRunEvent[168] = 16072046;
  273.     BadRunEvent[169] = 16072047;
  274.     BadRunEvent[170] = 16073004;
  275.     BadRunEvent[171] = 16073007;
  276.     BadRunEvent[172] = 16073015;
  277.     BadRunEvent[173] = 16082014;
  278.     BadRunEvent[174] = 16083003;
  279.     BadRunEvent[175] = 16083044;
  280.     BadRunEvent[176] = 16084003;
  281.     BadRunEvent[177] = 16084011;
  282.     BadRunEvent[178] = 16084017;
  283.     BadRunEvent[179] = 16085005;
  284.  
  285.     BadRunEvent[180] = 16087018;
  286.     BadRunEvent[181] = 16088013;
  287.     BadRunEvent[182] = 16088039;
  288.     BadRunEvent[183] = 16089002;
  289.     BadRunEvent[184] = 16089014;
  290.     BadRunEvent[185] = 16091039;
  291.     BadRunEvent[186] = 16091040;
  292.     BadRunEvent[187] = 16091057;
  293.     BadRunEvent[188] = 16091058;
  294.     BadRunEvent[189] = 16091059;
  295.     BadRunEvent[190] = 16091061;
  296.     BadRunEvent[191] = 16094018;
  297.     BadRunEvent[192] = 16095027;
  298.     BadRunEvent[193] = 16095031;
  299.     BadRunEvent[194] = 16095034;
  300.     BadRunEvent[195] = 16097028;
  301.     BadRunEvent[196] = 16098007;
  302.     BadRunEvent[197] = 16100023;
  303.     BadRunEvent[198] = 16100024;
  304.     BadRunEvent[199] = 16100025;
  305.  
  306.     BadRunEvent[200] = 16101018;
  307.     BadRunEvent[201] = 16102053;
  308.     BadRunEvent[202] = 16104046;
  309.     BadRunEvent[203] = 16105044;
  310.     BadRunEvent[204] = 16106024;
  311.     BadRunEvent[205] = 16106033;
  312.     BadRunEvent[206] = 16107004;
  313.     BadRunEvent[207] = 16107042;
  314.     BadRunEvent[208] = 16108026;
  315.     BadRunEvent[209] = 16109010;
  316.     BadRunEvent[210] = 16109011;
  317.     BadRunEvent[211] = 16109012;
  318.     BadRunEvent[212] = 16110005;
  319.     BadRunEvent[213] = 16110006;
  320.     BadRunEvent[214] = 16114032;
  321.     BadRunEvent[215] = 16114034;
  322.     BadRunEvent[216] = 16115001;
  323.     BadRunEvent[217] = 16115002;
  324.     BadRunEvent[218] = 16115056;
  325. }
  326.  
  327. void Run15pp200::SlaveBegin(TTree * /*tree*/)
  328. {
  329.    // The SlaveBegin() function is called after the Begin() function.
  330.    // When running with PROOF SlaveBegin() is called on each slave server.
  331.    // The tree argument is deprecated (on PROOF 0 is passed).
  332.  
  333.    TString option = GetOption();
  334.  
  335. }
  336.  
  337. Bool_t Run15pp200::Process(Long64_t entry)
  338. {
  339.    // The Process() function is called for each entry in the tree (or possibly
  340.    // keyed object in the case of PROOF) to be processed. The entry argument
  341.    // specifies which entry in the currently loaded tree is to be processed.
  342.    // It can be passed to either Run15pp200::GetEntry() or TBranch::GetEntry()
  343.    // to read either all or the required parts of the data. When processing
  344.    // keyed objects with PROOF, the object is already loaded and is available
  345.    // via the fObject pointer.
  346.    //
  347.    // This function should contain the "body" of the analysis. It can contain
  348.    // simple or elaborate selection criteria, run algorithms on the data
  349.    // of the event and typically fill histograms.
  350.    //
  351.    // The processing can be stopped by calling Abort().
  352.    //
  353.    // Use fStatus to set the return value of TTree::Process().
  354.    //
  355.    // The return value is currently not used.
  356.  
  357.     fChain->GetTree()->GetEntry(entry);
  358.  
  359.     // Initialize variables
  360.     vtxz = -999;
  361.     vpdvz = -999;
  362.     bbcx = 0;
  363.     ntrk = 0;
  364.    
  365.     dca.clear();
  366.     dedx.clear();
  367.     charge.clear();
  368.     pt.clear();
  369.     eta.clear();
  370.     phi.clear();
  371.     nSigmaPion.clear();
  372.     nSigmaKaon.clear();
  373.     nSigmaProton.clear();
  374.    
  375.     deltaY.clear();
  376.     deltaZ.clear();
  377.     deltaToF.clear();
  378.    
  379.     ToF_matchFlag.clear();
  380.     ToF.clear();
  381.     beta.clear();
  382.     isMuon.clear();
  383.    
  384.     // Dimuon trigger number
  385.     bool DiMuTrigger = false;
  386.  
  387.     for(int i = 0 ; i < evt_triggerid->size() ; i++)
  388.     {
  389.         if(evt_triggerid->at(i) == 470602 || evt_triggerid->at(i) == 480602 || evt_triggerid->at(i) == 490602)
  390.     DiMuTrigger = true;
  391.     }
  392.  
  393.     //Event level selection
  394.     bool BadRun = CheckBadRun(evt_runId);
  395.  
  396.     if(BadRun == true) return kTRUE;
  397.     if(DiMuTrigger == false) return kTRUE;
  398.     if(TMath::Abs(evt_priVtxZ) > 100) return kTRUE;
  399.     if(TMath::Abs(evt_priVtxZ - evt_vpdVz) > 6) return kTRUE;
  400.  
  401.     vtxz = evt_priVtxZ;
  402.     vpdvz = evt_vpdVz;
  403.     bbcx = evt_BBCx;
  404.     ntrk = trk_nTrk;
  405.  
  406.     // Track quality selection
  407.     for(int i = 0 ; i < trk_nGoodTrk ; i++)
  408.     {  
  409.         if(trk_nHitsFit->at(i) < 15) continue;
  410.         if(trk_nHitsDedx->at(i) < 10) continue;
  411.         if(((Float_t)trk_nHitsFit->at(i)/(Float_t)trk_nHitsMax->at(i) ) < 0.52) continue;
  412.        
  413.         if(trk_Ppt->at(i) < 0.1) continue;
  414.         if(TMath::Abs(trk_Peta->at(i) ) > 1) continue;
  415.         if(trk_dca->at(i) >= 3) continue;
  416.  
  417.         bool ismuon = CheckMuon(trk_Ppt->at(i), trk_Peta->at(i), mtd_matchFlag->at(i));
  418.  
  419.         dca.push_back(trk_dca->at(i));
  420.         dedx.push_back(trk_dedx->at(i));
  421.         charge.push_back(trk_charge->at(i));
  422.         pt.push_back(trk_Ppt->at(i));
  423.         eta.push_back(trk_Peta->at(i));
  424.         phi.push_back(trk_Pphi->at(i));
  425.         nSigmaPion.push_back(trk_nSigmaPion->at(i));
  426.         nSigmaKaon.push_back(trk_nSigmaKaon->at(i));
  427.         nSigmaProton.push_back(trk_nSigmaProton->at(i));
  428.        
  429.         deltaY.push_back(mtd_deltaY->at(i));
  430.         deltaZ.push_back(mtd_deltaZ->at(i));
  431.         deltaToF.push_back(mtd_deltaTimeOfFlight->at(i));
  432.        
  433.         ToF_matchFlag.push_back(tof_matchFlag->at(i));
  434.         ToF.push_back(tof_tof->at(i));
  435.         beta.push_back(tof_beta->at(i));
  436.        
  437.         isMuon.push_back(ismuon);
  438.     }
  439.    
  440.     if(pt.size() != 0) MyTree->Fill();
  441.  
  442.     return kTRUE;
  443. }
  444.  
  445. void Run15pp200::SlaveTerminate()
  446. {
  447.    // The SlaveTerminate() function is called after all entries or objects
  448.    // have been processed. When running with PROOF SlaveTerminate() is called
  449.    // on each slave server.
  450.  
  451. }
  452.  
  453. void Run15pp200::Terminate()
  454. {
  455.    // The Terminate() function is the last function to be called during
  456.    // a query. It always runs on the client, it can be used to present
  457.    // the results graphically or save the results to file.
  458.  
  459.     MyTree->Write();
  460.     output->Close();
  461.  
  462. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top