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(NULL),
126 fNumberOfModules(ssdadldc.fNumberOfModules),
128 fModIndProcessed(ssdadldc.fModIndProcessed),
129 fModIndRead(ssdadldc.fModIndRead),
131 fEqIndex(ssdadldc.fEqIndex),
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.fRawDataFileName) {
149 fRawDataFileName = new (nothrow) Char_t[strlen(ssdadldc.fRawDataFileName)+1];
150 if (fRawDataFileName) strncpy(fRawDataFileName, ssdadldc.fRawDataFileName, strlen(ssdadldc.fRawDataFileName)+1);
151 } else fRawDataFileName = NULL;
152 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
153 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
155 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
156 if (ssdadldc.fModules[modind]) {
157 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
158 if (!fModules[modind]) {
159 AliError("AliITSHandleDaSSD: Error copy constructor");
160 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
165 } else fModules[modind] = NULL;
168 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
169 fNumberOfModules = 0;
173 if (ssdadldc.fModIndex) {
174 fModIndex = new (nothrow) Int_t [ssdadldc.fNumberOfModules];
175 if (fModIndex) memcpy(fModIndex, ssdadldc.fModIndex, ssdadldc.fNumberOfModules*sizeof(Int_t));
176 } else fModIndex = NULL;
177 fBadChannelsList = new AliITSBadChannelsSSDv2(*ssdadldc.fBadChannelsList);
178 if (ssdadldc.fDDLModuleMap) {
179 fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
180 if (fDDLModuleMap) memcpy(fDDLModuleMap, ssdadldc.fDDLModuleMap, fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl * sizeof(Int_t));
181 } else fDDLModuleMap = NULL;
183 // if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by copy constructor, use other methods to init it!");
184 // if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by copy constructor, use other methods to init it!");
187 //______________________________________________________________________________
188 AliITSHandleDaSSD& AliITSHandleDaSSD::operator = (const AliITSHandleDaSSD& ssdadldc)
190 // assignment operator
191 if (this == &ssdadldc) return *this;
192 TObject::operator=(ssdadldc);
194 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
198 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
199 fNumberOfModules = ssdadldc.fNumberOfModules;
200 if ((fNumberOfModules > 0) && (ssdadldc.fModules)) {
201 fModules = new (nothrow) AliITSModuleDaSSD* [fNumberOfModules];
203 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
204 if (ssdadldc.fModules[modind]) {
205 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
206 if (!fModules[modind]) {
207 AliError("AliITSHandleDaSSD: Error assignment operator");
208 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
213 } else fModules[modind] = NULL;
216 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
217 fNumberOfModules = 0;
221 if(fRawDataFileName)delete[]fRawDataFileName;
222 if (ssdadldc.fRawDataFileName) {
223 fRawDataFileName = new (nothrow) Char_t[strlen(ssdadldc.fRawDataFileName)+1];
224 if (fRawDataFileName) strncpy(fRawDataFileName, ssdadldc.fRawDataFileName, strlen(ssdadldc.fRawDataFileName)+1);
225 } else fRawDataFileName = NULL;
226 fModIndProcessed = ssdadldc.fModIndProcessed;
227 fModIndRead = ssdadldc.fModIndRead;
229 if (ssdadldc.fModIndex) {
230 fModIndex = new (nothrow) Int_t [ssdadldc.fNumberOfModules];
231 if (fModIndex) memcpy(fModIndex, ssdadldc.fModIndex, ssdadldc.fNumberOfModules*sizeof(Int_t));
232 } else fModIndex = NULL;
234 fEqIndex = ssdadldc.fEqIndex;
235 fNumberOfEvents = ssdadldc.fNumberOfEvents;
236 fLdcId = ssdadldc.fLdcId;
237 fRunId = ssdadldc.fRunId;
238 fPedestalThresholdFactor = ssdadldc.fPedestalThresholdFactor;
239 fCmThresholdFactor = ssdadldc.fCmThresholdFactor;
240 fZsDefault = ssdadldc.fZsDefault;
241 fOffsetDefault = ssdadldc.fOffsetDefault;
242 fZsMinimum = ssdadldc.fZsMinimum;
243 fMergeBCLists = ssdadldc.fMergeBCLists;
244 fZsFactor = ssdadldc.fZsFactor;
245 fALaddersOff = ssdadldc.fALaddersOff;
246 fCLaddersOff = ssdadldc.fCLaddersOff;
247 if (fBadChannelsList) delete fBadChannelsList;
248 fBadChannelsList = new AliITSBadChannelsSSDv2(*ssdadldc.fBadChannelsList);
249 if (fDDLModuleMap) delete [] fDDLModuleMap;
250 if (ssdadldc.fDDLModuleMap) {
251 fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
252 if (fDDLModuleMap) memcpy(fDDLModuleMap, ssdadldc.fDDLModuleMap, fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl * sizeof(Int_t));
253 } else fDDLModuleMap = NULL;
255 // if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by assignment operator, use other methods to init it!");
256 // if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by assignment operator, use other methods to init it!");
261 //______________________________________________________________________________
262 AliITSHandleDaSSD::~AliITSHandleDaSSD()
264 // Default destructor
265 delete []fRawDataFileName;
268 for (Int_t i = 0; i < fNumberOfModules; i++)
270 if (fModules[i]) delete fModules[i];
274 if (fModIndex) delete [] fModIndex;
275 if (fBadChannelsList) delete fBadChannelsList;
276 if (fDDLModuleMap) delete [] fDDLModuleMap;
281 //______________________________________________________________________________
282 void AliITSHandleDaSSD::Reset()
284 // Delete array of AliITSModuleDaSSD* objects.
286 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
290 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
292 if (fBadChannelsList) {
293 delete fBadChannelsList;
294 fBadChannelsList = NULL;
296 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL; }
300 if(fRawDataFileName){
301 delete []fRawDataFileName;
302 fRawDataFileName = NULL;
304 fModIndProcessed = fModIndRead = 0;
307 fPedestalThresholdFactor = fgkPedestalThresholdFactor;
308 fCmThresholdFactor = fgkCmThresholdFactor;
313 //______________________________________________________________________________
314 Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname)
316 // Read raw data file and set initial and configuration parameters
317 Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0;
318 Int_t nofeqipmentev, nofeqipment = 0, eqn = 0;
319 AliRawReaderDate *rawreaderdate = NULL;
320 UChar_t *data = NULL;
321 Long_t datasize = 0, eqbelsize = 1;
323 rawreaderdate = new AliRawReaderDate(rdfname, 0);
324 if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) {
325 AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname));
329 if (rawreaderdate->NextEvent()) {
330 fRunId = rawreaderdate->GetRunNumber();
331 rawreaderdate->RewindEvents();
332 } else { MakeZombie(); return kFALSE; }
333 if (fModules) Reset();
334 //rawreaderdate->SelectEvents(-1);
335 rawreaderdate->Select("ITSSSD");
337 while (rawreaderdate->NextEvent()) {
338 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
341 while (rawreaderdate->ReadNextData(data)) {
342 fLdcId = rawreaderdate->GetLDCId();
344 datasize = rawreaderdate->GetDataSize();
345 eqbelsize = rawreaderdate->GetEquipmentElementSize();
346 if ( datasize % eqbelsize ) {
347 AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %ld is not an integer of equipment data size %ld",
348 rdfname, datasize, eqbelsize));
352 nofstripsev += (Int_t) (datasize / eqbelsize);
354 if (physeventind++) {
355 if (nofstrips != nofstripsev) AliWarning(Form("AliITSHandleDaSSD: number of strips varies from event to event, ev = %ld, %ld",
356 physeventind, nofstripsev));
357 if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to event");
359 nofstrips = nofstripsev;
360 nofeqipment = nofeqipmentev;
361 if (strn < nofstrips) strn = nofstrips;
362 if (eqn < nofeqipment) eqn = nofeqipment;
364 delete rawreaderdate;
365 if ((physeventind > 0) && (strn > 0))
367 fNumberOfEvents = physeventind;
369 delete []fRawDataFileName;
370 fRawDataFileName = new Char_t[strlen(rdfname)+1];
371 strncpy(fRawDataFileName,rdfname,strlen(rdfname)+1);
375 fModIndex = new (nothrow) Int_t [fgkNumberOfSSDModulesPerDdl * eqn];
377 for (Int_t i = 0; i < fgkNumberOfSSDModulesPerDdl * eqn; i++) fModIndex[i] = -1;
378 else AliWarning(Form("AliITSHandleDaSSD: Error Init(%s): Index array for %i modules was not created",
379 rdfname, fgkNumberOfSSDModulesPerDdl * eqn));
380 if (SetNumberOfModules(fgkNumberOfSSDModulesPerDdl * eqn)) {
381 TString str = TString::Format("Max number of equipment: %d, max number of channels: %ld\n", eqn, strn);
382 DumpInitData(str.Data());
392 //______________________________________________________________________________
393 AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
395 // Retrieve AliITSModuleDaSSD object from the array
396 if (!fModules) return NULL;
397 for (Int_t i = 0; i < fNumberOfModules; i++) {
399 if ( (fModules[i]->GetDdlId() == ddlID)
400 && (fModules[i]->GetAD() == ad)
401 && (fModules[i]->GetADC() == adc))
409 Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
411 // Retrieve the position of AliITSModuleDaSSD object in the array
412 if (!fModules) return -1;
413 for (Int_t i = 0; i < fNumberOfModules; i++) {
415 if ( (fModules[i]->GetDdlId() == ddlID)
416 && (fModules[i]->GetAD() == ad)
417 && (fModules[i]->GetADC() == adc))
426 //______________________________________________________________________________
427 AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const
429 // Retrieve AliITSChannalDaSSD object from the array
430 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
431 if ( (fModules[modind]->GetDdlId() == ddlID)
432 && (fModules[modind]->GetAD() == ad)
433 && (fModules[modind]->GetADC() == adc) )
435 return fModules[modind]->GetStrip(stripID);
438 AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!",
439 ddlID, ad, adc, stripID));
445 //______________________________________________________________________________
446 Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index)
448 // Assign array element with AliITSModuleDaSSD object
449 if ((index < fNumberOfModules) && (index >= 0))
451 if (fModules[index]) delete fModules[index];
452 fModules[index] = module;
460 //______________________________________________________________________________
461 Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules)
463 // Allocates memory for AliITSModuleDaSSD objects
464 if (numberofmodules > fgkNumberOfSSDModules)
465 AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD",
466 numberofmodules, fgkNumberOfSSDModules));
468 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
472 fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules];
474 fNumberOfModules = numberofmodules;
475 memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules);
478 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules));
479 fNumberOfModules = 0;
487 //______________________________________________________________________________
488 Bool_t AliITSHandleDaSSD::ReadStaticBadChannelsMap(const Char_t *filename)
490 // Reads Static Bad Channels Map from the file
493 AliWarning("No file name is specified for Static Bad Channels Map!");
496 bcfile = new TFile(filename, "READ");
497 if (bcfile->IsZombie()) {
498 AliWarning(Form("Error reading file %s with Static Bad Channels Map!", filename));
501 bcfile->GetObject("AliITSBadChannelsSSDv2;1", fBadChannelsList);
502 if (!fBadChannelsList) {
503 AliWarning("Error fBadChannelsList == NULL!");
515 Bool_t AliITSHandleDaSSD::ReadDDLModuleMap(const Char_t *filename)
517 // Reads the SSD DDL Map from the file
519 AliRawReaderDate *rwr = NULL;
520 AliITSRawStreamSSD *rsm = NULL;
522 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
523 fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
524 if (!fDDLModuleMap) {
525 AliWarning("Error allocation memory for DDL Map!");
529 AliWarning("No file name is specified for SSD DDL Map, using the one from AliITSRawStreamSSD!");
530 rwr = new AliRawReaderDate(event);
531 rsm = new AliITSRawStreamSSD(rwr);
532 rsm->Setv11HybridDDLMapping();
533 for (Int_t ddli = 0; ddli < fgkNumberOfSSDDDLs; ddli++)
534 for (Int_t mi = 0; mi < fgkNumberOfSSDModulesPerDdl; mi++)
535 fDDLModuleMap[(ddli * fgkNumberOfSSDModulesPerDdl + mi)] = rsm->GetModuleNumber(ddli, mi);
540 ddlmfile.open(filename, ios::in);
541 if (!ddlmfile.is_open()) {
542 AliWarning(Form("Error reading file %s with SSD DDL Map!", filename));
543 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
547 while((!ddlmfile.eof()) && (ind < (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))) {
548 ddlmfile >> fDDLModuleMap[ind++];
549 if (ddlmfile.fail()) AliError(Form("Error extracting number from the DDL map file %s, ind: %d ", filename, ind));
551 if (ind != (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))
552 AliWarning(Form("Only %i (< %i) entries were read from DDL Map!", ind, (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl)));
559 //______________________________________________________________________________
560 Int_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber)
562 // Reads raw data from file
563 if (!Init(fileName)){
564 AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile");
567 fNumberOfEvents = eventsnumber;
568 return ReadModuleRawData (fNumberOfModules);
573 //______________________________________________________________________________
574 Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber)
576 // Reads raw data from file
577 AliRawReader *rawreaderdate = NULL;
578 AliITSRawStreamSSD *stream = NULL;
579 AliITSModuleDaSSD *module;
580 AliITSChannelDaSSD *strip;
582 Int_t nofeqipment, eqind;
583 Short_t equipid, prequipid;
585 if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0;
587 AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data");
590 if (!fDDLModuleMap) if (!ReadDDLModuleMap()) AliWarning("DDL map is not defined, ModuleID will be set to 0!");
591 stream = new AliITSRawStreamSSD(rawreaderdate);
592 stream->Setv11HybridDDLMapping();
593 //rawreaderdate->SelectEvents(-1);
594 rawreaderdate->Select("ITSSSD");
597 while (rawreaderdate->NextEvent()) {
598 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
601 while (stream->Next()) {
602 equipid = rawreaderdate->GetEquipmentId();
603 if ((equipid != prequipid)) {
604 if ((eqind = GetEqIndex(equipid)) < 0) { fEqIndex.AddAt(equipid, nofeqipment); eqind = nofeqipment++; }
607 Int_t equiptype = rawreaderdate->GetEquipmentType();
608 UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID();
609 UChar_t ad = stream->GetAD();
610 UChar_t adc = stream->GetADC();
611 UShort_t stripID = stream->GetSideFlag() ? AliITSChannelDaSSD::GetMaxStripIdConst() - stream->GetStrip() : stream->GetStrip();
612 Short_t signal = stream->GetSignal();
614 Int_t indpos = (eqind * fgkNumberOfSSDModulesPerDdl)
615 + ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
616 Int_t modpos = fModIndex[indpos];
617 if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue;
618 if ((modpos < 0) && (modind < modulesnumber)) {
619 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
621 if (fDDLModuleMap) mddli = RetrieveModuleId(ddlID, ad, adc);
623 if (!module->SetModuleIdData (ddlID, ad, adc, mddli)) return 0;
624 module->SetModuleRorcId (equipid, equiptype);
625 modpos = fModIndRead + modind;
627 fModules[modpos] = module;
628 fModIndex[indpos] = modpos;
630 if (stripID < AliITSModuleDaSSD::GetStripsPerModuleConst()) {
631 if (!(strip = fModules[modpos]->GetStrip(stripID))) {
632 strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents);
633 fModules[modpos]->SetStrip(strip, stripID);
635 strip->SetSignal(eventind, signal);
637 if (!(fModules[modpos]->GetCMFerom())) {
638 fModules[modpos]->AllocateCMFeromArray();
639 fModules[modpos]->SetCMFeromEventsNumber(fNumberOfEvents);
641 fModules[modpos]->SetCMFerom(signal, (stripID - AliITSModuleDaSSD::GetStripsPerModuleConst()), eventind);
644 if (++eventind > fNumberOfEvents) break;
647 delete rawreaderdate;
648 if (modind) cout << "The memory was allocated for " << modind << " modules." << endl;
649 fModIndRead += modind;
650 if (modind < modulesnumber) RelocateModules();
656 //______________________________________________________________________________
657 Bool_t AliITSHandleDaSSD::RelocateModules()
659 // Relocate memory for AliITSModuleDaSSD object array
661 AliITSModuleDaSSD **marray = NULL;
662 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
663 if (fModules[modind]) nm += 1;
664 if (nm == fNumberOfModules) return kTRUE;
665 marray = new (nothrow) AliITSModuleDaSSD* [nm];
667 AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm));
671 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
672 if (fModules[modind]) marray[nm++] = fModules[modind];
675 fNumberOfModules = fModIndRead = nm;
681 //______________________________________________________________________________
682 Bool_t AliITSHandleDaSSD::AddFeromCm(const AliITSModuleDaSSD *const module)
684 // Restore the original signal value adding CM calculated and subtracted in ferom
685 AliITSChannelDaSSD *strip;
686 Short_t *signal, *cmferom;
688 if (!module) return kFALSE;
689 if (!module->GetCMFerom()) return kTRUE;
690 for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
691 if (!(cmferom = module->GetCMFerom(chipind))) {
692 AliWarning(Form("AliITSHandleDaSSD: There is no Ferom CM values for chip %i, module %i!", chipind, module->GetModuleId()));
695 for (Int_t strind = (chipind * AliITSModuleDaSSD::GetStripsPerChip());
696 strind < ((chipind + 1) * AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
697 if (!(strip = module->GetStrip(strind))) continue;
698 if (!(signal = strip->GetSignal())) continue;
699 // if (strip->GetEventsNumber() != module->GetEventsNumber()) return kFALSE;
701 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
702 if (SignalOutOfRange(signal[ev]) || SignalOutOfRange(cmferom[ev])) ovev += 1;
704 Short_t signal1 = signal[ev] + cmferom[ev];
705 strip->SetSignal(ev, signal1);
715 //______________________________________________________________________________
716 Bool_t AliITSHandleDaSSD::CalculatePedestal(const AliITSModuleDaSSD *const module)
718 // Calculates Pedestal
719 AliITSChannelDaSSD *strip;
720 Double_t pedestal, noise;
723 if (!module) return kFALSE;
724 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
725 if (!(strip = module->GetStrip(strind))) continue;
726 if (!(signal = strip->GetSignal())) {
727 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
728 module->GetModuleId(), strind));
731 //************* pedestal first pass ****************
734 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
735 if (SignalOutOfRange(signal[ev])) ovev += 1;
736 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1) : signal[ev];
737 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
738 strip->SetPedestal(static_cast<Float_t>(pedestal));
739 //************* noise *******************************
740 Double_t nsum = 0.0L;
742 for (ev = 0; ev < strip->GetEventsNumber(); ev++) {
743 if (SignalOutOfRange(signal[ev])) ovev += 1;
744 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
746 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / (Double_t)(n));
747 else noise = AliITSChannelDaSSD::GetUndefinedValue();
748 strip->SetNoise(static_cast<Float_t>(noise));
749 //************* pedestal second pass ****************
752 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
753 if ( SignalOutOfRange(signal[ev])
754 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
755 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1) : signal[ev];
756 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
757 strip->SetPedestal(static_cast<Float_t>(pedestal));
758 strip->SetOverflowNumber(ovev);
764 //______________________________________________________________________________
765 Bool_t AliITSHandleDaSSD::CalculateNoise(const AliITSModuleDaSSD *const module)
768 AliITSChannelDaSSD *strip;
772 if (!module) return kFALSE;
773 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
774 if (!(strip = module->GetStrip(strind))) continue;
775 if (!(signal = strip->GetSignal())) {
776 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
777 AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()",
778 module->GetModuleId(), strind));
781 Double_t nsum = 0.0L;
783 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
784 if (SignalOutOfRange(signal[ev])) ovev += 1;
785 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
787 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = static_cast<Float_t>(TMath::Sqrt(nsum / (Float_t)(n)));
788 else noise = AliITSChannelDaSSD::GetUndefinedValue();
789 strip->SetNoise(noise);
796 //______________________________________________________________________________
797 Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module)
799 // Calculates Noise with CM correction
800 AliITSChannelDaSSD *strip = NULL;
804 if (!CalculateCM(module)) {
805 AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE");
808 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
809 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
810 if (!(signal = strip->GetSignal())) {
811 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
812 AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCM(): there are no events data for module[%i] strip[%i]->GetSignal()",
813 module->GetModuleId(), strind));
814 continue; //return kFALSE;
816 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
817 Double_t nsum = 0.0L;
819 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
820 if (SignalOutOfRange(signal[ev])) ovev += 1;
821 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
823 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = static_cast<Float_t>(TMath::Sqrt(nsum / (Double_t)(n)));
824 else noise = AliITSChannelDaSSD::GetUndefinedValue();
825 strip->SetNoiseCM(noise);
832 //______________________________________________________________________________
833 Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module)
836 AliITSChannelDaSSD *strip = NULL;
840 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
841 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
842 stripind = chipind * module->GetStripsPerChip();
843 module->GetCM()[chipind].Set(fNumberOfEvents);
844 module->GetCM()[chipind].Reset(0.0f);
845 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
846 // calculate firs approximation of CM.
849 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
850 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
851 if (!(signal = strip->GetSignal())) {
852 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()",
853 module->GetModuleId(), strind));
856 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
857 else cm0 += (signal[ev] - strip->GetPedestal());
859 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n);
860 else { module->SetCM(0.0f, chipind, ev); continue; }
861 // calculate avarage (cm - (signal - pedestal)) over the chip
862 Double_t cmsigma = 0.0L;
864 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
865 if (!(strip = module->GetStrip(strind))) continue;
866 if (!(signal = strip->GetSignal())) {
867 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n",
868 module->GetModuleId(), strind));
871 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
872 else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2);
874 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = TMath::Sqrt(cmsigma / (Float_t)(n));
875 else { module->SetCM(0.0f, chipind, ev); continue; }
876 // calculate cm with threshold
877 Double_t cmsum = 0.0L;
879 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
880 if (!(strip = module->GetStrip(strind))) continue;
881 signal = strip->GetSignal();
882 if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
883 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
884 else cmsum += (signal[ev] - strip->GetPedestal());
886 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n);
888 if (!(module->SetCM(cmsum, chipind, ev)))
889 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
890 module->GetModuleId(), chipind, ev));
897 //______________________________________________________________________________
898 Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread, const Bool_t usewelford)
900 // Performs calculation of calibration parameters (pedestal, noise, ...)
902 if (nmread <= 0) return kFALSE;
903 if (!fModules) return kFALSE;
904 while ((nm = ReadModuleRawData(nmread)) > 0) {
905 cout << "Processing next " << nm << " modules;" << endl;
906 for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) {
907 if (!fModules[modind]) {
908 AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n",
912 AddFeromCm(fModules[modind]);
914 CalculatePedNoiseW(fModules[modind]);
915 CalculateNoiseCMW(fModules[modind]);
917 CalculatePedestal(fModules[modind]);
918 CalculateNoise(fModules[modind]);
919 CalculateNoiseCM(fModules[modind]);
925 fModIndProcessed = fModIndRead;
926 cout << fModIndProcessed << " - done" << endl;
927 if (nm < nmread ) break;
933 //______________________________________________________________________________
934 Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
936 // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class
937 if (!fDDLModuleMap) {
938 AliError("Error DDLMap is not initialized, return 0!");
941 Int_t mddli = ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
942 if ((ddlID < fgkNumberOfSSDDDLs) && (mddli < fgkNumberOfSSDModulesPerDdl)) {
943 mddli = fDDLModuleMap[ddlID * fgkNumberOfSSDModulesPerDdl + mddli];
946 AliWarning(Form("Module index = %d or ddlID = %d is out of range 0 is rturned", ddlID, mddli));
949 if (mddli > SHRT_MAX) return SHRT_MAX;
950 else return (Short_t)mddli;
955 //______________________________________________________________________________
956 AliITSNoiseSSDv2* AliITSHandleDaSSD::GetCalibrationOCDBNoise() const
958 // Fill in the array for OCDB
959 AliITSNoiseSSDv2 *ldcn = NULL;
960 AliITSModuleDaSSD *module = NULL;
961 AliITSChannelDaSSD *strip = NULL;
962 if (!fModules) return NULL;
963 ldcn = new AliITSNoiseSSDv2;
965 AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
968 for (Int_t i = 0; i < fNumberOfModules; i++) {
969 if (!(module = fModules[i])) continue;
970 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
971 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
972 if (!(strip = module->GetStrip(strind))) continue;
973 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
974 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() )
975 ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
977 ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
984 //______________________________________________________________________________
985 AliITSBadChannelsSSDv2* AliITSHandleDaSSD::GetCalibrationBadChannels() const
987 // Fill in the TObjArray with the list of bad channels
988 AliITSBadChannelsSSDv2 *ldcbc = NULL;
989 AliITSModuleDaSSD *module = NULL;
990 AliITSChannelDaSSD *strip = NULL;
991 if (!fModules) return NULL;
992 ldcbc = new AliITSBadChannelsSSDv2;
994 AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
997 for (Int_t i = 0; i < fNumberOfModules; i++) {
998 if (!(module = fModules[i])) continue;
999 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1000 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1001 if (!(strip = module->GetStrip(strind))) continue;
1002 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1003 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() )
1004 ldcbc->AddBadChannelP(modid, strip->GetStripId(), EvaluateIfChannelIsBad(module, strip->GetStripId()));
1006 ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()),
1007 EvaluateIfChannelIsBad(module, strip->GetStripId()));
1015 //______________________________________________________________________________
1016 Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname)
1018 // Save Calibration data locally
1019 AliITSBadChannelsSSDv2 *ldcbc = NULL;
1020 AliITSPedestalSSDv2 *ldcp = NULL;
1021 AliITSNoiseSSDv2 *ldcn = NULL;
1022 AliITSModuleDaSSD *module = NULL;
1023 AliITSChannelDaSSD *strip = NULL;
1025 TString dadatafilename("");
1026 if (!fModules) return kFALSE;
1027 ldcn = new AliITSNoiseSSDv2;
1028 ldcp = new AliITSPedestalSSDv2;
1029 ldcbc = new AliITSBadChannelsSSDv2;
1030 if ((!ldcn) || (!ldcp) || (!ldcp)) {
1031 AliError("Error allocation mamory for calibration objects, return kFALSE!");
1034 for (Int_t i = 0; i < fNumberOfModules; i++) {
1035 if (!(module = fModules[i])) continue;
1036 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1037 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1038 if (!(strip = module->GetStrip(strind))) continue;
1039 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1040 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) {
1041 ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
1042 ldcp->AddPedestalP(modid, strip->GetStripId(), strip->GetPedestal());
1043 ldcbc->AddBadChannelP(modid, strip->GetStripId(), EvaluateIfChannelIsBad(module, strip->GetStripId()));
1045 ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
1046 ldcp->AddPedestalN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetPedestal());
1047 ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()),
1048 EvaluateIfChannelIsBad(module, strip->GetStripId()));
1052 if (dafname) dadatafilename.Form("%s/", dafname);
1053 dadatafilename += TString::Format("ITSSSDda_%i.root", fLdcId);
1054 tmpfname = new Char_t[dadatafilename.Length()+1];
1055 Int_t sz = dadatafilename.Sizeof();
1056 dafname = strncpy(tmpfname, dadatafilename.Data(),sz);
1057 TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE");
1058 if (fileRun->IsZombie()) {
1059 AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data()));
1067 fileRun->WriteTObject(ldcn);
1068 fileRun->WriteTObject(ldcp);
1069 if (fBadChannelsList)
1070 if (fMergeBCLists) {
1071 MergeBadChannels(ldcbc);
1072 fileRun->WriteTObject(ldcbc);
1073 } else fileRun->WriteTObject(fBadChannelsList);
1074 else fileRun->WriteTObject(ldcbc);
1084 //______________________________________________________________________________
1085 Int_t AliITSHandleDaSSD::MergeBadChannels(AliITSBadChannelsSSDv2*& bcl) const
1087 // Merges the statick bad channels list with bad channels got upon calibration
1088 AliITSModuleDaSSD *module = 0;
1089 Int_t nmpch = 0, nmnch = 0, ngpch = 0, ngnch = 0;
1090 if (!fBadChannelsList || !bcl) {
1091 AliWarning("Either fBadChannelsList == NULL or bad_channels_list == NULL, there is nothing to merge!");
1094 for (Int_t modind = 0; modind < GetNumberOfModules(); modind++) {
1095 if (!(module = fModules[modind])) continue;
1096 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1097 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1098 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetPNStripsPerModule(); strind++) {
1099 if ( (!(fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask))
1100 && (bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask) )
1102 if ( (!(fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask))
1103 && (bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask) )
1105 if ( (!(bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask))
1106 && (fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) {
1107 bcl->AddBadChannelP(modid, strind, fBadChannelsList->GetBadChannelP(modid, strind));
1110 if ( (!(bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask))
1111 && (fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) {
1112 bcl->AddBadChannelN(modid, strind, fBadChannelsList->GetBadChannelN(modid, strind));
1117 AliInfo(Form("Static bad, dynamic good: P%d, N%d", nmpch, nmnch));
1118 AliInfo(Form("Static good, dynamic bad: P%d, N%d", ngpch, ngnch));
1119 return (nmnch + nmpch);
1124 //______________________________________________________________________________
1125 Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
1127 // Dump calibration parameters
1128 AliITSModuleDaSSD *mod;
1129 AliITSChannelDaSSD *strip;
1131 cout << "SSDDALDC::DumpModInfo(): Error, no modules are allocated!" << endl;
1134 cout << "Modules with MeanNoise > " << meannosethreshold << endl;
1135 for (Int_t i = 0; i < fNumberOfModules; i++) {
1136 if (!(mod = fModules[i])) continue;
1137 Double_t maxnoise = 0.0L, meannoise = 0.0L, meanovf = 0.0L;
1138 Float_t maxped = 0.0f;
1139 Int_t maxstrind = 0, novfstr = 0, maxovf = 0;
1140 for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
1141 if (!(strip = mod->GetStrip(strind))) {novfstr++; continue; }
1142 if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++; continue; }
1143 if (maxnoise < strip->GetNoiseCM()) {
1144 maxnoise = strip->GetNoiseCM();
1147 meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Double_t>(strind - novfstr + 1)
1148 : strip->GetNoiseCM();
1149 if (TMath::Abs(maxped) < TMath::Abs(strip->GetPedestal())) maxped = strip->GetPedestal();
1150 meanovf = (strind - novfstr) ? meanovf + (strip->GetOverflowNumber() - meanovf) / static_cast<Double_t>(strind - novfstr + 1)
1151 : strip->GetOverflowNumber();
1152 if (strip->GetOverflowNumber() > maxovf) maxovf = strip->GetOverflowNumber();
1154 if (meannoise > meannosethreshold)
1155 cout << "Mod: " << i << "; DDl: " << (int)mod->GetDdlId() << "; AD: " << (int)mod->GetAD()
1156 << "; ADC: " << (int)mod->GetADC() << "; MaxPed = " << maxped
1157 << "; MeanNoise = " << meannoise << "; MaxNoise = " << maxnoise << "; MaxNoiseStrip = " << maxstrind
1158 << "; NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
1159 if (maxovf > 10) cout << "Max number of events with overflow : " << maxovf << "; mean : " << meanovf << endl;
1166 //______________________________________________________________________________
1167 Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
1169 // Print Module calibration data whether in file or in cout
1170 AliITSChannelDaSSD *strip;
1172 ostream *outputfile;
1173 if (!fname) { outputfile = &cout; }
1175 datafile.open(fname, ios::out);
1176 if (datafile.fail()) return kFALSE;
1177 outputfile = dynamic_cast<ostream*>(&datafile);
1179 *outputfile << "DDL = " << (int)ddlID << "; AD = " << (int)ad << "; ADC = " << (int)adc << endl;
1180 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1181 if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) {
1182 *outputfile << "Str = " << strind << "; ped = " << strip->GetPedestal()
1183 << "; noise = " << strip->GetNoiseCM() << endl;
1187 if (datafile.is_open()) datafile.close();
1193 //______________________________________________________________________________
1194 void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
1196 // Print general information retrieved from raw data file
1197 cout << "Raw data file: " << fRawDataFileName << endl
1198 << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
1199 << "Number of physics events: " << fNumberOfEvents << endl
1204 //______________________________________________________________________________
1205 Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
1207 // Used to allocate simulated modules to test the performance
1208 AliITSModuleDaSSD *module;
1209 UChar_t ad, adc, ddlID;
1210 ad = adc = ddlID = 0;
1211 if (!(fModules[copymodind])) return kFALSE;
1212 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
1213 if (!fModules[modind]) {
1214 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
1215 if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
1216 else if (adc == 5) adc = 8;
1217 else if (adc == 13) {
1219 if (ad < 8) ad += 1;
1225 if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
1226 fModules[modind] = module;
1227 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1228 AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
1229 if(!cstrip)return kFALSE;
1230 Long_t eventsnumber = cstrip->GetEventsNumber();
1231 AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
1232 for (Long_t evind = 0; evind < eventsnumber; evind++) {
1233 Short_t sign = cstrip->GetSignal(evind);
1234 if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
1236 module->SetStrip(strip, strind);
1240 ddlID = fModules[modind]->GetDdlId();
1241 ad = fModules[modind]->GetAD();
1242 adc = fModules[modind]->GetADC();
1245 for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);
1251 //___________________________________________________________________________________________
1252 Bool_t AliITSHandleDaSSD::AdDataPresent(const Int_t ddl, const Int_t ad) const
1254 // Check if there are calibration data for given ddl and slot
1255 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
1256 if ((GetModule(modind)->GetAD() == ad) && (GetModule(modind)->GetDdlId() == ddl)) return kTRUE;
1262 //___________________________________________________________________________________________
1263 Bool_t AliITSHandleDaSSD::SaveEqSlotCalibrationData(const Int_t ddl, const Int_t ad, const Char_t *fname) const
1265 // Saves calibration files for selected equipment (DDL)
1267 Int_t zsml, offsetml;
1268 ULong_t zsth, offset, zsoffset;
1270 AliError("File name must be specified!");
1273 if (!AdDataPresent(ddl, ad)) {
1274 AliError(Form("Error SaveEqSlotCalibrationData(ddl = %i, ad = %i) no data present", ddl, ad));
1277 feefile.open(fname, ios::out);
1278 if (!feefile.is_open()) {
1279 AliError(Form("Can not open the file %s for output!", fname));
1282 for (zsml = 0; fgkZsBitMask >> zsml; zsml++) ;
1283 for (offsetml = 0; fgkOffSetBitMask >> offsetml; offsetml++) ;
1284 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1285 for (Int_t adcb = 0; adcb < fgkAdcPerDBlock; adcb++) {
1287 for (Int_t j = 0; j < 2; j++) {
1288 Int_t adc = adcb + j * 8;
1289 zsth = ZsThreshold(ddl, ad, adc, strind);
1290 offset = OffsetValue(ddl, ad, adc, strind);
1291 zsoffset = zsoffset | (((zsth << offsetml) | offset) << ((j == 0) ? (offsetml + zsml) : 0));
1293 feefile << "0x" << ConvBase(static_cast<unsigned long>(zsoffset), 16) << endl;
1301 //______________________________________________________________________________
1302 Int_t AliITSHandleDaSSD::ChannelIsBad(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1304 // Check if the channel is bad
1305 AliITSModuleDaSSD *module = NULL;
1307 if (fBadChannelsList && fDDLModuleMap) {
1308 modn = RetrieveModuleId(ddl, ad, adc);
1309 if (modn < 0) return -1;
1310 if (modn < fgkMinSSDModuleId) {
1311 AliWarning(Form("Module ddl/ad/adc: %d/%d/%d has number %d which is wrong for SSD module %d", ddl, ad, adc, strn, modn));
1314 Short_t modid = modn - fgkMinSSDModuleId;
1315 if (strn < AliITSModuleDaSSD::GetPNStripsPerModule())
1316 return (fBadChannelsList->GetBadChannelP(modid, strn) & fgkBadChannelMask);
1317 else return (fBadChannelsList->GetBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strn)) & fgkBadChannelMask);
1319 AliError("Error ether bad channels list or DDLMap is not initialized or both, EvaluateIfChannelIsBad(module, strip) is used!");
1320 if ((module = GetModule(ddl, ad, adc))) {
1321 return (EvaluateIfChannelIsBad(module, strn) & fgkBadChannelMask);
1323 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1332 //______________________________________________________________________________
1333 Int_t AliITSHandleDaSSD::LadderIsOff(const UChar_t ddl, const UChar_t ad, const UChar_t adc) const
1335 //Checks if the module with given ddl, ad, adc is on the ladder which is in the list of ladders which are off
1336 const Int_t nm5 = 500;
1337 const Int_t nm6 = 1248;
1338 const Int_t nml5a = 12;
1339 const Int_t nml5c = 10;
1340 const Int_t nml6a = 12;
1341 const Int_t nml6c = 13;
1342 Int_t modn, ladder, layer, side;
1343 AliITSModuleDaSSD *module;
1344 if (!(module = GetModule(ddl, ad, adc))) return 0;
1345 if ((modn = module->GetModuleId()) <= 0) modn = RetrieveModuleId(ddl, ad, adc);
1346 if (modn <= 0) return 0;
1347 layer = modn >= nm6 ? 1 : 0; // 6 : 5
1348 ladder = (modn - (layer ? nm6 : nm5)) / (layer ? (nml6a + nml6c) : (nml5a + nml5c));
1349 if ( ((modn - (layer ? nm6 : nm5)) % (layer ? (nml6a + nml6c) : (nml5a + nml5c))) < (layer ? nml6a : nml5a))
1352 ladder += (layer ? 600 : 500);
1355 if (fCLaddersOff.GetSize()) {
1356 for(Int_t i = 0; i < fCLaddersOff.GetSize(); i++)
1357 if (fCLaddersOff.At(i) == ladder) return fCLaddersOff.At(i);
1361 if (fALaddersOff.GetSize()) {
1362 for(Int_t i = 0; i < fALaddersOff.GetSize(); i++)
1363 if (fALaddersOff.At(i) == ladder) return fALaddersOff.At(i);
1371 //______________________________________________________________________________
1372 ULong_t AliITSHandleDaSSD::OffsetValue(const AliITSChannelDaSSD *strip,
1373 const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1375 // Calculate the offset value to be upload to FEROM
1377 if (fOffsetDefault < INT_MAX) pedint = fOffsetDefault;
1378 else pedint = TMath::Nint(strip->GetPedestal());
1379 if (pedint > static_cast<Int_t>((fgkOffSetBitMask >> 1))) {
1380 if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (EvaluateIfChannelIsBad(GetModule(ddl, ad, adc), strn))))
1381 AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
1382 pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), (fgkOffSetBitMask >> 1)));
1383 return (fgkOffSetBitMask >> 1);
1385 if ((-pedint) > static_cast<Int_t>(((fgkOffSetBitMask + 1) >> 1))) {
1386 if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (EvaluateIfChannelIsBad(GetModule(ddl, ad, adc), strn))))
1387 AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
1388 pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(),
1389 ((fgkOffSetBitMask & (~fgkOffSetBitMask >> 1)) - fgkOffSetBitMask - 1)));
1390 return fgkOffSetBitMask & (~fgkOffSetBitMask >> 1);
1392 return fgkOffSetBitMask & (pedint >= 0 ? pedint : pedint + fgkOffSetBitMask + 1);
1397 //______________________________________________________________________________
1398 ULong_t AliITSHandleDaSSD::OffsetValue(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1400 // Calculate the offset value to be upload to FEROM
1401 AliITSChannelDaSSD *strip = NULL;
1402 AliITSModuleDaSSD *module = NULL;
1403 if ((module = GetModule(ddl, ad, adc))) {
1404 if ((strip = module->GetStrip(strn))) return OffsetValue(strip, ddl, ad, adc, strn);
1406 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
1410 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1417 //______________________________________________________________________________
1418 ULong_t AliITSHandleDaSSD::ZsThreshold(const AliITSChannelDaSSD *strip) const
1420 // Calculate the value of zero suppression threshold to be upload to FEROM
1422 if (fZsDefault < 0) {
1423 zs = TMath::Nint(fZsFactor * strip->GetNoiseCM());
1424 if (zs < static_cast<ULong_t>(fZsMinimum)) zs = static_cast<ULong_t>(fZsMinimum);
1426 else zs = fZsDefault;
1427 return (zs < fgkZsBitMask) ? (zs & fgkZsBitMask) : fgkZsBitMask;
1431 //______________________________________________________________________________
1432 ULong_t AliITSHandleDaSSD::ZsThreshold(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1434 // Calculate the value of zero suppression threshold to be upload to FEROM, account bad channels list
1435 AliITSChannelDaSSD *strip = NULL;
1436 AliITSModuleDaSSD *module = NULL;
1437 if (ChannelIsBad(ddl, ad, adc, strn)) return fgkZsBitMask;
1438 if (LadderIsOff(ddl, ad, adc)) return fgkZsBitMask;
1439 if (fZsDefault > 0) if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) return fgkZsBitMask;
1440 if ((module = GetModule(ddl, ad, adc))) {
1441 if (fMergeBCLists) if (EvaluateIfChannelIsBad(module, strn)) return fgkZsBitMask;
1442 if ((strip = module->GetStrip(strn))) return ZsThreshold(strip);
1444 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
1448 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1454 //______________________________________________________________________________
1455 string AliITSHandleDaSSD::ConvBase(const unsigned long value, const long base) const
1457 // Converts the unsigned long number into that in another base
1458 string digits = "0123456789ABCDEF";
1460 unsigned long v = value;
1461 if((base < 2) || (base > 16)) {
1462 result = "Error: base out of range.";
1467 result = digits[v % base] + result;
1471 while((v) || (i<8));
1478 //______________________________________________________________________________
1479 Int_t AliITSHandleDaSSD::CheckOffChips() const
1481 // Check if the chip, module are off
1482 AliITSChannelDaSSD *strip;
1484 Int_t strnd, chipnd, modnd, stroff, chipoff, modoff;
1485 offthreshold = TMath::Nint(fZsMinimum/fZsFactor);
1487 for (Int_t mi = 0; mi < fNumberOfModules; mi++) {
1488 if (!fModules[mi]) { modnd++; continue; }
1489 if (fModules[mi]->GetModuleId() < 0) continue;
1490 if (LadderIsOff(fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()) ) continue;
1491 chipoff = chipnd = 0;
1492 for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
1494 Int_t stripind = chipind * AliITSModuleDaSSD::GetStripsPerChip();
1495 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1496 if (!(strip = fModules[mi]->GetStrip(strind))) { strnd++; continue; }
1497 if (strip->GetNoiseCM() < offthreshold ) stroff++;
1499 if (strnd == AliITSModuleDaSSD::GetStripsPerChip()) chipnd++;
1500 else if (stroff == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1501 else if ((stroff + strnd) == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1503 if ((!chipoff) && (!chipnd)) continue;
1504 if (chipnd == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1505 AliInfo(Form("Module: (ddl/ad/adc) %i/%i/%i seems to be off and it is not on the ladders which are off!",
1506 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1509 if (chipoff == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1510 AliInfo(Form("Module (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
1511 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1514 else if ((chipoff + chipnd) == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1515 AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
1516 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1520 AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i has %i chips which are off!",
1521 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC(), chipoff));
1525 return (modoff + modnd);
1529 //______________________________________________________________________________
1530 Bool_t AliITSHandleDaSSD::CalculatePedNoiseW(const AliITSModuleDaSSD *const module)
1532 // Calculates Pedestal and Noise using Welford algorithm
1533 AliITSChannelDaSSD *strip;
1534 Double_t pedestal, noise, p0, s0;
1537 if (!module) return kFALSE;
1538 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1539 if (!(strip = module->GetStrip(strind))) continue;
1540 if (!(signal = strip->GetSignal())) {
1541 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
1542 module->GetModuleId(), strind));
1545 //************* pedestal and noise first pass ****************
1546 pedestal = p0 = noise = 0.0L;
1548 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1549 if (SignalOutOfRange(signal[ev])) ovev += 1;
1552 pedestal = p0 = signal[ev];
1555 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1556 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1561 if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
1562 strip->SetPedestal(static_cast<Float_t>(pedestal));
1563 if ((n = strip->GetEventsNumber() - ovev - 1) > 0)
1564 strip->SetNoise( static_cast<Float_t>(TMath::Sqrt(noise / static_cast<Double_t>(n))) );
1566 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
1569 //************* Second pass excluds event with |p - s|>f*noise *****************
1570 pedestal = p0 = noise = 0.0L;
1572 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1573 if ( SignalOutOfRange(signal[ev])
1574 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
1577 pedestal = p0 = signal[ev];
1580 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1581 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1586 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n));
1587 else noise = AliITSChannelDaSSD::GetUndefinedValue();
1588 strip->SetNoise(static_cast<Float_t>(noise));
1589 if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
1590 strip->SetPedestal(static_cast<Float_t>(pedestal));
1591 strip->SetOverflowNumber(ovev);
1597 //______________________________________________________________________________
1598 Bool_t AliITSHandleDaSSD::CalculateCMW(AliITSModuleDaSSD *const module)
1600 // Calculates CM using Welford algorithm
1601 AliITSChannelDaSSD *strip = NULL;
1605 Double_t cm0, cm1, cmsigma, cms1;
1606 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
1607 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
1608 stripind = chipind * module->GetStripsPerChip();
1609 module->GetCM()[chipind].Set(fNumberOfEvents);
1610 module->GetCM()[chipind].Reset(0.0f);
1611 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
1612 // calculate firs approximation of CM and SigmaCM.
1613 cm0 = cm1 = cmsigma = 0.0L;
1615 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1616 if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; } //return kFALSE;
1617 if (!(signal = strip->GetSignal())) { ovstr += 1; continue; } //return kFALSE;
1618 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
1620 if (!(strind - stripind - ovstr)) {
1621 cm0 = cm1 = signal[ev] - strip->GetPedestal();
1624 cm1 = cm0 + (signal[ev] - strip->GetPedestal() - cm0) / static_cast<Double_t>(strind - stripind - ovstr + 1);
1625 cms1 = cmsigma + (signal[ev] - strip->GetPedestal() - cm0) * (signal[ev] - strip->GetPedestal() - cm1);
1630 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr - 1) > 0) cmsigma = TMath::Sqrt(cmsigma / static_cast<Double_t>(n));
1632 AliWarning(Form("AliITSHandleDaSSD: Too little number of strips have a signal for module:chip:event : [%d]:[%d]:[%ld]\n",
1633 module->GetModuleId(), chipind, ev));
1634 if (!(module->SetCM(0.0f, chipind, ev)))
1635 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
1636 module->GetModuleId(), chipind, ev));
1639 // calculate cm with threshold
1640 Double_t cmsum = 0.0L;
1642 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1643 if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; }
1644 if (!(signal = strip->GetSignal())) { ovstr += 1; continue; }
1645 if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
1646 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
1647 else cmsum += (signal[ev] - strip->GetPedestal());
1649 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Double_t)(n);
1651 if (!(module->SetCM(static_cast<Float_t>(cmsum), chipind, ev)))
1652 AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
1653 module->GetModuleId(), chipind, ev));
1660 //______________________________________________________________________________
1661 Bool_t AliITSHandleDaSSD::CalculateNoiseCMW(AliITSModuleDaSSD *const module)
1663 // Calculates Noise with CM correction
1664 AliITSChannelDaSSD *strip = NULL;
1667 if (!CalculateCMW(module)) {
1668 AliError("Error: AliITSHandleDaSSD::CalculateCMW() returned kFALSE");
1671 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1672 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
1673 if (!(signal = strip->GetSignal())) {
1674 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
1675 AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCMW(): there are no events data for module[%i] strip[%i]->GetSignal()",
1676 module->GetModuleId(), strind));
1677 continue; //return kFALSE;
1679 //** To get exactly the same set of events as for pedestal and noise calculation **
1680 Double_t pedestal, noise, p0, s0;
1681 pedestal = p0 = noise = 0.0L;
1683 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1684 if (SignalOutOfRange(signal[ev])) ovev += 1;
1687 pedestal = p0 = signal[ev];
1690 p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
1691 s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
1696 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n));
1698 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
1701 //** Calculation of CM corrected noise **
1702 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
1703 Double_t nsum = 0.0L;
1705 for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
1706 if ( SignalOutOfRange(signal[ev])
1707 || TMath::Abs(signal[ev] - pedestal) > (fPedestalThresholdFactor * noise)) ovev += 1;
1708 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
1710 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / static_cast<Double_t>(n));
1711 else noise = AliITSChannelDaSSD::GetUndefinedValue();
1712 strip->SetNoiseCM(static_cast<Float_t>(noise));
1719 //______________________________________________________________________________
1720 UChar_t AliITSHandleDaSSD::EvaluateIfChannelIsBad(const AliITSModuleDaSSD *const module, const Int_t stripn) const
1722 //Applies the bad channel creteria and set the appropriate flags for returned value
1723 AliITSChannelDaSSD *strip = 0;
1725 if (fZsDefault >= 0) { if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) bcflags |= 3; }
1726 else if (static_cast<ULong_t>(fZsMinimum) >= fgkZsBitMask) bcflags |= 3;
1727 if (LadderIsOff(module->GetDdlId(), module->GetAD(), module->GetADC()) ) bcflags |= 3;
1729 if (!(strip = module->GetStrip(stripn))) bcflags |= 3;
1731 if (strip->GetNoiseCM() == AliITSChannelDaSSD::GetUndefinedValue()) bcflags |= 8;
1732 if (static_cast<ULong_t>(TMath::Nint(fZsFactor * strip->GetNoiseCM())) >= fgkZsBitMask) bcflags |= 8;
1733 if (strip->GetNoiseCM() < 1) bcflags |= 16;
1734 if (strip->GetPedestal() > ((fgkOffSetBitMask >> 1) - 1)) bcflags |= 4;
1735 else if ((-(strip->GetPedestal())) > (fgkOffSetBitMask >> 1)) bcflags |= 4;
1736 if (bcflags) bcflags |= 3;