]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/CaloTrackCorrBase/AliAnaScale.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWG / CaloTrackCorrBase / AliAnaScale.cxx
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 //_________________________________________________________________________
17 // A basic analysis task to scale histograms to a given cross section
18 //
19 //*-- Yves Schutz 
20 //////////////////////////////////////////////////////////////////////////////
21
22 //Root system
23 #include <TH1.h>
24 #include <TH1F.h>
25
26 //Analysis system
27 #include "AliAnaScale.h" 
28
29 //__________________________
30 AliAnaScale::AliAnaScale() : 
31   fDebug(0),
32   fScale(1.0),
33   fInputList(0x0), 
34   fOutputList(0x0),
35   fSumw2(0),
36   fhCount() 
37 {
38   //Default constructor
39 }
40
41 //__________________________________________
42 AliAnaScale::AliAnaScale(const char *name) : 
43   AliAnalysisTask(name,""),  
44   fDebug(0),
45   fScale(1.0), 
46   fInputList(0x0), 
47   fOutputList(0x0), 
48   fSumw2(0),
49   fhCount(0) 
50 {
51   // Constructor
52   
53   // Called only after the event loop
54   SetPostEventLoop(kTRUE);
55   
56   // Input slot #0 
57   DefineInput(0,  TList::Class()) ; 
58   
59   // Output slot 
60   DefineOutput(0,  TList::Class()) ;
61   
62 }
63
64 //_________________________________________________
65 void AliAnaScale::ConnectInputData(const Option_t*)
66 {
67   // Initialisation of branch container and histograms 
68     
69   if(fDebug > 1) printf("*** Initialization of %s \n", GetName()) ; 
70   fInputList     = dynamic_cast<TList*>(GetInputData(0)) ; 
71   
72 }
73
74 //_____________________________________
75 void AliAnaScale::CreateOutputObjects()
76 {  
77   // Create the outputs containers
78
79   fOutputList = new TList() ; 
80   fOutputList->SetName(GetName()) ; 
81
82   fhCount =new TH1F("hCount","count files",1,0,1);  
83   fOutputList->Add(fhCount);
84
85   fOutputList->SetOwner(kTRUE);
86   
87   PostData(0, fOutputList);
88   
89 }
90
91 //________________________________
92 void AliAnaScale::Exec(Option_t *) 
93 {
94   // Do the Scaling
95   
96   if(fDebug > 0 ) printf(">>>>> Scaling factor %e, do Sumw2 %d <<<<< \n",fScale,fSumw2) ;
97   
98   const Int_t buffersize = 255;
99   char name[buffersize] ; 
100   
101   TIter next(fInputList) ;      
102   TObject * h ; 
103   while ( (h = next()) ) 
104   { 
105     if(h)
106     {
107       if ( !strncmp(h->ClassName(),"TH",2) ) 
108       {
109         snprintf(name, buffersize, "%sScaled", h->GetName()) ; 
110         
111         TH1 * hout = dynamic_cast<TH1*> (h->Clone(name)) ; 
112         
113         if(hout)
114         {
115           if(fSumw2) hout->Sumw2();
116           hout->Scale(fScale) ;  
117           fOutputList->Add(hout) ;
118         }// casting not null
119       } 
120       else  fOutputList->Add(h) ; 
121     }
122   }
123   // number of files
124   
125   //File scaled, needed for file merging on grid
126   fhCount->Fill(0);
127   
128   PostData(0, fOutputList);
129   
130 }
131
132
133 //______________________
134 void AliAnaScale::Init()
135 {
136   // Intialisation of parameters
137   
138   if(fDebug > 0 )printf("No initialization in scale class \n") ;
139
140 }
141