ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/interface/MatchMod.h
Revision: 1.1
Committed: Wed Jun 17 08:42:28 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Log Message:
Added MatchMod a module to give you a collection of geometrical matches of two collections.

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2     // $Id: MatchMod.h,v 1.5 2009/06/15 15:00:22 loizides Exp $
3     //
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     const char *GetColNameA() const { return fColNameA; }
32     const char *GetColNameB() const { return fColNameB; }
33     const char *GetColNameC() const { return fColNameC; }
34     const char *GetOutputName() const { return GetColNameC(); }
35     const char *GetInputNameA() const { return GetColNameA(); }
36     const char *GetInputNameB() const { return GetColNameB(); }
37     Double_t GetMatchRadius(Double_t m) { return fMaxR; }
38     void SetColNameA(const char *n) { fColNameA = n; }
39     void SetColNameB(const char *n) { fColNameB = n; }
40     void SetColNameC(const char *n) { fColNameC = n; }
41     void SetInputNameA(const char *n) { SetColNameA(n); }
42     void SetInputNameB(const char *n) { SetColNameB(n); }
43     void SetOutputName(const char *n) { SetColNameC(n); }
44     void SetMatchRadius(Double_t m) { fMaxR = m; }
45    
46     protected:
47     void Process();
48    
49     TString fColNameA; //name of input collection A
50     TString fColNameB; //name of input collection B
51     TString fColNameC; //name of output collection C
52     Double_t fMaxR; //maximum radius for matching (def=0.1)
53     Bool_t fAddPairs; //=true then add Pair into output collection (def=1)
54    
55     ClassDef(MatchMod,1) // Generic matching module
56     };
57     }
58    
59     //--------------------------------------------------------------------------------------------------
60     template<class ClA, class ClB>
61     mithep::MatchMod<ClA,ClB>::MatchMod(const char *name, const char *title) :
62     BaseMod(name,title),
63     fMaxR(0.1),
64     fAddPairs(kTRUE)
65     {
66     // Constructor.
67     }
68    
69     //--------------------------------------------------------------------------------------------------
70     template<class ClA, class ClB>
71     void mithep::MatchMod<ClA,ClB>::Process()
72     {
73     // Process the two collection and find matching pairs.
74    
75     using namespace mithep;
76    
77     Collection<ClA> *colA =
78     GetObjThisEvt<Collection<ClA> >(GetColNameA());
79     if (!colA) {
80     this->SendError(kAbortModule,
81     "Process",
82     "Could not obtain collection with name %s!", GetColNameA());
83     return;
84     }
85    
86     Collection<ClB> *colB =
87     GetObjThisEvt<Collection<ClB> >(GetColNameB());
88     if (!colB) {
89     this->SendError(kAbortModule,
90     "Process",
91     "Could not obtain collection with name %s!", GetColNameB());
92     return;
93     }
94    
95     if (fAddPairs) {
96     ObjArray<Pair<ClA,ClB> > *out = new ObjArray<Pair<ClA,ClB> >(0,GetOutputName());
97     out->SetOwner(kTRUE);
98     const UInt_t ents = colA->GetEntries();
99     for(UInt_t i=0;i<ents;++i) {
100     const ClA *pA = colA->At(i);
101     const ClB *pB = MatchingTools::Closest(pA,*colB,fMaxR,kFALSE);
102     if (!pB)
103     continue;
104     out->AddOwned(new Pair<ClA,ClB>(pA,pB));
105     }
106     AddObjThisEvt(out);
107     } else {
108     ObjArray<ClA> *out = new ObjArray<ClA>(0,GetOutputName());
109     out->SetOwner(kFALSE);
110     const UInt_t ents = colA->GetEntries();
111     for(UInt_t i=0;i<ents;++i) {
112     const ClA *pA = colA->At(i);
113     const ClB *pB = MatchingTools::Closest(pA,*colB,fMaxR,kFALSE);
114     if (!pB)
115     continue;
116     out->Add(pA);
117     }
118     }
119     }
120     #endif