ROOT logo
//*-- AUTHOR : Jochen Markert

//_HADES_CLASS_DESCRIPTION 
///////////////////////////////////////////////////////////////////////////////
//
// HMdcDeDx2Maker
//
// This transformation class calculates the pseudo dEdx from t2-t1 (time above threshold)
// of all fired drift cells included in one HMdcSeg. The transformation is performed using
// the parameter container HMdcDEdX2, which holds the parameters for normalization of the
// measured t2-t1 with impact angle and minimum distance to wire (CAL2 parametrization)
// and the algorithm to normalize the single measurements and average over all cells included
// in the segment. Inside the execute() function a loop over the category of HMdcTrkCand is
// performed and the dEdx calculation is done for each inner and outer HMdcSeg separately.
// The result is filled to HMdcTrkCand.
// Explanations can be looked up in HMdcDeDX2.
//
// Since the filling of dEdx is compute intensive, by default only the combined
// dEdx for inner+outer MDC segment is filled (used by dst production). Additional
// dEdx can be calculated per segment and Mdc module. All dEdx values will be stored
// in HMdcTrkCand.
//
// static setUseModule(Int_t module);   switch for caldedx()  = 0 first mod in seg,
//                                                            = 1 second mod in seg,
//                                                            = 2 both mods in seg (default)
// static setFillCase(In_t case);   0 = combined (default) ,
//                                  1 = combined + seg,
//                                  2 = combined + seg + mod
//
// The functions above have to called after creating the task.
///////////////////////////////////////////////////////////////////////////////
#include "hmdcdedx2maker.h"
#include "hmdcdedx2.h"
#include "hmdcseg.h"
#include "hmdcdef.h"
#include "hmdctrackddef.h"
#include "hmdctrkcand.h"
#include "hmdcclusinf.h"
#include "hmdcclus.h"
#include "hdebug.h"
#include "hades.h"
#include "hiterator.h"
#include "hruntimedb.h"
#include "hevent.h"
#include "hcategory.h"
#include "hmessagemgr.h"

#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;

ClassImp(HMdcDeDx2Maker)


Int_t   HMdcDeDx2Maker::module=2;
Int_t   HMdcDeDx2Maker::fillCase=2;


HMdcDeDx2Maker::HMdcDeDx2Maker(void) {
  // Default constructor .
  initParameters();
}
HMdcDeDx2Maker::HMdcDeDx2Maker(const Text_t* name,const Text_t* title)
                 :  HReconstructor(name,title) {
  // Constructor calls the constructor of class HReconstructor with the name
  // and the title as arguments.
  initParameters();
}

