]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
Updates on Lambda_c decays (S. Masciocchi)
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index 62fbd87c3fcdddf5e2906e4f255c23dbef315f9c..6c9c329408756478e0290d92264757218122099b 100644 (file)
 #include "AliDetectorTag.h"
 #include "AliEventTag.h"
 
+#include "AliGeomManager.h"
 #include "AliTrackPointArray.h"
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
@@ -200,6 +201,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdb
   fOptions(),
   fLoadAlignFromCDB(kTRUE),
   fLoadAlignData("ALL"),
+  fESDPar(""),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -248,6 +250,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fOptions(),
   fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
   fLoadAlignData(rec.fLoadAlignData),
+  fESDPar(rec.fESDPar),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -380,6 +383,9 @@ void AliReconstruction::SetSpecificStorage(const char* calibType, const char* ur
 
 }
 
+
+
+
 //_____________________________________________________________________________
 Bool_t AliReconstruction::SetRunNumber()
 {
@@ -417,72 +423,6 @@ Bool_t AliReconstruction::SetRunNumber()
   return kTRUE;
 }
 
-//_____________________________________________________________________________
-Bool_t AliReconstruction::ApplyAlignObjsToGeom(TObjArray* alObjArray)
-{
-  // Read collection of alignment objects (AliAlignObj derived) saved
-  // in the TClonesArray ClArrayName and apply them to the geometry
-  // manager singleton.
-  //
-  alObjArray->Sort();
-  Int_t nvols = alObjArray->GetEntriesFast();
-
-  Bool_t flag = kTRUE;
-
-  for(Int_t j=0; j<nvols; j++)
-    {
-      AliAlignObj* alobj = (AliAlignObj*) alObjArray->UncheckedAt(j);
-      if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
-    }
-
-  if (AliDebugLevelClass() >= 1) {
-    gGeoManager->GetTopNode()->CheckOverlaps(20);
-    TObjArray* ovexlist = gGeoManager->GetListOfOverlaps();
-    if(ovexlist->GetEntriesFast()){  
-      AliError("The application of alignment objects to the geometry caused huge overlaps/extrusions!");
-   }
-  }
-
-  return flag;
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliReconstruction::SetAlignObjArraySingleDet(const char* detName)
-{
-  // Fills array of single detector's alignable objects from CDB
-  
-  AliDebug(2, Form("Loading alignment data for detector: %s",detName));
-  
-  AliCDBEntry *entry;
-       
-  AliCDBPath path(detName,"Align","Data");
-       
-  entry=AliCDBManager::Instance()->Get(path.GetPath());
-  if(!entry){ 
-       AliDebug(2,Form("Couldn't load alignment data for detector %s",detName));
-       return kFALSE;
-  }
-  entry->SetOwner(1);
-  TClonesArray *alignArray = (TClonesArray*) entry->GetObject();       
-  alignArray->SetOwner(0);
-  AliDebug(2,Form("Found %d alignment objects for %s",
-                       alignArray->GetEntries(),detName));
-
-  AliAlignObj *alignObj=0;
-  TIter iter(alignArray);
-       
-  // loop over align objects in detector
-  while( ( alignObj=(AliAlignObj *) iter.Next() ) ){
-       fAlignObjArray->Add(alignObj);
-  }
-  // delete entry --- Don't delete, it is cached!
-       
-  AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
-  return kTRUE;
-
-}
-
 //_____________________________________________________________________________
 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
 {
@@ -496,52 +436,35 @@ Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
 
   // Load alignment data from CDB and fill fAlignObjArray 
   if(fLoadAlignFromCDB){
-       if(!fAlignObjArray) fAlignObjArray = new TObjArray();
        
-       //fAlignObjArray->RemoveAll(); 
-       fAlignObjArray->Clear();        
-       fAlignObjArray->SetOwner(0);
-       TString detStr = detectors;
-       TString dataNotLoaded="";
-       TString dataLoaded="";
-  
-       for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
-         if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
-         if(!SetAlignObjArraySingleDet(fgkDetectorName[iDet])){
-           dataNotLoaded += fgkDetectorName[iDet];
-           dataNotLoaded += " ";
-         } else {
-           dataLoaded += fgkDetectorName[iDet];
-           dataLoaded += " ";
-         }
-       } // end loop over detectors
-  
-       if ((detStr.CompareTo("ALL") == 0)) detStr = "";
-       dataNotLoaded += detStr;
-       if(!dataLoaded.IsNull()) AliInfo(Form("Alignment data loaded for: %s",
-                         dataLoaded.Data()));
-       if(!dataNotLoaded.IsNull()) AliInfo(Form("Didn't/couldn't load alignment data for: %s",
-                         dataNotLoaded.Data()));
-  } // fLoadAlignFromCDB flag
-  // Check if the array with alignment objects was
-  // provided by the user. If yes, apply the objects
-  // to the present TGeo geometry
-  if (fAlignObjArray) {
-    if (gGeoManager && gGeoManager->IsClosed()) {
-      if (ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
-       AliError("The misalignment of one or more volumes failed!"
-                "Compare the list of simulated detectors and the list of detector alignment data!");
+    TString detStr = detectors;
+    TString loadAlObjsListOfDets = "";
+    
+    for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+      if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
+      loadAlObjsListOfDets += fgkDetectorName[iDet];
+      loadAlObjsListOfDets += " ";
+    } // end loop over detectors
+    (AliGeomManager::Instance())->ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
+  }else{
+    // Check if the array with alignment objects was
+    // provided by the user. If yes, apply the objects
+    // to the present TGeo geometry
+    if (fAlignObjArray) {
+      if (gGeoManager && gGeoManager->IsClosed()) {
+       if ((AliGeomManager::Instance())->ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
+         AliError("The misalignment of one or more volumes failed!"
+                  "Compare the list of simulated detectors and the list of detector alignment data!");
+         return kFALSE;
+       }
+      }
+      else {
+       AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
        return kFALSE;
       }
     }
-    else {
-      AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
-      return kFALSE;
-    }
   }
-
+  
   delete fAlignObjArray; fAlignObjArray=0;
 
   // Update the TGeoPhysicalNodes
@@ -639,7 +562,7 @@ Bool_t AliReconstruction::Run(const char* input)
   stopwatch.Start();
 
   // get the possibly already existing ESD file and tree
-  AliESD* esd = new AliESD; AliESD* hltesd = new AliESD;
+  AliESD* esd = new AliESD(); AliESD* hltesd = new AliESD();
   TFile* fileOld = NULL;
   TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
   if (!gSystem->AccessPathName("AliESDs.root")){
@@ -647,32 +570,43 @@ Bool_t AliReconstruction::Run(const char* input)
     fileOld = TFile::Open("AliESDs.old.root");
     if (fileOld && fileOld->IsOpen()) {
       treeOld = (TTree*) fileOld->Get("esdTree");
-      if (treeOld) treeOld->SetBranchAddress("ESD", &esd);
+      if (treeOld)esd->ReadFromTree(treeOld);
       hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
-      if (hlttreeOld) hlttreeOld->SetBranchAddress("ESD", &hltesd);
+      if (hlttreeOld)  hltesd->ReadFromTree(hlttreeOld);
     }
   }
 
   // create the ESD output file and tree
   TFile* file = TFile::Open("AliESDs.root", "RECREATE");
+  file->SetCompressionLevel(2);
   if (!file->IsOpen()) {
     AliError("opening AliESDs.root failed");
     if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}    
   }
+
   TTree* tree = new TTree("esdTree", "Tree with ESD objects");
-  tree->Branch("ESD", "AliESD", &esd);
+  esd = new AliESD();
+  esd->CreateStdContent();
+  esd->WriteToTree(tree);
+
   TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
-  hlttree->Branch("ESD", "AliESD", &hltesd);
+  hltesd = new AliESD();
+  hltesd->CreateStdContent();
+  hltesd->WriteToTree(hlttree);
+
+  /* CKB Why?
   delete esd; delete hltesd;
   esd = NULL; hltesd = NULL;
-
+  */
   // create the branch with ESD additions
-  AliESDfriend *esdf=0;
+  AliESDfriend *esdf = 0; 
   if (fWriteESDfriend) {
-     TBranch *br=tree->Branch("ESDfriend.", "AliESDfriend", &esdf);
-     br->SetFile("AliESDfriends.root");
+    esdf = new AliESDfriend();
+    TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
+    br->SetFile("AliESDfriends.root");
+    esd->AddObject(esdf);
   }
-
+  
   // Get the diamond profile from OCDB
   AliCDBEntry* entry = AliCDBManager::Instance()
        ->Get("GRP/Calib/MeanVertex");
@@ -694,18 +628,18 @@ Bool_t AliReconstruction::Run(const char* input)
     if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
       // copy old ESD to the new one
       if (treeOld) {
-       treeOld->SetBranchAddress("ESD", &esd);
+       esd->ReadFromTree(treeOld);
        treeOld->GetEntry(iEvent);
       }
       tree->Fill();
       if (hlttreeOld) {
-       hlttreeOld->SetBranchAddress("ESD", &hltesd);
+       esd->ReadFromTree(hlttreeOld);
        hlttreeOld->GetEntry(iEvent);
       }
       hlttree->Fill();
       continue;
     }
