]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AOD/AliAODHandler.cxx
drawCorrelation macro adapted for Toy Model (MW)
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODHandler.cxx
index 04c17d32176bb1ce22f980f3fa9bd9270b47bb7c..b10e87ecd46bc1b30182199d74a24abea466f49f 100644 (file)
@@ -47,6 +47,8 @@
 #include "AliAODBranchReplicator.h"
 #include "Riostream.h"
 
+using std::endl;
+using std::cout;
 ClassImp(AliAODHandler)
 
 //______________________________________________________________________________
@@ -57,6 +59,8 @@ AliAODHandler::AliAODHandler() :
     fFillAODRun(kTRUE),
     fFillExtension(kTRUE),
     fNeedsHeaderReplication(kFALSE),
+    fNeedsTOFHeaderReplication(kFALSE),
+    fNeedsVZEROReplication(kFALSE),
     fNeedsTracksBranchReplication(kFALSE),
     fNeedsVerticesBranchReplication(kFALSE),
     fNeedsV0sBranchReplication(kFALSE),
@@ -69,6 +73,7 @@ AliAODHandler::AliAODHandler() :
        fNeedsCaloTriggerBranchReplication(kFALSE),
     fNeedsMCParticlesBranchReplication(kFALSE),
     fNeedsDimuonsBranchReplication(kFALSE),
+    fNeedsHMPIDBranchReplication(kFALSE),
     fAODIsReplicated(kFALSE),
     fAODEvent(NULL),
     fMCEventH(NULL),
@@ -89,6 +94,8 @@ AliAODHandler::AliAODHandler(const char* name, const char* title):
     fFillAODRun(kTRUE),
     fFillExtension(kTRUE),
     fNeedsHeaderReplication(kFALSE),
+    fNeedsTOFHeaderReplication(kFALSE),
+    fNeedsVZEROReplication(kFALSE),
     fNeedsTracksBranchReplication(kFALSE),
     fNeedsVerticesBranchReplication(kFALSE),
     fNeedsV0sBranchReplication(kFALSE),
@@ -98,9 +105,10 @@ AliAODHandler::AliAODHandler(const char* name, const char* title):
     fNeedsJetsBranchReplication(kFALSE),
     fNeedsFMDClustersBranchReplication(kFALSE),
     fNeedsCaloClustersBranchReplication(kFALSE),
-       fNeedsCaloTriggerBranchReplication(kFALSE),
+    fNeedsCaloTriggerBranchReplication(kFALSE),
     fNeedsMCParticlesBranchReplication(kFALSE),
     fNeedsDimuonsBranchReplication(kFALSE),
+    fNeedsHMPIDBranchReplication(kFALSE),
     fAODIsReplicated(kFALSE),
     fAODEvent(NULL),
     fMCEventH(NULL),
@@ -120,13 +128,9 @@ AliAODHandler::~AliAODHandler()
   
   delete fAODEvent;
 
-  if (fFileA)
-  {
-    // is already handled in TerminateIO
-    fFileA->Close();
-    delete fFileA;
-    fTreeA = 0;
-  }
+  if (fFileA) fFileA->Close();
+
+  delete fFileA;
   delete fTreeA;
   delete fExtensions;
   delete fFilters;
