ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

////////////////////////////////////////////////////////////////////////////////
//
//  This class implements a candidate resonance. It has two pointers to its
//  two candidate daughters, whose 4-momenta are combined to obtain the mother
//  invariant mass and other kinematical quantities.
//  This class contains also some methods used to compute kinematical relations
//  between the candidate resonance and other particles.
//
//  authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
//           M. Vala (martin.vala@cern.ch)
//
////////////////////////////////////////////////////////////////////////////////

#include <Riostream.h>
#include <TVector3.h>

#include "AliAODMCParticle.h"
#include "AliMCParticle.h"
#include "AliRsnEvent.h"

#include "AliRsnMother.h"

ClassImp(AliRsnMother)

//__________________________________________________________________________________________________
AliRsnMother::AliRsnMother(const AliRsnMother &obj) :
   TObject(obj),
   fRefEvent(obj.fRefEvent),
   fSum(obj.fSum),
   fSumMC(obj.fSumMC),
   fRef(obj.fRef),
   fRefMC(obj.fRefMC),
   fDCAproduct(obj.fDCAproduct)
{
//
// Copy constructor.
// Does not duplicate pointers.
//

   Int_t i;
   for (i = 0; i < 2; i++) fDaughter[i] = obj.fDaughter[i];
}

//__________________________________________________________________________________________________
AliRsnMother &AliRsnMother::operator=(const AliRsnMother &obj)
{
//
// Assignment operator.
// Does not duplicate pointers.
//
   if (this == &obj)
      return *this;

   fSum = obj.fSum;
   fRef = obj.fRef;
   fSumMC = obj.fSumMC;
   fRefMC = obj.fRefMC;
   fRefEvent = obj.fRefEvent;
   fDaughter[0] = obj.fDaughter[0];
   fDaughter[1] = obj.fDaughter[1];
   fDCAproduct = obj.fDCAproduct;

   return (*this);
}

//__________________________________________________________________________________________________
AliRsnMother::~AliRsnMother()
{
//
// Desctructor.
// Does nothing, since pointers are not created in this class.
//
}

//_______________________________________________________________________________________________________________________
void AliRsnMother::Reset()
{
//
// Resets the mother, zeroing all data members.
//

   Int_t i;
   for (i = 0; i < 2; i++) fDaughter[i] = 0x0;
   fRefEvent = 0x0;
   fSum.SetXYZM(0.0, 0.0, 0.0, 0.0);
   fRef.SetXYZM(0.0, 0.0, 0.0, 0.0);
}

//__________________________________________________________________________________________________
Int_t AliRsnMother::CommonMother() const
{
//
// If MC info is available, checks if the two tracks in the pair have the same mother.
// If the mother label is the same, the function returns the PDG code of mother,
// otherwise it returns 0.
// The two arguments passed by reference contain the GEANT labels of the mother
// of the two particles to which the two daughters point. This is for being able
// to check if they are really coming from a resonance (indexes >= 0) or not.
//

   Int_t m1  = fDaughter[0]->GetMother();
   Int_t m2  = fDaughter[1]->GetMother();
   Int_t out = 0;

   // a true mother makes sense only if both mothers
   // are not-negative and equal
   if (m1 >= 0 && m2 >= 0 && m1 == m2) {
      out = TMath::Abs(fDaughter[0]->GetMotherPDG());
      AliDebugClass(1, Form("Mothers are: %d %d --> EQUAL (PDG = %d)", m1, m2, out));
   }

   return out;
}

//__________________________________________________________________________________________________
Double_t AliRsnMother::AngleToLeading(Bool_t &success)
{
//
// Compute the angle betwee this and the leading particls
// of the reference event (if this was set properly).
// In case one of the two daughters is the leading, return
// a meaningless value, in order to skip this pair.
// if second argument is kTRUE, use MC values.
//

   if (!fRefEvent) {
      success = kFALSE;
      return -99.0;
   }

   Int_t id1 = fDaughter[0]->GetID();
   Int_t id2 = fDaughter[1]->GetID();
   Int_t idL = fRefEvent->GetLeadingIndex();

   if (id1 == idL || id2 == idL) {
      success = kFALSE;
      return -99.0;
   }

   AliRsnDaughter leading = fRefEvent->GetDaughter(idL, kFALSE);
   AliVParticle  *ref     = leading.GetRef();
   Double_t       angle   = ref->Phi() - fSum.Phi();

   //return angle w.r.t. leading particle in the range -pi/2, 3/2pi
   while (angle >= 1.5 * TMath::Pi()) angle -= 2 * TMath::Pi();
   while (angle < -0.5 * TMath::Pi()) angle += 2 * TMath::Pi();
   success = kTRUE;

   return angle;
}

