+
+
+//______________________________________________________________________________
+Int_t AliITSHandleDaSSD::ChannelIsBad(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
+{
+// Check if the channel is bad
+ AliITSModuleDaSSD *module = NULL;
+ Int_t modn = -1;
+ if (fBadChannelsList && fDDLModuleMap) {
+ modn = RetrieveModuleId(ddl, ad, adc);
+ if (modn < 0) return -1;
+ if (modn < fgkMinSSDModuleId) {
+ AliWarning(Form("Module ddl/ad/adc: %i/%i/%i has number %i which is wrong for SSD module", ddl, ad, adc, strn, modn));
+ return -1;
+ }
+ Short_t modid = modn - fgkMinSSDModuleId;
+ if (strn < AliITSModuleDaSSD::GetPNStripsPerModule())
+ return (fBadChannelsList->GetBadChannelP(modid, strn) & fgkBadChannelMask);
+ else return (fBadChannelsList->GetBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strn)) & fgkBadChannelMask);
+ } else {
+ AliError("Error ether bad channels list or DDLMap is not initialized or both, AliITSModuleDaSSD::CheckIfBad(str) is used!");
+ if ((module = GetModule(ddl, ad, adc))) {
+ return (module->CheckIfBad(strn) & fgkBadChannelMask);
+ } else {
+ AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
+ return 0ul;
+ }
+ return 0;
+ }
+}
+
+
+
+//______________________________________________________________________________
+Int_t AliITSHandleDaSSD::LadderIsOff(const UChar_t ddl, const UChar_t ad, const UChar_t adc) const
+{
+//Checks if the module with given ddl, ad, adc is on the ladder which is in the list of ladders which are off
+ const Int_t nm5 = 500;
+ const Int_t nm6 = 1248;
+ const Int_t nml5a = 12;
+ const Int_t nml5c = 10;
+ const Int_t nml6a = 12;
+ const Int_t nml6c = 13;
+ Int_t modn, ladder, layer, side;
+ AliITSModuleDaSSD *module;
+ if (!(module = GetModule(ddl, ad, adc))) return 0;
+ if ((modn = module->GetModuleId()) <= 0) modn = RetrieveModuleId(ddl, ad, adc);
+ if (modn <= 0) return 0;
+ layer = modn >= nm6 ? 1 : 0; // 6 : 5
+ ladder = (modn - (layer ? nm6 : nm5)) / (layer ? (nml6a + nml6c) : (nml5a + nml5c));
+ if ( ((modn - (layer ? nm6 : nm5)) % (layer ? (nml6a + nml6c) : (nml5a + nml5c))) < (layer ? nml6a : nml5a))
+ side = 0; // A
+ else side = 1; // C
+ ladder += (layer ? 600 : 500);
+ layer += 5;
+ if (side)
+ if (fCLaddersOff.GetSize()) {
+ for(Int_t i = 0; i < fCLaddersOff.GetSize(); i++)
+ if (fCLaddersOff.At(i) == ladder) return fCLaddersOff.At(i);
+ return 0;
+ } else return 0;
+ else
+ if (fALaddersOff.GetSize()) {
+ for(Int_t i = 0; i < fALaddersOff.GetSize(); i++)
+ if (fALaddersOff.At(i) == ladder) return fALaddersOff.At(i);
+ return 0;
+ } else return 0;
+ return 0;
+}
+
+
+
+//______________________________________________________________________________
+ULong_t AliITSHandleDaSSD::OffsetValue(const AliITSChannelDaSSD *strip,
+ const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
+{
+// Calculate the offset value to be upload to FEROM
+ Int_t pedint;
+ if (fOffsetDefault < INT_MAX) pedint = fOffsetDefault;
+ else pedint = TMath::Nint(strip->GetPedestal());
+ if (pedint > static_cast<Int_t>((fgkOffSetBitMask >> 1))) {
+ if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (GetModule(ddl, ad, adc)->CheckIfBad(strn))))
+ AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
+ pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), (fgkOffSetBitMask >> 1)));
+ return (fgkOffSetBitMask >> 1);
+ }
+ if ((-pedint) > static_cast<Int_t>(((fgkOffSetBitMask + 1) >> 1))) {
+ if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (GetModule(ddl, ad, adc)->CheckIfBad(strn))))
+ AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i can not be represented with mask 0x%s, Offset = %i",
+ pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(),
+ ((fgkOffSetBitMask & (~fgkOffSetBitMask >> 1)) - fgkOffSetBitMask - 1)));
+ return fgkOffSetBitMask & (~fgkOffSetBitMask >> 1);
+ }
+ return fgkOffSetBitMask & (pedint >= 0 ? pedint : pedint + fgkOffSetBitMask + 1);
+}
+
+
+
+//______________________________________________________________________________
+ULong_t AliITSHandleDaSSD::OffsetValue(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
+{
+// Calculate the offset value to be upload to FEROM
+ AliITSChannelDaSSD *strip = NULL;
+ AliITSModuleDaSSD *module = NULL;
+ if ((module = GetModule(ddl, ad, adc))) {
+ if ((strip = module->GetStrip(strn))) return OffsetValue(strip, ddl, ad, adc, strn);
+ else {
+ AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
+ return 0ul;
+ }
+ } else {
+ AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
+ return 0ul;
+ }
+}
+
+
+
+//______________________________________________________________________________
+ULong_t AliITSHandleDaSSD::ZsThreshold(AliITSChannelDaSSD *strip) const
+{
+// Calculate the value of zero suppression threshold to be upload to FEROM
+ ULong_t zs;
+ if (fZsDefault < 0) {
+ zs = TMath::Nint(fZsFactor * strip->GetNoiseCM());
+ if (zs < static_cast<ULong_t>(fZsMinimum)) zs = static_cast<ULong_t>(fZsMinimum);
+ }
+ else zs = fZsDefault;
+ return (zs < fgkZsBitMask) ? (zs & fgkZsBitMask) : fgkZsBitMask;
+}
+
+
+//______________________________________________________________________________
+ULong_t AliITSHandleDaSSD::ZsThreshold(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
+{
+// Calculate the value of zero suppression threshold to be upload to FEROM, account bad channels list
+ AliITSChannelDaSSD *strip = NULL;
+ AliITSModuleDaSSD *module = NULL;
+ if (ChannelIsBad(ddl, ad, adc, strn)) return fgkZsBitMask;
+ if (LadderIsOff(ddl, ad, adc)) return fgkZsBitMask;
+ if ((module = GetModule(ddl, ad, adc))) {
+ if (fMergeBCLists) if (module->CheckIfBad(strn)) return fgkZsBitMask;
+ if ((strip = module->GetStrip(strn))) return ZsThreshold(strip);
+ else {
+ AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, strip = %i, 0 is used!", ddl, ad, adc, strn));
+ return 0ul;
+ }
+ } else {
+ AliWarning(Form("There is no calibration data for ddl = %i, ad = %i, adc = %i, 0 is used!", ddl, ad, adc));
+ return 0ul;
+ }
+}
+
+
+//______________________________________________________________________________
+string AliITSHandleDaSSD::ConvBase(const unsigned long value, const long base) const
+{
+// Converts the unsigned long number into that in another base
+ string digits = "0123456789ABCDEF";
+ string result;
+ unsigned long v = value;
+ if((base < 2) || (base > 16)) {
+ result = "Error: base out of range.";
+ }
+ else {
+ int i = 0;
+ do {
+ result = digits[v % base] + result;
+ v /= base;
+ i++;
+ }
+ while((v) || (i<8));
+ }
+ return result;
+}
+
+
+
+//______________________________________________________________________________
+Int_t AliITSHandleDaSSD::CheckOffChips() const
+{
+// Check if the chip, module are off
+ AliITSChannelDaSSD *strip;
+ Int_t offthreshold;
+ Int_t strnd, chipnd, modnd, stroff, chipoff, modoff;
+ offthreshold = TMath::Nint(fZsMinimum/fZsFactor);
+ modnd = modoff = 0;
+ for (Int_t mi = 0; mi < fNumberOfModules; mi++) {
+ if (!fModules[mi]) { modnd++; continue; }
+ if (fModules[mi]->GetModuleId() < 0) continue;
+ if (LadderIsOff(fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()) ) continue;
+ chipoff = chipnd = 0;
+ for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
+ strnd = stroff = 0;
+ Int_t stripind = chipind * AliITSModuleDaSSD::GetStripsPerChip();
+ for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
+ if (!(strip = fModules[mi]->GetStrip(strind))) { strnd++; continue; }
+ if (strip->GetNoiseCM() < offthreshold ) stroff++;
+ }
+ if (strnd == AliITSModuleDaSSD::GetStripsPerChip()) chipnd++;
+ else if (stroff == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
+ else if ((stroff + strnd) == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
+ }
+ if ((!chipoff) && (!chipnd)) continue;
+ if (chipnd == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
+ AliInfo(Form("Module: (ddl/ad/adc) %i/%i/%i seems to be off and it is not on the ladders which are off!",
+ fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
+ modnd++;
+ }
+ if (chipoff == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
+ AliInfo(Form("Module (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
+ fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
+ modoff++;
+ }
+ else if ((chipoff + chipnd) == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
+ AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!",
+ fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
+ modoff++;
+ }
+ else if (chipoff) {
+ AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i has %i chips which are off!",
+ fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC(), chipoff));
+ modoff++;
+ }
+ }
+ return (modoff + modnd);
+}