FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutorialDet2Digitizer.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
9 
10 #include "FairLogger.h"
11 #include "FairRootManager.h"
12 #include "FairRunAna.h"
13 #include "FairRuntimeDb.h"
15 #include "FairTutorialDet2Point.h"
16 
17 #include <TClonesArray.h>
18 
20  : FairTask("TutorialDetDigitizer", 0)
21  , fTutorialDetPoints(nullptr)
22  , fCustomData2(new std::vector<CustomClass>)
23  , fDigiPar(nullptr)
24 {}
25 
26 FairTutorialDet2Digitizer::FairTutorialDet2Digitizer(const char* name, const char* /*title*/)
27  : FairTask(name, 0)
28  , fTutorialDetPoints(nullptr)
29  , fCustomData2(new std::vector<CustomClass>)
30  , fDigiPar(nullptr)
31 {}
32 
34 {
35  // FairRootManager *ioman =FairRootManager::Instance();
36  // ioman->Write();
37  // fDigiCollection->Clear("C");
38  // delete fDigiCollection;
39 }
40 
42 {
43  LOG(debug) << "FairTutorialDet2Digitizer :: SetParContainers() ";
44 
45  // Get Base Container
47  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
48 
49  fDigiPar = static_cast<FairTutorialDet2DigiPar*>(rtdb->getContainer("FairTutorialDet2DigiPar"));
50 
51  // parameters are not filled yet
52  fDigiPar->printparams();
53 }
54 
56 {
57  LOG(info) << " FairTutorialDet2Digitizer :: ReInit() ";
58 
60  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
61 
62  fDigiPar = static_cast<FairTutorialDet2DigiPar*>(rtdb->getContainer("FairTutorialDet2DigiPar"));
63 
64  return kSUCCESS;
65 }
66 
68 {
69  LOG(debug) << " FairTutorialDet2Digitizer :: Init() ";
70 
72  if (!ioman) {
73  LOG(fatal) << "No FairRootManager";
74  return kERROR;
75  } else {
76  fTutorialDetPoints = static_cast<TClonesArray*>(ioman->GetObject("TutorialDetPoint"));
77  if (!fTutorialDetPoints) {
78  LOG(error) << "No TutorialDetPoints array!";
79  LOG(error) << "Task will be inactive";
80  LOG(info) << " Task FairTutorialDet2Digitizer will be inactive, No TutorialDetPoints";
81  return kERROR;
82  }
83 
84  fCustomData = ioman->InitObjectAs<std::vector<CustomClass> const*>("TutorialCustomData");
85  if (!fCustomData) {
86  LOG(error) << "Custom Data cannot be created!";
87  LOG(error) << "Task will be inactive";
88  LOG(info) << " Task FairTutorialDet2Digitizer will be inactive, No Custom Data Vector";
89  return kERROR;
90  }
91 
92  // fListStack = (TClonesArray*)ioman->GetObject("MCTrack");
93  // fDigiCollection = new TClonesArray("FairTrdDigi", 100);
94  // ioman->Register("TRDDigi","TRD Digis",fDigiCollection,kTRUE);
95 
96  // now parameters are filled
97  // fDigiPar->printparams();
98 
99  // register data output of this task
100  Register();
101 
102  return kSUCCESS;
103  }
104 }
105 
106 void FairTutorialDet2Digitizer::Exec(Option_t* /*option*/)
107 {
108  // Here we print something
109 
110  LOG(debug) << " I am in FairTutorialDet2Digitizer::Exec";
111 
112  LOG(debug) << " The custom data input vector has size" << fCustomData->size() << "\n";
113 
114  for (auto& entry : *fCustomData) {
115  LOG(debug) << " Got entry " << entry.GetX() << " " << entry.GetQ() << "\n";
116  // process data and fill a structure here, which can be consumed by the next task
117  fCustomData2->emplace_back(entry.GetX() * 2, entry.GetQ() * 10);
118  }
119 
120  /*
121 
122  fNHits = 0;
123  FairTutorialDet2Point *pt=nullptr;
124 
125  Int_t nentries = fTutorialDetPoints->GetEntriesFast();
126 
127  Double_t ELoss; // total energy loss
128 
129  for (int j=0; j < nentries; j++) {
130 
131  pt = (FairTutorialDet2Point*) fTutorialDetPoints->At(j);
132 
133  if(nullptr == pt) continue;
134 
135  // Double_t x_mean = (pt->GetXIn()+pt->GetXOut())/2.;
136  // Double_t y_mean = (pt->GetYIn()+pt->GetYOut())/2.;
137  // Double_t z_mean = (pt->GetZIn()+pt->GetZOut())/2.;
138 
139  Double_t x_mean = pt->GetXOut();
140  Double_t y_mean = pt->GetYOut();
141  Double_t z_mean = pt->GetZOut();
142 
143  gGeoManager->FindNode(x_mean, y_mean, z_mean);
144  TString path = gGeoManager->GetPath();
145  Int_t ID = gGeoManager->GetCurrentNodeId();
146 
147  TGeoNode *curnode = gGeoManager->GetCurrentNode();
148  TGeoVolume *curvol = gGeoManager->GetCurrentVolume();
149  TGeoMaterial *curmat =curvol->GetMedium()->GetMaterial();
150 
151  const Double_t *global_point = gGeoManager->GetCurrentPoint();
152  Double_t local_point[3]; // global_point[3];
153 
154  gGeoManager->MasterToLocal(global_point, local_point);
155 
156  TGeoHMatrix *matrix = gGeoManager->GetCurrentMatrix();
157 
158  TGeoBBox *shape = (TGeoBBox*)curvol->GetShape();
159  Float_t sizex = shape->GetDX();
160  Float_t sizey = shape->GetDY();
161  Float_t sizez = shape->GetDZ();
162 
163  // LOG(info) <<"x_in: " << pt->GetXIn();
164  // LOG(info) <<"x_mean: " << x_mean;
165  //LOG(info) <<"x_out: " << pt->GetXOut();
166 
167  //LOG(info) <<"y: " << y_mean;
168 
169  //LOG(info) <<"z_in: " << pt->GetZIn();
170  //LOG(info) <<"z_mean: " << z_mean;
171  // LOG(info) <<"z_out: " << pt->GetZOut();
172 
173 
174  if (matrix->IsRotation()){
175  LOG(info) <<"Module is rotated";
176  } else {
177  LOG(info) <<"Module is not rotated";
178  }
179 
180 
181  }
182  */
183 }
184 
186 
188 {
189  // testing to transfer a variable to another task via a memory branch
190  LOG(info) << "Digitizer::Register\n";
191  FairRootManager::Instance()->RegisterAny("InMemory1", fCustomData2, false);
192 }
193 
list of container factories
Definition: FairRuntimeDb.h:24
InitStatus
Definition: FairTask.h:33
virtual void Exec(Option_t *option)
T InitObjectAs(const char *BrName)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
TObject * GetObject(const char *BrName)
FairParSet * getContainer(const Text_t *)
static FairRunAna * Instance()
Definition: FairRunAna.cxx:61
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
void RegisterAny(const char *name, T *&obj, Bool_t toFile)