ATLAS Offline Software
CheckFlow.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // File: Generators/FlowAfterburnber/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 
16 #include <TH1F.h>
17 #include <TH2F.h>
18 #include <TH3F.h>
19 
20 #include "AtlasHepMC/GenEvent.h"
21 #include "AtlasHepMC/GenParticle.h"
22 #include "AtlasHepMC/GenVertex.h"
23 
25 
26 
27 typedef std::vector<HepMC::ConstGenParticlePtr> MCparticleCollection ;
28 
29 CheckFlow::CheckFlow(const std::string& name, ISvcLocator* pSvcLocator) :
30  AthAlgorithm(name, pSvcLocator)
31 {
32 }
33 
35 
37 
38  ATH_MSG_INFO(">>> CheckFlow from Initialize");
39 
40  m_hgenerated = new TH1F("ngen","Generated",100,0,100000);
41  m_b = new TH1F("b","Impact parameter",35,0.,35.0);
42  m_phi = new TH1F("phi","Phi",100,-M_PI,M_PI);
43  m_phiR = new TH1F("phiR","PhiR",100,0,2*M_PI);
44  m_phi_vs_phiR = new TH1F("phi_vs_phiR","Phi - PhiR",100,-M_PI,M_PI);
45  m_phiv1reco_vs_phiR = new TH2F("phiv1reco_vs_phiR",
46  "PhiV1Reco vs PhiR", 30,-M_PI,M_PI,30,-M_PI,M_PI);
47  m_phiv2reco_vs_phiR = new TH2F("phiv2reco_vs_phiR",
48  "PhiV2Reco vs PhiR", 30,-M_PI/2,M_PI/2,30,-M_PI/2,M_PI/2);
49  m_phi_vs_phiR_etap = new TH1F("phi_vs_phiR_etap",
50  "Phi - PhiR positive eta",
51  100,-M_PI,M_PI);
52  m_phi_vs_phiR_etan = new TH1F("phi_vs_phiR_etan",
53  "Phi - PhiR negative eta",
54  100,-M_PI,M_PI);
55  m_v2betapth = new TH3F("v2betapth",
56  "V2 vs b, eta, pt",
57  20,0,20, 30,-7.5,7.5, 25,0,5000);
58  m_ebetapth = new TH3F("ebetapth",
59  "Tracks vs b, eta, pt",
60  20,0,20, 30,-7.5,7.5, 25,0,5000);
61 
62  SmartIF<ITHistSvc> rootHistSvc{Gaudi::svcLocator()->service("THistSvc")};
63  if (!rootHistSvc) {
64  ATH_MSG_ERROR( "Unable to locate THistSvc" );
65  return StatusCode::FAILURE;
66  }
67 
68  std::string StreamAndPath="/FlowOutPut/";
69  std::string histPath = StreamAndPath;
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 
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;
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 
CheckFlow.h
CheckFlow::execute
StatusCode execute()
Definition: CheckFlow.cxx:132
CheckFlow::m_ptcut_min
DoubleProperty m_ptcut_min
Definition: CheckFlow.h:44
MCparticleCollection
std::vector< HepMC::ConstGenParticlePtr > MCparticleCollection
Definition: CheckFlow.cxx:27
GenEvent.h
CheckFlow::m_phi
TH1F * m_phi
Definition: CheckFlow.h:52
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HijingEventParams.h
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
GenVertex.h
test_pyathena.pt
pt
Definition: test_pyathena.py:11
M_PI
#define M_PI
Definition: ActiveFraction.h:11
CheckFlow::m_v2betapth
TH3F * m_v2betapth
Definition: CheckFlow.h:59
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
CheckFlow::m_phi_vs_phiR_etap
TH1F * m_phi_vs_phiR_etap
Definition: CheckFlow.h:57
GenParticle.h
CheckFlow::m_phiv1reco_vs_phiR
TH2F * m_phiv1reco_vs_phiR
Definition: CheckFlow.h:55
CheckFlow::m_ebetapth
TH3F * m_ebetapth
Definition: CheckFlow.h:60
CheckFlow::finalize
StatusCode finalize()
Definition: CheckFlow.cxx:233
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
McEventCollection.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CheckFlow::initialize
StatusCode initialize()
Definition: CheckFlow.cxx:34
CheckFlow::m_phi_vs_phiR
TH1F * m_phi_vs_phiR
Definition: CheckFlow.h:54
CheckFlow.CheckFlow
CheckFlow
Definition: CheckFlow.py:50
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
CheckFlow::m_phiR
TH1F * m_phiR
Definition: CheckFlow.h:53
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CheckFlow::m_hgenerated
TH1F * m_hgenerated
Definition: CheckFlow.h:50
TruthHelper::GenAccessIO::getMC
StatusCode getMC(MCParticleCollection &mcParticles, const bool ifgen=false, const std::string &key="GEN_EVENT") const
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:29
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CheckFlow::m_phi_vs_phiR_etan
TH1F * m_phi_vs_phiR_etan
Definition: CheckFlow.h:58
CheckFlow::m_key
StringProperty m_key
Definition: CheckFlow.h:39
beamspotman.stat
stat
Definition: beamspotman.py:266
AthAlgorithm
Definition: AthAlgorithm.h:47
CheckFlow::m_rapcut_max
DoubleProperty m_rapcut_max
Definition: CheckFlow.h:47
CheckFlow::m_tesIO
TruthHelper::GenAccessIO * m_tesIO
Definition: CheckFlow.h:63
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CheckFlow::m_phiv2reco_vs_phiR
TH2F * m_phiv2reco_vs_phiR
Definition: CheckFlow.h:56
CheckFlow::m_bcut_max
DoubleProperty m_bcut_max
Definition: CheckFlow.h:43
TruthHelper::GenAccessIO
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:21
CheckFlow::m_rapcut_min
DoubleProperty m_rapcut_min
Definition: CheckFlow.h:46
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
CheckFlow::m_b
TH1F * m_b
Definition: CheckFlow.h:51
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
CheckFlow::m_ptcut_max
DoubleProperty m_ptcut_max
Definition: CheckFlow.h:45
CheckFlow::m_hijingKey
SG::ReadHandleKey< HijingEventParams > m_hijingKey
Definition: CheckFlow.h:62