1 /**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This class provides ITS SSD data handling
22 // Author: Oleksandr Borysov
24 ///////////////////////////////////////////////////////////////////////////////
29 #include <Riostream.h>
30 #include "AliITSHandleDaSSD.h"
38 #include "AliITSNoiseSSDv2.h"
39 #include "AliITSPedestalSSDv2.h"
40 #include "AliITSBadChannelsSSDv2.h"
41 #include "AliITSRawStreamSSD.h"
42 #include "AliRawReaderDate.h"
43 #include "AliITSRawStreamSSD.h"
44 #include "AliITSChannelDaSSD.h"
47 ClassImp(AliITSHandleDaSSD)
52 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModules = 1698; // Number of SSD modules in ITS
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
55 const Short_t AliITSHandleDaSSD::fgkMinSSDModuleId = 500; // Initial SSD modules number
56 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDSlotsPerDDL = 9; // Number of SSD slots per DDL
57 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDDDLs = 16; // Number of SSD modules in Slot
58 const Float_t AliITSHandleDaSSD::fgkPedestalThresholdFactor = 3.0; // Defalt value for fPedestalThresholdFactor
59 const Float_t AliITSHandleDaSSD::fgkCmThresholdFactor = 3.0; // Defalt value for fCmThresholdFactor
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
66 //______________________________________________________________________________
67 AliITSHandleDaSSD::AliITSHandleDaSSD() :
68 fRawDataFileName(NULL),
76 fBadChannelsList(NULL),
82 fPedestalThresholdFactor(fgkPedestalThresholdFactor),
83 fCmThresholdFactor(fgkCmThresholdFactor),
85 fOffsetDefault(INT_MAX),
90 // Default constructor
94 //______________________________________________________________________________
95 AliITSHandleDaSSD::AliITSHandleDaSSD(Char_t *rdfname) :
96 fRawDataFileName(NULL),
104 fBadChannelsList(NULL),
110 fPedestalThresholdFactor(fgkPedestalThresholdFactor) ,
111 fCmThresholdFactor(fgkCmThresholdFactor),
113 fOffsetDefault(INT_MAX),
118 if (!Init(rdfname)) AliError("AliITSHandleDaSSD::AliITSHandleDaSSD() initialization error!");
122 //______________________________________________________________________________
123 AliITSHandleDaSSD::AliITSHandleDaSSD(const AliITSHandleDaSSD& ssdadldc) :
125 fRawDataFileName(ssdadldc.fRawDataFileName),
126 fNumberOfModules(ssdadldc.fNumberOfModules),
128 fModIndProcessed(ssdadldc.fModIndProcessed),
129 fModIndRead(ssdadldc.fModIndRead),
132 fNumberOfEvents(ssdadldc.fNumberOfEvents),
133 fBadChannelsList(NULL),
135 fALaddersOff(ssdadldc.fALaddersOff),
136 fCLaddersOff(ssdadldc.fCLaddersOff),
137 fLdcId(ssdadldc.fLdcId),
138 fRunId(ssdadldc.fRunId),
139 fPedestalThresholdFactor(ssdadldc.fPedestalThresholdFactor),
140 fCmThresholdFactor(ssdadldc.fCmThresholdFactor),
141 fZsDefault(ssdadldc.fZsDefault),
142 fOffsetDefault(ssdadldc.fOffsetDefault),
143 fZsMinimum(ssdadldc.fZsMinimum),
144 fMergeBCLists(ssdadldc.fMergeBCLists),
145 fZsFactor(ssdadldc.fZsFactor)
148 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
149 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
151 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
152 if (ssdadldc.fModules[modind]) {
153 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
154 if (!fModules[modind]) {
155 AliError("AliITSHandleDaSSD: Error copy constructor");
156 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
161 } else fModules[modind] = NULL;
164 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
165 fNumberOfModules = 0;
169 if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by copy constructor, use other methods to init it!");
170 if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by copy constructor, use other methods to init it!");
174 //______________________________________________________________________________
175 AliITSHandleDaSSD& AliITSHandleDaSSD::operator = (const AliITSHandleDaSSD& ssdadldc)
177 // assignment operator
178 if (this == &ssdadldc) return *this;
179 TObject::operator=(ssdadldc);
181 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
185 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
186 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
187 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
189 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
190 if (ssdadldc.fModules[modind]) {
191 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
192 if (!fModules[modind]) {
193 AliError("AliITSHandleDaSSD: Error assignment operator");
194 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
199 } else fModules[modind] = NULL;
202 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
203 fNumberOfModules = 0;
207 if (ssdadldc.fRawDataFileName) {
208 fRawDataFileName = new (nothrow) Char_t[strlen(ssdadldc.fRawDataFileName)+1];
209 if (fRawDataFileName) strncpy(fRawDataFileName, ssdadldc.fRawDataFileName, strlen(ssdadldc.fRawDataFileName)+1);
210 } else fRawDataFileName = ssdadldc.fRawDataFileName;
211 fModIndProcessed = ssdadldc.fModIndProcessed;
212 fModIndRead = ssdadldc.fModIndRead;
214 if (ssdadldc.fModIndex) {
215 fModIndex = new (nothrow) Int_t [ssdadldc.fNumberOfModules];
216 if (fModIndex) memcpy(fModIndex, ssdadldc.fModIndex, ssdadldc.fNumberOfModules*sizeof(Int_t));
217 } else fModIndex = ssdadldc.fModIndex;
219 fEqIndex = ssdadldc.fEqIndex;
220 fNumberOfEvents = ssdadldc.fNumberOfEvents;
221 fLdcId = ssdadldc.fLdcId;
222 fRunId = ssdadldc.fRunId;
223 fPedestalThresholdFactor = ssdadldc.fPedestalThresholdFactor;
224 fCmThresholdFactor = ssdadldc.fCmThresholdFactor;
225 fZsDefault = ssdadldc.fZsDefault;
226 fOffsetDefault = ssdadldc.fOffsetDefault;
227 fZsMinimum = ssdadldc.fZsMinimum;
228 fMergeBCLists = ssdadldc.fMergeBCLists;
229 fZsFactor = ssdadldc.fZsFactor;
230 fALaddersOff = ssdadldc.fALaddersOff;
231 fCLaddersOff = ssdadldc.fCLaddersOff;
232 if (fBadChannelsList) delete fBadChannelsList;
233 fBadChannelsList = new AliITSBadChannelsSSDv2(*ssdadldc.fBadChannelsList);
234 if (fDDLModuleMap) delete [] fDDLModuleMap;
235 if (ssdadldc.fDDLModuleMap) {
236 fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
237 if (fDDLModuleMap) memcpy(fDDLModuleMap, ssdadldc.fDDLModuleMap, fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl * sizeof(Int_t));
238 } else fDDLModuleMap = 0;
240 if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by assignment operator, use other methods to init it!");
241 if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by assignment operator, use other methods to init it!");
246 //______________________________________________________________________________
247 AliITSHandleDaSSD::~AliITSHandleDaSSD()
249 // Default destructor
252 for (Int_t i = 0; i < fNumberOfModules; i++)
254 if (fModules[i]) delete fModules[i];
258 if (fModIndex) delete [] fModIndex;
259 if (fBadChannelsList) delete fBadChannelsList;
260 if (fDDLModuleMap) delete [] fDDLModuleMap;
265 //______________________________________________________________________________
266 void AliITSHandleDaSSD::Reset()
268 // Delete array of AliITSModuleDaSSD* objects.
270 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
274 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
276 if (fBadChannelsList) {
277 delete fBadChannelsList;
278 fBadChannelsList = NULL;
280 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL; }
284 fRawDataFileName = NULL;
285 fModIndProcessed = fModIndRead = 0;
288 fPedestalThresholdFactor = fgkPedestalThresholdFactor;
289 fCmThresholdFactor = fgkCmThresholdFactor;
294 //______________________________________________________________________________
295 Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname)
297 // Read raw data file and set initial and configuration parameters
298 Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0;
299 Int_t nofeqipmentev, nofeqipment = 0, eqn = 0;
300 AliRawReaderDate *rawreaderdate = NULL;
301 UChar_t *data = NULL;
302 Long_t datasize = 0, eqbelsize = 1;
304 rawreaderdate = new AliRawReaderDate(rdfname, 0);
305 if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) {
306 AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname));
310 if (rawreaderdate->NextEvent()) {
311 fRunId = rawreaderdate->GetRunNumber();
312 rawreaderdate->RewindEvents();
313 } else { MakeZombie(); return kFALSE; }
314 if (fModules) Reset();
315 //rawreaderdate->SelectEvents(-1);
316 rawreaderdate->Select("ITSSSD");
318 while (rawreaderdate->NextEvent()) {
319 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
322 while (rawreaderdate->ReadNextData(data)) {
323 fLdcId = rawreaderdate->GetLDCId();
325 datasize = rawreaderdate->GetDataSize();
326 eqbelsize = rawreaderdate->GetEquipmentElementSize();
327 if ( datasize % eqbelsize ) {
328 AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %ld is not an integer of equipment data size %ld",
329 rdfname, datasize, eqbelsize));
333 nofstripsev += (Int_t) (datasize / eqbelsize);
335 if (physeventind++) {
336 if (nofstrips != nofstripsev) AliWarning(Form("AliITSHandleDaSSD: number of strips varies from event to event, ev = %ld, %ld",
337 physeventind, nofstripsev));
338 if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to event");
340 nofstrips = nofstripsev;
341 nofeqipment = nofeqipmentev;
342 if (strn < nofstrips) strn = nofstrips;
343 if (eqn < nofeqipment) eqn = nofeqipment;
345 delete rawreaderdate;
346 if ((physeventind > 0) && (strn > 0))
348 fNumberOfEvents = physeventind;
349 fRawDataFileName = rdfname;
352 fModIndex = new (nothrow) Int_t [fgkNumberOfSSDModulesPerDdl * eqn];
354 for (Int_t i = 0; i < fgkNumberOfSSDModulesPerDdl * eqn; i++) fModIndex[i] = -1;
355 else AliWarning(Form("AliITSHandleDaSSD: Error Init(%s): Index array for %i modules was not created",
356 rdfname, fgkNumberOfSSDModulesPerDdl * eqn));
357 if (SetNumberOfModules(fgkNumberOfSSDModulesPerDdl * eqn)) {
358 TString str = TString::Format("Max number of equipment: %d, max number of channels: %ld\n", eqn, strn);
359 DumpInitData(str.Data());
369 //______________________________________________________________________________
370 AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
372 // Retrieve AliITSModuleDaSSD object from the array
373 if (!fModules) return NULL;
374 for (Int_t i = 0; i < fNumberOfModules; i++) {
376 if ( (fModules[i]->GetDdlId() == ddlID)
377 && (fModules[i]->GetAD() == ad)
378 && (fModules[i]->GetADC() == adc))
386 Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
388 // Retrieve the position of AliITSModuleDaSSD object in the array
389 if (!fModules) return -1;
390 for (Int_t i = 0; i < fNumberOfModules; i++) {
392 if ( (fModules[i]->GetDdlId() == ddlID)
393 && (fModules[i]->GetAD() == ad)
394 && (fModules[i]->GetADC() == adc))
403 //______________________________________________________________________________
404 AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const
406 // Retrieve AliITSChannalDaSSD object from the array
407 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
408 if ( (fModules[modind]->GetDdlId() == ddlID)
409 && (fModules[modind]->GetAD() == ad)
410 && (fModules[modind]->GetADC() == adc) )
412 return fModules[modind]->GetStrip(stripID);
415 AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!",
416 ddlID, ad, adc, stripID));
422 //______________________________________________________________________________
423 Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index)
425 // Assign array element with AliITSModuleDaSSD object
426 if ((index < fNumberOfModules) && (index >= 0))
428 if (fModules[index]) delete fModules[index];
429 fModules[index] = module;
437 //______________________________________________________________________________
438 Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules)
440 // Allocates memory for AliITSModuleDaSSD objects
441 if (numberofmodules > fgkNumberOfSSDModules)
442 AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD",
443 numberofmodules, fgkNumberOfSSDModules));
445 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
449 fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules];
451 fNumberOfModules = numberofmodules;
452 memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules);
455 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules));
456 fNumberOfModules = 0;
464 //______________________________________________________________________________
465 Bool_t AliITSHandleDaSSD::ReadStaticBadChannelsMap(const Char_t *filename)
467 // Reads Static Bad Channels Map from the file
470 AliWarning("No file name is specified for Static Bad Channels Map!");
473 bcfile = new TFile(filename, "READ");
474 if (bcfile->IsZombie()) {
475 AliWarning(Form("Error reading file %s with Static Bad Channels Map!", filename));
478 bcfile->GetObject("AliITSBadChannelsSSDv2;1", fBadChannelsList);
479 if (!fBadChannelsList) {
480 AliWarning("Error fBadChannelsList == NULL!");
492 Bool_t AliITSHandleDaSSD::ReadDDLModuleMap(const Char_t *filename)
494 // Reads the SSD DDL Map from the file
496 AliRawReaderDate *rwr = NULL;
497 AliITSRawStreamSSD *rsm = NULL;
499 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
500 fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
501 if (!fDDLModuleMap) {
502 AliWarning("Error allocation memory for DDL Map!");
506 AliWarning("No file name is specified for SSD DDL Map, using the one from AliITSRawStreamSSD!");
507 rwr = new AliRawReaderDate(event);
508 rsm = new AliITSRawStreamSSD(rwr);
509 rsm->Setv11HybridDDLMapping();
510 for (Int_t ddli = 0; ddli < fgkNumberOfSSDDDLs; ddli++)
511 for (Int_t mi = 0; mi < fgkNumberOfSSDModulesPerDdl; mi++)
512 fDDLModuleMap[(ddli * fgkNumberOfSSDModulesPerDdl + mi)] = rsm->GetModuleNumber(ddli, mi);
517 ddlmfile.open(filename, ios::in);
518 if (!ddlmfile.is_open()) {
519 AliWarning(Form("Error reading file %s with SSD DDL Map!", filename));
520 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
524 while((!ddlmfile.eof()) && (ind < (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))) {
525 ddlmfile >> fDDLModuleMap[ind++];
526 if (ddlmfile.fail()) AliError(Form("Error extracting number from the DDL map file %s, ind: %d ", filename, ind));
528 if (ind != (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))
529 AliWarning(Form("Only %i (< %i) entries were read from DDL Map!", ind, (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl)));
536 //______________________________________________________________________________
537 Int_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber)
539 // Reads raw data from file
540 if (!Init(fileName)){
541 AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile");
544 fNumberOfEvents = eventsnumber;
545 return ReadModuleRawData (fNumberOfModules);
550 //______________________________________________________________________________
551 Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber)
553 // Reads raw data from file
554 AliRawReader *rawreaderdate = NULL;
555 AliITSRawStreamSSD *stream = NULL;
556 AliITSModuleDaSSD *module;
557 AliITSChannelDaSSD *strip;
559 Int_t nofeqipment, eqind;
560 Short_t equipid, prequipid;
562 if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0;
564 AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data");
567 if (!fDDLModuleMap) if (!ReadDDLModuleMap()) AliWarning("DDL map is not defined, ModuleID will be set to 0!");
568 stream = new AliITSRawStreamSSD(rawreaderdate);
569 stream->Setv11HybridDDLMapping();
570 //rawreaderdate->SelectEvents(-1);
571 rawreaderdate->Select("ITSSSD");
574 while (rawreaderdate->NextEvent()) {
575 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
578 while (stream->Next()) {
579 equipid = rawreaderdate->GetEquipmentId();
580 if ((equipid != prequipid)) {
581 if ((eqind = GetEqIndex(equipid)) < 0) { fEqIndex.AddAt(equipid, nofeqipment); eqind = nofeqipment++; }
584 Int_t equiptype = rawreaderdate->GetEquipmentType();
585 UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID();
586 UChar_t ad = stream->GetAD();
587 UChar_t adc = stream->GetADC();
588 UShort_t stripID = stream->GetSideFlag() ? AliITSChannelDaSSD::GetMaxStripIdConst() - stream->GetStrip() : stream->GetStrip();
589 Short_t signal = stream->GetSignal();
591 Int_t indpos = (eqind * fgkNumberOfSSDModulesPerDdl)
592 + ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
593 Int_t modpos = fModIndex[indpos];
594 if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue;
595 if ((modpos < 0) && (modind < modulesnumber)) {
596 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
598 if (fDDLModuleMap) mddli = RetrieveModuleId(ddlID, ad, adc);
600 if (!module->SetModuleIdData (ddlID, ad, adc, mddli)) return 0;
601 module->SetModuleRorcId (equipid, equiptype);
602 modpos = fModIndRead + modind;
604 fModules[modpos] = module;
605 fModIndex[indpos] = modpos;
607 if (stripID < AliITSModuleDaSSD::GetStripsPerModuleConst()) {
608 if (!(strip = fModules[modpos]->GetStrip(stripID))) {
609 strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents);
610 fModules[modpos]->SetStrip(strip, stripID);
612 strip->SetSignal(eventind, signal);
614 if (!(fModules[modpos]->GetCMFerom())) {
615 fModules[modpos]->AllocateCMFeromArray();
616 fModules[modpos]->SetCMFeromEventsNumber(fNumberOfEvents);
618 fModules[modpos]->SetCMFerom(signal, (stripID - AliITSModuleDaSSD::GetStripsPerModuleConst()), eventind);
621 if (++eventind > fNumberOfEvents) break;
624 delete rawreaderdate;
625 if (modind) cout << "The memory was allocated for " << modind << " modules." << endl;
626 fModIndRead += modind;
627 if (modind < modulesnumber) RelocateModules();
633 //______________________________________________________________________________
634 Bool_t AliITSHandleDaSSD::RelocateModules()
636 // Relocate memory for AliITSModuleDaSSD object array
638 AliITSModuleDaSSD **marray = NULL;
639 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
640 if (fModules[modind]) nm += 1;
641 if (nm == fNumberOfModules) return kTRUE;
642 marray = new (nothrow) AliITSModuleDaSSD* [nm];
644 AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm));
648 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
649 if (fModules[modind]) marray[nm++] = fModules[modind];
652 fNumberOfModules = fModIndRead = nm;
658 //______________________________________________________________________________
659 Bool_t AliITSHandleDaSSD::AddFeromCm(const AliITSModuleDaSSD *const module)
661 // Restore the original signal value adding CM calculated and subtracted in ferom
662 AliITSChannelDaSSD *strip;
663 Short_t *signal, *cmferom;
665 if (!module) return kFALSE;
666 if (!module->GetCMFerom()) return kTRUE;
667 for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
668 if (!(cmferom = module->GetCMFerom(chipind))) {
669 AliWarning(Form("AliITSHandleDaSSD: There is no Ferom CM values for chip %i, module %i!", chipind, module->GetModuleId()));
672 for (Int_t strind = (chipind * AliITSModuleDaSSD::GetStripsPerChip());
673 strind < ((chipind + 1) * AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
674 if (!(strip = module->GetStrip(strind))) continue;
675 if (!(signal = strip->GetSignal())) continue;
676 // if (strip->GetEventsNumber() != module->GetEventsNumber()) return kFALSE;
678 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
679 if (SignalOutOfRange(signal[ev]) || SignalOutOfRange(cmferom[ev])) ovev += 1;
681 Short_t signal1 = signal[ev] + cmferom[ev];
682 strip->SetSignal(ev, signal1);
692 //______________________________________________________________________________
693 Bool_t AliITSHandleDaSSD::CalculatePedestal(const AliITSModuleDaSSD *const module)
695 // Calculates Pedestal
696 AliITSChannelDaSSD *strip;
697 Double_t pedestal, noise;
700 if (!module) return kFALSE;
701 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
702 if (!(strip = module->GetStrip(strind))) continue;
703 if (!(signal = strip->GetSignal())) {
704 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
705 module->GetModuleId(), strind));
708 //************* pedestal first pass ****************
711 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
712 if (SignalOutOfRange(signal[ev])) ovev += 1;
713 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1) : signal[ev];
714 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
715 strip->SetPedestal(static_cast<Float_t>(pedestal));
716 //************* noise *******************************
717 Double_t nsum = 0.0L;
719 for (ev = 0; ev < strip->GetEventsNumber(); ev++) {
720 if (SignalOutOfRange(signal[ev])) ovev += 1;
721 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
723 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / (Double_t)(n));
724 else noise = AliITSChannelDaSSD::GetUndefinedValue();
725 strip->SetNoise(static_cast<Float_t>(noise));
726 //************* pedestal second pass ****************
729 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
730 if ( SignalOutOfRange(signal[ev])
731 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
732 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1) : signal[ev];
733 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
734 strip->SetPedestal(static_cast<Float_t>(pedestal));
735 strip->SetOverflowNumber(ovev);
741 //______________________________________________________________________________
742 Bool_t AliITSHandleDaSSD::CalculateNoise(const AliITSModuleDaSSD *const module)
745 AliITSChannelDaSSD *strip;
749 if (!module) return kFALSE;
750 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
751 if (!(strip = module->GetStrip(strind))) continue;
752 if (!(signal = strip->GetSignal())) {
753 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
754 AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()",
755 module->GetModuleId(), strind));
758 Double_t nsum = 0.0L;
760 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
761 if (SignalOutOfRange(signal[ev])) ovev += 1;
762 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
764 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = static_cast<Float_t>(TMath::Sqrt(nsum / (Float_t)(n)));
765 else noise = AliITSChannelDaSSD::GetUndefinedValue();
766 strip->SetNoise(noise);
773 //______________________________________________________________________________
774 Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module)
776 // Calculates Noise with CM correction
777 AliITSChannelDaSSD *strip = NULL;
781 if (!CalculateCM(module)) {
782 AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE");
785 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
786 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
787 if (!(signal = strip->GetSignal())) {
788 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
789 AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCM(): there are no events data for module[%i] strip[%i]->GetSignal()",
790 module->GetModuleId(), strind));
791 continue; //return kFALSE;
793 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
794 Double_t nsum = 0.0L;
796 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
797 if (SignalOutOfRange(signal[ev])) ovev += 1;
798 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
800 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = static_cast<Float_t>(TMath::Sqrt(nsum / (Double_t)(n)));
801 else noise = AliITSChannelDaSSD::GetUndefinedValue();
802 strip->SetNoiseCM(noise);
809 //______________________________________________________________________________
810 Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module)
813 AliITSChannelDaSSD *strip = NULL;
817 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
818 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
819 stripind = chipind * module->GetStripsPerChip();
820 module->GetCM()[chipind].Set(fNumberOfEvents);
821 module->GetCM()[chipind].Reset(0.0f);
822 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
823 // calculate firs approximation of CM.
826 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
827 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
828 if (!(signal = strip->GetSignal())) {
829 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()",
830 module->GetModuleId(), strind));
833 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
834 else cm0 += (signal[ev] - strip->GetPedestal());
836 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n);
837 else { module->SetCM(0.0f, chipind, ev); continue; }
838 // calculate avarage (cm - (signal - pedestal)) over the chip
839 Double_t cmsigma = 0.0L;
841 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
842 if (!(strip = module->GetStrip(strind))) continue;
843 if (!(signal = strip->GetSignal())) {
844 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n",
845 module->GetModuleId(), strind));
848 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
849 else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2);
851 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = TMath::Sqrt(cmsigma / (Float_t)(n));
852 else { module->SetCM(0.0f, chipind, ev); continue; }
853 // calculate cm with threshold
854 Double_t cmsum = 0.0L;
856 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
857 if (!(strip = module->GetStrip(strind))) continue;
858 signal = strip->GetSignal();
859 if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
860 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
861 else cmsum += (signal[ev] - strip->GetPedestal());
863 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n);
865 if (!(module->SetCM(cmsum, chipind, ev)))
866 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
867 module->GetModuleId(), chipind, ev));
874 //______________________________________________________________________________
875 Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread, const Bool_t usewelford)
877 // Performs calculation of calibration parameters (pedestal, noise, ...)
879 if (nmread <= 0) return kFALSE;
880 if (!fModules) return kFALSE;
881 while ((nm = ReadModuleRawData(nmread)) > 0) {
882 cout << "Processing next " << nm << " modules;" << endl;
883 for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) {
884 if (!fModules[modind]) {
885 AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n",
889 AddFeromCm(fModules[modind]);
891 CalculatePedNoiseW(fModules[modind]);
892 CalculateNoiseCMW(fModules[modind]);
894 CalculatePedestal(fModules[modind]);
895 CalculateNoise(fModules[modind]);
896 CalculateNoiseCM(fModules[modind]);
902 fModIndProcessed = fModIndRead;
903 cout << fModIndProcessed << " - done" << endl;
904 if (nm < nmread ) break;
910 //______________________________________________________________________________
911 Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
913 // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class
914 if (!fDDLModuleMap) {
915 AliError("Error DDLMap is not initialized, return 0!");
918 Int_t mddli = ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
919 if ((ddlID < fgkNumberOfSSDDDLs) && (mddli < fgkNumberOfSSDModulesPerDdl)) {
920 mddli = fDDLModuleMap[ddlID * fgkNumberOfSSDModulesPerDdl + mddli];
923 AliWarning(Form("Module index = %d or ddlID = %d is out of range 0 is rturned", ddlID, mddli));
926 if (mddli > SHRT_MAX) return SHRT_MAX;
927 else return (Short_t)mddli;
932 //______________________________________________________________________________
933 AliITSNoiseSSDv2* AliITSHandleDaSSD::GetCalibrationOCDBNoise() const
935 // Fill in the array for OCDB
936 AliITSNoiseSSDv2 *ldcn = NULL;
937 AliITSModuleDaSSD *module = NULL;
938 AliITSChannelDaSSD *strip = NULL;
939 if (!fModules) return NULL;
940 ldcn = new AliITSNoiseSSDv2;
942 AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
945 for (Int_t i = 0; i < fNumberOfModules; i++) {
946 if (!(module = fModules[i])) continue;
947 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
948 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
949 if (!(strip = module->GetStrip(strind))) continue;
950 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
951 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() )
952 ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
954 ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
961 //______________________________________________________________________________
962 AliITSBadChannelsSSDv2* AliITSHandleDaSSD::GetCalibrationBadChannels() const
964 // Fill in the TObjArray with the list of bad channels
965 AliITSBadChannelsSSDv2 *ldcbc = NULL;
966 AliITSModuleDaSSD *module = NULL;
967 AliITSChannelDaSSD *strip = NULL;
968 if (!fModules) return NULL;
969 ldcbc = new AliITSBadChannelsSSDv2;
971 AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
974 for (Int_t i = 0; i < fNumberOfModules; i++) {
975 if (!(module = fModules[i])) continue;
976 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
977 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
978 if (!(strip = module->GetStrip(strind))) continue;
979 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
980 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() )
981 ldcbc->AddBadChannelP(modid, strip->GetStripId(), EvaluateIfChannelIsBad(module, strip->GetStripId()));
983 ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()),
984 EvaluateIfChannelIsBad(module, strip->GetStripId()));
992 //______________________________________________________________________________
993 Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname)
995 // Save Calibration data locally
996 AliITSBadChannelsSSDv2 *ldcbc = NULL;
997 AliITSPedestalSSDv2 *ldcp = NULL;
998 AliITSNoiseSSDv2 *ldcn = NULL;
999 AliITSModuleDaSSD *module = NULL;
1000 AliITSChannelDaSSD *strip = NULL;
1002 TString dadatafilename("");
1003 if (!fModules) return kFALSE;
1004 ldcn = new AliITSNoiseSSDv2;
1005 ldcp = new AliITSPedestalSSDv2;
1006 ldcbc = new AliITSBadChannelsSSDv2;
1007 if ((!ldcn) || (!ldcp) || (!ldcp)) {
1008 AliError("Error allocation mamory for calibration objects, return kFALSE!");
1011 for (Int_t i = 0; i < fNumberOfModules; i++) {
1012 if (!(module = fModules[i])) continue;
1013 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1014 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1015 if (!(strip = module->GetStrip(strind))) continue;
1016 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1017 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) {
1018 ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
1019 ldcp->AddPedestalP(modid, strip->GetStripId(), strip->GetPedestal());
1020 ldcbc->AddBadChannelP(modid, strip->GetStripId(), EvaluateIfChannelIsBad(module, strip->GetStripId()));
1022 ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
1023 ldcp->AddPedestalN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetPedestal());
1024 ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()),
1025 EvaluateIfChannelIsBad(module, strip->GetStripId()));
1029 if (dafname) dadatafilename.Form("%s/", dafname);
1030 dadatafilename += TString::Format("ITSSSDda_%i.root", fLdcId);
1031 tmpfname = new Char_t[dadatafilename.Length()+1];
1032 Int_t sz = dadatafilename.Sizeof();
1033 dafname = strncpy(tmpfname, dadatafilename.Data(),sz);
1034 TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE");
1035 if (fileRun->IsZombie()) {
1036 AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data()));
1044 fileRun->WriteTObject(ldcn);
1045 fileRun->WriteTObject(ldcp);
1046 if (fBadChannelsList)
1047 if (fMergeBCLists) {
1048 MergeBadChannels(ldcbc);
1049 fileRun->WriteTObject(ldcbc);
1050 } else fileRun->WriteTObject(fBadChannelsList);
1051 else fileRun->WriteTObject(ldcbc);
1061 //______________________________________________________________________________
1062 Int_t AliITSHandleDaSSD::MergeBadChannels(AliITSBadChannelsSSDv2*& bcl) const
1064 // Merges the statick bad channels list with bad channels got upon calibration
1065 AliITSModuleDaSSD *module = 0;
1066 Int_t nmpch = 0, nmnch = 0, ngpch = 0, ngnch = 0;
1067 if (!fBadChannelsList || !bcl) {
1068 AliWarning("Either fBadChannelsList == NULL or bad_channels_list == NULL, there is nothing to merge!");
1071 for (Int_t modind = 0; modind < GetNumberOfModules(); modind++) {
1072 if (!(module = fModules[modind])) continue;
1073 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1074 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1075 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetPNStripsPerModule(); strind++) {
1076 if ( (!(fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask))
1077 && (bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask) )
1079 if ( (!(fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask))
1080 && (bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask) )
1082 if ( (!(bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask))
1083 && (fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) {
1084 bcl->AddBadChannelP(modid, strind, fBadChannelsList->GetBadChannelP(modid, strind));
1087 if ( (!(bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask))
1088 && (fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) {
1089 bcl->AddBadChannelN(modid, strind, fBadChannelsList->GetBadChannelN(modid, strind));
1094 AliInfo(Form("Static bad, dynamic good: P%d, N%d", nmpch, nmnch));
1095 AliInfo(Form("Static good, dynamic bad: P%d, N%d", ngpch, ngnch));
1096 return (nmnch + nmpch);
1101 //______________________________________________________________________________
1102 Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
1104 // Dump calibration parameters
1105 AliITSModuleDaSSD *mod;
1106 AliITSChannelDaSSD *strip;
1108 cout << "SSDDALDC::DumpModInfo(): Error, no modules are allocated!" << endl;
1111 cout << "Modules with MeanNoise > " << meannosethreshold << endl;
1112 for (Int_t i = 0; i < fNumberOfModules; i++) {
1113 if (!(mod = fModules[i])) continue;
1114 Double_t maxnoise = 0.0L, meannoise = 0.0L, meanovf = 0.0L;
1115 Float_t maxped = 0.0f;
1116 Int_t maxstrind = 0, novfstr = 0, maxovf = 0;
1117 for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
1118 if (!(strip = mod->GetStrip(strind))) {novfstr++; continue; }
1119 if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++; continue; }
1120 if (maxnoise < strip->GetNoiseCM()) {
1121 maxnoise = strip->GetNoiseCM();
1124 meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Double_t>(strind - novfstr + 1)
1125 : strip->GetNoiseCM();
1126 if (TMath::Abs(maxped) < TMath::Abs(strip->GetPedestal())) maxped = strip->GetPedestal();
1127 meanovf = (strind - novfstr) ? meanovf + (strip->GetOverflowNumber() - meanovf) / static_cast<Double_t>(strind - novfstr + 1)
1128 : strip->GetOverflowNumber();
1129 if (strip->GetOverflowNumber() > maxovf) maxovf = strip->GetOverflowNumber();
1131 if (meannoise > meannosethreshold)
1132 cout << "Mod: " << i << "; DDl: " << (int)mod->GetDdlId() << "; AD: " << (int)mod->GetAD()
1133 << "; ADC: " << (int)mod->GetADC() << "; MaxPed = " << maxped
1134 << "; MeanNoise = " << meannoise << "; MaxNoise = " << maxnoise << "; MaxNoiseStrip = " << maxstrind
1135 << "; NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
1136 if (maxovf > 10) cout << "Max number of events with overflow : " << maxovf << "; mean : " << meanovf << endl;
1143 //______________________________________________________________________________
1144 Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
1146 // Print Module calibration data whether in file or in cout
1147 AliITSChannelDaSSD *strip;
1149 ostream *outputfile;
1150 if (!fname) { outputfile = &cout; }
1152 datafile.open(fname, ios::out);
1153 if (datafile.fail()) return kFALSE;
1154 outputfile = dynamic_cast<ostream*>(&datafile);
1156 *outputfile << "DDL = " << (int)ddlID << "; AD = " << (int)ad << "; ADC = " << (int)adc << endl;
1157 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1158 if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) {
1159 *outputfile << "Str = " << strind << "; ped = " << strip->GetPedestal()
1160 << "; noise = " << strip->GetNoiseCM() << endl;
1164 if (datafile.is_open()) datafile.close();
1170 //______________________________________________________________________________
1171 void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
1173 // Print general information retrieved from raw data file
1174 cout << "Raw data file: " << fRawDataFileName << endl
1175 << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
1176 << "Number of physics events: " << fNumberOfEvents << endl
1181 //______________________________________________________________________________
1182 Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
1184 // Used to allocate simulated modules to test the performance
1185 AliITSModuleDaSSD *module;
1186 UChar_t ad, adc, ddlID;
1187 ad = adc = ddlID = 0;
1188 if (!(fModules[copymodind])) return kFALSE;
1189 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
1190 if (!fModules[modind]) {
1191 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
1192 if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
1193 else if (adc == 5) adc = 8;
1194 else if (adc == 13) {
1196 if (ad < 8) ad += 1;
1202 if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
1203 fModules[modind] = module;
1204 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1205 AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
1206 if(!cstrip)return kFALSE;
1207 Long_t eventsnumber = cstrip->GetEventsNumber();
1208 AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
1209 for (Long_t evind = 0; evind < eventsnumber; evind++) {
1210 Short_t sign = cstrip->GetSignal(evind);
1211 if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
1213 module->SetStrip(strip, strind);
1217 ddlID = fModules[modind]->GetDdlId();
1218 ad = fModules[modind]->GetAD();
1219 adc = fModules[modind]->GetADC();
1222 for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);
1228 //___________________________________________________________________________________________
1229 Bool_t AliITSHandleDaSSD::AdDataPresent(const Int_t ddl, const Int_t ad) const
1231 // Check if there are calibration data for given ddl and slot
1232 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
1233 if ((GetModule(modind)->GetAD() == ad) && (GetModule(modind)->GetDdlId() == ddl)) return kTRUE;
1239 //___________________________________________________________________________________________
1240 Bool_t AliITSHandleDaSSD::SaveEqSlotCalibrationData(const Int_t ddl, const Int_t ad, const Char_t *fname) const
1242 // Saves calibration files for selected equipment (DDL)
1244 Int_t zsml, offsetml;
1245 ULong_t zsth, offset, zsoffset;
1247 AliError("File name must be specified!");
1250 if (!AdDataPresent(ddl, ad)) {
1251 AliError(Form("Error SaveEqSlotCalibrationData(ddl = %i, ad = %i) no data present", ddl, ad));
1254 feefile.open(fname, ios::out);
1255 if (!feefile.is_open()) {
1256 AliError(Form("Can not open the file %s for output!", fname));
1259 for (zsml = 0; fgkZsBitMask >> zsml; zsml++) ;
1260 for (offsetml = 0; fgkOffSetBitMask >> offsetml; offsetml++) ;
1261 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1262 for (Int_t adcb = 0; adcb < fgkAdcPerDBlock; adcb++) {
1264 for (Int_t j = 0; j < 2; j++) {
1265 Int_t adc = adcb + j * 8;
1266 zsth = ZsThreshold(ddl, ad, adc, strind);
1267 offset = OffsetValue(ddl, ad, adc, strind);
1268 zsoffset = zsoffset | (((zsth << offsetml) | offset) << ((j == 0) ? (offsetml + zsml) : 0));
1270 feefile << "0x" << ConvBase(static_cast<unsigned long>(zsoffset), 16) << endl;
1278 //______________________________________________________________________________
1279 Int_t AliITSHandleDaSSD::ChannelIsBad(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1281 // Check if the channel is bad
1282 AliITSModuleDaSSD *module = NULL;
1284 if (fBadChannelsList && fDDLModuleMap) {
1285 modn = RetrieveModuleId(ddl, ad, adc);
1286 if (modn < 0) return -1;
1287 if (modn < fgkMinSSDModuleId) {
1288 AliWarning(Form("Module ddl/ad/adc: %d/%d/%d has number %d which is wrong for SSD module %d", ddl, ad, adc, strn, modn));
1291 Short_t modid = modn - fgkMinSSDModuleId;
1292 if (strn < AliITSModuleDaSSD::GetPNStripsPerModule())
1293 return (fBadChannelsList->GetBadChannelP(modid, strn) & fgkBadChannelMask);
1294 else return (fBadChannelsList->GetBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strn)) & fgkBadChannelMask);
1296 AliError("Error ether bad channels list or DDLMap is not initialized or both, EvaluateIfChannelIsBad(module, strip) is used!");
1297 if ((module = GetModule(ddl, ad, adc))) {
1298 return (EvaluateIfChannelIsBad(module, strn) & fgkBadChannelMask);
1300 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1309 //______________________________________________________________________________
1310 Int_t AliITSHandleDaSSD::LadderIsOff(const UChar_t ddl, const UChar_t ad, const UChar_t adc) const
1312 //Checks if the module with given ddl, ad, adc is on the ladder which is in the list of ladders which are off
1313 const Int_t nm5 = 500;
1314 const Int_t nm6 = 1248;
1315 const Int_t nml5a = 12;
1316 const Int_t nml5c = 10;
1317 const Int_t nml6a = 12;
1318 const Int_t nml6c = 13;
1319 Int_t modn, ladder, layer, side;
1320 AliITSModuleDaSSD *module;
1321 if (!(module = GetModule(ddl, ad, adc))) return 0;
1322 if ((modn = module->GetModuleId()) <= 0) modn = RetrieveModuleId(ddl, ad, adc);
1323 if (modn <= 0) return 0;
1324 layer = modn >= nm6 ? 1 : 0; // 6 : 5
1325 ladder = (modn - (layer ? nm6 : nm5)) / (layer ? (nml6a + nml6c) : (nml5a + nml5c));
1326 if ( ((modn - (layer ? nm6 : nm5)) % (layer ? (nml6a + nml6c) : (nml5a + nml5c))) < (layer ? nml6a : nml5a))
1329 ladder += (layer ? 600 : 500);
1332 if (fCLaddersOff.GetSize()) {
1333 for(Int_t i = 0; i < fCLaddersOff.GetSize(); i++)
1334 if (fCLaddersOff.At(i) == ladder) return fCLaddersOff.At(i);
1338 if (fALaddersOff.GetSize()) {
1339 for(Int_t i = 0; i < fALaddersOff.GetSize(); i++)
1340 if (fALaddersOff.At(i) == ladder) return fALaddersOff.At(i);
1348 //______________________________________________________________________________
1349 ULong_t AliITSHandleDaSSD::OffsetValue(const AliITSChannelDaSSD *strip,
1350 const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1352 // Calculate the offset value to be upload to FEROM
1354 if (fOffsetDefault < INT_MAX) pedint = fOffsetDefault;
1355 else pedint = TMath::Nint(strip->GetPedestal());
1356 if (pedint > static_cast<Int_t>((fgkOffSetBitMask >> 1))) {
1357 if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (EvaluateIfChannelIsBad(GetModule(ddl, ad, adc), strn))))
1358 AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
1359 pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), (fgkOffSetBitMask >> 1)));
1360 return (fgkOffSetBitMask >> 1);
1362 if ((-pedint) > static_cast<Int_t>(((fgkOffSetBitMask + 1) >> 1))) {
1363 if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (EvaluateIfChannelIsBad(GetModule(ddl, ad, adc), strn))))
1364 AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
1365 pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(),
1366 ((fgkOffSetBitMask & (~fgkOffSetBitMask >> 1)) - fgkOffSetBitMask - 1)));
1367 return fgkOffSetBitMask & (~fgkOffSetBitMask >> 1);
1369 return fgkOffSetBitMask & (pedint >= 0 ? pedint : pedint + fgkOffSetBitMask + 1);
1374 //______________________________________________________________________________
1375 ULong_t AliITSHandleDaSSD::OffsetValue(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1377 // Calculate the offset value to be upload to FEROM
1378 AliITSChannelDaSSD *strip = NULL;
1379 AliITSModuleDaSSD *module = NULL;
1380 if ((module = GetModule(ddl, ad, adc))) {
1381 if ((strip = module->GetStrip(strn))) return OffsetValue(strip, ddl, ad, adc, strn);
1383 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
1387 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1394 //______________________________________________________________________________
1395 ULong_t AliITSHandleDaSSD::ZsThreshold(const AliITSChannelDaSSD *strip) const
1397 // Calculate the value of zero suppression threshold to be upload to FEROM
1399 if (fZsDefault < 0) {
1400 zs = TMath::Nint(fZsFactor * strip->GetNoiseCM());
1401 if (zs < static_cast<ULong_t>(fZsMinimum)) zs = static_cast<ULong_t>(fZsMinimum);
1403 else zs = fZsDefault;
1404 return (zs < fgkZsBitMask) ? (zs & fgkZsBitMask) : fgkZsBitMask;
1408 //______________________________________________________________________________
1409 ULong_t AliITSHandleDaSSD::ZsThreshold(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1411 // Calculate the value of zero suppression threshold to be upload to FEROM, account bad channels list
1412 AliITSChannelDaSSD *strip = NULL;
1413 AliITSModuleDaSSD *module = NULL;
1414 if (ChannelIsBad(ddl, ad, adc, strn)) return fgkZsBitMask;
1415 if (LadderIsOff(ddl, ad, adc)) return fgkZsBitMask;
1416 if (fZsDefault > 0) if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) return fgkZsBitMask;
1417 if ((module = GetModule(ddl, ad, adc))) {
1418 if (fMergeBCLists) if (EvaluateIfChannelIsBad(module, strn)) return fgkZsBitMask;
1419 if ((strip = module->GetStrip(strn))) return ZsThreshold(strip);
1421 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
1425 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1431 //______________________________________________________________________________
1432 string AliITSHandleDaSSD::ConvBase(const unsigned long value, const long base) const
1434 // Converts the unsigned long number into that in another base
1435 string digits = "0123456789ABCDEF";
1437 unsigned long v = value;
1438 if((base < 2) || (base > 16)) {
1439 result = "Error: base out of range.";
1444 result = digits[v % base] + result;
1448 while((v) || (i<8));
1455 //______________________________________________________________________________
1456 Int_t AliITSHandleDaSSD::CheckOffChips() const
1458 // Check if the chip, module are off
1459 AliITSChannelDaSSD *strip;
1461 Int_t strnd, chipnd, modnd, stroff, chipoff, modoff;
1462 offthreshold = TMath::Nint(fZsMinimum/fZsFactor);
1464 for (Int_t mi = 0; mi < fNumberOfModules; mi++) {
1465 if (!fModules[mi]) { modnd++; continue; }
1466 if (fModules[mi]->GetModuleId() < 0) continue;
1467 if (LadderIsOff(fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()) ) continue;
1468 chipoff = chipnd = 0;
1469 for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
1471 Int_t stripind = chipind * AliITSModuleDaSSD::GetStripsPerChip();
1472 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1473 if (!(strip = fModules[mi]->GetStrip(strind))) { strnd++; continue; }
1474 if (strip->GetNoiseCM() < offthreshold ) stroff++;
1476 if (strnd == AliITSModuleDaSSD::GetStripsPerChip()) chipnd++;
1477 else if (stroff == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1478 else if ((stroff + strnd) == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1480 if ((!chipoff) && (!chipnd)) continue;
1481 if (chipnd == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1482 AliInfo(Form("Module: (ddl/ad/adc) %i/%i/%i seems to be off and it is not on the ladders which are off!",
1483 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1486 if (chipoff == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1487 AliInfo(Form("Module (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
1488 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1491 else if ((chipoff + chipnd) == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1492 AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
1493 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1497 AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i has %i chips which are off!",
1498 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC(), chipoff));
1502 return (modoff + modnd);
1506 //______________________________________________________________________________
1507 Bool_t AliITSHandleDaSSD::CalculatePedNoiseW(const AliITSModuleDaSSD *const module)
1509 // Calculates Pedestal and Noise using Welford algorithm
1510 AliITSChannelDaSSD *strip;
1511 Double_t pedestal, noise, p0, s0;
1514 if (!module) return kFALSE;
1515 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1516 if (!(strip = module->GetStrip(strind))) continue;
1517 if (!(signal = strip->GetSignal())) {
1518 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
1519 module->GetModuleId(), strind));
1522 //************* pedestal and noise first pass ****************
1523 pedestal = p0 = noise = 0.0L;
1525 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1526 if (SignalOutOfRange(signal[ev])) ovev += 1;
1529 pedestal = p0 = signal[ev];
1532 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1533 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1538 if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
1539 strip->SetPedestal(static_cast<Float_t>(pedestal));
1540 if ((n = strip->GetEventsNumber() - ovev - 1) > 0)
1541 strip->SetNoise( static_cast<Float_t>(TMath::Sqrt(noise / static_cast<Double_t>(n))) );
1543 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
1546 //************* Second pass excluds event with |p - s|>f*noise *****************
1547 pedestal = p0 = noise = 0.0L;
1549 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1550 if ( SignalOutOfRange(signal[ev])
1551 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
1554 pedestal = p0 = signal[ev];
1557 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1558 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1563 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n));
1564 else noise = AliITSChannelDaSSD::GetUndefinedValue();
1565 strip->SetNoise(static_cast<Float_t>(noise));
1566 if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
1567 strip->SetPedestal(static_cast<Float_t>(pedestal));
1568 strip->SetOverflowNumber(ovev);
1574 //______________________________________________________________________________
1575 Bool_t AliITSHandleDaSSD::CalculateCMW(AliITSModuleDaSSD *const module)
1577 // Calculates CM using Welford algorithm
1578 AliITSChannelDaSSD *strip = NULL;
1582 Double_t cm0, cm1, cmsigma, cms1;
1583 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
1584 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
1585 stripind = chipind * module->GetStripsPerChip();
1586 module->GetCM()[chipind].Set(fNumberOfEvents);
1587 module->GetCM()[chipind].Reset(0.0f);
1588 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
1589 // calculate firs approximation of CM and SigmaCM.
1590 cm0 = cm1 = cmsigma = 0.0L;
1592 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1593 if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; } //return kFALSE;
1594 if (!(signal = strip->GetSignal())) { ovstr += 1; continue; } //return kFALSE;
1595 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
1597 if (!(strind - stripind - ovstr)) {
1598 cm0 = cm1 = signal[ev] - strip->GetPedestal();
1601 cm1 = cm0 + (signal[ev] - strip->GetPedestal() - cm0) / static_cast<Double_t>(strind - stripind - ovstr + 1);
1602 cms1 = cmsigma + (signal[ev] - strip->GetPedestal() - cm0) * (signal[ev] - strip->GetPedestal() - cm1);
1607 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr - 1) > 0) cmsigma = TMath::Sqrt(cmsigma / static_cast<Double_t>(n));
1609 AliWarning(Form("AliITSHandleDaSSD: Too little number of strips have a signal for module:chip:event : [%d]:[%d]:[%ld]\n",
1610 module->GetModuleId(), chipind, ev));
1611 if (!(module->SetCM(0.0f, chipind, ev)))
1612 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
1613 module->GetModuleId(), chipind, ev));
1616 // calculate cm with threshold
1617 Double_t cmsum = 0.0L;
1619 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1620 if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; }
1621 if (!(signal = strip->GetSignal())) { ovstr += 1; continue; }
1622 if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
1623 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
1624 else cmsum += (signal[ev] - strip->GetPedestal());
1626 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Double_t)(n);
1628 if (!(module->SetCM(static_cast<Float_t>(cmsum), chipind, ev)))
1629 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
1630 module->GetModuleId(), chipind, ev));
1637 //______________________________________________________________________________
1638 Bool_t AliITSHandleDaSSD::CalculateNoiseCMW(AliITSModuleDaSSD *const module)
1640 // Calculates Noise with CM correction
1641 AliITSChannelDaSSD *strip = NULL;
1644 if (!CalculateCMW(module)) {
1645 AliError("Error: AliITSHandleDaSSD::CalculateCMW() returned kFALSE");
1648 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1649 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
1650 if (!(signal = strip->GetSignal())) {
1651 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
1652 AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCMW(): there are no events data for module[%i] strip[%i]->GetSignal()",
1653 module->GetModuleId(), strind));
1654 continue; //return kFALSE;
1656 //** To get exactly the same set of events as for pedestal and noise calculation **
1657 Double_t pedestal, noise, p0, s0;
1658 pedestal = p0 = noise = 0.0L;
1660 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1661 if (SignalOutOfRange(signal[ev])) ovev += 1;
1664 pedestal = p0 = signal[ev];
1667 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1668 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1673 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n));
1675 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
1678 //** Calculation of CM corrected noise **
1679 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
1680 Double_t nsum = 0.0L;
1682 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1683 if ( SignalOutOfRange(signal[ev])
1684 || TMath::Abs(signal[ev] - pedestal) > (fPedestalThresholdFactor * noise)) ovev += 1;
1685 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
1687 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / static_cast<Double_t>(n));
1688 else noise = AliITSChannelDaSSD::GetUndefinedValue();
1689 strip->SetNoiseCM(static_cast<Float_t>(noise));
1696 //______________________________________________________________________________
1697 UChar_t AliITSHandleDaSSD::EvaluateIfChannelIsBad(const AliITSModuleDaSSD *const module, const Int_t stripn) const
1699 //Applies the bad channel creteria and set the appropriate flags for returned value
1700 AliITSChannelDaSSD *strip = 0;
1702 if (fZsDefault >= 0) { if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) bcflags |= 3; }
1703 else if (static_cast<ULong_t>(fZsMinimum) >= fgkZsBitMask) bcflags |= 3;
1704 if (LadderIsOff(module->GetDdlId(), module->GetAD(), module->GetADC()) ) bcflags |= 3;
1706 if (!(strip = module->GetStrip(stripn))) bcflags |= 3;
1708 if (strip->GetNoiseCM() == AliITSChannelDaSSD::GetUndefinedValue()) bcflags |= 8;
1709 if (static_cast<ULong_t>(TMath::Nint(fZsFactor * strip->GetNoiseCM())) >= fgkZsBitMask) bcflags |= 8;
1710 if (strip->GetNoiseCM() < 1) bcflags |= 16;
1711 if (strip->GetPedestal() > ((fgkOffSetBitMask >> 1) - 1)) bcflags |= 4;
1712 else if ((-(strip->GetPedestal())) > (fgkOffSetBitMask >> 1)) bcflags |= 4;
1713 if (bcflags) bcflags |= 3;