ATLAS Offline Software
Loading...
Searching...
No Matches
VP1PartSpectSystem.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
10
11/* --- FIXME: Qat has still to be ported to Qt5 I think...
12// Plotting
13//#include "QatPlotting/PlotStream.h"
14//#include "QatPlotWidgets/PlotView.h"
15//#include "QatDataAnalysis/Hist1D.h"
16//#include "QatPlotting/PlotHist1D.h"
17 */
18
19#include <QMainWindow>
20#include <QToolBar>
21#include <QAction>
22
23#include "TFile.h"
24#include "TROOT.h"
25#include "TH1F.h"
26#include "TKey.h"
27#include <memory>
28#include <sstream>
29
30
32public:
33 Imp();
34
36 std::unique_ptr<QMainWindow> PlotMainWindow;
37 std::unique_ptr<TFile> stream;
38
40};
41
46
48{
49 switch(parttype){
51 return QString("baryon_");
52 case VP1PartSpect::E :
53 return QString("e_");
55 return QString("gamma_");
57 return QString("lepton_");
59 return QString("meson_");
61 return QString("neutron_");
63 return QString("nucleus_");
64 case VP1PartSpect::Pi :
65 return QString("pi_");
67 return QString("proton_");
68 default:
69 return QString("");
70 }
71}
72
74 : IVP13DSystemSimple("PartSpectrum"
75 ,"System for displaying particle spectrum histograms"
76 ,"Vakho Tsulaia <tsulaia@mail.cern.ch>")
77 , m_d(new Imp())
78{
79}
80
85
87{
88 // Standard stuff
89 m_d->controller = new VP1PartSpectController(this);
90
91 // Connect controller signals to various slots
92 connect(m_d->controller,SIGNAL(fileUpdated(QString)),this,SLOT( fileUpdated(QString)));
93
94 connect(m_d->controller,SIGNAL(particleTypeChanged(VP1PartSpect::ParticleType)),this,SLOT(particleType()));
95
96 return m_d->controller;
97}
98
102
106
108{
109 VP1Serialise serialise(0/*version*/,this);
110 serialise.save(IVP13DSystemSimple::saveState());
111
113
114 serialise.save(m_d->controller->saveSettings());
115
116 serialise.disableUnsavedChecks();
117 return serialise.result();
118}
119
121{
122 VP1Deserialise state(ba,this);
123
124 if (state.version()!=0) {
125 message("Warning: State data in .vp1 file is in wrong format - ignoring!");
126 return;
127 }
128
130
132
133 m_d->controller->restoreSettings(state.restoreByteArray());
134
135 state.disableUnrestoredChecks();
136}
137
138void VP1PartSpectSystem::plotSpectrum(QStack<QString>& path, int copyNumber)
139{
140 // close plot main window if already open
141 m_d->PlotMainWindow.reset();
142
143 // Do something only if the system is active
144 if(activeState()==IVP1System::OFF) return;
145
146 if(!m_d->stream) {
147 message("No input file");
148 return;
149 }
150
151 m_d->stream->cd();
152 std::ostringstream copyNumberStream;
153 copyNumberStream << copyNumber;
154
155 while(path.size()>1){
156 QString dirBase= path.pop().replace(QString("::"),QString("_"));
157 QString directory=dirBase;
158 if(!gDirectory->cd(directory.toLatin1())) {
159 directory = (dirBase.toStdString()+"_"+copyNumberStream.str()).c_str();
160 if (!gDirectory->cd(directory.toLatin1())) {
161 directory = (dirBase.toStdString()+"_0").c_str();
162 if (!gDirectory->cd(directory.toLatin1())) {
163 message(QString("Unable to cd to ") + directory);
164 return;
165 } else {
166 messageDebug(QString("Entered ") + directory);
167 }
168 }
169 }
170 }
171
172 QString histogramName = m_d->histogramPrefix(m_d->controller->getParticleType());
173 QString entredHistoName = histogramName + "entred_";
174 QString entredHistoName_n = histogramName + "entred_";
175 QString entredHistoName_0 = histogramName + "entred_";
176 QString madeinHistoName = histogramName + "madein_";
177
178 QString histoNameBody = path.pop().replace(QString("::"),QString("_"))+QString("_hist");
179 QString histoNameBody_n = histoNameBody+QString("_") + QString(copyNumberStream.str().c_str())+QString("_hist");
180
181 QString histoNameBody_0 = histoNameBody+QString("_0_hist");
182
183 histogramName += histoNameBody;
184
185
186 entredHistoName += histoNameBody;
187 entredHistoName_n += histoNameBody_n;
188 entredHistoName_0 += histoNameBody_0;
189
190 TObject* entredObject = gROOT->FindObject(entredHistoName.toStdString().c_str());
191 if (!entredObject) {
192 entredObject = gROOT->FindObject(entredHistoName_n.toStdString().c_str());
193 if (!entredObject) {
194 entredObject = gROOT->FindObject(entredHistoName_0.toStdString().c_str());
195 if (!entredObject) {
196 message(QString("Unable to find histogram ") + entredHistoName);
197 }
198 else {
199 madeinHistoName += histoNameBody_0;
200 }
201 }
202 else {
203 madeinHistoName += histoNameBody_n;
204 }
205 }
206 else {
207 madeinHistoName += histoNameBody;
208 }
209
210
211
212 TH1F* tHist1F1 = 0;
213 TH1F* tHist1F2 = 0;
214
215
216 if(entredObject) {
217 tHist1F1 = dynamic_cast<TH1F*> (entredObject);
218 }
219
220
221 TObject* madeinObject = gROOT->FindObject(madeinHistoName.toStdString().c_str());
222 if(!madeinObject) {
223 message(QString("Unable to find histogram ") + madeinHistoName);
224 } else {
225 if(tHist1F1){
226 tHist1F2 = dynamic_cast<TH1F*> (madeinObject);
227 } else {
228 tHist1F1 = dynamic_cast<TH1F*> (madeinObject);
229 }
230 }
231
232 if((!tHist1F1)
233 && (!tHist1F2)) {
234 message("Unable to find either entred or madein histograms");
235 return;
236 }
237
238 /* FIXME: Qat has to be ported to Qt5...
239 // ___________ Plotting _______________
240
241 // Create new window for the plot
242 m_d->PlotMainWindow = new QMainWindow();
243 QToolBar *toolBar=m_d->PlotMainWindow->addToolBar("Tools");
244 QAction *dismissAction=toolBar->addAction("Dismiss");
245 dismissAction->setShortcut(QKeySequence("m_d"));
246 connect(dismissAction,SIGNAL(activated()), m_d->PlotMainWindow, SLOT(hide()));
247
248 // Create histogram
249 Hist1D* hist1D = new Hist1D(histogramName.toStdString()
250 ,tHist1F1->GetXaxis()->GetNbins()
251 ,tHist1F1->GetXaxis()->GetXmin()
252 ,tHist1F1->GetXaxis()->GetXmax());
253 for(int ii=0; ii<tHist1F1->GetXaxis()->GetNbins(); ++ii)
254 hist1D->accumulate(tHist1F1->GetBinCenter(ii),tHist1F2!=0?tHist1F1->GetBinContent(ii)+tHist1F2->GetBinContent(ii):tHist1F1->GetBinContent(ii));
255
256 PlotHist1D* pHist = new PlotHist1D(*hist1D);
257 PlotHist1D::Properties* prop = new PlotHist1D::Properties();
258 prop->pen.setColor(QColor("darkRed"));
259 prop->pen.setWidth(3);
260 pHist->setProperties(*prop); //const reference, but does not take possession of pointer
261
262 // Make a plot
263 QRectF rect = pHist->rectHint();
264 rect.setTop(1.0);
265 rect.setLeft(1.0);
266 PlotView* view = new PlotView(&rect);
267 view->setLogX(true);
268 view->setLogY(true);
269
270 m_d->PlotMainWindow->setCentralWidget(view);
271 view->setBox(false);
272 view->add(pHist);
273
274 // Construct three label streams
275 PlotStream titleStream(view->titleTextEdit()), xLabelStream(view->xLabelTextEdit()), yLabelStream(view->yLabelTextEdit());
276
277 // Label the title
278 titleStream
279 << PlotStream::Clear()
280 << PlotStream::Center()
281 << PlotStream::Family("Sans Serif")
282 << PlotStream::Size(12)
283 << PlotStream::Color(QColor("red"))
284 << histogramName.toStdString().c_str()
285 << PlotStream::EndP();
286
287 // Label the x-axis
288 xLabelStream
289 << PlotStream::Clear()
290 << PlotStream::Center()
291 << PlotStream::Family("Sans Serif")
292 << PlotStream::Size(12)
293 << "energy [MeV/c"
294 << PlotStream::Super()
295 << "2"
296 << PlotStream::Normal()
297 << "]"
298 << PlotStream::EndP();
299
300 // Label the y-axis
301 yLabelStream
302 << PlotStream::Clear()
303 << PlotStream::Center()
304 << PlotStream::Family("Sans Serif")
305 << PlotStream::Size(12)
306 << (m_d->controller->getParticleType()==VP1PartSpect::Neutron ? "neutrons / bin" : "electrons / bin")
307 << PlotStream::EndP();
308
309 // Show this view
310
311 m_d->PlotMainWindow->show();
312 delete prop;
313 prop=nullptr;
314 // ___________ Plotting _______________
315 */
316
317
318
319
320}
321
322void VP1PartSpectSystem::fileUpdated(const QString& fileName)
323{
324 // Open the new file
325 m_d->stream = std::make_unique<TFile>(fileName.toStdString().c_str(),"READ");
326 messageVerbose(fileName + " opened");
327}
328
330{
331 // To do
332}
IVP13DSystemSimple(const QString &name, const QString &information, const QString &contact_info)
void messageVerbose(const QString &) const
ActiveState activeState() const
virtual void restoreFromState(QByteArray)
void messageDebug(const QString &) const
State state() const
void message(const QString &) const
virtual QByteArray saveState()
The Athena Transient Store API.
VP1PartSpectController * controller
std::unique_ptr< QMainWindow > PlotMainWindow
std::unique_ptr< TFile > stream
QString histogramPrefix(VP1PartSpect::ParticleType)
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
void fileUpdated(const QString &)
void restoreFromState(QByteArray)
void plotSpectrum(QStack< QString > &, int copyNumber=-1)
void buildPermanentSceneGraph(StoreGateSvc *detstore, SoSeparator *root)