+
+
+//______________________________________________________________________________
+Int_t AliITSHandleDaSSD::MergeBadChannels(AliITSBadChannelsSSDv2*& bcl) const
+{
+// Merges the statick bad channels list with bad channels got upon calibration
+ AliITSModuleDaSSD *module = 0;
+ Int_t nmpch = 0, nmnch = 0, ngpch = 0, ngnch = 0;
+ if (!fBadChannelsList || !bcl) {
+ AliWarning("Either fBadChannelsList == NULL or bad_channels_list == NULL, there is nothing to merge!");
+ return -1;
+ }
+ for (Int_t modind = 0; modind < GetNumberOfModules(); modind++) {
+ if (!(module = fModules[modind])) continue;
+ if (module->GetModuleId() < fgkMinSSDModuleId) continue;
+ Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
+ for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetPNStripsPerModule(); strind++) {
+ if ( (!(fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask))
+ && (bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask) )
+ ngpch++;
+ if ( (!(fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask))
+ && (bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask) )
+ ngnch++;
+ if ( (!(bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask))
+ && (fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) {
+ bcl->AddBadChannelP(modid, strind, fBadChannelsList->GetBadChannelP(modid, strind));
+ nmpch++;
+ }
+ if ( (!(bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask))
+ && (fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) {
+ bcl->AddBadChannelN(modid, strind, fBadChannelsList->GetBadChannelN(modid, strind));
+ nmnch++;
+ }
+ }
+ }
+ AliInfo(Form("Static bad, dynamic good: P%d, N%d", nmpch, nmnch));
+ AliInfo(Form("Static good, dynamic bad: P%d, N%d", ngpch, ngnch));
+ return (nmnch + nmpch);
+}
+
+
+
+//______________________________________________________________________________
+Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
+{
+// Dump calibration parameters
+ AliITSModuleDaSSD *mod;
+ AliITSChannelDaSSD *strip;
+ if (!fModules) {
+ cout << "SSDDALDC::DumpModInfo(): Error, no modules are allocated!" << endl;
+ return kFALSE;
+ }
+ cout << "Modules with MeanNoise > " << meannosethreshold << endl;
+ for (Int_t i = 0; i < fNumberOfModules; i++) {
+ if (!(mod = fModules[i])) continue;
+ Float_t maxnoise = 0.0f, meannoise = 0.0f, maxped = 0.0f;
+ Int_t maxstrind = 0, novfstr = 0;
+ for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
+ if (!(strip = mod->GetStrip(strind))) {novfstr++; continue; }
+ if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++; continue; }
+ if (maxnoise < strip->GetNoiseCM()) {
+ maxnoise = strip->GetNoiseCM();
+ maxstrind = strind;
+ }
+ meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Float_t>(strind - novfstr + 1)
+ : strip->GetNoiseCM();
+ if (TMath::Abs(maxped) < TMath::Abs(strip->GetPedestal())) maxped = strip->GetPedestal();
+ }
+ if (meannoise > meannosethreshold)
+ cout << "Mod: " << i << "; DDl: " << (int)mod->GetDdlId() << "; AD: " << (int)mod->GetAD()
+ << "; ADC: " << (int)mod->GetADC() << "; MaxPed = " << maxped
+ << "; MeanNoise = " << meannoise
+ << "; NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
+ }
+ return kTRUE;
+}
+
+
+
+//______________________________________________________________________________
+Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
+{
+// Print Module calibration data whether in file on in cout
+ AliITSChannelDaSSD *strip;
+ ofstream datafile;
+ ostream *outputfile;
+ if (!fname) { outputfile = &cout; }
+ else {
+ datafile.open(fname, ios::out);
+ if (datafile.fail()) return kFALSE;
+ outputfile = dynamic_cast<ostream*>(&datafile);
+ }
+ *outputfile << "DDL = " << (int)ddlID << "; AD = " << (int)ad << "; ADC = " << (int)adc << endl;
+ for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
+ if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) {
+ *outputfile << "Str = " << strind << "; ped = " << strip->GetPedestal()
+ << "; noise = " << strip->GetNoiseCM() << endl;
+ }
+ else continue;
+ }
+ if (datafile.is_open()) datafile.close();
+ return kTRUE;
+}
+
+
+
+//______________________________________________________________________________
+void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
+{
+// Print general information retrieved from raw data file
+ cout << "Raw data file: " << fRawDataFileName << endl
+ << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
+ << "Number of physics events: " << fNumberOfEvents << endl
+ << str;
+}
+
+
+//______________________________________________________________________________
+Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
+{
+// Used to allocate simulated modules to test the performance
+ AliITSModuleDaSSD *module;
+ UChar_t ad, adc, ddlID;
+ ad = adc = ddlID = 0;
+ if (!(fModules[copymodind])) return kFALSE;
+ for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
+ if (!fModules[modind]) {
+ module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
+ if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
+ else if (adc == 5) adc = 8;
+ else if (adc == 13) {
+ adc = 0;
+ if (ad < 8) ad += 1;
+ else {
+ ad = 0;
+ ddlID +=1;
+ }
+ }
+ if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
+ fModules[modind] = module;
+ for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
+ AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
+ Long_t eventsnumber = cstrip->GetEventsNumber();
+ AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
+ for (Long_t evind = 0; evind < eventsnumber; evind++) {
+ Short_t sign = cstrip->GetSignal(evind);
+ if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
+ }
+ module->SetStrip(strip, strind);
+ }
+ }
+ else {
+ ddlID = fModules[modind]->GetDdlId();
+ ad = fModules[modind]->GetAD();
+ adc = fModules[modind]->GetADC();
+ }
+ }
+ for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);
+ return kTRUE;
+}
+
+
+
+//___________________________________________________________________________________________
+Bool_t AliITSHandleDaSSD::AdDataPresent(const Int_t ddl, const Int_t ad) const
+{
+// Check if there are calibration data for given ddl and slot
+ for (Int_t modind = 0; modind < fNumberOfModules; modind++)
+ if ((GetModule(modind)->GetAD() == ad) && (GetModule(modind)->GetDdlId() == ddl)) return kTRUE;
+ return kFALSE;
+}
+
+
+
+//___________________________________________________________________________________________
+Bool_t AliITSHandleDaSSD::SaveEqSlotCalibrationData(const Int_t ddl, const Int_t ad, const Char_t *fname) const
+// Saves calibration files for selected equipment (DDL)
+{
+ fstream feefile;
+ Int_t zsml, offsetml;
+ ULong_t zsth, offset, zsoffset;
+ if (!fname) {
+ AliError("File name must be specified!");
+ return kFALSE;
+ }
+ if (!AdDataPresent(ddl, ad)) {
+ AliError(Form("Error SaveEqSlotCalibrationData(ddl = %i, ad = %i) no data present", ddl, ad));
+ return kFALSE;
+ }
+ feefile.open(fname, ios::out);
+ if (!feefile.is_open()) {
+ AliError(Form("Can not open the file %s for output!", fname));
+ return kFALSE;
+ }
+ for (zsml = 0; fgkZsBitMask >> zsml; zsml++) ;
+ for (offsetml = 0; fgkOffSetBitMask >> offsetml; offsetml++) ;
+ for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
+ for (Int_t adcb = 0; adcb < fgkAdcPerDBlock; adcb++) {
+ zsoffset = 0x0;
+ for (Int_t j = 0; j < 2; j++) {
+ Int_t adc = adcb + j * 8;
+ zsth = ZsThreshold(ddl, ad, adc, strind);
+ offset = OffsetValue(ddl, ad, adc, strind);
+ zsoffset = zsoffset | (((zsth << offsetml) | offset) << ((j == 0) ? (offsetml + zsml) : 0));
+ }
+ feefile << "0x" << ConvBase(static_cast<unsigned long>(zsoffset), 16) << endl;
+ }
+ }
+ feefile.close();
+ return kTRUE;
+}
+
+
+//______________________________________________________________________________
+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);
+}