]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HMPID/AliHMPIDReconstructor.cxx
remove old file
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDReconstructor.cxx
CommitLineData
d3da6dc4 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
423554a3 15//.
16// HMPID base class to reconstruct an event
17//.
18//.
19//.
d3da6dc4 20#include "AliHMPIDReconstructor.h" //class header
21#include "AliHMPID.h" //Reconstruct()
a1d55ff3 22#include "AliHMPIDCluster.h" //Dig2Clu()
d3da6dc4 23#include "AliHMPIDParam.h" //FillEsd()
a0e5c1b9 24#include <AliCDBEntry.h> //ctor
25#include <AliCDBManager.h> //ctor
555a0dbf 26#include <AliESDEvent.h> //FillEsd()
a0e5c1b9 27#include <AliRawReader.h> //Reconstruct() for raw digits
d76c31f4 28#include "AliHMPIDRawStream.h" //ConvertDigits()
d3da6dc4 29ClassImp(AliHMPIDReconstructor)
30
94b1fbfa 31//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a0e5c1b9 32AliHMPIDReconstructor::AliHMPIDReconstructor():AliReconstructor(),fUserCut(0),fDaqSig(0),fDig(0),fClu(0)
94b1fbfa 33{
34//
35//ctor
36//
909bfbdc 37 AliHMPIDParam::Instance(); //geometry loaded for reconstruction
14dc2e6c 38 fUserCut = new Int_t[7];
ae5a42aa 39 fClu=new TObjArray(AliHMPIDParam::kMaxCh+1); fClu->SetOwner(kTRUE);
40 fDig=new TObjArray(AliHMPIDParam::kMaxCh+1); fDig->SetOwner(kTRUE);
9cc1a411 41
ae5a42aa 42 for(int i=AliHMPIDParam::kMinCh;i<=AliHMPIDParam::kMaxCh;i++){
94b1fbfa 43 fDig->AddAt(new TClonesArray("AliHMPIDDigit"),i);
611e810d 44 TClonesArray *pClus = new TClonesArray("AliHMPIDCluster");
45 pClus->SetUniqueID(i);
46 fClu->AddAt(pClus,i);
94b1fbfa 47 }
a0e5c1b9 48
a0e5c1b9 49 AliCDBEntry *pUserCutEnt =AliCDBManager::Instance()->Get("HMPID/Calib/UserCut"); //contains TObjArray of 14 TObject with n. of sigmas to cut charge
85692374 50 if(pUserCutEnt) {
51 TObjArray *pUserCut = (TObjArray*)pUserCutEnt->GetObject();
52 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){ //chambers loop
53 fUserCut[iCh] = pUserCut->At(iCh)->GetUniqueID();
54 Printf("HMPID: UserCut successfully loaded for chamber %i -> %i ",iCh,fUserCut[iCh]);
55 }
9cc1a411 56 }
a0e5c1b9 57
a0e5c1b9 58
9cc1a411 59 AliCDBEntry *pDaqSigEnt =AliCDBManager::Instance()->Get("HMPID/Calib/DaqSig"); //contains TObjArray of TObjArray 14 TMatrixF sigmas values for pads
60 if(!pDaqSigEnt) AliFatal("No pedestals from DAQ!");
61 fDaqSig = (TObjArray*)pDaqSigEnt->GetObject();
62 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){ //chambers loop
63 Printf(" HMPID: DaqSigCut successfully loaded for chamber %i -> %i ",iCh,(Int_t)fDaqSig->At(iCh)->GetUniqueID());
a0e5c1b9 64 }
94b1fbfa 65}//AliHMPIDReconstructor
d3da6dc4 66//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c6274c1 67void AliHMPIDReconstructor::Dig2Clu(TObjArray *pDigAll,TObjArray *pCluAll,Bool_t isTryUnfold)
d3da6dc4 68{
69// Finds all clusters for a given digits list provided not empty. Currently digits list is a list of all digits for a single chamber.
70// Puts all found clusters in separate lists, one per clusters.
3c6274c1 71// Arguments: pDigAll - list of digits for all chambers
72// pCluAll - list of clusters for all chambers
d3da6dc4 73// isTryUnfold - flag to choose between CoG and Mathieson fitting
74// Returns: none
ae5a42aa 75 TMatrixF padMap(AliHMPIDParam::kMinPx,AliHMPIDParam::kMaxPcx,AliHMPIDParam::kMinPy,AliHMPIDParam::kMaxPcy); //pads map for single chamber 0..159 x 0..143
3c6274c1 76
ae5a42aa 77 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){ //chambers loop
3c6274c1 78 TClonesArray *pDigCur=(TClonesArray*)pDigAll->At(iCh); //get list of digits for current chamber
79 if(pDigCur->GetEntriesFast()==0) continue; //no digits for current chamber
d3da6dc4 80
3c6274c1 81 padMap=(Float_t)-1; //reset map to -1 (means no digit for this pad)
82 TClonesArray *pCluCur=(TClonesArray*)pCluAll->At(iCh); //get list of clusters for current chamber
83
84 for(Int_t iDig=0;iDig<pDigCur->GetEntriesFast();iDig++){ //digits loop to fill pads map
85 AliHMPIDDigit *pDig= (AliHMPIDDigit*)pDigCur->At(iDig); //get current digit
86 padMap( pDig->PadChX(), pDig->PadChY() )=iDig; //fill the map, (padx,pady) cell takes digit index
87 }//digits loop to fill digits map
88
89 AliHMPIDCluster clu; //tmp cluster to be used as current
3c6274c1 90 for(Int_t iDig=0;iDig<pDigCur->GetEntriesFast();iDig++){ //digits loop for current chamber
91 AliHMPIDDigit *pDig=(AliHMPIDDigit*)pDigCur->At(iDig); //take current digit
92 if(!(pDig=UseDig(pDig->PadChX(),pDig->PadChY(),pDigCur,&padMap))) continue; //this digit is already taken in FormClu(), go after next digit
93 FormClu(&clu,pDig,pDigCur,&padMap); //form cluster starting from this digit by recursion
94
95 clu.Solve(pCluCur,isTryUnfold); //solve this cluster and add all unfolded clusters to provided list
96 clu.Reset(); //empty current cluster
97 }//digits loop for current chamber
98 }//chambers loop
d3da6dc4 99}//Dig2Clu()
100//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101void AliHMPIDReconstructor::FormClu(AliHMPIDCluster *pClu,AliHMPIDDigit *pDig,TClonesArray *pDigLst,TMatrixF *pDigMap)
102{
a1d55ff3 103// Forms the initial cluster as a combination of all adjascent digits. Starts from the given digit then calls itself recursevly for all neighbours.
d3da6dc4 104// Arguments: pClu - pointer to cluster being formed
a1d55ff3 105// Returns: none
d3da6dc4 106 pClu->DigAdd(pDig);//take this digit in cluster
107
3c6274c1 108 Int_t cnt=0,cx[4],cy[4];
d3da6dc4 109
ae5a42aa 110 if(pDig->PadPcX() != AliHMPIDParam::kMinPx){cx[cnt]=pDig->PadChX()-1; cy[cnt]=pDig->PadChY() ;cnt++;} //left
111 if(pDig->PadPcX() != AliHMPIDParam::kMaxPx){cx[cnt]=pDig->PadChX()+1; cy[cnt]=pDig->PadChY() ;cnt++;} //right
112 if(pDig->PadPcY() != AliHMPIDParam::kMinPy){cx[cnt]=pDig->PadChX() ; cy[cnt]=pDig->PadChY()-1;cnt++;} //down
113 if(pDig->PadPcY() != AliHMPIDParam::kMaxPy){cx[cnt]=pDig->PadChX() ; cy[cnt]=pDig->PadChY()+1;cnt++;} //up
d3da6dc4 114
a1d55ff3 115 for (Int_t i=0;i<cnt;i++){//neighbours loop
3c6274c1 116 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
a1d55ff3 117 }//neighbours loop
d3da6dc4 118}//FormClu()
119//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94b1fbfa 120void AliHMPIDReconstructor::Reconstruct(TTree *pDigTree,TTree *pCluTree)const
d3da6dc4 121{
122//Invoked by AliReconstruction to convert digits to clusters i.e. reconstruct simulated data
94b1fbfa 123//Arguments: pDigTree - pointer to Digit tree
124// pCluTree - poitner to Cluster tree
d3da6dc4 125// Returns: none
126 AliDebug(1,"Start.");
ae5a42aa 127 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) {
94b1fbfa 128 pCluTree->Branch(Form("HMPID%d",iCh),&((*fClu)[iCh]),4000,0);
129 pDigTree->SetBranchAddress(Form("HMPID%d",iCh),&((*fDig)[iCh]));
130 }
131 pDigTree->GetEntry(0);
132 Dig2Clu(fDig,fClu); //cluster finder
133 pCluTree->Fill(); //fill tree for current event
134
ae5a42aa 135 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){
94b1fbfa 136 fDig->At(iCh)->Clear();
137 fClu->At(iCh)->Clear();
138 }
d3da6dc4 139
d3da6dc4 140 AliDebug(1,"Stop.");
141}//Reconstruct(for simulated digits)
a1d55ff3 142//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94b1fbfa 143void AliHMPIDReconstructor::ConvertDigits(AliRawReader *pRR,TTree *pDigTree)const
144{
145//Invoked by AliReconstruction to convert raw digits from DDL files to digits
146//Arguments: pRR - ALICE raw reader pointer
147// pDigTree - pointer to Digit tree
148// Returns: none
149 AliDebug(1,"Start.");
21f61e25 150// Int_t digcnt=0;
151
152
ae5a42aa 153 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) {
21f61e25 154 pDigTree->Branch(Form("HMPID%d",iCh),&((*fDig)[iCh]),4000,0);
155
94b1fbfa 156 Int_t iDigCnt=0;
21f61e25 157 AliHMPIDRawStream stream(pRR);
158 while(stream.Next())
159 {
160
161 UInt_t ddl=stream.GetDDLNumber(); //returns 0,1,2 ... 13
162 if((UInt_t)(2*iCh)==ddl || (UInt_t)(2*iCh+1)==ddl) {
163 for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
164 for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
165 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
166 if(stream.GetCharge(ddl,row,dil,pad) < 1) continue;
167 AliHMPIDDigit dig(stream.GetPad(ddl,row,dil,pad),stream.GetCharge(ddl,row,dil,pad));
168 if(!IsDigSurvive(&dig)) continue;
169 new((*((TClonesArray*)fDig->At(iCh)))[iDigCnt++]) AliHMPIDDigit(dig); //add this digit to the tmp list
170 }//pad
171 }//dil
172 }//row
173 }//while
174 }
175 stream.Delete();
176 }
94b1fbfa 177 pDigTree->Fill();
21f61e25 178
ae5a42aa 179 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++)fDig->At(iCh)->Clear();
21f61e25 180
94b1fbfa 181 AliDebug(1,"Stop.");
182}//Reconstruct digits from raw digits
183//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
d76c31f4 184void AliHMPIDReconstructor::FillESD(TTree */*digitsTree*/, TTree */*clustersTree*/, AliESDEvent *pESD) const
d3da6dc4 185{
186// Calculates probability to be a electron-muon-pion-kaon-proton
187// from the given Cerenkov angle and momentum assuming no initial particle composition
188// (i.e. apriory probability to be the particle of the given sort is the same for all sorts)
189
190 AliPID ppp; //needed
191 Double_t pid[AliPID::kSPECIES],h[AliPID::kSPECIES];
192
193 for(Int_t iTrk=0;iTrk<pESD->GetNumberOfTracks();iTrk++){//ESD tracks loop
194 AliESDtrack *pTrk = pESD->GetTrack(iTrk);// get next reconstructed track
195 if(pTrk->GetHMPIDsignal()<=0){//HMPID does not find anything reasonable for this track, assign 0.2 for all species
196 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++) pid[iPart]=1.0/AliPID::kSPECIES;
197 pTrk->SetHMPIDpid(pid);
198 continue;
199 }
200 Double_t pmod = pTrk->GetP();
201 Double_t hTot=0;
202 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++){
203 Double_t mass = AliPID::ParticleMass(iPart);
204 Double_t cosThetaTh = TMath::Sqrt(mass*mass+pmod*pmod)/(AliHMPIDParam::Instance()->MeanIdxRad()*pmod);
a1d55ff3 205 if(cosThetaTh<1) //calculate the height of theoretical theta ckov on the gaus of experimental one
206 h[iPart] =TMath::Gaus(TMath::ACos(cosThetaTh),pTrk->GetHMPIDsignal(),TMath::Sqrt(pTrk->GetHMPIDchi2()),kTRUE);
d3da6dc4 207 else //beta < 1/ref. idx. => no light at all
208 h[iPart] =0 ;
209 hTot +=h[iPart]; //total height of all theoretical heights for normalization
210 }//species loop
211
212 Double_t hMin=TMath::Gaus(pTrk->GetHMPIDsignal()-4*TMath::Sqrt(pTrk->GetHMPIDchi2()),pTrk->GetHMPIDsignal(),TMath::Sqrt(pTrk->GetHMPIDchi2()),kTRUE);//5 sigma protection
213
214 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++)//species loop to assign probabilities
215 if(hTot>hMin)
216 pid[iPart]=h[iPart]/hTot;
217 else //all theoretical values are far away from experemental one
218 pid[iPart]=1.0/AliPID::kSPECIES;
219 pTrk->SetHMPIDpid(pid);
220 }//ESD tracks loop
a1d55ff3 221}//FillESD()