forked from alisw/AliRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAliZDCTowerCalibTask.cxx
208 lines (181 loc) · 6.54 KB
/
AliZDCTowerCalibTask.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
* *
* Author: The ALICE Off-line Project. *
* Contributors are mentioned in the code where appropriate. *
* *
* Permission to use, copy, modify and distribute this software and its *
* documentation strictly for non-commercial purposes is hereby granted *
* without fee, provided that the above copyright notice appears in all *
* copies and that both the copyright notice and this permission notice *
* appear in the supporting documentation. The authors make no claims *
* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
#include "TChain.h"
#include "TTree.h"
#include "TH1F.h"
#include "TCanvas.h"
#include "TDecompLU.h"
#include "AliAnalysisTask.h"
#include "AliAnalysisManager.h"
#include "AliESDEvent.h"
#include "AliESDInputHandler.h"
#include "AliESDZDC.h"
#include "AliZDCTowerCalibTask.h"
#include "AliZDCTowerCalib.h"
#include "AliCDBManager.h"
#include "AliCDBId.h"
#include "AliCDBRunRange.h"
#include "AliCDBStorage.h"
ClassImp(AliZDCTowerCalibTask)
//________________________________________________________________________
AliZDCTowerCalibTask::AliZDCTowerCalibTask()
: AliAnalysisTask(),
fESD(0),
fAZNA(),
fAZNC(),
fBZNA(),
fBZNC(),
fADCMin(0)
{
}
//________________________________________________________________________
AliZDCTowerCalibTask::AliZDCTowerCalibTask(const char *name)
: AliAnalysisTask(name, ""),
fESD(0),
fAZNA(),
fAZNC(),
fBZNA(),
fBZNC(),
fADCMin(0)
{
// Default constructor
// Define input and output slots here
// Input slot #0 works with a TChain
DefineInput(0, TChain::Class());
// // Output slot #0 writes into a TH1 container
// DefineOutput(0, TH1F::Class());
fAZNA.ResizeTo(4,4);
fAZNC.ResizeTo(4,4);
fBZNA.ResizeTo(4);
fBZNC.ResizeTo(4);
fAZNA.Zero();
fAZNC.Zero();
fBZNA.Zero();
fBZNC.Zero();
fADCMin = 0;
}
//________________________________________________________________________
void AliZDCTowerCalibTask::ConnectInputData(Option_t *)
{
// Connect ESD or AOD here
// Called once
TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
if (!tree) Printf("ERROR: Could not read chain from input slot 0");
else {
// Disable all branches and enable only the needed ones
// The next two lines are different when data produced as AliESDEvent is read
/*
tree->SetBranchStatus("*", kFALSE);
tree->SetBranchStatus("fTracks.*", kTRUE);
*/
AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
if (!esdH) Printf("ERROR: Could not get ESDInputHandler");
else fESD = esdH->GetEvent();
}
}
//________________________________________________________________________
void AliZDCTowerCalibTask::CreateOutputObjects(){
// Create histograms
// Called once
}
//________________________________________________________________________
void AliZDCTowerCalibTask::Exec(Option_t *)
{
// Main loop
// Called for each event
if (!fESD) {
Printf("ERROR: fESD not available");
return;
}
AliESDZDC *zdcEvent = fESD->GetESDZDC();
Double_t *ezn1 = 0, *ezn2 = 0;
if(fESD->GetEventType()==7){
ezn1 = (Double_t *) zdcEvent->GetZN1TowerEnergy(); // znc
ezn2 = (Double_t *) zdcEvent->GetZN2TowerEnergy(); // zna
}
Double_t ezn1sum = ezn1[1] + ezn1[2] + ezn1[3] + ezn1[4];
Double_t ezn2sum = ezn2[1] + ezn2[2] + ezn2[3] + ezn2[4];
// select event
Bool_t isZNAAccepted = kTRUE;
if (ezn2[0] < fADCMin || ezn2sum < fADCMin) isZNAAccepted = kFALSE;
Bool_t isZNCAccepted = kTRUE;
if (ezn1[0] < fADCMin || ezn1sum < fADCMin) isZNCAccepted = kFALSE;
// calculate coefficient matrix and known terms
for (Int_t i=0; i<4; i++) {
for (Int_t j=0; j<4; j++) {
if (isZNAAccepted) fAZNA[i][j] += ezn2[ i + 1 ] * ezn2[ j + 1 ] / ezn2[0];
if (isZNCAccepted) fAZNC[i][j] += ezn1[ i + 1 ] * ezn1[ j + 1 ] / ezn1[0];
}
if (isZNAAccepted) fBZNA[i] += ezn2[ i + 1 ];
if (isZNCAccepted) fBZNC[i] += ezn1[ i + 1 ];
}
// Post output data.
// PostData(0, fHistPt);
}
//________________________________________________________________________
void AliZDCTowerCalibTask::Terminate(Option_t *)
{
// solve the system of linear equations giving the calibration coefficients
// for zna and znc
TDecompLU luZNA(fAZNA);
Bool_t isZNAOk;
TVectorD coeffZNA = luZNA.Solve(fBZNA,isZNAOk);
if (isZNAOk) {
printf ("ZNA: coefficient matrix:\n");
fAZNA.Print();
printf ("ZNA: known terms:\n");
fBZNA.Print();
printf ("ZNA: Fitted calibration coefficients:\n");
coeffZNA.Print();
}
else {
printf ("Singular coefficient matrix for ZNA! Setting all coefficients to 1\n");
for (Int_t i=0; i<4; i++) coeffZNA[i] = 1;
}
TDecompLU luZNC(fAZNC);
Bool_t isZNCOk;
TVectorD coeffZNC = luZNC.Solve(fBZNC,isZNCOk);
if (isZNCOk) {
printf ("ZNC: coefficient matrix:\n");
fAZNC.Print();
printf ("ZNC: known terms:\n");
fBZNC.Print();
printf ("ZNC: Fitted calibration coefficients:\n");
coeffZNC.Print();
}
else {
printf ("Singular coefficient matrix for ZNC! Setting all coefficients to 1\n");
for (Int_t i=0; i<4; i++) coeffZNC[i] = 1;
}
// write to OCDB
AliZDCTowerCalib *towerCalib = new AliZDCTowerCalib();
towerCalib->SetZN1EqualCoeff(0, 1.);
towerCalib->SetZN2EqualCoeff(0, 1.);
for(Int_t j=1; j<5; j++){
towerCalib->SetZN1EqualCoeff(j, coeffZNC[j+1]);
towerCalib->SetZN2EqualCoeff(j, coeffZNA[j+1]);
}
towerCalib->Print("");
AliCDBManager *manager = AliCDBManager::Instance();
manager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
AliCDBMetaData *md = new AliCDBMetaData();
md->SetResponsible("Chiara Oppedisano");
md->SetComment("Calibration object for ZDC written by a macro");
md->SetObjectClassName("AliZDCTowerCalib");
md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
md->SetBeamPeriod(0);
AliCDBId id("ZDC/Calib/TowerCalib",fESD->GetRunNumber(),AliCDBRunRange::Infinity());
manager->GetDefaultStorage()->Put(towerCalib,id, md);
}