ATLAS Offline Software
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 
9 #include "VP1Base/VP1Serialise.h"
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 
31 public:
32  Imp();
33  ~Imp();
34 
36  QMainWindow* PlotMainWindow;
37  TFile* stream;
38 
40 };
41 
43  :controller(0)
44  ,PlotMainWindow(0)
45  ,stream(0)
46 {
47 }
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_");
62  case VP1PartSpect::Gamma :
63  return QString("gamma_");
65  return QString("lepton_");
66  case VP1PartSpect::Meson :
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 
90 {
91  delete m_d;
92 }
93 
95 {
96  // Standard stuff
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 
108 {
109 }
110 
112 {
113 }
114 
116 {
117  VP1Serialise serialise(0/*version*/,this);
119 
121 
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 
139  IVP13DSystemSimple::restoreFromState(state.restoreByteArray());
140 
141  m_d->controller->restoreSettings(state.restoreByteArray());
142 
143  state.disableUnrestoredChecks();
144 }
145 
146 void 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 
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 }
VP1Serialise.h
VP1Deserialise.h
VP1Serialise
Definition: VP1Serialise.h:45
IVP13DSystemSimple
Definition: IVP13DSystemSimple.h:24
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
VP1PartSpect::Nucleus
@ Nucleus
Definition: VP1PartSpectFlags.h:26
RoiUtil::serialise
void serialise(const std::vector< const IRoiDescriptor * > &rois, roiserial_type &s)
serialise an entire vector of IRoiDescriptors
Definition: RoiSerialise.cxx:45
VP1PartSpect::Neutron
@ Neutron
Definition: VP1PartSpectFlags.h:25
VP1PartSpectSystem::buildController
QWidget * buildController()
Definition: VP1PartSpectSystem.cxx:94
VP1PartSpectSystem::Imp::PlotMainWindow
QMainWindow * PlotMainWindow
Definition: VP1PartSpectSystem.cxx:36
VP1PartSpectSystem::particleType
void particleType()
Definition: VP1PartSpectSystem.cxx:342
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
VP1PartSpectSystem::buildEventSceneGraph
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
Definition: VP1PartSpectSystem.cxx:111
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1PartSpectSystem::VP1PartSpectSystem
VP1PartSpectSystem()
Definition: VP1PartSpectSystem.cxx:81
VP1PartSpect::Gamma
@ Gamma
Definition: VP1PartSpectFlags.h:22
VP1PartSpectSystem::~VP1PartSpectSystem
virtual ~VP1PartSpectSystem()
Definition: VP1PartSpectSystem.cxx:89
VP1Controller::saveSettings
QByteArray saveSettings() const
Definition: VP1Controller.cxx:405
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
VP1PartSpectSystem::Imp::controller
VP1PartSpectController * controller
Definition: VP1PartSpectSystem.cxx:35
VP1PartSpect::ParticleType
ParticleType
Definition: VP1PartSpectFlags.h:19
IVP1System::state
State state() const
Definition: IVP1System.cxx:129
IVP1System::saveState
virtual QByteArray saveState()
Definition: IVP1System.cxx:294
IVP1System::activeState
ActiveState activeState() const
Definition: IVP1System.cxx:135
VP1PartSpectSystem::fileUpdated
void fileUpdated(const QString &)
Definition: VP1PartSpectSystem.cxx:331
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
VP1PartSpectSystem::Imp::Imp
Imp()
Definition: VP1PartSpectSystem.cxx:42
VP1Controller::restoreSettings
void restoreSettings(QByteArray)
Definition: VP1Controller.cxx:387
DeMoScan.directory
string directory
Definition: DeMoScan.py:80
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
VP1PartSpectSystem::Imp
Definition: VP1PartSpectSystem.cxx:30
VP1PartSpectSystem::buildPermanentSceneGraph
void buildPermanentSceneGraph(StoreGateSvc *detstore, SoSeparator *root)
Definition: VP1PartSpectSystem.cxx:107
IVP13DSystemSimple::ensureBuildController
void ensureBuildController()
Definition: IVP13DSystemSimple.cxx:90
VP1Deserialise
Definition: VP1Deserialise.h:44
VP1PartSpectController
Definition: VP1PartSpectController.h:21
VP1PartSpectSystem::saveState
QByteArray saveState()
Definition: VP1PartSpectSystem.cxx:115
VP1PartSpectSystem::m_d
Imp * m_d
Definition: VP1PartSpectSystem.h:44
VP1PartSpectSystem::Imp::stream
TFile * stream
Definition: VP1PartSpectSystem.cxx:37
IVP1System::messageDebug
void messageDebug(const QString &) const
Definition: IVP1System.cxx:347
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
VP1PartSpectController.h
VP1PartSpectSystem::plotSpectrum
void plotSpectrum(QStack< QString > &, int copyNumber=-1)
Definition: VP1PartSpectSystem.cxx:146
VP1PartSpect::Lepton
@ Lepton
Definition: VP1PartSpectFlags.h:23
VP1PartSpect::Baryon
@ Baryon
Definition: VP1PartSpectFlags.h:20
VP1PartSpect::Proton
@ Proton
Definition: VP1PartSpectFlags.h:28
VP1PartSpectController::getParticleType
VP1PartSpect::ParticleType getParticleType()
Definition: VP1PartSpectController.cxx:105
VP1PartSpectSystem.h
VP1PartSpectSystem::Imp::~Imp
~Imp()
Definition: VP1PartSpectSystem.cxx:49
VP1PartSpect::Meson
@ Meson
Definition: VP1PartSpectFlags.h:24
VP1PartSpectSystem::restoreFromState
void restoreFromState(QByteArray)
Definition: VP1PartSpectSystem.cxx:128
VP1PartSpectSystem::Imp::histogramPrefix
QString histogramPrefix(VP1PartSpect::ParticleType)
Definition: VP1PartSpectSystem.cxx:55
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
IVP1System::message
void message(const QString &) const
Definition: IVP1System.cxx:336
VP1PartSpect::Pi
@ Pi
Definition: VP1PartSpectFlags.h:27
IVP1System::OFF
@ OFF
Definition: IVP1System.h:144
IVP1System::messageVerbose
void messageVerbose(const QString &) const
Definition: IVP1System.cxx:354
IVP1System::restoreFromState
virtual void restoreFromState(QByteArray)
Definition: IVP1System.cxx:302