Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGPP / TRD / AliTRDonlineTrackletFilter.cxx
CommitLineData
f1d8040f
JK
1
2
6419bebb 3// AliTRDonlineTrackletFilter implements an analysis task which reads
4// the tracklets from the TRD.Tracklets.root file and makes them
5// available to other analysis tasks. This allows to access the full
6// tracklet information without repeating the techncicalities in each
7// analysis task. The tracklets are made available in an exchange
8// container on the output slot 1.
9
b220e595 10#include "TFile.h"
11#include "TTree.h"
12#include "TChain.h"
13#include "TH1F.h"
14#include "TH2F.h"
15#include "TProfile.h"
16#include "TCanvas.h"
17
18#include "AliAnalysisManager.h"
19#include "AliESDEvent.h"
20#include "AliAODEvent.h"
21#include "AliMCEvent.h"
22#include "AliESDInputHandler.h"
23#include "AliAODHandler.h"
24#include "AliMCEventHandler.h"
25#include "AliLog.h"
26#include "AliESDTrdTrack.h"
27
28#include "AliTRDtrackletMCM.h"
29#include "AliTRDtrackletWord.h"
30#include "AliVParticle.h"
31#include "AliMCParticle.h"
32
33#include "AliTRDonlineTrackletFilter.h"
34
35ClassImp(AliTRDonlineTrackletFilter)
36
37AliTRDonlineTrackletFilter::AliTRDonlineTrackletFilter(const char *name) :
38 AliAnalysisTask(name, ""),
39 fESD(0x0),
40 fInputHandler(0x0),
41 fInputEvent(0x0),
42 fOutputAOD(0x0),
43 fMCEvent(0x0),
44 fTrackletsRaw(new TClonesArray("AliTRDtrackletWord")),
45 fTrackletsSim(new TClonesArray("AliTRDtrackletMCM")),
54d34aac 46 fTrackletTree(0x0),
b220e595 47 fGeo(new AliTRDgeometry),
48 fNevent(0),
54d34aac 49 fPath(""),
b220e595 50 fTrackletFile(0x0),
54d34aac 51 fNEventsPerFile(0),
52 fEvent(0),
53 fFileNumber(0),
b220e595 54 fTrackletTreeSim(0x0),
54d34aac 55 fTrackletTreeRaw(0x0)
b220e595 56{
57 // ctor
58
59 DefineInput(0, TChain::Class());
60
61 DefineOutput(0, TTree::Class());
62 DefineOutput(1, TTree::Class());
63}
64
65AliTRDonlineTrackletFilter::~AliTRDonlineTrackletFilter()
66{
67 // dtor
68
69 delete fTrackletsRaw;
70 delete fTrackletsSim;
71 delete fGeo;
72}
73
54d34aac 74void AliTRDonlineTrackletFilter::ConnectInputData(const Option_t */* option */)
b220e595 75{
6419bebb 76 // connect all the input handlers to access the data
77
b220e595 78 fInputHandler = (AliInputEventHandler*) AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
79 if (fInputHandler)
80 fInputEvent = fInputHandler->GetEvent();
81
82 AliMCEventHandler *mcH = (AliMCEventHandler*) AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler();
83 if (mcH)
84 fMCEvent = mcH->MCEvent();
85}
86
87void AliTRDonlineTrackletFilter::CreateOutputObjects()
88{
6419bebb 89 // create the output objects used to make the tracklets available to
90 // other tasks
91
b220e595 92 OpenFile(1);
93
6911c7f9 94 fTrackletTree = new TTree("TRDtrackletfilter", "on-line tracklets");
b220e595 95 fTrackletTree->Branch("tracklets_sim", fTrackletsSim);
96 fTrackletTree->Branch("tracklets_raw", fTrackletsRaw);
6911c7f9 97
98 PostData(1, fTrackletTree);
b220e595 99}
100
101Bool_t AliTRDonlineTrackletFilter::Notify()
102{
6419bebb 103 // we use notify to figure out which TRD.Tracklets.root file we have
104 // to use for accessing the tracklets
b220e595 105
106 TString filename(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
107
6911c7f9 108 AliDebug(1, Form("Now reading from %s", filename.Data()));
b220e595 109
110 if (filename.Contains("AliAOD.root"))
111 filename.ReplaceAll("AliAOD.root", "");
6911c7f9 112 else if (filename.Contains("NewAliESDs.root"))
113 filename.ReplaceAll("NewAliESDs.root", "");
b220e595 114 else if (filename.Contains("AliESDs.root"))
115 filename.ReplaceAll("AliESDs.root", "");
116 else if (filename.Contains("galice.root"))
117 filename.ReplaceAll("galice.root", "");
118 else if (filename.BeginsWith("root:"))
119 filename.Append("?ZIP=");
120
121 fPath = filename;
122
123 fTrackletFile = TFile::Open(Form("%sTRD.Tracklets.root", fPath.Data()));
124
125 if (!fTrackletFile) {
6911c7f9 126 AliError(Form("No tracklet file in %s", fPath.Data()));
b220e595 127 return kFALSE;
128 }
129
130 fNEventsPerFile = fTrackletFile->GetNkeys() - fTrackletFile->GetNProcessIDs(); //???
131
132 fEvent = -1;
133 fFileNumber = 0;
54d34aac 134
135 return kTRUE;
b220e595 136}
137
138
54d34aac 139void AliTRDonlineTrackletFilter::Exec(const Option_t * /* option */)
b220e595 140{
141 // execute this for each event
142
143 if (!LoadEvent())
144 return;
145
146 // ----- simulated tracklets -----
147 if (fTrackletTreeSim) {
148 AliTRDtrackletMCM *trkl = 0x0;
149
150 TBranch *br = fTrackletTreeSim->GetBranch("mcmtrklbranch");
151 br->SetAddress(&trkl);
152
153 for (Int_t iTracklet = 0; iTracklet < br->GetEntries(); iTracklet++) {
154 br->GetEntry(iTracklet);
155 new ((*fTrackletsSim)[fTrackletsSim->GetEntriesFast()]) AliTRDtrackletMCM(*trkl);
156 }
157 }
158
159 // ----- raw tracklets -----
160 if (fTrackletTreeRaw) {
161 Int_t hc;
162 TClonesArray *trklArray = 0x0;
163 fTrackletTreeRaw->SetBranchAddress("hc", &hc);
164 fTrackletTreeRaw->SetBranchAddress("trkl", &trklArray);
165 for (Int_t iHCidx = 0; iHCidx < fTrackletTreeRaw->GetEntries(); iHCidx++) {
166 fTrackletTreeRaw->GetEntry(iHCidx);
6911c7f9 167 if (trklArray) {
168 for (Int_t iTracklet = 0; iTracklet < trklArray->GetEntries(); iTracklet++) {
169 AliTRDtrackletWord *trklWord = (AliTRDtrackletWord*) ((*trklArray)[iTracklet]);
170 trklWord->SetDetector(hc/2);
171 new ((*fTrackletsRaw)[fTrackletsRaw->GetEntriesFast()]) AliTRDtrackletWord(*trklWord);
172 }
b220e595 173 }
174 }
175 }
176
6911c7f9 177 AliDebug(1, Form("%i tracklets", fTrackletsSim->GetEntriesFast()));
b220e595 178 fTrackletTree->SetBranchAddress("tracklets_sim", &fTrackletsSim);
179 fTrackletTree->SetBranchAddress("tracklets_raw", &fTrackletsRaw);
180 fTrackletTree->Fill();
181 PostData(1, fTrackletTree);
182}
183
184void AliTRDonlineTrackletFilter::LocalInit()
185{
186
187}
188
54d34aac 189void AliTRDonlineTrackletFilter::Terminate(const Option_t * /* option */)
b220e595 190{
191
192}
193
194Bool_t AliTRDonlineTrackletFilter::LoadEvent()
195{
196 // load tracklets for the current event
197
198 // ----- cleaning -----
199 fTrackletsSim->Delete();
200 fTrackletsRaw->Delete();
201
202 // ----- initialization -----
203 if (!fInputEvent) {
204 AliError("No event found!");
205 return kFALSE;
206 }
207 fESD = dynamic_cast<AliESDEvent*> (fInputEvent);
208
209 fEvent++;
6911c7f9 210 Int_t inew = fNEventsPerFile > 0 ? fEvent / fNEventsPerFile : 0;
b220e595 211 if ( inew != fFileNumber) {
212 fFileNumber++;
213
214 delete fTrackletFile;
215 fTrackletFile = TFile::Open(Form("%sTRD.Tracklets%d.root", fPath.Data(), fFileNumber));
216
217 if (!fTrackletFile) {
218 AliError("No tracklet file");
219 return kFALSE;
220 }
221 }
222
223 if (!fTrackletFile) {
224 AliError("no tracklet file");
225 return kFALSE;
226 }
227
228 // tracklets from simulation
229 char treename[30];
69503e16 230 snprintf(treename, 30, "Event%d/tracklets", fEvent);
b220e595 231
232 fTrackletTreeSim = (TTree*) fTrackletFile->Get(treename);
233
234 // tracklets from raw
235 char treenameRaw[30];
69503e16 236 snprintf(treenameRaw, 30, "Event%d/tracklets-raw", fEvent);
b220e595 237 fTrackletTreeRaw = (TTree*) fTrackletFile->Get(treenameRaw);
238
239 return kTRUE;
240}
241