]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MakeSDigits.C
New macro for generation SDigits from raw data for merging
[u/mrichter/AliRoot.git] / MUON / MakeSDigits.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 /* $Id */
17
18 /// \ingroup macros
19 /// \file MakeSDigits.C
20 /// \brief Macro for generation SDigits from raw data for merging 
21 /// \author Indranil Das, HEP Division, SINP (indra.das@saha.ac.in, indra.ehep@gmail.com)
22 ///
23 /// Usage : To run this code one should have $ALICE_ROOT/MUON/rootlogon.C 
24 ///         in the current working directory. Then run it from command line as,
25 /// <pre>aliroot MakeSDigits.C\(\""reconstructed galicefile"\",\""rawdatafile"\",\""OCDB path"\",run-numer\)
26 ///
27 ///        where inputs are : 1. galice file of local reconstruction directory
28 ///                           2. rootified rawdata file of local reconstruction directory.
29 ///                           In case the raw data are ddl files, specify the path which has "raw0", "raw1".... events
30 ///                           3. OCDB path
31 ///                           4. run number
32 ///        and the output is : "MUON.SDigits.root" file with the same tree and event structure as produced in simulation directory
33 /// </pre>
34 /// Note:  
35 /// galice.root and raw.root cannot be a directory read from alien 
36 /// beacuse "muonLoader->WriteSDigits("OVERWRITE")" tries to write in reconstruction directory,
37 /// which will fail. For files in alien, make a local copy of the galice and raw.root file, and run the code
38 /// in that directory.
39 ///
40 /// Merging Hints :    
41 /// Follow the merging procedure as specified in the \ref README_sim page, with 
42 /// <pre>MuonSim.MergeWith("recodir_that_has_MUON.SDigits.root_from_rawdata/galice.root",nofBackground)
43 /// </pre>
44 /// in the $ALICE_ROOT/MUON/runSimulation.C
45
46 /**********************************************************************
47  Created on : 11/01/2010
48  Purpose    : To create SDigits from RawData
49  Author     : Indranil Das, HEP Division, SINP
50  Email      : indra.das@saha.ac.in | indra.ehep@gmail.com
51 **********************************************************************/
52
53
54 int MakeSDigits(const char* galiceFile="galice.root", const char* rawRootFile="./raw.root", 
55                 const char* ocdb = "local://$ALICE_ROOT/OCDB", int run=0)
56 {
57   //TGrid connect for alien ocdb
58   TGrid::Connect("alien://");
59   
60   AliCDBManager *man = AliCDBManager::Instance();
61   man->SetDefaultStorage(ocdb);
62   man->SetRun(run);
63   
64   AliMpCDB::LoadDDLStore(true);
65   
66   AliRawReader *rawReader = AliRawReader::Create(rawRootFile);
67
68   AliRunLoader* runLoader = AliRunLoader::Open(galiceFile);
69   AliLoader* muonLoader = runLoader->GetDetectorLoader("MUON");
70   
71   for(Int_t iEvent=0;iEvent<runLoader->GetNumberOfEvents();iEvent++){
72  
73     cout<<"Running for Event : "<<iEvent<<endl;
74    
75     rawReader->NextEvent();
76     runLoader->GetEvent(iEvent);
77     
78     muonLoader->LoadSDigits("update");
79     muonLoader->CleanSDigits();
80     if (!muonLoader->TreeS()) muonLoader->MakeSDigitsContainer();
81     
82     TTree* treeS = muonLoader->TreeS();
83     
84     AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
85     sDigitStore->Connect(*treeS,true);
86
87     AliMUONDigitMaker *digitMaker = new AliMUONDigitMaker(false);
88     digitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
89     
90     TIter next(sDigitStore->CreateIterator());
91     AliMUONVDigit *mdigit;
92     
93     while ( (mdigit = reinterpret_cast<AliMUONVDigit *>(next())) ) {
94       mdigit->SetCharge(Float_t(mdigit->ADC()));
95       mdigit->SetADC(0);
96       //mdigit->Print();
97     }
98     treeS->Fill();
99    
100     muonLoader->WriteSDigits("OVERWRITE");
101     
102     muonLoader->UnloadSDigits();
103     
104     sDigitStore->Delete();
105     digitMaker->Delete();
106     
107   }
108   delete runLoader;
109
110   return 0;
111 }