]>
Commit | Line | Data |
---|---|---|
d810d0de | 1 | // $Id$ |
2 | // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 | |
5a5a1232 | 3 | |
d810d0de | 4 | /************************************************************************** |
5 | * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. * | |
6 | * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for * | |
51346b82 | 7 | * full copyright notice. * |
d810d0de | 8 | **************************************************************************/ |
9 | ||
b09247a2 | 10 | #include <memory> |
d810d0de | 11 | #include "AliEveVSDCreator.h" |
5a5a1232 | 12 | |
8cc1d3b4 | 13 | #include "AliEveEventManager.h" |
14 | ||
5a5a1232 | 15 | #include <AliStack.h> |
16 | #include <AliITSLoader.h> | |
17 | #include <AliTPCTrackHitsV2.h> | |
18 | #include <AliPDG.h> | |
19 | #include <AliHit.h> | |
22aefef8 | 20 | #include <AliESDEvent.h> |
d6a49f20 | 21 | #include <AliESDv0.h> |
5a5a1232 | 22 | #include <AliTPCclusterMI.h> |
23 | #include <AliTPCClustersRow.h> | |
5a5a1232 | 24 | #include <AliITSclusterV2.h> |
5a5a1232 | 25 | #include <AliESDkink.h> |
82e1eece | 26 | #include <AliESDtrack.h> |
5a5a1232 | 27 | |
28 | #include <AliRun.h> | |
a15e6d7d | 29 | #include <AliRunLoader.h> |
5a5a1232 | 30 | #include <AliTPCParam.h> |
31 | ||
32 | #include <TSystem.h> | |
33 | #include <TFile.h> | |
34 | ||
57ffa5fb | 35 | //______________________________________________________________________________ |
5a5a1232 | 36 | // |
73c1c0ec | 37 | // Create VSD file from ALICE data. |
5a5a1232 | 38 | |
d810d0de | 39 | ClassImp(AliEveVSDCreator) |
5a5a1232 | 40 | |
d810d0de | 41 | AliEveVSDCreator::AliEveVSDCreator(const Text_t* name, const Text_t* title) : |
84aff7a4 | 42 | TEveVSD(name, title), |
265ecb21 | 43 | |
73c1c0ec | 44 | fTPCHitRes (2), |
45 | fTRDHitRes (2), | |
5a5a1232 | 46 | |
73c1c0ec | 47 | fDebugLevel (0), |
48 | fRunLoader (0), | |
49 | fGenInfoMap () | |
265ecb21 | 50 | { |
73c1c0ec | 51 | // Constructor. |
52 | ||
5a5a1232 | 53 | // Particles not in ROOT's PDG database occuring in ALICE |
54 | AliPDG::AddParticlesToPdgDataBase(); | |
55 | { | |
56 | TDatabasePDG *pdgDB = TDatabasePDG::Instance(); | |
57 | // const Int_t kspe=50000000; | |
58 | const Int_t kion=10000000; | |
59 | ||
60 | const Double_t kAu2Gev=0.9314943228; | |
61 | const Double_t khSlash = 1.0545726663e-27; | |
62 | const Double_t kErg2Gev = 1/1.6021773349e-3; | |
63 | const Double_t khShGev = khSlash*kErg2Gev; | |
64 | const Double_t kYear2Sec = 3600*24*365.25; | |
65 | ||
66 | pdgDB->AddParticle("Deuteron","Deuteron",2*kAu2Gev+8.071e-3,kTRUE, | |
67 | 0,1,"Ion",kion+10020); | |
68 | pdgDB->AddParticle("Triton","Triton",3*kAu2Gev+14.931e-3,kFALSE, | |
69 | khShGev/(12.33*kYear2Sec),1,"Ion",kion+10030); | |
70 | pdgDB->AddParticle("Alpha","Alpha",4*kAu2Gev+2.424e-3,kTRUE, | |
71 | khShGev/(12.33*kYear2Sec),2,"Ion",kion+20040); | |
72 | pdgDB->AddParticle("HE3","HE3",3*kAu2Gev+14.931e-3,kFALSE, | |
73 | 0,2,"Ion",kion+20030); | |
74 | } | |
75 | ||
51346b82 | 76 | // AliKalmanTrack::SetConvConst(1); |
5a5a1232 | 77 | } |
78 | ||
57ffa5fb | 79 | /******************************************************************************/ |
5a5a1232 | 80 | |
8cc1d3b4 | 81 | void AliEveVSDCreator::CreateVSD(const Text_t* vsdFile) |
5a5a1232 | 82 | { |
8cc1d3b4 | 83 | // Create the VSD for current event in AliEveEventManager. |
73c1c0ec | 84 | // Result is stored in vsdFile. |
85 | // | |
86 | // Needs to be extended to support conversion of multiple events. | |
87 | ||
a15e6d7d | 88 | static const TEveException kEH("AliEveVSDCreator::CreateVSD "); |
5a5a1232 | 89 | |
8cc1d3b4 | 90 | fRunLoader = AliEveEventManager::AssertRunLoader(); |
5a5a1232 | 91 | |
73c1c0ec | 92 | if(fDebugLevel > 0) |
a15e6d7d | 93 | printf("%s open seems ok. Now loading sim data.\n", kEH.Data()); |
5a5a1232 | 94 | |
73c1c0ec | 95 | fRunLoader->LoadHeader(); |
96 | fRunLoader->LoadKinematics(); | |
97 | fRunLoader->LoadTrackRefs(); | |
98 | fRunLoader->LoadHits(); | |
5a5a1232 | 99 | |
100 | // GledNS::PushFD(); | |
101 | ||
73c1c0ec | 102 | if(fDebugLevel > 0) |
a15e6d7d | 103 | printf("%s opening output TEveVSD.\n", kEH.Data()); |
5a5a1232 | 104 | |
8cc1d3b4 | 105 | TFile* file = TFile::Open(vsdFile, "RECREATE", "ALICE Visualization Summary Data"); |
84aff7a4 | 106 | fDirectory = new TDirectoryFile("Event0", ""); |
5a5a1232 | 107 | |
73c1c0ec | 108 | if(fDebugLevel > 0) |
a15e6d7d | 109 | printf("%s creating trees now ...\n", kEH.Data()); |
5a5a1232 | 110 | |
111 | CreateTrees(); | |
112 | ||
73c1c0ec | 113 | if(fDebugLevel > 0) |
a15e6d7d | 114 | printf("%s trees created, closing files.\n", kEH.Data()); |
5a5a1232 | 115 | |
c1d0d915 | 116 | file->Write(); |
5a5a1232 | 117 | file->Close(); |
51346b82 | 118 | delete file; |
84aff7a4 | 119 | fDirectory =0; |
5a5a1232 | 120 | |
121 | //GledNS::PopFD(); | |
122 | ||
84aff7a4 | 123 | // clean after the TEveVSD data was sucessfuly written |
124 | fTreeK = 0; | |
125 | fTreeH = 0; | |
126 | //fTreeTR = 0; | |
127 | fTreeC = 0; | |
128 | fTreeV0 = 0; | |
129 | fTreeKK = 0; | |
130 | fTreeR = 0; | |
131 | fTreeGI = 0; | |
5a5a1232 | 132 | |
73c1c0ec | 133 | fRunLoader = 0; |
5a5a1232 | 134 | |
73c1c0ec | 135 | if(fDebugLevel > 0) |
a15e6d7d | 136 | printf("%s all done.\n", kEH.Data()); |
5a5a1232 | 137 | } |
138 | ||
d810d0de | 139 | void AliEveVSDCreator::CreateTrees() |
5a5a1232 | 140 | { |
73c1c0ec | 141 | // Create and fill the output trees by calling all the |
142 | // ConvertXyzz() functions. | |
143 | // Exceptions from individual functions are displayed as warnings. | |
144 | ||
a15e6d7d | 145 | static const TEveException kEH("AliEveVSDCreator::CreateTrees "); |
5a5a1232 | 146 | |
73c1c0ec | 147 | if (fDirectory == 0) |
a15e6d7d | 148 | throw(kEH + "output directory not set."); |
5a5a1232 | 149 | |
150 | try { | |
73c1c0ec | 151 | if (fDebugLevel > 1) |
a15e6d7d | 152 | printf("%sConvertKinematics.\n", kEH.Data()); |
5a5a1232 | 153 | ConvertKinematics(); |
a15e6d7d | 154 | } catch(TEveException& exc) { Warning(kEH, exc); } |
5a5a1232 | 155 | |
8cc1d3b4 | 156 | Warning(kEH, "Explicitly abandoning further conversion."); |
157 | return; | |
158 | ||
5a5a1232 | 159 | try { |
73c1c0ec | 160 | if (fDebugLevel > 1) |
a15e6d7d | 161 | printf("%sConvertHits.\n", kEH.Data()); |
5a5a1232 | 162 | ConvertHits(); |
a15e6d7d | 163 | } catch(TEveException& exc) { Warning(kEH, exc); } |
5a5a1232 | 164 | |
165 | try { | |
73c1c0ec | 166 | if (fDebugLevel > 1) |
a15e6d7d | 167 | printf("%sConvertClusters.\n", kEH.Data()); |
5a5a1232 | 168 | ConvertClusters(); |
a15e6d7d | 169 | } catch(TEveException& exc) { Warning(kEH, exc); } |
5a5a1232 | 170 | |
5a5a1232 | 171 | try { |
73c1c0ec | 172 | if (fDebugLevel > 1) |
a15e6d7d | 173 | printf("%sConvertRecTracks.\n", kEH.Data()); |
5a5a1232 | 174 | ConvertRecTracks(); |
84aff7a4 | 175 | } catch(TEveException& exc) { |
d810d0de | 176 | Warning(exc, "skipping AliEveV0 extraction."); |
5a5a1232 | 177 | goto end_esd_processing; |
178 | } | |
179 | ||
180 | try { | |
73c1c0ec | 181 | if (fDebugLevel > 1) |
a15e6d7d | 182 | printf("%sConvertV0.\n", kEH.Data()); |
5a5a1232 | 183 | ConvertV0(); |
a15e6d7d | 184 | } catch(TEveException& exc) { Warning(kEH, exc); } |
5a5a1232 | 185 | |
186 | try { | |
73c1c0ec | 187 | if (fDebugLevel > 1) |
a15e6d7d | 188 | printf("%sConvertKinks.\n", kEH.Data()); |
5a5a1232 | 189 | ConvertKinks(); |
a15e6d7d | 190 | } catch(TEveException& exc) { Warning(kEH, exc); } |
5a5a1232 | 191 | |
192 | end_esd_processing: | |
193 | ||
194 | try { | |
73c1c0ec | 195 | if (fDebugLevel > 1) |
a15e6d7d | 196 | printf("%sConvertGenInfo.\n", kEH.Data()); |
5a5a1232 | 197 | ConvertGenInfo(); |
a15e6d7d | 198 | } catch(TEveException& exc) { Warning(kEH, exc); } |
5a5a1232 | 199 | |
5a5a1232 | 200 | return; |
201 | } | |
202 | ||
57ffa5fb | 203 | /******************************************************************************/ |
5a5a1232 | 204 | // Kinematics |
57ffa5fb | 205 | /******************************************************************************/ |
5a5a1232 | 206 | |
d810d0de | 207 | void AliEveVSDCreator::ConvertKinematics() |
5a5a1232 | 208 | { |
73c1c0ec | 209 | // Convert kinematics. |
210 | // Track references are not stored, they should be. | |
211 | ||
a15e6d7d | 212 | static const TEveException kEH("AliEveVSDCreator::ConvertKinematics "); |
5a5a1232 | 213 | |
51346b82 | 214 | if(fTreeK != 0) |
a15e6d7d | 215 | throw (kEH + "kinematics already converted"); |
5a5a1232 | 216 | |
73c1c0ec | 217 | AliStack* stack = fRunLoader->Stack(); |
5a5a1232 | 218 | if(stack == 0) |
a15e6d7d | 219 | throw(kEH + "stack is null."); |
5a5a1232 | 220 | |
84aff7a4 | 221 | fDirectory->cd(); |
222 | fTreeK = new TTree("Kinematics", "TParticles sorted by Label"); | |
51346b82 | 223 | |
5a5a1232 | 224 | Int_t nentries = stack->GetNtrack(); |
fd31e9de | 225 | std::vector<TEveMCTrack> vmc(nentries); |
5a5a1232 | 226 | for (Int_t idx=0; idx<nentries; idx++) { |
73c1c0ec | 227 | TParticle* tp = stack->Particle(idx); |
84aff7a4 | 228 | vmc[idx] = *tp; |
229 | vmc[idx].fLabel = idx; | |
5a5a1232 | 230 | } |
231 | ||
84aff7a4 | 232 | // read track refrences |
d810d0de | 233 | // functionality now in AliEveKineTools. |
84aff7a4 | 234 | /* |
73c1c0ec | 235 | TTree* fTreeTR = fRunLoader->TreeTR(); |
5a5a1232 | 236 | |
84aff7a4 | 237 | if(fTreeTR == 0) { |
a15e6d7d | 238 | Warning(kEH, "no TrackRefs; some data will not be available."); |
5a5a1232 | 239 | } else { |
240 | TClonesArray* RunArrayTR = 0; | |
84aff7a4 | 241 | fTreeTR->SetBranchAddress("AliRun", &RunArrayTR); |
5a5a1232 | 242 | |
84aff7a4 | 243 | Int_t nPrimaries = (Int_t) fTreeTR->GetEntries(); |
5a5a1232 | 244 | for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) { |
84aff7a4 | 245 | // printf("T0 fTreeTR->GetEntry(%d) \n",iPrimPart); |
246 | fTreeTR->GetEntry(iPrimPart); | |
247 | // printf("END fTreeTR->GetEntry(%d) \n",iPrimPart); | |
51346b82 | 248 | |
5a5a1232 | 249 | for (Int_t iTrackRef = 0; iTrackRef < RunArrayTR->GetEntriesFast(); iTrackRef++) { |
51346b82 | 250 | AliTrackReference *trackRef = (AliTrackReference*)RunArrayTR->At(iTrackRef); |
5a5a1232 | 251 | Int_t track = trackRef->GetTrack(); |
51346b82 | 252 | if(track < nentries && track > 0){ |
253 | TEveMCTrack& mct = vmc[track]; | |
5a5a1232 | 254 | if(trackRef->TestBit(kNotDeleted)) { |
255 | mct.decayed = true; | |
256 | mct.t_decay = trackRef->GetTime(); | |
257 | mct.V_decay.x = trackRef->X(); | |
258 | mct.V_decay.y = trackRef->Y(); | |
259 | mct.V_decay.z = trackRef->Z(); | |
260 | mct.P_decay.x = trackRef->Px(); | |
261 | mct.P_decay.y = trackRef->Py(); | |
262 | mct.P_decay.z = trackRef->Pz(); | |
263 | if(TMath::Abs(mct.GetPdgCode()) == 11) | |
264 | mct.decayed = false; // a bug in TreeTR | |
265 | } | |
51346b82 | 266 | } |
5a5a1232 | 267 | } |
268 | } | |
269 | } | |
84aff7a4 | 270 | */ |
5a5a1232 | 271 | |
84aff7a4 | 272 | fTreeK->Branch("K", "TEveMCTrack", &fpK, fBuffSize); |
5a5a1232 | 273 | |
6242b962 | 274 | printf("sizeofvmc = %d\n", (Int_t) vmc.size()); |
fd31e9de | 275 | for(std::vector<TEveMCTrack>::iterator k=vmc.begin(); k!=vmc.end(); ++k) { |
84aff7a4 | 276 | TEveMCTrack& mct = *k; |
277 | fK = mct; | |
5a5a1232 | 278 | |
279 | TParticle* m = &mct; | |
84aff7a4 | 280 | Int_t mi = mct.fLabel; |
5a5a1232 | 281 | int cnt = 0; |
282 | while(m->GetMother(0) != -1) { | |
283 | if(cnt > 100) { | |
284 | printf("cnt %d mi=%d, mo=%d\n", cnt, mi, m->GetMother(0)); | |
285 | } | |
286 | mi = m->GetMother(0); | |
287 | m = &vmc[mi]; | |
288 | ++cnt; | |
289 | } | |
84aff7a4 | 290 | fK.fEvaLabel = mi; |
5a5a1232 | 291 | |
84aff7a4 | 292 | fTreeK->Fill(); |
5a5a1232 | 293 | } |
294 | ||
8cc1d3b4 | 295 | fTreeK->BuildIndex("fLabel"); |
5a5a1232 | 296 | } |
297 | ||
57ffa5fb | 298 | /******************************************************************************/ |
5a5a1232 | 299 | // Hits |
57ffa5fb | 300 | /******************************************************************************/ |
5a5a1232 | 301 | |
302 | namespace { | |
303 | ||
a15e6d7d | 304 | struct Detector_t |
5a5a1232 | 305 | { |
a15e6d7d | 306 | const char* fName; // Detector name. |
307 | const char* fHitbranch; // Name of branch containing hits. | |
308 | unsigned char fDetidx; // Index identifying the detector internally. | |
5a5a1232 | 309 | }; |
310 | ||
a15e6d7d | 311 | Detector_t fgDetectors[] = { |
5a5a1232 | 312 | { "ITS", "AliITShit", 0 }, |
313 | { "TPC", "AliTPCTrackHitsV2", 1 }, | |
314 | { "TRD", "AliTRDhit", 2 }, | |
315 | { "TOF", "AliTOFhit", 3 } | |
f4b3bbb7 | 316 | // { "HMPID", "AliHMPIDhit", 4 }, |
5a5a1232 | 317 | }; |
318 | ||
319 | } | |
320 | ||
57ffa5fb | 321 | /******************************************************************************/ |
5a5a1232 | 322 | |
d810d0de | 323 | void AliEveVSDCreator::ConvertHits() |
5a5a1232 | 324 | { |
73c1c0ec | 325 | // Convert MC hits. |
326 | // TPC hits are handled specially as they are compressed - only mayor | |
327 | // hits are stored | |
328 | ||
a15e6d7d | 329 | static const TEveException kEH("AliEveVSDCreator::ConvertHits "); |
5a5a1232 | 330 | |
73c1c0ec | 331 | if (fTreeH != 0) |
a15e6d7d | 332 | throw(kEH + "hits already converted."); |
5a5a1232 | 333 | |
84aff7a4 | 334 | fDirectory->cd(); |
335 | fTreeH = new TTree("Hits", "Combined detector hits."); | |
336 | fTreeH->Branch("H", "TEveHit", &fpH, fBuffSize); | |
51346b82 | 337 | |
fd31e9de | 338 | std::map<Int_t, Int_t> hmap; |
5a5a1232 | 339 | // parameters for ITS, TPC hits filtering |
340 | Float_t x,y,z, x1,y1,z1; | |
73c1c0ec | 341 | Float_t tpcSqrRes = fTPCHitRes*fTPCHitRes; |
342 | Float_t trdSqrRes = fTRDHitRes*fTRDHitRes; | |
5a5a1232 | 343 | |
344 | int l=0; | |
345 | // load hits from the rest of detectors | |
a15e6d7d | 346 | while (fgDetectors[l].fName != 0) |
73c1c0ec | 347 | { |
a15e6d7d | 348 | Detector_t& det = fgDetectors[l++]; |
5a5a1232 | 349 | |
a15e6d7d | 350 | switch(det.fDetidx) |
73c1c0ec | 351 | { |
352 | case 1: | |
353 | { | |
354 | Int_t count = 0; | |
a15e6d7d | 355 | TTree* treeh = fRunLoader->GetTreeH(det.fName, false); |
73c1c0ec | 356 | if(treeh == 0) { |
a15e6d7d | 357 | Warning(kEH, Form("no hits for %s.", det.fName)); |
73c1c0ec | 358 | continue; |
359 | } | |
360 | AliTPCTrackHitsV2 hv2, *hv2p = &hv2; | |
361 | treeh->SetBranchAddress("TPC2", &hv2p); | |
362 | Int_t np = treeh->GetEntries(); | |
363 | for (Int_t i = 0; i < np; ++i) | |
364 | { | |
365 | treeh->GetEntry(i); | |
366 | Int_t evaIdx = np -i -1; | |
367 | if (hv2.First() == 0) continue; | |
368 | x = y = z = 0; | |
369 | do { | |
370 | AliHit* ah = hv2.GetHit(); | |
371 | x1 = ah->X(); y1 = ah->Y(); z1 = ah->Z(); | |
372 | if ((x-x1)*(x-x1) + (y-y1)*(y-y1) + (z-z1)*(z-z1) > tpcSqrRes) | |
373 | { | |
a15e6d7d | 374 | fH.fDetId = det.fDetidx; |
73c1c0ec | 375 | fH.fSubdetId = 0; |
376 | fH.fLabel = ah->Track(); | |
377 | fH.fEvaLabel = evaIdx; | |
378 | fH.fV.fX = x1; fH.fV.fY = y1; fH.fV.fZ = z1; | |
379 | fTreeH->Fill(); | |
380 | hmap[fH.fLabel]++; | |
381 | x = x1; y = y1; z = z1; | |
382 | count++; | |
383 | } | |
384 | } while (hv2.Next()); | |
385 | } | |
386 | // printf("%d entries in TPChits \n",count); | |
387 | break; | |
5a5a1232 | 388 | } |
73c1c0ec | 389 | default: |
390 | { | |
a15e6d7d | 391 | TTree* treeh = fRunLoader->GetTreeH(det.fName, false); |
73c1c0ec | 392 | if (treeh == 0) { |
a15e6d7d | 393 | Warning(kEH, Form("no hits for %s.", det.fName)); |
73c1c0ec | 394 | continue; |
395 | } | |
a15e6d7d | 396 | TClonesArray *arr = new TClonesArray(det.fHitbranch); |
397 | treeh->SetBranchAddress(det.fName, &arr); | |
73c1c0ec | 398 | Int_t np = treeh->GetEntries(); |
399 | // in TreeH files hits are grouped in clones arrays | |
400 | // each eva particle has its own clone array | |
401 | for (Int_t i = 0; i < np; ++i) | |
402 | { | |
403 | treeh->GetEntry(i); | |
404 | Int_t evaIdx = np -i -1; | |
405 | Int_t nh=arr->GetEntriesFast(); | |
406 | x = y = z = 0; | |
407 | // printf("%d entry %d hits for primary %d \n", i, nh, evaIdx); | |
408 | for (Int_t j = 0; j < nh; ++j) | |
84aff7a4 | 409 | { |
73c1c0ec | 410 | AliHit* aliHit = (AliHit*)arr->UncheckedAt(j); |
a15e6d7d | 411 | fH.fDetId = det.fDetidx; |
84aff7a4 | 412 | fH.fSubdetId = 0; |
73c1c0ec | 413 | fH.fLabel = aliHit->GetTrack(); |
414 | fH.fEvaLabel = evaIdx; | |
415 | fH.fV.Set(aliHit->X(), aliHit->Y(), aliHit->Z()); | |
a15e6d7d | 416 | if (det.fDetidx == 2) |
73c1c0ec | 417 | { |
418 | x1=aliHit->X();y1=aliHit->Y();z1=aliHit->Z(); | |
419 | if ((x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1) < trdSqrRes) continue; | |
420 | x=x1; y=y1; z=z1; | |
421 | } | |
84aff7a4 | 422 | hmap[fH.fLabel]++; |
73c1c0ec | 423 | fTreeH->Fill(); |
51346b82 | 424 | } |
5a5a1232 | 425 | } |
73c1c0ec | 426 | delete arr; |
427 | break; | |
428 | } // end default | |
5a5a1232 | 429 | } // end switch |
430 | } // end while | |
51346b82 | 431 | |
5a5a1232 | 432 | |
433 | //set geninfo | |
73c1c0ec | 434 | for(std::map<Int_t, Int_t>::iterator j=hmap.begin(); j!=hmap.end(); ++j) |
435 | { | |
84aff7a4 | 436 | GetGeninfo(j->first)->fNHits += j->second; |
5a5a1232 | 437 | } |
5a5a1232 | 438 | } |
439 | ||
57ffa5fb | 440 | /******************************************************************************/ |
5a5a1232 | 441 | // Clusters |
57ffa5fb | 442 | /******************************************************************************/ |
5a5a1232 | 443 | |
d810d0de | 444 | void AliEveVSDCreator::ConvertClusters() |
5a5a1232 | 445 | { |
73c1c0ec | 446 | // Convert clusters. |
447 | // | |
448 | // Only supported for ITS and TPC at the moment, see dedicated | |
449 | // functions ConvertITSClusters() and ConvertTPCClusters(). | |
450 | // | |
451 | // It should be possible now to do this in a general manner (with | |
452 | // the alignment framework). | |
453 | ||
a15e6d7d | 454 | static const TEveException kEH("AliEveVSDCreator::ConvertClusters "); |
5a5a1232 | 455 | |
84aff7a4 | 456 | if(fTreeC != 0) |
a15e6d7d | 457 | throw(kEH + "clusters already converted."); |
5a5a1232 | 458 | |
84aff7a4 | 459 | fDirectory->cd(); |
460 | fTreeC = new TTree("Clusters", "rec clusters"); | |
461 | fTreeC->Branch("C", "TEveCluster", &fpC, fBuffSize); | |
5a5a1232 | 462 | |
463 | try { | |
464 | ConvertITSClusters(); | |
a15e6d7d | 465 | } catch(TEveException& exc) { Warning(kEH, exc); } |
5a5a1232 | 466 | |
467 | try { | |
468 | ConvertTPCClusters(); | |
a15e6d7d | 469 | } catch(TEveException& exc) { Warning(kEH, exc); } |
5a5a1232 | 470 | } |
471 | ||
57ffa5fb | 472 | /******************************************************************************/ |
5a5a1232 | 473 | |
d810d0de | 474 | void AliEveVSDCreator::ConvertTPCClusters() |
5a5a1232 | 475 | { |
73c1c0ec | 476 | // Convert TPC clusters and transform them to global coordinates. |
477 | ||
a15e6d7d | 478 | static const TEveException kEH("AliEveVSDCreator::ConvertTPCClusters "); |
5a5a1232 | 479 | |
8cc1d3b4 | 480 | fRunLoader->LoadRecPoints("TPC"); |
481 | TTree* tree = fRunLoader->GetTreeR("TPC", false); | |
482 | if (!tree) | |
a15e6d7d | 483 | throw(kEH + "'TreeR' not found."); |
5a5a1232 | 484 | |
73c1c0ec | 485 | AliTPCClustersRow clrow, *clrowp = &clrow; |
5a5a1232 | 486 | AliTPCclusterMI *cl; |
73c1c0ec | 487 | clrow.SetClass("AliTPCclusterMI"); |
488 | tree->SetBranchAddress("Segment", &clrowp); | |
5a5a1232 | 489 | |
490 | // count clusters | |
491 | Int_t nClusters = 0; | |
73c1c0ec | 492 | Int_t nEnt = tree->GetEntries(); |
493 | for (Int_t n = 0; n < nEnt; ++n) | |
494 | { | |
5a5a1232 | 495 | tree->GetEntry(n); |
73c1c0ec | 496 | nClusters += clrow.GetArray()->GetEntriesFast(); |
5a5a1232 | 497 | } |
498 | ||
fd31e9de | 499 | std::map<Int_t, Int_t> cmap; |
5a5a1232 | 500 | |
73c1c0ec | 501 | for (Int_t n = 0; n < tree->GetEntries(); ++n) |
502 | { | |
5a5a1232 | 503 | tree->GetEntry(n); |
73c1c0ec | 504 | Int_t ncl = clrow.GetArray()->GetEntriesFast(); |
505 | if (ncl > 0) | |
506 | { | |
73c1c0ec | 507 | while (ncl--) |
508 | { | |
509 | if (clrow.GetArray()) | |
510 | { | |
511 | // cl = new AliTPCclusterMI(*(AliTPCclusterMI*)clrow.GetArray()->UncheckedAt(ncl)); | |
512 | cl = (AliTPCclusterMI*)clrow.GetArray()->UncheckedAt(ncl); | |
513 | if (cl->GetLabel(0) >= 0) | |
84aff7a4 | 514 | { |
8cc1d3b4 | 515 | Float_t g[3]; //global coordinates |
516 | cl->GetGlobalXYZ(g); | |
5a5a1232 | 517 | |
84aff7a4 | 518 | fC.fDetId = 1; |
8cc1d3b4 | 519 | fC.fSubdetId = clrow.GetID(); |
84aff7a4 | 520 | fC.fLabel[0] = cl->GetLabel(0); |
521 | fC.fLabel[1] = cl->GetLabel(1); | |
522 | fC.fLabel[2] = cl->GetLabel(2); | |
8cc1d3b4 | 523 | fC.fV.Set(g); |
84aff7a4 | 524 | |
525 | fTreeC->Fill(); | |
526 | { | |
527 | int i = 0; | |
73c1c0ec | 528 | while (i < 3 && fC.fLabel[i]) |
84aff7a4 | 529 | cmap[fC.fLabel[i++]]++; |
5a5a1232 | 530 | } |
531 | } | |
532 | } | |
533 | } | |
534 | } | |
535 | } | |
536 | //set geninfo | |
73c1c0ec | 537 | for (std::map<Int_t, Int_t>::iterator j=cmap.begin(); j!=cmap.end(); ++j) |
538 | { | |
84aff7a4 | 539 | GetGeninfo(j->first)->fNClus += j->second; |
5a5a1232 | 540 | } |
541 | } | |
542 | ||
57ffa5fb | 543 | /******************************************************************************/ |
5a5a1232 | 544 | |
d810d0de | 545 | void AliEveVSDCreator::ConvertITSClusters() |
5a5a1232 | 546 | { |
73c1c0ec | 547 | // Convert ITS clusters and transform them to global coordinates. |
548 | ||
a15e6d7d | 549 | static const TEveException kEH("AliEveVSDCreator::ConvertITSClusters "); |
5a5a1232 | 550 | |
8cc1d3b4 | 551 | fRunLoader->LoadRecPoints("ITS"); |
552 | TTree* tree = fRunLoader->GetTreeR("ITS", false); | |
553 | if (!tree) | |
a15e6d7d | 554 | throw(kEH + "'TreeR' not found."); |
5a5a1232 | 555 | |
73c1c0ec | 556 | // |
a15e6d7d | 557 | AliITSLoader *itsLd = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader"); |
558 | AliITSgeom *geom = itsLd->GetITSgeom(); | |
5a5a1232 | 559 | |
560 | //printf("alice ITS geom %p \n",geom ); | |
561 | ||
73c1c0ec | 562 | if (!geom) |
a15e6d7d | 563 | throw(kEH + "can not find ITS geometry"); |
5a5a1232 | 564 | |
565 | TClonesArray *arr = new TClonesArray("AliITSclusterV2"); | |
566 | tree->SetBranchAddress("Clusters", &arr); | |
567 | Int_t nmods = tree->GetEntries(); | |
568 | Float_t gc[3]; | |
fd31e9de | 569 | std::map<Int_t, Int_t> cmap; |
5a5a1232 | 570 | |
73c1c0ec | 571 | for (Int_t mod = 0; mod < nmods; ++mod) |
572 | { | |
5a5a1232 | 573 | tree->GetEntry(mod); |
574 | Int_t nc=arr->GetEntriesFast(); | |
73c1c0ec | 575 | for (Int_t j = 0; j < nc; ++j) |
576 | { | |
577 | AliITSclusterV2* recp = (AliITSclusterV2*) arr->UncheckedAt(j); | |
5a5a1232 | 578 | |
51346b82 | 579 | Double_t rot[9]; |
5a5a1232 | 580 | geom->GetRotMatrix(mod,rot); |
51346b82 | 581 | Int_t lay,lad,det; |
5a5a1232 | 582 | geom->GetModuleId(mod,lay,lad,det); |
51346b82 | 583 | Float_t tx,ty,tz; |
584 | geom->GetTrans(lay,lad,det,tx,ty,tz); | |
5a5a1232 | 585 | |
586 | Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi(); | |
587 | Double_t phi1=TMath::Pi()/2+alpha; | |
73c1c0ec | 588 | if (lay == 1) phi1+=TMath::Pi(); |
5a5a1232 | 589 | |
590 | Float_t cp=TMath::Cos(phi1), sp=TMath::Sin(phi1); | |
591 | Float_t r=tx*cp+ty*sp; | |
84aff7a4 | 592 | gc[0] = r*cp - recp->GetY()*sp; |
593 | gc[1] = r*sp + recp->GetY()*cp; | |
594 | gc[2] = recp->GetZ(); | |
595 | ||
596 | fC.fDetId = 0; | |
597 | fC.fSubdetId = 0; | |
598 | fC.fLabel[0] = recp->GetLabel(0); | |
599 | fC.fLabel[1] = recp->GetLabel(1); | |
600 | fC.fLabel[2] = recp->GetLabel(2); | |
601 | fC.fV.fX = r*cp - recp->GetY()*sp; | |
602 | fC.fV.fY = r*sp + recp->GetY()*cp; | |
603 | fC.fV.fZ = recp->GetZ(); | |
604 | fTreeC->Fill(); | |
5a5a1232 | 605 | { int i = 0; |
84aff7a4 | 606 | while(i < 3 && fC.fLabel[i]) |
607 | cmap[fC.fLabel[i++]]++; | |
5a5a1232 | 608 | } |
51346b82 | 609 | } |
5a5a1232 | 610 | |
73c1c0ec | 611 | for (std::map<Int_t, Int_t>::iterator j=cmap.begin(); j!=cmap.end(); ++j) |
612 | { | |
84aff7a4 | 613 | GetGeninfo(j->first)->fNClus += j->second; |
5a5a1232 | 614 | } |
615 | } | |
616 | delete arr; | |
617 | } | |
618 | ||
57ffa5fb | 619 | /******************************************************************************/ |
5a5a1232 | 620 | // ESD |
57ffa5fb | 621 | /******************************************************************************/ |
5a5a1232 | 622 | |
d810d0de | 623 | void AliEveVSDCreator::ConvertRecTracks() |
5a5a1232 | 624 | { |
73c1c0ec | 625 | // Convert reconstructed tracks. |
626 | ||
a15e6d7d | 627 | static const TEveException kEH("AliEveVSDCreator::ConvertRecTracks "); |
5a5a1232 | 628 | |
73c1c0ec | 629 | if (fTreeR != 0) |
a15e6d7d | 630 | throw(kEH + "tracks already converted."); |
5a5a1232 | 631 | |
8cc1d3b4 | 632 | AliESDEvent* esdEvent = AliEveEventManager::AssertESD(); |
633 | ||
84aff7a4 | 634 | fDirectory->cd(); |
635 | fTreeR = new TTree("RecTracks", "rec tracks"); | |
5a5a1232 | 636 | |
84aff7a4 | 637 | fTreeR->Branch("R", "TEveRecTrack", &fpR, 512*1024,1); |
51346b82 | 638 | |
5a5a1232 | 639 | // reconstructed tracks |
a15e6d7d | 640 | AliESDtrack* esdTrack; |
5a5a1232 | 641 | Double_t dbuf[3]; |
73c1c0ec | 642 | for (Int_t n = 0; n < esdEvent->GetNumberOfTracks(); ++n) |
643 | { | |
a15e6d7d | 644 | esdTrack = esdEvent->GetTrack(n); |
645 | ||
646 | fR.fLabel = esdTrack->GetLabel(); | |
647 | fR.fStatus = (Int_t) esdTrack->GetStatus(); | |
648 | fR.fSign = (Int_t) esdTrack->GetSign(); | |
649 | esdTrack->GetXYZ(dbuf); fR.fV.Set(dbuf); | |
650 | esdTrack->GetPxPyPz(dbuf); fR.fP.Set(dbuf); | |
651 | Double_t ep = esdTrack->GetP(); | |
652 | fR.fBeta = ep/TMath::Sqrt(ep*ep + TMath::C()*TMath::C()*esdTrack->GetMass()*esdTrack->GetMass()); | |
84aff7a4 | 653 | fTreeR->Fill(); |
5a5a1232 | 654 | } |
84aff7a4 | 655 | fTreeR->BuildIndex("label"); |
73c1c0ec | 656 | delete esdEvent; |
5a5a1232 | 657 | } |
658 | ||
57ffa5fb | 659 | /******************************************************************************/ |
5a5a1232 | 660 | |
d810d0de | 661 | void AliEveVSDCreator::ConvertV0() |
5a5a1232 | 662 | { |
73c1c0ec | 663 | // Convert reconstructed V0s. |
664 | ||
a15e6d7d | 665 | static const TEveException kEH("AliEveVSDCreator::ConvertV0 "); |
5a5a1232 | 666 | |
84aff7a4 | 667 | if(fTreeV0 != 0) |
a15e6d7d | 668 | throw(kEH + "AliEveV0 already converted."); |
5a5a1232 | 669 | |
8cc1d3b4 | 670 | AliESDEvent* esdEvent = AliEveEventManager::AssertESD(); |
671 | ||
84aff7a4 | 672 | fDirectory->cd(); |
d810d0de | 673 | fTreeV0 = new TTree("AliEveV0", "AliEveV0 points"); |
5a5a1232 | 674 | |
d810d0de | 675 | fTreeV0->Branch("AliEveV0", "TEveRecV0", &fpV0, 512*1024,1); |
5a5a1232 | 676 | |
73c1c0ec | 677 | for (Int_t n = 0; n < esdEvent->GetNumberOfV0s(); ++n) |
982f2494 | 678 | { |
73c1c0ec | 679 | AliESDv0 *av = esdEvent->GetV0(n); |
680 | AliESDtrack *trackN = esdEvent->GetTrack(av->GetNindex()); // negative daughter | |
681 | AliESDtrack *trackP = esdEvent->GetTrack(av->GetPindex()); // positive daughter | |
982f2494 | 682 | |
5a5a1232 | 683 | Double_t pos[3]; |
684 | ||
84aff7a4 | 685 | fV0.fStatus = av->GetStatus(); |
5a5a1232 | 686 | // Point of closest approach |
b75d63a7 | 687 | av->GetXYZ(pos[0],pos[1],pos[2]); |
51346b82 | 688 | fV0.fVCa.fX = pos[0]; |
84aff7a4 | 689 | fV0.fVCa.fY = pos[1]; |
690 | fV0.fVCa.fZ = pos[2]; | |
51346b82 | 691 | // set birth vertex of neutral particle |
b75d63a7 | 692 | av->GetXYZ(pos[0], pos[1], pos[2]); |
84aff7a4 | 693 | fV0.fV0Birth.Set(pos); |
5a5a1232 | 694 | |
695 | // momentum and position of negative particle | |
b75d63a7 | 696 | av->GetParamN()->GetPxPyPz(pos); |
84aff7a4 | 697 | fV0.fPNeg.Set(pos); |
b75d63a7 | 698 | av->GetParamN()->GetXYZ(pos); |
84aff7a4 | 699 | fV0.fVNeg.Set(pos); |
5a5a1232 | 700 | |
701 | // momentum and position of positive particle | |
b75d63a7 | 702 | av->GetParamP()->GetPxPyPz(pos); |
84aff7a4 | 703 | fV0.fPPos.Set(pos); |
5a5a1232 | 704 | av->GetParamP()->GetXYZ(pos); |
84aff7a4 | 705 | fV0.fVPos.Set(pos); |
5a5a1232 | 706 | |
84aff7a4 | 707 | fV0.fLabel = 0; // !!!! mother label unknown |
708 | fV0.fPdg = av->GetPdgCode(); | |
982f2494 | 709 | |
5a5a1232 | 710 | // daughter indices |
84aff7a4 | 711 | fV0.fDLabel[0] = TMath::Abs(trackN->GetLabel()); |
712 | fV0.fDLabel[1] = TMath::Abs(trackP->GetLabel()); | |
5a5a1232 | 713 | |
51346b82 | 714 | // printf("AliEveV0 convert labels(%d,%d) index(%d,%d)\n", |
84aff7a4 | 715 | // fV0.d_label[0], fV0.d_label[1], |
982f2494 | 716 | // av->GetNIndex(), av->GetPIndex()); |
5a5a1232 | 717 | |
84aff7a4 | 718 | fTreeV0->Fill(); |
5a5a1232 | 719 | } |
73c1c0ec | 720 | // if (esdEvent->GetNumberOfV0s()) fTreeV0->BuildIndex("label"); |
721 | delete esdEvent; | |
5a5a1232 | 722 | } |
723 | ||
57ffa5fb | 724 | /******************************************************************************/ |
5a5a1232 | 725 | |
d810d0de | 726 | void AliEveVSDCreator::ConvertKinks() |
5a5a1232 | 727 | { |
73c1c0ec | 728 | // Convert reconstructed kinks. |
729 | ||
a15e6d7d | 730 | static const TEveException kEH("AliEveVSDCreator::ConvertKinks "); |
5a5a1232 | 731 | |
73c1c0ec | 732 | if (fTreeKK != 0) |
a15e6d7d | 733 | throw(kEH + "Kinks already converted."); |
5a5a1232 | 734 | |
8cc1d3b4 | 735 | AliESDEvent* esdEvent = AliEveEventManager::AssertESD(); |
736 | ||
84aff7a4 | 737 | fDirectory->cd(); |
738 | fTreeKK = new TTree("Kinks", "ESD Kinks"); | |
5a5a1232 | 739 | |
84aff7a4 | 740 | fTreeKK->Branch("KK", "TEveRecKink", &fpKK, fBuffSize); |
5a5a1232 | 741 | |
73c1c0ec | 742 | // printf("CONVERT KINK Read %d entries in tree kinks \n", esdEvent->GetNumberOfKinks()); |
743 | for (Int_t n = 0; n < esdEvent->GetNumberOfKinks(); ++n) | |
744 | { | |
745 | AliESDkink* kk = esdEvent->GetKink(n); | |
5a5a1232 | 746 | |
747 | Double_t pos[3]; | |
748 | ||
84aff7a4 | 749 | fKK.fLabel = kk->GetLabel(0); |
edaf814f | 750 | fKK.fStatus = 0; // status is Char_t[12] ... have no idea how/what to extract. |
5a5a1232 | 751 | |
752 | // reconstructed kink position | |
84aff7a4 | 753 | fKK.fLabelSec = kk->GetLabel(1); |
754 | fKK.fVKink.Set(kk->GetPosition()); | |
5a5a1232 | 755 | |
73c1c0ec | 756 | const AliExternalTrackParam& tpMother = kk->RefParamMother(); |
51346b82 | 757 | // momentum and position of mother |
73c1c0ec | 758 | tpMother.GetPxPyPz(pos); |
84aff7a4 | 759 | fKK.fP.Set(pos); |
73c1c0ec | 760 | tpMother.GetXYZ(pos); |
84aff7a4 | 761 | fKK.fV.Set(pos); |
73c1c0ec | 762 | const Double_t* par = tpMother.GetParameter(); |
763 | // printf("KINK Pt %f, %f \n",1/tpMother.Pt(),par[4] ); | |
84aff7a4 | 764 | fKK.fSign = (par[4] < 0) ? -1 : 1; |
51346b82 | 765 | |
73c1c0ec | 766 | const AliExternalTrackParam& tpDaughter = kk->RefParamDaughter(); |
51346b82 | 767 | // momentum and position of daughter |
73c1c0ec | 768 | tpDaughter.GetPxPyPz(pos); |
84aff7a4 | 769 | fKK.fPSec.Set(pos); |
73c1c0ec | 770 | tpDaughter.GetXYZ(pos); |
84aff7a4 | 771 | fKK.fVEnd.Set(pos); |
5a5a1232 | 772 | |
84aff7a4 | 773 | fTreeKK->Fill(); |
5a5a1232 | 774 | } |
73c1c0ec | 775 | if (esdEvent->GetNumberOfKinks()) fTreeKK->BuildIndex("label"); |
776 | delete esdEvent; | |
5a5a1232 | 777 | } |
57ffa5fb | 778 | /******************************************************************************/ |
84aff7a4 | 779 | // TEveMCRecCrossRef |
57ffa5fb | 780 | /******************************************************************************/ |
5a5a1232 | 781 | |
d810d0de | 782 | void AliEveVSDCreator::ConvertGenInfo() |
5a5a1232 | 783 | { |
73c1c0ec | 784 | // Build simulation-reconstruction cross-reference table. |
785 | // In a rather poor state at the moment. | |
786 | ||
a15e6d7d | 787 | static const TEveException kEH("AliEveVSDCreator::ConvertGenInfo "); |
5a5a1232 | 788 | |
84aff7a4 | 789 | if(fTreeGI != 0) |
a15e6d7d | 790 | throw(kEH + "GI already converted."); |
5a5a1232 | 791 | |
84aff7a4 | 792 | fDirectory->cd(); |
793 | fTreeGI = new TTree("TEveMCRecCrossRef", "Objects prepared for cross querry"); | |
5a5a1232 | 794 | |
84aff7a4 | 795 | TEveMCRecCrossRef::Class()->IgnoreTObjectStreamer(true); |
796 | fTreeGI->Branch("GI", "TEveMCRecCrossRef", &fpGI, fBuffSize); | |
797 | fTreeGI->Branch("K.", "TEveMCTrack", &fpK); | |
798 | fTreeGI->Branch("R.", "TEveRecTrack", &fpR); | |
5a5a1232 | 799 | |
73c1c0ec | 800 | for (std::map<Int_t, TEveMCRecCrossRef*>::iterator j=fGenInfoMap.begin(); j!=fGenInfoMap.end(); ++j) { |
84aff7a4 | 801 | fGI = *(j->second); |
802 | fGI.fLabel = j->first; | |
803 | fTreeK->GetEntry(j->first); | |
5a5a1232 | 804 | |
84aff7a4 | 805 | if (fTreeR) { |
806 | Int_t re = fTreeR->GetEntryNumberWithIndex(j->first); | |
51346b82 | 807 | if(re != -1) |
84aff7a4 | 808 | fGI.fIsRec = true; |
5a5a1232 | 809 | } |
73c1c0ec | 810 | // Int_t hasV0 = fTreeV0->GetEntryNumberWithIndex(j->first); |
811 | //if (hasV0 != -1) | |
d810d0de | 812 | // fGI.has_AliEveV0 = true; |
84aff7a4 | 813 | if (fTreeKK) { |
73c1c0ec | 814 | Int_t hasKk = fTreeKK->GetEntryNumberWithIndex(j->first); |
815 | if (hasKk != -1) | |
84aff7a4 | 816 | fGI.fHasKink = true; |
5a5a1232 | 817 | } |
84aff7a4 | 818 | fTreeGI->Fill(); |
5a5a1232 | 819 | } |
73c1c0ec | 820 | fGenInfoMap.clear(); |
5a5a1232 | 821 | } |
822 | ||
57ffa5fb | 823 | /******************************************************************************/ |
824 | /******************************************************************************/ | |
5a5a1232 | 825 | // Protected methods |
57ffa5fb | 826 | /******************************************************************************/ |
827 | /******************************************************************************/ | |
5a5a1232 | 828 | |
d810d0de | 829 | TEveMCRecCrossRef* AliEveVSDCreator::GetGeninfo(Int_t label) |
5a5a1232 | 830 | { |
73c1c0ec | 831 | // Return the cross-reference structure for given label. |
832 | // If the object does not exist it is created. | |
833 | ||
5a5a1232 | 834 | // printf("get_geninfo %d\n", label); |
84aff7a4 | 835 | TEveMCRecCrossRef* gi; |
73c1c0ec | 836 | std::map<Int_t, TEveMCRecCrossRef*>::iterator i = fGenInfoMap.find(label); |
837 | if (i == fGenInfoMap.end()) { | |
84aff7a4 | 838 | gi = new TEveMCRecCrossRef(); |
73c1c0ec | 839 | fGenInfoMap[label] = gi; |
5a5a1232 | 840 | } else { |
841 | gi = i->second; | |
842 | } | |
843 | return gi; | |
844 | } |