CbmRoot
Loading...
Searching...
No Matches
CbmStsHitProducerTaskIdeal.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: Volker Friese, Florian Uhlig [committer] */
4
5// -------------------------------------------------------------------------
6// ----- CbmStsHitProducerTaskIdeal source file -----
7// ----- Created 10/01/06 by V. Friese -----
8// -------------------------------------------------------------------------
10
11#include "CbmStsHit.h"
12#include "CbmStsPoint.h"
13#include "CbmTrdParSetGas.h"
14
15#include "FairRootManager.h"
16#include "FairRunAna.h"
17#include "FairRuntimeDb.h"
18#include <Logger.h>
19
20#include "TClonesArray.h"
21
22#include <iostream>
23
24using std::cout;
25using std::endl;
26
27
28// ----- Default constructor -------------------------------------------
30 : FairTask("Ideal STS Hit Producer Task")
31 , fPointArray(NULL)
32 , fHitArray(NULL)
33 , fTrdGasPar(NULL)
34{
35}
36// -------------------------------------------------------------------------
37
38
39// ----- Destructor ----------------------------------------------------
41// -------------------------------------------------------------------------
42
44{
45 fTrdGasPar = static_cast<CbmTrdParSetGas*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGas"));
46}
47
48// ----- Public method Init --------------------------------------------
50{
51
52 // Get RootManager
53 FairRootManager* ioman = FairRootManager::Instance();
54 if (!ioman) {
55 cout << "-E- CbmStsHitProducerTaskIdeal::Init: "
56 << "RootManager not instantised!" << endl;
57 return kFATAL;
58 }
59
60 // Get input array
61 fPointArray = (TClonesArray*) ioman->GetObject("StsPoint");
62 if (!fPointArray) {
63 cout << "-W- CbmStsHitProducerTaskIdeal::Init: "
64 << "No STSPoint array!" << endl;
65 return kERROR;
66 }
67
68 // Create and register output array
69 fHitArray = new TClonesArray("CbmStsHit");
70 ioman->Register("StsHit", "STS", fHitArray, IsOutputBranchPersistent("StsHit"));
71
72
73 if (fTrdGasPar) fTrdGasPar->Dump();
74
75 cout << "-I- CbmStsHitProducerTaskIdeal: Intialisation successfull" << endl;
76
77
78 return kSUCCESS;
79}
80// -------------------------------------------------------------------------
81
82
83std::vector<CbmStsPoint> CbmStsHitProducerTaskIdeal::Convert(TClonesArray* arr)
84{
85
86 std::vector<CbmStsPoint> vec;
87 Int_t entries = arr->GetEntriesFast();
88 if (entries > 0) {
89 CbmStsPoint* point = static_cast<CbmStsPoint*>(arr->At(0));
90 LOG(info) << "Entries in TCA for data type " << point->GetName() << ": " << entries;
91 }
92 for (int i = 0; i < entries; ++i) {
93 CbmStsPoint* point = static_cast<CbmStsPoint*>(arr->At(i));
94 vec.emplace_back(*point);
95 }
96 return vec;
97}
98
99
100std::vector<CbmStsHit> CbmStsHitProducerTaskIdeal::Algo(const std::vector<CbmStsPoint>& pointVect)
101{
102 // Declare some variables
103 // CbmStsPoint* point{nullptr};
104 Int_t detID {0}; // Detector ID
105 Double_t x {0.};
106 Double_t y {0.};
107 Double_t z {0.1}; // Position
108 Double_t dx {0.0001}; // Position error
109 TVector3 pos {};
110 TVector3 dpos {}; // Position and error vectors
111
112 std::vector<CbmStsHit> hitVect {};
113
114
115 // for(auto point: pointVect) {
116 for (unsigned long iPoint = 0; iPoint < pointVect.size(); ++iPoint) {
117
118 // Detector ID
119 detID = pointVect.at(iPoint).GetDetectorID();
120
121 // Determine hit position (centre plane of station)
122 x = 0.5 * (pointVect.at(iPoint).GetXOut() + pointVect.at(iPoint).GetXIn());
123 y = 0.5 * (pointVect.at(iPoint).GetYOut() + pointVect.at(iPoint).GetYIn());
124 z = 0.5 * (pointVect.at(iPoint).GetZOut() + pointVect.at(iPoint).GetZIn());
125
126 // Create new hit
127 pos.SetXYZ(x, y, z);
128 dpos.SetXYZ(dx, dx, 0.);
129
130 hitVect.emplace_back(detID, pos, dpos, 0., iPoint, iPoint, 0., 0.);
131 } // Loop over MCPoints
132
133 return hitVect;
134}
135// ----- Public method Exec --------------------------------------------
136void CbmStsHitProducerTaskIdeal::Exec(Option_t* /*opt*/)
137{
138
139 // Reset output array
140 if (!fHitArray) Fatal("Exec", "No StsHit array");
141
142 // fHitArray->Clear();
143 fHitArray->Delete();
144
146
147 // ConvertToVector
148 std::vector<CbmStsPoint> points = Convert(fPointArray);
149
150 // Pass the vector to the algorithm
151 // Get the vector with the newly created data objects from the algorithm
152 std::vector<CbmStsHit> hits = Algo(points);
153
154 // Fill the content of vector into TCA
155
156 int iPoint = 0;
157 for (const auto& hit : hits) {
158 new ((*fHitArray)[iPoint]) CbmStsHit(hit);
159 iPoint++;
160 }
161
162
163 // Event summary
164 cout << "-I- CbmStsHitProducerTaskIdeal: " << points.size() << " StsPoints, " << hits.size() << " Hits created."
165 << endl;
166}
167// -------------------------------------------------------------------------
168
169
TClonesArray * points
ClassImp(CbmConverterManager)
TVector3 dpos
Data class for a reconstructed hit in the STS.
static vector< vector< QAHit > > hits
std::vector< CbmStsHit > Algo(const std::vector< CbmStsPoint > &)
virtual void SetParContainers()
Inherited from FairTask.
std::vector< CbmStsPoint > Convert(TClonesArray *arr)
data class for a reconstructed 3-d hit in the STS
Definition CbmStsHit.h:35
Describe TRD module working settings (HV, etc)
virtual void Print(Option_t *opt="") const