]>
Commit | Line | Data |
---|---|---|
4c039060 | 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 | ||
88cb7938 | 16 | /* $Id$ */ |
4c039060 | 17 | |
fe4da5cc | 18 | /////////////////////////////////////////////////////////////////////////////// |
19 | // // | |
359cdddc | 20 | // Zero Degree Calorimeter // |
21 | // This class contains the basic functions for the ZDCs; // | |
22 | // functions specific to one particular geometry are // | |
23 | // contained in the derived classes // | |
fe4da5cc | 24 | // // |
fe4da5cc | 25 | /////////////////////////////////////////////////////////////////////////////// |
26 | ||
f901045b | 27 | // --- ROOT system |
fe4da5cc | 28 | #include <TBRIK.h> |
7ca4655f | 29 | #include <TClonesArray.h> |
88cb7938 | 30 | #include <TGeometry.h> |
31 | #include <TNode.h> | |
32 | #include <TTree.h> | |
232b622f | 33 | #include <TFile.h> |
8af17dba | 34 | #include <TSystem.h> |
90001c80 | 35 | #include <TRandom.h> |
fe4da5cc | 36 | |
f901045b | 37 | // --- AliRoot header files |
88cb7938 | 38 | #include "AliDetector.h" |
90001c80 | 39 | #include "AliRawDataHeader.h" |
40 | #include "AliRawReader.h" | |
41 | #include "AliLoader.h" | |
42 | #include "AliRun.h" | |
43 | #include "AliMC.h" | |
44 | #include "AliLog.h" | |
45 | #include "AliDAQ.h" | |
fe4da5cc | 46 | #include "AliZDC.h" |
f901045b | 47 | #include "AliZDCHit.h" |
6de91202 | 48 | #include "AliZDCSDigit.h" |
49 | #include "AliZDCDigit.h" | |
50 | #include "AliZDCDigitizer.h" | |
51 | #include "AliZDCRawStream.h" | |
8af17dba | 52 | #include "AliZDCCalibData.h" |
08f92f14 | 53 | #include "AliFstream.h" |
88cb7938 | 54 | |
fe4da5cc | 55 | |
56 | ClassImp(AliZDC) | |
8af17dba | 57 | |
fe4da5cc | 58 | //_____________________________________________________________________________ |
cc2abffd | 59 | AliZDC::AliZDC() : |
60 | AliDetector(), | |
61 | fNoShower (0), | |
62 | fCalibData (0) | |
63 | ||
fe4da5cc | 64 | { |
65 | // | |
66 | // Default constructor for the Zero Degree Calorimeter base class | |
67 | // | |
2e6fc82a | 68 | |
cc2abffd | 69 | fIshunt = 1; |
70 | fNhits = 0; | |
71 | fHits = 0; | |
72 | fDigits = 0; | |
73 | fNdigits = 0; | |
d16dd065 | 74 | |
fe4da5cc | 75 | } |
76 | ||
77 | //_____________________________________________________________________________ | |
cc2abffd | 78 | AliZDC::AliZDC(const char *name, const char *title) : |
79 | AliDetector(name,title), | |
80 | fNoShower (0), | |
81 | fCalibData (0) | |
82 | ||
fe4da5cc | 83 | { |
84 | // | |
85 | // Standard constructor for the Zero Degree Calorimeter base class | |
86 | // | |
cc2abffd | 87 | |
88 | fIshunt = 1; | |
89 | fNhits = 0; | |
90 | fDigits = 0; | |
91 | fNdigits = 0; | |
92 | ||
93 | fHits = new TClonesArray("AliZDCHit",1000); | |
5d12ce38 | 94 | gAlice->GetMCApp()->AddHitList(fHits); |
8af17dba | 95 | |
96 | char sensname[5],senstitle[25]; | |
97 | sprintf(sensname,"ZDC"); | |
98 | sprintf(senstitle,"ZDC dummy"); | |
99 | SetName(sensname); SetTitle(senstitle); | |
f901045b | 100 | |
866ab5a2 | 101 | } |
cc2abffd | 102 | |
866ab5a2 | 103 | //____________________________________________________________________________ |
104 | AliZDC::~AliZDC() | |
105 | { | |
106 | // | |
107 | // ZDC destructor | |
108 | // | |
109 | ||
cc2abffd | 110 | fIshunt = 0; |
d16dd065 | 111 | delete fCalibData; |
112 | ||
fe4da5cc | 113 | } |
cc2abffd | 114 | |
115 | //_____________________________________________________________________________ | |
116 | AliZDC::AliZDC(const AliZDC& ZDC) : | |
117 | AliDetector("ZDC","ZDC") | |
118 | { | |
119 | // copy constructor | |
120 | fNoShower = ZDC.fNoShower; | |
121 | fCalibData = ZDC.fCalibData; | |
122 | fZDCCalibFName = ZDC.fZDCCalibFName; | |
123 | } | |
124 | ||
125 | //_____________________________________________________________________________ | |
126 | AliZDC& AliZDC::operator=(const AliZDC& ZDC) | |
127 | { | |
128 | // assignement operator | |
129 | if(this!=&ZDC){ | |
130 | fNoShower = ZDC.fNoShower; | |
131 | fCalibData = ZDC.fCalibData; | |
132 | fZDCCalibFName = ZDC.fZDCCalibFName; | |
133 | } return *this; | |
134 | } | |
135 | ||
fe4da5cc | 136 | //_____________________________________________________________________________ |
137 | void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits) | |
138 | { | |
139 | // | |
f901045b | 140 | // Add a ZDC hit to the hit list. |
141 | // -> We make use of 2 array of hits: | |
142 | // [1] fHits (the usual one) that contains hits for each PRIMARY | |
143 | // [2] fStHits that contains hits for each EVENT and is used to | |
144 | // obtain digits at the end of each event | |
fe4da5cc | 145 | // |
f901045b | 146 | |
68ca986e | 147 | static Float_t primKinEn, xImpact, yImpact, sFlag; |
148 | ||
43f34e8b | 149 | AliZDCHit *newquad, *curprimquad; |
f901045b | 150 | newquad = new AliZDCHit(fIshunt, track, vol, hits); |
65d4f2be | 151 | TClonesArray &lhits = *fHits; |
cefa66cb | 152 | |
153 | if(fNhits==0){ | |
154 | // First hit -> setting flag for primary or secondary particle | |
5d12ce38 | 155 | Int_t primary = gAlice->GetMCApp()->GetPrimary(track); |
cefa66cb | 156 | if(track != primary){ |
3ff116f2 | 157 | newquad->SetSFlag(1); // SECONDARY particle entering the ZDC |
cefa66cb | 158 | } |
159 | else if(track == primary){ | |
3ff116f2 | 160 | newquad->SetSFlag(0); // PRIMARY particle entering the ZDC |
cefa66cb | 161 | } |
3ff116f2 | 162 | sFlag = newquad->GetSFlag(); |
163 | primKinEn = newquad->GetPrimKinEn(); | |
164 | xImpact = newquad->GetXImpact(); | |
165 | yImpact = newquad->GetYImpact(); | |
cefa66cb | 166 | } |
167 | else{ | |
3ff116f2 | 168 | newquad->SetPrimKinEn(primKinEn); |
169 | newquad->SetXImpact(xImpact); | |
170 | newquad->SetYImpact(yImpact); | |
171 | newquad->SetSFlag(sFlag); | |
cefa66cb | 172 | } |
173 | ||
43f34e8b | 174 | Int_t j; |
f901045b | 175 | for(j=0; j<fNhits; j++){ |
2e6fc82a | 176 | // If hits are equal (same track, same volume), sum them. |
f901045b | 177 | curprimquad = (AliZDCHit*) lhits[j]; |
178 | if(*curprimquad == *newquad){ | |
179 | *curprimquad = *curprimquad+*newquad; | |
cc2abffd | 180 | // CH. debug |
181 | /*if(newquad->GetEnergy() != 0. || newquad->GetLightPMC() != 0. || | |
182 | newquad->GetLightPMQ() != 0.){ | |
183 | printf("\n\t --- Equal hits found\n"); | |
184 | curprimquad->Print(""); | |
185 | newquad->Print(""); | |
186 | printf("\t --- Det. %d, Quad. %d: X = %f, E = %f, LightPMC = %f, LightPMQ = %f\n", | |
187 | curprimquad->GetVolume(0),curprimquad->GetVolume(1),curprimquad->GetXImpact(), | |
188 | curprimquad->GetEnergy(), curprimquad->GetLightPMC(), curprimquad->GetLightPMQ()); | |
189 | }*/ | |
190 | // | |
f901045b | 191 | delete newquad; |
68ca986e | 192 | return; |
f901045b | 193 | } |
194 | } | |
f901045b | 195 | |
196 | //Otherwise create a new hit | |
cc2abffd | 197 | new(lhits[fNhits]) AliZDCHit(*newquad); |
f901045b | 198 | fNhits++; |
cc2abffd | 199 | // CH. debug |
200 | /*printf("\n\t New ZDC hit added! fNhits = %d\n", fNhits); | |
201 | printf("\t Det. %d, Quad.t %d: X = %f, E = %f, LightPMC = %f, LightPMQ = %f\n", | |
202 | newquad->GetVolume(0),newquad->GetVolume(1),newquad->GetXImpact(), | |
203 | newquad->GetEnergy(), newquad->GetLightPMC(), newquad->GetLightPMQ()); | |
204 | */ | |
866ab5a2 | 205 | delete newquad; |
cefa66cb | 206 | } |
207 | ||
fe4da5cc | 208 | //_____________________________________________________________________________ |
209 | void AliZDC::BuildGeometry() | |
210 | { | |
211 | // | |
212 | // Build the ROOT TNode geometry for event display | |
213 | // in the Zero Degree Calorimeter | |
214 | // This routine is dummy for the moment | |
215 | // | |
216 | ||
68ca986e | 217 | TNode *node, *top; |
218 | TBRIK *brik; | |
359cdddc | 219 | const int kColorZDC = kBlue; |
fe4da5cc | 220 | |
221 | // | |
68ca986e | 222 | top=gAlice->GetGeometry()->GetNode("alice"); |
fe4da5cc | 223 | |
224 | // ZDC | |
fe4da5cc | 225 | brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5); |
68ca986e | 226 | top->cd(); |
227 | node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,""); | |
228 | node->SetLineColor(kColorZDC); | |
229 | fNodes->Add(node); | |
fe4da5cc | 230 | } |
231 | ||
359cdddc | 232 | //____________________________________________________________________________ |
233 | Float_t AliZDC::ZMin(void) const | |
234 | { | |
235 | // Minimum dimension of the ZDC module in z | |
6de91202 | 236 | return -11600.; |
359cdddc | 237 | } |
238 | ||
239 | //____________________________________________________________________________ | |
240 | Float_t AliZDC::ZMax(void) const | |
241 | { | |
242 | // Maximum dimension of the ZDC module in z | |
6de91202 | 243 | return -11750.; |
359cdddc | 244 | } |
245 | ||
246 | ||
fe4da5cc | 247 | //_____________________________________________________________________________ |
5bc762ca | 248 | void AliZDC::MakeBranch(Option_t *opt) |
fe4da5cc | 249 | { |
250 | // | |
359cdddc | 251 | // Create Tree branches for the ZDC |
fe4da5cc | 252 | // |
359cdddc | 253 | |
254 | char branchname[10]; | |
255 | sprintf(branchname,"%s",GetName()); | |
88cb7938 | 256 | |
257 | const char *cH = strstr(opt,"H"); | |
258 | ||
90001c80 | 259 | if(cH && fLoader->TreeH()) |
88cb7938 | 260 | fHits = new TClonesArray("AliZDCHit",1000); |
359cdddc | 261 | |
262 | AliDetector::MakeBranch(opt); | |
1450a7cd | 263 | } |
1450a7cd | 264 | |
b6d27557 | 265 | //_____________________________________________________________________________ |
266 | void AliZDC::Hits2SDigits() | |
267 | { | |
6de91202 | 268 | // Create summable digits from hits |
269 | ||
99a553ce | 270 | AliDebug(1,"\n Entering AliZDC::Hits2Digits() "); |
b6d27557 | 271 | |
85a5290f | 272 | fLoader->LoadHits("read"); |
273 | fLoader->LoadSDigits("recreate"); | |
6de91202 | 274 | AliRunLoader* runLoader = fLoader->GetRunLoader(); |
275 | AliZDCSDigit sdigit; | |
276 | AliZDCSDigit* psdigit = &sdigit; | |
85a5290f | 277 | |
6de91202 | 278 | // Event loop |
90001c80 | 279 | for(Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) { |
6de91202 | 280 | Float_t pmCZN = 0, pmCZP = 0, pmQZN[4], pmQZP[4], pmZEM1 = 0, pmZEM2 = 0; |
90001c80 | 281 | for(Int_t i = 0; i < 4; i++) pmQZN[i] = pmQZP[i] = 0; |
85a5290f | 282 | |
6de91202 | 283 | runLoader->GetEvent(iEvent); |
284 | TTree* treeH = fLoader->TreeH(); | |
359cdddc | 285 | Int_t ntracks = (Int_t) treeH->GetEntries(); |
6de91202 | 286 | ResetHits(); |
287 | ||
359cdddc | 288 | // Tracks loop |
6de91202 | 289 | Int_t sector[2]; |
90001c80 | 290 | for(Int_t itrack = 0; itrack < ntracks; itrack++) { |
6de91202 | 291 | treeH->GetEntry(itrack); |
90001c80 | 292 | for(AliZDCHit* zdcHit = (AliZDCHit*)FirstHit(-1); zdcHit; |
6de91202 | 293 | zdcHit = (AliZDCHit*)NextHit()) { |
b6d27557 | 294 | |
6de91202 | 295 | sector[0] = zdcHit->GetVolume(0); |
296 | sector[1] = zdcHit->GetVolume(1); | |
90001c80 | 297 | if((sector[1] < 1) || (sector[1] > 4)) { |
6de91202 | 298 | Error("Hits2SDigits", "sector[0] = %d, sector[1] = %d", |
299 | sector[0], sector[1]); | |
300 | continue; | |
301 | } | |
302 | Float_t lightQ = zdcHit->GetLightPMQ(); | |
303 | Float_t lightC = zdcHit->GetLightPMC(); | |
304 | ||
90001c80 | 305 | if(sector[0] == 1) { //ZN |
6de91202 | 306 | pmCZN += lightC; |
307 | pmQZN[sector[1]-1] += lightQ; | |
90001c80 | 308 | } else if(sector[0] == 2) { //ZP |
6de91202 | 309 | pmCZP += lightC; |
310 | pmQZP[sector[1]-1] += lightQ; | |
90001c80 | 311 | } else if(sector[0] == 3) { //ZEM |
312 | if(sector[1] == 1) pmZEM1 += lightC; | |
6de91202 | 313 | else pmZEM2 += lightQ; |
314 | } | |
315 | }//Hits loop | |
359cdddc | 316 | } |
6de91202 | 317 | |
318 | // create the output tree | |
319 | fLoader->MakeTree("S"); | |
320 | TTree* treeS = fLoader->TreeS(); | |
321 | const Int_t kBufferSize = 4000; | |
322 | treeS->Branch(GetName(), "AliZDCSDigit", &psdigit, kBufferSize); | |
323 | ||
90001c80 | 324 | // Create sdigits for ZN1 |
325 | sector[0] = 1; // Detector = ZN1 | |
6de91202 | 326 | sector[1] = 0; // Common PM ADC |
327 | new(psdigit) AliZDCSDigit(sector, pmCZN); | |
90001c80 | 328 | if(pmCZN > 0) treeS->Fill(); |
329 | for(Int_t j = 0; j < 4; j++) { | |
6de91202 | 330 | sector[1] = j+1; // Towers PM ADCs |
331 | new(psdigit) AliZDCSDigit(sector, pmQZN[j]); | |
90001c80 | 332 | if(pmQZN[j] > 0) treeS->Fill(); |
b6d27557 | 333 | } |
359cdddc | 334 | |
90001c80 | 335 | // Create sdigits for ZP1 |
336 | sector[0] = 2; // Detector = ZP1 | |
6de91202 | 337 | sector[1] = 0; // Common PM ADC |
338 | new(psdigit) AliZDCSDigit(sector, pmCZP); | |
90001c80 | 339 | if(pmCZP > 0) treeS->Fill(); |
340 | for(Int_t j = 0; j < 4; j++) { | |
6de91202 | 341 | sector[1] = j+1; // Towers PM ADCs |
342 | new(psdigit) AliZDCSDigit(sector, pmQZP[j]); | |
90001c80 | 343 | if(pmQZP[j] > 0) treeS->Fill(); |
6de91202 | 344 | } |
345 | ||
346 | // Create sdigits for ZEM | |
347 | sector[0] = 3; | |
348 | sector[1] = 1; // Detector = ZEM1 | |
349 | new(psdigit) AliZDCSDigit(sector, pmZEM1); | |
90001c80 | 350 | if(pmZEM1 > 0) treeS->Fill(); |
6de91202 | 351 | sector[1] = 2; // Detector = ZEM2 |
352 | new(psdigit) AliZDCSDigit(sector, pmZEM2); | |
90001c80 | 353 | if(pmZEM2 > 0) treeS->Fill(); |
6de91202 | 354 | |
355 | // write the output tree | |
356 | fLoader->WriteSDigits("OVERWRITE"); | |
85a5290f | 357 | } |
358 | ||
359 | fLoader->UnloadHits(); | |
360 | fLoader->UnloadSDigits(); | |
359cdddc | 361 | } |
362 | ||
363 | //_____________________________________________________________________________ | |
6de91202 | 364 | AliDigitizer* AliZDC::CreateDigitizer(AliRunDigitizer* manager) const |
359cdddc | 365 | { |
6de91202 | 366 | // Create the digitizer for ZDC |
367 | ||
368 | return new AliZDCDigitizer(manager); | |
359cdddc | 369 | } |
370 | ||
371 | //_____________________________________________________________________________ | |
6de91202 | 372 | void AliZDC::Digits2Raw() |
359cdddc | 373 | { |
6de91202 | 374 | // Convert ZDC digits to raw data |
375 | ||
83347831 | 376 | // Format: 24 int values -> ZN1(C+Q1-4), ZP1(C+Q1-4), ZEM1, ZEM2, ZN(C+Q1-4), ZP2(C+Q1-4), 2 Ref PMs |
377 | // + 24 int values for the corresponding out of time channels | |
d79f8d50 | 378 | // For the CAEN module V965 we have an Header, the Data Words and an End Of Block |
379 | // 12 channels x 2 gain chains read from 1st ADC module | |
83347831 | 380 | // 12 channels x 2 gain chains read from 2nd ADC module |
d79f8d50 | 381 | // 12 channels x 2 gain chains read from 3rd ADC module (o.o.t.) |
83347831 | 382 | // 12 channels x 2 gain chains read from 4rth ADC module (o.o.t.) |
d79f8d50 | 383 | // |
83347831 | 384 | const int knADCData1=24, knADCData2=24; // In principle the 2 numbers can be different! |
7f73eb6b | 385 | UInt_t lADCHeader1; |
7f73eb6b | 386 | UInt_t lADCHeader2; |
83347831 | 387 | UInt_t lADCData1[knADCData1]; |
8a2624cc | 388 | UInt_t lADCData2[knADCData2]; |
d79f8d50 | 389 | UInt_t lADCData3[knADCData1]; |
d79f8d50 | 390 | UInt_t lADCData4[knADCData2]; |
391 | // | |
232b622f | 392 | UInt_t lADCEndBlock; |
6de91202 | 393 | |
394 | // load the digits | |
395 | fLoader->LoadDigits("read"); | |
396 | AliZDCDigit digit; | |
397 | AliZDCDigit* pdigit = &digit; | |
398 | TTree* treeD = fLoader->TreeD(); | |
90001c80 | 399 | if(!treeD) return; |
6de91202 | 400 | treeD->SetBranchAddress("ZDC", &pdigit); |
83347831 | 401 | //printf("\t AliZDC::Digits2Raw -> TreeD has %d entries\n",(Int_t) treeD->GetEntries()); |
6de91202 | 402 | |
403 | // Fill data array | |
404 | // ADC header | |
232b622f | 405 | UInt_t lADCHeaderGEO = 0; |
406 | UInt_t lADCHeaderCRATE = 0; | |
8a2624cc | 407 | UInt_t lADCHeaderCNT1 = knADCData1; |
408 | UInt_t lADCHeaderCNT2 = knADCData2; | |
1450a7cd | 409 | |
7f73eb6b | 410 | lADCHeader1 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 | |
411 | lADCHeaderCNT1 << 8 ; | |
7f73eb6b | 412 | lADCHeader2 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 | |
413 | lADCHeaderCNT2 << 8 ; | |
6de91202 | 414 | |
415 | // ADC data word | |
232b622f | 416 | UInt_t lADCDataGEO = lADCHeaderGEO; |
83347831 | 417 | // |
8a2624cc | 418 | UInt_t lADCDataValue1[knADCData1]; |
419 | UInt_t lADCDataValue2[knADCData2]; | |
d79f8d50 | 420 | UInt_t lADCDataValue3[knADCData1]; |
421 | UInt_t lADCDataValue4[knADCData2]; | |
83347831 | 422 | // |
8a2624cc | 423 | UInt_t lADCDataOvFlw1[knADCData1]; |
424 | UInt_t lADCDataOvFlw2[knADCData2]; | |
d79f8d50 | 425 | UInt_t lADCDataOvFlw3[knADCData1]; |
426 | UInt_t lADCDataOvFlw4[knADCData2]; | |
83347831 | 427 | // |
d79f8d50 | 428 | for(Int_t i=0; i<knADCData1 ; i++){ |
7f73eb6b | 429 | lADCDataValue1[i] = 0; |
430 | lADCDataOvFlw1[i] = 0; | |
d79f8d50 | 431 | lADCDataValue3[i] = 0; |
432 | lADCDataOvFlw3[i] = 0; | |
7f73eb6b | 433 | } |
d79f8d50 | 434 | for(Int_t i=0; i<knADCData2 ; i++){ |
7f73eb6b | 435 | lADCDataValue2[i] = 0; |
436 | lADCDataOvFlw2[i] = 0; | |
d79f8d50 | 437 | lADCDataValue4[i] = 0; |
438 | lADCDataOvFlw4[i] = 0; | |
6de91202 | 439 | } |
83347831 | 440 | // |
232b622f | 441 | UInt_t lADCDataChannel = 0; |
6de91202 | 442 | |
443 | // loop over digits | |
d79f8d50 | 444 | for(Int_t iDigit=0; iDigit<treeD->GetEntries(); iDigit++){ |
6de91202 | 445 | treeD->GetEntry(iDigit); |
d79f8d50 | 446 | if(!pdigit) continue; |
a5d5ab4c | 447 | //digit.Print(""); |
abf60186 | 448 | |
d79f8d50 | 449 | // *** ADC data |
83347831 | 450 | Int_t index=0; |
451 | if(digit.GetSector(1)!=5){ // ZDC signal channels | |
452 | // *** ADC1 (ZN1, ZP1, ZEM1,2) or ADC3 (ZN1, ZP1, ZEM1,2 o.o.t.) | |
453 | if(digit.GetSector(0)==1 || digit.GetSector(0)==2 || digit.GetSector(0)==3){ | |
454 | if(digit.GetSector(0)==1 || digit.GetSector(0)==2){ | |
455 | index = (digit.GetSector(0)-1) + 4*digit.GetSector(1); // ZN1 or ZP1 | |
456 | lADCDataChannel = 8*(digit.GetSector(0)-1) + digit.GetSector(1); | |
457 | } | |
458 | else if(digit.GetSector(0)==3){ // ZEM 1,2 | |
459 | index = 20 + (digit.GetSector(1)-1); | |
460 | lADCDataChannel = 5 + 8*(digit.GetSector(1)-1); | |
461 | } | |
462 | // | |
463 | /*printf("\t AliZDC::Digits2Raw -> idig%d det %d quad %d index %d, ADCch %d ADCVal[%d, %d]\n", | |
464 | iDigit,digit.GetSector(0),digit.GetSector(1),index,lADCDataChannel, | |
465 | digit.GetADCValue(0),digit.GetADCValue(1));// Ch. debug | |
466 | */ | |
467 | // | |
468 | if(iDigit<knADCData1){ // *** In-time signals | |
469 | lADCDataValue1[index] = digit.GetADCValue(0); // High gain ADC ch. | |
470 | if(lADCDataValue1[index] > 2047) lADCDataOvFlw1[index] = 1; | |
471 | lADCDataValue1[index+2] = digit.GetADCValue(1); // Low gain ADC ch. | |
472 | if(lADCDataValue1[index+2] > 2047) lADCDataOvFlw1[index+2] = 1; | |
473 | ||
474 | lADCData1[index] = lADCDataGEO << 27 | 0x1 << 24 | lADCDataChannel << 17 | | |
475 | lADCDataOvFlw1[index] << 12 | (lADCDataValue1[index] & 0xfff); | |
476 | lADCData1[index+2] = lADCDataGEO << 27 | 0x1 << 24 | lADCDataChannel << 17 | 0x1 << 16 | | |
477 | lADCDataOvFlw1[index+2] << 12 | (lADCDataValue1[index+2] & 0xfff); | |
478 | } | |
479 | else{ // *** Out-of-time signals | |
480 | lADCDataValue3[index] = digit.GetADCValue(0); // High gain ADC ch. | |
481 | if(lADCDataValue3[index] > 2047) lADCDataOvFlw3[index] = 1; | |
482 | lADCDataValue3[index+2] = digit.GetADCValue(1); // Low gain ADC ch. | |
483 | if(lADCDataValue3[index+2] > 2047) lADCDataOvFlw3[index+2] = 1; | |
484 | ||
485 | lADCData3[index] = lADCDataGEO << 27 | lADCDataChannel << 17 | | |
486 | lADCDataOvFlw3[index] << 12 | (lADCDataValue3[index] & 0xfff); | |
487 | lADCData3[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 | | |
488 | lADCDataOvFlw3[index+2] << 12 | (lADCDataValue3[index+2] & 0xfff); | |
489 | } | |
7f73eb6b | 490 | } |
83347831 | 491 | // *** ADC2 (ZN2, ZP2) or ADC4 (ZN2, ZP2 o.o.t.) |
492 | else if(digit.GetSector(0)==4 || digit.GetSector(0)==5){ | |
493 | index = (digit.GetSector(0)-4) + 4*digit.GetSector(1); // ZN2 or ZP2 | |
494 | lADCDataChannel = 8*(digit.GetSector(0)-4) + digit.GetSector(1); | |
495 | // | |
496 | /*printf("\t AliZDC::Digits2Raw -> idig%d det %d quad %d index %d, ADCch %d ADCVal[%d, %d]\n", | |
497 | iDigit,digit.GetSector(0),digit.GetSector(1),index,lADCDataChannel, | |
498 | digit.GetADCValue(0),digit.GetADCValue(1));// Ch. debug | |
499 | */ | |
500 | // | |
501 | if(iDigit<knADCData2){ // *** In-time signals | |
502 | lADCDataValue2[index] = digit.GetADCValue(0); | |
503 | if(lADCDataValue2[index] > 2047) lADCDataOvFlw2[index] = 1; | |
504 | lADCDataValue2[index+2] = digit.GetADCValue(1); | |
505 | if(lADCDataValue2[index+2] > 2047) lADCDataOvFlw2[index+2] = 1; | |
506 | // | |
507 | lADCData2[index] = lADCDataGEO << 27 | lADCDataChannel << 17 | | |
508 | lADCDataOvFlw2[index] << 12 | (lADCDataValue2[index] & 0xfff); | |
509 | lADCData2[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 | | |
510 | lADCDataOvFlw2[index+2] << 12 | (lADCDataValue2[index+2] & 0xfff); | |
511 | } | |
512 | else{ // *** Out-of-time signals | |
513 | lADCDataValue4[index] = digit.GetADCValue(0); | |
514 | if(lADCDataValue4[index] > 2047) lADCDataOvFlw4[index] = 1; | |
515 | lADCDataValue4[index+2] = digit.GetADCValue(1); | |
516 | if(lADCDataValue4[index+2] > 2047) lADCDataOvFlw4[index+2] = 1; | |
517 | // | |
518 | lADCData4[index] = lADCDataGEO << 27 | lADCDataChannel << 17 | | |
519 | lADCDataOvFlw4[index] << 12 | (lADCDataValue4[index] & 0xfff); | |
520 | lADCData4[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 | | |
521 | lADCDataOvFlw4[index+2] << 12 | (lADCDataValue4[index+2] & 0xfff); | |
522 | } | |
d79f8d50 | 523 | } |
6de91202 | 524 | } |
83347831 | 525 | // *** ADC2 (Reference PTMs) or ADC4 (Reference PTMs o.o.t.) |
526 | else if(digit.GetSector(1)==5){ | |
527 | index = 20 + (digit.GetSector(0)-1)*1/3; | |
528 | lADCDataChannel = 5 + (digit.GetSector(0)-1)*8/3; | |
abf60186 | 529 | // |
83347831 | 530 | /*printf("\t AliZDC::Digits2Raw -> idig%d det %d quad %d index %d, ADCch %d ADCVal[%d, %d]\n", |
531 | iDigit,digit.GetSector(0),digit.GetSector(1),index,lADCDataChannel, | |
532 | digit.GetADCValue(0),digit.GetADCValue(1));// Ch. debug | |
c7426372 | 533 | */ |
7f73eb6b | 534 | // |
83347831 | 535 | if(iDigit<knADCData2){ // *** In-time signals |
536 | lADCDataValue2[index] = digit.GetADCValue(0); | |
537 | if(lADCDataValue2[index] > 2047) lADCDataOvFlw2[index] = 1; | |
538 | lADCDataValue2[index+2] = digit.GetADCValue(1); | |
539 | if(lADCDataValue2[index+2] > 2047) lADCDataOvFlw2[index+2] = 1; | |
d79f8d50 | 540 | // |
83347831 | 541 | lADCData2[index] = lADCDataGEO << 27 | lADCDataChannel << 17 | |
542 | lADCDataOvFlw2[index] << 12 | (lADCDataValue2[index] & 0xfff); | |
543 | lADCData2[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 | | |
544 | lADCDataOvFlw2[index+2] << 12 | (lADCDataValue2[index+2] & 0xfff); | |
545 | } | |
546 | else{ // *** Out-of-time signals | |
547 | lADCDataValue4[index] = digit.GetADCValue(0); | |
548 | if(lADCDataValue4[index] > 2047) lADCDataOvFlw4[index] = 1; | |
549 | lADCDataValue4[index+2] = digit.GetADCValue(1); | |
550 | if(lADCDataValue4[index+2] > 2047) lADCDataOvFlw4[index+2] = 1; | |
d79f8d50 | 551 | // |
83347831 | 552 | lADCData4[index] = lADCDataGEO << 27 | lADCDataChannel << 17 | |
553 | lADCDataOvFlw4[index] << 12 | (lADCDataValue4[index] & 0xfff); | |
554 | lADCData4[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 | | |
555 | lADCDataOvFlw4[index+2] << 12 | (lADCDataValue4[index+2] & 0xfff); | |
556 | } | |
557 | ||
6de91202 | 558 | } |
83347831 | 559 | if((index<0) || (index>23)) { |
6de91202 | 560 | Error("Digits2Raw", "sector[0] = %d, sector[1] = %d", |
561 | digit.GetSector(0), digit.GetSector(1)); | |
562 | continue; | |
1450a7cd | 563 | } |
1450a7cd | 564 | |
1450a7cd | 565 | |
1450a7cd | 566 | } |
83347831 | 567 | // |
568 | /* | |
569 | for(Int_t i=0;i<24;i++) printf("\t ADCData1[%d] = %x\n",i,lADCData1[i]); | |
d79f8d50 | 570 | for(Int_t i=0;i<20;i++) printf("\t ADCData2[%d] = %x\n",i,lADCData2[i]); |
571 | for(Int_t i=0;i<24;i++) printf("\t ADCData3[%d] = %x\n",i,lADCData3[i]); | |
572 | for(Int_t i=0;i<20;i++) printf("\t ADCData4[%d] = %x\n",i,lADCData4[i]); | |
c7426372 | 573 | */ |
7f73eb6b | 574 | |
6de91202 | 575 | // End of Block |
232b622f | 576 | UInt_t lADCEndBlockGEO = lADCHeaderGEO; |
577 | UInt_t lADCEndBlockEvCount = gAlice->GetEventNrInRun(); | |
83347831 | 578 | // |
232b622f | 579 | lADCEndBlock = lADCEndBlockGEO << 27 | 0x1 << 26 | lADCEndBlockEvCount; |
256c2b16 | 580 | //printf("\t AliZDC::Digits2Raw -> ADCEndBlock = %d\n",lADCEndBlock); |
6de91202 | 581 | |
582 | ||
583 | // open the output file | |
584 | char fileName[30]; | |
362c9d61 | 585 | strcpy(fileName,AliDAQ::DdlFileName("ZDC",0)); |
08f92f14 | 586 | |
587 | AliFstream* file = new AliFstream(fileName); | |
6de91202 | 588 | |
589 | // write the DDL data header | |
590 | AliRawDataHeader header; | |
d79f8d50 | 591 | header.fSize = sizeof(header) + |
592 | sizeof(lADCHeader1) + sizeof(lADCData1) + sizeof(lADCEndBlock) + | |
593 | sizeof(lADCHeader2) + sizeof(lADCData2) + sizeof(lADCEndBlock) + | |
83347831 | 594 | sizeof(lADCHeader1) + sizeof(lADCData3) + sizeof(lADCEndBlock) + |
595 | sizeof(lADCHeader2) + sizeof(lADCData4) + sizeof(lADCEndBlock); | |
596 | // | |
abf60186 | 597 | /*printf("sizeof header = %d, ADCHeader1 = %d, ADCData1 = %d, ADCEndBlock = %d\n", |
598 | sizeof(header),sizeof(lADCHeader1),sizeof(lADCData1),sizeof(lADCEndBlock)); | |
599 | printf("sizeof header = %d, ADCHeader2 = %d, ADCData2 = %d, ADCEndBlock = %d\n", | |
83347831 | 600 | sizeof(header),sizeof(lADCHeader2),sizeof(lADCData2),sizeof(lADCEndBlock)); |
601 | */ | |
602 | // | |
6de91202 | 603 | header.SetAttribute(0); // valid data |
08f92f14 | 604 | file->WriteBuffer((char*)(&header), sizeof(header)); |
6de91202 | 605 | |
606 | // write the raw data and close the file | |
08f92f14 | 607 | file->WriteBuffer((char*) &lADCHeader1, sizeof (lADCHeader1)); |
608 | file->WriteBuffer((char*)(lADCData1), sizeof(lADCData1)); | |
609 | file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock)); | |
610 | file->WriteBuffer((char*) &lADCHeader2, sizeof (lADCHeader2)); | |
611 | file->WriteBuffer((char*)(lADCData2), sizeof(lADCData2)); | |
612 | file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock)); | |
83347831 | 613 | file->WriteBuffer((char*) &lADCHeader1, sizeof (lADCHeader1)); |
08f92f14 | 614 | file->WriteBuffer((char*)(lADCData3), sizeof(lADCData3)); |
615 | file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock)); | |
83347831 | 616 | file->WriteBuffer((char*) &lADCHeader2, sizeof (lADCHeader2)); |
08f92f14 | 617 | file->WriteBuffer((char*)(lADCData4), sizeof(lADCData4)); |
618 | file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock)); | |
619 | delete file; | |
6de91202 | 620 | |
621 | // unload the digits | |
622 | fLoader->UnloadDigits(); | |
359cdddc | 623 | } |
624 | ||
90001c80 | 625 | //_____________________________________________________________________________ |
626 | Bool_t AliZDC::Raw2SDigits(AliRawReader* rawReader) | |
627 | { | |
628 | // Convert ZDC raw data to Sdigits | |
629 | ||
36f43fdf | 630 | AliLoader* loader = (gAlice->GetRunLoader())->GetLoader("ZDCLoader"); |
631 | if(!loader) { | |
632 | AliError("no ZDC loader found"); | |
633 | return kFALSE; | |
634 | } | |
635 | ||
636 | // // Event loop | |
637 | Int_t iEvent = 0; | |
90001c80 | 638 | while(rawReader->NextEvent()){ |
36f43fdf | 639 | (gAlice->GetRunLoader())->GetEvent(iEvent++); |
90001c80 | 640 | // Create the output digit tree |
36f43fdf | 641 | TTree* treeS = loader->TreeS(); |
642 | if(!treeS){ | |
643 | loader->MakeTree("S"); | |
644 | treeS = loader->TreeS(); | |
90001c80 | 645 | } |
646 | // | |
647 | AliZDCSDigit sdigit; | |
648 | AliZDCSDigit* psdigit = &sdigit; | |
649 | const Int_t kBufferSize = 4000; | |
650 | treeS->Branch("ZDC", "AliZDCSDigit", &psdigit, kBufferSize); | |
651 | // | |
652 | AliZDCRawStream rawStream(rawReader); | |
6310fd85 | 653 | Int_t sector[2], resADC, rawADC, corrADC, nPheVal; |
90001c80 | 654 | Int_t jcount = 0; |
655 | while(rawStream.Next()){ | |
656 | if(rawStream.IsADCDataWord()){ | |
83347831 | 657 | //For the moment only in-time SDigits are foreseen (1st 48 raw values) |
658 | if(jcount < 48){ | |
90001c80 | 659 | for(Int_t j=0; j<2; j++) sector[j] = rawStream.GetSector(j); |
6310fd85 | 660 | rawADC = rawStream.GetADCValue(); |
661 | resADC = rawStream.GetADCGain(); | |
36f43fdf | 662 | //printf("\t RAw2SDigits raw%d -> RawADC[%d, %d, %d] read\n", |
6310fd85 | 663 | // jcount, sector[0], sector[1], rawADC); |
90001c80 | 664 | // |
6310fd85 | 665 | corrADC = rawADC - Pedestal(sector[0], sector[1], resADC); |
666 | if(corrADC<0) corrADC=0; | |
667 | nPheVal = ADCch2Phe(sector[0], sector[1], corrADC, resADC); | |
36f43fdf | 668 | // |
669 | //printf("\t \t -> SDigit[%d, %d, %d] created\n", | |
670 | // sector[0], sector[1], nPheVal); | |
671 | // | |
90001c80 | 672 | new(psdigit) AliZDCSDigit(sector, (Float_t) nPheVal); |
673 | treeS->Fill(); | |
36f43fdf | 674 | jcount++; |
90001c80 | 675 | } |
90001c80 | 676 | }//IsADCDataWord |
677 | }//rawStream.Next | |
678 | // write the output tree | |
679 | fLoader->WriteSDigits("OVERWRITE"); | |
680 | fLoader->UnloadSDigits(); | |
681 | }//Event loop | |
682 | ||
683 | return kTRUE; | |
684 | } | |
685 | ||
686 | //_____________________________________________________________________________ | |
687 | Int_t AliZDC::Pedestal(Int_t Det, Int_t Quad, Int_t Res) const | |
688 | { | |
689 | // Returns a pedestal for detector det, PM quad, channel with res. | |
690 | // | |
36f43fdf | 691 | // Getting calibration object for ZDC set |
692 | AliCDBManager *man = AliCDBManager::Instance(); | |
36f43fdf | 693 | AliCDBEntry *entry = man->Get("ZDC/Calib/Data"); |
6310fd85 | 694 | AliZDCCalibData *calibData = (AliZDCCalibData*) entry->GetObject(); |
36f43fdf | 695 | // |
6310fd85 | 696 | if(!calibData){ |
36f43fdf | 697 | printf("\t No calibration object found for ZDC!"); |
698 | return -1; | |
699 | } | |
700 | // | |
6310fd85 | 701 | Float_t pedValue; |
702 | Float_t meanPed, pedWidth; | |
90001c80 | 703 | Int_t index=0; |
83347831 | 704 | if(Quad!=5){ |
705 | if(Det==1 || Det==2) index = 10*(Det-1)+Quad+5*Res; // ZN1, ZP1 | |
706 | else if(Det==3) index = 10*(Det-1)+(Quad-1)+Res; // ZEM | |
707 | else if(Det==4 || Det==5) index = 10*(Det-2)+Quad+5*Res+4; // ZN2, ZP2 | |
708 | } | |
709 | else index = 10*(Quad-1)+(Det-1)*1/3+2*Res+4; // Reference PMs | |
36f43fdf | 710 | // |
711 | // | |
6310fd85 | 712 | meanPed = calibData->GetMeanPed(index); |
713 | pedWidth = calibData->GetMeanPedWidth(index); | |
714 | pedValue = gRandom->Gaus(meanPed,pedWidth); | |
90001c80 | 715 | // |
6310fd85 | 716 | //printf("\t AliZDC::Pedestal - det(%d, %d) - Ped[%d] = %d\n",Det, Quad, index,(Int_t) pedValue); // Chiara debugging! |
36f43fdf | 717 | |
90001c80 | 718 | |
719 | ||
6310fd85 | 720 | return (Int_t) pedValue; |
90001c80 | 721 | } |
722 | ||
723 | ||
724 | //_____________________________________________________________________________ | |
36f43fdf | 725 | Int_t AliZDC::ADCch2Phe(Int_t Det, Int_t Quad, Int_t ADCVal, Int_t Res) const |
90001c80 | 726 | { |
727 | // Evaluation of the no. of phe produced | |
6310fd85 | 728 | Float_t pmGain[6][5]; |
729 | Float_t resADC[2]; | |
90001c80 | 730 | for(Int_t j = 0; j < 5; j++){ |
6310fd85 | 731 | pmGain[0][j] = 50000.; |
732 | pmGain[1][j] = 100000.; | |
733 | pmGain[2][j] = 100000.; | |
734 | pmGain[3][j] = 50000.; | |
735 | pmGain[4][j] = 100000.; | |
736 | pmGain[5][j] = 100000.; | |
90001c80 | 737 | } |
738 | // ADC Caen V965 | |
6310fd85 | 739 | resADC[0] = 0.0000008; // ADC Resolution high gain: 200 fC/adcCh |
740 | resADC[1] = 0.0000064; // ADC Resolution low gain: 25 fC/adcCh | |
90001c80 | 741 | // |
6310fd85 | 742 | Int_t nPhe = (Int_t) (ADCVal * pmGain[Det-1][Quad] * resADC[Res]); |
36f43fdf | 743 | // |
744 | //printf("\t AliZDC::ADCch2Phe -> det(%d, %d) - ADC %d phe %d\n",Det,Quad,ADCVal,nPhe); | |
90001c80 | 745 | |
746 | return nPhe; | |
747 | } | |
748 | ||
b81c9821 | 749 | //______________________________________________________________________ |
750 | void AliZDC::SetTreeAddress(){ | |
90001c80 | 751 | |
b81c9821 | 752 | // Set branch address for the Trees. |
90001c80 | 753 | if(fLoader->TreeH() && (fHits == 0x0)) |
b81c9821 | 754 | fHits = new TClonesArray("AliZDCHit",1000); |
755 | ||
b81c9821 | 756 | AliDetector::SetTreeAddress(); |
757 | } | |
359cdddc | 758 | |
8af17dba | 759 | //________________________________________________________________ |
760 | void AliZDC::CreateCalibData() | |
761 | { | |
762 | // | |
90001c80 | 763 | //if(fCalibData) delete fCalibData; // delete previous version |
8af17dba | 764 | fCalibData = new AliZDCCalibData(GetName()); |
765 | } | |
766 | //________________________________________________________________ | |
767 | void AliZDC::WriteCalibData(Int_t option) | |
768 | { | |
769 | // | |
770 | const int kCompressLevel = 9; | |
4d81e5e7 | 771 | char* fnam = GetZDCCalibFName(); |
90001c80 | 772 | if(!fnam || fnam[0]=='\0') { |
e689b8ea | 773 | fnam = gSystem->ExpandPathName("$(ALICE_ROOT)/data/AliZDCCalib.root"); |
8af17dba | 774 | Warning("WriteCalibData","No File Name is provided, using default %s",fnam); |
775 | } | |
776 | TFile* cdfile = TFile::Open(fnam,"UPDATE","",kCompressLevel); | |
777 | ||
778 | // Writes Calibration Data to current directory. | |
779 | // User MUST take care of corresponding file opening and ->cd()... !!! | |
780 | // By default, the object is overwritten. Use 0 option for opposite. | |
90001c80 | 781 | if(option) option = TObject::kOverwrite; |
782 | if(fCalibData) fCalibData->Write(0,option); | |
783 | else if(fCalibData) fCalibData->Write(0,option); | |
8af17dba | 784 | |
785 | cdfile->Close(); | |
786 | delete cdfile; | |
787 | } | |
788 | ||
789 | //________________________________________________________________ | |
790 | void AliZDC::LoadCalibData() | |
791 | { | |
792 | // | |
4d81e5e7 | 793 | char* fnam = GetZDCCalibFName(); |
90001c80 | 794 | if(!fnam || fnam[0]=='\0') return; |
795 | if(!gAlice->IsFileAccessible(fnam)) { | |
8af17dba | 796 | Error("LoadCalibData","ZDC Calibration Data file is not accessible, %s",fnam); |
797 | exit(1); | |
798 | } | |
799 | TFile* cdfile = TFile::Open(fnam); | |
800 | ||
801 | // Loads Calibration Data from current directory. | |
802 | // User MUST take care of corresponding file opening and ->cd()...!!! | |
803 | // | |
90001c80 | 804 | if(fCalibData) delete fCalibData; // delete previous version |
8af17dba | 805 | TString dtname = "Calib_"; |
806 | dtname += GetName(); | |
807 | fCalibData = (AliZDCCalibData*) gDirectory->Get(dtname.Data()); | |
90001c80 | 808 | if(!fCalibData) { |
8af17dba | 809 | Error("LoadCalibData","No Calibration data found for %s",GetName()); |
810 | exit(1); | |
811 | } | |
812 | ||
813 | cdfile->Close(); | |
814 | delete cdfile; | |
815 | } | |
816 |