#include <TTree.h>
#include <TObjArray.h>
+#include <TParticle.h>
#include <TMath.h>
+#include "AliRun.h"
+#include "AliMC.h"
#include <AliITSUSegmentationPix.h>
#include "AliITSUClusterizer.h"
#include "AliITSUClusterPix.h"
,fInputDigits(0)
,fInputDigitsReadIndex(0)
,fLayerID(0)
+ ,fNLabels(0)
+ ,fRawData(kFALSE)
,fLorAngCorrection(0)
,fOutputClusters(0)
,fDigitFreelist(0)
AliITSdigit *tmp=static_cast<AliITSdigit*>(fInputDigits->UncheckedAt(fInputDigitsReadIndex++));
AliITSUClusterizerClusterDigit *digit=AllocDigit();
digit->fDigit=tmp;
- // IMPORTANT: A lexiographical order (fV,fU) is assumed
- digit->fU=tmp->GetCoord1();
- digit->fV=tmp->GetCoord2();
return digit;
}
else
{
// convert set of digits to cluster data in LOCAL frame
const double k1to12 = 1./12;
+ static int maxLbinDigit = AliITSdigit::GetNTracks();
//
+ fNLabels = 0;
Int_t n=0;
cand->fLastDigit->fNext=0;
double x=0,z=0,xmn=1e9,xmx=-1e9,zmn=1e9,zmx=-1e9,px=0,pz=0;
float cx,cz;
for (AliITSUClusterizerClusterDigit *idigit=cand->fFirstDigit;idigit;idigit=idigit->fNext) {
- fSegm->GetPadCxz(idigit->fV,idigit->fU,cx,cz);
+ AliITSdigit* dig = idigit->fDigit;
+ fSegm->GetPadCxz(dig->GetCoord2(),dig->GetCoord1(),cx,cz);
x += cx;
z += cz;
if (cx<xmn) xmn=cx;
if (cx>xmx) xmx=cx;
if (cz<zmn) zmn=cz;
if (cz>zmx) zmx=cz;
- px += fSegm->Dpx(idigit->fV);
- pz += fSegm->Dpz(idigit->fU);
+ px += fSegm->Dpx(dig->GetCoord2());
+ pz += fSegm->Dpz(dig->GetCoord1());
+ //
+ if (!fRawData) {
+ for(Int_t dlab=0;dlab<maxLbinDigit;dlab++){
+ Int_t digitlab = (dig->GetTracks())[dlab];
+ if(digitlab<0) continue;
+ AddLabel(digitlab);
+ }
+ }
+ //
++n;
}
UChar_t nx=1,nz=1;
cluster->SetFrameLoc();
cluster->SetNxNz(nx,nz);
//
+ if (!fRawData) {
+ CheckLabels();
+ int nl = Min(kMaxLabInCluster,fNLabels);
+ for (int i=nl;i--;) cluster->SetLabel(fCurrLabels[i],i);
+ }
+ //
// Set Volume id
cluster->SetVolumeId(fVolID);
// printf("mod %d: (%.4lf,%.4lf)cm\n",fVolID,x,z);
//______________________________________________________________________________
void AliITSUClusterizer::Clusterize()
{
- // main algo
+ // main algo for MC clustererization
+ SetRawData(kFALSE);
+ //
AliITSUClusterizerClusterDigit *iDigit=NextDigit();
AliITSUClusterizerClusterPart *iPrevRowBegin=0;
AliITSUClusterizerClusterPart *iNextRowBegin=0;
AliITSUClusterizerClusterPart *iNextRow=0;
Int_t lastV=0;
while (iDigit) {
- if (iDigit->fV!=lastV) {
+ if (iDigit->fDigit->GetCoord2()!=lastV) {
// NEW ROW
if (iNextRow) iNextRow->fNextInRow=0;
if (iPrevRowBegin) CloseRemainingParts(iPrevRowBegin);
- if (iDigit->fV==lastV+1) {
+ if (iDigit->fDigit->GetCoord2()==lastV+1) {
iPrevRowBegin=iNextRowBegin;
iPrevRow =iNextRowBegin;
}
}
iNextRowBegin=0;
iNextRow =0;
- lastV=iDigit->fV;
+ lastV=iDigit->fDigit->GetCoord2();
}
// skip cluster parts before this digit
- while (iPrevRow && iPrevRow->fUEnd<iDigit->fU) {
+ while (iPrevRow && iPrevRow->fUEnd<iDigit->fDigit->GetCoord1()) {
iPrevRow=iPrevRow->fNextInRow;
}
// find the longest continous line of digits [iDigit,pDigit]=[iDigit,jDigit)
cand->fFirstPart=0;
cand->fFirstDigit=cand->fLastDigit=iDigit; // NB: first diggit is attached differently
iDigit->fNext=0;
- Int_t lastU =iDigit->fU;
+ Int_t lastU =iDigit->fDigit->GetCoord1();
Int_t lastU1=lastU+1;
- while (jDigit && jDigit->fU==lastU1 && jDigit->fV==lastV) {
+ while (jDigit && jDigit->fDigit->GetCoord1()==lastU1 && jDigit->fDigit->GetCoord2()==lastV) {
pDigit=jDigit;
jDigit=NextDigit();
AttachDigitToCand(cand,pDigit);
// after setting segmentation and recoparams
fLorAngCorrection = 0.5*fRecoParam->GetTanLorentzAngle(fLayerID)*bz/kNominalBz*fSegm->Dy();
}
+
+//______________________________________________________________________
+void AliITSUClusterizer::CheckLabels()
+{
+ // Tries to find mother's labels
+ //
+ if (fNLabels<1) return;
+ AliRunLoader *rl = AliRunLoader::Instance();
+ if(!rl) return;
+ TTree *trK=(TTree*)rl->TreeK();
+ if (!trK) return;
+ //
+ static int labS[kMaxLabels];
+ static float kine[kMaxLabels];
+ Int_t nlabels = fNLabels;
+ Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
+ for (Int_t i=fNLabels;i--;) labS[i] = fCurrLabels[i];
+ //
+ for (Int_t i=0;i<nlabels;i++) {
+ Int_t label = labS[i];
+ if (label>=ntracks) continue;
+ TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
+ kine[i] = part->Energy() - part->GetCalcMass(); // kinetic energy
+ if (kine[i] < 0.02) { // reduce soft particles from the same cluster
+ Int_t m=part->GetFirstMother();
+ if (m<0) continue; // primary
+ //
+ if (part->GetStatusCode()>0) continue;
+ //
+ // if the parent is within the same cluster, assign parent's label
+ for (int j=0;j<nlabels;j++) if (labS[j]==m) { labS[i] = m; break;}
+ }
+ }
+ //
+ if (nlabels>kMaxLabInCluster) { // only 3 labels are stored in cluster, sort in decreasing momentum
+ static int ind[kMaxLabels],labSS[kMaxLabels];
+ TMath::Sort(nlabels,kine,ind);
+ for (int i=nlabels;i--;) labSS[i] = labS[i];
+ for (int i=nlabels;i--;) labS[i] = labSS[ind[i]];
+ }
+ //
+ //compress labels -- if multi-times the same
+ for (Int_t i=0;i<nlabels;i++) fCurrLabels[i]=-2;
+ fNLabels = 0;
+ int j=0;
+ for (int i=0;i<nlabels;i++) {
+ for (j=fNLabels;j--;) if (labS[i]==fCurrLabels[j]) break; // the label already there
+ if (j<0) fCurrLabels[fNLabels++] = labS[i];
+ }
+ //
+}
{\r
//\r
public:\r
- enum {kDigitChunkSize=1024};\r
+ enum {kDigitChunkSize=1024, kMaxLabels=20,kMaxLabInCluster=3};\r
//\r
AliITSUClusterizer(Int_t nrowInit=0);\r
virtual ~AliITSUClusterizer();\r
+ void SetRawData(Bool_t v=kTRUE) {fRawData = v;}\r
void Clusterize();\r
void SetSegmentation(const AliITSUSegmentationPix *segm);\r
void SetRecoParam(const AliITSURecoParam* param) {fRecoParam = param;}\r
\r
void SetDigits(const TClonesArray *digits) {fInputDigits=digits;fInputDigitsReadIndex=0;}\r
void SetClusters(TClonesArray *clusters) {fOutputClusters=clusters;}\r
-\r
+ //\r
+ // labeling methods\r
+ void AddLabel(int label);\r
+ void CheckLabels();\r
+ //\r
protected: // transient data types\r
struct AliITSUClusterizerClusterDigit {\r
AliITSUClusterizerClusterDigit *fNext;\r
AliITSdigit *fDigit;\r
- Int_t fU;\r
- Int_t fV;\r
};\r
\r
struct AliITSUClusterizerClusterCand;\r
const TClonesArray *fInputDigits; // supplied digits\r
Int_t fInputDigitsReadIndex; // digits counter\r
Int_t fLayerID; // current layer id\r
+ //\r
+ Int_t fCurrLabels[kMaxLabels]; // labels collected for current cluster\r
+ Int_t fNLabels; // number of collected labels\r
+ Bool_t fRawData; // is raw data processed?\r
+ //\r
Double_t fLorAngCorrection; // Lorentz Angle correction for current layer\r
// Cluster Output\r
TClonesArray *fOutputClusters; // external container to store clusters\r
if (part->fNextInCluster) part->fNextInCluster->fPrevInCluster=part->fPrevInCluster;\r
}\r
\r
+//______________________________________________________________________________\r
+inline void AliITSUClusterizer::AddLabel(int label)\r
+{\r
+ // add new label\r
+ if (fNLabels==kMaxLabels) return;\r
+ for (int i=fNLabels;i--;) if (fCurrLabels[i]==label) return;\r
+ fCurrLabels[fNLabels++] = label;\r
+}\r
+\r
\r
#endif\r
\r