~uhh-ssd/+junk/Alibava_Analysis_Cluster

« back to all changes in this revision

Viewing changes to AsciiRoot.h

  • Committer: Joachim Erfle
  • Date: 2012-08-22 14:41:46 UTC
  • Revision ID: joachim.erfle@desy.de-20120822144146-dakrtohvlkd1kdi2
faster common mode, new firmware, stable langaus

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <vector>
5
5
//#include <Data.h>
6
6
#include <ctime>
 
7
#include <TH1.h>
7
8
#include <TH2.h>
8
9
#include <TGraph.h>
9
10
#include <TMultiGraph.h>
32
33
        double value;
33
34
};
34
35
 
 
36
struct EventDataBlock : public EventData
 
37
{
 
38
        unsigned short header[32];
 
39
};
 
40
 
 
41
 
 
42
             inline bool isws(char c, char const * const wstr=" \t\n")
 
43
{
 
44
    return (strchr(wstr, c) != NULL);
 
45
}
 
46
 
 
47
inline std::string trim_right(const std::string &s)
 
48
{
 
49
    std::string b=" \t\n";
 
50
    std::string str = s;
 
51
    return str.erase(str.find_last_not_of(b) +1);
 
52
}
 
53
 
 
54
inline std::string trim_left(const std::string &s)
 
55
{
 
56
    std::string b=" \t\n";
 
57
    std::string str = s;
 
58
    return str.erase( 0, str.find_first_not_of(b) );
 
59
}
 
60
 
 
61
inline std::string trim_str(const std::string &s)
 
62
{
 
63
    std::string str = s;
 
64
    return trim_left(trim_right(str) );
 
65
}
35
66
 
36
67
struct AsciiRootPriv;
37
68
 
40
71
class AsciiRoot
41
72
{
42
73
    public:
 
74
                typedef std::vector<std::string> XtraValues;
43
75
        enum BlockType { NewFile=0, StartOfRun, DataBlock, CheckPoint, EndOfRun };
44
76
    private:
45
77
        static const int max_nchan=256;
54
86
        int _step;
55
87
        int _nevts;
56
88
        int _nchan; // current number of channels
 
89
                XtraValues _xtra; // extra values from header
57
90
        int _relocate[max_nchan];
58
91
        int _group[max_nchan];
59
92
        double _seedcut;
60
93
        double _neighcut;
 
94
        unsigned short _header[2][16];
61
95
        double _ped[max_nchan];
62
96
        double _noise[max_nchan];
63
97
        double _signal[max_nchan];
65
99
        double _cmmd[max_nchan];
66
100
        double _cnoise[max_nchan];
67
101
        double _gain[max_nchan];
 
102
        bool   _mask[max_nchan];
68
103
        double _average_gain;
69
 
        bool   _mask[max_nchan];
70
 
        bool   _new_version;
 
104
        
 
105
        int     _version;
 
106
        int     _polarity;
71
107
        TRandom3 *rand;
72
108
        //TGraph *H_cmmd[2];
73
109
        //TCanvas * ARCanvas[512];
75
111
        TH1D *th1d_histos[512];
76
112
        TGraph *t_graph[512];
77
113
        TMultiGraph *t_multi[512];
78
 
        EventData _data;
 
114
        EventDataBlock _data;
79
115
        int int_buf;
80
 
        inline bool isws(char c, char const * const wstr=" \t\n")
81
 
{
82
 
    return (strchr(wstr, c) != NULL);
83
 
}
84
 
 
85
 
inline std::string trim_right(const std::string &s)
86
 
{
87
 
    std::string b=" \t\n";
88
 
    std::string str = s;
89
 
    return str.erase(str.find_last_not_of(b) +1);
90
 
}
91
 
 
92
 
inline std::string trim_left(const std::string &s)
93
 
{
94
 
    std::string b=" \t\n";
95
 
    std::string str = s;
96
 
    return str.erase( 0, str.find_first_not_of(b) );
97
 
}
98
 
 
99
 
inline std::string trim_str(const std::string &s)
100
 
{
101
 
    std::string str = s;
102
 
    return trim_left(trim_right(str) );
103
 
}
 
116
   
104
117
        /*
105
118
         * Extra monitoring data
106
119
         */
109
122
        int    _hist1clusterwidth[20];
110
123
        int    _hist2clusterwidth[20];
111
124
 
 
125
    protected:
 
126
        void reset_data();
 
127
        void set_data(int i, unsigned short x) { _data.data[i] = x; }
 
128
 
112
129
    public:
113
130
            /* A Construtor 
114
131
            * 
115
132
            * openes the given files
116
133
            */
117
 
        AsciiRoot(const char *nam=0,int num=0, const char *pedfile=0, const char *gainfile=0);
118
 
       virtual ~AsciiRoot();
119
 
 
120
 
 
 
134
                AsciiRoot(const char *nam=0,int num=0, const char *pedfile=0, const char *gainfile=0);
 
135
        virtual ~AsciiRoot();
 
136
 
 
137
        
 
138
        
121
139
        bool valid() const
122
140
        {
123
141
            return (ifile!=0);
133
151
        virtual void end_of_run(int, const char *) {}
134
152
        virtual void new_data_block(int, const char *) {};
135
153
 
 
154
        // The data format version
 
155
        int version() const { return _version; }
 
156
 
 
157
        
 
158
 
 
159
        int polarity() const { return _polarity; }
 
160
        void polarity(int x) { _polarity = ( x<0 ? -1 : 1); }
136
161
        /*
137
162
         * Sets the number of channels and the data in the case
138
163
         * of non "standard" values. If data==0, then only the number
170
195
        {
171
196
            return _sn[i];
172
197
        }
173
 
        unsigned short data(int i) const
174
 
        {
175
 
            return _data.data[i];
176
 
        }
 
198
 
177
199
        double get_cmmd(int i) const
178
200
        {
179
201
            return _cmmd[i];
184
206
            return _cnoise[i];
185
207
        }
186
208
 
 
209
        unsigned short data(int i) const
 
210
        {
 
211
            return _data.data[i];
 
212
        }
187
213
        double value() const
188
214
        {
189
215
            return _data.value;
233
259
            _seedcut = s;
234
260
            _neighcut = n;
235
261
        }
 
262
                unsigned short get_header(int ichip, int ibit) { return _header[ichip][ibit]; }
 
263
 
236
264
        TH1 *show_pedestals();
237
265
        void show_noise(TH1 &hnoise);
238
266
 
239
 
        TH2 *compute_pedestals(int mxevts=-1, bool do_cmmd=false);
 
267
        TH2 *compute_pedestals(int mxevts=-1, bool do_cmmd=true);
240
268
        void compute_pedestals_fast(int mxevts = -1, double ped_weight=0.01, double noise_weight=0.001);
241
269
 
242
270
 
251
279
        void common_mode(int Event=0);
252
280
        void load_relocation(const char *fnam);
253
281
        void load_group(const char *fnam);
 
282
 
 
283
                int nxtra() const { return _xtra.size(); }
 
284
        const std::string xtra(int i) const { return _xtra[i]; }
 
285
        void add_xtra(const std::string &x) { _xtra.push_back(x); }
 
286
        void add_xtra(const char *x) { _xtra.push_back(x); }
254
287
};
255
288
// Return true if file is an ASCII text file
256
289
bool is_text(const char *);