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