o automatic detection of 11a pass4 (Alla)
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliT0TenderSupply.cxx
CommitLineData
e8eb8c54 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///////////////////////////////////////////////////////////////////////////
17// //
18// T0 Tender supply //
19// //
20// //
21///////////////////////////////////////////////////////////////////////////
22
23#include <AliESDEvent.h>
24#include <AliESDtrack.h>
25
26#include <AliTender.h>
27#include <AliT0TenderSupply.h>
1f671b29 28#include <AliCDBManager.h>
29#include <AliCDBEntry.h>
30#include <AliT0CalibSeasonTimeShift.h>
3ce1dc33 31#include <AliESDInputHandler.h>
e8eb8c54 32
33ClassImp(AliT0TenderSupply)
34
35//________________________________________________________________________
36AliT0TenderSupply::AliT0TenderSupply():
37 AliTenderSupply(),
38 fCorrectMeanTime(kFALSE),
39 fCorrectStartTimeOnAmplSatur(kFALSE),
1f671b29 40 fAmplitudeThreshold(100),
41 fPass4LHC11aCorrection(kFALSE)
e8eb8c54 42{
43 //
44 // default constructor
45 //
1f671b29 46 for(int i=0; i<4; i++) fTimeOffset[i]=0;
e8eb8c54 47}
48
49//________________________________________________________________________
50AliT0TenderSupply::AliT0TenderSupply(const char *name, const AliTender *tender):
51 AliTenderSupply(name,tender),
52 fCorrectMeanTime(kFALSE),
53 fCorrectStartTimeOnAmplSatur(kFALSE),
1f671b29 54 fAmplitudeThreshold(100),
55 fPass4LHC11aCorrection(kFALSE)
e8eb8c54 56{
57 //
58 // constructor
59 //
60 for(int i=0; i<3; i++) fTimeOffset[i]=0;
61}
62
63//________________________________________________________________________
64AliT0TenderSupply::~AliT0TenderSupply(){
65 //
66 // destructor
67 //
68
69}
70
71//________________________________________________________________________
72void AliT0TenderSupply::Init(){
e8eb8c54 73 // Init
74 //
75 Int_t run = fTender->GetRun();
3ce1dc33 76 if (run == 0) return; // to skip first init, when we don't have yet a run number
77 fPass4LHC11aCorrection=kFALSE;
78
e8eb8c54 79
80 fCorrectMeanTime = kFALSE; //reset
1f671b29 81 for(int i=0; i<4; i++) fTimeOffset[i]=0;
82
83
84 fCorrectStartTimeOnAmplSatur = kFALSE;
85 fAmplitudeThreshold = 100; //in mips
86
87 if(167693<= run && run<=170593){ // LHC11h
88 fCorrectStartTimeOnAmplSatur = kTRUE;
89 fAmplitudeThreshold = 50; //in mips
90 }
e8eb8c54 91
e8eb8c54 92}
93
94//________________________________________________________________________
95void AliT0TenderSupply::ProcessEvent(){
96 //
97 // loop over all online T0 candidates and flag
98 // selected daughter tracks using the status bis of the TObject
99 //
100
101 AliESDEvent *event=fTender->GetEvent();
102 if (!event) return;
103
104 //Do something when the run number changed, like loading OCDB entries etc.
3ce1dc33 105 fPass4LHC11aCorrection=kFALSE;
e8eb8c54 106 if(fTender->RunChanged()){
3ce1dc33 107 Init();
108 if (fTender->GetRun()>=139699&& fTender->GetRun()<=146860){
109 AliESDInputHandler *esdIH = dynamic_cast<AliESDInputHandler*> (fTender->GetESDhandler());
110 if (esdIH) {
111 TTree *tree= (TTree*)esdIH->GetTree();
112 TFile *file= (TFile*)tree->GetCurrentFile();
113 if (file){
114 TString fileName(file->GetName());
115 if (fileName.Contains("pass4") ) fPass4LHC11aCorrection=kTRUE;
116 }
117 }
118 }
e8eb8c54 119 }
120
1f671b29 121 if(fPass4LHC11aCorrection) {
122 const Double32_t* mean = event->GetT0TOF();
123 event->SetT0TOF(0, (mean[1]+mean[2])/2.);
e8eb8c54 124
1f671b29 125 }
e8eb8c54 126 if(fCorrectStartTimeOnAmplSatur){
127 //correct A side ORA on amplitude saturation
128 const Double32_t* time = event->GetT0time();
129 const Double32_t* amplitude = event->GetT0amplitude();
130
131 Int_t idxOfFirstPmtA = -1;
132 Double32_t timeOrA = 99999;
133 for(int ipmt=12; ipmt<24; ipmt++){ //loop over A side
134 if( amplitude[ipmt] < fAmplitudeThreshold){
135 if( time[ipmt] > -200 && time[ipmt]!=0 && time[ipmt] < timeOrA ){
136 timeOrA = time[ipmt];
137 idxOfFirstPmtA = ipmt;
138 }
139 }
140 }
141
142 if(idxOfFirstPmtA>-1){ //a hit in aside with less than 40 mips
143 const Double32_t* mean = event->GetT0TOF();
144 Double32_t timeOrC = mean[2];
145 Double32_t timeOrAplusOrC = (timeOrA+timeOrC)/2;
146
147 event->SetT0TOF(0, timeOrAplusOrC);
148 event->SetT0TOF(1, timeOrA);
149 }
150 }
151
152 //...........................................
1f671b29 153 Float_t *t0means=0x0;
154 if(fCorrectMeanTime){
155 AliCDBManager* ocdbMan = AliCDBManager::Instance();
156 ocdbMan->SetRun(fTender->GetRun());
157 AliCDBEntry *entry = ocdbMan->Get("T0/Calib/TimeAdjust/");
158 if(entry) {
159 AliT0CalibSeasonTimeShift *clb = (AliT0CalibSeasonTimeShift*) entry->GetObject();
160 t0means= clb->GetT0Means();
161 } else {
162 for (Int_t i=0;i<4;i++) t0means[i]=0;
163 AliWarning("T0Tender no T0 entry found T0shift set to 0");
164 }
165 } else {
166 for (Int_t i=0;i<4;i++) t0means=0;
e8eb8c54 167 }
1f671b29 168 // correct mean time offsets
169 const Double32_t* mean = event->GetT0TOF();
170 for(int it0=0; it0<3; it0++){
171 if(-2000 < mean[it0]){
172 event->SetT0TOF(it0, mean[it0] - t0means[it0]);
173 }
174 }
175}
176
e8eb8c54 177