Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F10664361
OutputVarUtils.icc
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Subscribers
None
OutputVarUtils.icc
View Options
// emacs this is -*- c++ -*-
namespace SpartyJet {
/// Schedule all generic variables (jet moment, jet moment array, event variable,..)
template< class BRANCH0D, class BRANCH1D, class BRANCH2D>
void GenericJetVar< BRANCH0D, BRANCH1D, BRANCH2D>::schedule(TTree *tree){
// N.m_name = m_prefix + "_N";
// N.registerBranch(tree);
set_name_register(N, "N", tree);
if( !m_mmap) return;
int nmom = m_mmap->num_jet_moment();
m_moment_vars.resize(nmom);
m_log << m_prefix << " has moment num_jet_moment = "<< nmom << std::endl;
// schedule jet moment
for(int i=0;i<nmom;i++){
set_name_register(m_moment_vars[i], m_mmap->moment_name(i) , tree);
}
// schedule jet collection global variables
nmom = m_mmap->num_event_moment();
m_event_vars.resize(nmom) ;
for(int i=0;i<nmom;i++){
set_name_register(m_event_vars[i], m_mmap->event_moment_name(i) , tree);
}
// schedule jet moment arrays
nmom = m_mmap->num_jet_moment_array();
m_momentarray_vars.resize(nmom) ;
for(int i=0;i<nmom;i++){
set_name_register(m_momentarray_vars[i], m_mmap->moment_array_name(i) , tree);
}
// schedule jet collection global array variables
nmom = m_mmap->num_event_moment_array();
m_eventarray_vars.resize(nmom) ;
for(int i=0;i<nmom;i++){
set_name_register(m_eventarray_vars[i], m_mmap->event_moment_array_name(i) , tree);
}
m_Nmax = 10000;
}
template< class BRANCH0D, class BRANCH1D, class BRANCH2D>
void GenericJetVar< BRANCH0D, BRANCH1D, BRANCH2D>::set_data(JetCollection &theJets){
resize_vars(theJets);
//this->m_log << this->m_prefix<<" GenericJetVar set_data N= "<< N <<" /max="<< m_Nmax<<std::endl;
// !! important : point to this JetCollection map.
// This assumes it has the same structure as the map used in schedule
// (almost guaranteed when using JetAlgorithm)
m_mmap = theJets.get_JetMomentMap();
//return;
if( !m_mmap) return;
JetCollection::iterator it = theJets.begin();
JetCollection::iterator itE = theJets.end();
size_t jeti= 0;
for(; it!=itE; ++it){ // loop on each jet
// get jetmoments for this jet
JetMomentMap::value_store_t * store = m_mmap->get_jet_moments(*it);
if (store != NULL) {
int nmom = store->size();
for(int i=0;i<nmom;i++){ // loop on moments
m_moment_vars[i][jeti] = store->operator[](i); // fill moment i of jet jeti into the array
}
};
// Fill JetMoment array if any
JetMomentMap::valuearray_store_t * arraystore = m_mmap->get_jet_moment_arrays(*it);
if (arraystore != NULL) {
int nmomarray = arraystore->size();
for(int i=0;i<nmomarray;i++){ // loop on moments
std::vector<float> momentarray_i = arraystore->operator[](i); // get moment content
BRANCH2D & moments_i = m_momentarray_vars[i]; // get array holding moments 'i'
for(unsigned k=0; k< momentarray_i.size();k++){
//if(jeti<5) std::cout<< jeti << " _ "<< k<< " = "<< momentarray_i[k]<< std::endl;
moments_i[jeti][k] = momentarray_i[k];
}
}
}
jeti++;
if(jeti==m_Nmax) break;
}
// Now set global variables :
JetMomentMap::value_store_t * store = m_mmap->get_event_moment();
if (store !=NULL) {
int nvar = store->size();
//int nmom = m_mmap->num_jet_moment();
for(int i=0;i<nvar;i++){ // loop on moments
m_event_vars[i] = store->operator[](i);
}
}
// Now set global arrays :
JetMomentMap::valuearray_store_t * storearray = m_mmap->get_event_moment_array();
if (storearray !=NULL){
int nvar_a = storearray->size();
//int first = m_mmap->num_jet_moment() + m_mmap->num_event_moment();
for(int i=0;i<nvar_a;i++){ // loop on global arrays
BRANCH1D & moments_i = m_eventarray_vars[i];
int tsize = (storearray->operator[](i)).size();
for(int k=0; k<tsize; k++){
moments_i[k] = (storearray->operator[](i))[k];
}
}
}
}
template< class BRANCH0D, class BRANCH1D, class BRANCH2D>
void GenericJetVar< BRANCH0D, BRANCH1D, BRANCH2D>::resize_vars(JetCollection &theJets){
N = theJets.size();
size_t nmom = m_moment_vars.size();
for(size_t i=0;i<nmom;i++){ m_moment_vars[i].resize(N); }
nmom = m_momentarray_vars.size();
for(size_t i=0;i<nmom;i++){ m_momentarray_vars[i].resize(N); }
}
// *****************************************************
template< class BRANCH0D, class BRANCH1D, class BRANCH2D>
void JetVar< BRANCH0D, BRANCH1D, BRANCH2D>::set_var_names(std::string neta,std::string nphi,std::string npt,std::string ne,std::string nmass, std::string /*nind*/, std::string /* numc*/ ){
var_names.eta = neta;
var_names.phi = nphi;
var_names.p_T = npt;
var_names.e = ne;
var_names.mass = nmass;
}
// *****************************************************
template< class BRANCH0D, class BRANCH1D, class BRANCH2D>
void JetVar< BRANCH0D, BRANCH1D, BRANCH2D>::schedule(TTree* tree){
GenericJetVar< BRANCH0D, BRANCH1D, BRANCH2D>::schedule(tree);
this->m_Nmax = eta.size_max();
BranchWrap_simple<int> &N = this->N;
eta.set_refN( &N);
phi.set_refN( &N);
e.set_refN( &N);
mass.set_refN( &N);
p_T.set_refN( &N);
set_name_register(eta, var_names.eta, tree);
set_name_register(phi, var_names.phi, tree);
set_name_register(e, var_names.e, tree);
set_name_register(mass, var_names.mass, tree);
set_name_register(p_T, var_names.p_T, tree);
}
// *****************************************************
template< class BRANCH0D, class BRANCH1D, class BRANCH2D>
void JetVar< BRANCH0D, BRANCH1D, BRANCH2D>::set_data(JetCollection &theJets){
GenericJetVar< BRANCH0D, BRANCH1D, BRANCH2D>::set_data(theJets);
JetCollection::iterator jit = theJets.begin();
JetCollection::iterator jitE = theJets.end();
//m_log << " setting data "<< theJets.size() << std::endl;
size_t count=0;
size_t max = this->m_Nmax;
//max = max > this->N ? this->N : max;
//this->m_log << this->m_prefix<<" JetVar set_data max= "<< max <<std::endl;
for(; jit != jitE; ++jit){
Jet *j = (*jit);
eta[count] = j->eta();
if(IGenericJetVar::do_phiconversion) phi[count] = to_zero_2PI(j->phi());
else phi[count] = j->phi();
e[count] = j->e();
p_T[count] = j->pt();
mass[count] = j->mass();
//m_log<< count << " "<< j->e() << std::endl;
count++;
if(count == max) break;
}
this->N = count;
}
template< class BRANCH0D, class BRANCH1D, class BRANCH2D>
void JetVar< BRANCH0D, BRANCH1D, BRANCH2D>::resize_vars(JetCollection &theJets){
GenericJetVar< BRANCH0D, BRANCH1D, BRANCH2D>::resize_vars(theJets);
size_t Njet = this->N;
eta.resize(Njet);
phi.resize(Njet);
e.resize(Njet);
mass.resize(Njet);
p_T.resize(Njet);
}
template< class BRANCH0D, class BRANCH1D, class BRANCH2D, class BRANCH1Dind>
JetVarIndex<BRANCH0D, BRANCH1D, BRANCH2D, BRANCH1Dind>::JetVarIndex(std::string name,JetMomentMap *mmap): JetVar<BRANCH0D, BRANCH1D, BRANCH2D>(name,mmap){
m_input_refN=0;
m_input_sizeMax = index.size_max();
}
template< class BRANCH0D, class BRANCH1D, class BRANCH2D, class BRANCH1Dind>
void JetVarIndex< BRANCH0D, BRANCH1D, BRANCH2D, BRANCH1Dind >::schedule(TTree* tree){
this->JetVar< BRANCH0D, BRANCH1D, BRANCH2D >::schedule(tree); // define JetVar variables
// register the array of index :
if( ! m_input_refN) {this->m_log <<" !!! ERROR !!! JetVarIndex : input_var not set. "<< this->m_prefix<<std::endl; return;}
index.set_refN(m_input_refN);
set_name_register(index, this->var_names.ind, tree);
num_constit.set_refN(&this->N);
set_name_register(num_constit, this->var_names.numC, tree);
// std::string inputpref = m_input_refN->name();
// registerVar(tree, index, buildVarName(var_names.ind), buildTypeName(var_names.ind,inputpref,true));
// registerVar(tree, &num_constit, buildVarName(var_names.numC), buildTypeName(var_names.numC,m_prefix, true));
}
template< class BRANCH0D, class BRANCH1D, class BRANCH2D, class BRANCH1Dind>
void JetVarIndex< BRANCH0D, BRANCH1D, BRANCH2D, BRANCH1Dind >::set_data(JetCollection &theJets){
// Set the normal jet variables from input JetCollection
this->JetVar< BRANCH0D, BRANCH1D, BRANCH2D>::set_data(theJets);
// Set constituents indices
//this->m_log << this->m_prefix<<" JetVarIndex set_data " <<std::endl;
JetCollection::iterator jit = theJets.begin();
JetCollection::iterator jitE = theJets.end();
size_t Nconst = (size_t) (*m_input_refN);
Nconst = Nconst > m_input_sizeMax ? m_input_sizeMax : Nconst;
int max = this->m_Nmax;
// initialize index :
for(size_t i=0; i<Nconst; i++) index[i] = -1;
int jet=0;
// Loop on all jets :
for(; jit != jitE; ++jit){
Jet::constit_vect_t::iterator cit = (*jit)->firstConstituent();
Jet::constit_vect_t::iterator citE = (*jit)->lastConstituent();
num_constit[jet] = (*jit)->getConstituentNum();
// loop on all constituents :
for(; cit != citE; ++cit){
//this->m_log << " "<< (*cit)->index() << std::endl;
index[(*cit)->index()] = jet; // DANGEROUS !!! assume index is always big enough
}
jet++;
if( jet == max) break;
}
}
template< class BRANCH0D, class BRANCH1D, class BRANCH2D, class BRANCH1Dind>
void JetVarIndex< BRANCH0D, BRANCH1D, BRANCH2D, BRANCH1Dind >::resize_vars(JetCollection &theJets){
JetVar< BRANCH0D, BRANCH1D, BRANCH2D>::resize_vars(theJets);
num_constit.resize(this->N);
index.resize( (int)(*m_input_refN));
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 24, 6:37 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4821677
Default Alt Text
OutputVarUtils.icc (9 KB)
Attached To
rSPARTYJETSVN spartyjetsvn
Event Timeline
Log In to Comment