1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////////////////////////////////////////////
18 // AliTRDCalibChamberStatus: to determine which half chambers are off //
19 // Produce a AliTRDCalChamberStatus calibration object //
20 // Check with the AliTRDCalDCSFEE info //
24 // J. Book (jbook@ikf.uni-frankfurt.de) //
25 // R. Bailhache (rbailhache@ikf.uni-frankfurt.de) //
27 ////////////////////////////////////////////////////////////////////////////
31 #include <THnSparse.h>
33 #include <TDirectory.h>
41 #include "AliRawReader.h"
45 #include "AliTRDCalibChamberStatus.h"
46 #include "AliTRDgeometry.h"
47 #include "AliTRDfeeParam.h"
48 #include "AliTRDdigitsManager.h"
49 #include "AliTRDSignalIndex.h"
50 #include "AliTRDpadPlane.h"
51 #include "./Cal/AliTRDCalChamberStatus.h"
52 #include "./Cal/AliTRDCalDCS.h"
53 #include "./Cal/AliTRDCalDCSFEE.h"
55 #include "AliTRDrawStream.h"
61 ClassImp(AliTRDCalibChamberStatus) /*FOLD00*/
63 //_____________________________________________________________________
64 AliTRDCalibChamberStatus::AliTRDCalibChamberStatus() : /*FOLD00*/
68 fCounterEventNotEmpty(0),
69 fCalChamberStatus(0x0),
79 // default constructor
83 //_____________________________________________________________________
84 AliTRDCalibChamberStatus::AliTRDCalibChamberStatus(const AliTRDCalibChamberStatus &ped) : /*FOLD00*/
86 fDetector(ped.fDetector),
87 fNumberOfTimeBins(ped.fNumberOfTimeBins),
88 fCounterEventNotEmpty(ped.fCounterEventNotEmpty),
89 fCalChamberStatus(ped.fCalChamberStatus),
90 fHnSparseI(ped.fHnSparseI),
91 fHnSparseHCM(ped.fHnSparseHCM),
92 fHnSparseEvtDet(ped.fHnSparseEvtDet),
93 fHnSparseDebug(ped.fHnSparseDebug),
94 fHnSparseMCM(ped.fHnSparseMCM),
96 fDebugLevel(ped.fDebugLevel)
103 //_____________________________________________________________________
104 AliTRDCalibChamberStatus& AliTRDCalibChamberStatus::operator = (const AliTRDCalibChamberStatus &source)
107 // assignment operator
109 if (&source == this) return *this;
110 new (this) AliTRDCalibChamberStatus(source);
114 //_____________________________________________________________________
115 AliTRDCalibChamberStatus::~AliTRDCalibChamberStatus() /*FOLD00*/
120 if(fCalChamberStatus){
121 delete fCalChamberStatus;
129 if(fHnSparseEvtDet) {
130 delete fHnSparseEvtDet;
133 delete fHnSparseDebug;
143 //_____________________________________________________________________
144 void AliTRDCalibChamberStatus::Init()
147 // Init the different THnSparse
152 // Init the fHnSparseI
156 Int_t thnDimEvt[4]; // sm, layer, stack, halfchamber
161 //arrays for lower bounds :
162 Double_t* binEdgesEvt[4];
163 for(Int_t ivar = 0; ivar < 4; ivar++)
164 binEdgesEvt[ivar] = new Double_t[thnDimEvt[ivar] + 1];
165 //values for bin lower bounds
166 for(Int_t i=0; i<=thnDimEvt[0]; i++) binEdgesEvt[0][i]= 0.0 + (18.0)/thnDimEvt[0]*(Double_t)i;
167 for(Int_t i=0; i<=thnDimEvt[1]; i++) binEdgesEvt[1][i]= 0.0 + (6.0)/thnDimEvt[1]*(Double_t)i;
168 for(Int_t i=0; i<=thnDimEvt[2]; i++) binEdgesEvt[2][i]= 0.0 + (5.0)/thnDimEvt[2]*(Double_t)i;
169 for(Int_t i=0; i<=thnDimEvt[3]; i++) binEdgesEvt[3][i]= 0.0 + (2.0)/thnDimEvt[3]*(Double_t)i;
171 //create the THnSparse
172 fHnSparseI = new THnSparseI("NumberOfEntries","NumberOfEntries",4,thnDimEvt);
173 for (int k=0; k<4; k++) {
174 fHnSparseI->SetBinEdges(k,binEdgesEvt[k]);
179 // Init the fHnSparseHCM (THnSparseI)
182 //create the THnSparse
183 fHnSparseHCM = new THnSparseI("HCMerrors","HCMerrors",4,thnDimEvt);
184 for (int k=0; k<4; k++) {
185 fHnSparseHCM->SetBinEdges(k,binEdgesEvt[k]);
187 fHnSparseHCM->Sumw2();
192 if(fDebugLevel > 0) {
195 // Init the fHnSparseEvtDet (THnSparseI)
199 Int_t thnDimEvts[3]; // event, detector, halfchamber
200 thnDimEvts[0] = 10000;
203 //arrays for lower bounds :
204 Double_t* binEdgesEvts[3];
205 for(Int_t ivar = 0; ivar < 3; ivar++)
206 binEdgesEvts[ivar] = new Double_t[thnDimEvts[ivar] + 1];
207 //values for bin lower bounds
208 for(Int_t i=0; i<=thnDimEvts[0]; i++) binEdgesEvts[0][i]= 0.0 + (10000.0)/thnDimEvts[0]*(Double_t)i;
209 for(Int_t i=0; i<=thnDimEvts[1]; i++) binEdgesEvts[1][i]= 0.0 + (540.0)/thnDimEvts[1]*(Double_t)i;
210 for(Int_t i=0; i<=thnDimEvts[2]; i++) binEdgesEvts[2][i]= 0.0 + (2.0)/thnDimEvts[2]*(Double_t)i;
212 //create the THnSparse
213 fHnSparseEvtDet = new THnSparseI("NumberOfEntriesPerEvent","NumberOfEntriesPerEvent",3,thnDimEvts);
214 for (int k=0; k<3; k++) {
215 fHnSparseEvtDet->SetBinEdges(k,binEdgesEvts[k]);
217 fHnSparseEvtDet->Sumw2();
220 // Init the fHnSparseDebug (THnSparseI)
223 //create the THnSparse
224 fHnSparseDebug = new THnSparseI("NumberOfDifferentDecisions","NumberOfDifferentDecisions",4,thnDimEvt);
225 for (int k=0; k<4; k++) {
226 fHnSparseDebug->SetBinEdges(k,binEdgesEvt[k]);
228 fHnSparseDebug->Sumw2();
231 // Init the fHnSparseMCM (THnSparseI)
235 Int_t thnDimEvtt[6]; // sm, layer, stack, ROB, MCM
242 //arrays for lower bounds :
243 Double_t* binEdgesEvtt[6];
244 for(Int_t ivar = 0; ivar < 6; ivar++)
245 binEdgesEvtt[ivar] = new Double_t[thnDimEvtt[ivar] + 1];
246 //values for bin lower bounds
247 for(Int_t i=0; i<=thnDimEvtt[0]; i++) binEdgesEvtt[0][i]= 0.0 + (18.0)/thnDimEvtt[0]*(Double_t)i;
248 for(Int_t i=0; i<=thnDimEvtt[1]; i++) binEdgesEvtt[1][i]= 0.0 + (6.0)/thnDimEvtt[1]*(Double_t)i;
249 for(Int_t i=0; i<=thnDimEvtt[2]; i++) binEdgesEvtt[2][i]= 0.0 + (5.0)/thnDimEvtt[2]*(Double_t)i;
250 for(Int_t i=0; i<=thnDimEvtt[3]; i++) binEdgesEvtt[3][i]= 0.0 + (8.0)/thnDimEvtt[3]*(Double_t)i;
251 for(Int_t i=0; i<=thnDimEvtt[4]; i++) binEdgesEvtt[4][i]= 0.0 + (18.0)/thnDimEvtt[4]*(Double_t)i;
252 for(Int_t i=0; i<=thnDimEvtt[5]; i++) binEdgesEvtt[5][i]= 0.0 + (18.0)/thnDimEvtt[5]*(Double_t)i;
254 //create the THnSparse
255 fHnSparseMCM = new THnSparseI("MCMerrorDCS","MCMerrorDCS",6,thnDimEvtt);
256 for (int k=0; k<6; k++) {
257 fHnSparseMCM->SetBinEdges(k,binEdgesEvtt[k]);
259 fHnSparseMCM->Sumw2();
266 //_____________________________________________________________________
267 void AliTRDCalibChamberStatus::ProcessEvent(AliRawReader * rawReader, Int_t nevents_physics)
270 // Event Processing loop with AliTRDrawStream
274 Bool_t notEmpty = kFALSE;
276 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
277 digitsManager->CreateArrays();
279 AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
280 rawStream->SetDigitsManager(digitsManager);
281 // rawStream->SetNoErrorWarning();
282 // rawStream->SetSharedPadReadout(kFALSE);
286 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) {
290 // do the QA analysis
291 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
292 // printf("there is ADC data on this chamber!\n");
294 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
295 if (indexes->IsAllocated() == kFALSE) {
296 // AliError("Indexes do not exist!");
302 indexes->ResetCounters();
304 while (indexes->NextRCIndex(iRow, iCol)){
305 Int_t iMcm = (Int_t)(iCol/18); // current group of 18 col pads
307 Int_t layer = AliTRDgeometry::GetLayer(det);
308 Int_t sm = AliTRDgeometry::GetSector(det);
309 Int_t stac = AliTRDgeometry::GetStack(det);
311 if(iMcm > 3) rphi = 1.5;
313 Double_t val[4] = {sm,layer,stac,rphi};
314 fHnSparseI->Fill(&val[0]);
319 if(fDebugLevel > 0) {
320 Int_t detector = AliTRDgeometry::GetDetector(layer,stac,sm);
321 Double_t valu[3] = {nevents_physics,detector,rphi};
322 fHnSparseEvtDet->Fill(&valu[0]);
329 digitsManager->ClearArrays(det);
332 if(notEmpty) fCounterEventNotEmpty++;
334 delete digitsManager;
338 //_____________________________________________________________________
339 Bool_t AliTRDCalibChamberStatus::TestEventHisto(Int_t nevent) /*FOLD00*/
343 // fill the fHnSparseI with entries
349 for(Int_t ievent=0; ievent<nevent; ievent++){
350 for (Int_t ism=0; ism<18; ism++){
351 for (Int_t istack=0; istack<5; istack++){
352 for (Int_t ipl=0; ipl<6; ipl++){
353 for (Int_t icol=0; icol<geo.GetColMax(ipl); icol++){
355 if(icol > 72) side = 1;
356 Double_t val[4] = {ism,ipl,istack,side};
357 fHnSparseI->Fill(&val[0]);
367 //_____________________________________________________________________
368 void AliTRDCalibChamberStatus::AnalyseHisto() /*FOLD00*/
371 // Create the AliTRDCalChamberStatus according to the fHnSparseI
374 if(fCalChamberStatus) delete fCalChamberStatus;
375 fCalChamberStatus = new AliTRDCalChamberStatus();
377 // Check if enough events to say something
378 if(fCounterEventNotEmpty < 200) {
380 for (Int_t ism=0; ism<18; ism++) {
381 for (Int_t ipl=0; ipl<6; ipl++) {
382 for (Int_t istack=0; istack<5; istack++) {
383 // layer, stack, sector
384 Int_t det = AliTRDgeometry::GetDetector(ipl,istack,ism);
385 fCalChamberStatus->SetStatus(det,1);
392 // Mask out all chambers
393 for (Int_t ism=0; ism<18; ism++) {
394 for (Int_t ipl=0; ipl<6; ipl++) {
395 for (Int_t istack=0; istack<5; istack++) {
396 // layer, stack, sector
397 Int_t det = AliTRDgeometry::GetDetector(ipl,istack,ism);
398 fCalChamberStatus->SetStatus(det,2);
403 // Unmask good chambers
405 for(Int_t bin = 0; bin < fHnSparseI->GetNbins(); bin++) {
407 fHnSparseI->GetBinContent(bin,coord);
408 // layer, stack, sector
409 Int_t detector = AliTRDgeometry::GetDetector(coord[1]-1,coord[2]-1,coord[0]-1);
412 // Check which halfchamber side corresponds to the bin number (0=A, 1=B)
413 // Change the status accordingly
416 switch(fCalChamberStatus->GetStatus(detector))
418 case 1: break; // no changes
421 fCalChamberStatus->SetStatus(detector,4); break; // only SideB is masked
424 fCalChamberStatus->SetStatus(detector,3); break; // only SideA is masked
426 case 3: fCalChamberStatus->SetStatus(detector,1); break; // unmask SideA
427 case 4: fCalChamberStatus->SetStatus(detector,1); break; // unmask SideB
433 //_____________________________________________________________________
434 void AliTRDCalibChamberStatus::CheckEORStatus(AliTRDCalDCS *calDCS) /*FOLD00*/
437 // Correct the AliTRDCalChamberStatus according to the AliTRDCalDCS
438 // Using globale state of the HalfChamberMerger (HCM)
440 for(Int_t det = 0; det < 540; det++) {
441 AliTRDCalDCSFEE* calDCSFEEEOR = calDCS->GetCalDCSFEEObj(det);
443 if(!calDCSFEEEOR) continue;
445 // MCM Global State Machine State Definitions
457 Int_t sm = AliTRDgeometry::GetSector(det);
458 Int_t lay = AliTRDgeometry::GetLayer(det);
459 Int_t stac = AliTRDgeometry::GetStack(det);
461 Int_t stateA = 0; // 0=bad, 1=good state
464 // loop over all mcm to define DCS-HCS
465 for(Int_t ii = 0; ii < 8; ii++) { //ROB loop
466 for(Int_t i = 0; i < 18; i++) { //MCM loop
468 Int_t side = ii%2; // 0=sideA, 1=sideB
469 Int_t cstate = calDCSFEEEOR->GetMCMGlobalState(ii,i); //current mcm state
473 case 0: stateA=1; break;
474 case 1: stateB=1; break;
482 if(fDebugLevel > 0) {
483 if( ((fCalChamberStatus->GetStatus(det) <= 1) && (stateA==0 || stateB==0)) ||
484 ((fCalChamberStatus->GetStatus(det) == 2) && (stateA==1 || stateB==1)) ||
485 ((fCalChamberStatus->GetStatus(det) == 3) && (stateA==1 || stateB==0)) ||
486 ((fCalChamberStatus->GetStatus(det) == 4) && (stateB==0 || stateB==1)) )
488 //printf(" Different half chamber status in DCS and DATA!!\n");
489 Double_t val[4] = {sm,lay,stac,1};
490 fHnSparseDebug->Fill(&val[0]);
492 // Fill MCM status map
493 for(Int_t ii = 0; ii < 8; ii++) { //ROB loop
494 for(Int_t i = 0; i < 18; i++) { //MCM loop
495 Double_t valss[6] = {sm,lay,stac,ii,i
496 ,calDCSFEEEOR->GetMCMGlobalState(ii,i)};
497 fHnSparseMCM->Fill(&valss[0]);
506 //---------------------------------------
507 // Change the status according to DCS
508 //---------------------------------------
509 Int_t StatusData = fCalChamberStatus->GetStatus(det);
513 if(stateA==0 && stateB==0) fCalChamberStatus->SetStatus(det,2); // completely masked from DCS
514 if(stateA==1 && stateB==0) fCalChamberStatus->SetStatus(det,4); // Only B side masked from DCS
515 if(stateA==0 && stateB==1) fCalChamberStatus->SetStatus(det,3); // Only A side masked from DCS
516 if(stateA==1 && stateB==1) fCalChamberStatus->SetStatus(det,1);
518 case 2: // completely masked from DATA
519 if(stateA==0 && stateB==0) fCalChamberStatus->SetStatus(det,2); // completely masked from DCS
521 case 3: // Only A side masked from DATA
522 if(stateA==0 && stateB==0) fCalChamberStatus->SetStatus(det,2); // completely masked from DCS
523 if(stateA==1 && stateB==0) fCalChamberStatus->SetStatus(det,2); // Only B side masked from DCS
524 if(stateA==0 && stateB==1) fCalChamberStatus->SetStatus(det,3); // Only A side masked from DCS
525 if(stateA==1 && stateB==1) fCalChamberStatus->SetStatus(det,3);
527 case 4: // Only B side masked from DATA
528 if(stateA==0 && stateB==0) fCalChamberStatus->SetStatus(det,2); // completely masked from DCS
529 if(stateA==1 && stateB==0) fCalChamberStatus->SetStatus(det,4); // Only B side masked from DCS
530 if(stateA==0 && stateB==1) fCalChamberStatus->SetStatus(det,2); // Only A side masked from DCS
531 if(stateA==1 && stateB==1) fCalChamberStatus->SetStatus(det,4);
539 //_____________________________________________________________________________________
540 void AliTRDCalibChamberStatus::Add(AliTRDCalibChamberStatus *calibChamberStatus) /*FOLD00*/
543 // Add the THnSparseI of this calibChamberStatus
546 fCounterEventNotEmpty += calibChamberStatus->GetNumberEventNotEmpty();
548 THnSparseI *hnSparseI = calibChamberStatus->GetSparseI();
549 if(!hnSparseI) return;
552 fHnSparseI = (THnSparseI *) hnSparseI->Clone();
555 fHnSparseI->Add(hnSparseI);
560 //_____________________________________________________________________
561 void AliTRDCalibChamberStatus::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
564 // Write class to file
575 TDirectory *backup = gDirectory;
576 TFile f(filename,option.Data());
578 if ( !sDir.IsNull() ){
579 f.mkdir(sDir.Data());
585 if ( backup ) backup->cd();
587 //_____________________________________________________________________________
588 TH2D* AliTRDCalibChamberStatus::PlotSparseI(Int_t sm,Int_t side)
591 // Plot number of entries for supermodule sm
592 // as a function of layer and stack
595 if(!fHnSparseI) return 0x0;
597 fHnSparseI->GetAxis(0)->SetRange(sm+1,sm+1);
598 fHnSparseI->GetAxis(3)->SetRange(side+1,side+1);
599 TH2D *h2 = fHnSparseI->Projection(1,2);
605 //_____________________________________________________________________
606 TH2F *AliTRDCalibChamberStatus::MakeHisto2DSmPlEORStatus(AliTRDCalDCS *calDCS, Int_t sm, Int_t pl) /*FOLD00*/
609 // Plot globale state of the HalfChamberMerger (HCM)
611 AliTRDfeeParam *paramfee = AliTRDfeeParam::Instance();
613 AliTRDgeometry *trdGeo = new AliTRDgeometry();
614 AliTRDpadPlane *padPlane0 = trdGeo->GetPadPlane(pl,0); // layer,stack
615 Double_t row0 = padPlane0->GetRow0();
616 Double_t col0 = padPlane0->GetCol0();
619 snprintf(name,1000,"%s DCS status sm %d pl %d",GetTitle(),sm,pl);
620 TH2F * his = new TH2F( name, name, 88,-TMath::Abs(row0),TMath::Abs(row0)
621 ,148,-TMath::Abs(col0),TMath::Abs(col0));
625 Int_t offsetsmpl = 30*sm+pl;
629 for (Int_t k = 0; k < nstack; k++){
630 Int_t det = offsetsmpl+k*6;
631 Int_t stac = AliTRDgeometry::GetStack(det);
632 AliTRDCalDCSFEE* calDCSFEEEOR = calDCS->GetCalDCSFEEObj(det);
633 if(!calDCSFEEEOR) { continue;}
634 for (Int_t icol=0; icol<ncols; icol++){
636 if(stac==2) nrows = 12;
637 for (Int_t irow=0; irow<nrows; irow++){
640 Int_t krow = nrows-1-irow;
641 Int_t kcol = ncols-1-icol;
642 if(kb > 2) binz = 16*(kb-1)+12+krow+1+2*(kb+1);
643 else binz = 16*kb+krow+1+2*(kb+1);
644 Int_t biny = kcol+1+2;
646 Int_t mcm = paramfee->GetMCMfromPad(irow,icol);
647 Int_t rob = paramfee->GetROBfromPad(irow,icol);
648 if(mcm < 0) AliWarning("Problem with mcm number");
649 Int_t state = calDCSFEEEOR->GetMCMGlobalState(rob,TMath::Abs(mcm));
650 his->SetBinContent(binz,biny,state);
653 for(Int_t icol = 1; icol < 147; icol++){
654 for(Int_t l = 0; l < 2; l++){
657 if(kb > 2) binz = 16*(kb-1)+12+1+2*(kb+1)-(l+1);
658 else binz = 16*kb+1+2*(kb+1)-(l+1);
659 his->SetBinContent(binz,icol,16.0);
664 for(Int_t icol = 1; icol < 147; icol++){
665 his->SetBinContent(88,icol,16.0);
666 his->SetBinContent(87,icol,16.0);
668 for(Int_t irow = 1; irow < 89; irow++){
669 his->SetBinContent(irow,1,16.0);
670 his->SetBinContent(irow,2,16.0);
671 his->SetBinContent(irow,147,16.0);
672 his->SetBinContent(irow,148,16.0);
675 his->SetXTitle("z (cm)");
676 his->SetYTitle("y (cm)");
678 his->SetMinimum(0.0);
684 //_____________________________________________________________________________
685 TCanvas* AliTRDCalibChamberStatus::PlotHistos2DSmEORStatus(AliTRDCalDCS *calDCS, Int_t sm, const Char_t *name)
691 gStyle->SetPalette(1);
692 fC1 = new TCanvas(name,name,50,50,600,800);
695 MakeHisto2DSmPlEORStatus(calDCS,sm,0)->Draw("colz");
697 MakeHisto2DSmPlEORStatus(calDCS,sm,1)->Draw("colz");
699 MakeHisto2DSmPlEORStatus(calDCS,sm,2)->Draw("colz");
701 MakeHisto2DSmPlEORStatus(calDCS,sm,3)->Draw("colz");
703 MakeHisto2DSmPlEORStatus(calDCS,sm,4)->Draw("colz");
705 MakeHisto2DSmPlEORStatus(calDCS,sm,5)->Draw("colz");