1 //////////////////////////////////////////////////////////////////////////////
3 // * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 // * Author: The ALICE Off-line Project. *
6 // * Contributors are mentioned in the code where appropriate. *
8 // * Permission to use, copy, modify and distribute this software and its *
9 // * documentation strictly for non-commercial purposes is hereby granted *
10 // * without fee, provided that the above copyright notice appears in all *
11 // * copies and that both the copyright notice and this permission notice *
12 // * appear in the supporting documentation. The authors make no claims *
13 // * about the suitability of this software for any purpose. It is *
14 // * provided "as is" without express or implied warranty. *
15 // **************************************************************************/
17 //////////////////////////////////////////////////////////////////////////////
19 #include "Riostream.h"
22 #include "TObjString.h"
24 #include "TClonesArray.h"
26 #include "TObjArray.h"
30 // --- Standard library ---
32 // --- AliRoot header files ---
35 #include "AliRawReader.h"
36 #include "AliPMDRawStream.h"
37 #include "AliPMDddldata.h"
38 #include "AliPMDCalibGain.h"
41 ClassImp(AliPMDCalibGain)
43 AliPMDCalibGain::AliPMDCalibGain():
47 // Standard Constructor
48 for(Int_t idet = 0; idet < kDet; idet++)
50 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
52 fSMIso[idet][ismn] = 0.;
53 fSMCount[idet][ismn] = 0.;
54 fCountSm[idet][ismn]=0.;
55 fTempnhit[idet][ismn]=0.;
56 fTempnhitSq[idet][ismn]=0.;
57 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
59 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
61 fCellIso[idet][ismn][jrow][kcol] = 0.;
62 fCellCount[idet][ismn][jrow][kcol] = 0.;
63 fNhitCell[idet][ismn][jrow][kcol] = 0.;
64 fPedMeanRMS[idet][ismn][jrow][kcol] = 0.;
65 fHotFlag[idet][ismn][jrow][kcol] = 0.;
73 // ------------------------------------------------------------------------ //
74 AliPMDCalibGain::AliPMDCalibGain(const AliPMDCalibGain &pmdcalibgain):
75 TObject(pmdcalibgain),
78 for(Int_t idet = 0; idet < kDet; idet++)
80 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
82 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn] ;
83 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn] ;
84 fCountSm[idet][ismn] = pmdcalibgain.fCountSm[idet][ismn];
85 fTempnhit[idet][ismn] = pmdcalibgain.fTempnhit[idet][ismn];
86 fTempnhitSq[idet][ismn] = pmdcalibgain.fTempnhitSq[idet][ismn];
87 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
89 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
91 fCellIso[idet][ismn][jrow][kcol] = pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
92 fCellCount[idet][ismn][jrow][kcol] = pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
93 fNhitCell[idet][ismn][jrow][kcol] = pmdcalibgain.fNhitCell[idet][ismn][jrow][kcol];
94 fPedMeanRMS[idet][ismn][jrow][kcol] = pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
95 fHotFlag[idet][ismn][jrow][kcol] = pmdcalibgain.fHotFlag[idet][ismn][jrow][kcol];
103 // ------------------------------------------------------------------------ //
104 AliPMDCalibGain &AliPMDCalibGain::operator=(const AliPMDCalibGain &pmdcalibgain)
106 if(this != &pmdcalibgain)
108 this->fpw = pmdcalibgain.fpw;
109 for(Int_t idet = 0; idet < kDet; idet++)
111 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
113 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn];
114 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn];
115 fCountSm[idet][ismn] = pmdcalibgain.fCountSm[idet][ismn];
116 fTempnhit[idet][ismn] = pmdcalibgain.fTempnhit[idet][ismn];
117 fTempnhitSq[idet][ismn] = pmdcalibgain.fTempnhitSq[idet][ismn];
118 for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
120 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
122 fCellIso[idet][ismn][jrow][kcol] = pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
123 fCellCount[idet][ismn][jrow][kcol] = pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
124 fNhitCell[idet][ismn][jrow][kcol] = pmdcalibgain.fNhitCell[idet][ismn][jrow][kcol]; //za
125 fPedMeanRMS[idet][ismn][jrow][kcol] = pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
126 fHotFlag[idet][ismn][jrow][kcol] = pmdcalibgain.fHotFlag[idet][ismn][jrow][kcol];
135 // ------------------------------------------------------------------------ //
136 AliPMDCalibGain::~AliPMDCalibGain()
141 // ------------------------------------------------------------------------ //
143 Int_t AliPMDCalibGain::ExtractPedestal(const Char_t *rootFile)
145 // Pedestal extraction from the PMD_PED.root file
146 // To be called once at the beginning
148 Int_t det=0, sm=0, row=0, col=0;
149 Float_t mean=0., rms=0.;
151 TFile *pedfile = new TFile(rootFile);
155 printf("ERROR --- NO PEDESTAL (PMD_PED1.root) FILE IS FOUND --- STOP GAIN DA\n");
160 TTree *ped =(TTree*)pedfile->Get("ped");
162 ped->SetBranchAddress("det",&det);
163 ped->SetBranchAddress("sm",&sm);
164 ped->SetBranchAddress("row",&row);
165 ped->SetBranchAddress("col",&col);
166 ped->SetBranchAddress("mean",&mean);
167 ped->SetBranchAddress("rms",&rms);
169 Int_t nentries = (Int_t)ped->GetEntries();
171 for (Int_t ient = 0; ient < nentries; ient++)
174 fPedMeanRMS[det][sm][row][col] = mean + 3.*rms;
175 //printf("Mean= %f, RMS= %f, PedMeanRMS=%f\n",mean,rms,fPedMeanRMS[det][sm][row][col]);
185 //------------------------------------------------------------------------------------------------
187 Int_t AliPMDCalibGain::ExtractHotChannel(const Char_t *rootFile)
189 // HotChannel extraction from the PMD_HOT.root file
190 // To be called once at the beginning
192 Int_t det=0, sm=0, row=0, col=0;
195 TFile *hotmapfile = new TFile(rootFile);
199 printf(" NO HOTCHANNEL MAP (PMD_HOT.root) FILE IS FOUND \n");
201 for (Int_t idet = 0; idet < kDet; idet++)
203 for (Int_t ismn = 0; ismn < kMaxSMN; ismn++)
205 for (Int_t irow = 0; irow < kMaxRow; irow++)
207 for (Int_t icol = 0; icol < kMaxCol; icol++)
209 fHotFlag[idet][ismn][irow][icol] = 0.;
217 TTree *hot =(TTree*)hotmapfile->Get("hot");
219 hot->SetBranchAddress("det",&det);
220 hot->SetBranchAddress("sm",&sm);
221 hot->SetBranchAddress("row",&row);
222 hot->SetBranchAddress("col",&col);
223 hot->SetBranchAddress("flag",&flag);
225 Int_t nentries = (Int_t)hot->GetEntries();
227 for (Int_t ient = 0; ient < nentries; ient++)
230 fHotFlag[det][sm][row][col] = flag;
232 //printf(" HotFlag=%f\n",fHotFlag[det][sm][row][col]);
243 // ------------------------------------------------------------------------ //
245 void AliPMDCalibGain::ReadTempFile(const Char_t *tempFile)
247 // Read the variables from the file
250 intmpfile.open(tempFile);
252 Int_t iddet = 0, issm = 0, irrow = 0, iccol = 0;
253 Float_t smcount = 0., smiso = 0.;
254 Float_t cellcount = 0., celliso = 0.;
257 for (Int_t idet = 0; idet < kDet; idet++)
259 for (Int_t ism = 0; ism < kMaxSMN; ism++)
261 intmpfile >> iddet >> issm >> smcount >> smiso;
262 fSMCount[idet][ism] = smcount;
263 fSMIso[idet][ism] = smiso;
267 for (Int_t idet = 0; idet < kDet; idet++)
269 for (Int_t ism = 0; ism < kMaxSMN; ism++)
271 for (Int_t irow = 0; irow < kMaxRow; irow++)
273 for (Int_t icol = 0; icol < kMaxCol; icol++)
275 intmpfile >> iddet >> issm >> irrow >> iccol
276 >> cellcount >> celliso;
277 fCellCount[idet][ism][irow][icol] = cellcount;
278 fCellIso[idet][ism][irow][icol] = celliso;
288 // ------------------------------------------------------------------------ //
289 void AliPMDCalibGain::WriteTempFile(const Char_t *tempFile)
291 // Write the Temporary file if the required statics is not achieved
295 Following variables to be written to a file
298 fCellIso[idet][ismn][irow][icol];
301 fSMCount[idet][ismn];
302 fCellCount[idet][ismn][irow][icol];
306 fpw = fopen(tempFile,"w+");
308 for (Int_t idet = 0; idet < kDet; idet++)
310 // fprintf(fpw,"%d %f %f\n",idet,fDetCount[idet],fDetIso[idet]);
313 for (Int_t idet = 0; idet < kDet; idet++)
315 for (Int_t ism = 0; ism < kMaxSMN; ism++)
317 fprintf(fpw,"%d %d %f %f\n",idet,ism, fSMCount[idet][ism],fSMIso[idet][ism]);
321 for (Int_t idet = 0; idet < kDet; idet++)
323 for (Int_t ism = 0; ism < kMaxSMN; ism++)
325 for (Int_t irow = 0; irow < kMaxRow; irow++)
327 for (Int_t icol = 0; icol < kMaxCol; icol++)
329 fprintf(fpw,"%d %d %d %d %f %f\n",idet,ism,irow,icol,
330 fCellCount[idet][ism][irow][icol],
331 fCellIso[idet][ism][irow][icol]);
341 // ------------------------------------------------------------------------ //
343 Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlcont)
345 // Calculates the ADC of isolated cell
347 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
348 const Int_t kCellNeighbour = 6;
349 Int_t neibx[6] = {1,0,-1,-1,0,1};
350 Int_t neiby[6] = {0,1,1,0,-1,-1};
352 Int_t id1 = 0,jd1 = 0; //neighbour row/col
353 Int_t isocount = 0; //number of neighbours with 0 signal
355 Float_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
357 for(Int_t idet = 0; idet < kDet; idet++)
359 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
361 for(Int_t irow = 0; irow < kMaxRow; irow++)
363 for(Int_t icol = 0; icol < kMaxCol; icol++)
365 d1[idet][ismn][irow][icol] = 0.;
371 AliPMDRawStream rawStream(rawReader);
375 Int_t numberofDDLs = 0;
377 while ((iddl = rawStream.DdlData(pmdddlcont)) >=0) {
380 Int_t ientries = pmdddlcont->GetEntries();
382 for (Int_t ient = 0; ient < ientries; ient++)
384 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont->UncheckedAt(ient);
386 Int_t idet = pmdddl->GetDetector();
387 Int_t ismn = pmdddl->GetSMN();
388 Int_t mcm = pmdddl->GetMCM();
389 //Int_t ichno = pmdddl->GetChannel();
390 Int_t irow = pmdddl->GetRow();
391 Int_t icol = pmdddl->GetColumn();
392 Int_t isig = pmdddl->GetSignal();
394 // This is the protection not to crash the code
396 if(mcm == 0) continue;
397 if (irow < 0 || icol < 0 || irow > 47 || icol > 95) continue;
399 // Pedestal subtraction
400 if(fHotFlag[idet][ismn][irow][icol] == 1.0) isig = 0;
404 d1[idet][ismn][irow][icol] =
405 (Float_t) isig - fPedMeanRMS[idet][ismn][irow][icol];
407 //printf("Signal_ped_subtracted=%f, pedestal=%f\n",d1[idet][ismn][irow][icol]),fPedMeanRMS[idet][ismn][irow][icol];
409 fNhitCell[idet][ismn][irow][icol]++; //cell hit frequency
414 pmdddlcont->Delete();
417 for(Int_t idet=0; idet < kDet; idet++)
419 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
421 for(Int_t irow = 0; irow < kMaxRow; irow++)
423 for(Int_t icol = 0; icol < kMaxCol; icol++)
425 if(d1[idet][ismn][irow][icol] > 0)
428 for(Int_t ii = 0; ii < kCellNeighbour; ii++)
430 id1 = irow + neibx[ii];
431 jd1 = icol + neiby[ii];
432 if (id1 < 0) id1 = 0;
433 if (id1 > kMaxRow-1) id1 = kMaxRow - 1;
434 if (jd1 < 0) jd1 = 0;
435 if (jd1 > kMaxCol-1) jd1 = kMaxCol - 1;
436 if(d1[idet][ismn][id1][jd1] == 0)
439 if(isocount == kCellNeighbour)
441 //fDetIso[idet] += d1[idet][ismn][irow][icol];
442 fSMIso[idet][ismn] += d1[idet][ismn][irow][icol];
443 fCellIso[idet][ismn][irow][icol] += d1[idet][ismn][irow][icol];
445 fSMCount[idet][ismn]++;
446 fCellCount[idet][ismn][irow][icol]++;
450 } // neigh cell cond.
457 for(Int_t idet=0; idet < kDet; idet++)
459 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
461 for(Int_t irow = 0; irow < kMaxRow; irow++)
463 for(Int_t icol = 0; icol < kMaxCol; icol++)
465 if(fNhitCell[idet][ismn][irow][icol]>0)
467 fCountSm[idet][ismn] += 1;
468 fTempnhit[idet][ismn] += fNhitCell[idet][ismn][irow][icol];
469 fTempnhitSq[idet][ismn] += fNhitCell[idet][ismn][irow][icol]
470 *fNhitCell[idet][ismn][irow][icol];
477 if (numberofDDLs < kDDL) return kFALSE;
481 // ------------------------------------------------------------------------ //
482 void AliPMDCalibGain::Analyse(TTree *gaintree, TTree *meantree)
484 // Calculates the mean
485 Int_t det = 0, sm = 0, row = 0, col = 0;
487 Float_t cellmean = 0.;
489 Float_t modmean[2][24];
491 for (Int_t idet=0; idet < 2; idet++)
493 for (Int_t ism = 0; ism < 24; ism++)
495 modmean[idet][ism] = 0.;
499 gaintree->Branch("det",&det,"det/I");
500 gaintree->Branch("sm",&sm,"sm/I");
501 gaintree->Branch("row",&row,"row/I");
502 gaintree->Branch("col",&col,"col/I");
503 gaintree->Branch("gain",&gain,"gain/F");
505 for(Int_t idet = 0; idet < kDet; idet++)
507 for(Int_t ism = 0; ism < kMaxSMN; ism++)
509 if (fSMCount[idet][ism] > 0)
510 modmean[idet][ism] = fSMIso[idet][ism]/fSMCount[idet][ism];
511 for(Int_t irow = 0; irow < kMaxRow; irow++)
513 for(Int_t icol = 0; icol < kMaxCol; icol++)
515 if (fCellCount[idet][ism][irow][icol] > 0.)
517 cellmean = fCellIso[idet][ism][irow][icol]/fCellCount[idet][ism][irow][icol];
523 if (cellmean > 0.0 && fCellCount[idet][ism][irow][icol]>0.)
525 gain = cellmean/modmean[idet][ism];
531 //if(fCellCount[idet][ism][irow][icol]>0.) printf("CellCount =%f, gain= %f\n",fCellCount[idet][ism][irow][icol],gain);
540 // Writing each module mean value
541 meantree->Branch("det",&det,"det/I");
542 meantree->Branch("sm",&sm,"sm/I");
543 meantree->Branch("smmean",&smmean,"row/F");
545 for(Int_t idet = 0; idet < kDet; idet++)
547 for (Int_t ism = 0; ism < kMaxSMN; ism++)
551 smmean = modmean[idet][ism];
557 // ------------------------------------------------------------------------ //
558 void AliPMDCalibGain::FindHotCell(TTree *hottree, Float_t xvar)
560 // Calculates the mean
561 Int_t det = 0, sm = 0, row = 0, col = 0;
563 Float_t meannhit = 0.;
564 Float_t meanSqnhit = 0.;
565 Float_t sigmanhit = 0.,nhitcut = 0.;
569 hottree->Branch("det",&det,"det/I");
570 hottree->Branch("sm",&sm,"sm/I");
571 hottree->Branch("row",&row,"row/I");
572 hottree->Branch("col",&col,"col/I");
573 hottree->Branch("flag",&flag,"flag/F");
575 for(Int_t idet = 0; idet < kDet; idet++)
577 for(Int_t ism = 0; ism < kMaxSMN; ism++)
579 if (fCountSm[idet][ism]> 0)
581 meannhit = fTempnhit[idet][ism]/fCountSm[idet][ism];
582 meanSqnhit = fTempnhitSq[idet][ism]/fCountSm[idet][ism];
583 sigmanhit = sqrt(meanSqnhit-(meannhit*meannhit));
584 nhitcut = meannhit + xvar*sigmanhit;
586 for(Int_t irow = 0; irow < kMaxRow; irow++)
588 for(Int_t icol = 0; icol < kMaxCol; icol++)
595 if(fNhitCell[idet][ism][irow][icol] > nhitcut)