67 #include "TObjString.h"
77 #include <ext/hash_map>
82 using namespace __gnu_cxx;
83 using __gnu_cxx::hash_map;
127 virtual void algoEndJob ()
override;
131 void algoAnalyzeTheTree();
132 void algoComputeMPVandGain();
135 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange=50,
double HighRange=5400);
136 bool IsGoodLandauFit(
double* FitResults);
138 void MakeCalibrationMap();
139 bool produceTagFilter();
205 unsigned int eventnumber = 0;
243 template <
class T>
bool operator () (
const T& PseudoDetId1,
const T& PseudoDetId2) {
return PseudoDetId1==PseudoDetId2; }
247 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >
APVsColl;
251 if(A->GetNbinsX() == B->GetNbinsX()){
254 for(
int x=0;
x<=B->GetNbinsX()+1;
x++){
255 for(
int y=0;y<=B->GetNbinsY()+1; y++){
256 A->SetBinContent(
x,y,A->GetBinContent(
x,y)+B->GetBinContent(
x,y));
323 EventPrefix_ = evtinfo_pset.getUntrackedParameter<
string>(
"prefix");
324 EventSuffix_ = evtinfo_pset.getUntrackedParameter<
string>(
"suffix");
329 TrackPrefix_ = track_pset.getUntrackedParameter<
string>(
"prefix");
330 TrackSuffix_ = track_pset.getUntrackedParameter<
string>(
"suffix");
343 dbe->setCurrentFolder(
"AlCaReco/SiStripGains/");
346 Charge_Vs_Index =
dbe->book2D(
"Charge_Vs_Index" ,
"Charge_Vs_Index" , 88625, 0 , 88624,2000,0,4000);
361 auto const &
Det = tkGeom->dets();
365 unsigned int Index=0;
366 for(
unsigned int i=0;
i<
Det.size();
i++){
374 if(!DetUnit)
continue;
377 unsigned int NAPV = Topo.
nstrips()/128;
379 for(
unsigned int j=0;
j<NAPV;
j++){
395 APV->
x = DetUnit->position().basicVector().x();
396 APV->
y = DetUnit->position().basicVector().y();
397 APV->
z = DetUnit->position().basicVector().z();
398 APV->
Eta = DetUnit->position().basicVector().eta();
399 APV->
Phi = DetUnit->position().basicVector().phi();
400 APV->
R = DetUnit->position().basicVector().transverse();
401 APV->
Thickness = DetUnit->surface().bounds().thickness();
413 for(
unsigned int i=0;
i<
Det.size();
i++){
418 if(!DetUnit)
continue;
421 unsigned int NROCRow = Topo.
nrows()/(80.);
422 unsigned int NROCCol = Topo.
ncolumns()/(52.);
424 for(
unsigned int j=0;
j<NROCRow;
j++){
425 for(
unsigned int i=0;
i<NROCCol;
i++){
440 APV->
x = DetUnit->position().basicVector().x();
441 APV->
y = DetUnit->position().basicVector().y();
442 APV->
z = DetUnit->position().basicVector().z();
443 APV->
Eta = DetUnit->position().basicVector().eta();
444 APV->
Phi = DetUnit->position().basicVector().phi();
445 APV->
R = DetUnit->position().basicVector().transverse();
446 APV->
Thickness = DetUnit->surface().bounds().thickness();
488 if(gainHandle->getNumberOfTags()!=2){
edm::LogError(
"SiStripGainFromCalibTree")<<
"NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";fflush(stdout);
exit(0);};
489 float newPreviousGain = gainHandle->getApvGain(APV->
APVId,gainHandle->getRange(APV->
DetId, 1),1);
493 float newPreviousGainTick = gainHandle->getApvGain(APV->
APVId,gainHandle->getRange(APV->
DetId, 0),1);
567 FitResults[0] = -0.5;
569 FitResults[2] = -0.5;
571 FitResults[4] = -0.5;
577 TF1* MyLandau =
new TF1(
"MyLandau",
"landau",LowRange, HighRange);
578 MyLandau->SetParameter(1,300);
579 InputHisto->Fit(MyLandau,
"0QR WW");
582 FitResults[0] = MyLandau->GetParameter(1);
583 FitResults[1] = MyLandau->GetParError(1);
584 FitResults[2] = MyLandau->GetParameter(2);
585 FitResults[3] = MyLandau->GetParError(2);
586 FitResults[4] = MyLandau->GetChisquare() / MyLandau->GetNDF();
587 FitResults[5] = MyLandau->GetParameter(0);
593 if(FitResults[0] <= 0 )
return false;
607 unsigned int FirstAmplitude=0;
608 for(
unsigned int i=0;
i<(*chargeoverpath).size();
i++){
609 FirstAmplitude+=(*nstrips)[
i];
610 int TI = (*trackindex)[
i];
642 bool Saturation =
false;
643 for(
unsigned int s=0;
s<(*nstrips)[
i];
s++){
644 int StripCharge = (*amplitude)[FirstAmplitude-(*nstrips)[
i]+
s];
648 if(StripCharge>1024){
651 }
else if(StripCharge>254){
655 Charge += StripCharge;
659 Charge = (*charge)[
i];
661 Charge = (*charge)[
i]/265.0;
666 double ClusterChargeOverPath = ( (double) Charge )/(*path)[
i] ;
668 if(
Validation) {ClusterChargeOverPath/=(*gainused)[
i];}
685 }
else if(APV->
Eta>0){
698 printf(
"Openning file %3i/%3i --> %s\n",
i+1, (
int)
VInputFiles.size(), (
char*)(
VInputFiles[
i].c_str())); fflush(stdout);
700 TTree*
tree =
dynamic_cast<TTree*
> (tfile->Get(
tree_path_.c_str()));
730 unsigned int nentries = tree->GetEntries();
731 printf(
"Number of Events = %i + %i = %i\n",
NEvent,nentries,(
NEvent+nentries));
732 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
733 printf(
"Looping on the Tree :");
734 int TreeStep = nentries/50;
if(TreeStep<=1)TreeStep=1;
735 for (
unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
736 if(ientry%TreeStep==0){printf(
".");fflush(stdout);}
737 tree->GetEntry(ientry);
748 double FitResults[6];
749 double MPVmean = 300;
754 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
755 printf(
"Fitting Charge Distribution :");
758 if(I%TreeStep==0){printf(
".");fflush(stdout);}
760 if(APV->
Bin<0) APV->
Bin = chvsidx->GetXaxis()->FindBin(APV->
Index);
764 Proj = (TH1F*)(chvsidx->ProjectionY(
"",chvsidx->GetXaxis()->FindBin(APV->
Index),chvsidx->GetXaxis()->FindBin(APV->
Index),
"e"));
769 int SecondAPVId = APV->
APVId;
770 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
772 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
773 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
774 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
776 for(
unsigned int i=0;
i<16;
i++){
777 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >::iterator tmpit;
782 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
783 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
784 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
792 APV->
FitMPV = FitResults[0];
817 unsigned int tree_Index;
818 unsigned int tree_Bin;
819 unsigned int tree_DetId;
820 unsigned char tree_APVId;
821 unsigned char tree_SubDet;
828 float tree_Thickness;
830 float tree_FitMPVErr;
832 float tree_FitWidthErr;
833 float tree_FitChi2NDF;
836 double tree_PrevGain;
837 double tree_PrevGainTick;
838 double tree_NEntries;
842 MyTree = tfs->
make<TTree> (
"APVGain",
"APVGain");
843 MyTree->Branch(
"Index" ,&tree_Index ,
"Index/i");
844 MyTree->Branch(
"Bin" ,&tree_Bin ,
"Bin/i");
845 MyTree->Branch(
"DetId" ,&tree_DetId ,
"DetId/i");
846 MyTree->Branch(
"APVId" ,&tree_APVId ,
"APVId/b");
847 MyTree->Branch(
"SubDet" ,&tree_SubDet ,
"SubDet/b");
848 MyTree->Branch(
"x" ,&tree_x ,
"x/F");
849 MyTree->Branch(
"y" ,&tree_y ,
"y/F");
850 MyTree->Branch(
"z" ,&tree_z ,
"z/F");
851 MyTree->Branch(
"Eta" ,&tree_Eta ,
"Eta/F");
852 MyTree->Branch(
"R" ,&tree_R ,
"R/F");
853 MyTree->Branch(
"Phi" ,&tree_Phi ,
"Phi/F");
854 MyTree->Branch(
"Thickness" ,&tree_Thickness ,
"Thickness/F");
855 MyTree->Branch(
"FitMPV" ,&tree_FitMPV ,
"FitMPV/F");
856 MyTree->Branch(
"FitMPVErr" ,&tree_FitMPVErr ,
"FitMPVErr/F");
857 MyTree->Branch(
"FitWidth" ,&tree_FitWidth ,
"FitWidth/F");
858 MyTree->Branch(
"FitWidthErr" ,&tree_FitWidthErr,
"FitWidthErr/F");
859 MyTree->Branch(
"FitChi2NDF" ,&tree_FitChi2NDF ,
"FitChi2NDF/F");
860 MyTree->Branch(
"FitNorm" ,&tree_FitNorm ,
"FitNorm/F");
861 MyTree->Branch(
"Gain" ,&tree_Gain ,
"Gain/D");
862 MyTree->Branch(
"PrevGain" ,&tree_PrevGain ,
"PrevGain/D");
863 MyTree->Branch(
"PrevGainTick" ,&tree_PrevGainTick,
"PrevGainTick/D");
864 MyTree->Branch(
"NEntries" ,&tree_NEntries ,
"NEntries/D");
865 MyTree->Branch(
"isMasked" ,&tree_isMasked ,
"isMasked/O");
868 FILE* Gains = stdout;
869 fprintf(Gains,
"NEvents = %i\n",
NEvent);
870 fprintf(Gains,
"NTracks = %i\n",
NTrack);
873 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
874 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
878 fprintf(Gains,
"NEvents = %i\n",
NEvent);
879 fprintf(Gains,
"NTracks = %i\n",
NTrack);
882 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
883 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
888 if(APV==
NULL)
continue;
892 tree_Index = APV->
Index;
894 tree_DetId = APV->
DetId;
895 tree_APVId = APV->
APVId;
896 tree_SubDet = APV->
SubDet;
904 tree_FitMPV = APV->
FitMPV;
908 tree_FitChi2NDF = APV->
FitChi2;
910 tree_Gain = APV->
Gain;
917 if(tree_DetId==402673324){
918 printf(
"%i | %i : %f --> %f (%f)\n", tree_DetId, tree_APVId, tree_PrevGain, tree_Gain, tree_NEntries);
924 if(Gains)fclose(Gains);
937 edm::LogWarning(
"SiStripGainFromCalibTree")<<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD+
BAD) << endl;
949 edm::LogWarning(
"SiStripGainFromCalibTree")<<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << endl;
955 std::vector<float>* theSiStripVector =
NULL;
956 unsigned int PreviousDetId = 0;
959 if(APV==
NULL){ printf(
"Bug\n");
continue; }
960 if(APV->
SubDet<=2)
continue;
961 if(APV->
DetId != PreviousDetId){
962 if(theSiStripVector!=
NULL){
964 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
966 theSiStripVector =
new std::vector<float>;
967 PreviousDetId = APV->
DetId;
969 theSiStripVector->push_back(APV->
Gain);
971 if(theSiStripVector!=
NULL){
973 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
987 TChain* t1 =
new TChain(
"SiStripCalib/APVGain");
990 unsigned int tree_DetId;
991 unsigned char tree_APVId;
994 t1->SetBranchAddress(
"DetId" ,&tree_DetId );
995 t1->SetBranchAddress(
"APVId" ,&tree_APVId );
996 t1->SetBranchAddress(
"Gain" ,&tree_Gain );
998 for (
unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
999 t1->GetEntry(ientry);
edm::EDGetTokenT< std::vector< int > > trackindex_token_
T getParameter(std::string const &) const
EventNumber_t event() const
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< float > * trackp
unsigned int MinTrackHits
edm::EDGetTokenT< std::vector< double > > tracketa_token_
edm::EDGetTokenT< std::vector< unsigned char > > amplitude_token_
MonitorElement * Charge_Vs_PathlengthTIB
const std::vector< double > * chargeoverpath
edm::EDGetTokenT< std::vector< unsigned int > > rawid_token_
const std::vector< unsigned char > * amplitude
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
SiStripApvGain * getNewObject() override
virtual int ncolumns() const =0
const std::vector< double > * localdirz
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const std::vector< double > * trackchi2ndof
virtual void algoBeginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< double > * localdirx
~SiStripGainFromCalibTree()
dispatcher processEvent(e, inputTag, standby)
#define DEFINE_FWK_MODULE(type)
MonitorElement * Charge_Vs_PathlengthTECM2
unsigned int NClusterPixel
virtual void algoEndRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< unsigned int > * rawid
edm::EDGetTokenT< std::vector< bool > > overlapping_token_
double tagCondition_GoodFrac
SiStripGainFromCalibTree(const edm::ParameterSet &)
edm::Handle< T > connect(const T *&ptr, edm::EDGetTokenT< T > token, const edm::Event &evt)
virtual int nrows() const =0
MonitorElement * Charge_Vs_PathlengthTOB
void storeOnTree(TFileService *tfs)
T * make(const Args &...args) const
make new ROOT object
const std::vector< float > * trackpt
const std::vector< unsigned int > * trackhitsvalid
void MakeCalibrationMap()
double MaxTrackChiOverNdf
edm::EDGetTokenT< std::vector< bool > > farfromedge_token_
bool put(const uint32_t &detID, Range input)
uint32_t rawId() const
get the raw id
edm::EDGetTokenT< std::vector< unsigned int > > trackhitsvalid_token_
T x() const
Cartesian x coordinate.
std::vector< stAPVGain * > APVsCollOrdered
__gnu_cxx::hash_map< unsigned int, stAPVGain *, __gnu_cxx::hash< unsigned int >, isEqual > APVsColl
edm::EDGetTokenT< std::vector< double > > path_token_
MonitorElement * Charge_Vs_PathlengthTECM1
void algoComputeMPVandGain()
MonitorElement * Charge_Vs_PathlengthTECP2
MonitorElement * Charge_Vs_PathlengthTECP1
edm::EDGetTokenT< std::vector< float > > trackp_token_
bool IsGoodLandauFit(double *FitResults)
MonitorElement * Charge_Vs_Index_Absolute
virtual void algoBeginJob(const edm::EventSetup &iSetup) override
std::pair< ContainerIterator, ContainerIterator > Range
edm::EDGetTokenT< std::vector< bool > > TrigTech_token_
edm::EDGetTokenT< std::vector< double > > chargeoverpath_token_
const std::complex< double > I
const std::vector< double > * gainused
edm::EDGetTokenT< std::vector< double > > localdirz_token_
const std::vector< unsigned short > * firststrip
const std::vector< double > * localdiry
edm::EDGetTokenT< std::vector< unsigned int > > charge_token_
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
vector< string > VInputFiles
virtual void algoEndJob() override
edm::EDGetTokenT< std::vector< unsigned short > > nstrips_token_
const std::vector< int > * trackindex
edm::EDGetTokenT< std::vector< unsigned short > > firststrip_token_
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< std::vector< float > > trackpt_token_
T const * product() const
MonitorElement * Charge_Vs_PathlengthTIDM
const std::vector< bool > * overlapping
const std::vector< bool > * saturation
bool merge(LuminosityBlockRange &lh, LuminosityBlockRange &rh)
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
void algoAnalyzeTheTree()
const std::vector< bool > * farfromedge
const std::vector< bool > * TrigTech
void setDoStore(const bool doStore)
When set to false the payload will not be written to the db.
MonitorElement * Charge_Vs_Index
TH2F * getTH2F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
double tagCondition_NClusters
edm::EDGetTokenT< std::vector< double > > localdirx_token_
edm::EDGetTokenT< std::vector< bool > > saturation_token_
edm::EDGetTokenT< std::vector< double > > trackchi2ndof_token_
edm::EDGetTokenT< std::vector< double > > localdiry_token_
volatile std::atomic< bool > shutdown_flag false
TH2F * getTH2F(void) const
const std::vector< unsigned int > * charge
MonitorElement * Charge_Vs_PathlengthTIDP
const std::vector< double > * path
const std::vector< double > * trackphi
const std::vector< unsigned short > * nstrips
edm::EDGetTokenT< std::vector< double > > gainused_token_
edm::EDGetTokenT< std::vector< double > > trackphi_token_
const std::vector< double > * tracketa
unsigned int NClusterStrip
void merge(TH2 *A, TH2 *B)