@@ -78,7 +78,8 @@ def read_tra(self, input_name=None, output_name=None, run_test=False, use_ori=Fa
7878 'Psi local':psi_loc,\
7979 'Distance':dist,\
8080 'Chi galactic':chi_gal,\
81- 'Psi galactic':psi_gal}\
81+ 'Psi galactic':psi_gal,\
82+ 'CO seq':CO_seq}\
8283 Arrays contain unbinned photon data.
8384
8485 Notes
@@ -126,6 +127,10 @@ def read_tra(self, input_name=None, output_name=None, run_test=False, use_ori=Fa
126127 dg_y = []
127128 dg_z = []
128129
130+ # Compton seq
131+ CO_seq = []
132+
133+
129134 # Define electron rest energy, which is used in calculation
130135 # of Compton scattering angle.
131136 c_E0 = 510.9989500015 # keV
@@ -210,6 +215,7 @@ def read_tra(self, input_name=None, output_name=None, run_test=False, use_ori=Fa
210215 erg .pop ()
211216 phi .pop ()
212217 tt .pop ()
218+ CO_seq .pop ()
213219 # Not all sims include ori info,
214220 # so also need to check before pop:
215221 if len (lonX ) != 0 :
@@ -280,6 +286,11 @@ def read_tra(self, input_name=None, output_name=None, run_test=False, use_ori=Fa
280286 lonZ .append (this_lonZ )
281287 latZ .append (this_latZ )
282288
289+
290+ #number of interaction
291+ if this_line [0 ] == "SQ" :
292+ CO_seq .append (int (this_line [1 ]))
293+
283294 # Interaction position information:
284295 if (this_line [0 ] == "CH" ):
285296
@@ -323,7 +334,8 @@ def read_tra(self, input_name=None, output_name=None, run_test=False, use_ori=Fa
323334 dg_x = np .array (dg_x )
324335 dg_y = np .array (dg_y )
325336 dg_z = np .array (dg_z )
326-
337+ CO_seq = np .array (CO_seq )
338+
327339 # Check if the input data has pointing information,
328340 # if not, set dummy values:
329341 if (use_ori == False ) & (len (lonZ )== 0 ):
@@ -410,7 +422,8 @@ def read_tra(self, input_name=None, output_name=None, run_test=False, use_ori=Fa
410422 'Psi local' :psi_loc ,
411423 'Distance' :dist ,
412424 'Chi galactic' :chi_gal ,
413- 'Psi galactic' :psi_gal }
425+ 'Psi galactic' :psi_gal ,
426+ 'Compton Seq' :CO_seq }
414427 self .cosi_dataset = cosi_dataset
415428
416429 # Option to write unbinned data to file (either fits or hdf5):
@@ -550,7 +563,7 @@ def write_unbinned_output(self, output_name):
550563
551564 # Data units:
552565 units = ['keV' ,'s' ,'rad' ,'rad' ,
553- 'rad' ,'rad' ,'rad' ,'rad' ,'cm' ,'deg' ,'deg' ]
566+ 'rad' ,'rad' ,'rad' ,'rad' ,'cm' ,'deg' ,'deg' , '' ]
554567
555568 # For fits output:
556569 if self .unbinned_output == 'fits' :
@@ -723,6 +736,47 @@ def select_data_energy(self, emin, emax, output_name=None, unbinned_data=None):
723736
724737 return
725738
739+ def select_data_COseq (self , seqmin , seqmax , output_name = None , unbinned_data = None ):
740+
741+ """Applies CO sequence cuts [seqmin,seqmax) to unbinnned data dictionary.
742+
743+ Parameters
744+ ----------
745+ seqmin : int
746+ Minimum number of interaction.
747+ seqmax : int
748+ Maximum number of interaction.
749+ unbinned_data : str, optional
750+ Name of unbinned dictionary file.
751+ output_name : str, optional
752+ Prefix of output file (default is None, in which case no
753+ file is saved).
754+ """
755+
756+ logger .info ("Making data selections on Compton Sequence..." )
757+
758+ # Option to read in unbinned data file:
759+ if unbinned_data :
760+ self .cosi_dataset = self .get_dict (unbinned_data )
761+
762+ # Get energy cut index:
763+ COseq_array = self .cosi_dataset ["Compton Seq" ]
764+ COseq_cut_index = (COseq_array >= seqmin ) & (COseq_array < seqmax )
765+
766+ # Apply cuts to dictionary:
767+ for key in self .cosi_dataset :
768+
769+ self .cosi_dataset [key ] = self .cosi_dataset [key ][COseq_cut_index ]
770+
771+ # Write unbinned data to file (either fits or hdf5):
772+ if output_name != None :
773+ logger .info ("Saving file..." )
774+ self .write_unbinned_output (output_name )
775+
776+ return
777+
778+
779+
726780 def combine_unbinned_data (self , input_files , output_name = None ):
727781
728782 """Combines input unbinned data files.
0 commit comments