[8] | 1 |
|
---|
| 2 | #include <iostream>
|
---|
| 3 | #include <fstream>
|
---|
| 4 | #include <sstream>
|
---|
| 5 | #include <map>
|
---|
| 6 |
|
---|
| 7 | #include "TROOT.h"
|
---|
| 8 | #include "TApplication.h"
|
---|
| 9 |
|
---|
| 10 | #include "TFile.h"
|
---|
| 11 | #include "TChain.h"
|
---|
| 12 | #include "TString.h"
|
---|
| 13 |
|
---|
| 14 | #include "TH2.h"
|
---|
| 15 | #include "THStack.h"
|
---|
| 16 | #include "TLegend.h"
|
---|
| 17 | #include "TPaveText.h"
|
---|
| 18 | #include "TLorentzVector.h"
|
---|
| 19 |
|
---|
[10] | 20 | #include "TClonesArray.h"
|
---|
| 21 |
|
---|
[8] | 22 | #include "ExRootAnalysis/ExRootClasses.h"
|
---|
| 23 |
|
---|
| 24 | #include "ExRootAnalysis/ExRootTreeReader.h"
|
---|
| 25 |
|
---|
| 26 | #include "ExRootAnalysis/ExRootUtilities.h"
|
---|
| 27 | #include "ExRootAnalysis/ExRootProgressBar.h"
|
---|
| 28 |
|
---|
| 29 | using namespace std;
|
---|
| 30 |
|
---|
| 31 | /*
|
---|
| 32 | LHC Olympics format discription from http://www.jthaler.net/olympicswiki/doku.php?id=lhc_olympics:data_file_format
|
---|
| 33 |
|
---|
| 34 | * The first column of each row is just a counter that labels the object.
|
---|
| 35 | * The event begins with a row labelled "0"; this row contains the event number and the triggering information. The last row of the event is always the missing transverse momentum (MET).
|
---|
| 36 | * The second column of each row gives the type of object being listed [0, 1, 2, 3, 4, 6 = photon, electron, muon, hadronically-decaying tau, jet, missing transverse energy].
|
---|
| 37 | * The next three columns give the pseudorapidity, the azimuthal angle, and the transverse momentum of the object.
|
---|
| 38 | * The sixth column gives the invariant mass of the object.
|
---|
| 39 | * The seventh column gives the number of tracks associated with the object; in the case of a lepton, this number is multiplied by the charge of the lepton.
|
---|
| 40 | * The eighth column is 1 or 2 for a jet that has been "tagged" as containing a b-quark (actually a heavy flavor tag that sometimes indicates c-quarks), otherwise it is 0. For muons, the integer part of this number is the identity of the jet (see column 1) that is closest ot this muon in Delta R.
|
---|
| 41 | * The ninth column is the ratio of the hadronic versus electromagnetic energy deposited in the calorimeter cells associated with the object. For muons to the left of the decimal point is the summed pT in a R=0.4 cone (excluding the muon). To the right of the decimal point is etrat, which is a percentage between .00 and .99. It is the ratio of the transverse energy in a 3x3 grid surrounding the muon to the pT of the muon.
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | struct LHCOlympicsObject
|
---|
| 45 | {
|
---|
| 46 | enum {maxIntParam = 2, maxDblParam = 9};
|
---|
| 47 |
|
---|
| 48 | Int_t intParam[maxIntParam];
|
---|
| 49 | Double_t dblParam[maxDblParam];
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | //------------------------------------------------------------------------------
|
---|
| 53 |
|
---|
| 54 | class LHCOlympicsWriter
|
---|
| 55 | {
|
---|
| 56 | public:
|
---|
| 57 | LHCOlympicsWriter(ExRootTreeReader *treeReader,
|
---|
| 58 | ofstream *outputStream);
|
---|
| 59 | ~LHCOlympicsWriter();
|
---|
| 60 |
|
---|
| 61 | void ProcessEvent();
|
---|
| 62 |
|
---|
| 63 | private:
|
---|
| 64 |
|
---|
| 65 | void ResetLHCOlympicsObject();
|
---|
| 66 | void WriteLHCOlympicsObject();
|
---|
| 67 |
|
---|
| 68 | void AnalyseEvent();
|
---|
| 69 |
|
---|
| 70 | void AnalysePhotons();
|
---|
| 71 | void AnalyseElectrons();
|
---|
| 72 | void AnalyseMuons();
|
---|
| 73 | void AnalyseTaus();
|
---|
| 74 | void AnalyseJets();
|
---|
| 75 |
|
---|
| 76 | void AnalyseMissingET();
|
---|
| 77 |
|
---|
| 78 | LHCOlympicsObject fCurrentObject;
|
---|
| 79 |
|
---|
| 80 | Long64_t fTriggerWord, fEventNumber;
|
---|
| 81 |
|
---|
| 82 | ExRootTreeReader *fTreeReader;
|
---|
| 83 | ofstream *fOutputStream;
|
---|
| 84 |
|
---|
| 85 | TClonesArray *fBranchEvent;
|
---|
| 86 | TClonesArray *fBranchPhoton;
|
---|
| 87 | TClonesArray *fBranchElectron;
|
---|
| 88 | TClonesArray *fBranchMuon;
|
---|
| 89 | TClonesArray *fBranchTau;
|
---|
| 90 | TClonesArray *fBranchJet;
|
---|
| 91 | TClonesArray *fBranchMissingET;
|
---|
| 92 |
|
---|
| 93 | TIterator *fItPhoton;
|
---|
| 94 | TIterator *fItElectron;
|
---|
| 95 | TIterator *fItMuon;
|
---|
| 96 | TIterator *fItTau;
|
---|
| 97 | TIterator *fItJet;
|
---|
| 98 |
|
---|
| 99 | };
|
---|
| 100 |
|
---|
| 101 | //------------------------------------------------------------------------------
|
---|
| 102 |
|
---|
| 103 | LHCOlympicsWriter::LHCOlympicsWriter(ExRootTreeReader *treeReader,
|
---|
| 104 | ofstream *outputStream) :
|
---|
| 105 | fTriggerWord(0), fEventNumber(1), fTreeReader(0), fOutputStream(0)
|
---|
| 106 | {
|
---|
| 107 | fTreeReader = treeReader;
|
---|
| 108 | fOutputStream = outputStream;
|
---|
| 109 |
|
---|
| 110 | // information about reconstructed event
|
---|
| 111 | fBranchEvent = fTreeReader->UseBranch("Event");
|
---|
| 112 | // reconstructed photons
|
---|
| 113 | fBranchPhoton = fTreeReader->UseBranch("Photon");
|
---|
| 114 | fItPhoton = fBranchPhoton->MakeIterator();
|
---|
| 115 | // reconstructed electrons
|
---|
| 116 | fBranchElectron = fTreeReader->UseBranch("Electron");
|
---|
| 117 | fItElectron = fBranchElectron->MakeIterator();
|
---|
| 118 | // reconstructed muons
|
---|
| 119 | fBranchMuon = fTreeReader->UseBranch("Muon");
|
---|
| 120 | fItMuon = fBranchMuon->MakeIterator();
|
---|
| 121 | // reconstructed hadronically-decaying tau leptons
|
---|
| 122 | fBranchTau = fTreeReader->UseBranch("Tau");
|
---|
| 123 | fItTau = fBranchTau->MakeIterator();
|
---|
| 124 | // reconstructed jets
|
---|
| 125 | fBranchJet = fTreeReader->UseBranch("Jet");
|
---|
| 126 | fItJet = fBranchJet->MakeIterator();
|
---|
| 127 | // missing transverse energy
|
---|
| 128 | fBranchMissingET = fTreeReader->UseBranch("MissingET");
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | //------------------------------------------------------------------------------
|
---|
| 132 |
|
---|
| 133 | LHCOlympicsWriter::~LHCOlympicsWriter()
|
---|
| 134 | {
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | //---------------------------------------------------------------------------
|
---|
| 138 |
|
---|
| 139 | void LHCOlympicsWriter::ProcessEvent()
|
---|
| 140 | {
|
---|
| 141 | fCurrentObject.intParam[0] = 0;
|
---|
| 142 |
|
---|
| 143 | AnalyseEvent();
|
---|
| 144 |
|
---|
| 145 | AnalysePhotons();
|
---|
| 146 | AnalyseElectrons();
|
---|
| 147 | AnalyseMuons();
|
---|
| 148 | AnalyseTaus();
|
---|
| 149 | AnalyseJets();
|
---|
| 150 |
|
---|
| 151 | AnalyseMissingET();
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | //---------------------------------------------------------------------------
|
---|
| 155 |
|
---|
| 156 | void LHCOlympicsWriter::ResetLHCOlympicsObject()
|
---|
| 157 | {
|
---|
| 158 | int i;
|
---|
| 159 | for(i = 1; i < LHCOlympicsObject::maxIntParam; ++i)
|
---|
| 160 | {
|
---|
| 161 | fCurrentObject.intParam[i] = 0;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | for(i = 0; i < LHCOlympicsObject::maxDblParam; ++i)
|
---|
| 165 | {
|
---|
| 166 | fCurrentObject.dblParam[i] = 0.0;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | //---------------------------------------------------------------------------
|
---|
| 171 |
|
---|
| 172 | void LHCOlympicsWriter::WriteLHCOlympicsObject()
|
---|
| 173 | {
|
---|
| 174 | int i;
|
---|
| 175 | for(i = 0; i < LHCOlympicsObject::maxIntParam; ++i)
|
---|
| 176 | {
|
---|
| 177 | (*fOutputStream) << fCurrentObject.intParam[i] << "\t";
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | for(i = 0; i < LHCOlympicsObject::maxDblParam; ++i)
|
---|
| 181 | {
|
---|
| 182 | (*fOutputStream) << fCurrentObject.dblParam[i] << "\t";
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | (*fOutputStream) << endl;
|
---|
| 186 |
|
---|
| 187 | ++fCurrentObject.intParam[0];
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | //---------------------------------------------------------------------------
|
---|
| 191 |
|
---|
| 192 | void LHCOlympicsWriter::AnalyseEvent()
|
---|
| 193 | {
|
---|
| 194 | ExRootEvent *element;
|
---|
| 195 |
|
---|
| 196 | element = static_cast<ExRootEvent*>(fBranchEvent->At(0));
|
---|
| 197 |
|
---|
| 198 | (*fOutputStream) << fCurrentObject.intParam[0] << "\t";
|
---|
| 199 | (*fOutputStream) << element->Number << "\t";
|
---|
| 200 | (*fOutputStream) << element->Trigger << endl;
|
---|
| 201 |
|
---|
| 202 | ++fCurrentObject.intParam[0];
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | //---------------------------------------------------------------------------
|
---|
| 206 |
|
---|
| 207 | void LHCOlympicsWriter::AnalysePhotons()
|
---|
| 208 | {
|
---|
| 209 | ExRootPhoton *element;
|
---|
| 210 |
|
---|
| 211 | fItPhoton->Reset();
|
---|
| 212 | while((element = static_cast<ExRootPhoton*>(fItPhoton->Next())))
|
---|
| 213 | {
|
---|
| 214 | ResetLHCOlympicsObject();
|
---|
| 215 |
|
---|
| 216 | fCurrentObject.intParam[1] = 0;
|
---|
| 217 |
|
---|
| 218 | fCurrentObject.dblParam[0] = element->Eta;
|
---|
| 219 | fCurrentObject.dblParam[1] = element->Phi;
|
---|
| 220 | fCurrentObject.dblParam[2] = element->PT;
|
---|
| 221 |
|
---|
| 222 | fCurrentObject.dblParam[6] = element->EhadOverEem;
|
---|
| 223 |
|
---|
| 224 | WriteLHCOlympicsObject();
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | //---------------------------------------------------------------------------
|
---|
| 229 |
|
---|
| 230 | void LHCOlympicsWriter::AnalyseElectrons()
|
---|
| 231 | {
|
---|
| 232 | ExRootElectron *element;
|
---|
| 233 |
|
---|
| 234 | fItElectron->Reset();
|
---|
| 235 | while((element = static_cast<ExRootElectron*>(fItElectron->Next())))
|
---|
| 236 | {
|
---|
| 237 | ResetLHCOlympicsObject();
|
---|
| 238 |
|
---|
| 239 | fCurrentObject.intParam[1] = 1;
|
---|
| 240 |
|
---|
| 241 | fCurrentObject.dblParam[0] = element->Eta;
|
---|
| 242 | fCurrentObject.dblParam[1] = element->Phi;
|
---|
| 243 | fCurrentObject.dblParam[2] = element->PT;
|
---|
| 244 |
|
---|
| 245 | fCurrentObject.dblParam[4] = element->Ntrk * element->Charge;
|
---|
| 246 |
|
---|
| 247 | fCurrentObject.dblParam[6] = element->EhadOverEem;
|
---|
| 248 |
|
---|
| 249 | WriteLHCOlympicsObject();
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | //---------------------------------------------------------------------------
|
---|
| 254 |
|
---|
| 255 | void LHCOlympicsWriter::AnalyseMuons()
|
---|
| 256 | {
|
---|
| 257 | ExRootMuon *element;
|
---|
| 258 |
|
---|
| 259 | fItMuon->Reset();
|
---|
| 260 | while((element = static_cast<ExRootMuon*>(fItMuon->Next())))
|
---|
| 261 | {
|
---|
| 262 | ResetLHCOlympicsObject();
|
---|
| 263 |
|
---|
| 264 | fCurrentObject.intParam[1] = 2;
|
---|
| 265 |
|
---|
| 266 | fCurrentObject.dblParam[0] = element->Eta;
|
---|
| 267 | fCurrentObject.dblParam[1] = element->Phi;
|
---|
| 268 | fCurrentObject.dblParam[2] = element->PT;
|
---|
| 269 |
|
---|
| 270 | fCurrentObject.dblParam[4] = element->Ntrk * element->Charge;
|
---|
| 271 |
|
---|
| 272 | fCurrentObject.dblParam[5] = element->JetIndex;
|
---|
| 273 |
|
---|
| 274 | fCurrentObject.dblParam[6] = element->PTiso + element->ETiso;
|
---|
| 275 |
|
---|
| 276 | WriteLHCOlympicsObject();
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | //---------------------------------------------------------------------------
|
---|
| 281 |
|
---|
| 282 | void LHCOlympicsWriter::AnalyseTaus()
|
---|
| 283 | {
|
---|
| 284 | ExRootTau *element;
|
---|
| 285 |
|
---|
| 286 | fItTau->Reset();
|
---|
| 287 | while((element = static_cast<ExRootTau*>(fItTau->Next())))
|
---|
| 288 | {
|
---|
| 289 | ResetLHCOlympicsObject();
|
---|
| 290 |
|
---|
| 291 | fCurrentObject.intParam[1] = 3;
|
---|
| 292 |
|
---|
| 293 | fCurrentObject.dblParam[0] = element->Eta;
|
---|
| 294 | fCurrentObject.dblParam[1] = element->Phi;
|
---|
| 295 | fCurrentObject.dblParam[2] = element->PT;
|
---|
| 296 |
|
---|
| 297 | fCurrentObject.dblParam[4] = element->Ntrk * element->Charge;
|
---|
| 298 |
|
---|
| 299 | fCurrentObject.dblParam[6] = element->EhadOverEem;
|
---|
| 300 |
|
---|
| 301 | WriteLHCOlympicsObject();
|
---|
| 302 | }
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | //---------------------------------------------------------------------------
|
---|
| 306 |
|
---|
| 307 | void LHCOlympicsWriter::AnalyseJets()
|
---|
| 308 | {
|
---|
| 309 | ExRootJet *element;
|
---|
| 310 |
|
---|
| 311 | fItJet->Reset();
|
---|
| 312 | while((element = static_cast<ExRootJet*>(fItJet->Next())))
|
---|
| 313 | {
|
---|
| 314 | ResetLHCOlympicsObject();
|
---|
| 315 |
|
---|
| 316 | fCurrentObject.intParam[1] = 4;
|
---|
| 317 |
|
---|
| 318 | fCurrentObject.dblParam[0] = element->Eta;
|
---|
| 319 | fCurrentObject.dblParam[1] = element->Phi;
|
---|
| 320 | fCurrentObject.dblParam[2] = element->PT;
|
---|
| 321 |
|
---|
| 322 | fCurrentObject.dblParam[3] = element->Mass;
|
---|
| 323 |
|
---|
| 324 | fCurrentObject.dblParam[4] = element->Ntrk;
|
---|
| 325 |
|
---|
| 326 | fCurrentObject.dblParam[5] = element->BTag;
|
---|
| 327 |
|
---|
| 328 | fCurrentObject.dblParam[6] = element->EhadOverEem;
|
---|
| 329 |
|
---|
| 330 | WriteLHCOlympicsObject();
|
---|
| 331 | }
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | //---------------------------------------------------------------------------
|
---|
| 335 |
|
---|
| 336 | void LHCOlympicsWriter::AnalyseMissingET()
|
---|
| 337 | {
|
---|
| 338 | ExRootMissingET *element;
|
---|
| 339 |
|
---|
| 340 | element = static_cast<ExRootMissingET*>(fBranchMissingET->At(0));
|
---|
| 341 |
|
---|
| 342 | ResetLHCOlympicsObject();
|
---|
| 343 |
|
---|
| 344 | fCurrentObject.intParam[1] = 6;
|
---|
| 345 |
|
---|
| 346 | fCurrentObject.dblParam[1] = element->Phi;
|
---|
| 347 | fCurrentObject.dblParam[2] = element->MET;
|
---|
| 348 |
|
---|
| 349 | WriteLHCOlympicsObject();
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 | //---------------------------------------------------------------------------
|
---|
| 353 |
|
---|
| 354 | int main(int argc, char *argv[])
|
---|
| 355 | {
|
---|
| 356 | char *appName = "ExRootLHCOlympicsWriter";
|
---|
| 357 |
|
---|
| 358 | if(argc != 3)
|
---|
| 359 | {
|
---|
| 360 | cout << " Usage: " << appName << " input_file" << " output_file" << endl;
|
---|
| 361 | cout << " input_file - input file in ROOT format." << endl;
|
---|
| 362 | cout << " output_file - output file in LHEF format," << endl;
|
---|
| 363 | return 1;
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | int appargc = 1;
|
---|
| 367 | char *appargv[] = {appName};
|
---|
| 368 | TApplication app(appName, &appargc, appargv);
|
---|
| 369 |
|
---|
| 370 | // Open a stream connected to an output file:
|
---|
| 371 | ofstream outputFileStream(argv[2]);
|
---|
| 372 |
|
---|
| 373 | if(!outputFileStream.is_open())
|
---|
| 374 | {
|
---|
| 375 | cerr << "** ERROR: Can't open '" << argv[2] << "' for output" << endl;
|
---|
| 376 | return 1;
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | TChain *chain = new TChain("LHCO");
|
---|
| 380 | chain->Add(argv[1]);
|
---|
| 381 |
|
---|
| 382 | ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
|
---|
| 383 |
|
---|
| 384 | cout << "** Calculating number of events to process. Please wait..." << endl;
|
---|
| 385 | Long64_t allEntries = treeReader->GetEntries();
|
---|
| 386 | cout << "** Input file contains " << allEntries << " events" << endl;
|
---|
| 387 |
|
---|
| 388 | Long64_t entry;
|
---|
| 389 |
|
---|
| 390 | if(allEntries > 0)
|
---|
| 391 | {
|
---|
| 392 | // Create LHC Olympics converter:
|
---|
| 393 | LHCOlympicsWriter *writer = new LHCOlympicsWriter(treeReader, &outputFileStream);
|
---|
| 394 |
|
---|
| 395 | ExRootProgressBar progressBar(allEntries);
|
---|
| 396 | // Loop over all events
|
---|
| 397 | for(entry = 0; entry < allEntries; ++entry)
|
---|
| 398 | {
|
---|
| 399 | if(!treeReader->ReadEntry(entry))
|
---|
| 400 | {
|
---|
| 401 | cout << "** ERROR: cannot read event " << entry << endl;
|
---|
| 402 | break;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | writer->ProcessEvent();
|
---|
| 406 |
|
---|
| 407 | progressBar.Update(entry);
|
---|
| 408 | }
|
---|
| 409 | progressBar.Finish();
|
---|
| 410 |
|
---|
| 411 | delete writer;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | cout << "** Exiting..." << endl;
|
---|
| 415 |
|
---|
| 416 | delete treeReader;
|
---|
| 417 | delete chain;
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 |
|
---|