Belle II Software  release-06-02-00
ECLHitDebugModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 //This module
9 #include <ecl/modules/eclHitDebug/ECLHitDebugModule.h>
10 
11 //Root
12 #include <TVector3.h>
13 
14 //Framework
15 #include <framework/gearbox/Unit.h>
16 
17 //ECL
18 #include <ecl/dataobjects/ECLSimHit.h>
19 #include <ecl/dataobjects/ECLDebugHit.h>
20 #include <ecl/geometry/ECLGeometryPar.h>
21 
22 using namespace std;
23 using namespace Belle2;
24 using namespace ECL;
25 
26 //-----------------------------------------------------------------
27 // Register the Module
28 //-----------------------------------------------------------------
29 REG_MODULE(ECLHitDebug)
30 
31 //-----------------------------------------------------------------
32 // Implementation
33 //-----------------------------------------------------------------
34 
36 {
37  // Set description
38  setDescription("ECLHitDebugModule");
39  setPropertyFlags(c_ParallelProcessingCertified);
40 
41 }
42 
43 ECLHitDebugModule::~ECLHitDebugModule()
44 {
45 }
46 
47 void ECLHitDebugModule::initialize()
48 {
49  // Initialize variables
50  m_nRun = 0 ;
51  m_nEvent = 0 ;
52  m_hitNum = 0;
53  // CPU time start
54  m_timeCPU = clock() * Unit::us;
55  m_eclDebugHits.registerInDataStore();
56 }
57 
58 void ECLHitDebugModule::beginRun()
59 {
60 }
61 
62 void ECLHitDebugModule::event()
63 {
64  //---------------------------------------------------------------------
65  // Merge the hits in the same cell and save them into ECL signal map.
66  //---------------------------------------------------------------------
67 
68  int const Nbin = 80;
69  int const interval = 8000 / Nbin;
70  static float E_cell[8736][Nbin];
71  static float Tof_ave[8736][Nbin];
72  memset(E_cell, 0, sizeof(float) * 8736 * Nbin);
73  memset(Tof_ave, 0, sizeof(float) * 8736 * Nbin);
74 
75  // Get instance of ecl geometry parameters
76  ECLGeometryPar* eclp = ECLGeometryPar::Instance();
77  // Loop over all hits of steps
78  for (int iHits = 0; iHits < m_eclSimArray.getEntries(); iHits++) {
79  // Get a hit
80  ECLSimHit* aECLSimHit = m_eclSimArray[iHits];
81 
82  // Hit geom. info
83  int hitCellId = aECLSimHit->getCellId() - 1;
84  double hitE = aECLSimHit->getEnergyDep() * Unit::GeV;
85  double hitTOF = aECLSimHit->getFlightTime() * Unit::ns;
86  G4ThreeVector t = aECLSimHit->getPosIn();
87  TVector3 HitInPos(t.x(), t.y(), t.z());
88 
89  const TVector3& PosCell = eclp->GetCrystalPos(hitCellId);
90  const TVector3& VecCell = eclp->GetCrystalVec(hitCellId);
91  double local_pos = (15. - (HitInPos - PosCell) * VecCell);
92 
93  int iECLCell = hitCellId;
94  if (hitTOF < 8000) {
95  int TimeIndex = (int) hitTOF / interval;
96  E_cell[iECLCell][TimeIndex] = E_cell[iECLCell][TimeIndex] + hitE;
97  Tof_ave[iECLCell][TimeIndex] += (6.05 + 0.0749 * local_pos - 0.00112 * local_pos * local_pos + hitTOF) * hitE ;
98  }
99 
100  }//for nHit
101 
102 
103  for (int iECLCell = 0; iECLCell < 8736; iECLCell++) {
104  for (int TimeIndex = 0; TimeIndex < Nbin; TimeIndex++) {
105 
106  if (E_cell[iECLCell][TimeIndex] > 0) {
107  m_eclDebugHits.appendNew();
108  m_hitNum = m_eclDebugHits.getEntries() - 1;
109  m_eclDebugHits[m_hitNum]->setCellId(iECLCell + 1);
110  m_eclDebugHits[m_hitNum]->setEnergyDep(E_cell[iECLCell][TimeIndex]);
111  m_eclDebugHits[m_hitNum]->setTimeAve(Tof_ave[iECLCell][TimeIndex] / E_cell[iECLCell][TimeIndex]);
112  }//if Energy > 0
113  }//16 Time interval 16x 500 ns
114  } //store each crystal hit
115 
116  m_nEvent++;
117 }
118 
119 
120 void ECLHitDebugModule::endRun()
121 {
122  m_nRun++;
123 }
124 
125 void ECLHitDebugModule::terminate()
126 {
127 }
Class to represent the hit of one cell.
ClassECLSimHit - Geant4 simulated hit for the ECL.
Definition: ECLSimHit.h:29
int getCellId() const
Get Cell ID.
Definition: ECLSimHit.h:86
double getFlightTime() const
Get Flight time from IP.
Definition: ECLSimHit.h:101
double getEnergyDep() const
Get Deposit energy.
Definition: ECLSimHit.h:106
G4ThreeVector getPosIn() const
Get Position.
Definition: ECLSimHit.h:121
The Class for ECL Geometry Parameters.
TVector3 GetCrystalVec(int cid)
The direction of crystal.
TVector3 GetCrystalPos(int cid)
The Position of crystal.
Base class for Modules.
Definition: Module.h:72
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.