+ mean /= corrTimeGain;
+ rms /= corrTimeGain;
+ //
+ if (returnVal==1) return rms;
+ if (returnVal==2) return ncl;
+ return mean;
+}
+
+Float_t AliTPCseed::CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, Int_t returnVal, Int_t rowThres){
+
+ //
+ // calculates dedx using the cluster
+ // low - up specify trunc mean range - default form 0-0.7
+ // type - 1 - max charge or 0- total charge in cluster
+ // //2- max no corr 3- total+ correction
+ // i1-i2 - the pad-row range used for calculation
+ //
+ // posNorm - usage of pos normalization
+ // returnVal - 0 return mean
+ // - 1 return RMS
+ // - 2 return number of clusters
+ //
+ // rowThres - number of rows before and after given pad row to check for clusters below threshold
+ //
+ // normalization parametrization taken from AliTPCClusterParam
+ //
+ AliTPCClusterParam * parcl = AliTPCcalibDB::Instance()->GetClusterParam();
+ AliTPCParam * param = AliTPCcalibDB::Instance()->GetParameters();
+ if (!parcl) return 0;
+ if (!param) return 0;
+ Int_t row0 = param->GetNRowLow();
+ Int_t row1 = row0+param->GetNRowUp1();
+
+ Float_t amp[160];
+ Int_t indexes[160];
+ Int_t ncl=0;
+ Int_t nclBelowThr = 0; // counts number of clusters below threshold
+ //
+ //
+ Float_t gainGG = 1; // gas gain factor -always enabled
+ Float_t gainPad = 1; // gain map - used always
+ Float_t corrPos = 1; // local position correction - if posNorm enabled
+ //
+ //
+ //
+ if (AliTPCcalibDB::Instance()->GetParameters()){
+ gainGG= AliTPCcalibDB::Instance()->GetParameters()->GetGasGain()/20000; //relative gas gain
+ }
+ //
+ // extract time-dependent correction for pressure and temperature variations
+ //
+ UInt_t runNumber = 1;
+ Float_t corrTimeGain = 1;
+ TObjArray * timeGainSplines = 0x0;
+ TGraphErrors * grPadEqual = 0x0;
+ //
+ AliTPCTransform * trans = AliTPCcalibDB::Instance()->GetTransform();
+ const AliTPCRecoParam * recoParam = AliTPCcalibDB::Instance()->GetTransform()->GetCurrentRecoParam();
+ //
+ if (recoParam->GetNeighborRowsDedx() == 0) rowThres = 0;
+ //
+ if (trans) {
+ runNumber = trans->GetCurrentRunNumber();
+ //AliTPCcalibDB::Instance()->SetRun(runNumber);
+ timeGainSplines = AliTPCcalibDB::Instance()->GetTimeGainSplinesRun(runNumber);
+ if (timeGainSplines && recoParam->GetUseGainCorrectionTime()>0) {
+ UInt_t time = trans->GetCurrentTimeStamp();
+ AliSplineFit * fitMIP = (AliSplineFit *) timeGainSplines->At(0);
+ AliSplineFit * fitFPcosmic = (AliSplineFit *) timeGainSplines->At(1);
+ if (fitMIP) {
+ corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitMIP, time); /*fitMIP->Eval(time);*/
+ } else {
+ if (fitFPcosmic) corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitFPcosmic, time); /*fitFPcosmic->Eval(time); */
+ }
+ //
+ if (type==1) grPadEqual = (TGraphErrors * ) timeGainSplines->FindObject("TGRAPHERRORS_MEANQMAX_PADREGIONGAIN_BEAM_ALL");
+ if (type==0) grPadEqual = (TGraphErrors * ) timeGainSplines->FindObject("TGRAPHERRORS_MEANQTOT_PADREGIONGAIN_BEAM_ALL");
+ }
+ }
+
+ const Float_t kClusterShapeCut = 1.5; // IMPPRTANT TO DO: move value to AliTPCRecoParam
+ const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
+ const Float_t kedgey =3.;
+ //
+ //
+ for (Int_t irow=i1; irow<i2; irow++){
+ AliTPCclusterMI* cluster = GetClusterPointer(irow);
+ if (!cluster && irow > 1 && irow < 157) {
+ Bool_t isClBefore = kFALSE;
+ Bool_t isClAfter = kFALSE;
+ for(Int_t ithres = 1; ithres <= rowThres; ithres++) {
+ AliTPCclusterMI * clusterBefore = GetClusterPointer(irow - ithres);
+ if (clusterBefore) isClBefore = kTRUE;
+ AliTPCclusterMI * clusterAfter = GetClusterPointer(irow + ithres);
+ if (clusterAfter) isClAfter = kTRUE;
+ }
+ if (isClBefore && isClAfter) nclBelowThr++;
+ }
+ if (!cluster) continue;
+ //
+ //
+ if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
+ //
+ AliTPCTrackerPoint * point = GetTrackPoint(irow);
+ if (point==0) continue;
+ Float_t rsigmay = TMath::Sqrt(point->GetSigmaY());
+ if (rsigmay > kClusterShapeCut) continue;
+ //
+ if (cluster->IsUsed(11)) continue; // remove shared clusters for PbPb
+ //
+ Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
+ Int_t ipad= 0;
+ if (irow>=row0) ipad=1;
+ if (irow>=row1) ipad=2;
+ //
+ //
+ //
+ AliTPCCalPad * gainMap = AliTPCcalibDB::Instance()->GetDedxGainFactor();
+ if (gainMap) {
+ //
+ // Get gainPad - pad by pad calibration
+ //
+ Float_t factor = 1;
+ AliTPCCalROC * roc = gainMap->GetCalROC(cluster->GetDetector());
+ if (irow < row0) { // IROC
+ factor = roc->GetValue(irow, TMath::Nint(cluster->GetPad()));
+ } else { // OROC
+ factor = roc->GetValue(irow - row0, TMath::Nint(cluster->GetPad()));
+ }
+ if (factor>0.3) gainPad=factor;
+ }
+ //
+ // Do position normalization - relative distance to
+ // center of pad- time bin