]>
Commit | Line | Data |
---|---|---|
65fb704d | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* | |
17 | $Log$ | |
8409d8c9 | 18 | Revision 1.1 2000/11/30 07:12:48 alibrary |
19 | Introducing new Rndm and QA classes | |
20 | ||
65fb704d | 21 | */ |
22 | ||
23 | /////////////////////////////////////////////////////////////////////////////// | |
24 | // // | |
25 | // // | |
26 | /////////////////////////////////////////////////////////////////////////////// | |
27 | ||
8409d8c9 | 28 | |
65fb704d | 29 | #include <strings.h> |
30 | ||
31 | #include "TObjArray.h" | |
32 | #include "TH1.h" | |
33 | #include "TList.h" | |
34 | #include "TROOT.h" | |
35 | #include "TBrowser.h" | |
36 | #include "TMath.h" | |
37 | #include "TLorentzVector.h" | |
38 | #include "TDatabasePDG.h" | |
39 | #include "TMath.h" | |
8409d8c9 | 40 | #include "TPad.h" |
41 | #include "TExec.h" | |
42 | #include "TPaveLabel.h" | |
43 | #include "TCanvas.h" | |
65fb704d | 44 | |
45 | #include "AliMCQA.h" | |
46 | #include "AliRun.h" | |
47 | #include "AliModule.h" | |
48 | #include "AliMC.h" | |
49 | ||
50 | ClassImp(AliMCQA) | |
51 | ||
52 | ||
53 | //_____________________________________________________________________________ | |
8409d8c9 | 54 | AliMCQA::AliMCQA() : fQAList(0), fDetDone(0), fQAHist(0), fVolNames(0), |
55 | fModNames(0),fMPaveLabel(0),fVPaveLabel(0) | |
56 | { | |
57 | // | |
58 | // Default constructor | |
59 | // | |
60 | } | |
61 | ||
62 | //_____________________________________________________________________________ | |
63 | AliMCQA::AliMCQA(Int_t ndets) : fMPaveLabel(0),fVPaveLabel(0) | |
65fb704d | 64 | { |
65 | // | |
66 | // Constructor, creates the list of lists of histograms | |
67 | // | |
68 | TList *list; | |
8409d8c9 | 69 | TH1F* h; |
70 | ||
71 | fNdets=ndets; | |
65fb704d | 72 | |
73 | fQAList = new TObjArray(ndets); | |
74 | TObjArray &hist = *fQAList; | |
75 | ||
76 | char title[100]; | |
77 | // | |
78 | TObjArray &mods = *(gAlice->Modules()); | |
79 | AliModule *mod; | |
80 | TList *dir = gDirectory->GetList(); | |
81 | for (Int_t i=0; i<ndets; i++) { | |
82 | hist[i] = list = new TList(); | |
83 | mod = (AliModule *) mods[i]; | |
84 | ||
85 | // Energy Spectrum | |
86 | sprintf(title,"Spectrum entering: %s ",mod->GetName()); | |
87 | list->Add(new TH1F("hEnIn",strcat(title,mod->GetTitle()),100,-4,2)); | |
88 | dir->Remove(dir->FindObject("hEnIn")); | |
89 | ||
90 | sprintf(title,"Spectrum exiting: %s ",mod->GetName()); | |
91 | list->Add(new TH1F("hEnOut",strcat(title,mod->GetTitle()),100,-4,2)); | |
92 | dir->Remove(dir->FindObject("hEnOut")); | |
93 | ||
94 | // Z position | |
95 | sprintf(title,"Z coordinate entering: %s ",mod->GetName()); | |
96 | list->Add(new TH1F("hZIn",strcat(title,mod->GetTitle()),100, | |
97 | mod->ZMin(),mod->ZMax())); | |
98 | dir->Remove(dir->FindObject("hZIn")); | |
99 | ||
100 | sprintf(title,"Z coordinate exiting: %s ",mod->GetName()); | |
101 | list->Add(new TH1F("hZOut",strcat(title,mod->GetTitle()),100, | |
102 | mod->ZMin(),mod->ZMax())); | |
103 | dir->Remove(dir->FindObject("hZOut")); | |
104 | } | |
105 | // | |
106 | gROOT->GetListOfBrowsables()->Add(this,"AliMCQA"); | |
107 | ||
108 | fDetDone = new Int_t[fNdets]; | |
8409d8c9 | 109 | |
110 | // | |
111 | // Global QA histograms | |
112 | // | |
113 | fQAHist = new TObjArray(2); | |
114 | fNvolumes=gMC->NofVolumes(); | |
115 | ||
116 | fQAHist->Add(new TH1F("hMCVcalls","Monte Carlo calls per volume", | |
117 | fNvolumes, 0.5, fNvolumes+0.5)); | |
118 | h = (TH1F*) dir->FindObject("hMCVcalls"); | |
119 | h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddVolumeName()")); | |
120 | dir->Remove(dir->FindObject("hMCVcalls")); | |
121 | // | |
122 | // Build list of volume names | |
123 | // | |
124 | Int_t i; | |
125 | fVolNames=new TObjArray(fNvolumes); | |
126 | for(i=0;i<fNvolumes;++i) { | |
127 | AliModule *mod = (AliModule*) | |
128 | (*gAlice->Modules())[gAlice->DetFromMate(gMC->VolId2Mate(i+1))]; | |
129 | (*fVolNames)[i]=new TNamed(gMC->VolName(i+1),mod->GetName()); | |
130 | } | |
131 | ||
132 | fQAHist->Add(new TH1F("hMCMcalls","Monte Carlo calls per module", | |
133 | fNdets, -0.5, fNdets-0.5)); | |
134 | h = (TH1F*) dir->FindObject("hMCMcalls"); | |
135 | h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()")); | |
136 | ||
137 | dir->Remove(dir->FindObject("hMCMcalls")); | |
138 | // | |
139 | // Build list of module names | |
140 | // | |
141 | fModNames=new TObjArray(fNdets); | |
142 | for(i=0;i<fNdets;++i) | |
143 | (*fModNames)[i]= | |
144 | new TNamed(((AliModule *)(*gAlice->Modules())[i])->GetName(),""); | |
65fb704d | 145 | } |
146 | ||
147 | //_____________________________________________________________________________ | |
148 | void AliMCQA::Browse(TBrowser *b) | |
149 | { | |
150 | // | |
151 | // Called when the item "Run" is clicked on the left pane | |
152 | // of the Root browser. | |
153 | // It displays the Root Trees and all detectors. | |
154 | // | |
8409d8c9 | 155 | TH1 *hist; |
156 | // | |
157 | // Global histos first | |
158 | // | |
159 | TIter global(fQAHist); | |
160 | while((hist = (TH1*)global())) | |
161 | b->Add(hist,hist->GetTitle()); | |
162 | // | |
163 | // Module histograms now | |
164 | // | |
65fb704d | 165 | TIter next(fQAList); |
166 | TList *histos; | |
65fb704d | 167 | while((histos = (TList*)next())) { |
168 | TIter next1(histos); | |
8409d8c9 | 169 | while((hist = (TH1*)next1())) |
65fb704d | 170 | b->Add(hist,hist->GetTitle()); |
65fb704d | 171 | } |
172 | } | |
173 | ||
174 | //_____________________________________________________________________________ | |
175 | void AliMCQA::PreTrack() | |
176 | { | |
8409d8c9 | 177 | // |
178 | // Called before each track | |
179 | // | |
65fb704d | 180 | fOldId=-1; |
181 | for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0; | |
182 | } | |
183 | ||
184 | //_____________________________________________________________________________ | |
185 | void AliMCQA::StepManager(Int_t id) | |
186 | { | |
8409d8c9 | 187 | // |
188 | // Called at each step | |
189 | // | |
190 | TH1F *hist; | |
191 | Int_t copy; | |
192 | // | |
193 | // Fill Global histograms first | |
194 | // | |
195 | hist = (TH1F*) fQAHist->FindObject("hMCVcalls"); | |
196 | hist->Fill(gMC->CurrentVolID(copy)); | |
197 | hist = (TH1F*) fQAHist->FindObject("hMCMcalls"); | |
198 | hist->Fill(id); | |
199 | // | |
200 | // Now the step manager histograms | |
201 | // | |
65fb704d | 202 | if(fOldId != id) { |
65fb704d | 203 | TLorentzVector p, x; |
204 | gMC->TrackMomentum(p); | |
205 | gMC->TrackPosition(x); | |
206 | Double_t energy = TMath::Max( | |
207 | p[3]-gAlice->PDGDB()->GetParticle(gMC->TrackPid())->Mass(),1.e-12); | |
208 | if(fOldId > -1) { | |
209 | if(!fDetDone[fOldId] && !gMC->IsNewTrack()) { | |
210 | TList *histold = (TList*) (*fQAList)[fOldId]; | |
211 | hist = (TH1F*) histold->FindObject("hEnOut"); | |
212 | hist->Fill(TMath::Log10(energy)); | |
213 | hist = (TH1F*) histold->FindObject("hZOut"); | |
214 | hist->Fill(x[2]); | |
215 | fDetDone[fOldId]=1; | |
216 | } | |
217 | } | |
218 | if(!fDetDone[id] && !gMC->IsNewTrack()) { | |
219 | TList *histnew = (TList*) (*fQAList)[id]; | |
220 | hist = (TH1F*) histnew->FindObject("hEnIn"); | |
221 | hist->Fill(TMath::Log10(energy)); | |
222 | hist = (TH1F*) histnew->FindObject("hZIn"); | |
223 | hist->Fill(x[2]); | |
224 | } | |
225 | fOldId=id; | |
226 | } | |
227 | } | |
8409d8c9 | 228 | |
229 | //_____________________________________________________________________________ | |
230 | void AliMCQA::AddModuleName() | |
231 | { | |
232 | // | |
233 | // Add function DrawModuleName to the module frequency histogram pad | |
234 | // | |
235 | static TVirtualPad* oldpad=0; | |
236 | if(oldpad!=gPad) { | |
237 | gPad->GetCanvas()->FeedbackMode(kTRUE); | |
238 | if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawModuleName()"); | |
239 | DrawPaveLabel(fMPaveLabel); | |
240 | oldpad=gPad; | |
241 | } | |
242 | } | |
243 | ||
244 | //_____________________________________________________________________________ | |
245 | void AliMCQA::AddVolumeName() | |
246 | { | |
247 | // | |
248 | // Add function DrawVolumeName to the volume frequency histogram pad | |
249 | // | |
250 | static TVirtualPad* oldpad=0; | |
251 | if(oldpad!=gPad) { | |
252 | gPad->GetCanvas()->FeedbackMode(kTRUE); | |
253 | if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawVolumeName()"); | |
254 | DrawPaveLabel(fVPaveLabel); | |
255 | oldpad=gPad; | |
256 | } | |
257 | } | |
258 | ||
259 | //_____________________________________________________________________________ | |
260 | void AliMCQA::DrawPaveLabel(TPaveLabel *&pv) | |
261 | { | |
262 | // | |
263 | // Draws the PaveLabel with the meaning of the bin | |
264 | // | |
265 | float uxmin = gPad->GetUxmin(); | |
266 | float uxmax = gPad->GetUxmax(); | |
267 | float uymin = gPad->GetUymin(); | |
268 | float uymax = gPad->GetUymax(); | |
269 | float lx = uxmax-uxmin; | |
270 | float ly = uymax-uymin; | |
271 | ||
272 | if(pv) delete pv; | |
273 | pv | |
274 | = new TPaveLabel(uxmin+0.05*lx,uymax-(0.05+0.1)*ly, | |
275 | uxmin+(0.05+0.2)*lx,uymax-0.05*ly, | |
276 | ""); | |
277 | pv->Draw(); | |
278 | } | |
279 | ||
280 | //_____________________________________________________________________________ | |
281 | Int_t AliMCQA::GetHBin(const char* hname) | |
282 | { | |
283 | // | |
284 | // Get the bin where the cursor is | |
285 | // | |
286 | TList *dir = gDirectory->GetList(); | |
287 | TH1 *h=(TH1*)dir->FindObject(hname); | |
288 | ||
289 | ||
290 | int px = gPad->GetEventX(); | |
291 | Float_t upx = gPad->AbsPixeltoX(px); | |
292 | Float_t x = gPad->PadtoX(upx); | |
293 | ||
294 | return h->GetXaxis()->FindBin(x); | |
295 | } | |
296 | ||
297 | //_____________________________________________________________________________ | |
298 | void AliMCQA::DrawModuleName() | |
299 | { | |
300 | // | |
301 | // Writes the name of the module of the bin where the cursor is | |
302 | // | |
303 | TObject *select = gPad->GetSelected(); | |
304 | if(!select) return; | |
305 | ||
306 | Int_t binx = GetHBin("hMCMcalls"); | |
307 | if(0<binx && binx<=fNdets) { | |
308 | char lab[15]; | |
309 | strcpy(lab,((TNamed*)(*fModNames)[binx-1])->GetName()); | |
310 | fMPaveLabel->SetLabel(lab); | |
311 | ||
312 | gPad->Modified(); | |
313 | gPad->Update(); | |
314 | } | |
315 | } | |
316 | ||
317 | //_____________________________________________________________________________ | |
318 | void AliMCQA::DrawVolumeName() | |
319 | { | |
320 | // | |
321 | // Writes the name of the volume:module of the bin where the cursor is | |
322 | // | |
323 | TObject *select = gPad->GetSelected(); | |
324 | if(!select) return; | |
325 | ||
326 | Int_t binx = GetHBin("hMCVcalls"); | |
327 | if(0<binx && binx<=fNvolumes) { | |
328 | char lab[20]; | |
329 | sprintf(lab,"%s: %s",((TNamed*)(*fVolNames)[binx-1])->GetName(), | |
330 | ((TNamed*)(*fVolNames)[binx-1])->GetTitle()); | |
331 | fVPaveLabel->SetLabel(lab); | |
332 | ||
333 | gPad->Modified(); | |
334 | gPad->Update(); | |
335 | } | |
336 | } | |
337 | ||
338 |