PandaRoot
PndTimeStructureAnaTask.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
13 #ifndef PndTimeStructureAnaTask_H
14 #define PndTimeStructureAnaTask_H
15 
16 #include "FairTask.h" // for FairTask, InitStatus
17 #include "FairTSBufferFunctional.h"
18 #include "FairEventHeader.h"
19 
20 #include "TH1.h"
21 #include "TGraph.h"
22 
23 #include "Rtypes.h" // for Bool_t, Int_t, kTRUE, etc
24 #include "TString.h" // for TString
25 
26 class FairTimeStamp;
27 class TClonesArray;
28 
29 struct DataObject {
31 
32  DataObject(TString branchName, Double_t timeGap)
33  : fBranchName(branchName), fBranch(nullptr), fOldEventNr(-1), fOldTimeStamp(0), fEventMixture(kFALSE), fTimeGap(timeGap), fNEventsInSelection(0)
34  {
35  TString histoName("hBetweenEvents");
36  histoName += fBranchName;
37  TString eventHistoName("hInsideEvent");
38  eventHistoName += fBranchName;
39  TString eventDiffHistoName("hEventLength");
40  eventDiffHistoName += fBranchName;
41  TString eventsInSelection("hEventsInSelection");
42  eventsInSelection += fBranchName;
43  fTimeHisto = new TH1D(histoName, histoName, 10000, 0, 10000);
44  fEventHisto = new TH1D(eventHistoName, eventHistoName, 100, 0, 100);
45  fEventDiffHisto = new TH1D(eventDiffHistoName, eventDiffHistoName, 1000, 0, 1000);
46  fEventsInSelection = new TH1D(eventsInSelection, eventsInSelection, 100, 0, 100);
47  }
48  std::vector<Double_t> CalcIntegral(TH1 *h1)
49  {
50  std::vector<Double_t> result;
51  Double_t sum = 0;
52  for (int i = 0; i < h1->GetNbinsX(); i++) {
53  sum += h1->GetBinContent(i);
54  result.push_back(sum);
55  }
56  return result;
57  }
58 
59  std::vector<Double_t> GetBinCenters(TH1 *h1)
60  {
61  std::vector<Double_t> result;
62  for (int i = 0; i < h1->GetNbinsX(); i++) {
63  result.push_back(h1->GetBinCenter(i));
64  }
65  return result;
66  }
67  void FillGraphs()
68  {
69 
70  TString eventGapName = fBranchName + "EventGap";
71  fEventGap = new TH1D(eventGapName.Data(), eventGapName.Data(), fTimeHisto->GetNbinsX(), fTimeHisto->GetXaxis()->GetXmin(), fTimeHisto->GetXaxis()->GetXmax());
73 
74  TString eventGapPercName = fBranchName + "EventGapPerc";
75  fEventGapPerc = new TH1D(eventGapPercName.Data(), eventGapPercName.Data(), fTimeHisto->GetNbinsX(), fTimeHisto->GetXaxis()->GetXmin(), fTimeHisto->GetXaxis()->GetXmax());
77 
78  TString overlapName = fBranchName + "Overlap";
79  fOverlap = new TH1D(overlapName.Data(), overlapName.Data(), fEventHisto->GetNbinsX(), fEventHisto->GetXaxis()->GetXmin(), fEventHisto->GetXaxis()->GetXmax());
81 
82  TString overlapPercName = fBranchName + "OverlapPerc";
83  fOverlapPerc = new TH1D(overlapPercName.Data(), overlapPercName.Data(), fEventHisto->GetNbinsX(), fEventHisto->GetXaxis()->GetXmin(), fEventHisto->GetXaxis()->GetXmax());
85  }
86 
87  void FillGraph(TH1D *theGraph, TH1 *h1)
88  {
89  std::vector<Double_t> values = CalcIntegral(h1);
90  std::vector<Double_t> binCenters = GetBinCenters(h1);
91  for (size_t i = 0; i < values.size(); i++)
92  theGraph->Fill(binCenters[i], values[i]);
93  }
94 
95  void FillGraphPercent(TH1D *theGraph, TH1 *h1)
96  {
97  std::vector<Double_t> values = CalcIntegral(h1);
98  std::vector<Double_t> binCenters = GetBinCenters(h1);
99  for (size_t i = 0; i < values.size(); i++)
100  theGraph->Fill(binCenters[i], values[i] / values.back() * 100.0);
101  }
102 
103  TString fBranchName;
104  TClonesArray *fBranch;
105  TH1D *fTimeHisto;
106  TH1D *fEventHisto;
108  TH1D *fEventGap;
111  TH1D *fOverlap;
113  Int_t fOldEventNr;
114  Double_t fOldTimeStamp;
116  Double_t fTimeGap;
118  std::map<Int_t, std::pair<Double_t, Double_t>> fEventStartStopMap;
119 };
120 
121 class PndTimeStructureAnaTask : public FairTask {
122  public:
124  PndTimeStructureAnaTask() : FairTask("TimeStructureAnaTask"), fTimeOfPreviousEvent(0.), fEntryNr(0) { SetVerbose(0); }
125 
127  PndTimeStructureAnaTask(const char *name) : FairTask(name), fEntryNr(0) { SetVerbose(0); }
128 
131 
133  virtual InitStatus Init();
134  virtual InitStatus ReInit();
135 
137  virtual void Exec(Option_t *opt);
138  virtual void FinishEvent();
139  virtual void FinishTask();
140 
141  virtual void SetParContainers(){};
142 
143  void AddBranchName(TString name, Double_t gap)
144  {
145  fData.push_back(DataObject(name, gap));
146  name += "Prim";
147  fDataPrim.push_back(DataObject(name, gap));
148  }
149 
150  protected:
151  void FillTimeGapsEvent();
152 
153  private:
154  std::vector<DataObject> fData; // data for all type of particles
155  std::vector<DataObject> fDataPrim; // data for primary particles
156  TH1D *fHistoMixedEvents;
157  TH1D *fHistoMixedEventsPrim;
158  TH1D *fHistoTimeGapsEvents;
159  FairEventHeader *fEventHeader;
160  double fTimeOfPreviousEvent;
161 
162  Int_t fEntryNr;
163 
164  ClassDef(PndTimeStructureAnaTask, 1);
165 };
166 
167 #endif
std::vector< Double_t > GetBinCenters(TH1 *h1)
DataObject(TString branchName, Double_t timeGap)
unsigned int i
Definition: P4_F32vec4.h:21
void FillGraph(TH1D *theGraph, TH1 *h1)
void AddBranchName(TString name, Double_t gap)
std::map< Int_t, std::pair< Double_t, Double_t > > fEventStartStopMap
PndTimeStructureAnaTask(const char *name)
std::vector< Double_t > CalcIntegral(TH1 *h1)
TClonesArray * fBranch
void FillGraphPercent(TH1D *theGraph, TH1 *h1)