@@ -262,28 +266,28 @@ void AliAODHandler::StoreMCParticles(){
       TArrayF vtxMC(3);
       genHeader->PrimaryVertex(vtxMC);
       mcHeader->SetVertex(vtxMC[0],vtxMC[1],vtxMC[2]);
-
       // we search the MCEventHeaders first 
       // Two cases, cocktail or not...
       AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
       if(genCocktailHeader){
-         // we have a coktail header
+         // we have a coktail header add the name once
          mcHeader->AddGeneratorName(genHeader->GetName());
-         // Loop from the back so that the first one sets the process type
          TList* headerList = genCocktailHeader->GetHeaders();
-         for(int i = headerList->GetEntries()-1;i>=0;--i){
-             AliGenEventHeader *headerEntry = dynamic_cast<AliGenEventHeader*>(headerList->At(i));
-         if (!headerEntry) {
-           AliFatal("AliGenEventHeader entry not found in the header list");
-         } else {   
-           SetMCHeaderInfo(mcHeader,headerEntry);
-         }  
-         }
+         // the first entry defines some extra general settings
+         AliGenEventHeader *headerEntry = dynamic_cast<AliGenEventHeader*>(headerList->At(0));
+         if (!headerEntry) {
+           AliFatal("AliGenEventHeader entry not found in the header list");
+         } else {   
+           SetMCHeaderInfo(mcHeader,headerEntry);
+         }  
       }
       else{
-         // No Cocktail just take the first one
-         SetMCHeaderInfo(mcHeader,genHeader);
+       // No Cocktail just take the first one
+       SetMCHeaderInfo(mcHeader,genHeader);
       }
+      // Add all the headers and names, if no cocktail header 
+      // there will be only one entry
+      mcHeader->AddCocktailHeaders(genHeader);
   }
   
 
