Update timestamps for new AMANDA simulation (17/02/2015)
[u/mrichter/AliRoot.git] / HMPID / HMPIDFindAlignTracks.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TArray.h>
3 #include <TFile.h>
4 #include <TSystem.h>
5 #include <TStopwatch.h>
6 #include <TChain.h>
7 #include <TGrid.h>
8 #include <TAlienCollection.h>
9 #include <TGridCollection.h>
10 #include <TNtuple.h>
11 #include <TGeoManager.h>
12 #include "AliGeomManager.h"
13 #include "AliAlignmentTracks.h"
14 #include "AliTrackFitter.h"
15 #include "AliTrackFitterKalman.h"
16 #include "AliTrackFitterRieman.h"
17 #include "AliTrackResidualsFast.h"
18 #include "AliTrackResidualsChi2.h"
19 #include "AliTrackResidualsLinear.h"
20 #endif
21
22 TChain *CreateChainFromCollection(const char* xmlfile, const char *treeName,Int_t nFiles);
23
24 //**************************************************************************************************************************************************
25 void HmpAlignNew(Int_t runNum=105160, const Int_t iterations=1,const Int_t minTrackPoint=30,TString fileintro="AliTrackPoints.root",TString geometryfile="geometry.root"){
26
27   Int_t   nFile2Xml = 1;         //on Grid - how many ESD files to chain in xml
28   TString xmlName;
29
30   xmlName=Form("run000%d.xml",runNum);
31
32   TChain *chain = new TChain("esdTree");
33
34   TGrid::Connect("alien://");
35   chain = CreateChainFromCollection(xmlName.Data(),"esdTree",nFile2Xml);   
36
37   if(!gGeoManager) AliGeomManager::LoadGeometry(geometryfile.Data());
38
39   AliAlignmentTracks *AliAlTrack=new AliAlignmentTracks();
40
41   AliAlTrack->AddESD(chain);
42   
43   AliAlTrack->ProcessESD(); 
44
45   TStopwatch *timer=new TStopwatch();
46   timer->Start();
47  
48   AliAlTrack->SetPointsFilename(fileintro.Data());
49
50   AliAlTrack->BuildIndex();
51
52 //  AliTrackFitter *fitter=new AliTrackFitterKalman();
53   AliTrackFitter *fitter=new AliTrackFitterRieman();
54   fitter->SetMinNPoints(minTrackPoint);
55
56   AliAlTrack->SetTrackFitter(fitter);
57
58 //  AliTrackResiduals *res = new AliTrackResidualsFast();
59   AliTrackResiduals *res = new AliTrackResidualsChi2();
60   res->SetMinNPoints(1);
61   AliAlTrack->SetMinimizer(res);
62
63   for(Int_t i = 0; i<7; i++){
64     
65   TArrayI tmpId(1); 
66   tmpId.AddAt(AliGeomManager::LayerToVolUID(AliGeomManager::kHMPID,i),0);  
67   const TArrayI *volId = &tmpId;
68    
69   AliAlTrack->AlignVolumes(volId, NULL, AliGeomManager::kTPC1,AliGeomManager::kTPC2,iterations);  
70  }
71
72   timer->Stop();
73   timer->Print();
74   return;
75 }
76 //*************************************************************************************************************************************************************
77 TChain *CreateChainFromCollection(const char* xmlfile, const char *treeName,Int_t nFiles)
78 {
79 // Create a chain from an alien collection.                                                                          
80   
81   gSystem->Load("libSTEERBase");
82   gSystem->Load("libESD");
83   gSystem->Load("libANALYSIS");
84   gSystem->Load("libANALYSISalice");  
85
86   
87   TAlienCollection *myCollection  = TAlienCollection::Open(xmlfile);
88
89    
90    if (!myCollection) {
91       ::Error("CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
92      return NULL ;
93    }
94
95   TChain* chain = new TChain(treeName);
96   myCollection->Reset() ;
97   Int_t iCount = 0;
98   while ( myCollection->Next() ){
99     if(nFiles!=0)iCount++;
100     if(iCount > nFiles)break;
101     chain->Add(myCollection->GetTURL("")) ;
102     Printf("Adding %s",myCollection->GetTURL(""));
103   }
104   chain->ls();
105   return chain;
106 }