Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
ChargedFluctuationsAna.cxx
1/*
2 * FluctuationsAna.cxx
3 *
4 * Created on: 31 sie 2017
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "ChargedFluctuationsAna.h"
11
12#include "Cout.h"
13#include "CutContainer.h"
14#include "CutsAndMonitors.h"
15#include "DataFormat.h"
16#include "DataFormatManager.h"
17#include "Event.h"
18#include "EventVirtualCut.h"
19#include "MemoryMapManager.h"
20#include "Package.h"
21#include "Std.h"
22#include "TrackCut.h"
23
24#include <TCollection.h>
25#include <TList.h>
26#include <TPRegexp.h>
27
28
29namespace Hal {
30 ChargedFluctuationsAna::ChargedFluctuationsAna() :
31 fBins(1000),
32 fMin(0),
33 fMax(1000),
34 fEventBins(1),
35 fEventPar(DataFieldID::Event::EBasic::kEventZero),
36 fTrackColsHalf(0),
37 fEventMin(-0.5),
38 fEventMax(0.5),
39 fHistogram(nullptr) {}
40
41 void ChargedFluctuationsAna::ProcessEvent() {
42 Int_t step = fCurrentEventCollectionID * 8;
43 Double_t evProperty = fCurrentEvent->GetFieldVal(fEventPar);
44 for (int j = 0; j < fTrackColsHalf * 2; j++) {
45 fCounts[j] = 0;
46 }
47
48 for (int i = 0; i < fMemoryMap->GetTemporaryTotalTracksNo(); i++) {
49 fCurrentTrack = fCurrentEvent->GetTrack(i);
50 for (int j = 0; j < fTrackColsHalf * 2; j++) {
51 if (fCutContainer->PassTrack(fCurrentTrack, j + step)) ++fCounts[j];
52 }
53 }
54 for (int j = 0; j < fTrackColsHalf * 2; j += 2) {
55 fHistogram->Fill(fCurrentEventCollectionID, j, fCounts[2 * j], fCounts[2 * j + 1], evProperty);
56 }
57 }
58
59 Task::EInitFlag ChargedFluctuationsAna::Init() {
60 if (TrackAna::Init() == Task::EInitFlag::kFATAL) return Task::EInitFlag::kFATAL;
61 fTrackColsHalf = fCutContainer->GetTrackCollectionsNo() / fCutContainer->GetEventCollectionsNo();
62 if (fTrackColsHalf % 2 == 1) return Task::EInitFlag::kFATAL;
63 fCounts.resize(fTrackColsHalf);
64 fTrackColsHalf = fTrackColsHalf / 2;
65 fHistogram = new HistogramManager_2_3D<TH3D>();
66 fHistogram->Init(fEventCollectionsNo, fTrackColsHalf, fBins, fMin, fMax, fBins, fMin, fMax, fEventBins, fEventMin, fEventMax);
67 const Event* ev = DataFormatManager::Instance()->GetFormat(GetTaskID());
68 TString parName = ev->GetFieldName(fEventPar);
69 for (int i = 0; i < fEventCollectionsNo; i++) {
70 TString eventName = Form("Event [%i]", i);
71 if (i < (int) fEventLabels.size()) { eventName = fEventLabels[i]; }
72 for (int j = 0; j < fTrackColsHalf; j++) {
73 Int_t posColl = 2 * j;
74 Int_t negColl = 2 * j + 1;
75 TString trackNameA = Form("Track [%i]", posColl);
76 TString trackNameB = Form("Track [%i]", negColl);
77 if (posColl < (int) fTrackLabels.size()) { trackNameA = fTrackLabels[posColl]; }
78 if (negColl < (int) fTrackLabels.size()) { trackNameB = fTrackLabels[negColl]; }
79
80 TH3D* h = fHistogram->At(i, j);
81 h->SetTitle(Form("%s %s vs %s", eventName.Data(), trackNameA.Data(), trackNameB.Data()));
82 h->SetName(h->GetTitle());
83 h->GetXaxis()->SetTitle(Form("N_{%s}", trackNameA.Data()));
84 h->GetYaxis()->SetTitle(Form("N_{%s}", trackNameB.Data()));
85 h->GetZaxis()->SetTitle(Form("%s", parName.Data()));
86 }
87 }
88 return Task::EInitFlag::kSUCCESS;
89 }
90
91 Package* ChargedFluctuationsAna::Report() const {
92 Package* report = TrackAna::Report();
93 for (int i = 0; i < fHistogram->GetSize(); i++) {
94 for (int j = 0; j < fHistogram->Get(i)->GetSize(); j++) {
95 report->AddObject(fHistogram->At(i, j));
96 }
97 }
98 return report;
99 }
100
101 void ChargedFluctuationsAna::SetTrackHistogramAxis(Int_t bins, Double_t min, Double_t max) {
102 fBins = bins;
103 fMin = min;
104 fMax = max;
105 }
106
107 void ChargedFluctuationsAna::CheckCutContainerCollections() {
108 fEventCollectionsNo = fCutContainer->GetEventCollectionsNo();
109 fTrackCollectionsNo = fCutContainer->GetTrackCollectionsNo();
110 if (fEventCollectionsNo == 0) { AddCut(EventVirtualCut()); }
111 if (fTrackCollectionsNo % 2 == 0) {
112 for (int i = 1; i < fEventCollectionsNo; i++) {
113 for (int j = 0; j < fTrackCollectionsNo; j++) {
114 fCutContainer->ReplicateCollection(ECutUpdate::kTrack, j, fTrackCollectionsNo * i + j);
115 }
116 }
117 } else {
118 Cout::PrintInfo("wrong number of track collections, this might result in crash", EInfo::kError);
119 }
120 }
121
122 TString ChargedFluctuationsAna::HistoTitle(Int_t id, TString pattern) const {
123 return Form("%s [%i];dN/%s^{+};dN/d%s^{-}", pattern.Data(), id, pattern.Data(), pattern.Data());
124 }
125
126 TString ChargedFluctuationsAna::HistoName(Int_t id, TString pattern) const {
127 return Form("Distribution of %s in [%i]", pattern.Data(), id);
128 }
129
130
131 void ChargedFluctuationsAna::AddCut(const Cut& cut, Option_t* opt) {
132 if (cut.InheritsFrom("Hal::TrackCut")) return;
133 TrackAna::AddCut(cut, opt);
134 }
135
136 ChargedFluctuationsAna::~ChargedFluctuationsAna() {
137 if (fHistogram) { delete fHistogram; }
138 }
139
140
141 void ChargedFluctuationsAna::SetEventLabels(const std::initializer_list<TString>& init) {
142 std::initializer_list<TString>::iterator it;
143 for (it = init.begin(); it != init.end(); ++it) {
144 fEventLabels.push_back(*it);
145 }
146 }
147
148 void ChargedFluctuationsAna::SetTrackLabels(const std::initializer_list<TString>& init) {
149 std::initializer_list<TString>::iterator it;
150 for (it = init.begin(); it != init.end(); ++it) {
151 fTrackLabels.push_back(*it);
152 }
153 }
154
155 void ChargedFluctuationsAna::SetEventHistogramAxis(Int_t bins, Double_t min, Double_t max) {
156 fEventBins = bins;
157 fEventMin = min;
158 fEventMax = max;
159 }
160
161 TString ChargedFluctuationsAna::CleanOpt(Option_t* opt, Int_t cut) const {
162 TString newOpt = opt;
163 TPRegexp reg("{[x0-9]*}");
164 reg.Substitute(newOpt, "", "g");
165 while (newOpt.Contains("++"))
166 newOpt = newOpt.ReplaceAll("++", "+");
167 if (newOpt.BeginsWith("+")) newOpt = newOpt(1, newOpt.Length() - 1);
168 if (newOpt.EndsWith("+")) newOpt = newOpt(0, newOpt.Length() - 1);
169 if (cut < 0) return newOpt;
170 if (newOpt.Length() > 0)
171 newOpt = Form("%s+{%i}", newOpt.Data(), cut);
172 else
173 newOpt = Form("{%i}", cut);
174 return newOpt;
175 }
176
177 void ChargedFluctuationsAna::AddCut(const TrackCut& pos, const TrackCut& neg, Option_t* opt) {
178 if (pos.GetCollectionID() == neg.GetCollectionID()) {
179 Cout::PrintInfo("cannot add two cuts with the same collection ID by ChargedFluctuationsAna::AddCut!", EInfo::kLowWarning);
180 }
181 if (TMath::Abs(pos.GetCollectionID() - neg.GetCollectionID()) != 1) {
182 Cout::PrintInfo("cannot add two cuts with delta collection ID!=1 by ChargedFluctuationsAna::AddCut!", EInfo::kLowWarning);
183 }
184 TString option = CleanOpt(opt, -1);
185 TrackAna::AddCut(pos, opt);
186 TrackAna::AddCut(neg, opt);
187 }
188
189 void ChargedFluctuationsAna::SetEventprop(Int_t evProp) { fEventPar = evProp; }
190
191 void ChargedFluctuationsAna::AddCutsAndMonitors(const CutsAndMonitors& posTrack,
192 const CutsAndMonitors& negTrack,
193 Option_t* /*opt*/) {
194 if (posTrack.GetCut(0)->GetCollectionID() == negTrack.GetCut(0)->GetCollectionID()) {
195 Cout::PrintInfo("cannot add two cuts with the same collection ID by NicaChargedFluctuationsAna::AddCut!",
196 EInfo::kLowWarning);
197 }
198 if (TMath::Abs(posTrack.GetCut(0)->GetCollectionID() - negTrack.GetCut(0)->GetCollectionID()) != 1) {
199 Cout::PrintInfo("cannot add two cuts with delta collection ID!=1 by NicaChargedFluctuationsAna::AddCut!",
200 EInfo::kLowWarning);
201 }
202 for (int iCut = 0; iCut < posTrack.GetNCuts(); iCut++) {
203 TrackAna::AddCut(*posTrack.GetCut(iCut), posTrack.GetCutOption(iCut));
204 }
205 for (int iCut = 0; iCut < negTrack.GetNCuts(); iCut++) {
206 TrackAna::AddCut(*negTrack.GetCut(iCut), negTrack.GetCutOption(iCut));
207 }
208 for (int iMon = 0; iMon < posTrack.GetNCutMonitors(); iMon++) {
209 TrackAna::AddCutMonitor(*posTrack.GetMonitor(iMon), posTrack.GetCutMonitorOption(iMon));
210 }
211 for (int iMon = 0; iMon < negTrack.GetNCutMonitors(); iMon++) {
212 TrackAna::AddCutMonitor(*negTrack.GetMonitor(iMon), negTrack.GetCutMonitorOption(iMon));
213 }
214 }
215
216} // namespace Hal
Definition Cut.h:40
Int_t GetCollectionID() const
Definition Cut.h:257
Int_t GetNCutMonitors() const
TString GetCutOption(Int_t i) const
const CutMonitor * GetMonitor(Int_t i) const
const Cut * GetCut(Int_t i) const
TString GetCutMonitorOption(Int_t i) const
virtual TString GetFieldName(Int_t fieldID) const
Definition Event.cxx:272
void AddObject(TObject *object)
Definition Package.cxx:209