change library dependencies and paths to the new places of the analysis under PWGGA...
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / macros / AddTaskEMCALClusterize.C
1 AliAnalysisTaskEMCALClusterize* AddTaskEMCALClusterize(
2                                                        const Int_t   bMC        = kFALSE,
3                                                        const TString name       = "V1Unfold", 
4                                                        const TString trigger    = "", 
5                                                        const Int_t   run        = 0, 
6                                                        const TString pass       = "pass3",
7                                                        const Bool_t  tm         = kTRUE, 
8                                                        const Int_t   minEcell   = 50,
9                                                        const Int_t   minEseed   = 100,
10                                                        const Int_t   maxDeltaT  = 250,
11                                                        const Int_t   timeWindow = 1000,
12                                                        const Int_t   minEUnf    = 15, 
13                                                        const Int_t   minFrac    = 1
14                                                        )
15 {  
16   // Get the pointer to the existing analysis manager via the static access method.
17   //==============================================================================
18   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
19   if (!mgr) {
20     ::Error("AddTaskEMCALClusterize", "No analysis manager to connect to.");
21     return NULL;
22   }  
23   
24   // Check the analysis type using the event handlers connected to the analysis manager.
25   //==============================================================================
26   if (!mgr->GetInputEventHandler()) {
27     ::Error("AddTaskEMCALClusterize", "This task requires an input event handler");
28     return NULL;
29   }
30   
31   AliAnalysisTaskEMCALClusterize* clusterize = new AliAnalysisTaskEMCALClusterize(Form("EMCALClusterize%s_Ecell%d_Eseed%d_DT%d_WT%d",
32                                                                                        name.Data(),minEcell,minEseed,maxDeltaT,timeWindow));
33
34   clusterize->SetAODBranchName(Form("%s_Ecell%d_Eseed%d_DT%d_WT%d",
35                                     name.Data(),minEcell,minEseed,maxDeltaT,timeWindow));
36
37   printf("Created Branch Name: %s_Ecell%d_Eseed%d_DT%d_WT%d\n",name.Data(),minEcell,minEseed, maxDeltaT,timeWindow);
38   //clusterize->SetOCDBPath("local://$ALICE_ROOT/OCDB");
39
40   clusterize->SwitchOffFillAODCaloCells();
41   clusterize->SwitchOffFillAODHeader();
42   clusterize->FillAODFile(kFALSE); // fill aod.root with clusters?, not really needed for analysis.
43
44   if(tm) clusterize->SwitchOnTrackMatching();
45   else   clusterize->SwitchOffTrackMatching();
46   
47   // Settings for LHC11a
48   if(run > 140000 && run <= 146860) {
49     clusterize->SwitchOnLEDEventsRemoval() ;
50     printf("Clusterizer: Reject LED events\n");
51   }
52   else clusterize->SwitchOffLEDEventsRemoval() ;
53   
54   printf(" ---- Clusterize RUN >%d< ---- \n",run);
55   
56   if(run > 140000)  clusterize->SetGeometryName("EMCAL_COMPLETEV1");
57   else              clusterize->SetGeometryName("EMCAL_FIRSTYEARV1");
58
59   AliEMCALRecParam * params = clusterize->GetRecParam();
60
61   params->SetW0(4.5);
62
63   //printf("**** InputHandler %s ***\n",(mgr->GetInputEventHandler())->ClassName());
64   TString sHandler((mgr->GetInputEventHandler())->ClassName());
65   if(sHandler.Contains("AOD")){
66     printf("AliAnalysisTaskEMCALClusterize - Open time cuts for AODs\n");
67     params->SetTimeCut(1e6);//Open this cut for AODs
68     params->SetTimeMin(-1); //Open this cut for AODs
69     params->SetTimeMax(1e6);//Open this cut for AODs    
70   }
71   else{
72     printf("AliAnalysisTaskEMCALClusterize - Set time cuts for ESDs\n");
73     if(maxDeltaT > 1) params->SetTimeCut(maxDeltaT*1.e-9);
74     else            { params->SetTimeCut(250*1.e-9); printf("default maxDeltaT = 250 ns\n"); }// Same as in reco
75     
76     if(timeWindow > 1){
77       params->SetTimeMin(-1*timeWindow*1.e-9);
78       params->SetTimeMax(timeWindow*1.e-9);
79     }
80     else{ // same as in reco
81       params->SetTimeMin(425*1.e-9);
82       params->SetTimeMax(825*1.e-9);
83       printf("default time window 425 ns < T < 825 ns\n");
84     }
85   }
86
87   params->SetClusteringThreshold(minEseed/1.e3);                                          
88   params->SetMinECut            (minEcell/1.e3); 
89
90   // Clusterizer type
91   if(name.Contains("V2")) params->SetClusterizerFlag(AliEMCALRecParam::kClusterizerv2);
92   if(name.Contains("V1")) params->SetClusterizerFlag(AliEMCALRecParam::kClusterizerv1);
93   if(name.Contains("NxN"))params->SetClusterizerFlag(AliEMCALRecParam::kClusterizerNxN);
94
95
96   //Unfolding
97   if(name.Contains("JustUnfold"))
98     clusterize->JustUnfold(kTRUE); // if TRUE, do just unfolding, do not recluster cells
99   else  
100     clusterize->JustUnfold(kFALSE); 
101
102   if (name.Contains("Unfold")){
103
104     clusterize->SwitchOnCellEnergySelection();
105     clusterize->SetCellCuts(minEUnf/1000.,minFrac/10000.);
106     printf("AliAnalysisTaskEMCALClusterize - Cuts: min E %f, frac %f\n",minEUnf/1000.,minFrac/10000.);
107     //clusterize->SwitchOffCellEnergySelection(); 
108
109     if(!name.Contains("Just"))
110     params->SetUnfold(kTRUE);
111   else 
112     params->SetUnfold(kFALSE);
113
114   } // unfold
115   
116   TGeoHMatrix* matrix[10];
117   AliEMCALRecoUtils * reco = clusterize->GetRecoUtils();
118   
119   gROOT->LoadMacro("ConfigureEMCALRecoUtils.C"); // $ALICE_ROOT/PWGGA/EMCALTasks/macros
120   ConfigureEMCALRecoUtils(
121                           reco,
122                           bMC, 
123                           matrix,
124                           "",//AODB path, default
125                           run, 
126                           pass
127                           );
128   
129   //Alignment matrices
130   
131   clusterize->SetImportGeometryFromFile(kTRUE); // import geometry.root file
132   
133   for (Int_t mod=0;mod<10;mod++)
134   {
135     //((TGeoHMatrix*) mobj->At(mod))->Print();
136     clusterize->SetGeometryMatrixInSM(matrix[mod],mod);
137   }
138   
139   clusterize->SwitchOnLoadOwnGeometryMatrices();
140     
141   if(trigger=="EMC7"){
142     printf("AliAnalysisTaskEMCALClusterize ---Data with kEMC7 Trigger and clusterizer %s\n",name.Data());
143     clusterize->SelectCollisionCandidates(AliVEvent::kEMC7);
144   }
145   else if (trigger=="INT7"){
146     printf("AliAnalysisTaskEMCALClusterize ---Data with kINT7 Trigger and clusterizer %s\n",name.Data());
147     clusterize->SelectCollisionCandidates(AliVEvent::kINT7);
148   }
149   else if(trigger=="EMC1"){
150     printf("AliAnalysisTaskEMCALClusterize ---Data with kEMC1 Trigger and clusterizer %s\n",name.Data());
151     clusterize->SelectCollisionCandidates(AliVEvent::kEMC1);
152   }
153   else if(trigger=="MB"){
154     printf("AliAnalysisTaskEMCALClusterize ---Data with kMB Trigger and clusterizer %s\n",name.Data());
155     clusterize->SelectCollisionCandidates(AliVEvent::kMB);
156   }
157
158   mgr->AddTask(clusterize);
159   
160   // Create containers for input/output
161   AliAnalysisDataContainer *cinput1  = mgr->GetCommonInputContainer()  ;
162   AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer() ;
163   
164   mgr->ConnectInput  (clusterize, 0,  cinput1 );
165   mgr->ConnectOutput (clusterize, 0, coutput1 );
166   
167   return clusterize;
168   
169 }