source: trunk/examples/advanced/Tiara/source/tiara/src/TiaraDPSSampledEnergy.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 5.6 KB
RevLine 
[807]1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// $Id: TiaraDPSSampledEnergy.cc,v 1.9 2006/06/29 15:44:48 gunter Exp $
27// GEANT4 tag $Name: $
28//
29
30#include "TiaraDPSSampledEnergy.hh"
31
32#ifdef G4ANALYSIS_USE
33
34#include "Randomize.hh"
35#include "TiaraFileAcess.hh"
36
37
38#include "AIDA/AIDA.h"
39
40
41TiaraDPSSampledEnergy::TiaraDPSSampledEnergy(const G4String &eng,
42 G4double minEnergyCut,
43 const G4String &sourceTree,
44 const G4String &nameExt)
45 :
46 // fTree( (checkFileIsReadable(sourceTree, "TiaraDPSSampledEnergy::TiaraDPSSampledEnergy"),
47// AIDA_createAnalysisFactory()
48// ->createTreeFactory()
49// ->create(sourceTree, "xml",true,false)) ),
50 //fSampleDPS(dynamic_cast<AIDA::IDataPointSet *>(fTree->find(G4String("dps" + eng + nameExt)))),
51 fMinEnergyCut(minEnergyCut),
52 fMaxProb(0)
53 // fMinE(fSampleDPS->point(0)->coordinate(0)->value()),
54 //fMaxE(fSampleDPS->point(fSampleDPS->size()-1)->coordinate(0)->value())
55{
56 /////////////////////////////////////////
57
58 AIDA::IAnalysisFactory* aFact = AIDA_createAnalysisFactory();
59
60 AIDA::ITreeFactory *treeFact = aFact->createTreeFactory();
61
62 fTree = treeFact -> create(sourceTree, "xml",true,false);
63
64 AIDA::IManagedObject* object = fTree->find("dps" + eng + nameExt);
65 if(object) {
66 AIDA::IDataPointSet* sample = object->cast("AIDA::IDataPointSet");
67 fSampleDPS = sample;
68 }
69 fMinE = fSampleDPS->point(0)->coordinate(0)->value();
70 fMaxE = fSampleDPS->point(fSampleDPS->size()-1)->coordinate(0)->value();
71
72 /////////////////////////////////////////
73
74 for (G4int i=0; i < fSampleDPS->size(); i++) {
75 AIDA::IDataPoint *p = fSampleDPS->point(i);
76 G4double prob(p->coordinate(1)->value());
77 fEnergy_Flux[p->coordinate(0)->value() * 10] = prob;
78 if (prob > fMaxProb) {
79 fMaxProb = prob;
80 }
81 }
82 if (!(fMaxProb > 0)) {
83 G4Exception("TiaraDPSSampledEnergy::TiaraDPSSampledEnergy: fMaxProb <= 0!");
84 }
85}
86
87TiaraDPSSampledEnergy::TiaraDPSSampledEnergy(const TiaraDPSSampledEnergy& rhs)
88 : TiaraVSourceEnergyGenerator()
89{
90 *this = rhs;
91}
92
93TiaraDPSSampledEnergy& TiaraDPSSampledEnergy::
94operator=(const TiaraDPSSampledEnergy& rhs) {
95 if (this!=&rhs) {
96 TiaraDPSSampledEnergy &nonConstRhs = static_cast<TiaraDPSSampledEnergy &>(rhs);
97 fTree = nonConstRhs.fTree;
98 fSampleDPS = nonConstRhs.fSampleDPS;
99 fEnergy_Flux = nonConstRhs.fEnergy_Flux;
100 fMinEnergyCut = nonConstRhs.fMinEnergyCut;
101 fMaxProb = nonConstRhs.fMaxProb;
102 fMinE = nonConstRhs.fMinE;
103 fMaxE = nonConstRhs.fMaxE;
104 }
105 return *this;
106}
107
108TiaraDPSSampledEnergy::~TiaraDPSSampledEnergy(){
109}
110
111
112TiaraVSourceEnergyGenerator *TiaraDPSSampledEnergy::Clone() const {
113 return new TiaraDPSSampledEnergy(*this);
114}
115
116G4double TiaraDPSSampledEnergy::GetEnergy() {
117
118 G4double e(0.0);
119 while (!(e>fMinEnergyCut)) {
120 // a factor 10 is introduced to have an integer map
121 // for .5 values
122 G4double r(10 * (fMinE + G4UniformRand() * (fMaxE - fMinE) ));
123 G4int cLow(0);
124 G4int cHigh(0);
125 getBounds(cLow,cHigh,r);
126 G4double dx10(r-cLow); // a facto 10 enters
127
128 G4double fLow(fEnergy_Flux[cLow]);
129 G4double fHigh(fEnergy_Flux[cHigh]);
130
131 // if ( (!(fLow>0.0)) || (!(fHigh>0.0)) ) {
132 // G4cout << "TiaraDPSSampledEnergy::GetEnergy: WARNING: (!(fLow>0.0) || (!(fHigh>0.0) " << G4endl;
133 // G4cout << "r: " << r << G4endl;
134 // G4cout << "d: " << d << G4endl;
135 // G4cout << "cLow: " << cLow << G4endl;
136 // G4cout << "cHigh: " << cHigh << G4endl;
137 // }
138 // G4cout << "fLow: " << fLow << ", fHigh: " << fHigh << G4endl;
139
140 G4double dy(fHigh - fLow);
141 G4double m01(dy/(cHigh-cLow)); // a factor 1/10 enters
142 G4double p((fLow + m01*dx10)/fMaxProb);
143 // G4cout << "p: " << p << G4endl;
144 G4double discard(G4UniformRand());
145 // G4cout << "discard: " << discard << G4endl;
146 if (discard < p) {
147 e = r/10.;
148 break;
149 }
150 }
151 return e;
152}
153
154void TiaraDPSSampledEnergy::getBounds(G4int &cL, G4int &cH, G4double v) {
155 std::map<int, double>::iterator itH = fEnergy_Flux.upper_bound(v);
156 cH = itH->first;
157 std::map<int, double>::iterator itL = --itH;
158 cL = itL->first;
159}
160
161#endif
162
163
164
165
166
167
168
Note: See TracBrowser for help on using the repository browser.