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