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"
37 #include "AliITSNoiseSSDv2.h"
38 #include "AliITSPedestalSSDv2.h"
39 #include "AliITSBadChannelsSSDv2.h"
40 #include "AliITSRawStreamSSD.h"
41 #include "AliRawReaderDate.h"
42 #include "AliITSRawStreamSSD.h"
43 #include "AliITSChannelDaSSD.h"
46 ClassImp(AliITSHandleDaSSD)
51 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModules = 1698; // Number of SSD modules in ITS
52 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModulesPerDdl = 108; // Number of SSD modules in DDL
53 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDModulesPerSlot = 12; // Number of SSD modules in Slot
54 const Short_t AliITSHandleDaSSD::fgkMinSSDModuleId = 500; // Initial SSD modules number
55 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDSlotsPerDDL = 9; // Number of SSD slots per DDL
56 const Int_t AliITSHandleDaSSD::fgkNumberOfSSDDDLs = 16; // Number of SSD modules in Slot
57 const Float_t AliITSHandleDaSSD::fgkPedestalThresholdFactor = 3.0; // Defalt value for fPedestalThresholdFactor
58 const Float_t AliITSHandleDaSSD::fgkCmThresholdFactor = 3.0; // Defalt value for fCmThresholdFactor
60 const UInt_t AliITSHandleDaSSD::fgkZsBitMask = 0x0000003F; // Bit mask for FEROM ZS
61 const UInt_t AliITSHandleDaSSD::fgkOffSetBitMask = 0x000003FF; // Bit mask for FEROM Offset correction
62 const UInt_t AliITSHandleDaSSD::fgkBadChannelMask = 0x00000001; // Mask to suppress the channel from the bad channel list
63 const Int_t AliITSHandleDaSSD::fgkAdcPerDBlock = 6; // FEROM configuration file constant
65 //______________________________________________________________________________
66 AliITSHandleDaSSD::AliITSHandleDaSSD() :
67 fRawDataFileName(NULL),
75 fBadChannelsList(NULL),
81 fPedestalThresholdFactor(fgkPedestalThresholdFactor),
82 fCmThresholdFactor(fgkCmThresholdFactor),
84 fOffsetDefault(INT_MAX),
89 // Default constructor
93 //______________________________________________________________________________
94 AliITSHandleDaSSD::AliITSHandleDaSSD(Char_t *rdfname) :
95 fRawDataFileName(NULL),
103 fBadChannelsList(NULL),
109 fPedestalThresholdFactor(fgkPedestalThresholdFactor) ,
110 fCmThresholdFactor(fgkCmThresholdFactor),
112 fOffsetDefault(INT_MAX),
117 if (!Init(rdfname)) AliError("AliITSHandleDaSSD::AliITSHandleDaSSD() initialization error!");
121 //______________________________________________________________________________
122 AliITSHandleDaSSD::AliITSHandleDaSSD(const AliITSHandleDaSSD& ssdadldc) :
124 fRawDataFileName(ssdadldc.fRawDataFileName),
125 fNumberOfModules(ssdadldc.fNumberOfModules),
127 fModIndProcessed(ssdadldc.fModIndProcessed),
128 fModIndRead(ssdadldc.fModIndRead),
131 fNumberOfEvents(ssdadldc.fNumberOfEvents),
132 fBadChannelsList(NULL),
134 fALaddersOff(ssdadldc.fALaddersOff),
135 fCLaddersOff(ssdadldc.fCLaddersOff),
136 fLdcId(ssdadldc.fLdcId),
137 fRunId(ssdadldc.fRunId),
138 fPedestalThresholdFactor(ssdadldc.fPedestalThresholdFactor),
139 fCmThresholdFactor(ssdadldc.fCmThresholdFactor),
140 fZsDefault(ssdadldc.fZsDefault),
141 fOffsetDefault(ssdadldc.fOffsetDefault),
142 fZsMinimum(ssdadldc.fZsMinimum),
143 fMergeBCLists(ssdadldc.fMergeBCLists),
144 fZsFactor(ssdadldc.fZsFactor)
147 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
148 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
150 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
151 if (ssdadldc.fModules[modind]) {
152 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
153 if (!fModules[modind]) {
154 AliError("AliITSHandleDaSSD: Error copy constructor");
155 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
160 } else fModules[modind] = NULL;
163 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
164 fNumberOfModules = 0;
168 if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by copy constructor, use other methods to init it!");
169 if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by copy constructor, use other methods to init it!");
173 //______________________________________________________________________________
174 AliITSHandleDaSSD& AliITSHandleDaSSD::operator = (const AliITSHandleDaSSD& ssdadldc)
176 // assignment operator
177 if (this == &ssdadldc) return *this;
178 TObject::operator=(ssdadldc);
180 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
184 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
185 if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
186 fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
188 for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
189 if (ssdadldc.fModules[modind]) {
190 fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
191 if (!fModules[modind]) {
192 AliError("AliITSHandleDaSSD: Error assignment operator");
193 for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
198 } else fModules[modind] = NULL;
201 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
202 fNumberOfModules = 0;
206 fRawDataFileName = NULL;
207 fModIndProcessed = 0;
210 fEqIndex = ssdadldc.fEqIndex;
211 fNumberOfEvents = ssdadldc.fNumberOfEvents;
212 fLdcId = ssdadldc.fLdcId;
213 fRunId = ssdadldc.fRunId;
214 fPedestalThresholdFactor = ssdadldc.fPedestalThresholdFactor;
215 fCmThresholdFactor = ssdadldc.fCmThresholdFactor;
216 fZsDefault = ssdadldc.fZsDefault;
217 fOffsetDefault = ssdadldc.fOffsetDefault;
218 fZsMinimum = ssdadldc.fZsMinimum;
219 fMergeBCLists = ssdadldc.fMergeBCLists;
220 fZsFactor = ssdadldc.fZsFactor;
221 fALaddersOff = ssdadldc.fALaddersOff;
222 fCLaddersOff = ssdadldc.fCLaddersOff;
223 fBadChannelsList = NULL;
224 fDDLModuleMap = NULL;
226 if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by assignment operator, use other methods to init it!");
227 if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by assignment operator, use other methods to init it!");
232 //______________________________________________________________________________
233 AliITSHandleDaSSD::~AliITSHandleDaSSD()
235 // Default destructor
238 for (Int_t i = 0; i < fNumberOfModules; i++)
240 if (fModules[i]) delete fModules[i];
244 if (fModIndex) delete [] fModIndex;
245 if (fBadChannelsList) delete fBadChannelsList;
246 if (fDDLModuleMap) delete [] fDDLModuleMap;
251 //______________________________________________________________________________
252 void AliITSHandleDaSSD::Reset()
254 // Delete array of AliITSModuleDaSSD* objects.
256 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
260 if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
262 if (fBadChannelsList) {
263 delete fBadChannelsList;
264 fBadChannelsList = NULL;
266 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL; }
270 fRawDataFileName = NULL;
271 fModIndProcessed = fModIndRead = 0;
274 fPedestalThresholdFactor = fgkPedestalThresholdFactor;
275 fCmThresholdFactor = fgkCmThresholdFactor;
280 //______________________________________________________________________________
281 Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname)
283 // Read raw data file and set initial and configuration parameters
284 Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0;
285 Int_t nofeqipmentev, nofeqipment = 0, eqn = 0;
286 AliRawReaderDate *rawreaderdate = NULL;
287 UChar_t *data = NULL;
288 Long_t datasize = 0, eqbelsize = 1;
290 rawreaderdate = new AliRawReaderDate(rdfname, 0);
291 if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) {
292 AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname));
296 if (rawreaderdate->NextEvent()) {
297 fRunId = rawreaderdate->GetRunNumber();
298 rawreaderdate->RewindEvents();
299 } else { MakeZombie(); return kFALSE; }
300 if (fModules) Reset();
301 //rawreaderdate->SelectEvents(-1);
302 rawreaderdate->Select("ITSSSD");
304 while (rawreaderdate->NextEvent()) {
305 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
308 while (rawreaderdate->ReadNextData(data)) {
309 fLdcId = rawreaderdate->GetLDCId();
311 datasize = rawreaderdate->GetDataSize();
312 eqbelsize = rawreaderdate->GetEquipmentElementSize();
313 if ( datasize % eqbelsize ) {
314 AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %i is not an integer of equipment data size %i",
315 rdfname, datasize, eqbelsize));
319 nofstripsev += (Int_t) (datasize / eqbelsize);
321 if (physeventind++) {
322 if (nofstrips != nofstripsev) AliWarning(Form("AliITSHandleDaSSD: number of strips varies from event to event, ev = %i, %i",
323 physeventind, nofstripsev));
324 if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to event");
326 nofstrips = nofstripsev;
327 nofeqipment = nofeqipmentev;
328 if (strn < nofstrips) strn = nofstrips;
329 if (eqn < nofeqipment) eqn = nofeqipment;
331 delete rawreaderdate;
332 if ((physeventind > 0) && (strn > 0))
334 fNumberOfEvents = physeventind;
335 fRawDataFileName = rdfname;
338 fModIndex = new (nothrow) Int_t [fgkNumberOfSSDModulesPerDdl * eqn];
340 for (Int_t i = 0; i < fgkNumberOfSSDModulesPerDdl * eqn; i++) fModIndex[i] = -1;
341 else AliWarning(Form("AliITSHandleDaSSD: Error Init(%s): Index array for %i modules was not created",
342 rdfname, fgkNumberOfSSDModulesPerDdl * eqn));
343 if (SetNumberOfModules(fgkNumberOfSSDModulesPerDdl * eqn)) {
344 TString str = TString::Format("Max number of equipment: %i, max number of channels: %i\n", eqn, strn);
345 DumpInitData(str.Data());
355 //______________________________________________________________________________
356 AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
358 // Retrieve AliITSModuleDaSSD object from the array
359 if (!fModules) return NULL;
360 for (Int_t i = 0; i < fNumberOfModules; i++) {
362 if ( (fModules[i]->GetDdlId() == ddlID)
363 && (fModules[i]->GetAD() == ad)
364 && (fModules[i]->GetADC() == adc))
372 Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
374 // Retrieve the position of AliITSModuleDaSSD object in the array
375 if (!fModules) return -1;
376 for (Int_t i = 0; i < fNumberOfModules; i++) {
378 if ( (fModules[i]->GetDdlId() == ddlID)
379 && (fModules[i]->GetAD() == ad)
380 && (fModules[i]->GetADC() == adc))
389 //______________________________________________________________________________
390 AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const
392 // Retrieve AliITSChannalDaSSD object from the array
393 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
394 if ( (fModules[modind]->GetDdlId() == ddlID)
395 && (fModules[modind]->GetAD() == ad)
396 && (fModules[modind]->GetADC() == adc) )
398 return fModules[modind]->GetStrip(stripID);
401 AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!",
402 ddlID, ad, adc, stripID));
408 //______________________________________________________________________________
409 Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index)
411 // Assign array element with AliITSModuleDaSSD object
412 if ((index < fNumberOfModules) && (index >= 0))
414 if (fModules[index]) delete fModules[index];
415 fModules[index] = module;
423 //______________________________________________________________________________
424 Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules)
426 // Allocates memory for AliITSModuleDaSSD objects
427 if (numberofmodules > fgkNumberOfSSDModules)
428 AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD",
429 numberofmodules, fgkNumberOfSSDModules));
431 for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
435 fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules];
437 fNumberOfModules = numberofmodules;
438 memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules);
441 AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules));
442 fNumberOfModules = 0;
450 //______________________________________________________________________________
451 Bool_t AliITSHandleDaSSD::ReadStaticBadChannelsMap(const Char_t *filename)
453 // Reads Static Bad Channels Map from the file
456 AliWarning("No file name is specified for Static Bad Channels Map!");
459 bcfile = new TFile(filename, "READ");
460 if (bcfile->IsZombie()) {
461 AliWarning(Form("Error reading file %s with Static Bad Channels Map!", filename));
464 bcfile->GetObject("AliITSBadChannelsSSDv2;1", fBadChannelsList);
465 if (!fBadChannelsList) {
466 AliWarning("Error fBadChannelsList == NULL!");
478 Bool_t AliITSHandleDaSSD::ReadDDLModuleMap(const Char_t *filename)
480 // Reads the SSD DDL Map from the file
482 AliRawReaderDate *rwr = NULL;
483 AliITSRawStreamSSD *rsm = NULL;
485 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
486 fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
487 if (!fDDLModuleMap) {
488 AliWarning("Error allocation memory for DDL Map!");
492 AliWarning("No file name is specified for SSD DDL Map, using the one from AliITSRawStreamSSD!");
493 rwr = new AliRawReaderDate(event);
494 rsm = new AliITSRawStreamSSD(rwr);
495 rsm->Setv11HybridDDLMapping();
496 for (Int_t ddli = 0; ddli < fgkNumberOfSSDDDLs; ddli++)
497 for (Int_t mi = 0; mi < fgkNumberOfSSDModulesPerDdl; mi++)
498 fDDLModuleMap[(ddli * fgkNumberOfSSDModulesPerDdl + mi)] = rsm->GetModuleNumber(ddli, mi);
503 ddlmfile.open(filename, ios::in);
504 if (!ddlmfile.is_open()) {
505 AliWarning(Form("Error reading file %s with SSD DDL Map!", filename));
506 if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
510 while((!ddlmfile.eof()) && (ind < (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))) {
511 ddlmfile >> fDDLModuleMap[ind++];
512 if (ddlmfile.fail()) AliError(Form("Error extracting number from the DDL map file %s, ind: ", filename, ind));
514 if (ind != (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))
515 AliWarning(Form("Only %i (< %i) entries were read from DDL Map!", ind, (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl)));
522 //______________________________________________________________________________
523 Int_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber)
525 // Reads raw data from file
526 if (!Init(fileName)){
527 AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile");
530 fNumberOfEvents = eventsnumber;
531 return ReadModuleRawData (fNumberOfModules);
536 //______________________________________________________________________________
537 Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber)
539 // Reads raw data from file
540 AliRawReader *rawreaderdate = NULL;
541 AliITSRawStreamSSD *stream = NULL;
542 AliITSModuleDaSSD *module;
543 AliITSChannelDaSSD *strip;
545 Int_t nofeqipment, eqind;
546 Short_t equipid, prequipid;
548 if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0;
550 AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data");
553 if (!fDDLModuleMap) if (!ReadDDLModuleMap()) AliWarning("DDL map is not defined, ModuleID will be set to 0!");
554 stream = new AliITSRawStreamSSD(rawreaderdate);
555 stream->Setv11HybridDDLMapping();
556 //rawreaderdate->SelectEvents(-1);
557 rawreaderdate->Select("ITSSSD");
560 while (rawreaderdate->NextEvent()) {
561 if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
564 while (stream->Next()) {
565 equipid = rawreaderdate->GetEquipmentId();
566 if ((equipid != prequipid)) {
567 if ((eqind = GetEqIndex(equipid)) < 0) { fEqIndex.AddAt(equipid, nofeqipment); eqind = nofeqipment++; }
570 Int_t equiptype = rawreaderdate->GetEquipmentType();
571 UChar_t ddlID = (UChar_t)rawreaderdate->GetDDLID();
572 UChar_t ad = stream->GetAD();
573 UChar_t adc = stream->GetADC();
574 UShort_t stripID = stream->GetSideFlag() ? AliITSChannelDaSSD::GetMaxStripIdConst() - stream->GetStrip() : stream->GetStrip();
575 Short_t signal = stream->GetSignal();
577 Int_t indpos = (eqind * fgkNumberOfSSDModulesPerDdl)
578 + ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
579 Int_t modpos = fModIndex[indpos];
580 if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue;
581 if ((modpos < 0) && (modind < modulesnumber)) {
582 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
584 if (fDDLModuleMap) mddli = RetrieveModuleId(ddlID, ad, adc);
586 if (!module->SetModuleIdData (ddlID, ad, adc, mddli)) return 0;
587 module->SetModuleRorcId (equipid, equiptype);
588 module->SetCMFeromEventsNumber(fNumberOfEvents);
589 modpos = fModIndRead + modind;
591 fModules[modpos] = module;
592 fModIndex[indpos] = modpos;
594 if (stripID < AliITSModuleDaSSD::GetStripsPerModuleConst()) {
595 if (!(strip = fModules[modpos]->GetStrip(stripID))) {
596 strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents);
597 fModules[modpos]->SetStrip(strip, stripID);
599 strip->SetSignal(eventind, signal);
600 } else fModules[modpos]->SetCMFerom(signal, (stripID - AliITSModuleDaSSD::GetStripsPerModuleConst()), eventind);
602 if (++eventind > fNumberOfEvents) break;
605 delete rawreaderdate;
606 if (modind) cout << "The memory was allocated for " << modind << " modules." << endl;
607 fModIndRead += modind;
608 if (modind < modulesnumber) RelocateModules();
614 //______________________________________________________________________________
615 Bool_t AliITSHandleDaSSD::RelocateModules()
617 // Relocate memory for AliITSModuleDaSSD object array
619 AliITSModuleDaSSD **marray = NULL;
620 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
621 if (fModules[modind]) nm += 1;
622 if (nm == fNumberOfModules) return kTRUE;
623 marray = new (nothrow) AliITSModuleDaSSD* [nm];
625 AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm));
629 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
630 if (fModules[modind]) marray[nm++] = fModules[modind];
633 fNumberOfModules = fModIndRead = nm;
639 //______________________________________________________________________________
640 Bool_t AliITSHandleDaSSD::AddFeromCm(AliITSModuleDaSSD *const module)
641 // Restore the original signal value adding CM calculated and subtracted in ferom
643 AliITSChannelDaSSD *strip;
644 Short_t *signal, *cmferom;
646 if (!module) return kFALSE;
647 for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
648 if (!(cmferom = module->GetCMFerom(chipind))) {
649 AliWarning(Form("AliITSHandleDaSSD: There is no Ferom CM values for chip %i, module %i!", chipind, module->GetModuleId()));
652 for (Int_t strind = (chipind * AliITSModuleDaSSD::GetStripsPerChip());
653 strind < ((chipind + 1) * AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
654 if (!(strip = module->GetStrip(strind))) continue;
655 if (!(signal = strip->GetSignal())) continue;
656 // if (strip->GetEventsNumber() != module->GetEventsNumber()) return kFALSE;
658 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
659 if (SignalOutOfRange(signal[ev]) || SignalOutOfRange(cmferom[ev])) ovev += 1;
661 Short_t signal1 = signal[ev] + cmferom[ev];
662 strip->SetSignal(ev, signal1);
672 //______________________________________________________________________________
673 Bool_t AliITSHandleDaSSD::CalculatePedestal(AliITSModuleDaSSD *const module)
675 // Calculates Pedestal
676 AliITSChannelDaSSD *strip;
677 Float_t pedestal, noise;
680 if (!module) return kFALSE;
681 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
682 if (!(strip = module->GetStrip(strind))) continue;
683 if (!(signal = strip->GetSignal())) {
684 AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
685 module->GetModuleId(), strind));
688 //************* pedestal first pass ****************
691 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
692 if (SignalOutOfRange(signal[ev])) ovev += 1;
693 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
694 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
695 strip->SetPedestal(pedestal);
696 //************* noise *******************************
697 Double_t nsum = 0.0L;
699 for (ev = 0; ev < strip->GetEventsNumber(); ev++) {
700 if (SignalOutOfRange(signal[ev])) ovev += 1;
701 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
703 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
704 else noise = AliITSChannelDaSSD::GetUndefinedValue();
705 strip->SetNoise(noise);
706 //************* pedestal second pass ****************
709 for (ev = 0; ev < strip->GetEventsNumber(); ev++)
710 if ( SignalOutOfRange(signal[ev])
711 || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
712 else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
713 if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
714 strip->SetPedestal(pedestal);
715 strip->SetOverflowNumber(ovev);
721 //______________________________________________________________________________
722 Bool_t AliITSHandleDaSSD::CalculateNoise(AliITSModuleDaSSD *const module)
725 AliITSChannelDaSSD *strip;
729 if (!module) return kFALSE;
730 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
731 if (!(strip = module->GetStrip(strind))) continue;
732 if (!(signal = strip->GetSignal())) {
733 strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
734 AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()",
735 module->GetModuleId(), strind));
738 Double_t nsum = 0.0L;
740 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
741 if (SignalOutOfRange(signal[ev])) ovev += 1;
742 else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
744 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
745 else noise = AliITSChannelDaSSD::GetUndefinedValue();
746 strip->SetNoise(noise);
753 //______________________________________________________________________________
754 Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module)
756 // Calculates Noise with CM correction
757 AliITSChannelDaSSD *strip = NULL;
761 if (!CalculateCM(module)) {
762 AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE");
765 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
766 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
767 if (!(signal = strip->GetSignal())) {
768 strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
769 AliError(Form("SSDDAModule: Error CalculateNoiseWithoutCM(): there are no events data for module[%i] strip[%i]->GetSignal()",
770 module->GetModuleId(), strind));
771 continue; //return kFALSE;
773 Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
774 Double_t nsum = 0.0L;
776 for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
777 if (SignalOutOfRange(signal[ev])) ovev += 1;
778 else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
780 if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = sqrt(nsum / (Float_t)(n));
781 else noise = AliITSChannelDaSSD::GetUndefinedValue();
782 strip->SetNoiseCM(noise);
789 //______________________________________________________________________________
790 Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module)
793 AliITSChannelDaSSD *strip = NULL;
797 module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
798 for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
799 stripind = chipind * module->GetStripsPerChip();
800 module->GetCM()[chipind].Set(fNumberOfEvents);
801 module->GetCM()[chipind].Reset(0.0f);
802 for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
803 // calculate firs approximation of CM.
806 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
807 if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
808 if (!(signal = strip->GetSignal())) {
809 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()",
810 module->GetModuleId(), strind));
813 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
814 else cm0 += (signal[ev] - strip->GetPedestal());
816 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n);
817 else { module->SetCM(0.0f, chipind, ev); continue; }
818 // calculate avarage (cm - (signal - pedestal)) over the chip
819 Double_t cmsigma = 0.0L;
821 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
822 if (!(strip = module->GetStrip(strind))) continue;
823 if (!(signal = strip->GetSignal())) {
824 AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n",
825 module->GetModuleId(), strind));
828 if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
829 else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2);
831 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = sqrt(cmsigma / (Float_t)(n));
832 else { module->SetCM(0.0f, chipind, ev); continue; }
833 // calculate cm with threshold
834 Double_t cmsum = 0.0L;
836 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
837 if (!(strip = module->GetStrip(strind))) continue;
838 signal = strip->GetSignal();
839 if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
840 || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
841 else cmsum += (signal[ev] - strip->GetPedestal());
843 if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n);
845 // if (!(module->SetCM(cmsum, chipind, ev)));
852 //______________________________________________________________________________
853 Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread)
855 // Performs calculation of calibration parameters (pedestal, noise, ...)
857 if (nmread <= 0) return kFALSE;
858 if (!fModules) return kFALSE;
859 while ((nm = ReadModuleRawData(nmread)) > 0) {
860 cout << "Processing next " << nm << " modules;" << endl;
861 for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) {
862 if (!fModules[modind]) {
863 AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n",
867 AddFeromCm(fModules[modind]);
868 CalculatePedestal(fModules[modind]);
869 CalculateNoise(fModules[modind]);
870 CalculateNoiseCM(fModules[modind]);
875 fModIndProcessed = fModIndRead;
876 cout << fModIndProcessed << " - done" << endl;
882 //______________________________________________________________________________
883 Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
885 // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class
886 if (!fDDLModuleMap) {
887 AliError("Error DDLMap is not initialized, return 0!");
890 Int_t mddli = ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
891 if ((ddlID < fgkNumberOfSSDDDLs) && (mddli < fgkNumberOfSSDModulesPerDdl)) {
892 mddli = fDDLModuleMap[ddlID * fgkNumberOfSSDModulesPerDdl + mddli];
895 AliWarning(Form("Module index = %d or ddlID = %d is out of range 0 is rturned", ddlID, mddli));
898 if (mddli > SHRT_MAX) return SHRT_MAX;
899 else return (Short_t)mddli;
904 //______________________________________________________________________________
905 AliITSNoiseSSDv2* AliITSHandleDaSSD::GetCalibrationOCDBNoise() const
907 // Fill in the array for OCDB
908 AliITSNoiseSSDv2 *ldcn = NULL;
909 AliITSModuleDaSSD *module = NULL;
910 AliITSChannelDaSSD *strip = NULL;
911 if (!fModules) return NULL;
912 ldcn = new AliITSNoiseSSDv2;
914 AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
917 for (Int_t i = 0; i < fNumberOfModules; i++) {
918 if (!(module = fModules[i])) continue;
919 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
920 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
921 if (!(strip = module->GetStrip(strind))) continue;
922 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
923 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() )
924 ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
926 ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
933 //______________________________________________________________________________
934 AliITSBadChannelsSSDv2* AliITSHandleDaSSD::GetCalibrationBadChannels() const
936 // Fill in the TObjArray with the list of bad channels
937 AliITSBadChannelsSSDv2 *ldcbc = NULL;
938 AliITSModuleDaSSD *module = NULL;
939 AliITSChannelDaSSD *strip = NULL;
940 if (!fModules) return NULL;
941 ldcbc = new AliITSBadChannelsSSDv2;
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 ldcbc->AddBadChannelP(modid, strip->GetStripId(), module->CheckIfBad(strip->GetStripId()));
955 ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()),
956 module->CheckIfBad(strip->GetStripId()));
964 //______________________________________________________________________________
965 Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname)
967 // Save Calibration data locally
968 AliITSBadChannelsSSDv2 *ldcbc = NULL;
969 AliITSPedestalSSDv2 *ldcp = NULL;
970 AliITSNoiseSSDv2 *ldcn = NULL;
971 AliITSModuleDaSSD *module = NULL;
972 AliITSChannelDaSSD *strip = NULL;
974 TString dadatafilename("");
975 if (!fModules) return kFALSE;
976 ldcn = new AliITSNoiseSSDv2;
977 ldcp = new AliITSPedestalSSDv2;
978 ldcbc = new AliITSBadChannelsSSDv2;
979 if ((!ldcn) || (!ldcp) || (!ldcp)) {
980 AliError("Error allocation mamory for calibration objects, return kFALSE!");
983 for (Int_t i = 0; i < fNumberOfModules; i++) {
984 if (!(module = fModules[i])) continue;
985 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
986 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
987 if (!(strip = module->GetStrip(strind))) continue;
988 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
989 if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) {
990 ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
991 ldcp->AddPedestalP(modid, strip->GetStripId(), strip->GetPedestal());
992 ldcbc->AddBadChannelP(modid, strip->GetStripId(), module->CheckIfBad(strip->GetStripId()));
994 ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
995 ldcp->AddPedestalN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetPedestal());
996 ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()),
997 module->CheckIfBad(strip->GetStripId()));
1001 if (dafname) dadatafilename.Form("%s/", dafname);
1002 dadatafilename += TString::Format("ITSSSDda_%i.root", fLdcId);
1003 tmpfname = new Char_t[dadatafilename.Length()+1];
1004 dafname = strcpy(tmpfname, dadatafilename.Data());
1005 TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE");
1006 if (fileRun->IsZombie()) {
1007 AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data()));
1015 fileRun->WriteTObject(ldcn);
1016 fileRun->WriteTObject(ldcp);
1017 if (fBadChannelsList)
1018 if (fMergeBCLists) {
1019 MergeBadChannels(ldcbc);
1020 fileRun->WriteTObject(ldcbc);
1021 } else fileRun->WriteTObject(fBadChannelsList);
1022 else fileRun->WriteTObject(ldcbc);
1032 //______________________________________________________________________________
1033 Int_t AliITSHandleDaSSD::MergeBadChannels(AliITSBadChannelsSSDv2*& bcl) const
1035 // Merges the statick bad channels list with bad channels got upon calibration
1036 AliITSModuleDaSSD *module = 0;
1037 Int_t nmpch = 0, nmnch = 0, ngpch = 0, ngnch = 0;
1038 if (!fBadChannelsList || !bcl) {
1039 AliWarning("Either fBadChannelsList == NULL or bad_channels_list == NULL, there is nothing to merge!");
1042 for (Int_t modind = 0; modind < GetNumberOfModules(); modind++) {
1043 if (!(module = fModules[modind])) continue;
1044 if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1045 Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1046 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetPNStripsPerModule(); strind++) {
1047 if ( (!(fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask))
1048 && (bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask) )
1050 if ( (!(fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask))
1051 && (bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask) )
1053 if ( (!(bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask))
1054 && (fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) {
1055 bcl->AddBadChannelP(modid, strind, fBadChannelsList->GetBadChannelP(modid, strind));
1058 if ( (!(bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask))
1059 && (fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) {
1060 bcl->AddBadChannelN(modid, strind, fBadChannelsList->GetBadChannelN(modid, strind));
1065 AliInfo(Form("Static bad, dynamic good: P%d, N%d", nmpch, nmnch));
1066 AliInfo(Form("Static good, dynamic bad: P%d, N%d", ngpch, ngnch));
1067 return (nmnch + nmpch);
1072 //______________________________________________________________________________
1073 Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
1075 // Dump calibration parameters
1076 AliITSModuleDaSSD *mod;
1077 AliITSChannelDaSSD *strip;
1079 cout << "SSDDALDC::DumpModInfo(): Error, no modules are allocated!" << endl;
1082 cout << "Modules with MeanNoise > " << meannosethreshold << endl;
1083 for (Int_t i = 0; i < fNumberOfModules; i++) {
1084 if (!(mod = fModules[i])) continue;
1085 Float_t maxnoise = 0.0f, meannoise = 0.0f, maxped = 0.0f;
1086 Int_t maxstrind = 0, novfstr = 0;
1087 for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
1088 if (!(strip = mod->GetStrip(strind))) {novfstr++; continue; }
1089 if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++; continue; }
1090 if (maxnoise < strip->GetNoiseCM()) {
1091 maxnoise = strip->GetNoiseCM();
1094 meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Float_t>(strind - novfstr + 1)
1095 : strip->GetNoiseCM();
1096 if (TMath::Abs(maxped) < TMath::Abs(strip->GetPedestal())) maxped = strip->GetPedestal();
1098 if (meannoise > meannosethreshold)
1099 cout << "Mod: " << i << "; DDl: " << (int)mod->GetDdlId() << "; AD: " << (int)mod->GetAD()
1100 << "; ADC: " << (int)mod->GetADC() << "; MaxPed = " << maxped
1101 << "; MeanNoise = " << meannoise
1102 << "; NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
1109 //______________________________________________________________________________
1110 Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
1112 // Print Module calibration data whether in file on in cout
1113 AliITSChannelDaSSD *strip;
1115 ostream *outputfile;
1116 if (!fname) { outputfile = &cout; }
1118 datafile.open(fname, ios::out);
1119 if (datafile.fail()) return kFALSE;
1120 outputfile = dynamic_cast<ostream*>(&datafile);
1122 *outputfile << "DDL = " << (int)ddlID << "; AD = " << (int)ad << "; ADC = " << (int)adc << endl;
1123 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1124 if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) {
1125 *outputfile << "Str = " << strind << "; ped = " << strip->GetPedestal()
1126 << "; noise = " << strip->GetNoiseCM() << endl;
1130 if (datafile.is_open()) datafile.close();
1136 //______________________________________________________________________________
1137 void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
1139 // Print general information retrieved from raw data file
1140 cout << "Raw data file: " << fRawDataFileName << endl
1141 << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
1142 << "Number of physics events: " << fNumberOfEvents << endl
1147 //______________________________________________________________________________
1148 Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
1150 // Used to allocate simulated modules to test the performance
1151 AliITSModuleDaSSD *module;
1152 UChar_t ad, adc, ddlID;
1153 ad = adc = ddlID = 0;
1154 if (!(fModules[copymodind])) return kFALSE;
1155 for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
1156 if (!fModules[modind]) {
1157 module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
1158 if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
1159 else if (adc == 5) adc = 8;
1160 else if (adc == 13) {
1162 if (ad < 8) ad += 1;
1168 if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
1169 fModules[modind] = module;
1170 for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1171 AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
1172 Long_t eventsnumber = cstrip->GetEventsNumber();
1173 AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
1174 for (Long_t evind = 0; evind < eventsnumber; evind++) {
1175 Short_t sign = cstrip->GetSignal(evind);
1176 if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
1178 module->SetStrip(strip, strind);
1182 ddlID = fModules[modind]->GetDdlId();
1183 ad = fModules[modind]->GetAD();
1184 adc = fModules[modind]->GetADC();
1187 for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);
1193 //___________________________________________________________________________________________
1194 Bool_t AliITSHandleDaSSD::AdDataPresent(const Int_t ddl, const Int_t ad) const
1196 // Check if there are calibration data for given ddl and slot
1197 for (Int_t modind = 0; modind < fNumberOfModules; modind++)
1198 if ((GetModule(modind)->GetAD() == ad) && (GetModule(modind)->GetDdlId() == ddl)) return kTRUE;
1204 //___________________________________________________________________________________________
1205 Bool_t AliITSHandleDaSSD::SaveEqSlotCalibrationData(const Int_t ddl, const Int_t ad, const Char_t *fname) const
1206 // Saves calibration files for selected equipment (DDL)
1209 Int_t zsml, offsetml;
1210 ULong_t zsth, offset, zsoffset;
1212 AliError("File name must be specified!");
1215 if (!AdDataPresent(ddl, ad)) {
1216 AliError(Form("Error SaveEqSlotCalibrationData(ddl = %i, ad = %i) no data present", ddl, ad));
1219 feefile.open(fname, ios::out);
1220 if (!feefile.is_open()) {
1221 AliError(Form("Can not open the file %s for output!", fname));
1224 for (zsml = 0; fgkZsBitMask >> zsml; zsml++) ;
1225 for (offsetml = 0; fgkOffSetBitMask >> offsetml; offsetml++) ;
1226 for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1227 for (Int_t adcb = 0; adcb < fgkAdcPerDBlock; adcb++) {
1229 for (Int_t j = 0; j < 2; j++) {
1230 Int_t adc = adcb + j * 8;
1231 zsth = ZsThreshold(ddl, ad, adc, strind);
1232 offset = OffsetValue(ddl, ad, adc, strind);
1233 zsoffset = zsoffset | (((zsth << offsetml) | offset) << ((j == 0) ? (offsetml + zsml) : 0));
1235 feefile << "0x" << ConvBase(static_cast<unsigned long>(zsoffset), 16) << endl;
1243 //______________________________________________________________________________
1244 Int_t AliITSHandleDaSSD::ChannelIsBad(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1246 // Check if the channel is bad
1247 AliITSModuleDaSSD *module = NULL;
1249 if (fBadChannelsList && fDDLModuleMap) {
1250 modn = RetrieveModuleId(ddl, ad, adc);
1251 if (modn < 0) return -1;
1252 if (modn < fgkMinSSDModuleId) {
1253 AliWarning(Form("Module ddl/ad/adc: %i/%i/%i has number %i which is wrong for SSD module", ddl, ad, adc, strn, modn));
1256 Short_t modid = modn - fgkMinSSDModuleId;
1257 if (strn < AliITSModuleDaSSD::GetPNStripsPerModule())
1258 return (fBadChannelsList->GetBadChannelP(modid, strn) & fgkBadChannelMask);
1259 else return (fBadChannelsList->GetBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strn)) & fgkBadChannelMask);
1261 AliError("Error ether bad channels list or DDLMap is not initialized or both, AliITSModuleDaSSD::CheckIfBad(str) is used!");
1262 if ((module = GetModule(ddl, ad, adc))) {
1263 return (module->CheckIfBad(strn) & fgkBadChannelMask);
1265 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1274 //______________________________________________________________________________
1275 Int_t AliITSHandleDaSSD::LadderIsOff(const UChar_t ddl, const UChar_t ad, const UChar_t adc) const
1277 //Checks if the module with given ddl, ad, adc is on the ladder which is in the list of ladders which are off
1278 const Int_t nm5 = 500;
1279 const Int_t nm6 = 1248;
1280 const Int_t nml5a = 12;
1281 const Int_t nml5c = 10;
1282 const Int_t nml6a = 12;
1283 const Int_t nml6c = 13;
1284 Int_t modn, ladder, layer, side;
1285 AliITSModuleDaSSD *module;
1286 if (!(module = GetModule(ddl, ad, adc))) return 0;
1287 if ((modn = module->GetModuleId()) <= 0) modn = RetrieveModuleId(ddl, ad, adc);
1288 if (modn <= 0) return 0;
1289 layer = modn >= nm6 ? 1 : 0; // 6 : 5
1290 ladder = (modn - (layer ? nm6 : nm5)) / (layer ? (nml6a + nml6c) : (nml5a + nml5c));
1291 if ( ((modn - (layer ? nm6 : nm5)) % (layer ? (nml6a + nml6c) : (nml5a + nml5c))) < (layer ? nml6a : nml5a))
1294 ladder += (layer ? 600 : 500);
1297 if (fCLaddersOff.GetSize()) {
1298 for(Int_t i = 0; i < fCLaddersOff.GetSize(); i++)
1299 if (fCLaddersOff.At(i) == ladder) return fCLaddersOff.At(i);
1303 if (fALaddersOff.GetSize()) {
1304 for(Int_t i = 0; i < fALaddersOff.GetSize(); i++)
1305 if (fALaddersOff.At(i) == ladder) return fALaddersOff.At(i);
1313 //______________________________________________________________________________
1314 ULong_t AliITSHandleDaSSD::OffsetValue(const AliITSChannelDaSSD *strip,
1315 const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1317 // Calculate the offset value to be upload to FEROM
1319 if (fOffsetDefault < INT_MAX) pedint = fOffsetDefault;
1320 else pedint = TMath::Nint(strip->GetPedestal());
1321 if (pedint > static_cast<Int_t>((fgkOffSetBitMask >> 1))) {
1322 if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (GetModule(ddl, ad, adc)->CheckIfBad(strn))))
1323 AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
1324 pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), (fgkOffSetBitMask >> 1)));
1325 return (fgkOffSetBitMask >> 1);
1327 if ((-pedint) > static_cast<Int_t>(((fgkOffSetBitMask + 1) >> 1))) {
1328 if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (GetModule(ddl, ad, adc)->CheckIfBad(strn))))
1329 AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
1330 pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(),
1331 ((fgkOffSetBitMask & (~fgkOffSetBitMask >> 1)) - fgkOffSetBitMask - 1)));
1332 return fgkOffSetBitMask & (~fgkOffSetBitMask >> 1);
1334 return fgkOffSetBitMask & (pedint >= 0 ? pedint : pedint + fgkOffSetBitMask + 1);
1339 //______________________________________________________________________________
1340 ULong_t AliITSHandleDaSSD::OffsetValue(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1342 // Calculate the offset value to be upload to FEROM
1343 AliITSChannelDaSSD *strip = NULL;
1344 AliITSModuleDaSSD *module = NULL;
1345 if ((module = GetModule(ddl, ad, adc))) {
1346 if ((strip = module->GetStrip(strn))) return OffsetValue(strip, ddl, ad, adc, strn);
1348 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
1352 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1359 //______________________________________________________________________________
1360 ULong_t AliITSHandleDaSSD::ZsThreshold(AliITSChannelDaSSD *strip) const
1362 // Calculate the value of zero suppression threshold to be upload to FEROM
1364 if (fZsDefault < 0) {
1365 zs = TMath::Nint(fZsFactor * strip->GetNoiseCM());
1366 if (zs < static_cast<ULong_t>(fZsMinimum)) zs = static_cast<ULong_t>(fZsMinimum);
1368 else zs = fZsDefault;
1369 return (zs < fgkZsBitMask) ? (zs & fgkZsBitMask) : fgkZsBitMask;
1373 //______________________________________________________________________________
1374 ULong_t AliITSHandleDaSSD::ZsThreshold(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1376 // Calculate the value of zero suppression threshold to be upload to FEROM, account bad channels list
1377 AliITSChannelDaSSD *strip = NULL;
1378 AliITSModuleDaSSD *module = NULL;
1379 if (ChannelIsBad(ddl, ad, adc, strn)) return fgkZsBitMask;
1380 if (LadderIsOff(ddl, ad, adc)) return fgkZsBitMask;
1381 if ((module = GetModule(ddl, ad, adc))) {
1382 if (fMergeBCLists) if (module->CheckIfBad(strn)) return fgkZsBitMask;
1383 if ((strip = module->GetStrip(strn))) return ZsThreshold(strip);
1385 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
1389 AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
1395 //______________________________________________________________________________
1396 string AliITSHandleDaSSD::ConvBase(const unsigned long value, const long base) const
1398 // Converts the unsigned long number into that in another base
1399 string digits = "0123456789ABCDEF";
1401 unsigned long v = value;
1402 if((base < 2) || (base > 16)) {
1403 result = "Error: base out of range.";
1408 result = digits[v % base] + result;
1412 while((v) || (i<8));
1419 //______________________________________________________________________________
1420 Int_t AliITSHandleDaSSD::CheckOffChips() const
1422 // Check if the chip, module are off
1423 AliITSChannelDaSSD *strip;
1425 Int_t strnd, chipnd, modnd, stroff, chipoff, modoff;
1426 offthreshold = TMath::Nint(fZsMinimum/fZsFactor);
1428 for (Int_t mi = 0; mi < fNumberOfModules; mi++) {
1429 if (!fModules[mi]) { modnd++; continue; }
1430 if (fModules[mi]->GetModuleId() < 0) continue;
1431 if (LadderIsOff(fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()) ) continue;
1432 chipoff = chipnd = 0;
1433 for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
1435 Int_t stripind = chipind * AliITSModuleDaSSD::GetStripsPerChip();
1436 for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1437 if (!(strip = fModules[mi]->GetStrip(strind))) { strnd++; continue; }
1438 if (strip->GetNoiseCM() < offthreshold ) stroff++;
1440 if (strnd == AliITSModuleDaSSD::GetStripsPerChip()) chipnd++;
1441 else if (stroff == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1442 else if ((stroff + strnd) == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1444 if ((!chipoff) && (!chipnd)) continue;
1445 if (chipnd == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1446 AliInfo(Form("Module: (ddl/ad/adc) %i/%i/%i seems to be off and it is not on the ladders which are off!",
1447 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1450 if (chipoff == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1451 AliInfo(Form("Module (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
1452 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1455 else if ((chipoff + chipnd) == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1456 AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
1457 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1461 AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i has %i chips which are off!",
1462 fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC(), chipoff));
1466 return (modoff + modnd);