1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 // HMPID base class to reconstruct an event
20 #include "AliHMPIDReconstructor.h" //class header
21 #include "AliHMPID.h" //Reconstruct()
22 #include "AliHMPIDCluster.h" //Dig2Clu()
23 #include "AliHMPIDParam.h" //FillEsd()
24 #include <AliCDBEntry.h> //ctor
25 #include <AliCDBManager.h> //ctor
26 #include <AliESDEvent.h> //FillEsd()
27 #include <AliRawReader.h> //Reconstruct() for raw digits
28 ClassImp(AliHMPIDReconstructor)
30 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31 AliHMPIDReconstructor::AliHMPIDReconstructor():AliReconstructor(),fUserCut(0),fDaqSig(0),fDig(0),fClu(0)
36 AliHMPIDParam::Instance(); //geometry loaded for reconstruction
37 fUserCut = new Int_t[7];
38 fClu=new TObjArray(AliHMPIDParam::kMaxCh+1); fClu->SetOwner(kTRUE);
39 fDig=new TObjArray(AliHMPIDParam::kMaxCh+1); fDig->SetOwner(kTRUE);
41 for(int i=AliHMPIDParam::kMinCh;i<=AliHMPIDParam::kMaxCh;i++){
42 fDig->AddAt(new TClonesArray("AliHMPIDDigit"),i);
43 TClonesArray *pClus = new TClonesArray("AliHMPIDCluster");
44 pClus->SetUniqueID(i);
48 AliCDBEntry *pUserCutEnt =AliCDBManager::Instance()->Get("HMPID/Calib/UserCut"); //contains TObjArray of 14 TObject with n. of sigmas to cut charge
50 TObjArray *pUserCut = (TObjArray*)pUserCutEnt->GetObject();
51 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){ //chambers loop
52 fUserCut[iCh] = pUserCut->At(iCh)->GetUniqueID();
53 Printf("HMPID: UserCut successfully loaded for chamber %i -> %i ",iCh,fUserCut[iCh]);
58 AliCDBEntry *pDaqSigEnt =AliCDBManager::Instance()->Get("HMPID/Calib/DaqSig"); //contains TObjArray of TObjArray 14 TMatrixF sigmas values for pads
59 if(!pDaqSigEnt) AliFatal("No pedestals from DAQ!");
60 fDaqSig = (TObjArray*)pDaqSigEnt->GetObject();
61 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){ //chambers loop
62 Printf(" HMPID: DaqSigCut successfully loaded for chamber %i -> %i ",iCh,(Int_t)fDaqSig->At(iCh)->GetUniqueID());
64 }//AliHMPIDReconstructor
65 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 void AliHMPIDReconstructor::Dig2Clu(TObjArray *pDigAll,TObjArray *pCluAll,Bool_t isTryUnfold)
68 // Finds all clusters for a given digits list provided not empty. Currently digits list is a list of all digits for a single chamber.
69 // Puts all found clusters in separate lists, one per clusters.
70 // Arguments: pDigAll - list of digits for all chambers
71 // pCluAll - list of clusters for all chambers
72 // isTryUnfold - flag to choose between CoG and Mathieson fitting
74 TMatrixF padMap(AliHMPIDParam::kMinPx,AliHMPIDParam::kMaxPcx,AliHMPIDParam::kMinPy,AliHMPIDParam::kMaxPcy); //pads map for single chamber 0..159 x 0..143
76 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){ //chambers loop
77 TClonesArray *pDigCur=(TClonesArray*)pDigAll->At(iCh); //get list of digits for current chamber
78 if(pDigCur->GetEntriesFast()==0) continue; //no digits for current chamber
80 padMap=(Float_t)-1; //reset map to -1 (means no digit for this pad)
81 TClonesArray *pCluCur=(TClonesArray*)pCluAll->At(iCh); //get list of clusters for current chamber
83 for(Int_t iDig=0;iDig<pDigCur->GetEntriesFast();iDig++){ //digits loop to fill pads map
84 AliHMPIDDigit *pDig= (AliHMPIDDigit*)pDigCur->At(iDig); //get current digit
85 padMap( pDig->PadChX(), pDig->PadChY() )=iDig; //fill the map, (padx,pady) cell takes digit index
86 }//digits loop to fill digits map
88 AliHMPIDCluster clu; //tmp cluster to be used as current
89 for(Int_t iDig=0;iDig<pDigCur->GetEntriesFast();iDig++){ //digits loop for current chamber
90 AliHMPIDDigit *pDig=(AliHMPIDDigit*)pDigCur->At(iDig); //take current digit
91 if(!(pDig=UseDig(pDig->PadChX(),pDig->PadChY(),pDigCur,&padMap))) continue; //this digit is already taken in FormClu(), go after next digit
92 FormClu(&clu,pDig,pDigCur,&padMap); //form cluster starting from this digit by recursion
94 clu.Solve(pCluCur,isTryUnfold); //solve this cluster and add all unfolded clusters to provided list
95 clu.Reset(); //empty current cluster
96 }//digits loop for current chamber
99 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100 void AliHMPIDReconstructor::FormClu(AliHMPIDCluster *pClu,AliHMPIDDigit *pDig,TClonesArray *pDigLst,TMatrixF *pDigMap)
102 // Forms the initial cluster as a combination of all adjascent digits. Starts from the given digit then calls itself recursevly for all neighbours.
103 // Arguments: pClu - pointer to cluster being formed
105 pClu->DigAdd(pDig);//take this digit in cluster
107 Int_t cnt=0,cx[4],cy[4];
109 if(pDig->PadPcX() != AliHMPIDParam::kMinPx){cx[cnt]=pDig->PadChX()-1; cy[cnt]=pDig->PadChY() ;cnt++;} //left
110 if(pDig->PadPcX() != AliHMPIDParam::kMaxPx){cx[cnt]=pDig->PadChX()+1; cy[cnt]=pDig->PadChY() ;cnt++;} //right
111 if(pDig->PadPcY() != AliHMPIDParam::kMinPy){cx[cnt]=pDig->PadChX() ; cy[cnt]=pDig->PadChY()-1;cnt++;} //down
112 if(pDig->PadPcY() != AliHMPIDParam::kMaxPy){cx[cnt]=pDig->PadChX() ; cy[cnt]=pDig->PadChY()+1;cnt++;} //up
114 for (Int_t i=0;i<cnt;i++){//neighbours loop
115 if((pDig=UseDig(cx[i],cy[i],pDigLst,pDigMap))) FormClu(pClu,pDig,pDigLst,pDigMap); //check if this neighbour pad fired and mark it as taken
118 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
119 void AliHMPIDReconstructor::Reconstruct(TTree *pDigTree,TTree *pCluTree)const
121 //Invoked by AliReconstruction to convert digits to clusters i.e. reconstruct simulated data
122 //Arguments: pDigTree - pointer to Digit tree
123 // pCluTree - poitner to Cluster tree
125 AliDebug(1,"Start.");
126 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) {
127 pCluTree->Branch(Form("HMPID%d",iCh),&((*fClu)[iCh]),4000,0);
128 pDigTree->SetBranchAddress(Form("HMPID%d",iCh),&((*fDig)[iCh]));
130 pDigTree->GetEntry(0);
131 Dig2Clu(fDig,fClu); //cluster finder
132 pCluTree->Fill(); //fill tree for current event
134 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){
135 fDig->At(iCh)->Clear();
136 fClu->At(iCh)->Clear();
140 }//Reconstruct(for simulated digits)
141 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
142 void AliHMPIDReconstructor::Reconstruct(AliRunLoader *pAL,AliRawReader* pRR)const
144 //Invoked by AliReconstruction to convert raw digits from DDL files to clusters
145 //Arguments: pAL - ALICE run loader pointer
146 // pRR - ALICE raw reader pointer
148 AliLoader *pRL=pAL->GetDetectorLoader("HMPID"); AliHMPID *pRich=(AliHMPID*)pAL->GetAliRun()->GetDetector("HMPID");//get pointers for HMPID and HMPID loader
150 AliHMPIDDigit dig; //tmp digit, raw digit will be converted to it
152 TObjArray digLst; Int_t iDigCnt[7]; for(Int_t i=0;i<7;i++){digLst.AddAt(new TClonesArray("AliHMPIDDigit"),i); iDigCnt[i]=0;} //tmp list of digits for allchambers
155 while(pRR->NextEvent()){//events loop
156 pAL->GetEvent(iEvtN++);
157 pRL->MakeTree("R"); pRich->MakeBranch("R");
159 for(Int_t iCh=0;iCh<7;iCh++){//chambers loop
160 pRR->Select("HMPID",2*iCh,2*iCh+1);//select only DDL files for the current chamber
162 while(pRR->ReadNextInt(w32)){//raw records loop (in selected DDL files)
163 UInt_t ddl=pRR->GetDDLID(); //returns 0,1,2 ... 13
164 dig.Raw(w32,ddl,pRR);
165 AliDebug(1,Form("Ch=%i DDL=%i raw=0x%x digit=(%3i,%3i,%3i,%3i) Q=%5.2f",iCh,ddl,w32,dig.Ch(),dig.Pc(),dig.PadPcX(),dig.PadPcY(),dig.Q()));
166 if(!IsDigSurvive(&dig)) continue; //sigma cut test
167 new((*((TClonesArray*)digLst.At(iCh)))[iDigCnt[iCh]++]) AliHMPIDDigit(dig); //add this digit to the tmp list
172 Dig2Clu(&digLst,pRich->CluLst());//cluster finder for all chambers
173 for(Int_t i=0;i<7;i++){digLst.At(i)->Delete(); iDigCnt[i]=0;} //clean up list of digits for all chambers
175 pRL->TreeR()->Fill(); //fill tree for current event
176 pRL->WriteRecPoints("OVERWRITE");//write out clusters for current event
179 pRL->UnloadRecPoints();
180 }//Reconstruct raw data
181 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
182 void AliHMPIDReconstructor::ConvertDigits(AliRawReader *pRR,TTree *pDigTree)const
184 //Invoked by AliReconstruction to convert raw digits from DDL files to digits
185 //Arguments: pRR - ALICE raw reader pointer
186 // pDigTree - pointer to Digit tree
188 AliDebug(1,"Start.");
189 AliHMPIDDigit dig; //tmp digit, raw digit will be converted to it
190 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) {
191 pDigTree->Branch(Form("HMPID%d",iCh),&((*fDig)[iCh]),4000,0);
192 pRR->Select("HMPID",2*iCh,2*iCh+1);//select only DDL files for the current chamber
195 while(pRR->ReadNextInt(w32)){//raw records loop (in selected DDL files)
196 UInt_t ddl=pRR->GetDDLID(); //returns 0,1,2 ... 13
197 if(!dig.Raw(w32,ddl,pRR)) continue;
198 AliDebug(1,Form("Ch=%i DDL=%i raw=0x%x digit=(%3i,%3i,%3i,%3i) Q=%5.2f",iCh,ddl,w32,dig.Ch(),dig.Pc(),dig.PadPcX(),dig.PadPcY(),dig.Q()));
199 if(!IsDigSurvive(&dig)) continue; //sigma cut test
200 new((*((TClonesArray*)fDig->At(iCh)))[iDigCnt++]) AliHMPIDDigit(dig); //add this digit to the tmp list
205 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++)fDig->At(iCh)->Clear();
207 }//Reconstruct digits from raw digits
208 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
209 void AliHMPIDReconstructor::FillESD(AliRunLoader *, AliESDEvent *pESD) const
211 // Calculates probability to be a electron-muon-pion-kaon-proton
212 // from the given Cerenkov angle and momentum assuming no initial particle composition
213 // (i.e. apriory probability to be the particle of the given sort is the same for all sorts)
216 Double_t pid[AliPID::kSPECIES],h[AliPID::kSPECIES];
218 for(Int_t iTrk=0;iTrk<pESD->GetNumberOfTracks();iTrk++){//ESD tracks loop
219 AliESDtrack *pTrk = pESD->GetTrack(iTrk);// get next reconstructed track
220 if(pTrk->GetHMPIDsignal()<=0){//HMPID does not find anything reasonable for this track, assign 0.2 for all species
221 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++) pid[iPart]=1.0/AliPID::kSPECIES;
222 pTrk->SetHMPIDpid(pid);
225 Double_t pmod = pTrk->GetP();
227 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++){
228 Double_t mass = AliPID::ParticleMass(iPart);
229 Double_t cosThetaTh = TMath::Sqrt(mass*mass+pmod*pmod)/(AliHMPIDParam::Instance()->MeanIdxRad()*pmod);
230 if(cosThetaTh<1) //calculate the height of theoretical theta ckov on the gaus of experimental one
231 h[iPart] =TMath::Gaus(TMath::ACos(cosThetaTh),pTrk->GetHMPIDsignal(),TMath::Sqrt(pTrk->GetHMPIDchi2()),kTRUE);
232 else //beta < 1/ref. idx. => no light at all
234 hTot +=h[iPart]; //total height of all theoretical heights for normalization
237 Double_t hMin=TMath::Gaus(pTrk->GetHMPIDsignal()-4*TMath::Sqrt(pTrk->GetHMPIDchi2()),pTrk->GetHMPIDsignal(),TMath::Sqrt(pTrk->GetHMPIDchi2()),kTRUE);//5 sigma protection
239 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++)//species loop to assign probabilities
241 pid[iPart]=h[iPart]/hTot;
242 else //all theoretical values are far away from experemental one
243 pid[iPart]=1.0/AliPID::kSPECIES;
244 pTrk->SetHMPIDpid(pid);
247 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++