]>
Commit | Line | Data |
---|---|---|
223dda26 | 1 | /************************************************************************** |
2 | * Copyright(c) 2007-2009, 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 | ||
8bcdc40d | 16 | /* $Id$ */ |
223dda26 | 17 | |
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | /// | |
20 | /// This class provides ITS SSD data handling | |
21 | /// used by DA. | |
2e2c6def | 22 | // Author: Oleksandr Borysov |
61a57d07 | 23 | // Date: 18/07/2008 |
223dda26 | 24 | /////////////////////////////////////////////////////////////////////////////// |
25 | ||
304a787e | 26 | #include <cstring> |
be4f467e | 27 | #include <fstream> |
61a57d07 | 28 | #include <new> |
223dda26 | 29 | #include <Riostream.h> |
f67db810 | 30 | #include "AliITSHandleDaSSD.h" |
7ab0e0a5 | 31 | //#include <math.h> |
c4d90345 | 32 | #include <limits.h> |
223dda26 | 33 | #include "event.h" |
34 | #include "TFile.h" | |
c4d90345 | 35 | #include "TString.h" |
292c304e | 36 | #include "TMath.h" |
c4d90345 | 37 | #include "AliLog.h" |
88128115 | 38 | #include "AliITSNoiseSSDv2.h" |
39 | #include "AliITSPedestalSSDv2.h" | |
40 | #include "AliITSBadChannelsSSDv2.h" | |
c4d90345 | 41 | #include "AliITSRawStreamSSD.h" |
223dda26 | 42 | #include "AliRawReaderDate.h" |
371588bb | 43 | #include "AliITSRawStreamSSD.h" |
223dda26 | 44 | #include "AliITSChannelDaSSD.h" |
f67db810 | 45 | |
46 | ||
47 | ClassImp(AliITSHandleDaSSD) | |
48 | ||
49 | using namespace std; | |
50 | ||
51 | ||
c4d90345 | 52 | const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModules = 1698; // Number of SSD modules in ITS |
2e2c6def | 53 | const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModulesPerDdl = 108; // Number of SSD modules in DDL |
54 | const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModulesPerSlot = 12; // Number of SSD modules in Slot | |
61a57d07 | 55 | const Short_t AliITSHandleDaSSD::fgkMinSSDModuleId = 500; // Initial SSD modules number |
be4f467e | 56 | const Int_t AliITSHandleDaSSD::fgkNumberOfSSDSlotsPerDDL = 9; // Number of SSD slots per DDL |
6e7691a5 | 57 | const Int_t AliITSHandleDaSSD::fgkNumberOfSSDDDLs = 16; // Number of SSD modules in Slot |
c4d90345 | 58 | const Float_t AliITSHandleDaSSD::fgkPedestalThresholdFactor = 3.0; // Defalt value for fPedestalThresholdFactor |
59 | const Float_t AliITSHandleDaSSD::fgkCmThresholdFactor = 3.0; // Defalt value for fCmThresholdFactor | |
60 | ||
be4f467e | 61 | const UInt_t AliITSHandleDaSSD::fgkZsBitMask = 0x0000003F; // Bit mask for FEROM ZS |
62 | const UInt_t AliITSHandleDaSSD::fgkOffSetBitMask = 0x000003FF; // Bit mask for FEROM Offset correction | |
63 | const UInt_t AliITSHandleDaSSD::fgkBadChannelMask = 0x00000001; // Mask to suppress the channel from the bad channel list | |
64 | const Int_t AliITSHandleDaSSD::fgkAdcPerDBlock = 6; // FEROM configuration file constant | |
65 | ||
c4d90345 | 66 | //______________________________________________________________________________ |
f67db810 | 67 | AliITSHandleDaSSD::AliITSHandleDaSSD() : |
c4d90345 | 68 | fRawDataFileName(NULL), |
f67db810 | 69 | fNumberOfModules(0), |
70 | fModules(NULL), | |
c4d90345 | 71 | fModIndProcessed(0), |
72 | fModIndRead(0), | |
2e2c6def | 73 | fModIndex(NULL), |
61a57d07 | 74 | fEqIndex(0), |
c4d90345 | 75 | fNumberOfEvents(0), |
61a57d07 | 76 | fBadChannelsList(NULL), |
6e7691a5 | 77 | fDDLModuleMap(NULL), |
61a57d07 | 78 | fALaddersOff(0), |
79 | fCLaddersOff(0), | |
f67db810 | 80 | fLdcId(0), |
c4d90345 | 81 | fRunId(0), |
82 | fPedestalThresholdFactor(fgkPedestalThresholdFactor), | |
be4f467e | 83 | fCmThresholdFactor(fgkCmThresholdFactor), |
84 | fZsDefault(-1), | |
85 | fOffsetDefault(INT_MAX), | |
61a57d07 | 86 | fZsMinimum(2), |
87 | fMergeBCLists(1), | |
be4f467e | 88 | fZsFactor(3.0) |
f67db810 | 89 | { |
223dda26 | 90 | // Default constructor |
f67db810 | 91 | } |
92 | ||
93 | ||
c4d90345 | 94 | //______________________________________________________________________________ |
95 | AliITSHandleDaSSD::AliITSHandleDaSSD(Char_t *rdfname) : | |
96 | fRawDataFileName(NULL), | |
f67db810 | 97 | fNumberOfModules(0), |
98 | fModules(NULL), | |
c4d90345 | 99 | fModIndProcessed(0), |
100 | fModIndRead(0), | |
2e2c6def | 101 | fModIndex(NULL), |
61a57d07 | 102 | fEqIndex(0), |
c4d90345 | 103 | fNumberOfEvents(0), |
61a57d07 | 104 | fBadChannelsList(NULL), |
6e7691a5 | 105 | fDDLModuleMap(NULL), |
61a57d07 | 106 | fALaddersOff(0), |
107 | fCLaddersOff(0), | |
f67db810 | 108 | fLdcId(0), |
c4d90345 | 109 | fRunId(0), |
110 | fPedestalThresholdFactor(fgkPedestalThresholdFactor) , | |
be4f467e | 111 | fCmThresholdFactor(fgkCmThresholdFactor), |
112 | fZsDefault(-1), | |
113 | fOffsetDefault(INT_MAX), | |
61a57d07 | 114 | fZsMinimum(2), |
115 | fMergeBCLists(1), | |
be4f467e | 116 | fZsFactor(3.0) |
f67db810 | 117 | { |
c4d90345 | 118 | if (!Init(rdfname)) AliError("AliITSHandleDaSSD::AliITSHandleDaSSD() initialization error!"); |
f67db810 | 119 | } |
120 | ||
121 | ||
c4d90345 | 122 | //______________________________________________________________________________ |
f67db810 | 123 | AliITSHandleDaSSD::AliITSHandleDaSSD(const AliITSHandleDaSSD& ssdadldc) : |
124 | TObject(ssdadldc), | |
b99cb574 | 125 | fRawDataFileName(NULL), |
f67db810 | 126 | fNumberOfModules(ssdadldc.fNumberOfModules), |
a69c8ba0 | 127 | fModules(NULL), |
c4d90345 | 128 | fModIndProcessed(ssdadldc.fModIndProcessed), |
129 | fModIndRead(ssdadldc.fModIndRead), | |
2e2c6def | 130 | fModIndex(NULL), |
b99cb574 | 131 | fEqIndex(ssdadldc.fEqIndex), |
c4d90345 | 132 | fNumberOfEvents(ssdadldc.fNumberOfEvents), |
61a57d07 | 133 | fBadChannelsList(NULL), |
134 | fDDLModuleMap(NULL), | |
135 | fALaddersOff(ssdadldc.fALaddersOff), | |
136 | fCLaddersOff(ssdadldc.fCLaddersOff), | |
f67db810 | 137 | fLdcId(ssdadldc.fLdcId), |
c4d90345 | 138 | fRunId(ssdadldc.fRunId), |
139 | fPedestalThresholdFactor(ssdadldc.fPedestalThresholdFactor), | |
be4f467e | 140 | fCmThresholdFactor(ssdadldc.fCmThresholdFactor), |
141 | fZsDefault(ssdadldc.fZsDefault), | |
142 | fOffsetDefault(ssdadldc.fOffsetDefault), | |
61a57d07 | 143 | fZsMinimum(ssdadldc.fZsMinimum), |
144 | fMergeBCLists(ssdadldc.fMergeBCLists), | |
be4f467e | 145 | fZsFactor(ssdadldc.fZsFactor) |
f67db810 | 146 | { |
147 | // copy constructor | |
b99cb574 | 148 | if (ssdadldc.fRawDataFileName) { |
149 | fRawDataFileName = new (nothrow) Char_t[strlen(ssdadldc.fRawDataFileName)+1]; | |
150 | if (fRawDataFileName) strncpy(fRawDataFileName, ssdadldc.fRawDataFileName, strlen(ssdadldc.fRawDataFileName)+1); | |
151 | } else fRawDataFileName = NULL; | |
a69c8ba0 | 152 | if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) { |
153 | fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules]; | |
154 | if (fModules) { | |
155 | for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) { | |
156 | if (ssdadldc.fModules[modind]) { | |
157 | fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind])); | |
158 | if (!fModules[modind]) { | |
159 | AliError("AliITSHandleDaSSD: Error copy constructor"); | |
160 | for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind]; | |
161 | delete [] fModules; | |
162 | fModules = NULL; | |
163 | break; | |
164 | } | |
165 | } else fModules[modind] = NULL; | |
166 | } | |
167 | } else { | |
168 | AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules)); | |
169 | fNumberOfModules = 0; | |
170 | fModules = NULL; | |
171 | } | |
172 | } | |
b99cb574 | 173 | if (ssdadldc.fModIndex) { |
174 | fModIndex = new (nothrow) Int_t [ssdadldc.fNumberOfModules]; | |
175 | if (fModIndex) memcpy(fModIndex, ssdadldc.fModIndex, ssdadldc.fNumberOfModules*sizeof(Int_t)); | |
176 | } else fModIndex = NULL; | |
177 | fBadChannelsList = new AliITSBadChannelsSSDv2(*ssdadldc.fBadChannelsList); | |
178 | if (ssdadldc.fDDLModuleMap) { | |
179 | fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl]; | |
180 | if (fDDLModuleMap) memcpy(fDDLModuleMap, ssdadldc.fDDLModuleMap, fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl * sizeof(Int_t)); | |
181 | } else fDDLModuleMap = NULL; | |
f67db810 | 182 | |
b99cb574 | 183 | // if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by copy constructor, use other methods to init it!"); |
184 | // if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by copy constructor, use other methods to init it!"); | |
185 | } | |
f67db810 | 186 | |
c4d90345 | 187 | //______________________________________________________________________________ |
f67db810 | 188 | AliITSHandleDaSSD& AliITSHandleDaSSD::operator = (const AliITSHandleDaSSD& ssdadldc) |
189 | { | |
190 | // assignment operator | |
a69c8ba0 | 191 | if (this == &ssdadldc) return *this; |
61a57d07 | 192 | TObject::operator=(ssdadldc); |
a69c8ba0 | 193 | if (fModules) { |
194 | for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i]; | |
195 | delete [] fModules; | |
196 | fModules = NULL; | |
197 | } | |
2e2c6def | 198 | if (fModIndex) { delete [] fModIndex; fModIndex = NULL; } |
79710a18 | 199 | fNumberOfModules = ssdadldc.fNumberOfModules; |
200 | if ((fNumberOfModules > 0) && (ssdadldc.fModules)) { | |
201 | fModules = new (nothrow) AliITSModuleDaSSD* [fNumberOfModules]; | |
a69c8ba0 | 202 | if (fModules) { |
79710a18 | 203 | for (Int_t modind = 0; modind < fNumberOfModules; modind++) { |
a69c8ba0 | 204 | if (ssdadldc.fModules[modind]) { |
61a57d07 | 205 | fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind])); |
206 | if (!fModules[modind]) { | |
207 | AliError("AliITSHandleDaSSD: Error assignment operator"); | |
a69c8ba0 | 208 | for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind]; |
61a57d07 | 209 | delete [] fModules; |
210 | fModules = NULL; | |
211 | break; | |
212 | } | |
213 | } else fModules[modind] = NULL; | |
a69c8ba0 | 214 | } |
215 | } else { | |
216 | AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules)); | |
217 | fNumberOfModules = 0; | |
218 | fModules = NULL; | |
219 | } | |
220 | } | |
b99cb574 | 221 | if(fRawDataFileName)delete[]fRawDataFileName; |
304a787e | 222 | if (ssdadldc.fRawDataFileName) { |
223 | fRawDataFileName = new (nothrow) Char_t[strlen(ssdadldc.fRawDataFileName)+1]; | |
224 | if (fRawDataFileName) strncpy(fRawDataFileName, ssdadldc.fRawDataFileName, strlen(ssdadldc.fRawDataFileName)+1); | |
b99cb574 | 225 | } else fRawDataFileName = NULL; |
304a787e | 226 | fModIndProcessed = ssdadldc.fModIndProcessed; |
227 | fModIndRead = ssdadldc.fModIndRead; | |
228 | ||
229 | if (ssdadldc.fModIndex) { | |
230 | fModIndex = new (nothrow) Int_t [ssdadldc.fNumberOfModules]; | |
231 | if (fModIndex) memcpy(fModIndex, ssdadldc.fModIndex, ssdadldc.fNumberOfModules*sizeof(Int_t)); | |
b99cb574 | 232 | } else fModIndex = NULL; |
304a787e | 233 | |
61a57d07 | 234 | fEqIndex = ssdadldc.fEqIndex; |
235 | fNumberOfEvents = ssdadldc.fNumberOfEvents; | |
236 | fLdcId = ssdadldc.fLdcId; | |
237 | fRunId = ssdadldc.fRunId; | |
238 | fPedestalThresholdFactor = ssdadldc.fPedestalThresholdFactor; | |
239 | fCmThresholdFactor = ssdadldc.fCmThresholdFactor; | |
240 | fZsDefault = ssdadldc.fZsDefault; | |
241 | fOffsetDefault = ssdadldc.fOffsetDefault; | |
242 | fZsMinimum = ssdadldc.fZsMinimum; | |
243 | fMergeBCLists = ssdadldc.fMergeBCLists; | |
244 | fZsFactor = ssdadldc.fZsFactor; | |
245 | fALaddersOff = ssdadldc.fALaddersOff; | |
246 | fCLaddersOff = ssdadldc.fCLaddersOff; | |
304a787e | 247 | if (fBadChannelsList) delete fBadChannelsList; |
248 | fBadChannelsList = new AliITSBadChannelsSSDv2(*ssdadldc.fBadChannelsList); | |
249 | if (fDDLModuleMap) delete [] fDDLModuleMap; | |
250 | if (ssdadldc.fDDLModuleMap) { | |
251 | fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl]; | |
252 | if (fDDLModuleMap) memcpy(fDDLModuleMap, ssdadldc.fDDLModuleMap, fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl * sizeof(Int_t)); | |
b99cb574 | 253 | } else fDDLModuleMap = NULL; |
304a787e | 254 | |
b99cb574 | 255 | // if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by assignment operator, use other methods to init it!"); |
256 | // if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by assignment operator, use other methods to init it!"); | |
f67db810 | 257 | return *this; |
258 | } | |
259 | ||
260 | ||
c4d90345 | 261 | //______________________________________________________________________________ |
f67db810 | 262 | AliITSHandleDaSSD::~AliITSHandleDaSSD() |
223dda26 | 263 | { |
264 | // Default destructor | |
b99cb574 | 265 | delete []fRawDataFileName; |
f67db810 | 266 | if (fModules) |
267 | { | |
268 | for (Int_t i = 0; i < fNumberOfModules; i++) | |
269 | { | |
270 | if (fModules[i]) delete fModules[i]; | |
271 | } | |
272 | delete [] fModules; | |
273 | } | |
2e2c6def | 274 | if (fModIndex) delete [] fModIndex; |
61a57d07 | 275 | if (fBadChannelsList) delete fBadChannelsList; |
6e7691a5 | 276 | if (fDDLModuleMap) delete [] fDDLModuleMap; |
f67db810 | 277 | } |
278 | ||
279 | ||
280 | ||
c4d90345 | 281 | //______________________________________________________________________________ |
282 | void AliITSHandleDaSSD::Reset() | |
283 | { | |
284 | // Delete array of AliITSModuleDaSSD* objects. | |
285 | if (fModules) { | |
286 | for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i]; | |
287 | delete [] fModules; | |
288 | fModules = NULL; | |
2e2c6def | 289 | } |
290 | if (fModIndex) { delete [] fModIndex; fModIndex = NULL; } | |
6e7691a5 | 291 | /* |
61a57d07 | 292 | if (fBadChannelsList) { |
293 | delete fBadChannelsList; | |
294 | fBadChannelsList = NULL; | |
6e7691a5 | 295 | } |
296 | if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL; } | |
297 | */ | |
61a57d07 | 298 | fALaddersOff.Set(0); |
299 | fCLaddersOff.Set(0); | |
b99cb574 | 300 | if(fRawDataFileName){ |
301 | delete []fRawDataFileName; | |
302 | fRawDataFileName = NULL; | |
303 | } | |
c4d90345 | 304 | fModIndProcessed = fModIndRead = 0; |
305 | fNumberOfEvents = 0; | |
306 | fLdcId = fRunId = 0; | |
307 | fPedestalThresholdFactor = fgkPedestalThresholdFactor; | |
308 | fCmThresholdFactor = fgkCmThresholdFactor; | |
309 | } | |
310 | ||
311 | ||
312 | ||
313 | //______________________________________________________________________________ | |
be4f467e | 314 | Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname) |
c4d90345 | 315 | { |
316 | // Read raw data file and set initial and configuration parameters | |
317 | Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0; | |
318 | Int_t nofeqipmentev, nofeqipment = 0, eqn = 0; | |
319 | AliRawReaderDate *rawreaderdate = NULL; | |
320 | UChar_t *data = NULL; | |
321 | Long_t datasize = 0, eqbelsize = 1; | |
322 | ||
c4d90345 | 323 | rawreaderdate = new AliRawReaderDate(rdfname, 0); |
324 | if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) { | |
325 | AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname)); | |
326 | MakeZombie(); | |
327 | return kFALSE; | |
371588bb | 328 | } |
c4d90345 | 329 | if (rawreaderdate->NextEvent()) { |
c4d90345 | 330 | fRunId = rawreaderdate->GetRunNumber(); |
331 | rawreaderdate->RewindEvents(); | |
332 | } else { MakeZombie(); return kFALSE; } | |
333 | if (fModules) Reset(); | |
61a57d07 | 334 | //rawreaderdate->SelectEvents(-1); |
371588bb | 335 | rawreaderdate->Select("ITSSSD"); |
c4d90345 | 336 | nofstrips = 0; |
337 | while (rawreaderdate->NextEvent()) { | |
338 | if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue; | |
339 | nofstripsev = 0; | |
340 | nofeqipmentev = 0; | |
341 | while (rawreaderdate->ReadNextData(data)) { | |
2e2c6def | 342 | fLdcId = rawreaderdate->GetLDCId(); |
c4d90345 | 343 | nofeqipmentev += 1; |
344 | datasize = rawreaderdate->GetDataSize(); | |
345 | eqbelsize = rawreaderdate->GetEquipmentElementSize(); | |
371588bb | 346 | if ( datasize % eqbelsize ) { |
a5a317a9 | 347 | AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %ld is not an integer of equipment data size %ld", |
c4d90345 | 348 | rdfname, datasize, eqbelsize)); |
349 | MakeZombie(); | |
be4f467e | 350 | return kFALSE; |
c4d90345 | 351 | } |
371588bb | 352 | nofstripsev += (Int_t) (datasize / eqbelsize); |
c4d90345 | 353 | } |
354 | if (physeventind++) { | |
a5a317a9 | 355 | if (nofstrips != nofstripsev) AliWarning(Form("AliITSHandleDaSSD: number of strips varies from event to event, ev = %ld, %ld", |
371588bb | 356 | physeventind, nofstripsev)); |
357 | if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to event"); | |
c4d90345 | 358 | } |
359 | nofstrips = nofstripsev; | |
360 | nofeqipment = nofeqipmentev; | |
371588bb | 361 | if (strn < nofstrips) strn = nofstrips; |
c4d90345 | 362 | if (eqn < nofeqipment) eqn = nofeqipment; |
363 | } | |
364 | delete rawreaderdate; | |
365 | if ((physeventind > 0) && (strn > 0)) | |
366 | { | |
367 | fNumberOfEvents = physeventind; | |
b99cb574 | 368 | if(rdfname){ |
369 | delete []fRawDataFileName; | |
370 | fRawDataFileName = new Char_t[strlen(rdfname)+1]; | |
371 | strncpy(fRawDataFileName,rdfname,strlen(rdfname)+1); | |
372 | } | |
61a57d07 | 373 | fEqIndex.Set(eqn); |
374 | fEqIndex.Reset(-1); | |
2e2c6def | 375 | fModIndex = new (nothrow) Int_t [fgkNumberOfSSDModulesPerDdl * eqn]; |
376 | if (fModIndex) | |
377 | for (Int_t i = 0; i < fgkNumberOfSSDModulesPerDdl * eqn; i++) fModIndex[i] = -1; | |
378 | else AliWarning(Form("AliITSHandleDaSSD: Error Init(%s): Index array for %i modules was not created", | |
379 | rdfname, fgkNumberOfSSDModulesPerDdl * eqn)); | |
371588bb | 380 | if (SetNumberOfModules(fgkNumberOfSSDModulesPerDdl * eqn)) { |
a5a317a9 | 381 | TString str = TString::Format("Max number of equipment: %d, max number of channels: %ld\n", eqn, strn); |
c4d90345 | 382 | DumpInitData(str.Data()); |
383 | return kTRUE; | |
384 | } | |
385 | } | |
386 | MakeZombie(); | |
387 | return kFALSE; | |
388 | } | |
389 | ||
390 | ||
c4d90345 | 391 | |
392 | //______________________________________________________________________________ | |
f67db810 | 393 | AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const |
394 | { | |
223dda26 | 395 | // Retrieve AliITSModuleDaSSD object from the array |
f67db810 | 396 | if (!fModules) return NULL; |
397 | for (Int_t i = 0; i < fNumberOfModules; i++) { | |
398 | if (fModules[i]) { | |
399 | if ( (fModules[i]->GetDdlId() == ddlID) | |
400 | && (fModules[i]->GetAD() == ad) | |
401 | && (fModules[i]->GetADC() == adc)) | |
402 | return fModules[i]; | |
403 | } | |
404 | } | |
405 | return NULL; | |
406 | } | |
407 | ||
408 | ||
c4d90345 | 409 | Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const |
410 | { | |
411 | // Retrieve the position of AliITSModuleDaSSD object in the array | |
412 | if (!fModules) return -1; | |
413 | for (Int_t i = 0; i < fNumberOfModules; i++) { | |
414 | if (fModules[i]) { | |
415 | if ( (fModules[i]->GetDdlId() == ddlID) | |
416 | && (fModules[i]->GetAD() == ad) | |
417 | && (fModules[i]->GetADC() == adc)) | |
418 | return i; | |
419 | } | |
420 | } | |
421 | return -1; | |
422 | } | |
423 | ||
424 | ||
f67db810 | 425 | |
c4d90345 | 426 | //______________________________________________________________________________ |
f67db810 | 427 | AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const |
428 | { | |
223dda26 | 429 | // Retrieve AliITSChannalDaSSD object from the array |
f67db810 | 430 | for (Int_t modind = 0; modind < fNumberOfModules; modind++) { |
431 | if ( (fModules[modind]->GetDdlId() == ddlID) | |
432 | && (fModules[modind]->GetAD() == ad) | |
433 | && (fModules[modind]->GetADC() == adc) ) | |
434 | { | |
435 | return fModules[modind]->GetStrip(stripID); | |
436 | } | |
437 | } | |
c4d90345 | 438 | AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!", |
439 | ddlID, ad, adc, stripID)); | |
f67db810 | 440 | return NULL; |
441 | } | |
442 | ||
443 | ||
444 | ||
c4d90345 | 445 | //______________________________________________________________________________ |
f67db810 | 446 | Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index) |
447 | { | |
223dda26 | 448 | // Assign array element with AliITSModuleDaSSD object |
f67db810 | 449 | if ((index < fNumberOfModules) && (index >= 0)) |
450 | { | |
451 | if (fModules[index]) delete fModules[index]; | |
452 | fModules[index] = module; | |
453 | return kTRUE; | |
454 | } | |
455 | else return kFALSE; | |
456 | } | |
457 | ||
458 | ||
c4d90345 | 459 | |
460 | //______________________________________________________________________________ | |
f67db810 | 461 | Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules) |
462 | { | |
223dda26 | 463 | // Allocates memory for AliITSModuleDaSSD objects |
464 | if (numberofmodules > fgkNumberOfSSDModules) | |
c4d90345 | 465 | AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD", |
466 | numberofmodules, fgkNumberOfSSDModules)); | |
467 | if (fModules) { | |
468 | for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i]; | |
469 | delete [] fModules; | |
470 | fModules = NULL; | |
471 | } | |
223dda26 | 472 | fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules]; |
473 | if (fModules) { | |
474 | fNumberOfModules = numberofmodules; | |
475 | memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules); | |
476 | return kTRUE; | |
477 | } else { | |
c4d90345 | 478 | AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules)); |
f67db810 | 479 | fNumberOfModules = 0; |
480 | fModules = NULL; | |
223dda26 | 481 | } |
f67db810 | 482 | return kFALSE; |
483 | } | |
484 | ||
485 | ||
c4d90345 | 486 | |
6e7691a5 | 487 | //______________________________________________________________________________ |
488 | Bool_t AliITSHandleDaSSD::ReadStaticBadChannelsMap(const Char_t *filename) | |
489 | { | |
490 | // Reads Static Bad Channels Map from the file | |
491 | TFile *bcfile; | |
492 | if (!filename) { | |
493 | AliWarning("No file name is specified for Static Bad Channels Map!"); | |
494 | return kFALSE; | |
495 | } | |
496 | bcfile = new TFile(filename, "READ"); | |
497 | if (bcfile->IsZombie()) { | |
498 | AliWarning(Form("Error reading file %s with Static Bad Channels Map!", filename)); | |
499 | return kFALSE; | |
500 | } | |
88128115 | 501 | bcfile->GetObject("AliITSBadChannelsSSDv2;1", fBadChannelsList); |
61a57d07 | 502 | if (!fBadChannelsList) { |
503 | AliWarning("Error fBadChannelsList == NULL!"); | |
6e7691a5 | 504 | bcfile->Close(); |
505 | delete bcfile; | |
506 | return kFALSE; | |
507 | } | |
508 | bcfile->Close(); | |
509 | delete bcfile; | |
510 | return kTRUE; | |
511 | } | |
512 | ||
513 | ||
514 | ||
515 | Bool_t AliITSHandleDaSSD::ReadDDLModuleMap(const Char_t *filename) | |
516 | { | |
517 | // Reads the SSD DDL Map from the file | |
518 | ifstream ddlmfile; | |
519 | AliRawReaderDate *rwr = NULL; | |
520 | AliITSRawStreamSSD *rsm = NULL; | |
521 | void *event = NULL; | |
522 | if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;} | |
523 | fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl]; | |
524 | if (!fDDLModuleMap) { | |
525 | AliWarning("Error allocation memory for DDL Map!"); | |
526 | return kFALSE; | |
527 | } | |
528 | if (!filename) { | |
529 | AliWarning("No file name is specified for SSD DDL Map, using the one from AliITSRawStreamSSD!"); | |
530 | rwr = new AliRawReaderDate(event); | |
531 | rsm = new AliITSRawStreamSSD(rwr); | |
532 | rsm->Setv11HybridDDLMapping(); | |
533 | for (Int_t ddli = 0; ddli < fgkNumberOfSSDDDLs; ddli++) | |
534 | for (Int_t mi = 0; mi < fgkNumberOfSSDModulesPerDdl; mi++) | |
535 | fDDLModuleMap[(ddli * fgkNumberOfSSDModulesPerDdl + mi)] = rsm->GetModuleNumber(ddli, mi); | |
536 | if (rsm) delete rsm; | |
537 | if (rwr) delete rwr; | |
538 | return kTRUE; | |
539 | } | |
540 | ddlmfile.open(filename, ios::in); | |
541 | if (!ddlmfile.is_open()) { | |
542 | AliWarning(Form("Error reading file %s with SSD DDL Map!", filename)); | |
543 | if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;} | |
544 | return kFALSE; | |
545 | } | |
546 | Int_t ind = 0; | |
547 | while((!ddlmfile.eof()) && (ind < (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))) { | |
548 | ddlmfile >> fDDLModuleMap[ind++]; | |
a5a317a9 | 549 | if (ddlmfile.fail()) AliError(Form("Error extracting number from the DDL map file %s, ind: %d ", filename, ind)); |
6e7691a5 | 550 | } |
551 | if (ind != (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl)) | |
552 | AliWarning(Form("Only %i (< %i) entries were read from DDL Map!", ind, (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))); | |
553 | ddlmfile.close(); | |
554 | return kTRUE; | |
555 | } | |
556 | ||
557 | ||
558 | ||
c4d90345 | 559 | //______________________________________________________________________________ |
371588bb | 560 | Int_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber) |
f67db810 | 561 | { |
223dda26 | 562 | // Reads raw data from file |
c4d90345 | 563 | if (!Init(fileName)){ |
564 | AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile"); | |
f67db810 | 565 | return kFALSE; |
566 | } | |
371588bb | 567 | fNumberOfEvents = eventsnumber; |
568 | return ReadModuleRawData (fNumberOfModules); | |
f67db810 | 569 | } |
570 | ||
571 | ||
c4d90345 | 572 | |
573 | //______________________________________________________________________________ | |
574 | Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber) | |
575 | { | |
576 | // Reads raw data from file | |
371588bb | 577 | AliRawReader *rawreaderdate = NULL; |
578 | AliITSRawStreamSSD *stream = NULL; | |
c4d90345 | 579 | AliITSModuleDaSSD *module; |
580 | AliITSChannelDaSSD *strip; | |
371588bb | 581 | Long_t eventind = 0; |
61a57d07 | 582 | Int_t nofeqipment, eqind; |
583 | Short_t equipid, prequipid; | |
584 | Short_t modind; | |
c4d90345 | 585 | if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0; |
586 | if (!fModules) { | |
587 | AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data"); | |
588 | return 0; | |
589 | } | |
6e7691a5 | 590 | if (!fDDLModuleMap) if (!ReadDDLModuleMap()) AliWarning("DDL map is not defined, ModuleID will be set to 0!"); |
371588bb | 591 | stream = new AliITSRawStreamSSD(rawreaderdate); |
592 | stream->Setv11HybridDDLMapping(); | |
61a57d07 | 593 | //rawreaderdate->SelectEvents(-1); |
594 | rawreaderdate->Select("ITSSSD"); | |
c4d90345 | 595 | modind = 0; |
61a57d07 | 596 | nofeqipment = 0; |
c4d90345 | 597 | while (rawreaderdate->NextEvent()) { |
598 | if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue; | |
371588bb | 599 | prequipid = -1; |
61a57d07 | 600 | eqind = -1; |
371588bb | 601 | while (stream->Next()) { |
61a57d07 | 602 | equipid = rawreaderdate->GetEquipmentId(); |
603 | if ((equipid != prequipid)) { | |
604 | if ((eqind = GetEqIndex(equipid)) < 0) { fEqIndex.AddAt(equipid, nofeqipment); eqind = nofeqipment++; } | |
605 | prequipid = equipid; | |
606 | } | |
371588bb | 607 | Int_t equiptype = rawreaderdate->GetEquipmentType(); |
608 | UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID(); | |
609 | UChar_t ad = stream->GetAD(); | |
610 | UChar_t adc = stream->GetADC(); | |
611 | UShort_t stripID = stream->GetSideFlag() ? AliITSChannelDaSSD::GetMaxStripIdConst() - stream->GetStrip() : stream->GetStrip(); | |
612 | Short_t signal = stream->GetSignal(); | |
613 | ||
61a57d07 | 614 | Int_t indpos = (eqind * fgkNumberOfSSDModulesPerDdl) |
371588bb | 615 | + ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2)); |
616 | Int_t modpos = fModIndex[indpos]; | |
617 | if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue; | |
618 | if ((modpos < 0) && (modind < modulesnumber)) { | |
619 | module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst()); | |
6e7691a5 | 620 | Int_t mddli; |
621 | if (fDDLModuleMap) mddli = RetrieveModuleId(ddlID, ad, adc); | |
622 | else mddli = 0; | |
61a57d07 | 623 | if (!module->SetModuleIdData (ddlID, ad, adc, mddli)) return 0; |
624 | module->SetModuleRorcId (equipid, equiptype); | |
61a57d07 | 625 | modpos = fModIndRead + modind; |
626 | modind += 1; | |
627 | fModules[modpos] = module; | |
628 | fModIndex[indpos] = modpos; | |
371588bb | 629 | } |
630 | if (stripID < AliITSModuleDaSSD::GetStripsPerModuleConst()) { | |
c4d90345 | 631 | if (!(strip = fModules[modpos]->GetStrip(stripID))) { |
632 | strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents); | |
633 | fModules[modpos]->SetStrip(strip, stripID); | |
634 | } | |
635 | strip->SetSignal(eventind, signal); | |
59087bde | 636 | } else { |
637 | if (!(fModules[modpos]->GetCMFerom())) { | |
638 | fModules[modpos]->AllocateCMFeromArray(); | |
639 | fModules[modpos]->SetCMFeromEventsNumber(fNumberOfEvents); | |
640 | } | |
641 | fModules[modpos]->SetCMFerom(signal, (stripID - AliITSModuleDaSSD::GetStripsPerModuleConst()), eventind); | |
642 | } | |
c4d90345 | 643 | } |
644 | if (++eventind > fNumberOfEvents) break; | |
645 | } | |
371588bb | 646 | delete stream; |
c4d90345 | 647 | delete rawreaderdate; |
648 | if (modind) cout << "The memory was allocated for " << modind << " modules." << endl; | |
649 | fModIndRead += modind; | |
650 | if (modind < modulesnumber) RelocateModules(); | |
651 | return modind; | |
652 | } | |
653 | ||
654 | ||
655 | ||
656 | //______________________________________________________________________________ | |
f67db810 | 657 | Bool_t AliITSHandleDaSSD::RelocateModules() |
223dda26 | 658 | { |
659 | // Relocate memory for AliITSModuleDaSSD object array | |
f67db810 | 660 | Int_t nm = 0; |
223dda26 | 661 | AliITSModuleDaSSD **marray = NULL; |
f67db810 | 662 | for (Int_t modind = 0; modind < fNumberOfModules; modind++) |
663 | if (fModules[modind]) nm += 1; | |
664 | if (nm == fNumberOfModules) return kTRUE; | |
223dda26 | 665 | marray = new (nothrow) AliITSModuleDaSSD* [nm]; |
666 | if (!marray) { | |
c4d90345 | 667 | AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm)); |
f67db810 | 668 | return kFALSE; |
669 | } | |
670 | nm = 0; | |
671 | for (Int_t modind = 0; modind < fNumberOfModules; modind++) | |
672 | if (fModules[modind]) marray[nm++] = fModules[modind]; | |
673 | delete [] fModules; | |
674 | fModules = marray; | |
c4d90345 | 675 | fNumberOfModules = fModIndRead = nm; |
f67db810 | 676 | return kTRUE; |
677 | } | |
678 | ||
679 | ||
c4d90345 | 680 | |
371588bb | 681 | //______________________________________________________________________________ |
292c304e | 682 | Bool_t AliITSHandleDaSSD::AddFeromCm(const AliITSModuleDaSSD *const module) |
371588bb | 683 | { |
292c304e | 684 | // Restore the original signal value adding CM calculated and subtracted in ferom |
371588bb | 685 | AliITSChannelDaSSD *strip; |
686 | Short_t *signal, *cmferom; | |
687 | ||
688 | if (!module) return kFALSE; | |
59087bde | 689 | if (!module->GetCMFerom()) return kTRUE; |
371588bb | 690 | for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) { |
691 | if (!(cmferom = module->GetCMFerom(chipind))) { | |
692 | AliWarning(Form("AliITSHandleDaSSD: There is no Ferom CM values for chip %i, module %i!", chipind, module->GetModuleId())); | |
693 | continue; | |
694 | } | |
695 | for (Int_t strind = (chipind * AliITSModuleDaSSD::GetStripsPerChip()); | |
696 | strind < ((chipind + 1) * AliITSModuleDaSSD::GetStripsPerChip()); strind++) { | |
697 | if (!(strip = module->GetStrip(strind))) continue; | |
698 | if (!(signal = strip->GetSignal())) continue; | |
699 | // if (strip->GetEventsNumber() != module->GetEventsNumber()) return kFALSE; | |
700 | Long_t ovev = 0; | |
701 | for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) { | |
702 | if (SignalOutOfRange(signal[ev]) || SignalOutOfRange(cmferom[ev])) ovev += 1; | |
703 | else { | |
704 | Short_t signal1 = signal[ev] + cmferom[ev]; | |
705 | strip->SetSignal(ev, signal1); | |
61a57d07 | 706 | } |
371588bb | 707 | } |
708 | } | |
709 | } | |
710 | return kTRUE; | |
711 | } | |
712 | ||
713 | ||
714 | ||
c4d90345 | 715 | //______________________________________________________________________________ |
292c304e | 716 | Bool_t AliITSHandleDaSSD::CalculatePedestal(const AliITSModuleDaSSD *const module) |
f67db810 | 717 | { |
223dda26 | 718 | // Calculates Pedestal |
f67db810 | 719 | AliITSChannelDaSSD *strip; |
d86972f6 | 720 | Double_t pedestal, noise; |
c4d90345 | 721 | Short_t *signal; |
722 | Long_t ovev, ev, n; | |
723 | if (!module) return kFALSE; | |
724 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
725 | if (!(strip = module->GetStrip(strind))) continue; | |
726 | if (!(signal = strip->GetSignal())) { | |
727 | AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()", | |
728 | module->GetModuleId(), strind)); | |
729 | continue; | |
f67db810 | 730 | } |
c4d90345 | 731 | //************* pedestal first pass **************** |
d86972f6 | 732 | pedestal = 0.0L; |
c4d90345 | 733 | ovev = 0l; |
734 | for (ev = 0; ev < strip->GetEventsNumber(); ev++) | |
735 | if (SignalOutOfRange(signal[ev])) ovev += 1; | |
d86972f6 | 736 | else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1) : signal[ev]; |
c4d90345 | 737 | if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue(); |
d86972f6 | 738 | strip->SetPedestal(static_cast<Float_t>(pedestal)); |
c4d90345 | 739 | //************* noise ******************************* |
740 | Double_t nsum = 0.0L; | |
741 | ovev = 0l; | |
742 | for (ev = 0; ev < strip->GetEventsNumber(); ev++) { | |
743 | if (SignalOutOfRange(signal[ev])) ovev += 1; | |
744 | else nsum += pow((signal[ev] - strip->GetPedestal()), 2); | |
745 | } | |
7ab0e0a5 | 746 | if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / (Double_t)(n)); |
c4d90345 | 747 | else noise = AliITSChannelDaSSD::GetUndefinedValue(); |
d86972f6 | 748 | strip->SetNoise(static_cast<Float_t>(noise)); |
c4d90345 | 749 | //************* pedestal second pass **************** |
d86972f6 | 750 | pedestal = 0.0L; |
c4d90345 | 751 | ovev = 0l; |
752 | for (ev = 0; ev < strip->GetEventsNumber(); ev++) | |
753 | if ( SignalOutOfRange(signal[ev]) | |
754 | || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1; | |
d86972f6 | 755 | else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1) : signal[ev]; |
c4d90345 | 756 | if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue(); |
d86972f6 | 757 | strip->SetPedestal(static_cast<Float_t>(pedestal)); |
c4d90345 | 758 | strip->SetOverflowNumber(ovev); |
f67db810 | 759 | } |
760 | return kTRUE; | |
761 | } | |
762 | ||
763 | ||
c4d90345 | 764 | //______________________________________________________________________________ |
292c304e | 765 | Bool_t AliITSHandleDaSSD::CalculateNoise(const AliITSModuleDaSSD *const module) |
f67db810 | 766 | { |
223dda26 | 767 | // Calculates Noise |
f67db810 | 768 | AliITSChannelDaSSD *strip; |
769 | Short_t *signal; | |
770 | Float_t noise; | |
771 | Long_t ovev, n; | |
c4d90345 | 772 | if (!module) return kFALSE; |
773 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
774 | if (!(strip = module->GetStrip(strind))) continue; | |
775 | if (!(signal = strip->GetSignal())) { | |
776 | strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue()); | |
777 | AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()", | |
778 | module->GetModuleId(), strind)); | |
779 | continue; | |
f67db810 | 780 | } |
c4d90345 | 781 | Double_t nsum = 0.0L; |
782 | ovev = 0l; | |
783 | for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) { | |
784 | if (SignalOutOfRange(signal[ev])) ovev += 1; | |
785 | else nsum += pow((signal[ev] - strip->GetPedestal()), 2); | |
786 | } | |
7ab0e0a5 | 787 | if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = static_cast<Float_t>(TMath::Sqrt(nsum / (Float_t)(n))); |
c4d90345 | 788 | else noise = AliITSChannelDaSSD::GetUndefinedValue(); |
789 | strip->SetNoise(noise); | |
f67db810 | 790 | } |
791 | return kTRUE; | |
792 | } | |
793 | ||
794 | ||
795 | ||
c4d90345 | 796 | //______________________________________________________________________________ |
797 | Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module) | |
f67db810 | 798 | { |
c4d90345 | 799 | // Calculates Noise with CM correction |
800 | AliITSChannelDaSSD *strip = NULL; | |
801 | Short_t *signal; | |
802 | Float_t noise; | |
803 | Long_t ovev, n; | |
804 | if (!CalculateCM(module)) { | |
805 | AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE"); | |
806 | return kFALSE; | |
807 | } | |
808 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
809 | if (!(strip = module->GetStrip(strind))) continue; //return kFALSE; | |
810 | if (!(signal = strip->GetSignal())) { | |
811 | strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue()); | |
d86972f6 | 812 | AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCM(): there are no events data for module[%i] strip[%i]->GetSignal()", |
c4d90345 | 813 | module->GetModuleId(), strind)); |
2e2c6def | 814 | continue; //return kFALSE; |
f67db810 | 815 | } |
c4d90345 | 816 | Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip(); |
817 | Double_t nsum = 0.0L; | |
818 | ovev = 0l; | |
819 | for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) { | |
820 | if (SignalOutOfRange(signal[ev])) ovev += 1; | |
821 | else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2); | |
822 | } | |
7ab0e0a5 | 823 | if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = static_cast<Float_t>(TMath::Sqrt(nsum / (Double_t)(n))); |
c4d90345 | 824 | else noise = AliITSChannelDaSSD::GetUndefinedValue(); |
825 | strip->SetNoiseCM(noise); | |
826 | } | |
2e2c6def | 827 | return kTRUE; |
f67db810 | 828 | } |
829 | ||
830 | ||
831 | ||
c4d90345 | 832 | //______________________________________________________________________________ |
833 | Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module) | |
f67db810 | 834 | { |
c4d90345 | 835 | // Calculates CM |
f67db810 | 836 | AliITSChannelDaSSD *strip = NULL; |
c4d90345 | 837 | Short_t *signal; |
838 | Long_t ovstr, n; | |
839 | Int_t stripind; | |
840 | module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst()); | |
841 | for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) { | |
842 | stripind = chipind * module->GetStripsPerChip(); | |
371588bb | 843 | module->GetCM()[chipind].Set(fNumberOfEvents); |
844 | module->GetCM()[chipind].Reset(0.0f); | |
c4d90345 | 845 | for (Long_t ev = 0; ev < fNumberOfEvents; ev++) { |
846 | // calculate firs approximation of CM. | |
847 | Double_t cm0 = 0.0L; | |
848 | ovstr = 0l; | |
849 | for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) { | |
850 | if (!(strip = module->GetStrip(strind))) continue; //return kFALSE; | |
851 | if (!(signal = strip->GetSignal())) { | |
852 | AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()", | |
853 | module->GetModuleId(), strind)); | |
854 | return kFALSE; | |
855 | } | |
61a57d07 | 856 | if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1; |
c4d90345 | 857 | else cm0 += (signal[ev] - strip->GetPedestal()); |
f67db810 | 858 | } |
c4d90345 | 859 | if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n); |
860 | else { module->SetCM(0.0f, chipind, ev); continue; } | |
861 | // calculate avarage (cm - (signal - pedestal)) over the chip | |
862 | Double_t cmsigma = 0.0L; | |
863 | ovstr = 0l; | |
864 | for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) { | |
865 | if (!(strip = module->GetStrip(strind))) continue; | |
866 | if (!(signal = strip->GetSignal())) { | |
867 | AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n", | |
868 | module->GetModuleId(), strind)); | |
869 | return kFALSE; | |
f67db810 | 870 | } |
61a57d07 | 871 | if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1; |
c4d90345 | 872 | else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2); |
f67db810 | 873 | } |
7ab0e0a5 | 874 | if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = TMath::Sqrt(cmsigma / (Float_t)(n)); |
c4d90345 | 875 | else { module->SetCM(0.0f, chipind, ev); continue; } |
876 | // calculate cm with threshold | |
877 | Double_t cmsum = 0.0L; | |
878 | ovstr = 0l; | |
879 | for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) { | |
880 | if (!(strip = module->GetStrip(strind))) continue; | |
881 | signal = strip->GetSignal(); | |
61a57d07 | 882 | if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue()) |
883 | || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1; | |
c4d90345 | 884 | else cmsum += (signal[ev] - strip->GetPedestal()); |
885 | } | |
886 | if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n); | |
887 | else cmsum = 0.0L; | |
59087bde | 888 | if (!(module->SetCM(cmsum, chipind, ev))) |
a5a317a9 | 889 | AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n", |
59087bde | 890 | module->GetModuleId(), chipind, ev)); |
c4d90345 | 891 | } |
892 | } | |
893 | return kTRUE; | |
894 | } | |
895 | ||
896 | ||
897 | //______________________________________________________________________________ | |
d86972f6 | 898 | Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread, const Bool_t usewelford) |
c4d90345 | 899 | { |
900 | // Performs calculation of calibration parameters (pedestal, noise, ...) | |
901 | Int_t nm = 0; | |
902 | if (nmread <= 0) return kFALSE; | |
903 | if (!fModules) return kFALSE; | |
904 | while ((nm = ReadModuleRawData(nmread)) > 0) { | |
905 | cout << "Processing next " << nm << " modules;" << endl; | |
906 | for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) { | |
907 | if (!fModules[modind]) { | |
908 | AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n", | |
909 | modind)); | |
910 | return kFALSE; | |
f67db810 | 911 | } |
371588bb | 912 | AddFeromCm(fModules[modind]); |
d86972f6 | 913 | if (usewelford) { |
914 | CalculatePedNoiseW(fModules[modind]); | |
915 | CalculateNoiseCMW(fModules[modind]); | |
916 | } else { | |
917 | CalculatePedestal(fModules[modind]); | |
918 | CalculateNoise(fModules[modind]); | |
919 | CalculateNoiseCM(fModules[modind]); | |
920 | } | |
f67db810 | 921 | } |
c4d90345 | 922 | DeleteSignal(); |
371588bb | 923 | DeleteCM(); |
924 | DeleteCMFerom(); | |
c4d90345 | 925 | fModIndProcessed = fModIndRead; |
926 | cout << fModIndProcessed << " - done" << endl; | |
d86972f6 | 927 | if (nm < nmread ) break; |
c4d90345 | 928 | } |
929 | return kTRUE; | |
f67db810 | 930 | } |
931 | ||
932 | ||
c4d90345 | 933 | //______________________________________________________________________________ |
934 | Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const | |
935 | { | |
936 | // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class | |
61a57d07 | 937 | if (!fDDLModuleMap) { |
938 | AliError("Error DDLMap is not initialized, return 0!"); | |
939 | return 0; | |
940 | } | |
6e7691a5 | 941 | Int_t mddli = ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2)); |
942 | if ((ddlID < fgkNumberOfSSDDDLs) && (mddli < fgkNumberOfSSDModulesPerDdl)) { | |
943 | mddli = fDDLModuleMap[ddlID * fgkNumberOfSSDModulesPerDdl + mddli]; | |
944 | } | |
c4d90345 | 945 | else { |
6e7691a5 | 946 | AliWarning(Form("Module index = %d or ddlID = %d is out of range 0 is rturned", ddlID, mddli)); |
947 | mddli = 0; | |
c4d90345 | 948 | } |
6e7691a5 | 949 | if (mddli > SHRT_MAX) return SHRT_MAX; |
950 | else return (Short_t)mddli; | |
c4d90345 | 951 | } |
952 | ||
f67db810 | 953 | |
c4d90345 | 954 | |
955 | //______________________________________________________________________________ | |
88128115 | 956 | AliITSNoiseSSDv2* AliITSHandleDaSSD::GetCalibrationOCDBNoise() const |
223dda26 | 957 | { |
958 | // Fill in the array for OCDB | |
88128115 | 959 | AliITSNoiseSSDv2 *ldcn = NULL; |
61a57d07 | 960 | AliITSModuleDaSSD *module = NULL; |
961 | AliITSChannelDaSSD *strip = NULL; | |
962 | if (!fModules) return NULL; | |
88128115 | 963 | ldcn = new AliITSNoiseSSDv2; |
61a57d07 | 964 | if (!ldcn) { |
88128115 | 965 | AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!"); |
61a57d07 | 966 | return NULL; |
967 | } | |
968 | for (Int_t i = 0; i < fNumberOfModules; i++) { | |
969 | if (!(module = fModules[i])) continue; | |
970 | if (module->GetModuleId() < fgkMinSSDModuleId) continue; | |
971 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
972 | if (!(strip = module->GetStrip(strind))) continue; | |
973 | Short_t modid = module->GetModuleId() - fgkMinSSDModuleId; | |
974 | if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) | |
975 | ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM()); | |
976 | else | |
977 | ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM()); | |
978 | } | |
979 | } | |
980 | return ldcn; | |
981 | } | |
982 | ||
983 | ||
984 | //______________________________________________________________________________ | |
88128115 | 985 | AliITSBadChannelsSSDv2* AliITSHandleDaSSD::GetCalibrationBadChannels() const |
61a57d07 | 986 | { |
987 | // Fill in the TObjArray with the list of bad channels | |
88128115 | 988 | AliITSBadChannelsSSDv2 *ldcbc = NULL; |
61a57d07 | 989 | AliITSModuleDaSSD *module = NULL; |
990 | AliITSChannelDaSSD *strip = NULL; | |
f67db810 | 991 | if (!fModules) return NULL; |
88128115 | 992 | ldcbc = new AliITSBadChannelsSSDv2; |
61a57d07 | 993 | if (!ldcbc) { |
88128115 | 994 | AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!"); |
61a57d07 | 995 | return NULL; |
996 | } | |
f67db810 | 997 | for (Int_t i = 0; i < fNumberOfModules; i++) { |
61a57d07 | 998 | if (!(module = fModules[i])) continue; |
999 | if (module->GetModuleId() < fgkMinSSDModuleId) continue; | |
1000 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
1001 | if (!(strip = module->GetStrip(strind))) continue; | |
1002 | Short_t modid = module->GetModuleId() - fgkMinSSDModuleId; | |
1003 | if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) | |
d86972f6 | 1004 | ldcbc->AddBadChannelP(modid, strip->GetStripId(), EvaluateIfChannelIsBad(module, strip->GetStripId())); |
61a57d07 | 1005 | else |
1006 | ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), | |
d86972f6 | 1007 | EvaluateIfChannelIsBad(module, strip->GetStripId())); |
f67db810 | 1008 | } |
f67db810 | 1009 | } |
61a57d07 | 1010 | return ldcbc; |
f67db810 | 1011 | } |
1012 | ||
1013 | ||
61a57d07 | 1014 | |
c4d90345 | 1015 | //______________________________________________________________________________ |
61a57d07 | 1016 | Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname) |
f67db810 | 1017 | { |
223dda26 | 1018 | // Save Calibration data locally |
88128115 | 1019 | AliITSBadChannelsSSDv2 *ldcbc = NULL; |
1020 | AliITSPedestalSSDv2 *ldcp = NULL; | |
1021 | AliITSNoiseSSDv2 *ldcn = NULL; | |
61a57d07 | 1022 | AliITSModuleDaSSD *module = NULL; |
1023 | AliITSChannelDaSSD *strip = NULL; | |
c4d90345 | 1024 | Char_t *tmpfname; |
1025 | TString dadatafilename(""); | |
f67db810 | 1026 | if (!fModules) return kFALSE; |
88128115 | 1027 | ldcn = new AliITSNoiseSSDv2; |
1028 | ldcp = new AliITSPedestalSSDv2; | |
1029 | ldcbc = new AliITSBadChannelsSSDv2; | |
61a57d07 | 1030 | if ((!ldcn) || (!ldcp) || (!ldcp)) { |
1031 | AliError("Error allocation mamory for calibration objects, return kFALSE!"); | |
1032 | return kFALSE; | |
1033 | } | |
f67db810 | 1034 | for (Int_t i = 0; i < fNumberOfModules; i++) { |
61a57d07 | 1035 | if (!(module = fModules[i])) continue; |
1036 | if (module->GetModuleId() < fgkMinSSDModuleId) continue; | |
1037 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
1038 | if (!(strip = module->GetStrip(strind))) continue; | |
1039 | Short_t modid = module->GetModuleId() - fgkMinSSDModuleId; | |
1040 | if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) { | |
1041 | ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM()); | |
1042 | ldcp->AddPedestalP(modid, strip->GetStripId(), strip->GetPedestal()); | |
d86972f6 | 1043 | ldcbc->AddBadChannelP(modid, strip->GetStripId(), EvaluateIfChannelIsBad(module, strip->GetStripId())); |
61a57d07 | 1044 | } else { |
1045 | ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM()); | |
1046 | ldcp->AddPedestalN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetPedestal()); | |
1047 | ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), | |
d86972f6 | 1048 | EvaluateIfChannelIsBad(module, strip->GetStripId())); |
61a57d07 | 1049 | } |
f67db810 | 1050 | } |
f67db810 | 1051 | } |
a69c8ba0 | 1052 | if (dafname) dadatafilename.Form("%s/", dafname); |
371588bb | 1053 | dadatafilename += TString::Format("ITSSSDda_%i.root", fLdcId); |
a69c8ba0 | 1054 | tmpfname = new Char_t[dadatafilename.Length()+1]; |
443e42aa | 1055 | Int_t sz = dadatafilename.Sizeof(); |
1056 | dafname = strncpy(tmpfname, dadatafilename.Data(),sz); | |
c4d90345 | 1057 | TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE"); |
f67db810 | 1058 | if (fileRun->IsZombie()) { |
c4d90345 | 1059 | AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data())); |
2e2c6def | 1060 | ldcn->Delete(); |
f67db810 | 1061 | delete fileRun; |
2e2c6def | 1062 | delete ldcn; |
1063 | delete ldcp; | |
1064 | delete ldcbc; | |
f67db810 | 1065 | return kFALSE; |
1066 | } | |
2e2c6def | 1067 | fileRun->WriteTObject(ldcn); |
1068 | fileRun->WriteTObject(ldcp); | |
61a57d07 | 1069 | if (fBadChannelsList) |
1070 | if (fMergeBCLists) { | |
1071 | MergeBadChannels(ldcbc); | |
1072 | fileRun->WriteTObject(ldcbc); | |
1073 | } else fileRun->WriteTObject(fBadChannelsList); | |
6e7691a5 | 1074 | else fileRun->WriteTObject(ldcbc); |
f67db810 | 1075 | fileRun->Close(); |
f67db810 | 1076 | delete fileRun; |
2e2c6def | 1077 | delete ldcn; |
1078 | delete ldcp; | |
1079 | delete ldcbc; | |
c4d90345 | 1080 | return kTRUE; |
1081 | } | |
1082 | ||
1083 | ||
61a57d07 | 1084 | //______________________________________________________________________________ |
88128115 | 1085 | Int_t AliITSHandleDaSSD::MergeBadChannels(AliITSBadChannelsSSDv2*& bcl) const |
61a57d07 | 1086 | { |
1087 | // Merges the statick bad channels list with bad channels got upon calibration | |
1088 | AliITSModuleDaSSD *module = 0; | |
1089 | Int_t nmpch = 0, nmnch = 0, ngpch = 0, ngnch = 0; | |
1090 | if (!fBadChannelsList || !bcl) { | |
1091 | AliWarning("Either fBadChannelsList == NULL or bad_channels_list == NULL, there is nothing to merge!"); | |
1092 | return -1; | |
1093 | } | |
1094 | for (Int_t modind = 0; modind < GetNumberOfModules(); modind++) { | |
1095 | if (!(module = fModules[modind])) continue; | |
1096 | if (module->GetModuleId() < fgkMinSSDModuleId) continue; | |
1097 | Short_t modid = module->GetModuleId() - fgkMinSSDModuleId; | |
1098 | for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetPNStripsPerModule(); strind++) { | |
1099 | if ( (!(fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask)) | |
1100 | && (bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) | |
1101 | ngpch++; | |
1102 | if ( (!(fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask)) | |
1103 | && (bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) | |
1104 | ngnch++; | |
1105 | if ( (!(bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask)) | |
1106 | && (fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) { | |
1107 | bcl->AddBadChannelP(modid, strind, fBadChannelsList->GetBadChannelP(modid, strind)); | |
1108 | nmpch++; | |
1109 | } | |
1110 | if ( (!(bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask)) | |
1111 | && (fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) { | |
1112 | bcl->AddBadChannelN(modid, strind, fBadChannelsList->GetBadChannelN(modid, strind)); | |
1113 | nmnch++; | |
1114 | } | |
1115 | } | |
1116 | } | |
1117 | AliInfo(Form("Static bad, dynamic good: P%d, N%d", nmpch, nmnch)); | |
1118 | AliInfo(Form("Static good, dynamic bad: P%d, N%d", ngpch, ngnch)); | |
1119 | return (nmnch + nmpch); | |
1120 | } | |
1121 | ||
1122 | ||
c4d90345 | 1123 | |
1124 | //______________________________________________________________________________ | |
1125 | Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const | |
1126 | { | |
1127 | // Dump calibration parameters | |
1128 | AliITSModuleDaSSD *mod; | |
1129 | AliITSChannelDaSSD *strip; | |
1130 | if (!fModules) { | |
1131 | cout << "SSDDALDC::DumpModInfo(): Error, no modules are allocated!" << endl; | |
1132 | return kFALSE; | |
1133 | } | |
1134 | cout << "Modules with MeanNoise > " << meannosethreshold << endl; | |
1135 | for (Int_t i = 0; i < fNumberOfModules; i++) { | |
1136 | if (!(mod = fModules[i])) continue; | |
d86972f6 | 1137 | Double_t maxnoise = 0.0L, meannoise = 0.0L, meanovf = 0.0L; |
1138 | Float_t maxped = 0.0f; | |
1139 | Int_t maxstrind = 0, novfstr = 0, maxovf = 0; | |
c4d90345 | 1140 | for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) { |
1141 | if (!(strip = mod->GetStrip(strind))) {novfstr++; continue; } | |
1142 | if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++; continue; } | |
1143 | if (maxnoise < strip->GetNoiseCM()) { | |
1144 | maxnoise = strip->GetNoiseCM(); | |
1145 | maxstrind = strind; | |
1146 | } | |
d86972f6 | 1147 | meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Double_t>(strind - novfstr + 1) |
c4d90345 | 1148 | : strip->GetNoiseCM(); |
d86972f6 | 1149 | if (TMath::Abs(maxped) < TMath::Abs(strip->GetPedestal())) maxped = strip->GetPedestal(); |
1150 | meanovf = (strind - novfstr) ? meanovf + (strip->GetOverflowNumber() - meanovf) / static_cast<Double_t>(strind - novfstr + 1) | |
1151 | : strip->GetOverflowNumber(); | |
1152 | if (strip->GetOverflowNumber() > maxovf) maxovf = strip->GetOverflowNumber(); | |
c4d90345 | 1153 | } |
1154 | if (meannoise > meannosethreshold) | |
1155 | cout << "Mod: " << i << "; DDl: " << (int)mod->GetDdlId() << "; AD: " << (int)mod->GetAD() | |
371588bb | 1156 | << "; ADC: " << (int)mod->GetADC() << "; MaxPed = " << maxped |
304a787e | 1157 | << "; MeanNoise = " << meannoise << "; MaxNoise = " << maxnoise << "; MaxNoiseStrip = " << maxstrind |
c4d90345 | 1158 | << "; NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl; |
d86972f6 | 1159 | if (maxovf > 10) cout << "Max number of events with overflow : " << maxovf << "; mean : " << meanovf << endl; |
c4d90345 | 1160 | } |
1161 | return kTRUE; | |
1162 | } | |
1163 | ||
1164 | ||
1165 | ||
1166 | //______________________________________________________________________________ | |
1167 | Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const | |
1168 | { | |
59087bde | 1169 | // Print Module calibration data whether in file or in cout |
c4d90345 | 1170 | AliITSChannelDaSSD *strip; |
1171 | ofstream datafile; | |
1172 | ostream *outputfile; | |
1173 | if (!fname) { outputfile = &cout; } | |
1174 | else { | |
1175 | datafile.open(fname, ios::out); | |
1176 | if (datafile.fail()) return kFALSE; | |
1177 | outputfile = dynamic_cast<ostream*>(&datafile); | |
1178 | } | |
1179 | *outputfile << "DDL = " << (int)ddlID << "; AD = " << (int)ad << "; ADC = " << (int)adc << endl; | |
1180 | for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) { | |
8bcdc40d | 1181 | if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) { |
c4d90345 | 1182 | *outputfile << "Str = " << strind << "; ped = " << strip->GetPedestal() |
1183 | << "; noise = " << strip->GetNoiseCM() << endl; | |
1184 | } | |
1185 | else continue; | |
1186 | } | |
1187 | if (datafile.is_open()) datafile.close(); | |
1188 | return kTRUE; | |
1189 | } | |
1190 | ||
1191 | ||
1192 | ||
371588bb | 1193 | //______________________________________________________________________________ |
c4d90345 | 1194 | void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const |
1195 | { | |
371588bb | 1196 | // Print general information retrieved from raw data file |
c4d90345 | 1197 | cout << "Raw data file: " << fRawDataFileName << endl |
1198 | << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl | |
1199 | << "Number of physics events: " << fNumberOfEvents << endl | |
1200 | << str; | |
1201 | } | |
1202 | ||
1203 | ||
1204 | //______________________________________________________________________________ | |
1205 | Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind) | |
1206 | { | |
1207 | // Used to allocate simulated modules to test the performance | |
1208 | AliITSModuleDaSSD *module; | |
1209 | UChar_t ad, adc, ddlID; | |
1210 | ad = adc = ddlID = 0; | |
1211 | if (!(fModules[copymodind])) return kFALSE; | |
1212 | for (Int_t modind = 0; modind < fNumberOfModules; modind++) { | |
1213 | if (!fModules[modind]) { | |
1214 | module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst()); | |
1215 | if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1; | |
1216 | else if (adc == 5) adc = 8; | |
1217 | else if (adc == 13) { | |
1218 | adc = 0; | |
1219 | if (ad < 8) ad += 1; | |
1220 | else { | |
1221 | ad = 0; | |
1222 | ddlID +=1; | |
1223 | } | |
1224 | } | |
1225 | if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE; | |
1226 | fModules[modind] = module; | |
1227 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
1228 | AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind); | |
443e42aa | 1229 | if(!cstrip)return kFALSE; |
c4d90345 | 1230 | Long_t eventsnumber = cstrip->GetEventsNumber(); |
1231 | AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber); | |
1232 | for (Long_t evind = 0; evind < eventsnumber; evind++) { | |
61a57d07 | 1233 | Short_t sign = cstrip->GetSignal(evind); |
c4d90345 | 1234 | if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind)); |
1235 | } | |
1236 | module->SetStrip(strip, strind); | |
1237 | } | |
1238 | } | |
1239 | else { | |
1240 | ddlID = fModules[modind]->GetDdlId(); | |
1241 | ad = fModules[modind]->GetAD(); | |
1242 | adc = fModules[modind]->GetADC(); | |
1243 | } | |
1244 | } | |
1245 | for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080); | |
f67db810 | 1246 | return kTRUE; |
1247 | } | |
be4f467e | 1248 | |
1249 | ||
1250 | ||
1251 | //___________________________________________________________________________________________ | |
1252 | Bool_t AliITSHandleDaSSD::AdDataPresent(const Int_t ddl, const Int_t ad) const | |
1253 | { | |
1254 | // Check if there are calibration data for given ddl and slot | |
1255 | for (Int_t modind = 0; modind < fNumberOfModules; modind++) | |
1256 | if ((GetModule(modind)->GetAD() == ad) && (GetModule(modind)->GetDdlId() == ddl)) return kTRUE; | |
1257 | return kFALSE; | |
1258 | } | |
1259 | ||
1260 | ||
1261 | ||
1262 | //___________________________________________________________________________________________ | |
1263 | Bool_t AliITSHandleDaSSD::SaveEqSlotCalibrationData(const Int_t ddl, const Int_t ad, const Char_t *fname) const | |
be4f467e | 1264 | { |
292c304e | 1265 | // Saves calibration files for selected equipment (DDL) |
be4f467e | 1266 | fstream feefile; |
1267 | Int_t zsml, offsetml; | |
1268 | ULong_t zsth, offset, zsoffset; | |
1269 | if (!fname) { | |
1270 | AliError("File name must be specified!"); | |
1271 | return kFALSE; | |
1272 | } | |
1273 | if (!AdDataPresent(ddl, ad)) { | |
1274 | AliError(Form("Error SaveEqSlotCalibrationData(ddl = %i, ad = %i) no data present", ddl, ad)); | |
1275 | return kFALSE; | |
1276 | } | |
1277 | feefile.open(fname, ios::out); | |
1278 | if (!feefile.is_open()) { | |
1279 | AliError(Form("Can not open the file %s for output!", fname)); | |
1280 | return kFALSE; | |
1281 | } | |
5af4a2d0 | 1282 | for (zsml = 0; fgkZsBitMask >> zsml; zsml++) ; |
1283 | for (offsetml = 0; fgkOffSetBitMask >> offsetml; offsetml++) ; | |
be4f467e | 1284 | for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) { |
1285 | for (Int_t adcb = 0; adcb < fgkAdcPerDBlock; adcb++) { | |
1286 | zsoffset = 0x0; | |
1287 | for (Int_t j = 0; j < 2; j++) { | |
1288 | Int_t adc = adcb + j * 8; | |
1289 | zsth = ZsThreshold(ddl, ad, adc, strind); | |
1290 | offset = OffsetValue(ddl, ad, adc, strind); | |
1291 | zsoffset = zsoffset | (((zsth << offsetml) | offset) << ((j == 0) ? (offsetml + zsml) : 0)); | |
1292 | } | |
1293 | feefile << "0x" << ConvBase(static_cast<unsigned long>(zsoffset), 16) << endl; | |
1294 | } | |
1295 | } | |
1296 | feefile.close(); | |
1297 | return kTRUE; | |
1298 | } | |
1299 | ||
1300 | ||
1301 | //______________________________________________________________________________ | |
1302 | Int_t AliITSHandleDaSSD::ChannelIsBad(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const | |
1303 | { | |
1304 | // Check if the channel is bad | |
61a57d07 | 1305 | AliITSModuleDaSSD *module = NULL; |
1306 | Int_t modn = -1; | |
1307 | if (fBadChannelsList && fDDLModuleMap) { | |
be4f467e | 1308 | modn = RetrieveModuleId(ddl, ad, adc); |
1309 | if (modn < 0) return -1; | |
61a57d07 | 1310 | if (modn < fgkMinSSDModuleId) { |
a5a317a9 | 1311 | AliWarning(Form("Module ddl/ad/adc: %d/%d/%d has number %d which is wrong for SSD module %d", ddl, ad, adc, strn, modn)); |
61a57d07 | 1312 | return -1; |
be4f467e | 1313 | } |
61a57d07 | 1314 | Short_t modid = modn - fgkMinSSDModuleId; |
1315 | if (strn < AliITSModuleDaSSD::GetPNStripsPerModule()) | |
1316 | return (fBadChannelsList->GetBadChannelP(modid, strn) & fgkBadChannelMask); | |
1317 | else return (fBadChannelsList->GetBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strn)) & fgkBadChannelMask); | |
1318 | } else { | |
d86972f6 | 1319 | AliError("Error ether bad channels list or DDLMap is not initialized or both, EvaluateIfChannelIsBad(module, strip) is used!"); |
32c31f19 | 1320 | if ((module = GetModule(ddl, ad, adc))) { |
d86972f6 | 1321 | return (EvaluateIfChannelIsBad(module, strn) & fgkBadChannelMask); |
be4f467e | 1322 | } else { |
61a57d07 | 1323 | AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc)); |
1324 | return 0ul; | |
be4f467e | 1325 | } |
be4f467e | 1326 | return 0; |
1327 | } | |
1328 | } | |
61a57d07 | 1329 | |
1330 | ||
1331 | ||
1332 | //______________________________________________________________________________ | |
1333 | Int_t AliITSHandleDaSSD::LadderIsOff(const UChar_t ddl, const UChar_t ad, const UChar_t adc) const | |
1334 | { | |
1335 | //Checks if the module with given ddl, ad, adc is on the ladder which is in the list of ladders which are off | |
1336 | const Int_t nm5 = 500; | |
1337 | const Int_t nm6 = 1248; | |
1338 | const Int_t nml5a = 12; | |
1339 | const Int_t nml5c = 10; | |
1340 | const Int_t nml6a = 12; | |
1341 | const Int_t nml6c = 13; | |
1342 | Int_t modn, ladder, layer, side; | |
1343 | AliITSModuleDaSSD *module; | |
1344 | if (!(module = GetModule(ddl, ad, adc))) return 0; | |
1345 | if ((modn = module->GetModuleId()) <= 0) modn = RetrieveModuleId(ddl, ad, adc); | |
1346 | if (modn <= 0) return 0; | |
1347 | layer = modn >= nm6 ? 1 : 0; // 6 : 5 | |
1348 | ladder = (modn - (layer ? nm6 : nm5)) / (layer ? (nml6a + nml6c) : (nml5a + nml5c)); | |
1349 | if ( ((modn - (layer ? nm6 : nm5)) % (layer ? (nml6a + nml6c) : (nml5a + nml5c))) < (layer ? nml6a : nml5a)) | |
1350 | side = 0; // A | |
1351 | else side = 1; // C | |
1352 | ladder += (layer ? 600 : 500); | |
1353 | layer += 5; | |
1354 | if (side) | |
1355 | if (fCLaddersOff.GetSize()) { | |
1356 | for(Int_t i = 0; i < fCLaddersOff.GetSize(); i++) | |
1357 | if (fCLaddersOff.At(i) == ladder) return fCLaddersOff.At(i); | |
1358 | return 0; | |
1359 | } else return 0; | |
1360 | else | |
1361 | if (fALaddersOff.GetSize()) { | |
1362 | for(Int_t i = 0; i < fALaddersOff.GetSize(); i++) | |
1363 | if (fALaddersOff.At(i) == ladder) return fALaddersOff.At(i); | |
1364 | return 0; | |
1365 | } else return 0; | |
1366 | return 0; | |
1367 | } | |
1368 | ||
1369 | ||
be4f467e | 1370 | |
1371 | //______________________________________________________________________________ | |
1372 | ULong_t AliITSHandleDaSSD::OffsetValue(const AliITSChannelDaSSD *strip, | |
1373 | const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const | |
1374 | { | |
1375 | // Calculate the offset value to be upload to FEROM | |
1376 | Int_t pedint; | |
1377 | if (fOffsetDefault < INT_MAX) pedint = fOffsetDefault; | |
1378 | else pedint = TMath::Nint(strip->GetPedestal()); | |
1379 | if (pedint > static_cast<Int_t>((fgkOffSetBitMask >> 1))) { | |
d86972f6 | 1380 | if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (EvaluateIfChannelIsBad(GetModule(ddl, ad, adc), strn)))) |
61a57d07 | 1381 | AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i", |
1382 | pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), (fgkOffSetBitMask >> 1))); | |
1383 | return (fgkOffSetBitMask >> 1); | |
be4f467e | 1384 | } |
1385 | if ((-pedint) > static_cast<Int_t>(((fgkOffSetBitMask + 1) >> 1))) { | |
d86972f6 | 1386 | if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (EvaluateIfChannelIsBad(GetModule(ddl, ad, adc), strn)))) |
61a57d07 | 1387 | AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i", |
1388 | pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), | |
1389 | ((fgkOffSetBitMask & (~fgkOffSetBitMask >> 1)) - fgkOffSetBitMask - 1))); | |
be4f467e | 1390 | return fgkOffSetBitMask & (~fgkOffSetBitMask >> 1); |
1391 | } | |
1392 | return fgkOffSetBitMask & (pedint >= 0 ? pedint : pedint + fgkOffSetBitMask + 1); | |
1393 | } | |
1394 | ||
1395 | ||
1396 | ||
1397 | //______________________________________________________________________________ | |
1398 | ULong_t AliITSHandleDaSSD::OffsetValue(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const | |
1399 | { | |
1400 | // Calculate the offset value to be upload to FEROM | |
1401 | AliITSChannelDaSSD *strip = NULL; | |
1402 | AliITSModuleDaSSD *module = NULL; | |
32c31f19 | 1403 | if ((module = GetModule(ddl, ad, adc))) { |
1404 | if ((strip = module->GetStrip(strn))) return OffsetValue(strip, ddl, ad, adc, strn); | |
be4f467e | 1405 | else { |
1406 | AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn)); | |
1407 | return 0ul; | |
1408 | } | |
1409 | } else { | |
1410 | AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc)); | |
1411 | return 0ul; | |
1412 | } | |
1413 | } | |
1414 | ||
1415 | ||
1416 | ||
1417 | //______________________________________________________________________________ | |
292c304e | 1418 | ULong_t AliITSHandleDaSSD::ZsThreshold(const AliITSChannelDaSSD *strip) const |
be4f467e | 1419 | { |
1420 | // Calculate the value of zero suppression threshold to be upload to FEROM | |
1421 | ULong_t zs; | |
61a57d07 | 1422 | if (fZsDefault < 0) { |
1423 | zs = TMath::Nint(fZsFactor * strip->GetNoiseCM()); | |
1424 | if (zs < static_cast<ULong_t>(fZsMinimum)) zs = static_cast<ULong_t>(fZsMinimum); | |
1425 | } | |
be4f467e | 1426 | else zs = fZsDefault; |
1427 | return (zs < fgkZsBitMask) ? (zs & fgkZsBitMask) : fgkZsBitMask; | |
1428 | } | |
1429 | ||
1430 | ||
1431 | //______________________________________________________________________________ | |
1432 | ULong_t AliITSHandleDaSSD::ZsThreshold(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const | |
1433 | { | |
1434 | // Calculate the value of zero suppression threshold to be upload to FEROM, account bad channels list | |
1435 | AliITSChannelDaSSD *strip = NULL; | |
1436 | AliITSModuleDaSSD *module = NULL; | |
61a57d07 | 1437 | if (ChannelIsBad(ddl, ad, adc, strn)) return fgkZsBitMask; |
1438 | if (LadderIsOff(ddl, ad, adc)) return fgkZsBitMask; | |
d86972f6 | 1439 | if (fZsDefault > 0) if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) return fgkZsBitMask; |
32c31f19 | 1440 | if ((module = GetModule(ddl, ad, adc))) { |
d86972f6 | 1441 | if (fMergeBCLists) if (EvaluateIfChannelIsBad(module, strn)) return fgkZsBitMask; |
32c31f19 | 1442 | if ((strip = module->GetStrip(strn))) return ZsThreshold(strip); |
be4f467e | 1443 | else { |
1444 | AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn)); | |
1445 | return 0ul; | |
1446 | } | |
1447 | } else { | |
1448 | AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc)); | |
1449 | return 0ul; | |
1450 | } | |
1451 | } | |
1452 | ||
1453 | ||
1454 | //______________________________________________________________________________ | |
1455 | string AliITSHandleDaSSD::ConvBase(const unsigned long value, const long base) const | |
1456 | { | |
1457 | // Converts the unsigned long number into that in another base | |
1458 | string digits = "0123456789ABCDEF"; | |
1459 | string result; | |
1460 | unsigned long v = value; | |
1461 | if((base < 2) || (base > 16)) { | |
1462 | result = "Error: base out of range."; | |
1463 | } | |
1464 | else { | |
1465 | int i = 0; | |
1466 | do { | |
1467 | result = digits[v % base] + result; | |
1468 | v /= base; | |
1469 | i++; | |
1470 | } | |
1471 | while((v) || (i<8)); | |
1472 | } | |
1473 | return result; | |
1474 | } | |
61a57d07 | 1475 | |
1476 | ||
1477 | ||
1478 | //______________________________________________________________________________ | |
1479 | Int_t AliITSHandleDaSSD::CheckOffChips() const | |
1480 | { | |
1481 | // Check if the chip, module are off | |
1482 | AliITSChannelDaSSD *strip; | |
1483 | Int_t offthreshold; | |
1484 | Int_t strnd, chipnd, modnd, stroff, chipoff, modoff; | |
1485 | offthreshold = TMath::Nint(fZsMinimum/fZsFactor); | |
1486 | modnd = modoff = 0; | |
1487 | for (Int_t mi = 0; mi < fNumberOfModules; mi++) { | |
1488 | if (!fModules[mi]) { modnd++; continue; } | |
1489 | if (fModules[mi]->GetModuleId() < 0) continue; | |
1490 | if (LadderIsOff(fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()) ) continue; | |
1491 | chipoff = chipnd = 0; | |
1492 | for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) { | |
1493 | strnd = stroff = 0; | |
1494 | Int_t stripind = chipind * AliITSModuleDaSSD::GetStripsPerChip(); | |
1495 | for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) { | |
1496 | if (!(strip = fModules[mi]->GetStrip(strind))) { strnd++; continue; } | |
1497 | if (strip->GetNoiseCM() < offthreshold ) stroff++; | |
1498 | } | |
1499 | if (strnd == AliITSModuleDaSSD::GetStripsPerChip()) chipnd++; | |
1500 | else if (stroff == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++; | |
1501 | else if ((stroff + strnd) == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++; | |
1502 | } | |
1503 | if ((!chipoff) && (!chipnd)) continue; | |
1504 | if (chipnd == AliITSModuleDaSSD::GetChipsPerModuleConst()) { | |
1505 | AliInfo(Form("Module: (ddl/ad/adc) %i/%i/%i seems to be off and it is not on the ladders which are off!", | |
1506 | fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC())); | |
1507 | modnd++; | |
1508 | } | |
1509 | if (chipoff == AliITSModuleDaSSD::GetChipsPerModuleConst()) { | |
1510 | AliInfo(Form("Module (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!", | |
1511 | fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC())); | |
1512 | modoff++; | |
1513 | } | |
1514 | else if ((chipoff + chipnd) == AliITSModuleDaSSD::GetChipsPerModuleConst()) { | |
1515 | AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!", | |
1516 | fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC())); | |
1517 | modoff++; | |
1518 | } | |
1519 | else if (chipoff) { | |
1520 | AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i has %i chips which are off!", | |
1521 | fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC(), chipoff)); | |
1522 | modoff++; | |
1523 | } | |
1524 | } | |
1525 | return (modoff + modnd); | |
1526 | } | |
59087bde | 1527 | |
d86972f6 | 1528 | |
1529 | //______________________________________________________________________________ | |
292c304e | 1530 | Bool_t AliITSHandleDaSSD::CalculatePedNoiseW(const AliITSModuleDaSSD *const module) |
d86972f6 | 1531 | { |
1532 | // Calculates Pedestal and Noise using Welford algorithm | |
1533 | AliITSChannelDaSSD *strip; | |
1534 | Double_t pedestal, noise, p0, s0; | |
1535 | Short_t *signal; | |
1536 | Int_t ovev, n; | |
1537 | if (!module) return kFALSE; | |
1538 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
1539 | if (!(strip = module->GetStrip(strind))) continue; | |
1540 | if (!(signal = strip->GetSignal())) { | |
1541 | AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()", | |
1542 | module->GetModuleId(), strind)); | |
1543 | continue; | |
1544 | } | |
1545 | //************* pedestal and noise first pass **************** | |
1546 | pedestal = p0 = noise = 0.0L; | |
1547 | ovev = 0; | |
1548 | for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) { | |
1549 | if (SignalOutOfRange(signal[ev])) ovev += 1; | |
1550 | else | |
1551 | if (!(ev - ovev)) { | |
1552 | pedestal = p0 = signal[ev]; | |
1553 | noise = 0.0L; | |
1554 | } else { | |
1555 | p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1); | |
1556 | s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0); | |
1557 | pedestal = p0; | |
1558 | noise = s0; | |
1559 | } | |
1560 | } | |
1561 | if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue(); | |
1562 | strip->SetPedestal(static_cast<Float_t>(pedestal)); | |
1563 | if ((n = strip->GetEventsNumber() - ovev - 1) > 0) | |
7ab0e0a5 | 1564 | strip->SetNoise( static_cast<Float_t>(TMath::Sqrt(noise / static_cast<Double_t>(n))) ); |
d86972f6 | 1565 | else { |
1566 | strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue()); | |
1567 | continue; | |
1568 | } | |
1569 | //************* Second pass excluds event with |p - s|>f*noise ***************** | |
1570 | pedestal = p0 = noise = 0.0L; | |
1571 | ovev = 0; | |
1572 | for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) { | |
1573 | if ( SignalOutOfRange(signal[ev]) | |
1574 | || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1; | |
1575 | else | |
1576 | if (!(ev - ovev)) { | |
1577 | pedestal = p0 = signal[ev]; | |
1578 | noise = 0.0L; | |
1579 | } else { | |
1580 | p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1); | |
1581 | s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0); | |
1582 | pedestal = p0; | |
1583 | noise = s0; | |
1584 | } | |
1585 | } | |
7ab0e0a5 | 1586 | if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n)); |
d86972f6 | 1587 | else noise = AliITSChannelDaSSD::GetUndefinedValue(); |
1588 | strip->SetNoise(static_cast<Float_t>(noise)); | |
1589 | if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue(); | |
1590 | strip->SetPedestal(static_cast<Float_t>(pedestal)); | |
1591 | strip->SetOverflowNumber(ovev); | |
1592 | } | |
1593 | return kTRUE; | |
1594 | } | |
1595 | ||
1596 | ||
1597 | //______________________________________________________________________________ | |
1598 | Bool_t AliITSHandleDaSSD::CalculateCMW(AliITSModuleDaSSD *const module) | |
1599 | { | |
1600 | // Calculates CM using Welford algorithm | |
1601 | AliITSChannelDaSSD *strip = NULL; | |
1602 | Short_t *signal; | |
1603 | Int_t ovstr, n; | |
1604 | Int_t stripind; | |
1605 | Double_t cm0, cm1, cmsigma, cms1; | |
1606 | module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst()); | |
1607 | for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) { | |
1608 | stripind = chipind * module->GetStripsPerChip(); | |
1609 | module->GetCM()[chipind].Set(fNumberOfEvents); | |
1610 | module->GetCM()[chipind].Reset(0.0f); | |
1611 | for (Long_t ev = 0; ev < fNumberOfEvents; ev++) { | |
1612 | // calculate firs approximation of CM and SigmaCM. | |
1613 | cm0 = cm1 = cmsigma = 0.0L; | |
1614 | ovstr = 0; | |
1615 | for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) { | |
1616 | if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; } //return kFALSE; | |
1617 | if (!(signal = strip->GetSignal())) { ovstr += 1; continue; } //return kFALSE; | |
1618 | if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1; | |
1619 | else { | |
1620 | if (!(strind - stripind - ovstr)) { | |
1621 | cm0 = cm1 = signal[ev] - strip->GetPedestal(); | |
1622 | cmsigma = 0.0L; | |
1623 | } else { | |
1624 | cm1 = cm0 + (signal[ev] - strip->GetPedestal() - cm0) / static_cast<Double_t>(strind - stripind - ovstr + 1); | |
1625 | cms1 = cmsigma + (signal[ev] - strip->GetPedestal() - cm0) * (signal[ev] - strip->GetPedestal() - cm1); | |
1626 | cm0 = cm1; | |
1627 | cmsigma = cms1; | |
1628 | } } | |
1629 | } | |
7ab0e0a5 | 1630 | if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr - 1) > 0) cmsigma = TMath::Sqrt(cmsigma / static_cast<Double_t>(n)); |
d86972f6 | 1631 | else { |
a5a317a9 | 1632 | AliWarning(Form("AliITSHandleDaSSD: Too little number of strips have a signal for module:chip:event : [%d]:[%d]:[%ld]\n", |
d86972f6 | 1633 | module->GetModuleId(), chipind, ev)); |
1634 | if (!(module->SetCM(0.0f, chipind, ev))) | |
a5a317a9 | 1635 | AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n", |
d86972f6 | 1636 | module->GetModuleId(), chipind, ev)); |
1637 | continue; | |
1638 | } | |
1639 | // calculate cm with threshold | |
1640 | Double_t cmsum = 0.0L; | |
1641 | ovstr = 0; | |
1642 | for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) { | |
1643 | if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; } | |
1644 | if (!(signal = strip->GetSignal())) { ovstr += 1; continue; } | |
1645 | if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue()) | |
1646 | || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1; | |
1647 | else cmsum += (signal[ev] - strip->GetPedestal()); | |
1648 | } | |
1649 | if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Double_t)(n); | |
1650 | else cmsum = 0.0L; | |
1651 | if (!(module->SetCM(static_cast<Float_t>(cmsum), chipind, ev))) | |
a5a317a9 | 1652 | AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n", |
d86972f6 | 1653 | module->GetModuleId(), chipind, ev)); |
1654 | } | |
1655 | } | |
1656 | return kTRUE; | |
1657 | } | |
1658 | ||
1659 | ||
1660 | //______________________________________________________________________________ | |
1661 | Bool_t AliITSHandleDaSSD::CalculateNoiseCMW(AliITSModuleDaSSD *const module) | |
1662 | { | |
1663 | // Calculates Noise with CM correction | |
1664 | AliITSChannelDaSSD *strip = NULL; | |
1665 | Short_t *signal; | |
1666 | Int_t ovev, n; | |
1667 | if (!CalculateCMW(module)) { | |
1668 | AliError("Error: AliITSHandleDaSSD::CalculateCMW() returned kFALSE"); | |
1669 | return kFALSE; | |
1670 | } | |
1671 | for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) { | |
1672 | if (!(strip = module->GetStrip(strind))) continue; //return kFALSE; | |
1673 | if (!(signal = strip->GetSignal())) { | |
1674 | strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue()); | |
1675 | AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCMW(): there are no events data for module[%i] strip[%i]->GetSignal()", | |
1676 | module->GetModuleId(), strind)); | |
1677 | continue; //return kFALSE; | |
1678 | } | |
1679 | //** To get exactly the same set of events as for pedestal and noise calculation ** | |
1680 | Double_t pedestal, noise, p0, s0; | |
1681 | pedestal = p0 = noise = 0.0L; | |
1682 | ovev = 0; | |
1683 | for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) { | |
1684 | if (SignalOutOfRange(signal[ev])) ovev += 1; | |
1685 | else | |
1686 | if (!(ev - ovev)) { | |
1687 | pedestal = p0 = signal[ev]; | |
1688 | noise = 0.0L; | |
1689 | } else { | |
1690 | p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1); | |
1691 | s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0); | |
1692 | pedestal = p0; | |
1693 | noise = s0; | |
1694 | } | |
1695 | } | |
7ab0e0a5 | 1696 | if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n)); |
d86972f6 | 1697 | else { |
1698 | strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue()); | |
1699 | continue; | |
1700 | } | |
1701 | //** Calculation of CM corrected noise ** | |
1702 | Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip(); | |
1703 | Double_t nsum = 0.0L; | |
1704 | ovev = 0; | |
1705 | for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) { | |
1706 | if ( SignalOutOfRange(signal[ev]) | |
1707 | || TMath::Abs(signal[ev] - pedestal) > (fPedestalThresholdFactor * noise)) ovev += 1; | |
1708 | else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2); | |
1709 | } | |
7ab0e0a5 | 1710 | if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / static_cast<Double_t>(n)); |
d86972f6 | 1711 | else noise = AliITSChannelDaSSD::GetUndefinedValue(); |
1712 | strip->SetNoiseCM(static_cast<Float_t>(noise)); | |
1713 | } | |
1714 | return kTRUE; | |
1715 | } | |
1716 | ||
1717 | ||
1718 | ||
1719 | //______________________________________________________________________________ | |
1720 | UChar_t AliITSHandleDaSSD::EvaluateIfChannelIsBad(const AliITSModuleDaSSD *const module, const Int_t stripn) const | |
1721 | { | |
1722 | //Applies the bad channel creteria and set the appropriate flags for returned value | |
1723 | AliITSChannelDaSSD *strip = 0; | |
1724 | UInt_t bcflags = 0; | |
1725 | if (fZsDefault >= 0) { if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) bcflags |= 3; } | |
1726 | else if (static_cast<ULong_t>(fZsMinimum) >= fgkZsBitMask) bcflags |= 3; | |
1727 | if (LadderIsOff(module->GetDdlId(), module->GetAD(), module->GetADC()) ) bcflags |= 3; | |
1728 | ||
1729 | if (!(strip = module->GetStrip(stripn))) bcflags |= 3; | |
1730 | else { | |
1731 | if (strip->GetNoiseCM() == AliITSChannelDaSSD::GetUndefinedValue()) bcflags |= 8; | |
1732 | if (static_cast<ULong_t>(TMath::Nint(fZsFactor * strip->GetNoiseCM())) >= fgkZsBitMask) bcflags |= 8; | |
1733 | if (strip->GetNoiseCM() < 1) bcflags |= 16; | |
1734 | if (strip->GetPedestal() > ((fgkOffSetBitMask >> 1) - 1)) bcflags |= 4; | |
1735 | else if ((-(strip->GetPedestal())) > (fgkOffSetBitMask >> 1)) bcflags |= 4; | |
1736 | if (bcflags) bcflags |= 3; | |
1737 | } | |
1738 | return bcflags; | |
1739 | } | |
1740 |