]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEER/AliReconstruction.h
Setting of aliases to rawReader done only once. Base decision on cosmic or calib...
[u/mrichter/AliRoot.git] / STEER / STEER / AliReconstruction.h
1 #ifndef ALIRECONSTRUCTION_H
2 #define ALIRECONSTRUCTION_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id: AliReconstruction.h 63911 2013-08-19 16:46:41Z hristov $ */
7
8 ///////////////////////////////////////////////////////////////////////////////
9 //                                                                           //
10 // class for running the reconstruction                                      //
11 // Clusters and tracks are created for all detectors and all events by       //
12 // typing:                                                                   //
13 //                                                                           //
14 //   AliReconstruction rec;                                                  //
15 //   rec.Run();                                                              //
16 //                                                                           //
17 ///////////////////////////////////////////////////////////////////////////////
18
19
20 #include <TSelector.h>
21 #include <TString.h>
22 #include <TObjArray.h>
23
24 class AliReconstructor;
25 class AliRunLoader;
26 class AliRawReader;
27 class AliLoader;
28 class AliTracker;
29 class AliMagF;
30 class AliVertexer;
31 class AliTrackleter;
32 class AliESDVertex;
33 class AliESDEvent;
34 class AliESDfriend;
35 class AliESDpid;
36 class AliVertexerTracks;
37 class TFile;
38 class TTree;
39 class TList;
40 class AliQAManager; 
41 class TMap;
42 class AliRecoParam;
43 class AliDetectorRecoParam;
44 class AliRunInfo;
45 class AliGRPObject;
46 class THashTable;
47 class AliTriggerRunScalers;
48 class AliCTPTimeParams;
49 class AliAnalysisManager;
50 class AliRecoInputHandler;
51
52 #include "AliQAv1.h"
53 #include "AliEventInfo.h"
54 #include "AliRecoParam.h"
55
56 using std::ofstream;
57
58 class AliReconstruction: public TSelector {
59 public:
60   AliReconstruction(const char* gAliceFilename = "galice.root");
61   virtual ~AliReconstruction();
62
63   void           SetGAliceFile(const char* fileName);
64   void           SetInput(const char* input);
65   void           SetOutput(const char* output);
66
67   void           SetEquipmentIdMap(const char *mapFile) {fEquipIdMap = mapFile;};
68   void           SetEventRange(Int_t firstEvent = 0, Int_t lastEvent = -1) 
69     {fFirstEvent = firstEvent; fLastEvent = lastEvent;};
70   void           SetNumberOfEventsPerFile(UInt_t nEvents)
71     {fNumberOfEventsPerFile = nEvents;};
72   void           SetFractionFriends(Double32_t frac = 0.04)
73     {fFractionFriends = frac;};
74   void           SetOption(const char* detector, const char* option);
75   void           SetRecoParam(const char* detector, AliDetectorRecoParam *par);
76
77   void           SetCosmicAlias(const char* nm="kCosmic") {fCosmicAlias = nm;}
78   void           SetLaserAlias(const char* nm="kCalibLaser") {fLaserAlias = nm;}
79
80   TString&       GetCosmicAlias() const {return (TString&)fCosmicAlias;}
81   TString&       GetLaserAlias()  const {return (TString&)fLaserAlias;}
82
83   void           SetRunLocalReconstruction(const char* detectors) {
84     fRunLocalReconstruction = detectors;};
85   void           SetRunTracking(const char* detectors) {
86     fRunTracking = detectors;};
87   void           SetFillESD(const char* detectors) {fFillESD = detectors;};
88   void           SetRunReconstruction(const char* detectors) {
89     SetRunLocalReconstruction(detectors); 
90     SetRunTracking(detectors);
91     SetFillESD(detectors);};
92   void           SetDeleteRecPoints(const char* dets) {fDeleteRecPoints = dets;}
93   void           SetDeleteDigits(const char* dets)    {fDeleteDigits = dets;}
94   void           SetUseTrackingErrorsForAlignment(const char* detectors) 
95     {fUseTrackingErrorsForAlignment = detectors;};
96   void           SetLoadAlignFromCDB(Bool_t load)  {fLoadAlignFromCDB = load;};
97   void           SetLoadAlignData(const char* detectors) 
98     {fLoadAlignData = detectors;};
99
100   void           SetTreeBuffSize(Long64_t sz=30000000) {fTreeBuffSize = sz;}
101   //*** Global reconstruction flag setters
102   void SetRunMultFinder(Bool_t flag=kTRUE) {fRunMultFinder=flag;};
103   void SetRunVertexFinder(Bool_t flag=kTRUE) {fRunVertexFinder=flag;};
104   void SetRunVertexFinderTracks(Bool_t flag=kTRUE) {fRunVertexFinderTracks=flag;};
105   void SetRunV0Finder(Bool_t flag=kTRUE) {fRunV0Finder=flag;};
106   void SetRunCascadeFinder(Bool_t flag=kTRUE) {fRunCascadeFinder=flag;};
107   void SetStopOnError(Bool_t flag=kTRUE) {fStopOnError=flag;}
108   void SetStopOnMissingTriggerFile(Bool_t flag=kTRUE) {fStopOnMissingTriggerFile=flag;}
109   void SetWriteAlignmentData(Bool_t flag=kTRUE){fWriteAlignmentData=flag;}
110   void SetWriteESDfriend(Bool_t flag=kTRUE){fWriteESDfriend=flag;}
111   void SetFillTriggerESD(Bool_t flag=kTRUE){fFillTriggerESD=flag;}
112   void SetDiamondProfileSPD(AliESDVertex *dp) {fDiamondProfileSPD=dp;}
113   void SetDiamondProfile(AliESDVertex *dp) {fDiamondProfile=dp;}
114   void SetDiamondProfileTPC(AliESDVertex *dp) {fDiamondProfileTPC=dp;}
115                    
116   void SetCleanESD(Bool_t flag=kTRUE){fCleanESD=flag;}
117   void SetUseHLTData(const char* detectors){fUseHLTData=detectors;}
118   void SetV0DCAmax(Float_t d) {fV0DCAmax=d;}
119   void SetV0CsPmin(Float_t d) {fV0CsPmin=d;}
120   void SetDmax(Float_t d) {fDmax=d;}
121   void SetZmax(Float_t z) {fZmax=z;}
122   Float_t GetV0DCAmax() const {return fV0DCAmax;}
123   Float_t GetV0CsPmin() const {return fV0CsPmin;}
124   Float_t GetDmax() const {return fDmax;}
125   Float_t GetZmax() const {return fZmax;}
126   
127   Bool_t HasNextEventAfter(Int_t eventId);
128   
129   //
130   Bool_t  IsRunMultFinder()   const {return fRunMultFinder;}
131   
132   // CDB storage activation
133   void SetDefaultStorage(const char* uri);
134   void SetSpecificStorage(const char* calibType, const char* uri);
135   void SetCDBSnapshotMode(const char* snapshotFileName);
136   void AddCheckRecoCDBvsSimuCDB(const char* cdbpath,const char* comment="");
137   void RemCheckRecoCDBvsSimuCDB(const char* cdbpath);
138   void ResetCheckRecoCDBvsSimuCDB() {fCheckRecoCDBvsSimuCDB.Delete();}
139   void RectifyCDBurl(TString& url);
140   const TObjArray* GetCheckRecoCDBvsSimuCDB() const {return &fCheckRecoCDBvsSimuCDB;}
141   void CheckRecoCDBvsSimuCDB();
142   Bool_t MisalignGeometry(const TString& detectors);
143
144   void           SetAlignObjArray(TObjArray *array)
145                    {fAlignObjArray = array;
146                    fLoadAlignFromCDB = kFALSE;}
147
148   virtual Int_t  Version() const {return 2;}
149   virtual void   Begin(TTree*);
150   virtual void   SlaveBegin(TTree*);
151   virtual void   Init(TTree *tree);
152   virtual Bool_t Process(Long64_t entry);
153   virtual Bool_t ProcessEvent(Int_t iEvent);
154   virtual void   SlaveTerminate();
155   virtual void   Terminate();
156   virtual Bool_t Run(const char* input = NULL);
157   void           Abort(const char *method, EAbort what);
158   virtual void   SetOption(const char* option) {
159     TSelector::SetOption(option);
160   }
161
162   // Trackers
163   AliTracker* GetTracker(Int_t idx) const { return fTracker[idx]; }
164   Bool_t      CreateTrackers(const TString& detectors);
165   void        ImportRunLoader(AliRunLoader* rl) { fRunLoader = rl; }
166
167   // Quality Assurance 
168   void    SetQACycles(AliQAv1::DETECTORINDEX_t det, Int_t cycles) { fQACycles[det] = cycles ; }
169   void    SetQAWriteExpert(AliQAv1::DETECTORINDEX_t det) { fQAWriteExpert[det] = kTRUE ; }
170   Bool_t  SetRunQA(TString detAndAction="ALL:ALL") ; 
171   void    SetRunGlobalQA(Bool_t flag=kTRUE){fRunGlobalQA = flag;}
172   void    SetQARefDefaultStorage(const char* uri);
173   void    InitQA();
174   void    MergeQA(const char *fileName = NULL); 
175   void    SetWriteQAExpert() { fWriteQAExpertData = kTRUE ; }
176   Bool_t  IsRunQA() const { return fRunQA ; } 
177   Bool_t  IsRunGlobalQA() const { return fRunGlobalQA ; }
178   Bool_t  IsInTasks(AliQAv1::TASKINDEX_t tsk) { return fQATasks.Contains(Form("%d", tsk)) ; }
179   
180   // Plane Efficiency Evaluation
181   void    SetRunPlaneEff(Bool_t flag=kFALSE)  {fRunPlaneEff = flag;}
182
183   enum {
184     kNDetectors = 18   // number of detectors    + AD +FIT //alla
185   };
186   static Int_t   GetDetIndex(const char * detector);
187   static const char** GetDetectorNames() { return fgkDetectorName; }
188
189   // Upgrade
190  void SetUpgradeModule(const char* detectors)  {fUpgradeModule = detectors; MatchUpgradeDetector() ; }
191  void MatchUpgradeDetector();
192
193   // Connection to analysis manager. 
194   // If a macro is set it should contain a function returning an analysis 
195   // manager object. The macro is ignored in case the analysis manager is 
196   // set via SetAnalysisManager
197   void        SetAnalysisMacro(const char *macropath) {fAnalysisMacro = macropath;}
198   const char *GetAnalysisMacro() const {return fAnalysisMacro.Data();}
199   void        SetAnalysisManager(AliAnalysisManager *mgr) {fAnalysis = mgr;}
200   AliAnalysisManager *GetAnalysisManager() const {return fAnalysis;}
201
202   // A method to declare defined trigger classes even if they are not
203   // present in the run, needed for proper event selection based on trigger
204   void        DeclareTriggerClasses(const char *trClasses) {fDeclTriggerClasses = trClasses;}
205   //
206   //
207   void                                   CleanProcessedEvent();
208    
209   AliESDEvent* GetESDEvent() const { return fesd; }
210   AliESDfriend* GetESDfriend() const { return fesdf; }
211   AliRunLoader* GetRunLoader() const { return fRunLoader;}
212   AliRawReader* GetRawReader() const { return fRawReader; }
213   
214   Bool_t       HasEnoughResources(int ev);
215   void         SetStopOnResourcesExcess(int vRSS=3000,int vVMEM=4000);
216   //
217   //
218   virtual Bool_t ProcessEvent(void* event);
219   void           InitRun(const char* input);
220
221 protected:
222   // Functions needed to select events for which we store the ESD friends
223   Bool_t IsHighPt() const;
224   Bool_t IsCosmicOrCalibSpecie() const;
225   void WriteESDfriend();
226
227 private:
228   AliReconstruction(const AliReconstruction& rec);
229   AliReconstruction& operator = (const AliReconstruction& rec);
230
231   void           InitRawReader(const char* input);
232   void           InitCDB();
233   Bool_t         InitGRP();
234   void           SetCDBLock();
235   Bool_t         SetRunNumberFromData();
236   Bool_t         LoadCDB();
237   Bool_t         LoadTriggerScalersCDB();
238   Bool_t         LoadCTPTimeParamsCDB();
239   Bool_t         ReadIntensityInfoCDB();
240   Bool_t         RunLocalEventReconstruction(const TString& detectors);
241   Bool_t         RunVertexFinder(AliESDEvent*& esd);
242   Bool_t         RunMuonTracking(AliESDEvent*& esd);
243   Bool_t         RunMFTTrackingMU(AliESDEvent*& esd);      // AU
244   Bool_t         RunSPDTrackleting(AliESDEvent*& esd);
245   Bool_t         RunMultFinder(AliESDEvent*& esd);
246   Bool_t         RunTracking(AliESDEvent*& esd, AliESDpid &PID);
247   Bool_t         CleanESD(AliESDEvent *esd);
248   Bool_t         FillESD(AliESDEvent*& esd, const TString& detectors);
249   Bool_t         FillTriggerESD(AliESDEvent*& esd);
250   Bool_t         FillTriggerScalers(AliESDEvent*& esd);
251   Bool_t         FillRawEventHeaderESD(AliESDEvent*& esd);
252   void           DeleteRecPoints(const TString& detectors);
253   void           DeleteDigits(const TString& detectors);
254
255   Bool_t         IsSelected(TString detName, TString& detectors) const;
256   Bool_t         InitRunLoader();
257   AliReconstructor* GetReconstructor(Int_t iDet);
258   AliVertexer*   CreateVertexer();
259   AliTrackleter* CreateMultFinder();
260   void           CleanUp();
261
262   Bool_t         ParseOutput();
263
264   //==========================================//
265   void           WriteAlignmentData(AliESDEvent* esd);
266
267   void           FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd);
268
269   //Quality Assurance
270   //  void                 CheckQA() ;
271
272   // Plane Efficiency evaluation
273   Bool_t  FinishPlaneEff(); //ultimate tasks related to Plane Eff. evaluation 
274   Bool_t  InitPlaneEff();   // initialize what is needed for Plane Eff. evaluation
275
276   Bool_t               InitAliEVE();
277   void                 RunAliEVE();
278
279   Bool_t         InitRecoParams(); // init the array with the reconstruciton parameters
280   Bool_t         GetEventInfo();   // fill the event info inside the event loop
281   void           ProcessTriggerAliases();
282   Bool_t         TriggerMatches2Alias(const char* trigName, const char* alias);
283   const char    *MatchDetectorList(const char *detectorList, UInt_t detectorMask);
284
285   //*** Global reconstruction flags *******************
286   Bool_t         fRunVertexFinder;    // run the vertex finder
287   Bool_t         fRunVertexFinderTracks;    // run the vertex finder with tracks
288   Bool_t         fRunMuonTracking;    // run the MUON tracking
289   Bool_t         fRunMFTTrackingMU;   // run the MFT+MUON tracking      // AU
290   Bool_t         fRunV0Finder;        // run the ESD V0 finder
291   Bool_t         fRunCascadeFinder;   // run the ESD cascade finder
292   Bool_t         fRunMultFinder;      // run the trackleter for ITS clusters
293   Bool_t         fStopOnError;        // stop or continue on errors
294   Bool_t         fStopOnMissingTriggerFile; // stop if the simulated trigger file is absent
295   Bool_t         fWriteAlignmentData; // write track space-points flag
296   Bool_t         fWriteESDfriend;     // write ESD friend flag
297   Bool_t         fFillTriggerESD;     // fill trigger info into ESD
298
299   //*** Clean ESD flag and parameters *******************
300   Bool_t         fCleanESD;      // clean ESD flag
301   Float_t        fV0DCAmax;      // max. allowed DCA between V0 daugthers 
302   Float_t        fV0CsPmin;      // min. allowed cosine of V0 pointing angle 
303   Float_t        fDmax;          // max. allowed transverse impact parameter 
304   Float_t        fZmax;          // max. allowed longitudinal impact parameter 
305   
306   TString        fCosmicAlias;        // alias for cosmic triggers
307   TString        fLaserAlias;         // alias for laser triggers
308   //
309   TString        fRunLocalReconstruction; // run the local reconstruction for these detectors
310   TString        fRunTracking;        // run the tracking for these detectors
311   TString        fFillESD;            // fill ESD for these detectors
312   TString        fDeleteRecPoints;    // delete recpoints after each event
313   TString        fDeleteDigits;       // delete digits after each event
314   TString        fLoadCDB;            // prefetch CDB entries and init reco-params for these detectors
315   TString        fUseTrackingErrorsForAlignment; // for these detectors
316   TString        fGAliceFileName;     // name of the galice file
317   TString        fRawInput;           // name of input raw-data file or directory
318   TString        fESDOutput;          //! name of output ESD file
319   TString        fProofOutputFileName;//! name of output file in PROOF mode
320   TString        fProofOutputLocation;//! output location in PROOF mode
321   Bool_t         fProofOutputDataset; //! keep output file in PROOF mode in dataset or merge
322   TString        fProofOutputArchive; //! list of file to be kept in output zip archive in PROOF mode
323   TString        fEquipIdMap;         // name of file with equipment id map
324   Int_t          fFirstEvent;         // index of first event to be reconstr.
325   Int_t          fLastEvent;          // index of last event to be reconstr.
326   UInt_t         fNumberOfEventsPerFile; // number of events per file in case of raw-data reconstruction
327   Double32_t     fFractionFriends; // fraction of ESD friends to be stored
328   TObjArray      fOptions;            // options for reconstructor objects
329   Bool_t         fLoadAlignFromCDB;   // Load alignment data from CDB and apply it to geometry or not
330   TString        fLoadAlignData;      // Load alignment data from CDB for these detectors
331   TString        fUseHLTData;        // Detectors for which the HLT data is used as input
332   AliRunInfo*    fRunInfo;            // an object which contains essential global conditions information
333   AliEventInfo   fEventInfo;          // an object which contains essential event information
334   AliTriggerRunScalers* fRunScalers;  // an object which contains the trigger counters for xsection
335   AliCTPTimeParams* fCTPTimeParams;   // an object which contains the trigger delays
336   AliCTPTimeParams* fCTPTimeAlign;    // an object which contains the CTP (mis)alignment data
337   AliRunLoader*  fRunLoader;          //! current run loader object
338   AliRawReader*  fRawReader;          //! current raw data reader
339   AliRawReader*  fParentRawReader;    //! parent raw data reader in case of AliRawReaderHLT
340
341   static const char* fgkDetectorName[kNDetectors]; //! names of detectors
342   AliReconstructor*  fReconstructor[kNDetectors];  //! array of reconstructor objects
343   AliRecoParam   fRecoParam;                      // container for the reco-param objects for detectors
344   AliLoader*     fLoader[kNDetectors];   //! detector loaders
345   AliTracker*    fTracker[kNDetectors];  //! trackers
346   AliTracker*    fSPDTrackleter;           //! trackleter [for SPD Plane Efficiency purposes]
347   AliESDVertex*  fDiamondProfileSPD;       // (x,y) diamond profile from SPD for AliITSVertexer3D(Z)
348   AliESDVertex*  fDiamondProfile;          // (x,y) diamond profile for AliVertexerTracks (ITS+TPC)
349   AliESDVertex*  fDiamondProfileTPC;       // (x,y) diamond profile from TPC for AliVertexerTracks
350   THashTable*    fListOfCosmicTriggers;    // list of cosmic triggers as defined by trigger coordination (RS for BWD comp)
351   THashList*     fAlias2Trigger;          // list of aliases with string of triggers per alias
352
353   AliGRPObject*  fGRPData;              // Data from the GRP/GRP/Data CDB folder
354
355   TObjArray*     fAlignObjArray;      //! array with the alignment objects to be applied to the geometry
356
357   TString        fCDBUri;             //! Uri of the default CDB storage
358   TString        fQARefUri;         //! Uri of the default QA reference storage
359   TObjArray      fSpecCDBUri;         //! Array with detector specific CDB storages
360   TObjArray      fCheckRecoCDBvsSimuCDB; // Array for CDB items which must be the same in the sim and rec
361   Bool_t         fInitCDBCalled;               //! flag to check if CDB storages are already initialized
362   Bool_t         fCDBSnapshotMode;             //! flag true if we are setting the CDB Manager in snapshot mode
363   Bool_t         fSetRunNumberFromDataCalled;  //! flag to check if run number is already loaded from run loader
364
365   //Quality Assurance
366   Int_t  fQACycles[     AliQAv1::kNDET];  // # events over which QA data are accumulated
367   Bool_t fQAWriteExpert[AliQAv1::kNDET];  // Flag to save or not expert QA data
368   TString               fQADetectors ;  // list of detectors to be QA'ed        
369   TString               fQATasks ;      // list of QA tasks to be performed     
370   Bool_t                fRunQA ;        // Run QA flag
371   Bool_t                fRunGlobalQA;   // Run global QA flag
372   Bool_t                fSameQACycle;   //! open a new QA data file or not
373   Bool_t                fInitQACalled;  //! control of QA intialisation
374   Bool_t                fWriteQAExpertData ; //! decides wheter or not to write experts QA data; true by default
375
376   // Plane Efficiency Evaluation
377   Bool_t         fRunPlaneEff ;      // Evaluate Plane Efficiency
378
379   // PID
380   AliESDpid*     fESDpid;                      // PID object
381
382   // New members needed in order to split Run method
383   // into InitRun,RunEvent,FinishRun methods
384   AliESDEvent*         fesd;        //! Pointer to the ESD event object
385   AliESDEvent*         fhltesd;     //! Pointer to the HLT ESD event object
386   AliESDfriend*        fesdf;       //! Pointer to the ESD friend object
387   TFile*               ffile;       //! Pointer to the ESD file
388   TFile*               ffileF;      //! Pointer to the ESD friend file
389   TTree*               ftree;       //! Pointer to the ESD tree
390   TTree*               ftreeF;      //! Pointer to the ESD friend tree
391   TTree*               fhlttree;    //! Pointer to the HLT ESD tree
392   AliVertexerTracks*   ftVertexer;  //! Pointer to the vertexer based on ESD tracks
393   Bool_t               fIsNewRunLoader; // galice.root created from scratch (real raw data case)
394   Bool_t               fRunAliEVE;  // Run AliEVE or not
395   Double_t             fBeamInt[2][2]; //! mean beam intensities from AliLHCData
396   
397   TTree*              fChain;      //! The raw-data chain in case of AliRawReaderChain
398
399   // Counters used in WriteESDfriend()
400   Int_t fNall;    //! Number of reconstructed events
401   Int_t fNspecie; //! Number of events, selected by IsCosmicOrCalibSpecie
402   Int_t fSspecie; //! Number of events, sampled from fNspecie
403   Int_t fNhighPt; //! Number of events, selected by IsHighPt 
404   Int_t fShighPt; //! Number of events, sampled from fNhighPt
405  
406   // Counters for SetAutoFlush configuration
407   Long64_t fTreeBuffSize;   //  allowed uncompressed buffer size per tree
408   Long64_t fMemCountESD;    //! accumulated ESD size before AutoSave 
409   Long64_t fMemCountESDF;   //! accumulated ESD size before AutoSave 
410   Long64_t fMemCountESDHLT; //! accumulated ESD size before AutoSave 
411   //
412   // Upgrade detector reconstruction
413   TString fUpgradeModule;
414   Bool_t  fUpgradeMask[kNDetectors];
415   // Connect an analysis manager in the event loop
416   TString              fAnalysisMacro; // Full path to a macro creating an analysis manager train
417   AliAnalysisManager  *fAnalysis;      //! Analysis manager
418   AliRecoInputHandler *fRecoHandler;   //! Input handler adapted for reconstruction
419   TString              fDeclTriggerClasses; // Declared defined trigger classes
420   //
421   Bool_t               fStopped;        //  flag that reco is stopped due to the limited resources 
422   Int_t                fMaxRSS;         //  max RSS memory, MB
423   Int_t                fMaxVMEM;        //  max VMEM memory, MB
424   static const char*   fgkStopEvFName;  //  filename for stop.event stamp
425   //
426   ClassDef(AliReconstruction, 49)      // class for running the reconstruction
427 };
428
429 #endif