CbmRoot
Loading...
Searching...
No Matches
CbmMuchHitProducerIdeal.cxx
Go to the documentation of this file.
1/* Copyright (C) 2006-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Anna Senger, Andrey Lebedev, Denis Bertini [committer], Florian Uhlig */
4
12
13#include "CbmMuchGeoScheme.h"
14#include "CbmMuchPixelHit.h"
15#include "CbmMuchPoint.h"
16#include "FairRootManager.h"
17#include "TClonesArray.h"
18#include "TFile.h"
19#include "TRandom.h"
20#include "TVector3.h"
21
22#include <Logger.h>
23
24#include <cmath>
25
26using std::fabs;
27
28CbmMuchHitProducerIdeal::CbmMuchHitProducerIdeal(const char* digiFileName, Int_t Id)
29 : FairTask("CbmMuchHitProducerIdeal")
30 , fMuchPoints(NULL)
31 , fMuchPixelHits(NULL)
32 , fSigmaX(0.01)
33 , fSigmaY(0.01)
34 , fSigmaZ(0.)
35 , fId(Id)
36 , fDigiFile(digiFileName)
37 , fGeoScheme(NULL)
38{
39}
40
42
44{
45 FairRootManager* ioman = FairRootManager::Instance();
46 fMuchPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint"));
47 fMuchPixelHits = new TClonesArray("CbmMuchPixelHit", 100);
48 ioman->Register("MuchPixelHit", "MUCH", fMuchPixelHits, IsOutputBranchPersistent("MuchPixelHit"));
49
50 // Initialize GeoScheme
53 TFile* oldFile = gFile;
54 TDirectory* oldDir = gDirectory;
55
56 TFile* file = new TFile(fDigiFile);
57 LOG_IF(fatal, !file) << "Could not open file " << fDigiFile;
58 TObjArray* stations = file->Get<TObjArray>("stations");
59 LOG_IF(fatal, !stations) << "TObjArray stations not found in file " << fDigiFile;
60 file->Close();
61 file->Delete();
63 gFile = oldFile;
64 gDirectory = oldDir;
65
66 fGeoScheme->Init(stations, fId);
67 return kSUCCESS;
68}
69
71{
72 static Int_t eventNo = 0;
73 fMuchPixelHits->Clear();
74 Int_t iHit = 0;
75 Int_t nofMuchPoints = fMuchPoints->GetEntriesFast();
76 for (Int_t iPoint = 0; iPoint < nofMuchPoints; iPoint++) {
77 const CbmMuchPoint* point = static_cast<const CbmMuchPoint*>(fMuchPoints->At(iPoint));
78
79 // Smear position
80 Double_t dX = gRandom->Gaus(0, fSigmaX);
81 Double_t dY = gRandom->Gaus(0, fSigmaY);
82 Double_t dZ = gRandom->Gaus(0, fSigmaZ);
83
84 dX = (fabs(dX) < 3 * fSigmaX) ? dX : (dX > 0) ? 3 * fSigmaX : -3 * fSigmaX;
85 dY = (fabs(dY) < 3 * fSigmaY) ? dY : (dY > 0) ? 3 * fSigmaY : -3 * fSigmaY;
86 dZ = (fabs(dZ) < 3 * fSigmaZ) ? dZ : (dZ > 0) ? 3 * fSigmaZ : -3 * fSigmaZ;
87
88 TVector3 hitPos(point->GetXIn() + dX, point->GetYIn() + dY, point->GetZIn() + dZ);
89 TVector3 hitPosErr(fSigmaX, fSigmaY, fSigmaZ);
90
91 Int_t address = point->GetDetectorID();
92 Int_t planeId = fGeoScheme->GetLayerSideNr(address);
93
94 new ((*fMuchPixelHits)[iHit++]) CbmMuchPixelHit(address, hitPos, hitPosErr, 0, iPoint, planeId);
95 }
96 eventNo++;
97 LOG(info) << "CbmMuchHitProducerIdeal::Exec: eventNo=" << eventNo << " nofPoints=" << fMuchPoints->GetEntriesFast()
98 << " nofHits=" << fMuchPixelHits->GetEntriesFast();
99}
100
102
ClassImp(CbmConverterManager)
Ideal hit producer for MUon CHambers detector.
Class for pixel hits in MUCH detector.
Int_t GetLayerSideNr(Int_t detId) const
static CbmMuchGeoScheme * Instance()
void Init(TObjArray *stations, Int_t flag)
CbmMuchHitProducerIdeal(const char *digiFileName, Int_t Id)
double GetYIn() const
double GetZIn() const
double GetXIn() const