Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 : /* $Id$ */
16 : /** @file AliFMDCalibGain.cxx
17 : @author Christian Holm Christensen <cholm@nbi.dk>
18 : @date Sun Mar 26 18:30:02 2006
19 : @brief Per strip gain calibration
20 : */
21 : //____________________________________________________________________
22 : //
23 : // Gain value and width for each strip in the FMD.
24 : // Foo
25 : // Bar
26 : // Baz
27 : // Gnus
28 : //
29 : #include "AliFMDCalibGain.h" // ALIFMDCALIBGAIN_H
30 : #include <iostream>
31 : #include <TString.h>
32 : #include <AliLog.h>
33 : #include "AliFMDDebug.h"
34 :
35 : #include "AliFMDBoolMap.h"
36 :
37 :
38 : //____________________________________________________________________
39 12 : ClassImp(AliFMDCalibGain)
40 : #if 0
41 : ; // This is here to keep Emacs for indenting the next line
42 : #endif
43 :
44 : //____________________________________________________________________
45 3 : AliFMDCalibGain::AliFMDCalibGain()
46 3 : : fValue(0), // nDet == 0 mean 51200 slots
47 3 : fThreshold(-1.)
48 15 : {
49 : // CTOR
50 3 : fValue.Reset(-1.);
51 3 : fThreshold = -1.;
52 6 : }
53 :
54 : //____________________________________________________________________
55 : AliFMDCalibGain::AliFMDCalibGain(const AliFMDCalibGain& o)
56 0 : : TObject(o),
57 0 : fValue(o.fValue),
58 0 : fThreshold(o.fThreshold)
59 0 : {
60 : // Copy CTOR
61 0 : }
62 :
63 : //____________________________________________________________________
64 : AliFMDCalibGain&
65 : AliFMDCalibGain::operator=(const AliFMDCalibGain& o)
66 : {
67 : // Assignment operator
68 0 : if (&o == this) return *this;
69 0 : fValue = o.fValue;
70 0 : fThreshold = o.fThreshold;
71 0 : return (*this);
72 0 : }
73 :
74 : //____________________________________________________________________
75 : void
76 : AliFMDCalibGain::Set(UShort_t det, Char_t ring, UShort_t sec,
77 : UShort_t str, Float_t val)
78 : {
79 : // Set the value for a strip
80 0 : if (fValue.CheckIndex(det, ring, sec, str) < 0) return;
81 0 : fValue(det, ring, sec, str) = val;
82 0 : }
83 :
84 : //____________________________________________________________________
85 : Float_t
86 : AliFMDCalibGain::Value(UShort_t det, Char_t ring, UShort_t sec,
87 : UShort_t str)
88 : {
89 : // Get the value for a strip
90 980266 : return fValue(det, ring, sec, str);
91 : }
92 :
93 : //____________________________________________________________________
94 : namespace {
95 0 : struct MakeDead : public AliFMDMap::ForOne
96 : {
97 0 : MakeDead(AliFMDBoolMap* dead, Float_t min, Float_t max)
98 0 : : fDead(dead), fMin(min), fMax(max), fCount(0)
99 0 : {}
100 : MakeDead(const MakeDead& other)
101 : : AliFMDMap::ForOne(other),
102 : fDead(other.fDead), fMin(other.fMin), fMax(other.fMax),
103 : fCount(other.fCount)
104 : {}
105 : MakeDead& operator=(const MakeDead& other)
106 : {
107 : if (&other == this) return *this;
108 : fDead = other.fDead;
109 : fMin = other.fMin;
110 : fMax = other.fMax;
111 : fCount = other.fCount;
112 : return *this;
113 : }
114 : Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t v)
115 : {
116 0 : AliDebugGeneral("AliFMDCalibGain::MakeDeadMap", 100,
117 : Form("Checking if gain of FMD%d%c[%2d,%3d]=%f "
118 : "is out of range [%f,%f]",
119 : d, r, s, t, v, fMin, fMax));
120 0 : if (v > fMax || v < fMin) {
121 0 : fDead->operator()(d,r,s,t) = kTRUE;
122 0 : fCount++;
123 0 : }
124 0 : return kTRUE;
125 : }
126 : Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t)
127 0 : { return kFALSE; }
128 : Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, UShort_t)
129 0 : { return kFALSE; }
130 : Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Bool_t)
131 0 : { return kFALSE; }
132 : AliFMDBoolMap* fDead;
133 : Float_t fMin;
134 : Float_t fMax;
135 : Int_t fCount;
136 : };
137 : }
138 :
139 : //____________________________________________________________________
140 : AliFMDBoolMap*
141 : AliFMDCalibGain::MakeDeadMap(Float_t min, Float_t max,
142 : AliFMDBoolMap* dead) const
143 : {
144 0 : if (!dead) {
145 0 : dead = new AliFMDBoolMap(0,0,0,0);
146 0 : dead->Reset(kFALSE);
147 0 : }
148 0 : MakeDead dm(dead, min, max);
149 0 : fValue.ForEach(dm);
150 0 : AliFMDDebug(1, ("Found a total of %d dead channels", dm.fCount));
151 : return dead;
152 0 : }
153 :
154 : //____________________________________________________________________
155 : Bool_t
156 : AliFMDCalibGain::ReadFromFile(std::istream& in)
157 : {
158 : //Get header (how long is it ?)
159 0 : TString header;
160 0 : header.ReadLine(in);
161 0 : header.ToLower();
162 0 : if(!header.Contains("gains")) {
163 0 : AliError("File does not contain gains!");
164 0 : return kFALSE;;
165 : }
166 :
167 : // Read column headers
168 0 : header.ReadLine(in);
169 :
170 : int lineno = 2;
171 : // Read until EOF
172 0 : while(in.peek()!=EOF) {
173 0 : if(in.bad()) {
174 0 : AliError(Form("Bad read at line %d of input", lineno));
175 : break;
176 : }
177 0 : UShort_t det, sec, strip;
178 0 : Char_t ring;
179 :
180 0 : Float_t gain,error, chi2ndf;
181 0 : Char_t c[6];
182 :
183 0 : in >> det >> c[0]
184 0 : >> ring >> c[1]
185 0 : >> sec >> c[2]
186 0 : >> strip >> c[3]
187 0 : >> gain >> c[4]
188 0 : >> error >> c[5]
189 0 : >> chi2ndf;
190 0 : lineno++;
191 0 : Set(det,ring,sec,strip,gain);
192 0 : }
193 : return kTRUE;
194 0 : }
195 : //____________________________________________________________________
196 : //
197 : // EOF
198 : //
|