source: HiSusy/trunk/Delphes-3.0.0/external/ExRootAnalysis/ExRootFilter.cc @ 1

Last change on this file since 1 was 1, checked in by zerwas, 11 years ago

first import of structure, PYTHIA8 and DELPHES

File size: 3.4 KB
Line 
1
2/** \class ExRootFilter
3 *
4 *  Class simplifying classification and subarrays handling
5 *
6 *  $Date: 2008-06-04 13:57:55 $
7 *  $Revision: 1.1 $
8 *
9 *
10 *  \author P. Demin - UCL, Louvain-la-Neuve
11 *
12 */
13
14#include "ExRootAnalysis/ExRootFilter.h"
15#include "ExRootAnalysis/ExRootClassifier.h"
16
17#include "TSeqCollection.h"
18#include "TObjArray.h"
19
20#include <iostream>
21#include <stdexcept>
22#include <sstream>
23
24using namespace std;
25
26typedef map<Int_t, TObjArray*> TCategoryMap;
27typedef map<ExRootClassifier*, pair<Bool_t, TCategoryMap> > TClassifierMap;
28
29ExRootFilter::ExRootFilter(const TSeqCollection *collection) :
30  fCollection(collection)
31{
32  fIter = fCollection->MakeIterator();
33}
34
35//------------------------------------------------------------------------------
36
37ExRootFilter::~ExRootFilter()
38{
39  TClassifierMap::iterator it_map;
40  TCategoryMap::iterator it_submap;
41  for(it_map = fMap.begin(); it_map != fMap.end(); ++it_map)
42  {
43    for(it_submap = it_map->second.second.begin();
44        it_submap != it_map->second.second.end(); ++it_submap)
45    {
46      delete (it_submap->second);
47    }
48  }
49
50  delete fIter;
51}
52
53//------------------------------------------------------------------------------
54
55void ExRootFilter::Reset(ExRootClassifier *classifier)
56{
57  TClassifierMap::iterator it_map;
58  TCategoryMap::iterator it_submap;
59  if(classifier)
60  {
61    it_map = fMap.find(classifier);
62    if(it_map != fMap.end())
63    {
64      it_map->second.first = kTRUE;
65      for(it_submap = it_map->second.second.begin();
66          it_submap != it_map->second.second.end(); ++it_submap)
67      {
68        it_submap->second->Clear();
69      }
70    }
71  }
72  else
73  {
74    for(it_map = fMap.begin(); it_map != fMap.end(); ++it_map)
75    {
76      it_map->second.first = kTRUE;
77      for(it_submap = it_map->second.second.begin();
78          it_submap != it_map->second.second.end(); ++it_submap)
79      {
80        it_submap->second->Clear();
81      }
82    }
83  } 
84}
85
86//------------------------------------------------------------------------------
87
88TObjArray *ExRootFilter::GetSubArray(ExRootClassifier *classifier, Int_t category)
89{
90  Int_t result;
91  TObject *element;
92  TObjArray *array;
93  TCategoryMap::iterator it_submap;
94  pair<TCategoryMap::iterator, bool> pair_submap;
95  pair<TClassifierMap::iterator, bool> pair_map;
96
97  TClassifierMap::iterator it_map = fMap.find(classifier);
98  if(it_map == fMap.end())
99  {
100    pair_map = fMap.insert(make_pair(classifier, make_pair(kTRUE, TCategoryMap())));
101    if(!pair_map.second)
102    {
103      throw runtime_error("can't insert category map");
104    }
105
106    it_map = pair_map.first;
107  }
108
109  if(it_map->second.first)
110  {
111    it_map->second.first = kFALSE;
112    fIter->Reset();
113    while((element = fIter->Next()) != 0)
114    {
115      result = classifier->GetCategory(element);
116      if(result < 0) continue;
117      it_submap = it_map->second.second.find(result);
118      if(it_submap == it_map->second.second.end())
119      {
120        array = new TObjArray(fCollection->GetSize());
121        pair_submap = it_map->second.second.insert(make_pair(result, array));
122        if(!pair_submap.second)
123        {
124          throw runtime_error("can't insert category");
125        }
126
127        it_submap = pair_submap.first;
128      }
129      it_submap->second->Add(element);
130    }
131  }
132
133  it_submap = it_map->second.second.find(category);
134  return (it_submap != it_map->second.second.end()) ? it_submap->second : 0; 
135}
136
137//------------------------------------------------------------------------------
138
Note: See TracBrowser for help on using the repository browser.