1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
#include <string>
#include <fstream>
#include <iostream>
#include <math.h>
#include "lhe_Analysis.h"
#define PI 3.1415926536
using namespace std;
int main(){
string fileName;
fileName.clear();
//input your file name here
fileName.assign("ht++2dilepton_02.lhe");
ifstream inFile(fileName.data(), ifstream::in);
ofstream outFile("H++_0.txt", ofstream::out);
string eventPart;
int nStart = -1;
if(inFile.good()){
//read the unuseful head part in the lhe file
while(!inFile.eof() && eventPart.compare("<event>") != 0){
eventPart.clear();
inFile>>eventPart;
}
// ==================================
// Read event from the input file
while(!inFile.eof() && eventPart.compare("<event>") == 0 ) {
int nExternal = 0;
int iEvent = 0;
float wgt = 0.;
float scale = 0.;
float aQed = 0.;
float aQcd = 0.;
float tempFloat = 0.;
inFile>>nExternal>>iEvent>>wgt>>scale>>aQed>>aQcd;
for(int i=0; i<nExternal; i++){
inFile>>lheObj[i].id>>lheObj[i].iStatus>>lheObj[i].iMoth1>>lheObj[i].iMoth2>>lheObj[i].iColfl1>>lheObj[i].iColfl2
>>lheObj[i].px>>lheObj[i].py>>lheObj[i].pz>>lheObj[i].p0>>lheObj[i].mass>>tempFloat>>lheObj[i].helicity;
numlheObj++;
}
//convert lheObj to myJets, myElectrons, myMuons, myTaus
// recognize jets
for(int i=0; i<numlheObj; i++){//for:50
//consider final states only
if(lheObj[i].iStatus!=1) continue;
//consider quark as jets at parton level
if(abs(lheObj[i].id)<=6){
myJets[numJets].p0 = lheObj[i].p0;
myJets[numJets].px = lheObj[i].px;
myJets[numJets].py = lheObj[i].py;
myJets[numJets].pz = lheObj[i].pz;
myJets[numJets].mass = lheObj[i].mass;
myJets[numJets].trueType = lheObj[i].id;
numJets++;
}
}//endfor:50
// ==================================
// Analyze the current event......
numEventJets = 0;
for(int i=0; i<45; i++) {
eventJets[i].clear();
}
for(int i=0; i<numJets; i++){
eventJets[i].p0 = myJets[i].p0;
eventJets[i].px = myJets[i].px;
eventJets[i].py = myJets[i].py;
eventJets[i].pz = myJets[i].pz;
eventJets[i].mass = myJets[i].mass;
eventJets[i].trueType = myJets[i].trueType;
eventJets[i].pt = determinePT(eventJets[i].px, eventJets[i].py);
numEventJets++;
}
//cout the information interested in
outFile<<"eventNumber"<<endl;
outFile<<"etaj0"<<"ptj0"<<"etaj1"<<"ptj1"<<endl;
outFile<<"etal0"<<"ptl0"<<"etal1"<<"ptl1"<<endl;
// ==================================
// After the current event, begin to read next event
while(!inFile.eof() && eventPart.compare("</event>") != 0){
eventPart.clear();
inFile>>eventPart;
}
}
}
return 1;
}
// ============================================================================
void sortJets(const int nJets, recoJet *theJets)
{
recoJet dummyJet;
if (nJets == 0) return;
for (int i = 0; i < nJets - 1; i++)
for (int j = i + 1; j < nJets; j++)
if ( (theJets+j)->pt > (theJets+i)->pt ) {
dummyJet = *(theJets+j);
*(theJets+j) = *(theJets+i);
*(theJets+i) = dummyJet;
}
}
void sortTaus(const int nTaus, visTau *theTaus)
{
visTau dummyTau;
if (nTaus == 0) return;
for (int i = 0; i < nTaus - 1; i++)
for (int j = i+1; j < nTaus; j++)
if ( (theTaus+j)->ptvis > (theTaus+i)->ptvis) {
dummyTau = *(theTaus+j);
*(theTaus+j) = *(theTaus+i);
*(theTaus+i) = dummyTau;
}
}
float determineEta(float p_x, float p_y, float p_z)
{
float theta, eta, p_t;
p_t = sqrt(p_x*p_x + p_y*p_y);
theta = atan(fabs(p_t / p_z));
if(p_z < 0.)
theta = PI - theta;
eta = -log(tan(theta / 2));
return eta;
}
float determinePhi(float p_x, float p_y)
{
float phi;
phi = atan(fabs(p_y / p_x));
if(p_x < 0. && p_y > 0.)
phi = PI - phi;
if(p_x < 0. && p_y < 0.)
phi = PI + phi;
if(p_x > 0. && p_y < 0.)
phi = 2*PI - phi;
return phi;
}
float determineDeltaPhi(float phi1, float phi2)
{
float deltaphi;
deltaphi = fabs(phi1 - phi2);
if(deltaphi > PI)
deltaphi = 2.*PI - deltaphi;
return deltaphi;
}
float determinePT(float p_x, float p_y)
{
float pt;
pt = sqrt(p_x*p_x + p_y*p_y);
return pt;
}
float determineDeltaR(float p1_x, float p1_y, float p1_z, float p2_x, float p2_y, float p2_z)
{
float delR, eta1, eta2, phi1, phi2, delphi;
eta1 = determineEta(p1_x, p1_y, p1_z);
eta2 = determineEta(p2_x, p2_y, p2_z);
phi1 = determinePhi(p1_x, p1_y);
phi2 = determinePhi(p2_x, p2_y);
delphi = fabs(phi1 - phi2);
if(delphi > PI)
delphi = 2.*PI - delphi;
delR = sqrt((eta1 - eta2)*(eta1 - eta2) + delphi*delphi);
return delR;
}
Put the code you need help with here.
|