-
+    
     AliInfo(Form("processing event %d", iEvent));
     fRunLoader->GetEvent(iEvent);
 
@@ -722,16 +656,18 @@ Bool_t AliReconstruction::Run(const char* input)
       }
     }
 
-    esd = new AliESD; hltesd = new AliESD;
+  
     esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
     hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
     esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
     hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
-
+    
     // Set magnetic field from the tracker
     esd->SetMagneticField(AliTracker::GetBz());
     hltesd->SetMagneticField(AliTracker::GetBz());
 
+    
+    
     // Fill raw-data error log into the ESD
     if (fRawReader) FillRawDataErrorLog(iEvent,esd);
 
@@ -797,7 +733,15 @@ Bool_t AliReconstruction::Run(const char* input)
     }
 
     //Try to improve the reconstructed primary vertex position using the tracks
-    AliESDVertex *pvtx=tVertexer.FindPrimaryVertex(esd);
+    AliESDVertex *pvtx=0;
+    Bool_t dovertex=kTRUE;
+    TObject* obj = fOptions.FindObject("ITS");
+    if (obj) {
+      TString optITS = obj->GetTitle();
+      if (optITS.Contains("cosmics") || optITS.Contains("COSMICS")) 
+       dovertex=kFALSE;
+    }
+    if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
     if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
     
     if (pvtx)
