00001
00002
00004 #ifndef __Segments__
00005 #define __Segments__
00006
00007 #include "CUtils.h"
00008 #include "ReadAscii.h"
00009 #include "TFile.h"
00010 #include "TTree.h"
00011 #include "TH1.h"
00012
00013 using namespace std;
00014
00020 class Segments {
00021
00022 friend class ReadTriggerSegments;
00023
00024 public:
00025
00034 Segments(void);
00035
00044 Segments(const string segment_file, const int ncol=2, const int default_tag=-1);
00045
00052 Segments(TTree *segment_tree);
00053
00062 Segments(const vector<double> segment_starts, const vector<double> segment_ends);
00063
00072 Segments(const double segment_start, const double segment_end, const int segment_tag=-1);
00073
00077 virtual ~Segments(void);
00088 inline bool GetStatus(void) const { return status; };
00089
00093 inline int GetNsegments(void){ return (int)seg_start.size(); };
00094
00099 int GetNSegmentsWithTag(const int tag);
00100
00105 inline vector<double> GetStarts(void){ return seg_start; };
00106
00111 inline vector<double> GetEnds(void){ return seg_end; };
00112
00117 inline vector<int> GetTags(void){ return seg_tag; };
00118
00124 double GetStart(const int s=0);
00125
00131 double GetEnd(const int s=0);
00132
00138 double GetDuration(const int s=0);
00139
00145 int GetTag(const int s);
00146
00151 inline double GetLiveTime(void){ return livetime_tot; };
00152
00159 double GetLiveTime(const double gps_start, const double gps_end);
00160
00166 double GetLiveTime(const int s);
00167
00172 double GetLiveTimeWithTag(const int tag);
00173
00183 TH1I* GetHisto(const double offset=0.0);
00184
00197 TH1I* GetHisto(const double gps_start, const double gps_end, const double offset=0.0);
00198
00205 TTree* GetTree(void);
00206
00216 TTree* GetTree(const double gps_start, const double gps_end);
00217
00228 bool GetTimeSeries(bool *timeseries, const int sampling_rate, const int gps_start, const int gps_end);
00229
00239 int GetClosestSegment(const double gps, vector<double> &seg);
00240
00246 bool IsInsideSegment(const double gps);
00247
00254 bool IsInsideSegment(const double gps, int &seg_n);
00255
00267 bool ApplyPadding(const double pad_low, const double pad_up);
00268
00278 double SmartShift(void);
00279
00289 bool AddSegment(const double gps_start, const double gps_end, const int tag=-1);
00290
00299 bool Append(Segments *Seg);
00300
00308 bool Intersect(Segments *Seg);
00309
00314 bool TruncateAfter(const double gps);
00315
00325 bool Intersect(const double gps_start, const double gps_end, const int tag=-1);
00326
00337 bool Reverse(void);
00338
00343 void Reset(void);
00344
00351 bool SetTag(const int s, const int tag);
00352
00358 bool SetTags(const int tag);
00359
00370 bool Dump(int ncol=2);
00371
00381 bool Write(const string txtfilename, const int ncol=2);
00382
00390 bool WriteROOT(const string rootfilename);
00391
00392 protected:
00393
00394 bool status;
00395 vector<double> seg_start;
00396 vector<double> seg_end;
00397 vector<int> seg_tag;
00398 double livetime_tot;
00399
00400 private:
00401
00402 bool CheckConsistency(void);
00403 bool SetMarks(void);
00404 bool ComputeLiveTime(void);
00405 bool MergeOverlaps(const int s_start=0);
00406
00407 vector <int> time_mark;
00408 vector <int> n_mark;
00409
00410 inline int TagProduct(const int tag1, const int tag2){
00411 if(tag1<0) return -1;
00412 else if (tag2<0) return -1;
00413 else return TMath::Max(tag1,tag2);
00414 return -1;
00415 };
00416
00417 inline int TagSum(const int tag1, const int tag2){ return TMath::Max(tag1,tag2); };
00418
00419 ClassDef(Segments,0)
00420 };
00421
00422 #endif
00423
00424