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"
40 ClassImp(AliPMDCalibGain)
42 AliPMDCalibGain::AliPMDCalibGain():
46 // Standard Constructor
47 for(Int_t idet = 0; idet < kDet; idet++)
49 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
51 fSMIso[idet][ismn] = 0.;
52 fSMCount[idet][ismn] = 0.;
53 fCountSm[idet][ismn]=0.;
54 fTempnhit[idet][ismn]=0.;
55 fTempnhitSq[idet][ismn]=0.;
56 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
58 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
60 fCellIso[idet][ismn][jrow][kcol] = 0.;
61 fCellCount[idet][ismn][jrow][kcol] = 0.;
62 fNhitCell[idet][ismn][jrow][kcol] = 0.;
63 fPedMeanRMS[idet][ismn][jrow][kcol] = 0.;
64 fHotFlag[idet][ismn][jrow][kcol] = 0.;
72 // ------------------------------------------------------------------------ //
73 AliPMDCalibGain::AliPMDCalibGain(const AliPMDCalibGain &pmdcalibgain):
74 TObject(pmdcalibgain),
77 for(Int_t idet = 0; idet < kDet; idet++)
79 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
81 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn] ;
82 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn] ;
83 fCountSm[idet][ismn] = pmdcalibgain.fCountSm[idet][ismn];
84 fTempnhit[idet][ismn] = pmdcalibgain.fTempnhit[idet][ismn];
85 fTempnhitSq[idet][ismn] = pmdcalibgain.fTempnhitSq[idet][ismn];
86 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
88 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
90 fCellIso[idet][ismn][jrow][kcol] = pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
91 fCellCount[idet][ismn][jrow][kcol] = pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
92 fNhitCell[idet][ismn][jrow][kcol] = pmdcalibgain.fNhitCell[idet][ismn][jrow][kcol];
93 fPedMeanRMS[idet][ismn][jrow][kcol] = pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
94 fHotFlag[idet][ismn][jrow][kcol] = pmdcalibgain.fHotFlag[idet][ismn][jrow][kcol];
102 // ------------------------------------------------------------------------ //
103 AliPMDCalibGain &AliPMDCalibGain::operator=(const AliPMDCalibGain &pmdcalibgain)
105 if(this != &pmdcalibgain)
107 this->fpw = pmdcalibgain.fpw;
108 for(Int_t idet = 0; idet < kDet; idet++)
110 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
112 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn];
113 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn];
114 fCountSm[idet][ismn] = pmdcalibgain.fCountSm[idet][ismn];
115 fTempnhit[idet][ismn] = pmdcalibgain.fTempnhit[idet][ismn];
116 fTempnhitSq[idet][ismn] = pmdcalibgain.fTempnhitSq[idet][ismn];
117 for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
119 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
121 fCellIso[idet][ismn][jrow][kcol] = pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
122 fCellCount[idet][ismn][jrow][kcol] = pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
123 fNhitCell[idet][ismn][jrow][kcol] = pmdcalibgain.fNhitCell[idet][ismn][jrow][kcol]; //za
124 fPedMeanRMS[idet][ismn][jrow][kcol] = pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
125 fHotFlag[idet][ismn][jrow][kcol] = pmdcalibgain.fHotFlag[idet][ismn][jrow][kcol];
134 // ------------------------------------------------------------------------ //
135 AliPMDCalibGain::~AliPMDCalibGain()
140 // ------------------------------------------------------------------------ //
142 Int_t AliPMDCalibGain::ExtractPedestal(const Char_t *rootFile)
144 // Pedestal extraction from the PMD_PED.root file
145 // To be called once at the beginning
147 Int_t det=0, sm=0, row=0, col=0;
148 Float_t mean=0., rms=0.;
150 TFile *pedfile = new TFile(rootFile);
154 printf("ERROR --- NO PEDESTAL (PMD_PED1.root) FILE IS FOUND --- STOP GAIN DA\n");
159 TTree *ped =(TTree*)pedfile->Get("ped");
161 ped->SetBranchAddress("det",&det);
162 ped->SetBranchAddress("sm",&sm);
163 ped->SetBranchAddress("row",&row);
164 ped->SetBranchAddress("col",&col);
165 ped->SetBranchAddress("mean",&mean);
166 ped->SetBranchAddress("rms",&rms);
168 Int_t nentries = (Int_t)ped->GetEntries();
170 for (Int_t ient = 0; ient < nentries; ient++)
173 fPedMeanRMS[det][sm][row][col] = mean + 3.*rms;
174 //printf("Mean= %f, RMS= %f, PedMeanRMS=%f\n",mean,rms,fPedMeanRMS[det][sm][row][col]);
184 //------------------------------------------------------------------------------------------------
186 Int_t AliPMDCalibGain::ExtractHotChannel(const Char_t *rootFile)
188 // HotChannel extraction from the PMD_HOT.root file
189 // To be called once at the beginning
191 Int_t det=0, sm=0, row=0, col=0;
194 TFile *hotmapfile = new TFile(rootFile);
198 printf(" NO HOTCHANNEL MAP (PMD_HOT.root) FILE IS FOUND \n");
200 for (Int_t idet = 0; idet < kDet; idet++)
202 for (Int_t ismn = 0; ismn < kMaxSMN; ismn++)
204 for (Int_t irow = 0; irow < kMaxRow; irow++)
206 for (Int_t icol = 0; icol < kMaxCol; icol++)
208 fHotFlag[idet][kMaxSMN][kMaxRow][kMaxCol] = 0.;
216 TTree *hot =(TTree*)hotmapfile->Get("hot");
218 hot->SetBranchAddress("det",&det);
219 hot->SetBranchAddress("sm",&sm);
220 hot->SetBranchAddress("row",&row);
221 hot->SetBranchAddress("col",&col);
222 hot->SetBranchAddress("flag",&flag);
224 Int_t nentries = (Int_t)hot->GetEntries();
226 for (Int_t ient = 0; ient < nentries; ient++)
229 fHotFlag[det][sm][row][col] = flag;
231 //printf(" HotFlag=%f\n",fHotFlag[det][sm][row][col]);
242 // ------------------------------------------------------------------------ //
244 void AliPMDCalibGain::ReadTempFile(const Char_t *tempFile)
246 // Read the variables from the file
249 intmpfile.open(tempFile);
251 Int_t iddet = 0, issm = 0, irrow = 0, iccol = 0;
252 Float_t smcount = 0., smiso = 0.;
253 Float_t cellcount = 0., celliso = 0.;
256 for (Int_t idet = 0; idet < kDet; idet++)
258 for (Int_t ism = 0; ism < kMaxSMN; ism++)
260 intmpfile >> iddet >> issm >> smcount >> smiso;
261 fSMCount[idet][ism] = smcount;
262 fSMIso[idet][ism] = smiso;
266 for (Int_t idet = 0; idet < kDet; idet++)
268 for (Int_t ism = 0; ism < kMaxSMN; ism++)
270 for (Int_t irow = 0; irow < kMaxRow; irow++)
272 for (Int_t icol = 0; icol < kMaxCol; icol++)
274 intmpfile >> iddet >> issm >> irrow >> iccol
275 >> cellcount >> celliso;
276 fCellCount[idet][ism][irow][icol] = cellcount;
277 fCellIso[idet][ism][irow][icol] = celliso;
287 // ------------------------------------------------------------------------ //
288 void AliPMDCalibGain::WriteTempFile(const Char_t *tempFile)
290 // Write the Temporary file if the required statics is not achieved
294 Following variables to be written to a file
297 fCellIso[idet][ismn][irow][icol];
300 fSMCount[idet][ismn];
301 fCellCount[idet][ismn][irow][icol];
305 fpw = fopen(tempFile,"w+");
307 for (Int_t idet = 0; idet < kDet; idet++)
309 // fprintf(fpw,"%d %f %f\n",idet,fDetCount[idet],fDetIso[idet]);
312 for (Int_t idet = 0; idet < kDet; idet++)
314 for (Int_t ism = 0; ism < kMaxSMN; ism++)
316 fprintf(fpw,"%d %d %f %f\n",idet,ism, fSMCount[idet][ism],fSMIso[idet][ism]);
320 for (Int_t idet = 0; idet < kDet; idet++)
322 for (Int_t ism = 0; ism < kMaxSMN; ism++)
324 for (Int_t irow = 0; irow < kMaxRow; irow++)
326 for (Int_t icol = 0; icol < kMaxCol; icol++)
328 fprintf(fpw,"%d %d %d %d %f %f\n",idet,ism,irow,icol,
329 fCellCount[idet][ism][irow][icol],
330 fCellIso[idet][ism][irow][icol]);
340 // ------------------------------------------------------------------------ //
342 Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlcont)
344 // Calculates the ADC of isolated cell
346 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
347 const Int_t kCellNeighbour = 6;
348 Int_t neibx[6] = {1,0,-1,-1,0,1};
349 Int_t neiby[6] = {0,1,1,0,-1,-1};
351 Int_t id1 = 0,jd1 = 0; //neighbour row/col
352 Int_t isocount = 0; //number of neighbours with 0 signal
354 Float_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
356 for(Int_t idet = 0; idet < kDet; idet++)
358 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
360 for(Int_t irow = 0; irow < kMaxRow; irow++)
362 for(Int_t icol = 0; icol < kMaxCol; icol++)
364 d1[idet][ismn][irow][icol] = 0.;
370 AliPMDRawStream rawStream(rawReader);
374 Int_t numberofDDLs = 0;
376 while ((iddl = rawStream.DdlData(pmdddlcont)) >=0) {
379 Int_t ientries = pmdddlcont->GetEntries();
381 for (Int_t ient = 0; ient < ientries; ient++)
383 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont->UncheckedAt(ient);
385 Int_t idet = pmdddl->GetDetector();
386 Int_t ismn = pmdddl->GetSMN();
387 Int_t mcm = pmdddl->GetMCM();
388 //Int_t ichno = pmdddl->GetChannel();
389 Int_t irow = pmdddl->GetRow();
390 Int_t icol = pmdddl->GetColumn();
391 Int_t isig = pmdddl->GetSignal();
393 // This is the protection not to crash the code
395 if(mcm == 0) continue;
396 if (irow < 0 || icol < 0 || irow > 47 || icol > 95) continue;
398 // Pedestal subtraction
399 if(fHotFlag[idet][ismn][irow][icol] == 1.0) isig = 0;
403 d1[idet][ismn][irow][icol] =
404 (Float_t) isig - fPedMeanRMS[idet][ismn][irow][icol];
406 //printf("Signal_ped_subtracted=%f, pedestal=%f\n",d1[idet][ismn][irow][icol]),fPedMeanRMS[idet][ismn][irow][icol];
408 fNhitCell[idet][ismn][irow][icol]++; //cell hit frequency
413 pmdddlcont->Delete();
416 for(Int_t idet=0; idet < kDet; idet++)
418 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
420 for(Int_t irow = 0; irow < kMaxRow; irow++)
422 for(Int_t icol = 0; icol < kMaxCol; icol++)
424 if(d1[idet][ismn][irow][icol] > 0)
427 for(Int_t ii = 0; ii < kCellNeighbour; ii++)
429 id1 = irow + neibx[ii];
430 jd1 = icol + neiby[ii];
431 if (id1 < 0) id1 = 0;
432 if (id1 > kMaxRow-1) id1 = kMaxRow - 1;
433 if (jd1 < 0) jd1 = 0;
434 if (jd1 > kMaxCol-1) jd1 = kMaxCol - 1;
435 if(d1[idet][ismn][id1][jd1] == 0)
438 if(isocount == kCellNeighbour)
440 //fDetIso[idet] += d1[idet][ismn][irow][icol];
441 fSMIso[idet][ismn] += d1[idet][ismn][irow][icol];
442 fCellIso[idet][ismn][irow][icol] += d1[idet][ismn][irow][icol];
444 fSMCount[idet][ismn]++;
445 fCellCount[idet][ismn][irow][icol]++;
449 } // neigh cell cond.
456 for(Int_t idet=0; idet < kDet; idet++)
458 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
460 for(Int_t irow = 0; irow < kMaxRow; irow++)
462 for(Int_t icol = 0; icol < kMaxCol; icol++)
464 if(fNhitCell[idet][ismn][irow][icol]>0)
466 fCountSm[idet][ismn] += 1;
467 fTempnhit[idet][ismn] += fNhitCell[idet][ismn][irow][icol];
468 fTempnhitSq[idet][ismn] += fNhitCell[idet][ismn][irow][icol]
469 *fNhitCell[idet][ismn][irow][icol];
476 if (numberofDDLs < kDDL) return kFALSE;
480 // ------------------------------------------------------------------------ //
481 void AliPMDCalibGain::Analyse(TTree *gaintree, TTree *meantree)
483 // Calculates the mean
484 Int_t det = 0, sm = 0, row = 0, col = 0;
486 Float_t cellmean = 0.;
488 Float_t modmean[2][24];
490 for (Int_t idet=0; idet < 2; idet++)
492 for (Int_t ism = 0; ism < 24; ism++)
494 modmean[idet][ism] = 0.;
498 gaintree->Branch("det",&det,"det/I");
499 gaintree->Branch("sm",&sm,"sm/I");
500 gaintree->Branch("row",&row,"row/I");
501 gaintree->Branch("col",&col,"col/I");
502 gaintree->Branch("gain",&gain,"gain/F");
504 for(Int_t idet = 0; idet < kDet; idet++)
506 for(Int_t ism = 0; ism < kMaxSMN; ism++)
508 if (fSMCount[idet][ism] > 0)
509 modmean[idet][ism] = fSMIso[idet][ism]/fSMCount[idet][ism];
510 for(Int_t irow = 0; irow < kMaxRow; irow++)
512 for(Int_t icol = 0; icol < kMaxCol; icol++)
514 if (fCellCount[idet][ism][irow][icol] > 0.)
516 cellmean = fCellIso[idet][ism][irow][icol]/fCellCount[idet][ism][irow][icol];
522 if (cellmean > 0.0 && fCellCount[idet][ism][irow][icol]>0.)
524 gain = cellmean/modmean[idet][ism];
530 //if(fCellCount[idet][ism][irow][icol]>0.) printf("CellCount =%f, gain= %f\n",fCellCount[idet][ism][irow][icol],gain);
539 // Writing each module mean value
540 meantree->Branch("det",&det,"det/I");
541 meantree->Branch("sm",&sm,"sm/I");
542 meantree->Branch("smmean",&smmean,"row/F");
544 for(Int_t idet = 0; idet < kDet; idet++)
546 for (Int_t ism = 0; ism < kMaxSMN; ism++)
550 smmean = modmean[idet][ism];
556 // ------------------------------------------------------------------------ //
557 void AliPMDCalibGain::FindHotCell(TTree *hottree, Float_t xvar)
559 // Calculates the mean
560 Int_t det = 0, sm = 0, row = 0, col = 0;
562 Float_t meannhit = 0.;
563 Float_t meanSqnhit = 0.;
564 Float_t sigmanhit = 0.,nhitcut = 0.;
568 hottree->Branch("det",&det,"det/I");
569 hottree->Branch("sm",&sm,"sm/I");
570 hottree->Branch("row",&row,"row/I");
571 hottree->Branch("col",&col,"col/I");
572 hottree->Branch("flag",&flag,"flag/F");
574 for(Int_t idet = 0; idet < kDet; idet++)
576 for(Int_t ism = 0; ism < kMaxSMN; ism++)
578 if (fCountSm[idet][ism]> 0)
580 meannhit = fTempnhit[idet][ism]/fCountSm[idet][ism];
581 meanSqnhit = fTempnhitSq[idet][ism]/fCountSm[idet][ism];
582 sigmanhit = sqrt(meanSqnhit-(meannhit*meannhit));
583 nhitcut = meannhit + xvar*sigmanhit;
585 for(Int_t irow = 0; irow < kMaxRow; irow++)
587 for(Int_t icol = 0; icol < kMaxCol; icol++)
594 if(fNhitCell[idet][ism][irow][icol] > nhitcut)