ROOT logo
// $Id$
/*
 * @file sim-hlt-tpc.C
 * @brief HLT Conformal mapping tracker embedded into AliRoot simulation.
 *
 * Example macro to run the HLT Conformal mapping tracker embedded into
 * AliRoot simulation. The reconstruction is done from the TPC digits.
 *
 * Usage: aliroot -b -q sim-hlt-tpc.C | tee sim-hlt-tpc.log
 *
 * The chain to be run is defined within the macro. The input data is
 * read from the TPC.Digits.
 *
 * The following options can be specified comma separated in a string:
 * <pre>
 *   aliroot -b -q sim-hlt-tpc.C'("options")'
 *       CA      use the cellular automaton  tracker and track merger
 *       CM      use the conformal mapping tracker and track merger
 *       SORTED  use CF pre-sorting and corresponding sequential CF
 *               algorithm, by default the algorithm capable of reading
 *               unsorted data is used
 *       RAW     write raw data for all detectors
 *       RAWHLT  write raw data only for HLT
 *       MC      propagate the MC information
 * </pre>
 *
 * The macro asumes the data to be already simulated. If it should run
 * within the initial simulation, comment the corresponding functions
 * below (SetRunGeneration etc.)
 *
 * @author Matthias.Richter@ift.uib.no
 * @ingroup alihlt_tpc
 */
