ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/interface/MatchMod.h
Revision: 1.3
Committed: Wed Jun 17 15:32:04 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -1 lines
Log Message:
Bugfix

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.3 // $Id: MatchMod.h,v 1.2 2009/06/17 14:52:47 loizides Exp $
3 loizides 1.1 //
4     // MatchMod
5     //
6     // This module compares two input collections geomatrically, and creates a new
7     // collection of Pair objects that match within a given radius in eta-phi.
8     //
9     // Authors: C.Loizides
10     //--------------------------------------------------------------------------------------------------
11    
12     #ifndef MITPHYSICS_MODS_MATCHMOD_H
13     #define MITPHYSICS_MODS_MATCHMOD_H
14    
15     #include "MitAna/DataCont/interface/Collection.h"
16     #include "MitAna/DataCont/interface/ObjArray.h"
17     #include "MitAna/DataTree/interface/Pair.h"
18     #include "MitAna/TreeMod/interface/BaseMod.h"
19     #include "MitPhysics/Utils/interface/MatchingTools.h"
20     #include <TH1D.h>
21    
22     namespace mithep
23     {
24     template<class ClA, class ClB=ClA>
25     class MatchMod : public BaseMod
26     {
27     public:
28     MatchMod(const char *name="MatchMod",
29     const char *title="Generic matching module");
30    
31 loizides 1.2 Bool_t GetAddPairs(Bool_t b) const { return fAddPairs; }
32 loizides 1.1 const char *GetColNameA() const { return fColNameA; }
33     const char *GetColNameB() const { return fColNameB; }
34     const char *GetColNameC() const { return fColNameC; }
35     const char *GetOutputName() const { return GetColNameC(); }
36     const char *GetInputNameA() const { return GetColNameA(); }
37     const char *GetInputNameB() const { return GetColNameB(); }
38     Double_t GetMatchRadius(Double_t m) { return fMaxR; }
39     void SetColNameA(const char *n) { fColNameA = n; }
40     void SetColNameB(const char *n) { fColNameB = n; }
41     void SetColNameC(const char *n) { fColNameC = n; }
42     void SetInputNameA(const char *n) { SetColNameA(n); }
43     void SetInputNameB(const char *n) { SetColNameB(n); }
44     void SetOutputName(const char *n) { SetColNameC(n); }
45     void SetMatchRadius(Double_t m) { fMaxR = m; }
46 loizides 1.2 void SetAddPairs(Bool_t b) { fAddPairs = b; }
47 loizides 1.1
48     protected:
49     void Process();
50 loizides 1.2 void SlaveBegin();
51 loizides 1.1
52     TString fColNameA; //name of input collection A
53     TString fColNameB; //name of input collection B
54     TString fColNameC; //name of output collection C
55     Double_t fMaxR; //maximum radius for matching (def=0.1)
56     Bool_t fAddPairs; //=true then add Pair into output collection (def=1)
57    
58     ClassDef(MatchMod,1) // Generic matching module
59     };
60     }
61    
62     //--------------------------------------------------------------------------------------------------
63     template<class ClA, class ClB>
64     mithep::MatchMod<ClA,ClB>::MatchMod(const char *name, const char *title) :
65     BaseMod(name,title),
66     fMaxR(0.1),
67     fAddPairs(kTRUE)
68     {
69     // Constructor.
70     }
71    
72     //--------------------------------------------------------------------------------------------------
73     template<class ClA, class ClB>
74     void mithep::MatchMod<ClA,ClB>::Process()
75     {
76     // Process the two collection and find matching pairs.
77    
78     using namespace mithep;
79    
80     Collection<ClA> *colA =
81     GetObjThisEvt<Collection<ClA> >(GetColNameA());
82     if (!colA) {
83     this->SendError(kAbortModule,
84     "Process",
85     "Could not obtain collection with name %s!", GetColNameA());
86     return;
87     }
88    
89     Collection<ClB> *colB =
90     GetObjThisEvt<Collection<ClB> >(GetColNameB());
91     if (!colB) {
92     this->SendError(kAbortModule,
93     "Process",
94     "Could not obtain collection with name %s!", GetColNameB());
95     return;
96     }
97    
98     if (fAddPairs) {
99     ObjArray<Pair<ClA,ClB> > *out = new ObjArray<Pair<ClA,ClB> >(0,GetOutputName());
100     out->SetOwner(kTRUE);
101     const UInt_t ents = colA->GetEntries();
102     for(UInt_t i=0;i<ents;++i) {
103     const ClA *pA = colA->At(i);
104     const ClB *pB = MatchingTools::Closest(pA,*colB,fMaxR,kFALSE);
105     if (!pB)
106     continue;
107     out->AddOwned(new Pair<ClA,ClB>(pA,pB));
108     }
109     AddObjThisEvt(out);
110     } else {
111     ObjArray<ClA> *out = new ObjArray<ClA>(0,GetOutputName());
112     out->SetOwner(kFALSE);
113     const UInt_t ents = colA->GetEntries();
114     for(UInt_t i=0;i<ents;++i) {
115     const ClA *pA = colA->At(i);
116     const ClB *pB = MatchingTools::Closest(pA,*colB,fMaxR,kFALSE);
117     if (!pB)
118     continue;
119     out->Add(pA);
120     }
121 loizides 1.3 AddObjThisEvt(out);
122 loizides 1.1 }
123     }
124 loizides 1.2
125     //--------------------------------------------------------------------------------------------------
126     template<class ClA, class ClB>
127     void mithep::MatchMod<ClA,ClB>::SlaveBegin()
128     {
129     // Run starting code on the client to do some consistency checks.
130    
131    
132     if (fColNameA.IsNull()) {
133     SendError(kAbortModule, "SlaveBegin", "No name given for input collection A.");
134     return;
135     }
136    
137     if (fColNameB.IsNull()) {
138     SendError(kAbortModule, "SlaveBegin", "No name given for input collection B.");
139     return;
140     }
141    
142     if (fColNameC.IsNull()) {
143     fColNameC="Matched";
144     fColNameC+=fColNameA;
145     fColNameC+=fColNameB;
146     }
147     }
148 loizides 1.1 #endif