Angular analysis of B+->K*+(K+pi0)mumu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.6 KiB

  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. #include <sstream>
  5. #include <TFile.h>
  6. #include <TTree.h>
  7. #include <vector>
  8. //Compile with g++ -std=c++11 testCpp.cc -o test; ./test
  9. std::string convert_vector_to_string(std::vector<double> myVector){
  10. std::stringstream ss;
  11. copy(myVector.begin(), myVector.end(), std::ostream_iterator<double>(ss, " "));
  12. std::string s = ss.str();
  13. return s.substr(0, s.length()-1); // get rid of the trailing space
  14. }
  15. int try_getObservable(std::string observable, TFile* file){
  16. if (!file->GetListOfKeys()->Contains(observable.c_str())){
  17. //Also check if Fl<->S1s and A_FB<->S6s is available
  18. if (observable == "Fl") return 10+try_getObservable("S1s",file);
  19. if (observable == "S1s") return 20+try_getObservable("Fl",file);
  20. if (observable == "Afb") return 30+try_getObservable("S6s",file);
  21. if (observable == "S6s") return 40+try_getObservable("Afb",file);
  22. return 0;
  23. }
  24. else return 1;
  25. }
  26. std::vector<double> load_param_values_into_vector(std::string paramName, std::string fileName){
  27. //There is a function for this in bu2kstarmumu_parameters.cc, but that is inherited from parameters, therefore a parameter class needs to be created for this
  28. //That would be tedious, so there is a new class that opens the root file with results and reads it from a tree directly into an array
  29. //Create the vector that will be returned
  30. std::vector<double> output;
  31. //Open file
  32. std::cout << "Opening " << fileName <<std::endl;
  33. TFile* file = new TFile(fileName.c_str(), "READ");
  34. int isFoundFlag = try_getObservable(paramName, file);
  35. std::cout << isFoundFlag << std::endl;
  36. //Get the tree
  37. TTree* tree = (TTree*)file->Get(paramName.c_str());
  38. //Activate only needed branches
  39. tree->SetBranchStatus("*",0);
  40. tree->SetBranchStatus("value",1);
  41. double value = 0;
  42. tree->SetBranchAddress("value", &value);
  43. //Loop over nBins that are saved in the tree
  44. for (int wait = 0; wait < 10; wait++){ //Make the code stall for a bit
  45. for (int b = 0; b < tree->GetEntries(); b++){
  46. tree->GetEntry(b);
  47. output.push_back(value);
  48. }
  49. }
  50. std::cout << convert_vector_to_string(output) << std::endl;
  51. return output;
  52. }
  53. using namespace std; //I know it is not safe, but ef it
  54. int main() {
  55. cout << "Hello World!" << endl;
  56. load_param_values_into_vector("S3",
  57. "/home/lhcb/kopecna/B2KstarMuMu/code/ewp-Bplus2Kstmumu-AngAna/FCNCfitter/fitResults/GenLvlFit/finalresultgenLvl_MC_SignalFit_ALLBINS_OnlyAngles.root");
  58. }