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