Skip to content

Commit 2bb3ad7

Browse files
committed
Propagate camera option to core code, and gain scripts
1 parent e48302d commit 2bb3ad7

File tree

12 files changed

+99
-12
lines changed

12 files changed

+99
-12
lines changed

notebooks/tool_implementation/tuto_photostat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
progress_bar=True,
7575
run_number=FF_run_number,
7676
Ped_run_number=Ped_run_number,
77+
camera="NectarCAMQM",
7778
SPE_result=path[0],
7879
method="LocalPeakWindowSum",
7980
extractor_kwargs={"window_width": 12, "window_shift": 4},

src/nectarchain/data/management.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def findrun(
5353
"""
5454
basepath = f"{os.environ['NECTARCAMDATA']}/runs/"
5555
list = glob.glob(
56-
basepath + "**/*" + str(run_number) + "*.fits.fz", recursive=True
56+
basepath + "**/*" + str(run_number).zfill(4) + "*.fits.fz", recursive=True
5757
)
5858
list_path = [Path(chemin) for chemin in list]
5959
if len(list_path) == 0:
@@ -188,7 +188,7 @@ def __get_GRID_location_DIRAC(
188188
catalog = DCatalog()
189189
with redirect_stdout(sys.stdout):
190190
fccli = FileCatalogClientCLI(catalog.catalog)
191-
sys.stdout = StdoutRecord(keyword=f"Run{run_number}")
191+
sys.stdout = StdoutRecord(keyword=f"Run{str(run_number).zfill(4)}")
192192
fccli.do_find("-q " + basepath)
193193
lfns = sys.stdout.output
194194
sys.stdout = sys.__stdout__

src/nectarchain/makers/calibration/gain/photostat_makers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ def _load_eventsource(self, FF_run=True):
8282
if FF_run:
8383
self.log.debug("loading FF event source")
8484
self.event_source = self.enter_context(
85-
self.load_run(self.run_number, self.max_events)
85+
self.load_run(self.run_number, self.max_events, camera=self.camera)
8686
)
8787
else:
8888
self.log.debug("loading Ped event source")
8989
self.event_source = self.enter_context(
90-
self.load_run(self.Ped_run_number, self.max_events)
90+
self.load_run(self.Ped_run_number, self.max_events, camera=self.camera)
9191
)
9292

9393
def start(

src/nectarchain/makers/core.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
ComponentNameList,
1414
Integer,
1515
Path,
16+
TraitError,
17+
Unicode,
1618
classes_with_traits,
1719
flag,
1820
)
@@ -70,7 +72,10 @@ def _default_log_file(self):
7072

7173
@staticmethod
7274
def load_run(
73-
run_number: int, max_events: int = None, run_file: str = None
75+
run_number: int,
76+
max_events: int = None,
77+
run_file: str = None,
78+
camera: int = "NectarCAMQM",
7479
) -> LightNectarCAMEventSource:
7580
"""Static method to load from $NECTARCAMDATA directory data for specified run
7681
with max_events.
@@ -83,6 +88,8 @@ def load_run(
8388
max of events to be loaded. Defaults to -1, to load everything.
8489
run_file : optional
8590
if provided, will load this run file
91+
camera : str
92+
camera for which data are processed. (Default: NectarCAMQM)
8693
8794
Returns
8895
-------
@@ -91,7 +98,7 @@ def load_run(
9198
"""
9299
# Load the data from the run file.
93100
if run_file is None:
94-
generic_filename, _ = DataManagement.findrun(run_number)
101+
generic_filename, _ = DataManagement.findrun(run_number, camera=camera)
95102
log.info(f"{str(generic_filename)} will be loaded")
96103
eventsource = LightNectarCAMEventSource(
97104
input_url=generic_filename, max_events=max_events
@@ -110,6 +117,7 @@ class EventsLoopNectarCAMCalibrationTool(BaseNectarCAMCalibrationTool):
110117
111118
Args:
112119
run_number (int): The ID of the run to be processed.
120+
camera (str): The NectarCAM camera for which data should be processed.
113121
max_events (int, optional): The maximum number of events to be loaded.
114122
Defaults to None.
115123
run_file (optional): The specific run file to be loaded.
@@ -131,6 +139,7 @@ class EventsLoopNectarCAMCalibrationTool(BaseNectarCAMCalibrationTool):
131139
aliases = {
132140
("i", "input"): "EventsLoopNectarCAMCalibrationTool.run_file",
133141
("r", "run-number"): "EventsLoopNectarCAMCalibrationTool.run_number",
142+
("c", "camera"): "EventsLoopNectarCAMCalibrationTool.camera",
134143
("m", "max-events"): "EventsLoopNectarCAMCalibrationTool.max_events",
135144
("o", "output"): "EventsLoopNectarCAMCalibrationTool.output_path",
136145
"events-per-slice": "EventsLoopNectarCAMCalibrationTool.events_per_slice",
@@ -161,6 +170,13 @@ class EventsLoopNectarCAMCalibrationTool(BaseNectarCAMCalibrationTool):
161170
config=True
162171
)
163172

173+
camera = Unicode(
174+
help="camera for which the data will be processed",
175+
default_value="NectarCAMQM",
176+
allow_none=False,
177+
read_only=True,
178+
).tag(config=True)
179+
164180
output_path = Path(
165181
help="output filename",
166182
default_value=pathlib.Path(
@@ -218,6 +234,14 @@ def __new__(cls, *args, **kwargs):
218234

219235
def __init__(self, *args, **kwargs):
220236
super().__init__(*args, **kwargs)
237+
238+
prefix = "NectarCAM"
239+
cameras = [f"{prefix}" + "QM"]
240+
cameras.extend([f"{prefix + str(i)}" for i in range(2, 10)])
241+
242+
if self.camera not in cameras and self.run_file is None:
243+
raise TraitError(f"The camera field should be one of {cameras}.")
244+
221245
if not ("output_path" in kwargs.keys()):
222246
self._init_output_path()
223247

src/nectarchain/user_scripts/ggrolleron/gain_PhotoStat_computation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from nectarchain.makers.calibration import PhotoStatisticNectarCAMCalibrationTool
1212
from nectarchain.makers.extractor.utils import CtapipeExtractor
1313

14+
prefix = "NectarCAM"
15+
cameras = [f"{prefix}" + "QM"]
16+
cameras.extend([f"{prefix + str(i)}" for i in range(2, 10)])
17+
1418
parser = argparse.ArgumentParser(
1519
prog="gain_SPEfit_computation.py",
1620
description=f"compute high and low gain with the Photo-statistic\
@@ -24,6 +28,16 @@
2428
"--Ped_run_number", nargs="+", default=[], help="run(s) list", type=int
2529
)
2630

31+
parser.add_argument(
32+
"-c",
33+
"--camera",
34+
choices=cameras,
35+
default=[camera for camera in cameras if "QM" in camera][0],
36+
help="""Process data for a specific NectarCAM camera.
37+
Default: NectarCAMQM (Qualification Model).""",
38+
type=str,
39+
)
40+
2741
# max events to be loaded
2842
parser.add_argument(
2943
"-m",
@@ -170,6 +184,7 @@ def main(
170184
progress_bar=True,
171185
run_number=_FF_run_number,
172186
max_events=_max_events,
187+
camera=args.camera,
173188
Ped_run_number=_Ped_run_number,
174189
SPE_result=path[0],
175190
**kwargs,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#HOW TO :
22
#to perform photo-statistic high and low gain computation with pedestal run 2609, flat field run 2609 and SPE fit result from run 2634 (1400V run)
3-
python gain_PhotoStat_computation.py --FF_run_number 3937 --Ped_run_number 3938 --SPE_run_number 3942 --SPE_config HHVfixed --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v INFO --reload_events
3+
python gain_PhotoStat_computation.py --camera="NectarCAMQM" --FF_run_number 3937 --Ped_run_number 3938 --SPE_run_number 3942 --SPE_config HHVfixed --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v INFO --reload_events
44

src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_combined_computation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
)
1515
from nectarchain.makers.extractor.utils import CtapipeExtractor
1616

17+
prefix = "NectarCAM"
18+
cameras = [f"{prefix}" + "QM"]
19+
cameras.extend([f"{prefix + str(i)}" for i in range(2, 10)])
20+
1721
parser = argparse.ArgumentParser(
1822
prog="gain_SPEfit_combined_computation.py",
1923
description=f"compute high gain with SPE fit for one run at nominal voltage from a SPE result from a run at 1400V. By default, output data are saved in $NECTARCAMDATA/../SPEfit/data/",
@@ -23,6 +27,16 @@
2327
"-r", "--run_number", nargs="+", default=[], help="run(s) list", type=int
2428
)
2529

30+
parser.add_argument(
31+
"-c",
32+
"--camera",
33+
choices=cameras,
34+
default=[camera for camera in cameras if "QM" in camera][0],
35+
help="""Process data for a specific NectarCAM camera.
36+
Default: NectarCAMQM (Qualification Model).""",
37+
type=str,
38+
)
39+
2640
# max events to be loaded
2741
parser.add_argument(
2842
"-m",
@@ -171,6 +185,7 @@ def main(
171185
tool = FlatFieldSPECombinedStdNectarCAMCalibrationTool(
172186
progress_bar=True,
173187
run_number=_run_number,
188+
camera=args.camera,
174189
max_events=_max_events,
175190
SPE_result=path[0],
176191
**kwargs,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#HOW TO :
22

33
#to perform SPE fit of run 3936 (supposed to be taken at nominal voltage) from SPE fit performed on 3942 (taken at 1400V) (luminosity can not be supposed the same)
4-
python gain_SPEfit_combined_computation.py -r 3936 --HHV_run_number 3942 --multiproc --nproc 8 --chunksize 2 -p 45 56 --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v DEBUG --reload_events
4+
python gain_SPEfit_combined_computation.py --camera="NectarCAMQM" -r 3936 --HHV_run_number 3942 --multiproc --nproc 8 --chunksize 2 -p 45 56 --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v DEBUG --reload_events

src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_computation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
)
1616
from nectarchain.makers.extractor.utils import CtapipeExtractor
1717

18+
prefix = "NectarCAM"
19+
cameras = [f"{prefix}" + "QM"]
20+
cameras.extend([f"{prefix + str(i)}" for i in range(2, 10)])
21+
1822
parser = argparse.ArgumentParser(
1923
prog="gain_SPEfit_computation.py",
2024
description=f"compute high gain with SPE fit for one run at very very high voltage (~1400V) or at nominal voltage (it can often fail). By default, output data are saved in $NECTARCAMDATA/../SPEfit/data/",
@@ -24,6 +28,16 @@
2428
"-r", "--run_number", nargs="+", default=[], help="run(s) list", type=int
2529
)
2630

31+
parser.add_argument(
32+
"-c",
33+
"--camera",
34+
choices=cameras,
35+
default=[camera for camera in cameras if "QM" in camera][0],
36+
help="""Process data for a specific NectarCAM camera.
37+
Default: NectarCAMQM (Qualification Model).""",
38+
type=str,
39+
)
40+
2741
# max events to be loaded
2842
parser.add_argument(
2943
"-m",
@@ -160,6 +174,7 @@ def main(
160174
try:
161175
tool = _class(
162176
progress_bar=True,
177+
camera=args.camera,
163178
run_number=_run_number,
164179
max_events=_max_events,
165180
**kwargs,

src/nectarchain/user_scripts/ggrolleron/gain_SPEfit_computation.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#nominal runs : 2633,3936
55

66
#to perform SPE fit of a run at nominal voltage
7-
python gain_SPEfit_computation.py -r 3942 --reload_events --multiproc --nproc 8 --chunksize 2 -p 45 56 --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v DEBUG
7+
python gain_SPEfit_computation.py --camera="NectarCAMQM" -r 3942 --reload_events --multiproc --nproc 8 --chunksize 2 -p 45 56 --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v DEBUG
88
#to perform SPE fit of a HHV run
9-
python gain_SPEfit_computation.py -r 3936 --reload_events --multiproc --nproc 8 --chunksize 2 -p 45 56 --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v DEBUG
9+
python gain_SPEfit_computation.py --camera="NectarCAMQM" -r 3936 --reload_events --multiproc --nproc 8 --chunksize 2 -p 45 56 --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v DEBUG
1010
#to perform SPE fit of a HHV run letting n and pp parameters free
11-
python gain_SPEfit_computation.py -r 3942 --HHV --free_pp_n --reload_events --multiproc --nproc 8 --chunksize 2 -p 45 56 --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v DEBUG
11+
python gain_SPEfit_computation.py --camera="NectarCAMQM" -r 3942 --HHV --free_pp_n --reload_events --multiproc --nproc 8 --chunksize 2 -p 45 56 --max_events 100 --method LocalPeakWindowSum --extractor_kwargs '{"window_width":16,"window_shift":4}' --overwrite -v DEBUG

0 commit comments

Comments
 (0)