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 **************************************************************************/
18 #include "AliAnalysisManager.h"
19 #include "AliInputEventHandler.h"
20 #include "AliMultiInputEventHandler.h"
21 #include "AliVEvent.h"
22 #include "AliESDEvent.h"
23 #include "AliAODEvent.h"
24 #include "AliESDCaloCluster.h"
25 #include "AliVParticle.h"
26 #include "AliVTrack.h"
27 #include "AliAODCluster.h"
28 #include "AliVCaloCells.h"
29 #include "AliOADBContainer.h"
30 #include "AliPHOSGeometry.h"
31 #include "AliAnalysisManager.h"
35 #include "AliPHOSClusterSelection.h"
37 AliPHOSClusterSelection::AliPHOSClusterSelection()
38 : fMinChargedParticleTrackDistance(-1.),
44 // Defaults to the most lenient selection allowable
48 AliPHOSClusterSelection::~AliPHOSClusterSelection()
52 Bool_t AliPHOSClusterSelection::IsSelected(AliVCluster* cluster) const
54 return IsSelectedCPV(cluster)
55 && IsSelectedUnfolded(cluster)
56 && IsSelectedDisp(cluster)
57 && IsSelectedTOF(cluster);
60 Bool_t AliPHOSClusterSelection::IsSelectedCPV(AliVCluster* cluster) const
62 if( 0 > fMinChargedParticleTrackDistance )//No selection on CPV
66 Bool_t cpvBit = true; //Changed to false if there is a matching track in the requested radius.
68 Double_t dx=cluster->GetTrackDx();//Position for Track matching
69 Double_t dz=cluster->GetTrackDz();
72 AliESDEvent* EventESD = dynamic_cast<AliESDEvent*> (AliPHOSClusterSelection::GetCurrentEvent());//dynamic cast to test for ESD or AOD
73 AliAODEvent* EventAOD = dynamic_cast<AliAODEvent*> (AliPHOSClusterSelection::GetCurrentEvent());
75 if(EventAOD) mf = EventAOD->GetMagneticField(); //Positive for ++ and negative for --
76 else if(EventESD) mf = EventESD->GetMagneticField(); //Positive for ++ and negative for --
80 AliESDCaloCluster * ESDcluster = static_cast<AliESDCaloCluster*> (cluster);//Know its ESD so static cast is fine?
81 TArrayI * itracks = ESDcluster-> GetTracksMatched() ;
82 if(itracks->GetSize()>0){
83 Int_t iTr = itracks->At(0);
84 if(iTr>=0 && iTr<EventESD->GetNumberOfTracks()){
85 AliVParticle* track = EventESD->GetTrack(iTr);
86 Double_t pt = track->Pt() ;
87 Short_t charge = track->Charge() ;
88 Double_t r = AliPHOSClusterSelection::TestCPV(dx, dz, pt, charge, mf);
89 cpvBit=(r>fMinChargedParticleTrackDistance) ;
96 AliAODCluster * AODcluster = static_cast<AliAODCluster*> (cluster);
97 int nTracksMatched = AODcluster->GetNTracksMatched();
98 if(nTracksMatched > 0) {
99 AliVTrack* track = dynamic_cast<AliVTrack*> (cluster->GetTrackMatched(0));
101 Double_t pt = track->Pt();
102 Short_t charge = track->Charge();
103 Double_t r = AliPHOSClusterSelection::TestCPV(dx, dz, pt, charge, mf);
104 cpvBit=(r>fMinChargedParticleTrackDistance) ;
113 Bool_t AliPHOSClusterSelection::IsSelectedUnfolded(AliVCluster* cluster) const
118 Bool_t NotUnfolded = cluster->GetNExMax()<2;//True if it was not unfolded
123 Bool_t AliPHOSClusterSelection::IsSelectedDisp(AliVCluster* cluster) const
128 Double_t m02 = 0.,m20 = 0.;
129 if(fIsCore<0){//No core calculation
130 m02 = cluster->GetM02();
131 m20 = cluster->GetM20();
132 return AliPHOSClusterSelection::TestLambda(cluster->E(),m20,m02) ;
135 AliVCaloCells* cells = static_cast<AliVCaloCells*> (AliPHOSClusterSelection::GetCurrentEvent()->GetPHOSCells());//Need the cells
136 AliPHOSClusterSelection::EvalCoreLambdas(cluster, cells, m02, m20);
137 return AliPHOSClusterSelection::TestLambda(cluster->E(),m20,m02);
143 Bool_t AliPHOSClusterSelection::IsSelectedTOF(AliVCluster* cluster) const
148 // Time of Flight (TOF)
149 Double_t tof = cluster->GetTOF();//Time of Flight for the cluster
150 return TMath::Abs(tof) < fMaxTOF;//True if the cut is passed
154 AliPHOSClusterSelection* AliPHOSClusterSelection::SetMinChargedParticleTrackDistance(Float_t distance)
156 // 'distance' set the minimal allowable distance between the cluster
157 // and the nearest extrapolated track.
158 // If 'distance' is negative, then all clusters are sellected, the selection
159 // being "not applied" or "disabled".
161 fMinChargedParticleTrackDistance = distance;
165 AliPHOSClusterSelection* AliPHOSClusterSelection::SetNotUnfolded(Bool_t notUnfolded)
167 //if notUnfolded true, it rejects Unfolded Clusters
168 fNotUnfolded = notUnfolded;
172 AliPHOSClusterSelection* AliPHOSClusterSelection::SetMaxDispR2(Float_t maxR2)
174 // 'maxR2' sets the maximum allowed dispersion.
175 // If 'maxR2' is negative, then all clusters are selected, the selection
176 // being "not applied" or "disabled".
182 AliPHOSClusterSelection* AliPHOSClusterSelection::SetIsCore(Bool_t isCore)
184 // 'isCore' sets wether core version of Disp is used. -1 gives no core.
190 AliPHOSClusterSelection* AliPHOSClusterSelection::SetMaxTOF(Float_t maxTOF)
192 // 'maxTOF' sets the maximum allowed time of flight for the cluster.
193 // If 'maxTOF' is negative, all clusters are selected and the selection is "disabled".
199 TString AliPHOSClusterSelection::ToString() const
201 // returns a string an quasi-unique string for whatever selection
202 // parameters the instance contains. The uniqueness of the string
203 // is limited by the precision given in the formatting of the string.
204 // Take care that the precision is sufficient for your needs.
206 return TString::Format("%.1f_%i_%.1f_%.1f_%.1f",
207 fMinChargedParticleTrackDistance,
215 Float_t AliPHOSClusterSelection::GetMinChargedParticleTrackDistance(const TString& string)
217 TString * s =&(static_cast<TObjString*>(string.Tokenize("_")->At(0))->String());
218 Float_t flt= s->Atof();
219 //delete s; //s is defined in the stack, no delete necessary
223 Bool_t AliPHOSClusterSelection::GetUnfolded(const TString& string)
225 TString * s =&(static_cast<TObjString*>(string.Tokenize("_")->At(1))->String());
226 Bool_t bl = s->Atoi();
230 Float_t AliPHOSClusterSelection::GetMaxDispR2(const TString& string)
232 TString * s =&(static_cast<TObjString*>(string.Tokenize("_")->At(2))->String());
233 Float_t flt = s->Atof();
237 Bool_t AliPHOSClusterSelection::GetIsCore(const TString& string)
239 TString * s =&(static_cast<TObjString*>(string.Tokenize("_")->At(3))->String());
240 Bool_t blt = s->Atoi();
244 Float_t AliPHOSClusterSelection::GetMaxTOF(const TString& string)
246 TString * s =&(static_cast<TObjString*>(string.Tokenize("_")->At(4))->String());
247 Float_t flt = s->Atof();
252 Double_t AliPHOSClusterSelection::TestCPV(Double_t dx, Double_t dz, Double_t pt, Int_t charge, Double_t mf) const {
253 //Parameterization of LHC10h period
255 //Copied from Pi0Flow task
259 Double_t sx=TMath::Min(5.4,2.59719e+02*TMath::Exp(-pt/1.02053e-01)+
260 6.58365e-01*5.91917e-01*5.91917e-01/((pt-9.61306e-01)*(pt-9.61306e-01)+5.91917e-01*5.91917e-01)+1.59219);
261 Double_t sz=TMath::Min(2.75,4.90341e+02*1.91456e-02*1.91456e-02/(pt*pt+1.91456e-02*1.91456e-02)+1.60) ;
263 if(mf<0.){ //field --
266 meanX=TMath::Min(7.3, 3.89994*1.20679*1.20679/(pt*pt+1.20679*1.20679)+0.249029+2.49088e+07*TMath::Exp(-pt*3.33650e+01)) ;
268 meanX=-TMath::Min(7.7,3.86040*0.912499*0.912499/(pt*pt+0.912499*0.912499)+1.23114+4.48277e+05*TMath::Exp(-pt*2.57070e+01)) ;
273 meanX=-TMath::Min(8.0,3.86040*1.31357*1.31357/(pt*pt+1.31357*1.31357)+0.880579+7.56199e+06*TMath::Exp(-pt*3.08451e+01)) ;
275 meanX= TMath::Min(6.85, 3.89994*1.16240*1.16240/(pt*pt+1.16240*1.16240)-0.120787+2.20275e+05*TMath::Exp(-pt*2.40913e+01)) ;
278 Double_t rz=(dz-meanZ)/sz ;
279 Double_t rx=(dx-meanX)/sx ;
280 return TMath::Sqrt(rx*rx+rz*rz) ;
283 //____________________________________________________________________________
284 void AliPHOSClusterSelection::EvalCoreLambdas(AliVCluster * clu, AliVCaloCells * cells,Double_t &m02, Double_t &m20) const
286 //calculate dispecrsion of the cluster in the circle with radius distanceCut around the maximum
287 //Copied from pi0flowtask
289 const Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
290 // Calculates the center of gravity in the local PHOS-module coordinates
292 const Int_t mulDigit=clu->GetNCells() ;
293 Double_t xc[mulDigit] ;
294 Double_t zc[mulDigit] ;
295 Double_t wi[mulDigit] ;
298 const Double_t logWeight=4.5 ;
299 for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
303 Int_t absId = clu->GetCellAbsId(iDigit) ;
306 AliESDEvent* EventESD = dynamic_cast<AliESDEvent*> (AliPHOSClusterSelection::GetCurrentEvent());//dynamic cast to test for ESD or AOD
308 AliAODEvent* EventAOD = dynamic_cast<AliAODEvent*> (AliPHOSClusterSelection::GetCurrentEvent());
310 fRunNumber = EventESD->GetRunNumber() ;
312 fRunNumber = EventESD->GetRunNumber() ;
314 AliOADBContainer geomContainer("phosGeo");//Initialize Geometry
315 geomContainer.InitFromFile("$ALICE_ROOT/OADB/PHOS/PHOSGeometry.root","PHOSRotationMatrixes");
316 TObjArray *matrixes = (TObjArray*)geomContainer.GetObject(fRunNumber,"PHOSRotationMatrixes");
317 AliPHOSGeometry * fPHOSGeo = AliPHOSGeometry::GetInstance("IHEP") ;
318 for(Int_t mod=0; mod<5; mod++) {
319 if(!matrixes->At(mod)) {
320 AliInfo(Form("No PHOS Matrix for mod:%d, geo=%p\n", mod, fPHOSGeo));
325 fPHOSGeo->AbsToRelNumbering(absId, relid) ;
326 fPHOSGeo->RelPosInModule(relid, xi, zi);
329 Double_t ei = elist[iDigit]*cells->GetCellAmplitude(absId) ;
331 if (clu->E()>0 && ei>0) {
332 wi[iDigit] = TMath::Max( 0., logWeight + TMath::Log( ei / clu->E() ) ) ;
333 Double_t w=wi[iDigit];
334 x += xc[iDigit] * w ;
335 z += zc[iDigit] * w ;
350 for(Int_t iDigit1=0; iDigit1<mulDigit; iDigit1++) {
351 Double_t w=wi[iDigit1];
353 Double_t xi1= xc[iDigit1] ;
354 Double_t zi1= zc[iDigit1] ;
355 if((xi1-x)*(xi1-x)+(zi1-z)*(zi1-z) < 4.5*4.5){
358 dxx += w * xi1 * xi1 ;
359 dzz += w * zi1 * zi1 ;
360 dxz += w * xi1 * zi1 ;
376 m02 = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
377 m20 = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
386 //_____________________________________________________________________________
387 Bool_t AliPHOSClusterSelection::TestLambda(Double_t pt,Double_t l1,Double_t l2) const
389 //Evaluates if lambdas correspond to photon cluster
390 //Tuned using pp data
391 //copied from Pi0FlowTask
392 Double_t l2Mean, l1Mean, l2Sigma, l1Sigma, c, R2;
394 l2Mean = 1.53126+9.50835e+06/(1.+1.08728e+07*pt+1.73420e+06*pt*pt) ;
395 l1Mean = 1.12365+0.123770*TMath::Exp(-pt*0.246551)+5.30000e-03*pt ;
396 l2Sigma = 6.48260e-02+7.60261e+10/(1.+1.53012e+11*pt+5.01265e+05*pt*pt)+9.00000e-03*pt;
397 l1Sigma = 4.44719e-04+6.99839e-01/(1.+1.22497e+00*pt+6.78604e-07*pt*pt)+9.00000e-03*pt;
398 c=-0.35-0.550*TMath::Exp(-0.390730*pt) ;
399 R2=0.5*(l1-l1Mean)*(l1-l1Mean)/l1Sigma/l1Sigma +
400 0.5*(l2-l2Mean)*(l2-l2Mean)/l2Sigma/l2Sigma +
401 0.5*c*(l1-l1Mean)*(l2-l2Mean)/l1Sigma/l2Sigma ;
404 //For core radius R=4.5
405 l1Mean = 1.150200 + 0.097886/(1.+1.486645*pt+0.000038*pt*pt) ;
406 l2Mean = 1.574706 + 0.997966*exp(-0.895075*pt)-0.010666*pt ;
407 l1Sigma = 0.100255 + 0.337177*exp(-0.517684*pt)+0.001170*pt ;
408 l2Sigma = 0.232580 + 0.573401*exp(-0.735903*pt)-0.002325*pt ;
409 c = -0.110983 -0.017353/(1.-1.836995*pt+0.934517*pt*pt) ;
410 R2=0.5*(l1-l1Mean)*(l1-l1Mean)/l1Sigma/l1Sigma +
411 0.5*(l2-l2Mean)*(l2-l2Mean)/l2Sigma/l2Sigma +
412 0.5*c*(l1-l1Mean)*(l2-l2Mean)/l1Sigma/l2Sigma ;
414 return (R2<fMaxDispR2*fMaxDispR2);//TODO: Check if this should be 2. order
418 AliVEvent* AliPHOSClusterSelection::GetCurrentEvent() const
420 // Hackish way of getting the current event.
421 // Its probably not appropriate to call this function outside of
422 // AliAnalysisTaskSE::UserExec
424 AliAnalysisManager* analysisManager = dynamic_cast<AliAnalysisManager*>(AliAnalysisManager::GetAnalysisManager());
425 AliInputEventHandler* inputHandler = dynamic_cast<AliInputEventHandler*>(analysisManager->GetInputEventHandler());
426 AliMultiInputEventHandler *multiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(inputHandler);
427 if (multiInputHandler)
428 inputHandler = dynamic_cast<AliInputEventHandler *>(multiInputHandler->GetFirstInputEventHandler());
430 AliVEvent* inputEvent = dynamic_cast<AliVEvent*>(inputHandler->GetEvent());
432 AliError("Was not able to retrieve event!");