+
+
+
+//______________________________________________________________________________
+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);
+}
+
+
+//______________________________________________________________________________
+Bool_t AliITSHandleDaSSD::CalculatePedNoiseW(const AliITSModuleDaSSD *const module)
+{
+// Calculates Pedestal and Noise using Welford algorithm
+ AliITSChannelDaSSD *strip;
+ Double_t pedestal, noise, p0, s0;
+ Short_t *signal;
+ Int_t ovev, n;
+ if (!module) return kFALSE;
+ for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
+ if (!(strip = module->GetStrip(strind))) continue;
+ if (!(signal = strip->GetSignal())) {
+ AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
+ module->GetModuleId(), strind));
+ continue;
+ }
+//************* pedestal and noise first pass ****************
+ pedestal = p0 = noise = 0.0L;
+ ovev = 0;
+ for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
+ if (SignalOutOfRange(signal[ev])) ovev += 1;
+ else
+ if (!(ev - ovev)) {
+ pedestal = p0 = signal[ev];
+ noise = 0.0L;
+ } else {
+ p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
+ s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
+ pedestal = p0;
+ noise = s0;
+ }
+ }
+ if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
+ strip->SetPedestal(static_cast<Float_t>(pedestal));
+ if ((n = strip->GetEventsNumber() - ovev - 1) > 0)
+ strip->SetNoise( static_cast<Float_t>(TMath::Sqrt(noise / static_cast<Double_t>(n))) );
+ else {
+ strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
+ continue;
+ }
+//************* Second pass excluds event with |p - s|>f*noise *****************
+ pedestal = p0 = noise = 0.0L;
+ ovev = 0;
+ for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
+ if ( SignalOutOfRange(signal[ev])
+ || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
+ else
+ if (!(ev - ovev)) {
+ pedestal = p0 = signal[ev];
+ noise = 0.0L;
+ } else {
+ p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
+ s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
+ pedestal = p0;
+ noise = s0;
+ }
+ }
+ if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n));
+ else noise = AliITSChannelDaSSD::GetUndefinedValue();
+ strip->SetNoise(static_cast<Float_t>(noise));
+ if (strip->GetEventsNumber() == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
+ strip->SetPedestal(static_cast<Float_t>(pedestal));
+ strip->SetOverflowNumber(ovev);
+ }
+ return kTRUE;
+}
+
+
+//______________________________________________________________________________
+Bool_t AliITSHandleDaSSD::CalculateCMW(AliITSModuleDaSSD *const module)
+{
+// Calculates CM using Welford algorithm
+ AliITSChannelDaSSD *strip = NULL;
+ Short_t *signal;
+ Int_t ovstr, n;
+ Int_t stripind;
+ Double_t cm0, cm1, cmsigma, cms1;
+ module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
+ for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
+ stripind = chipind * module->GetStripsPerChip();
+ module->GetCM()[chipind].Set(fNumberOfEvents);
+ module->GetCM()[chipind].Reset(0.0f);
+ for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
+ // calculate firs approximation of CM and SigmaCM.
+ cm0 = cm1 = cmsigma = 0.0L;
+ ovstr = 0;
+ for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
+ if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; } //return kFALSE;
+ if (!(signal = strip->GetSignal())) { ovstr += 1; continue; } //return kFALSE;
+ if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
+ else {
+ if (!(strind - stripind - ovstr)) {
+ cm0 = cm1 = signal[ev] - strip->GetPedestal();
+ cmsigma = 0.0L;
+ } else {
+ cm1 = cm0 + (signal[ev] - strip->GetPedestal() - cm0) / static_cast<Double_t>(strind - stripind - ovstr + 1);
+ cms1 = cmsigma + (signal[ev] - strip->GetPedestal() - cm0) * (signal[ev] - strip->GetPedestal() - cm1);
+ cm0 = cm1;
+ cmsigma = cms1;
+ } }
+ }
+ if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr - 1) > 0) cmsigma = TMath::Sqrt(cmsigma / static_cast<Double_t>(n));
+ else {
+ AliWarning(Form("AliITSHandleDaSSD: Too little number of strips have a signal for module:chip:event : [%d]:[%d]:[%ld]\n",
+ module->GetModuleId(), chipind, ev));
+ if (!(module->SetCM(0.0f, chipind, ev)))
+ AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
+ module->GetModuleId(), chipind, ev));
+ continue;
+ }
+ // calculate cm with threshold
+ Double_t cmsum = 0.0L;
+ ovstr = 0;
+ for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
+ if (!(strip = module->GetStrip(strind))) { ovstr += 1; continue; }
+ if (!(signal = strip->GetSignal())) { ovstr += 1; continue; }
+ if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())
+ || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
+ else cmsum += (signal[ev] - strip->GetPedestal());
+ }
+ if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Double_t)(n);
+ else cmsum = 0.0L;
+ if (!(module->SetCM(static_cast<Float_t>(cmsum), chipind, ev)))
+ AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%d]:[%d]:[%ld]\n",
+ module->GetModuleId(), chipind, ev));
+ }
+ }
+ return kTRUE;
+}
+
+
+//______________________________________________________________________________
+Bool_t AliITSHandleDaSSD::CalculateNoiseCMW(AliITSModuleDaSSD *const module)
+{
+// Calculates Noise with CM correction
+ AliITSChannelDaSSD *strip = NULL;
+ Short_t *signal;
+ Int_t ovev, n;
+ if (!CalculateCMW(module)) {
+ AliError("Error: AliITSHandleDaSSD::CalculateCMW() returned kFALSE");
+ return kFALSE;
+ }
+ for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
+ if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
+ if (!(signal = strip->GetSignal())) {
+ strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
+ AliError(Form("AliITSHandleDaSSD: Error CalculateNoiseCMW(): there are no events data for module[%i] strip[%i]->GetSignal()",
+ module->GetModuleId(), strind));
+ continue; //return kFALSE;
+ }
+//** To get exactly the same set of events as for pedestal and noise calculation **
+ Double_t pedestal, noise, p0, s0;
+ pedestal = p0 = noise = 0.0L;
+ ovev = 0;
+ for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
+ if (SignalOutOfRange(signal[ev])) ovev += 1;
+ else
+ if (!(ev - ovev)) {
+ pedestal = p0 = signal[ev];
+ noise = 0.0L;
+ } else {
+ p0 = pedestal + (signal[ev] - pedestal) / static_cast<Double_t>(ev - ovev + 1);
+ s0 = noise + (signal[ev] - pedestal) * (signal[ev] - p0);
+ pedestal = p0;
+ noise = s0;
+ }
+ }
+ if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(noise / static_cast<Double_t>(n));
+ else {
+ strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
+ continue;
+ }
+//** Calculation of CM corrected noise **
+ Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
+ Double_t nsum = 0.0L;
+ ovev = 0;
+ for (Int_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
+ if ( SignalOutOfRange(signal[ev])
+ || TMath::Abs(signal[ev] - pedestal) > (fPedestalThresholdFactor * noise)) ovev += 1;
+ else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
+ }
+ if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise = TMath::Sqrt(nsum / static_cast<Double_t>(n));
+ else noise = AliITSChannelDaSSD::GetUndefinedValue();
+ strip->SetNoiseCM(static_cast<Float_t>(noise));
+ }
+ return kTRUE;
+}
+
+
+
+//______________________________________________________________________________
+UChar_t AliITSHandleDaSSD::EvaluateIfChannelIsBad(const AliITSModuleDaSSD *const module, const Int_t stripn) const
+{
+//Applies the bad channel creteria and set the appropriate flags for returned value
+ AliITSChannelDaSSD *strip = 0;
+ UInt_t bcflags = 0;
+ if (fZsDefault >= 0) { if (static_cast<ULong_t>(fZsDefault) >= fgkZsBitMask) bcflags |= 3; }
+ else if (static_cast<ULong_t>(fZsMinimum) >= fgkZsBitMask) bcflags |= 3;
+ if (LadderIsOff(module->GetDdlId(), module->GetAD(), module->GetADC()) ) bcflags |= 3;
+
+ if (!(strip = module->GetStrip(stripn))) bcflags |= 3;
+ else {
+ if (strip->GetNoiseCM() == AliITSChannelDaSSD::GetUndefinedValue()) bcflags |= 8;
+ if (static_cast<ULong_t>(TMath::Nint(fZsFactor * strip->GetNoiseCM())) >= fgkZsBitMask) bcflags |= 8;
+ if (strip->GetNoiseCM() < 1) bcflags |= 16;
+ if (strip->GetPedestal() > ((fgkOffSetBitMask >> 1) - 1)) bcflags |= 4;
+ else if ((-(strip->GetPedestal())) > (fgkOffSetBitMask >> 1)) bcflags |= 4;
+ if (bcflags) bcflags |= 3;
+ }
+ return bcflags;
+}
+