]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/macros/anaEMCALCalib.C
Transition PWG4 --> PWGGA
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / macros / anaEMCALCalib.C
CommitLineData
6eb2a715 1/* $Id: $ */
2//--------------------------------------------------
3// Example macro to do analysis with the
4// analysis classes in PWG4PartCorr
5// Can be executed with Root and AliRoot
6//
7// Pay attention to the options and definitions
8// set in the lines below
9//
10// Author : Gustavo Conesa Balbastre (INFN-LNF)
11//
12//-------------------------------------------------
13enum anaModes {mLocal, mLocalCAF,mPROOF,mGRID};
14//mLocal: Analyze locally files in your computer
15//mLocalCAF: Analyze locally CAF files
16//mPROOF: Analyze CAF files with PROOF
17
18//---------------------------------------------------------------------------
19//Settings to read locally several files, only for "mLocal" mode
20//The different values are default, they can be set with environmental
21//variables: INDIR, PATTERN, NFILES, respectivelly
22char * kInDir = "/user/data/files/";
23char * kPattern = ""; // Data are in files kInDir/kPattern+i
24Int_t kFile = 1; // Number of files
25//---------------------------------------------------------------------------
26//Collection file for grid analysis
27char * kXML = "collection.xml";
28//---------------------------------------------------------------------------
29
247abff4 30const TString kInputData = "ESD"; //ESD, AOD, MC
9584c261 31TString kTreeName = "esdTree";
247abff4 32
6eb2a715 33void anaEMCALCalib(Int_t mode=mLocal)
34{
35 // Main
9584c261 36 char cmd[200] ;
37 sprintf(cmd, ".! rm -rf aod.root pi0calib.root") ;
38 gROOT->ProcessLine(cmd) ;
6eb2a715 39 //--------------------------------------------------------------------
40 // Load analysis libraries
41 // Look at the method below,
42 // change whatever you need for your analysis case
43 // ------------------------------------------------------------------
44 LoadLibraries(mode) ;
45 //gSystem->Unload("libPWG4CaloCalib.so");
46 //Try to set the new library
47 //gSystem->Load("./PWG4CaloCalib/libPWG4CaloCalib.so");
247abff4 48 //gSystem->ListLibraries();
19db8f8c 49
6eb2a715 50 //-------------------------------------------------------------------------------------------------
51 //Create chain from ESD and from cross sections files, look below for options.
52 //-------------------------------------------------------------------------------------------------
53 if(kInputData == "ESD") kTreeName = "esdTree" ;
54 else if(kInputData == "AOD") kTreeName = "aodTree" ;
55 else {
56 cout<<"Wrong data type "<<kInputData<<endl;
57 break;
58 }
19db8f8c 59
6eb2a715 60 TChain *chain = new TChain(kTreeName) ;
61 CreateChain(mode, chain);
19db8f8c 62
6eb2a715 63 if(chain){
64 AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
65
66 //--------------------------------------
67 // Make the analysis manager
68 //-------------------------------------
69 AliAnalysisManager *mgr = new AliAnalysisManager("Manager", "Manager");
19db8f8c 70
6eb2a715 71 //input
72 if(kInputData == "ESD")
19db8f8c 73 {
74 // ESD handler
75 AliESDInputHandler *esdHandler = new AliESDInputHandler();
76 mgr->SetInputEventHandler(esdHandler);
77 esdHandler->SetReadFriends(kFALSE);
78 cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
79 }
6eb2a715 80 if(kInputData == "AOD")
19db8f8c 81 {
82 // AOD handler
83 AliAODInputHandler *aodHandler = new AliAODInputHandler();
84 mgr->SetInputEventHandler(aodHandler);
85 cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
86
87 }
6eb2a715 88
19db8f8c 89 // mgr->SetDebugLevel(1);
6eb2a715 90
91 //-------------------------------------------------------------------------
92 //Define task, put here any other task that you want to use.
93 //-------------------------------------------------------------------------
6eb2a715 94
95 // ESD filter task
9584c261 96 if(kInputData == "ESD"){
19db8f8c 97
e2fe2603 98 //gROOT->LoadMacro("AddTaskPhysicsSelection.C");
99 //AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
100
6eb2a715 101 }
102
247abff4 103 // Create containers for input/output
104 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
19db8f8c 105
e2fe2603 106 AliAnalysisTaskEMCALPi0CalibSelection * pi0calib = new AliAnalysisTaskEMCALPi0CalibSelection ("EMCALPi0Calibration");
107 if(kInputData == "ESD") pi0calib->SelectCollisionCandidates();
108 //pi0calib->SetDebugLevel(10);
109 //pi0calib->UseFilteredEventAsInput();
110 pi0calib->SetClusterMinEnergy(0.5);
111 pi0calib->SetClusterMaxEnergy(10.);
112 pi0calib->SetAsymmetryCut(0.5);
113 pi0calib->SetClusterMinNCells(0);
114 pi0calib->SetNCellsGroup(0);
115 pi0calib->SwitchOnSameSM();
116 //pi0calib->SwitchOnOldAODs();
117
4f7f37d3 118 TGeoHMatrix *matrix[4];
119
120 double rotationMatrix[4][9] = {-0.014585, -0.999892, -0.002031, 0.999892, -0.014589, 0.001950, -0.001979, -0.002003, 0.999996,
121 -0.014585, 0.999892, 0.002031, 0.999892, 0.014589, -0.001950, -0.001979, 0.002003, -0.999996,
122 -0.345861, -0.938280, -0.003412, 0.938281, -0.345869, 0.001950, -0.003010, -0.002527, 0.999992,
123 -0.345861, 0.938280, 0.003412, 0.938281, 0.345869, -0.001950, -0.003010, 0.002527, -0.999992};
124
125 double translationMatrix[4][3] = {0.367264, 446.508738, 175.97185+0.3,
126 1.078181, 445.826258, -174.026758+0.3,
127 -153.843916, 418.304256, 175.956905+0.8,
128 -152.649580, 417.621779, -174.040392+0.8};
129 for(int j=0; j<4; j++)
130 {
131 matrix[j] = new TGeoHMatrix();
132 matrix[j]->SetRotation(rotationMatrix[j]);
133 matrix[j]->SetTranslation(translationMatrix[j]);
134 matrix[j]->Print();
135 pi0calib->SetGeometryMatrixInSM(matrix[j],j);
136 }
137
138
139 pi0calib->SwitchOnLoadOwnGeometryMatrices();
140
e2fe2603 141 pi0calib->SwitchOnClusterCorrection();
142 AliEMCALRecoUtils * reco = pi0calib->GetEMCALRecoUtils();
4f7f37d3 143 reco->SetParticleType(AliEMCALRecoUtils::kPhoton);
144 reco->SetW0(4.5);
145
146 //reco->SetPositionAlgorithm(AliEMCALRecoUtils::kUnchanged);
147
148 reco->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
149 //reco->SetMisalTransShift(0,1.134); reco->SetMisalTransShift(1,8.2); reco->SetMisalTransShift(2,1.197);
150 //reco->SetMisalTransShift(3,-3.093); reco->SetMisalTransShift(4,6.82);reco->SetMisalTransShift(5,1.635);
151
152 //reco->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerIndex);
153 //reco->SetMisalTransShift(0,1.08); reco->SetMisalTransShift(1,8.35); reco->SetMisalTransShift(2,1.12);
154 //reco->SetMisalRotShift(3,-8.05); reco->SetMisalRotShift(4,8.05);
155 //reco->SetMisalTransShift(3,-0.42); reco->SetMisalTransShift(5,1.55);
156
157 reco->SetNonLinearityFunction(AliEMCALRecoUtils::kNoCorrection);
158 //reco->SetNonLinearityFunction(AliEMCALRecoUtils::kPi0GammaGamma);
159 //reco->SetNonLinearityParam(0,1.04); reco->SetNonLinearityParam(1,-0.1445);
160 //reco->SetNonLinearityParam(2,1.046);
161
162// reco->SetNonLinearityFunction(AliEMCALRecoUtils::kPi0GammaConversion);
163// reco->SetNonLinearityParam(0,1.033); reco->SetNonLinearityParam(1,0.0566186);
164// reco->SetNonLinearityParam(2,0.982133);
165
166
167// reco->SetNonLinearityFunction(AliEMCALRecoUtils::kPi0MC);
168// reco->SetNonLinearityParam(0,1.001); reco->SetNonLinearityParam(1,-0.01264);
169// reco->SetNonLinearityParam(2,-0.03632);
170// reco->SetNonLinearityParam(3,0.1798); reco->SetNonLinearityParam(4,-0.522);
171
172// reco->SwitchOnRecalibration();
173// TFile * f = new TFile("RecalibrationFactors.root","read");
174// TH2F * h0 = (TH2F*)f->Get("EMCALRecalFactors_SM0")->Clone();
175// TH2F * h1 = (TH2F*)f->Get("EMCALRecalFactors_SM1")->Clone();
176// TH2F * h2 = (TH2F*)f->Get("EMCALRecalFactors_SM2")->Clone();
177// TH2F * h3 = (TH2F*)f->Get("EMCALRecalFactors_SM3")->Clone();
178
179// reco->SetEMCALChannelRecalibrationFactors(0,h0);
180// reco->SetEMCALChannelRecalibrationFactors(1,h1);
181// reco->SetEMCALChannelRecalibrationFactors(2,h2);
182// reco->SetEMCALChannelRecalibrationFactors(3,h3);
183
184 reco->SwitchOnBadChannelsRemoval();
185 // SM0
186 reco->SetEMCALChannelStatus(0,3,13); reco->SetEMCALChannelStatus(0,44,1); reco->SetEMCALChannelStatus(0,3,13);
187 reco->SetEMCALChannelStatus(0,20,7); reco->SetEMCALChannelStatus(0,38,2);
188 // SM1
189 reco->SetEMCALChannelStatus(1,4,7); reco->SetEMCALChannelStatus(1,4,13); reco->SetEMCALChannelStatus(1,9,20);
190 reco->SetEMCALChannelStatus(1,14,15); reco->SetEMCALChannelStatus(1,23,16); reco->SetEMCALChannelStatus(1,32,23);
191 reco->SetEMCALChannelStatus(1,37,5); reco->SetEMCALChannelStatus(1,40,1); reco->SetEMCALChannelStatus(1,40,2);
192 reco->SetEMCALChannelStatus(1,40,5); reco->SetEMCALChannelStatus(1,41,0); reco->SetEMCALChannelStatus(1,41,1);
193 reco->SetEMCALChannelStatus(1,41,2); reco->SetEMCALChannelStatus(1,41,4);
194 // SM2
195 reco->SetEMCALChannelStatus(2,14,15); reco->SetEMCALChannelStatus(2,18,16); reco->SetEMCALChannelStatus(2,18,17);
196 reco->SetEMCALChannelStatus(2,18,18); reco->SetEMCALChannelStatus(2,18,20); reco->SetEMCALChannelStatus(2,18,21);
197 reco->SetEMCALChannelStatus(2,18,23); reco->SetEMCALChannelStatus(2,19,16); reco->SetEMCALChannelStatus(2,19,17);
198 reco->SetEMCALChannelStatus(2,19,19); reco->SetEMCALChannelStatus(2,19,20); reco->SetEMCALChannelStatus(2,19,21);
199 reco->SetEMCALChannelStatus(2,19,22);
200 //SM3
201 reco->SetEMCALChannelStatus(3,4,7);
202
203 reco->SetNumberOfCellsFromEMCALBorder(1);
204
e2fe2603 205 //reco->Print("");
4f7f37d3 206
e2fe2603 207 pi0calib->PrintInfo();
208 mgr->AddTask(pi0calib);
247abff4 209
6eb2a715 210 AliAnalysisDataContainer *coutput2 =
247abff4 211 mgr->CreateContainer("pi0calib", TList::Class(), AliAnalysisManager::kOutputContainer, "pi0calib.root");
6eb2a715 212
213 AliAnalysisDataContainer *cout_cuts = mgr->CreateContainer("Cuts", TList::Class(),
247abff4 214 AliAnalysisManager::kOutputContainer, "pi0calib.root");
6eb2a715 215
216 mgr->ConnectInput (pi0calib, 0, cinput1);
6eb2a715 217 mgr->ConnectOutput (pi0calib, 1, coutput2 );
218 mgr->ConnectOutput (pi0calib, 2, cout_cuts);
19db8f8c 219
6eb2a715 220 //-----------------------
221 // Run the analysis
222 //-----------------------
223 TString smode = "";
224 if (mode==mLocal || mode == mLocalCAF)
225 smode = "local";
226 else if (mode==mPROOF)
227 smode = "proof";
228 else if (mode==mGRID)
229 smode = "local";
230
231 mgr->InitAnalysis();
232 mgr->PrintStatus();
233 mgr->StartAnalysis(smode.Data(),chain);
19db8f8c 234
235cout <<" Analysis ended sucessfully "<< endl ;
236
6eb2a715 237 }
238 else cout << "Chain was not produced ! "<<endl;
239
240}
241
242void LoadLibraries(const anaModes mode) {
243
244 //--------------------------------------
245 // Load the needed libraries most of them already loaded by aliroot
246 //--------------------------------------
247 gSystem->Load("libTree.so");
248 gSystem->Load("libGeom.so");
249 gSystem->Load("libVMC.so");
250 gSystem->Load("libXMLIO.so");
251
252 //----------------------------------------------------------
253 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
254 //----------------------------------------------------------
255 if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
256 //--------------------------------------------------------
257 // If you want to use already compiled libraries
258 // in the aliroot distribution
259 //--------------------------------------------------------
260
261 gSystem->Load("libSTEERBase.so");
262 gSystem->Load("libESD.so");
263 gSystem->Load("libAOD.so");
264 gSystem->Load("libANALYSIS.so");
265 gSystem->Load("libANALYSISalice.so");
266 gSystem->Load("libANALYSISalice.so");
4f7f37d3 267 //TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
6eb2a715 268 gSystem->Load("libPWG4CaloCalib.so");
19db8f8c 269 //SetupPar("PWG4CaloCalib");
6eb2a715 270 /*
271 // gSystem->Load("libPWG4omega3pi.so");
272 // gSystem->Load("libCORRFW.so");
40a0a69c 273 // gSystem->Load("libPWGHFbase.so");
274 // gSystem->Load("libPWGmuon.so");
6eb2a715 275 */
276 //--------------------------------------------------------
277 //If you want to use root and par files from aliroot
278 //--------------------------------------------------------
279 /*
280 SetupPar("STEERBase");
281 SetupPar("ESD");
282 SetupPar("AOD");
283 SetupPar("ANALYSIS");
284 SetupPar("ANALYSISalice");
285 SetupPar("PHOSUtils");
286 SetupPar("EMCALUtils");
287 //Create Geometry
288 TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
289 SetupPar("PWG4CaloCalib");
290*/
291 }
292
293 //---------------------------------------------------------
294 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
295 //---------------------------------------------------------
296 else if (mode==mPROOF) {
297 //
298 // Connect to proof
299 // Put appropriate username here
300 // TProof::Reset("proof://mgheata@lxb6046.cern.ch");
301 TProof::Open("proof://mgheata@lxb6046.cern.ch");
302
303 // gProof->ClearPackages();
304 // gProof->ClearPackage("ESD");
305 // gProof->ClearPackage("AOD");
306 // gProof->ClearPackage("ANALYSIS");
307 // gProof->ClearPackage("PWG4PartCorrBase");
308 // gProof->ClearPackage("PWG4PartCorrDep");
309
310 // Enable the STEERBase Package
311 gProof->UploadPackage("STEERBase.par");
312 gProof->EnablePackage("STEERBase");
313 // Enable the ESD Package
314 gProof->UploadPackage("ESD.par");
315 gProof->EnablePackage("ESD");
316 // Enable the AOD Package
317 gProof->UploadPackage("AOD.par");
318 gProof->EnablePackage("AOD");
319 // Enable the Analysis Package
320 gProof->UploadPackage("ANALYSIS.par");
321 gProof->EnablePackage("ANALYSIS");
322 // Enable the PHOS geometry Package
323 //gProof->UploadPackage("PHOSUtils.par");
324 //gProof->EnablePackage("PHOSUtils");
325 // Enable PartCorr analysis
326 gProof->UploadPackage("PWG4PartCorrBase.par");
327 gProof->EnablePackage("PWG4PartCorrBase");
328 gProof->UploadPackage("PWG4PartCorrDep.par");
329 gProof->EnablePackage("PWG4PartCorrDep");
330 gProof->ShowEnabledPackages();
331 }
332
333}
334
335void SetupPar(char* pararchivename)
336{
337 //Load par files, create analysis libraries
338 //For testing, if par file already decompressed and modified
339 //classes then do not decompress.
340
341 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
342 TString parpar(Form("%s.par", pararchivename)) ;
343 if ( gSystem->AccessPathName(parpar.Data()) ) {
344 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
345 TString processline(Form(".! make %s", parpar.Data())) ;
346 gROOT->ProcessLine(processline.Data()) ;
347 gSystem->ChangeDirectory(cdir) ;
348 processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
349 gROOT->ProcessLine(processline.Data()) ;
350 }
351 if ( gSystem->AccessPathName(pararchivename) ) {
352 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
353 gROOT->ProcessLine(processline.Data());
354 }
355
356 TString ocwd = gSystem->WorkingDirectory();
357 gSystem->ChangeDirectory(pararchivename);
358
359 // check for BUILD.sh and execute
360 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
361 printf("*******************************\n");
362 printf("*** Building PAR archive ***\n");
363 cout<<pararchivename<<endl;
364 printf("*******************************\n");
365
366 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
367 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
368 return -1;
369 }
370 }
371 // check for SETUP.C and execute
372 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
373 printf("*******************************\n");
374 printf("*** Setup PAR archive ***\n");
375 cout<<pararchivename<<endl;
376 printf("*******************************\n");
377 gROOT->Macro("PROOF-INF/SETUP.C");
378 }
379
380 gSystem->ChangeDirectory(ocwd.Data());
381 printf("Current dir: %s\n", ocwd.Data());
382}
383
384
385
386void CreateChain(const anaModes mode, TChain * chain){
387 //Fills chain with data
388 TString ocwd = gSystem->WorkingDirectory();
389
390 //-----------------------------------------------------------
391 //Analysis of CAF data locally and with PROOF
392 //-----------------------------------------------------------
393 if(mode ==mPROOF || mode ==mLocalCAF){
394 // Chain from CAF
395 gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
396 // The second parameter is the number of input files in the chain
397 chain = CreateESDChain("ESD12001.txt", 5);
398 }
399
400 //---------------------------------------
401 //Local files analysis
402 //---------------------------------------
403 else if(mode == mLocal){
404 //If you want to add several ESD files sitting in a common directory INDIR
405 //Specify as environmental variables the directory (INDIR), the number of files
406 //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
407
408 if(gSystem->Getenv("INDIR"))
409 kInDir = gSystem->Getenv("INDIR") ;
410 else cout<<"INDIR not set, use default: "<<kInDir<<endl;
411
412 if(gSystem->Getenv("PATTERN"))
413 kPattern = gSystem->Getenv("PATTERN") ;
414 else cout<<"PATTERN not set, use default: "<<kPattern<<endl;
415
416 if(gSystem->Getenv("NFILES"))
417 kFile = atoi(gSystem->Getenv("NFILES")) ;
418 else cout<<"NFILES not set, use default: "<<kFile<<endl;
419
420 //Check if env variables are set and are correct
421 if ( kInDir && kFile) {
422 printf("Get %d files from directory %s\n",kFile,kInDir);
423 if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
424 printf("%s does not exist\n", kInDir) ;
425 return ;
426 }
427
428
429 cout<<"INDIR : "<<kInDir<<endl;
430 cout<<"NFILES : "<<kFile<<endl;
431 cout<<"PATTERN : " <<kPattern<<endl;
432
433 TString datafile="";
434 if(kInputData == "ESD") datafile = "AliESDs.root" ;
435 else if(kInputData == "AOD") datafile = "aod.root" ;
436 else if(kInputData == "MC") datafile = "galice.root" ;
437
438 //Loop on ESD files, add them to chain
439 Int_t event =0;
440 Int_t skipped=0 ;
441 char file[120] ;
442
443 for (event = 0 ; event < kFile ; event++) {
444 sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ;
445 TFile * fESD = 0 ;
446 //Check if file exists and add it, if not skip it
447 if ( fESD = TFile::Open(file)) {
448 if ( fESD->Get(kTreeName) ) {
449 printf("++++ Adding %s\n", file) ;
450 chain->AddFile(file);
451 }
452 }
453 else {
454 printf("---- Skipping %s\n", file) ;
455 skipped++ ;
456 }
457 }
458 printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;
459 }
460 else {
461 TString input = "AliESDs.root" ;
462 cout<<">>>>>> No list added, take a single file <<<<<<<<< "<<input<<endl;
463 chain->AddFile(input);
464 }
465
466 }// local files analysis
467
468 //------------------------------
469 //GRID xml files
470 //-----------------------------
471 else if(mode == mGRID){
472 //Get colection file. It is specified by the environmental
473 //variable XML
474
475 if(gSystem->Getenv("XML") )
476 kXML = gSystem->Getenv("XML");
477 else
478 sprintf(kXML, "collection.xml") ;
479
480 if (!TFile::Open(kXML)) {
481 printf("No collection file with name -- %s -- was found\n",kXML);
482 return ;
483 }
484 else cout<<"XML file "<<kXML<<endl;
485
486 //Load necessary libraries and connect to the GRID
487 gSystem->Load("libNetx.so") ;
488 gSystem->Load("libRAliEn.so");
489 TGrid::Connect("alien://") ;
490
491 //Feed Grid with collection file
492 //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
493 TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
494 if (! collection) {
495 AliError(Form("%s not found", kXML)) ;
496 return kFALSE ;
497 }
498 TGridResult* result = collection->GetGridResult("",0 ,0);
499
500 // Makes the ESD chain
501 printf("*** Getting the Chain ***\n");
502 for (Int_t index = 0; index < result->GetEntries(); index++) {
503 TString alienURL = result->GetKey(index, "turl") ;
504 cout << "================== " << alienURL << endl ;
505 chain->Add(alienURL) ;
506 }
507 }// xml analysis
508
509 gSystem->ChangeDirectory(ocwd.Data());
510}
511