HMdcDeDx2Maker::~HMdcDeDx2Maker(void) {
  // destructor deletes the iterator
  if (trkcanditer) delete trkcanditer;
  trkcanditer = 0;
}
void HMdcDeDx2Maker::initParameters()
{
    trkcandCat = 0;
    segCat     = 0;
    clsCat     = 0;
    clsInfCat  = 0;
    cal1Cat    = 0;
    trkcanditer= 0;
    mdcdedx    = 0;
    hasPrinted = kFALSE;
    module     = 2;
    fillCase   = 2;
}
void HMdcDeDx2Maker::setParContainers() {
  // creates the parameter containers MdcDeDx if they do not
  // exist and adds them to the list of parameter containers in the runtime
  // database
    mdcdedx = (HMdcDeDx2*)(((HRuntimeDb*)(gHades->getRuntimeDb()))->getContainer("MdcDeDx2"));
    if(!mdcdedx) {
	    Error("HMdcDeDx2Maker:setParContainers()","RETRIEVED 0 POINTER FOR HMDCDEDX!");
	    exit(1);
    }else{
	Bool_t ok = mdcdedx->initContainer();
	if(!ok){
	    Error("HMdcDeDx2Maker:setParContainers()","INIT OF HMDCDEDX FAILED!");
	    exit(1);
	}
    }
}
Bool_t HMdcDeDx2Maker::init(void) {
    // gets the pointers to HMdcTrkC and HMdcSeg categories
    // calls the function setParContainers()
    setParContainers();
    trkcandCat = (HCategory*)(((HEvent*)(gHades->getCurrentEvent()))->getCategory(catMdcTrkCand));
    if (!trkcandCat) {
	Error("HMdcDeDx2Maker:init()","HMdcTrkCand Category not available!");
	exit(1);
    }
    segCat = (HCategory*)(((HEvent*)(gHades->getCurrentEvent()))->getCategory(catMdcSeg));
    if (!segCat) {
	Error("HMdcDeDx2Maker:init()","HMdcSeg Category not available!");
	exit(1);
    }
    clsCat = (HCategory*)(((HEvent*)(gHades->getCurrentEvent()))->getCategory(catMdcClus));
    if (!clsCat) {
	Error("HMdcDeDx2Maker:init()","HMdcClus Category not available!");
	exit(1);
    }
    clsInfCat = (HCategory*)(((HEvent*)(gHades->getCurrentEvent()))->getCategory(catMdcClusInf));
    if (!clsInfCat) {
	Error("HMdcDeDx2Maker:init()","HMdcClusInf Category not available!");
	exit(1);
    }
    cal1Cat = (HCategory*)(((HEvent*)(gHades->getCurrentEvent()))->getCategory(catMdcCal1));
    if (!cal1Cat) {
	Error("HMdcDeDx2Maker:init()","HMdcCal1 Category not available!");
	exit(1);
    }

    trkcanditer = (HIterator *)((HCategory*)trkcandCat)->MakeIterator("native");

    if(!hasPrinted)printStatus();
    fActive = kTRUE;
    return kTRUE;
}
void HMdcDeDx2Maker::printStatus()
{
    // prints the parameters to the screen
    SEPERATOR_msg("-",60);
    INFO_msg(10,HMessageMgr::DET_MDC,"HMdcDeDx2MakerSetup:");

    gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName()
			   ,"Input Mode      =  %i :  0 = from 1. MDC in seg, 1 = from 2. MDC in seg , 2 = from both MDC in seg",module);
    gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName()
			   ,"Fill Mode       =  %i :  0 = combined, 1 = combined+seg, 2 = combined+seg+mod",fillCase);

    SEPERATOR_msg("-",60);
    hasPrinted = kTRUE;
}
Int_t HMdcDeDx2Maker::execute(void)
{

    // calculates dEdx for all Segments contained in HMdcTrkCand.
    // The result is filled to HMdctrk.

    if(trkcandCat->getEntries() < 0) return 0;
    if(segCat    ->getEntries() < 0) return 0;
    if(clsCat    ->getEntries() < 0) return 0;
    if(clsInfCat ->getEntries() < 0) return 0;
    if(cal1Cat   ->getEntries() < 0) return 0;

    HMdcTrkCand* trkcand;

    trkcanditer->Reset();

    Float_t dedx   ;
    Float_t dedxold;
    Float_t sig    ;
    Float_t sigold ;
    UChar_t nw     ;
    UChar_t nwcut  ;

    HMdcSeg* seg[2] = {0};

    Int_t n = trkcandCat->getEntries();
    for(Int_t i=0;i<n;i++){
	trkcand = (HMdcTrkCand *) trkcandCat->getObject(i);

	seg[0] = seg[1] = 0;
	if(trkcand->getSeg1Ind() != -1) { seg[0] = (HMdcSeg*)segCat->getObject(trkcand->getSeg1Ind()); }
	if(trkcand->getSeg2Ind() != -1) { seg[1] = (HMdcSeg*)segCat->getObject(trkcand->getSeg2Ind()); }

	// fill case 0 (always) : combined
        dedx = mdcdedx->calcDeDx(seg,&dedxold,&sigold,&nw,&sig,&nwcut,2,module,kTRUE,-99.);

	if(dedx > -98.){
	    trkcand->setdedxSeg        (2,dedx );
	    trkcand->setSigmadedxSeg   (2,sig  );
	    trkcand->setNWirededxSeg   (2,nw   );
	    trkcand->setNWireCutdedxSeg(2,nwcut);
	}

	if(fillCase > 0){ // case 1: combined + seg
	    //-----------------------------------------------------
	    // inner seg
	    dedx = mdcdedx->calcDeDx(seg,&dedxold,&sigold,&nw,&sig,&nwcut,0,module,kTRUE,-99.);

	    if(dedx > -98.){
		trkcand->setdedxSeg        (0,dedx );
		trkcand->setSigmadedxSeg   (0,sig  );
		trkcand->setNWirededxSeg   (0,nw   );
		trkcand->setNWireCutdedxSeg(0,nwcut);
	    }
	    // outer seg
	    dedx = mdcdedx->calcDeDx(seg,&dedxold,&sigold,&nw,&sig,&nwcut,1,module,kTRUE,-99.);

	    if(dedx > -98.){
		trkcand->setdedxSeg        (1,dedx );
		trkcand->setSigmadedxSeg   (1,sig  );
		trkcand->setNWirededxSeg   (1,nw   );
		trkcand->setNWireCutdedxSeg(1,nwcut);
	    }
	}

	if(fillCase > 1 ) // case 2: combined + seg + module
	{
	    // per module
	    Float_t dedxM    [4];
	    Float_t dedxOldM [4];
	    Float_t sigM     [4];
	    Float_t sigOldM  [4];
	    UChar_t nwM      [4];
	    UChar_t nwCutM   [4];

	    for(Int_t m = 0; m < 4; m ++){
		if(seg[0] != 0 && m < 2){  // inner seg
		    dedxM[m] = mdcdedx->calcDeDx(seg,&dedxOldM[m],&sigOldM[m],&nwM[m],&sigM[m],&nwCutM[m],0,m%2,kTRUE,-99.);
		    if(dedx > -98.){
			trkcand->setdedx        (m,dedxM [m]);
			trkcand->setSigmadedx   (m,sigM  [m]);
			trkcand->setNWirededx   (m,nwM   [m]);
			trkcand->setNWireCutdedx(m,nwCutM[m]);
		    }
		}
		if(seg[1] != 0 && m > 1){ // outer seg
		    dedxM[m] = mdcdedx->calcDeDx(seg,&dedxOldM[m],&sigOldM[m],&nwM[m],&sigM[m],&nwCutM[m],1,m%2,kTRUE,-99.);
		    if(dedx > -98.){
			trkcand->setdedx        (m,dedxM [m]);
			trkcand->setSigmadedx   (m,sigM  [m]);
			trkcand->setNWirededx   (m,nwM   [m]);
			trkcand->setNWireCutdedx(m,nwCutM[m]);
		    }
		}
	    }
	}
	//-----------------------------------------------------


    }

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