ROOT logo
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// AliFemtoSpherocityEventCut - the basic cut for events.                     //
// Only cuts on event multiplicity, z-vertex position and                     //
// transverse spherocity are accepted.                                        //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

#include "AliFemtoSpherocityEventCut.h"
//#include <cstdio>

#ifdef __ROOT__
ClassImp(AliFemtoSpherocityEventCut)
#endif

AliFemtoSpherocityEventCut::AliFemtoSpherocityEventCut() :
  AliFemtoEventCut(),
  fEventMult(),
  fVertZPos(),
  fAcceptBadVertex(false), 
  fNEventsPassed(0), 
  fNEventsFailed(0),
  fAcceptOnlyPhysics(0),
  fSoCutMin(0.0),
  fSoCutMax(1.0),
  fSelectTrigger(0)
{
  // Default constructor
  fEventMult[0] = 0;
  fEventMult[1] = 100000;
  fVertZPos[0] = -100.0;
  fVertZPos[1] = 100.0;
  fPsiEP[0] = -1000.0;
  fPsiEP[1] = 1000.0;
} 
//------------------------------
AliFemtoSpherocityEventCut::~AliFemtoSpherocityEventCut(){
  // Default destructor
}
//------------------------------
bool AliFemtoSpherocityEventCut::Pass(const AliFemtoEvent* event){  

  // Pass events if they fall within the multiplicity and z-vertex
  // position range. Fail otherwise
  //  int mult =  event->NumberOfTracks();
  int mult = (int) event->UncorrectedNumberOfPrimaries();
  double vertexZPos = event->PrimVertPos().z();
  double spherocity=-10;
  int MULT=0;
 

   AliFemtoTrackCollection * tracks = event->TrackCollection(); 
  for (AliFemtoTrackIterator iter=tracks->begin();iter!=tracks->end();iter++){
  
    Double_t NewPt =  (*iter)->Pt();
    Double_t NewEta = (*iter)->P().PseudoRapidity();    
    if(TMath::Abs(NewEta)>0.8 || NewPt<0.5){continue;}
    
     MULT++;
  
  }  	
    //if(SumPt==0){return kFALSE;}
      if(MULT<3){return kFALSE;}
 
	Double_t *pxA=new Double_t[MULT];
	Double_t *pyA=new Double_t[MULT];
	Double_t sumapt=0;
	Int_t counter=0;
  
   AliFemtoTrackCollection * tracks2 = event->TrackCollection(); 
  for (AliFemtoTrackIterator iter2=tracks2->begin();iter2!=tracks2->end();iter2++){
  
    Double_t NewPt2 =  (*iter2)->Pt();
    Double_t NewPhi2 = (*iter2)->P().Phi();
    Double_t NewEta2 = (*iter2)->P().PseudoRapidity();
    if(TMath::Abs(NewEta2)>0.8 || NewPt2<0.5){continue;}
    
    Double_t Px;
    Double_t Py;
    
    Px= NewPt2 * TMath::Cos(NewPhi2);
    Py= NewPt2 * TMath::Sin(NewPhi2);
    
    
    pxA[counter]=Px;
    pyA[counter]=Py;
    sumapt+=NewPt2;
    counter++;
  
  } 
  
  Double_t pFull = 0;
  Double_t Spherocity = 2;
  //Getting thrust
  for(Int_t i = 0; i < 360; ++i){
    Double_t numerador = 0;
    Double_t phiparam  = 0;
    Double_t nx = 0;
    Double_t ny = 0;
    phiparam=((TMath::Pi()) * i) / 180;   // parametrization of the angle
    nx = TMath::Cos(phiparam);            // x component of an unitary vector n
    ny = TMath::Sin(phiparam);            // y component of an unitary vector n
    for(Int_t i1 = 0; i1 < MULT; ++i1){
      numerador += TMath::Abs(ny * pxA[i1] - nx * pyA[i1]);//product between momentum proyection in XY plane and the unitari vector.
    }
    pFull=TMath::Power( (numerador / sumapt),2 );
    if(pFull < Spherocity)//maximization of pFull
      {Spherocity = pFull;}
  }

  
    spherocity=((Spherocity)*TMath::Pi()*TMath::Pi())/4.0;

  if(pxA){// clean up array memory used for TMath::Sort
    delete[] pxA;
    pxA=0;
  }
  if(pyA){// clean up array memory used for TMath::Sort
    delete[] pyA;
    pyA=0;
  }

  if(spherocity>fSoCutMax || spherocity<fSoCutMin){
	  //cout<<" Event kicked out !"<<"SoCutMax= "<<fSoCutMax<<"  SoCutMin= "<<fSoCutMin<<endl;
	  return kFALSE;}  
  
  double epvzero = event->ReactionPlaneAngle();

  // cout << "AliFemtoSpherocityEventCut:: epvzero:       " << fPsiEP[0] << " < " << epvzero << " < " << fPsiEP[1] << endl;
//   cout << "AliFemtoSpherocityEventCut:: mult:       " << fEventMult[0] << " < " << mult << " < " << fEventMult[1] << endl;
//   cout << "AliFemtoSpherocityEventCut:: VertexZPos: " << fVertZPos[0] << " < " << vertexZPos << " < " << fVertZPos[1] << endl;
//   cout << "AliFemtoSpherocityEventCut:: VertexZErr: " << event->PrimVertCov()[4] << endl;

  // cout << "AliFemtoSpherocityEventCut:: MagneticField: " << event->MagneticField() << endl;
  // cout << "AliFemtoSpherocityEventCut:: IsCollisionCandidate: " << event->IsCollisionCandidate() << endl;
  // cout << "AliFemtoSpherocityEventCut:: TriggerCluster: " << event->TriggerCluster() << endl;
  // cout << "AliFemtoSpherocityEventCut:: fSelectTrigger: " << fSelectTrigger << endl;
  // cout << "AliFemtoSpherocityEventCut:: " << endl;
  bool goodEvent =
    ((mult >= fEventMult[0]) && 
     (mult <= fEventMult[1]) && 
     (vertexZPos > fVertZPos[0]) &&
     (vertexZPos < fVertZPos[1]) &&
     (epvzero > fPsiEP[0]) &&
     (epvzero < fPsiEP[1]) &&
     ((!fAcceptBadVertex) || (event->ZDCParticipants() > 1.0)) &&
      ((!fSelectTrigger) || (event->TriggerCluster() == fSelectTrigger))
);

  // cout << "AliFemtoSpherocityEventCut:: goodEvent" <<goodEvent << endl;

  goodEvent ? fNEventsPassed++ : fNEventsFailed++ ;
  // cout << "AliFemtoSpherocityEventCut:: return : " << goodEvent << endl;
//     (fAcceptBadVertex || (event->PrimVertCov()[4] > -1000.0)) &&

  return (goodEvent);
}
//------------------------------
AliFemtoString AliFemtoSpherocityEventCut::Report(){
  // Prepare report
  string stemp;
  char ctemp[100];
  snprintf(ctemp , 100, "\nMultiplicity:\t %d-%d",fEventMult[0],fEventMult[1]);
  stemp = ctemp;
  snprintf(ctemp , 100, "\nVertex Z-position:\t %E-%E",fVertZPos[0],fVertZPos[1]);
  stemp += ctemp;
  snprintf(ctemp , 100, "\nNumber of events which passed:\t%ld  Number which failed:\t%ld",fNEventsPassed,fNEventsFailed);
  stemp += ctemp;
  AliFemtoString returnThis = stemp;
  return returnThis;
}
void AliFemtoSpherocityEventCut::SetAcceptBadVertex(bool b)
{
  fAcceptBadVertex = b;
}
bool AliFemtoSpherocityEventCut::GetAcceptBadVertex()
{
  return fAcceptBadVertex;
}
 AliFemtoSpherocityEventCut.cxx:1
 AliFemtoSpherocityEventCut.cxx:2
 AliFemtoSpherocityEventCut.cxx:3
 AliFemtoSpherocityEventCut.cxx:4
 AliFemtoSpherocityEventCut.cxx:5
 AliFemtoSpherocityEventCut.cxx:6
 AliFemtoSpherocityEventCut.cxx:7
 AliFemtoSpherocityEventCut.cxx:8
 AliFemtoSpherocityEventCut.cxx:9
 AliFemtoSpherocityEventCut.cxx:10
 AliFemtoSpherocityEventCut.cxx:11
 AliFemtoSpherocityEventCut.cxx:12
 AliFemtoSpherocityEventCut.cxx:13
 AliFemtoSpherocityEventCut.cxx:14
 AliFemtoSpherocityEventCut.cxx:15
 AliFemtoSpherocityEventCut.cxx:16
 AliFemtoSpherocityEventCut.cxx:17
 AliFemtoSpherocityEventCut.cxx:18
 AliFemtoSpherocityEventCut.cxx:19
 AliFemtoSpherocityEventCut.cxx:20
 AliFemtoSpherocityEventCut.cxx:21
 AliFemtoSpherocityEventCut.cxx:22
 AliFemtoSpherocityEventCut.cxx:23
 AliFemtoSpherocityEventCut.cxx:24
 AliFemtoSpherocityEventCut.cxx:25
 AliFemtoSpherocityEventCut.cxx:26
 AliFemtoSpherocityEventCut.cxx:27
 AliFemtoSpherocityEventCut.cxx:28
 AliFemtoSpherocityEventCut.cxx:29
 AliFemtoSpherocityEventCut.cxx:30
 AliFemtoSpherocityEventCut.cxx:31
 AliFemtoSpherocityEventCut.cxx:32
 AliFemtoSpherocityEventCut.cxx:33
 AliFemtoSpherocityEventCut.cxx:34
 AliFemtoSpherocityEventCut.cxx:35
 AliFemtoSpherocityEventCut.cxx:36
 AliFemtoSpherocityEventCut.cxx:37
 AliFemtoSpherocityEventCut.cxx:38
 AliFemtoSpherocityEventCut.cxx:39
 AliFemtoSpherocityEventCut.cxx:40
 AliFemtoSpherocityEventCut.cxx:41
 AliFemtoSpherocityEventCut.cxx:42
 AliFemtoSpherocityEventCut.cxx:43
 AliFemtoSpherocityEventCut.cxx:44
 AliFemtoSpherocityEventCut.cxx:45
 AliFemtoSpherocityEventCut.cxx:46
 AliFemtoSpherocityEventCut.cxx:47
 AliFemtoSpherocityEventCut.cxx:48
 AliFemtoSpherocityEventCut.cxx:49
 AliFemtoSpherocityEventCut.cxx:50
 AliFemtoSpherocityEventCut.cxx:51
 AliFemtoSpherocityEventCut.cxx:52
 AliFemtoSpherocityEventCut.cxx:53
 AliFemtoSpherocityEventCut.cxx:54
 AliFemtoSpherocityEventCut.cxx:55
 AliFemtoSpherocityEventCut.cxx:56
 AliFemtoSpherocityEventCut.cxx:57
 AliFemtoSpherocityEventCut.cxx:58
 AliFemtoSpherocityEventCut.cxx:59
 AliFemtoSpherocityEventCut.cxx:60
 AliFemtoSpherocityEventCut.cxx:61
 AliFemtoSpherocityEventCut.cxx:62
 AliFemtoSpherocityEventCut.cxx:63
 AliFemtoSpherocityEventCut.cxx:64
 AliFemtoSpherocityEventCut.cxx:65
 AliFemtoSpherocityEventCut.cxx:66
 AliFemtoSpherocityEventCut.cxx:67
 AliFemtoSpherocityEventCut.cxx:68
 AliFemtoSpherocityEventCut.cxx:69
 AliFemtoSpherocityEventCut.cxx:70
 AliFemtoSpherocityEventCut.cxx:71
 AliFemtoSpherocityEventCut.cxx:72
 AliFemtoSpherocityEventCut.cxx:73
 AliFemtoSpherocityEventCut.cxx:74
 AliFemtoSpherocityEventCut.cxx:75
 AliFemtoSpherocityEventCut.cxx:76
 AliFemtoSpherocityEventCut.cxx:77
 AliFemtoSpherocityEventCut.cxx:78
 AliFemtoSpherocityEventCut.cxx:79
 AliFemtoSpherocityEventCut.cxx:80
 AliFemtoSpherocityEventCut.cxx:81
 AliFemtoSpherocityEventCut.cxx:82
 AliFemtoSpherocityEventCut.cxx:83
 AliFemtoSpherocityEventCut.cxx:84
 AliFemtoSpherocityEventCut.cxx:85
 AliFemtoSpherocityEventCut.cxx:86
 AliFemtoSpherocityEventCut.cxx:87
 AliFemtoSpherocityEventCut.cxx:88
 AliFemtoSpherocityEventCut.cxx:89
 AliFemtoSpherocityEventCut.cxx:90
 AliFemtoSpherocityEventCut.cxx:91
 AliFemtoSpherocityEventCut.cxx:92
 AliFemtoSpherocityEventCut.cxx:93
 AliFemtoSpherocityEventCut.cxx:94
 AliFemtoSpherocityEventCut.cxx:95
 AliFemtoSpherocityEventCut.cxx:96
 AliFemtoSpherocityEventCut.cxx:97
 AliFemtoSpherocityEventCut.cxx:98
 AliFemtoSpherocityEventCut.cxx:99
 AliFemtoSpherocityEventCut.cxx:100
 AliFemtoSpherocityEventCut.cxx:101
 AliFemtoSpherocityEventCut.cxx:102
 AliFemtoSpherocityEventCut.cxx:103
 AliFemtoSpherocityEventCut.cxx:104
 AliFemtoSpherocityEventCut.cxx:105
 AliFemtoSpherocityEventCut.cxx:106
 AliFemtoSpherocityEventCut.cxx:107
 AliFemtoSpherocityEventCut.cxx:108
 AliFemtoSpherocityEventCut.cxx:109
 AliFemtoSpherocityEventCut.cxx:110
 AliFemtoSpherocityEventCut.cxx:111
 AliFemtoSpherocityEventCut.cxx:112
 AliFemtoSpherocityEventCut.cxx:113
 AliFemtoSpherocityEventCut.cxx:114
 AliFemtoSpherocityEventCut.cxx:115
 AliFemtoSpherocityEventCut.cxx:116
 AliFemtoSpherocityEventCut.cxx:117
 AliFemtoSpherocityEventCut.cxx:118
 AliFemtoSpherocityEventCut.cxx:119
 AliFemtoSpherocityEventCut.cxx:120
 AliFemtoSpherocityEventCut.cxx:121
 AliFemtoSpherocityEventCut.cxx:122
 AliFemtoSpherocityEventCut.cxx:123
 AliFemtoSpherocityEventCut.cxx:124
 AliFemtoSpherocityEventCut.cxx:125
 AliFemtoSpherocityEventCut.cxx:126
 AliFemtoSpherocityEventCut.cxx:127
 AliFemtoSpherocityEventCut.cxx:128
 AliFemtoSpherocityEventCut.cxx:129
 AliFemtoSpherocityEventCut.cxx:130
 AliFemtoSpherocityEventCut.cxx:131
 AliFemtoSpherocityEventCut.cxx:132
 AliFemtoSpherocityEventCut.cxx:133
 AliFemtoSpherocityEventCut.cxx:134
 AliFemtoSpherocityEventCut.cxx:135
 AliFemtoSpherocityEventCut.cxx:136
 AliFemtoSpherocityEventCut.cxx:137
 AliFemtoSpherocityEventCut.cxx:138
 AliFemtoSpherocityEventCut.cxx:139
 AliFemtoSpherocityEventCut.cxx:140
 AliFemtoSpherocityEventCut.cxx:141
 AliFemtoSpherocityEventCut.cxx:142
 AliFemtoSpherocityEventCut.cxx:143
 AliFemtoSpherocityEventCut.cxx:144
 AliFemtoSpherocityEventCut.cxx:145
 AliFemtoSpherocityEventCut.cxx:146
 AliFemtoSpherocityEventCut.cxx:147
 AliFemtoSpherocityEventCut.cxx:148
 AliFemtoSpherocityEventCut.cxx:149
 AliFemtoSpherocityEventCut.cxx:150
 AliFemtoSpherocityEventCut.cxx:151
 AliFemtoSpherocityEventCut.cxx:152
 AliFemtoSpherocityEventCut.cxx:153
 AliFemtoSpherocityEventCut.cxx:154
 AliFemtoSpherocityEventCut.cxx:155
 AliFemtoSpherocityEventCut.cxx:156
 AliFemtoSpherocityEventCut.cxx:157
 AliFemtoSpherocityEventCut.cxx:158
 AliFemtoSpherocityEventCut.cxx:159
 AliFemtoSpherocityEventCut.cxx:160
 AliFemtoSpherocityEventCut.cxx:161
 AliFemtoSpherocityEventCut.cxx:162
 AliFemtoSpherocityEventCut.cxx:163
 AliFemtoSpherocityEventCut.cxx:164
 AliFemtoSpherocityEventCut.cxx:165
 AliFemtoSpherocityEventCut.cxx:166
 AliFemtoSpherocityEventCut.cxx:167
 AliFemtoSpherocityEventCut.cxx:168
 AliFemtoSpherocityEventCut.cxx:169
 AliFemtoSpherocityEventCut.cxx:170
 AliFemtoSpherocityEventCut.cxx:171
 AliFemtoSpherocityEventCut.cxx:172
 AliFemtoSpherocityEventCut.cxx:173
 AliFemtoSpherocityEventCut.cxx:174
 AliFemtoSpherocityEventCut.cxx:175
 AliFemtoSpherocityEventCut.cxx:176
 AliFemtoSpherocityEventCut.cxx:177
 AliFemtoSpherocityEventCut.cxx:178
 AliFemtoSpherocityEventCut.cxx:179