Trigger class updated
[u/mrichter/AliRoot.git] / ZDC / AliZDCTrigger.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 #include "AliLog.h"
17 #include "AliRun.h"
18 #include "AliLoader.h"
19 #include "AliRunLoader.h"
20 #include "AliTriggerInput.h"
21
22 #include "AliZDC.h"
23 #include "AliZDCDigit.h"
24 #include "AliZDCTrigger.h"
25
26 //________________________________________________________________
27 ClassImp(AliZDCTrigger)
28
29 //________________________________________________________________
30 AliZDCTrigger::AliZDCTrigger() : AliTriggerDetector() 
31 {
32    SetName("ZDC");
33    CreateInputs();
34    //
35    SetZNMinCut(0);
36    SetZDCLeftMinCut(0);
37    SetZDCRightMinCut(0);
38    SetZEMMinCut(0);
39    SetZDCLeftEMDCuts(0,0);
40    SetZDCRightEMDCuts(0,0);
41    SetZDCLeftMBCut(0);
42    SetZDCRightMBCut(0);
43    SetZDCLeftCentrCut(0);
44    SetZDCRightCentrCut(0);
45    SetZDCLeftSemiCentrCut(0);
46    SetZDCRightSemiCentrCut(0);
47    SetZEMCentrCut(0);
48
49 }
50
51 //________________________________________________________________
52 void AliZDCTrigger::CreateInputs()
53 {
54    // inputs 
55    
56    // Do not create inputs again!!
57    if( fInputs.GetEntriesFast() > 0 ) return;
58    
59    fInputs.AddLast(new AliTriggerInput("ZDC_1_L1",   "ZDC Minimum Bias", 0x01));
60    fInputs.AddLast(new AliTriggerInput("ZDC_2_L1",   "ZDC Central", 0x02));
61    fInputs.AddLast(new AliTriggerInput("ZDC_3_L1",   "ZDC Semi-central", 0x04));
62    fInputs.AddLast(new AliTriggerInput("ZDC_EMD_L1", "ZDC EMD events", 0x08));
63 }
64
65 //________________________________________________________________
66 void AliZDCTrigger::Trigger()
67 {
68
69
70    AliRunLoader *runLoader = gAlice->GetRunLoader();
71
72    AliLoader *ZDCLoader = runLoader->GetLoader("ZDCLoader");
73    ZDCLoader->LoadDigits("READ");
74    AliZDCDigit digit;
75    AliZDCDigit* pdigit = &digit;
76    TTree* TD = ZDCLoader->TreeD();
77    if (!TD) cerr<<"AliZDCTrigger: digits tree not found\n";
78    TD->SetBranchAddress("ZDC", &pdigit);
79    //
80    Float_t ZNLeftSignal[2], ZPLeftSignal[2], ZDCLeftSumSignal[2];
81    Float_t ZNRightSignal[2], ZPRightSignal[2], ZDCRightSumSignal[2];
82    Float_t ZEMSumSignal[2];
83    for(Int_t iDigit=0; iDigit<TD->GetEntries(); iDigit++){
84       TD->GetEntry(iDigit);
85       //
86       // *** ZDC LEFT
87       if(digit.GetSector(0)==1)
88          for(Int_t i=0; i<2; i++){ //0=high range; 1=low range
89             ZNLeftSignal[i] += digit.GetADCValue(i);
90             ZDCLeftSumSignal[i] += digit.GetADCValue(i);
91           }
92       else if(digit.GetSector(0)==2)
93          for(Int_t i=0; i<2; i++){
94             ZPLeftSignal[i] += digit.GetADCValue(i);
95             ZDCLeftSumSignal[i] += digit.GetADCValue(i);
96           }
97       else if(digit.GetSector(0)==3)
98          for(Int_t i=0; i<2; i++) ZEMSumSignal[i] += digit.GetADCValue(i);
99       // *** ZDC RIGHT
100       else if(digit.GetSector(0)==4)
101          for(Int_t i=0; i<2; i++){ //0=high range; 1=low range
102             ZNRightSignal[i] += digit.GetADCValue(i);
103             ZDCRightSumSignal[i] += digit.GetADCValue(i);
104           }
105       else if(digit.GetSector(0)==5)
106          for(Int_t i=0; i<2; i++){
107             ZPRightSignal[i] += digit.GetADCValue(i);
108             ZDCRightSumSignal[i] += digit.GetADCValue(i);
109           }
110    }
111    // *******************************************************************
112    if(ZNLeftSignal[0]>fZDCLeftEMDCuts[0] && ZNLeftSignal[0]<fZDCLeftEMDCuts[1] && 
113       ZNRightSignal[0]>fZDCRightEMDCuts[0] && ZNRightSignal[0]<fZDCRightEMDCuts[1] &&
114       ZEMSumSignal[1]<fZEMMinCut){ // *** 1n EMD trigger
115         SetInput("ZDC_EMD_L1");
116    }
117    // *******************************************************************
118    if(ZDCLeftSumSignal[1]>fZDCLeftMBCut && ZDCRightSumSignal[1]>fZDCRightMBCut) 
119        // *** ZDC minimum bias trigger
120        SetInput("ZDC_1_L1");
121    // *******************************************************************
122    if(ZDCLeftSumSignal[1]>fZDCLeftMinCut && ZDCLeftSumSignal[1]<fZDCLeftCentrCut &&
123       ZDCRightSumSignal[1]>fZDCRightMinCut && ZDCRightSumSignal[1]<fZDCRightCentrCut &&
124       ZEMSumSignal[1]>fZEMCentrCut) 
125        // *** ZDC central (0-10%)
126        SetInput("ZDC_2_L1");
127    // *******************************************************************
128    if(ZDCLeftSumSignal[1]>fZDCLeftCentrCut && ZDCLeftSumSignal[1]<fZDCLeftSemiCentrCut &&
129       ZDCRightSumSignal[1]>fZDCRightCentrCut && ZDCRightSumSignal[1]<fZDCRightSemiCentrCut
130       && ZEMSumSignal[1]>fZEMCentrCut) 
131        // *** ZDC semi-central (10-40%)
132        SetInput("ZDC_3_L1");
133    
134 }
135
136 //________________________________________________________________
137 void AliZDCTrigger::SetZNMinCut(Float_t ZNMinCut) 
138 {
139   if(ZNMinCut)  fZNMinCut = ZNMinCut;
140   else  fZNMinCut = 400.;
141 }
142
143 //________________________________________________________________
144 void AliZDCTrigger::SetZDCLeftMinCut(Float_t ZDCLeftMinCut) 
145 {
146   if(ZDCLeftMinCut)  fZDCLeftMinCut = ZDCLeftMinCut;
147   else  fZDCLeftMinCut = 800.;
148 }
149 //________________________________________________________________
150 void AliZDCTrigger::SetZDCRightMinCut(Float_t ZDCRightMinCut) 
151 {
152   if(ZDCRightMinCut)  fZDCRightMinCut = ZDCRightMinCut;
153   else  fZDCRightMinCut = 800.;
154 }
155
156 //________________________________________________________________
157 void AliZDCTrigger::SetZEMMinCut(Float_t ZEMMinCut) 
158 {
159   if(ZEMMinCut)  fZEMMinCut = ZEMMinCut;
160   else  fZEMMinCut = 80.;
161 }
162 //________________________________________________________________
163 void AliZDCTrigger::SetZDCLeftEMDCuts(Float_t* ZDCLeftEMDCuts) 
164 {
165   if(ZDCLeftEMDCuts) for(int j=0; j<2; j++) fZDCLeftEMDCuts[j] = ZDCLeftEMDCuts[j];
166   else{
167     fZDCLeftEMDCuts[0] = 600.;
168     fZDCLeftEMDCuts[1] = 1000.;
169   }
170 }
171 //________________________________________________________________
172 void AliZDCTrigger::SetZDCLeftEMDCuts(Float_t ZDCLeftEMDCutInf, 
173         Float_t ZDCLeftEMDCutSup) 
174 {
175   if(ZDCLeftEMDCutInf && ZDCLeftEMDCutSup){
176     fZDCLeftEMDCuts[0]=ZDCLeftEMDCutInf; 
177     fZDCLeftEMDCuts[1]=ZDCLeftEMDCutSup;
178   }     
179   else{
180     fZDCLeftEMDCuts[0] = 600.;
181     fZDCLeftEMDCuts[1] = 1000.;
182   }
183 }
184 //________________________________________________________________
185 void AliZDCTrigger::SetZDCRightEMDCuts(Float_t* ZDCRightEMDCuts) 
186 {
187   if(ZDCRightEMDCuts) for(int j=0; j<2; j++) fZDCRightEMDCuts[j] = ZDCRightEMDCuts[j];
188   else{
189     fZDCRightEMDCuts[0] = 600.;
190     fZDCRightEMDCuts[1] = 1000.;
191   }
192 }
193 //________________________________________________________________
194 void AliZDCTrigger::SetZDCRightEMDCuts(Float_t ZDCRightEMDCutInf, 
195         Float_t ZDCRightEMDCutSup) 
196 {
197   if(ZDCRightEMDCutInf && ZDCRightEMDCutSup){
198     fZDCRightEMDCuts[0]=ZDCRightEMDCutInf; 
199     fZDCRightEMDCuts[1]=ZDCRightEMDCutSup;
200   }     
201   else{
202     fZDCRightEMDCuts[0] = 600.;
203     fZDCRightEMDCuts[1] = 1000.;
204   }
205 }
206 //________________________________________________________________
207 void AliZDCTrigger::SetZDCLeftMBCut(Float_t ZDCLeftMBCut) 
208 {
209   if(ZDCLeftMBCut) fZDCLeftMBCut = ZDCLeftMBCut;
210   else fZDCLeftMBCut = 800.;
211 }
212 //________________________________________________________________
213 void AliZDCTrigger::SetZDCRightMBCut(Float_t ZDCRightMBCut) 
214 {
215   if(ZDCRightMBCut) fZDCRightMBCut = ZDCRightMBCut;
216   else fZDCRightMBCut = 800.;
217 }
218 //________________________________________________________________
219 void AliZDCTrigger::SetZDCLeftCentrCut(Float_t ZDCLeftCentrCut) 
220 {
221   if(ZDCLeftCentrCut) fZDCLeftCentrCut = ZDCLeftCentrCut;
222   else fZDCLeftCentrCut = 10000.;
223 }
224 //________________________________________________________________
225 void AliZDCTrigger::SetZDCRightCentrCut(Float_t ZDCRightCentrCut) 
226 {
227   if(ZDCRightCentrCut) fZDCRightCentrCut = ZDCRightCentrCut;
228   else fZDCRightCentrCut = 10000.;
229 }
230 //________________________________________________________________
231 void AliZDCTrigger::SetZDCLeftSemiCentrCut(Float_t ZDCLeftSemiCentrCut) 
232 {
233   if(ZDCLeftSemiCentrCut) fZDCLeftSemiCentrCut = ZDCLeftSemiCentrCut;
234   else fZDCLeftSemiCentrCut = 18500.;
235 }
236 //________________________________________________________________
237 void AliZDCTrigger::SetZDCRightSemiCentrCut(Float_t ZDCRightSemiCentrCut) 
238 {
239   if(ZDCRightSemiCentrCut) fZDCRightSemiCentrCut = ZDCRightSemiCentrCut;
240   else fZDCRightSemiCentrCut = 18500.;
241 }
242 //________________________________________________________________
243 void AliZDCTrigger::SetZEMCentrCut(Float_t ZEMCentrCut) 
244 {
245   if(ZEMCentrCut) fZEMCentrCut = ZEMCentrCut;
246   else fZEMCentrCut = 210.;
247 }