//__________________________________________________________________________________________________
void AliRsnMother::ComputeSum(Double_t mass0, Double_t mass1, Double_t motherMass)
{
//
// Sets the masses for the 4-momenta of the daughters and then
// sums them, taking into account that the space part is set to
// each of them when the reference object is set (see AliRsnDaughter::SetRef)
//

   fDaughter[0]->FillP(mass0);
   fDaughter[1]->FillP(mass1);

   // sum
   fSum   = fDaughter[0]->Prec() + fDaughter[1]->Prec();
   fSumMC = fDaughter[0]->Psim() + fDaughter[1]->Psim();

   // reference
   fRef.SetXYZM(fSum.X(), fSum.Y(), fSum.Z(), motherMass);
   fRefMC.SetXYZM(fSumMC.X(), fSumMC.Y(), fSumMC.Z(), motherMass);
}

//__________________________________________________________________________________________________
Double_t AliRsnMother::CosThetaStar(Bool_t first, Bool_t useMC)
{
//
// Computes the cosine of theta*, which is the angle of one of the daughters
// with respect to the total momentum of the resonance, in its rest frame.
// The arguments are needed to choose which of the daughters one want to use
// and if reconstructed or MC momentum must be used.
// [Contribution from Z. Feckova]
//

   TLorentzVector &mother    = Sum(useMC);
   TLorentzVector &daughter0 = (first ? fDaughter[0]->P(useMC) : fDaughter[1]->P(useMC));
//    TLorentzVector &daughter1 = (first ? fDaughter[1]->P(useMC) : fDaughter[0]->P(useMC));
   TVector3 momentumM(mother.Vect());
   TVector3 normal(mother.Y() / momentumM.Mag(), -mother.X() / momentumM.Mag(), 0.0);

//    // Computes first the invariant mass of the mother
//    Double_t mass0      = fDaughter[0]->P(useMC).M();
//    Double_t mass1      = fDaughter[1]->P(useMC).M();
//    Double_t p0         = daughter0.Vect().Mag();
//    Double_t p1         = daughter1.Vect().Mag();
//    Double_t E0         = TMath::Sqrt(mass0 * mass0 + p0 * p0);
//    Double_t E1         = TMath::Sqrt(mass1 * mass1 + p1 * p1);
//    Double_t MotherMass = TMath::Sqrt((E0 + E1) * (E0 + E1) - (p0 * p0 + 2.0 * daughter0.Vect().Dot(daughter1.Vect()) + p1 * p1));
//    MotherMass = fSum.M();

   // Computes components of beta
   Double_t betaX = -mother.X() / mother.E();
   Double_t betaY = -mother.Y() / mother.E();
   Double_t betaZ = -mother.Z() / mother.E();

   // Computes Lorentz transformation of the momentum of the first daughter
   // into the rest frame of the mother and theta*
   daughter0.Boost(betaX, betaY, betaZ);
   TVector3 momentumD = daughter0.Vect();

   Double_t cosThetaStar = normal.Dot(momentumD) / momentumD.Mag();

   return cosThetaStar;
}

//__________________________________________________________________________________________________
Double_t AliRsnMother::DCAproduct()
{
  //
  // returns product of DCA of the two daughters
  //
  AliRsnEvent *event1 = fDaughter[0]->GetOwnerEvent();
  AliRsnEvent *event2 = fDaughter[1]->GetOwnerEvent();
  
  if(event1 != event2){  
    AliError("Attempting to build pair with tracks coming from different events");
    return 0.0;
  }
   
  if (event1->IsAOD()) {
    AliAODEvent *aodEvent = (AliAODEvent*)event1->GetRefAOD();  
    if (!aodEvent) return 0.0;
    AliAODTrack *track1 = (AliAODTrack*)fDaughter[0]->Ref2AODtrack();
    AliAODTrack *track2 = (AliAODTrack*)fDaughter[1]->Ref2AODtrack();
    AliVVertex *vertex = aodEvent->GetPrimaryVertex();   
    if (!vertex || !track1 || !track2) return 0.0;
     
    Double_t b1[2], cov1[3], b2[2], cov2[3];
    if ( track1->PropagateToDCA(vertex, aodEvent->GetMagneticField(), kVeryBig, b1, cov1) &&   
	 track2->PropagateToDCA(vertex, aodEvent->GetMagneticField(), kVeryBig, b2, cov2) )
      fDCAproduct = b1[0]*b2[0]; 
    else fDCAproduct = 0.0;
  } else {
    AliESDEvent *esdEvent = (AliESDEvent*)event1->GetRefESD();  
    if (!esdEvent) return 0.0;
    AliESDtrack *track1 = (AliESDtrack*)fDaughter[0]->Ref2ESDtrack();
    AliESDtrack *track2 = (AliESDtrack*)fDaughter[1]->Ref2ESDtrack();
    const AliVVertex *vertex = esdEvent->GetPrimaryVertex();
    if (!vertex || !track1 || !track2) return 0.0;
     
    Double_t b1[2], cov1[3], b2[2], cov2[3];
    if ( track1->PropagateToDCA(vertex, esdEvent->GetMagneticField(), kVeryBig, b1, cov1) &&    
	 track2->PropagateToDCA(vertex, esdEvent->GetMagneticField(), kVeryBig, b2, cov2) )
      fDCAproduct = b1[0]*b2[0];  
    else fDCAproduct = 0.0;  
  }
  return fDCAproduct;
}

