]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONTrigger.C
Formatting changes.
[u/mrichter/AliRoot.git] / MUON / MUONTrigger.C
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // This macro is to be used to check the trigger algorithm w/o having to
17 // (re-)perform simulation and digitalization. 
18 // It loads the digits, erase TreeR and store the current trigger output in 
19 // TreeR.
20 // The different trigger outputs can be compared by looking at the GLT branch 
21 // of TreeD (filled during simulation) and the TC branch of TreeR (filled from 
22 // a copy of TreeD during reconstruction or with this macro).
23 // Note: rec points from tracking chamber will be lost.
24 //
25 // usage: (to be compiled)
26 // MUONTrigger("galice.root",0) -> Default Trigger Code
27 // MUONTrigger("galice.root",1) -> New Trigger Code
28
29 #if !defined(__CINT__) || defined(__MAKECINT__)
30 #include "AliRun.h"
31 #include "AliMUON.h"
32 #include "AliMUONLoader.h"
33 #include "AliMUONData.h"
34 #include "AliMUONDigit.h"
35 #include "AliMUONTriggerDecisionV1.h"
36 #include "AliMUONTriggerElectronics.h"
37 #include "AliMUONCalibrationData.h"
38 #include "AliCDBManager.h"
39 #endif
40 void MUONTrigger(char * FileName="galice.root", Int_t NewTriggerCode=0)
41 {
42   // Creating Run Loader and openning file containing Digits 
43     AliRunLoader * RunLoader = AliRunLoader::Open(FileName,"MUONLoader","UPDATE");
44     if (RunLoader ==0x0) {
45         printf(">>> Error : Error Opening %s file \n",FileName);
46         return;
47     }
48     // Loading AliRun master
49     if (RunLoader->GetAliRun() == 0x0) RunLoader->LoadgAlice();
50     gAlice = RunLoader->GetAliRun();
51     
52     // Loading MUON subsystem
53     AliLoader * MUONLoader = RunLoader->GetLoader("MUONLoader");
54     MUONLoader->LoadDigits("READ");
55     MUONLoader->LoadRecPoints("UPDATE"); // absolutely essential !!!
56
57     Int_t nevents;
58     nevents = RunLoader->GetNumberOfEvents();
59
60     // Creating MUON data container
61     AliMUONData* MUONData = new AliMUONData(MUONLoader,"MUON","MUON");
62
63     // Creating MUONTriggerDecision
64     TTask *TriggerProcessor;
65     if (NewTriggerCode == 0) {
66         cout << " using default trigger code " << "\n";
67         TriggerProcessor = new AliMUONTriggerDecisionV1(MUONData);      
68     } else {
69         cout << " using new trigger code " << "\n";
70         AliCDBManager* cdbManager = AliCDBManager::Instance();
71         cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
72         Int_t runnumber = gAlice->GetRunNumber();
73         AliMUONCalibrationData *CalibrationData = new AliMUONCalibrationData(runnumber);
74         TriggerProcessor = new AliMUONTriggerElectronics(MUONData,CalibrationData);
75     }
76
77     // Testing if Trigger has already been done
78     RunLoader->GetEvent(0);    
79     if (MUONLoader->TreeR()) {
80         if (MUONData->IsTriggerBranchesInTree()) {
81             MUONLoader->UnloadRecPoints();
82             MUONLoader->LoadRecPoints("RECREATE");
83             printf("Recreating recpoints files\n");
84         }
85     }
86
87     AliMUONDigit * mDigit;    
88     Int_t digits[7];
89     
90     for(Int_t ievent = 0; ievent < nevents; ievent++) {
91         printf(">>> Event %i out of %i \n",ievent,nevents);
92         RunLoader->GetEvent(ievent);
93         MUONData->SetTreeAddress("D");
94         
95         MUONData->GetDigits();
96         for(Int_t ichamber=10; ichamber<14; ichamber++) {         
97             Int_t idigit, ndigits;
98             ndigits = (Int_t) MUONData->Digits(ichamber)->GetEntriesFast();
99
100             for(idigit=0; idigit<ndigits; idigit++) {
101                 mDigit = static_cast<AliMUONDigit*>(MUONData->Digits(ichamber)->At(idigit));
102                 digits[0] = mDigit->PadX();
103                 digits[1] = mDigit->PadY();
104                 digits[2] = mDigit->Cathode();
105                 digits[3] = mDigit->Signal();
106                 digits[4] = mDigit->Physics();
107                 digits[5] = mDigit->Hit();
108                 digits[6] = mDigit->DetElemId();
109                 
110                 printf("ichamber ix iy %d %d %d \n",ichamber,mDigit->PadX(),mDigit->PadY());
111                 
112             } // loop on digits
113         } // loop on chambers
114
115         if (MUONLoader->TreeR() == 0x0) {       
116             MUONLoader->MakeRecPointsContainer();
117         } else {
118             if (MUONData->IsTriggerBranchesInTree()){ 
119                 if (ievent==0) MUONLoader->UnloadRecPoints();
120                 MUONLoader->MakeRecPointsContainer();
121                 cout << "Recreating RecPointsContainer and deleting previous ones" << "\n";
122             }
123         }       
124         
125         MUONData->MakeBranch("TC");     
126         MUONData->SetTreeAddress("TC");
127         TriggerProcessor->ExecuteTask();
128
129         MUONData->Fill("TC");
130         MUONLoader->WriteRecPoints("OVERWRITE");  
131         MUONData->ResetDigits();
132
133     } // loop on events
134     MUONLoader->UnloadDigits();
135     MUONLoader->UnloadRecPoints();
136 }
137