]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/dielectron/AliDielectronTrackRotator.cxx
framework update; new classes for track rotation (for background), cuts grouping...
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronTrackRotator.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2009, 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 ///////////////////////////////////////////////////////////////////////////
17 //                Dielectron TrackRotator                                  //
18 //                                                                       //
19 //                                                                       //
20 /*
21 Detailed description
22
23
24 */
25 //                                                                       //
26 ///////////////////////////////////////////////////////////////////////////
27
28 #include <TMath.h>
29 #include <TObjArray.h>
30 #include <AliAODTrack.h>
31 #include <AliESDtrack.h>
32 #include <TRandom3.h>
33
34 #include "AliDielectronTrackRotator.h"
35
36 ClassImp(AliDielectronTrackRotator)
37
38 AliDielectronTrackRotator::AliDielectronTrackRotator() :
39   TNamed(),
40   fIterations(1),
41   fRotationType(kRotateBothRandom),
42   fStartAnglePhi(TMath::Pi()),
43   fConeAnglePhi(TMath::Pi()/6.),
44   fkArrTracksP(0x0),
45   fkArrTracksN(0x0),
46   fCurrentIteration(0),
47   fCurrentTackP(0),
48   fCurrentTackN(0),
49   fTrackP(0x0),
50   fTrackN(0x0)
51 {
52   //
53   // Default Constructor
54   //
55   gRandom->SetSeed();
56 }
57
58 //______________________________________________
59 AliDielectronTrackRotator::AliDielectronTrackRotator(const char* name, const char* title) :
60   TNamed(name, title),
61   fIterations(1),
62   fRotationType(kRotateBothRandom),
63   fStartAnglePhi(TMath::Pi()),
64   fConeAnglePhi(TMath::Pi()/6.),
65   fkArrTracksP(0x0),
66   fkArrTracksN(0x0),
67   fCurrentIteration(0),
68   fCurrentTackP(0),
69   fCurrentTackN(0),
70   fTrackP(0x0),
71   fTrackN(0x0)
72 {
73   //
74   // Named Constructor
75   //
76   gRandom->SetSeed();
77 }
78
79 //______________________________________________
80 AliDielectronTrackRotator::~AliDielectronTrackRotator()
81 {
82   //
83   // Default Destructor
84   //
85   
86 }
87
88 //______________________________________________
89 void AliDielectronTrackRotator::Reset()
90 {
91   //
92   // Reset the current iterators
93   //
94   fCurrentIteration=0;
95   fCurrentTackP=0;
96   fCurrentTackN=0;
97 }
98
99 //______________________________________________
100 Bool_t AliDielectronTrackRotator::NextCombination()
101 {
102   //
103   // Perform track rotation of the tracks in the track arrays as long as there are possible combinations
104   //
105   if (!fkArrTracksP || !fkArrTracksP) {
106     Reset();
107     return kFALSE;
108   }
109
110   Int_t nP=fkArrTracksP->GetEntriesFast();
111   Int_t nN=fkArrTracksN->GetEntriesFast();
112   if (nP==0||nN==0){
113     Reset();
114     return kFALSE;
115   }
116   
117   if (fCurrentIteration==fIterations){
118     fCurrentIteration=0;
119     ++fCurrentTackP;
120   }
121   
122   if (fCurrentTackP==nP){
123     ++fCurrentTackN;
124     fCurrentTackP=0;
125   }
126   
127   if (fCurrentTackN==nN){
128     Reset();
129     return kFALSE;
130   }
131   
132   if (!RotateTracks()){
133     Reset();
134     return kFALSE;
135   }
136   
137   ++fCurrentIteration;
138   return kTRUE;
139 }
140
141 //______________________________________________
142 Bool_t AliDielectronTrackRotator::RotateTracks()
143 {
144   //
145   // Actual track rotation
146   // Find out particle type and perform the rotation
147   //
148   
149   const AliVTrack *trackP=dynamic_cast<AliVTrack*>(fkArrTracksP->UncheckedAt(fCurrentTackP));
150   const AliVTrack *trackN=dynamic_cast<AliVTrack*>(fkArrTracksP->UncheckedAt(fCurrentTackN));
151   if (!trackP||!trackN) return kFALSE;
152
153   
154   Double_t angle  = fStartAnglePhi+(2*gRandom->Rndm()-1)*fConeAnglePhi;
155   Int_t    charge = TMath::Nint(gRandom->Rndm());
156   
157   if (trackP->IsA()==AliESDtrack::Class()) {
158     
159     if (!fTrackP) {
160       fTrackP=new AliESDtrack;
161       fTrackN=new AliESDtrack;
162     }
163     
164     trackP->Copy(*fTrackP);
165     trackN->Copy(*fTrackN);
166     
167     if (fRotationType==kRotatePositive||(fRotationType==kRotateBothRandom&&charge==0)){
168       ((AliESDtrack*)fTrackP)->Rotate(angle);
169     }
170     
171     if (fRotationType==kRotateNegative||(fRotationType==kRotateBothRandom&&charge==1)){
172       ((AliESDtrack*)fTrackN)->Rotate(angle);
173     }
174     
175   } else if (trackP->IsA()==AliAODTrack::Class()) {
176     
177     if (!fTrackP) {
178       fTrackP=new AliAODTrack;
179       fTrackN=new AliAODTrack;
180     }
181     
182     (*(AliAODTrack*)fTrackP)=(*(AliAODTrack*)trackP);
183     (*(AliAODTrack*)fTrackN)=(*(AliAODTrack*)trackN);
184         
185     if (fRotationType==kRotatePositive||(fRotationType==kRotateBothRandom&&charge==0)){
186       Double_t phi=fTrackP->Phi()+angle;
187       if (phi>2*TMath::Pi()) phi-=2*TMath::Pi();
188       ((AliAODTrack*)fTrackP)->SetPhi(phi);
189     }
190     
191     if (fRotationType==kRotateNegative||(fRotationType==kRotateBothRandom&&charge==1)){
192       Double_t phi=fTrackN->Phi()+angle;
193       if (phi>2*TMath::Pi()) phi-=2*TMath::Pi();
194       ((AliAODTrack*)fTrackN)->SetPhi(phi);
195     }
196     
197   }
198
199   return kTRUE;
200 }