ATLAS Offline Software
Loading...
Searching...
No Matches
CheckFlow.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// File: Generators/FlowAfterburner/CheckFlow.h
6// Description:
7// This is a simple algorithm to histogram particle properties
8// for diagnosing of flow generation
9//
10// AuthorList:
11// Andrzej Olszewski: Initial Code February 2006
12// Andrzej Olszewski: Converted to ROOT histograms July 2007
15#include "GaudiKernel/ITHistSvc.h"
16
17#include <TH1F.h>
18#include <TH2F.h>
19#include <TH3F.h>
20
21#include "AtlasHepMC/GenEvent.h"
24
25#include <cmath>
26
27
28typedef std::vector<HepMC::ConstGenParticlePtr> MCparticleCollection ;
29
30CheckFlow::CheckFlow(const std::string& name, ISvcLocator* pSvcLocator) :
31 AthAlgorithm(name, pSvcLocator)
32{
33}
34
36
37 ATH_CHECK(m_hijingKey.initialize());
38
39 ATH_MSG_INFO(">>> CheckFlow from Initialize");
40
41 m_hgenerated = new TH1F("ngen","Generated",100,0,100000);
42 m_b = new TH1F("b","Impact parameter",35,0.,35.0);
43 m_phi = new TH1F("phi","Phi",100,-M_PI,M_PI);
44 m_phiR = new TH1F("phiR","PhiR",100,0,2*M_PI);
45 m_phi_vs_phiR = new TH1F("phi_vs_phiR","Phi - PhiR",100,-M_PI,M_PI);
46 m_phiv1reco_vs_phiR = new TH2F("phiv1reco_vs_phiR",
47 "PhiV1Reco vs PhiR", 30,-M_PI,M_PI,30,-M_PI,M_PI);
48 m_phiv2reco_vs_phiR = new TH2F("phiv2reco_vs_phiR",
49 "PhiV2Reco vs PhiR", 30,-M_PI/2,M_PI/2,30,-M_PI/2,M_PI/2);
50 m_phi_vs_phiR_etap = new TH1F("phi_vs_phiR_etap",
51 "Phi - PhiR positive eta",
52 100,-M_PI,M_PI);
53 m_phi_vs_phiR_etan = new TH1F("phi_vs_phiR_etan",
54 "Phi - PhiR negative eta",
55 100,-M_PI,M_PI);
56 m_v2betapth = new TH3F("v2betapth",
57 "V2 vs b, eta, pt",
58 20,0,20, 30,-7.5,7.5, 25,0,5000);
59 m_ebetapth = new TH3F("ebetapth",
60 "Tracks vs b, eta, pt",
61 20,0,20, 30,-7.5,7.5, 25,0,5000);
62
63 SmartIF<ITHistSvc> rootHistSvc{Gaudi::svcLocator()->service("THistSvc")};
64 if (!rootHistSvc) {
65 ATH_MSG_ERROR( "Unable to locate THistSvc" );
66 return StatusCode::FAILURE;
67 }
68
69 std::string histPath = "/FlowOutPut/";
70 if ( rootHistSvc->regHist(histPath+m_hgenerated->GetName(),
71 m_hgenerated).isFailure() )
72 msg(MSG::WARNING) << "Can't book "
73 << histPath+m_hgenerated->GetName() << endmsg;
74
75 if ( rootHistSvc->regHist(histPath+m_b->GetName(),
76 m_b).isFailure() )
77 msg(MSG::WARNING) << "Can't book "
78 << histPath+m_b->GetName() << endmsg;
79
80 if ( rootHistSvc->regHist(histPath+m_phi->GetName(),
81 m_phi).isFailure() )
82 msg(MSG::WARNING) << "Can't book "
83 << histPath+m_phi->GetName() << endmsg;
84
85 if ( rootHistSvc->regHist(histPath+m_phiR->GetName(),
86 m_phiR).isFailure() )
87 msg(MSG::WARNING) << "Can't book "
88 << histPath+m_phiR->GetName() << endmsg;
89
90 if ( rootHistSvc->regHist(histPath+m_phi_vs_phiR->GetName(),
91 m_phi_vs_phiR).isFailure() )
92 msg(MSG::WARNING) << "Can't book "
93 << histPath+m_phi_vs_phiR->GetName() << endmsg;
94
95 if ( rootHistSvc->regHist(histPath+m_phiv1reco_vs_phiR->GetName(),
96 m_phiv1reco_vs_phiR).isFailure() )
97 msg(MSG::WARNING) << "Can't book "
98 << histPath+m_phiv1reco_vs_phiR->GetName() << endmsg;
99
100 if ( rootHistSvc->regHist(histPath+m_phiv2reco_vs_phiR->GetName(),
101 m_phiv2reco_vs_phiR).isFailure() )
102 msg(MSG::WARNING) << "Can't book "
103 << histPath+m_phiv2reco_vs_phiR->GetName() << endmsg;
104
105 if ( rootHistSvc->regHist(histPath+m_phi_vs_phiR_etap->GetName(),
106 m_phi_vs_phiR_etap).isFailure() )
107 msg(MSG::WARNING) << "Can't book "
108 << histPath+m_phi_vs_phiR_etap->GetName() << endmsg;
109
110 if ( rootHistSvc->regHist(histPath+m_phi_vs_phiR_etan->GetName(),
111 m_phi_vs_phiR_etan).isFailure() )
112 msg(MSG::WARNING) << "Can't book "
113 << histPath+m_phi_vs_phiR_etan->GetName() << endmsg;
114
115 if ( rootHistSvc->regHist(histPath+m_v2betapth->GetName(),
116 m_v2betapth).isFailure() )
117 msg(MSG::WARNING) << "Can't book "
118 << histPath+m_v2betapth->GetName() << endmsg;
119
120 if ( rootHistSvc->regHist(histPath+m_ebetapth->GetName(),
121 m_ebetapth).isFailure() )
122 msg(MSG::WARNING) << "Can't book "
123 << histPath+m_ebetapth->GetName() << endmsg;
124
125 msg(MSG::DEBUG) << "Histograms have been booked " << endmsg;
126
128
129 return StatusCode::SUCCESS;
130}
131
132StatusCode CheckFlow::execute() {
133 msg(MSG::INFO) << ">>> CheckFlow from execute" << endmsg;
134
135 //
136 // Event parameters
137 //
139 float b = hijing_pars->get_b();
140 float phiR = hijing_pars->get_bphi();
141
142
143 // Check cut on impact parameter b
144 if(b<m_bcut_min || b>m_bcut_max)
145 return StatusCode::SUCCESS;
146
147 m_b->Fill(b, 1.);
148 m_phiR->Fill(phiR, 1.);
149
150 float ngenerated = 0;
151 double phiv1_recon, phiv1_recop;
152 double phiv1_reco = 0, phiv2_reco = 0;
153 double phi_reco_sin1phip = 0, phi_reco_cos1phip = 0;
154 double phi_reco_sin1phin = 0, phi_reco_cos1phin = 0;
155 double phi_reco_sin2phi = 0, phi_reco_cos2phi = 0;
156
157 std::vector<HepMC::ConstGenParticlePtr> particles;
158 StatusCode stat = m_tesIO->getMC(particles, false, m_key);
159 if (stat.isFailure()) {
160 msg(MSG::ERROR) << "Could not find " << m_key << endmsg;
161 return stat;
162 }
163
164 for (auto pitr: particles) {
165 int pid = pitr->pdg_id();
166 int p_stat = pitr->status();
167 double pt = pitr->momentum().perp();
168 double rapid = pitr->momentum().pseudoRapidity();
169 double phi = pitr->momentum().phi();
170 msg(MSG::DEBUG)
171 << " PID = " << pid << " Status = " << p_stat
172 << " Eta = " << rapid << " Phi = " << phi
173 << " PhiR = " << phiR << endmsg;
174
175 if( (std::abs(rapid) >= m_rapcut_min) && (std::abs(rapid) <= m_rapcut_max) &&
176 (std::abs(pt) >= m_ptcut_min) && (std::abs(pt) <= m_ptcut_max) ) {
177 ngenerated++;
178 m_phi->Fill(phi, 1.);
179 double phi_corr = phi - phiR;
180 // v2 vs b,eta,pt histograms
181 m_v2betapth->Fill(b,rapid,pt,cos(2*phi_corr));
182 m_ebetapth->Fill(b,rapid,pt,1);
183 // -----------------
184 // convert to (-pi,pi) range
185 int kpi = (int)(phi_corr/(2*M_PI));
186 phi_corr -= kpi * 2*M_PI;
187 if (phi_corr < -M_PI) phi_corr += 2*M_PI;
188 if (phi_corr > M_PI) phi_corr -= 2*M_PI;
189 // --------------------------------------
190 m_phi_vs_phiR->Fill(phi_corr, 1.);
191 if(rapid>=0) m_phi_vs_phiR_etap->Fill(phi_corr, 1.);
192 else m_phi_vs_phiR_etan->Fill(phi_corr, 1.);
193 // -------------------------------------------------
194 if( rapid >= 0 ) {
195 phi_reco_sin1phip += std::sin(1*phi);
196 phi_reco_cos1phip += std::cos(1*phi);
197 } else {
198 phi_reco_sin1phin += std::sin(1*phi);
199 phi_reco_cos1phin += std::cos(1*phi);
200 }
201 phi_reco_sin2phi += std::sin(2*phi);
202 phi_reco_cos2phi += std::cos(2*phi);
203 }
204 }
205 m_hgenerated->Fill(ngenerated, 1.);
206
207 // calculate event plane position
208 phiv1_recop = std::atan2( phi_reco_sin1phip,phi_reco_cos1phip );
209 phiv1_recon = std::atan2( phi_reco_sin1phin,phi_reco_cos1phin ) + M_PI;
210 if( phiv1_recon > M_PI ) phiv1_recon -= 2*M_PI;
211 // averaged v1 plane position (in pos and neg eta ranges)
212 phiv1_reco = (phiv1_recop + phiv1_recon)/2;
213 phiv2_reco = 0.5 * std::atan2( phi_reco_sin2phi,phi_reco_cos2phi );
214 msg(MSG::INFO)
215 << " PhiR = " << phiR
216 << " PhiV1Reco = " << phiv1_reco
217 << " PhiV2Reco = " << phiv2_reco << endmsg;
218
219 // convert phiR (0, 2*pi) to (-pi,pi) range
220 double phiR_v1corr = phiR;
221 if( phiR > M_PI ) phiR_v1corr = phiR_v1corr - 2*M_PI;
222 // convert phiR (0, 2*pi) to (-pi/2,pi/2) range
223 double phiR_v2corr = phiR;
224 if (phiR > M_PI/2) phiR_v2corr -= M_PI;
225 if (phiR > 3*M_PI/2) phiR_v2corr -= 2*M_PI;
226 m_phiv1reco_vs_phiR->Fill(phiR_v1corr, phiv1_reco);
227 m_phiv2reco_vs_phiR->Fill(phiR_v2corr, phiv2_reco);
228
229 // End of execution for each event
230 return StatusCode::SUCCESS;
231}
232
234 msg(MSG::INFO) << ">>> CheckFlow from finalize" << endmsg;
235
236 return StatusCode::SUCCESS;
237}
238
#define M_PI
Scalar phi() const
phi method
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
std::vector< HepMC::ConstGenParticlePtr > MCparticleCollection
Definition CheckFlow.cxx:28
Base class from which all concrete Athena algorithm classes should be derived.
TH3F * m_ebetapth
Definition CheckFlow.h:59
StringProperty m_key
Definition CheckFlow.h:38
TH1F * m_phi_vs_phiR
Definition CheckFlow.h:53
TH2F * m_phiv1reco_vs_phiR
Definition CheckFlow.h:54
TH1F * m_phi
Definition CheckFlow.h:51
TruthHelper::GenAccessIO * m_tesIO
Definition CheckFlow.h:62
TH1F * m_phi_vs_phiR_etap
Definition CheckFlow.h:56
SG::ReadHandleKey< HijingEventParams > m_hijingKey
Definition CheckFlow.h:61
TH2F * m_phiv2reco_vs_phiR
Definition CheckFlow.h:55
StatusCode initialize()
Definition CheckFlow.cxx:35
TH1F * m_phiR
Definition CheckFlow.h:52
StatusCode finalize()
TH1F * m_phi_vs_phiR_etan
Definition CheckFlow.h:57
TH1F * m_hgenerated
Definition CheckFlow.h:49
StatusCode execute()
DoubleProperty m_ptcut_min
Definition CheckFlow.h:43
DoubleProperty m_rapcut_min
Definition CheckFlow.h:45
DoubleProperty m_bcut_max
Definition CheckFlow.h:42
DoubleProperty m_rapcut_max
Definition CheckFlow.h:46
TH1F * m_b
Definition CheckFlow.h:50
DoubleProperty m_ptcut_max
Definition CheckFlow.h:44
TH3F * m_v2betapth
Definition CheckFlow.h:58
MsgStream & msg
Definition testRead.cxx:32