]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RICH/AliRICHReconstructor.cxx
track matching macros from Alberto
[u/mrichter/AliRoot.git] / RICH / AliRICHReconstructor.cxx
CommitLineData
121a60bd 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 **************************************************************************/
15
0422a446 16#include "AliRICHReconstructor.h" //class header
122efc54 17#include "AliRICH.h" //Reconstruct(...)
0422a446 18#include <AliRawReader.h> //Reconstruct(...)
0422a446 19#include <AliRun.h> //ConvertDigits uses gAlice
db910db9 20#include <AliESD.h> //RichAna()
21#include <AliStack.h> //RichAna()
22#include <TFile.h> //RichAna()
23#include <TFile.h> //RichAna()
24#include <TParticle.h> //RichAna()
25#include <TH1F.h> //CluQA()
26#include <TH2F.h> //CluQA()
27#include <TCanvas.h> //CluQA()
28#include <TNtupleD.h> //CheckPR()
2714766e 29#include <TPolyMarker.h> //Test()
121a60bd 30ClassImp(AliRICHReconstructor)
31
2714766e 32//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db910db9 33void AliRICHReconstructor::CluQA(AliRunLoader *pAL)
34{
35// Quality assesment plots for clusters.
36// This methode takes list of digits and form list of clusters again in order to
37// calculate cluster shape and cluster particle mixture
38 AliLoader *pRL=pAL->GetDetectorLoader("RICH"); AliRICH *pRich=(AliRICH*)pAL->GetAliRun()->GetDetector("RICH");//get pointers for RICH and RICH loader
39 Int_t iNevt=pAL->GetNumberOfEvents(); if(iNevt==0) {AliInfoClass("No events");return;}
40 if(pRL->LoadDigits()) {AliInfoClass("No digits file");return;}
41 pAL->LoadHeader();
42 pAL->LoadKinematics();
43// AliStack *pStack=pAL->Stack();
44 TH1::AddDirectory(kFALSE);
45
db910db9 46
f936e4b2 47 TH1F* pQ=new TH1F("RichCluQdc" ,"All QDC;q [QDC]" ,4000 ,0 ,4000);// QDC hists
48 TH1F* pCerQ=new TH1F("RichCluCerQdc" ,"Ckov QDC;q [QDC]" ,4000 ,0 ,4000);
49 TH1F* pMipQ=new TH1F("RichCluMipQdc" ,"MIP QDC;q [QDC]" ,4000 ,0 ,4000);
db910db9 50
f936e4b2 51 TH1F* pS=new TH1F("RichCluSize" ,"Cluster size;size" ,100 ,0 ,100 );// size hists
52 TH1F* pCerS=new TH1F("RichCluCerSize" ,"Ckov size;size" ,100 ,0 ,100 );
53 TH1F* pMipS=new TH1F("RichCluMipSize" ,"MIP size;size" ,100 ,0 ,100 );
54
55 TH2F* pM=new TH2F("RichCluMap" ,"Cluster map;x [cm];y [cm]" ,1000 ,0 ,AliRICHParam::PcSizeX(),1000,0,AliRICHParam::PcSizeY()); // maps
56 TH2F* pMipM=new TH2F("RichCluMipMap" ,"MIP map;x [cm];y [cm]" ,1000 ,0 ,AliRICHParam::PcSizeX(),1000,0,AliRICHParam::PcSizeY());
57 TH2F* pCerM=new TH2F("RichCluCerMap" ,"Ckov map;x [cm];y [cm]" ,1000 ,0 ,AliRICHParam::PcSizeX(),1000,0,AliRICHParam::PcSizeY());
db910db9 58
59
60 TClonesArray *pCluLst=new TClonesArray("AliRICHCluster");//tmp list of clusters
61
62 for(Int_t iEvtN=0; iEvtN<iNevt; iEvtN++){
63 pAL->GetEvent(iEvtN);
64 pRL->TreeD()->GetEntry(0);
f936e4b2 65 for(Int_t iChN=1;iChN<=AliRICHParam::kNch;iChN++){//chambers loop
db910db9 66 if(pRich->Digs(iChN)->GetEntriesFast()>0) Dig2Clu(pRich->Digs(iChN),pCluLst,kFALSE);//cluster finder for the current chamber if any digits present
67 }//chambers loop
68
db910db9 69 for(Int_t iCluN=0 ; iCluN < pCluLst->GetEntriesFast() ; iCluN++){
70 AliRICHCluster *pClu = (AliRICHCluster*)pCluLst->At(iCluN);
f936e4b2 71 Int_t cfm=0; for(Int_t iDig=0;iDig<pClu->Size();iDig++) cfm+=pClu->Dig(iDig)->Cfm(); //collect ckov-fee-mip structure of current cluster
72 Int_t iNckov=cfm/1000000; Int_t iNfee =cfm%1000000/1000; Int_t iNmip =cfm%1000000%1000;
73
db910db9 74 pQ ->Fill(pClu->Q()) ; pS ->Fill(pClu->Size()) ; pM ->Fill(pClu->X(),pClu->Y()); //all clusters
75 if(iNckov!=0 && iNfee==0 && iNmip==0) {pCerQ->Fill(pClu->Q()) ; pCerS->Fill(pClu->Size()) ; pCerM ->Fill(pClu->X(),pClu->Y());}//ckov only cluster
db910db9 76 if(iNckov==0 && iNfee==0 && iNmip!=0) {pMipQ->Fill(pClu->Q()) ; pMipS->Fill(pClu->Size()) ; pMipM ->Fill(pClu->X(),pClu->Y());}//mip only cluster
77
78 }//clusters loop
79 }//events loop
80
81 pRL->UnloadDigits(); pAL->UnloadKinematics(); pAL->UnloadHeader();
82 TCanvas *pC=new TCanvas("RichCluQA",Form("QA for cluster from %i events",iNevt),1000,900); pC->Divide(3,3);
f936e4b2 83 pC->cd(1); pM->Draw(); pC->cd(2); pQ->Draw(); pC->cd(3); pS->Draw();
84 pC->cd(4); pMipM->Draw(); pC->cd(5); pMipQ->Draw(); pC->cd(6); pMipS->Draw();
85 pC->cd(7); pCerM->Draw(); pC->cd(8); pCerQ->Draw(); pC->cd(9); pCerS->Draw();
db910db9 86}//CluQA()
2714766e 87//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db910db9 88void AliRICHReconstructor::CheckPR()
89{
90//Pattern recognition with stack particles
91 TFile *pFile = new TFile("$(HOME)/RPR.root","RECREATE","RICH Pattern Recognition");
92 TNtupleD *hn = new TNtupleD("hn","ntuple","Pmod:Charge:TrackTheta:TrackPhi:TrackX:TrackY:MinX:MinY:ChargeMIP:ThetaCerenkov:NPhotons:MipIndex:Chamber:Particle");
93// printf("\n\n");
94// printf("Pattern Recognition done for event %5i",0);
95 AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
96 AliMagF * magf = gAlice->Field();
97 AliTracker::SetFieldMap(magf,kTRUE);
98 for(Int_t iEvtN=0;iEvtN<pRich->GetLoader()->GetRunLoader()->GetNumberOfEvents();iEvtN++) {
99 pRich->GetLoader()->GetRunLoader()->GetEvent(iEvtN);
100 AliRICHTracker *tr = new AliRICHTracker();
101 tr->RecWithStack(hn);
102 AliInfoClass(Form("Pattern Recognition done for event %i \b",iEvtN));
103// printf("\b\b\b\b\b%5i",iEvtN+1);
104 }
105 printf("\n\n");
106 pFile->Write();pFile->Close();
107}
108//__________________________________________________________________________________________________
109void AliRICHReconstructor::Dig2Clu(TClonesArray *pDigLst,TClonesArray *pCluLst,Bool_t isTryUnfold)
110{
111//Finds all clusters for a given digits list provided not empty. Currently digits list is a list of all digits for a single chamber.
112//If pStack not 0 then also finds Ckov-Fee-Mip composition for formed clusters.
113//Puts all found clusters in the given clusters list.
114//Arguments: pDigLst - list of digits provided not empty
115// pCluLst - list of clusters, provided empty
116// isTryUnfold - flag to choose between CoG and Mathieson fitting
117// Returns: none
118 TMatrixF digMap(1,AliRICHParam::NpadsX(),1,AliRICHParam::NpadsY()); digMap=(Float_t)-1; //digit map for one chamber reseted to -1
119 for(Int_t iDigN=0 ; iDigN < pDigLst->GetEntriesFast() ; iDigN++){ //digits loop to fill digits map
120 AliRICHDigit *pDig= (AliRICHDigit*)pDigLst->At(iDigN); //get current digit
2714766e 121 digMap( pDig->PadX(), pDig->PadY() )=iDigN; //fill the map, (padx,pady) cell takes digit index
db910db9 122 } //digits loop to fill digits map
123
124 AliRICHCluster clu; //tmp cluster to be used as current
125
126 for(Int_t iDigN=0;iDigN<pDigLst->GetEntriesFast();iDigN++){ //digits loop to form clusters list
127 AliRICHDigit *pDig=(AliRICHDigit*)pDigLst->At(iDigN); //take current digit
128 if(!(pDig=UseDig(pDig->PadX(),pDig->PadY(),pDigLst,&digMap))) continue; //this digit is already taken in FormClu(), go after next digit
129 FormClu(&clu,pDig,pDigLst,&digMap); //form cluster starting from this digit by recursion
130 clu.Solve(pCluLst,isTryUnfold); //solve this cluster and add all unfolded clusters to provided list
131 clu.Reset(); //empty current cluster
132 } //digits loop to form clusters list
133}//Dig2Clu()
134//__________________________________________________________________________________________________
135void AliRICHReconstructor::FormClu(AliRICHCluster *pClu,AliRICHDigit *pDig,TClonesArray *pDigLst,TMatrixF *pDigMap)
136{
137//Forms the initial cluster as a sum of all adjascent digits. Starts from the given digit
138//then calls itself recursevly for all neighbours.
139//Arguments: pClu - pointer to cluster being formed
140// Returns: none
141 pClu->DigAdd(pDig);//take this digit in cluster
142
143 Int_t x[4],y[4];
144
145 Int_t iNnei=AliRICHParam::PadNeighbours(pDig->PadX(),pDig->PadY(),x,y);//returns in x,y all possible neighbours of the given padx,pady
146 for (Int_t i=0;i<iNnei;i++)
147 if((pDig=UseDig(x[i],y[i],pDigLst,pDigMap))) FormClu(pClu,pDig,pDigLst,pDigMap); //check if this neighbour hit and mark it as taken
148}//FormClu()
149//__________________________________________________________________________________________________
150void AliRICHReconstructor::Reconstruct(AliRunLoader *pAL)const
151{
152//Invoked by AliReconstruction to convert digits to clusters i.e. reconstruct simulated data
153//Arguments: pAL - ALICE run loader pointer
154// Returns: none
155 AliDebug(1,"Start.");
194e649f 156 AliLoader *pRL=pAL->GetDetectorLoader("RICH");
157 AliRICH *pRich=(AliRICH*)pAL->GetAliRun()->GetDetector("RICH");//get pointers for RICH and RICH loader
db910db9 158 pRL->LoadDigits();
194e649f 159 pRL->LoadRecPoints("recreate");
db910db9 160
161 for(Int_t iEvtN=0;iEvtN<pAL->GetNumberOfEvents();iEvtN++){//events loop
4b10d461 162 pAL->GetEvent(iEvtN); AliDebug(1,Form("Processing event %i...",iEvtN)); //switch current directory to next event
db910db9 163 pRL->TreeD()->GetEntry(0); pRL->MakeTree("R"); pRich->MakeBranch("R"); //load digits to memory and create branches for clusters
164 for(Int_t iChN=1;iChN<=7;iChN++){//chambers loop
165 if(pRich->Digs(iChN)->GetEntriesFast()>0) Dig2Clu(pRich->Digs(iChN),pRich->Clus(iChN));//cluster finder for the current chamber if any digits present
166 }//chambers loop
167 pRL->TreeR()->Fill(); //fill tree for current event
168 pRL->WriteRecPoints("OVERWRITE");//write out clusters for current event
169 pRich->DigReset(); pRich->CluReset();
170 }//events loop
171
172 pRL->UnloadDigits();
173 pRL->UnloadRecPoints();
174
175 AliDebug(1,"Stop.");
176}//Reconstruct(for simulated digits)
177//__________________________________________________________________________________________________
0422a446 178void AliRICHReconstructor::Reconstruct(AliRunLoader *pAL,AliRawReader* pRR)const
179{
122efc54 180//Invoked by AliReconstruction to convert raw digits from DDL files to clusters
181//Arguments: pAL - ALICE run loader pointer
182// pRR - ALICE raw reader pointer
183// Returns: none
184 AliLoader *pRL=pAL->GetDetectorLoader("RICH"); AliRICH *pRich=(AliRICH*)pAL->GetAliRun()->GetDetector("RICH");//get pointers for RICH and RICH loader
0422a446 185
186 AliRICHDigit dig; //tmp digit, raw digit will be converted to it
187 TClonesArray *pDigList=new TClonesArray("AliRICHDigit"); Int_t iDigCnt=0; //tmp list of digits for single chamber only
188
189 Int_t iEvtN=0;
190 while(pRR->NextEvent()){//events loop
191 pAL->GetEvent(iEvtN++);
192 pRL->MakeTree("R"); pRich->MakeBranch("R");
193
194 for(Int_t iChN=1;iChN<=7;iChN++){//chambers loop
362c9d61 195 pRR->Select("RICH",2*iChN-2,2*iChN-1);//select only DDL files for the current chamber
0422a446 196 UInt_t w32=0;
197 while(pRR->ReadNextInt(w32)){//raw records loop (in selected DDL files)
198 UInt_t ddl=pRR->GetDDLID(); //returns 0,1,2 ... 13
199 dig.Raw2Dig(ddl,w32);
db910db9 200 AliDebug(1,Form("Ch=%i DDL=%i raw=0x%x digit=(%3i,%3i,%3i,%3i) Q=%5.2f",iChN,ddl,w32,dig.C(),dig.S(),dig.PadX(),dig.PadY(),dig.Qdc()));
0422a446 201 new((*pDigList)[iDigCnt++]) AliRICHDigit(dig); //add this digit to the tmp list
202 }//raw records loop
db910db9 203 if(iDigCnt) Dig2Clu(pDigList,pRich->Clus(iChN));//cluster finder for the current chamber if any digits present
0422a446 204 pRR->Reset();
205 pDigList->Delete(); iDigCnt=0;//clean up list of digits for the current chamber
206 }//chambers loop
207 pRL->TreeR()->Fill(); //fill tree for current event
208 pRL->WriteRecPoints("OVERWRITE");//write out clusters for current event
db910db9 209 pRich->CluReset();
0422a446 210 }//events loop
211 pRL->UnloadRecPoints();
212}//Reconstruct raw data
2714766e 213//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
db910db9 214void AliRICHReconstructor::Test(Bool_t isTryUnfold)
215{
216// Test the cluster finding algorithm by providing predifined set of digits
217// Arguments: none
218// Returns: none
219 TClonesArray *pDigTst=new TClonesArray("AliRICHDigit"); TClonesArray *pCluTst=new TClonesArray("AliRICHCluster");
220 Int_t iDigCnt=0;
221 Int_t c,padx,pady,qdc;
222//ckov cluster
2714766e 223 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx= 89,pady=13),qdc= 10);
224 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx= 90,pady=13),qdc= 7);
225 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx= 90,pady=12),qdc= 6);
226 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx= 91,pady=12),qdc= 7);
db910db9 227//mip cluster
2714766e 228 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx= 99,pady=21),qdc= 9);
229 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx= 99,pady=22),qdc= 26);
230 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx=100,pady=21),qdc= 39);
231 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx=100,pady=22),qdc=109);
232 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx=100,pady=23),qdc= 7);
233 new((*pDigTst)[iDigCnt++]) AliRICHDigit(AliRICHDigit::P2A(c=1,padx=101,pady=22),qdc= 11);
db910db9 234
2714766e 235 Printf("Initial digits (1 ckov cluster and 1 mip cluster):"); pDigTst->Print();
db910db9 236 Dig2Clu(pDigTst,pCluTst,isTryUnfold);
2714766e 237 Printf("Resulting clusters (expecting to have 2):"); pCluTst->Print();
db910db9 238 delete pDigTst; delete pCluTst;
239}//Test()
2714766e 240//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
241void AliRICHReconstructor::Test(TClonesArray *pDigLst,Bool_t isTryUnfold)
242{
243// Test the cluster finding algorithm for given list of digits. Note that list of digits will not be deleted.
244// Arguments: pDigLst- list of digits
245// Returns: none
246 TClonesArray *pCluLst=new TClonesArray("AliRICHCluster");
247 Dig2Clu(pDigLst,pCluLst,isTryUnfold);
248
249 Int_t iNdig=pDigLst->GetEntriesFast();
250 Int_t iNclu=pCluLst->GetEntriesFast();
251
252 TH2F *pH2=new TH2F("RDH2",Form("Tst dig->clu Digs: %i Clus: %i;cm;cm",iNdig,iNclu),AliRICHParam::NpadsX(),0,AliRICHParam::PcSizeX(),AliRICHParam::NpadsY(),0,AliRICHParam::PcSizeY());
253 pH2->SetStats(kFALSE);
254 for(Int_t iDig=0;iDig < iNdig;iDig++) {//digits loop
255 AliRICHDigit *pDig = (AliRICHDigit*)pDigLst->At(iDig);
256 TVector2 x2=AliRICHParam::Pad2Loc(pDig->Pad());
257 pH2->Fill(x2.X(),x2.Y(),pDig->Qdc());
258 }//digits loop
259
260 TPolyMarker *pCluMarker=new TPolyMarker(iNclu); pCluMarker->SetMarkerStyle(5); pCluMarker->SetMarkerColor(kBlue);
261 for(Int_t iClu=0;iClu < iNclu;iClu++) {//clusters loop
262 AliRICHCluster *pClu = (AliRICHCluster*)pCluLst->At(iClu);
263 pCluMarker->SetNextPoint(pClu->X(),pClu->Y());
264 }//digits loop
265
266 pH2->Draw("col");
267 pCluMarker->Draw();
268 AliRICHParam::DrawSectors();
269 delete pCluLst;
270}//Test()
271//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
84093f6f 272
273void AliRICHReconstructor::FillESD(AliRunLoader *, AliESD *pESD) const
274{
275// Calculates probability to be a electron-muon-pion-kaon-proton
276// from the given Cerenkov angle and momentum assuming no initial particle composition
277// (i.e. apriory probability to be the particle of the given sort is the same for all sorts)
278
279 AliPID ppp; //needed
280 Double_t pid[AliPID::kSPECIES],h[AliPID::kSPECIES];
281 Double_t refIndex=AliRICHParam::Instance()->IdxC6F14(AliRICHParam::EckovMean());
282
283 for(Int_t iTrk=0;iTrk<pESD->GetNumberOfTracks();iTrk++){//ESD tracks loop
284 AliESDtrack *pTrack = pESD->GetTrack(iTrk);// get next reconstructed track
285 if(pTrack->GetRICHsignal()<=0){//RICH does not find anything reasonable for this track, assign 0.2 for all species
286 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++) pid[iPart]=1.0/AliPID::kSPECIES;
287 pTrack->SetRICHpid(pid);
288 continue;
289 }
290 Double_t pmod = pTrack->GetP();
291 Double_t hTot=0;
292 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++){
293 Double_t mass = AliPID::ParticleMass(iPart);
294 Double_t cosThetaTh = TMath::Sqrt(mass*mass+pmod*pmod)/(refIndex*pmod);
295 if(cosThetaTh<1) //calculate the height of theortical theta ckov on the gaus of experimental one
296 h[iPart] =TMath::Gaus(TMath::ACos(cosThetaTh),pTrack->GetRICHsignal(),TMath::Sqrt(pTrack->GetRICHchi2()),kTRUE);
297
298 else //beta < 1/ref. idx. => no light at all
299 h[iPart] =0 ;
300 hTot +=h[iPart]; //total height of all theoretical heights for normalization
301 }//species loop
302
a81bb7c2 303 Double_t hMin=TMath::Gaus(pTrack->GetRICHsignal()-4*TMath::Sqrt(pTrack->GetRICHchi2()),pTrack->GetRICHsignal(),TMath::Sqrt(pTrack->GetRICHchi2()),kTRUE);//5 sigma protection
84093f6f 304
305 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++)//species loop to assign probabilities
306 if(hTot>hMin)
307 pid[iPart]=h[iPart]/hTot;
308 else //all theoretical values are far away from experemental one
309 pid[iPart]=1.0/AliPID::kSPECIES;
310 pTrack->SetRICHpid(pid);
311 }//ESD tracks loop
312 //last line is to check if the nearest thetacerenkov to the teorethical one is within 5 sigma, otherwise no response (equal prob to every particle
313}//FillESD