Changeset 7188 for trunk/MagicSoft/Mars/macros
- Timestamp:
- 07/13/05 19:06:26 (19 years ago)
- Location:
- trunk/MagicSoft/Mars/macros
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/macros/starmc.C
r7005 r7188 52 52 // differences in gain of outer pixels) 53 53 // 54 CalibrationFilename = new TString(" /data1/magic/mc_data/root/Period025/gammas_nonoise/Gamma_zbin0_*.root");54 CalibrationFilename = new TString("nonoise/Gamma_zbin0_0_7_1000to1009_w0.root"); 55 55 // File to be used in the calibration (must be a camera file without added noise) 56 56 57 58 Char_t* AnalysisFilename = "Gamma_zbin1_0_*.root"; // File to be analyzed 59 57 Char_t* AnalysisFilename = "Gamma_zbin0_0_*.root"; // File to be analyzed 60 58 61 59 … … 76 74 // USER CHANGE: tail cuts for image analysis 77 75 78 Float_t CleanLev[2] = {7., 5.}; 79 MImgCleanStd clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image. 80 clean.SetMethod(MImgCleanStd::kAbsolute); // In absolute units (phot or phe- as chosen below) 81 76 Float_t CleanLev[2] = {10., 5.}; // Tail cuts for the analysis loop 77 MImgCleanStd clean2(CleanLev[0], CleanLev[1]); // Applies tail cuts to image. 78 clean2.SetMethod(MImgCleanStd::kAbsolute); 82 79 83 80 // USER CHANGE: signal extraction 84 //85 // MExtractFixedWindowPeakSearch sigextract;86 // sigextract.SetWindows(6, 6, 4);87 81 88 82 // MExtractTimeAndChargeDigitalFilter sigextract; … … 91 85 92 86 MExtractTimeAndChargeSpline sigextract; 87 sigextract.SetChargeType(MExtractTimeAndChargeSpline::kIntegral); 93 88 sigextract.SetRiseTimeHiGain(0.5); 94 89 sigextract.SetFallTimeHiGain(0.5); … … 96 91 // USER CHANGE: high to low gain ratio. DEPENDS on EXTRACTOR!! 97 92 // One should calculate somewhere else what this factor is for each extractor! 98 Float_t hi2low = 12.; // tentative value for spline with risetime 0.5, fall time 0.5 93 94 // Float_t hi2low = 10.83; 95 // value for digital filter, HG window 4, LG window 6 96 97 Float_t hi2low = 11.28; 98 // value for spline with risetime 0.5, fall time 0.5, low gain stretch 1.5 99 99 100 100 … … 108 108 109 109 110 MImgCleanStd clean(0.,0.); 111 // All pixels containing any photon will be accepted. This is what we want 112 // for the calibration loop (since no noise is added) 113 clean.SetMethod(MImgCleanStd::kAbsolute); 114 // In absolute units (phot or phe- as chosen below) 115 110 116 MSrcPosCam src; 111 117 // 112 // ONLY FOR WOBBLE MODE!! 113 // src.SetX(120.); // units: mm 118 // ONLY FOR WOBBLE MODE!! : set the rigt source position on camera! 119 // src.SetX(120.); // units: mm. Value for MC w+ files 120 // src.SetX(-120.); // units: mm. Value for MC w- files 114 121 115 122 src.SetReadyToSave(); … … 244 251 // 245 252 253 246 254 MProgressBar bar; 247 255 bar.SetWindowName("Calibrating..."); … … 273 281 tlist.RemoveFromList(&read); 274 282 283 tlist.AddToListBefore(&clean2, &clean); 284 tlist.RemoveFromList(&clean); 285 275 286 // 276 287 // Analyzed only the desired fraction of events, skip the rest: -
trunk/MagicSoft/Mars/macros/starmcstereo.C
r3439 r7188 17 17 ! 18 18 ! Author(s): Abelardo Moralejo 1/2004 <mailto:moralejo@pd.infn.it> 19 ! Thomas Bretz, 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>20 19 ! 21 20 ! Copyright: MAGIC Software Development, 2000-2004 … … 33 32 ///////////////////////////////////////////////////////////////////////////// 34 33 35 // 36 // User change. 37 // 38 39 Float_t ctx[7] = {0., 0., 0., 0., 0., 0., 0.}; 40 Float_t cty[7] = {-70., -40., -30., 30., 50., 60., 70.}; // in meters 41 // 42 // FIXME: unfortunately present version of reflector was not prepared for 43 // stereo configurations and keeps no track of CT position. So the positions 44 // must be set above by the user, making sure that they correspond to the 45 // files one is analysing. 46 // 47 48 void starmcstereo(Int_t ct1 = 2, Int_t ct2 = 5) 34 void starmcstereo(Int_t ct1 = 1, Int_t ct2 = 2) 49 35 { 50 if (ct1 > sizeof(ctx)/sizeof(ctx[0]) || 51 ct2 > sizeof(ctx)/sizeof(ctx[0]) ) 52 { 53 cout << endl << "Wrong CT id number!" << endl; 36 // ------------- user change ----------------- 37 38 TString* CalibrationFilename = 0; 39 40 // Calibration file: a file with no added noise. Comment out next line if you 41 // do not want to calibrate the data (means SIZE will be in ADC counts) 42 43 CalibrationFilename = new TString("nonoise/Gamma_20_0_7_200000to200009_XX_w0.root"); 44 45 Char_t* AnalysisFilename = "Gamma_20_0_7_*_XX_w0.root"; // File to be analyzed 46 Char_t* OutFileTag = "gammas"; // Output file tag 47 48 // First open input files to check that the required telescopes 49 // are in the file, and get telescope coordinates. 50 51 TChain *rh = new TChain("RunHeaders"); 52 rh->Add(AnalysisFilename); 53 MMcCorsikaRunHeader *corsrh = new MMcCorsikaRunHeader(); 54 rh->SetBranchAddress("MMcCorsikaRunHeader.", &corsrh); 55 rh->GetEvent(0); 56 // We assume that all the read files will have the same telescopes inside, 57 // so we look only into the first runheader. 58 Int_t allcts = corsrh->GetNumCT(); 59 if (ct1 > allcts || ct2 > allcts) 60 { 61 cout << endl << "Wrong CT id number, not contained in input file!" << endl; 54 62 return; 55 63 } 64 // Set telescope coordinates as read from first runheader: 65 Float_t ctx[2]; 66 Float_t cty[2]; 67 ctx[0] = ((*corsrh)[ct1-1])->GetCTx(); 68 cty[0] = ((*corsrh)[ct1-1])->GetCTy(); 69 ctx[1] = ((*corsrh)[ct2-1])->GetCTx(); 70 cty[1] = ((*corsrh)[ct2-1])->GetCTy(); 71 72 // Now find out number of pixels in each camera: 73 MMcConfigRunHeader* confrh1 = new MMcConfigRunHeader(); 74 MMcConfigRunHeader* confrh2 = new MMcConfigRunHeader(); 75 rh->SetBranchAddress("MMcConfigRunHeader;1.", &confrh1); 76 rh->SetBranchAddress("MMcConfigRunHeader;2.", &confrh2); 77 rh->GetEvent(0); 78 Int_t npix[2]; 79 npix[0] = confrh1->GetNumPMTs(); 80 npix[1] = confrh2->GetNumPMTs(); 81 82 rh->Delete(); 83 56 84 57 85 Int_t CT[2] = {ct1, ct2}; // Only 2-telescope analysis for the moment 58 Int_t NCTs = sizeof(CT)/sizeof(CT[0]);86 Int_t NCTs = 2; 59 87 60 88 61 89 // ------------- user change ----------------- 62 90 63 Char_t* AnalysisFilename = "gam-yXX-00001.root"; // File to be analyzed 64 Char_t* OutFileTag = "gammas"; // Output file tag 65 66 Float_t CleanLev[2] = {4., 3.}; // Tail cuts for image analysis 67 68 Int_t BinsHigh[2] = {5, 9}; // First and last FADC bin of the range to be integrated, 69 Int_t BinsLow[2] = {5, 9}; // for high and low gain respectively. 91 Float_t BinsHigh[2] = {0, 79}; 92 Float_t BinsLow[2] = {0, 79}; // FADC slices (2GHz sampling) 93 Float_t CleanLev[2] = {7., 5.}; // Units: phes (absolute cleaning will be used later!) 94 // Tail cuts for the analysis loop. In the first (calibration) loop they will not 95 // be used; we run over a noiseless file and we want to accept all pixels with any 96 // number of phes. 97 98 99 MImgCleanStd** clean = new MImgCleanStd*[NCTs]; 100 101 MImgCleanStd* clean[0] = new MImgCleanStd(1.,1.); 102 MImgCleanStd* clean[1] = new MImgCleanStd(1.,1.); 103 // Just dummy levels. Since the calibration file will be a noiseless file, RMS of 104 // pedestal will be 0, and all events will be accepted, regardless of the cleaning level. 105 // For some reason the above lines do not work if made on a loop! (???) 106 clean[0]->SetSerialNumber(CT[0]); 107 clean[1]->SetSerialNumber(CT[1]); 108 109 MExtractTimeAndChargeSpline* sigextract = new MExtractTimeAndChargeSpline[NCTs]; 110 MMcCalibrationUpdate* mccalibupdate = new MMcCalibrationUpdate[NCTs]; 111 MCalibrateData* calib = new MCalibrateData[NCTs]; 112 MMcCalibrationCalc* mccalibcalc = new MMcCalibrationCalc[NCTs]; 70 113 71 114 // ------------------------------------------- 72 73 //74 // This is a demonstration program which calculates the image75 // parameters from a Magic Monte Carlo root file. Units of Size are76 // for the moment, FADC counts.77 //78 //79 115 // Create a empty Parameter List and an empty Task List 80 116 // The tasklist is identified in the eventloop by its name 81 117 // 82 118 MParList plist; 83 84 119 MTaskList tlist; 85 86 120 plist.AddToList(&tlist); 87 121 … … 89 123 MBadPixelsCam badpix[NCTs]; 90 124 91 for (Int_t ict = 0; ict < NCTs; ict++) 125 Float_t hi2lowratio = 10.0; 126 127 for (Int_t i = 0; i < NCTs; i++) 92 128 { 93 129 TString s = "MSrcPosCam;"; 94 s += CT[i ct];95 src[i ct].SetName(s);96 src[i ct].SetReadyToSave();97 plist.AddToList(&(src[i ct]));130 s += CT[i]; 131 src[i].SetName(s); 132 src[i].SetReadyToSave(); 133 plist.AddToList(&(src[i])); 98 134 99 135 TString b = "MBadPixelsCam;"; 100 b += CT[ict]; 101 badpix[ict].SetName(b); 102 badpix[ict].SetReadyToSave(); 103 plist.AddToList(&(badpix[ict])); 104 } 136 b += CT[i]; 137 badpix[i].SetName(b); 138 badpix[i].InitSize(npix[i]); 139 badpix[i].SetReadyToSave(); 140 plist.AddToList(&(badpix[i])); 141 142 sigextract[i].SetSerialNumber(CT[i]); 143 sigextract[i].SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]); 144 sigextract[i].SetRiseTimeHiGain(0.5); 145 sigextract[i].SetFallTimeHiGain(0.5); 146 sigextract[i].SetLoGainStretch(1.); 147 148 mccalibupdate[i].SetSerialNumber(CT[i]); 149 mccalibupdate[i].SetUserLow2HiGainFactor(hi2lowratio); 150 mccalibupdate[i].SetSignalType(MCalibrateData::kPhe); 151 152 calib[i].SetSerialNumber(CT[i]); 153 calib[i].SetCalibConvMinLimit(0.); 154 calib[i].SetCalibConvMaxLimit(100.); // Override limits for real data 155 calib[i].SetCalibrationMode(MCalibrateData::kFfactor); 156 // Do not change CalibrationMode (just indicates where the cal. constants will be stored) 157 calib[i].SetSignalType(mccalibupdate[i].GetSignalType()); 158 159 mccalibcalc[i].SetSerialNumber(CT[i]); 160 mccalibcalc[i].SetMinSize(200); 161 // Minimum SIZE for an event to be used in the calculation of calibration constants. 162 // Units are ADC counts, and value depends on signal extractor! 163 } 164 165 105 166 // 106 167 // Now setup the tasks and tasklist: … … 110 171 read.DisableAutoScheme(); 111 172 112 read.AddFile(AnalysisFilename); 173 if (CalibrationFilename) 174 read.AddFile(CalibrationFilename->Data()); 175 113 176 114 177 MGeomApply* apply = new MGeomApply[NCTs]; 115 116 178 MMcPedestalCopy* pcopy = new MMcPedestalCopy[NCTs]; 117 118 MExtractSignal* sigextract = new MExtractSignal[NCTs];119 120 MMcCalibrationUpdate* mccalibupdate = new MMcCalibrationUpdate[NCTs];121 MCalibrate* calib = new MCalibrate[NCTs];122 123 MImgCleanStd** clean = new MImgCleanStd*[NCTs];124 125 179 MHillasCalc* hcalc = new MHillasCalc[NCTs]; 126 MHillasSrcCalc* scalc = new MHillasSrcCalc[NCTs];127 180 128 181 TString outfile = "star_"; 129 182 outfile += CT[0]; 130 if (NCTs==2) 131 { 132 outfile += "_"; 133 outfile += CT[1]; 134 } 183 outfile += "_"; 184 outfile += CT[1]; 135 185 136 186 // … … 144 194 outfile = "star_"; 145 195 outfile += CT[0]; 146 if (NCTs==2) 147 { 148 outfile += "_"; 149 outfile += CT[1]; 150 } 196 outfile += "_"; 197 outfile += CT[1]; 151 198 152 199 outfile += "_"; … … 159 206 { 160 207 apply[i]->SetSerialNumber(CT[i]); 161 162 208 pcopy[i]->SetSerialNumber(CT[i]); 163 209 164 sigextract[i]->SetSerialNumber(CT[i]);165 sigextract[i].SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]);166 167 mccalibupdate[i]->SetSerialNumber(CT[i]);168 calib[i]->SetSerialNumber(CT[i]);169 170 clean[i] = new MImgCleanStd(CleanLev[0], CleanLev[1]);171 clean[i]->SetSerialNumber(CT[i]);172 173 210 hcalc[i]->SetSerialNumber(CT[i]); 174 scalc[i]->SetSerialNumber(CT[i]); 211 hcalc[i].Disable(MHillasCalc::kCalcHillasSrc); 212 // Source-dependent parameters not needed in the first loop (calibration) 175 213 176 214 write1.SetSerialNumber(CT[i]); 177 215 write2.SetSerialNumber(CT[i]); 178 216 179 write1.AddContainer(write1.AddSerialNumber("MMcEvt"), "Events"); 180 write1.AddContainer(write1.AddSerialNumber("MHillas"), "Events"); 181 write1.AddContainer(write1.AddSerialNumber("MHillasExt"), "Events"); 182 write1.AddContainer(write1.AddSerialNumber("MHillasSrc"), "Events"); 183 write1.AddContainer(write1.AddSerialNumber("MNewImagePar"), "Events"); 184 write1.AddContainer(write1.AddSerialNumber("MSrcPosCam"), "RunHeaders"); 185 write2.AddContainer(write2.AddSerialNumber("MMcEvt"), "Events"); 186 write2.AddContainer(write2.AddSerialNumber("MHillas"), "Events"); 187 write2.AddContainer(write2.AddSerialNumber("MHillasExt"), "Events"); 188 write2.AddContainer(write2.AddSerialNumber("MHillasSrc"), "Events"); 189 write2.AddContainer(write2.AddSerialNumber("MNewImagePar"), "Events"); 190 write2.AddContainer(write2.AddSerialNumber("MSrcPosCam"), "RunHeaders"); 191 } 192 193 if (NCTs==2) 194 { 195 write1.AddContainer("MStereoPar", "Events"); 196 write2.AddContainer("MStereoPar", "Events"); 197 } 217 write1.AddContainer("MMcEvt", "Events"); 218 write1.AddContainer("MHillas", "Events"); 219 write1.AddContainer("MHillasExt", "Events"); 220 write1.AddContainer("MHillasSrc", "Events"); 221 write1.AddContainer("MNewImagePar", "Events"); 222 write1.AddContainer("MSrcPosCam", "Events"); 223 write2.AddContainer("MMcEvt", "Events"); 224 write2.AddContainer("MHillas", "Events"); 225 write2.AddContainer("MHillasExt", "Events"); 226 write2.AddContainer("MHillasSrc", "Events"); 227 write2.AddContainer("MNewImagePar", "Events"); 228 write2.AddContainer("MSrcPosCam", "Events"); 229 } 230 231 MStereoPar* mstereo = new MStereoPar; 232 plist.AddToList(mstereo); 233 234 write1.AddContainer(mstereo, "Events"); 235 write2.AddContainer(mstereo, "Events"); 236 // We use MWriteRootFile::AddContainer(MParContainer* ,...) instead 237 // of using the container name as above, because in the former case the 238 // serial number tag (indicating the telescope id) is added to the 239 // container name, which is fine for containers of which there is one 240 // per telescope. However, the container MStereoPar is unique, since it 241 // is filled with information coming from both telescopes. 198 242 199 243 write1.AddContainer("MRawRunHeader", "RunHeaders"); … … 204 248 205 249 tlist.AddToList(&read); 250 251 // Skip untriggered events (now camera simulation output contains by default all simulated events) 252 MContinue* trigger = new MContinue("(MMcTrig;1.fNumFirstLevel<1) && (MMcTrig;2.fNumFirstLevel<1)","Events"); 253 tlist.AddToList(trigger); 206 254 207 255 for (i = 0; i < NCTs; i++) … … 214 262 tlist.AddToList(clean[i]); 215 263 tlist.AddToList(&(hcalc[i])); 216 tlist.AddToList(&(scalc[i])); 217 } 218 264 tlist.AddToList(&(mccalibcalc[i])); 265 } 266 267 268 MF filter1("{MMcEvt;1.fEvtNumber%2}<0.5"); 269 MF filter2("{MMcEvt;1.fEvtNumber%2}>0.5"); 270 // 271 // ^^^^ Filters to divide output in two: test and train samples. 272 // 273 write1.SetFilter (&filter1); 274 write2.SetFilter (&filter2); 275 276 // 277 // Create and set up the eventloop 278 // 279 MProgressBar bar; 280 bar.SetWindowName("Calibrating"); 281 282 MEvtLoop evtloop; 283 evtloop.SetProgressBar(&bar); 284 evtloop.SetParList(&plist); 285 286 // 287 // First loop: calibration loop. Go over MC events simulated with 288 // no noise, to correlate SIZE with the number of phes and get the 289 // conversion factor (this is done by MMcCalibrationCalc). 290 // 291 if (CalibrationFilename) 292 { 293 if (!evtloop.Eventloop()) 294 return; 295 } 296 297 tlist.PrintStatistics(); 298 299 /////////////////////////////////////////////////////////////////////// 300 301 302 // Now prepare the second loop: go over the events you want to analyze. 303 // This time the MMcCalibrationUpdate tasks will apply the previously 304 // calculated calibration factors. 305 306 // First substitute the reading task: 307 MReadMarsFile read2("Events"); 308 read2.AddFile(AnalysisFilename); 309 read2.DisableAutoScheme(); 310 tlist.AddToListBefore(&read2, &read); 311 tlist.RemoveFromList(&read); 312 313 // Delete cleaning tasks and create new ones with absolute cleaning method: 314 for (Int_t i= 0; i < NCTs; i++ ) 315 { 316 tlist.RemoveFromList(clean[i]); 317 delete clean[i]; 318 } 319 320 // New cleaning tasks: 321 clean[0] = new MImgCleanStd(CleanLev[0], CleanLev[1]); 322 clean[1] = new MImgCleanStd(CleanLev[0], CleanLev[1]); 323 clean[0]->SetMethod(MImgCleanStd::kAbsolute); 324 clean[1]->SetMethod(MImgCleanStd::kAbsolute); 325 clean[0]->SetSerialNumber(CT[0]); 326 clean[1]->SetSerialNumber(CT[1]); 327 tlist.AddToListBefore(clean[0],&(hcalc[0])); 328 tlist.AddToListBefore(clean[1],&(hcalc[1])); 329 330 tlist.RemoveFromList(&(mccalibcalc[0])); 331 tlist.RemoveFromList(&(mccalibcalc[1])); // Remove calibration tasks from list. 332 333 // Now calculate also source-dependent Hillas parameters: 334 for (i = 0; i < NCTs; i++) 335 hcalc[i].Enable(MHillasCalc::kCalcHillasSrc); 336 337 // Add task to calculate stereo parameters: 219 338 MStereoCalc stereocalc; 220 339 stereocalc.SetCTids(CT[0],CT[1]); 221 222 // 223 // FIXME: telescope coordinates must be introduced by the user, since 224 // they are not available nor in the camera file, neither in the reflector 225 // output. 226 // 227 228 stereocalc.SetCT1coor(ctx[CT[0]-1],cty[CT[0]-1]); 229 stereocalc.SetCT2coor(ctx[CT[1]-1],cty[CT[1]-1]); 230 340 stereocalc.SetCT1coor(ctx[0],cty[0]); 341 stereocalc.SetCT2coor(ctx[1],cty[1]); 231 342 tlist.AddToList(&stereocalc); 232 343 233 234 MF filter1("{MMcEvt;1.fEvtNumber%2}<0.5"); 235 MF filter2("{MMcEvt;1.fEvtNumber%2}>0.5"); 236 // 237 // ^^^^ Filters to divide output in two: test and train samples. 238 // 239 240 write1.SetFilter (&filter1); 241 write2.SetFilter (&filter2); 242 344 // Add writing tasks: 243 345 tlist.AddToList(&filter1); 244 346 tlist.AddToList(&write1); … … 246 348 tlist.AddToList(&write2); 247 349 248 // 249 // Create and set up the eventloop 250 // 251 MProgressBar bar; 252 253 MEvtLoop evtloop; 254 evtloop.SetProgressBar(&bar); 255 evtloop.SetParList(&plist); 256 257 // 258 // Execute your analysis 259 // 350 bar.SetWindowName("Analyzing"); 351 260 352 if (!evtloop.Eventloop()) 261 353 return; 262 354 355 tlist.PrintStatistics(); 356 263 357 for (Int_t i= 0; i < NCTs; i++ ) 264 358 delete clean[i]; 265 359 266 tlist.PrintStatistics(); 360 plist.FindObject("MCalibrationChargeCam;1")->Write(); 361 plist.FindObject("MCalibrationChargeCam;2")->Write(); 362 363 plist.FindObject("MCalibrationQECam;1")->Write(); 364 plist.FindObject("MCalibrationQECam;2")->Write(); 365 366 return; 267 367 }
Note:
See TracChangeset
for help on using the changeset viewer.