Trigger class for ZDC
[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    SetZDCMinCut(0);
37    SetZEMMinCut(0);
38    SetZDCLeftEMDCuts(0,0);
39    SetZDCRightEMDCuts(0,0);
40    SetZDCMBCut(0);
41    SetZDCCentrCut(0);
42    SetZDCSemiCentrCut(0);
43    SetZEMCentrCut(0);
44
45 }
46
47 //________________________________________________________________
48 void AliZDCTrigger::CreateInputs()
49 {
50    // inputs 
51    
52    // Do not create inputs again!!
53    if( fInputs.GetEntriesFast() > 0 ) return;
54    
55    fInputs.AddLast(new AliTriggerInput("ZDC_1_L1",   "ZDC Minimum Bias", 0x01));
56    fInputs.AddLast(new AliTriggerInput("ZDC_2_L1",   "ZDC Central", 0x02));
57    fInputs.AddLast(new AliTriggerInput("ZDC_3_L1",   "ZDC Semi-central", 0x04));
58    fInputs.AddLast(new AliTriggerInput("ZDC_EMD_L1", "ZDC EMD events", 0x08));
59 }
60
61 //________________________________________________________________
62 void AliZDCTrigger::Trigger()
63 {
64
65
66    AliRunLoader *runLoader = gAlice->GetRunLoader();
67
68    AliLoader *ZDCLoader = runLoader->GetLoader("ZDCLoader");
69    ZDCLoader->LoadDigits("READ");
70    AliZDCDigit digit;
71    AliZDCDigit* pdigit = &digit;
72    TTree* TD = ZDCLoader->TreeD();
73    if (!TD) cerr<<"AliZDCTrigger: digits tree not found\n";
74    TD->SetBranchAddress("ZDC", &pdigit);
75    //
76    Float_t ZNSignal[2], ZPSignal[2], ZDCSumSignal[2], ZEMSumSignal[2];
77    for(Int_t iDigit=0; iDigit<TD->GetEntries(); iDigit++){
78       TD->GetEntry(iDigit);
79       //
80       if(digit.GetSector(0)==1)
81          for(Int_t i=0; i<2; i++){
82             ZNSignal[i] += digit.GetADCValue(i);
83             ZDCSumSignal[i] += digit.GetADCValue(i);
84           }
85       else if(digit.GetSector(0)==2)
86          for(Int_t i=0; i<2; i++){
87             ZPSignal[i] += digit.GetADCValue(i);
88             ZDCSumSignal[i] += digit.GetADCValue(i);
89           }
90       else if(digit.GetSector(0)==3)
91          for(Int_t i=0; i<2; i++) ZEMSumSignal[i] += digit.GetADCValue(i);
92    }
93    // *******************************************************************
94    if(ZNSignal[1]>fZDCLeftEMDCuts[0] && ZNSignal[1]<fZDCLeftEMDCuts[1] && 
95         ZEMSumSignal[1]<fZEMMinCut){ // *** n EMD event
96        SetInput("ZDC_EMD_L1");
97    }
98    // *******************************************************************
99    if(ZDCSumSignal[0]>fZDCMBCut) // *** ZDC minimum bias
100      SetInput("ZDC_1_L1");
101    // *******************************************************************
102    if(ZDCSumSignal[0]>fZDCMinCut && ZDCSumSignal[0]<fZDCMBCut) 
103      // *** ZDC central (0-10%)
104      SetInput("ZDC_2_L1");
105    // *******************************************************************
106    if(ZDCSumSignal[0]>fZDCCentrCut && ZDCSumSignal[0]<fZDCSemiCentrCut
107            && ZEMSumSignal[0]>fZEMCentrCut) 
108      // *** ZDC semi-central (10-40%)
109      SetInput("ZDC_3_L1");
110    
111 }
112
113 //________________________________________________________________
114 void AliZDCTrigger::SetZNMinCut(Float_t ZNMinCut) 
115 {
116   if(ZNMinCut)  fZNMinCut = ZNMinCut;
117   else  fZNMinCut = 400.;
118 }
119
120 //________________________________________________________________
121 void AliZDCTrigger::SetZDCMinCut(Float_t ZDCMinCut) 
122 {
123   if(ZDCMinCut)  fZDCMinCut = ZDCMinCut;
124   else  fZDCMinCut = 800.;
125 }
126
127 //________________________________________________________________
128 void AliZDCTrigger::SetZEMMinCut(Float_t ZEMMinCut) 
129 {
130   if(ZEMMinCut)  fZEMMinCut = ZEMMinCut;
131   else  fZEMMinCut = 80.;
132 }
133 //________________________________________________________________
134 void AliZDCTrigger::SetZDCLeftEMDCuts(Float_t* ZDCLeftEMDCuts) 
135 {
136   if(ZDCLeftEMDCuts) for(int j=0; j<2; j++) fZDCLeftEMDCuts[j] = ZDCLeftEMDCuts[j];
137   else{
138     fZDCLeftEMDCuts[0] = 600.;
139     fZDCLeftEMDCuts[1] = 1000.;
140   }
141 }
142 //________________________________________________________________
143 void AliZDCTrigger::SetZDCLeftEMDCuts(Float_t ZDCLeftEMDCutInf, 
144         Float_t ZDCLeftEMDCutSup) 
145 {
146   if(ZDCLeftEMDCutInf && ZDCLeftEMDCutSup){
147     fZDCLeftEMDCuts[0]=ZDCLeftEMDCutInf; 
148     fZDCLeftEMDCuts[1]=ZDCLeftEMDCutSup;
149   }     
150   else{
151     fZDCLeftEMDCuts[0] = 600.;
152     fZDCLeftEMDCuts[1] = 1000.;
153   }
154 }
155 //________________________________________________________________
156 void AliZDCTrigger::SetZDCRightEMDCuts(Float_t* ZDCRightEMDCuts) 
157 {
158   if(ZDCRightEMDCuts) for(int j=0; j<2; j++) fZDCRightEMDCuts[j] = ZDCRightEMDCuts[j];
159   else{
160     fZDCRightEMDCuts[0] = 600.;
161     fZDCRightEMDCuts[1] = 1000.;
162   }
163 }
164 //________________________________________________________________
165 void AliZDCTrigger::SetZDCRightEMDCuts(Float_t ZDCRightEMDCutInf, 
166         Float_t ZDCRightEMDCutSup) 
167 {
168   if(ZDCRightEMDCutInf && ZDCRightEMDCutSup){
169     fZDCRightEMDCuts[0]=ZDCRightEMDCutInf; 
170     fZDCRightEMDCuts[1]=ZDCRightEMDCutSup;
171   }     
172   else{
173     fZDCRightEMDCuts[0] = 600.;
174     fZDCRightEMDCuts[1] = 1000.;
175   }
176 }
177 //________________________________________________________________
178 void AliZDCTrigger::SetZDCMBCut(Float_t ZDCMBCut) 
179 {
180   if(ZDCMBCut) fZDCMBCut = ZDCMBCut;
181   else fZDCMBCut = 800.;
182 }
183 //________________________________________________________________
184 void AliZDCTrigger::SetZDCCentrCut(Float_t ZDCCentrCut) 
185 {
186   if(ZDCCentrCut) fZDCCentrCut = ZDCCentrCut;
187   else fZDCCentrCut = 10000.;
188 }
189 //________________________________________________________________
190 void AliZDCTrigger::SetZDCSemiCentrCut(Float_t ZDCSemiCentrCut) 
191 {
192   if(ZDCSemiCentrCut) fZDCSemiCentrCut = ZDCSemiCentrCut;
193   else fZDCSemiCentrCut = 18500.;
194 }
195 //________________________________________________________________
196 void AliZDCTrigger::SetZEMCentrCut(Float_t ZEMCentrCut) 
197 {
198   if(ZEMCentrCut) fZEMCentrCut = ZEMCentrCut;
199   else fZEMCentrCut = 210.;
200 }