Created
July 30, 2012 17:00
-
-
Save carbolymer/3208364 to your computer and use it in GitHub Desktop.
Plik: /home/mgalazyn/workspace/tpi/TChainProxy.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "TChainProxy.h" | |
TChainProxy::TChainProxy() : _type(NONE), _isSiniukowLoaded(false) | |
{ | |
_types[0] = "particles"; // Therminator | |
_types[1] = "tf"; // Siniukow | |
_types[2] = "teposevent"; // EPOS | |
_chain = new TChain(); | |
_therminatorParticle = 0; | |
} | |
TChainProxy::~TChainProxy() | |
{ | |
delete _chain; | |
} | |
Int_t TChainProxy::Add(const char *fileName) | |
{ | |
// event type recognition on first file | |
if(_type == NONE) | |
{ | |
TFile *file; | |
TTree | |
*therminatorTree = 0, | |
*siniukowTree = 0, | |
*eposTree = 0; | |
file = new TFile(fileName); | |
file->GetObject(_types[0], therminatorTree); | |
file->GetObject(_types[1], siniukowTree); | |
file->GetObject(_types[2], eposTree); | |
if(therminatorTree) | |
_type = Therminator; | |
else if(siniukowTree) | |
_type = Siniukow; | |
else if(eposTree) | |
_type = EPOS; | |
else | |
{ | |
std::cout << "Unknown event file!!!" << std::endl; | |
delete file; | |
return 0; | |
} | |
_chain->SetName(_types[_type]); | |
delete file; | |
} | |
return _chain->Add(fileName); | |
} | |
Int_t TChainProxy::GetEntry(Long64_t entryNumber) | |
{ | |
if(_type == Therminator) | |
_chain->GetEntry(entryNumber); | |
else if(_type == Siniukow) | |
{ | |
_loadSiniukow(); | |
*_therminatorParticle = _siniukowParticles[entryNumber]; | |
} | |
else if(_type == EPOS) | |
{ | |
_loadEPOS(); | |
*_therminatorParticle = _EPOSParticles[entryNumber]; | |
} | |
return 1; | |
} | |
Long64_t TChainProxy::GetEntries() | |
{ | |
if(_type == Therminator) | |
return _chain->GetEntries(); | |
if(_type == Siniukow) | |
{ | |
_loadSiniukow(); | |
return _siniukowParticles.size(); | |
} | |
if(_type == EPOS) | |
{ | |
_loadEPOS(); | |
return _EPOSParticles.size(); | |
} | |
else | |
return 0; | |
} | |
Int_t TChainProxy::SetBranchAddress(const char *skip, ParticleCoor *particle) | |
{ | |
_therminatorParticle = particle; | |
if(_type == Therminator) | |
_chain->SetBranchAddress("particle", _therminatorParticle); | |
else if (_type == Siniukow) | |
; // nothing here | |
else if (_type == EPOS) | |
; // nothing here | |
else | |
{ | |
std::cout << "Unknown event file!!!" << std::endl; | |
return 1; | |
} | |
return 1; | |
} | |
void TChainProxy::_loadSiniukow() | |
{ | |
SiniukowEvent event; | |
ParticleCoor particle; | |
unsigned int totalEventCount, iEvent, iParticle, eid; | |
if(_type != Siniukow) | |
return; // ONLY for Siniukow | |
if(_isSiniukowLoaded) | |
return; // event files are already loaded | |
_chain->SetBranchStatus("*",1); | |
_chain->SetBranchAddress("npart",&event.npart); | |
_chain->SetBranchAddress("id", event.id); | |
_chain->SetBranchAddress("mid", event.mid ); | |
_chain->SetBranchAddress("x", event.x); | |
_chain->SetBranchAddress("y", event.y); | |
_chain->SetBranchAddress("z", event.z); | |
_chain->SetBranchAddress("t", event.t); | |
_chain->SetBranchAddress("px", event.px); | |
_chain->SetBranchAddress("py", event.py); | |
_chain->SetBranchAddress("pz", event.pz); | |
_chain->SetBranchAddress("E", event.E); | |
totalEventCount = _chain->GetEntries(); | |
for(iEvent = 0; iEvent < totalEventCount; ++iEvent) | |
{ | |
eid = 0; | |
_chain->GetEntry(iEvent); | |
for (iParticle = 0; iParticle < event.npart; ++iParticle) | |
{ | |
particle.mass = TMath::Sqrt( | |
TMath::Power(event.E[iParticle]/TMath::C(),2) | |
- TMath::Power(event.px[iParticle],2) | |
- TMath::Power(event.py[iParticle],2) | |
- TMath::Power(event.pz[iParticle],2) | |
); | |
particle.t = event.t[iParticle]; | |
particle.x = event.x[iParticle]; | |
particle.y = event.y[iParticle]; | |
particle.z = event.z[iParticle]; | |
particle.e = event.E[iParticle]; | |
particle.px = event.px[iParticle]; | |
particle.py = event.py[iParticle]; | |
particle.pz = event.pz[iParticle]; | |
particle.decayed = 0; | |
particle.pid = event.id[iParticle]; | |
particle.fatherpid = event.mid[iParticle]; | |
particle.rootpid = 0; | |
particle.eid = ++eid; | |
particle.fathereid = 0; | |
particle.eventid = iEvent; | |
_siniukowParticles.push_back(particle); | |
} | |
} | |
_isSiniukowLoaded = true; | |
} | |
void TChainProxy::_loadEPOS() | |
{ | |
EPOSEvent event; | |
ParticleCoor particle; | |
unsigned int totalEventCount, iEvent, iParticle, eid; | |
if(_type != EPOS) | |
return; // ONLY for EPOS | |
if(_isEPOSLoaded) | |
return; // event files are already loaded | |
_chain->SetBranchStatus("*",1); | |
_chain->SetBranchAddress("np", &event.np); | |
_chain->SetBranchAddress("bim", &event.bim); | |
_chain->SetBranchAddress("zus", event.zus); | |
_chain->SetBranchAddress("px", event.px); | |
_chain->SetBranchAddress("py", event.py); | |
_chain->SetBranchAddress("pz", event.pz); | |
_chain->SetBranchAddress("e", event.e); | |
_chain->SetBranchAddress("x", event.x); | |
_chain->SetBranchAddress("y", event.y); | |
_chain->SetBranchAddress("z", event.z); | |
_chain->SetBranchAddress("t", event.t); | |
_chain->SetBranchAddress("id", event.id); | |
_chain->SetBranchAddress("ist", event.ist); | |
_chain->SetBranchAddress("ity", event.ity); | |
_chain->SetBranchAddress("ior", event.ior); | |
_chain->SetBranchAddress("jor", event.jor); | |
totalEventCount = _chain->GetEntries(); | |
for(iEvent = 0; iEvent < totalEventCount; ++iEvent) | |
{ | |
eid = 0; | |
_chain->GetEntry(iEvent); | |
for (iParticle = 0; iParticle < event.np; ++iParticle) | |
{ | |
if(event.ist[iParticle] != 0) | |
continue; | |
particle.mass = TMath::Sqrt( | |
TMath::Power(event.e[iParticle]/TMath::C(),2) | |
- TMath::Power(event.px[iParticle],2) | |
- TMath::Power(event.py[iParticle],2) | |
- TMath::Power(event.pz[iParticle],2) | |
); | |
particle.t = event.t[iParticle]; | |
particle.x = event.x[iParticle]; | |
particle.y = event.y[iParticle]; | |
particle.z = event.z[iParticle]; | |
particle.e = event.e[iParticle]; | |
particle.px = event.px[iParticle]; | |
particle.py = event.py[iParticle]; | |
particle.pz = event.pz[iParticle]; | |
particle.decayed = 0; | |
particle.pid = event.id[iParticle]; | |
if(event.ior[iParticle] == 0 && event.jor[iParticle] == 0) | |
{ | |
particle.fatherpid = 0; | |
particle.rootpid = 0; | |
particle.fathereid = 0; | |
} | |
else | |
{ particle.fatherpid = event.id[event.ior[iParticle]]; | |
particle.rootpid = 0; | |
particle.fathereid = event.ior[iParticle]; | |
} | |
particle.eid = ++eid; | |
particle.eventid = iEvent; | |
_EPOSParticles.push_back(particle); | |
} | |
} | |
_isEPOSLoaded = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment