00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00033
00034
00045
00046
00047
00048 #include <CLHEP/Units/SystemOfUnits.h>
00049
00050 #include "io/MJLogger.hh"
00051 #include "waveform/MJWaveformChargePoint.hh"
00052 #include "waveform/MJWaveformPlanarCrystal.hh"
00053 #include "waveform/MJWaveformPlanarSegment.hh"
00054
00055
00056
00057 #include "waveform/MJWaveformPlanarDetector.hh"
00058
00059
00060
00061 MJWaveformPlanarDetector::MJWaveformPlanarDetector():
00062 fData(0), fPlanarCrystal1(0), fPlanarCrystal2(0), fStep(0)
00063 {;}
00064
00065
00066
00067 MJWaveformPlanarDetector::MJWaveformPlanarDetector(const MJWaveformPlanarDetector & other)
00068 {;}
00069
00070
00071
00072 MJWaveformPlanarDetector::~MJWaveformPlanarDetector()
00073 {
00074 delete fData;
00075 }
00076
00077
00078
00079 void MJWaveformPlanarDetector::BeginOfEventAction()
00080 {
00081 Hep3Vector coord;
00082
00083
00084 coord.setX(5.0 * cm);
00085 coord.setY(5.0 * cm);
00086 coord.setZ((2.5 + 0.5*fStep++) * cm);
00087 HepInt crap[3];
00088 HepInt *location;
00089 location = crap;
00090 fPlanarCrystal1->ConvertCoordinateToGridpoint(&coord, location);
00091 HepInt sign;
00092 HepDouble Eloss;
00093 MJWaveformChargePoint *epoint = new MJWaveformChargePoint(
00094 location,
00095 sign = -1,
00096 Eloss = 2.0 * MeV,
00097 fPlanarCrystal1);
00098 MJWaveformChargePoint *hpoint = new MJWaveformChargePoint(
00099 location,
00100 sign = +1,
00101 Eloss = 2.0 * MeV,
00102 fPlanarCrystal1);
00103 epoint->InitializePropagation();
00104 hpoint->InitializePropagation();
00105 fPlanarCrystal1->AddChargePoint(epoint);
00106 fPlanarCrystal1->AddChargePoint(hpoint);
00107
00108 coord.setX(5.0 * cm);
00109 coord.setY(5.0 * cm);
00110 coord.setZ(6.3 * cm);
00111 fPlanarCrystal1->ConvertCoordinateToGridpoint(&coord, location);
00112 epoint = new MJWaveformChargePoint(
00113 location,
00114 sign = -1,
00115 Eloss = 4.0 * MeV,
00116 fPlanarCrystal1);
00117 hpoint = new MJWaveformChargePoint(
00118 location,
00119 sign = +1,
00120 Eloss = 4.0 * MeV,
00121 fPlanarCrystal1);
00122 epoint->InitializePropagation();
00123 hpoint->InitializePropagation();
00124 fPlanarCrystal1->AddChargePoint(epoint);
00125 fPlanarCrystal1->AddChargePoint(hpoint);
00126
00127 fPlanarCrystal1->GetFirstSegment()->ResetCounters();
00128 fPlanarCrystal1->GetFirstSegment()->GetNextSegment()->ResetCounters();
00129 }
00130
00131
00132
00133 void MJWaveformPlanarDetector::Construct()
00134 {
00135
00136 fPlanarCrystal1 = new MJWaveformPlanarCrystal;
00137 fPlanarCrystal2 = new MJWaveformPlanarCrystal;
00138 fPlanarCrystal1->Construct();
00139 fPlanarCrystal2->Construct();
00140 AddCrystal(fPlanarCrystal1);
00141 AddCrystal(fPlanarCrystal2);
00142
00143
00144 fData = new TreeStructure;
00145 fRootFile = new TFile("crap.root", "RECREATE");
00146 fRootTree = new TTree("fTree", "A Tree, A Beautiful Tree");
00147 fRootTree->Branch("Time", fData->Time, "Time[500]/F");
00148 fRootTree->Branch("Current", fData->Current, "Current[2][500]/F");
00149 fRootTree->Branch("Charge", fData->Charge, "Charge[2][500]/F");
00150 fRootTree->Branch("InitialPosition", fData->InitialPosition,
00151 "InitialPosition[10][3]/F");
00152 fRootTree->Branch("InitialCharge", fData->InitialCharge,
00153 "InitialCharge[10]/F");
00154 fRootTree->Branch("NumberOfPoints", &fData->NumberOfPoints,
00155 "NumberOfPoints/I");
00156 }
00157
00158
00159
00160 void MJWaveformPlanarDetector::EndOfEventAction()
00161 {
00162 GenerateSignals();
00163 MJVWaveformSegment *seg1 = fPlanarCrystal1->GetFirstSegment();
00164 MJVWaveformSegment *seg2 = seg1->GetNextSegment();
00165 HepDouble timestep = fPlanarCrystal1->GetTimeStep();
00166 HepDouble *curr1 = seg1->GetCurrentSignal();
00167 HepDouble *chrg1 = seg1->GetChargeSignal();
00168 HepDouble *curr2 = seg2->GetCurrentSignal();
00169 HepDouble *chrg2 = seg2->GetChargeSignal();
00170 HepInt np = fData->NumberOfPoints = seg1->GetChargeStep();
00171 for(HepInt i = 0; i < np; i++) {
00172 fData->Time[i] = CLHEPtoROOT(timestep * i / ns);
00173 fData->Current[0][i] = CLHEPtoROOT(curr1[i] / microampere);
00174 fData->Current[1][i] = CLHEPtoROOT(curr2[i] / microampere);
00175 fData->Charge[0][i] = CLHEPtoROOT(chrg1[i] / eplus);
00176 fData->Charge[1][i] = CLHEPtoROOT(chrg2[i] / eplus);
00177 }
00178 fRootTree->Fill();
00179 }
00180
00181
00182
00183 void MJWaveformPlanarDetector::EndOfRunAction()
00184 {
00185 fRootTree->Write();
00186 fRootFile->Write();
00187 fRootFile->Close();
00188 fRootFile->Delete();
00189 }
00190
00191
00192