- Int_t retval=0;
- Int_t nevents=Int_t (runLoader->TreeE()->GetEntries());
-#ifdef DEBUG
- cout<<" nevents "<<nevents<<endl;
-#endif
- for(Int_t ievent=0;ievent<nevents;ievent++)
- {
-#ifdef DEBUG
- cout<<" *** event "<<ievent<<endl;
-#endif
- runLoader->GetEvent(ievent) ;
- //event z-vertex for correction eta-rad dependence
- AliHeader *header = runLoader->GetHeader();
- AliGenEventHeader* genHeader = header->GenEventHeader();
- TArrayF *o = new TArrayF(3);
- if (genHeader) genHeader->PrimaryVertex(*o);
- Float_t zVertex=o->At(2);
-
- for (Int_t i=0; i<5; i++)
- hTotal[i+1]->Reset();
-
- retval = plFMD->LoadDigits("READ");
- if (retval)
- {
- Error("Exec","Error occured while loading digits. Exiting.");
- return;
- }
-
- TTree* treeD = plFMD->TreeD();
- if (treeD == 0x0)
- {
- Error("Exec","Can not get Tree with Digits. Nothing to reconstruct - Exiting");
- return;
- }
-
- TBranch *brDigits=0;
-
- brDigits=treeD->GetBranch("FMD");
-
- if (brDigits) {
- brDigits->SetAddress(&digits);
- }else{
- cerr<<"EXEC Branch FMD digits not found"<<endl;
- return;
- }
-
- if(plFMD->TreeR()==0) plFMD->MakeTree("R");
-
- //Make branches
- const Int_t kBufferSize = 16000;
- plFMD->TreeR()->Branch("FMD", &reconParticles, kBufferSize);
-
-
- Int_t zeroADC=6;
- // read Digits
- AliFMDdigit *fmdDigit;
- if (plFMD->TreeD()->GetEvent(0))
- {
- Int_t nDigits=digits->GetEntries();
- Int_t recParticles[6];
- Int_t nRecPart=0 ;
- Int_t zeroPads=0;
- Int_t numberOfPads=0;
- Int_t pedestal;
- Float_t channelWidth=(22400*50)/1024;
- for (Int_t digit=0;digit<nDigits;digit++)
- {
- fmdDigit=(AliFMDdigit*)digits->UncheckedAt(digit);
- ivol=fmdDigit->Volume();
- iSector=fmdDigit->NumberOfSector();
- iRing=fmdDigit->NumberOfRing();
- pedestal=Int_t(gRandom->Gaus(500,250));
- padADC= fmdDigit->ADCsignal()
- -Int_t(Float_t(pedestal)/channelWidth);
- if (padADC<0) padADC=0;
- hTotal[ivol]->Fill(iSector,iRing,padADC);
- } //digit loop
-
- //reconstruct multiplicity in 0.1 eta according Poisson distribution
-
- Int_t rmin=0; Int_t rmax=0;
- Int_t smin=0; Int_t smax=0;
- for (ivol=0; ivol<knumVolumes; ivol++)
- {
- Float_t ring2number=Float_t (numberOfRings[ivol])/
- (rout[ivol]-rin[ivol]);
- Float_t realZ=zVertex+z[ivol];
- theta=TMath::ATan(rout[ivol]/TMath::Abs(realZ));
- etain = - TMath::Log( TMath::Tan(theta/2.));
- theta=TMath::ATan(rin[ivol]/TMath::Abs(realZ));
- etaout=- TMath::Log( TMath::Tan(theta/2.));
- numberOfEtaIntervals[ivol]=Int_t((etaout-etain)*10)-1;
- eta=etain;
- for (Int_t e1=0;e1<=numberOfEtaIntervals[ivol];e1++)
- {
- theta = 2.*TMath::ATan (TMath::Exp (-eta));
- Float_t radmin = TMath::Abs(realZ) * (TMath::Tan (theta));
- rmax= Int_t ( (radmin-rin[ivol])*ring2number+0.5);
- eta=eta+0.1;
- theta = 2.*TMath::ATan (TMath::Exp (-eta));
- rad = TMath::Abs(realZ) * (TMath::Tan (theta));
- rmin=Int_t( (rad-rin[ivol])*ring2number+0.5);
-
- zeroPads=0;
- smin=0;
- smax=numberOfSectors[ivol];
- numberOfPads=(rmax-rmin)*(smax-smin);
- for (Int_t iring=rmin; iring<rmax; iring++)
- {
- for
- (Int_t isector=0;
- isector<numberOfSectors[ivol];
- isector++)
- {
- if(hTotal[ivol+1]->GetBinContent(isector+1,iring+1)
- <zeroADC) zeroPads++;}
-
- } //ring
- Float_t numberOfPads=Float_t(smax-smin)*Float_t(rmax-rmin);
-
- Double_t lambda=-TMath::Log(Double_t(zeroPads)/numberOfPads);
- Int_t fRecon=Int_t (lambda*numberOfPads+0.5);
- recParticles[0]=ivol+1;
- recParticles[1]=smin;
- recParticles[2]=smax;
- recParticles[3]=rmin;
- recParticles[4]=rmax;
- recParticles[5]= fRecon;
- new((*reconParticles)[nRecPart++]) AliFMDReconstParticles(recParticles);
-
-
- } // eta
- } // volume
-
- }//if (plFMD->TreeD()->GetEvent(0))
- plFMD->TreeR()->Reset();
- plFMD->TreeR()->Fill();
- plFMD->WriteRecPoints("OVERWRITE");
- plFMD->UnloadDigits();
- } //event loop
- plFMD->UnloadRecPoints();
-#ifdef DEBUG
- Info(" Exec"," finished");
+ ProcessSignal(det, rng, sec, str, adc);
+}
+
+//____________________________________________________________________
+void
+AliFMDReconstructor::ProcessSignal(UShort_t det,
+ Char_t rng,
+ UShort_t sec,
+ UShort_t str,
+ Short_t adc) const
+{
+ // Process the signal from a single strip
+ //
+ // Parameters:
+ // det Detector ID
+ // rng Ring ID
+ // sec Sector ID
+ // rng Strip ID
+ // adc ADC counts
+ //
+ if (adc >= AliFMDRawReader::kBadSignal) {
+ AliFMDDebug(1, ("FMD%d%c[%2d,%3d] is marked bad", det, rng, sec, str));
+ fBad(det,rng,sec,str) = true;
+ return;
+ }
+
+ // Check that the strip is not marked as dead
+ AliFMDParameters* param = AliFMDParameters::Instance();
+ if (param->IsDead(det, rng, sec, str)) {
+ AliFMDDebug(1, ("FMD%d%c[%2d,%3d] is dead", det, rng, sec, str));
+ fBad(det,rng,sec,str) = true;
+ return;
+ }
+
+ // digit->Print();
+ // Get eta and phi
+ Float_t eta, phi;
+ PhysicalCoordinates(det, rng, sec, str, eta, phi);
+
+ // Substract pedestal.
+ UShort_t counts = SubtractPedestal(det, rng, sec, str, adc);
+ if(counts == USHRT_MAX) return;
+
+ // Gain match digits.
+ Double_t edep = Adc2Energy(det, rng, sec, str, eta, counts);
+ // Get rid of nonsense energy
+ if(edep < 0) return;
+
+ // Make rough multiplicity
+ Double_t mult = Energy2Multiplicity(det, rng, sec, str, edep);
+ // Get rid of nonsense mult
+ //if (mult > 20) {
+ // AliWarning(Form("The mutliplicity in FMD%d%c[%2d,%3d]=%f > 20 "
+ // "(ADC: %d, Energy: %f)", det, rng, sec, str, mult,
+ // counts, edep));
+ // }
+ if (mult < 0) return;
+ AliFMDDebug(10, ("FMD%d%c[%2d,%3d]: "
+ "ADC: %d, Counts: %d, Energy: %f, Mult: %f",
+ det, rng, sec, str, adc, counts, edep, mult));
+
+ // Create a `RecPoint' on the output branch.
+ if (fMult) {
+ AliFMDRecPoint* m =
+ new ((*fMult)[fNMult]) AliFMDRecPoint(det, rng, sec, str,
+ eta, phi, edep, mult);
+ (void)m; // Suppress warnings about unused variables.
+ fNMult++;
+ }
+
+ fESDObj->SetMultiplicity(det, rng, sec, str, mult);
+ fESDObj->SetEta(det, rng, sec, str, eta);
+
+ if (fDiagAll) fDiagAll->Fill(adc, mult);
+
+}
+
+//____________________________________________________________________
+void
+AliFMDReconstructor::DigitizeSignal(TClonesArray* sdigits,
+ UShort_t det,
+ Char_t rng,
+ UShort_t sec,
+ UShort_t str,
+ UShort_t /* sam */,
+ Short_t adc) const
+{
+ // Process the signal from a single strip
+ //
+ // Parameters:
+ // det Detector ID
+ // rng Ring ID
+ // sec Sector ID
+ // rng Strip ID
+ // adc ADC counts
+ //
+ AliFMDParameters* param = AliFMDParameters::Instance();
+ // Check that the strip is not marked as dead
+ if (param->IsDead(det, rng, sec, str)) {
+ AliFMDDebug(10, ("FMD%d%c[%2d,%3d] is dead", det, rng, sec, str));
+ return;
+ }
+
+ // Substract pedestal.
+ UShort_t counts = SubtractPedestal(det, rng, sec, str, adc);
+ if(counts == USHRT_MAX || counts == 0) return;
+
+ // Gain match digits.
+ Double_t edep = Adc2Energy(det, rng, sec, str, counts);
+ // Get rid of nonsense energy
+ if(edep < 0) return;
+
+ Int_t n = sdigits->GetEntriesFast();
+ // AliFMDSDigit* sdigit =
+ new ((*sdigits)[n])
+ AliFMDSDigit(det, rng, sec, str, edep, counts, counts, counts, counts);
+ // sdigit->SetCount(sam, counts);
+}
+
+//____________________________________________________________________
+UShort_t
+AliFMDReconstructor::SubtractPedestal(UShort_t det,
+ Char_t rng,
+ UShort_t sec,
+ UShort_t str,
+ UShort_t adc,
+ Float_t noiseFactor,
+ Bool_t zsEnabled,
+ UShort_t zsNoiseFactor) const
+{
+ //
+ // Subtract the pedestal off the ADC counts.
+ //
+ // Parameters:
+ // det Detector number
+ // rng Ring identifier
+ // sec Sector number
+ // str Strip number
+ // adc ADC counts
+ // noiseFactor If pedestal substracted pedestal is less then
+ // this times the noise, then consider this to be 0.
+ // zsEnabled Whether zero-suppression is on.
+ // zsNoiseFactor Noise factor used in on-line pedestal
+ // subtraction.
+ //
+ // Return:
+ // The pedestal subtracted ADC counts (possibly 0), or @c
+ // USHRT_MAX in case of problems.
+ //
+ AliFMDParameters* param = AliFMDParameters::Instance();
+ Float_t ped = (zsEnabled ? 0 :
+ param->GetPedestal(det, rng, sec, str));
+ Float_t noise = param->GetPedestalWidth(det, rng, sec, str);
+ if(ped < 0 || noise < 0) {
+ AliWarningClass(Form("Invalid pedestal (%f) or noise (%f) "
+ "for FMD%d%c[%02d,%03d]",
+ ped, noise, det, rng, sec, str));
+ return USHRT_MAX;
+ }
+ AliDebugClass(15, Form("Subtracting pedestal for FMD%d%c[%2d,%3d]=%4d "
+ "(%s w/factor %d, noise factor %f, "
+ "pedestal %8.2f+/-%8.2f)",
+ det, rng, sec, str, adc,
+ (zsEnabled ? "zs'ed" : "straight"),
+ zsNoiseFactor, noiseFactor, ped, noise));
+
+ Int_t counts = adc + Int_t(zsEnabled ? zsNoiseFactor * noise : - ped);
+ counts = TMath::Max(Int_t(counts), 0);
+ // Calculate the noise factor for suppressing remenants of the noise
+ // peak. If we have done on-line zero suppression, we only check
+ // for noise signals that are larger than the suppressed noise. If
+ // the noise factor used on line is larger than the factor used
+ // here, we do not do this check at all.
+ //
+ // For example:
+ // Online factor | Read factor | Result
+ // ---------------+--------------+-------------------------------
+ // 2 | 3 | Check if signal > 1 * noise
+ // 3 | 3 | Check if signal > 0
+ // 3 | 2 | Check if signal > 0
+ //
+ // In this way, we make sure that we do not suppress away too much
+ // data, and that the read-factor is the most stringent cut.
+ Float_t nf = TMath::Max(0.F, noiseFactor - (zsEnabled ? zsNoiseFactor : 0));
+ if (counts < noise * nf) counts = 0;
+ if (counts > 0) AliDebugClass(15, "Got a hit strip");
+
+ UShort_t ret = counts < 0 ? 0 : counts;
+ return ret;
+}
+
+
+//____________________________________________________________________
+UShort_t
+AliFMDReconstructor::SubtractPedestal(UShort_t det,
+ Char_t rng,
+ UShort_t sec,
+ UShort_t str,
+ Short_t adc) const
+{
+ // Member function to subtract the pedestal from a digit
+ //
+ // Parameters:
+ // det Detector ID
+ // rng Ring ID
+ // sec Sector ID
+ // rng Strip ID
+ // adc # of ADC counts
+ // Return:
+ // Pedestal subtracted signal or USHRT_MAX in case of problems
+ //
+ UShort_t counts = SubtractPedestal(det, rng, sec, str, adc,
+ fNoiseFactor, fZS[det-1],
+ fZSFactor[det-1]);
+ if (fDiagStep1) fDiagStep1->Fill(adc, counts);
+
+ return counts;
+}
+
+//____________________________________________________________________
+Float_t
+AliFMDReconstructor::Adc2Energy(UShort_t det,
+ Char_t rng,
+ UShort_t sec,
+ UShort_t str,
+ UShort_t count) const
+{
+ // Converts number of ADC counts to energy deposited.
+ // Note, that this member function can be overloaded by derived
+ // classes to do strip-specific look-ups in databases or the like,
+ // to find the proper gain for a strip.
+ //
+ // In the first simple version, we calculate the energy deposited as
+ //
+ // EnergyDeposited = cos(theta) * gain * count
+ //
+ // where
+ //
+ // Pre_amp_MIP_Range
+ // gain = ----------------- * Energy_deposited_per_MIP
+ // ADC_channel_size
+ //
+ // is constant and the same for all strips.
+ //
+ // For the production we use the conversion measured in the NBI lab.
+ // The total conversion is then:
+ //
+ // gain = ADC / DAC
+ //
+ // EdepMip * count
+ // => energy = ----------------
+ // gain * DACPerADC
+ //
+ // Parameters:
+ // det Detector ID
+ // rng Ring ID
+ // sec Sector ID
+ // rng Strip ID
+ // counts Number of ADC counts over pedestal
+ // Return
+ // The energy deposited in a single strip, or -1 in case of problems
+ //
+ if (count <= 0) return 0;
+ AliFMDParameters* param = AliFMDParameters::Instance();
+ Float_t gain = param->GetPulseGain(det, rng, sec, str);
+ // 'Tagging' bad gains as bad energy
+ if (gain < 0) {
+ AliWarning(Form("Invalid gain (%f) for FMD%d%c[%02d,%03d]",
+ gain, det, rng, sec, str));
+ return -1;
+ }
+ AliFMDDebug(5, ("Converting counts %d to energy (factor=%f, DAC2MIP=%f)",
+ count, gain,param->GetDACPerMIP()));
+
+ Double_t edep = ((count * param->GetEdepMip())
+ / (gain * param->GetDACPerMIP()));
+ return edep;
+}
+
+//____________________________________________________________________
+Float_t
+AliFMDReconstructor::Adc2Energy(UShort_t det,
+ Char_t rng,
+ UShort_t sec,
+ UShort_t str,
+ Float_t eta,
+ UShort_t count) const
+{
+ // Converts number of ADC counts to energy deposited.
+ // Note, that this member function can be overloaded by derived
+ // classes to do strip-specific look-ups in databases or the like,
+ // to find the proper gain for a strip.
+ //
+ // In the first simple version, we calculate the energy deposited as
+ //
+ // EnergyDeposited = cos(theta) * gain * count
+ //
+ // where
+ //
+ // Pre_amp_MIP_Range
+ // gain = ----------------- * Energy_deposited_per_MIP
+ // ADC_channel_size
+ //
+ // is constant and the same for all strips.
+ //
+ // For the production we use the conversion measured in the NBI lab.
+ // The total conversion is then:
+ //
+ // gain = ADC / DAC
+ //
+ // EdepMip * count
+ // => energy = ----------------
+ // gain * DACPerADC
+ //
+ // Parameters:
+ // det Detector ID
+ // rng Ring ID
+ // sec Sector ID
+ // rng Strip ID
+ // eta Psuedo-rapidity
+ // counts Number of ADC counts over pedestal
+ // Return
+ // The energy deposited in a single strip, or -1 in case of problems
+ //
+ Double_t edep = Adc2Energy(det, rng, sec, str, count);
+
+ if (fDiagStep2) fDiagStep2->Fill(count, edep);
+ if (fAngleCorrect) {
+ Double_t theta = 2 * TMath::ATan(TMath::Exp(-eta));
+ Double_t corr = TMath::Abs(TMath::Cos(theta));
+ Double_t cedep = corr * edep;
+ AliFMDDebug(10, ("correcting for path %f * %f = %f (eta=%f, theta=%f)",
+ edep, corr, cedep, eta, theta));
+ if (fDiagStep3) fDiagStep3->Fill(edep, cedep);
+ edep = cedep;
+ }
+ return edep;
+}
+
+//____________________________________________________________________
+Float_t
+AliFMDReconstructor::Energy2Multiplicity(UShort_t /*det*/,
+ Char_t /*rng*/,
+ UShort_t /*sec*/,
+ UShort_t /*str*/,
+ Float_t edep) const
+{
+ // Converts an energy signal to number of particles.
+ // Note, that this member function can be overloaded by derived
+ // classes to do strip-specific look-ups in databases or the like,
+ // to find the proper gain for a strip.
+ //
+ // In this simple version, we calculate the multiplicity as
+ //
+ // multiplicity = Energy_deposited / Energy_deposited_per_MIP
+ //
+ // where
+ //
+ // Energy_deposited_per_MIP = 1.664 * SI_density * SI_thickness
+ //
+ // is constant and the same for all strips
+ //
+ // Parameters:
+ // det Detector ID
+ // rng Ring ID
+ // sec Sector ID
+ // rng Strip ID
+ // edep Energy deposited in a single strip
+ // Return
+ // The "bare" multiplicity corresponding to the energy deposited
+ AliFMDParameters* param = AliFMDParameters::Instance();
+ Double_t edepMIP = param->GetEdepMip();
+ Float_t mult = edep / edepMIP;
+#if 0
+ if (edep > 0)
+ AliFMDDebug(15, ("Translating energy %f to multiplicity via "
+ "divider %f->%f", edep, edepMIP, mult));