FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTestDetectorDigiTask.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  #include <TClonesArray.h> // for TClonesArray
10  #include <TGenericClassInfo.h> // for TGenericClassInfo
11  #include <TMath.h> // for Sqrt
12  #include <TRandom.h> // for TRandom, gRandom
13  #include <iostream> // for operator<<, basic_ostream, endl
14  #include "FairLink.h" // for FairLink
15  #include "FairRootManager.h" // for FairRootManager
16  #include "FairTestDetectorDigi.h" // for FairTestDetectorDigi
17  #include "FairTestDetectorPoint.h" // for FairTestDetectorPoint
18 
20  : FairTask("TestDetectorDigTask")
21  , fTimeResolution(0.)
22  , fPointArray(nullptr)
23  , fDigiArray(nullptr)
24 {}
25 
27 
29 {
31  if (!ioman) {
32  std::cout << "-E- FairTestDetectorDigiTask::Init: "
33  << "RootManager not instantiated!" << std::endl;
34  return kFATAL;
35  }
36 
37  fPointArray = static_cast<TClonesArray*>(ioman->GetObject("FairTestDetectorPoint"));
38  if (!fPointArray) {
39  std::cout << "-W- FairTestDetectorDigiTask::Init: "
40  << "No Point array!" << std::endl;
41  return kERROR;
42  }
43 
44  // Create and register output array
45  fDigiArray = new TClonesArray("FairTestDetectorDigi");
46  ioman->Register("FairTestDetectorDigi", "FairTestDetector", fDigiArray, kTRUE);
47 
48  return kSUCCESS;
49 }
50 
51 void FairTestDetectorDigiTask::Exec(Option_t* /*opt*/)
52 {
53 
54  fDigiArray->Delete();
55 
56  // fill the map
57 
58  for (int ipnt = 0; ipnt < fPointArray->GetEntries(); ipnt++) {
59  FairTestDetectorPoint* point = static_cast<FairTestDetectorPoint*>(fPointArray->At(ipnt));
60  if (!point) {
61  continue;
62  }
63 
64  Int_t xPad = CalcPad(point->GetX(), point->GetXOut());
65  Int_t yPad = CalcPad(point->GetY(), point->GetYOut());
66  Int_t zPad = CalcPad(point->GetZ(), point->GetZOut());
67 
68  Double_t timestamp = CalcTimeStamp(point->GetTime());
69 
70  FairTestDetectorDigi* digi = new ((*fDigiArray)[ipnt]) FairTestDetectorDigi(xPad, yPad, zPad, timestamp);
71  if (fTimeResolution > 0) {
72  digi->SetTimeStampError(fTimeResolution / TMath::Sqrt(fTimeResolution));
73  } else {
74  digi->SetTimeStampError(0);
75  }
76 
77  digi->AddLink(FairLink(-1, FairRootManager::Instance()->GetEntryNr(), "FairTestDetectorPoint", ipnt));
78  }
79 }
80 
81 Int_t FairTestDetectorDigiTask::CalcPad(Double_t posIn, Double_t posOut)
82 {
83  Int_t result = static_cast<Int_t>(posIn + posOut) / 2;
84  return result;
85 }
86 
87 Double_t FairTestDetectorDigiTask::CalcTimeStamp(Double_t timeOfFlight)
88 {
89  Double_t eventTime = FairRootManager::Instance()->GetEventTime();
90  Double_t detectionTime = gRandom->Gaus(0, fTimeResolution);
91 
92  Double_t result = eventTime + timeOfFlight + detectionTime;
93 
94  if (result < 0) {
95  return 0;
96  } else {
97  return result;
98  }
99 }
100 
virtual void Exec(Option_t *opt)
InitStatus
Definition: FairTask.h:33
Double_t GetZ() const
Definition: FairMCPoint.h:69
Double_t GetX() const
Definition: FairMCPoint.h:67
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
TObject * GetObject(const char *BrName)
Double_t GetEventTime()
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
void SetTimeStampError(Double_t t)
Definition: FairTimeStamp.h:48
Double_t GetY() const
Definition: FairMCPoint.h:68
Double_t GetTime() const
Definition: FairMCPoint.h:62