]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDParam.cxx
Fixing the decoding of regional header bits.
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDParam.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 #include "AliHMPIDParam.h"  //class header
16 #include "AliHMPIDDigit.h"  //ctor
17 #include "AliLog.h"         //general
18 #include <AliRunLoader.h>   //Stack()
19 #include <AliStack.h>       //Stack()
20 #include <TLatex.h>         //TestTrans()  
21 #include <TView.h>          //TestTrans()
22 #include <TPolyMarker3D.h>  //TestTrans()
23 #include <TRotation.h>
24 #include <TParticle.h>      //Stack()    
25 #include <TGeoPhysicalNode.h> //ctor
26 #include <TGeoBBox.h>
27 ClassImp(AliHMPIDParam)
28
29
30 // Mathieson constant definition
31 const Double_t AliHMPIDParam::fgkD     = 0.222500;  // ANODE-CATHODE distance 0.445/2
32 //                                                                                          K3 = 0.66 along the wires (anode-cathode/wire pitch=0.5625)
33 const Double_t AliHMPIDParam::fgkSqrtK3x = TMath::Sqrt(0.66);
34 const Double_t AliHMPIDParam::fgkK2x     = TMath::PiOver2()*(1 - 0.5*fgkSqrtK3x);
35 const Double_t AliHMPIDParam::fgkK1x     = 0.25*fgkK2x*fgkSqrtK3x/TMath::ATan(fgkSqrtK3x);
36 const Double_t AliHMPIDParam::fgkK4x     = fgkK1x/(fgkK2x*fgkSqrtK3x);
37 //                                                                                          K3 = 0.87 along the wires (anode-cathode/wire pitch=0.5625)
38 const Double_t AliHMPIDParam::fgkSqrtK3y = TMath::Sqrt(0.87);
39 const Double_t AliHMPIDParam::fgkK2y     = TMath::PiOver2()*(1 - 0.5*fgkSqrtK3y);
40 const Double_t AliHMPIDParam::fgkK1y     = 0.25*fgkK2y*fgkSqrtK3y/TMath::ATan(fgkSqrtK3y);
41 const Double_t AliHMPIDParam::fgkK4y     = fgkK1y/(fgkK2y*fgkSqrtK3y);
42 //
43   
44
45 Float_t AliHMPIDParam::fgkMinPcX[]={0.,0.,0.,0.,0.,0.};
46 Float_t AliHMPIDParam::fgkMaxPcX[]={0.,0.,0.,0.,0.,0.};
47 Float_t AliHMPIDParam::fgkMinPcY[]={0.,0.,0.,0.,0.,0.};
48 Float_t AliHMPIDParam::fgkMaxPcY[]={0.,0.,0.,0.,0.,0.};
49
50 Float_t AliHMPIDParam::fgCellX=0.;
51 Float_t AliHMPIDParam::fgCellY=0.;
52
53 Float_t AliHMPIDParam::fgPcX=0;
54 Float_t AliHMPIDParam::fgPcY=0;
55
56 Float_t AliHMPIDParam::fgAllX=0;
57 Float_t AliHMPIDParam::fgAllY=0;
58
59 Bool_t AliHMPIDParam::fgInstanceType=kTRUE;  
60
61 AliHMPIDParam* AliHMPIDParam::fgInstance=0x0;        //singleton pointer               
62
63 Int_t AliHMPIDParam::fgSigmas=4;
64
65 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 AliHMPIDParam::AliHMPIDParam(Bool_t noGeo=kFALSE):
67   TNamed("HmpidParam","default version"),
68   fX(0), fY(0), fRadNmean(0)
69 {
70 // Here all the intitializition is taken place when AliHMPIDParam::Instance() is invoked for the first time.
71 // In particular, matrices to be used for LORS<->MARS trasnformations are initialized from TGeo structure.    
72 // Note that TGeoManager should be already initialized from geometry.root file  
73
74
75   fRadNmean = MeanIdxRad(); //initialization of the running ref. index of freon
76   
77   Float_t dead=2.6;// cm of the dead zones between PCs-> See 2CRC2099P1
78
79
80   if(noGeo==kTRUE) fgInstanceType=kFALSE;                                                   //instance from ideal geometry, no actual geom is present
81     
82   if(noGeo==kFALSE && !gGeoManager)  
83   {
84     TGeoManager::Import("geometry.root");
85     if(!gGeoManager) AliFatal("!!!!!!No geometry loaded!!!!!!!");
86   }
87   
88   fgCellX=0.8;fgCellY=0.84;
89   
90   if(!noGeo==kTRUE){
91     TGeoVolume *pCellVol = gGeoManager->GetVolume("Hcel");
92     if(pCellVol) {
93       TGeoBBox *bcell = (TGeoBBox *)pCellVol->GetShape();
94       fgCellX=2.*bcell->GetDX(); fgCellY = 2.*bcell->GetDY();  // overwrite the values with the read ones
95     }
96   }    
97   fgPcX=80.*fgCellX; fgPcY = 48.*fgCellY;
98   fgAllX=2.*fgPcX+dead;
99   fgAllY=3.*fgPcY+2.*dead;
100
101   fgkMinPcX[1]=fgPcX+dead; fgkMinPcX[3]=fgkMinPcX[1];  fgkMinPcX[5]=fgkMinPcX[3];
102   fgkMaxPcX[0]=fgPcX; fgkMaxPcX[2]=fgkMaxPcX[0];  fgkMaxPcX[4]=fgkMaxPcX[2];
103   fgkMaxPcX[1]=fgAllX; fgkMaxPcX[3]=fgkMaxPcX[1];  fgkMaxPcX[5]=fgkMaxPcX[3];
104
105   fgkMinPcY[2]=fgPcY+dead; fgkMinPcY[3]=fgkMinPcY[2];  
106   fgkMinPcY[4]=2.*fgPcY+2.*dead; fgkMinPcY[5]=fgkMinPcY[4];
107   fgkMaxPcY[0]=fgPcY; fgkMaxPcY[1]=fgkMaxPcY[0];  
108   fgkMaxPcY[2]=2.*fgPcY+dead; fgkMaxPcY[3]=fgkMaxPcY[2]; 
109   fgkMaxPcY[4]=fgAllY; fgkMaxPcY[5]=fgkMaxPcY[4];   
110     
111   fX=0.5*SizeAllX();
112   fY=0.5*SizeAllY();
113   
114   for(Int_t i=kMinCh;i<=kMaxCh;i++) 
115     if(gGeoManager && gGeoManager->IsClosed()) {
116       TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(Form("/HMPID/Chamber%i",i));
117       if (!pne) {
118         AliErrorClass(Form("The symbolic volume %s does not correspond to any physical entry!",Form("HMPID_%i",i)));
119         fM[i]=new TGeoHMatrix;
120         IdealPosition(i,fM[i]);
121       } else {
122         TGeoPhysicalNode *pnode = pne->GetPhysicalNode();
123         if(pnode) fM[i]=new TGeoHMatrix(*(pnode->GetMatrix()));
124         else {
125           fM[i]=new TGeoHMatrix;
126           IdealPosition(i,fM[i]);
127         }
128       }
129     } else{
130       fM[i]=new TGeoHMatrix;
131       IdealPosition(i,fM[i]);
132     } 
133   fgInstance=this; 
134 }//ctor
135 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136 void AliHMPIDParam::Print(Option_t* opt) const
137 {
138 // print some usefull (hopefully) info on some internal guts of HMPID parametrisation 
139   
140   for(Int_t i=0;i<7;i++) fM[i]->Print(opt);
141 }//Print()
142 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
143 void AliHMPIDParam::IdealPosition(Int_t iCh, TGeoHMatrix *pMatrix)
144 {
145 // Construct ideal position matrix for a given chamber
146 // Arguments: iCh- chamber ID; pMatrix- pointer to precreated unity matrix where to store the results
147 //   Returns: none
148   const Double_t kAngHor=19.5;        //  horizontal angle between chambers  19.5 grad
149   const Double_t kAngVer=20;          //  vertical angle between chambers    20   grad     
150   const Double_t kAngCom=30;          //  common HMPID rotation with respect to x axis  30   grad     
151   const Double_t kTrans[3]={490,0,0}; //  center of the chamber is on window-gap surface
152   pMatrix->RotateY(90);               //  rotate around y since initial position is in XY plane -> now in YZ plane
153   pMatrix->SetTranslation(kTrans);    //  now plane in YZ is shifted along x 
154   switch(iCh){
155     case 0:                pMatrix->RotateY(kAngHor);  pMatrix->RotateZ(-kAngVer);  break; //right and down 
156     case 1:                                            pMatrix->RotateZ(-kAngVer);  break; //down              
157     case 2:                pMatrix->RotateY(kAngHor);                               break; //right 
158     case 3:                                                                         break; //no rotation
159     case 4:                pMatrix->RotateY(-kAngHor);                              break; //left   
160     case 5:                                            pMatrix->RotateZ(kAngVer);   break; //up
161     case 6:                pMatrix->RotateY(-kAngHor); pMatrix->RotateZ(kAngVer);   break; //left and up 
162   }
163   pMatrix->RotateZ(kAngCom);     //apply common rotation  in XY plane    
164    
165 }
166 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167 Int_t AliHMPIDParam::Stack(Int_t evt,Int_t tid)
168 {
169 // Prints some useful info from stack
170 // Arguments: evt - event number. if not -1 print info only for that event
171 //            tid - track id. if not -1 then print it and all it's mothers if any   
172 //   Returns: mother tid of the given tid if any
173   AliRunLoader *pAL=AliRunLoader::Open(); 
174   if(pAL->LoadHeader()) return -1;
175   if(pAL->LoadKinematics()) return -1;
176   
177   Int_t mtid=-1;
178   Int_t iNevt=pAL->GetNumberOfEvents();
179   
180   for(Int_t iEvt=0;iEvt<iNevt;iEvt++){//events loop
181     if(evt!=-1 && evt!=iEvt) continue; //in case one needs to print the requested event, ignore all others
182     pAL->GetEvent(iEvt);    
183     AliStack *pStack=pAL->Stack();  
184     if(tid==-1){                        //print all tids for this event
185       for(Int_t i=0;i<pStack->GetNtrack();i++) pStack->Particle(i)->Print();
186           Printf("totally %i tracks including %i primaries for event %i out of %i event(s)",
187           pStack->GetNtrack(),pStack->GetNprimary(),iEvt,iNevt);
188     }else{                              //print only this tid and it;s mothers
189       if(tid<0 || tid>pStack->GetNtrack()) {Printf("Wrong tid, valid tid range for event %i is 0-%i",iEvt,pStack->GetNtrack());break;}
190       TParticle *pTrack=pStack->Particle(tid); mtid=pTrack->GetFirstMother();
191       TString str=pTrack->GetName();
192       while((tid=pTrack->GetFirstMother()) >= 0){
193         pTrack=pStack->Particle(tid);
194         str+=" from ";str+=pTrack->GetName();
195       } 
196     }//if(tid==-1)      
197   }//events loop
198   pAL->UnloadHeader();  pAL->UnloadKinematics();
199   return mtid;
200 }
201 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
202 Int_t AliHMPIDParam::StackCount(Int_t pid,Int_t evt)
203 {
204 // Counts total number of particles of given sort (including secondary) for a given event
205   AliRunLoader *pAL=AliRunLoader::Open(); 
206   pAL->GetEvent(evt);    
207   if(pAL->LoadHeader()) return 0;
208   if(pAL->LoadKinematics()) return 0;
209   AliStack *pStack=pAL->Stack();
210   
211   Int_t iCnt=0;
212   for(Int_t i=0;i<pStack->GetNtrack();i++) if(pStack->Particle(i)->GetPdgCode()==pid) iCnt++;
213   
214   pAL->UnloadHeader();  pAL->UnloadKinematics();
215   return iCnt;
216 }
217 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
218 Double_t AliHMPIDParam::Sigma2(Double_t trkTheta,Double_t trkPhi,Double_t ckovTh, Double_t ckovPh)
219 {
220 // Analithical calculation of total error (as a sum of localization, geometrical and chromatic errors) on Cerenkov angle for a given Cerenkov photon 
221 // created by a given MIP. Fromulae according to CERN-EP-2000-058 
222 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
223 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
224 //            MIP beta
225 //   Returns: absolute error on Cerenkov angle, [radians]    
226   
227   TVector3 v(-999,-999,-999);
228   Double_t trkBeta = 1./(TMath::Cos(ckovTh)*GetRefIdx());
229   
230   if(trkBeta > 1) trkBeta = 1;                 //protection against bad measured thetaCer  
231   if(trkBeta < 0) trkBeta = 0.0001;            //
232
233   v.SetX(SigLoc (trkTheta,trkPhi,ckovTh,ckovPh,trkBeta));
234   v.SetY(SigGeom(trkTheta,trkPhi,ckovTh,ckovPh,trkBeta));
235   v.SetZ(SigCrom(trkTheta,trkPhi,ckovTh,ckovPh,trkBeta));
236
237   return v.Mag2();
238 }
239 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
240 Double_t AliHMPIDParam::SigLoc(Double_t trkTheta,Double_t trkPhi,Double_t thetaC, Double_t phiC,Double_t betaM)
241 {
242 // Analitical calculation of localization error (due to finite segmentation of PC) on Cerenkov angle for a given Cerenkov photon 
243 // created by a given MIP. Fromulae according to CERN-EP-2000-058 
244 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
245 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
246 //            MIP beta
247 //   Returns: absolute error on Cerenkov angle, [radians]    
248   
249   Double_t phiDelta = phiC - trkPhi;
250
251   Double_t sint     = TMath::Sin(trkTheta);
252   Double_t cost     = TMath::Cos(trkTheta);
253   Double_t sinf     = TMath::Sin(trkPhi);
254   Double_t cosf     = TMath::Cos(trkPhi);
255   Double_t sinfd    = TMath::Sin(phiDelta);
256   Double_t cosfd    = TMath::Cos(phiDelta);
257   Double_t tantheta = TMath::Tan(thetaC);
258   
259   Double_t alpha =cost-tantheta*cosfd*sint;                                                 // formula (11)
260   Double_t k = 1.-GetRefIdx()*GetRefIdx()+alpha*alpha/(betaM*betaM);        // formula (after 8 in the text)
261   if (k<0) return 1e10;
262   Double_t mu =sint*sinf+tantheta*(cost*cosfd*sinf+sinfd*cosf);                             // formula (10)
263   Double_t e  =sint*cosf+tantheta*(cost*cosfd*cosf-sinfd*sinf);                             // formula (9)
264
265   Double_t kk = betaM*TMath::Sqrt(k)/(GapThick()*alpha);                            // formula (6) and (7)
266   Double_t dtdxc = kk*(k*(cosfd*cosf-cost*sinfd*sinf)-(alpha*mu/(betaM*betaM))*sint*sinfd); // formula (6)           
267   Double_t dtdyc = kk*(k*(cosfd*sinf+cost*sinfd*cosf)+(alpha* e/(betaM*betaM))*sint*sinfd); // formula (7)            pag.4
268
269   Double_t errX = 0.2,errY=0.25;                                                            //end of page 7
270   return  TMath::Sqrt(errX*errX*dtdxc*dtdxc + errY*errY*dtdyc*dtdyc);
271 }
272 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273 Double_t AliHMPIDParam::SigCrom(Double_t trkTheta,Double_t trkPhi,Double_t thetaC, Double_t phiC,Double_t betaM)
274 {
275 // Analitical calculation of chromatic error (due to lack of knowledge of Cerenkov photon energy) on Cerenkov angle for a given Cerenkov photon 
276 // created by a given MIP. Fromulae according to CERN-EP-2000-058 
277 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
278 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
279 //            MIP beta
280 //   Returns: absolute error on Cerenkov angle, [radians]    
281   
282   Double_t phiDelta = phiC - trkPhi;
283
284   Double_t sint     = TMath::Sin(trkTheta);
285   Double_t cost     = TMath::Cos(trkTheta);
286   Double_t cosfd    = TMath::Cos(phiDelta);
287   Double_t tantheta = TMath::Tan(thetaC);
288   
289   Double_t alpha =cost-tantheta*cosfd*sint;                                                 // formula (11)
290   Double_t dtdn = cost*GetRefIdx()*betaM*betaM/(alpha*tantheta);                    // formula (12)
291             
292 //  Double_t f = 0.00928*(7.75-5.635)/TMath::Sqrt(12.);
293   Double_t f = 0.0172*(7.75-5.635)/TMath::Sqrt(24.);
294
295   return f*dtdn;
296 }//SigCrom()
297 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
298 Double_t AliHMPIDParam::SigGeom(Double_t trkTheta,Double_t trkPhi,Double_t thetaC, Double_t phiC,Double_t betaM)
299 {
300 // Analitical calculation of geometric error (due to lack of knowledge of creation point in radiator) on Cerenkov angle for a given Cerenkov photon 
301 // created by a given MIP. Formulae according to CERN-EP-2000-058 
302 // Arguments: Cerenkov and azimuthal angles for Cerenkov photon, [radians]
303 //            dip and azimuthal angles for MIP taken at the entrance to radiator, [radians]        
304 //            MIP beta
305 //   Returns: absolute error on Cerenkov angle, [radians]    
306
307   Double_t phiDelta = phiC - trkPhi;
308
309   Double_t sint     = TMath::Sin(trkTheta);
310   Double_t cost     = TMath::Cos(trkTheta);
311   Double_t sinf     = TMath::Sin(trkPhi);
312   Double_t cosfd    = TMath::Cos(phiDelta);
313   Double_t costheta = TMath::Cos(thetaC);
314   Double_t tantheta = TMath::Tan(thetaC);
315   
316   Double_t alpha =cost-tantheta*cosfd*sint;                                                  // formula (11)
317   
318   Double_t k = 1.-GetRefIdx()*GetRefIdx()+alpha*alpha/(betaM*betaM);         // formula (after 8 in the text)
319   if (k<0) return 1e10;
320
321   Double_t eTr = 0.5*RadThick()*betaM*TMath::Sqrt(k)/(GapThick()*alpha);     // formula (14)
322   Double_t lambda = 1.-sint*sint*sinf*sinf;                                                  // formula (15)
323
324   Double_t c1 = 1./(1.+ eTr*k/(alpha*alpha*costheta*costheta));                              // formula (13.a)
325   Double_t c2 = betaM*TMath::Power(k,1.5)*tantheta*lambda/(GapThick()*alpha*alpha);  // formula (13.b)
326   Double_t c3 = (1.+eTr*k*betaM*betaM)/((1+eTr)*alpha*alpha);                                // formula (13.c)
327   Double_t c4 = TMath::Sqrt(k)*tantheta*(1-lambda)/(GapThick()*betaM);               // formula (13.d)
328   Double_t dtdT = c1 * (c2+c3*c4);
329   Double_t trErr = RadThick()/(TMath::Sqrt(12.)*cost);
330
331   return trErr*dtdT;
332 }//SigGeom()
333 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++