//__________________________________________________________________________________________________
void AliRsnMother::PrintInfo(const Option_t * /*option*/) const
{
//
// Print some info of the pair.
// The options are passed to the AliRsnDaughter::Print() method
//

   AliInfo("======== BEGIN PAIR INFO ===========");
   AliInfo("Track #1");
   fDaughter[0]->Print();
   AliInfo("Track #2");
   fDaughter[1]->Print();
   AliInfo("========= END PAIR INFO ===========");
}

//__________________________________________________________________________________________________
Bool_t AliRsnMother::CheckPair(Bool_t checkMC) const
{
//
// Checks that the pair is well initialized:
// - both daughters are good pointers
// - if MC is required, both daughters have a MC reference
//

   if (!fDaughter[0] || !fDaughter[1]) {
      AliError("One of the two tracks is NULL in this pair!");
      return kFALSE;
   }

   if (checkMC) {
      if (fDaughter[0]->GetRefMC() == 0x0 || fDaughter[1]->GetRefMC() == 0x0) {
         AliError("Required MC info but not all MC refs are available");
         return kFALSE;
      }
   }

   return kTRUE;
}
 AliRsnMother.cxx:1
 AliRsnMother.cxx:2
 AliRsnMother.cxx:3
 AliRsnMother.cxx:4
 AliRsnMother.cxx:5
 AliRsnMother.cxx:6
 AliRsnMother.cxx:7
 AliRsnMother.cxx:8
 AliRsnMother.cxx:9
 AliRsnMother.cxx:10
 AliRsnMother.cxx:11
 AliRsnMother.cxx:12
 AliRsnMother.cxx:13
 AliRsnMother.cxx:14
 AliRsnMother.cxx:15
 AliRsnMother.cxx:16
 AliRsnMother.cxx:17
 AliRsnMother.cxx:18
 AliRsnMother.cxx:19
 AliRsnMother.cxx:20
 AliRsnMother.cxx:21
 AliRsnMother.cxx:22
 AliRsnMother.cxx:23
 AliRsnMother.cxx:24
 AliRsnMother.cxx:25
 AliRsnMother.cxx:26
 AliRsnMother.cxx:27
 AliRsnMother.cxx:28
 AliRsnMother.cxx:29
 AliRsnMother.cxx:30
 AliRsnMother.cxx:31
 AliRsnMother.cxx:32
 AliRsnMother.cxx:33
 AliRsnMother.cxx:34
 AliRsnMother.cxx:35
 AliRsnMother.cxx:36
 AliRsnMother.cxx:37
 AliRsnMother.cxx:38
 AliRsnMother.cxx:39
 AliRsnMother.cxx:40
 AliRsnMother.cxx:41
 AliRsnMother.cxx:42
 AliRsnMother.cxx:43
 AliRsnMother.cxx:44
 AliRsnMother.cxx:45
 AliRsnMother.cxx:46
 AliRsnMother.cxx:47
 AliRsnMother.cxx:48
 AliRsnMother.cxx:49
 AliRsnMother.cxx:50
 AliRsnMother.cxx:51
 AliRsnMother.cxx:52
 AliRsnMother.cxx:53
 AliRsnMother.cxx:54
 AliRsnMother.cxx:55
 AliRsnMother.cxx:56
 AliRsnMother.cxx:57
 AliRsnMother.cxx:58
 AliRsnMother.cxx:59
 AliRsnMother.cxx:60
 AliRsnMother.cxx:61
 AliRsnMother.cxx:62
 AliRsnMother.cxx:63
 AliRsnMother.cxx:64
 AliRsnMother.cxx:65
 AliRsnMother.cxx:66
 AliRsnMother.cxx:67
 AliRsnMother.cxx:68
 AliRsnMother.cxx:69
 AliRsnMother.cxx:70
 AliRsnMother.cxx:71
 AliRsnMother.cxx:72
 AliRsnMother.cxx:73
 AliRsnMother.cxx:74
 AliRsnMother.cxx:75
 AliRsnMother.cxx:76
 AliRsnMother.cxx:77
 AliRsnMother.cxx:78
 AliRsnMother.cxx:79
 AliRsnMother.cxx:80
 AliRsnMother.cxx:81
 AliRsnMother.cxx:82
 AliRsnMother.cxx:83
 AliRsnMother.cxx:84
 AliRsnMother.cxx:85
 AliRsnMother.cxx:86
 AliRsnMother.cxx:87
 AliRsnMother.cxx:88
 AliRsnMother.cxx:89
 AliRsnMother.cxx:90
 AliRsnMother.cxx:91
 AliRsnMother.cxx:92
 AliRsnMother.cxx:93
 AliRsnMother.cxx:94
 AliRsnMother.cxx:95
 AliRsnMother.cxx:96
 AliRsnMother.cxx:97
 AliRsnMother.cxx:98
 AliRsnMother.cxx:99
 AliRsnMother.cxx:100
 AliRsnMother.cxx:101
 AliRsnMother.cxx:102
 AliRsnMother.cxx:103
 AliRsnMother.cxx:104
 AliRsnMother.cxx:105
 AliRsnMother.cxx:106
 AliRsnMother.cxx:107
 AliRsnMother.cxx:108
 AliRsnMother.cxx:109
 AliRsnMother.cxx:110
 AliRsnMother.cxx:111
 AliRsnMother.cxx:112
 AliRsnMother.cxx:113
 AliRsnMother.cxx:114
 AliRsnMother.cxx:115
 AliRsnMother.cxx:116
 AliRsnMother.cxx:117
 AliRsnMother.cxx:118
 AliRsnMother.cxx:119
 AliRsnMother.cxx:120
 AliRsnMother.cxx:121
 AliRsnMother.cxx:122
 AliRsnMother.cxx:123
 AliRsnMother.cxx:124
 AliRsnMother.cxx:125
 AliRsnMother.cxx:126
 AliRsnMother.cxx:127
 AliRsnMother.cxx:128
 AliRsnMother.cxx:129
 AliRsnMother.cxx:130
 AliRsnMother.cxx:131
 AliRsnMother.cxx:132
 AliRsnMother.cxx:133
 AliRsnMother.cxx:134
 AliRsnMother.cxx:135
 AliRsnMother.cxx:136
 AliRsnMother.cxx:137
 AliRsnMother.cxx:138
 AliRsnMother.cxx:139
 AliRsnMother.cxx:140
 AliRsnMother.cxx:141
 AliRsnMother.cxx:142
 AliRsnMother.cxx:143
 AliRsnMother.cxx:144
 AliRsnMother.cxx:145
 AliRsnMother.cxx:146
 AliRsnMother.cxx:147
 AliRsnMother.cxx:148
 AliRsnMother.cxx:149
 AliRsnMother.cxx:150
 AliRsnMother.cxx:151
 AliRsnMother.cxx:152
 AliRsnMother.cxx:153
 AliRsnMother.cxx:154
 AliRsnMother.cxx:155
 AliRsnMother.cxx:156
 AliRsnMother.cxx:157
 AliRsnMother.cxx:158
 AliRsnMother.cxx:159
 AliRsnMother.cxx:160
 AliRsnMother.cxx:161
 AliRsnMother.cxx:162
 AliRsnMother.cxx:163
 AliRsnMother.cxx:164
 AliRsnMother.cxx:165
 AliRsnMother.cxx:166
 AliRsnMother.cxx:167
 AliRsnMother.cxx:168
 AliRsnMother.cxx:169
 AliRsnMother.cxx:170
 AliRsnMother.cxx:171
 AliRsnMother.cxx:172
 AliRsnMother.cxx:173
 AliRsnMother.cxx:174
 AliRsnMother.cxx:175
 AliRsnMother.cxx:176
 AliRsnMother.cxx:177
 AliRsnMother.cxx:178
 AliRsnMother.cxx:179
 AliRsnMother.cxx:180
 AliRsnMother.cxx:181
 AliRsnMother.cxx:182
 AliRsnMother.cxx:183
 AliRsnMother.cxx:184
 AliRsnMother.cxx:185
 AliRsnMother.cxx:186
 AliRsnMother.cxx:187
 AliRsnMother.cxx:188
 AliRsnMother.cxx:189
 AliRsnMother.cxx:190
 AliRsnMother.cxx:191
 AliRsnMother.cxx:192
 AliRsnMother.cxx:193
 AliRsnMother.cxx:194
 AliRsnMother.cxx:195
 AliRsnMother.cxx:196
 AliRsnMother.cxx:197
 AliRsnMother.cxx:198
 AliRsnMother.cxx:199
 AliRsnMother.cxx:200
 AliRsnMother.cxx:201
 AliRsnMother.cxx:202
 AliRsnMother.cxx:203
 AliRsnMother.cxx:204
 AliRsnMother.cxx:205
 AliRsnMother.cxx:206
 AliRsnMother.cxx:207
 AliRsnMother.cxx:208
 AliRsnMother.cxx:209
 AliRsnMother.cxx:210
 AliRsnMother.cxx:211
 AliRsnMother.cxx:212
 AliRsnMother.cxx:213
 AliRsnMother.cxx:214
 AliRsnMother.cxx:215
 AliRsnMother.cxx:216
 AliRsnMother.cxx:217
 AliRsnMother.cxx:218
 AliRsnMother.cxx:219
 AliRsnMother.cxx:220
 AliRsnMother.cxx:221
 AliRsnMother.cxx:222
 AliRsnMother.cxx:223
 AliRsnMother.cxx:224
 AliRsnMother.cxx:225
 AliRsnMother.cxx:226
 AliRsnMother.cxx:227
 AliRsnMother.cxx:228
 AliRsnMother.cxx:229
 AliRsnMother.cxx:230
 AliRsnMother.cxx:231
 AliRsnMother.cxx:232
 AliRsnMother.cxx:233
 AliRsnMother.cxx:234
 AliRsnMother.cxx:235
 AliRsnMother.cxx:236
 AliRsnMother.cxx:237
 AliRsnMother.cxx:238
 AliRsnMother.cxx:239
 AliRsnMother.cxx:240
 AliRsnMother.cxx:241
 AliRsnMother.cxx:242
 AliRsnMother.cxx:243
 AliRsnMother.cxx:244
 AliRsnMother.cxx:245
 AliRsnMother.cxx:246
 AliRsnMother.cxx:247
 AliRsnMother.cxx:248
 AliRsnMother.cxx:249
 AliRsnMother.cxx:250
 AliRsnMother.cxx:251
 AliRsnMother.cxx:252
 AliRsnMother.cxx:253
 AliRsnMother.cxx:254
 AliRsnMother.cxx:255
 AliRsnMother.cxx:256
 AliRsnMother.cxx:257
 AliRsnMother.cxx:258
 AliRsnMother.cxx:259
 AliRsnMother.cxx:260
 AliRsnMother.cxx:261
 AliRsnMother.cxx:262
 AliRsnMother.cxx:263
 AliRsnMother.cxx:264
 AliRsnMother.cxx:265
 AliRsnMother.cxx:266
 AliRsnMother.cxx:267
 AliRsnMother.cxx:268
 AliRsnMother.cxx:269
 AliRsnMother.cxx:270
 AliRsnMother.cxx:271
 AliRsnMother.cxx:272
 AliRsnMother.cxx:273
 AliRsnMother.cxx:274
 AliRsnMother.cxx:275
 AliRsnMother.cxx:276
 AliRsnMother.cxx:277
 AliRsnMother.cxx:278
 AliRsnMother.cxx:279
 AliRsnMother.cxx:280
 AliRsnMother.cxx:281
 AliRsnMother.cxx:282
 AliRsnMother.cxx:283
 AliRsnMother.cxx:284
 AliRsnMother.cxx:285
 AliRsnMother.cxx:286
 AliRsnMother.cxx:287
 AliRsnMother.cxx:288
 AliRsnMother.cxx:289
 AliRsnMother.cxx:290
 AliRsnMother.cxx:291
 AliRsnMother.cxx:292
 AliRsnMother.cxx:293
 AliRsnMother.cxx:294
 AliRsnMother.cxx:295
 AliRsnMother.cxx:296
 AliRsnMother.cxx:297
 AliRsnMother.cxx:298
 AliRsnMother.cxx:299
 AliRsnMother.cxx:300
 AliRsnMother.cxx:301
 AliRsnMother.cxx:302
 AliRsnMother.cxx:303
 AliRsnMother.cxx:304
 AliRsnMother.cxx:305
 AliRsnMother.cxx:306
 AliRsnMother.cxx:307
 AliRsnMother.cxx:308
 AliRsnMother.cxx:309
 AliRsnMother.cxx:310
 AliRsnMother.cxx:311
 AliRsnMother.cxx:312