source: fact/tools/pyscripts/callisto2.py@ 13409

Last change on this file since 13409 was 12717, checked in by lusterma, 13 years ago
added callisto2.py, run2.py and runlist_20111124.txt as example on how to run a MARS script on a list of files
File size: 4.3 KB
Line 
1#!/usr/bin/python
2#
3'''
4function callisto
5produce and save calibrated FACT data
6'''
7from ROOT import *
8
9# get the MARS library loaded
10gSystem.Load( '/data02/scratch/Mars_20111207_2145_from_data/libmars.so' )
11from ROOT import *
12
13def callisto( drsfile, datafile, mapfile, plotfile = '~/res/t-callisto.root'):
14 """
15 write calibrated data files
16 """
17 if mapfile == '':
18 map = NULL
19 else:
20 usemap = True
21 map = mapfile
22
23 # signal extraction parameter
24 # Extraction range in slices. It will always(!) contain the full range of integration
25 first_slice, last_slice = 30, 250 # 15ns
26 # Integral range left and right of the maximum in slices
27 rise_time, fall_time = 13, 23
28
29 type = MExtralgoSpline.kIntegralRel
30
31 # Data files to be processed
32 read5 = MRawFitsRead()
33 read5.LoadMap( map )
34 read5.AddFile( datafile )
35
36 # create a display instance
37 d = MStatusDisplay()
38
39 loop = MEvtLoop() # create an eventloop instance
40 loop.SetDisplay( d ) #
41
42 bad_pixel_list = [ 424, 583, 830, 923, 1208, 1388 ]
43 badpixels = MBadPixelsCam()
44 badpixels.InitSize(1440)
45 for pixel in bad_pixel_list:
46 badpixels[ pixel ].SetUnsuitable(MBadPixelsPix.kUnsuitable)
47
48 drscalib = MDrsCalibration()
49 if drscalib.ReadFits( drsfile ) != True :
50 print 'problems reading drsfile: ', drsfile
51 exit( -1 )
52
53 timecam = MCalibrationRelTimeCam()
54
55 tlist = MTaskList()
56 plist2 = MParList()
57
58 plist2.AddToList( tlist );
59 plist2.AddToList( drscalib );
60 plist2.AddToList( badpixels );
61 plist2.AddToList( timecam );
62
63 apply = MGeomApply()
64 drsapply = MDrsCalibApply()
65
66 cont = MContinue( 'MRawEvtHeader.GetTriggerID != 4' )
67
68 extractor = MExtractTimeAndChargeSpline()
69 extractor.SetRange( first_slice, last_slice )
70 extractor.SetRiseTimeHiGain( rise_time )
71 extractor.SetFallTimeHiGain( fall_time )
72 extractor.SetChargeType( type )
73 extractor.SetSaturationLimit(600000)
74 extractor.SetNoiseCalculation( kFALSE )
75
76 evtA1 = MHCamEvent(0, "Extra'd", "Extracted Calibration Signal;;S [cnts/sl]")
77 evtA2 = MHCamEvent(4, "ArrTm", "Extracted ArrivalTime;;T")
78
79 fillA1 = MFillH(evtA1, "MExtractedSignalCam", "FillExtractedSignal")
80 fillA2 = MFillH(evtA2, "MArrivalTimeCam", "FillArrivalTime")
81
82 # Use this for data, but not for calibration events
83 evtA1.SetErrorSpread( kFALSE )
84
85 conv = MCalibrateData()
86 conv.SetCalibrationMode( MCalibrateData.kNone )
87 conv.SetPedestalFlag( MCalibrateData.kNo )
88
89 calctm = MCalibrateRelTimes()
90
91 treat = MBadPixelsTreat()
92 treat.SetProcessPedestalRun( kFALSE )
93 treat.SetProcessPedestalEvt( kFALSE )
94
95 evtB1 = MHCamEvent(0, "Interp'd","Interpolated Signal scaled with A/A_{0};;S [phe]")
96 evtB1.SetErrorSpread( kFALSE )
97
98 fillB1 = MFillH(evtB1, "MSignalCam", "FillInterpolated")
99
100 # fname = TString( Form('s/([0-9]+_[0-9]+)[.]fits([.]gz)?$/%s\\/$1_C.root/', outpath ) )
101 # fname = TString()
102 fname = "s/([0-9]+_[0-9]+)[.]fits([.]gz)?$/.\\/$1_C.root/"
103 # print 'fname: ', fname
104
105
106 # The second rule is for the case reading raw-files!
107 write = MWriteRootFile(2, fname, "NEW", "Calibrated Data")
108 write.AddContainer("MRawRunHeader", "RunHeaders")
109 write.AddContainer("MGeomCam", "RunHeaders")
110 write.AddContainer("MSignalCam", "Events")
111 write.AddContainer("MTime", "Events")
112 write.AddContainer("MRawEvtHeader", "Events")
113 # write.AddContainer("MTriggerPattern", "Events")
114
115 # ------------------ Setup histograms and fill tasks ----------------
116
117 tlist.AddToList( read5 )
118 tlist.AddToList( cont )
119 tlist.AddToList( apply )
120 tlist.AddToList( drsapply )
121 tlist.AddToList( extractor )
122 tlist.AddToList( fillA1 )
123 tlist.AddToList( fillA2 )
124 tlist.AddToList( conv )
125 tlist.AddToList( calctm )
126 tlist.AddToList( treat )
127 tlist.AddToList( fillB1 )
128 tlist.AddToList( write )
129
130 loop.SetParList( plist2 )
131 # if ( loop.Eventloop() ): exit( -1 )
132 # if ( loop.GetDisplay() ): exit( -1 )
133 print 'loop.Eventloop(): ', loop.Eventloop()
134 print 'loop.GetDisplay(): ', loop.GetDisplay()
135
136 title = '-- Calibrate Signal: ' + drsfile + ' --'
137 d.SetTitle( title, kFALSE);
138
139 # TString path;
140 # path += Form("%s%s-callisto.root", outpath, TString(TString(strrchr(drsfile, '/'))(0, 13)).Data());
141
142 d.SaveAs( plotfile )
143
Note: See TracBrowser for help on using the repository browser.