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>
38 #include <TPaveLabel.h>
42 #include "AliModule.h"
47 //_______________________________________________________________________
61 // Default constructor
65 //_______________________________________________________________________
66 AliMCQA::AliMCQA(const AliMCQA &qa):
85 //_______________________________________________________________________
86 AliMCQA::AliMCQA(Int_t ndets):
88 fNvolumes(gMC->NofVolumes()),
89 fQAList(new TObjArray(ndets)),
91 fDetDone(new Int_t[ndets]),
92 fQAHist(new TObjArray(2)),
93 fVolNames(new TObjArray(fNvolumes)),
94 fModNames(new TObjArray(fNdets)),
99 // Constructor, creates the list of lists of histograms
105 TObjArray &hist = *fQAList;
109 TObjArray &mods = *(gAlice->Modules());
110 TList *dir = gDirectory->GetList();
111 for (i=0; i<ndets; i++) {
112 hist[i] = list = new TList();
113 AliModule *mod = dynamic_cast<AliModule*>(mods[i]);
116 sprintf(title,"Spectrum entering: %s ",mod->GetName());
117 list->Add(new TH1F("hEnIn",strcat(title,mod->GetTitle()),100,-4,2));
118 dir->Remove(dir->FindObject("hEnIn"));
120 sprintf(title,"Spectrum exiting: %s ",mod->GetName());
121 list->Add(new TH1F("hEnOut",strcat(title,mod->GetTitle()),100,-4,2));
122 dir->Remove(dir->FindObject("hEnOut"));
125 sprintf(title,"Z coordinate entering: %s ",mod->GetName());
126 list->Add(new TH1F("hZIn",strcat(title,mod->GetTitle()),100,
127 mod->ZMin(),mod->ZMax()));
128 dir->Remove(dir->FindObject("hZIn"));
130 sprintf(title,"Z coordinate exiting: %s ",mod->GetName());
131 list->Add(new TH1F("hZOut",strcat(title,mod->GetTitle()),100,
132 mod->ZMin(),mod->ZMax()));
133 dir->Remove(dir->FindObject("hZOut"));
136 gROOT->GetListOfBrowsables()->Add(this,"AliMCQA");
139 // Global QA histograms
142 fQAHist->Add(new TH1F("hMCVcalls","Monte Carlo calls per volume",
143 fNvolumes, 0.5, fNvolumes+0.5));
144 h = dynamic_cast<TH1F*>(dir->FindObject("hMCVcalls"));
145 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddVolumeName()"));
146 dir->Remove(dir->FindObject("hMCVcalls"));
148 // Build list of volume names
150 for(i=0;i<fNvolumes;++i) {
151 AliModule *mod = dynamic_cast<AliModule*>
152 ((*gAlice->Modules())[gAlice->DetFromMate(gMC->VolId2Mate(i+1))]);
153 (*fVolNames)[i]=new TNamed(gMC->VolName(i+1),mod->GetName());
156 fQAHist->Add(new TH1F("hMCMcalls","Monte Carlo calls per module",
157 fNdets, -0.5, fNdets-0.5));
158 h = dynamic_cast<TH1F*>(dir->FindObject("hMCMcalls"));
159 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()"));
161 dir->Remove(dir->FindObject("hMCMcalls"));
163 // Build list of module names
165 for(i=0;i<fNdets;++i)
167 new TNamed((dynamic_cast<AliModule*>((*gAlice->Modules())[i]))->GetName(),"");
170 //_______________________________________________________________________
171 void AliMCQA::Copy(AliMCQA &) const
173 Fatal("Copy ctor","Not implemented!\n");
176 //_______________________________________________________________________
182 gROOT->GetListOfBrowsables()->Remove(this);
183 //if program crashes here - it probobly means that
184 //one of added browsables was deleted and not removed previously from that list
212 //_______________________________________________________________________
213 void AliMCQA::Browse(TBrowser *b)
216 // Called when the item "Run" is clicked on the left pane
217 // of the Root browser.
218 // It displays the Root Trees and all detectors.
222 // Global histos first
224 TIter global(fQAHist);
225 while((hist = dynamic_cast<TH1*>(global())))
226 b->Add(hist,hist->GetTitle());
228 // Module histograms now
232 while((histos = dynamic_cast<TList*>(next()))) {
234 while((hist = dynamic_cast<TH1*>(next1())))
235 b->Add(hist,hist->GetTitle());
239 //_______________________________________________________________________
240 void AliMCQA::PreTrack()
243 // Called before each track
246 for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0;
249 //_______________________________________________________________________
250 void AliMCQA::StepManager(Int_t id)
253 // Called at each step
258 // Fill Global histograms first
262 static TH1F* mcvcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCVcalls"));
263 mcvcalls->Fill(gMC->CurrentVolID(copy));
264 static TH1F* mcmcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCMcalls"));
268 // Now the step manager histograms
271 static Double_t mpi0=0;
272 static Double_t mpip=0;
273 static Double_t mpim=0;
274 static Double_t mep=0;
275 static Double_t mem=0;
277 Int_t num = gMC->TrackPid();
281 if (mpi0==0) mpi0=gAlice->PDGDB()->GetParticle(num)->Mass();
285 if (mpip==0) mpip=gAlice->PDGDB()->GetParticle(num)->Mass();
289 if (mpim==0) mpim=gAlice->PDGDB()->GetParticle(num)->Mass();
293 if (mep==0) mep=gAlice->PDGDB()->GetParticle(num)->Mass();
297 if (mem==0) mem=gAlice->PDGDB()->GetParticle(num)->Mass();
301 if (gAlice->PDGDB()->GetParticle(num))
302 mass = gAlice->PDGDB()->GetParticle(num)->Mass();
306 static TLorentzVector p, x;
307 gMC->TrackMomentum(p);
308 gMC->TrackPosition(x);
309 Double_t energy = TMath::Max(p[3]-mass,1.e-12);
311 if(!fDetDone[fOldId] && !gMC->IsNewTrack()) {
312 TList *histold = dynamic_cast<TList*>((*fQAList)[fOldId]);
313 hist = dynamic_cast<TH1F*>(histold->FindObject("hEnOut"));
314 hist->Fill(TMath::Log10(energy));
315 hist = dynamic_cast<TH1F*>(histold->FindObject("hZOut"));
320 if(!fDetDone[id] && !gMC->IsNewTrack()) {
321 TList *histnew = dynamic_cast<TList*>((*fQAList)[id]);
322 hist = dynamic_cast<TH1F*>(histnew->FindObject("hEnIn"));
323 hist->Fill(TMath::Log10(energy));
324 hist = dynamic_cast<TH1F*>(histnew->FindObject("hZIn"));
331 //_______________________________________________________________________
332 void AliMCQA::AddModuleName()
335 // Add function DrawModuleName to the module frequency histogram pad
337 static TVirtualPad* oldpad=0;
339 gPad->GetCanvas()->FeedbackMode(kTRUE);
340 if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawModuleName()");
341 DrawPaveLabel(fMPaveLabel);
346 //_______________________________________________________________________
347 void AliMCQA::AddVolumeName()
350 // Add function DrawVolumeName to the volume frequency histogram pad
352 static TVirtualPad* oldpad=0;
354 gPad->GetCanvas()->FeedbackMode(kTRUE);
355 if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawVolumeName()");
356 DrawPaveLabel(fVPaveLabel);
361 //_______________________________________________________________________
362 void AliMCQA::DrawPaveLabel(TPaveLabel *&pv)
365 // Draws the PaveLabel with the meaning of the bin
367 float uxmin = gPad->GetUxmin();
368 float uxmax = gPad->GetUxmax();
369 float uymin = gPad->GetUymin();
370 float uymax = gPad->GetUymax();
371 float lx = uxmax-uxmin;
372 float ly = uymax-uymin;
376 = new TPaveLabel(uxmin+0.05*lx,uymax-(0.05+0.1)*ly,
377 uxmin+(0.05+0.2)*lx,uymax-0.05*ly,
382 //_______________________________________________________________________
383 Int_t AliMCQA::GetHBin(const char* hname)
386 // Get the bin where the cursor is
388 TList *dir = gDirectory->GetList();
389 TH1 *h=dynamic_cast<TH1*>(dir->FindObject(hname));
392 int px = gPad->GetEventX();
393 Float_t upx = gPad->AbsPixeltoX(px);
394 Float_t x = gPad->PadtoX(upx);
396 return h->GetXaxis()->FindBin(x);
399 //_______________________________________________________________________
400 void AliMCQA::DrawModuleName()
403 // Writes the name of the module of the bin where the cursor is
405 TObject *select = gPad->GetSelected();
408 Int_t binx = GetHBin("hMCMcalls");
409 if(0<binx && binx<=fNdets) {
411 strcpy(lab,dynamic_cast<TNamed*>((*fModNames)[binx-1])->GetName());
412 fMPaveLabel->SetLabel(lab);
419 //_______________________________________________________________________
420 void AliMCQA::DrawVolumeName()
423 // Writes the name of the volume:module of the bin where the cursor is
425 TObject *select = gPad->GetSelected();
428 Int_t binx = GetHBin("hMCVcalls");
429 if(0<binx && binx<=fNvolumes) {
431 sprintf(lab,"%s: %s",dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetName(),
432 dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetTitle());
433 fVPaveLabel->SetLabel(lab);