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 #include "AliRICHReconstructor.h" //class header
17 #include "AliRICH.h" //Reconstruct(...)
18 #include <AliRawReader.h> //Reconstruct(...)
19 #include <AliRun.h> //ConvertDigits uses gAlice
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()
29 #include <TPolyMarker.h> //Test()
30 ClassImp(AliRICHReconstructor)
32 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33 void AliRICHReconstructor::CluQA(AliRunLoader *pAL)
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;}
42 pAL->LoadKinematics();
43 // AliStack *pStack=pAL->Stack();
44 TH1::AddDirectory(kFALSE);
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);
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 );
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());
60 TClonesArray *pCluLst=new TClonesArray("AliRICHCluster");//tmp list of clusters
62 for(Int_t iEvtN=0; iEvtN<iNevt; iEvtN++){
64 pRL->TreeD()->GetEntry(0);
65 for(Int_t iChN=1;iChN<=AliRICHParam::kNch;iChN++){//chambers loop
66 if(pRich->Digs(iChN)->GetEntriesFast()>0) Dig2Clu(pRich->Digs(iChN),pCluLst,kFALSE);//cluster finder for the current chamber if any digits present
69 for(Int_t iCluN=0 ; iCluN < pCluLst->GetEntriesFast() ; iCluN++){
70 AliRICHCluster *pClu = (AliRICHCluster*)pCluLst->At(iCluN);
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;
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
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
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);
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();
87 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88 void AliRICHReconstructor::CheckPR()
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");
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);
106 pFile->Write();pFile->Close();
108 //__________________________________________________________________________________________________
109 void AliRICHReconstructor::Dig2Clu(TClonesArray *pDigLst,TClonesArray *pCluLst,Bool_t isTryUnfold)
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
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
121 digMap( pDig->PadX(), pDig->PadY() )=iDigN; //fill the map, (padx,pady) cell takes digit index
122 } //digits loop to fill digits map
124 AliRICHCluster clu; //tmp cluster to be used as current
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
134 //__________________________________________________________________________________________________
135 void AliRICHReconstructor::FormClu(AliRICHCluster *pClu,AliRICHDigit *pDig,TClonesArray *pDigLst,TMatrixF *pDigMap)
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
141 pClu->DigAdd(pDig);//take this digit in cluster
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
149 //__________________________________________________________________________________________________
150 void AliRICHReconstructor::Reconstruct(AliRunLoader *pAL)const
152 //Invoked by AliReconstruction to convert digits to clusters i.e. reconstruct simulated data
153 //Arguments: pAL - ALICE run loader pointer
155 AliDebug(1,"Start.");
156 AliLoader *pRL=pAL->GetDetectorLoader("RICH");
157 AliRICH *pRich=(AliRICH*)pAL->GetAliRun()->GetDetector("RICH");//get pointers for RICH and RICH loader
159 pRL->LoadRecPoints("recreate");
161 for(Int_t iEvtN=0;iEvtN<pAL->GetNumberOfEvents();iEvtN++){//events loop
162 pAL->GetEvent(iEvtN); AliDebug(1,Form("Processing event %i...",iEvtN)); //switch current directory to next event
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
167 pRL->TreeR()->Fill(); //fill tree for current event
168 pRL->WriteRecPoints("OVERWRITE");//write out clusters for current event
169 pRich->DigReset(); pRich->CluReset();
173 pRL->UnloadRecPoints();
176 }//Reconstruct(for simulated digits)
177 //__________________________________________________________________________________________________
178 void AliRICHReconstructor::Reconstruct(AliRunLoader *pAL,AliRawReader* pRR)const
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
184 AliLoader *pRL=pAL->GetDetectorLoader("RICH"); AliRICH *pRich=(AliRICH*)pAL->GetAliRun()->GetDetector("RICH");//get pointers for RICH and RICH loader
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
190 while(pRR->NextEvent()){//events loop
191 pAL->GetEvent(iEvtN++);
192 pRL->MakeTree("R"); pRich->MakeBranch("R");
194 for(Int_t iChN=1;iChN<=7;iChN++){//chambers loop
195 pRR->Select("RICH",2*iChN-2,2*iChN-1);//select only DDL files for the current chamber
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);
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()));
201 new((*pDigList)[iDigCnt++]) AliRICHDigit(dig); //add this digit to the tmp list
203 if(iDigCnt) Dig2Clu(pDigList,pRich->Clus(iChN));//cluster finder for the current chamber if any digits present
205 pDigList->Delete(); iDigCnt=0;//clean up list of digits for the current chamber
207 pRL->TreeR()->Fill(); //fill tree for current event
208 pRL->WriteRecPoints("OVERWRITE");//write out clusters for current event
211 pRL->UnloadRecPoints();
212 }//Reconstruct raw data
213 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
214 void AliRICHReconstructor::Test(Bool_t isTryUnfold)
216 // Test the cluster finding algorithm by providing predifined set of digits
219 TClonesArray *pDigTst=new TClonesArray("AliRICHDigit"); TClonesArray *pCluTst=new TClonesArray("AliRICHCluster");
221 Int_t c,padx,pady,qdc;
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);
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);
235 Printf("Initial digits (1 ckov cluster and 1 mip cluster):"); pDigTst->Print();
236 Dig2Clu(pDigTst,pCluTst,isTryUnfold);
237 Printf("Resulting clusters (expecting to have 2):"); pCluTst->Print();
238 delete pDigTst; delete pCluTst;
240 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
241 void AliRICHReconstructor::Test(TClonesArray *pDigLst,Bool_t isTryUnfold)
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
246 TClonesArray *pCluLst=new TClonesArray("AliRICHCluster");
247 Dig2Clu(pDigLst,pCluLst,isTryUnfold);
249 Int_t iNdig=pDigLst->GetEntriesFast();
250 Int_t iNclu=pCluLst->GetEntriesFast();
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());
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());
268 AliRICHParam::DrawSectors();
271 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273 void AliRICHReconstructor::FillESD(AliRunLoader *, AliESD *pESD) const
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)
280 Double_t pid[AliPID::kSPECIES],h[AliPID::kSPECIES];
281 Double_t refIndex=AliRICHParam::Instance()->IdxC6F14(AliRICHParam::EckovMean());
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);
290 Double_t pmod = pTrack->GetP();
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);
298 else //beta < 1/ref. idx. => no light at all
300 hTot +=h[iPart]; //total height of all theoretical heights for normalization
303 Double_t hMin=TMath::Gaus(pTrack->GetRICHsignal()-4*TMath::Sqrt(pTrack->GetRICHchi2()),pTrack->GetRICHsignal(),TMath::Sqrt(pTrack->GetRICHchi2()),kTRUE);//5 sigma protection
305 for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++)//species loop to assign probabilities
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);
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