Adding a task for the relative TPC-ITS alignment (M. Krzewicki)
[u/mrichter/AliRoot.git] / PWG1 / AliAnalysisTaskITSTPCalignment.cxx
CommitLineData
4a84c20d 1////////////////////////////////////////////////////////////////////////////////
2// AliAnalysisTaskITSTPCalignment
3// Runs the relative ITS TPC alignment procedure and TPC vdrift calib
4// Origin: Mikolaj Krzewicki, mikolaj.krzewicki@cern.ch
5////////////////////////////////////////////////////////////////////////////////
6
7#include "TChain.h"
8#include "TTree.h"
9#include "TH2.h"
10#include "AliAnalysisTask.h"
11#include "AliAnalysisManager.h"
12#include "AliESDEvent.h"
13#include "AliESDInputHandler.h"
14#include "AliRelAlignerKalman.h"
15#include "AliRelAlignerKalmanArray.h"
16#include "AliAnalysisTaskITSTPCalignment.h"
17
18ClassImp(AliAnalysisTaskITSTPCalignment)
19
20//________________________________________________________________________
21AliAnalysisTaskITSTPCalignment::AliAnalysisTaskITSTPCalignment():
22 AliAnalysisTask(),
23 fESD(0),
24 fArray(0),
25 fYZResidualsHist(0),
26 fPLResidualsHist(0),
27 fListOfHistos(0),
28 fSaveInterval(600),
29 fTimeMatchingTolerance(20),
30 fDoQA(kFALSE)
31{
32 //dummy ctor
33}
34
35//________________________________________________________________________
36AliAnalysisTaskITSTPCalignment::AliAnalysisTaskITSTPCalignment(const char *name):
37 AliAnalysisTask(name,name),
38 fESD(0),
39 fArray(0),
40 fYZResidualsHist(0),
41 fPLResidualsHist(0),
42 fListOfHistos(0),
43 fSaveInterval(600),
44 fTimeMatchingTolerance(20),
45 fDoQA(kFALSE)
46{
47 // Constructor
48
49 // Define input and output slots here
50 // Input slot #0 works with a TChain
51 DefineInput(0, TChain::Class());
52 DefineOutput(0, AliRelAlignerKalmanArray::Class());
53 DefineOutput(1, TList::Class());
54}
55
56//________________________________________________________________________
57void AliAnalysisTaskITSTPCalignment::ConnectInputData(Option_t *)
58{
59 // Called once
60 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
61 if (!tree)
62 {
63 Printf("ERROR: Could not read chain from input slot 0");
64 }
65 else
66 {
67 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
68 if (!esdH)
69 {
70 Printf("ERROR: Could not get ESDInputHandler");
71 }
72 else
73 fESD = esdH->GetEvent();
74 }
75}
76
77//________________________________________________________________________
78void AliAnalysisTaskITSTPCalignment::CreateOutputObjects()
79{
80 // Create output objects
81 // Called once
82
83 fArray = new AliRelAlignerKalmanArray("ITSTPCalignmentArray");
84 fArray->SetSaveInterval(fSaveInterval);
85 fArray->SetTimeMatchingTolerance(fTimeMatchingTolerance);
86
87 fYZResidualsHist = new TH2F("fYZResidualsHist", "YZ residuals", 50, -0.5, 0.5, 50, -2., 2. );
88 fPLResidualsHist = new TH2F("fPLResidualsHist", "sin(phi) tan(lambda) residuals", 50, -.05, 0.05, 50, -0.05, 0.05 );
89
90 fListOfHistos = new TList();
91 fListOfHistos->Add(fYZResidualsHist);
92 fListOfHistos->Add(fPLResidualsHist);
93}
94
95//________________________________________________________________________
96void AliAnalysisTaskITSTPCalignment::Exec(Option_t *)
97{
98 // Main loop
99 // Called for each event
100 if (!fESD)
101 {
102 Printf("ERROR: fESD not available");
103 return;
104 }
105
106 AliRelAlignerKalman* aligner = fArray->GetAligner();
107
108 Int_t lastrunnumber = aligner->GetRunNumber();
109 UInt_t currentTimeStamp = fESD->GetTimeStamp();
110
111 //for a new run reset TPC errors
112 if (lastrunnumber != fESD->GetRunNumber())
113 {
114 aligner->ResetTPCparamsCovariance();
115 fArray->SetCurrentTimeBin(currentTimeStamp);
116 }
117
118 //if time jumps back reset all
119 if (currentTimeStamp < aligner->GetTimeStamp())
120 {
121 aligner->Reset();
122 fArray->SetCurrentTimeBin(currentTimeStamp);
123 }
124
125 //Update the parmeters
126 if (fArray->AddCosmicEvent(fESD))
127 if (fDoQA)
128 {
129 //fill the QA histograms
130 TArrayI trackTArrITS(1);
131 TArrayI trackTArrTPC(1);
132 if (aligner->FindCosmicTrackletNumbersInEvent(
133 trackTArrITS, trackTArrTPC, fESD ))
134 {
135 AliESDtrack* ptrack;
136 const AliExternalTrackParam* pconstparams1;
137 const AliExternalTrackParam* pconstparams2;
138 AliExternalTrackParam params1;
139 AliExternalTrackParam params2;
140
141 ////////////////////////////////
142 for (Int_t i=0;i<trackTArrITS.GetSize();i++)
143 {
144 //ITS track
145 ptrack = fESD->GetTrack(trackTArrITS[i]);
146 pconstparams1 = ptrack->GetOuterParam();
147 if (!pconstparams1) continue;
148 params1 = *pconstparams1; //make copy to be safe
149
150 //TPC track
151 ptrack = fESD->GetTrack(trackTArrTPC[i]);
152 pconstparams2 = ptrack->GetInnerParam();
153 if (!pconstparams2) continue;
154 params2 = *pconstparams2; //make copy
155 params2.Rotate(params1.GetAlpha());
156 params2.PropagateTo( params1.GetX(), aligner->GetMagField() );
157
158 Float_t resy = params2.GetY() - params1.GetY();
159 Float_t resz = params2.GetZ() - params1.GetZ();
160 Float_t ressnp = params2.GetSnp() - params1.GetSnp();
161 Float_t restgl = params2.GetTgl() - params1.GetTgl();
162 fYZResidualsHist->Fill(resy,resz);
163 fPLResidualsHist->Fill(ressnp,restgl);
164 }
165 }//if DoQA
166
167 }//if AddEvent
168
169 // Post output data.
170 PostData(0, fArray);
171 PostData(1, fListOfHistos);
172}
173
174//________________________________________________________________________
175void AliAnalysisTaskITSTPCalignment::Terminate(Option_t *)
176{
177 // Called once at the end of the query
178 fArray->Merge(new TList()); //final cleanup
179}
180