]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDReconstructor.cxx
Transfer of the initialisation of the QA Data objects in the framework; clean the...
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDReconstructor.cxx
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 //.
16 // HMPID base class to reconstruct an event
17 //.
18 //.
19 //.
20 #include "AliHMPIDReconstructor.h" //class header
21 #include "AliHMPID.h"              //Reconstruct() 
22 #include "AliHMPIDCluster.h"       //Dig2Clu()
23 #include "AliHMPIDPid.h"           //FillEsd() 
24 #include "AliHMPIDParam.h"         //FillEsd() 
25 #include <AliCDBEntry.h>           //ctor
26 #include <AliCDBManager.h>         //ctor
27 #include <AliESDEvent.h>           //FillEsd()
28 #include <AliRawReader.h>          //Reconstruct() for raw digits
29 #include <AliLog.h>                //
30 #include "AliHMPIDRawStream.h"     //ConvertDigits()
31 #include "AliHMPIDRecoParam.h"     //ctor
32 ClassImp(AliHMPIDReconstructor)
33
34 AliHMPIDRecoParam* AliHMPIDReconstructor::fgkRecoParam =0;  // 
35 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
36 AliHMPIDReconstructor::AliHMPIDReconstructor():AliReconstructor(),fUserCut(0),fDaqSig(0),fDig(0),fClu(0)
37 {
38 //
39 //ctor
40 //
41   AliHMPIDParam::Instance();                                                        //geometry loaded for reconstruction
42   fUserCut = new Int_t[7];
43   fClu=new TObjArray(AliHMPIDParam::kMaxCh+1); fClu->SetOwner(kTRUE);
44   fDig=new TObjArray(AliHMPIDParam::kMaxCh+1); fDig->SetOwner(kTRUE);
45   
46   for(int i=AliHMPIDParam::kMinCh;i<=AliHMPIDParam::kMaxCh;i++){ 
47     fDig->AddAt(new TClonesArray("AliHMPIDDigit",24000),i);
48     TClonesArray *pClus = new TClonesArray("AliHMPIDCluster",24000);
49     pClus->SetUniqueID(i);
50     fClu->AddAt(pClus,i);
51   }
52
53    if(fgkRecoParam!=0x0 && fgkRecoParam->GetUserCutMode()==kTRUE) {
54     for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) {
55       fUserCut[iCh] = fgkRecoParam->GetUserCut(iCh);
56       AliDebug(1,Form("UserCut successfully loaded (from RecoParam) for chamber %i -> %i ",iCh,fUserCut[iCh]));
57     }
58   }  
59   else {
60     for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) {
61       fUserCut[iCh] = 3;                                                                             // minimal requirement for sigma cut
62       AliDebug(1,Form("UserCut loaded from defaults for chamber %i -> %i ",iCh,fUserCut[iCh]));
63     }
64   } 
65
66   AliCDBEntry *pDaqSigEnt =AliCDBManager::Instance()->Get("HMPID/Calib/DaqSig");  //contains TObjArray of TObjArray 14 TMatrixF sigmas values for pads 
67   if(!pDaqSigEnt) AliFatal("No pedestals from DAQ!");
68   fDaqSig = (TObjArray*)pDaqSigEnt->GetObject();
69   for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){                  //chambers loop 
70     AliDebug(1,Form("DaqSigCut successfully loaded for chamber %i -> %i ",iCh,(Int_t)fDaqSig->At(iCh)->GetUniqueID()));
71   }
72 }//AliHMPIDReconstructor
73 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
74 void AliHMPIDReconstructor::Dig2Clu(TObjArray *pDigAll,TObjArray *pCluAll,Int_t *pUserCut,Bool_t isTryUnfold)
75 {
76 // Finds all clusters for a given digits list provided not empty. Currently digits list is a list of all digits for a single chamber.
77 // Puts all found clusters in separate lists, one per clusters. 
78 // Arguments: pDigAll     - list of digits for all chambers 
79 //            pCluAll     - list of clusters for all chambers
80 //            isTryUnfold - flag to choose between CoG and Mathieson fitting  
81 //  Returns: none    
82   TMatrixF padMap(AliHMPIDParam::kMinPx,AliHMPIDParam::kMaxPcx,AliHMPIDParam::kMinPy,AliHMPIDParam::kMaxPcy);  //pads map for single chamber 0..159 x 0..143 
83   
84   for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){                  //chambers loop 
85     TClonesArray *pDigCur=(TClonesArray*)pDigAll->At(iCh);                                //get list of digits for current chamber
86     if(pDigCur->GetEntriesFast()==0) continue;                                            //no digits for current chamber
87   
88     padMap=(Float_t)-1;                                                                   //reset map to -1 (means no digit for this pad)  
89     TClonesArray *pCluCur=(TClonesArray*)pCluAll->At(iCh);                                //get list of clusters for current chamber
90     
91     for(Int_t iDig=0;iDig<pDigCur->GetEntriesFast();iDig++){                              //digits loop to fill pads map
92       AliHMPIDDigit *pDig= (AliHMPIDDigit*)pDigCur->At(iDig);                             //get current digit
93       padMap( pDig->PadChX(), pDig->PadChY() )=iDig;                                      //fill the map, (padx,pady) cell takes digit index
94     }//digits loop to fill digits map 
95     
96     AliHMPIDCluster clu;                                                                  //tmp cluster to be used as current
97     for(Int_t iDig=0;iDig<pDigCur->GetEntriesFast();iDig++){                              //digits loop for current chamber
98       AliHMPIDDigit *pDig=(AliHMPIDDigit*)pDigCur->At(iDig);                              //take current digit
99       if(!(pDig=UseDig(pDig->PadChX(),pDig->PadChY(),pDigCur,&padMap))) continue;         //this digit is already taken in FormClu(), go after next digit
100       FormClu(&clu,pDig,pDigCur,&padMap);                                                 //form cluster starting from this digit by recursion
101       clu.Solve(pCluCur,pUserCut,isTryUnfold);                                 //solve this cluster and add all unfolded clusters to provided list  
102       clu.Reset();                                                                        //empty current cluster
103     }//digits loop for current chamber
104   }//chambers loop
105 }//Dig2Clu()
106 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107 void  AliHMPIDReconstructor::FormClu(AliHMPIDCluster *pClu,AliHMPIDDigit *pDig,TClonesArray *pDigLst,TMatrixF *pDigMap)
108 {
109 // Forms the initial cluster as a combination of all adjascent digits. Starts from the given digit then calls itself recursevly  for all neighbours.
110 // Arguments: pClu - pointer to cluster being formed
111 //   Returns: none   
112   pClu->DigAdd(pDig);//take this digit in cluster
113
114   Int_t cnt=0,cx[4],cy[4];
115   
116   if(pDig->PadPcX() != AliHMPIDParam::kMinPx){cx[cnt]=pDig->PadChX()-1; cy[cnt]=pDig->PadChY()  ;cnt++;}       //left
117   if(pDig->PadPcX() != AliHMPIDParam::kMaxPx){cx[cnt]=pDig->PadChX()+1; cy[cnt]=pDig->PadChY()  ;cnt++;}       //right
118   if(pDig->PadPcY() != AliHMPIDParam::kMinPy){cx[cnt]=pDig->PadChX()  ; cy[cnt]=pDig->PadChY()-1;cnt++;}       //down
119   if(pDig->PadPcY() != AliHMPIDParam::kMaxPy){cx[cnt]=pDig->PadChX()  ; cy[cnt]=pDig->PadChY()+1;cnt++;}       //up
120   
121   for (Int_t i=0;i<cnt;i++){//neighbours loop
122     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  
123   }//neighbours loop  
124 }//FormClu()
125 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
126 void AliHMPIDReconstructor::Reconstruct(TTree *pDigTree,TTree *pCluTree)const
127 {
128 //Invoked  by AliReconstruction to convert digits to clusters i.e. reconstruct simulated data
129 //Arguments: pDigTree - pointer to Digit tree
130 //           pCluTree - poitner to Cluster tree
131 //  Returns: none    
132   AliDebug(1,"Start.");
133   for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++) {
134     pCluTree->Branch(Form("HMPID%d",iCh),&((*fClu)[iCh]),7);
135     pDigTree->SetBranchAddress(Form("HMPID%d",iCh),&((*fDig)[iCh]));
136   }   
137   pDigTree->GetEntry(0);
138   Dig2Clu(fDig,fClu,fUserCut);     //cluster finder 
139   pCluTree->Fill();                //fill tree for current event
140   
141   for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){
142     fDig->At(iCh)->Clear();
143     fClu->At(iCh)->Clear();
144   }
145   
146   AliDebug(1,"Stop.");      
147 }//Reconstruct(for simulated digits)
148 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
149 void AliHMPIDReconstructor::ConvertDigits(AliRawReader *pRR,TTree *pDigTree)const
150 {
151 //Invoked  by AliReconstruction to convert raw digits from DDL files to digits
152 //Arguments: pRR - ALICE raw reader pointer
153 //           pDigTree - pointer to Digit tree
154 //  Returns: none    
155   AliDebug(1,"Start.");
156 //  Int_t digcnt=0;
157   
158   Int_t iDigCnt[7]={0,0,0,0,0,0,0};
159
160   for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){
161     pDigTree->Branch(Form("HMPID%d",iCh),&((*fDig)[iCh]));
162   }
163     
164   AliHMPIDRawStream stream(pRR);    
165   
166   while(stream.Next())
167   {
168     Int_t ch = AliHMPIDParam::DDL2C(stream.GetDDLNumber());
169     for(Int_t iPad=0;iPad<stream.GetNPads();iPad++) {
170       AliHMPIDDigit dig(stream.GetPadArray()[iPad],stream.GetChargeArray()[iPad]);
171       if(!IsDigSurvive(&dig)) continue; 
172       new((*((TClonesArray*)fDig->At(ch)))[iDigCnt[ch]++]) AliHMPIDDigit(dig); //add this digit to the tmp list 
173     }
174   }
175   
176   pDigTree->Fill();
177   
178   for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++)fDig->At(iCh)->Clear();
179   
180   AliDebug(1,"Stop.");
181 }//Reconstruct digits from raw digits
182 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
183 void AliHMPIDReconstructor::FillESD(TTree */*digitsTree*/, TTree */*clustersTree*/, AliESDEvent *pESD) const
184 {
185 // Fill ESD with all the infos from HMPID
186 // Probability vector from AliHMPIDPid
187 //...
188   AliHMPIDPid pID;
189   Double_t prob[AliPID::kSPECIES];
190   
191   for(Int_t iTrk=0;iTrk<pESD->GetNumberOfTracks();iTrk++){//ESD tracks loop
192     AliESDtrack *pTrk = pESD->GetTrack(iTrk);// get next reconstructed track
193     pID.FindPid(pTrk,AliPID::kSPECIES,prob);
194     pTrk->SetHMPIDpid(prob);
195   }//ESD tracks loop
196   
197 }//FillESD()