BmnRoot
Loading...
Searching...
No Matches
BmnSiMDDigitizer.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- BmnSiMDDigitizer source file -----
3// ----- Created 23/12/20 by I. Kozlov (SPSU) -----
4// -------------------------------------------------------------------------
5
6#include "BmnSiMDDigitizer.h"
7#include "BmnSiMDPoint.h"
8#include "BmnTrigDigit.h"
9
10#include "FairRootManager.h"
11
12#include "TClonesArray.h"
13#include "TMath.h"
14
15#include <iostream>
16
17static Double_t workTime = 0.0;
18
19
20using namespace std;
21using namespace TMath;
22
23// ----- Default constructor -------------------------------------------
25 : FairTask("Bmn SiMD Digitizer"),
26 fPointArray(nullptr),
27 fDigitArray(),
28 fNMod(64) {
29}
30// -------------------------------------------------------------------------
31
32// ----- Destructor ----------------------------------------------------
34// -------------------------------------------------------------------------
35
36// ----- Public method Init --------------------------------------------
38
39 if (fVerbose) cout << "BmnSiMDDigitizer::Init() started\n ";
40
41 // Get RootManager
42 FairRootManager* ioman = FairRootManager::Instance();
43 if (!ioman) {
44 cout << "-E- BmnSiMDDigitizer::Init: " << "RootManager not instantiated!" << endl;
45 return kFATAL;
46 }
47
48 // Get input array
49 fPointArray = (TClonesArray*)ioman->GetObject("SiMDPoint");
50 if (!fPointArray) {
51 cout << "BmnSiMDDigitizer::Init(): branch SiMDPoint not found! Task will be deactivated" << endl;
52 SetActive(kFALSE);
53 return kERROR;
54 }
55
56 // Create and register output array
57 fDigitArray = new TClonesArray("BmnTrigDigit");
58 ioman->Register("SiMDDigit", "SiMD", fDigitArray, kTRUE);
59
60 fModsAngles = new Double_t[fNMod];
61 for (Int_t i = 0; i < fNMod; i++) {
62 fModsAngles[i] = i * 5.625;
63 }
64
65 if (fVerbose) cout << "BmnSiMDDigitizer::Init() finished\n";
66 return kSUCCESS;
67
68}
69// -------------------------------------------------------------------------
70
71// -------------------------------------------------------------------------
72// ----- Public method Exec --------------------------------------------
73void BmnSiMDDigitizer::Exec(Option_t* opt) {
74
75 if (!IsActive())
76 return;
77
78 TStopwatch sw;
79 sw.Start();
80
81 if (fVerbose) cout << " BmnSiMDDigitizer::Exec() started\n";
82
83 // Reset output array
84 if (!fDigitArray) Fatal("Exec", "No SiMDDigit array");
85
86 fDigitArray->Delete();
87
88 //map for storage energies at modules
89 map<Int_t, Double_t> ampMap;
90
91 // Loop over MCPoints
92 for (Int_t iPoint = 0; iPoint < fPointArray->GetEntriesFast(); iPoint++) {
93 BmnSiMDPoint* point = (BmnSiMDPoint*)fPointArray->At(iPoint);
94 if (!point) continue;
95
96 Int_t mod = ModByPoint(point->GetXOut(), point->GetYOut());
97
98 auto it = ampMap.find(mod);
99 if (it != ampMap.end()) {
100 ampMap[mod] += point->GetEnergyLoss();
101 } else {
102 ampMap[mod] = point->GetEnergyLoss();
103 }
104 }
105
106 //for (map<Int_t, Double_t>::iterator mit = ampMap.begin(); mit != ampMap.end(); ++mit) {
107 for (auto mit : ampMap) {
108 BmnTrigDigit digi;
109 digi.SetMod((Short_t)mit.first);
110 digi.SetAmp(mit.second);
111 new ((*fDigitArray)[fDigitArray->GetEntriesFast()]) BmnTrigDigit(digi);
112 }
113
114 if (fVerbose) {
115 printf(" Number of BmnSiMDPoints = %d\n", fPointArray->GetEntriesFast());
116 printf(" Number of BmnSiMDDigits = %d\n", fDigitArray->GetEntriesFast());
117 cout << " BmnSiMDDigitizer::Exec() finished\n";
118 }
119
120 sw.Stop();
121 workTime += sw.RealTime();
122}
123
124Int_t BmnSiMDDigitizer::ModByPoint(Double_t x, Double_t y) {
125
126 //Double_t XPOS = 0.5;
127 //Double_t YPOS = -4.6;
128
129 Double_t newX = x;// -XPOS;
130 Double_t newY = y;// -YPOS;
131 // Double_t pAngle = GetPointAngle(newX, newY);
132 Double_t pAngle = TVector2(newX, newY).Phi() * RadToDeg();
133 for (Int_t i = 0; i < fNMod; i++) {
134 if (pAngle >= fModsAngles[i] && pAngle <= (fModsAngles[i] + 5.6))
135 return i;
136 }
137 return -1;
138}
139
141 printf("Work time of the SiMD digitizer: %4.4f sec.\n", workTime);
142}
int i
Definition P4_F32vec4.h:22
virtual void Exec(Option_t *opt)
virtual InitStatus Init()
virtual void Finish()
Double_t GetYOut() const
Double_t GetXOut() const
void SetMod(Short_t mod)
void SetAmp(Double_t amp)
STL namespace.