]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/macros/testGeomTrigger.C
Fixes for coverity
[u/mrichter/AliRoot.git] / HLT / trigger / macros / testGeomTrigger.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include "Riostream.h"
3 #include "TFile.h"
4 #include "TSystem.h"
5 #include "TRandom3.h"
6 #include "TMath.h"
7 #include "TParticle.h"
8 #include "AliESDEvent.h"
9 #include "AliESDMuonTrack.h"
10 #include "AliHLTSystem.h"
11 #include "AliHLTConfiguration.h"
12 #include "AliHLTTriggerDecision.h"
13
14 #endif
15
16 void CreateTrack(AliESDMuonTrack& track, Double_t minPt, Double_t maxPt, Double_t charge)
17 {
18   Double_t pz = -100;
19   Double_t pt = gRandom->Rndm() * (maxPt - minPt) + minPt;
20   Double_t angle = gRandom->Rndm() * 2 * TMath::Pi();
21   Double_t px = pt * TMath::Cos(angle);
22   Double_t py = pt * TMath::Sin(angle);
23   track.SetThetaX(TMath::ATan2(px, pz));
24   track.SetThetaY(TMath::ATan2(py, pz));
25   Double_t invP = 1. / TMath::Sqrt(py*py + pz*pz) * charge;
26   track.SetInverseBendingMomentum(invP);
27 }
28
29 TParticle CreateParticle(Double_t minPt, Double_t maxPt)
30 {
31   Double_t mass = 0.1056583699; // [GeV/c] muon mass.
32   Double_t pz = 0;
33   Double_t pt = gRandom->Rndm() * (maxPt - minPt) + minPt;
34   Double_t angle = gRandom->Rndm() * 2 * TMath::Pi();
35   //  Double_t angle = 270*TMath::DegToRad();
36   Double_t px = pt * TMath::Cos(angle);
37   Double_t py = pt * TMath::Sin(angle);
38   Double_t etot = TMath::Sqrt(pt*pt + pz*pz + mass*mass);
39   return TParticle(13, 0, 0, 0, 0, 0, px, py, pz, etot, 0, 0, 0, 0);
40 }
41
42 void CreateInput(
43     const char* filename,
44     Int_t numOfBarrelTracks, Double_t minBarrelPt, Double_t maxBarrelPt,
45     Int_t numOfMuonTracks, Double_t minMuonPt, Double_t maxMuonPt
46   )
47 {
48   TFile* file = new TFile(filename, "RECREATE");
49   AliESDEvent event;
50   event.CreateStdContent();
51   for (int i = 0; i < numOfBarrelTracks; i++)
52   {
53     TParticle p = CreateParticle(minBarrelPt, maxBarrelPt);
54     AliESDtrack track(&p);
55     event.AddTrack(&track);
56   }
57   for (int i = 0; i < numOfMuonTracks; i++)
58   {
59     AliESDMuonTrack mutrack;
60     CreateTrack(mutrack, minMuonPt, maxMuonPt, (i%2==0) ? -1 : 1);
61     event.AddMuonTrack(&mutrack);
62   }
63   event.Write();
64   delete file;
65 }
66
67 bool CheckIfOutputIsOk()
68 {
69   const char* filename = "FullTriggerTestOutput.root";
70   TFile file(filename, "READ");
71   int expectedResult[4] = {0, 1, 0, 1};
72   AliHLTTriggerDecision* decision[4];
73   for (int i = 0; i < 4; i++)
74   {
75     char name[1024];
76     sprintf(name, "HLTGlobalTrigger;%d", i+1);
77     decision[i] = dynamic_cast<AliHLTTriggerDecision*>(file.Get(name));
78     if (decision[i] == NULL)
79     {
80       cerr << "ERROR: '" << name << "' AliHLTTriggerDecision object not found in file " << filename << endl;
81       return false;
82     }
83     cout << "===============================================================================" << endl;
84     cout << "============================== Global Decision " << i+1 << " ==============================" << endl;
85     cout << "===============================================================================" << endl;
86     decision[i]->Print();
87     if (decision[i]->Result() != expectedResult[i])
88     {
89       cout << "FAILED result check. Expected a result of " << expectedResult[i]
90            << " for trigger decision " << i+1
91            << " but received: " << decision[i]->Result()
92            << endl;
93       return false;
94     }
95   }
96   return true;
97 }
98
99 bool testGeomTrigger()
100 {
101   gRandom->SetSeed(123);
102   gSystem->Load("libAliHLTTrigger.so");
103   CreateInput("FullTriggerTestInput1.root", 5, 0.1, 1.9, 0, 0.1, 0.9);
104   CreateInput("FullTriggerTestInput2.root", 3, 2.1, 4.0, 0, 0.1, 0.9);
105   CreateInput("FullTriggerTestInput3.root", 6, 0.1, 1.9, 0, 1.1, 2.0);
106   CreateInput("FullTriggerTestInput4.root", 2, 2.1, 4.0, 0, 1.1, 2.0);
107   AliHLTSystem sys;
108   sys.LoadComponentLibraries("libAliHLTUtil.so");
109   sys.LoadComponentLibraries("libAliHLTTrigger.so");
110   const char* cmdline = " -datatype ROOTTOBJ 'HLT ' -datafile FullTriggerTestInput1.root"
111     " -nextevent -datafile FullTriggerTestInput2.root"
112     " -nextevent -datafile FullTriggerTestInput3.root"
113     " -nextevent -datafile FullTriggerTestInput4.root";
114   AliHLTConfiguration pub("pub", "ROOTFilePublisher", NULL, cmdline);
115   AliHLTConfiguration trg1("trg1", "BarrelGeomMultiplicityTrigger", "pub", "-triggername PHOSgeomtrigger -geomfile PHOSgeomtrigger.root");
116   AliHLTConfiguration glob("global", "HLTGlobalTrigger", "trg1", "-config testGeomTriggerConfig.C");
117   AliHLTConfiguration sink("sink", "ROOTFileWriter", "global", "-datafile FullTriggerTestOutput.root -concatenate-events");
118   sys.BuildTaskList("sink");
119   sys.Run(4);
120   return CheckIfOutputIsOk();
121 }