25 #include "TPaveText.h"
26 #include "TDirectory.h"
27 #include "TEventList.h"
31 #include "TRootEmbeddedCanvas.h"
33 #include "TTimeStamp.h"
45 using std::stringstream;
53 fEventIndex(0), fEventList(new TEventList()), fNeedsReordering(true),
54 fStylePulse(new TGraph()), fUseADCUnits(false),fZeroOffset(false),fUnitary(false), fShowLegends(false), fSamplesLabel(
"")
58 SetBit(kCanDelete, kFALSE);
71 fEventData(pulse.fEventData), fEventIndex(pulse.fEventIndex), fEventList(new TEventList()),
72 fNeedsReordering(pulse.fNeedsReordering), fOrderedEvents(pulse.fOrderedEvents), fOrderVariable(pulse.fOrderVariable),
73 fStylePulse(new TGraph()), fUseADCUnits(pulse.fUseADCUnits), fZeroOffset(pulse.fZeroOffset), fUnitary(pulse.fUnitary), fShowLegends(pulse.fShowLegends),
74 fSamplesLabel(pulse.fSamplesLabel)
79 SetBit(kCanDelete, kFALSE);
107 set<Color_t> existingColors;
108 list<QGPulse*>::const_iterator plotIter;
109 for (plotIter =
fPulses.begin(); plotIter !=
fPulses.end(); ++plotIter) {
110 existingColors.insert((*plotIter)->GetLineColor());
112 while (existingColors.count(color) != 0) {
114 if (color == 5 || color == 10) {
143 string xAxisLabel =
"Time (" +
GetXUnits() +
")";
144 string yAxisLabel =
"Voltage (" +
GetYUnits() +
")";
145 GetXaxis()->SetTitle(xAxisLabel.c_str());
146 GetYaxis()->SetTitle(yAxisLabel.c_str());
147 GetYaxis()->SetTitleOffset(1.35);
150 bool drawSuperimpose =
false;
154 drawSuperimpose =
true;
158 if (drawSuperimpose) {
169 if (isPulse && GetN() > 0) {
182 TPaveText* eventTxt =
new TPaveText(rightEdge *2/3, topEdge - 0.05*n , rightEdge, topEdge,
"NDC");
183 eventTxt->SetFillStyle(0);
184 eventTxt->SetBorderSize(0);
185 eventTxt->SetTextAlign(13);
186 for (vector<string>::iterator tlIter =
fEventData.begin(); tlIter !=
fEventData.end(); ++tlIter) {
214 for (vector<TMarker*>::const_iterator marker =
fSampleMarkers.begin();
224 TH1F *supportHistogram =
new TH1F();
225 supportHistogram->SetBit(kCanDelete, kTRUE);
226 supportHistogram->SetStats(kFALSE);
227 supportHistogram->SetBins(1, 0, 5);
228 supportHistogram->GetYaxis()->SetRangeUser(0, 5);
229 supportHistogram->Draw(
"AH");
250 for (vector<TMarker*>::const_iterator marker =
fSampleMarkers.begin();
264 vector<string>::iterator cutIter;
266 string::size_type beginPosition = cutIter->find_first_not_of(
" ");
267 if (beginPosition == string::npos) {
268 *cutIter = cutIter->substr(beginPosition);
270 string::size_type endPosition = cutIter->find_first_of(
" !=<>");
271 if (endPosition != string::npos) {
272 *cutIter = cutIter->substr(0, endPosition);
278 if (chain->GetSelectedRows() == 1) {
280 if (*cutIter ==
"NsTime/1e9") {
281 ss.flags(std::ios::fixed);
284 else if (cutIter->find(
"UnixTime") != string::npos){
290 ss <<
" == " << chain->GetV1()[0] << flush;
291 cutIter->append(ss.str());
306 cout <<
"Cannot generate the pulse because there is no file open" << endl;
312 TEventList *eventList;
313 gDirectory->GetObject(
"eventList", eventList);
329 SetEventData(pulseEditWindow->GetEventDataFrame()->GetCuts());
330 SetOrderVariable(pulseEditWindow->GetPulseParametersFrame()->GetOrderVariable());
331 SetEventIndex(pulseEditWindow->GetPulseParametersFrame()->GetEventIndex());
332 SetSuperimpose(pulseEditWindow->GetPulseParametersFrame()->IsSuperimposeSet());
333 SetUseADCUnits(pulseEditWindow->GetPulseParametersFrame()->IsUseADCUnitsSet());
334 SetZeroOffset(pulseEditWindow->GetPulseParametersFrame()->IsZeroOffsetSet());
335 SetUnitary(pulseEditWindow->GetPulseParametersFrame()->IsUnitarySet());
336 SetShowLegends(pulseEditWindow->GetPulseParametersFrame()->IsShowLegendsSet());
337 SetSamplesLabel(pulseEditWindow->GetPulseParametersFrame()->GetSamplesLabel());
339 cout <<
"QGPulse::GetParametersFromEditWindow() Warning: dynamic_cast<QGPulseEditWindow*> failed" << endl;
365 bool useADC2mV =
false;
366 Double_t samplingPeriod = 1;
367 bool useSamplingPeriod =
false;
372 if (samplingFrequency != 0) {
373 samplingPeriod = 1.0 / samplingFrequency;
374 useSamplingPeriod =
true;
378 Double_t *V =
new Double_t[pulse.
Size()];
379 Double_t *t =
new Double_t[pulse.
Size()];
382 for (Int_t i = 0; i < (Int_t)pulse.
Size(); ++i) {
394 t[i] *= samplingPeriod;
419 if (index < (Int_t)pulse.
Size()) {
420 TMarker *marker =
new TMarker();
421 marker->SetMarkerStyle(23);
422 marker->SetX(t[index]);
423 marker->SetY(V[index]);
428 const vector<QSampleInfo>& significantSamples
430 for (vector<QSampleInfo>::const_iterator sample = significantSamples.begin();
431 sample != significantSamples.end();
433 Int_t index = sample->GetSampleIndex();
434 if (index < (Int_t)pulse.
Size()) {
435 TMarker *marker =
new TMarker();
436 marker->SetMarkerStyle(23);
437 if (sample->GetIsNoise()) {
438 marker->SetMarkerColor(kYellow);
440 else if (sample->GetIsPulser()) {
441 marker->SetMarkerColor(kRed);
443 else if (sample->GetIsSignal()) {
444 marker->SetMarkerColor(kGreen);
446 else if (sample->GetIsLED()) {
447 marker->SetMarkerColor(kMagenta);
449 else if (sample->GetIsReversed()) {
450 marker->SetMarkerStyle(22);
451 marker->SetMarkerSize(1.5);
452 marker->SetMarkerColor(kGreen+2);
454 else if (sample->GetIsVeto()) {
455 marker->SetMarkerStyle(29);
456 marker->SetMarkerSize(2);
457 marker->SetMarkerColor(kOrange + 1);
459 marker->SetX(t[index]);
460 marker->SetY(V[index]);
475 TF1 *styleFunction =
new TF1(
"styleFunction",
"1.2*TMath::Exp(-1.2*(x-1)) + 0.8*TMath::Exp(-0.4*(x-1)) - 2*TMath::Exp(-12*(x-1))", 0, 5);
478 for (Int_t i = 0; i <
N; ++i) {
479 Double_t x = 5.0/
N*i;
480 Double_t y = x < 1 ? 1.0 : 1.0 + 2.25*styleFunction->Eval(x);
483 delete styleFunction;
491 Int_t currentEventNumber = -1;
498 for (Int_t index = 0; index <
fEventList->GetN(); ++index) {
508 multimap<Double_t, Long64_t> eventMap;
510 for (index = 0; index <
fEventList->GetN(); ++index) {
511 eventMap.insert(make_pair(orderVariableArray[index],
fEventList->GetEntry(index)));
513 multimap<Double_t, Long64_t>::const_iterator iter;
515 for (iter = eventMap.begin(); iter != eventMap.end(); ++iter, ++index) {
517 if (iter->second == currentEventNumber)
fEventIndex = index;
527 if (0 <= index && index < fEventList->GetN()) {
537 string oldName = TGraph::GetName();
538 string newName = name;
539 if (newName != oldName) {
543 TGraph::SetName(name);
562 TString valueTString(value);
568 if (valueTString.IsFloat()) {
573 if (valueTString.IsFloat()) {
578 if (valueTString.IsFloat()) {
579 SetLineStyle(valueTString.Atoi());
583 if (valueTString.IsFloat()) {
584 SetLineWidth(valueTString.Atoi());
588 if (valueTString.IsFloat()) {
589 SetMarkerColor(valueTString.Atoi());
593 if (valueTString.IsFloat()) {
594 SetMarkerSize(valueTString.Atof());
598 if (valueTString.IsFloat()) {
599 SetMarkerStyle(valueTString.Atoi());
607 pulseEditWindow->UpdateEventData();
613 if(eventDatum.find(
"StartRunUnixTime") != string::npos){
615 string rhs = eventDatum.substr(eventDatum.find(
" == ")+4);
616 std::istringstream ss(rhs);
619 TTimeStamp timeStamp (timeSeconds, 0);
620 eventDatum.erase(eventDatum.find(
" == ")+4);
621 eventDatum.append(timeStamp.AsString(
"s"));
624 size_t eventStamp = eventDatum.find(
"StartRunUnixTime+NsTime/1e9 ");
625 if (eventStamp != string::npos)
626 eventDatum.replace(eventStamp, 27,
"Event Time Stamp");
628 size_t runStamp = eventDatum.find(
"StartRunUnixTime ");
629 if (runStamp != string::npos)
630 eventDatum.replace(runStamp, 16,
"Run Time Stamp");
633 eventDatum.replace(eventDatum.find(
" == "), 4,
": ");
ahisto2 SetLineColor(kRed)
#define ORDER_VARIABLE_KEY
#define PULSE_VARIABLE_KEY
basic channel and run based info. Used in the QRunData object.
double fSamplingFrequency
sampling frequency in Hz
double fADC2mV
conversion: mV = ADC * fADC2mV
void RemoveFromDrawnPlots(QGPlot *plot)
Remove pointer to a plot from the list of drawn plots.
void AddToDrawnPlots(QGPlot *plot)
Add pointer to a plot to the list of drawn plots.
QGPlotFrame * GetPlotFrame()
Get pointer to the plot frame.
QGFileHandler * GetFileHandler() const
Get pointer to file handler.
void ClearDrawnPlots()
Clears the collection of drawn plots.
std::list< QGPlot * > & GetDrawnPlots()
Get collection of drawn plots.
const QChannelRunData * GetChannelRunData(const Long64_t eventNumber)
Get the run data for an event.
const Diana::QVector & GetPulse(const Long64_t eventNumber, const std::string &samplesName)
Get the pulse of an event.
bool IsFileOpen()
Check whether a file is open.
TObject * GetGenericObject(const Long64_t eventNumber, const std::string &samplesName)
const std::vector< QSampleInfo > & GetSignificantSamples(const Long64_t eventNumber)
Get significant samples of an event.
const QSampleInfo & GetMasterSample(const Long64_t eventNumber)
Get master sample of an event.
QChain * GetQChain()
Get a pointer to the chian.
Base class for scatter plots and pulses.
virtual void Reset()
Reset the graph to an empty state.
virtual void SetPoints(Int_t n, const Double_t *x, const Double_t *y)
Set the points of the graph.
QGPlotStyleFrame * GetPlotStyleFrame()
Get pointer to the plot style frame.
virtual void SetPlot(QGPlot *plot)=0
Set plot, pure virtual function must be overriden by derived classes.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
Get pointer to canvas.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
Get pointer to embedded canvas.
virtual void SetSuperimpose(bool flag=false)
Set whether the plot should be superimposed.
virtual std::string GeneratePlotName(const std::string &baseName) const
Generate a name for the plot.
virtual const std::string & GetYUnits() const
Get y-axis units.
virtual bool IsNameInUse(const std::string &name) const
Check whether string is the name of any plot.
QGPlotEditWindow * fPlotEditWindow
Pointer to plot edit window.
virtual const std::string & GetXUnits() const
Get x-axis units.
virtual void SetProperty(const std::string &key, const std::string &value)
Set property (used for opening a session)
std::string fCutsString
Cuts in a single string.
bool fSuperimpose
Indicates whether plot should be superimposed on existing plot.
QGCanvasWindow * fCanvasWindow
Canvas window to which plot is associated.
virtual void SetXUnits(const std::string &units)
Set X-axis units.
virtual void SetYUnits(const std::string &units)
Set Y-axis units.
Class for pulse edit window.
Class for GUI pulse plots.
bool NeedsReordering() const
Check whether the pulses need reordering.
std::vector< Long64_t > fOrderedEvents
Ordered collection of events that pass the cuts.
Int_t GetNumberOfEvents()
Get number of events that pass the cuts.
std::vector< TMarker * > fSampleMarkers
Sample markers for significant samples.
QGPulse()
Default constructor.
void Erase()
Erase the pulse.
void AutoSetStyle()
Automatically set the pulse style.
std::string HumanizeEventData(std::string)
Humanize the event data to display along with pulse.
void SetEventIndex(Long_t index)
Set event index of displayed pulse.
void SetOrderVariable(const std::string &orderVariable)
Set the variable by which pulses are ordered.
static std::list< QGPulse * > fPulses
Collection of pointers to all QGPulses.
std::string fSamplesLabel
samples to draw
virtual ~QGPulse()
Destructor.
void SetSamplesLabel(const std::string &samplesLabel)
Set the label of samples to draw.
void SetEventData(const std::vector< std::string > &eventData)
Set event data.
void SetProperty(const std::string &key, const std::string &value)
Set property (used for opening a session)
void SetShowLegends(bool flag=true)
Set whether to display legends on the pulse.
void SetName(const char *name=0)
Set name of the pulse.
void FillEventData()
Fill event data for the displayed pulse.
std::string fOrderVariable
Variable by which pulses are ordered.
bool fShowLegends
Whether or not to show legends on pulse.
void UpdatePulseEditWindow()
Update pulse edit window.
void Display()
Display pulse.
bool fUseADCUnits
Whether or not to use ADC units, otherwise use mV and seconds.
void SetReorder(bool flag=true)
Set whether the pulses need to be reordered.
TGraph * fStylePulse
Mini-pulse to show style of this pulse.
void MakeStylePlot()
Make style plot.
bool fZeroOffset
Subtract first sample to all samples.
std::vector< std::string > fEventData
Event data for displayed pulse.
bool GetPulseFromChain(Long64_t eventIndex)
Get pulse from chain.
void GetParametersFromEditWindow()
Get parameters from edit window.
void DrawStylePulse()
Draw a mini-pulse showing the style of the pulse.
TEventList * fEventList
List of events passing the cuts.
void SetUseADCUnits(bool flag=true)
Set whether to display the pulse using ADC units.
void Duplicate()
Duplicate the pulse.
void SetZeroOffset(bool flag=true)
Set whether subtract first sample to tue pulse.
void Order()
Order the pulses accoring to the order variable.
std::vector< Long64_t >::size_type fEventIndex
Index of current event.
void SetUnitary(bool flag=true)
Set whether normalize pulse.
void DisplayEditWindow()
Display edit window.
void DisplaySampleMarkers()
Display markers for significant samples.
bool fUnitary
Zero offset and unitary amplitude.
void Generate(QChain *chain=0)
Generate the pulse.
contains information on flagged samples
Int_t GetSampleIndex() const
Get SampleIndex from the beginning of the waveform.
Interface for vectors in Diana analysis.
UInt_t Size() const
size of QVector
double GetMax() const
get maximum element