diff --git a/processors/TPlasticMappingProcessor.cc b/processors/TPlasticMappingProcessor.cc index 012b88580a7923f498e74a56c8e32717dc0297b4..fb27a730a5f152f2767172f496dd29fa299bc5af 100644 --- a/processors/TPlasticMappingProcessor.cc +++ b/processors/TPlasticMappingProcessor.cc @@ -3,27 +3,24 @@ * @brief * * @date Created: 2013-08-12 12:45:58 - * Last Modified: 2013-08-12 18:07:12 + * Last Modified: 2013-09-05 16:09:08 * @author KAWASE Shoichiro * * Copyright (C) 2013 KAWASE Shoichiro All rights reserved. */ #include "TPlasticMappingProcessor.h" +#include "TTimingChargeData.h" #include - -#include +#include using art::TPlasticMappingProcessor; -using std::cout; -using std::endl; - // Default constructor TPlasticMappingProcessor::TPlasticMappingProcessor() : fPlastic(NULL) { - StringVec_t defInput; defInput.push_back("categorized"); + StringVec_t defInput; defInput.push_back("catdata"); RegisterInputCollection("InputCollection","rawdata object returned by TRIDFEventStore", fInputColName,defInput); RegisterOutputCollection("OutputCollection","output collection name", @@ -35,16 +32,19 @@ TPlasticMappingProcessor::TPlasticMappingProcessor() fChargeTypeID,2); RegisterProcessorParameter("TimingTypeID","data type id for timing information (default: 1)", fTimingTypeID,1); + RegisterProcessorParameter("TrailingComesFirst","0: Leading->Trailing (default), 1: Trailing->Leading (for QTC etc.)", + fTrailingComesFirst,kFALSE); } // Default destructor TPlasticMappingProcessor::~TPlasticMappingProcessor() { if(fPlastic) delete fPlastic; + fPlastic = NULL; } void TPlasticMappingProcessor::Init(TEventCollection *col) { - fCategorizedData = dynamic_cast(col->Get(fInputColName.front())); - fPlastic = new TClonesArray("TCatSimpleData"); // should be corrected + fCategorizedData = (TCategorizedData**)col->Get(fInputColName.front())->GetObjectRef(); + fPlastic = new TClonesArray("art::TTimingChargeData"); fPlastic->SetName(fOutputColName); col->Add(fOutputColName,fPlastic,fOutputIsTransparent); } @@ -53,47 +53,103 @@ void TPlasticMappingProcessor::Process() { fPlastic->Clear("C"); - TObjArray *cat = fCategorizedData->FindCategory(fCatID); - cout << cat << endl; + TObjArray *cat = (*fCategorizedData)->FindCategory(fCatID); + if (!cat) return; - TIterator *itr = cat->MakeIterator(); - TObjArray *det = NULL; - - while((det = (TObjArray*)itr->Next())) { - Int_t did = det->GetUniqueID(); - cout << "did = " << did << endl; - cout << det->GetEntriesFast() << endl; - - TRefArray *ts = (TRefArray*)det->At(fTimingTypeID); - cout << fTimingTypeID << endl; - if (!ts){ continue; } - - Int_t nHit = ts->GetLast()+1; - cout << "nHit = " << nHit << endl; - - for(Int_t iHit = 0; iHit != nHit; ++iHit) { - printf("%d %d\n", iHit, nHit); -/* - TCatRawDataV1190 *hit = (TCatRawDataV1190*) ts->At(iHit); - if (!hit) { continue; } - if (!(hit->IsValid)) { continue; } -*/ -/* - TCatSimpleData *data = new ((*fPlastic)[fPlastic->GetEntriesFast()]) TCatSimpleData; // should be corrected - data->SetTiming(hit->Leading()); - data->SetCharge(hit->Width()); - data->SetDetID(hit->GetDetectorID()); - data->SetCatID(fCatID); -*/ + Int_t n = cat->GetEntriesFast(); + TObjArray *det = NULL; + TRefArray *tArray = NULL; + TRefArray *qArray = NULL; + + for(Int_t i = 0 ; i != n ; ++i){ + det = (TObjArray*)cat->At(i); +// Int_t did = det->GetUniqueID(); +// cout << "did = " << did << endl; +// cout << det->GetEntriesFast() << endl; + + tArray = (TRefArray*)det->At(fTimingTypeID); + if (!tArray){ continue; } + + if (fChargeType == kWIDTH) { + MapEdgedTime(tArray); + } else /* if (fChargeType == kQDC) */ { + qArray = (TRefArray*)det->At(fChargeTypeID); + MapTimeCharge(tArray,qArray); } -/* - TCatSimpleData::SetSortType(TCatSimpleData::kCharge); - TCatSImpleData::SetSortOrder(TCatSImpleData::kDESC); -*/ + + // sort data in the same event in decsending order of charge + TTimingChargeData::SetSortType(TTimingChargeData::kCharge); + TTimingChargeData::SetSortOrder(TTimingChargeData::kDESC); + fPlastic->Sort(); + } } +void TPlasticMappingProcessor::MapEdgedTime(TRefArray *tArray) +{ + TTimingChargeData *data = NULL; + TRawTimingWithEdge *hit = NULL; + Bool_t isLeading = kFALSE; + Int_t nHit = tArray->GetLast() + 1; +// cout << "nHit = " << nHit << endl; + +// printf("MapEdgedTime()\n"); + + for(Int_t iHit = 0; iHit != nHit; ++iHit) { + + hit = (TRawTimingWithEdge*) tArray->At(iHit); + if (!hit) continue; + + isLeading = (hit->IsLeading() != fTrailingComesFirst); + + if(isLeading) { +// printf("IsLeading\n"); + // "Leading" edge + data = static_cast(fPlastic->ConstructedAt(fPlastic->GetEntriesFast())); + if (!data) { + printf("something strange happened in TPlasticMappingProc::MapEdgedTime\n"); + continue; + } + data->SetTiming(hit->GetTiming()); + data->SetDetID(hit->GetDetID()); + } else if (data) { + // "Trailing" edge after "Leading" one + data->SetCharge(hit->GetTiming() - data->GetTiming()); + data = NULL; + } else { + // consecutive "Trailing" edge + // thought to be abnormal + } + } +} + +void TPlasticMappingProcessor::MapTimeCharge(TRefArray *tArray, TRefArray *qArray){ + + if(!tArray) return; + + TTimingChargeData *data = NULL; + + Int_t nHit = tArray->GetLast() + 1; + + TRawTiming *tHit = NULL; + TRawTiming *qHit = NULL; + + tHit = (TRawTiming*) tArray->At(0); + if (!tHit) { return; } + + data = static_cast(fPlastic->ConstructedAt(fPlastic->GetEntriesFast())); + data->SetTiming(tHit->GetTiming()); + data->SetDetID(tHit->GetDetID()); + + if(!qArray || qArray->GetLast() != 0) return; + + qHit = (TRawTiming*) qArray->At(0); + + data->SetCharge(qHit->GetTiming()); + +} + void TPlasticMappingProcessor::PreLoop() { } diff --git a/processors/TPlasticMappingProcessor.h b/processors/TPlasticMappingProcessor.h index 930a781523c8bb5ea075ed046519a785856c5ae1..f5eefede6fb56f2a279351b4cfb750f3f16993ad 100644 --- a/processors/TPlasticMappingProcessor.h +++ b/processors/TPlasticMappingProcessor.h @@ -3,7 +3,7 @@ * @brief * * @date Created: 2013-08-12 12:36:40 - * Last Modified: 2013-08-12 16:21:01 + * Last Modified: 2013-09-05 13:44:25 * @author KAWASE Shoichiro * * Copyright (C) 2013 KAWASE Shoichiro All rights reserved @@ -20,6 +20,7 @@ namespace art{ } class TClonesArray; +class TRefArray; class art::TPlasticMappingProcessor : public TProcessor { @@ -35,15 +36,16 @@ public: virtual void PostLoop(); protected: - StringVec_t fInputColName; - TString fOutputColName; - TCategorizedData* fCategorizedData; - TClonesArray* fPlastic; + StringVec_t fInputColName; + TString fOutputColName; + TCategorizedData **fCategorizedData; + TClonesArray *fPlastic; - Int_t fCatID; // default: 21 (spla in anapaw) - Int_t fChargeType; // 0: V1190 width (default), 1: QDC (V792 etc) - Int_t fChargeTypeID; // used only when fChargeType is QDC - Int_t fTimingTypeID; // Typeid for timing (and width when fChargeType is V1190 width) + Int_t fCatID; // default: 21 (spla in anapaw) + Int_t fChargeType; // 0: V1190 width (default), 1: QDC (V792 etc) + Int_t fChargeTypeID; // used only when fChargeType is QDC + Int_t fTimingTypeID; // Typeid for timing (& width when fChargeType is V1190width) + Bool_t fTrailingComesFirst; // F: TL->TT (default), T: TT->TL (for QTC etc.) private: // Copy constructor (prohibited) @@ -51,6 +53,11 @@ private: // Assignment operator (prohibited) TPlasticMappingProcessor& operator=(const TPlasticMappingProcessor& rhs); + void MapEdgedTime(TRefArray *tArray); + void MapTimeCharge(TRefArray *tArray, TRefArray *qArray); + + enum EChargeTypeID { kWIDTH, kQDC, }; + }; #endif // TPLASTICMAPPINGPROCESSOR_H diff --git a/processors/TTimingChargeData.cc b/processors/TTimingChargeData.cc new file mode 100644 index 0000000000000000000000000000000000000000..932c01abc7f730c56e1b5828bfa52682abe428e4 --- /dev/null +++ b/processors/TTimingChargeData.cc @@ -0,0 +1,86 @@ +/** + * @file TTimingChargeData.cc + * @brief + * + * @date Created: 2013-08-14 10:34:09 + * Last Modified: 2013-08-21 11:26:15 + * @author KAWASE Shoichiro + * + * Copyright (C) 2013 KAWASE Shoichiro All rights reserved. + */ + +#include "TTimingChargeData.h" + +#include "TMath.h" + +ClassImp(art::TTimingChargeData); + +using art::TTimingChargeData; + +// Default constructor +TTimingChargeData::TTimingChargeData() + : fTiming(TMath::QuietNaN()), fCharge(TMath::QuietNaN()) { +} + +// Default destructor +TTimingChargeData::~TTimingChargeData() { +} + +// Copy constructor +TTimingChargeData::TTimingChargeData(const TTimingChargeData& rhs) + : TObject(rhs) { + fTiming = rhs.fTiming; + fCharge = rhs.fCharge; +} + +// Assignment operator +TTimingChargeData& TTimingChargeData::operator=(const TTimingChargeData& rhs) { + if (this != &rhs) { + ((TTimingChargeData&)rhs).Copy(*this); + } + return *this; + } + +Int_t TTimingChargeData::Compare(const TObject *obj) const{ + + TTimingChargeData *data= (TTimingChargeData*) obj; + Int_t ret = -1; + if(!obj) { + ret = 1; + } else { + switch (fSortType) { + case kCharge: + if (fCharge > data->GetCharge()) { + ret = 1; + } else if (fCharge == data->GetCharge()) { + ret = 0; + } else { + ret = -1; + } + break; + case kTime: + if (fTiming > data->GetTiming()) { + ret = 1; + } else if (fTiming == data->GetTiming()) { + ret = 0; + } else { + ret = -1; + } + break; + default: + return TObject::Compare(obj); + break; + } + } + switch (fSortOrder) { + case kASC: + return ret; + case kDESC: + return -ret; + } + + return 0; +} + +Int_t TTimingChargeData::fSortType = TTimingChargeData::kID; +Int_t TTimingChargeData::fSortOrder = TTimingChargeData::kDESC; diff --git a/processors/TTimingChargeData.h b/processors/TTimingChargeData.h new file mode 100644 index 0000000000000000000000000000000000000000..201403dd6b5d046cf8a22ce75a3b9002ccf2b39d --- /dev/null +++ b/processors/TTimingChargeData.h @@ -0,0 +1,68 @@ +/** + * @file TTimingChargeData.h + * @brief + * + * @date Created: 2013-08-14 10:19:28 + * Last Modified: 2013-08-21 11:53:01 + * @author KAWASE Shoichiro + * + * Copyright (C) 2013 KAWASE Shoichiro All rights reserved + */ + +#ifndef TTIMINGCHARGEDATA_H +#define TTIMINGCHARGEDATA_H + +#include + +namespace art{ + +class TTimingChargeData : public TObject { +public: + typedef enum {kID, kCharge, kTime} ETimingChargeSortType; //! + typedef enum {kASC, kDESC} ESortOrder; //! + + // Default constructor + TTimingChargeData(); + // Default destructor + virtual ~TTimingChargeData(); + // Copy constructor + TTimingChargeData(const TTimingChargeData& rhs); + // Assignment operator + TTimingChargeData& operator=(const TTimingChargeData& rhs); + + virtual Int_t Compare(const TObject*) const; + + virtual Double_t GetTiming() const {return fTiming;} + virtual void SetTiming(const Double_t &val){fTiming = val;} + + virtual Double_t GetCharge() const {return fCharge;} + virtual void SetCharge(const Double_t &val){fCharge = val;} + + virtual Int_t GetDetID() const {return fDetectorID;} + virtual void SetDetID(const Int_t &val){fDetectorID = val;} + + static void SetSortOrder(const Int_t &order){fSortOrder = order;} + static void SetSortType(const Int_t &type){fSortType = type;} + + virtual Bool_t IsSortable() const {return kTRUE;} + + virtual void Copy(TObject& dest) const { + TObject::Copy(dest); + TTimingChargeData &cobj = *(TTimingChargeData*)&dest; + cobj.fTiming = fTiming; + cobj.fCharge = fCharge; + cobj.fDetectorID = fDetectorID; + } + +protected: + Double_t fTiming; + Double_t fCharge; + Int_t fDetectorID; + static Int_t fSortType; //! + static Int_t fSortOrder; //! + + ClassDef(TTimingChargeData,1); +}; + +} +#endif // TTIMINGCHARGEDATA_H diff --git a/processors/linkdef_user.h b/processors/linkdef_user.h index ba5d507ea8a6eed2190eeb081c60adf3b21f3b64..366ccd17f43436473c04559a8ad0b38f806934b4 100644 --- a/processors/linkdef_user.h +++ b/processors/linkdef_user.h @@ -3,7 +3,7 @@ * @brief * * @date Created: 2013-08-12 14:48:07 - * Last Modified: 2013-08-12 15:49:43 + * Last Modified: 2013-09-05 13:45:06 * @author KAWASE Shoichiro * * Copyright (C) 2013 KAWASE Shoichiro All rights reserved @@ -19,6 +19,8 @@ #pragma link off all functions; #pragma link C++ class art::TPlasticMappingProcessor-; +#pragma link C++ class art::TTimingChargeData+; + #endif // __CINT__ diff --git a/processors/makefile b/processors/makefile index 12fe84d36cd85da2c56a8cc0b72f564d46f7776c..448efbb882243f3f848341471da642235bea4d96 100644 --- a/processors/makefile +++ b/processors/makefile @@ -1,5 +1,6 @@ #CXX = g++ -OBJ = TPlasticMappingProcessor.o +OBJ = TPlasticMappingProcessor.o \ + TTimingChargeData.o UNAME = $(shell uname) ifeq ($(UNAME),Darwin)