Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:15:17

0001 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0002   Convert .txt file into ROOT tree and store in .root file.
0003   Includes routines to handle data given by Goloskokov & Kroll,
0004   and data from http://rprmodel.ugent.be/calc/
0005   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
0006 
0007 #include <iostream>
0008 #include <fstream>
0009 #include <string>
0010 #include <algorithm>
0011 #include <sstream>
0012 #include <iomanip>
0013 
0014 #include "TFile.h"
0015 #include "TTree.h"
0016 
0017 using namespace std;
0018 
0019 void GKConvert(string in_filepath, string out_filepath){
0020   ifstream in_filestream;
0021 
0022   in_filestream.open(in_filepath.c_str());
0023 
0024   if (! in_filestream){
0025     cout << "File not Found" << endl;
0026     exit(1);
0027   }
0028 
0029   //Skip to Data
0030   string line;
0031   int i;
0032   for (i = 0; i < 18; i++) {
0033     getline(in_filestream, line);
0034   }
0035 
0036   //Create a tree
0037   TFile out_TFile(out_filepath.c_str(), "UPDATE");
0038 
0039   gDirectory->Delete("GK_Raw;*");
0040   //This ensures only the most recent tree in in the file
0041 
0042   TTree GK_Raw("GK_Raw", "Asymmetry Data");
0043 
0044   //Initialize variables for each data column
0045   Double_t w, q2, tp, t, asy, asysfi, asy2fi, asyfpfs, asy3f;
0046 
0047   //Create branches for each variable
0048   GK_Raw.Branch("w", &w, "w/D");
0049   GK_Raw.Branch("q2", &q2, "q2/D");
0050   GK_Raw.Branch("tp", &tp, "tp/D");
0051   GK_Raw.Branch("t",&t,"t/D");
0052   GK_Raw.Branch("asy",&asy,"asy/D");
0053   GK_Raw.Branch("asysfi",&asysfi,"asysfi/D");
0054   GK_Raw.Branch("asy2fi",&asy2fi,"asy2fi/D");
0055   GK_Raw.Branch("asyfpfs",&asyfpfs,"asyfpfs/D");
0056   GK_Raw.Branch("asy3f",&asy3f,"asy3f/D");
0057 
0058   //Fill the tree
0059   while (!in_filestream.eof()) {
0060     in_filestream >> w >> q2 >> tp >> t >> asy >> asysfi >> asy2fi
0061                   >> asyfpfs >> asy3f;
0062     //cout << w << "\t" << q2 << "\t" << tp <<"\t";
0063     //cout << t << "\t" << asy << "\t" << asysfi << "\t";
0064     //cout << asy2fi << "\t" << asyfpfs << "\t" << asy3f;
0065     //cout << endl;
0066     GK_Raw.Fill();
0067   }
0068 
0069   GK_Raw.Write();
0070 }
0071 
0072 void VR_SigL(string in_filepath, string out_filepath){
0073   ifstream in_filestream;
0074 
0075   in_filestream.open(in_filepath.c_str());
0076 
0077   if (! in_filestream){
0078     cout << "File not Found" << endl;
0079     exit(1);
0080   }
0081 
0082   //Skip to Data
0083   string line;
0084   int i;
0085   for (i = 0; i < 3; i++) {
0086     getline(in_filestream, line);
0087   }
0088 
0089   //Create a tree
0090   TFile out_TFile(out_filepath.c_str(), "UPDATE");
0091 
0092   gDirectory->Delete("VR_SigL_Raw;*");
0093   //This ensures only the most recent tree in in the file
0094 
0095   TTree VR_SigL_Raw("VR_SigL_Raw", "VR Model");
0096 
0097   //Initialize variables for each data column
0098   Double_t Q2, W, Negt, sigL;
0099 
0100   //Create branches for each variable
0101   VR_SigL_Raw.Branch("Q2", &Q2, "Q2/D");
0102   VR_SigL_Raw.Branch("W", &W, "W/D");
0103   VR_SigL_Raw.Branch("Negt", &Negt, "-t/D");
0104   VR_SigL_Raw.Branch("dsig_L",&sigL,"dsig_L/D");
0105 
0106   //Fill the tree
0107   while (!in_filestream.eof()) {
0108     in_filestream >> Q2 >> W >> Negt >> sigL;
0109     VR_SigL_Raw.Fill();
0110   }
0111 
0112   VR_SigL_Raw.Write();
0113 }
0114 
0115 
0116 void AsyPars(string in_filepath, string out_filepath,
0117              string asyname, int nPars)
0118 {
0119   ifstream in_filestream;
0120 
0121   in_filestream.open(in_filepath.c_str());
0122 
0123   if (! in_filestream){
0124     cout << "File not Found" << endl;
0125     exit(1);
0126   }
0127 
0128 
0129   //Create a tree
0130   TFile out_TFile(out_filepath.c_str(), "UPDATE");
0131 
0132   TTree t1(asyname.c_str(), "Asymmetry");
0133 
0134   double pars[nPars];
0135   double Qsq;
0136 
0137   char llist[100] = "pars[%d]/D";
0138   char temp[100];
0139 
0140   sprintf(temp, llist, nPars);
0141 
0142   t1.Branch("Qsq",&Qsq,"Qsq/D");
0143   t1.Branch("pars",&pars,temp);
0144 
0145   while(!in_filestream.eof()){
0146     in_filestream >> Qsq;
0147     for (int i=0; i<nPars; i++){
0148       in_filestream >> pars[i];
0149     }
0150     t1.Fill();
0151   }
0152 
0153   t1.Write();
0154 }
0155 
0156 void AsyAll()
0157 {
0158   AsyPars("../data/input/asyout.txt",
0159           "../data/output/test.root",
0160           "asy",
0161           4);
0162   AsyPars("../data/input/asysfiout.txt",
0163           "../data/output/test.root",
0164           "asysfi",
0165           3);
0166   AsyPars("../data/input/asy2fiout.txt",
0167           "../data/output/test.root",
0168           "asy2fi",
0169           3);
0170   AsyPars("../data/input/asyfpfsout.txt",
0171           "../data/output/test.root",
0172           "asyfpfs",
0173           3);
0174   AsyPars("../data/input/asy3fout.txt",
0175           "../data/output/test.root",
0176           "asy3f",
0177           3);
0178 }