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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONTriggerChamberEff
20 /// Implementation of the trigger chamber efficiency determination from
21 /// data, and returns the
22 /// efficiencyCells.dat with the calculated efficiencies
24 /// \author Diego Stocco (Torino)
25 //-----------------------------------------------------------------------------
27 #include "AliMUONTriggerChamberEff.h"
28 #include "AliMUONVDigit.h"
29 #include "AliMUONConstants.h"
30 #include "AliMUONTriggerTrack.h"
31 #include "AliMUONDigitMaker.h"
32 #include "AliMUONLocalTrigger.h"
33 #include "AliMUONGeometryTransformer.h"
35 #include "AliMUONTrack.h"
36 #include "AliMUONTrackParam.h"
37 #include "AliMUONTrackExtrap.h"
39 #include "AliMUONDigitStoreV1.h"
40 #include "AliMUONVDigitStore.h"
41 #include "AliMUONVTriggerStore.h"
42 #include "AliMUONVTriggerTrackStore.h"
43 #include "AliMUONVTrackStore.h"
45 #include "AliMpVSegmentation.h"
46 #include "AliMpSegmentation.h"
48 #include "AliMpDEIterator.h"
49 #include "AliMpPlaneType.h"
50 #include "AliMpDEManager.h"
51 #include "AliMpConstants.h"
53 #include "AliMpDDLStore.h"
55 #include "AliMpTriggerCrate.h"
56 #include "AliMpLocalBoard.h"
60 #include <Riostream.h>
65 #include <TSeqCollection.h>
73 #include <TPaveLabel.h>
78 ClassImp(AliMUONTriggerChamberEff)
81 //_____________________________________________________________________________
82 AliMUONTriggerChamberEff::AliMUONTriggerChamberEff()
86 fReproduceTrigResponse(kFALSE),
92 /// Default constructor
99 //_____________________________________________________________________________
100 AliMUONTriggerChamberEff::AliMUONTriggerChamberEff(const AliMUONGeometryTransformer* transformer,
101 const AliMUONDigitMaker* digitMaker,
104 fTransformer(transformer),
105 fDigitMaker(digitMaker),
106 fReproduceTrigResponse(kFALSE),
108 fWriteOnESD(writeOnESD),
110 fkMaxDistance(99999.)
112 /// Standard constructor
119 //_____________________________________________________________________________
120 AliMUONTriggerChamberEff::~AliMUONTriggerChamberEff()
123 Bool_t writeOnESD=fWriteOnESD;
125 if(writeOnESD) SaveInESDFile();
129 //_____________________________________________________________________________
130 AliMUONTriggerChamberEff::AliMUONTriggerChamberEff(const AliMUONTriggerChamberEff& other)
134 fReproduceTrigResponse(other.fReproduceTrigResponse),
135 fPrintInfo(other.fPrintInfo),
136 fWriteOnESD(other.fWriteOnESD),
137 fDebugLevel(other.fDebugLevel),
138 fkMaxDistance(other.fkMaxDistance),
139 fTrigger44(other.fTrigger44),
140 fTrigger34(other.fTrigger34)
144 for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
145 fInefficientSlat[chCath] = other.fInefficientSlat[chCath];
146 fHitPerSlat[chCath] = other.fHitPerSlat[chCath];
147 fInefficientBoard[chCath] = other.fInefficientBoard[chCath];
148 fHitPerBoard[chCath] = other.fHitPerBoard[chCath];
153 //_____________________________________________________________________________
154 AliMUONTriggerChamberEff& AliMUONTriggerChamberEff::operator=(const AliMUONTriggerChamberEff& other)
156 /// Asignment operator
157 // check assignement to self
161 // base class assignement
162 TObject::operator=(other);
166 fReproduceTrigResponse = other.fReproduceTrigResponse;
167 fPrintInfo = other.fPrintInfo;
168 fWriteOnESD = other.fWriteOnESD;
169 fDebugLevel = other.fDebugLevel;
171 fTrigger44 = other.fTrigger44;
172 fTrigger34 = other.fTrigger34;
174 for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
175 fInefficientSlat[chCath] = other.fInefficientSlat[chCath];
176 fHitPerSlat[chCath] = other.fHitPerSlat[chCath];
177 fInefficientBoard[chCath] = other.fInefficientBoard[chCath];
178 fHitPerBoard[chCath] = other.fHitPerBoard[chCath];
184 //_____________________________________________________________________________
185 void AliMUONTriggerChamberEff::ResetArrays()
188 /// Sets the data member counters to 0.
191 fTrigger44.Set(fgkNcathodes);
192 fTrigger34.Set(fgkNplanes);
194 for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
195 fInefficientSlat[chCath].Set(fgkNslats);
196 fHitPerSlat[chCath].Set(fgkNslats);
197 fInefficientBoard[chCath].Set(AliMpConstants::NofLocalBoards());
198 fHitPerBoard[chCath].Set(AliMpConstants::NofLocalBoards());
204 for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
205 fInefficientSlat[chCath].Reset();
206 fHitPerSlat[chCath].Reset();
207 fInefficientBoard[chCath].Reset();
208 fHitPerBoard[chCath].Reset();
213 //______________________________________________________________________________
215 AliMUONTriggerChamberEff::TriggerDigits(const AliMUONVTriggerStore& triggerStore,
216 AliMUONVDigitStore& digitStore) const
219 /// make (S)Digit for trigger
223 AliMUONLocalTrigger* locTrg;
224 TIter next(triggerStore.CreateLocalIterator());
226 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
228 if (locTrg->IsNull()) continue;
230 TArrayS xyPattern[fgkNcathodes];
231 locTrg->GetXPattern(xyPattern[0]);
232 locTrg->GetYPattern(xyPattern[1]);
234 Int_t nBoard = locTrg->LoCircuit();
235 fDigitMaker->TriggerDigits(nBoard, xyPattern, digitStore);
241 //_____________________________________________________________________________
242 void AliMUONTriggerChamberEff::InfoDigit(AliMUONVDigitStore& digitStore)
245 /// Prints information on digits (for debugging)
247 TIter next(digitStore.CreateIterator());
248 AliMUONVDigit* mDigit=0x0;
250 while ( ( mDigit = static_cast<AliMUONVDigit*>(next()) ) )
258 //_____________________________________________________________________________
259 Int_t AliMUONTriggerChamberEff::MatchingPad(AliMUONVDigitStore& digitStore, Int_t &detElemId,
260 Float_t coor[2], Bool_t isMatch[2],
261 TArrayI nboard[2], TArrayF &zRealMatch, Float_t y11)
264 /// Check slat and board number of digit matching track
267 enum {kBending, kNonBending};
269 Float_t minMatchDist[fgkNcathodes];
270 Int_t padsInCheckArea[fgkNcathodes];
272 for(Int_t cath=0; cath<fgkNcathodes; cath++){
273 isMatch[cath] = kFALSE;
274 minMatchDist[cath] = fkMaxDistance/10.;
275 padsInCheckArea[cath] = 0;
277 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
278 Int_t ch = iChamber-10;
279 Float_t oldDeltaZ = AliMUONConstants::DefaultChamberZ(iChamber) - AliMUONConstants::DefaultChamberZ(10);
281 Int_t iSlat = detElemId%100;
282 Int_t trigDigitBendPlane = -1;
283 Int_t foundDetElemId = detElemId;
284 Float_t foundZmatch=999.;
285 Float_t yCoorAtPadZ=999.;
287 TIter next(digitStore.CreateIterator());
288 AliMUONVDigit* mDigit;
291 while ( ( mDigit = static_cast<AliMUONVDigit*>(next()) ) )
294 Int_t currDetElemId = mDigit->DetElemId();
295 Int_t currCh = AliMpDEManager::GetChamberId(currDetElemId);
296 if(currCh!=iChamber) continue;
297 Int_t currSlat = currDetElemId%100;
298 Int_t slatDiff = TMath::Abs(currSlat-iSlat);
299 if(slatDiff>1 && slatDiff<17) continue; // Check neighbour slats
300 Int_t cathode = mDigit->Cathode();
301 Int_t ix = mDigit->PadX();
302 Int_t iy = mDigit->PadY();
303 Float_t xpad, ypad, zpad;
304 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()
305 ->GetMpSegmentation(currDetElemId,AliMp::GetCathodType(cathode));
307 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
308 Float_t xlocal1 = pad.Position().X();
309 Float_t ylocal1 = pad.Position().Y();
310 Float_t dpx = pad.Dimensions().X();
311 Float_t dpy = pad.Dimensions().Y();
312 fTransformer->Local2Global(currDetElemId, xlocal1, ylocal1, 0, xpad, ypad, zpad);
313 if(fDebugLevel>2)printf("DetElemId = %i\tCathode = %i\t(x,y) Pad = (%i,%i) = (%.2f,%.2f)\tDim = (%.2f,%.2f)\tTrack = (%.2f,%.2f)\n",currDetElemId,cathode,ix,iy,xpad,ypad,dpx,dpy,coor[0],coor[1]);
314 // searching track intersection with chambers (second approximation)
317 Float_t deltaZ = zpad - zRealMatch[0];
318 y = (coor[1]-y11)*deltaZ/oldDeltaZ + y11;
319 if(fDebugLevel>=3 && TMath::Abs(y-coor[1])>0.1)printf("oldDeltaZ = %7.2f newDeltaZ = %7.2f\toldY = %7.2f new y = %7.2f\n",oldDeltaZ,deltaZ,coor[1],y);
321 Float_t matchDist = PadMatchTrack(xpad, ypad, dpx, dpy, coor[0], y, ch);
322 if(matchDist<fkMaxDistance/2.) padsInCheckArea[cathode]++;
323 if(matchDist>minMatchDist[cathode])continue;
324 isMatch[cathode] = kTRUE;
325 minMatchDist[cathode] = matchDist;
326 foundDetElemId = currDetElemId;
329 if(cathode==kBending) trigDigitBendPlane = idigit;
330 for (Int_t loc=0; loc<pad.GetNofLocations(); loc++){
331 AliMpIntPair location = pad.GetLocation(loc);
332 nboard[cathode][loc] = location.GetFirst();
334 for(Int_t loc=pad.GetNofLocations(); loc<fgkNlocations; loc++){
335 nboard[cathode][loc]=-1;
339 for(Int_t cath=0; cath<fgkNcathodes; cath++){
340 if(padsInCheckArea[cath]>2) {
341 if(fDebugLevel>=1) printf("padsInCheckArea[%i] = %i\n",cath,padsInCheckArea[cath]);
346 if(isMatch[kBending] || isMatch[kNonBending]){
347 detElemId = foundDetElemId;
348 zRealMatch[ch] = foundZmatch;
349 coor[1] = yCoorAtPadZ;
351 Int_t whichCathode=kBending;
352 if(!isMatch[kBending])whichCathode=kNonBending;
355 return trigDigitBendPlane;
358 //_____________________________________________________________________________
359 Float_t AliMUONTriggerChamberEff::PadMatchTrack(Float_t xPad, Float_t yPad,
360 Float_t dpx, Float_t dpy,
361 Float_t xTrackAtPad, Float_t yTrackAtPad,
365 /// Decides if the digit belongs to the trigger track.
368 Float_t maxDist = 2.;//3. // cm
369 Float_t maxDistCheckArea = 6.; // cm
371 Float_t matchDist = fkMaxDistance;
373 Float_t deltaX = TMath::Abs(xPad-xTrackAtPad)-dpx;
374 Float_t deltaY = TMath::Abs(yPad-yTrackAtPad)-dpy;
375 Float_t maxDistX = maxDist;
376 Float_t maxDistY = maxDist;
378 if(fReproduceTrigResponse){
381 deltaX = TMath::Abs(xPad-xTrackAtPad);
382 deltaY = TMath::Abs(yPad-yTrackAtPad);
383 if(dpx<dpy && chamber>=2) maxDistX = 3.*dpx;// Non-bending plane: check the +- 1 strip between stations
384 if(dpy<dpx && chamber%2) maxDistY = 3.*dpy;// bending plane: check the +- 1 strip between planes in the same station
387 if(deltaX<=maxDistX && deltaY<=maxDistY) matchDist = TMath::Max(deltaX, deltaY);
388 else if(deltaX<=maxDistCheckArea && deltaY<=maxDistCheckArea) matchDist = fkMaxDistance/5.;
393 //_____________________________________________________________________________
394 void AliMUONTriggerChamberEff::CalculateEfficiency(Int_t trigger44, Int_t trigger34,
395 Float_t &efficiency, Float_t &error,
396 Bool_t failuresAsInput)
399 /// Returns the efficiency.
405 efficiency=(Double_t)trigger44/((Double_t)trigger34);
406 if(failuresAsInput)efficiency=1.-(Double_t)trigger44/((Double_t)trigger34);
408 Double_t q = TMath::Abs(1-efficiency);
409 if(efficiency<0)error=0.0;
410 else error = TMath::Sqrt(efficiency*q/((Double_t)trigger34));
414 //_____________________________________________________________________________
415 Int_t AliMUONTriggerChamberEff::DetElemIdFromPos(Float_t x, Float_t y,
416 Int_t chamber, Int_t cathode)
419 /// Given the (x,y) position in the chamber,
420 /// it returns the corresponding slat
423 Int_t resultingDetElemId = -1;
425 Float_t minDist = 999.;
426 for ( it.First(chamber-1); ! it.IsDone(); it.Next() ){
427 Int_t detElemId = it.CurrentDEId();
428 Int_t ich = detElemId/100-10;
429 Float_t tolerance=0.2*((Float_t)ich);
430 Float_t currDist=9999.;
432 const AliMpVSegmentation* seg =
433 AliMpSegmentation::Instance()
434 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
437 Float_t deltax = seg->Dimensions().X();
438 Float_t deltay = seg->Dimensions().Y();
439 Float_t xlocal1 = -deltax;
440 Float_t ylocal1 = -deltay;
441 Float_t xlocal2 = +deltax;
442 Float_t ylocal2 = +deltay;
443 Float_t xg01, yg01, zg1, xg02, yg02, zg2;
444 fTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg01, yg01, zg1);
445 fTransformer->Local2Global(detElemId, xlocal2, ylocal2, 0, xg02, yg02, zg2);
447 Float_t xg1 = xg01, xg2 = xg02, yg1 = yg01, yg2 = yg02;
458 if(x>=xg1-tolerance && x<=xg2+tolerance && y>=yg1-tolerance && y<=yg2+tolerance){ // takes into account errors in extrapolation
459 if(y<yg1) currDist = yg1-y;
460 else if(y>yg2) currDist = y-yg2;
461 if(currDist<minDist) {
462 resultingDetElemId = detElemId;
466 resultingDetElemId = detElemId;
469 } // loop on detElemId
470 return resultingDetElemId;
474 //_____________________________________________________________________________
475 void AliMUONTriggerChamberEff::LocalBoardFromPos(Float_t x, Float_t y,
476 Int_t detElemId, Int_t cathode,
480 /// Given the (x,y) position in the chamber,
481 /// it returns the corresponding local board
484 for(Int_t loc=0; loc<fgkNlocations; loc++){
488 fTransformer->Global2Local(detElemId, x, y, 0, xl, yl, zl);
490 const AliMpVSegmentation* seg =
491 AliMpSegmentation::Instance()
492 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
494 AliMpPad pad = seg->PadByPosition(pos,kFALSE);
495 for (Int_t loc=0; loc<pad.GetNofLocations(); loc++){
496 AliMpIntPair location = pad.GetLocation(loc);
497 localBoard[loc] = location.GetFirst();
503 //_____________________________________________________________________________
504 void AliMUONTriggerChamberEff::EventChamberEff(const AliMUONVTriggerStore& triggerStore,
505 const AliMUONVTriggerTrackStore& trigTrackStore,
506 const AliMUONVTrackStore& trackStore)
510 /// It loops over the the trigger rec. tracks in the event.
511 /// Then it search for matching digits around the track.
512 /// Finally it calculates the efficiency for each trigger board.
513 /// Files with calculated efficiency are placed in the user defined outputDir.
516 if(!fTransformer || ! fDigitMaker) {
517 AliError(Form("AliMUONGeometryTransformer or AliMUONDigitMaker not properly initialized!!"));
521 enum {kBending, kNonBending};
522 Float_t rad2deg = 180./TMath::Pi();
524 Int_t chOrder[fgkNchambers] = {0,2,1,3};
526 TArrayF zRealMatch(fgkNchambers);
527 TArrayF correctFactor(fgkNcathodes);
529 Bool_t match[fgkNchambers][fgkNcathodes];
530 Bool_t matchPad[fgkNcathodes];
531 for(Int_t cath=0; cath<fgkNcathodes; cath++){
532 matchPad[cath] = kFALSE;
535 TArrayF zMeanChamber(fgkNchambers);
536 for(Int_t ch=0; ch<fgkNchambers; ch++){
537 zMeanChamber[ch] = AliMUONConstants::DefaultChamberZ(10+ch);
540 TArrayI digitPerTrack(fgkNcathodes);
542 Float_t trackIntersectCh[fgkNchambers][fgkNcathodes];
544 TArrayI triggeredDigits[2];
545 for(Int_t itrack=0; itrack<2; itrack++){
546 triggeredDigits[itrack].Set(fgkNchambers);
547 triggeredDigits[itrack].Reset(-1);
550 TArrayI trigScheme[fgkNcathodes];
551 TArrayI slatThatTriggered[fgkNcathodes];
552 for(Int_t cath=0; cath<fgkNcathodes; cath++){
553 trigScheme[cath].Set(fgkNchambers);
554 slatThatTriggered[cath].Set(fgkNchambers);
557 Int_t boardThatTriggered[fgkNchambers][fgkNcathodes][fgkNlocations];
558 TArrayI nboard[fgkNcathodes];
559 for(Int_t cath=0; cath<fgkNcathodes; cath++){
560 nboard[cath].Set(fgkNlocations);
562 Int_t ineffBoard[fgkNlocations];
563 for(Int_t loc=0; loc<fgkNlocations; loc++){
564 ineffBoard[loc] = -1;
567 AliMUONDigitStoreV1 digitStore;
568 TriggerDigits(triggerStore,digitStore);
570 AliMUONTriggerTrack *recTrigTrack = 0x0;
572 TIter next(trigTrackStore.CreateIterator());
574 while ( ( recTrigTrack = static_cast<AliMUONTriggerTrack*>(next()) ) )
576 if(!IsCleanTrack(recTrigTrack, trackStore)) {
577 if(fDebugLevel>=1) printf("\tTrack %p (%f, %f) don't match tracker track: rejected!\n",(void *)recTrigTrack,recTrigTrack->GetX11(),recTrigTrack->GetY11());
581 digitPerTrack.Reset();
582 for(Int_t ch=0; ch<fgkNchambers; ch++){
583 zRealMatch[ch] = zMeanChamber[ch];
584 for(Int_t cath=0; cath<fgkNcathodes; cath++){
585 match[ch][cath]=kFALSE;
586 //slatThatTriggered[ch][cath]=-1;
587 //trigScheme[ch][cath] = 0;
588 for(Int_t loc=0; loc<fgkNlocations; loc++){
589 boardThatTriggered[ch][cath][loc]=-1;
594 for(Int_t cath=0; cath<fgkNcathodes; cath++){
595 slatThatTriggered[cath].Reset(-1);
596 trigScheme[cath].Reset();
599 Bool_t isClearEvent = kTRUE;
600 Bool_t doubleCountTrack = kFALSE;
602 Float_t x11 = recTrigTrack->GetX11();// x position (info from non-bending plane)
603 Float_t y11 = recTrigTrack->GetY11();// y position (info from bending plane)
604 Float_t thetaX = recTrigTrack->GetThetax();
605 Float_t thetaY = recTrigTrack->GetThetay();
607 if(fDebugLevel>=3) printf("\tTrack = %p\npos from track: (x,y) = (%f, %f), (thetaX, thetaY) = (%f, %f)\n",(void *)recTrigTrack,x11,y11,thetaX*rad2deg,thetaY*rad2deg);
609 for(Int_t ch=0; ch<fgkNchambers; ch++) { // chamber loop
610 Int_t currCh = chOrder[ch];
612 printf("zMeanChamber[%i] = %.2f\tzRealMatch[0] = %.2f\n",currCh,zMeanChamber[currCh],zRealMatch[0]);
614 for(Int_t cath=0; cath<fgkNcathodes; cath++){
615 correctFactor[cath]=1.;
617 // calculate corrections to trigger track theta
618 if(ch>=1)correctFactor[kNonBending] = zMeanChamber[0]/zRealMatch[0];// corrects x position
619 if(ch>=2)correctFactor[kBending] = (zMeanChamber[2] - zMeanChamber[0]) / (zRealMatch[2] - zRealMatch[0]);// corrects y position
621 // searching track intersection with chambers (first approximation)
622 Float_t deltaZ = zMeanChamber[currCh] - zMeanChamber[0];
623 trackIntersectCh[currCh][0] = zMeanChamber[currCh] * TMath::Tan(thetaX) * correctFactor[kNonBending];// x position (info from non-bending plane)
624 trackIntersectCh[currCh][1] = y11 + deltaZ * TMath::Tan(thetaY) * correctFactor[kBending];// y position (info from bending plane)
625 Int_t detElemIdFromTrack = DetElemIdFromPos(trackIntersectCh[currCh][0], trackIntersectCh[currCh][1], 11+currCh, 0);
626 if(detElemIdFromTrack<0) {
627 if(fDebugLevel>1) printf("Warning: trigger track outside trigger chamber\n");
631 triggeredDigits[1][currCh] = MatchingPad(digitStore, detElemIdFromTrack, trackIntersectCh[currCh], matchPad, nboard, zRealMatch, y11);
633 // if MatchingPad = -500 => too many digits matching pad =>
634 // => Event not clear => Reject track
635 if(triggeredDigits[1][currCh]<-100){
636 isClearEvent = kFALSE;
637 if(fDebugLevel>=1) printf("Warning: track = %p (%i) matches many pads. Rejected!\n",(void *)recTrigTrack, detElemIdFromTrack);
641 // deciding if digit matches track
642 Bool_t isDiffLocBoard = kFALSE;
643 if(fReproduceTrigResponse && ch>2){
644 for(Int_t cath=0; cath<fgkNcathodes; cath++){
645 if(boardThatTriggered[currCh][cath][0]>=0){
646 if(boardThatTriggered[currCh][cath][0]!=boardThatTriggered[currCh-1][cath][0]) isDiffLocBoard = kTRUE;
651 if(isDiffLocBoard && fDebugLevel>=1)printf("\tDifferent local board\n");
653 for(Int_t cath=0; cath<fgkNcathodes; cath++){
654 match[currCh][cath] = (matchPad[cath] && !isDiffLocBoard);
655 if(!match[currCh][cath]) continue;
656 digitPerTrack[cath]++;
657 trigScheme[cath][currCh]++;
658 slatThatTriggered[cath][currCh] = detElemIdFromTrack;
659 for(Int_t loc=0; loc<fgkNlocations; loc++){
660 boardThatTriggered[currCh][cath][loc] = nboard[cath][loc];
663 } // end chamber loop
665 for(Int_t cath=0; cath<fgkNcathodes; cath++){
666 if(digitPerTrack[cath]<3)isClearEvent = kFALSE;
667 if(fDebugLevel>=1 && !isClearEvent)printf("Warning: found %i digits for trigger track cathode %i.\nRejecting event\n", digitPerTrack[cath],cath);
670 if(!isClearEvent && !fReproduceTrigResponse) continue;
672 Int_t commonDigits = 0;
673 for(Int_t ch=0; ch<fgkNchambers; ch++){
674 if(triggeredDigits[1][ch]==triggeredDigits[0][ch]) commonDigits++; // Compare with previous track
675 triggeredDigits[0][ch] = triggeredDigits[1][ch]; // Store this track parameters for comparison with next one
678 doubleCountTrack=kTRUE;
681 if(!doubleCountTrack || fReproduceTrigResponse){
682 for(Int_t cath=0; cath<fgkNcathodes; cath++){
684 Bool_t goodForSlatEff = kTRUE;
685 Bool_t goodForBoardEff = kTRUE;
686 Int_t ineffSlat = -1;
687 Int_t ineffDetElId = -1;
688 Int_t firstSlat = slatThatTriggered[cath][0]%100;
689 if(firstSlat<0) firstSlat=slatThatTriggered[cath][1]%100;
690 Int_t firstBoard = boardThatTriggered[0][kBending][0];
691 if(firstBoard<0) firstBoard=boardThatTriggered[1][kBending][0];
692 for(Int_t ch=0; ch<fgkNchambers; ch++){
693 Bool_t isCurrChIneff = kFALSE;
694 is44 *= trigScheme[cath][ch];
695 Int_t currSlat = slatThatTriggered[cath][ch]%100;
697 ineffDetElId = DetElemIdFromPos(trackIntersectCh[ch][0], trackIntersectCh[ch][1], 11+ch, cath);
698 currSlat = ineffDetElId%100;
699 ineffSlat = currSlat;
700 isCurrChIneff = kTRUE;
702 if(currSlat!=firstSlat)goodForSlatEff=kFALSE;
703 Bool_t atLeastOneLoc=kFALSE;
704 if(isCurrChIneff) LocalBoardFromPos(trackIntersectCh[ch][0], trackIntersectCh[ch][1], ineffDetElId, cath, ineffBoard);
705 for(Int_t loc=0; loc<fgkNlocations; loc++){
706 Int_t currBoard = boardThatTriggered[ch][cath][loc];
707 if(isCurrChIneff) currBoard = ineffBoard[loc];
708 if(currBoard==firstBoard){
713 if(!atLeastOneLoc)goodForBoardEff=kFALSE;
714 } // end chamber loop
719 if(fDebugLevel>=1)printf("Trigger44[%i] = %i\n",cath,fTrigger44[cath]);
721 for(Int_t ch=0; ch<fgkNchambers; ch++){
722 Int_t chCath = fgkNchambers*cath + ch;
723 fHitPerSlat[chCath][firstSlat]++;
724 if(fDebugLevel>=1)printf("Slat that triggered = %i\n",slatThatTriggered[cath][ch]);
725 if(goodForBoardEff && firstBoard>0){
726 fHitPerBoard[chCath][firstBoard-1]++;
727 if(fDebugLevel>=1)printf("Board that triggered = %i\n",firstBoard);
729 else if(fDebugLevel>=1) printf("Track = %p: Particle crossed different boards: rejected!\n",(void *)recTrigTrack);
732 else if(fDebugLevel>=1) printf("Track = %p: Particle crossed different slats: rejected!\n",(void *)recTrigTrack);
737 Int_t ineffCh = ineffDetElId/100-11;
738 Int_t chCath = fgkNchambers*cath + ineffCh;
739 fTrigger34[chCath]++;
740 if(fDebugLevel>=1) printf("Trigger34[%i] = %i\n",chCath,fTrigger34[chCath]);
742 if(fDebugLevel>=1) printf("Slat non efficient = %i\n",ineffDetElId);
743 fInefficientSlat[chCath][ineffSlat]++;
745 if(goodForBoardEff && firstBoard>0){
746 if(fDebugLevel>=1) printf("Board non efficient = %i\n",firstBoard);
747 fInefficientBoard[chCath][firstBoard-1]++;
749 else if(fDebugLevel>=1) printf("Track = %p: Particle crossed different boards: rejected!\n",(void *)recTrigTrack);
751 else if(fDebugLevel>=1) printf("Track = %p: Particle crossed different slats: rejected!\n",(void *)recTrigTrack);
753 } // end loop on cathodes
755 else if(doubleCountTrack){
757 printf("\n\tTrack = %p: \nDouble Count Track: Track rejected!\n",(void *)recTrigTrack);
759 } // end trigger tracks loop
761 if(fPrintInfo) InfoDigit(digitStore);
764 //_____________________________________________________________________________
765 void AliMUONTriggerChamberEff::WriteEfficiencyMap(const char* outputDir)
768 /// Writes information on calculated efficiency.
769 /// It writes: triggerChamberEff.root file containing efficiency histograms.
772 char *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
774 char outFileName[100];
776 sprintf(outFileName, "%s/MUON.TriggerEfficiencyMap.root",outputDir);
777 TFile *outputHistoFile = new TFile(outFileName,"RECREATE");
778 TDirectory *dir = gDirectory;
780 char *yAxisTitle = "trigger efficiency (a.u.)";
781 char *xAxisTitle = "chamber";
783 const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
785 TH1F *histoChamber[fgkNcathodes];
790 enum {kAllChEff, kChNonEff, kNumOfHistoTypes};
791 char *histoTypeName[kNumOfHistoTypes] = {"CountInCh", "NonCountInCh"};
792 char *histoTypeTitle[kNumOfHistoTypes] = {"counted", "non counted"};
793 TH1F *histoCheckSlat[8][kNumOfHistoTypes];
794 TH1F *histoCheckBoard[8][kNumOfHistoTypes];
795 // end ADDED for check
800 for(Int_t cath=0; cath<fgkNcathodes; cath++){
801 sprintf(histoName, "%sChamberEff", cathCode[cath]);
802 sprintf(histoTitle, "Chamber efficiency %s", cathCode[cath]);
803 histoChamber[cath] = new TH1F(histoName, histoTitle, fgkNchambers, 11-0.5, 15-0.5);
804 histoChamber[cath]->SetXTitle(xAxisTitle);
805 histoChamber[cath]->SetYTitle(yAxisTitle);
806 histoChamber[cath]->GetXaxis()->SetNdivisions(fgkNchambers);
807 for(Int_t ch=0; ch<fgkNchambers; ch++){
808 Int_t chCath = fgkNchambers*cath + ch;
809 sprintf(histoName, "%sSlatEffChamber%i", cathCode[cath], 11+ch);
810 sprintf(histoTitle, "Chamber %i: slat efficiency %s", 11+ch, cathCode[cath]);
811 histoSlat[chCath] = new TH1F(histoName, histoTitle, fgkNslats, 0-0.5, fgkNslats-0.5);
812 histoSlat[chCath]->SetXTitle("slat");
813 histoSlat[chCath]->SetYTitle(yAxisTitle);
814 histoSlat[chCath]->GetXaxis()->SetNdivisions(fgkNslats);
816 sprintf(histoName, "%sBoardEffChamber%i", cathCode[cath], 11+ch);
817 sprintf(histoTitle, "Chamber %i: board efficiency %s", 11+ch, cathCode[cath]);
818 histoBoard[chCath] = new TH1F(histoName, histoTitle, kNumOfBoards, 1-0.5, kNumOfBoards+1.-0.5);
819 histoBoard[chCath]->SetXTitle("boards");
820 histoBoard[chCath]->SetYTitle(yAxisTitle);
821 histoBoard[chCath]->GetXaxis()->SetNdivisions(kNumOfBoards);
824 for(Int_t hType=0; hType<kNumOfHistoTypes; hType++){
825 sprintf(histoName, "%sSlat%s%i", cathCode[cath], histoTypeName[hType], 11+ch);
826 sprintf(histoTitle, "Chamber %i: slat %s %s", 11+ch, histoTypeTitle[hType], cathCode[cath]);
827 histoCheckSlat[chCath][hType] = new TH1F(histoName, histoTitle, fgkNslats, 0-0.5, fgkNslats-0.5);
828 histoCheckSlat[chCath][hType]->SetXTitle("slat");
829 histoCheckSlat[chCath][hType]->SetYTitle(yAxisTitle);
830 histoCheckSlat[chCath][hType]->GetXaxis()->SetNdivisions(fgkNslats);
832 sprintf(histoName, "%sBoard%s%i", cathCode[cath], histoTypeName[hType], 11+ch);
833 sprintf(histoTitle, "Chamber %i: board %s %s", 11+ch, histoTypeTitle[hType], cathCode[cath]);
834 histoCheckBoard[chCath][hType] = new TH1F(histoName, histoTitle, kNumOfBoards, 1-0.5, kNumOfBoards+1.-0.5);
835 histoCheckBoard[chCath][hType]->SetXTitle("boards");
836 histoCheckBoard[chCath][hType]->SetYTitle(yAxisTitle);
837 histoCheckBoard[chCath][hType]->GetXaxis()->SetNdivisions(kNumOfBoards);
839 // end ADDED for check
843 Float_t efficiency, efficiencyError;
846 for(Int_t cath=0; cath<fgkNcathodes; cath++){
847 for(Int_t ch=0; ch<fgkNchambers; ch++){
848 Int_t chCath = fgkNchambers*cath + ch;
849 for(Int_t slat=0; slat<fgkNslats; slat++){
850 CalculateEfficiency(fHitPerSlat[chCath][slat], fHitPerSlat[chCath][slat]+fInefficientSlat[chCath][slat], efficiency, efficiencyError, kFALSE);
851 bin = histoSlat[chCath]->FindBin(slat);
852 histoSlat[chCath]->SetBinContent(bin, efficiency);
853 histoSlat[chCath]->SetBinError(bin, efficiencyError);
856 histoCheckSlat[chCath][kAllChEff]->SetBinContent(bin, fHitPerSlat[chCath][slat]);
857 histoCheckSlat[chCath][kChNonEff]->SetBinContent(bin, fInefficientSlat[chCath][slat]);
859 CalculateEfficiency(fTrigger44[cath], fTrigger34[chCath]+fTrigger44[cath], efficiency, efficiencyError, kFALSE);
860 bin = histoChamber[cath]->FindBin(11+ch);
861 histoChamber[cath]->SetBinContent(bin, efficiency);
862 histoChamber[cath]->SetBinError(bin, efficiencyError);
864 for(Int_t board=0; board<kNumOfBoards; board++){
865 CalculateEfficiency(fHitPerBoard[chCath][board], fHitPerBoard[chCath][board]+fInefficientBoard[chCath][board], efficiency, efficiencyError, kFALSE);
866 bin = histoBoard[chCath]->FindBin(board+1);
867 histoBoard[chCath]->SetBinContent(bin, efficiency);
868 histoBoard[chCath]->SetBinError(bin, efficiencyError);
871 histoCheckBoard[chCath][kAllChEff]->SetBinContent(bin, fHitPerBoard[chCath][board]);
872 histoCheckBoard[chCath][kChNonEff]->SetBinContent(bin, fInefficientBoard[chCath][board]);
878 outputHistoFile->cd();
879 dir->GetList()->Write();
880 outputHistoFile->Close();
884 //_____________________________________________________________________________
885 void AliMUONTriggerChamberEff::WriteEfficiencyMapTxt(const char* outputDir)
888 /// Writes the calculated efficiency in the text file efficiencyCells.dat
890 /// The file can be further put in $ALICE_ROOT/MUON/data
891 /// and used to run simulations with measured trigger chamber efficiencies.
896 Float_t efficiency, efficiencyError;
898 Int_t aCapo[] = {16, 38, 60, 76, 92, 108, 117, 133, 155, 177, 193, 209, 225, 234};
901 sprintf(filename, "%s/efficiencyCells.dat", outputDir);
902 ofstream outFile(filename);
903 outFile << "localBoards" << endl;
904 for(Int_t ch=0; ch<fgkNchambers; ch++){
906 outFile << "\n\ndetElemId:\t" << 11+ch;
908 for(Int_t cath=0; cath<fgkNcathodes; cath++){
909 outFile << "\n cathode:\t" << cath << endl;
910 Int_t chCath = fgkNchambers*cath + ch;
912 for(Int_t board=0; board<AliMpConstants::NofLocalBoards(); board++){
914 if(board==aCapo[currLine]){
918 CalculateEfficiency(fHitPerBoard[chCath][board], fHitPerBoard[chCath][board]+fInefficientBoard[chCath][board], efficiency, efficiencyError, kFALSE);
919 outFile << " " << setw(effOutWidth) << efficiency;
927 //_____________________________________________________________________________
928 Bool_t AliMUONTriggerChamberEff::IsCleanTrack(AliMUONTriggerTrack *triggerTrack,
929 const AliMUONVTrackStore& trackStore)
932 /// Try to match track from tracking system with trigger track
934 const Double_t kDistSigma[3]={1,1,0.02}; // sigma of distributions (trigger-track) X,Y,slopeY
935 const Double_t kMaxChi2MatchTrigger = 16.0;
937 AliMUONTrackParam trackParam;
939 Double_t distTriggerTrack[3];
940 Double_t xTrack, yTrack, ySlopeTrack, chi2;
943 TIter next(trackStore.CreateIterator());
945 while ( ( track = static_cast<AliMUONTrack*>(next()) ) )
947 trackParam = *((AliMUONTrackParam*) (track->GetTrackParamAtHit()->Last()));
948 AliMUONTrackExtrap::ExtrapToZ(&trackParam, AliMUONConstants::DefaultChamberZ(10)); // extrap to 1st trigger chamber
950 xTrack = trackParam.GetNonBendingCoor();
951 yTrack = trackParam.GetBendingCoor();
952 ySlopeTrack = trackParam.GetBendingSlope();
954 distTriggerTrack[0] = (triggerTrack->GetX11()-xTrack)/kDistSigma[0];
955 distTriggerTrack[1] = (triggerTrack->GetY11()-yTrack)/kDistSigma[1];
956 distTriggerTrack[2] = (TMath::Tan(triggerTrack->GetThetay())-ySlopeTrack)/kDistSigma[2];
958 for (Int_t iVar = 0; iVar < 3; iVar++) chi2 += distTriggerTrack[iVar]*distTriggerTrack[iVar];
959 chi2 /= 3.; // Normalized Chi2: 3 degrees of freedom (X,Y,slopeY)
960 if (chi2 < kMaxChi2MatchTrigger) return kTRUE;
967 //_____________________________________________________________________________
968 void AliMUONTriggerChamberEff::SaveInESDFile()
971 /// Store AliMUONTriggerChamberEff in esd file
973 TDirectory *dir = gDirectory;
974 TFile *logFile = 0x0;
975 TSeqCollection *list = gROOT->GetListOfFiles();
976 Int_t n = list->GetEntries();
977 for(Int_t i=0; i<n; i++) {
978 logFile = (TFile*)list->At(i);
979 if (strstr(logFile->GetName(), "AliESDs.root")) break;
982 TTree *esdTree = (TTree*)logFile->Get("esdTree");
984 if(!esdTree->GetUserInfo()->FindObject("AliMUONTriggerChamberEff")){
985 AliInfo(Form("Adding AliMUONTrigChamberEff in %s",logFile->GetName()));
986 esdTree->GetUserInfo()->Add(this->Clone());
987 esdTree->Write("",TObject::kOverwrite);
995 //_____________________________________________________________________________
996 void AliMUONTriggerChamberEff::DisplayEfficiency(Bool_t perSlat)
999 /// Display calculated efficiency.
1002 const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
1004 Int_t side, col, line, nbx, slat;
1005 Float_t xCenter, yCenter, zCenter, xWidth, yWidth;
1006 Int_t x1, y1, x2, y2, board=0;
1007 char name[8], text[200];
1009 gStyle->SetPalette(1);
1011 TString boardName[234];
1013 // instanciate the elec. mapping class
1014 AliMpDDLStore* ddlStore = AliMpDDLStore::Instance();
1016 // loop over the trigger DDL (Right: 20, Left: 21)
1017 for (Int_t iDDL = 20; iDDL <= 21; ++iDDL) {
1020 AliMpDDL* ddl = ddlStore->GetDDL(iDDL);
1022 Int_t nCrate = ddl->GetNofTriggerCrates();
1024 // loop over the number of crate in DDL
1025 for (Int_t index = 0; index < nCrate; ++index) {
1028 AliMpTriggerCrate* crate = ddlStore->GetTriggerCrate(iDDL, index);
1030 Int_t nLocal = crate->GetNofLocalBoards();
1032 for (Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
1034 // get local board Id from crate object
1035 board = crate->GetLocalBoardId(iLocal);
1036 if(board>kNumOfBoards || board<=0) continue;
1038 AliMpLocalBoard* localBoard = ddlStore->GetLocalBoard(board);
1039 boardName[board-1] = localBoard->GetName();
1044 char *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
1046 Float_t boardsX = 257.00; // cm
1047 Float_t boardsY = 307.00; // cm
1050 TPaveLabel *boardLabel[8][234];
1053 char histoTitle[90];
1055 Float_t efficiency, efficiencyError;
1057 for(Int_t cath=0; cath<fgkNcathodes; cath++){
1058 for(Int_t ch=0; ch<fgkNchambers; ch++){
1059 Int_t chCath = fgkNchambers*cath + ch;
1060 sprintf(histoName, "%sChamber%i", cathCode[cath], 11+ch);
1061 sprintf(histoTitle, "Chamber %i: efficiency %s", 11+ch, cathCode[cath]);
1062 histo[chCath] = new TH2F(histoName, histoTitle, (Int_t)boardsX, -boardsX, boardsX, (Int_t)boardsY, -boardsY, boardsY);
1063 histo[chCath]->SetXTitle("X (cm)");
1064 histo[chCath]->SetYTitle("Y (cm)");
1068 TString mapspath = gSystem->Getenv("ALICE_ROOT");
1069 mapspath.Append("/MUON/data");
1071 sprintf(text,"%s/guimapp11.txt",mapspath.Data());
1072 FILE *fmap = fopen(text,"r");
1074 for (Int_t ib = 0; ib < kNumOfBoards; ib++) {
1075 fscanf(fmap,"%d %d %d %d %f %f %f %f %f %s \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
1077 slat = (line-5)%fgkNslats;
1078 for(Int_t iBoard=0; iBoard<kNumOfBoards; iBoard++){
1079 if(!boardName[iBoard].Contains(name)) continue;
1084 for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
1085 x1 = histo[chCath]->GetXaxis()->FindBin(xCenter-xWidth/2.)+1;
1086 y1 = histo[chCath]->GetYaxis()->FindBin(yCenter-yWidth/2.)+1;
1087 x2 = histo[chCath]->GetXaxis()->FindBin(xCenter+xWidth/2.)-1;
1088 y2 = histo[chCath]->GetYaxis()->FindBin(yCenter+yWidth/2.)-1;
1090 boardLabel[chCath][board] = new TPaveLabel(xCenter-xWidth/2., yCenter-yWidth/2., xCenter+xWidth/2., yCenter+yWidth/2., Form("%3d",board+1));
1091 boardLabel[chCath][board]->SetFillStyle(0);
1092 boardLabel[chCath][board]->SetBorderSize(0);
1095 CalculateEfficiency(fHitPerBoard[chCath][board], fHitPerBoard[chCath][board]+fInefficientBoard[chCath][board], efficiency, efficiencyError, kFALSE);
1098 CalculateEfficiency(fHitPerSlat[chCath][slat], fHitPerSlat[chCath][slat]+fInefficientSlat[chCath][slat], efficiency, efficiencyError, kFALSE);
1101 for(Int_t binX=x1; binX<=x2; binX++){
1102 for(Int_t binY=y1; binY<=y2; binY++){
1103 histo[chCath]->SetBinContent(binX, binY, efficiency);
1104 histo[chCath]->SetBinError(binX, binY, efficiencyError);
1111 for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
1112 sprintf(histoName, "%sCan", histo[chCath]->GetName());
1113 sprintf(histoTitle, "%s", histo[chCath]->GetTitle());
1114 can[chCath] = new TCanvas(histoName, histoTitle, 100+10*chCath, 10*chCath, 700, 700);
1115 can[chCath]->SetRightMargin(0.14);
1116 can[chCath]->SetLeftMargin(0.12);
1117 histo[chCath]->GetZaxis()->SetRangeUser(0.,1.);
1118 histo[chCath]->GetYaxis()->SetTitleOffset(1.4);
1119 histo[chCath]->SetStats(kFALSE);
1120 histo[chCath]->Draw("COLZ");
1121 for (Int_t board = 0; board < kNumOfBoards; board++) {
1122 boardLabel[chCath][board]->Draw("same");
1127 //_____________________________________________________________________________
1128 void AliMUONTriggerChamberEff::CheckConstants() const
1130 /// Check consistence of redefined constants
1132 assert(fgkNcathodes == AliMpConstants::NofCathodes());
1133 assert(fgkNchambers == AliMpConstants::NofTriggerChambers());
1134 assert(fgkNplanes == AliMpConstants::NofTriggerChambers() * fgkNcathodes);