sim_hlt_tpc(const char* options="CA")
{
  // this is just a tool to switch the logging systems
  AliHLTLogging log;
  //log.SwitchAliLog(0);

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // scanning the options
  //
  bool bUseCA=true;   // use the CA tracker and merger
  bool bCFSort=false; // CF pre-sorting and sequential CF algorithm
  bool bRawData=false;// raw data for all detectors
  bool bRawHLTData=false; // raw data only for HLT
  bool bPropagateMC=false;
  TString tsOptions=options;
  TObjArray* pTokens=tsOptions.Tokenize(",");
  if (pTokens) {
    for (int n=0; n<pTokens->GetEntries(); n++) {
      TString arg=((TObjString*)pTokens->At(n))->GetString();
      if (arg.CompareTo("ca", TString::kIgnoreCase)==0) {
	bUseCA=true;
      } else if (arg.CompareTo("cm", TString::kIgnoreCase)==0) {
	bUseCA=false;
      } else if (arg.CompareTo("sorted", TString::kIgnoreCase)==0) {
	bCFSort=true;
      } else if (arg.CompareTo("unsorted", TString::kIgnoreCase)==0) {
	bCFSort=false;
      } else if (arg.CompareTo("raw", TString::kIgnoreCase)==0) {
	bRawData=true;
      } else if (arg.CompareTo("rawhlt", TString::kIgnoreCase)==0) {
	bRawHLTData=true;
      } else if (arg.CompareTo("mc", TString::kIgnoreCase)==0) {
	bPropagateMC=true;
      } else {
	cout << "unknown argument: " << arg << endl;
	return 0;
      }
    }
    delete pTokens;
  }
  // summary
  cout << "using " << bUseCA?"CA":"CM" << " tracker" << endl;
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // init the HLT system in order to define the analysis chain below
  //
  AliHLTSystem* gHLT=AliHLTPluginBase::GetInstance();

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // define the analysis chain
  //

  // load TPCParam from OCDB
  const char* cdbEntry="TPC/Calib/Parameters";
  AliCDBManager* pMan=AliCDBManager::Instance();
  AliTPCParam* pTPCParam=NULL;
  if (pMan) {
    if (!pMan->IsDefaultStorageSet()) {
      pMan->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
      pMan->SetRun(0);
    }
    AliCDBEntry *pEntry = pMan->Get(cdbEntry);
    if (pEntry && 
	pEntry->GetObject() &&
	(pTPCParam=dynamic_cast<AliTPCParam*>(pEntry->GetObject()))) {
    } else {
      HLTWarning("can not load AliTPCParam from CDB entry %s", cdbEntry);
    }
  }

  int iMinSlice=0; 
  int iMaxSlice=35;
  int iMinPart=0;
  int iMaxPart=5;
  TString mergerInput;
  TString writerInput;
  TString sinkClusterInput;
  for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
    TString trackerInput;
    for (int part=iMinPart; part<=iMaxPart; part++) {
      TString arg, publisher, cf;

      // digit publisher components
      arg.Form("-slice %d -partition %d", slice, part);
      publisher.Form("DP_%02d_%d", slice, part);
      AliHLTConfiguration pubconf(publisher.Data(), "TPCDigitPublisher", NULL , arg.Data());

      // cluster finder components
      arg="-timebins ";
      if (pTPCParam) arg+=pTPCParam->GetMaxTBin()+1;
      else arg+=446; // old simulated data
      if (bCFSort) arg+=" -sorted ";
      if (bPropagateMC) arg+=" -do-mc ";
      cf.Form("CF_%02d_%d", slice, part);
      AliHLTConfiguration cfconf(cf.Data(), "TPCClusterFinderUnpacked", publisher.Data(), arg.Data());
      if (trackerInput.Length()>0) trackerInput+=" ";
      trackerInput+=cf;
      if (sinkClusterInput.Length()>0) sinkClusterInput+=" ";
      sinkClusterInput+=cf;
    }

    TString tracker;
    // tracker finder components
    tracker.Form("TR_%02d", slice);
    if (bUseCA) {
      AliHLTConfiguration trackerconf(tracker.Data(), "TPCCATracker", trackerInput.Data(), "");
    } else {
      AliHLTConfiguration trackerconf(tracker.Data(), "TPCSliceTracker", trackerInput.Data(), "-pp-run");
    }

    //add all trackers to writer input. Include if you would like all slice tracks written.
    //if (writerInput.Length()>0) writerInput+=" ";
    //writerInput+=tracker;

    // add all clusterfinders to the writer input
    if (writerInput.Length()>0) writerInput+=" ";
    writerInput+=trackerInput;

    if (mergerInput.Length()>0) mergerInput+=" ";
    mergerInput+=tracker;

  }

  // GlobalMerger component
  if (bUseCA) {
    AliHLTConfiguration mergerconf("globalmerger","TPCCAGlobalMerger",mergerInput.Data(),"");
  } else {
    AliHLTConfiguration mergerconf("globalmerger","TPCGlobalMerger",mergerInput.Data(),"");
  }

  TString converterInput="globalmerger";

  // collector for the MC information to be propagated from CFs to ESDConverter
  if (bPropagateMC){
    AliHLTConfiguration mcinfo("mcinfo", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLMCINFO' 'TPC '");  
    AliHLTConfiguration mcTrackMarker("mcTrackMarker","TPCTrackMCMarker","globalmerger mcinfo","" );
    converterInput+=" mcTrackMarker";
  }

  if (writerInput.Length()>0) writerInput+=" ";
  writerInput+="globalmerger";


  //////////////////////////////////////////////////////////////////////////////////////////
  //
  // output section
  //

  //////////////////////////////////////////////////////////////////////////////////////////
  // sink1: id=sink-writeall write all blocks
  AliHLTConfiguration sink1("sink-writeall", "FileWriter"   , writerInput.Data(), "-specfmt -subdir=event_%d -blcknofmt=_0x%x -idfmt=_0x%08x");


  //////////////////////////////////////////////////////////////////////////////////////////
  // sink2: id=sink-esd-file write ESD using the TPCEsdWriter
  AliHLTConfiguration sink2("sink-esd-file", "TPCEsdWriter"   , converterInput.Data(), "-datafile AliHLTESDs.root");


  //////////////////////////////////////////////////////////////////////////////////////////
  // sink3: id=sink-esd add ESD to HLTOUT using the TPCEsdConverter

  // the esd converter configuration
  AliHLTConfiguration sink3("sink-esd", "TPCEsdConverter"   , converterInput.Data(), "");

  //////////////////////////////////////////////////////////////////////////////////////////
  // sink4: id=sink-clusters add cluster data blocks to HLTOUT
  AliHLTConfiguration sink4("sink-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTERS' 'TPC '");

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Init and run the HLT simulation
  // All but HLT simulation is switched off
  //
  AliSimulation sim;
 
  // switch of simulation and data generation
  // comment all that stuff to also simulate the events and data
  sim.SetRunGeneration(kFALSE);
  sim.SetMakeDigits("");
  sim.SetMakeSDigits("");
  sim.SetMakeDigitsFromHits("");
  //sim.SetMakeTrigger("");
  sim.SetRunQA(":");

  // the normal simulation sets the specific storage for the GRP entry
  if (gSystem->AccessPathName("GRP/GRP/Data")) {
    cerr << "*********************************************************" << endl;
    cerr << "error: no GRP entry found in the currect directory, simulation might be incomplete. Skip setting specific storage for GRP entry" << endl;
    cerr << "*********************************************************" << endl << endl;
  } else {
    sim.SetSpecificStorage("GRP/GRP/Data",
			   Form("local://%s",gSystem->pwd()));
  }

  TString rawDataSelection="HLT";
  if (bRawData) rawDataSelection="ALL";
  if (bRawHLTData || bRawData) sim.SetWriteRawData(rawDataSelection, "raw.root", kTRUE);

  // set the options for the HLT simulation
  sim.SetRunHLT("libAliHLTUtil.so libAliHLTTPC.so loglevel=0x7c "
		"chains=sink-esd,sink-clusters");
  sim.Run();
}
 sim-hlt-tpc.C:1
 sim-hlt-tpc.C:2
 sim-hlt-tpc.C:3
 sim-hlt-tpc.C:4
 sim-hlt-tpc.C:5
 sim-hlt-tpc.C:6
 sim-hlt-tpc.C:7
 sim-hlt-tpc.C:8
 sim-hlt-tpc.C:9
 sim-hlt-tpc.C:10
 sim-hlt-tpc.C:11
 sim-hlt-tpc.C:12
 sim-hlt-tpc.C:13
 sim-hlt-tpc.C:14
 sim-hlt-tpc.C:15
 sim-hlt-tpc.C:16
 sim-hlt-tpc.C:17
 sim-hlt-tpc.C:18
 sim-hlt-tpc.C:19
 sim-hlt-tpc.C:20
 sim-hlt-tpc.C:21
 sim-hlt-tpc.C:22
 sim-hlt-tpc.C:23
 sim-hlt-tpc.C:24
 sim-hlt-tpc.C:25
 sim-hlt-tpc.C:26
 sim-hlt-tpc.C:27
 sim-hlt-tpc.C:28
 sim-hlt-tpc.C:29
 sim-hlt-tpc.C:30
 sim-hlt-tpc.C:31
 sim-hlt-tpc.C:32
 sim-hlt-tpc.C:33
 sim-hlt-tpc.C:34
 sim-hlt-tpc.C:35
 sim-hlt-tpc.C:36
 sim-hlt-tpc.C:37
 sim-hlt-tpc.C:38
 sim-hlt-tpc.C:39
 sim-hlt-tpc.C:40
 sim-hlt-tpc.C:41
 sim-hlt-tpc.C:42
 sim-hlt-tpc.C:43
 sim-hlt-tpc.C:44
 sim-hlt-tpc.C:45
 sim-hlt-tpc.C:46
 sim-hlt-tpc.C:47
 sim-hlt-tpc.C:48
 sim-hlt-tpc.C:49
 sim-hlt-tpc.C:50
 sim-hlt-tpc.C:51
 sim-hlt-tpc.C:52
 sim-hlt-tpc.C:53
 sim-hlt-tpc.C:54
 sim-hlt-tpc.C:55
 sim-hlt-tpc.C:56
 sim-hlt-tpc.C:57
 sim-hlt-tpc.C:58
 sim-hlt-tpc.C:59
 sim-hlt-tpc.C:60
 sim-hlt-tpc.C:61
 sim-hlt-tpc.C:62
 sim-hlt-tpc.C:63
 sim-hlt-tpc.C:64
 sim-hlt-tpc.C:65
 sim-hlt-tpc.C:66
 sim-hlt-tpc.C:67
 sim-hlt-tpc.C:68
 sim-hlt-tpc.C:69
 sim-hlt-tpc.C:70
 sim-hlt-tpc.C:71
 sim-hlt-tpc.C:72
 sim-hlt-tpc.C:73
 sim-hlt-tpc.C:74
 sim-hlt-tpc.C:75
 sim-hlt-tpc.C:76
 sim-hlt-tpc.C:77
 sim-hlt-tpc.C:78
 sim-hlt-tpc.C:79
 sim-hlt-tpc.C:80
 sim-hlt-tpc.C:81
 sim-hlt-tpc.C:82
 sim-hlt-tpc.C:83
 sim-hlt-tpc.C:84
 sim-hlt-tpc.C:85
 sim-hlt-tpc.C:86
 sim-hlt-tpc.C:87
 sim-hlt-tpc.C:88
 sim-hlt-tpc.C:89
 sim-hlt-tpc.C:90
 sim-hlt-tpc.C:91
 sim-hlt-tpc.C:92
 sim-hlt-tpc.C:93
 sim-hlt-tpc.C:94
 sim-hlt-tpc.C:95
 sim-hlt-tpc.C:96
 sim-hlt-tpc.C:97
 sim-hlt-tpc.C:98
 sim-hlt-tpc.C:99
 sim-hlt-tpc.C:100
 sim-hlt-tpc.C:101
 sim-hlt-tpc.C:102
 sim-hlt-tpc.C:103
 sim-hlt-tpc.C:104
 sim-hlt-tpc.C:105
 sim-hlt-tpc.C:106
 sim-hlt-tpc.C:107
 sim-hlt-tpc.C:108
 sim-hlt-tpc.C:109
 sim-hlt-tpc.C:110
 sim-hlt-tpc.C:111
 sim-hlt-tpc.C:112
 sim-hlt-tpc.C:113
 sim-hlt-tpc.C:114
 sim-hlt-tpc.C:115
 sim-hlt-tpc.C:116
 sim-hlt-tpc.C:117
 sim-hlt-tpc.C:118
 sim-hlt-tpc.C:119
 sim-hlt-tpc.C:120
 sim-hlt-tpc.C:121
 sim-hlt-tpc.C:122
 sim-hlt-tpc.C:123
 sim-hlt-tpc.C:124
 sim-hlt-tpc.C:125
 sim-hlt-tpc.C:126
 sim-hlt-tpc.C:127
 sim-hlt-tpc.C:128
 sim-hlt-tpc.C:129
 sim-hlt-tpc.C:130
 sim-hlt-tpc.C:131
 sim-hlt-tpc.C:132
 sim-hlt-tpc.C:133
 sim-hlt-tpc.C:134
 sim-hlt-tpc.C:135
 sim-hlt-tpc.C:136
 sim-hlt-tpc.C:137
 sim-hlt-tpc.C:138
 sim-hlt-tpc.C:139
 sim-hlt-tpc.C:140
 sim-hlt-tpc.C:141
 sim-hlt-tpc.C:142
 sim-hlt-tpc.C:143
 sim-hlt-tpc.C:144
 sim-hlt-tpc.C:145
 sim-hlt-tpc.C:146
 sim-hlt-tpc.C:147
 sim-hlt-tpc.C:148
 sim-hlt-tpc.C:149
 sim-hlt-tpc.C:150
 sim-hlt-tpc.C:151
 sim-hlt-tpc.C:152
 sim-hlt-tpc.C:153
 sim-hlt-tpc.C:154
 sim-hlt-tpc.C:155
 sim-hlt-tpc.C:156
 sim-hlt-tpc.C:157
 sim-hlt-tpc.C:158
 sim-hlt-tpc.C:159
 sim-hlt-tpc.C:160
 sim-hlt-tpc.C:161
 sim-hlt-tpc.C:162
 sim-hlt-tpc.C:163
 sim-hlt-tpc.C:164
 sim-hlt-tpc.C:165
 sim-hlt-tpc.C:166
 sim-hlt-tpc.C:167
 sim-hlt-tpc.C:168
 sim-hlt-tpc.C:169
 sim-hlt-tpc.C:170
 sim-hlt-tpc.C:171
 sim-hlt-tpc.C:172
 sim-hlt-tpc.C:173
 sim-hlt-tpc.C:174
 sim-hlt-tpc.C:175
 sim-hlt-tpc.C:176
 sim-hlt-tpc.C:177
 sim-hlt-tpc.C:178
 sim-hlt-tpc.C:179
 sim-hlt-tpc.C:180
 sim-hlt-tpc.C:181
 sim-hlt-tpc.C:182
 sim-hlt-tpc.C:183
 sim-hlt-tpc.C:184
 sim-hlt-tpc.C:185
 sim-hlt-tpc.C:186
 sim-hlt-tpc.C:187
 sim-hlt-tpc.C:188
 sim-hlt-tpc.C:189
 sim-hlt-tpc.C:190
 sim-hlt-tpc.C:191
 sim-hlt-tpc.C:192
 sim-hlt-tpc.C:193
 sim-hlt-tpc.C:194
 sim-hlt-tpc.C:195
 sim-hlt-tpc.C:196
 sim-hlt-tpc.C:197
 sim-hlt-tpc.C:198
 sim-hlt-tpc.C:199
 sim-hlt-tpc.C:200
 sim-hlt-tpc.C:201
 sim-hlt-tpc.C:202
 sim-hlt-tpc.C:203
 sim-hlt-tpc.C:204
 sim-hlt-tpc.C:205
 sim-hlt-tpc.C:206
 sim-hlt-tpc.C:207
 sim-hlt-tpc.C:208
 sim-hlt-tpc.C:209
 sim-hlt-tpc.C:210
 sim-hlt-tpc.C:211
 sim-hlt-tpc.C:212
 sim-hlt-tpc.C:213
 sim-hlt-tpc.C:214
 sim-hlt-tpc.C:215
 sim-hlt-tpc.C:216
 sim-hlt-tpc.C:217
 sim-hlt-tpc.C:218
 sim-hlt-tpc.C:219
 sim-hlt-tpc.C:220
 sim-hlt-tpc.C:221
 sim-hlt-tpc.C:222
 sim-hlt-tpc.C:223
 sim-hlt-tpc.C:224
 sim-hlt-tpc.C:225
 sim-hlt-tpc.C:226
 sim-hlt-tpc.C:227
 sim-hlt-tpc.C:228
 sim-hlt-tpc.C:229
 sim-hlt-tpc.C:230
 sim-hlt-tpc.C:231
 sim-hlt-tpc.C:232
 sim-hlt-tpc.C:233
 sim-hlt-tpc.C:234
 sim-hlt-tpc.C:235
 sim-hlt-tpc.C:236
 sim-hlt-tpc.C:237
 sim-hlt-tpc.C:238
 sim-hlt-tpc.C:239
 sim-hlt-tpc.C:240
 sim-hlt-tpc.C:241
 sim-hlt-tpc.C:242
 sim-hlt-tpc.C:243
 sim-hlt-tpc.C:244
 sim-hlt-tpc.C:245
 sim-hlt-tpc.C:246
 sim-hlt-tpc.C:247
 sim-hlt-tpc.C:248