@@ -826,8 +770,8 @@ Bool_t AliReconstruction::Run(const char* input)
  
     // write ESD
     if (fWriteESDfriend) {
-       esdf=new AliESDfriend();
-       esd->GetESDfriend(esdf);
+      new (esdf) AliESDfriend(); // Reset...
+      esd->GetESDfriend(esdf);
     }
     tree->Fill();
 
@@ -835,11 +779,25 @@ Bool_t AliReconstruction::Run(const char* input)
     hlttree->Fill();
 
     if (fCheckPointLevel > 0)  WriteESD(esd, "final"); 
-    delete esd; delete esdf; delete hltesd;
-    esd = NULL; esdf=NULL; hltesd = NULL;
+    esd->Reset();
+    hltesd->Reset();
+    // esdf->Reset();
+    // delete esdf; esdf = 0;
+  } 
+
+
+  tree->GetUserInfo()->Add(esd);
+  hlttree->GetUserInfo()->Add(hltesd);
+
+
+
+  if(fESDPar.Contains("ESD.par")){
+    AliInfo("Attaching ESD.par to Tree");
+    TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
+    tree->GetUserInfo()->Add(fn);
   }
 
+
   AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
               stopwatch.RealTime(),stopwatch.CpuTime()));
 
@@ -855,10 +813,12 @@ Bool_t AliReconstruction::Run(const char* input)
     aodFile->Close();
   }
 
+  gROOT->cd();
   // Create tags for the events in the ESD tree (the ESD tree is always present)
   // In case of empty events the tags will contain dummy values
   CreateTag(file);
