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