er  dev
ERTelescopeDigitizer.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERTelescopeDigitizer.h"
10 
11 #include "TVector3.h"
12 #include "TGeoMatrix.h"
13 #include "TMath.h"
14 #include "TRandom3.h"
15 
16 #include "FairRootManager.h"
17 #include "FairRuntimeDb.h"
18 #include "FairLink.h"
19 #include "FairLogger.h"
20 
21 #include "ERDetectorList.h"
22 #include "ERPoint.h"
23 
24 //-------------------------------------------------------------------------------------------------
25 ERTelescopeDigitizer::ERTelescopeDigitizer()
26  : ERDigitizer("ER telescope digitization")
27 {
28  fAvailibleRunManagers.push_back("ERRunSim");
29  fAvailibleRunManagers.push_back("ERRunAna");
30 }
31 //-------------------------------------------------------------------------------------------------
32 ERTelescopeDigitizer::ERTelescopeDigitizer(Int_t verbose)
33  : ERDigitizer("ER telescope digitization ", verbose)
34 {
35  fAvailibleRunManagers.push_back("ERRunSim");
36  fAvailibleRunManagers.push_back("ERRunAna");
37 }
38 //-------------------------------------------------------------------------------------------------
40  if (ERTask::Init() != kSUCCESS)
41  return kFATAL;
42  // Get input array
43  FairRootManager* ioman = FairRootManager::Instance();
44  if ( ! ioman ) Fatal("Init", "No FairRootManager");
45 
46  TList* allbrNames = ioman->GetBranchNameList();
47  TIter nextBranch(allbrNames);
48  TObjString* bName;
49  std::vector<TString> pointBranches;
50  while (bName = (TObjString*)nextBranch()) {
51  TString bFullName = bName->GetString();
52  LOG(DEBUG) << "Branch full name " << bFullName << FairLogger::endl;
53  if (bFullName.Contains("Point") && bFullName.Contains("Telescope")) {
54  // Rename input point branches to output digi branches by changing class name prefix
55  // ERDetectorPoint_sensitiveVolNameNumber -> ERDetectorDigi_sensitiveVolNameNumber
56  // In map of output collections first parameter is full input branch name without class prefix
57  Int_t bPrefixNameLength = bFullName.First('_');
58  TString brName(bFullName(bPrefixNameLength + 1, bFullName.Length()));
59  fQTelescopePoints[brName] = (TClonesArray*) ioman->GetObject(bFullName);
60  TString bPrefixName(bFullName(0, bPrefixNameLength));
61  bPrefixName.Replace(bPrefixNameLength - 5, bPrefixNameLength, "Digi");
62  TString outBrName = bPrefixName + "_" + brName;
63  fQTelescopeDigi[brName] = new TClonesArray("ERDigi", consts::approx_telescope_digi_number);
64  LOG(DEBUG) << "Branch name " << brName << FairLogger::endl;
65  ioman->Register(outBrName, "Telescope", fQTelescopeDigi[brName], kTRUE);
66  }
67  }
68  return kSUCCESS;
69 }
70 //-------------------------------------------------------------------------------------------------
71 void ERTelescopeDigitizer::Exec(Option_t* opt) {
72  Reset();
73  for (const auto &itPointBranches : fQTelescopePoints) {
74  Double_t elossThreshold, timeThreshold;
75  Double_t elossSigma, timeSigma;
76  std::map<Int_t, std::vector<Int_t>> sortedPoints;
77  if (itPointBranches.first.Contains("Si")) {
78  elossThreshold = fSiElossThreshold;
79  elossSigma = fSiElossSigma;
80  timeSigma = fSiTimeSigma;
81  }
82  if (itPointBranches.first.Contains("CsI")) {
83  elossThreshold = fCsIElossThreshold;
84  elossSigma = fCsIElossSigma;
85  timeSigma = fCsITimeSigma;
86  }
87  for (Int_t iPoint = 0; iPoint < itPointBranches.second->GetEntriesFast(); iPoint++){
88  ERPoint* point = (ERPoint*)(itPointBranches.second->At(iPoint));
89  sortedPoints[point->GetVolNb()].push_back(iPoint);
90  }
91  for (const auto &itPoint : sortedPoints) {
92  Float_t edep = 0.; //sum edep in strip
93  Float_t time = std::numeric_limits<float>::max(); // min time in strip
94  for (const auto itPointsForCurrentVolume : itPoint.second) {
95  const auto* point = (ERPoint*)(itPointBranches.second->At(itPointsForCurrentVolume));
96  edep += point->GetEnergyLoss();
97  if (point->GetTime() < time) {
98  time = point->GetTime();
99  }
100  }
101  if (edep == 0) { // if no points in input branch
102  continue;
103  }
104  edep = gRandom->Gaus(edep, elossSigma);
105  if (edep < elossThreshold)
106  continue;
107  time = gRandom->Gaus(time, timeSigma);
108  auto* digi = AddDigi(edep, time, itPoint.first, itPointBranches.first);
109  //for (const auto itPointsForCurrentVolume : itPoint.second) {
110  // digi->AddLink(FairLink("ERPoint", itPointsForCurrentVolume));
111  //}
112  }
113  }
114  /*@TODO: This functionality can be transferred to ERDigitizer if the information
115  about the conformity of the trigger station and the digi collection moves there.*/
116  for ( const auto &itDigiBranch : fQTelescopeDigi ) {
117  TString branchName = itDigiBranch.first;
118  TClonesArray* digiCol = itDigiBranch.second;
119  for ( const auto &trigger : fTriggers) {
120  TString triggerStation = trigger.first;
121  if (branchName.Contains(triggerStation)){
122  LOG(DEBUG) << "Apply trigger to station " << triggerStation << FairLogger::endl;
123  ApplyTrigger(triggerStation,digiCol);
124  }
125  }
126  }
127 }
128 //-------------------------------------------------------------------------------------------------
130  for (const auto itDigiBranches : fQTelescopeDigi) {
131  if (itDigiBranches.second) {
132  itDigiBranches.second->Delete();
133  }
134  }
135 }
136 //-------------------------------------------------------------------------------------------------
138 }
139 //-------------------------------------------------------------------------------------------------
140 ERDigi* ERTelescopeDigitizer::AddDigi(Float_t edep, Double_t time, Int_t stripNb,
141  TString digiBranchName) {
142  ERDigi *digi = new((*fQTelescopeDigi[digiBranchName])
143  [fQTelescopeDigi[digiBranchName]->GetEntriesFast()]) ERDigi(edep, time, stripNb);
144  return digi;
145 }
146 //-------------------------------------------------------------------------------------------------
147 ClassImp(ERTelescopeDigitizer)
virtual InitStatus Init()
Definition: ERDigi.h:15
virtual InitStatus Init()
Definition: ERTask.cxx:31
The data class for storing pieces of charged tracks in sensitive volumes in NeuRad.
Definition: ERPoint.h:23
std::vector< TString > fAvailibleRunManagers
Run managers that are availible for this task.
Definition: ERTask.h:64
virtual void Exec(Option_t *opt)