ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/interface/MatchMod.h
Revision: 1.4
Committed: Thu Jun 18 15:26:49 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a, Mit_028a, Mit_028, Mit_027, Mit_027a, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, Mit_009c, HEAD
Changes since 1.3: +3 -1 lines
Log Message:
Printout warning

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: MatchMod.h,v 1.3 2009/06/17 15:32:04 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 Bool_t GetAddPairs(Bool_t b) const { return fAddPairs; }
32 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 void SetAddPairs(Bool_t b) { fAddPairs = b; }
47
48 protected:
49 void Process();
50 void SlaveBegin();
51
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 AddObjThisEvt(out);
122 }
123 }
124
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 SendError(kWarning, "SlaveBegin", "No name given for output collection,"
147 " will use \"%s\"", fColNameC.Data());
148 }
149 }
150 #endif