CbmRoot
GenNoiseElectrons.cxx
Go to the documentation of this file.
1 #include "GenNoiseElectrons.h"
2 #include "CbmMCTrack.h"
3 #include "CbmMuchGeoScheme.h"
4 #include "CbmMuchPoint.h"
5 #include "CbmTrdPoint.h"
6 #include "FairLogger.h"
7 #include "TClonesArray.h"
8 #include "TGeoManager.h"
9 #include "TH1F.h"
10 #include "TRandom3.h"
11 #include <TFile.h>
12 
14 
16  : fNofNoiseE(1)
17  , fNofStations(4)
18  , fMCTracks(0)
19  , fMuchPoints(0)
20  , fTrdPoints(0)
21  , fOutMCTracks(0)
22  , fOutMuchPoints(0)
23  , fOutTrdPoints(0) {}
24 
26  delete fOutMCTracks;
27  delete fOutMuchPoints;
28  delete fOutTrdPoints;
29 }
30 
31 static Double_t x_rmss[4][3];
32 static Double_t y_rmss[4][3];
33 
34 static Double_t GetRMS(const char* name) {
35  Double_t result = -1.;
36  char fileName[128];
37  sprintf(fileName, "%s.root", name);
38  TFile* curFile = TFile::CurrentFile();
39  TFile* f = new TFile(fileName);
40 
41  if (!f->IsZombie()) {
42  TH1F* h = static_cast<TH1F*>(f->Get(name));
43 
44  if (0 != h) result = h->GetRMS();
45  }
46 
47  delete f;
48  TFile::CurrentFile() = curFile;
49  return result;
50 }
51 
53  FairRootManager* ioman = FairRootManager::Instance();
54 
55  if (0 == ioman) LOG(fatal) << "No FairRootManager";
56 
57  fMCTracks = static_cast<TClonesArray*>(ioman->GetObject("MCTrack"));
58  fMuchPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint"));
59  fTrdPoints = static_cast<TClonesArray*>(ioman->GetObject("TrdPoint"));
60 
61  if (0 == fMCTracks || 0 == fMuchPoints || 0 == fTrdPoints)
62  LOG(fatal) << "No MC tracks or points";
63 
64  char name[128];
65 
66  for (int i = 0; i < 4; ++i) {
67  for (int j = 0; j < 3; ++j) {
68  sprintf(name, "noise_e_x_%d_%d", i, j);
69  x_rmss[i][j] = GetRMS(name);
70 
71  if (x_rmss[i][j] < 0) {
72  sprintf(name, "Couldn't read noise_e_x_%d_%d", i, j);
73  LOG(fatal) << name;
74  }
75 
76  sprintf(name, "noise_e_y_%d_%d", i, j);
77  y_rmss[i][j] = GetRMS(name);
78 
79  if (y_rmss[i][j] < 0) {
80  sprintf(name, "Couldn't read noise_e_y_%d_%d", i, j);
81  LOG(fatal) << name;
82  }
83  }
84  }
85 
86  time_t initTime;
87  gRandom->SetSeed(time(&initTime));
88 
89  fOutMCTracks = new TClonesArray("CbmMCTrack", 1000);
90  ioman->Register("MCTrack", "MC", fOutMCTracks, kTRUE);
91  fOutMuchPoints = new TClonesArray("CbmMuchPoint", 1000);
92  ioman->Register("MuchPoint", "MUCH", fOutMuchPoints, kTRUE);
93  fOutTrdPoints = new TClonesArray("CbmTrdPoint", 1000);
94  ioman->Register("TrdPoint", "TRD", fOutTrdPoints, kTRUE);
95 
96  return kSUCCESS;
97 }
98 
99 void LxGenNoiseElectrons::Exec(Option_t* /*opt*/) {
100  fOutMCTracks->Delete();
101  fOutMuchPoints->Delete();
102  fOutTrdPoints->Delete();
103 
104  Int_t nofMCTracks = fMCTracks->GetEntriesFast();
105  TClonesArray& mctref = *fOutMCTracks;
106 
107  for (Int_t i = 0; i < nofMCTracks; ++i) {
108  const CbmMCTrack* mcTrack =
109  static_cast<const CbmMCTrack*>(fMCTracks->At(i));
110  new (mctref[i]) CbmMCTrack(*mcTrack);
111  }
112 
113  Int_t nofMuchPoints = fMuchPoints->GetEntriesFast();
114  TClonesArray& mpref = *fOutMuchPoints;
115 
116  for (Int_t i = 0; i < nofMuchPoints; ++i) {
117  const CbmMuchPoint* muchPoint =
118  static_cast<const CbmMuchPoint*>(fMuchPoints->At(i));
119  new (mpref[i]) CbmMuchPoint(*muchPoint);
120  }
121 
122  Int_t nofTrdPoints = fTrdPoints->GetEntriesFast();
123  TClonesArray& tpref = *fOutTrdPoints;
124 
125  for (Int_t i = 0; i < nofTrdPoints; ++i) {
126  const CbmTrdPoint* trdPoint =
127  static_cast<const CbmTrdPoint*>(fTrdPoints->At(i));
128  new (tpref[i]) CbmTrdPoint(*trdPoint);
129  }
130 
131  Int_t ind = nofMuchPoints;
132 
133  for (Int_t i = 0; i < nofMuchPoints; ++i) {
134  const CbmMuchPoint* pMuchPt =
135  static_cast<const CbmMuchPoint*>(fMuchPoints->At(i));
136  Int_t stationNumber =
138  Int_t layerNumber =
140 
141  for (int j = 0; j < fNofNoiseE; ++j) {
142  TVector3 posIn;
143  pMuchPt->PositionIn(posIn);
144  TVector3 posOut;
145  pMuchPt->PositionOut(posOut);
146  TVector3 posDelta = posOut - posIn;
147 
148  for (int k = 0; k < 20; ++k) {
149  TVector3 noiseDelta(
150  gRandom->Gaus(0, x_rmss[stationNumber][layerNumber]),
151  gRandom->Gaus(0, y_rmss[stationNumber][layerNumber]),
152  0);
153  TVector3 newIn = posIn + noiseDelta;
154  TGeoNode* node = gGeoManager->FindNode(newIn.X(), newIn.Y(), newIn.Z());
155 
156  if (0 == node) continue;
157 
158  TString nodeName(node->GetName());
159 
160  if (!nodeName.Contains("active", TString::kIgnoreCase)) continue;
161 
162  TVector3 newOut = newIn + 0.5 * posDelta;
163  node = gGeoManager->FindNode(newOut.X(), newOut.Y(), newOut.Z());
164 
165  if (0 == node) continue;
166 
167  TString nodeName2(node->GetName());
168 
169  if (!nodeName2.Contains("active", TString::kIgnoreCase)) continue;
170 
171  CbmMuchPoint noiseMuchPt(*pMuchPt);
172  noiseMuchPt.SetPosition(newIn);
173  noiseMuchPt.SetPositionOut(newOut);
174  noiseMuchPt.SetTrackID(-1);
175  new (mpref[ind++]) CbmMuchPoint(noiseMuchPt);
176  break;
177  }
178  }
179  }
180 }
181 
LxGenNoiseElectrons::Finish
void Finish()
Definition: GenNoiseElectrons.cxx:182
LxGenNoiseElectrons::Init
InitStatus Init()
Definition: GenNoiseElectrons.cxx:52
LxGenNoiseElectrons::fNofNoiseE
Int_t fNofNoiseE
Definition: GenNoiseElectrons.h:20
CbmMuchPoint
Definition: CbmMuchPoint.h:21
f
float f
Definition: L1/vectors/P4_F32vec4.h:24
LxGenNoiseElectrons::LxGenNoiseElectrons
LxGenNoiseElectrons()
LxGenNoiseElectrons::Exec
void Exec(Option_t *opt)
Definition: GenNoiseElectrons.cxx:99
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmMuchPoint::GetDetectorId
Int_t GetDetectorId() const
Definition: CbmMuchPoint.h:69
GetRMS
static Double_t GetRMS(const char *name)
Definition: GenNoiseElectrons.cxx:34
LxGenNoiseElectrons::fMCTracks
TClonesArray * fMCTracks
Definition: GenNoiseElectrons.h:22
ClassImp
ClassImp(LxGenNoiseElectrons) LxGenNoiseElectrons
Definition: GenNoiseElectrons.cxx:13
LxGenNoiseElectrons::fOutMuchPoints
TClonesArray * fOutMuchPoints
Definition: GenNoiseElectrons.h:26
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
CbmMuchPoint.h
h
Data class with information on a STS local track.
CbmMuchPoint::PositionIn
void PositionIn(TVector3 &pos) const
Definition: CbmMuchPoint.h:79
GenNoiseElectrons.h
CbmMuchPoint::PositionOut
void PositionOut(TVector3 &pos) const
Definition: CbmMuchPoint.h:80
x_rmss
static Double_t x_rmss[4][3]
Definition: GenNoiseElectrons.cxx:31
CbmTrdPoint
Definition: CbmTrdPoint.h:23
LxGenNoiseElectrons
Definition: GenNoiseElectrons.h:6
LxGenNoiseElectrons::fOutTrdPoints
TClonesArray * fOutTrdPoints
Definition: GenNoiseElectrons.h:27
CbmMCTrack.h
CbmMCTrack
Definition: CbmMCTrack.h:34
CbmTrdPoint.h
CbmMuchPoint::SetPositionOut
void SetPositionOut(TVector3 pos)
Definition: CbmMuchPoint.h:107
LxGenNoiseElectrons::~LxGenNoiseElectrons
~LxGenNoiseElectrons()
Definition: GenNoiseElectrons.cxx:25
LxGenNoiseElectrons::fTrdPoints
TClonesArray * fTrdPoints
Definition: GenNoiseElectrons.h:24
CbmMuchGeoScheme.h
LxGenNoiseElectrons::fMuchPoints
TClonesArray * fMuchPoints
Definition: GenNoiseElectrons.h:23
y_rmss
static Double_t y_rmss[4][3]
Definition: GenNoiseElectrons.cxx:32
LxGenNoiseElectrons::fOutMCTracks
TClonesArray * fOutMCTracks
Definition: GenNoiseElectrons.h:25