+ for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
+ {
+ Float_t qcath = qtot * ( cath == 0 ? currentCorrel : 1.0/currentCorrel);
+
+ // Get an iterator to loop over pads, within the given area.
+ const AliMpVSegmentation* seg =
+ AliMpSegmentation::Instance()
+ ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
+
+ AliMpVPadIterator* it = seg->CreateIterator(area);
+
+ if (!it)
+ {
+ AliError(Form("Could not get iterator for detElemId %d",detElemId));
+ return;
+ }
+
+ // Start loop over pads.
+ it->First();
+
+ if ( it->IsDone() )
+ {
+ // Exceptional case : iterator is built, but is invalid from the start.
+ AliMpPad pad = seg->PadByPosition(area.GetPositionX(),area.GetPositionY(),
+ kFALSE);
+ if ( pad.IsValid() )
+ {
+ AliDebug(1, Form("Got an invalid iterator bug (area.Position() is within "
+ " DE but the iterator is void) for detElemId %d cath %d",
+ detElemId,cath));
+ }
+ else
+ {
+ AliDebug(1, Form("Got an invalid iterator bug for detElemId %d cath %d."
+ "Might be a bad hit ? area.Position()=(%e,%e) "
+ "Dimensions()=(%e,%e)",
+ detElemId,cath,area.GetPositionX(),area.GetPositionY(),
+ area.GetDimensionX(),area.GetDimensionY()));
+ }
+ delete it;
+ return;
+ }
+
+ while ( !it->IsDone() )
+ {
+ // For each pad given by the iterator, compute the charge of that
+ // pad, according to the Mathieson distribution.
+ AliMpPad pad = it->CurrentItem();
+ TVector2 lowerLeft(TVector2(x,y)-TVector2(pad.GetPositionX(),pad.GetPositionY())-
+ TVector2(pad.GetDimensionX(),pad.GetDimensionY()));
+ TVector2 upperRight(lowerLeft + TVector2(pad.GetDimensionX(),pad.GetDimensionY())*2.0);
+ Float_t qp = TMath::Abs(fMathieson->IntXY(lowerLeft.X(),lowerLeft.Y(),
+ upperRight.X(),upperRight.Y()));
+
+ if ( qp > fChargeThreshold &&
+ qp*qcath > AliMUONConstants::DefaultADC2MV()*AliMUONConstants::DefaultA0()*AliMUONConstants::DefaultCapa() )
+ {
+ // If we're above threshold, then we create a digit,
+ // and fill it with relevant information, including electronics.
+
+ // note that the second condition above is to be backward compatible (when
+ // the sdigitizer was making a cut on Int_t(qp*qcath) > 0 and qcath was in ADC, not in fC)
+
+ AliMUONDigit* d = new AliMUONDigit(detElemId,pad.GetManuId(),
+ pad.GetManuChannel(),cath);
+ d->SetPadXY(pad.GetIx(),pad.GetIy());
+ d->SetCharge(qp*qcath);
+ digits.Add(d);
+ }
+ it->Next();
+ }
+ delete it;
+ }
+}