ConvGamma preburner update
authorslindal <slindal@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 9 May 2011 13:22:35 +0000 (13:22 +0000)
committerslindal <slindal@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 9 May 2011 13:22:35 +0000 (13:22 +0000)
PWG4/GammaConv/AliAnalysisTaskGCPartToPWG4Part.cxx
PWG4/GammaConv/AliAnalysisTaskGCPartToPWG4Part.h

index 8aff6d2..02c536b 100644 (file)
@@ -39,8 +39,11 @@ ClassImp(AliAnalysisTaskGCPartToPWG4Part)
 AliAnalysisTaskGCPartToPWG4Part::AliAnalysisTaskGCPartToPWG4Part() 
 : AliAnalysisTaskSE(), 
   fDeltaAODFileName(""),
+  fGammaCutString("GammaConv"),
+  fPionCutString("GammaConv"),
   fAODBranchName("GammaConv_gamma"),
-  fAODPWG4Particles(NULL),
+  fAODPWG4Photons(NULL),
+  fAODPWG4Pi0(NULL),
    fDebugLevel(0)
 {
   // Dummy Constructor
@@ -49,10 +52,14 @@ AliAnalysisTaskGCPartToPWG4Part::AliAnalysisTaskGCPartToPWG4Part()
 //________________________________________________________________________________
 AliAnalysisTaskGCPartToPWG4Part::~AliAnalysisTaskGCPartToPWG4Part() {
 
-  if(fAODPWG4Particles)
-    fAODPWG4Particles = NULL;
-  delete fAODPWG4Particles;
+  if(fAODPWG4Photons)
+    delete fAODPWG4Photons;
+  fAODPWG4Photons = NULL;
 
+  if(fAODPWG4Pi0)
+    delete fAODPWG4Pi0;
+  fAODPWG4Pi0 = NULL;
 
 }
 
@@ -62,8 +69,11 @@ AliAnalysisTaskGCPartToPWG4Part::~AliAnalysisTaskGCPartToPWG4Part() {
 AliAnalysisTaskGCPartToPWG4Part::AliAnalysisTaskGCPartToPWG4Part(const char *name) : 
   AliAnalysisTaskSE(name), 
   fDeltaAODFileName(""),
+  fGammaCutString("GammaConv"),
+  fPionCutString("GammaConv"),
   fAODBranchName("GammaConv_gamma"),
-  fAODPWG4Particles(NULL),
+  fAODPWG4Photons(NULL),
+  fAODPWG4Pi0(NULL),
   fDebugLevel(0)
 {
   // Constructor
@@ -79,9 +89,13 @@ AliAnalysisTaskGCPartToPWG4Part::AliAnalysisTaskGCPartToPWG4Part(const char *nam
 
 //________________________________________________________________________
 void AliAnalysisTaskGCPartToPWG4Part::UserCreateOutputObjects() {
-  fAODPWG4Particles = new TClonesArray("AliAODPWG4ParticleCorrelation", 0);
-  fAODPWG4Particles->SetName("ConversionGamma");
-  AddAODBranch("TClonesArray", &fAODPWG4Particles);
+  fAODPWG4Photons = new TClonesArray("AliAODPWG4ParticleCorrelation", 0);
+  fAODPWG4Photons->SetName("PhotonsCTS");
+  AddAODBranch("TClonesArray", &fAODPWG4Photons);
+
+  fAODPWG4Pi0 = new TClonesArray("AliAODPWG4ParticleCorrelation", 0);
+  fAODPWG4Pi0->SetName("Pi0sCTS");
+  AddAODBranch("TClonesArray", &fAODPWG4Pi0);
 
 }
 
@@ -89,7 +103,7 @@ void AliAnalysisTaskGCPartToPWG4Part::UserCreateOutputObjects() {
 void AliAnalysisTaskGCPartToPWG4Part::UserExec(Option_t *) 
 {
   
-  AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
+  //AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
 
   //Clear stuff for new event
   CleanUp();
@@ -101,11 +115,7 @@ void AliAnalysisTaskGCPartToPWG4Part::UserExec(Option_t *)
     return;
   }
   
-
   ProcessConvGamma(aodEvent);
-
-
-  //PostData(1, fOutputList);
         
 }
 
@@ -133,18 +143,12 @@ void AliAnalysisTaskGCPartToPWG4Part::ProcessConvGamma( const AliAODEvent * cons
   for (Int_t iPhot = 0; iPhot < convGamma->GetEntriesFast(); iPhot++) {
 
     AliAODPWG4ParticleCorrelation * photon = NULL;
-    AliGammaConversionAODObject * aodO = dynamic_cast<AliGammaConversionAODObject*>(convGamma->At(iPhot));
-    if(aodO) {  
-      photon = AddToAOD(aodO, fAODPWG4Particles, "ConvGamma");
-    } else {   
-      AliAODConversionParticle * convParticle = dynamic_cast<AliAODConversionParticle*>(convGamma->At(iPhot));
-      if (convParticle) {
-       photon = AddToAOD(convParticle, fAODPWG4Particles, "ConvGamma");
+    AliAODConversionParticle * convParticle = dynamic_cast<AliAODConversionParticle*>(convGamma->At(iPhot));
+    if (convParticle && BothTracksPresent(convParticle, tracks)) {
+      photon = AddToAOD(convParticle, fAODPWG4Photons, "ConvGamma");
       
-      } else {
-       AliError(Form("ERROR: Could not receive ga %d\n", iPhot));
-       continue;
-      }
+    } else {
+      continue;
     }
     
     if(photon && fDebugLevel > 2) {
@@ -153,145 +157,33 @@ void AliAnalysisTaskGCPartToPWG4Part::ProcessConvGamma( const AliAODEvent * cons
 
   }
 
-}
-
-
-//////_________________________________________________________________________________________
-//Int_t AliAnalysisTaskGCPartToPWG4Part::CheckTag(AliAODPWG4ParticleCorrelation * particle, TClonesArray * tracks, TClonesArray * arrayMC, AliAODMCHeader * mcHeader) {
-
-
-  // for (int imc = 0; imc < arrayMC->GetEntriesFast(); imc++) {
-  // //for (int imc = 0; imc < 20; imc++) {
-
-    
-    
-  //   AliAODMCParticle * mParticle = dynamic_cast<AliAODMCParticle*>(arrayMC->At(imc));
-  //   //    cout << mParticle->GetPdgCode() << " " <<mParticle->GetStatus() << endl;
-
-   
-  //   //if( mParticle->GetPdgCode() == 34) cout<< "BALLE"<<endl;// && mParticle->GetMother() < 10) {
-
-  //   if( mParticle->GetPdgCode() == 22 ) { //&& mParticle->GetMother() < 10) {
-  //     //AliAODMCParticle * mother = dynamic_cast<AliAODMCParticle*>(arrayMC->At(mParticle->GetMother()));
-  //     //if (TMath::Abs(mother->GetPdgCode()) < 22 && TMath::Abs(mother->GetPdgCode()) != 11) cout  <<"KKKKKKKKK"<< mother->GetPdgCode() <<endl;
-       
-  //     for (int id = 0; id < mParticle->GetNDaughters(); id++) {
-  //   int idaughter = mParticle->GetDaughter(id);
-  //   if(idaughter>0 && idaughter < arrayMC->GetEntriesFast()) {
-  //     AliAODMCParticle * dmParticle = dynamic_cast<AliAODMCParticle*>(arrayMC->At(mParticle->GetDaughter(id)));
-  //     cout  << dmParticle->GetPdgCode() << endl; 
-  //   }
-  //     }
-  //   }
-  // }
-
-
-
-
-
-
-
-
-
-
-
-
-  // Int_t tag = 0;
-
-  // Int_t l1 = particle->GetTrackLabel(0);
-  // Int_t l2 = particle->GetTrackLabel(1);
-  
-  // AliAODTrack * track1 = NULL;
-  // AliAODTrack * track2 = NULL;
 
+  TClonesArray * pions = GetPions(aodEvent);
+  if(!pions) {
+    AliError(Form("No branch by name %s found in file %s", fAODBranchName.Data(), fDeltaAODFileName.Data()));
+    return;
+  }
 
-  // for(int i = 0; i < tracks->GetEntriesFast(); i++) {
-    
-  //   AliAODTrack * track = (AliAODTrack*)tracks->At(i);
-  //   if (track->GetID() == l1) {
-  //     track1 = track;
-  //   } else if (track->GetID() == l2) {
-  //     track2 = track; 
-  //   }
+  for (Int_t iPhot = 0; iPhot < pions->GetEntriesFast(); iPhot++) {
+    AliAODPWG4ParticleCorrelation * pion = NULL;
+    AliAODConversionParticle * convParticle = dynamic_cast<AliAODConversionParticle*>(pions->At(iPhot));
+    if (convParticle && BothGammaPresent(convParticle, convGamma, tracks)) {
+      pion = AddPionToAOD(convParticle, fAODPWG4Pi0, "ConvGamma", convGamma);
+      
+    } else {
+      continue;
+    }
     
-  //   if(track1 && track2) break;
-  // }
-
+    if(pion && fDebugLevel > 2) {
+      printf("Added conversion pion number %d, pt: %f \n", iPhot, pion->Pt());
+    }
+  }
 
-  // if(!track1 || !track2) return tag;
-  // if(track1->GetLabel() < 0 || track2->GetLabel() < 0) {
-  //   //cout << "error balla"<< endl; 
   
-  // } else { 
-
-  //   AliAODMCParticle * mcPart1 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(track1->GetLabel()));
-  //   AliAODMCParticle * mcPart2 = dynamic_cast<AliAODMCParticle*>(arrayMC->At(track2->GetLabel()));
-    
-  //   if (mcPart1 && mcPart2) {
-
-  //     if(mcPart1->GetMother() == mcPart2->GetMother()) {
-       
-  //   AliAODMCParticle * photon = dynamic_cast<AliAODMCParticle*>(arrayMC->At(mcPart1->GetMother()));
-  //   Int_t motherIndex = photon->GetMother();
-  //   //tag= fAnaUtils->CheckOriginInAOD(&motherIndex, 1, arrayMC);
-
-  //   AliAODMCParticle * mother = dynamic_cast<AliAODMCParticle*>(arrayMC->At(motherIndex));
-  //   if(!mother) continue;
-
-  //   if (photon->GetPdgCode() == 22 ) {
-
-  //     if (TMath::Abs(mother->GetPdgCode()) < 22 && TMath::Abs(mother->GetPdgCode()) != 11) {
-           
-  //       //fAnaUtils->SetTagBit(tag, AliMCAnalysisUtils::kMCPhoton);
-  //       //fAnaUtils->SetTagBit(tag, AliMCAnalysisUtils::kMCPrompt);
-           
-  //       cout  <<"KKKKKKKKK "<< mother->GetPdgCode() << " " << mother->GetStatus() << " mi " << motherIndex << " daught: " << mother->GetNDaughters() << endl;
-  //       cout << photon->GetStatus() << " " << photon->Pt() << " headerpt:" << mcHeader->GetPtHard() << " " <<mcPart1->GetMother() << endl;
-           
-  //     }
-  //   } else {
-  //     cout << "FAKE "<< photon->PdgCode() << " " << photon->Pt() << " " <<  photon->GetStatus() << endl;
-  //   }
 
-
-       
-
-
-
-  //   //Int_t parentId = mother->GetMother();
-  //   //AliAODMCParticle * gp = dynamic_cast<AliAODMCParticle*>(arrayMC->At(parentId));
+}
 
 
-       
-
-  //   if(! mother->IsPrimary()) {
-  //     //cout << mother->GetPdgCode() << " " << mother->GetStatus() <<endl;
-  //     //      cout << "other one? " << mother->PdgCode() << " " << gp->PdgCode() << " " << gp->GetStatus() << endl;
-  //     //    cout << "yeay3  " <<  mother->GetPdgCode() << endl;
-  //   } else { //if (mother->IsPhysicalPrimary() ){
-         
-         
-  //     if(mother->GetStatus() < 10) {
-  //       //cout << "yeay4  " <<  mother->GetPdgCode() << endl;
-  //       // cout << "pion? " << gp->PdgCode() << " " << gp->GetStatus() << endl;
-  //       //cout << "???" << mother->PdgCode() << " " << mother->GetStatus() << " " << gp->PdgCode() << " " << gp->GetStatus() << endl;
-  //     } else {
-  //       //cout << "yeay5  " <<  mother->GetPdgCode() << endl;
-  //       //cout << "other? " << mother->PdgCode() << " " << mother->GetStatus() << " " << gp->PdgCode() << " " << gp->GetStatus() << endl;
-  //     }
-         
-         
-  //     // } else {
-  //     //   cout << "MI: " << mother->GetPdgCode() << " " << mother->GetStatus() <<endl;
-  //   }
-       
-  //     }
-  //   }
-  // }
-  // //cout << "REturn tag " << tag << endl;
-  //return 0;
-//}
 
 
 ///__________________________________________________________________________________
@@ -323,6 +215,27 @@ AliAODPWG4ParticleCorrelation * AliAnalysisTaskGCPartToPWG4Part::AddToAOD(AliAOD
 }
 
 
+///__________________________________________________________________________________
+AliAODPWG4ParticleCorrelation * AliAnalysisTaskGCPartToPWG4Part::AddPionToAOD(AliAODConversionParticle * pion, TClonesArray * branch, TString detector, TClonesArray * photons) {
+  new((*branch)[branch->GetEntriesFast()]) AliAODPWG4ParticleCorrelation(pion->Px(), pion->Py(), pion->Pz(), pion->E());
+  AliAODPWG4ParticleCorrelation * pwg4Pion = dynamic_cast<AliAODPWG4ParticleCorrelation*>(branch->Last());
+  if(pwg4Pion) {
+    Int_t tl[4] = {-1, -1, -1, -1};
+    pion->GetGrandChildren(photons, tl);
+    pwg4Pion->SetTrackLabel(tl[0], tl[1], tl[2], tl[3]);
+    pwg4Pion->SetDetector(detector);
+    for(Int_t i = 0; i < 4; i++) {
+      cout << tl[i] << " ";
+    }
+    cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
+    return pwg4Pion;
+  } else {
+    return NULL;
+  }
+  
+}
+
+
 
 
 //_____________________________________________________________________
@@ -343,16 +256,17 @@ AliAODEvent * AliAnalysisTaskGCPartToPWG4Part::GetAODEvent() {
 
 }
 
+
 //_____________________________________________________________________
-TClonesArray * AliAnalysisTaskGCPartToPWG4Part::GetConversionGammas(const AliAODEvent * aodEvent) {
+TClonesArray * AliAnalysisTaskGCPartToPWG4Part::GetAODBranch(const AliAODEvent * aodEvent, TString branchName) const {
 
   //Get Conversion gamma branch of AOD. First try standard AOD
-  TClonesArray * convGamma = dynamic_cast<TClonesArray*>(aodEvent->FindListObject(fAODBranchName.Data()));
+  TClonesArray * branch = dynamic_cast<TClonesArray*>(aodEvent->FindListObject(branchName.Data()));
   
 
   //If it's there, send it back
-  if(convGamma)  return convGamma;
-
+  if(branch)  return branch;
+  
 
   //If AOD not in standard file have to locate it in delta AOD
   if( !(fDeltaAODFileName.Length() > 0)  ) return NULL;
@@ -362,15 +276,66 @@ TClonesArray * AliAnalysisTaskGCPartToPWG4Part::GetConversionGammas(const AliAOD
     AliAODExtension * gExt = dynamic_cast<AliAODExtension*>(aodHandler->GetExtensions()->FindObject(fDeltaAODFileName));
     if(gExt) {
       AliAODEvent * gcEvent = gExt->GetAOD();
-      return dynamic_cast<TClonesArray*>(gcEvent->FindListObject("GammaConv_gamma"));
+      return dynamic_cast<TClonesArray*>(gcEvent->FindListObject(branchName.Data()));
     }
   }  
   return NULL;
+
 }
+//_____________________________________________________________________
+TClonesArray * AliAnalysisTaskGCPartToPWG4Part::GetConversionGammas(const AliAODEvent * aodEvent) const {
+  return GetAODBranch(aodEvent, Form("%s_gamma", fGammaCutString.Data()));
+}
+
+//_____________________________________________________________________
+TClonesArray * AliAnalysisTaskGCPartToPWG4Part::GetPions(const AliAODEvent * aodEvent) const {
+    return GetAODBranch(aodEvent, Form("%s_Pi0", fPionCutString.Data()));
+}
+
 
 //_________________________________________________________________________
 void AliAnalysisTaskGCPartToPWG4Part::CleanUp() {
-  fAODPWG4Particles->Delete();
+  fAODPWG4Photons->Delete();
+  fAODPWG4Pi0->Delete();
 }
 
 
+//______________________________________________________________________________________________
+Bool_t AliAnalysisTaskGCPartToPWG4Part::BothTracksPresent(const AliAODConversionParticle * const photon, const TClonesArray * const tracks)  const {
+
+  AliAODTrack * track1 = NULL;
+  AliAODTrack * track2 = NULL;
+  for(Int_t i = 0; i < tracks->GetEntriesFast(); i++) {
+    AliAODTrack * track = dynamic_cast<AliAODTrack*>(tracks->At(i));
+    if(track->GetID() == photon->GetLabel1()) track1 = track;
+    else if (track->GetID() == photon->GetLabel2()) track2 = track;
+    if(track1 && track2) break;
+  }
+  
+  if(track1 && track2) {
+    return kTRUE;
+  }
+  cout << "Could not get both tracks!!! labels "  << photon->GetLabel1() << " " << photon->GetLabel2()  <<endl;
+  return kFALSE;
+  
+
+}
+
+//______________________________________________________________________________________________
+Bool_t AliAnalysisTaskGCPartToPWG4Part::BothGammaPresent(const AliAODConversionParticle * const pion, const TClonesArray * const photons, const TClonesArray * const tracks)  const {
+
+  AliAODConversionParticle * photon1 = dynamic_cast<AliAODConversionParticle*>(photons->At(pion->GetLabel1()));
+  AliAODConversionParticle * photon2 = dynamic_cast<AliAODConversionParticle*>(photons->At(pion->GetLabel2()));
+
+  if(photon1 && photon2) {
+    if( BothTracksPresent(photon1, tracks) &&  BothTracksPresent(photon1, tracks)) {
+      return kTRUE;
+    }
+  } else {
+    cout << "can't find both photons "<< endl;
+  }
+  
+  return kFALSE;
+}
index fe30e15..011262a 100644 (file)
@@ -34,6 +34,10 @@ public:
 \r
   void SetDebugLevel(Int_t debugLevel) { fDebugLevel = debugLevel; }\r
   Int_t GetDebugLevel() const { return fDebugLevel; }\r
+\r
+  void SetGammaCutId(TString cut) { fGammaCutString = Form("GammaConv_%s", cut.Data());}\r
+  void SetPionCutId(TString cut) { fPionCutString = Form("GammaConv_%s", cut.Data());}\r
+\r
   \r
  private:\r
 \r
@@ -43,19 +47,28 @@ public:
   //Get the AOD event from whereever it might be accessible\r
   AliAODEvent * GetAODEvent();\r
 \r
+  Bool_t BothTracksPresent(const AliAODConversionParticle * const photon, const TClonesArray * const tracks) const;\r
+  Bool_t BothGammaPresent(const AliAODConversionParticle * const pion, const TClonesArray * const photons, const TClonesArray * const tracks) const;\r
+\r
   //Get Conversion gammas branch\r
-  TClonesArray * GetConversionGammas(const AliAODEvent * aodEvent);\r
+  TClonesArray * GetConversionGammas(const AliAODEvent * aodEvent) const;\r
+  TClonesArray * GetPions(const AliAODEvent * aodEvent) const;\r
+  TClonesArray * GetAODBranch(const AliAODEvent * aodEvent, TString branchName) const;\r
 \r
   //Fill AOD tree with PWG4 particles\r
   AliAODPWG4ParticleCorrelation * AddToAOD(AliGammaConversionAODObject * aodO, TClonesArray * branch, TString detector);\r
   AliAODPWG4ParticleCorrelation * AddToAOD(AliAODConversionParticle * aodO, TClonesArray * branch, TString detector);\r
-  \r
+  AliAODPWG4ParticleCorrelation * AddPionToAOD(AliAODConversionParticle * pion, TClonesArray * branch, TString detector, TClonesArray * photons);  \r
   //Process conv gamma\r
   void ProcessConvGamma( const AliAODEvent * const aodEvent );\r
 \r
   TString     fDeltaAODFileName;//! File where Gamma Conv AOD is located, if not in default AOD\r
+  TString     fGammaCutString;   //! The cut string of the conversion analysis used to produce input AOD\r
+  TString     fPionCutString;   //! The cut string of the conversion analysis used to produce input AOD\r
   TString     fAODBranchName;\r
-  TClonesArray * fAODPWG4Particles;\r
+  TClonesArray * fAODPWG4Photons;\r
+  TClonesArray * fAODPWG4Pi0;\r
+\r
 \r
   Int_t fDebugLevel;\r
 \r