CbmRoot
CalcStats.cxx
Go to the documentation of this file.
1 #include "CalcStats.h"
2 #include "CbmMCTrack.h"
3 #include "CbmMuchGeoScheme.h"
4 #include "CbmMuchPoint.h"
5 #include "CbmTrdAddress.h"
6 #include "CbmTrdPoint.h"
7 #include "FairLogger.h"
8 #include "TClonesArray.h"
9 #include <TFile.h>
10 #include <list>
11 #include <map>
12 
14 
15  using namespace std;
16 
17 struct LxStatTrack {
18  list<Int_t> muchPoints[4][3];
19  list<Int_t> trdPoints[4];
20 };
21 
22 LxCalcStats::LxCalcStats() : fMCTracks(0), fMuchPoints(0), fTrdPoints(0) {}
23 
24 InitStatus LxCalcStats::Init() {
25  FairRootManager* ioman = FairRootManager::Instance();
26 
27  if (0 == ioman) LOG(fatal) << "No FairRootManager";
28 
29  fMCTracks = static_cast<TClonesArray*>(ioman->GetObject("MCTrack"));
30  fMuchPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint"));
31  fTrdPoints = static_cast<TClonesArray*>(ioman->GetObject("TrdPoint"));
32 
33  if (0 == fMCTracks || (0 == fMuchPoints && 0 == fTrdPoints))
34  LOG(fatal) << "No MC tracks or points";
35 
36  char buf[128];
37 
38  for (int i = 0; i < 4; ++i) {
39  for (int j = 0; j < 3; ++j) {
40  sprintf(buf, "noise_e_x_%d_%d", i, j);
41  xHistos[i][j] = new TH1F(buf, buf, 240, -30., 30.);
42  sprintf(buf, "noise_e_y_%d_%d", i, j);
43  yHistos[i][j] = new TH1F(buf, buf, 240, -30., 30.);
44  }
45  }
46 
47  for (int i = 1; i < 4; ++i) {
48  sprintf(buf, "trdDeltaThetaX_%d", i);
49  trdDeltaThetaXHistos[i - 1] = new TH1F(buf, buf, 100, -1.0, 1.0);
50  sprintf(buf, "trdDeltaThetaY_%d", i);
51  trdDeltaThetaYHistos[i - 1] = new TH1F(buf, buf, 100, -1.0, 1.0);
52  }
53 
54  return kSUCCESS;
55 }
56 
57 void LxCalcStats::Exec(Option_t* /*opt*/) {
58  map<Int_t, LxStatTrack> eNoiseTracks;
59  Int_t nofMuchPoints = 0 == fMuchPoints ? 0 : fMuchPoints->GetEntriesFast();
60 
61  for (Int_t i = 0; i < nofMuchPoints; ++i) {
62  const CbmMuchPoint* point =
63  static_cast<const CbmMuchPoint*>(fMuchPoints->At(i));
64  Int_t stationNumber =
66  Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(point->GetDetectorId());
67  Int_t trackId = point->GetTrackID();
68  map<Int_t, LxStatTrack>::iterator trIt = eNoiseTracks.find(trackId);
69 
70  if (trIt == eNoiseTracks.end()) eNoiseTracks[trackId] = LxStatTrack();
71 
72  eNoiseTracks[trackId].muchPoints[stationNumber][layerNumber].push_back(i);
73  }
74 
75  for (Int_t i = 0; i < nofMuchPoints; ++i) {
76  const CbmMuchPoint* point =
77  static_cast<const CbmMuchPoint*>(fMuchPoints->At(i));
78  Int_t stationNumber =
80  Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(point->GetDetectorId());
81  Int_t trackId = point->GetTrackID();
82  const CbmMCTrack* track =
83  static_cast<const CbmMCTrack*>(fMCTracks->At(trackId));
84  Int_t pdgCode = track->GetPdgCode();
85 
86  if (11 == pdgCode) {
87  Double_t x = (point->GetXIn() + point->GetXOut()) / 2;
88  Double_t y = (point->GetYIn() + point->GetYOut()) / 2;
89  Int_t parentId = track->GetMotherId();
90 
91  while (parentId >= 0) {
92  const CbmMCTrack* parent =
93  static_cast<const CbmMCTrack*>(fMCTracks->At(parentId));
94  const list<Int_t> parentPts =
95  eNoiseTracks[parentId].muchPoints[stationNumber][layerNumber];
96 
97  for (list<Int_t>::const_iterator j = parentPts.begin();
98  j != parentPts.end();
99  ++j) {
100  Int_t parentPtId = *j;
101  const CbmMuchPoint* parentPt =
102  static_cast<const CbmMuchPoint*>(fMuchPoints->At(parentPtId));
103  Double_t pX = (parentPt->GetXIn() + parentPt->GetXOut()) / 2;
104  Double_t pY = (parentPt->GetYIn() + parentPt->GetYOut()) / 2;
105  xHistos[stationNumber][layerNumber]->Fill(x - pX);
106  yHistos[stationNumber][layerNumber]->Fill(y - pY);
107  }
108 
109  parentId = parent->GetMotherId();
110  }
111  }
112  }
113 
114  map<Int_t, LxStatTrack> jPsiMuTracks;
115  Int_t nofTrdPoints = 0 == fTrdPoints ? 0 : fTrdPoints->GetEntriesFast();
116 
117  for (Int_t i = 0; i < nofTrdPoints; ++i) {
118  const CbmTrdPoint* point =
119  static_cast<const CbmTrdPoint*>(fTrdPoints->At(i));
120  Int_t layerNumber = CbmTrdAddress::GetLayerId(point->GetModuleAddress());
121  Int_t trackId = point->GetTrackID();
122  const CbmMCTrack* track =
123  static_cast<const CbmMCTrack*>(fMCTracks->At(trackId));
124 
125  if (-11 != track->GetPdgCode() && 11 != track->GetPdgCode()) continue;
126 
127  Int_t motherId = track->GetMotherId();
128 
129  if (0 > motherId) continue;
130 
131  const CbmMCTrack* mother =
132  static_cast<const CbmMCTrack*>(fMCTracks->At(motherId));
133 
134  if (443 != mother->GetPdgCode()) continue;
135 
136  map<Int_t, LxStatTrack>::iterator trIt = jPsiMuTracks.find(trackId);
137 
138  if (trIt == jPsiMuTracks.end()) jPsiMuTracks[trackId] = LxStatTrack();
139 
140  jPsiMuTracks[trackId].trdPoints[layerNumber].push_back(i);
141  }
142 
143  for (map<Int_t, LxStatTrack>::const_iterator i = jPsiMuTracks.begin();
144  i != jPsiMuTracks.end();
145  ++i) {
146  const LxStatTrack& track = i->second;
147 
148  for (int j = 1; j < 4; ++j) {
149  const list<Int_t>& lPoints = track.trdPoints[j - 1];
150  const list<Int_t>& rPoints = track.trdPoints[j];
151 
152  for (list<Int_t>::const_iterator k = rPoints.begin(); k != rPoints.end();
153  ++k) {
154  const CbmTrdPoint* rPoint =
155  static_cast<const CbmTrdPoint*>(fTrdPoints->At(*k));
156  Double_t rX = (rPoint->GetXIn() + rPoint->GetXOut()) / 2;
157  Double_t rY = (rPoint->GetYIn() + rPoint->GetYOut()) / 2;
158  Double_t rZ = (rPoint->GetZIn() + rPoint->GetZOut()) / 2;
159  Double_t rTx = rX / rZ;
160  Double_t rTy = rY / rZ;
161 
162  for (list<Int_t>::const_iterator l = lPoints.begin();
163  l != lPoints.end();
164  ++l) {
165  const CbmTrdPoint* lPoint =
166  static_cast<const CbmTrdPoint*>(fTrdPoints->At(*l));
167  Double_t lX = (lPoint->GetXIn() + lPoint->GetXOut()) / 2;
168  Double_t lY = (lPoint->GetYIn() + lPoint->GetYOut()) / 2;
169  Double_t lZ = (lPoint->GetZIn() + lPoint->GetZOut()) / 2;
170  Double_t deltaZ = lZ - rZ;
171  Double_t x = rX + rTx * deltaZ;
172  Double_t y = rY + rTy * deltaZ;
173  trdDeltaThetaXHistos[j - 1]->Fill((lX - x) / deltaZ);
174  trdDeltaThetaYHistos[j - 1]->Fill((lY - y) / deltaZ);
175  }
176  }
177  }
178  }
179 }
180 
181 static void SaveHisto(TH1F* h) {
182  TFile* curFile = TFile::CurrentFile();
183  char name[128];
184  sprintf(name, "%s.root", h->GetName());
185  TFile fh(name, "RECREATE");
186  h->Write();
187  fh.Close();
188  delete h;
189  TFile::CurrentFile() = curFile;
190 }
191 
193  for (int i = 0; i < 4; ++i) {
194  for (int j = 0; j < 3; ++j) {
195  SaveHisto(xHistos[i][j]);
196  SaveHisto(yHistos[i][j]);
197  }
198  }
199 
200  for (int i = 0; i < 3; ++i) {
203  }
204 }
CbmMuchPoint::GetXOut
Double_t GetXOut() const
Definition: CbmMuchPoint.h:73
CbmMCTrack::GetMotherId
Int_t GetMotherId() const
Definition: CbmMCTrack.h:71
h
Generates beam ions for transport simulation.
Definition: CbmBeamGenerator.h:17
CbmTrdPoint::GetYOut
Double_t GetYOut() const
Definition: CbmTrdPoint.h:67
LxCalcStats::fTrdPoints
TClonesArray * fTrdPoints
Definition: CalcStats.h:19
CbmMuchPoint
Definition: CbmMuchPoint.h:21
CbmTrdPoint::GetZIn
Double_t GetZIn() const
Definition: CbmTrdPoint.h:65
CbmTrdAddress.h
Helper class to convert unique channel ID back and forth.
LxCalcStats::Exec
void Exec(Option_t *opt)
Definition: CalcStats.cxx:57
LxCalcStats::yHistos
TH1F * yHistos[4][3]
Definition: CalcStats.h:21
CbmMCTrack::GetPdgCode
Int_t GetPdgCode() const
Definition: CbmMCTrack.h:70
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
LxCalcStats::trdDeltaThetaXHistos
TH1F * trdDeltaThetaXHistos[3]
Definition: CalcStats.h:22
CbmMuchPoint::GetDetectorId
Int_t GetDetectorId() const
Definition: CbmMuchPoint.h:69
CbmTrdPoint::GetXOut
Double_t GetXOut() const
Definition: CbmTrdPoint.h:66
CbmTrdAddress::GetLayerId
static UInt_t GetLayerId(UInt_t address)
Return layer ID from address.
Definition: CbmTrdAddress.h:69
CbmMuchPoint::GetYOut
Double_t GetYOut() const
Definition: CbmMuchPoint.h:74
CbmMuchGeoScheme::GetLayerIndex
static Int_t GetLayerIndex(Int_t address)
Definition: CbmMuchGeoScheme.h:71
CbmMuchGeoScheme::GetStationIndex
static Int_t GetStationIndex(Int_t address)
Definition: CbmMuchGeoScheme.h:68
LxCalcStats::xHistos
TH1F * xHistos[4][3]
Definition: CalcStats.h:20
CbmMuchPoint.h
LxStatTrack
Definition: CalcStats.cxx:17
SaveHisto
static void SaveHisto(TH1F *h)
Definition: CalcStats.cxx:181
LxCalcStats::trdDeltaThetaYHistos
TH1F * trdDeltaThetaYHistos[3]
Definition: CalcStats.h:23
LxCalcStats::fMCTracks
TClonesArray * fMCTracks
Definition: CalcStats.h:17
CbmTrdPoint::GetZOut
Double_t GetZOut() const
Definition: CbmTrdPoint.h:68
CalcStats.h
LxCalcStats
Definition: CalcStats.h:7
CbmTrdPoint
Definition: CbmTrdPoint.h:23
LxCalcStats::fMuchPoints
TClonesArray * fMuchPoints
Definition: CalcStats.h:18
CbmMCTrack.h
CbmTrdPoint::GetXIn
Double_t GetXIn() const
Definition: CbmTrdPoint.h:63
LxCalcStats::Finish
void Finish()
Definition: CalcStats.cxx:192
CbmMCTrack
Definition: CbmMCTrack.h:34
CbmMuchPoint::GetYIn
Double_t GetYIn() const
Definition: CbmMuchPoint.h:71
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdPoint::GetModuleAddress
Int_t GetModuleAddress() const
Definition: CbmTrdPoint.h:76
LxStatTrack::trdPoints
list< Int_t > trdPoints[4]
Definition: CalcStats.cxx:19
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdPoint.h
CbmMuchPoint::GetXIn
Double_t GetXIn() const
Definition: CbmMuchPoint.h:70
ClassImp
ClassImp(LxCalcStats) using namespace std
CbmMuchGeoScheme.h
CbmTrdPoint::GetYIn
Double_t GetYIn() const
Definition: CbmTrdPoint.h:64
LxCalcStats::LxCalcStats
LxCalcStats()
Definition: CalcStats.cxx:22
LxCalcStats::Init
InitStatus Init()
Definition: CalcStats.cxx:24