ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtLinkDAQTask.h
Go to the documentation of this file.
1 #ifndef ATLINKDAQTASK_H
2 #define ATLINKDAQTASK_H
3 /*
4  * Task to link runs in attpcroot and HiRAEVT
5  * requires that the AT-TPC root code was build against the HiRAEVT code
6  * This doesn't modify the tree at all, but creates a new tree holding a copy
7  * of the detectors in the passed HiRAEVT tree, which is added as a friend to
8  * the AT-TPC root tree. That way this only has to be run per run and the TPC tree
9  * can be recreated without having to re-run this code.
10  *
11  * This links the DAQs by looking at the reduced interval between events, where the reduced interval i
12  * intervalTPC/intervalNSCL. This works even when the clocks are different frequencies
13  *
14  *
15  * As an input it takes some mean and radius to search around, and a histogram of the reduced interval
16  * is saved.
17  *
18  * Requires use of the new run type AtRunAna, it extends FairRunAna but exposes some additional
19  * behavior
20  *
21  * Adam Anthony 5/27/21
22  *
23  */
24 
25 #include <TChain.h>
26 #include <TString.h>
27 #include <TTree.h>
28 // FairRoot classes
29 #include <FairTask.h>
30 
31 #include <Rtypes.h>
32 
33 #include <memory>
34 #include <vector>
35 
36 // HiRAEVT classes
37 class HTTimestamp;
38 // ROOT classes
39 class TClonesArray;
40 // ATTPCROOT classes
41 class AtBaseEvent;
42 class TFile;
43 
44 class AtLinkDAQTask : public FairTask {
45 
46 private:
47  // Info for AT-TPC Tree
48  TClonesArray *fInputEventArray{}; // AtRawEvent
49  TString fInputBranchName{"AtRawEvent"}; // Name if AtRawEvent branch
50  AtBaseEvent *fEvent{nullptr};
51 
52  // Info for HiRAEVT Tree input
53  std::unique_ptr<TChain> evtTree{nullptr};
54  TString fEvtTimestampName;
55  HTTimestamp *fEvtTS{nullptr};
56 
57  // Info for output HiRAEVT tree
58  TString fEvtOutputFileName{""};
59  TFile *fEvtOutputFile{};
60  TTree *fEvtOutputTree{};
61 
62  // Variables used during merging
63  ULong64_t fEvtTreeIndex{0};
64  ULong64_t fOldEvtTimestamp{0};
65  ULong64_t fEvtTimestamp{0};
66  Double_t fIntervalEvt{0};
67 
68  ULong64_t fTpcTreeIndex{0};
69  std::vector<ULong64_t> fOldTpcTimestamp;
70  std::vector<ULong64_t> fTpcTimestamp;
71  Double_t fIntervalTpc{0};
72 
73  Double_t fDifferenceOffset{0};
74 
75  // Input parameters
76  Double_t fSearchMean{0}; // This is the ratio of clock frequencies
77  Double_t fSearchRadius{0};
78  Double_t fCorruptedSearchRadius{0};
79  Int_t fTpcTimestampIndex{0};
80 
81  Bool_t kPersistent{false};
82  Bool_t kFirstEvent{true};
83  Bool_t kFillEvt{};
84  Bool_t kCorruptedTimestamp{};
85 
86  Bool_t kUseRatio{false};
87 
88  // diagnostic graphs to write in HiRAEVT output file
89  std::vector<std::vector<double>> fGrDataRatio;
90  std::vector<std::vector<double>> fGrDataAbs;
91 
92  Double_t GetScaledInterval(ULong64_t intervalEvt, ULong64_t intervalTpc);
93 
94  void DoFirstEvent();
95  bool UpdateTimestamps();
96  void ResetFlags();
97  void Fill();
98  Int_t CheckMatch();
99  bool ExtraEvtEvent();
100 
101 public:
102  AtLinkDAQTask() = default;
103  ~AtLinkDAQTask() = default;
104 
105  bool SetInputTree(TString fileName, TString treeName);
106  bool AddInputTree(TString fileName);
107  void SetEvtTimestamp(TString name) { fEvtTimestampName = name; }
108  void SetTpcTimestampIndex(Int_t index) { fTpcTimestampIndex = index; }
109  void SetEvtOutputFile(TString fileName) { fEvtOutputFileName = fileName; }
110  void SetPersistance(Bool_t val) { kPersistent = val; }
111  void SetInputBranch(TString name) { fInputBranchName = name; }
112 
113  void SetSearchMean(Double_t mean) { fSearchMean = mean; }
114  void SetSearchRadius(Double_t radius) { fSearchRadius = radius; }
115  void SetCorruptedSearchRadius(Double_t radius) { fCorruptedSearchRadius = radius; }
116 
117  void SetUseRatio(Bool_t val) { kUseRatio = val; }
118 
119  const TChain *GetInChain() { return evtTree.get(); }
120  TFile *GetOutFile() { return fEvtOutputFile; }
121  virtual InitStatus Init() override;
122  virtual void Exec(Option_t *opt) override;
123  virtual void Finish() override; // called at end of run
124  virtual void FinishEvent() override
125  {
126  if (kFillEvt)
127  fEvtOutputTree->Fill();
128  } // Called at the end of an event
129 };
130 #endif //#define ATLINKDAQTASK_H
AtLinkDAQTask::SetPersistance
void SetPersistance(Bool_t val)
Definition: AtLinkDAQTask.h:110
AtLinkDAQTask::SetEvtTimestamp
void SetEvtTimestamp(TString name)
Definition: AtLinkDAQTask.h:107
AtLinkDAQTask::SetUseRatio
void SetUseRatio(Bool_t val)
Definition: AtLinkDAQTask.h:117
AtLinkDAQTask::SetSearchMean
void SetSearchMean(Double_t mean)
Definition: AtLinkDAQTask.h:113
AtLinkDAQTask::SetEvtOutputFile
void SetEvtOutputFile(TString fileName)
Definition: AtLinkDAQTask.h:109
AtLinkDAQTask::Init
virtual InitStatus Init() override
Definition: AtLinkDAQTask.cxx:51
AtLinkDAQTask::Finish
virtual void Finish() override
Definition: AtLinkDAQTask.cxx:310
AtLinkDAQTask::SetInputTree
bool SetInputTree(TString fileName, TString treeName)
Definition: AtLinkDAQTask.cxx:26
AtLinkDAQTask::~AtLinkDAQTask
~AtLinkDAQTask()=default
AtLinkDAQTask::GetOutFile
TFile * GetOutFile()
Definition: AtLinkDAQTask.h:120
AtLinkDAQTask::GetInChain
const TChain * GetInChain()
Definition: AtLinkDAQTask.h:119
AtLinkDAQTask::FinishEvent
virtual void FinishEvent() override
Definition: AtLinkDAQTask.h:124
AtLinkDAQTask::Exec
virtual void Exec(Option_t *opt) override
Definition: AtLinkDAQTask.cxx:178
AtLinkDAQTask::SetTpcTimestampIndex
void SetTpcTimestampIndex(Int_t index)
Definition: AtLinkDAQTask.h:108
AtBaseEvent
Base class for all event types in ATTPCROOT.
Definition: AtBaseEvent.h:20
AtLinkDAQTask
Definition: AtLinkDAQTask.h:44
AtLinkDAQTask::AtLinkDAQTask
AtLinkDAQTask()=default
AtLinkDAQTask::SetSearchRadius
void SetSearchRadius(Double_t radius)
Definition: AtLinkDAQTask.h:114
AtLinkDAQTask::AddInputTree
bool AddInputTree(TString fileName)
Definition: AtLinkDAQTask.cxx:40
AtLinkDAQTask::SetCorruptedSearchRadius
void SetCorruptedSearchRadius(Double_t radius)
Definition: AtLinkDAQTask.h:115
AtLinkDAQTask::SetInputBranch
void SetInputBranch(TString name)
Definition: AtLinkDAQTask.h:111
mean
double mean(const double *a, size_t m)
Definition: cluster.cxx:26