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 ///////////////////////////////////////////////////////////////////////////////
19 // TRD trigger class //
22 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliLoader.h"
32 #include "AliTRDdigitsManager.h"
33 #include "AliTRDgeometry.h"
34 #include "AliTRDdataArrayI.h"
35 #include "AliTRDcalibDB.h"
36 #include "AliTRDCommonParam.h"
37 #include "Cal/AliTRDCalPIDLQ.h"
38 #include "AliTRDrawData.h"
40 #include "AliTRDtrigger.h"
41 #include "AliTRDmodule.h"
42 #include "AliTRDmcmTracklet.h"
43 #include "AliTRDtrigParam.h"
44 #include "AliTRDmcm.h"
45 #include "AliTRDzmaps.h"
47 //#include "AliHeader.h"
49 ClassImp(AliTRDtrigger)
51 //_____________________________________________________________________________
52 AliTRDtrigger::AliTRDtrigger():
54 fTracks("AliTRDgtuTrack",0)
57 // AliTRDtrigger default constructor
60 fDigitsManager = NULL;
89 //_____________________________________________________________________________
90 AliTRDtrigger::AliTRDtrigger(const Text_t *name, const Text_t *title):
92 fTracks("AliTRDgtuTrack",1000)
95 // AliTRDtrigger constructor
98 fDigitsManager = new AliTRDdigitsManager();
100 fTracklets = new TObjArray(400);
127 //_____________________________________________________________________________
128 AliTRDtrigger::AliTRDtrigger(const AliTRDtrigger &p):TNamed(p)
131 // AliTRDtrigger copy constructor
134 ((AliTRDtrigger &) p).Copy(*this);
138 ///_____________________________________________________________________________
139 AliTRDtrigger::~AliTRDtrigger()
142 // AliTRDtrigger destructor
146 fTracklets->Delete();
154 //_____________________________________________________________________________
155 AliTRDtrigger &AliTRDtrigger::operator=(const AliTRDtrigger &p)
158 // Assignment operator
161 if (this != &p) ((AliTRDtrigger &) p).Copy(*this);
166 //_____________________________________________________________________________
167 void AliTRDtrigger::Copy(TObject &) const
173 AliFatal("Not implemented");
177 //_____________________________________________________________________________
178 void AliTRDtrigger::Init()
181 fModule = new AliTRDmodule(fTrigParam);
183 AliHeader *header = fRunLoader->GetHeader();
184 fNPrimary = header->GetNprimary();
188 fField = fTrigParam->GetField();
189 fGeo = (AliTRDgeometry*)AliTRDgeometry::GetGeometry(fRunLoader);
191 fCalib = AliTRDcalibDB::Instance();
194 Error("Init","No instance of AliTRDcalibDB.");
198 fCParam = AliTRDCommonParam::Instance();
201 Error("Init","No common params.");
207 //_____________________________________________________________________________
208 Bool_t AliTRDtrigger::Open(const Char_t *name, Int_t nEvent)
211 // Opens the AliROOT file.
214 TString evfoldname = AliConfig::GetDefaultEventFolderName();
215 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
218 fRunLoader = AliRunLoader::Open(name);
221 Error("Open","Can not open session for file %s.",name);
227 if (fRunLoader->GetAliRun() == 0x0) fRunLoader->LoadgAlice();
228 gAlice = fRunLoader->GetAliRun();
231 fRunLoader->LoadgAlice();
232 gAlice = fRunLoader->GetAliRun();
234 Error("Open","Could not find AliRun object.");
239 // Import the Trees for the event nEvent in the file
240 fRunLoader->GetEvent(nEvent);
244 TObjArray *ioArray = 0;
246 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
247 loader->MakeTree("T");
248 fTrackletTree = loader->TreeT();
249 fTrackletTree->Branch("TRDmcmTracklet","TObjArray",&ioArray,32000,0);
251 fRunLoader->LoadHeader();
260 //_____________________________________________________________________________
261 Bool_t AliTRDtrigger::ReadDigits()
264 // Reads the digits arrays from the input aliroot file
268 Error("ReadDigits","Can not find the Run Loader");
272 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
273 if (!loader->TreeD()) loader->LoadDigits();
275 if (!loader->TreeD()) return kFALSE;
277 return (fDigitsManager->ReadDigits(loader->TreeD()));
281 //_____________________________________________________________________________
282 Bool_t AliTRDtrigger::ReadDigits(AliRawReader* rawReader)
285 // Reads the digits arrays from the ddl file
288 AliTRDrawData *raw = new AliTRDrawData();
291 fDigitsManager = raw->Raw2Digits(rawReader);
297 //_____________________________________________________________________________
298 Bool_t AliTRDtrigger::ReadTracklets(AliRunLoader *rl)
301 // Reads the tracklets find the tracks
306 AliLoader *loader = rl->GetLoader("TRDLoader");
307 loader->LoadTracks();
308 fTrackletTree = loader->TreeT();
310 TBranch *branch = fTrackletTree->GetBranch("TRDmcmTracklet");
312 Error("ReadTracklets","Can't get the branch !");
315 TObjArray *tracklets = new TObjArray(400);
316 branch->SetAddress(&tracklets);
318 Int_t nEntries = (Int_t) fTrackletTree->GetEntries();
320 Int_t iStack, iStackPrev = -1;
322 for (iEntry = 0; iEntry < nEntries; iEntry++) {
323 fTrackletTree->GetEvent(iEntry);
325 for (itrk = 0; itrk < tracklets->GetEntriesFast(); itrk++){
327 fTrk = (AliTRDmcmTracklet*)tracklets->UncheckedAt(itrk);
329 idet = fTrk->GetDetector();
331 iStack = idet / (AliTRDgeometry::Nplan());
332 if (iStackPrev != iStack) {
333 if (iStackPrev == -1) {
336 MakeTracks(idet-AliTRDgeometry::Nplan());
342 Tracklets()->Add(fTrk);
344 if (iEntry == (nEntries-1) && itrk == (tracklets->GetEntriesFast()-1)) {
346 MakeTracks(idet-AliTRDgeometry::Nplan());
354 loader->UnloadTracks();
360 //_____________________________________________________________________________
361 Bool_t AliTRDtrigger::MakeTracklets(Bool_t makeTracks)
364 // Create tracklets from digits
368 Int_t chamEnd = AliTRDgeometry::Ncham();
370 Int_t planEnd = AliTRDgeometry::Nplan();
372 Int_t sectEnd = AliTRDgeometry::Nsect();
374 fTrkTest = new AliTRDmcmTracklet(0,0,0);
376 fMCM = new AliTRDmcm(fTrigParam,0);
378 Int_t time, col, row, col1, col2;
380 Int_t idet, iStack, iStackPrev;
384 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
386 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
388 // number of ROBs in the chamber
395 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
397 idet = fGeo->GetDetector(iplan,icham,isect);
401 iStack = idet / (AliTRDgeometry::Nplan());
402 if (iStackPrev != iStack) {
403 if (iStackPrev == -1) {
406 MakeTracks(idet-AliTRDgeometry::Nplan());
413 Int_t nRowMax = fCParam->GetRowMax(iplan,icham,isect);
414 Int_t nColMax = fCParam->GetColMax(iplan);
415 Int_t nTimeTotal = fCalib->GetNumberOfTimeBins();
418 fDigits = fDigitsManager->GetDigits(idet);
419 if (!fDigits) return kFALSE;
421 fTrack0 = fDigitsManager->GetDictionary(idet,0);
422 if (!fTrack0) return kFALSE;
424 fTrack1 = fDigitsManager->GetDictionary(idet,1);
425 if (!fTrack1) return kFALSE;
427 fTrack2 = fDigitsManager->GetDictionary(idet,2);
428 if (!fTrack2) return kFALSE;
431 for (Int_t iRob = 0; iRob < fNROB; iRob++) {
433 for (Int_t iMcm = 0; iMcm < kNMCM; iMcm++) {
437 fMCM->SetRobId(iRob);
438 fMCM->SetChaId(idet);
440 SetMCMcoordinates(iMcm);
442 row = fMCM->GetRow();
444 if (row < 0 || row >= nRowMax) {
445 Error("MakeTracklets","MCM row number out of range.");
449 fMCM->GetColRange(col1,col2);
451 for (time = 0; time < nTimeTotal; time++) {
452 for (col = col1; col < col2; col++) {
453 if (col >= 0 && col < nColMax) {
454 amp = TMath::Abs(fDigits->GetDataUnchecked(row,col,time));
458 fMCM->SetADC(col-col1,time,amp);
463 if (fTrigParam->GetTailCancelation()) {
464 fMCM->Filter(fTrigParam->GetNexponential(),fTrigParam->GetFilterType());
469 for (Int_t iSeed = 0; iSeed < kMaxTrackletsPerMCM; iSeed++) {
471 if (fMCM->GetSeedCol()[iSeed] < 0) continue;
473 if ( fTrigParam->GetDebugLevel() > 1 )
474 printf("Add tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]);
476 if ( fTrigParam->GetDebugLevel() == -1 ) {
477 printf("Add tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]);
478 for (time = 0; time < nTimeTotal; time++) {
479 for (col = 0; col < kMcmCol; col++) {
480 printf("%03.0f ",fMCM->GetADC(col,time));
486 if (TestTracklet(idet,row,iSeed,0)) {
487 AddTracklet(idet,row,iSeed,fNtracklets++);
499 // Compress the arrays
500 fDigits->Compress(1,0);
501 fTrack0->Compress(1,0);
502 fTrack1->Compress(1,0);
503 fTrack2->Compress(1,0);
505 WriteTracklets(idet);
513 MakeTracks(idet-AliTRDgeometry::Nplan());
521 //_____________________________________________________________________________
522 void AliTRDtrigger::SetMCMcoordinates(Int_t imcm)
525 // Configure MCM position in the pad plane
528 Int_t robid = fMCM->GetRobId();
530 // setting the Row and Col range
532 const Int_t kNcolRob = 2; // number of ROBs per chamber in column direction
533 const Int_t kNmcmRob = 4; // number of MCMs per ROB in column/row direction
535 Int_t mcmid = imcm%(kNmcmRob*kNmcmRob);
537 if (robid%kNcolRob == 0) {
539 if ( mcmid%kNmcmRob == 0 ) {
540 fMCM->SetColRange(18*0-1,18*1-1+2+1);
542 if ( mcmid%kNmcmRob == 1 ) {
543 fMCM->SetColRange(18*1-1,18*2-1+2+1);
545 if ( mcmid%kNmcmRob == 2 ) {
546 fMCM->SetColRange(18*2-1,18*3-1+2+1);
548 if ( mcmid%kNmcmRob == 3 ) {
549 fMCM->SetColRange(18*3-1,18*4-1+2+1);
554 if ( mcmid%kNmcmRob == 0 ) {
555 fMCM->SetColRange(18*4-1,18*5-1+2+1);
557 if ( mcmid%kNmcmRob == 1 ) {
558 fMCM->SetColRange(18*5-1,18*6-1+2+1);
560 if ( mcmid%kNmcmRob == 2 ) {
561 fMCM->SetColRange(18*6-1,18*7-1+2+1);
563 if ( mcmid%kNmcmRob == 3 ) {
564 fMCM->SetColRange(18*7-1,18*8-1+2+1);
569 fMCM->SetRow(kNmcmRob*(robid/kNcolRob)+mcmid/kNmcmRob);
573 //_____________________________________________________________________________
574 Bool_t AliTRDtrigger::TestTracklet(Int_t det, Int_t row, Int_t seed, Int_t n)
577 // Check first the tracklet pt
580 Int_t nTimeTotal = fCalib->GetNumberOfTimeBins();
584 fTrkTest->SetDetector(det);
585 fTrkTest->SetRow(row);
588 Int_t iCol, iCol1, iCol2, track[3];
589 iCol = fMCM->GetSeedCol()[seed]; // 0....20 (MCM)
590 fMCM->GetColRange(iCol1,iCol2); // range in the pad plane
593 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
595 amp[0] = fMCM->GetADC(iCol-1,iTime);
596 amp[1] = fMCM->GetADC(iCol ,iTime);
597 amp[2] = fMCM->GetADC(iCol+1,iTime);
599 // extract track contribution only from the central pad
600 track[0] = fTrack0->GetDataUnchecked(row,iCol+iCol1,iTime);
601 track[1] = fTrack1->GetDataUnchecked(row,iCol+iCol1,iTime);
602 track[2] = fTrack2->GetDataUnchecked(row,iCol+iCol1,iTime);
604 if (fMCM->IsCluster(iCol,iTime)) {
606 fTrkTest->AddCluster(iCol+iCol1,iTime,amp,track);
608 } else if ((iCol+1+1) < kMcmCol) {
610 amp[0] = fMCM->GetADC(iCol-1+1,iTime);
611 amp[1] = fMCM->GetADC(iCol +1,iTime);
612 amp[2] = fMCM->GetADC(iCol+1+1,iTime);
614 if (fMCM->IsCluster(iCol+1,iTime)) {
616 // extract track contribution only from the central pad
617 track[0] = fTrack0->GetDataUnchecked(row,iCol+1+iCol1,iTime);
618 track[1] = fTrack1->GetDataUnchecked(row,iCol+1+iCol1,iTime);
619 track[2] = fTrack2->GetDataUnchecked(row,iCol+1+iCol1,iTime);
621 fTrkTest->AddCluster(iCol+1+iCol1,iTime,amp,track);
630 fTrkTest->CookLabel(0.8);
632 if (fTrkTest->GetLabel() >= fNPrimary) {
633 Info("AddTracklet","Only primaries are stored!");
639 fTrkTest->MakeTrackletGraph(fGeo,fField);
640 fTrkTest->MakeClusAmpGraph();
641 if (TMath::Abs(fTrkTest->GetPt()) < fTrigParam->GetLtuPtCut()) {
649 //_____________________________________________________________________________
650 void AliTRDtrigger::AddTracklet(Int_t det, Int_t row, Int_t seed, Int_t n)
653 // Add a found tracklet
656 Int_t nTimeTotal = fCalib->GetNumberOfTimeBins();
658 fTrk = new AliTRDmcmTracklet(det,row,n);
660 Int_t iCol, iCol1, iCol2, track[3];
661 iCol = fMCM->GetSeedCol()[seed]; // 0....20 (MCM)
662 fMCM->GetColRange(iCol1,iCol2); // range in the pad plane
665 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
667 amp[0] = fMCM->GetADC(iCol-1,iTime);
668 amp[1] = fMCM->GetADC(iCol ,iTime);
669 amp[2] = fMCM->GetADC(iCol+1,iTime);
671 // extract track contribution only from the central pad
672 track[0] = fTrack0->GetDataUnchecked(row,iCol+iCol1,iTime);
673 track[1] = fTrack1->GetDataUnchecked(row,iCol+iCol1,iTime);
674 track[2] = fTrack2->GetDataUnchecked(row,iCol+iCol1,iTime);
676 if (fMCM->IsCluster(iCol,iTime)) {
678 fTrk->AddCluster(iCol+iCol1,iTime,amp,track);
680 } else if ((iCol+1+1) < kMcmCol) {
682 amp[0] = fMCM->GetADC(iCol-1+1,iTime);
683 amp[1] = fMCM->GetADC(iCol +1,iTime);
684 amp[2] = fMCM->GetADC(iCol+1+1,iTime);
686 if (fMCM->IsCluster(iCol+1,iTime)) {
688 // extract track contribution only from the central pad
689 track[0] = fTrack0->GetDataUnchecked(row,iCol+1+iCol1,iTime);
690 track[1] = fTrack1->GetDataUnchecked(row,iCol+1+iCol1,iTime);
691 track[2] = fTrack2->GetDataUnchecked(row,iCol+1+iCol1,iTime);
693 fTrk->AddCluster(iCol+1+iCol1,iTime,amp,track);
702 fTrk->CookLabel(0.8);
704 if (fTrk->GetLabel() >= fNPrimary) {
705 Info("AddTracklet","Only primaries are stored!");
710 fTrk->MakeTrackletGraph(fGeo,fField);
711 fTrk->MakeClusAmpGraph();
712 if (TMath::Abs(fTrk->GetPt()) < fTrigParam->GetLtuPtCut()) {
716 Tracklets()->Add(fTrk);
720 //_____________________________________________________________________________
721 Bool_t AliTRDtrigger::WriteTracklets(Int_t det)
724 // Fills TRDmcmTracklet branch in the tree with the Tracklets
725 // found in detector = det. For det=-1 writes the tree.
728 if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
729 Error("WriteTracklets","Unexpected detector index %d.",det);
733 TBranch *branch = fTrackletTree->GetBranch("TRDmcmTracklet");
735 TObjArray *ioArray = 0;
736 branch = fTrackletTree->Branch("TRDmcmTracklet","TObjArray",&ioArray,32000,0);
739 if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
741 Int_t nTracklets = Tracklets()->GetEntriesFast();
742 TObjArray *detTracklets = new TObjArray(400);
744 for (Int_t i = 0; i < nTracklets; i++) {
745 AliTRDmcmTracklet *trk = (AliTRDmcmTracklet *) Tracklets()->UncheckedAt(i);
747 if (det == trk->GetDetector()) {
748 detTracklets->AddLast(trk);
754 branch->SetAddress(&detTracklets);
755 fTrackletTree->Fill();
765 Info("WriteTracklets","Writing the Tracklet tree %s for event %d."
766 ,fTrackletTree->GetName(),fRunLoader->GetEventNumber());
768 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
769 loader->WriteTracks("OVERWRITE");
779 //_____________________________________________________________________________
780 void AliTRDtrigger::MakeTracks(Int_t det)
783 // Create GTU tracks per module (stack of 6 chambers)
788 Int_t nRowMax, iplan, icham, isect, row;
790 if ((det < 0) || (det >= AliTRDgeometry::Ndet())) {
791 Error("MakeTracks","Unexpected detector index %d.",det);
795 Int_t nTracklets = Tracklets()->GetEntriesFast();
797 AliTRDmcmTracklet *trk;
798 for (Int_t i = 0; i < nTracklets; i++) {
800 trk = (AliTRDmcmTracklet *) Tracklets()->UncheckedAt(i);
802 iplan = fGeo->GetPlane(trk->GetDetector());
803 icham = fGeo->GetChamber(trk->GetDetector());
804 isect = fGeo->GetSector(trk->GetDetector());
806 nRowMax = fCParam->GetRowMax(iplan,icham,isect);
809 fModule->AddTracklet(trk->GetDetector(),
821 fModule->SortTracklets();
822 fModule->RemoveMultipleTracklets();
823 fModule->SortZ((Int_t)fGeo->GetChamber(det));
824 fModule->FindTracks();
825 fModule->SortTracks();
826 fModule->RemoveMultipleTracks();
828 Int_t nModTracks = fModule->GetNtracks();
829 AliTRDgtuTrack *gtutrk;
830 for (Int_t i = 0; i < nModTracks; i++) {
831 gtutrk = (AliTRDgtuTrack*)fModule->GetTrack(i);
832 if (TMath::Abs(gtutrk->GetPt()) < fTrigParam->GetGtuPtCut()) continue;
835 AddTrack(gtutrk,det);