@@ -307,7 +311,9 @@ void AliAODHandler::StoreMCParticles(){
          if(i<nprim)flag |= AliAODMCParticle::kPrimary;
          
          if(mcEvent->IsPhysicalPrimary(i))flag |= AliAODMCParticle::kPhysicalPrim;
-         
+         if(mcEvent->IsSecondaryFromWeakDecay(i))flag |= AliAODMCParticle::kSecondaryFromWeakDecay;
+         if(mcEvent->IsSecondaryFromMaterial(i))flag |= AliAODMCParticle::kSecondaryFromMaterial;
+
          if(fMCEventH->GetNewLabel(i)!=j){
              AliError(Form("MISMATCH New label %d j: %d",fMCEventH->GetNewLabel(i),j));
          }
@@ -315,6 +321,7 @@ void AliAODHandler::StoreMCParticles(){
          AliAODMCParticle mcpartTmp(mcpart,i,flag);
          
          mcpartTmp.SetStatus(mcpart->Particle()->GetStatusCode());
+         mcpartTmp.SetMCProcessCode(mcpart->Particle()->GetUniqueID());
          // 
          Int_t d0 =  mcpartTmp.GetDaughter(0);
          Int_t d1 =  mcpartTmp.GetDaughter(1);
@@ -379,6 +386,7 @@ void AliAODHandler::StoreMCParticles(){
 
   // AODTracks
   TClonesArray* tracks = fAODEvent->GetTracks();
+  Int_t tofLabel[3];
   if(tracks){
     for(int it = 0; it < fAODEvent->GetNTracks();++it){
       AliAODTrack *track = fAODEvent->GetTrack(it);
@@ -389,7 +397,7 @@ void AliAODHandler::StoreMCParticles(){
        label *= -1;
        sign  = -1;
       }
-
+      
       if (label >= AliMCEvent::BgLabelOffset()) label =  mcEvent->BgLabelToIndex(label);
       if(label > np || track->GetLabel() == 0){
        AliWarning(Form("Wrong ESD track label %5d (%5d)",track->GetLabel(), label));
@@ -398,6 +406,23 @@ void AliAODHandler::StoreMCParticles(){
        AliWarning(Form("New label not found for %5d (%5d)",track->GetLabel(), label));
       }
       track->SetLabel(sign*fMCEventH->GetNewLabel(label));
+      
+      track->GetTOFLabel(tofLabel);
+      
+      for (Int_t i =0; i < 3; i++) {
+       label  = tofLabel[i]; // esd label
+       Int_t nlabel = label; // new label
+       if (label < 0) continue;
+       if (label >= AliMCEvent::BgLabelOffset()) nlabel =  mcEvent->BgLabelToIndex(label);
+       if(nlabel > np || label == 0) {
+         AliWarning(Form("Wrong TOF label %5d (%5d)", label, nlabel));
+       }
+       if(fMCEventH->GetNewLabel(label) == 0){
+         AliWarning(Form("New TOF label not found for %5d",label ));
+       }
+       tofLabel[i] = fMCEventH->GetNewLabel(label);
+      } 
+      track->SetTOFLabel(tofLabel);
     }
   }
   
@@ -418,6 +443,43 @@ void AliAODHandler::StoreMCParticles(){
       //      cluster->SetLabels(labels,nLabel);
     }// iClust
   }// clusters
+  
+  // AOD calo cells MC label re-index
+  Int_t iCell, nCell, cellMCLabel, cellMCLabelNew;;
+  Short_t cellAbsId;
+  Double_t cellE, cellT, cellEFrac;
+  AliAODCaloCells *cells;
+  
+  // EMCal
+  cells = fAODEvent->GetEMCALCells();
+  if( cells ){
+    nCell = cells->GetNumberOfCells() ;
+    for( iCell = 0; iCell < nCell; iCell++ ){ 
+      cells->GetCell( iCell, cellAbsId, cellE, cellT, cellMCLabel, cellEFrac );
+      // GetNewLabel returns 1 in case when -1 is supplied
+      if( cellMCLabel < 0 )
+        cellMCLabelNew = cellMCLabel;
+      else
+        cellMCLabelNew = fMCEventH->GetNewLabel( cellMCLabel );
+        
+      cells->SetCell( iCell, cellAbsId, cellE, cellT, cellMCLabelNew, cellEFrac );
+    }
+  }
+  // PHOS
+  cells = fAODEvent->GetPHOSCells();
+  if( cells ){
+    nCell = cells->GetNumberOfCells() ;
+    for( iCell = 0; iCell < nCell; iCell++ ){ 
+      cells->GetCell( iCell, cellAbsId, cellE, cellT, cellMCLabel, cellEFrac );
+      // GetNewLabel returns 1 in case when -1 is supplied
+      if( cellMCLabel < 0 )
+        cellMCLabelNew = cellMCLabel;
+      else
+        cellMCLabelNew = fMCEventH->GetNewLabel( cellMCLabel );
+        
+      cells->SetCell( iCell, cellAbsId, cellE, cellT, cellMCLabelNew, cellEFrac );
+    }
+  }
 
   // AOD tracklets
   AliAODTracklets *tracklets = fAODEvent->GetTracklets();
@@ -661,7 +723,7 @@ void AliAODHandler::SetOutputFileName(const char* fname)
 }
 
 //______________________________________________________________________________
-const char *AliAODHandler::GetOutputFileName()
+const char *AliAODHandler::GetOutputFileName() const
 {
 // Get file name.
    return fFileName.Data();
@@ -708,20 +770,17 @@ void  AliAODHandler::SetMCHeaderInfo(AliAODMCHeader *mcHeader,AliGenEventHeader
   // Utility function to cover different cases for the AliGenEventHeader
   // Needed since different ProcessType and ImpactParamter are not 
   // in the base class...
-  // We don't encode process types for event cocktails yet
-  // could be done e.g. by adding offsets depnding on the generator
 
   if(!genHeader)return;
-  mcHeader->AddGeneratorName(genHeader->GetName());
   AliGenPythiaEventHeader *pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
-    if (pythiaGenHeader) {
-      mcHeader->SetEventType(pythiaGenHeader->ProcessType());
-      mcHeader->SetPtHard(pythiaGenHeader->GetPtHard());
-      return;
-    }
-    
-    AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(genHeader);
-
+  if (pythiaGenHeader) {
+    mcHeader->SetEventType(pythiaGenHeader->ProcessType());
+    mcHeader->SetPtHard(pythiaGenHeader->GetPtHard());
+    return;
+  }
+  
+  AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(genHeader);
+  
   if (dpmJetGenHeader){
     mcHeader->SetEventType(dpmJetGenHeader->ProcessType());
     return;
@@ -733,7 +792,7 @@ void  AliAODHandler::SetMCHeaderInfo(AliAODMCHeader *mcHeader,AliGenEventHeader
     return;
   }
   
-  AliWarning(Form("MC Eventheader not known: %s",genHeader->GetName()));
-
+  //  AliWarning(Form("MC Eventheader not known: %s",genHeader->GetName()));
+  
 }