Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
SpectraAna.cxx
1/*
2 * SpectraAna.cxx
3 *
4 * Created on: 21-07-2015
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "SpectraAna.h"
11
12#include "Cout.h"
13#include "Cut.h"
14#include "CutCollection.h"
15#include "CutContainer.h"
16#include "Std.h"
17#include "Package.h"
18#include "Parameter.h"
19#include "Track.h"
20#include "TrackPdgCut.h"
21
22#include <TH2.h>
23#include <TMath.h>
24#include <TObjArray.h>
25#include <TObjString.h>
26#include <TString.h>
27
28
29namespace Hal {
31 fPtEta(NULL),
32 fPtY(NULL),
33 fMtEta(NULL),
34 fMtY(NULL),
35 fPtBins(100),
36 fMtBins(100),
37 fEtaBins(100),
38 fYBins(100),
39 fPtMin(0.0),
40 fPtMax(2.5),
41 fMtMin(0.0),
42 fMtMax(2.5),
43 fEtaMin(-1.0),
44 fEtaMax(1.0),
45 fYMin(-1.0),
46 fYMax(1.0),
47 fEventCollectionsNames(NULL),
48 fTrackCollectionsNames(NULL),
49 fMass(),
50 fUseMass(kFALSE) {
51 AddTags("spectra");
52 }
53
55 Double_t px = fCurrentTrack->GetPx();
56 Double_t py = fCurrentTrack->GetPy();
57 Double_t pz = fCurrentTrack->GetPz();
58 Double_t p = TMath::Sqrt(px * px + py * py + pz * pz);
59 Double_t e, m;
60 if (fUseMass) {
61 m = fMass.at(fCurrentTrackCollectionID);
62 e = TMath::Sqrt(p * p + m * m);
63 } else {
64 e = fCurrentTrack->GetE();
65 m = TMath::Sqrt(e * e - p * p);
66 }
67 Double_t pt = TMath::Sqrt(px * px + py * py);
68 Double_t mt = TMath::Sqrt(pt * pt + m * m);
69 Double_t y = 0.5 * TMath::Log((e + pz) / (e - pz));
70 Double_t eta;
71 if (pt == 0) {
72 if (pz == 0)
73 eta = 0.0;
74 else if (pz > 0)
75 eta = kMaxInt;
76 else
77 eta = -kMaxInt;
78 } else {
79 eta = 0.5 * TMath::Log((p + pz) / (p - pz));
80 }
81 fPtY->Fill(fCurrentTrackCollectionID, y, pt);
82 fPtEta->Fill(fCurrentTrackCollectionID, eta, pt);
83 fMtY->Fill(fCurrentTrackCollectionID, y, mt);
84 fMtEta->Fill(fCurrentTrackCollectionID, eta, mt);
85 }
86
88 Package* package = TrackAna::Report();
89 for (int i = 0; i < fTrackCollectionsNo; i++) {
90 Package* pack = new Package();
91 Int_t event_collection_no = fCutContainer->GetTrackCollection(i)->GetPrevAddr(0);
92 TString title_event = ((TObjString*) fEventCollectionsNames->UncheckedAt(event_collection_no))->GetString();
93 TString title_track = ((TObjString*) fTrackCollectionsNames->UncheckedAt(i))->GetString();
94 TString pack_name = Form("%s#%s", title_event.Data(), title_track.Data());
95 pack->SetName(pack_name);
96 pack->AddObject(new ParameterString("EventCollectionName", title_event));
97 pack->AddObject(new ParameterString("TrackCollectionname", title_track));
98 ULong64_t processed_events = fCutContainer->GetEventCollection(event_collection_no)->GetPassed();
99 pack->AddObject(new ParameterULong64("Events Passed", processed_events));
100 pack->AddObject(new ParameterBool("UseMass", fUseMass));
101 if (fUseMass) pack->AddObject(new ParameterDouble("Mass", fMass.at(i)));
102 pack->AddObject(fPtY->At(i));
103 pack->AddObject(fPtEta->At(i));
104 pack->AddObject(fMtY->At(i));
105 pack->AddObject(fMtEta->At(i));
106 package->AddObject(pack);
107 }
108 return package;
109 }
110
111 Task::EInitFlag SpectraAna::Init() {
112 Task::EInitFlag stat = TrackAna::Init();
113 // initialization of histograms
114 fPtEta = new HistogramManager_1_2D<TH2D>();
115 fPtY = new HistogramManager_1_2D<TH2D>();
116 fMtEta = new HistogramManager_1_2D<TH2D>();
117 fMtY = new HistogramManager_1_2D<TH2D>();
118 HistogramAxisConf** axisConf = new HistogramAxisConf*[3];
119 HistogramAxisConf* pt_axis = new HistogramAxisConf("p_{T} [GeV/c]", fPtBins, fPtMin, fPtMax);
120 HistogramAxisConf* mt_axis = new HistogramAxisConf("m_{T} [GeV/c]", fMtBins, fMtMin, fMtMax);
121 HistogramAxisConf* eta_axis = new HistogramAxisConf("#eta", fEtaBins, fEtaMin, fEtaMax);
122 HistogramAxisConf* y_axis = new HistogramAxisConf("y", fYBins, fYMin, fYMax);
123 HistogramAxisConf* z_axis = new HistogramAxisConf("dummy", 0, 0, 0);
124 axisConf[2] = z_axis;
125 z_axis->SetTitle("dN/dP_{T}d#eta");
126 axisConf[1] = pt_axis;
127 axisConf[0] = eta_axis;
128 fPtEta->Init(fTrackCollectionsNo, axisConf, "", kFALSE);
129 z_axis->SetTitle("dN/dP_{T}dy");
130 axisConf[1] = pt_axis;
131 axisConf[0] = y_axis;
132 fPtY->Init(fTrackCollectionsNo, axisConf, "", kFALSE);
133 z_axis->SetTitle("dN/dm_{T}d#eta");
134 axisConf[1] = mt_axis;
135 axisConf[0] = eta_axis;
136 fMtEta->Init(fTrackCollectionsNo, axisConf, "", kFALSE);
137 z_axis->SetTitle("dN/dm_{T}dy");
138 axisConf[1] = mt_axis;
139 axisConf[0] = y_axis;
140 fMtY->Init(fTrackCollectionsNo, axisConf, "", kFALSE);
141 delete pt_axis;
142 delete mt_axis;
143 delete y_axis;
144 delete eta_axis;
145 delete z_axis;
146 delete[] axisConf;
147 CheckNames();
148 for (int i = 0; i < fTrackCollectionsNo; i++) {
149 Int_t event_collection_no = fCutContainer->GetTrackCollection(i)->GetPrevAddr(0);
150 TString title = ((TObjString*) fEventCollectionsNames->UncheckedAt(event_collection_no))->GetString();
151 title = title + " ";
152 title = title + ((TObjString*) fTrackCollectionsNames->UncheckedAt(i))->GetString();
153 fPtY->At(i)->SetTitle(title);
154 fPtEta->At(i)->SetTitle(title);
155 fMtY->At(i)->SetTitle(title);
156 fMtEta->At(i)->SetTitle(title);
157 fPtY->At(i)->SetName(title);
158 fPtEta->At(i)->SetName(title);
159 fMtY->At(i)->SetName(title);
160 fMtEta->At(i)->SetName(title);
161 }
162 if (fUseMass) {
163 if (fMass.size() == 0) {
164 Cout::PrintInfo("Mass used but mass is not set", EInfo::kError);
165 return Task::EInitFlag::kFATAL;
166 } else {
167 if ((unsigned int) (fTrackCollectionsNo) < fMass.size()) {
168 Cout::PrintInfo("Mass used, but some masses are not set", EInfo::kError);
169 fMass.resize(fTrackCollectionsNo);
170 }
171 for (int i = 0; i < fTrackCollectionsNo; i++) {
172 Cout::PrintInfo(Form("Mass at collection %i (%4.2f) is not valid", i, fMass.at(i)), EInfo::kError);
173 }
174 }
175 }
176 return stat;
177 }
178
179 void SpectraAna::SetPtAxis(Int_t bins, Double_t min, Double_t max) {
180 fPtBins = bins;
181 fPtMin = min;
182 fPtMax = max;
183 }
184
185 void SpectraAna::SetMtAxis(Int_t bins, Double_t min, Double_t max) {
186 fMtBins = bins;
187 fMtMin = min;
188 fMtMax = max;
189 }
190
191 void SpectraAna::SetYAxis(Int_t bins, Double_t min, Double_t max) {
192 fYBins = bins;
193 fYMin = min;
194 fYMax = max;
195 }
196
197 void SpectraAna::SetEtaAxis(Int_t bins, Double_t min, Double_t max) {
198 fEtaBins = bins;
199 fEtaMin = min;
200 fEtaMax = max;
201 }
202
203 void SpectraAna::SetEventCollectionName(TString name, Int_t event_collection) {
204 if (fEventCollectionsNames == NULL) { fEventCollectionsNames = new TClonesArray("TObjString"); }
205 TObjString* obj_string = (TObjString*) fEventCollectionsNames->ConstructedAt(event_collection);
206 obj_string->SetString(name);
207 }
208
209 void SpectraAna::SetTrackCollectionName(TString name, Int_t track_collection) {
210 if (fTrackCollectionsNames == NULL) { fTrackCollectionsNames = new TClonesArray("TObjString"); }
211 TObjString* obj_string = (TObjString*) fTrackCollectionsNames->ConstructedAt(track_collection);
212 obj_string->SetString(name);
213 }
214
215 void SpectraAna::CheckNames() {
216 if (fTrackCollectionsNames == NULL) { fTrackCollectionsNames = new TClonesArray("TObjString"); }
217 for (int i = 0; i < fTrackCollectionsNo; i++) {
218 TObjString* obj = (TObjString*) fTrackCollectionsNames->UncheckedAt(i);
219 if (obj == NULL) {
220 obj = (TObjString*) fTrackCollectionsNames->ConstructedAt(i);
221 obj->SetString(Form("track_collection[%i]", i));
222 }
223 }
224
225 if (fEventCollectionsNames == NULL) { fEventCollectionsNames = new TClonesArray("TObjString"); }
226 for (int i = 0; i < fEventCollectionsNo; i++) {
227 TObjString* obj = (TObjString*) fEventCollectionsNames->UncheckedAt(i);
228 if (obj == NULL) {
229 obj = (TObjString*) fEventCollectionsNames->ConstructedAt(i);
230 obj->SetString(Form("event_collection[%i]", i));
231 }
232 }
233 }
234
235 void SpectraAna::SetMass(Double_t mass, Int_t track_collection) {
236 fUseMass = kTRUE;
237 if (fMass.size() < (UInt_t) track_collection) { fMass.resize(track_collection + 1); }
238 fMass[track_collection] = mass;
239 }
240
241 void SpectraAna::SetOption(Option_t* opt) {
242 TString option = opt;
243 if (!option.EqualTo("auto")) {
245 } else {
246 Int_t event_collections = 0;
247 if (fCutContainer) {
248 Cout::PrintInfo("You sent auto option without event cuts, automatic configuration "
249 "will be work only for first even colllection",
250 EInfo::kWarning);
251 event_collections = fCutContainer->GetEventCollectionsNo();
252 }
253 TrackPdgCut pion_p;
254 ;
255 pion_p.SetMinAndMax(211);
256 TrackPdgCut pion_n;
257 pion_n.SetMinAndMax(-211);
258 TrackPdgCut kaon_p;
259 kaon_p.SetMinAndMax(321);
260 TrackPdgCut kaon_n;
261 kaon_n.SetMinAndMax(-321);
262 TrackPdgCut proton_p;
263 proton_p.SetMinAndMax(2212);
264 TrackPdgCut proton_n;
265 proton_n.SetMinAndMax(-2212);
266 for (int i = 0; i < event_collections; i++) {
267 Int_t count = event_collections * i;
268 pion_p.SetCollectionID(0 + count);
269 AddCut(pion_p);
270 SetTrackCollectionName("positive pions", 0 + count);
271 pion_n.SetCollectionID(1 + count);
272 AddCut(pion_n);
273 SetTrackCollectionName("negative pions", 1 + count);
274 kaon_p.SetCollectionID(2 + count);
275 AddCut(kaon_p);
276 SetTrackCollectionName("positive kaons", 2 + count);
277 kaon_n.SetCollectionID(3 + count);
278 AddCut(kaon_n);
279 SetTrackCollectionName("negative kaons", 3 + count);
280 proton_p.SetCollectionID(4 + event_collections * i);
281 AddCut(proton_p);
282 SetTrackCollectionName("protons", 4 + count);
283 proton_n.SetCollectionID(5 + count);
284 AddCut(proton_n);
285 SetTrackCollectionName("antiprotons", 5 + count);
286 }
287 }
288 }
289
290 SpectraAna::~SpectraAna() {
291 /* if(fPtY){
292 delete fPtY;
293 delete fPtEta;
294 delete fMtY;
295 delete fMtEta;
296 }*/
297 if (fTrackCollectionsNames) delete fTrackCollectionsNames;
298 if (fEventCollectionsNames) delete fEventCollectionsNames;
299 }
300} // namespace Hal
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
Int_t GetPrevAddr(Int_t index) const
ULong64_t GetPassed(Option_t *opt="") const
Int_t GetEventCollectionsNo() const
CutCollection * GetTrackCollection(Int_t collection) const
CutCollection * GetEventCollection(Int_t collection) const
void SetMinAndMax(Double_t val, Int_t i=0)
Definition Cut.cxx:91
void SetCollectionID(Int_t i)
Definition Cut.h:247
CutContainer * fCutContainer
Definition EventAna.h:78
Int_t fEventCollectionsNo
Definition EventAna.h:61
virtual void AddCut(const Cut &cut, Option_t *opt="")
Definition EventAna.cxx:322
virtual void AddTags(TString tag)
Definition EventAna.cxx:304
void Fill(Int_t i, Double_t X, Double_t Y)
void Init(Int_t size, HistogramAxisConf **axisconf, TString title, Bool_t Sumw=kFALSE)
void SetName(TString name)
Definition Package.cxx:298
void AddObject(TObject *object)
Definition Package.cxx:209
void SetPtAxis(Int_t bins, Double_t min, Double_t max)
void SetMtAxis(Int_t bins, Double_t min, Double_t max)
virtual void ProcessTrack()
void SetYAxis(Int_t bins, Double_t min, Double_t max)
Package * Report() const
void SetMass(Double_t mass, Int_t track_collection)
void SetOption(Option_t *opt)
void SetEventCollectionName(TString name, Int_t event_collection=0)
virtual Task::EInitFlag Init()
void SetEtaAxis(Int_t bins, Double_t min, Double_t max)
void SetTrackCollectionName(TString name, Int_t track_collection=0)
Track * fCurrentTrack
Definition TrackAna.h:42
virtual Task::EInitFlag Init()
Definition TrackAna.cxx:48
Int_t fCurrentTrackCollectionID
Definition TrackAna.h:34
Int_t fTrackCollectionsNo
Definition TrackAna.h:30
virtual void SetOption(Option_t *option)
Definition TrackAna.cxx:56
Double_t GetPz() const
Definition Track.h:109
Double_t GetPx() const
Definition Track.h:99
Double_t GetPy() const
Definition Track.h:104
Double_t GetE() const
Definition Track.h:114