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 public:
00023
00032 Segments(void);
00033
00042 Segments(const string segment_file, const int ncol=2, const int default_tag=-1);
00043
00050 Segments(TTree *segment_tree);
00051
00060 Segments(const vector<double> segment_starts, const vector<double> segment_ends);
00061
00070 Segments(const double segment_start, const double segment_end, const int segment_tag=-1);
00071
00075 virtual ~Segments(void);
00086 inline bool GetStatus(void) const { return status; };
00087
00091 inline int GetNsegments(void){ return (int)seg_start.size(); };
00092
00097 int GetNSegmentsWithTag(const int tag);
00098
00103 inline vector<double> GetStarts(void){ return seg_start; };
00104
00109 inline vector<double> GetEnds(void){ return seg_end; };
00110
00115 inline vector<int> GetTags(void){ return seg_tag; };
00116
00122 double GetStart(const int s=0);
00123
00129 double GetEnd(const int s=0);
00130
00136 double GetDuration(const int s=0);
00137
00143 int GetTag(const int s);
00144
00149 inline double GetLiveTime(void){ return livetime_tot; };
00150
00157 double GetLiveTime(const double gps_start, const double gps_end);
00158
00164 double GetLiveTime(const int s);
00165
00170 double GetLiveTimeWithTag(const int tag);
00171
00181 TH1I* GetHisto(const double offset=0.0);
00182
00195 TH1I* GetHisto(const double gps_start, const double gps_end, const double offset=0.0);
00196
00203 TTree* GetTree(void);
00204
00214 TTree* GetTree(const double gps_start, const double gps_end);
00215
00226 bool GetTimeSeries(bool *timeseries, const int sampling_rate, const int gps_start, const int gps_end);
00227
00237 int GetClosestSegment(const double gps, vector<double> &seg);
00238
00244 bool IsInsideSegment(const double gps);
00245
00252 bool IsInsideSegment(const double gps, int &seg_n);
00253
00265 bool ApplyPadding(const double pad_low, const double pad_up);
00266
00276 double SmartShift(void);
00277
00287 bool AddSegment(const double gps_start, const double gps_end, const int tag=-1);
00288
00297 bool Append(Segments *Seg);
00298
00306 bool Intersect(Segments *Seg);
00307
00317 bool Intersect(const double gps_start, const double gps_end, const int tag=-1);
00318
00329 bool Reverse(void);
00330
00337 bool Reset(void);
00338
00345 bool SetTag(const int s, const int tag);
00346
00352 bool SetTags(const int tag);
00353
00364 bool Dump(int ncol=2);
00365
00375 bool Write(const string txtfilename, const int ncol=2);
00376
00384 bool WriteROOT(const string rootfilename);
00385
00386 protected:
00387
00388 bool status;
00389 vector<double> seg_start;
00390 vector<double> seg_end;
00391 vector<int> seg_tag;
00392 double livetime_tot;
00393
00394 private:
00395
00396 bool CheckConsistency(void);
00397 bool SetMarks(void);
00398 bool ComputeLiveTime(void);
00399 bool MergeOverlaps(const int s_start=0);
00400
00401 vector <int> time_mark;
00402 vector <int> n_mark;
00403
00404 inline int TagProduct(const int tag1, const int tag2){
00405 if(tag1<0) return -1;
00406 else if (tag2<0) return -1;
00407 else return TMath::Max(tag1,tag2);
00408 return -1;
00409 };
00410
00411 inline int TagSum(const int tag1, const int tag2){ return TMath::Max(tag1,tag2); };
00412
00413 ClassDef(Segments,0)
00414 };
00415
00416 #endif
00417
00418