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 int GetTag(const int s);
00137
00142 inline double GetLiveTime(void){ return livetime_tot; };
00143
00150 double GetLiveTime(const double gps_start, const double gps_end);
00151
00157 double GetLiveTime(const int s);
00158
00168 TH1I* GetHisto(const double offset=0.0);
00169
00182 TH1I* GetHisto(const double gps_start, const double gps_end, const double offset=0.0);
00183
00190 TTree* GetTree(void);
00191
00201 TTree* GetTree(const double gps_start, const double gps_end);
00202
00212 int GetClosestSegment(const double gps, vector<double> &seg);
00213
00219 bool IsInsideSegment(const double gps);
00220
00227 bool IsInsideSegment(const double gps, int &seg_n);
00228
00240 bool ApplyPadding(const double pad_low, const double pad_up);
00241
00251 bool AddSegment(const double gps_start, const double gps_end, const int tag=-1);
00252
00261 bool Append(Segments *Seg);
00262
00270 bool Intersect(Segments *Seg);
00271
00281 bool Intersect(const double gps_start, const double gps_end, const int tag=-1);
00282
00291 bool Reverse(void);
00292
00299 bool Reset(void);
00300
00307 bool SetTag(const int s, const int tag);
00308
00314 bool SetTags(const int tag);
00315
00326 bool Dump(int ncol=2);
00327
00337 bool Write(const string txtfilename, const int ncol=2);
00338
00346 bool WriteROOT(const string rootfilename);
00347
00348 protected:
00349
00350 bool status;
00351 vector<double> seg_start;
00352 vector<double> seg_end;
00353 vector<int> seg_tag;
00354 double livetime_tot;
00355
00356 private:
00357
00358 bool CheckConsistency(void);
00359 bool SetMarks(void);
00360 bool ComputeLiveTime(void);
00361 bool MergeOverlaps(void);
00362
00363 vector <int> time_mark;
00364 vector <int> n_mark;
00365
00366 inline int TagProduct(const int tag1, const int tag2){
00367 if(tag1<0) return -1;
00368 else if (tag2<0) return -1;
00369 else if (tag1==tag2) return tag1;
00370 else if (tag1>tag2) return tag1;
00371 else if (tag1<tag2) return tag2;
00372 else return -1;
00373 return -1;
00374 };
00375
00376
00377 ClassDef(Segments,0)
00378 };
00379
00380 #endif
00381
00382