source: trunk/MagicSoft/Simulation/Detector/StarResponse/starresponse.cxx@ 5254

Last change on this file since 5254 was 5254, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 4.6 KB
Line 
1#include "starresponse.hxx"
2
3#include <TROOT.h>
4#include <TRandom2.h>
5
6#include "MStarLight.hxx"
7#include "MTrigger.hxx"
8#include "MFadc.hxx"
9
10using namespace std;
11
12Int_t BuildStarLight( Float_t brightness, char *path, MTrigger *trigger, MFadc *fadc )
13{
14 // this functions fills the things with the standard response
15 // function of MTrigger and MFadc
16 //
17
18 cout << " filling Starlight for Brightness " << brightness
19 << " phe/nsec " << endl ;
20
21 char filename[256] ;
22
23 TRandom2 Zufall( (UInt_t) brightness * 100) ; // a random generator
24
25 MStarLight data(fadc->GetFadcSlicesPerNanosec(), fadc->GetResponseSlicesFadc());
26 // create instance of the MStarLight
27
28 // Shall I write the root file???
29
30 int write_root;
31
32 write_root= get_write_root();
33
34 Float_t trigresp[RESPONSE_SLICES_TRIG];
35
36 // Get information from Trigger instance!!!
37 trigger->GetResponse(trigresp);
38 data.SetTrigResponse(trigresp);
39
40 data.SetAmplTrig ( trigger->GetAmplitude() );
41 data.SetFwhmTrig ( trigger->GetFwhm() );
42
43 Float_t *fadcresp = new Float_t[fadc->GetResponseSlicesFadc()];
44
45 // Get information from FADC instance !!!!!
46 fadc->GetResponse(fadcresp);
47 data.SetFadcResponse(fadcresp);
48
49 data.SetShapeFadc ( fadc->GetShape() );
50 data.SetIntegFadc ( fadc->GetIntegral() );
51 data.SetFwhmFadc ( fadc->GetFwhm() );
52
53 // start with the loop over random events
54 //
55
56 Float_t a = 0.; // the amplitude of the signal
57 Float_t time = 0.; // the time of the phe
58
59 for (Int_t i = 0; i < (Int_t) (brightness * TIMERANGE) ; i++)
60 {
61 a = trigger->FillStar( 500, 10.) ; // random the amplitude
62 time=Zufall.Rndm() * TIMERANGE ; // random the time
63
64 data.FillResponse(a, time ) ; // fill the response function
65 }
66
67 if(brightness<=1.0)
68 sprintf(filename, "%s/Brightness%.2f.slt", path, brightness) ;
69 else
70 sprintf(filename, "%s/Brightness%.1f.slt", path, brightness) ;
71
72 data.WriteBinary( filename );
73
74 if(write_root)
75 {
76 if(brightness<=1.0)
77 sprintf(filename, "%s/Brightness%.2f.root", path, brightness);
78 else
79 sprintf(filename, "%s/Brightness%.1f.root", path, brightness);
80
81 cout << " the file will be written in " << filename << endl;
82
83 data.StoreHisto( filename );
84 }
85
86 data.Reset();
87
88 return(0);
89
90}
91// ======================================================================
92// ======================================================================
93// ======================================================================
94// ======================================================================
95// ======================================================================
96// ======================================================================
97int main (int argc, char **argv )
98{
99 cout << " Start with the StarResponse " << endl ;
100
101 // first of all initalize ROOT
102
103 TROOT starrespo("starrespo", "The response of MAGIC to Starlight");
104
105 // Variables that define the StarLight which is going to be generated.
106
107 float nphe_min=0.0, nphe_max=10.0, nphe_pre=0.1;
108
109 float trig_fwhm,trig_ampl;
110 float fadc_fwhm,fadc_integral;
111 float fadc_slices_per_ns;
112 Int_t fadc_shape, trig_shape;
113
114 //
115 char path[256] ;
116 char parfilename[256];
117 sprintf (path, "./") ;
118
119 // Instance of MFadc and MTrigger needed inside BuildStarLight
120
121 MTrigger *trigger;
122 MFadc *fadc;
123
124 if(argc == 1){
125 sprintf(parfilename, "starresponse.par");
126 }
127 else{ // a filename was given
128 sprintf(parfilename, "%s", argv[1]);
129 }
130
131 // Reading parameters from input card
132
133 readparam(parfilename);
134
135 // Setting the parameters read from teh input card
136 strcpy( path,get_database_path());
137
138 get_simulated_phe(&nphe_min, &nphe_max, &nphe_pre);
139
140 get_trig_properties(&trig_shape, &trig_ampl, &trig_fwhm);
141 trigger = new MTrigger(1,0.,0.,trig_ampl,trig_fwhm);
142
143 get_fadc_properties(&fadc_shape, &fadc_integral, &fadc_fwhm, &fadc_slices_per_ns);
144
145 fadc = new MFadc(1, fadc_shape, fadc_integral, fadc_fwhm,
146 fadc_shape, fadc_integral, fadc_fwhm, 0., fadc_slices_per_ns);
147
148 // loop over Brightness
149
150 // Limit precision (for speed reasons). Below 1 phe/ns/pixel we build the database
151 // files in steps of 0.01 (minimum). Above 1 phe/ns/pixel the steps are of 0.1 at least.
152 // These values can be made larger through the input card of starresponse
153
154 nphe_pre = nphe_pre < 0.01? 0.01 : nphe_pre;
155 for (Float_t b = nphe_min; b <= 1.0; b += nphe_pre )
156 BuildStarLight (b, path, trigger, fadc);
157
158 nphe_pre = nphe_pre < 0.1? 0.1 : nphe_pre;
159 for (Float_t b = 1.0+nphe_pre; b <= nphe_max; b += nphe_pre )
160 BuildStarLight (b, path, trigger, fadc);
161
162 delete(trigger);
163 delete(fadc);
164
165 return 0;
166}
167
Note: See TracBrowser for help on using the repository browser.