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 fNumberOfModules = ssdadldc.fNumberOfModules;
187 if ((fNumberOfModules > 0) && (ssdadldc.fModules)) {
188 fModules = new (nothrow) AliITSModuleDaSSD* [fNumberOfModules];
190 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
191 if (ssdadldc.fModules[modind]) {
192 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
193 if (!fModules[modind]) {
194 AliError("AliITSHandleDaSSD: Error assignment operator");
195 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
200 } else fModules[modind] = NULL;
203 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
204 fNumberOfModules = 0;
208 if (ssdadldc.fRawDataFileName) {
209 fRawDataFileName = new (nothrow) Char_t[strlen(ssdadldc.fRawDataFileName)+1];
210 if (fRawDataFileName) strncpy(fRawDataFileName, ssdadldc.fRawDataFileName, strlen(ssdadldc.fRawDataFileName)+1);
211 } else fRawDataFileName = ssdadldc.fRawDataFileName;
212 fModIndProcessed = ssdadldc.fModIndProcessed;
213 fModIndRead = ssdadldc.fModIndRead;
215 if (ssdadldc.fModIndex) {
216 fModIndex = new (nothrow) Int_t [ssdadldc.fNumberOfModules];
217 if (fModIndex) memcpy(fModIndex, ssdadldc.fModIndex, ssdadldc.fNumberOfModules*sizeof(Int_t));
218 } else fModIndex = ssdadldc.fModIndex;
220 fEqIndex = ssdadldc.fEqIndex;
221 fNumberOfEvents = ssdadldc.fNumberOfEvents;
222 fLdcId = ssdadldc.fLdcId;
223 fRunId = ssdadldc.fRunId;
224 fPedestalThresholdFactor = ssdadldc.fPedestalThresholdFactor;
225 fCmThresholdFactor = ssdadldc.fCmThresholdFactor;
226 fZsDefault = ssdadldc.fZsDefault;
227 fOffsetDefault = ssdadldc.fOffsetDefault;
228 fZsMinimum = ssdadldc.fZsMinimum;
229 fMergeBCLists = ssdadldc.fMergeBCLists;
230 fZsFactor = ssdadldc.fZsFactor;
231 fALaddersOff = ssdadldc.fALaddersOff;
232 fCLaddersOff = ssdadldc.fCLaddersOff;
233 if (fBadChannelsList) delete fBadChannelsList;
234 fBadChannelsList = new AliITSBadChannelsSSDv2(*ssdadldc.fBadChannelsList);
235 if (fDDLModuleMap) delete [] fDDLModuleMap;
236 if (ssdadldc.fDDLModuleMap) {
237 fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
238 if (fDDLModuleMap) memcpy(fDDLModuleMap, ssdadldc.fDDLModuleMap, fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl * sizeof(Int_t));
239 } else fDDLModuleMap = 0;
241 if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by assignment operator, use other methods to init it!");
242 if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by assignment operator, use other methods to init it!");
247 //______________________________________________________________________________
248 AliITSHandleDaSSD::~AliITSHandleDaSSD()
250 // Default destructor
253 for (Int_t i = 0; i < fNumberOfModules; i++)
255 if (fModules[i]) delete fModules[i];
259 if (fModIndex) delete [] fModIndex;
260 if (fBadChannelsList) delete fBadChannelsList;
261 if (fDDLModuleMap) delete [] fDDLModuleMap;
266 //______________________________________________________________________________
267 void AliITSHandleDaSSD::Reset()
269 // Delete array of AliITSModuleDaSSD* objects.
271 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
275 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
277 if (fBadChannelsList) {
278 delete fBadChannelsList;
279 fBadChannelsList = NULL;
281 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL; }
285 fRawDataFileName = NULL;
286 fModIndProcessed = fModIndRead = 0;
289 fPedestalThresholdFactor = fgkPedestalThresholdFactor;
290 fCmThresholdFactor = fgkCmThresholdFactor;
295 //______________________________________________________________________________
296 Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname)
298 // Read raw data file and set initial and configuration parameters
299 Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0;
300 Int_t nofeqipmentev, nofeqipment = 0, eqn = 0;
301 AliRawReaderDate *rawreaderdate = NULL;
302 UChar_t *data = NULL;
303 Long_t datasize = 0, eqbelsize = 1;
305 rawreaderdate = new AliRawReaderDate(rdfname, 0);
306 if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) {
307 AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname));
311 if (rawreaderdate->NextEvent()) {
312 fRunId = rawreaderdate->GetRunNumber();
313 rawreaderdate->RewindEvents();
314 } else { MakeZombie(); return kFALSE; }
315 if (fModules) Reset();
316 //rawreaderdate->SelectEvents(-1);
317 rawreaderdate->Select("ITSSSD");
319 while (rawreaderdate->NextEvent()) {
320 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
323 while (rawreaderdate->ReadNextData(data)) {
324 fLdcId = rawreaderdate->GetLDCId();
326 datasize = rawreaderdate->GetDataSize();
327 eqbelsize = rawreaderdate->GetEquipmentElementSize();
328 if ( datasize % eqbelsize ) {
329 AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %ld is not an integer of equipment data size %ld",
330 rdfname, datasize, eqbelsize));
334 nofstripsev += (Int_t) (datasize / eqbelsize);
336 if (physeventind++) {
337 if (nofstrips != nofstripsev) AliWarning(Form("AliITSHandleDaSSD: number of strips varies from event to event, ev = %ld, %ld",
338 physeventind, nofstripsev));
339 if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to event");
341 nofstrips = nofstripsev;
342 nofeqipment = nofeqipmentev;
343 if (strn < nofstrips) strn = nofstrips;
344 if (eqn < nofeqipment) eqn = nofeqipment;
346 delete rawreaderdate;
347 if ((physeventind > 0) && (strn > 0))
349 fNumberOfEvents = physeventind;
350 fRawDataFileName = rdfname;
353 fModIndex = new (nothrow) Int_t [fgkNumberOfSSDModulesPerDdl * eqn];
355 for (Int_t i = 0; i < fgkNumberOfSSDModulesPerDdl * eqn; i++) fModIndex[i] = -1;
356 else AliWarning(Form("AliITSHandleDaSSD: Error Init(%s): Index array for %i modules was not created",
357 rdfname, fgkNumberOfSSDModulesPerDdl * eqn));
358 if (SetNumberOfModules(fgkNumberOfSSDModulesPerDdl * eqn)) {
359 TString str = TString::Format("Max number of equipment: %d, max number of channels: %ld\n", eqn, strn);
360 DumpInitData(str.Data());
370 //______________________________________________________________________________
371 AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
373 // Retrieve AliITSModuleDaSSD object from the array
374 if (!fModules) return NULL;
375 for (Int_t i = 0; i < fNumberOfModules; i++) {
377 if ( (fModules[i]->GetDdlId() == ddlID)
378 && (fModules[i]->GetAD() == ad)
379 && (fModules[i]->GetADC() == adc))
387 Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
389 // Retrieve the position of AliITSModuleDaSSD object in the array
390 if (!fModules) return -1;
391 for (Int_t i = 0; i < fNumberOfModules; i++) {
393 if ( (fModules[i]->GetDdlId() == ddlID)
394 && (fModules[i]->GetAD() == ad)
395 && (fModules[i]->GetADC() == adc))
404 //______________________________________________________________________________
405 AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const
407 // Retrieve AliITSChannalDaSSD object from the array
408 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
409 if ( (fModules[modind]->GetDdlId() == ddlID)
410 && (fModules[modind]->GetAD() == ad)
411 && (fModules[modind]->GetADC() == adc) )
413 return fModules[modind]->GetStrip(stripID);
416 AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!",
417 ddlID, ad, adc, stripID));
423 //______________________________________________________________________________
424 Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index)
426 // Assign array element with AliITSModuleDaSSD object
427 if ((index < fNumberOfModules) && (index >= 0))
429 if (fModules[index]) delete fModules[index];
430 fModules[index] = module;
438 //______________________________________________________________________________
439 Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules)
441 // Allocates memory for AliITSModuleDaSSD objects
442 if (numberofmodules > fgkNumberOfSSDModules)
443 AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD",
444 numberofmodules, fgkNumberOfSSDModules));
446 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
450 fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules];
452 fNumberOfModules = numberofmodules;
453 memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules);
456 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules));
457 fNumberOfModules = 0;
465 //______________________________________________________________________________
466 Bool_t AliITSHandleDaSSD::ReadStaticBadChannelsMap(const Char_t *filename)
468 // Reads Static Bad Channels Map from the file
471 AliWarning("No file name is specified for Static Bad Channels Map!");
474 bcfile = new TFile(filename, "READ");
475 if (bcfile->IsZombie()) {
476 AliWarning(Form("Error reading file %s with Static Bad Channels Map!", filename));
479 bcfile->GetObject("AliITSBadChannelsSSDv2;1", fBadChannelsList);
480 if (!fBadChannelsList) {
481 AliWarning("Error fBadChannelsList == NULL!");
493 Bool_t AliITSHandleDaSSD::ReadDDLModuleMap(const Char_t *filename)
495 // Reads the SSD DDL Map from the file
497 AliRawReaderDate *rwr = NULL;
498 AliITSRawStreamSSD *rsm = NULL;
500 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
501 fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
502 if (!fDDLModuleMap) {
503 AliWarning("Error allocation memory for DDL Map!");
507 AliWarning("No file name is specified for SSD DDL Map, using the one from AliITSRawStreamSSD!");
508 rwr = new AliRawReaderDate(event);
509 rsm = new AliITSRawStreamSSD(rwr);
510 rsm->Setv11HybridDDLMapping();
511 for (Int_t ddli = 0; ddli < fgkNumberOfSSDDDLs; ddli++)
512 for (Int_t mi = 0; mi < fgkNumberOfSSDModulesPerDdl; mi++)
513 fDDLModuleMap[(ddli * fgkNumberOfSSDModulesPerDdl + mi)] = rsm->GetModuleNumber(ddli, mi);
518 ddlmfile.open(filename, ios::in);
519 if (!ddlmfile.is_open()) {
520 AliWarning(Form("Error reading file %s with SSD DDL Map!", filename));
521 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
525 while((!ddlmfile.eof()) && (ind < (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))) {
526 ddlmfile >> fDDLModuleMap[ind++];
527 if (ddlmfile.fail()) AliError(Form("Error extracting number from the DDL map file %s, ind: %d ", filename, ind));
529 if (ind != (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))
530 AliWarning(Form("Only %i (< %i) entries were read from DDL Map!", ind, (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl)));
537 //______________________________________________________________________________
538 Int_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber)
540 // Reads raw data from file
541 if (!Init(fileName)){
542 AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile");
545 fNumberOfEvents = eventsnumber;
546 return ReadModuleRawData (fNumberOfModules);
551 //______________________________________________________________________________
552 Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber)
554 // Reads raw data from file
555 AliRawReader *rawreaderdate = NULL;
556 AliITSRawStreamSSD *stream = NULL;
557 AliITSModuleDaSSD *module;
558 AliITSChannelDaSSD *strip;
560 Int_t nofeqipment, eqind;
561 Short_t equipid, prequipid;
563 if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0;
565 AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data");
568 if (!fDDLModuleMap) if (!ReadDDLModuleMap()) AliWarning("DDL map is not defined, ModuleID will be set to 0!");
569 stream = new AliITSRawStreamSSD(rawreaderdate);
570 stream->Setv11HybridDDLMapping();
571 //rawreaderdate->SelectEvents(-1);
572 rawreaderdate->Select("ITSSSD");
575 while (rawreaderdate->NextEvent()) {
576 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
579 while (stream->Next()) {
580 equipid = rawreaderdate->GetEquipmentId();
581 if ((equipid != prequipid)) {
582 if ((eqind = GetEqIndex(equipid)) < 0) { fEqIndex.AddAt(equipid, nofeqipment); eqind = nofeqipment++; }
585 Int_t equiptype = rawreaderdate->GetEquipmentType();
586 UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID();
587 UChar_t ad = stream->GetAD();
588 UChar_t adc = stream->GetADC();
589 UShort_t stripID = stream->GetSideFlag() ? AliITSChannelDaSSD::GetMaxStripIdConst() - stream->GetStrip() : stream->GetStrip();
590 Short_t signal = stream->GetSignal();
592 Int_t indpos = (eqind * fgkNumberOfSSDModulesPerDdl)
593 + ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
594 Int_t modpos = fModIndex[indpos];
595 if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue;
596 if ((modpos < 0) && (modind < modulesnumber)) {
597 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
599 if (fDDLModuleMap) mddli = RetrieveModuleId(ddlID, ad, adc);
601 if (!module->SetModuleIdData (ddlID, ad, adc, mddli)) return 0;
602 module->SetModuleRorcId (equipid, equiptype);
603 modpos = fModIndRead + modind;
605 fModules[modpos] = module;
606 fModIndex[indpos] = modpos;
608 if (stripID < AliITSModuleDaSSD::GetStripsPerModuleConst()) {
609 if (!(strip = fModules[modpos]->GetStrip(stripID))) {
610 strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents);
611 fModules[modpos]->SetStrip(strip, stripID);
613 strip->SetSignal(eventind, signal);
615 if (!(fModules[modpos]->GetCMFerom())) {
616 fModules[modpos]->AllocateCMFeromArray();
617 fModules[modpos]->SetCMFeromEventsNumber(fNumberOfEvents);
619 fModules[modpos]->SetCMFerom(signal, (stripID - AliITSModuleDaSSD::GetStripsPerModuleConst()), eventind);
622 if (++eventind > fNumberOfEvents) break;
625 delete rawreaderdate;
626 if (modind) cout << "The memory was allocated for " << modind << " modules." << endl;
627 fModIndRead += modind;
628 if (modind < modulesnumber) RelocateModules();
634 //______________________________________________________________________________
635 Bool_t AliITSHandleDaSSD::RelocateModules()
637 // Relocate memory for AliITSModuleDaSSD object array
639 AliITSModuleDaSSD **marray = NULL;
640 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
641 if (fModules[modind]) nm += 1;
642 if (nm == fNumberOfModules) return kTRUE;
643 marray = new (nothrow) AliITSModuleDaSSD* [nm];
645 AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm));
649 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
650 if (fModules[modind]) marray[nm++] = fModules[modind];
653 fNumberOfModules = fModIndRead = nm;
659 //______________________________________________________________________________
660 Bool_t AliITSHandleDaSSD::AddFeromCm(const AliITSModuleDaSSD *const module)
662 // Restore the original signal value adding CM calculated and subtracted in ferom
663 AliITSChannelDaSSD *strip;
664 Short_t *signal, *cmferom;
666 if (!module) return kFALSE;
667 if (!module->GetCMFerom()) return kTRUE;
668 for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
669 if (!(cmferom = module->GetCMFerom(chipind))) {
670 AliWarning(Form("AliITSHandleDaSSD: There is no Ferom CM values for chip %i, module %i!", chipind, module->GetModuleId()));
673 for (Int_t strind = (chipind * AliITSModuleDaSSD::GetStripsPerChip());
674 strind < ((chipind + 1) * AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
675 if (!(strip = module->GetStrip(strind))) continue;
676 if (!(signal = strip->GetSignal())) continue;
677 // if (strip->GetEventsNumber() != module->GetEventsNumber()) return kFALSE;
679 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
680 if (SignalOutOfRange(signal[ev]) || SignalOutOfRange(cmferom[ev])) ovev += 1;
682 Short_t signal1 = signal[ev] + cmferom[ev];
683 strip->SetSignal(ev, signal1);
693 //______________________________________________________________________________
694 Bool_t AliITSHandleDaSSD::CalculatePedestal(const AliITSModuleDaSSD *const module)
696 // Calculates Pedestal
697 AliITSChannelDaSSD *strip;
698 Double_t pedestal, noise;
701 if (!module) return kFALSE;
702 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
703 if (!(strip = module->GetStrip(strind))) continue;
704 if (!(signal = strip->GetSignal())) {
705 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
706 module->GetModuleId(), strind));
709 //************* pedestal first pass ****************
712 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
713 if (SignalOutOfRange(signal[ev])) ovev += 1;
714 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1) : signal[ev];
715 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
716 strip->SetPedestal(static_cast<Float_t>(pedestal));
717 //************* noise *******************************
718 Double_t nsum = 0.0L;
720 for (ev = 0; ev < strip->GetEventsNumber(); ev++) {
721 if (SignalOutOfRange(signal[ev])) ovev += 1;
722 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
724 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / (Double_t)(n));
725 else noise = AliITSChannelDaSSD::GetUndefinedValue();
726 strip->SetNoise(static_cast<Float_t>(noise));
727 //************* pedestal second pass ****************
730 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
731 if ( SignalOutOfRange(signal[ev])
732 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
733 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1) : signal[ev];
734 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
735 strip->SetPedestal(static_cast<Float_t>(pedestal));
736 strip->SetOverflowNumber(ovev);
742 //______________________________________________________________________________
743 Bool_t AliITSHandleDaSSD::CalculateNoise(const AliITSModuleDaSSD *const module)
746 AliITSChannelDaSSD *strip;
750 if (!module) return kFALSE;
751 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
752 if (!(strip = module->GetStrip(strind))) continue;
753 if (!(signal = strip->GetSignal())) {
754 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
755 AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()",
756 module->GetModuleId(), strind));
759 Double_t nsum = 0.0L;
761 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
762 if (SignalOutOfRange(signal[ev])) ovev += 1;
763 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
765 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = static_cast<Float_t>(TMath::Sqrt(nsum / (Float_t)(n)));
766 else noise = AliITSChannelDaSSD::GetUndefinedValue();
767 strip->SetNoise(noise);
774 //______________________________________________________________________________
775 Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module)
777 // Calculates Noise with CM correction
778 AliITSChannelDaSSD *strip = NULL;
782 if (!CalculateCM(module)) {
783 AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE");
786 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
787 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
788 if (!(signal = strip->GetSignal())) {
789 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
790 AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCM(): there are no events data for module[%i] strip[%i]->GetSignal()",
791 module->GetModuleId(), strind));
792 continue; //return kFALSE;
794 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
795 Double_t nsum = 0.0L;
797 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
798 if (SignalOutOfRange(signal[ev])) ovev += 1;
799 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
801 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = static_cast<Float_t>(TMath::Sqrt(nsum / (Double_t)(n)));
802 else noise = AliITSChannelDaSSD::GetUndefinedValue();
803 strip->SetNoiseCM(noise);
810 //______________________________________________________________________________
811 Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module)
814 AliITSChannelDaSSD *strip = NULL;
818 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
819 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
820 stripind = chipind * module->GetStripsPerChip();
821 module->GetCM()[chipind].Set(fNumberOfEvents);
822 module->GetCM()[chipind].Reset(0.0f);
823 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
824 // calculate firs approximation of CM.
827 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
828 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
829 if (!(signal = strip->GetSignal())) {
830 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()",
831 module->GetModuleId(), strind));
834 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
835 else cm0 += (signal[ev] - strip->GetPedestal());
837 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n);
838 else { module->SetCM(0.0f, chipind, ev); continue; }
839 // calculate avarage (cm - (signal - pedestal)) over the chip
840 Double_t cmsigma = 0.0L;
842 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
843 if (!(strip = module->GetStrip(strind))) continue;
844 if (!(signal = strip->GetSignal())) {
845 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n",
846 module->GetModuleId(), strind));
849 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
850 else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2);
852 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = TMath::Sqrt(cmsigma / (Float_t)(n));
853 else { module->SetCM(0.0f, chipind, ev); continue; }
854 // calculate cm with threshold
855 Double_t cmsum = 0.0L;
857 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
858 if (!(strip = module->GetStrip(strind))) continue;
859 signal = strip->GetSignal();
860 if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
861 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
862 else cmsum += (signal[ev] - strip->GetPedestal());
864 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n);
866 if (!(module->SetCM(cmsum, chipind, ev)))
867 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
868 module->GetModuleId(), chipind, ev));
875 //______________________________________________________________________________
876 Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread, const Bool_t usewelford)
878 // Performs calculation of calibration parameters (pedestal, noise, ...)
880 if (nmread <= 0) return kFALSE;
881 if (!fModules) return kFALSE;
882 while ((nm = ReadModuleRawData(nmread)) > 0) {
883 cout << "Processing next " << nm << " modules;" << endl;
884 for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) {
885 if (!fModules[modind]) {
886 AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n",
890 AddFeromCm(fModules[modind]);
892 CalculatePedNoiseW(fModules[modind]);
893 CalculateNoiseCMW(fModules[modind]);
895 CalculatePedestal(fModules[modind]);
896 CalculateNoise(fModules[modind]);
897 CalculateNoiseCM(fModules[modind]);
903 fModIndProcessed = fModIndRead;
904 cout << fModIndProcessed << " - done" << endl;
905 if (nm < nmread ) break;
911 //______________________________________________________________________________
912 Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
914 // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class
915 if (!fDDLModuleMap) {
916 AliError("Error DDLMap is not initialized, return 0!");
919 Int_t mddli = ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
920 if ((ddlID < fgkNumberOfSSDDDLs) && (mddli < fgkNumberOfSSDModulesPerDdl)) {
921 mddli = fDDLModuleMap[ddlID * fgkNumberOfSSDModulesPerDdl + mddli];
924 AliWarning(Form("Module index = %d or ddlID = %d is out of range 0 is rturned", ddlID, mddli));
927 if (mddli > SHRT_MAX) return SHRT_MAX;
928 else return (Short_t)mddli;
933 //______________________________________________________________________________
934 AliITSNoiseSSDv2* AliITSHandleDaSSD::GetCalibrationOCDBNoise() const
936 // Fill in the array for OCDB
937 AliITSNoiseSSDv2 *ldcn = NULL;
938 AliITSModuleDaSSD *module = NULL;
939 AliITSChannelDaSSD *strip = NULL;
940 if (!fModules) return NULL;
941 ldcn = new AliITSNoiseSSDv2;
943 AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
946 for (Int_t i = 0; i < fNumberOfModules; i++) {
947 if (!(module = fModules[i])) continue;
948 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
949 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
950 if (!(strip = module->GetStrip(strind))) continue;
951 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
952 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() )
953 ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
955 ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
962 //______________________________________________________________________________
963 AliITSBadChannelsSSDv2* AliITSHandleDaSSD::GetCalibrationBadChannels() const
965 // Fill in the TObjArray with the list of bad channels
966 AliITSBadChannelsSSDv2 *ldcbc = NULL;
967 AliITSModuleDaSSD *module = NULL;
968 AliITSChannelDaSSD *strip = NULL;
969 if (!fModules) return NULL;
970 ldcbc = new AliITSBadChannelsSSDv2;
972 AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
975 for (Int_t i = 0; i < fNumberOfModules; i++) {
976 if (!(module = fModules[i])) continue;
977 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
978 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
979 if (!(strip = module->GetStrip(strind))) continue;
980 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
981 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() )
982 ldcbc->AddBadChannelP(modid, strip->GetStripId(), EvaluateIfChannelIsBad(module, strip->GetStripId()));
984 ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()),
985 EvaluateIfChannelIsBad(module, strip->GetStripId()));
993 //______________________________________________________________________________
994 Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname)
996 // Save Calibration data locally
997 AliITSBadChannelsSSDv2 *ldcbc = NULL;
998 AliITSPedestalSSDv2 *ldcp = NULL;
999 AliITSNoiseSSDv2 *ldcn = NULL;
1000 AliITSModuleDaSSD *module = NULL;
1001 AliITSChannelDaSSD *strip = NULL;
1003 TString dadatafilename("");
1004 if (!fModules) return kFALSE;
1005 ldcn = new AliITSNoiseSSDv2;
1006 ldcp = new AliITSPedestalSSDv2;
1007 ldcbc = new AliITSBadChannelsSSDv2;
1008 if ((!ldcn) || (!ldcp) || (!ldcp)) {
1009 AliError("Error allocation mamory for calibration objects, return kFALSE!");
1012 for (Int_t i = 0; i < fNumberOfModules; i++) {
1013 if (!(module = fModules[i])) continue;
1014 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1015 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1016 if (!(strip = module->GetStrip(strind))) continue;
1017 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1018 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) {
1019 ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
1020 ldcp->AddPedestalP(modid, strip->GetStripId(), strip->GetPedestal());
1021 ldcbc->AddBadChannelP(modid, strip->GetStripId(), EvaluateIfChannelIsBad(module, strip->GetStripId()));
1023 ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
1024 ldcp->AddPedestalN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetPedestal());
1025 ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()),
1026 EvaluateIfChannelIsBad(module, strip->GetStripId()));
1030 if (dafname) dadatafilename.Form("%s/", dafname);
1031 dadatafilename += TString::Format("ITSSSDda_%i.root", fLdcId);
1032 tmpfname = new Char_t[dadatafilename.Length()+1];
1033 Int_t sz = dadatafilename.Sizeof();
1034 dafname = strncpy(tmpfname, dadatafilename.Data(),sz);
1035 TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE");
1036 if (fileRun->IsZombie()) {
1037 AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data()));
1045 fileRun->WriteTObject(ldcn);
1046 fileRun->WriteTObject(ldcp);
1047 if (fBadChannelsList)
1048 if (fMergeBCLists) {
1049 MergeBadChannels(ldcbc);
1050 fileRun->WriteTObject(ldcbc);
1051 } else fileRun->WriteTObject(fBadChannelsList);
1052 else fileRun->WriteTObject(ldcbc);
1062 //______________________________________________________________________________
1063 Int_t AliITSHandleDaSSD::MergeBadChannels(AliITSBadChannelsSSDv2*& bcl) const
1065 // Merges the statick bad channels list with bad channels got upon calibration
1066 AliITSModuleDaSSD *module = 0;
1067 Int_t nmpch = 0, nmnch = 0, ngpch = 0, ngnch = 0;
1068 if (!fBadChannelsList || !bcl) {
1069 AliWarning("Either fBadChannelsList == NULL or bad_channels_list == NULL, there is nothing to merge!");
1072 for (Int_t modind = 0; modind < GetNumberOfModules(); modind++) {
1073 if (!(module = fModules[modind])) continue;
1074 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1075 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1076 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetPNStripsPerModule(); strind++) {
1077 if ( (!(fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask))
1078 && (bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask) )
1080 if ( (!(fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask))
1081 && (bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask) )
1083 if ( (!(bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask))
1084 && (fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) {
1085 bcl->AddBadChannelP(modid, strind, fBadChannelsList->GetBadChannelP(modid, strind));
1088 if ( (!(bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask))
1089 && (fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) {
1090 bcl->AddBadChannelN(modid, strind, fBadChannelsList->GetBadChannelN(modid, strind));
1095 AliInfo(Form("Static bad, dynamic good: P%d, N%d", nmpch, nmnch));
1096 AliInfo(Form("Static good, dynamic bad: P%d, N%d", ngpch, ngnch));
1097 return (nmnch + nmpch);
1102 //______________________________________________________________________________
1103 Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
1105 // Dump calibration parameters
1106 AliITSModuleDaSSD *mod;
1107 AliITSChannelDaSSD *strip;
1109 cout << "SSDDALDC::DumpModInfo(): Error, no modules are allocated!" << endl;
1112 cout << "Modules with MeanNoise > " << meannosethreshold << endl;
1113 for (Int_t i = 0; i < fNumberOfModules; i++) {
1114 if (!(mod = fModules[i])) continue;
1115 Double_t maxnoise = 0.0L, meannoise = 0.0L, meanovf = 0.0L;
1116 Float_t maxped = 0.0f;
1117 Int_t maxstrind = 0, novfstr = 0, maxovf = 0;
1118 for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
1119 if (!(strip = mod->GetStrip(strind))) {novfstr++; continue; }
1120 if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++; continue; }
1121 if (maxnoise < strip->GetNoiseCM()) {
1122 maxnoise = strip->GetNoiseCM();
1125 meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Double_t>(strind - novfstr + 1)
1126 : strip->GetNoiseCM();
1127 if (TMath::Abs(maxped) < TMath::Abs(strip->GetPedestal())) maxped = strip->GetPedestal();
1128 meanovf = (strind - novfstr) ? meanovf + (strip->GetOverflowNumber() - meanovf) / static_cast<Double_t>(strind - novfstr + 1)
1129 : strip->GetOverflowNumber();
1130 if (strip->GetOverflowNumber() > maxovf) maxovf = strip->GetOverflowNumber();
1132 if (meannoise > meannosethreshold)
1133 cout << "Mod: " << i << "; DDl: " << (int)mod->GetDdlId() << "; AD: " << (int)mod->GetAD()
1134 << "; ADC: " << (int)mod->GetADC() << "; MaxPed = " << maxped
1135 << "; MeanNoise = " << meannoise << "; MaxNoise = " << maxnoise << "; MaxNoiseStrip = " << maxstrind
1136 << "; NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
1137 if (maxovf > 10) cout << "Max number of events with overflow : " << maxovf << "; mean : " << meanovf << endl;
1144 //______________________________________________________________________________
1145 Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
1147 // Print Module calibration data whether in file or in cout
1148 AliITSChannelDaSSD *strip;
1150 ostream *outputfile;
1151 if (!fname) { outputfile = &cout; }
1153 datafile.open(fname, ios::out);
1154 if (datafile.fail()) return kFALSE;
1155 outputfile = dynamic_cast<ostream*>(&datafile);
1157 *outputfile << "DDL = " << (int)ddlID << "; AD = " << (int)ad << "; ADC = " << (int)adc << endl;
1158 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1159 if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) {
1160 *outputfile << "Str = " << strind << "; ped = " << strip->GetPedestal()
1161 << "; noise = " << strip->GetNoiseCM() << endl;
1165 if (datafile.is_open()) datafile.close();
1171 //______________________________________________________________________________
1172 void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
1174 // Print general information retrieved from raw data file
1175 cout << "Raw data file: " << fRawDataFileName << endl
1176 << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
1177 << "Number of physics events: " << fNumberOfEvents << endl
1182 //______________________________________________________________________________
1183 Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
1185 // Used to allocate simulated modules to test the performance
1186 AliITSModuleDaSSD *module;
1187 UChar_t ad, adc, ddlID;
1188 ad = adc = ddlID = 0;
1189 if (!(fModules[copymodind])) return kFALSE;
1190 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
1191 if (!fModules[modind]) {
1192 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
1193 if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
1194 else if (adc == 5) adc = 8;
1195 else if (adc == 13) {
1197 if (ad < 8) ad += 1;
1203 if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
1204 fModules[modind] = module;
1205 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1206 AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
1207 if(!cstrip)return kFALSE;
1208 Long_t eventsnumber = cstrip->GetEventsNumber();
1209 AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
1210 for (Long_t evind = 0; evind < eventsnumber; evind++) {
1211 Short_t sign = cstrip->GetSignal(evind);
1212 if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
1214 module->SetStrip(strip, strind);
1218 ddlID = fModules[modind]->GetDdlId();
1219 ad = fModules[modind]->GetAD();
1220 adc = fModules[modind]->GetADC();
1223 for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);
1229 //___________________________________________________________________________________________
1230 Bool_t AliITSHandleDaSSD::AdDataPresent(const Int_t ddl, const Int_t ad) const
1232 // Check if there are calibration data for given ddl and slot
1233 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
1234 if ((GetModule(modind)->GetAD() == ad) && (GetModule(modind)->GetDdlId() == ddl)) return kTRUE;
1240 //___________________________________________________________________________________________
1241 Bool_t AliITSHandleDaSSD::SaveEqSlotCalibrationData(const Int_t ddl, const Int_t ad, const Char_t *fname) const
1243 // Saves calibration files for selected equipment (DDL)
1245 Int_t zsml, offsetml;
1246 ULong_t zsth, offset, zsoffset;
1248 AliError("File name must be specified!");
1251 if (!AdDataPresent(ddl, ad)) {
1252 AliError(Form("Error SaveEqSlotCalibrationData(ddl = %i, ad = %i) no data present", ddl, ad));
1255 feefile.open(fname, ios::out);
1256 if (!feefile.is_open()) {
1257 AliError(Form("Can not open the file %s for output!", fname));
1260 for (zsml = 0; fgkZsBitMask >> zsml; zsml++) ;
1261 for (offsetml = 0; fgkOffSetBitMask >> offsetml; offsetml++) ;
1262 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1263 for (Int_t adcb = 0; adcb < fgkAdcPerDBlock; adcb++) {
1265 for (Int_t j = 0; j < 2; j++) {
1266 Int_t adc = adcb + j * 8;
1267 zsth = ZsThreshold(ddl, ad, adc, strind);
1268 offset = OffsetValue(ddl, ad, adc, strind);
1269 zsoffset = zsoffset | (((zsth << offsetml) | offset) << ((j == 0) ? (offsetml + zsml) : 0));
1271 feefile << "0x" << ConvBase(static_cast<unsigned long>(zsoffset), 16) << endl;
1279 //______________________________________________________________________________
1280 Int_t AliITSHandleDaSSD::ChannelIsBad(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1282 // Check if the channel is bad
1283 AliITSModuleDaSSD *module = NULL;
1285 if (fBadChannelsList && fDDLModuleMap) {
1286 modn = RetrieveModuleId(ddl, ad, adc);
1287 if (modn < 0) return -1;
1288 if (modn < fgkMinSSDModuleId) {
1289 AliWarning(Form("Module ddl/ad/adc: %d/%d/%d has number %d which is wrong for SSD module %d", ddl, ad, adc, strn, modn));
1292 Short_t modid = modn - fgkMinSSDModuleId;
1293 if (strn < AliITSModuleDaSSD::GetPNStripsPerModule())
1294 return (fBadChannelsList->GetBadChannelP(modid, strn) & fgkBadChannelMask);
1295 else return (fBadChannelsList->GetBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strn)) & fgkBadChannelMask);
1297 AliError("Error ether bad channels list or DDLMap is not initialized or both, EvaluateIfChannelIsBad(module, strip) is used!");
1298 if ((module = GetModule(ddl, ad, adc))) {
1299 return (EvaluateIfChannelIsBad(module, strn) & fgkBadChannelMask);
1301 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1310 //______________________________________________________________________________
1311 Int_t AliITSHandleDaSSD::LadderIsOff(const UChar_t ddl, const UChar_t ad, const UChar_t adc) const
1313 //Checks if the module with given ddl, ad, adc is on the ladder which is in the list of ladders which are off
1314 const Int_t nm5 = 500;
1315 const Int_t nm6 = 1248;
1316 const Int_t nml5a = 12;
1317 const Int_t nml5c = 10;
1318 const Int_t nml6a = 12;
1319 const Int_t nml6c = 13;
1320 Int_t modn, ladder, layer, side;
1321 AliITSModuleDaSSD *module;
1322 if (!(module = GetModule(ddl, ad, adc))) return 0;
1323 if ((modn = module->GetModuleId()) <= 0) modn = RetrieveModuleId(ddl, ad, adc);
1324 if (modn <= 0) return 0;
1325 layer = modn >= nm6 ? 1 : 0; // 6 : 5
1326 ladder = (modn - (layer ? nm6 : nm5)) / (layer ? (nml6a + nml6c) : (nml5a + nml5c));
1327 if ( ((modn - (layer ? nm6 : nm5)) % (layer ? (nml6a + nml6c) : (nml5a + nml5c))) < (layer ? nml6a : nml5a))
1330 ladder += (layer ? 600 : 500);
1333 if (fCLaddersOff.GetSize()) {
1334 for(Int_t i = 0; i < fCLaddersOff.GetSize(); i++)
1335 if (fCLaddersOff.At(i) == ladder) return fCLaddersOff.At(i);
1339 if (fALaddersOff.GetSize()) {
1340 for(Int_t i = 0; i < fALaddersOff.GetSize(); i++)
1341 if (fALaddersOff.At(i) == ladder) return fALaddersOff.At(i);
1349 //______________________________________________________________________________
1350 ULong_t AliITSHandleDaSSD::OffsetValue(const AliITSChannelDaSSD *strip,
1351 const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1353 // Calculate the offset value to be upload to FEROM
1355 if (fOffsetDefault < INT_MAX) pedint = fOffsetDefault;
1356 else pedint = TMath::Nint(strip->GetPedestal());
1357 if (pedint > static_cast<Int_t>((fgkOffSetBitMask >> 1))) {
1358 if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (EvaluateIfChannelIsBad(GetModule(ddl, ad, adc), strn))))
1359 AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
1360 pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), (fgkOffSetBitMask >> 1)));
1361 return (fgkOffSetBitMask >> 1);
1363 if ((-pedint) > static_cast<Int_t>(((fgkOffSetBitMask + 1) >> 1))) {
1364 if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (EvaluateIfChannelIsBad(GetModule(ddl, ad, adc), strn))))
1365 AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
1366 pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(),
1367 ((fgkOffSetBitMask & (~fgkOffSetBitMask >> 1)) - fgkOffSetBitMask - 1)));
1368 return fgkOffSetBitMask & (~fgkOffSetBitMask >> 1);
1370 return fgkOffSetBitMask & (pedint >= 0 ? pedint : pedint + fgkOffSetBitMask + 1);
1375 //______________________________________________________________________________
1376 ULong_t AliITSHandleDaSSD::OffsetValue(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1378 // Calculate the offset value to be upload to FEROM
1379 AliITSChannelDaSSD *strip = NULL;
1380 AliITSModuleDaSSD *module = NULL;
1381 if ((module = GetModule(ddl, ad, adc))) {
1382 if ((strip = module->GetStrip(strn))) return OffsetValue(strip, ddl, ad, adc, strn);
1384 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
1388 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1395 //______________________________________________________________________________
1396 ULong_t AliITSHandleDaSSD::ZsThreshold(const AliITSChannelDaSSD *strip) const
1398 // Calculate the value of zero suppression threshold to be upload to FEROM
1400 if (fZsDefault < 0) {
1401 zs = TMath::Nint(fZsFactor * strip->GetNoiseCM());
1402 if (zs < static_cast<ULong_t>(fZsMinimum)) zs = static_cast<ULong_t>(fZsMinimum);
1404 else zs = fZsDefault;
1405 return (zs < fgkZsBitMask) ? (zs & fgkZsBitMask) : fgkZsBitMask;
1409 //______________________________________________________________________________
1410 ULong_t AliITSHandleDaSSD::ZsThreshold(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1412 // Calculate the value of zero suppression threshold to be upload to FEROM, account bad channels list
1413 AliITSChannelDaSSD *strip = NULL;
1414 AliITSModuleDaSSD *module = NULL;
1415 if (ChannelIsBad(ddl, ad, adc, strn)) return fgkZsBitMask;
1416 if (LadderIsOff(ddl, ad, adc)) return fgkZsBitMask;
1417 if (fZsDefault > 0) if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) return fgkZsBitMask;
1418 if ((module = GetModule(ddl, ad, adc))) {
1419 if (fMergeBCLists) if (EvaluateIfChannelIsBad(module, strn)) return fgkZsBitMask;
1420 if ((strip = module->GetStrip(strn))) return ZsThreshold(strip);
1422 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
1426 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1432 //______________________________________________________________________________
1433 string AliITSHandleDaSSD::ConvBase(const unsigned long value, const long base) const
1435 // Converts the unsigned long number into that in another base
1436 string digits = "0123456789ABCDEF";
1438 unsigned long v = value;
1439 if((base < 2) || (base > 16)) {
1440 result = "Error: base out of range.";
1445 result = digits[v % base] + result;
1449 while((v) || (i<8));
1456 //______________________________________________________________________________
1457 Int_t AliITSHandleDaSSD::CheckOffChips() const
1459 // Check if the chip, module are off
1460 AliITSChannelDaSSD *strip;
1462 Int_t strnd, chipnd, modnd, stroff, chipoff, modoff;
1463 offthreshold = TMath::Nint(fZsMinimum/fZsFactor);
1465 for (Int_t mi = 0; mi < fNumberOfModules; mi++) {
1466 if (!fModules[mi]) { modnd++; continue; }
1467 if (fModules[mi]->GetModuleId() < 0) continue;
1468 if (LadderIsOff(fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()) ) continue;
1469 chipoff = chipnd = 0;
1470 for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
1472 Int_t stripind = chipind * AliITSModuleDaSSD::GetStripsPerChip();
1473 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1474 if (!(strip = fModules[mi]->GetStrip(strind))) { strnd++; continue; }
1475 if (strip->GetNoiseCM() < offthreshold ) stroff++;
1477 if (strnd == AliITSModuleDaSSD::GetStripsPerChip()) chipnd++;
1478 else if (stroff == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1479 else if ((stroff + strnd) == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1481 if ((!chipoff) && (!chipnd)) continue;
1482 if (chipnd == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1483 AliInfo(Form("Module: (ddl/ad/adc) %i/%i/%i seems to be off and it is not on the ladders which are off!",
1484 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1487 if (chipoff == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1488 AliInfo(Form("Module (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
1489 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1492 else if ((chipoff + chipnd) == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1493 AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
1494 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1498 AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i has %i chips which are off!",
1499 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC(), chipoff));
1503 return (modoff + modnd);
1507 //______________________________________________________________________________
1508 Bool_t AliITSHandleDaSSD::CalculatePedNoiseW(const AliITSModuleDaSSD *const module)
1510 // Calculates Pedestal and Noise using Welford algorithm
1511 AliITSChannelDaSSD *strip;
1512 Double_t pedestal, noise, p0, s0;
1515 if (!module) return kFALSE;
1516 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1517 if (!(strip = module->GetStrip(strind))) continue;
1518 if (!(signal = strip->GetSignal())) {
1519 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
1520 module->GetModuleId(), strind));
1523 //************* pedestal and noise first pass ****************
1524 pedestal = p0 = noise = 0.0L;
1526 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1527 if (SignalOutOfRange(signal[ev])) ovev += 1;
1530 pedestal = p0 = signal[ev];
1533 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1534 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1539 if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
1540 strip->SetPedestal(static_cast<Float_t>(pedestal));
1541 if ((n = strip->GetEventsNumber() - ovev - 1) > 0)
1542 strip->SetNoise( static_cast<Float_t>(TMath::Sqrt(noise / static_cast<Double_t>(n))) );
1544 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
1547 //************* Second pass excluds event with |p - s|>f*noise *****************
1548 pedestal = p0 = noise = 0.0L;
1550 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1551 if ( SignalOutOfRange(signal[ev])
1552 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
1555 pedestal = p0 = signal[ev];
1558 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1559 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1564 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n));
1565 else noise = AliITSChannelDaSSD::GetUndefinedValue();
1566 strip->SetNoise(static_cast<Float_t>(noise));
1567 if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
1568 strip->SetPedestal(static_cast<Float_t>(pedestal));
1569 strip->SetOverflowNumber(ovev);
1575 //______________________________________________________________________________
1576 Bool_t AliITSHandleDaSSD::CalculateCMW(AliITSModuleDaSSD *const module)
1578 // Calculates CM using Welford algorithm
1579 AliITSChannelDaSSD *strip = NULL;
1583 Double_t cm0, cm1, cmsigma, cms1;
1584 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
1585 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
1586 stripind = chipind * module->GetStripsPerChip();
1587 module->GetCM()[chipind].Set(fNumberOfEvents);
1588 module->GetCM()[chipind].Reset(0.0f);
1589 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
1590 // calculate firs approximation of CM and SigmaCM.
1591 cm0 = cm1 = cmsigma = 0.0L;
1593 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1594 if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; } //return kFALSE;
1595 if (!(signal = strip->GetSignal())) { ovstr += 1; continue; } //return kFALSE;
1596 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
1598 if (!(strind - stripind - ovstr)) {
1599 cm0 = cm1 = signal[ev] - strip->GetPedestal();
1602 cm1 = cm0 + (signal[ev] - strip->GetPedestal() - cm0) / static_cast<Double_t>(strind - stripind - ovstr + 1);
1603 cms1 = cmsigma + (signal[ev] - strip->GetPedestal() - cm0) * (signal[ev] - strip->GetPedestal() - cm1);
1608 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr - 1) > 0) cmsigma = TMath::Sqrt(cmsigma / static_cast<Double_t>(n));
1610 AliWarning(Form("AliITSHandleDaSSD: Too little number of strips have a signal for module:chip:event : [%d]:[%d]:[%ld]\n",
1611 module->GetModuleId(), chipind, ev));
1612 if (!(module->SetCM(0.0f, chipind, ev)))
1613 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
1614 module->GetModuleId(), chipind, ev));
1617 // calculate cm with threshold
1618 Double_t cmsum = 0.0L;
1620 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1621 if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; }
1622 if (!(signal = strip->GetSignal())) { ovstr += 1; continue; }
1623 if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
1624 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
1625 else cmsum += (signal[ev] - strip->GetPedestal());
1627 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Double_t)(n);
1629 if (!(module->SetCM(static_cast<Float_t>(cmsum), chipind, ev)))
1630 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
1631 module->GetModuleId(), chipind, ev));
1638 //______________________________________________________________________________
1639 Bool_t AliITSHandleDaSSD::CalculateNoiseCMW(AliITSModuleDaSSD *const module)
1641 // Calculates Noise with CM correction
1642 AliITSChannelDaSSD *strip = NULL;
1645 if (!CalculateCMW(module)) {
1646 AliError("Error: AliITSHandleDaSSD::CalculateCMW() returned kFALSE");
1649 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1650 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
1651 if (!(signal = strip->GetSignal())) {
1652 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
1653 AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCMW(): there are no events data for module[%i] strip[%i]->GetSignal()",
1654 module->GetModuleId(), strind));
1655 continue; //return kFALSE;
1657 //** To get exactly the same set of events as for pedestal and noise calculation **
1658 Double_t pedestal, noise, p0, s0;
1659 pedestal = p0 = noise = 0.0L;
1661 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1662 if (SignalOutOfRange(signal[ev])) ovev += 1;
1665 pedestal = p0 = signal[ev];
1668 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1669 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1674 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n));
1676 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
1679 //** Calculation of CM corrected noise **
1680 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
1681 Double_t nsum = 0.0L;
1683 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1684 if ( SignalOutOfRange(signal[ev])
1685 || TMath::Abs(signal[ev] - pedestal) > (fPedestalThresholdFactor * noise)) ovev += 1;
1686 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
1688 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / static_cast<Double_t>(n));
1689 else noise = AliITSChannelDaSSD::GetUndefinedValue();
1690 strip->SetNoiseCM(static_cast<Float_t>(noise));
1697 //______________________________________________________________________________
1698 UChar_t AliITSHandleDaSSD::EvaluateIfChannelIsBad(const AliITSModuleDaSSD *const module, const Int_t stripn) const
1700 //Applies the bad channel creteria and set the appropriate flags for returned value
1701 AliITSChannelDaSSD *strip = 0;
1703 if (fZsDefault >= 0) { if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) bcflags |= 3; }
1704 else if (static_cast<ULong_t>(fZsMinimum) >= fgkZsBitMask) bcflags |= 3;
1705 if (LadderIsOff(module->GetDdlId(), module->GetAD(), module->GetADC()) ) bcflags |= 3;
1707 if (!(strip = module->GetStrip(stripn))) bcflags |= 3;
1709 if (strip->GetNoiseCM() == AliITSChannelDaSSD::GetUndefinedValue()) bcflags |= 8;
1710 if (static_cast<ULong_t>(TMath::Nint(fZsFactor * strip->GetNoiseCM())) >= fgkZsBitMask) bcflags |= 8;
1711 if (strip->GetNoiseCM() < 1) bcflags |= 16;
1712 if (strip->GetPedestal() > ((fgkOffSetBitMask >> 1) - 1)) bcflags |= 4;
1713 else if ((-(strip->GetPedestal())) > (fgkOffSetBitMask >> 1)) bcflags |= 4;
1714 if (bcflags) bcflags |= 3;