]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDTriggerL1.cxx
- fix for track writing (before accumulated over events)
[u/mrichter/AliRoot.git] / TRD / AliTRDTriggerL1.cxx
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 /* $Id: AliTRDTriggerL1.cxx 31904 2009-04-08 16:42:03Z cblume $ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // TRD trigger L1 (GTU) simulation steering                                  //
21 // currently the Trigger() method calls the GTU tracking simulation and      //
22 // runs two example triggers, namely on a single high pt particle and        //
23 // on a jet.                                                                 //
24 //                                                                           //
25 ///////////////////////////////////////////////////////////////////////////////
26
27
28 #include "TObjArray.h"
29
30 #include "AliLog.h"
31 #include "AliTriggerInput.h"
32 #include "AliRunLoader.h"
33 #include "AliLoader.h"
34
35 #include "AliTRDTriggerL1.h"
36 #include "AliTRDgtuSim.h"
37 #include "AliTRDtrackGTU.h"
38
39 AliTRDTriggerL1::AliTRDTriggerL1()
40 {
41   SetName("TRD");
42 }
43
44 AliTRDTriggerL1::~AliTRDTriggerL1()
45 {
46
47 }
48
49 void AliTRDTriggerL1::CreateInputs()
50 {
51   // create the trigger inputs for TRD
52
53   if (fInputs.GetEntriesFast() > 0)
54     return;
55
56   fInputs.AddLast(new AliTriggerInput("1HSH", "TRD", 1));
57   fInputs.AddLast(new AliTriggerInput("1HJT", "TRD", 1));
58 }
59
60 void AliTRDTriggerL1::Trigger()
61 {
62   // run the trigger algorithms
63
64   AliRunLoader *runLoader = AliRunLoader::Instance();
65   if (!runLoader)
66     return;
67   AliLoader *trdLoader = runLoader->GetLoader("TRDLoader");
68   if (!trdLoader)
69     return;
70   
71   // now running the GTU tracking;
72   AliTRDgtuSim *gtusim = new AliTRDgtuSim();
73   gtusim->RunGTU(trdLoader, 0x0);
74   
75   TTree *trackTree = trdLoader->GetDataLoader("gtutracks")->Tree();
76   if (!trackTree) {
77     AliDebug(1,"Did not find track tree");
78     return;
79   }
80   TBranch *branch = trackTree->GetBranch("TRDtrackGTU");
81   AliDebug(1,Form("TRD trigger: found %lld tracks", trackTree->GetEntriesFast()));
82   
83   // trigger thresholds should go elsewhere
84   Float_t ptThreshold1 = 2;
85   Float_t ptThreshold2 = 9.9;
86   Int_t trackThreshold1 = 6;
87   Int_t trackThreshold2 = 2;
88   
89   // trigger algorithms to come, e.g.
90   Bool_t triggeredHighPt = kFALSE;
91   Bool_t triggeredJet = kFALSE;
92   
93   if (branch) {
94     AliTRDtrackGTU *trk = 0x0;
95     branch->SetAddress(&trk);
96
97     // high pt trigger
98     for (Int_t iTrack = 0; iTrack < trackTree->GetEntriesFast(); iTrack++) {
99       trackTree->GetEntry(iTrack);
100       if (TMath::Abs(trk->GetPt()) > 3.0) {
101         AliDebug(1, Form("Found track in sector %2i, stack %i with pt = %3.1f, triggered", 
102                          trk->GetSector(), trk->GetStack(), trk->GetPt()));
103         triggeredHighPt = kTRUE;
104       }
105     }
106
107     // jet trigger
108     Int_t nTracks1[90]; // tracks above lower pt threshold
109     Int_t nTracks2[90]; // tracks above higher pt threshold
110     memset(nTracks1,0,sizeof(Int_t)*90);
111     memset(nTracks2,0,sizeof(Int_t)*90);
112     for (Int_t iTrack = 0; iTrack < trackTree->GetEntriesFast(); iTrack++) {
113       trackTree->GetEntry(iTrack);
114       if (TMath::Abs(trk->GetPt()) > ptThreshold1)
115         nTracks1[5*trk->GetSector() + trk->GetStack()]++;
116       if (TMath::Abs(trk->GetPt()) > ptThreshold2)
117         nTracks2[5*trk->GetSector() + trk->GetStack()]++;
118     }
119     for (Int_t iStack = 0; iStack < 90; iStack++) {
120       if ((nTracks1[iStack] >= trackThreshold1) || (nTracks2[iStack] >= trackThreshold2))
121         triggeredJet = kTRUE;
122     }
123   }
124   else {
125     AliWarning("GTU Branch not found");
126   }
127
128   if (triggeredHighPt) { 
129     AliInfo("Fired high-pt trigger");
130     SetInput("1HSH");
131   }
132
133   if (triggeredJet) {
134     AliInfo("Fired jet trigger");
135     SetInput("1HJT");
136   }
137
138   // cleaning up
139   delete gtusim;
140 }