]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/scripts/GetMedia.C
0. General code clean-up, including messages, and the like.
[u/mrichter/AliRoot.git] / FMD / scripts / GetMedia.C
CommitLineData
bf000c32 1//____________________________________________________________________
088f8e79 2//
3// $Id$
4//
5// Script that contains a class to get the media where a certain track
6// was created. This is used for background studies.
7//
8// Use the script `Compile.C' to compile this class using ACLic.
9//
10#include <TH2D.h>
11#include <AliFMDHit.h>
12#include <AliFMDInput.h>
13#include <iostream>
14#include <TStyle.h>
15#include <TArrayF.h>
16#include <TArrayI.h>
17#include <AliRun.h>
18#include <TNtuple.h>
19
20struct Media : public TNamed
21{
22 TArrayI* fMeds;
23 TNtuple* fCount;
24 Media(const char* name, const char* title)
25 : TNamed(name, title), fMeds(0)
26 {
27 fCount = new TNtuple(GetName(), "E/I:DET:RNG:SEC:STR:X/F:Y:Z:EDEP:PDG/I");
28 }
29 Media(const char* name)
30 : TNamed(name, "Media information"), fMeds(0), fCount(0)
31 {
32 AliDetector* det = gAlice->GetDetector(name);
33 if (!det) {
34 Warning("Media", "Detector %s not found in gAlice", name);
35 return;
36 }
37 fMeds = det->GetIdtmed();
38 if (!fMeds) {
39 Warning("Media", "No mediums for detector %s found", name);
40 return;
41 }
42 fCount = new TNtuple(GetName(), "E/I:DET:RNG:SEC:STR:X/F:Y:Z:EDEP:PDG/I");
43 }
44};
45
46
bf000c32 47//____________________________________________________________________
088f8e79 48class GetMedia : public AliFMDInputHits
49{
50private:
51 TString fModList;
52 TObjArray fMedia;
53 Media* fOther;
54 Media* fAll;
55 Int_t fEv;
56 TFile* fOutput;
57public:
bf000c32 58 //__________________________________________________________________
088f8e79 59 GetMedia(const char* modlist="FMD:ITS:BODY:ABSO:START:PIPE",
60 const char* output="media.root")
61 {
62 fOutput = TFile::Open(output, "RECREATE");
63 fOther = new Media("other", "Unknown media"),
64 fAll = new Media("All", "All media")
65 fEv = 0;
66 AddLoad(kKinematics);
67 }
bf000c32 68 //__________________________________________________________________
088f8e79 69 Media* FindMedia(Int_t med)
70 {
71 TIter next(&fMedia);
72 Media* media = 0;
73 while ((media == static_cast<Media*>(next()))) {
74 if (!media->fMeds) continue;
75 TArrayI& ids = *(media->fMeds);
76 for (Int_t i = 0; i < ids.fN; i++)
77 if (med == ids[i]) return media;
78 }
79 return 0;
80 }
bf000c32 81 //__________________________________________________________________
088f8e79 82 Bool_t Init()
83 {
84 if (!gGeoManager) {
85 Error("GetMedia", "No geometry defined - make sure you have that");
86 return kFALSE;
87 }
88 if (!gAlice) {
89 Error("GetMedia", "gAlice not defined");
90 return kFALSE;
91 }
92 Int_t now = 0;
93 Int_t colon;
94 while ((colon = fModList.Index(":", now)) >= 0) {
95 fMedia.Add(new Media(fModList(now, colon-now)));
96 now = colon+1;
97 }
98 if (now < fModList.Length())
99 fMedia.Add(new Media(now, fModList.Length()-now));
100 if (fMedia.GetEntries() <= 0) return kFALSE;
101 return AliFMDInputHits::Init();
102 }
bf000c32 103 //__________________________________________________________________
088f8e79 104 Bool_t Begin(Int_t ev)
105 {
106 fEv = ev;
107 return AliFMDInputHits::Begin(ev);
108 }
bf000c32 109 //__________________________________________________________________
088f8e79 110 Bool_t ProcessHit(AliFMDHit* hit, TParticle* track)
111 {
112 if (!hit || !track) {
113 std::cout << "No hit or track (hit: " << hit << ", track: "
114 << track << ")" << std::endl;
115 return kFALSE;
116 }
117 // Get production vertex
118 Double_t vx = track->Vx();
119 Double_t vy = track->Vy();
120 Double_t vz = track->Vz();
121
122 fAll->fCounts->Fill(fEv, hit->Detector(),Int_t(hit->Ring()),
123 hit->Sector(), hit->Strip(),
124 hit->X(), hit->Y(), hit->Z(), hit->Edep(),
125 hit->Pdg());
126 // Get node
127 TGeoNode* prodNode = gGeoManager->FindNode(vx,vy,vz);
128 if (!prodNode) return kTRUE;
129
130 // Get volume
131 TGeoVolume* prodVol = prodNode->GetVolume();
132 if (!prodVol) return kTRUE;
133
134 // Med medium
135 TGeoMedium* prodMed = prodVol->GetMedium();
136 if (!prodMed) return kTRUE;
137
138 Media* media = FindMedia(prodMed->GetUniqueID());
139 if (media) media = fOther;
140
141 // r = TMath::Sqrt(hit->X() * hit->X() + hit->Y() * hit->Y());
142 // if(r!=0) Float_t wgt=1./(2. * 3.1415*r);
143 media->fCounts->Fill(fEv, hit->Detector(),Int_t(hit->Ring()),
144 hit->Sector(), hit->Strip(),
145 hit->X(), hit->Y(), hit->Z(), hit->Edep(),
146 hit->Pdg());
147 return kTRUE;
148 }
bf000c32 149 //__________________________________________________________________
088f8e79 150 Bool_t Finish()
151 {
152 fOutput->Write();
153 fOutput->Close();
154 return kTRUE;
155 }
156};
157
158//____________________________________________________________________
159//
160// EOF
161//