Changeset 13 for trunk/modules


Ignore:
Timestamp:
Sep 15, 2008, 10:59:33 AM (16 years ago)
Author:
Pavel Demin
Message:

add configuration for branches

Location:
trunk/modules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/MadGraphMatchingTreeWriter.cc

    r2 r13  
    4040  fJetEtaMax = GetDouble("JetEtaMax", 4.5);
    4141
     42  fClassMap[ExRootGenParticle::Class()] = &MadGraphMatchingTreeWriter::ProcessPartons;
     43
     44  fClassMap[ExRootMatching::Class()] = &MadGraphMatchingTreeWriter::ProcessMatching;
     45
     46  fClassMap[ExRootGenJet::Class()] = &MadGraphMatchingTreeWriter::ProcessJets;
     47
     48  TBranchMap::iterator itBranchMap;
     49  map< TClass *, TProcessMethod >::iterator itClassMap;
     50
     51  // read branch configuration and
    4252  // import array with output from filter/classifier/jetfinder modules
    4353
    44   fInputArrayPartonJets = ImportArray(GetString("InputArrayPartonJets", "partonjetfinder/candidates"));
    45   fItInputArrayPartonJets = fInputArrayPartonJets->MakeIterator();
    46 
    47   fInputArrayHadronJets = ImportArray(GetString("InputArrayHadronJets", "hadronjetfinder/candidates"));
    48   fItInputArrayHadronJets = fInputArrayHadronJets->MakeIterator();
    49 
    50   fInputArrayMatching = ImportArray(GetString("InputArrayMatching", "partonjetfinder/matching"));
    51   fItInputArrayMatching = fInputArrayMatching->MakeIterator();
    52 
    53   fInputArrayPartons = ImportArray(GetString("InputArrayPartons", "initstateselection/candidates"));
    54   fItInputArrayPartons = fInputArrayPartons->MakeIterator();
    55 
    56   fBranchPartonJets = NewBranch("PartonJet", ExRootGenJet::Class());
    57   fBranchHadronJets = NewBranch("HadronJet", ExRootGenJet::Class());
    58   fBranchMatching = NewBranch("Match", ExRootMatching::Class());
    59   fBranchPartons = NewBranch("Parton", ExRootGenParticle::Class());
     54  ExRootConfParam param = GetParam("Branch");
     55  Long_t i, size;
     56  TString branchName, branchClassName, branchInputArray;
     57  TClass *branchClass;
     58  const TObjArray *array;
     59  ExRootTreeBranch *branch;
     60
     61  size = param.GetSize();
     62  for(i = 0; i < size; ++i)
     63  {
     64    branchName = param[i][0].GetString();
     65    branchClassName = param[i][1].GetString();
     66    branchInputArray = param[i][2].GetString();
     67
     68    branchClass = gROOT->GetClass(branchClassName);
     69
     70    if(!branchClass)
     71    {
     72      cout << "** ERROR: cannot find class '" << branchClassName << "'" << endl;
     73      continue;
     74    }
     75
     76    itClassMap = fClassMap.find(branchClass);
     77    if(itClassMap == fClassMap.end())
     78    {
     79      cout << "** ERROR: cannot create branch for class '" << branchClassName << "'" << endl;
     80      continue;
     81    }
     82
     83    array = ImportArray(branchInputArray);
     84    branch = NewBranch(branchName, branchClass);
     85
     86    fBranchMap.insert(make_pair(branch, make_pair(itClassMap->second, array->MakeIterator())));
     87  }
     88
    6089}
    6190
     
    6493void MadGraphMatchingTreeWriter::Finish()
    6594{
    66   if(fItInputArrayPartonJets) delete fItInputArrayPartonJets;
    67   if(fItInputArrayHadronJets) delete fItInputArrayHadronJets;
    68   if(fItInputArrayMatching) delete fItInputArrayMatching;
    69   if(fItInputArrayPartons) delete fItInputArrayPartons;
    70 }
    71 
    72 //------------------------------------------------------------------------------
    73 
    74 void MadGraphMatchingTreeWriter::Process()
     95  TBranchMap::iterator itBranchMap;
     96  TIterator *iterator;
     97
     98  for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap)
     99  {
     100    iterator = itBranchMap->second.second;
     101    if(iterator) delete iterator;
     102 }
     103}
     104
     105//------------------------------------------------------------------------------
     106
     107void MadGraphMatchingTreeWriter::ProcessPartons(ExRootTreeBranch *branch, TIterator *iterator)
    75108{
    76109  ExRootCandidate *candidate = 0;
    77   ExRootGenParticle *entryParton = 0;
    78   ExRootMatching *matching = 0, *entryMatching = 0;
    79   ExRootGenJet *entryJet = 0;
     110  ExRootGenParticle *entry = 0;
    80111  Double_t pt, signPz, eta, rapidity;
    81112
    82   // loop over all parton jets
    83   fItInputArrayPartonJets->Reset();
    84   while((candidate = static_cast<ExRootCandidate*>(fItInputArrayPartonJets->Next())))
     113  // loop over all partons
     114  iterator->Reset();
     115  while((candidate = static_cast<ExRootCandidate*>(iterator->Next())))
    85116  {
    86117    const TLorentzVector &momentum = candidate->GetP4();
     118
     119    entry = static_cast<ExRootGenParticle*>(branch->NewEntry());
    87120
    88121    pt = momentum.Pt();
     
    91124    rapidity = (pt == 0.0 ? signPz*999.9 : momentum.Rapidity());
    92125
    93     if(pt < fJetPTMin) continue;
    94     if(TMath::Abs(eta) > fJetEtaMax) continue;
    95 
    96     entryJet = static_cast<ExRootGenJet*>(fBranchPartonJets->NewEntry());
    97 
    98     entryJet->E = momentum.E();
    99     entryJet->Px = momentum.Px();
    100     entryJet->Py = momentum.Py();
    101     entryJet->Pz = momentum.Pz();
    102 
    103     entryJet->Eta = eta;
    104     entryJet->Phi = momentum.Phi();
    105     entryJet->PT = pt;
    106 
    107     entryJet->Rapidity = rapidity;
    108 
    109     entryJet->Mass = momentum.M();
    110   }
    111 
    112   // loop over all hadron jets
    113   fItInputArrayHadronJets->Reset();
    114   while((candidate = static_cast<ExRootCandidate*>(fItInputArrayHadronJets->Next())))
     126    entry->PID = candidate->GetType()->PdgCode();
     127
     128    entry->E = momentum.E();
     129    entry->Px = momentum.Px();
     130    entry->Py = momentum.Py();
     131    entry->Pz = momentum.Pz();
     132
     133    entry->Eta = eta;
     134    entry->Phi = momentum.Phi();
     135    entry->PT = pt;
     136
     137    entry->Rapidity = rapidity;
     138  }
     139}
     140
     141//------------------------------------------------------------------------------
     142
     143void MadGraphMatchingTreeWriter::ProcessMatching(ExRootTreeBranch *branch, TIterator *iterator)
     144{
     145  ExRootMatching *matching = 0, *entry = 0;
     146
     147  // loop over all matching
     148  iterator->Reset();
     149  while((matching = static_cast<ExRootMatching*>(iterator->Next())))
     150  {
     151    entry = static_cast<ExRootMatching*>(branch->NewEntry());
     152
     153    entry->DMerge = matching->DMerge;
     154    entry->YMerge = matching->YMerge;
     155  }
     156}
     157
     158//------------------------------------------------------------------------------
     159
     160void MadGraphMatchingTreeWriter::ProcessJets(ExRootTreeBranch *branch, TIterator *iterator)
     161{
     162  ExRootCandidate *candidate = 0;
     163  ExRootGenJet *entry = 0;
     164  Double_t pt, signPz, eta, rapidity;
     165
     166  // loop over all jets
     167  iterator->Reset();
     168  while((candidate = static_cast<ExRootCandidate*>(iterator->Next())))
    115169  {
    116170    const TLorentzVector &momentum = candidate->GetP4();
     
    124178    if(TMath::Abs(eta) > fJetEtaMax) continue;
    125179
    126     entryJet = static_cast<ExRootGenJet*>(fBranchHadronJets->NewEntry());
    127 
    128     entryJet->E = momentum.E();
    129     entryJet->Px = momentum.Px();
    130     entryJet->Py = momentum.Py();
    131     entryJet->Pz = momentum.Pz();
    132 
    133     entryJet->Eta = eta;
    134     entryJet->Phi = momentum.Phi();
    135     entryJet->PT = pt;
    136 
    137     entryJet->Rapidity = rapidity;
    138 
    139     entryJet->Mass = momentum.M();
    140   }
    141 
    142   // loop over all matching
    143   fItInputArrayMatching->Reset();
    144   while((matching = static_cast<ExRootMatching*>(fItInputArrayMatching->Next())))
    145   {
    146     entryMatching = static_cast<ExRootMatching*>(fBranchMatching->NewEntry());
    147 
    148     entryMatching->DMerge = matching->DMerge;
    149     entryMatching->YMerge = matching->YMerge;
    150   }
    151 
    152   // loop over all partons
    153   fItInputArrayPartons->Reset();
    154   while((candidate = static_cast<ExRootCandidate*>(fItInputArrayPartons->Next())))
    155   {
    156     const TLorentzVector &momentum = candidate->GetP4();
    157 
    158     entryParton = static_cast<ExRootGenParticle*>(fBranchPartons->NewEntry());
    159 
    160     pt = momentum.Pt();
    161     signPz = (momentum.Pz() >= 0.0) ? 1.0 : -1.0;
    162     eta = (pt == 0.0 ? signPz*999.9 : momentum.Eta());
    163     rapidity = (pt == 0.0 ? signPz*999.9 : momentum.Rapidity());
    164 
    165     entryParton->PID = candidate->GetType()->PdgCode();
    166 
    167     entryParton->E = momentum.E();
    168     entryParton->Px = momentum.Px();
    169     entryParton->Py = momentum.Py();
    170     entryParton->Pz = momentum.Pz();
    171 
    172     entryParton->Eta = eta;
    173     entryParton->Phi = momentum.Phi();
    174     entryParton->PT = pt;
    175 
    176     entryParton->Rapidity = rapidity;
    177   }
    178 }
    179 
    180 //------------------------------------------------------------------------------
    181 
     180    entry = static_cast<ExRootGenJet*>(branch->NewEntry());
     181
     182    entry->E = momentum.E();
     183    entry->Px = momentum.Px();
     184    entry->Py = momentum.Py();
     185    entry->Pz = momentum.Pz();
     186
     187    entry->Eta = eta;
     188    entry->Phi = momentum.Phi();
     189    entry->PT = pt;
     190
     191    entry->Rapidity = rapidity;
     192
     193    entry->Mass = momentum.M();
     194  }
     195}
     196
     197//------------------------------------------------------------------------------
     198
     199void MadGraphMatchingTreeWriter::Process()
     200{
     201
     202  TBranchMap::iterator itBranchMap;
     203  ExRootTreeBranch *branch;
     204  TProcessMethod method;
     205  TIterator *iterator;
     206
     207  for(itBranchMap = fBranchMap.begin(); itBranchMap != fBranchMap.end(); ++itBranchMap)
     208  {
     209    branch = itBranchMap->first;
     210    method = itBranchMap->second.first;
     211    iterator = itBranchMap->second.second;
     212
     213    (this->*method)(branch, iterator);
     214  }
     215
     216}
     217
     218//------------------------------------------------------------------------------
     219
  • trunk/modules/MadGraphMatchingTreeWriter.h

    r2 r13  
    44#include "ExRootAnalysis/ExRootModule.h"
    55
    6 #include "TString.h"
    7 
    86#include <map>
    97
    10 class TH1;
     8class TClass;
    119class TIterator;
    12 class TObjArray;
    13 class TClonesArray;
     10class ExRootTreeBranch;
    1411
    1512class MadGraphMatchingTreeWriter: public ExRootModule
     
    2623private:
    2724
    28   Double_t fJetPTMin, fJetEtaMax;
     25  void ProcessPartons(ExRootTreeBranch *branch, TIterator *iterator);
     26  void ProcessMatching(ExRootTreeBranch *branch, TIterator *iterator);
     27  void ProcessJets(ExRootTreeBranch *branch, TIterator *iterator);
    2928
    30   const TObjArray *fInputArrayPartonJets; //!
    31   const TObjArray *fInputArrayHadronJets; //!
    32   const TObjArray *fInputArrayMatching; //!
    33   const TObjArray *fInputArrayPartons; //!
     29  Double_t fJetPTMin, fJetEtaMax; //!
     30#ifndef __CINT__
     31  typedef void (MadGraphMatchingTreeWriter::*TProcessMethod)(ExRootTreeBranch*, TIterator*); //!
    3432
    35   TIterator *fItInputArrayPartonJets; //!
    36   TIterator *fItInputArrayHadronJets; //!
    37   TIterator *fItInputArrayMatching; //!
    38   TIterator *fItInputArrayPartons; //!
    39  
    40   ExRootTreeBranch *fBranchPartonJets; //!
    41   ExRootTreeBranch *fBranchHadronJets; //!
    42   ExRootTreeBranch *fBranchMatching; //!
    43   ExRootTreeBranch *fBranchPartons; //!
     33  typedef std::map<ExRootTreeBranch *, std::pair<TProcessMethod, TIterator*> > TBranchMap; //!
    4434
     35  TBranchMap fBranchMap; //!
     36
     37  std::map< TClass *, TProcessMethod > fClassMap; //!
     38#endif
    4539  ClassDef(MadGraphMatchingTreeWriter, 1)
    4640};
Note: See TracChangeset for help on using the changeset viewer.