Fork me on GitHub

source: git/modules/VertexSorter.cc@ b0fa9af

ImprovedOutputFile Timing dual_readout llp
Last change on this file since b0fa9af was b0fa9af, checked in by Michele Selvaggi <michele.selvaggi@…>, 9 years ago

added missing cc

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/** \class VertexSorter
2 *
3 * Merges particles from pile-up sample into event
4 *
5 *
6 * $Date: 2013-02-12 15:13:59 +0100 (Tue, 12 Feb 2013) $
7 * $Revision: 907 $
8 *
9 *
10 * \author M. Selvaggi - UCL, Louvain-la-Neuve
11 *
12 */
13
14#include <unordered_map>
15#include "modules/VertexSorter.h"
16
17//#include "CLHEP/Units/GlobalSystemOfUnits.h"
18//#include "CLHEP/Units/GlobalPhysicalConstants.h"
19
20#include "classes/DelphesClasses.h"
21#include "classes/DelphesFactory.h"
22#include "classes/DelphesFormula.h"
23#include "classes/DelphesPileUpReader.h"
24
25#include "ExRootAnalysis/ExRootResult.h"
26#include "ExRootAnalysis/ExRootFilter.h"
27#include "ExRootAnalysis/ExRootClassifier.h"
28
29#include "TMath.h"
30#include "TString.h"
31#include "TFormula.h"
32#include "TRandom3.h"
33#include "TObjArray.h"
34#include "TDatabasePDG.h"
35#include "TLorentzVector.h"
36#include "TMatrixT.h"
37#include "TVector3.h"
38
39static const double mm = 1.;
40static const double m = 1000.*mm;
41static const double ns = 1.;
42static const double s = 1.e+9 *ns;
43static const double c_light = 2.99792458e+8 * m/s;
44
45//------------------------------------------------------------------------------
46
47VertexSorter::VertexSorter() :
48 fInputArray(NULL), fTrackInputArray(NULL), fItTrackInputArray(NULL), fJetInputArray(NULL), fItJetInputArray(NULL), fOutputArray(NULL)
49{
50}
51
52//------------------------------------------------------------------------------
53
54VertexSorter::~VertexSorter()
55{
56}
57
58//------------------------------------------------------------------------------
59
60void VertexSorter::Init()
61{
62 fInputArray = ImportArray(GetString("InputArray", "VertexFinder/clusters"));
63
64 fTrackInputArray = ImportArray(GetString("TrackInputArray", "VertexFinder/tracks"));
65 fItTrackInputArray = fTrackInputArray->MakeIterator();
66
67 if (string (GetString("JetInputArray", "")) != "")
68 {
69 fJetInputArray = ImportArray(GetString("JetInputArray", ""));
70 fItJetInputArray = fJetInputArray->MakeIterator();
71 }
72
73 if (string (GetString("BeamSpotInputArray", "")) != "")
74 {
75 fBeamSpotInputArray = ImportArray(GetString("BeamSpotInputArray", ""));
76 fItBeamSpotInputArray = fBeamSpotInputArray->MakeIterator();
77 }
78
79 fOutputArray = ExportArray(GetString("OutputArray", "clusters"));
80
81 fMethod = GetString ("Method", "BTV");
82}
83
84//------------------------------------------------------------------------------
85
86void VertexSorter::Finish()
87{
88 if(fItTrackInputArray) delete fItTrackInputArray;
89 if(fItJetInputArray) delete fItJetInputArray;
90}
91
92//------------------------------------------------------------------------------
93//
94bool VertexSorter::secondDescending (pair<unsigned, double> pair0, pair<unsigned, double> pair1)
95{
96 return (pair0.second > pair1.second);
97}
98bool VertexSorter::secondAscending (pair<unsigned, double> pair0, pair<unsigned, double> pair1)
99{
100 return (pair0.second < pair1.second);
101}
102
103void VertexSorter::Process()
104{
105 Candidate *candidate, *jetCandidate, *beamSpotCandidate;
106 unordered_map<int, unsigned> clusterIDToIndex;
107 unordered_map<int, double> clusterIDToSumPT2;
108 vector<pair<int, double> > sortedClusterIDs;
109
110 for (int iCluster = 0; iCluster < fInputArray->GetEntries (); iCluster++)
111 {
112 const Candidate &cluster = *((Candidate *) fInputArray->At (iCluster));
113 clusterIDToIndex[cluster.ClusterIndex] = iCluster;
114 clusterIDToSumPT2[cluster.ClusterIndex] = 0.0;
115 }
116
117 if (fMethod == "BTV")
118 {
119 if (!fJetInputArray)
120 {
121 cout << "BTV PV sorting selected, but no jet collection given!" << endl;
122 throw 0;
123 }
124
125 fItTrackInputArray->Reset();
126 while((candidate = static_cast<Candidate*>(fItTrackInputArray->Next())))
127 {
128 if (candidate->Momentum.Pt () < 1.0)
129 continue;
130 if (candidate->ClusterIndex < 0)
131 continue;
132 TLorentzVector p (candidate->Momentum.Px (), candidate->Momentum.Py (), candidate->Momentum.Pz (), candidate->Momentum.E ());
133 bool isInJet = false;
134
135 fItJetInputArray->Reset();
136 while((jetCandidate = static_cast<Candidate*>(fItJetInputArray->Next())))
137 {
138 if (jetCandidate->Momentum.Pt () < 30.0)
139 continue;
140 TLorentzVector q (jetCandidate->Momentum.Px (), jetCandidate->Momentum.Py (), jetCandidate->Momentum.Pz (), jetCandidate->Momentum.E ());
141
142 if (p.DeltaR (q) > 0.4)
143 continue;
144 isInJet = true;
145 break;
146 }
147 if (!isInJet)
148 continue;
149
150 clusterIDToSumPT2.at (candidate->ClusterIndex) += candidate->Momentum.Pt () * candidate->Momentum.Pt ();
151 }
152
153 for (const auto &clusterID : clusterIDToSumPT2)
154 sortedClusterIDs.push_back (make_pair (clusterID.first, clusterID.second));
155 sort (sortedClusterIDs.begin (), sortedClusterIDs.end (), secondDescending);
156 }
157 else if (fMethod == "GenClosest")
158 {
159 if (!fBeamSpotInputArray)
160 {
161 cout << "GenClosest PV sorting selected, but no beamspot collection given!" << endl;
162 throw 0;
163 }
164 if (!fBeamSpotInputArray->GetSize ())
165 {
166 cout << "Beamspot collection is empty!" << endl;
167 throw 0;
168 }
169
170 beamSpotCandidate = (Candidate *) fBeamSpotInputArray->At (0);
171 for (int iCluster = 0; iCluster < fInputArray->GetEntries (); iCluster++)
172 {
173 const Candidate &cluster = *((Candidate *) fInputArray->At (iCluster));
174 sortedClusterIDs.push_back (make_pair (cluster.ClusterIndex, fabs (cluster.Position.Z () - beamSpotCandidate->Position.Z ())));
175 }
176 sort (sortedClusterIDs.begin (), sortedClusterIDs.end (), secondAscending);
177 }
178 else if (fMethod == "GenBest")
179 {
180 fItTrackInputArray->Reset();
181 while((candidate = static_cast<Candidate*>(fItTrackInputArray->Next())))
182 {
183 if (candidate->IsPU)
184 continue;
185 for (const auto &clusterID : clusterIDToIndex)
186 {
187 if (candidate->ClusterIndex != clusterID.first)
188 continue;
189 clusterIDToSumPT2.at (clusterID.first) += candidate->Momentum.Pt () * candidate->Momentum.Pt ();
190 }
191 }
192
193 for (const auto &clusterID : clusterIDToSumPT2)
194 sortedClusterIDs.push_back (make_pair (clusterID.first, clusterID.second));
195 sort (sortedClusterIDs.begin (), sortedClusterIDs.end (), secondDescending);
196 }
197 else
198 {
199 cout << "\"" << fMethod << "\" is not a valid sorting method!" << endl;
200 cout << "Valid methods are:" << endl;
201 cout << " BTV" << endl;
202 cout << " GenClosest" << endl;
203 cout << " GenBest" << endl;
204 throw 0;
205 }
206
207 for (const auto &clusterID : sortedClusterIDs)
208 {
209 Candidate *cluster = (Candidate *) fInputArray->At (clusterIDToIndex.at (clusterID.first));
210 if (fMethod == "BTV")
211 cluster->BTVSumPT2 = clusterID.second;
212 else if (fMethod == "GenClosest")
213 cluster->GenDeltaZ = clusterID.second;
214 else if (fMethod == "GenBest")
215 cluster->GenSumPT2 = clusterID.second;
216 fOutputArray->Add (cluster);
217 }
218}
219
220//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.