~maus-emr/maus/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 *
 * MAUS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MAUS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#include "EMRSD.hh"

#include <G4TransportationManager.hh>
#include <G4FieldManager.hh>
#include <G4Field.hh>
#include "G4HCofThisEvent.hh"
#include "G4Step.hh"
#include "G4ThreeVector.hh"
#include "G4SDManager.hh"
#include "G4ios.hh"

#include "Interface/MICEEvent.hh"
#include "Interface/dataCards.hh"
#include "Config/MiceModule.hh"
#include <G4StepStatus.hh>
#include <cstring>
#include <iostream>
#include <fstream>

#include "TFile.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TTree.h"

/**
* SAVING DATA IN JSON FILES 
**/

EMRSD::EMRSD(MiceModule* mod) : MAUSSD(mod) {
}

void EMRSD::Initialize(G4HCofThisEvent* HCE)
{
}


G4bool EMRSD::ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist) {

  G4double edep = aStep->GetTotalEnergyDeposit();

  int pid = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();

  if ( edep == 0. ) return false;
  if ( fabs(pid) != 13 ) return false;

  if (!_hits.isMember("emr_hits")) {
    _hits["emr_hits"] = Json::Value(Json::arrayValue);
  }
  int hit_i = _hits["emr_hits"].size();
//   _hits["emr_hits"].append(Json::Value());

//   std::cout << "EMRSD : " << hit_i << std::endl ;

//   G4TouchableHandle theTouchable = aStep->GetPreStepPoint()->GetTouchableHandle();
//   G4int barNumber = theTouchable->GetCopyNumber();  // get the fiber copy number
//   G4ThreeVector Pos = aStep->GetPreStepPoint()->GetPosition();  // true MC position
//   G4ThreeVector Mom = aStep->GetTrack()->GetMomentum();  // true momentum

//   Json::Value channel_id;
//    channel_id["bar_number"] = barNumber;
//    //  channel_id["bar_number"] = _module->propertyInt("Bar");

//   _hits["emr_hits"][hit_i]["channel_id"] = channel_id;
//   _hits["emr_hits"][hit_i]["track_id"] = aStep->GetTrack()->GetTrackID();
//   _hits["emr_hits"][hit_i]["energy"] = aStep->GetTrack()->GetTotalEnergy();
//   _hits["emr_hits"][hit_i]["charge"] =
//                              aStep->GetTrack()->GetDefinition()->GetPDGCharge();
//   _hits["emr_hits"][hit_i]["particle_id"] = pid;
//   _hits["emr_hits"][hit_i]["time"] =
//                                      aStep->GetPreStepPoint()->GetGlobalTime();
//   _hits["emr_hits"][hit_i]["energy_deposited"] = edep;
//   _hits["emr_hits"][hit_i]["momentum"]["x"] = Mom.x();
//   _hits["emr_hits"][hit_i]["momentum"]["y"] = Mom.y();
//   _hits["emr_hits"][hit_i]["momentum"]["z"] = Mom.z();
//   _hits["emr_hits"][hit_i]["position"]["x"] = Pos.x();
//   _hits["emr_hits"][hit_i]["position"]["y"] = Pos.y();
//   _hits["emr_hits"][hit_i]["position"]["z"] = Pos.z();

  return true;
}

void EMRSD::EndOfEvent(G4HCofThisEvent* HCE) {
  // do nothing
 }


/**
* SAVING DATA IN CPP FILES (TO BE CONVERTED LATER TO JSON OR ROOT) 
**/

// EMRSD::EMRSD( MiceModule* mod) : MAUSSD( mod )
// {
// }

// EMRSD::~EMRSD()
// {
// }

// void EMRSD::Initialize(G4HCofThisEvent* HCE) {

//   _hit_cppdata.SetEnergyDeposited(0.); 
//   _hit_cppdata.SetPathLength(0.);

//   _Edep = 0.;
//   _path = 0.;
// }

// G4bool EMRSD::ProcessHits(G4Step* aStep,G4TouchableHistory* ROhist) {

//     G4Track* track = aStep->GetTrack();

//     _Edep = aStep->GetTotalEnergyDeposit();
//     _path = aStep->GetStepLength();
//     ThreeVector pos( aStep->GetPreStepPoint()->GetPosition().x(),
//                      aStep->GetPreStepPoint()->GetPosition().y(),
//                      aStep->GetPreStepPoint()->GetPosition().z()); 
//     ThreeVector mom( track->GetMomentum().x(),
//                      track->GetMomentum().y(),
//                      track->GetMomentum().z());

//     _hit_cppdata.SetTrackId( track->GetTrackID() );
//     _hit_cppdata.SetParticleId( track->GetDefinition()->GetPDGEncoding() );
//     _hit_cppdata.SetEnergy( track->GetTotalEnergy() );
//     _hit_cppdata.SetCharge( track->GetDefinition()->GetPDGCharge() );
//     _hit_cppdata.SetTime( aStep->GetPreStepPoint()->GetGlobalTime() );
//     _hit_cppdata.SetPosition( pos );
//     _hit_cppdata.SetMomentum( mom );

//     _Edep += aStep->GetTotalEnergyDeposit();
//     _path += aStep->GetStepLength();
  

//   return true;
// }

// void EMRSD::EndOfEvent( G4HCofThisEvent* HCE ) {
//   _hit_cppdata.SetEnergyDeposited(_Edep); 
//   _hit_cppdata.SetPathLength(_path);	
// }