Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:12:25

0001 // Code takes a Sartre  HepMC output and converts it to a MILOU ascii output, which is then built into an EICTree.
0002 
0003 // 4 final state particles
0004 // Scattered electron (KS=2)
0005 // Scattered proton (KS=1)
0006 // Decay electron and positron (KS=1)
0007 // JPsi (KS=1)
0008 int convert_sartre2eictree()
0009 {
0010   TString inputFile("18x275_DVMP_1M_ascii.out");
0011   TString outputFile("18x275_DVMP_1M_ascii_converted.out");
0012   std::ifstream file(inputFile);
0013 
0014 
0015    
0016     std::ofstream output(outputFile);
0017     output << "MILOU\n============================================\nI, ievent, linesnum, weight, genprocess, radcorr,        truex, trueQ2, truey, truet, treuphi, phibelgen, phibelres,       phibelrec\n============================================\nI, K(I,1)  K(I,2)  K(I,3)  K(I,4)  K(I,5)             P(I,1)  P(I,2)  P(I,3)  P(I,4)  P(I,5) V(I,1)  V(I,2)  V(I,3)\n============================================\n";
0018     std::string str; 
0019     std::string file_contents;
0020     int event_count = 0;
0021     int particle_count = 0;
0022     while (std::getline(file, str))
0023     {
0024       file_contents = str;
0025       if(file_contents.size()==0)
0026     continue;
0027       if(file_contents.at(0)=='F')
0028         {
0029       // Search for the Q2
0030       string tmp;            // A string to store the word on each iteration.
0031       stringstream str_strm(file_contents);
0032       vector<string> words;     // Create vector to hold our words
0033       
0034       int counter = 0;
0035       while (str_strm >> tmp) {
0036         if(counter==5)
0037           {
0038         if(tmp.find("e")<tmp.length())
0039           tmp=tmp.replace(tmp.find("e"),1,"E");
0040         break;
0041           }
0042         counter++;
0043       }
0044       output << get_arbitrary_event(event_count++,tmp);
0045       particle_count = 0;
0046       if(event_count%100==0)
0047         {
0048           cout << "Processing Event " << event_count << endl;
0049         }
0050     }
0051       if(file_contents.at(0)=='P')
0052     {
0053       // Found a particle
0054       // See if it is final state
0055       int index_jpsi = file_contents.find(" 443 ");
0056       int index_other = file_contents.find(" 1 0 0 ");
0057       if(index_jpsi>0||index_other>0)
0058         {
0059           output << ++particle_count;
0060           output << "\t";
0061           if(particle_count==1)
0062         {
0063           output<< "2\t";
0064         }
0065           else
0066         {
0067           output << "1\t";
0068         }
0069           string tmp;            // A string to store the word on each iteration.
0070           stringstream str_strm(file_contents);
0071           vector<string> words;     // Create vector to hold our words
0072     
0073           int counter = 0;
0074           while (str_strm >> tmp) {
0075         if(counter==2)
0076           {
0077             output << tmp;
0078             output <<"\t 0 \t 0 \t 0 \t";
0079           }
0080         if(counter>=3&&counter<=7)
0081           {
0082             if(tmp.find("e")<tmp.length())
0083               tmp=tmp.replace(tmp.find("e"),1,"E");
0084             output << tmp;
0085             output << "\t";
0086           }
0087         counter++;
0088           }
0089 
0090           output << "0 \t 0 \t 0\n";
0091         }
0092     }
0093       if(particle_count==5)
0094     {
0095       output<<" =============== Event finished =============== \n";
0096       particle_count=0;
0097     }
0098     }
0099     output.close();
0100     gSystem->Load("$OPT_SPHENIX/eic-smear_root-5.34.36/lib/libeicsmear.so");
0101 
0102     BuildTree(outputFile);
0103 
0104   return 0;
0105 }
0106 
0107 std::string get_arbitrary_event(int x,string Q)
0108 {
0109   std::string alpha;
0110   stringstream ss;
0111   ss << "0" << "\t" << x << "           5   1.00000000               0           0   7.56711757E-04   " << Q << "      0.373815268      0.177931070       0.00000000       2.9 2728496       110.619263     -0.310856074\n ============================================\n";
0112   alpha = ss.str();
0113   return alpha;
0114 }