1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Quality Assurance class //
21 // Provides standard histograms for every element of the detector //
23 ///////////////////////////////////////////////////////////////////////////////
30 #include <TDatabasePDG.h>
34 #include <TLorentzVector.h>
36 #include <TObjArray.h>
37 #include <TPaveLabel.h>
39 #include <TVirtualMC.h>
44 #include "AliModule.h"
49 //_______________________________________________________________________
63 // Default constructor
67 //_______________________________________________________________________
68 AliMCQA::AliMCQA(const AliMCQA &qa):
87 //_______________________________________________________________________
88 AliMCQA::AliMCQA(Int_t ndets):
90 fNvolumes(gMC->NofVolumes()),
91 fQAList(new TObjArray(ndets)),
93 fDetDone(new Int_t[ndets]),
94 fQAHist(new TObjArray(2)),
95 fVolNames(new TObjArray(fNvolumes)),
96 fModNames(new TObjArray(fNdets)),
101 // Constructor, creates the list of lists of histograms
107 TObjArray &hist = *fQAList;
111 TObjArray &mods = *(gAlice->Modules());
112 TList *dir = gDirectory->GetList();
113 for (i=0; i<ndets; i++) {
114 hist[i] = list = new TList();
115 AliModule *mod = dynamic_cast<AliModule*>(mods[i]);
118 sprintf(title,"Spectrum entering: %s ",mod->GetName());
119 list->Add(new TH1F("hEnIn",strcat(title,mod->GetTitle()),100,-4,2));
120 dir->Remove(dir->FindObject("hEnIn"));
122 sprintf(title,"Spectrum exiting: %s ",mod->GetName());
123 list->Add(new TH1F("hEnOut",strcat(title,mod->GetTitle()),100,-4,2));
124 dir->Remove(dir->FindObject("hEnOut"));
127 sprintf(title,"Z coordinate entering: %s ",mod->GetName());
128 list->Add(new TH1F("hZIn",strcat(title,mod->GetTitle()),100,
129 mod->ZMin(),mod->ZMax()));
130 dir->Remove(dir->FindObject("hZIn"));
132 sprintf(title,"Z coordinate exiting: %s ",mod->GetName());
133 list->Add(new TH1F("hZOut",strcat(title,mod->GetTitle()),100,
134 mod->ZMin(),mod->ZMax()));
135 dir->Remove(dir->FindObject("hZOut"));
138 gROOT->GetListOfBrowsables()->Add(this,"AliMCQA");
141 // Global QA histograms
144 fQAHist->Add(new TH1F("hMCVcalls","Monte Carlo calls per volume",
145 fNvolumes, 0.5, fNvolumes+0.5));
146 h = dynamic_cast<TH1F*>(dir->FindObject("hMCVcalls"));
147 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddVolumeName()"));
148 dir->Remove(dir->FindObject("hMCVcalls"));
150 // Build list of volume names
152 AliMC * mc = gAlice->GetMCApp();
153 for(i=0;i<fNvolumes;++i) {
154 AliModule *mod = dynamic_cast<AliModule*>
155 ((*gAlice->Modules())[mc->DetFromMate(gMC->VolId2Mate(i+1))]);
156 (*fVolNames)[i]=new TNamed(gMC->VolName(i+1),mod->GetName());
159 fQAHist->Add(new TH1F("hMCMcalls","Monte Carlo calls per module",
160 fNdets, -0.5, fNdets-0.5));
161 h = dynamic_cast<TH1F*>(dir->FindObject("hMCMcalls"));
162 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()"));
164 dir->Remove(dir->FindObject("hMCMcalls"));
166 // Build list of module names
168 for(i=0;i<fNdets;++i)
170 new TNamed((dynamic_cast<AliModule*>((*gAlice->Modules())[i]))->GetName(),"");
173 //_______________________________________________________________________
174 void AliMCQA::Copy(TObject &) const
176 AliFatal("Not implemented!");
179 //_______________________________________________________________________
185 gROOT->GetListOfBrowsables()->Remove(this);
186 //if program crashes here - it probobly means that
187 //one of added browsables was deleted and not removed previously from that list
215 //_______________________________________________________________________
216 void AliMCQA::Browse(TBrowser *b)
219 // Called when the item "Run" is clicked on the left pane
220 // of the Root browser.
221 // It displays the Root Trees and all detectors.
225 // Global histos first
227 TIter global(fQAHist);
228 while((hist = dynamic_cast<TH1*>(global())))
229 b->Add(hist,hist->GetTitle());
231 // Module histograms now
235 while((histos = dynamic_cast<TList*>(next()))) {
237 while((hist = dynamic_cast<TH1*>(next1())))
238 b->Add(hist,hist->GetTitle());
242 //_______________________________________________________________________
243 void AliMCQA::PreTrack()
246 // Called before each track
249 for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0;
252 //_______________________________________________________________________
253 void AliMCQA::StepManager(Int_t id)
256 // Called at each step
261 // Fill Global histograms first
265 static TH1F* mcvcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCVcalls"));
266 mcvcalls->Fill(gMC->CurrentVolID(copy));
267 static TH1F* mcmcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCMcalls"));
271 // Now the step manager histograms
274 static Double_t mpi0=0;
275 static Double_t mpip=0;
276 static Double_t mpim=0;
277 static Double_t mep=0;
278 static Double_t mem=0;
280 Int_t num = gMC->TrackPid();
284 if (mpi0==0) mpi0=gAlice->PDGDB()->GetParticle(num)->Mass();
288 if (mpip==0) mpip=gAlice->PDGDB()->GetParticle(num)->Mass();
292 if (mpim==0) mpim=gAlice->PDGDB()->GetParticle(num)->Mass();
296 if (mep==0) mep=gAlice->PDGDB()->GetParticle(num)->Mass();
300 if (mem==0) mem=gAlice->PDGDB()->GetParticle(num)->Mass();
304 if (gAlice->PDGDB()->GetParticle(num))
305 mass = gAlice->PDGDB()->GetParticle(num)->Mass();
309 static TLorentzVector p, x;
310 gMC->TrackMomentum(p);
311 gMC->TrackPosition(x);
312 Double_t energy = TMath::Max(p[3]-mass,1.e-12);
314 if(!fDetDone[fOldId] && !gMC->IsNewTrack()) {
315 TList *histold = dynamic_cast<TList*>((*fQAList)[fOldId]);
316 hist = dynamic_cast<TH1F*>(histold->FindObject("hEnOut"));
317 hist->Fill(TMath::Log10(energy));
318 hist = dynamic_cast<TH1F*>(histold->FindObject("hZOut"));
323 if(!fDetDone[id] && !gMC->IsNewTrack()) {
324 TList *histnew = dynamic_cast<TList*>((*fQAList)[id]);
325 hist = dynamic_cast<TH1F*>(histnew->FindObject("hEnIn"));
326 hist->Fill(TMath::Log10(energy));
327 hist = dynamic_cast<TH1F*>(histnew->FindObject("hZIn"));
334 //_______________________________________________________________________
335 void AliMCQA::AddModuleName()
338 // Add function DrawModuleName to the module frequency histogram pad
340 static TVirtualPad* oldpad=0;
342 gPad->GetCanvas()->FeedbackMode(kTRUE);
343 if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawModuleName()");
344 DrawPaveLabel(fMPaveLabel);
349 //_______________________________________________________________________
350 void AliMCQA::AddVolumeName()
353 // Add function DrawVolumeName to the volume frequency histogram pad
355 static TVirtualPad* oldpad=0;
357 gPad->GetCanvas()->FeedbackMode(kTRUE);
358 if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawVolumeName()");
359 DrawPaveLabel(fVPaveLabel);
364 //_______________________________________________________________________
365 void AliMCQA::DrawPaveLabel(TPaveLabel *&pv)
368 // Draws the PaveLabel with the meaning of the bin
370 float uxmin = gPad->GetUxmin();
371 float uxmax = gPad->GetUxmax();
372 float uymin = gPad->GetUymin();
373 float uymax = gPad->GetUymax();
374 float lx = uxmax-uxmin;
375 float ly = uymax-uymin;
379 = new TPaveLabel(uxmin+0.05*lx,uymax-(0.05+0.1)*ly,
380 uxmin+(0.05+0.2)*lx,uymax-0.05*ly,
385 //_______________________________________________________________________
386 Int_t AliMCQA::GetHBin(const char* hname)
389 // Get the bin where the cursor is
391 TList *dir = gDirectory->GetList();
392 TH1 *h=dynamic_cast<TH1*>(dir->FindObject(hname));
395 int px = gPad->GetEventX();
396 Float_t upx = gPad->AbsPixeltoX(px);
397 Float_t x = gPad->PadtoX(upx);
399 return h->GetXaxis()->FindBin(x);
402 //_______________________________________________________________________
403 void AliMCQA::DrawModuleName()
406 // Writes the name of the module of the bin where the cursor is
408 TObject *select = gPad->GetSelected();
411 Int_t binx = GetHBin("hMCMcalls");
412 if(0<binx && binx<=fNdets) {
414 strcpy(lab,dynamic_cast<TNamed*>((*fModNames)[binx-1])->GetName());
415 fMPaveLabel->SetLabel(lab);
422 //_______________________________________________________________________
423 void AliMCQA::DrawVolumeName()
426 // Writes the name of the volume:module of the bin where the cursor is
428 TObject *select = gPad->GetSelected();
431 Int_t binx = GetHBin("hMCVcalls");
432 if(0<binx && binx<=fNvolumes) {
434 sprintf(lab,"%s: %s",dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetName(),
435 dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetTitle());
436 fVPaveLabel->SetLabel(lab);