-  CleanUp(file, fileOld);
+
+ CleanUp(file, fileOld);
 
   return kTRUE;
 }
@@ -1023,7 +983,6 @@ Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
       vertex->SetName("default");
     }
     else {
-      vertex->SetTruePos(vtxPos);  // store also the vertex from MC
       vertex->SetName("reconstructed");
     }
 
@@ -1041,7 +1000,7 @@ Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
   }
   esd->SetVertex(vertex);
   // if SPD multiplicity has been determined, it is stored in the ESD
-  AliMultiplicity *mult= fVertexer->GetMultiplicity();
+  AliMultiplicity *mult = fVertexer->GetMultiplicity();
   if(mult)esd->SetMultiplicity(mult);
 
   for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
@@ -1182,7 +1141,8 @@ Bool_t AliReconstruction::RunTracking(AliESD*& esd)
   AliInfo("running tracking");
 
   //Fill the ESD with the T0 info (will be used by the TOF) 
-  GetReconstructor(11)->FillESD(fRunLoader, esd);
+  if (fReconstructor[11])
+      GetReconstructor(11)->FillESD(fRunLoader, esd);
 
   // pass 1: TPC + ITS inwards
   for (Int_t iDet = 1; iDet >= 0; iDet--) {
@@ -1234,7 +1194,7 @@ Bool_t AliReconstruction::RunTracking(AliESD*& esd)
     // run tracking
     if (fTracker[iDet]->PropagateBack(esd) != 0) {
       AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
-      return kFALSE;
+      //      return kFALSE;
     }
     if (fCheckPointLevel > 1) {
       WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
@@ -1266,7 +1226,7 @@ Bool_t AliReconstruction::RunTracking(AliESD*& esd)
     // run tracking
     if (fTracker[iDet]->RefitInward(esd) != 0) {
       AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
-      return kFALSE;
+      //      return kFALSE;
     }
     if (fCheckPointLevel > 1) {
       WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
@@ -1832,10 +1792,9 @@ void AliReconstruction::CreateTag(TFile* file)
     return ;
   }  
   Int_t lastEvent = 0;
-  TTree *t = (TTree*) file->Get("esdTree");
-  TBranch * b = t->GetBranch("ESD");
-  AliESD *esd = 0;
-  b->SetAddress(&esd);
+  TTree *b = (TTree*) file->Get("esdTree");
+  AliESD *esd = new AliESD();
+  esd->ReadFromTree(b);
 
   b->GetEntry(fFirstEvent);
   Int_t iInitRunNumber = esd->GetRunNumber();
@@ -2825,3 +2784,50 @@ void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESD* esd)
   }
 
 }
+
+TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
+  ifstream in;
+  in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
+  Int_t kBytes = (Int_t)in.tellg();
+  printf("Size: %d \n",kBytes);
+  TNamed *fn = 0;
+  if(in.good()){
+    char* memblock = new char [kBytes];
+    in.seekg (0, ios::beg);
+    in.read (memblock, kBytes);
+    in.close();
+    TString fData(memblock,kBytes);
+    fn = new TNamed(fName,fData);
+    printf("fData Size: %d \n",fData.Sizeof());
+    printf("fName Size: %d \n",fName.Sizeof());
+    printf("fn    Size: %d \n",fn->Sizeof());
+    delete[] memblock;
+  }
+  else{
+    AliInfo(Form("Could not Open %s\n",fPath.Data()));
+  }
+
+  return fn;
+}
+
+void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
+
+  // This is not really needed in AliReconstruction at the moment
+  // but can serve as a template
+
+  TList *fList = fTree->GetUserInfo();
+  TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
+  printf("fn Size: %d \n",fn->Sizeof());
+
+  TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
+  const char* cdata = fn->GetTitle();
+  printf("fTmp Size %d\n",fTmp.Sizeof());
+
+  int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
+  printf("calculated size %d\n",size);
+  ofstream out(fName.Data(),ios::out | ios::binary);
+  out.write(cdata,size);
+  out.close();
+
+}
+